Stroika Library 3.0d18
 
Loading...
Searching...
No Matches
ActiveLedItControl.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef __ActiveLedItControl_h__
5#define __ActiveLedItControl_h__ 1
6
7/*
8 * Description:
9 * Declaration of the ActiveLedItControl ActiveX Control class.
10 */
11#include "Stroika/Foundation/StroikaPreComp.h"
12
13#include <afxctl.h>
14#include <objsafe.h> // for IObjectSafety; in ActiveX SDK
15#include <set>
16
17#include "Stroika/Frameworks/Led/SpellCheckEngine.h"
18#include "Stroika/Frameworks/Led/StyledTextIO/StyledTextIO_HTML.h"
19#include "Stroika/Frameworks/Led/StyledTextIO/StyledTextIO_RTF.h"
20
21#include "ActiveLedItConfig.h"
22#include "LedItView.h"
23
24#include "ActiveLedIt_h.h"
25
26enum Led_FileFormat {
27 eTextFormat,
28 eLedPrivateFormat,
29 eRTFFormat,
30 eHTMLFormat,
31 eUnknownFormat,
32 eDefaultFormat = eRTFFormat,
33};
34
35class COMBased_SpellCheckEngine : public SpellCheckEngine, private SpellCheckEngine::UDInterface, private TextBreaks {
36private:
37 using inherited = SpellCheckEngine;
38
39public:
40 COMBased_SpellCheckEngine (IDispatch* engine);
41
42private:
43 CComPtr<IDispatch> fEngine;
44
45public:
46 virtual bool ScanForUndefinedWord (const Led_tChar* startBuf, const Led_tChar* endBuf, const Led_tChar** cursor,
47 const Led_tChar** wordStartResult, const Led_tChar** wordEndResult) override;
48
49protected:
50 virtual bool LookupWord_ (const Led_tString& checkWord, Led_tString* matchedWordResult) override;
51
52public:
53 virtual vector<Led_tString> GenerateSuggestions (const Led_tString& misspelledWord) override;
54
55public:
56 virtual TextBreaks* PeekAtTextBreaksUsed () override;
57
58 // From TextBreaks
59public:
60 virtual void FindWordBreaks (const Led_tChar* startOfText, size_t lengthOfText, size_t textOffsetToStartLookingForWord,
61 size_t* wordStartResult, size_t* wordEndResult, bool* wordReal) const override;
62 virtual void FindLineBreaks (const Led_tChar* startOfText, size_t lengthOfText, size_t textOffsetToStartLookingForWord,
63 size_t* wordEndResult, bool* wordReal) const override;
64
65public:
66 virtual UDInterface* GetUDInterface () override;
67
68 // From SpellCheckEngine::UDInterface
69public:
70 virtual bool AddWordToUserDictionarySupported () const override;
71 virtual void AddWordToUserDictionary (const Led_tString& word) override;
72};
73
74DISABLE_COMPILER_MSC_WARNING_START (4250) // inherits via dominance warning
75
76class ActiveLedItControl : public COleControl, public MarkerOwner, public LedItViewController {
77private:
78 DECLARE_DYNCREATE (ActiveLedItControl)
79
80public:
81 ActiveLedItControl ();
82
83protected:
84 ~ActiveLedItControl ();
85
86#if qKeepListOfALInstancesForSPR_1599BWA
87public:
88 static const set<ActiveLedItControl*>& GetAll ();
89
90private:
91 static set<ActiveLedItControl*> sAll;
92#endif
93
94protected:
95 virtual void DidUpdateText (const UpdateInfo& /*updateInfo*/) noexcept override;
96 virtual TextStore* PeekAtTextStore () const override;
97
98public:
99 virtual void OnDraw (CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid) override;
100 virtual void OnDrawMetafile (CDC* pDC, const CRect& rcBounds) override;
101 afx_msg BOOL OnEraseBkgnd (CDC* pDC);
102 virtual void DoPropExchange (CPropExchange* pPX) override;
103 virtual void OnResetState () override;
104 virtual DWORD GetControlFlags () override;
105 virtual void OnGetControlInfo (LPCONTROLINFO pControlInfo) override;
106 virtual BOOL PreTranslateMessage (MSG* pMsg) override;
107 virtual void AddFrameLevelUI () override;
108 virtual void RemoveFrameLevelUI () override;
109 virtual BOOL OnSetObjectRects (LPCRECT lprcPosRect, LPCRECT lprcClipRect) override;
110 virtual BOOL OnGetNaturalExtent (DWORD /* dwAspect */, LONG /* lindex */, DVTARGETDEVICE* /* ptd */, HDC /* hicTargetDev */,
111 DVEXTENTINFO* /* pExtentInfo */, LPSIZEL /* psizel */
112 ) override;
113
114private:
115 struct OnCreateExtras {
116 OnCreateExtras ();
117 bool fReadOnly;
118 bool fEnabled;
119 };
120 unique_ptr<OnCreateExtras> fOnCreateExtras;
121
122private:
123 nonvirtual void ExchangeTextAsRTFBlob (CPropExchange* pPX);
124
125public:
126 DECLARE_INTERFACE_MAP ()
127
128 BEGIN_INTERFACE_PART (ObjSafe, IObjectSafety)
129 STDMETHOD_ (HRESULT, GetInterfaceSafetyOptions)
130 (
131 /* [in] */ REFIID riid,
132 /* [out] */ DWORD __RPC_FAR* pdwSupportedOptions,
133 /* [out] */ DWORD __RPC_FAR* pdwEnabledOptions);
134
135 STDMETHOD_ (HRESULT, SetInterfaceSafetyOptions)
136 (
137 /* [in] */ REFIID riid,
138 /* [in] */ DWORD dwOptionSetMask,
139 /* [in] */ DWORD dwEnabledOptions);
140 END_INTERFACE_PART (ObjSafe);
141
142protected:
143 DECLARE_OLECREATE_EX (ActiveLedItControl) // Class factory and guid
144 DECLARE_OLETYPELIB (ActiveLedItControl) // GetTypeInfo
145 DECLARE_PROPPAGEIDS (ActiveLedItControl) // Property page IDs
146 DECLARE_OLECTLTYPE (ActiveLedItControl) // Type name and misc status
147
148 // Reflect to OWNED window, since we have two separate windows. If we ever merge these, then most of this reflecting code can die.
149protected:
150 afx_msg int OnCreate (LPCREATESTRUCT lpCreateStruct);
151 afx_msg void OnWindowPosChanged (WINDOWPOS* lpwndpos);
152 afx_msg void OnSetFocus (CWnd* pOldWnd);
153
154protected:
155 nonvirtual void Layout ();
156
157protected:
158 afx_msg void OLE_InvalidateLayout ();
159
160#if qDontUIActivateOnOpen
161protected:
162 virtual HRESULT OnOpen (BOOL bTryInPlace, LPMSG pMsg) override;
163#endif
164
165protected:
166 virtual void OnBackColorChanged () override;
167#if qFunnyDisplayInDesignMode
168 virtual void OnAmbientPropertyChange (DISPID dispid) override;
169#endif
170
171protected:
172 afx_msg UINT OLE_VersionNumber ();
173 afx_msg BSTR OLE_ShortVersionString ();
174 afx_msg BOOL OLE_GetReadOnly ();
175 afx_msg void OLE_SetReadOnly (BOOL bNewValue);
176 afx_msg BOOL OLE_GetEnabled ();
177 afx_msg void OLE_SetEnabled (BOOL bNewValue);
178 afx_msg BOOL OLE_GetEnableAutoChangesBackgroundColor ();
179 afx_msg void OLE_SetEnableAutoChangesBackgroundColor (BOOL bNewValue);
180 afx_msg int OLE_GetWindowMarginTop ();
181 afx_msg void OLE_SetWindowMarginTop (int windowMarginTop);
182 afx_msg int OLE_GetWindowMarginLeft ();
183 afx_msg void OLE_SetWindowMarginLeft (int windowMarginLeft);
184 afx_msg int OLE_GetWindowMarginBottom ();
185 afx_msg void OLE_SetWindowMarginBottom (int windowMarginBottom);
186 afx_msg int OLE_GetWindowMarginRight ();
187 afx_msg void OLE_SetWindowMarginRight (int windowMarginRight);
188 afx_msg int OLE_GetPrintMarginTop ();
189 afx_msg void OLE_SetPrintMarginTop (int printMarginTop);
190 afx_msg int OLE_GetPrintMarginLeft ();
191 afx_msg void OLE_SetPrintMarginLeft (int printMarginLeft);
192 afx_msg int OLE_GetPrintMarginBottom ();
193 afx_msg void OLE_SetPrintMarginBottom (int printMarginBottom);
194 afx_msg int OLE_GetPrintMarginRight ();
195 afx_msg void OLE_SetPrintMarginRight (int printMarginRight);
196 afx_msg UINT GetHasVerticalScrollBar ();
197 afx_msg void SetHasVerticalScrollBar (UINT bNewValue);
198 afx_msg UINT GetHasHorizontalScrollBar ();
199 afx_msg void SetHasHorizontalScrollBar (UINT bNewValue);
200 afx_msg BSTR GetBufferText ();
201 afx_msg void SetBufferText (LPCTSTR text);
202 afx_msg BSTR GetBufferTextCRLF ();
203 afx_msg void SetBufferTextCRLF (LPCTSTR text);
204 afx_msg BSTR GetBufferTextAsRTF ();
205 afx_msg string GetBufferTextAsRTF_ ();
206 afx_msg void SetBufferTextAsRTF (LPCTSTR text);
207 afx_msg BSTR GetBufferTextAsHTML ();
208 afx_msg void SetBufferTextAsHTML (LPCTSTR text);
209 afx_msg VARIANT GetBufferTextAsDIB ();
210 afx_msg long GetBufferLength ();
211 afx_msg long GetMaxLength ();
212 afx_msg void SetMaxLength (long maxLength);
213 afx_msg BOOL GetSupportContextMenu ();
214 afx_msg void SetSupportContextMenu (BOOL bNewValue);
215 afx_msg BOOL OLE_GetHideDisabledContextMenuItems ();
216 afx_msg void OLE_SetHideDisabledContextMenuItems (BOOL bNewValue);
217 afx_msg BOOL GetSmartCutAndPaste ();
218 afx_msg void SetSmartCutAndPaste (BOOL bNewValue);
219 afx_msg BOOL OLE_GetSmartQuoteMode ();
220 afx_msg void OLE_SetSmartQuoteMode (BOOL bNewValue);
221 afx_msg BOOL GetWrapToWindow ();
222 afx_msg void SetWrapToWindow (BOOL bNewValue);
223 afx_msg BOOL GetShowParagraphGlyphs ();
224 afx_msg void SetShowParagraphGlyphs (BOOL bNewValue);
225 afx_msg BOOL GetShowTabGlyphs ();
226 afx_msg void SetShowTabGlyphs (BOOL bNewValue);
227 afx_msg BOOL GetShowSpaceGlyphs ();
228 afx_msg void SetShowSpaceGlyphs (BOOL bNewValue);
229 afx_msg BOOL OLE_GetUseSelectEOLBOLRowHilightStyle ();
230 afx_msg void OLE_SetUseSelectEOLBOLRowHilightStyle (BOOL bNewValue);
231 afx_msg BOOL OLE_GetShowSecondaryHilight ();
232 afx_msg void OLE_SetShowSecondaryHilight (BOOL bNewValue);
233
234 // Hidable text
235protected:
236 afx_msg BOOL OLE_GetShowHidableText ();
237 afx_msg void OLE_SetShowHidableText (BOOL bNewValue);
238 afx_msg OLE_COLOR OLE_GetHidableTextColor ();
239 afx_msg void OLE_SetHidableTextColor (OLE_COLOR color);
240 afx_msg BOOL OLE_GetHidableTextColored ();
241 afx_msg void OLE_SetHidableTextColored (BOOL bNewValue);
242
243 // Spell checking
244protected:
245 afx_msg VARIANT OLE_GetSpellChecker ();
246 afx_msg void OLE_SetSpellChecker (VARIANT& newValue);
247
248private:
249 IDispatch* fSpellChecker;
250 COMBased_SpellCheckEngine fLedSpellCheckWrapper;
251
252private:
253 nonvirtual void ChangedSpellCheckerCOMObject ();
254
255 // Context Menu (and commands) support
256private:
257 CComPtr<IDispatch> fConextMenu;
258 CComPtr<IDispatch> fToolbarList;
259 CComPtr<IDispatch> fBuiltinCommands;
260 CComPtr<IDispatch> fPredefinedMenus;
261 CComPtr<IDispatch> fAcceleratorTable;
262
263protected:
264 afx_msg VARIANT OLE_GetContextMenu ();
265 afx_msg void OLE_SetContextMenu (VARIANT& newValue);
266 afx_msg VARIANT OLE_GetToolbarList ();
267 afx_msg void OLE_SetToolbarList (VARIANT& newValue);
268 afx_msg VARIANT OLE_GetBuiltinCommands ();
269 afx_msg VARIANT OLE_GetPredefinedMenus ();
270 afx_msg IDispatch* OLE_GetDefaultContextMenu ();
271 afx_msg IDispatch* OLE_GetDefaultAcceleratorTable ();
272 afx_msg IDispatch* OLE_MakeNewPopupMenuItem ();
273 afx_msg IDispatch* OLE_MakeNewUserMenuItem ();
274 afx_msg IDispatch* OLE_MakeNewAcceleratorElement ();
275 afx_msg void OLE_InvokeCommand (const VARIANT& command);
276 afx_msg BOOL OLE_CommandEnabled (const VARIANT& command);
277 afx_msg BOOL OLE_CommandChecked (const VARIANT& command);
278 afx_msg IDispatch* OLE_MakeNewToolbarList ();
279 nonvirtual CComPtr<IDispatch> MakeNewToolbar ();
280 afx_msg IDispatch* OLE_MakeNewToolbar ();
281 afx_msg IDispatch* OLE_MakeIconButtonToolbarItem ();
282 nonvirtual CComPtr<IDispatch> MakeSeparatorToolbarItem ();
283 afx_msg IDispatch* OLE_MakeSeparatorToolbarItem ();
284 nonvirtual CComPtr<IDispatch> MakeBuiltinToolbar (LPCOLESTR builtinToolbarName);
285 afx_msg IDispatch* OLE_MakeBuiltinToolbar (LPCOLESTR builtinToolbarName);
286 nonvirtual CComPtr<IDispatch> MakeBuiltinToolbarItem (LPCOLESTR builtinToolbarItemName);
287 afx_msg IDispatch* OLE_MakeBuiltinToolbarItem (LPCOLESTR builtinToolbarItemName);
288 afx_msg VARIANT OLE_GetAcceleratorTable ();
289 afx_msg void OLE_SetAcceleratorTable (VARIANT& newValue);
290
291private:
292 struct ToolBarIconSpec {
293 const TCHAR* fIconName;
294 int fIconResId;
295 const TCHAR* fCmdName;
296 IconButtonStyle fButtonStyle;
297 };
298 nonvirtual CComPtr<IDispatch> mkIconElement (int iconResID);
299 nonvirtual CComPtr<IDispatch> mkIconElement (const ToolBarIconSpec& s);
300 nonvirtual CComPtr<IDispatch> mkIconElement (int iconResID, CComPtr<IDispatch> cmdList);
301 nonvirtual CComPtr<IDispatch> MakeBuiltinComboBoxToolbarItem (CComPtr<IDispatch> cmdList);
302
303private:
304 nonvirtual HACCEL GetCurrentWin32AccelTable ();
305
306private:
307 HACCEL fWin32AccelTable;
308 Time::TimePointSeconds fLastAccelTableUpdateAt{}; // speed tweek
309
310protected:
311 afx_msg VARIANT OLE_GetCurrentEventArguments ();
312
313private:
314 CComPtr<IDispatch> fCurrentEventArguments;
315
316protected:
317 //selection-based APIs
318 afx_msg long GetSelStart ();
319 afx_msg void SetSelStart (long start);
320 afx_msg long GetSelLength ();
321 afx_msg void SetSelLength (long length);
322 afx_msg BSTR GetSelText ();
323 afx_msg void SetSelText (LPCTSTR text);
324 afx_msg BSTR GetSelTextAsRTF ();
325 afx_msg void SetSelTextAsRTF (LPCTSTR text);
326 afx_msg BSTR GetSelTextAsHTML ();
327 afx_msg void SetSelTextAsHTML (LPCTSTR text);
328 afx_msg OLE_COLOR GetSelColor ();
329 afx_msg void SetSelColor (OLE_COLOR color);
330 afx_msg BSTR GetSelFontFace ();
331 afx_msg void SetSelFontFace (LPCTSTR fontFace);
332 afx_msg long GetSelFontSize ();
333 afx_msg void SetSelFontSize (long size);
334 afx_msg long GetSelBold ();
335 afx_msg void SetSelBold (long bold);
336 afx_msg long GetSelItalic ();
337 afx_msg void SetSelItalic (long italic);
338 afx_msg long GetSelStrikeThru ();
339 afx_msg void SetSelStrikeThru (long strikeThru);
340 afx_msg long GetSelUnderline ();
341 afx_msg void SetSelUnderline (long underline);
342 afx_msg UINT OLE_GetSelJustification ();
343 afx_msg void OLE_SetSelJustification (UINT justification);
344 afx_msg UINT OLE_GetSelListStyle ();
345 afx_msg void OLE_SetSelListStyle (UINT listStyle);
346 afx_msg UINT OLE_GetSelHidable ();
347 afx_msg void OLE_SetSelHidable (UINT hidable);
348
349 afx_msg void AboutBox ();
350 afx_msg void LoadFile (LPCTSTR filename);
351 afx_msg void SaveFile (LPCTSTR filename);
352 afx_msg void SaveFileCRLF (LPCTSTR filename);
353 afx_msg void SaveFileRTF (LPCTSTR filename);
354 afx_msg void SaveFileHTML (LPCTSTR filename);
355 afx_msg void Refresh ();
356 afx_msg void ScrollToSelection ();
357
358 //UNDO support
359public:
360 afx_msg long OLE_GetMaxUndoLevel ();
361 afx_msg void OLE_SetMaxUndoLevel (long maxUndoLevel);
362 afx_msg BOOL OLE_GetCanUndo ();
363 afx_msg BOOL OLE_GetCanRedo ();
364 afx_msg void OLE_Undo ();
365 afx_msg void OLE_Redo ();
366 afx_msg void OLE_CommitUndo ();
367
368public:
369 afx_msg void OLE_LaunchFontSettingsDialog ();
370 afx_msg void OLE_LaunchParagraphSettingsDialog ();
371
372 // Find dialog
373public:
374 afx_msg void OLE_LaunchFindDialog ();
375 afx_msg long OLE_Find (long searchFrom, const VARIANT& findText, BOOL wrapSearch, BOOL wholeWordSearch, BOOL caseSensativeSearch);
376
377 // Replace dialog
378public:
379 afx_msg void OLE_LaunchReplaceDialog ();
380 afx_msg long OLE_FindReplace (long searchFrom, const VARIANT& findText, const VARIANT& replaceText, BOOL wrapSearch,
381 BOOL wholeWordSearch, BOOL caseSensativeSearch);
382
383 // Printing support
384public:
385 afx_msg void OLE_PrinterSetupDialog ();
386 afx_msg void OLE_PrintDialog ();
387 afx_msg void OLE_PrintOnce ();
388
389 // GetHeight
390public:
391 afx_msg long OLE_GetHeight (long from, long to);
392
393public:
394 afx_msg BOOL OLE_GetDirty ();
395 afx_msg void OLE_SetDirty (BOOL dirty);
396
397private:
398 bool fDataDirty; // keep separate flag - instead of using IsModfied/SetModifiedFlag () - cuz those set for other properties than the text (like control size etc). This is only for DOCUMENT data being dirty.
399
400 //LedItViewController callbacks
401public:
402 virtual void OnBrowseHelpCommand () override;
403 virtual void OnAboutBoxCommand () override;
404 virtual void ForceUIActive () override;
405 virtual void FireOLEEvent (DISPID eventID) override;
406 virtual void FireOLEEvent (DISPID dispid, BYTE* pbParams, ...) override;
407 virtual void FireUpdateUserCommand (const wstring& internalCmdName, VARIANT_BOOL* enabled, VARIANT_BOOL* checked, wstring* name) override;
408 virtual void FireUserCommand (const wstring& internalCmdName) override;
409#if qFunnyDisplayInDesignMode
410 virtual bool IsInDesignMode () const override;
411 virtual bool DrawExtraDesignModeBorder () const override;
412#endif
413 virtual HMENU GenerateContextMenu () override;
414
415protected:
416 DECLARE_DISPATCH_MAP ()
417 DECLARE_MESSAGE_MAP ()
418 DECLARE_EVENT_MAP ()
419
420private:
421 nonvirtual Led_FileFormat GuessFormatFromName (LPCTSTR name);
422 nonvirtual void DoReadFile (LPCTSTR filename, Memory::StackBuffer<char>* buffer, size_t* size);
423 nonvirtual void WriteBytesToFile (LPCTSTR filename, const void* buffer, size_t size);
424
425 // Dispatch and event IDs
426public:
427 LedItView fEditor;
428 StyledTextIO::HTMLInfo fHTMLInfo;
429};
430
431DISABLE_COMPILER_MSC_WARNING_END (4250) // inherits via dominance warning
432
433/*
434 ********************************************************************************
435 ***************************** Implementation Details ***************************
436 ********************************************************************************
437 */
438// class ActiveLedItControl::OnCreateExtras
439inline ActiveLedItControl::OnCreateExtras::OnCreateExtras ()
440 : fReadOnly (false)
441 , fEnabled (true)
442{
443}
444
445#endif /*__ActiveLedItControl_h__*/
time_point< RealtimeClock, DurationSeconds > TimePointSeconds
TimePointSeconds is a simpler approach to chrono::time_point, which doesn't require using templates e...
Definition Realtime.h:82