Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
MFC.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Frameworks_Led_Platform_MFC_h_
5#define _Stroika_Frameworks_Led_Platform_MFC_h_ 1
6
7#include "Stroika/Frameworks/StroikaPreComp.h"
8
9/*
10@MODULE: Led_MFC
11@DESCRIPTION:
12 <p>Led MFC specific wrappers.</p>
13 <p>Note that since MFC provides no abstract base classes for implementing editor-like
14 behavior, Led cannot subclass from CEdit or CEditView.</p>
15 <p>Also - for some purposes, it would be better to inherit from CWnd. And for others, better to inherit
16 from CView. Versions of Led prior to Led 2.3 inherited from CView.</p>
17 <p>Now - through the magic of templates - Led supports (almost) any MFC base class (at least
18 CView and CWnd) for a Led-based editor, so long as it supports at least the functionality of CWnd/CView.</p>
19 <p>The current Led sample applications (LedIt! and LedLineIt! all use Led inheriting from
20 a CView, and that is necessary to get the OLE/embedding funcitonality built in. But Led has also been
21 tested as a replacemnt edit control inheriting from CWnd (@LEC).</p>
22 */
23
24static_assert (qStroika_HasComponent_ATLMFC,
25 "Error: Stroika::Framework::Led::Platform MFC code requires the ATLMFC feature to be set true");
26
27DISABLE_COMPILER_MSC_WARNING_START (4459)
28DISABLE_COMPILER_MSC_WARNING_START (5054)
29#include <afxole.h>
30DISABLE_COMPILER_MSC_WARNING_END (5054)
31DISABLE_COMPILER_MSC_WARNING_END (4459)
32
33#include <afxwin.h>
34#include <oleidl.h>
35
36#include "Stroika/Frameworks/Led/IdleManager.h"
37#include "Stroika/Frameworks/Led/Platform/Windows.h"
38#include "Stroika/Frameworks/Led/TextInteractor.h"
39
40namespace Stroika::Frameworks::Led::Platform {
41
42/*
43 **************** Windows Specific configuration variables **************
44 */
45
46/*
47 @CONFIGVAR: qLedAssertsDefaultToMFCAsserts
48 @DESCRIPTION: <p>By default when using MFC, make the Led asserts fall-thru into the default
49 MFC assertion code. Some customers have indicated they prefer this (spr#0424).</p>
50 <p>Originally I made this default to TRUE, as the SPR requested. But I personally
51 find the MFC Assert stuff a major pain in the donkey. Whenever you get an assert
52 due to a display bug, it brings up a dialog, and dimissing that alert triggers
53 (due to extra redisplay) extra re-enters into the same code which had the assert
54 doing displays.</p>
55 <p>Since it was requested, I'll continue to make it easy for others to turn this on.
56 But I leave it off by default.</p>
57 */
58#ifndef qLedAssertsDefaultToMFCAsserts
59#define qLedAssertsDefaultToMFCAsserts 0
60#endif
61
62/*
63 @CONFIGVAR: qSupportDrawTextGetTextExtent
64 @DESCRIPTION:
65 <p>Turn OFF by default (because requires including SimpleTextStore and SimpleTextImager and WordWrappedTextImager
66 in your projects - which you may not want to do).
67 See @'Led_DrawText' and @'Led_GetTextExtent'.</p>
68 */
69#ifndef qSupportDrawTextGetTextExtent
70#define qSupportDrawTextGetTextExtent 0
71#endif
72
73/*
74 @CONFIGVAR: qProvideLedStubsForOLEACCDLL
75 @DESCRIPTION:
76 <p>Windows 98 has a problem with OLEACC.DLL. Though it is <em>supposed</em> to be included with Win98-
77 people somehow frequently come up with systems that don't have it, or have it corrupted.
78 (for example, see MSFT knowledge base article
79 http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B810684
80 )</p>
81 <p>As of version 7 of MFC (with Visual Studio.Net), Microsoft added virtual functions that refer to
82 this DLL. The virtual function CWnd::EnsureStdObj calls CreateStdAccessibleObject (from OLEACC.DLL),
83 the virtual function CWnd::CreateAccessibleProxy calls LresultFromObject (from OLEACC.DLL),
84 and CWnd::GetAccessibleChild () which calls AccessibleObjectFromWindow (from OLEACC.DLL). This creates
85 a dependency of OLEACC.DLL which is unfortunate for applications that link against MFC and really don't need
86 those functions.
87 </p>
88 <p>We provide a workaround for this problem by providing our own - friendlier stub routines for these
89 two OLEACC.DLL functions.</p>
90 <p>Defaulted to ON if _MFC_VER>=0x0700.</p>
91 <p>NOW Defaults off, since its hard to believe this would still exist</p>
92 */
93#ifndef qProvideLedStubsForOLEACCDLL
94#define qProvideLedStubsForOLEACCDLL 0
95#endif
96
97/*
98 **************** MFC bug workaround defines **************
99 */
100
101// Still broken In MSVC 6.0 (LGP 990304) - CFrameWnd::CreateView() still does cast of void* to CWnd* which breaks unless CWnd* is leftmost
102// Still broken In MSVC 5.0 (LGP 970318) - now the bug is in CFrameWnd::CreateView() though...
103// Still broken In MSVC 4.0 (LGP 951125)
104// (only not broken for old LedTestMFC app - breaks in new LedIt! app however. Maybe
105// should re-investigate???)
106// LGP 941129 (updated 950506)
107// The bug is with MFC 3.0/3.1, in CFrameWnd::OnCreateClient()
108// It did a cast of the result of CreateObject() to CWnd*, without
109// knowing the real type it started with, so that code looses if
110// CWnd is not the left-most base class.
111#ifndef qMFCRequiresCWndLeftmostBaseClass
112#define qMFCRequiresCWndLeftmostBaseClass 1
113#endif
114
115 CPoint AsCPoint (Led_Point p);
116 Led_Point AsLedPoint (CPoint p);
117
118 CRect AsCRect (Led_Rect r);
119 Led_Rect AsLedRect (CRect r);
120
121 CSize AsCSize (Led_Size s);
122
123 /*
124 @CLASS: Led_MFC_TmpCDCFromTablet
125 @DESCRIPTION: <p>Helper class to convert a @'Tablet*' to an MFC CDC. Just creates a temporary wrapper.</p>
126 <p><strong>Caution</strong>:
127 You must create a NAMED temporary.
128 A named temporary has lifetime til the end of the enclosing scope.
129 An unnamed temporary has lifetime only til the next sequence point (less or equal to the rest of the current statement - I believe).</p>
130 */
131 class Led_MFC_CDCFromTablet {
132 public:
133 Led_MFC_CDCFromTablet (Tablet* t);
134 ~Led_MFC_CDCFromTablet ();
135 operator CDC* ();
136
137 private:
138 CDC fCDC;
139 };
140
141 /*
142 @CLASS: Led_MFC_TabletFromCDC
143 @DESCRIPTION: <p>Helper class to convert an MFC CDC to a @'Tablet*'. Just creates a temporary wrapper.</p>
144 <p><strong>Caution</strong>:
145 You must create a NAMED temporary.
146 A named temporary has lifetime til the end of the enclosing scope.
147 An unnamed temporary has lifetime only til the next sequence point (less or equal to the rest of the current statement - I believe).</p>
148 */
149 class Led_MFC_TabletFromCDC {
150 public:
151 Led_MFC_TabletFromCDC (CDC* pDC);
152 ~Led_MFC_TabletFromCDC ();
153
154 public:
155 operator Tablet* ();
156 Tablet* operator->();
157
158 private:
159 Tablet fTablet;
160 };
161
162 /*
163 @CLASS: Led_MFC_Helper<MFC_BASE_CLASS,BASE_INTERACTOR>
164 @BASES: MFC_BASE_CLASS=@'CWnd', @'Led_Win32_Helper<BASE_INTERACTOR>', BASE_INTERACTOR=@'TextInteractor'
165 @DESCRIPTION: <p>There are two obvious ways to hook into MFC. One is to create a subclass of CWnd. The other is
166 to create a subclass of CView. Because CView inherits from CWnd, but not virtually, you are strongly encouraged
167 to pick one or the other. Alas - neither is really a good choice for ALL applications. For a big, main view, associated
168 with a document, you want to subclass from CView. For a little control (as in a dialog), you want to subclass from CWnd.</p>
169 <p>This template makes it easier (soon easy, but for now, just easier) to subclass from either one. The default one, and
170 the one Led mainly uses is CView. But soon I'll support (better) subclassing from CWnd.</p>
171 */
172 template <typename MFC_BASE_CLASS = CWnd, typename BASE_INTERACTOR = TextInteractor>
173 class Led_MFC_Helper :
174#if qMFCRequiresCWndLeftmostBaseClass
175 public MFC_BASE_CLASS,
176 public Led_Win32_Helper<BASE_INTERACTOR>
177#else
178 public Led_Win32_Helper<BASE_INTERACTOR>,
179 public MFC_BASE_CLASS
180#endif
181 {
182 private:
183 using inherited = void*; // avoid using this keyword since this is mixin of two classes
184 private:
185 using LED_WIN32_HELPER = Led_Win32_Helper<BASE_INTERACTOR>;
186
187 public:
188 using UpdateInfo = MarkerOwner::UpdateInfo;
189
190 protected:
191 Led_MFC_Helper ();
192
193 public:
194 virtual ~Led_MFC_Helper ();
195
196 public:
197 nonvirtual BOOL ReplaceWindow (HWND hWnd);
198
199 // Led_Win32_Helper Hooks
200 public:
201 virtual HWND GetHWND () const override;
202
203 // Window message hooks NEEDED to get basic editor functionality
204 protected:
205 afx_msg int OnCreate (LPCREATESTRUCT lpCreateStruct);
206 afx_msg void OnPaint ();
207 afx_msg BOOL OnSetCursor (CWnd* pWnd, UINT nHitTest, UINT message);
208 afx_msg UINT OnGetDlgCode ();
209 afx_msg void OnChar (UINT nChar, UINT nRepCnt, UINT /*nFlags*/);
210 afx_msg LRESULT OnUniChar (WPARAM wParam, LPARAM lParam);
211 afx_msg LRESULT OnIMEChar (WPARAM wParam, LPARAM lParam);
212 afx_msg LRESULT OnIME_COMPOSITION (WPARAM wParam, LPARAM lParam);
213 afx_msg LRESULT OnIME_ENDCOMPOSITION (WPARAM wParam, LPARAM lParam);
214 afx_msg void OnKeyDown (UINT nChar, UINT nRepCnt, UINT /*nFlags*/);
215 afx_msg void OnMouseMove (UINT /*nFlags*/, CPoint oPoint);
216 afx_msg void OnLButtonDown (UINT nFlags, CPoint oPoint);
217 afx_msg void OnLButtonUp (UINT /*nFlags*/, CPoint oPoint);
218 afx_msg void OnLButtonDblClk (UINT /*nFlags*/, CPoint oPoint);
219 afx_msg void OnSetFocus (CWnd* pOldWnd);
220 afx_msg void OnKillFocus (CWnd* pNewWnd);
221 afx_msg void OnSize (UINT nType, int cx, int cy);
222 afx_msg BOOL OnEraseBkgnd (CDC* pDC);
223 afx_msg void OnVScroll (UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
224 afx_msg void OnHScroll (UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
225 afx_msg BOOL OnMouseWheel (UINT fFlags, short zDelta, CPoint point);
226 afx_msg void OnEnable (BOOL bEnable);
227 afx_msg void OnTimer (UINT_PTR nEventID);
228
229 // Disambiguate mixins
230 public:
231 virtual Led_Rect GetWindowRect () const;
232 nonvirtual void GetWindowRect (LPRECT lpRect) const;
233
234 public:
235 nonvirtual DWORD GetStyle () const;
236
237 // Command handing - map MFC commands to Led/TextInteractor commands
238 public:
239 afx_msg void OnUpdateCommand_MSG (CCmdUI* pCmdUI);
240 afx_msg void OnPerformCommand_MSG (UINT commandNumber);
241
242 protected:
243 DECLARE_MESSAGE_MAP ()
244 };
245
246 /*
247 @CLASS: Led_MFC_MimicMFCAPIHelper<BASECLASS>
248 @BASES: BASECLASS = @'Led_MFC_Helper<MFC_BASE_CLASS,BASE_INTERACTOR>'
249 @DESCRIPTION: <p>Mimicry of the MFC CEdit methods - to facilitate using this class in place of any
250 existing CEdit usage. These methods simply do send-message calls just as their
251 CEdit counterparts. Then messages are then trapped in the OnMsgXXX handlers.</p>
252 <p>NB: Use of this class almost ALWAYS requires also mixing in the template
253 @'Led_MFC_OptionalWin32SDKMessageMimicHelper<BASECLASS>'. since that is what (by default) implements
254 the OnMsgXXX helpers.</p>
255 */
256 template <typename BASECLASS = Led_MFC_Helper<>>
257 class Led_MFC_MimicMFCAPIHelper : public BASECLASS {
258 protected:
259 Led_MFC_MimicMFCAPIHelper () = default;
260
261 public:
262 nonvirtual BOOL Create (DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID);
263 nonvirtual BOOL CanUndo () const;
264 nonvirtual int GetLineCount_CEdit () const; // HAD to rename cuz of conflict...
265 nonvirtual BOOL GetModify () const;
266 nonvirtual void SetModify (BOOL bModified = TRUE);
267 nonvirtual void GetRect (LPRECT lpRect) const;
268 nonvirtual DWORD GetSel () const;
269 nonvirtual void GetSel (int& nStartChar, int& nEndChar) const;
270 nonvirtual int GetLine (int nIndex, LPTSTR lpszBuffer) const;
271 nonvirtual int GetLine (int nIndex, LPTSTR lpszBuffer, int nMaxLength) const;
272 nonvirtual void EmptyUndoBuffer ();
273 nonvirtual BOOL FmtLines (BOOL bAddEOL);
274 nonvirtual void LimitText (int nChars = 0);
275 nonvirtual int LineFromChar (int nIndex = -1) const;
276 nonvirtual int LineIndex (int nLine = -1) const;
277 nonvirtual int LineLength (int nLine = -1) const;
278 nonvirtual void LineScroll (int nLines, int nChars = 0);
279 nonvirtual void ReplaceSel (LPCTSTR lpszNewText);
280 nonvirtual void SetPasswordChar (TCHAR ch);
281 nonvirtual void SetRect (LPCRECT lpRect);
282 nonvirtual void SetRectNP (LPCRECT lpRect);
283 nonvirtual void SetSel (DWORD dwSelection, BOOL bNoScroll = FALSE);
284 nonvirtual void SetSel (int nStartChar, int nEndChar, BOOL bNoScroll = FALSE);
285 nonvirtual BOOL SetTabStops (int nTabStops, LPINT rgTabStops);
286 nonvirtual void SetTabStops ();
287 nonvirtual BOOL SetTabStops (const int& cxEachStop); // takes an 'int'
288 nonvirtual BOOL Undo ();
289 nonvirtual void Clear ();
290 nonvirtual void Copy ();
291 nonvirtual void Cut ();
292 nonvirtual void Paste ();
293 nonvirtual BOOL SetReadOnly (BOOL bReadOnly = TRUE);
294 nonvirtual int GetFirstVisibleLine () const;
295 nonvirtual TCHAR GetPasswordChar () const;
296 };
297
298 /*
299 @CLASS: Led_MFC_OptionalWin32SDKMessageMimicHelper<BASECLASS>
300 @BASES: BASECLASS = @'Led_MFC_Helper<MFC_BASE_CLASS,BASE_INTERACTOR>'
301 @DESCRIPTION: <p>Mimicry of the starndard Win32 messages sent to an edit control. We cannot
302 mimic ALL the messages. Some just don't make sense (like GETHANDLE). But for those that do, we
303 do our best.</p>
304 */
305 template <typename BASECLASS = Led_MFC_Helper<>>
306 class Led_MFC_OptionalWin32SDKMessageMimicHelper : public Led_Win32_Win32SDKMessageMimicHelper<BASECLASS> {
307 private:
308 using inherited = Led_Win32_Win32SDKMessageMimicHelper<BASECLASS>;
309
310 protected:
311 Led_MFC_OptionalWin32SDKMessageMimicHelper () = default;
312
313 public:
314 template <int MESSAGE_NUMBER>
315 afx_msg LRESULT OnMFCSDKMessageDispatcher (WPARAM wParam, LPARAM lParam)
316 {
317 LRESULT result = 0;
318 Verify (this->HandleMessage (MESSAGE_NUMBER, wParam, lParam, &result));
319 return result;
320 }
321
322 protected:
323 DECLARE_MESSAGE_MAP ()
324 };
325
326 /*
327 @CLASS: Led_MFC_DragAndDropWindow<BASECLASS>
328 @BASES: BASECLASS
329 @DESCRIPTION: <p>NB: BASECLASS <em>must</em> derive (possibly indirectly) from CWnd.</p>
330 <p>Probably eventually migrate more stuff from @'Led_MFC_CViewHelper<BASECLASS>' here to this class. But for now,
331 I'm risk averse. I don't want to break the class library. And this is all that is needed to move out to meet the immediate
332 complaints.</p>
333 */
334 template <typename BASECLASS = Led_MFC_Helper<>>
335 class Led_MFC_DragAndDropWindow : public BASECLASS {
336 private:
337 using inherited = BASECLASS;
338
339 protected:
340 Led_MFC_DragAndDropWindow ();
341
342 public:
343 ~Led_MFC_DragAndDropWindow ();
344
345 public:
346 /*
347 @CLASS: Led_MFC_DragAndDropWindow<BASECLASS>::CommandNames
348 @DESCRIPTION: <p>Command names for each of the user-visible commands produced by the @'TextInteractor' module.
349 This name is used used in the constructed Undo command name, as
350 in, "Undo Drag and Drop". You can replace this name with whatever you like.
351 You change this value with @'TextInteractor::SetCommandNames'.</p>
352 <p> The point of this is to allow for different UI-language localizations,
353 without having to change Led itself.</p>
354 <p>See also @'Led_MFC_DragAndDropWindow<BASECLASS>::GetCommandNames'.</p>
355 <p>See also @'TextInteractor::CommandNames'.</p>
356 <p>Note - also - this class must be declared lexically inside the
357 outer template -and not outside - do to compiler bugs with MSVC60(SP4).
358 Didn't take the time to trace them down carefully - LGP 2000-08-19.</p>
359 */
360 struct CommandNames {
361 CommandNames ()
362 : fDragCommandName (Led_SDK_TCHAROF ("Drag"))
363 , fDropCommandName (Led_SDK_TCHAROF ("Drop"))
364 , fDragNDropCommandName (Led_SDK_TCHAROF ("Drag and Drop"))
365 {
366 }
367
368 SDKString fDragCommandName;
369 SDKString fDropCommandName;
370 SDKString fDragNDropCommandName;
371 };
372
373 // This class builds commands with command names. The UI may wish to change these
374 // names (eg. to customize for particular languages, etc)
375 // Just patch these strings here, and commands will be created with these names.
376 // (These names appear in text of undo menu item)
377 public:
378 static const CommandNames& GetCommandNames ();
379 static void SetCommandNames (const CommandNames& cmdNames);
380
381 private:
382 static CommandNames sCommandNames;
383
384 protected:
385 COleDropTarget fDropTarget;
386
387 protected:
388 afx_msg int OnCreate (LPCREATESTRUCT lpCreateStruct);
389
390 // mouse down tracking... and drag and drop...
391 protected:
392 virtual bool IsADragSelect (Led_Point clickedWhere) const;
393 nonvirtual void HandleDragSelect (UINT nFlags, CPoint oPoint);
394 nonvirtual void HandleSharedDragOverUpdateSelCode ();
395 nonvirtual DROPEFFECT HelperDragEnter (COleDataObject* pDataObject, DWORD dwKeyState, CPoint point);
396 nonvirtual DROPEFFECT HelperDragOver (COleDataObject* pDataObject, DWORD dwKeyState, CPoint point);
397 nonvirtual BOOL HelperDrop (COleDataObject* pDataObject, DROPEFFECT dropEffect, CPoint point);
398 nonvirtual void HelperDragLeave ();
399
400 protected:
401 CPoint fDragPoint; // current position
402 CSize fDragSize; // size of dragged object
403 CSize fDragOffset; // offset to focus rect
404 DROPEFFECT fPrevDropEffect;
405
406 protected:
407 nonvirtual bool GetObjectInfo (COleDataObject* pDataObject, CSize* pSize, CSize* pOffset);
408
409 protected:
410 afx_msg void OnTimer (UINT_PTR nEventID);
411
412 private:
413 nonvirtual void StartDragAutoscrollTimer ();
414 nonvirtual void StopDragAutoscrollTimer ();
415 enum {
416 eAutoscrolling4DragTimerEventID = 435
417 }; // Magic#
418 UINT_PTR fDragAutoScrollTimerID; // zero means no timer
419
420 private:
421 struct LedStartDragAndDropContext {
422 public:
423 LedStartDragAndDropContext (Led_MFC_DragAndDropWindow<BASECLASS>* ledMFCView)
424 : fOurDrag (false)
425 , fOurDragStart (0)
426 , fOurDragEnd (0)
427 , fWeRecievedDrop (false)
428 , fLedMFCView (ledMFCView)
429 , fOrigSelection (ledMFCView->GetTextStore (), ledMFCView->GetSelectionStart (), ledMFCView->GetSelectionEnd ())
430 {
431 }
432
433 public:
434 bool fOurDrag;
435 size_t fOurDragStart;
436 size_t fOurDragEnd;
437 bool fWeRecievedDrop;
438 Led_MFC_DragAndDropWindow<BASECLASS>* fLedMFCView;
439 TempMarker fOrigSelection;
440 };
441
442 static LedStartDragAndDropContext* sCurrentDragInfo;
443
444 protected:
445 DECLARE_MESSAGE_MAP ()
446 };
447
448 /*
449 @CLASS: Led_MFC_CViewHelper<BASECLASS>
450 @BASES: BASECLASS
451 @DESCRIPTION: <p>NB: BASECLASS <em>must</em> derive (possibly indirectly) from CView.</p>
452 */
453 template <typename BASECLASS = Led_MFC_DragAndDropWindow<>>
454 class Led_MFC_CViewHelper : public BASECLASS {
455 private:
456 using inherited = BASECLASS;
457
458 protected:
459 Led_MFC_CViewHelper ();
460
461 public:
462 virtual ~Led_MFC_CViewHelper ();
463
464 // CEditView storage methods.
465 public:
466 virtual void DeleteContents ();
467 virtual void Serialize (CArchive& ar);
468 nonvirtual void SerializeRaw (CArchive& ar);
469 nonvirtual void ReadFromArchive (CArchive& ar, UINT nLen);
470 nonvirtual void WriteToArchive (CArchive& ar);
471
472 protected:
473 afx_msg void OnPaint ();
474 virtual void OnDraw (CDC* pDC) override;
475 afx_msg void OnLButtonDown (UINT nFlags, CPoint oPoint);
476 afx_msg int OnCreate (LPCREATESTRUCT lpCreateStruct);
477 afx_msg void OnVScroll (UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
478 afx_msg void OnHScroll (UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
479
480 public:
481 nonvirtual TWIPS_Rect GetPrintMargins () const;
482 nonvirtual void SetPrintMargins (const TWIPS_Rect& printMargins);
483
484 private:
485 TWIPS_Rect fPrintMargins;
486
487 protected:
488 virtual BOOL OnPreparePrinting (CPrintInfo* pInfo) override;
489 virtual void OnBeginPrinting (CDC* pDC, CPrintInfo* pInfo) override;
490 virtual void OnPrint (CDC* pDC, CPrintInfo* pInfo) override;
491 virtual void OnEndPrinting (CDC* pDC, CPrintInfo* pInfo) override;
492
493 public:
494 virtual void OnPrepareDC (CDC* pDC, CPrintInfo* pInfo) override;
495
496 protected:
497 virtual Led_Rect CalculatePrintingRect (CDC* pDC) const;
498
499 protected:
500 struct PrintInfo {
501 PrintInfo (BASECLASS& editor, CDC* useTablet, Led_Rect oldWindowRect, size_t savedScrollPos, bool savedForceAlLRowsFlag)
502 : fTmpTablet{useTablet}
503 , fOldUpdateTablet{editor, fTmpTablet, BASECLASS::TemporarilyUseTablet::eDontDoTextMetricsChangedCall}
504 , fOldWindowRect{oldWindowRect}
505 , fSavedScrollPos{savedScrollPos}
506 , fSavedForceAllRowsFlag{savedForceAlLRowsFlag}
507 {
508 }
509 Led_MFC_TabletFromCDC fTmpTablet;
510 typename BASECLASS::TemporarilyUseTablet fOldUpdateTablet;
511 Led_Rect fOldWindowRect;
512 size_t fSavedScrollPos;
513 bool fSavedForceAllRowsFlag;
514 vector<size_t> fWindowStarts;
515 };
516 PrintInfo* fPrintInfo; // Non-NULL only during printing...
517
518 // mouse down tracking... and drag and drop...
519 protected:
520 virtual DROPEFFECT OnDragEnter (COleDataObject* pDataObject, DWORD dwKeyState, CPoint point) override;
521 virtual DROPEFFECT OnDragOver (COleDataObject* pDataObject, DWORD dwKeyState, CPoint point) override;
522 virtual BOOL OnDrop (COleDataObject* pDataObject, DROPEFFECT dropEffect, CPoint point) override;
523 virtual void OnDragLeave () override;
524
525 public:
526 virtual void InvalidateScrollBarParameters () override;
527
528 protected:
529 virtual void UpdateScrollBars () override;
530
531 protected:
532 DECLARE_MESSAGE_MAP ()
533 };
534
535 /*
536 @CLASS: Led_MFC
537 @BASES: @'Led_MFC_CViewHelper<BASECLASS>', where BASECLASS=@'Led_MFC_OptionalWin32SDKMessageMimicHelper<BASECLASS>, where BASECLASS=@'Led_MFC_MimicMFCAPIHelper<BASECLASS>', where BASECLASS == @'Led_MFC_Helper<BASECLASS>', where BASECLASS=CView
538 @DESCRIPTION: <p>This template is provided partly as a convenience, for such a common case. But MOSTLY as backwards compatability
539 for Led 2.2. In Led 2.2, Led_MFC was the SOLE class provided to integrated Led with MFC. Now there is a whole suite of
540 individually selectable templates to provide that interfacing.</p>
541 */
542 using Led_MFC =
543 Led_MFC_CViewHelper<Led_MFC_DragAndDropWindow<Led_MFC_OptionalWin32SDKMessageMimicHelper<Led_MFC_MimicMFCAPIHelper<Led_MFC_Helper<CView, TextInteractor>>>>>;
544
545 /*
546 @CLASS: Led_MFC_COleControlHelper<BASECLASS>
547 @BASES: BASECLASS
548 @DESCRIPTION: <p>NB: BASECLASS <em>must</em> derive (possibly indirectly) from CView.</p>
549 */
550 template <typename BASECLASS = Led_MFC_DragAndDropWindow<>>
551 class Led_MFC_COleControlHelper : public BASECLASS {
552 private:
553 using inherited = BASECLASS;
554
555 public:
556 using UpdateMode = TextInteractor::UpdateMode;
557
558 protected:
559 Led_MFC_COleControlHelper ()
560 {
561 }
562
563 public:
564 virtual ~Led_MFC_COleControlHelper ()
565 {
566 }
567
568 public:
569 nonvirtual void Refresh (UpdateMode updateMode = TextInteractor::eDefaultUpdate) const
570 {
571 const TextInteractor* ti = this;
572 ti->Refresh (updateMode);
573 }
574 nonvirtual void Refresh (const Led_Rect& area, UpdateMode updateMode = TextInteractor::eDefaultUpdate) const
575 {
576 const TextInteractor* ti = this;
577 ti->Refresh (area, updateMode);
578 }
579 nonvirtual void Refresh (size_t from, size_t to, UpdateMode updateMode = TextInteractor::eDefaultUpdate) const
580 {
581 const TextInteractor* ti = this;
582 ti->Refresh (from, to, updateMode);
583 }
584 nonvirtual void Refresh (const Marker* range, UpdateMode updateMode = TextInteractor::eDefaultUpdate) const
585 {
586 const TextInteractor* ti = this;
587 ti->Refresh (range, updateMode);
588 }
589 };
590
591 DISABLE_COMPILER_MSC_WARNING_START (4250) // inherits via dominance warning
592 /*
593 @CLASS: Led_MFC_ExceptionHandlerHelper<BASECLASS>
594 @BASES: BASECLASS = @'Led_MFC_Helper<MFC_BASE_CLASS,BASE_INTERACTOR>'
595 @DESCRIPTION: <p>This helper is designed to manage exception handling, when the Led class is being used in a context (say OCX)
596 where it cannot throw exceptions in error situations.</p>
597 <p>This class wraps many messages the control is likely to get, and when there is an exception, it calls a virtual
598 exception-handling method (which by default - beeps), and then returns normally.</p>
599 */
600 template <typename BASECLASS = Led_MFC>
601 class Led_MFC_ExceptionHandlerHelper : public BASECLASS {
602 private:
603 using inherited = BASECLASS;
604
605 protected:
606 virtual void HandleException () const;
607
608 public:
609 afx_msg void OnChar (UINT nChar, UINT nRepCnt, UINT nFlags);
610 afx_msg LRESULT OnIMEChar (WPARAM wParam, LPARAM lParam);
611 afx_msg void OnKeyDown (UINT nChar, UINT nRepCnt, UINT nFlags);
612 afx_msg LRESULT OnMsgPaste (WPARAM wParam, LPARAM lParam);
613 afx_msg void OnLButtonDown (UINT nFlags, CPoint oPoint);
614 afx_msg void OnLButtonUp (UINT /*nFlags*/, CPoint oPoint);
615 afx_msg void OnLButtonDblClk (UINT /*nFlags*/, CPoint oPoint);
616 afx_msg BOOL OnCmdMsg (UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo);
617
618 protected:
619 DECLARE_MESSAGE_MAP ()
620 };
621 DISABLE_COMPILER_MSC_WARNING_END (4250) // inherits via dominance warning
622
623 DISABLE_COMPILER_MSC_WARNING_START (4250) // inherits via dominance warning
624 /*
625 @CLASS: Led_MFC_X
626 @BASES: ChosenInteractor, @'Led_MFC'
627 @DESCRIPTION: <p>Utility template to mix together Led_MFC an a <code>ChosenInteractor</code> which already has support
628 for a particular TextImager mixed in.</p>
629 */
630 template <typename ChosenInteractor, typename LEDMFC = Led_MFC>
631 class Led_MFC_X :
632#if qMFCRequiresCWndLeftmostBaseClass
633 public LEDMFC,
634 public ChosenInteractor
635#else
636 public ChosenInteractor,
637 public LEDMFC
638#endif
639 {
640 public:
641 Led_MFC_X ();
642
643 public:
644 virtual void AboutToUpdateText (const MarkerOwner::UpdateInfo& updateInfo) override;
645 virtual void DidUpdateText (const MarkerOwner::UpdateInfo& updateInfo) noexcept override;
646 };
647 DISABLE_COMPILER_MSC_WARNING_END (4250) // inherits via dominance warning
648
649 /*
650 @CLASS: Led_MFCReaderDAndDFlavorPackage
651 @BASES: @'ReaderFlavorPackage'
652 @DESCRIPTION: <p>ReaderFlavorPackage which reads from a COleDataObject as
653 its underlying storage. Useful for Drop (Drag and Drop) processing.</p>
654 */
655 class Led_MFCReaderDAndDFlavorPackage : public ReaderFlavorPackage {
656 public:
657 Led_MFCReaderDAndDFlavorPackage (COleDataObject* dataObject);
658
659 virtual bool GetFlavorAvailable (Led_ClipFormat clipFormat) const override;
660 virtual size_t GetFlavorSize (Led_ClipFormat clipFormat) const override;
661 virtual size_t ReadFlavorData (Led_ClipFormat clipFormat, size_t bufSize, void* buf) const override;
662
663 nonvirtual COleDataObject* GetOleDataObject () const;
664
665 private:
666 COleDataObject* fDataObject;
667 };
668
669 /*
670 @CLASS: Led_MFCWriterDAndDFlavorPackage
671 @BASES: @'WriterFlavorPackage'
672 @DESCRIPTION: <p>A WriterFlavorPackage which writes to a COleDataObject as
673 its underlying storage. Useful for Drag (Drag and Drop) processing.</p>
674 */
675 class Led_MFCWriterDAndDFlavorPackage : public WriterFlavorPackage {
676 public:
677 Led_MFCWriterDAndDFlavorPackage (COleDataSource* dataObject);
678
679 virtual void AddFlavorData (Led_ClipFormat clipFormat, size_t bufSize, const void* buf) override;
680
681 nonvirtual COleDataSource* GetOleDataSource () const;
682
683 private:
684 COleDataSource* fDataObject;
685 };
686
687 template <typename TRIVIALWORDWRAPPEDTEXTIMAGER, typename SIMPLETEXTIMAGER, typename TEXTSTORE>
688 CSize Led_GetTextExtent (CDC* cdc, const Led_tString& text, CRect r, bool wordWrap);
689
690 template <typename TRIVIALWORDWRAPPEDTEXTIMAGER, typename SIMPLETEXTIMAGER, typename TEXTSTORE>
691 void Led_DrawText (CDC* cdc, const Led_tString& text, CRect r, bool wordWrap);
692
693#if qSupportDrawTextGetTextExtent
694 CSize Led_GetTextExtent (CDC* cdc, const Led_tString& text, CRect r, bool wordWrap);
695 void Led_DrawText (CDC* cdc, const Led_tString& text, CRect r, bool wordWrap);
696#endif
697
698 /*
699 @CLASS: MFC_CommandNumberMapping
700 @DESCRIPTION: <p></p>
701 */
702 class MFC_CommandNumberMapping : public CommandNumberMapping<UINT> {
703 protected:
704 MFC_CommandNumberMapping ();
705 };
706
707 /*
708 @CLASS: Led_MFC_TmpCmdUpdater
709 @BASES: @'TextInteractor::CommandUpdater'
710 @DESCRIPTION: <p>Helper used in @'Led_Win32_Helper<BASE_INTERACTOR>'</p>
711 */
712 class Led_MFC_TmpCmdUpdater : public TextInteractor::CommandUpdater {
713 public:
714 explicit Led_MFC_TmpCmdUpdater (CCmdUI* pCmdUI);
715
716 public:
717 virtual CommandNumber GetCmdID () const override;
718 virtual bool GetEnabled () const override;
719 virtual void SetEnabled (bool enabled) override;
720 virtual void SetChecked (bool checked) override;
721 virtual void SetText (const SDKChar* text) override;
722
723 public:
724 operator CCmdUI* ();
725 operator Led_MFC_TmpCmdUpdater* ();
726
727 private:
728 CommandNumber fCmdNum;
729 CCmdUI* fCmdUI;
730 bool fEnabled;
731 };
732
733/*
734 @CLASS: LED_MFC_HANDLE_COMMAND
735 @DESCRIPTION: <p>Trivial helper for building MFC message maps.</p>
736 */
737#define LED_MFC_HANDLE_COMMAND(A) \
738 ON_COMMAND_RANGE (A, A, &ThisClass::OnPerformCommand_MSG) \
739 ON_UPDATE_COMMAND_UI (A, &ThisClass::OnUpdateCommand_MSG)
740
741/*
742 @CLASS: LED_MFC_HANDLE_COMMAND_RANGE
743 @DESCRIPTION: <p>Trivial helper for building MFC message maps.</p>
744 */
745#define LED_MFC_HANDLE_COMMAND_RANGE(A, B) \
746 ON_COMMAND_RANGE (A, B, &ThisClass::OnPerformCommand_MSG) \
747 ON_UPDATE_COMMAND_UI_RANGE (A, B, &ThisClass::OnUpdateCommand_MSG)
748
749/*
750 @CLASS: LED_MFC_HANDLE_COMMAND_M
751 @DESCRIPTION: <p></p>
752 */
753#define LED_MFC_HANDLE_COMMAND_M(A) LED_MFC_HANDLE_COMMAND (MFC_CommandNumberMapping::Get ().ReverseLookup (A))
754
755/*
756 @CLASS: LED_MFC_HANDLE_COMMAND_RANGE_M
757 @DESCRIPTION: <p></p>
758 */
759#define LED_MFC_HANDLE_COMMAND_RANGE_M(A, B) \
760 LED_MFC_HANDLE_COMMAND_RANGE (MFC_CommandNumberMapping::Get ().ReverseLookup (A), MFC_CommandNumberMapping::Get ().ReverseLookup (B))
761}
762
763/*
764 ********************************************************************************
765 ***************************** Implementation Details ***************************
766 ********************************************************************************
767 */
768#include "MFC.inl"
769
770#endif /*_Stroika_Frameworks_Led_Platform_MFC_h_*/
#define Verify(c)
Definition Assertions.h:419
void Copy(T *dest, size_t nEltsInDest, const T *src)
Safe variant of strncpy() - which always NUL-terminates the string.
basic_string< SDKChar > SDKString
Definition SDKString.h:38