4#include "Stroika/Foundation/StroikaPreComp.h"
6DISABLE_COMPILER_MSC_WARNING_START (5054)
8DISABLE_COMPILER_MSC_WARNING_END (5054)
10#include "Stroika/Foundation/DataExchange/OptionsFile.h"
12#include "Stroika/Foundation/Execution/ModuleGetterSetter.h"
13#include "Stroika/Foundation/IO/FileSystem/FileUtils.h"
15#include "Stroika/Frameworks/Led/ChunkedArrayTextStore.h"
16#include "Stroika/Frameworks/Led/StdDialogs.h"
21#include "UserConfigCommands.h"
25#if qFunnyDisplayInDesignMode
26#include "Stroika/Frameworks/Led/HandySimple.h"
33using SearchParameters = LedItView::SearchParameters;
37 SearchParameters fSearchParameters{};
40 struct Options_Storage_IMPL_ {
41 Options_Storage_IMPL_ ()
42 : fOptionsFile_{L
"AppSettings"sv,
50 Led_tString* intoObj) ->
void { *intoObj = d.
As<
String> ().As<Led_tString> (); });
51 mapper.AddCommonType<vector<Led_tString>> ();
53 mapper.AddClass<SearchParameters> ({
54 {
"MatchString"sv, &SearchParameters::fMatchString},
55 {
"WrapSearch"sv, &SearchParameters::fWrapSearch},
56 {
"WholeWordSearch"sv, &SearchParameters::fWholeWordSearch},
57 {
"CaseSensativeSearch"sv, &SearchParameters::fCaseSensativeSearch},
58 {
"RecentMatchStrings"sv, &SearchParameters::fRecentFindStrings},
61 mapper.AddClass<Options_> ({
62 {
"Search-Parameters"sv, &Options_::fSearchParameters},
70 [] (
const String& moduleName,
const String& fileSuffix) {
71 static const auto kDefaultMapper_ = OptionsFile::mkFilenameMapper (L
"ActiveLedIt"sv);
72 filesystem::path fileName = kDefaultMapper_ (moduleName, fileSuffix);
73 filesystem::create_directories (fileName.parent_path ());
76 , fActualCurrentConfigData_{fOptionsFile_.Read<Options_> (Options_{})}
78 Set (fActualCurrentConfigData_);
82 return fActualCurrentConfigData_;
84 void Set (
const Options_& v)
86 fActualCurrentConfigData_ = v;
87 fOptionsFile_.Write (v);
92 Options_ fActualCurrentConfigData_;
98class My_CMDNUM_MAPPING :
public MFC_CommandNumberMapping {
102 AddAssociation (kFindAgainCmd, LedItView::kFindAgain_CmdID);
103 AddAssociation (kEnterFindStringCmd, LedItView::kEnterFindString_CmdID);
104 AddAssociation (kReplaceCmd, LedItView::kReplace_CmdID);
105 AddAssociation (kReplaceAgainCmd, LedItView::kReplaceAgain_CmdID);
106 AddAssociation (kSpellCheckCmd, LedItView::kSpellCheck_CmdID);
108 AddAssociation (kSelectWordCmd, LedItView::kSelectWord_CmdID);
109 AddAssociation (kSelectTextRowCmd, LedItView::kSelectTextRow_CmdID);
110 AddAssociation (kSelectParagraphCmd, LedItView::kSelectParagraph_CmdID);
111 AddAssociation (kSelectTableIntraCellAllCmd, LedItView::kSelectTableIntraCellAll_CmdID);
112 AddAssociation (kSelectTableCellCmd, LedItView::kSelectTableCell_CmdID);
113 AddAssociation (kSelectTableRowCmd, LedItView::kSelectTableRow_CmdID);
114 AddAssociation (kSelectTableColumnCmd, LedItView::kSelectTableColumn_CmdID);
115 AddAssociation (kSelectTableCmd, LedItView::kSelectTable_CmdID);
117 AddAssociation (kFontSize9Cmd, LedItView::kFontSize9_CmdID);
118 AddAssociation (kFontSize10Cmd, LedItView::kFontSize10_CmdID);
119 AddAssociation (kFontSize12Cmd, LedItView::kFontSize12_CmdID);
120 AddAssociation (kFontSize14Cmd, LedItView::kFontSize14_CmdID);
121 AddAssociation (kFontSize18Cmd, LedItView::kFontSize18_CmdID);
122 AddAssociation (kFontSize24Cmd, LedItView::kFontSize24_CmdID);
123 AddAssociation (kFontSize36Cmd, LedItView::kFontSize36_CmdID);
124 AddAssociation (kFontSize48Cmd, LedItView::kFontSize48_CmdID);
125 AddAssociation (kFontSize72Cmd, LedItView::kFontSize72_CmdID);
126#if qSupportOtherFontSizeDlg
127 AddAssociation (kFontSizeOtherCmd, LedItView::kFontSizeOther_CmdID);
129 AddAssociation (kFontSizeSmallerCmd, LedItView::kFontSizeSmaller_CmdID);
130 AddAssociation (kFontSizeLargerCmd, LedItView::kFontSizeLarger_CmdID);
132 AddAssociation (kBlackColorCmd, LedItView::kFontColorBlack_CmdID);
133 AddAssociation (kMaroonColorCmd, LedItView::kFontColorMaroon_CmdID);
134 AddAssociation (kGreenColorCmd, LedItView::kFontColorGreen_CmdID);
135 AddAssociation (kOliveColorCmd, LedItView::kFontColorOlive_CmdID);
136 AddAssociation (kNavyColorCmd, LedItView::kFontColorNavy_CmdID);
137 AddAssociation (kPurpleColorCmd, LedItView::kFontColorPurple_CmdID);
138 AddAssociation (kTealColorCmd, LedItView::kFontColorTeal_CmdID);
139 AddAssociation (kGrayColorCmd, LedItView::kFontColorGray_CmdID);
140 AddAssociation (kSilverColorCmd, LedItView::kFontColorSilver_CmdID);
141 AddAssociation (kRedColorCmd, LedItView::kFontColorRed_CmdID);
142 AddAssociation (kLimeColorCmd, LedItView::kFontColorLime_CmdID);
143 AddAssociation (kYellowColorCmd, LedItView::kFontColorYellow_CmdID);
144 AddAssociation (kBlueColorCmd, LedItView::kFontColorBlue_CmdID);
145 AddAssociation (kFuchsiaColorCmd, LedItView::kFontColorFuchsia_CmdID);
146 AddAssociation (kAquaColorCmd, LedItView::kFontColorAqua_CmdID);
147 AddAssociation (kWhiteColorCmd, LedItView::kFontColorWhite_CmdID);
148 AddAssociation (kFontColorOtherCmd, LedItView::kFontColorOther_CmdID);
150 AddAssociation (kJustifyLeftCmd, LedItView::kJustifyLeft_CmdID);
151 AddAssociation (kJustifyCenterCmd, LedItView::kJustifyCenter_CmdID);
152 AddAssociation (kJustifyRightCmd, LedItView::kJustifyRight_CmdID);
153 AddAssociation (kJustifyFullCmd, LedItView::kJustifyFull_CmdID);
155#if qSupportParagraphSpacingDlg
156 AddAssociation (kParagraphSpacingCmd, LedItView::kParagraphSpacingCommand_CmdID);
158#if qSupportParagraphIndentsDlg
159 AddAssociation (kParagraphIndentsCmd, LedItView::kParagraphIndentsCommand_CmdID);
162 AddAssociation (kListStyle_NoneCmd, LedItView::kListStyle_None_CmdID);
163 AddAssociation (kListStyle_BulletCmd, LedItView::kListStyle_Bullet_CmdID);
165 AddAssociation (kIncreaseIndentCmd, LedItView::kIncreaseIndent_CmdID);
166 AddAssociation (kDecreaseIndentCmd, LedItView::kDecreaseIndent_CmdID);
168 AddRangeAssociation (kBaseFontNameCmd, kLastFontNameCmd, LedItView::kFontMenuFirst_CmdID, LedItView::kFontMenuLast_CmdID);
170 AddAssociation (kFontStylePlainCmd, LedItView::kFontStylePlain_CmdID);
171 AddAssociation (kFontStyleBoldCmd, LedItView::kFontStyleBold_CmdID);
172 AddAssociation (kFontStyleItalicCmd, LedItView::kFontStyleItalic_CmdID);
173 AddAssociation (kFontStyleUnderlineCmd, LedItView::kFontStyleUnderline_CmdID);
174 AddAssociation (kFontStyleStrikeoutCmd, LedItView::kFontStyleStrikeout_CmdID);
175 AddAssociation (kSubScriptCmd, LedItView::kSubScriptCommand_CmdID);
176 AddAssociation (kSuperScriptCmd, LedItView::kSuperScriptCommand_CmdID);
177 AddAssociation (kChooseFontDialogCmd, LedItView::kChooseFontCommand_CmdID);
179 AddAssociation (kInsertTableCmd, LedItView::kInsertTable_CmdID);
180 AddAssociation (kInsertTableRowAboveCmd, LedItView::kInsertTableRowAbove_CmdID);
181 AddAssociation (kInsertTableRowBelowCmd, LedItView::kInsertTableRowBelow_CmdID);
182 AddAssociation (kInsertTableColBeforeCmd, LedItView::kInsertTableColBefore_CmdID);
183 AddAssociation (kInsertTableColAfterCmd, LedItView::kInsertTableColAfter_CmdID);
184 AddAssociation (kInsertURLCmd, LedItView::kInsertURL_CmdID);
185 AddAssociation (kInsertSymbolCmd, LedItView::kInsertSymbol_CmdID);
188 AddRangeAssociation (kFirstSelectedEmbeddingCmd, kLastSelectedEmbeddingCmd, LedItView::kFirstSelectedEmbedding_CmdID,
189 LedItView::kLastSelectedEmbedding_CmdID);
193 AddAssociation (kHideSelectionCmd, LedItView::kHideSelection_CmdID);
194 AddAssociation (kUnHideSelectionCmd, LedItView::kUnHideSelection_CmdID);
196 AddAssociation (kRemoveTableRowsCmd, LedItView::kRemoveTableRows_CmdID);
197 AddAssociation (kRemoveTableColumnsCmd, LedItView::kRemoveTableColumns_CmdID);
201 AddAssociation (kShowHideParagraphGlyphsCmd, LedItView::kShowHideParagraphGlyphs_CmdID);
202 AddAssociation (kShowHideTabGlyphsCmd, LedItView::kShowHideTabGlyphs_CmdID);
203 AddAssociation (kShowHideSpaceGlyphsCmd, LedItView::kShowHideSpaceGlyphs_CmdID);
207My_CMDNUM_MAPPING sMy_CMDNUM_MAPPING;
209struct ActiveLedIt_DialogSupport : TextInteractor::DialogSupport, WordProcessor::DialogSupport {
211 using CommandNumber = TextInteractor::DialogSupport::CommandNumber;
214 ActiveLedIt_DialogSupport ()
216 TextInteractor::SetDialogSupport (
this);
217 WordProcessor::SetDialogSupport (
this);
219 ~ActiveLedIt_DialogSupport ()
221 WordProcessor::SetDialogSupport (NULL);
222 TextInteractor::SetDialogSupport (NULL);
226#if qSupportStdFindDlg
228 virtual void DisplayFindDialog (Led_tString* findText,
const vector<Led_tString>& recentFindSuggestions,
bool* wrapSearch,
229 bool* wholeWordSearch,
bool* caseSensative,
bool* pressedOK)
override
231 Led_StdDialogHelper_FindDialog findDialog (::AfxGetResourceHandle (), ::GetActiveWindow ());
233 findDialog.fFindText = *findText;
234 findDialog.fRecentFindTextStrings = recentFindSuggestions;
235 findDialog.fWrapSearch = *wrapSearch;
236 findDialog.fWholeWordSearch = *wholeWordSearch;
237 findDialog.fCaseSensativeSearch = *caseSensative;
239 findDialog.DoModal ();
241 *findText = findDialog.fFindText;
242 *wrapSearch = findDialog.fWrapSearch;
243 *wholeWordSearch = findDialog.fWholeWordSearch;
244 *caseSensative = findDialog.fCaseSensativeSearch;
245 *pressedOK = findDialog.fPressedOK;
248#if qSupportStdReplaceDlg
250 virtual ReplaceButtonPressed DisplayReplaceDialog (Led_tString* findText,
const vector<Led_tString>& recentFindSuggestions,
251 Led_tString* replaceText,
bool* wrapSearch,
bool* wholeWordSearch,
bool* caseSensative)
override
253 Led_StdDialogHelper_ReplaceDialog replaceDialog (::AfxGetResourceHandle (), ::GetActiveWindow ());
255 replaceDialog.fFindText = *findText;
256 replaceDialog.fRecentFindTextStrings = recentFindSuggestions;
257 replaceDialog.fReplaceText = *replaceText;
258 replaceDialog.fWrapSearch = *wrapSearch;
259 replaceDialog.fWholeWordSearch = *wholeWordSearch;
260 replaceDialog.fCaseSensativeSearch = *caseSensative;
262 replaceDialog.DoModal ();
264 *findText = replaceDialog.fFindText;
265 *replaceText = replaceDialog.fReplaceText;
266 *wrapSearch = replaceDialog.fWrapSearch;
267 *wholeWordSearch = replaceDialog.fWholeWordSearch;
268 *caseSensative = replaceDialog.fCaseSensativeSearch;
270 switch (replaceDialog.fPressed) {
271 case Led_StdDialogHelper_ReplaceDialog::eCancel:
272 return eReplaceButton_Cancel;
273 case Led_StdDialogHelper_ReplaceDialog::eFind:
274 return eReplaceButton_Find;
275 case Led_StdDialogHelper_ReplaceDialog::eReplace:
276 return eReplaceButton_Replace;
277 case Led_StdDialogHelper_ReplaceDialog::eReplaceAll:
278 return eReplaceButton_ReplaceAll;
279 case Led_StdDialogHelper_ReplaceDialog::eReplaceAllInSelection:
280 return eReplaceButton_ReplaceAllInSelection;
283 return eReplaceButton_Cancel;
286#if qSupportStdSpellCheckDlg
288 virtual void DisplaySpellCheckDialog (SpellCheckDialogCallback& callback)
override
290 Led_StdDialogHelper_SpellCheckDialog::CallbackDelegator<SpellCheckDialogCallback> delegator{callback};
291#if qStroika_Foundation_Common_Platform_MacOS
292 Led_StdDialogHelper_SpellCheckDialog spellCheckDialog (delegator);
293#elif qStroika_Foundation_Common_Platform_Windows
294 Led_StdDialogHelper_SpellCheckDialog spellCheckDialog (delegator, ::AfxGetResourceHandle (), ::GetActiveWindow ());
295#elif qStroika_FeatureSupported_XWindows
296 Led_StdDialogHelper_SpellCheckDialog spellCheckDialog (delegator, GTK_WINDOW (LedItApplication::Get ().GetAppWindow ()));
299 spellCheckDialog.DoModal ();
305 virtual FontNameSpecifier CmdNumToFontName (CommandNumber cmdNum)
override
307 Require (cmdNum >= WordProcessor::kFontMenuFirst_CmdID);
308 Require (cmdNum <= WordProcessor::kFontMenuLast_CmdID);
309 return ::CmdNumToFontName (MFC_CommandNumberMapping::Get ().ReverseLookup (cmdNum)).c_str ();
311#if qSupportOtherFontSizeDlg
312 virtual DistanceType PickOtherFontHeight (DistanceType origHeight)
override
314#if qStroika_Foundation_Common_Platform_MacOS
315 Led_StdDialogHelper_OtherFontSizeDialog dlg;
316#elif qStroika_Foundation_Common_Platform_Windows
317 Led_StdDialogHelper_OtherFontSizeDialog dlg (::AfxGetResourceHandle (), ::GetActiveWindow ());
319 dlg.InitValues (origHeight);
320 if (dlg.DoModal ()) {
321 return dlg.fFontSize_Result;
328#if qSupportParagraphSpacingDlg
329 virtual bool PickNewParagraphLineSpacing (TWIPS* spaceBefore,
bool* spaceBeforeValid, TWIPS* spaceAfter,
bool* spaceAfterValid,
330 LineSpacing* lineSpacing,
bool* lineSpacingValid)
override
332#if qStroika_Foundation_Common_Platform_MacOS
333 Led_StdDialogHelper_ParagraphSpacingDialog dlg;
334#elif qStroika_Foundation_Common_Platform_Windows
335 Led_StdDialogHelper_ParagraphSpacingDialog dlg (::AfxGetResourceHandle (), ::GetActiveWindow ());
337 dlg.InitValues (*spaceBefore, *spaceBeforeValid, *spaceAfter, *spaceAfterValid, *lineSpacing, *lineSpacingValid);
339 if (dlg.DoModal ()) {
340 *spaceBeforeValid = dlg.fSpaceBefore_Valid;
341 if (*spaceBeforeValid) {
342 *spaceBefore = dlg.fSpaceBefore_Result;
344 *spaceAfterValid = dlg.fSpaceAfter_Valid;
345 if (*spaceAfterValid) {
346 *spaceAfter = dlg.fSpaceAfter_Result;
348 *lineSpacingValid = dlg.fLineSpacing_Valid;
349 if (*lineSpacingValid) {
350 *lineSpacing = dlg.fLineSpacing_Result;
359#if qSupportParagraphIndentsDlg
360 virtual bool PickNewParagraphMarginsAndFirstIndent (TWIPS* leftMargin,
bool* leftMarginValid, TWIPS* rightMargin,
361 bool* rightMarginValid, TWIPS* firstIndent,
bool* firstIndentValid)
override
363#if qStroika_Foundation_Common_Platform_MacOS
364 Led_StdDialogHelper_ParagraphIndentsDialog dlg;
365#elif qStroika_Foundation_Common_Platform_Windows
366 Led_StdDialogHelper_ParagraphIndentsDialog dlg (::AfxGetResourceHandle (), ::GetActiveWindow ());
368 dlg.InitValues (*leftMargin, *leftMarginValid, *rightMargin, *rightMarginValid, *firstIndent, *firstIndentValid);
369 if (dlg.DoModal ()) {
370 *leftMarginValid = dlg.fLeftMargin_Valid;
371 if (*leftMarginValid) {
372 *leftMargin = dlg.fLeftMargin_Result;
374 *rightMarginValid = dlg.fRightMargin_Valid;
375 if (*rightMarginValid) {
376 *rightMargin = dlg.fRightMargin_Result;
378 *firstIndentValid = dlg.fFirstIndent_Valid;
379 if (*firstIndentValid) {
380 *firstIndent = dlg.fFirstIndent_Result;
389 virtual void ShowSimpleEmbeddingInfoDialog (
const SDKString& embeddingTypeName)
override
392 Led_StdDialogHelper_UnknownEmbeddingInfoDialog infoDialog (::AfxGetResourceHandle (), ::GetActiveWindow ());
393 infoDialog.fEmbeddingTypeName = embeddingTypeName;
394 (void)infoDialog.DoModal ();
396 virtual bool ShowURLEmbeddingInfoDialog (
const SDKString& embeddingTypeName, SDKString* urlTitle, SDKString* urlValue)
override
398 Led_StdDialogHelper_URLXEmbeddingInfoDialog infoDialog (::AfxGetResourceHandle (), ::GetActiveWindow ());
399 infoDialog.fEmbeddingTypeName = embeddingTypeName;
400 infoDialog.fTitleText = *urlTitle;
401 infoDialog.fURLText = *urlValue;
402 if (infoDialog.DoModal ()) {
403 *urlTitle = infoDialog.fTitleText;
404 *urlValue = infoDialog.fURLText;
411 virtual bool ShowAddURLEmbeddingInfoDialog (SDKString* urlTitle, SDKString* urlValue)
override
413 Led_StdDialogHelper_AddURLXEmbeddingInfoDialog infoDialog (::AfxGetResourceHandle (), ::GetActiveWindow ());
414 infoDialog.fTitleText = *urlTitle;
415 infoDialog.fURLText = *urlValue;
416 if (infoDialog.DoModal ()) {
417 *urlTitle = infoDialog.fTitleText;
418 *urlValue = infoDialog.fURLText;
425#if qSupportAddNewTableDlg
426 bool AddNewTableDialog (
size_t* nRows,
size_t* nCols)
430 Led_StdDialogHelper_AddNewTableDialog infoDialog (::AfxGetResourceHandle (), ::GetActiveWindow ());
431 infoDialog.fRows = *nRows;
432 infoDialog.fColumns = *nCols;
433 if (infoDialog.DoModal ()) {
434 *nRows = infoDialog.fRows;
435 *nCols = infoDialog.fColumns;
443#if qSupportEditTablePropertiesDlg
444 virtual bool EditTablePropertiesDialog (TableSelectionPropertiesInfo* tableProperties)
override
448 using DLGTYPE = Led_StdDialogHelper_EditTablePropertiesDialog;
449#if qStroika_Foundation_Common_Platform_MacOS
451#elif qStroika_Foundation_Common_Platform_Windows
452 DLGTYPE infoDialog (::AfxGetResourceHandle (), ::GetActiveWindow ());
454 DLGTYPE::cvt<DLGTYPE::Info, TableSelectionPropertiesInfo> (&infoDialog.fInfo, *tableProperties);
455 if (infoDialog.DoModal ()) {
456 DLGTYPE::cvt<TableSelectionPropertiesInfo, DLGTYPE::Info> (tableProperties, infoDialog.fInfo);
465static ActiveLedIt_DialogSupport sActiveLedIt_DialogSupport;
467static BOOL CALLBACK _AfxAbortProc (HDC,
int)
469 _AFX_WIN_STATE* pWinState = _afxWinState;
471 while (!pWinState->m_bUserAbort && ::PeekMessage (&msg, NULL, NULL, NULL, PM_NOREMOVE)) {
472 if (!AfxGetThread ()->PumpMessage ())
475 return !pWinState->m_bUserAbort;
483LedItViewController::LedItViewController ()
485 , fCommandHandler (kMaxNumUndoLevels)
486 , fHidableTextDatabase ()
489 fHidableTextDatabase = make_shared<ColoredUniformHidableTextMarkerOwner> (fTextStore);
497DISABLE_COMPILER_MSC_WARNING_START (4407)
498BEGIN_MESSAGE_MAP (LedItView, LedItView::inherited)
499ON_WM_MOUSEACTIVATE ()
500ON_WM_INITMENUPOPUP ()
510ON_WM_LBUTTONDBLCLK ()
514ON_COMMAND (ID_FILE_PRINT, OnFilePrint)
515ON_COMMAND (ID_FILE_PRINT_SETUP, OnFilePrintSetup)
516ON_COMMAND (ID_HELP_FINDER, OnBrowseHelpCommand)
517ON_COMMAND (kCheckForUpdatesWebPageCmdID, OnCheckForUpdatesWebPageCommand)
518ON_COMMAND (ID_APP_ABOUT, OnAboutBoxCommand)
519ON_COMMAND (kPasteFormatTextCmdID, OnPasteAsTextCommand)
520ON_UPDATE_COMMAND_UI (kPasteFormatTextCmdID, OnUpdatePasteAsTextCommand)
521ON_COMMAND_RANGE (kFirstOLEUserCmdCmdID, kLastOLEUserCmdCmdID, OnOLEUserCommand)
522ON_UPDATE_COMMAND_UI_RANGE (kFirstOLEUserCmdCmdID, kLastOLEUserCmdCmdID, OnUpdateOLEUserCommand)
524DISABLE_COMPILER_MSC_WARNING_END (4407)
526LedItView::LedItView ()
529 , fSupportContextMenu (true)
530 , fHideDisabledContextMenuItems (true)
531 , fWrapToWindow (true)
533 , fEnableAutoChangesBackgroundColor (true)
534 , fInDrawMetaFileMode (false)
536 SetScrollBarType (v, eScrollBarAsNeeded);
537 SetScrollBarType (h, eScrollBarAsNeeded);
538 if (qFunnyDisplayInDesignMode) {
539 SetUseBitmapScrollingOptimization (
false);
541 SetUseSecondaryHilight (
true);
542 const TWIPS kLedItViewTopMargin = TWIPS (120);
543 const TWIPS kLedItViewBottomMargin = TWIPS (0);
544 const TWIPS kLedItViewLHSMargin = TWIPS (150);
545 const TWIPS kLedItViewRHSMargin = TWIPS (0);
546 SetDefaultWindowMargins (TWIPS_Rect (kLedItViewTopMargin, kLedItViewLHSMargin, kLedItViewBottomMargin - kLedItViewTopMargin,
547 kLedItViewRHSMargin - kLedItViewLHSMargin));
550LedItView::~LedItView ()
552 SetController (NULL);
555void LedItView::SetController (LedItViewController* controller)
557 if (fController != NULL) {
558 SetHidableTextDatabase (NULL);
559 SetCommandHandler (NULL);
560 SpecifyTextStore (NULL);
562 fController = controller;
563 if (fController != NULL) {
564 SpecifyTextStore (&fController->fTextStore);
565 SetCommandHandler (&fController->fCommandHandler);
566 SetHidableTextDatabase (fController->fHidableTextDatabase);
570void LedItView::SetSupportContextMenu (
bool allowContextMenu)
572 fSupportContextMenu = allowContextMenu;
575void LedItView::SetHideDisabledContextMenuItems (
bool hideDisabledContextMenuItems)
577 fHideDisabledContextMenuItems = hideDisabledContextMenuItems;
580void LedItView::SetWrapToWindow (
bool wrapToWindow)
582 if (fWrapToWindow != wrapToWindow) {
583 fWrapToWindow = wrapToWindow;
584 InvalidateAllCaches ();
589void LedItView::SetMaxLength (
long maxLength)
591 fMaxLength = maxLength;
594void LedItView::GetLayoutMargins (RowReference row, CoordinateType* lhs, CoordinateType* rhs)
const
596 if (GetWrapToWindow ()) {
600 CoordinateType l = 0;
601 CoordinateType r = 0;
602 inherited::GetLayoutMargins (row, &l, &r);
603 r = max (
static_cast<CoordinateType
> (GetWindowRect ().GetWidth ()), l + 1);
613 inherited::GetLayoutMargins (row, lhs, rhs);
617void LedItView::SetWindowRect (
const Led_Rect& windowRect)
620 Led_Rect oldWindowRect = GetWindowRect ();
621 if (windowRect != oldWindowRect) {
622 WordWrappedTextImager::SetWindowRect (windowRect);
623 if (GetWrapToWindow () and windowRect.GetSize () != oldWindowRect.GetSize ()) {
624 InvalidateAllCaches ();
629DistanceType LedItView::CalculateFarthestRightMarginInWindow ()
const
632 return GetWindowRect ().GetWidth ();
635 return inherited::CalculateFarthestRightMarginInWindow () / 20;
639void LedItView::PostNcDestroy ()
643int LedItView::OnMouseActivate (CWnd* pDesktopWnd, UINT nHitTest, UINT message)
645 if (fController != NULL) {
646 fController->ForceUIActive ();
648 return inherited::OnMouseActivate (pDesktopWnd, nHitTest, message);
651void LedItView::OnInitMenuPopup (CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
658 state.m_pSubMenu = NULL;
659 state.m_pMenu = pPopupMenu;
660 Assert (state.m_pOther == NULL);
661 Assert (state.m_pParentMenu == NULL);
664 state.m_nIndexMax = pPopupMenu->GetMenuItemCount ();
665 for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax; ++state.m_nIndex) {
666 state.m_nID = pPopupMenu->GetMenuItemID (state.m_nIndex);
667 if (state.m_nID != 0) {
668 Assert (state.m_pOther == NULL);
669 Assert (state.m_pMenu != NULL);
670 state.DoUpdate (
this,
true);
675 if (GetHideDisabledContextMenuItems ()) {
676 bool prevItemSep =
true;
677 for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax;) {
678 state.m_nID = pPopupMenu->GetMenuItemID (state.m_nIndex);
679 if (state.m_nID == 0 and prevItemSep) {
680 pPopupMenu->RemoveMenu (state.m_nIndex, MF_BYPOSITION);
684 if (state.m_nID != 0) {
686 memset (&mInfo, 0,
sizeof (mInfo));
687 mInfo.cbSize =
sizeof (mInfo);
688 mInfo.fMask = MIIM_STATE;
689 Verify (::GetMenuItemInfo (pPopupMenu->GetSafeHmenu (), state.m_nIndex,
true, &mInfo));
690 if (mInfo.fState & MFS_DISABLED) {
691 pPopupMenu->RemoveMenu (state.m_nIndex, MF_BYPOSITION);
696 prevItemSep = bool (state.m_nID == 0);
701 pPopupMenu->RemoveMenu (state.m_nIndexMax - 1, MF_BYPOSITION);
705 inherited::OnInitMenuPopup (pPopupMenu, nIndex, bSysMenu);
708void LedItView::OnContextMenu (CWnd* , CPoint pt)
710 if (GetSupportContextMenu ()) {
713 if (menu.Attach (fController->GenerateContextMenu ())) {
714 menu.TrackPopupMenu (TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y,
this);
718extern short AFXAPI _AfxShiftState ();
720void LedItView::OnSysKeyDown (UINT nChar, UINT nRepCnt, UINT nFlags)
722 if (fController != NULL) {
723 USHORT shortChar =
static_cast<USHORT
> (nChar);
724 fController->FireKeyDown (&shortChar, _AfxShiftState ());
726 inherited::OnSysKeyDown (nChar, nRepCnt, nFlags);
729void LedItView::OnSysKeyUp (UINT nChar, UINT nRepCnt, UINT nFlags)
731 if (fController != NULL) {
732 USHORT shortChar =
static_cast<USHORT
> (nChar);
733 fController->FireKeyUp (&shortChar, _AfxShiftState ());
735 inherited::OnSysKeyUp (nChar, nRepCnt, nFlags);
738void LedItView::OnKeyDown (UINT nChar, UINT nRepCnt, UINT nFlags)
740 if (fController != NULL) {
741 USHORT shortChar =
static_cast<USHORT
> (nChar);
742 fController->FireKeyDown (&shortChar, _AfxShiftState ());
744 inherited::OnKeyDown (nChar, nRepCnt, nFlags);
747void LedItView::OnKeyUp (UINT nChar, UINT nRepCnt, UINT nFlags)
749 if (fController != NULL) {
750 USHORT shortChar =
static_cast<USHORT
> (nChar);
751 fController->FireKeyUp (&shortChar, _AfxShiftState ());
753 inherited::OnKeyUp (nChar, nRepCnt, nFlags);
756void LedItView::OnTypedNormalCharacter (Led_tChar theChar,
bool optionPressed,
bool shiftPressed,
bool commandPressed,
bool controlPressed,
bool altKeyPressed)
758 if (fController != NULL) {
759 USHORT shortChar = theChar;
760 fController->FireKeyPress (&shortChar);
762 inherited::OnTypedNormalCharacter (theChar, optionPressed, shiftPressed, commandPressed, controlPressed, altKeyPressed);
765void LedItView::OnLButtonDown (UINT nFlags, CPoint oPoint)
767 if (fController != NULL) {
768 fController->FireMouseDown (LEFT_BUTTON, _AfxShiftState (), oPoint.x, oPoint.y);
770 inherited::OnLButtonDown (nFlags, oPoint);
773void LedItView::OnLButtonUp (UINT nFlags, CPoint oPoint)
775 if (fController != NULL) {
776 fController->FireMouseUp (LEFT_BUTTON, _AfxShiftState (), oPoint.x, oPoint.y);
777 if (GetCurClickCount () == 1) {
778 fController->FireClick ();
781 inherited::OnLButtonUp (nFlags, oPoint);
784void LedItView::OnLButtonDblClk (UINT nFlags, CPoint oPoint)
786 if (fController != NULL) {
787 fController->FireDblClick ();
789 inherited::OnLButtonDblClk (nFlags, oPoint);
792void LedItView::OnRButtonDown (UINT nFlags, CPoint oPoint)
794 if (fController != NULL) {
795 fController->FireMouseDown (RIGHT_BUTTON, _AfxShiftState (), oPoint.x, oPoint.y);
797 inherited::OnRButtonDown (nFlags, oPoint);
800void LedItView::OnRButtonUp (UINT nFlags, CPoint oPoint)
802 if (fController != NULL) {
803 fController->FireMouseUp (RIGHT_BUTTON, _AfxShiftState (), oPoint.x, oPoint.y);
805 inherited::OnRButtonUp (nFlags, oPoint);
808void LedItView::OnMouseMove (UINT nFlags, CPoint oPoint)
810 if (fController != NULL) {
811 fController->FireMouseMove (LEFT_BUTTON, _AfxShiftState (), oPoint.x, oPoint.y);
813 inherited::OnMouseMove (nFlags, oPoint);
816void LedItView::OnPasteAsTextCommand ()
818 InteractiveModeUpdater iuMode (*
this);
819 BreakInGroupedCommands ();
821 if (OnPasteCommand_Before ()) {
823 UndoableContextHelper undoContext (*
this, Led_SDK_TCHAROF (
"Paste Text"),
false);
825 OnPasteCommand_PasteFlavor_Specific (kTEXTClipFormat);
827 undoContext.CommandComplete ();
830 OnPasteCommand_After ();
833 OnPasteCommand_After ();
835 BreakInGroupedCommands ();
838void LedItView::OnUpdatePasteAsTextCommand (CCmdUI* pCmdUI)
840 OnUpdatePasteCommand (Led_MFC_TmpCmdUpdater (pCmdUI));
843void LedItView::OnOLEUserCommand (UINT nID)
845 if (fController != NULL) {
846 fController->FireUserCommand (UserCommandNameNumberRegistry::Get ().Lookup (nID));
850void LedItView::OnUpdateOLEUserCommand (CCmdUI* pCmdUI)
852 if (fController != NULL) {
853 VARIANT_BOOL enabled =
true;
854 VARIANT_BOOL checked =
false;
857 fController->FireUpdateUserCommand (UserCommandNameNumberRegistry::Get ().Lookup (pCmdUI->m_nID), &enabled, &checked, &name);
858 pCmdUI->Enable (enabled);
859 pCmdUI->SetCheck (checked);
860 if (not name.empty ()) {
866LedItView::SearchParameters LedItView::GetSearchParameters ()
const
868 return sOptions_.Get ().fSearchParameters;
871void LedItView::SetSearchParameters (
const SearchParameters& sp)
873 sOptions_.Update ([=] (Options_ d) {
874 d.fSearchParameters = sp;
879void LedItView::SetSelection (
size_t start,
size_t end)
881 bool changed = start != GetSelectionStart () or end != GetSelectionEnd ();
882 inherited::SetSelection (start, end);
883 if (changed and fController != NULL) {
884 fController->FireOLEEvent (DISPID_SelChange);
888void LedItView::AboutToUpdateText (
const UpdateInfo& updateInfo)
890 if (GetMaxLength () != -1) {
891 long textAdded =
static_cast<long> (updateInfo.fTextLength) -
static_cast<long> (updateInfo.fReplaceTo - updateInfo.fReplaceFrom);
892 if (textAdded +
static_cast<long> (GetLength ()) > GetMaxLength ()) {
897 inherited::AboutToUpdateText (updateInfo);
900void LedItView::EraseBackground (Tablet* tablet,
const Led_Rect& subsetToDraw,
bool printing)
902 if (fEnableAutoChangesBackgroundColor) {
903 inherited::EraseBackground (tablet, subsetToDraw, printing);
906 TextImager::EraseBackground (tablet, subsetToDraw, printing);
909#if qFunnyDisplayInDesignMode
910 if (fController->IsInDesignMode ()) {
911 Led_tString message = LED_TCHAR_OF (
"Design Mode");
912 static WaterMarkHelper<> waterMarkerImager (message);
913 waterMarkerImager.SetWatermarkColor (Color::kYellow);
914 Led_Rect designModeRect = Led_Rect (0, 0, 20, 150);
915 Led_Rect wr = GetWindowRect ();
917 if (
static_cast<DistanceType
> (designModeRect.bottom) > wr.GetHeight ()) {
918 designModeRect.bottom = wr.GetHeight ();
920 if (
static_cast<DistanceType
> (designModeRect.right) > wr.GetWidth ()) {
921 designModeRect.right = wr.GetWidth ();
923 designModeRect = CenterRectInRect (designModeRect, wr);
924 DistanceType h = designModeRect.GetHeight ();
925 designModeRect.bottom = wr.bottom;
926 designModeRect.top = designModeRect.bottom - h;
928 waterMarkerImager.DrawWatermark (tablet, designModeRect, subsetToDraw);
929 if (fController->DrawExtraDesignModeBorder ()) {
930 Color useBorderColor = Color::kBlack;
932 Color defBackgrndColor = Led_GetTextBackgroundColor ();
933 if (GetHWND () != NULL) {
934 DWORD dwStyle = GetStyle ();
935 if (((dwStyle & WS_DISABLED) or (dwStyle & ES_READONLY)) and (not printing)) {
936 defBackgrndColor =
Color (::GetSysColor (COLOR_BTNFACE));
940 useBorderColor =
Color (~defBackgrndColor.GetRed (), ~defBackgrndColor.GetGreen (), ~defBackgrndColor.GetBlue ());
943 Led_Rect wmr = tablet->CvtFromTWIPS (GetDefaultWindowMargins ());
945 cr.top -= wmr.GetTop ();
946 cr.left -= wmr.GetLeft ();
947 cr.bottom += wmr.GetBottom ();
948 cr.right += wmr.GetRight ();
949 tablet->FrameRectangle (cr, useBorderColor, 1);
955long LedItView::OLE_FindReplace (
long searchFrom,
const Led_tString& findText,
const Led_tString& replaceText, BOOL wrapSearch,
956 BOOL wholeWordSearch, BOOL caseSensativeSearch)
958 TextStore::SearchParameters parameters;
959 parameters.fMatchString = findText;
960 parameters.fWrapSearch = !!wrapSearch;
961 parameters.fWholeWordSearch = !!wholeWordSearch;
962 parameters.fCaseSensativeSearch = !!caseSensativeSearch;
964 size_t whereTo = GetTextStore ().Find (parameters, searchFrom);
965 if (whereTo != kBadIndex) {
966 size_t replaceStart = whereTo;
967 size_t replaceEnd = whereTo + parameters.fMatchString.length ();
968 TextInteractor::UndoableContextHelper undoContext (*
this, TextInteractor::GetCommandNames ().fReplaceCommandName, replaceStart,
969 replaceEnd, GetSelectionStart (), GetSelectionEnd (),
false);
971 InteractiveReplace_ (undoContext.GetUndoRegionStart (), undoContext.GetUndoRegionEnd (), replaceText.c_str (), replaceText.length ());
973 undoContext.CommandComplete ();
974 return static_cast<long> (whereTo + replaceText.length ());
980void LedItView::UpdateScrollBars ()
982 if (fInDrawMetaFileMode) {
985 inherited::UpdateScrollBars ();
988void LedItView::OnBrowseHelpCommand ()
990 if (fController != NULL) {
991 fController->OnBrowseHelpCommand ();
995void LedItView::OnCheckForUpdatesWebPageCommand ()
997 Led_URLManager::Get ().Open (MakeSophistsAppNameVersionURL (
"/Led/CheckForUpdates.asp", kAppName,
""));
1000void LedItView::OnAboutBoxCommand ()
1002 if (fController != NULL) {
1003 fController->OnAboutBoxCommand ();
1007void LedItView::OnFilePrintOnce ()
1009 DoPrintHelper (
false);
1012void LedItView::OnFilePrint ()
1014 DoPrintHelper (
true);
1017void LedItView::OnFilePrintSetup ()
1019 CPrintDialog pd (TRUE);
1020 AfxGetApp ()->DoPrintDialog (&pd);
1033void LedItView::DoPrintHelper (
bool showPrintDlg)
1035 class CPrintingDialog :
public CDialog {
1038 IDD = AFX_IDD_PRINTDLG
1040 CPrintingDialog (CWnd* pParent)
1042 Create (CPrintingDialog::IDD, pParent);
1043 _afxWinState->m_bUserAbort = FALSE;
1045 virtual ~CPrintingDialog ()
1048 virtual BOOL OnInitDialog ()
1050 SetWindowText (AfxGetAppName ());
1052 return CDialog::OnInitDialog ();
1054 virtual void OnCancel ()
1056 _afxWinState->m_bUserAbort = TRUE;
1057 CDialog::OnCancel ();
1062 CPrintInfo printInfo;
1063 ASSERT (printInfo.m_pPD != NULL);
1065 if (not showPrintDlg) {
1066 printInfo.m_bDirect =
true;
1067 printInfo.m_dwFlags &= ~PRINTFLAG_PROMPTUSER;
1070 if (OnPreparePrinting (&printInfo)) {
1072 ASSERT (printInfo.m_pPD->m_pd.hDC != NULL);
1076 if (printInfo.m_pPD->m_pd.Flags & PD_PRINTTOFILE && !printInfo.m_bDocObject) {
1078 CString strDef (MAKEINTRESOURCE (AFX_IDS_PRINTDEFAULTEXT));
1079 CString strPrintDef (MAKEINTRESOURCE (AFX_IDS_PRINTDEFAULT));
1080 CString strFilter (MAKEINTRESOURCE (AFX_IDS_PRINTFILTER));
1081 CString strCaption (MAKEINTRESOURCE (AFX_IDS_PRINTCAPTION));
1082 CFileDialog dlg (FALSE, strDef, strPrintDef, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, strFilter);
1083 dlg.m_ofn.lpstrTitle = strCaption;
1085 if (dlg.DoModal () != IDOK)
1089 strOutput = dlg.GetPathName ();
1093 CString strTitle =
"ActiveLedIt! document";
1095 memset (&docInfo, 0,
sizeof (DOCINFO));
1096 docInfo.cbSize =
sizeof (DOCINFO);
1097 docInfo.lpszDocName = strTitle;
1098 CString strPortName;
1100 if (strOutput.IsEmpty ()) {
1101 docInfo.lpszOutput = NULL;
1102 strPortName = printInfo.m_pPD->GetPortName ();
1103 nFormatID = AFX_IDS_PRINTONPORT;
1106 docInfo.lpszOutput = strOutput;
1107 extern UINT AFXAPI AfxGetFileTitle (LPCTSTR lpszPathName, LPTSTR lpszTitle, UINT nMax);
1108 AfxGetFileTitle (strOutput, strPortName.GetBuffer (_MAX_PATH), _MAX_PATH);
1109 nFormatID = AFX_IDS_PRINTTOFILE;
1114 if (!printInfo.m_bDocObject) {
1115 dcPrint.Attach (printInfo.m_pPD->m_pd.hDC);
1116 dcPrint.m_bPrinting = TRUE;
1118 OnBeginPrinting (&dcPrint, &printInfo);
1120 if (!printInfo.m_bDocObject) {
1121 dcPrint.SetAbortProc (_AfxAbortProc);
1125 HWND mainWnd = AfxGetMainWnd ()->m_hWnd;
1126 ::EnableWindow (mainWnd, FALSE);
1127 CPrintingDialog dlgPrintStatus (
this);
1128 BOOL bError = FALSE;
1131 dlgPrintStatus.SetDlgItemText (AFX_IDC_PRINT_DOCNAME, strTitle);
1132 dlgPrintStatus.SetDlgItemText (AFX_IDC_PRINT_PRINTERNAME, printInfo.m_pPD->GetDeviceName ());
1133 AfxFormatString1 (strTemp, nFormatID, strPortName);
1134 dlgPrintStatus.SetDlgItemText (AFX_IDC_PRINT_PORTNAME, strTemp);
1135 dlgPrintStatus.ShowWindow (SW_SHOW);
1136 dlgPrintStatus.UpdateWindow ();
1139 if (!printInfo.m_bDocObject && dcPrint.StartDoc (&docInfo) == SP_ERROR) {
1141 ::EnableWindow (mainWnd,
true);
1144 OnEndPrinting (&dcPrint, &printInfo);
1145 dlgPrintStatus.DestroyWindow ();
1147 AfxMessageBox (AFX_IDP_FAILED_TO_START_PRINT);
1152 UINT nEndPage = printInfo.GetToPage ();
1153 UINT nStartPage = printInfo.GetFromPage ();
1155 if (nEndPage < printInfo.GetMinPage ())
1156 nEndPage = printInfo.GetMinPage ();
1157 if (nEndPage > printInfo.GetMaxPage ())
1158 nEndPage = printInfo.GetMaxPage ();
1160 if (nStartPage < printInfo.GetMinPage ())
1161 nStartPage = printInfo.GetMinPage ();
1162 if (nStartPage > printInfo.GetMaxPage ())
1163 nStartPage = printInfo.GetMaxPage ();
1165 int nStep = (nEndPage >= nStartPage) ? 1 : -1;
1166 nEndPage = (nEndPage == 0xffff) ? 0xffff : nEndPage + nStep;
1168 VERIFY (strTemp.LoadString (AFX_IDS_PRINTPAGENUM));
1173 if (printInfo.m_bDocObject) {
1174 OnPrepareDC (&dcPrint, &printInfo);
1175 OnPrint (&dcPrint, &printInfo);
1179 for (printInfo.m_nCurPage = nStartPage; printInfo.m_nCurPage != nEndPage; printInfo.m_nCurPage += nStep) {
1180 OnPrepareDC (&dcPrint, &printInfo);
1183 if (!printInfo.m_bContinuePrinting)
1188 wsprintf (szBuf, strTemp, printInfo.m_nCurPage);
1189 dlgPrintStatus.SetDlgItemText (AFX_IDC_PRINT_PAGENUM, szBuf);
1192 printInfo.m_rectDraw.SetRect (0, 0, dcPrint.GetDeviceCaps (HORZRES), dcPrint.GetDeviceCaps (VERTRES));
1193 dcPrint.DPtoLP (&printInfo.m_rectDraw);
1196 if (dcPrint.StartPage () < 0) {
1203 BOOL bMarked4 =
false;
1205 DISABLE_COMPILER_MSC_WARNING_START (4996)
1206 DWORD dwVersion = ::GetVersion ();
1207 BOOL bWin4 = (BYTE)dwVersion >= 4;
1210 bMarked4 = (GetProcessVersion (0) >= 0x00040000);
1212 DISABLE_COMPILER_MSC_WARNING_END (4996)
1215 OnPrepareDC (&dcPrint, &printInfo);
1217 ASSERT (printInfo.m_bContinuePrinting);
1220 OnPrint (&dcPrint, &printInfo);
1221 if (dcPrint.EndPage () < 0 || !_AfxAbortProc (dcPrint.m_hDC, 0)) {
1230 if (!printInfo.m_bDocObject) {
1231 dcPrint.AbortDoc ();
1234 ::EnableWindow (mainWnd,
true);
1236 OnEndPrinting (&dcPrint, &printInfo);
1241 if (!printInfo.m_bDocObject) {
1245 dcPrint.AbortDoc ();
1248 ::EnableWindow (mainWnd,
true);
1250 OnEndPrinting (&dcPrint, &printInfo);
1251 dlgPrintStatus.DestroyWindow ();
1258void LedItView::AssertValid ()
const
1260 inherited::AssertValid ();
1263void LedItView::Dump (CDumpContext& dc)
const
1265 inherited::Dump (dc);
#define RequireNotNull(p)
String is like std::u32string, except it is much easier to use, often much more space efficient,...
nonvirtual SDKString AsSDKString() const
Set<T> is a container of T, where once an item is added, additionally adds () do nothing.
ObjectVariantMapper can be used to map C++ types to and from variant-union types, which can be transp...
nonvirtual void Add(const TypeMappingDetails &s)
static const ModuleDataUpgraderType kDefaultUpgrader
Simple variant-value (case variant union) object, with (variant) basic types analogous to a value in ...
Helper to define synchronized, lazy constructed, module initialization (intended to work with DataExc...