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