Stroika Library 3.0d18
 
Loading...
Searching...
No Matches
LedLineItApplication.cpp
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4
5#include "Stroika/Foundation/StroikaPreComp.h"
6
7#include <afx.h>
8
11
12#include "Stroika/Frameworks/Led/Platform/Windows_FileRegistration.h"
13#include "Stroika/Frameworks/Led/StdDialogs.h"
14
15#include "FontMenu.h"
16#include "LedLineItDocFrame.h"
17#include "LedLineItDocument.h"
18#include "LedLineItInPlaceFrame.h"
19#include "LedLineItMainFrame.h"
20#include "LedLineItView.h"
21#include "Options.h"
22#include "Resource.h"
23
24#include "LedLineItApplication.h"
25
26using namespace Stroika::Foundation;
27using namespace Stroika::Frameworks::Led;
28
29#define STD_EXCEPT_CATCHER(APP) \
30 catch (CMemoryException * e) \
31 { \
32 (APP).HandleBadAllocException (); \
33 e->Delete (); \
34 } \
35 catch (CException * e) \
36 { \
37 (APP).HandleMFCException (e); \
38 e->Delete (); \
39 } \
40 catch (bad_alloc) \
41 { \
42 (APP).HandleBadAllocException (); \
43 } \
44 catch (const system_error&) \
45 { \
46 (APP).HandleUnknownException (); \
47 } \
48 catch (TextInteractor::BadUserInput&) \
49 { \
50 (APP).HandleBadUserInputException (); \
51 } \
52 catch (...) \
53 { \
54 (APP).HandleUnknownException (); \
55 }
56
57class SimpleLedTemplate : public CMultiDocTemplate {
58public:
59 SimpleLedTemplate (const char* daStr)
60 : CMultiDocTemplate (IDR_MAINFRAME, RUNTIME_CLASS (LedLineItDocument), RUNTIME_CLASS (LedLineItDocFrame), RUNTIME_CLASS (LedLineItView))
61 {
62 m_strDocStrings = daStr;
63 }
64
65 virtual void LoadTemplate () override
66 {
67 CMultiDocTemplate::LoadTemplate ();
68
69 // Now go and fixup the font menu...
70 if (m_hMenuShared != NULL) {
71 CMenu tmp;
72 tmp.Attach (m_hMenuShared);
73#if qSupportSyntaxColoring
74 FixupFontMenu (tmp.GetSubMenu (2)->GetSubMenu (7));
75#else
76 FixupFontMenu (tmp.GetSubMenu (2)->GetSubMenu (6));
77#endif
78 tmp.Detach ();
79 }
80 }
81
82public:
83 CDocument* OpenDocumentFile (LPCTSTR lpszPathName, BOOL bMakeVisible)
84 {
85 /*
86 * Based on CDocManager::OpenDocumentFile () from MFC (Version?? from MSVC.Net 2k3 - 2003-11-28)
87 * but fixed to better handle exceptions. -- LGP 2003-11-28
88 */
89 CDocument* pDocument = CreateNewDocument ();
90 if (pDocument == NULL) {
91 TRACE (traceAppMsg, 0, "CDocTemplate::CreateNewDocument returned NULL.\n");
92 AfxMessageBox (AFX_IDP_FAILED_TO_CREATE_DOC);
93 return NULL;
94 }
95 ASSERT_VALID (pDocument);
96
97 try {
98 BOOL bAutoDelete = pDocument->m_bAutoDelete;
99 pDocument->m_bAutoDelete = FALSE; // don't destroy if something goes wrong
100 CFrameWnd* pFrame = CreateNewFrame (pDocument, NULL);
101 pDocument->m_bAutoDelete = bAutoDelete;
102 if (pFrame == NULL) {
103 AfxMessageBox (AFX_IDP_FAILED_TO_CREATE_DOC);
104 delete pDocument; // explicit delete on error
105 return NULL;
106 }
107 ASSERT_VALID (pFrame);
108
109 if (lpszPathName == NULL) {
110 // create a new document - with default document name
111 SetDefaultTitle (pDocument);
112
113 // avoid creating temporary compound file when starting up invisible
114 if (!bMakeVisible)
115 pDocument->m_bEmbedded = TRUE;
116
117 if (!pDocument->OnNewDocument ()) {
118 // user has be alerted to what failed in OnNewDocument
119 TRACE (traceAppMsg, 0, "CDocument::OnNewDocument returned FALSE.\n");
120 pFrame->DestroyWindow ();
121 return NULL;
122 }
123
124 // it worked, now bump untitled count
125 ++m_nUntitledCount;
126 }
127 else {
128 // open an existing document
129 CWaitCursor wait;
130 if (!pDocument->OnOpenDocument (lpszPathName)) {
131 TRACE (traceAppMsg, 0, "CDocument::OnOpenDocument returned FALSE.\n");
132 throw bad_alloc (); // misc random exception - not sure what TO throw here?
133 }
134 pDocument->SetPathName (lpszPathName);
135 }
136
137 InitialUpdateFrame (pFrame, pDocument, bMakeVisible);
138 return pDocument;
139 }
140 catch (...) {
141 pDocument->OnCloseDocument ();
142 throw;
143 }
144 }
145};
146
147// Make sure the given name isn't a mangled 8.3 name
148inline SDKString GetLongPathName (const SDKString& pathName)
149{
150 TCHAR szPath[_MAX_PATH];
151 Require (pathName.length () < _MAX_PATH);
152 Characters::CString::Copy (szPath, Memory::NEltsOf (szPath), pathName.c_str ());
153 WIN32_FIND_DATA fileData;
154 HANDLE hFind = ::FindFirstFile (szPath, &fileData);
155 if (hFind != INVALID_HANDLE_VALUE) {
156 TCHAR* lastSlash = ::_tcsrchr (szPath, '\\');
157 if (lastSlash == NULL) {
158 szPath[0] = '\0'; // just plain file name
159 }
160 else {
161 // strip the filename part - just keeping the full directory path
162 *lastSlash = '\0';
163 Characters::CString::Cat (szPath, Memory::NEltsOf (szPath), _T ("\\"));
164 }
165 Characters::CString::Cat (szPath, Memory::NEltsOf (szPath), fileData.cFileName);
166 VERIFY (::FindClose (hFind));
167 }
168 return szPath;
169}
170
171class LedLineItDocManager : public CDocManager {
172private:
173 using inherited = CDocManager;
174
175public:
176 LedLineItDocManager ()
177 : inherited ()
178 {
179 }
180
181public:
182 virtual void OnFileOpen () override
183 {
184 ::CString fileName;
185 CodePage codePage = 0;
186 if (LedLineItDocument::DoPromptOpenFileName (&fileName, &codePage)) {
187 OpenDocumentFile (fileName, codePage);
188 }
189 }
190
191public:
192 virtual BOOL DoPromptFileName (::CString& /*fileName*/, UINT /*nIDSTitle*/, DWORD /*lFlags*/, BOOL /*bOpenFileDialog*/, CDocTemplate* /*pTemplate*/) override
193 {
194 Assert (false); // shouldn't be called - cuz we now override OnFileOpen () to avoid it...
195 return false;
196 }
197
198public:
199 CDocument* OpenDocumentFile (LPCTSTR lpszFileName, CodePage codePage)
200 {
201 Assert (LedLineItDocument::sHiddenDocOpenArg == kIGNORECodePage);
202 try {
203 // If there is already an open, untitledDoc - and we open a new document - silently close the unused
204 // untitled doc
205 CDocument* untitledDoc = NULL;
206 {
207 size_t docCount = 0;
208 POSITION tp = GetFirstDocTemplatePosition ();
209 while (tp != NULL) {
210 CDocTemplate* t = GetNextDocTemplate (tp);
211 AssertNotNull (t);
212 POSITION dp = t->GetFirstDocPosition ();
213 while (dp != NULL) {
214 CDocument* doc = t->GetNextDoc (dp);
215 AssertNotNull (doc);
216 ++docCount;
217 if (docCount == 1) {
218 // See if doc not dirty and has no file name and if so - set it to untitledDoc
219 if (not doc->IsModified () and doc->GetPathName ().GetLength () == 0) {
220 untitledDoc = doc;
221 }
222 }
223 else {
224 untitledDoc = NULL;
225 }
226 }
227 }
228 }
229
230 LedLineItDocument::sHiddenDocOpenArg = codePage;
231 CDocument* doc = inherited::OpenDocumentFile (GetLongPathName (lpszFileName).c_str (), TRUE);
232 LedLineItDocument::sHiddenDocOpenArg = kIGNORECodePage;
233
234 if (untitledDoc != NULL) {
235 untitledDoc->OnCloseDocument ();
236 }
237 return doc;
238 }
239 catch (...) {
240 LedLineItDocument::sHiddenDocOpenArg = kIGNORECodePage;
241 throw;
242 }
243 }
244 virtual CDocument* OpenDocumentFile (LPCTSTR lpszFileName) override
245 {
246 return OpenDocumentFile (lpszFileName, kAutomaticallyGuessCodePage);
247 }
248};
249
250const char kAppName[] = "LedLineIt";
251
252/*
253 ********************************************************************************
254 ******************************** LedLineItApplication **************************
255 ********************************************************************************
256 */
257LedLineItApplication theApp;
258
259// This identifier was generated to be statistically unique for your app.
260// You may change it if you prefer to choose a specific identifier.
261// {0FC00620-28BD-11CF-899C-00AA00580325}
262static const CLSID clsid = {0xfc00620, 0x28bd, 0x11cf, {0x89, 0x9c, 0x0, 0xaa, 0x0, 0x58, 0x3, 0x25}};
263
264BEGIN_MESSAGE_MAP (LedLineItApplication, CWinApp)
265ON_COMMAND (ID_APP_ABOUT, OnAppAbout)
266ON_COMMAND (ID_FILE_NEW, OnFileNew)
267ON_COMMAND (ID_FILE_OPEN, OnFileOpen)
268ON_COMMAND (ID_FILE_PRINT_SETUP, OnFilePrintSetup)
269ON_COMMAND (kToggleAutoIndentOptionCmd, OnToggleAutoIndentOptionCommand)
270ON_UPDATE_COMMAND_UI (kToggleAutoIndentOptionCmd, OnToggleAutoIndentOptionUpdateCommandUI)
271ON_COMMAND (kToggleTreatTabAsIndentCharOptionCmd, OnToggleTreatTabAsIndentCharOptionCommand)
272ON_UPDATE_COMMAND_UI (kToggleTreatTabAsIndentCharOptionCmd, OnToggleTreatTabAsIndentCharOptionUpdateCommandUI)
273ON_COMMAND (kToggleUseSmartCutNPasteCmdID, OnToggleSmartCutNPasteOptionCommand)
274ON_UPDATE_COMMAND_UI (kToggleUseSmartCutNPasteCmdID, OnToggleSmartCutNPasteOptionUpdateCommandUI)
275#if qSupportSyntaxColoring
276ON_COMMAND_RANGE (kNoSyntaxColoringCmd, kVBSyntaxColoringCmd, OnSyntaxColoringOptionCommand)
277ON_UPDATE_COMMAND_UI_RANGE (kNoSyntaxColoringCmd, kVBSyntaxColoringCmd, OnSyntaxColoringOptionUpdateCommandUI)
278#endif
279ON_COMMAND (cmdChooseDefaultFontDialog, OnChooseDefaultFontCommand)
280ON_COMMAND (kGotoLedLineItWebPageCmdID, OnGotoLedLineItWebPageCommand)
281ON_COMMAND (kCheckForUpdatesWebPageCmdID, OnCheckForUpdatesWebPageCommand)
282ON_COMMAND (kGotoSophistsWebPageCmdID, OnGotoSophistsWebPageCommand)
283END_MESSAGE_MAP ()
284
285LedLineItApplication* LedLineItApplication::sThe = NULL;
286
287LedLineItApplication::LedLineItApplication ()
288 :
289#if qIncludeBasicSpellcheckEngine
290 fSpellCheckEngine ()
291 ,
292#endif
293 fOleTemplateServer ()
294{
295 Require (sThe == NULL);
296 sThe = this;
297}
298
299LedLineItApplication::~LedLineItApplication ()
300{
301 Require (sThe == this);
302 sThe = NULL;
303}
304
305LedLineItApplication& LedLineItApplication::Get ()
306{
307 EnsureNotNull (sThe);
308 return *sThe;
309}
310
311BOOL LedLineItApplication::InitInstance ()
312{
313 SetRegistryKey (_T ("Sophist Solutions, Inc."));
314
315 // Initialize OLE libraries
316 if (!AfxOleInit ()) {
317 AfxMessageBox (IDP_OLE_INIT_FAILED);
318 return false;
319 }
320
321 // Create MDI Frame Window
322 {
323 LedLineItMainFrame* pFrame = new LedLineItMainFrame ();
324 if (not pFrame->LoadFrame (IDR_MAINFRAME)) {
325 return false;
326 }
327 m_pMainWnd = pFrame;
328
329 pFrame->DragAcceptFiles ();
330 }
331
332 // Parse command line for standard shell commands, DDE, file open
333 CCommandLineInfo cmdInfo;
334 ParseCommandLine (cmdInfo);
335
336#if 0
337 // LGP 960509 - doesn't appear to have any effect if present or not...
338 // and prevents linking on Mac (CodeWarrior x-compiler).
339 Enable3dControlsStatic (); // Call this when linking to MFC statically
340#endif
341
342 LoadStdProfileSettings (9); // Load standard INI file options (including MRU)
343
344 Assert (m_pDocManager == NULL);
345 m_pDocManager = new LedLineItDocManager ();
346
347 AddDocTemplateForString ("LedLineIt\n\nLedLineIt\n\n.ledtext\nLedLineIt.Document\nLedLineIt Document", true);
348
349 // Enable DDE Open, and register icons / file types with the explorer/shell
350 EnableShellOpen ();
351 RegisterShellFileTypes (true); // ARG???
352
353 // When a server application is launched stand-alone, it is a good idea
354 // to update the system registry in case it has been damaged.
355 fOleTemplateServer.UpdateRegistry (OAT_INPLACE_SERVER);
356 COleObjectFactory::UpdateRegistryAll ();
357
358#if qIncludeBasicSpellcheckEngine && qStroika_Foundation_Debug_AssertionsChecked
360 SpellCheckEngine_Basic::RegressionTest ();
361 }
362 fSpellCheckEngine = make_shared<SpellCheckEngine_Basic_Simple> ();
363#if qStroika_Foundation_Common_Platform_Windows
364 {
365 // Place the dictionary in a reasonable - but hardwired place. Later - allow for editing that location,
366 // and other spellchecking options (see SPR#1591)
367 TCHAR defaultPath[MAX_PATH + 1];
368 Verify (::SHGetSpecialFolderPath (NULL, defaultPath, CSIDL_FLAG_CREATE | CSIDL_PERSONAL, true));
369 fSpellCheckEngine->SetUserDictionary (SDKString{defaultPath} + Led_SDK_TCHAROF ("\\My LedLineIt Dictionary.txt"));
370 }
371#endif
372#endif
373
374#if qStroika_Foundation_Common_Platform_Windows
375 {
376 class MyRegistrationHelper : public Win32UIFileAssociationRegistrationHelper {
377 private:
378 using inherited = Win32UIFileAssociationRegistrationHelper;
379
380 public:
381 MyRegistrationHelper ()
382 : inherited (::AfxGetResourceHandle ())
383 {
384 }
385
386 public:
387 virtual bool CheckUserSaysOKToUpdate () const override
388 {
389 Options o;
390 if (o.GetCheckFileAssocsAtStartup ()) {
391 Led_StdDialogHelper_UpdateWin32FileAssocsDialog dlg (::AfxGetResourceHandle (), ::GetActiveWindow ());
392 dlg.fAppName = Led_SDK_TCHAROF ("LedLineIt!");
393 dlg.fTypeList = Led_SDK_TCHAROF (".txt,.bat");
394 dlg.fKeepChecking = true;
395 bool result = dlg.DoModal ();
396 o.SetCheckFileAssocsAtStartup (dlg.fKeepChecking);
397 return result;
398 }
399 else {
400 return false;
401 }
402 }
403 };
404 MyRegistrationHelper fileAssocHelper;
405 SDKString txtDocIcon = Win32UIFileAssociationInfo::kNoChange;
406 SDKString batDocIcon = Win32UIFileAssociationInfo::kNoChange;
407 fileAssocHelper.Add (Win32UIFileAssociationInfo (Led_SDK_TCHAROF (".txt"), Led_SDK_TCHAROF ("txtfile"), Led_SDK_TCHAROF ("Text Document"),
408 Win32UIFileAssociationInfo::kNoChange, Led_SDK_TCHAROF ("$EXE$ \"%1\"")));
409 fileAssocHelper.Add (Win32UIFileAssociationInfo (Led_SDK_TCHAROF (".bat"), Led_SDK_TCHAROF ("batfile"),
410 Led_SDK_TCHAROF ("MS-DOS Batch File"), Win32UIFileAssociationInfo::kNoChange,
411 Led_SDK_TCHAROF ("$EXE$ \"%1\""), Win32UIFileAssociationInfo::kNoChange));
412 fileAssocHelper.DoIt ();
413 }
414#endif
415
416 // Check to see if launched as OLE server
417 if (cmdInfo.m_bRunEmbedded || cmdInfo.m_bRunAutomated) {
418 // Register all OLE server (factories) as running. This enables the
419 // OLE libraries to create objects from other applications.
420 COleTemplateServer::RegisterAll ();
421
422 // Application was run with /Embedding or /Automation. Don't show the
423 // main window in this case.
424 return true;
425 }
426
427 AssertNotNull (m_pMainWnd);
428 m_pMainWnd->ShowWindow (m_nCmdShow); // show window NOW so will be up if any error processing cmdline args
429
430 // Dispatch commands specified on the command line
431 if (not ProcessShellCommand (cmdInfo)) {
432 return false;
433 }
434
435 return true;
436}
437
438void LedLineItApplication::WinHelpInternal ([[maybe_unused]] DWORD_PTR dwData, [[maybe_unused]] UINT nCmd)
439{
440 // get path of executable
441 TCHAR directoryName[_MAX_PATH];
442 Verify (::GetModuleFileName (m_hInstance, directoryName, _MAX_PATH));
443
444 {
445 LPTSTR lpszExt = _tcsrchr (directoryName, '\\');
446 ASSERT (lpszExt != NULL);
447 ASSERT (*lpszExt == '\\');
448 *(lpszExt + 1) = '\0';
449 }
450 Characters::CString::Cat (directoryName, Memory::NEltsOf (directoryName), _T ("LedLineItDocs\\"));
451
452 // wrap in try/catch, and display error if no open???
453 // (NB: we use .htm instead of .html cuz some old systems - I think maybe
454 // Win95 with only Netscape 2.0 installed - only have .htm registered - not
455 // .html).
456 (void)::ShellExecute (NULL, _T ("open"), _T ("index.htm"), NULL, directoryName, SW_SHOWNORMAL);
457}
458
459BOOL LedLineItApplication::PumpMessage ()
460{
461 try {
462 return inherited::PumpMessage ();
463 }
464 STD_EXCEPT_CATCHER (*this);
465 return true;
466}
467
468void LedLineItApplication::HandleMFCException (CException* /*e*/) noexcept
469{
470 // tmp hack for now...
471 HandleUnknownException ();
472}
473
474void LedLineItApplication::HandleBadAllocException () noexcept
475{
476 try {
477 CDialog errorDialog (kBadAllocExceptionOnCmdDialogID);
478 errorDialog.DoModal ();
479 }
480 catch (...) {
481 Led_BeepNotify ();
482 }
483}
484
485void LedLineItApplication::HandleBadUserInputException () noexcept
486{
487 try {
488#if qStroika_Foundation_Common_Platform_Windows
489 CDialog errorDialog (kBadUserInputExceptionOnCmdDialogID);
490 errorDialog.DoModal ();
491#else
492 HandleUnknownException ();
493#endif
494 }
495 catch (...) {
496 Led_BeepNotify ();
497 }
498}
499
500void LedLineItApplication::HandleUnknownException () noexcept
501{
502 try {
503 CDialog errorDialog (kUnknownExceptionOnCmdDialogID);
504 errorDialog.DoModal ();
505 }
506 catch (...) {
507 Led_BeepNotify ();
508 }
509}
510
511void LedLineItApplication::AddDocTemplateForString (const char* tmplStr, bool connectToServer)
512{
513 SimpleLedTemplate* pDocTemplate = new SimpleLedTemplate (tmplStr);
514 pDocTemplate->SetContainerInfo (IDR_CNTR_INPLACE);
515 pDocTemplate->SetServerInfo (IDR_SRVR_EMBEDDED, IDR_SRVR_INPLACE, RUNTIME_CLASS (LedLineItInPlaceFrame));
516 AddDocTemplate (pDocTemplate);
517 if (connectToServer) {
518 // Connect the COleTemplateServer to the document template.
519 // The COleTemplateServer creates new documents on behalf
520 // of requesting OLE containers by using information
521 // specified in the document template.
522 fOleTemplateServer.ConnectTemplate (clsid, pDocTemplate, true);
523 // Note: SDI applications register server objects only if /Embedding
524 // or /Automation is present on the command line.
525 }
526}
527
528void LedLineItApplication::OnAppAbout ()
529{
530 class MyAboutBox : public Led_StdDialogHelper_AboutBox {
531 private:
532 using inherited = Led_StdDialogHelper_AboutBox;
533
534 public:
535 MyAboutBox (HINSTANCE hInstance, HWND parentWnd)
536 : inherited (hInstance, parentWnd)
537 {
538 }
539
540 public:
541 virtual BOOL OnInitDialog () override
542 {
543 BOOL result = inherited::OnInitDialog ();
544
545 // Cuz of fact that dlog sizes specified in dlog units, and that doesn't work well for bitmaps
546 // we must resize our dlog on the fly based on pict resource size...
547 const CoordinateType kPictWidth = 437; // must agree with ACTUAL bitmap size
548 const CoordinateType kPictHeight = 273;
549 const CoordinateType kButHSluff = 17;
550 const CoordinateType kButVSluff = 19;
551 {
552 RECT windowRect;
553 ::GetWindowRect (GetHWND (), &windowRect);
554 // figure size of non-client area...
555 int ncWidth = 0;
556 int ncHeight = 0;
557 {
558 RECT clientRect;
559 ::GetClientRect (GetHWND (), &clientRect);
560 ncWidth = AsLedRect (windowRect).GetWidth () - AsLedRect (clientRect).GetWidth ();
561 ncHeight = AsLedRect (windowRect).GetHeight () - AsLedRect (clientRect).GetHeight ();
562 }
563 ::MoveWindow (GetHWND (), windowRect.left, windowRect.top, kPictWidth + ncWidth, kPictHeight + ncHeight, false);
564 }
565
566 // Place and fill in version information
567 {
568 HWND w = ::GetDlgItem (GetHWND (), kLedStdDlg_AboutBox_VersionFieldID);
569 AssertNotNull (w);
570 const int kVERWidth = 230;
571 ::MoveWindow (w, kPictWidth / 2 - kVERWidth / 2, 32, kVERWidth, 16, false);
572#if _UNICODE
573#define kUNICODE_NAME_ADORNER L" [UNICODE]"
574#else
575#define kUNICODE_NAME_ADORNER " [Internal UNICODE]"
576#endif
577 ::SetWindowText (w, _T (qLed_ShortVersionString) kUNICODE_NAME_ADORNER _T (" (") _T (__DATE__) _T (")"));
578 }
579
580 // Place hidden buttons which map to URLs
581 {
582 HWND w = ::GetDlgItem (GetHWND (), kLedStdDlg_AboutBox_InfoLedFieldID);
583 AssertNotNull (w);
584 ::MoveWindow (w, 15, 159, 142, 17, false);
585 w = ::GetDlgItem (GetHWND (), kLedStdDlg_AboutBox_LedWebPageFieldID);
586 AssertNotNull (w);
587 ::MoveWindow (w, 227, 159, 179, 17, false);
588 }
589
590 // Place OK button
591 {
592 HWND w = ::GetDlgItem (GetHWND (), IDOK);
593 AssertNotNull (w);
594 RECT tmp;
595 ::GetWindowRect (w, &tmp);
596 ::MoveWindow (w, kButHSluff, kPictHeight - AsLedRect (tmp).GetHeight () - kButVSluff, AsLedRect (tmp).GetWidth (),
597 AsLedRect (tmp).GetHeight (), false); // width/height we should presevere
598 }
599
600 ::SetWindowText (GetHWND (), _T ("About LedLineIt!"));
601
602 return (result);
603 }
604
605 public:
606 virtual void OnClickInInfoField () override
607 {
608 try {
609 Led_URLManager::Get ().Open ("mailto:info-led@sophists.com");
610 }
611 catch (...) {
612 // ignore for now - since errors here prent dialog from dismissing (on MacOSX)
613 }
614 inherited::OnClickInInfoField ();
615 }
616
617 virtual void OnClickInLedWebPageField () override
618 {
619 try {
620 Led_URLManager::Get ().Open (MakeSophistsAppNameVersionURL ("/Led/LedLineIt/", kAppName));
621 }
622 catch (...) {
623 // ignore for now - since errors here prent dialog from dismissing (on MacOSX)
624 }
625 inherited::OnClickInLedWebPageField ();
626 }
627 };
628 MyAboutBox dlg (m_hInstance, AfxGetMainWnd ()->m_hWnd);
629 dlg.DoModal ();
630}
631
632void LedLineItApplication::OnGotoLedLineItWebPageCommand ()
633{
634 Led_URLManager::Get ().Open (MakeSophistsAppNameVersionURL ("/Led/LedLineIt/", kAppName));
635}
636
637void LedLineItApplication::OnCheckForUpdatesWebPageCommand ()
638{
639 Led_URLManager::Get ().Open (MakeSophistsAppNameVersionURL ("/Led/CheckForUpdates.asp", kAppName));
640}
641
642void LedLineItApplication::OnGotoSophistsWebPageCommand ()
643{
644 Led_URLManager::Get ().Open (MakeSophistsAppNameVersionURL ("/", kAppName));
645}
646
647void LedLineItApplication::OnToggleAutoIndentOptionCommand ()
648{
649 Options o;
650 o.SetAutoIndent (not o.GetAutoIndent ());
651}
652
653void LedLineItApplication::OnToggleTreatTabAsIndentCharOptionUpdateCommandUI (CCmdUI* pCmdUI)
654{
655 RequireNotNull (pCmdUI);
656 pCmdUI->Enable ();
657 pCmdUI->SetCheck (Options{}.GetTreatTabAsIndentChar ());
658}
659
660void LedLineItApplication::OnToggleTreatTabAsIndentCharOptionCommand ()
661{
662 Options o;
663 o.SetTreatTabAsIndentChar (not o.GetTreatTabAsIndentChar ());
664}
665
666void LedLineItApplication::OnToggleAutoIndentOptionUpdateCommandUI (CCmdUI* pCmdUI)
667{
668 RequireNotNull (pCmdUI);
669 pCmdUI->Enable ();
670 pCmdUI->SetCheck (Options{}.GetAutoIndent ());
671}
672
673void LedLineItApplication::OnToggleSmartCutNPasteOptionCommand ()
674{
675 Options o;
676 o.SetSmartCutAndPaste (not o.GetSmartCutAndPaste ());
677 UpdateViewsForPrefsChange ();
678}
679
680void LedLineItApplication::OnToggleSmartCutNPasteOptionUpdateCommandUI (CCmdUI* pCmdUI)
681{
682 RequireNotNull (pCmdUI);
683 pCmdUI->Enable ();
684 pCmdUI->SetCheck (Options{}.GetSmartCutAndPaste ());
685}
686
687#if qSupportSyntaxColoring
688void LedLineItApplication::OnSyntaxColoringOptionCommand (UINT cmdNum)
689{
690 Options o;
691 switch (cmdNum) {
692 case kNoSyntaxColoringCmd:
693 o.SetSyntaxColoringOption (Options::eSyntaxColoringNone);
694 break;
695 case kCPlusPlusSyntaxColoringCmd:
696 o.SetSyntaxColoringOption (Options::eSyntaxColoringCPlusPlus);
697 break;
698 case kVBSyntaxColoringCmd:
699 o.SetSyntaxColoringOption (Options::eSyntaxColoringVB);
700 break;
701 default:
702 Assert (false);
703 }
704 UpdateViewsForPrefsChange ();
705}
706
707void LedLineItApplication::OnSyntaxColoringOptionUpdateCommandUI (CCmdUI* pCmdUI)
708{
709 RequireNotNull (pCmdUI);
710 pCmdUI->Enable ();
711 switch (pCmdUI->m_nID) {
712 case kNoSyntaxColoringCmd:
713 pCmdUI->SetCheck (Options{}.GetSyntaxColoringOption () == Options::eSyntaxColoringNone);
714 break;
715 case kCPlusPlusSyntaxColoringCmd:
716 pCmdUI->SetCheck (Options{}.GetSyntaxColoringOption () == Options::eSyntaxColoringCPlusPlus);
717 break;
718 case kVBSyntaxColoringCmd:
719 pCmdUI->SetCheck (Options{}.GetSyntaxColoringOption () == Options::eSyntaxColoringVB);
720 break;
721 default:
722 Assert (false);
723 }
724}
725#endif
726
727void LedLineItApplication::OnChooseDefaultFontCommand ()
728{
729 FontSpecification fsp = Options{}.GetDefaultNewDocFont ();
730
731 LOGFONT lf;
732 (void)::memset (&lf, 0, sizeof (lf));
733 {
734 Characters::CString::Copy (lf.lfFaceName, Memory::NEltsOf (lf.lfFaceName), fsp.GetFontNameSpecifier ().fName);
735 Assert (::_tcslen (lf.lfFaceName) < sizeof (lf.lfFaceName)); // cuz our cached entry - if valid - always short enuf...
736 }
737 lf.lfWeight = (fsp.GetStyle_Bold ()) ? FW_BOLD : FW_NORMAL;
738 lf.lfItalic = (fsp.GetStyle_Italic ());
739 lf.lfUnderline = (fsp.GetStyle_Underline ());
740 lf.lfStrikeOut = (fsp.GetStyle_Strikeout ());
741
742 lf.lfHeight = fsp.PeekAtTMHeight ();
743
744 FontDlgWithNoColorNoStyles dlog (&lf);
745 if (dlog.DoModal () == IDOK) {
746 Options{}.SetDefaultNewDocFont (FontSpecification (*dlog.m_cf.lpLogFont));
747 }
748}
749
750void LedLineItApplication::UpdateViewsForPrefsChange ()
751{
752 bool smartCutNPaste = Options{}.GetSmartCutAndPaste ();
753
754 // Update each open view
755 POSITION tp = GetFirstDocTemplatePosition ();
756 while (tp != NULL) {
757 CDocTemplate* t = GetNextDocTemplate (tp);
758 AssertNotNull (t);
759 POSITION dp = t->GetFirstDocPosition ();
760 while (dp != NULL) {
761 CDocument* doc = t->GetNextDoc (dp);
762 AssertNotNull (doc);
763 POSITION vp = doc->GetFirstViewPosition ();
764 while (vp != NULL) {
765 CView* v = doc->GetNextView (vp);
766 AssertNotNull (v);
767 LedLineItView* lv = dynamic_cast<LedLineItView*> (v);
768 if (lv != NULL) {
769 lv->SetSmartCutAndPasteMode (smartCutNPaste);
770#if qSupportSyntaxColoring
771 lv->ResetSyntaxColoringTable ();
772#endif
773 }
774 }
775 }
776 }
777}
778
779BOOL LedLineItApplication::ProcessShellCommand (CCommandLineInfo& rCmdInfo)
780{
781 try {
782/*
783 * SPR#0775. MFC doesnt' keep track of all the files requested to open. So walk the list of file arguments
784 * a SECOND TIME! PATHETIC!
785 */
786#if !qNo_argc_argv_MacrosSupported
787 if (rCmdInfo.m_nShellCommand == CCommandLineInfo::FileOpen) {
788 for (int i = 1; i < __argc; ++i) {
789 LPCTSTR pszParam = __targv[i];
790 if (pszParam[0] == '-' || pszParam[0] == '/') {
791 // skip flags
792 }
793 else {
794 try {
795 if (not m_pDocManager->OpenDocumentFile (pszParam)) {
796 return false;
797 }
798 }
799 catch (...) {
800 // see if file just doesn't exist. If so - then create NEW DOC with that file name (preset) - but not saved
801 HANDLE h = ::CreateFile (rCmdInfo.m_strFileName, 0, 0, NULL, OPEN_EXISTING, 0, NULL);
802 if (h == INVALID_HANDLE_VALUE) {
803 POSITION p = m_pDocManager->GetFirstDocTemplatePosition ();
804 CDocTemplate* pTemplate = (CDocTemplate*)m_pDocManager->GetNextDocTemplate (p);
805 AssertNotNull (pTemplate);
806 CDocument* newDoc = pTemplate->OpenDocumentFile (NULL); // new doc
807 if (newDoc != NULL) {
808 // Set path and title so if you just hit save - you are promted to save in the name you specified, but
809 // there are visual clues that this isn't the orig file
810 newDoc->SetPathName (pszParam, false);
811 newDoc->SetTitle (newDoc->GetTitle () + Led_SDK_TCHAROF (" {new}"));
812 continue; // with outer for loop - ignore exception
813 }
814 }
815 else {
816 ::CloseHandle (h);
817 }
818 throw;
819 }
820 }
821 }
822 return true;
823 }
824#endif
825 return inherited::ProcessShellCommand (rCmdInfo);
826 }
827 STD_EXCEPT_CATCHER (*this);
828 return false;
829}
#define AssertNotNull(p)
Definition Assertions.h:333
#define EnsureNotNull(p)
Definition Assertions.h:340
#define qStroika_Foundation_Debug_AssertionsChecked
The qStroika_Foundation_Debug_AssertionsChecked flag determines if assertions are checked and validat...
Definition Assertions.h:48
#define RequireNotNull(p)
Definition Assertions.h:347
#define Verify(c)
Definition Assertions.h:419
basic_string< SDKChar > SDKString
Definition SDKString.h:38