Stroika Library 3.0d21
 
Loading...
Searching...
No Matches
StdDialogs.cpp
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#include "Stroika/Frameworks/StroikaPreComp.h"
5
6#include <cstdio>
7
8#if qStroika_Foundation_Common_Platform_Windows
9#include <windows.h>
10
11#include <commdlg.h>
12#endif
13
16#include "Stroika/Foundation/Characters/LineEndings.h"
17#include "Stroika/Frameworks/Led/GDI.h"
18
19#include "StdDialogs.h"
20
21using namespace Stroika::Foundation;
22using namespace Stroika::Frameworks;
23using namespace Stroika::Frameworks::Led;
24
26
27namespace {
28 SDKString FormatINTAsString (int t)
29 {
30 return Characters::CString::Format (Led_SDK_TCHAROF ("%d"), t);
31 }
32 bool ParseStringToINT (const SDKString& s, int* t)
33 {
34#if 1
35 // get rid of this function - COULD do better API - but this is fine for how we currently use it...
36 // -- LGP 2012-09-19
38 *t = Characters::CString::String2Int<int> (s);
39 return true;
40#else
41 int l = 0;
42#if qTargetPlatformSDKUseswchar_t
43 if (::swscanf (s.c_str (), L"%d", &l) < 1) {
44 return false;
45 }
46 else {
47 *t = TWIPS{l};
48 return true;
49 }
50#else
51 if (::sscanf (s.c_str (), "%d", &l) < 1) {
52 return false;
53 }
54 else {
55 *t = TWIPS (l);
56 return true;
57 }
58#endif
59#endif
60 }
61 // Later revise these so they take into account UNITS - like CM, or IN, or TWIPS, or pt, etc...
62 SDKString FormatTWIPSAsString (TWIPS t)
63 {
64 return FormatINTAsString (t);
65 }
66 bool ParseStringToTWIPS (const SDKString& s, TWIPS* t)
67 {
68 int i = 0;
69 bool r = ParseStringToINT (s, &i);
70 if (r) {
71 *t = TWIPS{i};
72 }
73 return r;
74 }
75}
76
77/*
78 ********************************************************************************
79 ******************************* StdColorPopupHelper ****************************
80 ********************************************************************************
81 */
82StdColorPopupHelper::StdColorPopupHelper (bool allowNone)
83 : fIsSelectedColor{allowNone}
84 , fAllowNone{allowNone}
85#if qStroika_Foundation_Common_Platform_Windows
86 , fHWnd{NULL}
87#endif
88{
90 [[maybe_unused]] size_t offset = fAllowNone ? 1 : 0;
91 for (size_t i = 0; i < 16; ++i) {
92 Assert (MapColorIdx (MapColorIdx (i + offset)) == i + offset);
93 }
94 }
95}
96StdColorPopupHelper::~StdColorPopupHelper ()
97{
98}
99
100bool StdColorPopupHelper::GetSelectedColor (Color* c) const
101{
102 if (fIsSelectedColor and c != NULL) {
103 *c = fSelectedColor;
104 }
105 return fIsSelectedColor;
106}
107
108void StdColorPopupHelper::SetSelectedColor (const Color& c)
109{
110 fSelectedColor = c;
111 fIsSelectedColor = true;
112#if qStroika_Foundation_Common_Platform_Windows
113 if (fHWnd != NULL) {
114 Verify (::SendMessage (fHWnd, CB_SETCURSEL, MapColorIdx (c), 0) != CB_ERR);
115 }
116#endif
117}
118
119void StdColorPopupHelper::SetNoSelectedColor ()
120{
121 Require (fAllowNone);
122 fIsSelectedColor = false;
123#if qStroika_Foundation_Common_Platform_Windows
124 if (fHWnd != NULL) {
125 Verify (::SendMessage (fHWnd, CB_SETCURSEL, 0, 0) != CB_ERR);
126 }
127#endif
128}
129
130size_t StdColorPopupHelper::MapColorIdx (const Color& c) const
131{
132 size_t offset = fAllowNone ? 1 : 0;
133 if (c == Color::kBlack) {
134 return offset + 0;
135 };
136 if (c == Color::kMaroon) {
137 return offset + 1;
138 };
139 if (c == Color::kGreen) {
140 return offset + 2;
141 };
142 if (c == Color::kOlive) {
143 return offset + 3;
144 };
145 if (c == Color::kNavyBlue) {
146 return offset + 4;
147 };
148 if (c == Color::kPurple) {
149 return offset + 5;
150 };
151 if (c == Color::kTeal) {
152 return offset + 6;
153 };
154 if (c == Color::kGray) {
155 return offset + 7;
156 };
157 if (c == Color::kSilver) {
158 return offset + 8;
159 };
160 if (c == Color::kRed) {
161 return offset + 9;
162 };
163 if (c == Color::kLimeGreen) {
164 return offset + 10;
165 };
166 if (c == Color::kYellow) {
167 return offset + 11;
168 };
169 if (c == Color::kBlue) {
170 return offset + 12;
171 };
172 if (c == Color::kFuchsia) {
173 return offset + 13;
174 };
175 if (c == Color::kAqua) {
176 return offset + 14;
177 };
178 if (c == Color::kWhite) {
179 return offset + 15;
180 };
181 return offset + 16; // OTHER
182}
183
184Color StdColorPopupHelper::MapColorIdx (size_t i) const
185{
186 size_t offset = fAllowNone ? 1 : 0;
187 switch (i - offset) {
188 case 0:
189 return Color::kBlack;
190 case 1:
191 return Color::kMaroon;
192 case 2:
193 return Color::kGreen;
194 case 3:
195 return Color::kOlive;
196 case 4:
197 return Color::kNavyBlue;
198 case 5:
199 return Color::kPurple;
200 case 6:
201 return Color::kTeal;
202 case 7:
203 return Color::kGray;
204 case 8:
205 return Color::kSilver;
206 case 9:
207 return Color::kRed;
208 case 10:
209 return Color::kLimeGreen;
210 case 11:
211 return Color::kYellow;
212 case 12:
213 return Color::kBlue;
214 case 13:
215 return Color::kFuchsia;
216 case 14:
217 return Color::kAqua;
218 case 15:
219 return Color::kWhite;
220 default:
221 Assert (false);
222 return Color::kBlack;
223 }
224}
225
226#if qStroika_Foundation_Common_Platform_Windows
227void StdColorPopupHelper::Attach (HWND popup)
228{
229 Require (fHWnd == NULL);
230 RequireNotNull (popup);
231 Require (::IsWindow (popup));
232 fHWnd = popup;
233 (void)::SendMessage (popup, CB_RESETCONTENT, 0, 0);
234 DoMenuAppends ();
235}
236#endif
237
238#if qStroika_Foundation_Common_Platform_Windows
239void StdColorPopupHelper::OnSelChange ()
240{
241#if qStroika_Foundation_Common_Platform_Windows
242 Require (::IsWindow (fHWnd));
243 int r = static_cast<int> (::SendMessage (fHWnd, CB_GETCURSEL, 0, 0));
244#endif
245
246 int otherIdx = fAllowNone ? 17 : 16;
247 if (fAllowNone and r == 0) {
248 SetNoSelectedColor ();
249 }
250 else if (r == otherIdx) {
251 StdColorPickBox colorPicker (fSelectedColor);
252 if (colorPicker.DoModal ()) {
253 SetSelectedColor (colorPicker.fColor);
254 }
255 }
256 else {
257 Color c = MapColorIdx (r);
258 SetSelectedColor (c);
259 }
260}
261#endif
262
263#if qStroika_Foundation_Common_Platform_Windows
264void StdColorPopupHelper::DoMenuAppends ()
265{
266 if (fAllowNone) {
267 AppendMenuString (Led_SDK_TCHAROF (""));
268 }
269 AppendMenuString (Led_SDK_TCHAROF ("Black"));
270 AppendMenuString (Led_SDK_TCHAROF ("Maroon"));
271 AppendMenuString (Led_SDK_TCHAROF ("Green"));
272 AppendMenuString (Led_SDK_TCHAROF ("Olive"));
273 AppendMenuString (Led_SDK_TCHAROF ("Navy"));
274 AppendMenuString (Led_SDK_TCHAROF ("Purple"));
275 AppendMenuString (Led_SDK_TCHAROF ("Teal"));
276 AppendMenuString (Led_SDK_TCHAROF ("Gray"));
277 AppendMenuString (Led_SDK_TCHAROF ("Silver"));
278 AppendMenuString (Led_SDK_TCHAROF ("Red"));
279 AppendMenuString (Led_SDK_TCHAROF ("Lime"));
280 AppendMenuString (Led_SDK_TCHAROF ("Yellow"));
281 AppendMenuString (Led_SDK_TCHAROF ("Blue"));
282 AppendMenuString (Led_SDK_TCHAROF ("Fuchsia"));
283 AppendMenuString (Led_SDK_TCHAROF ("Aqua"));
284 AppendMenuString (Led_SDK_TCHAROF ("White"));
285 AppendMenuString (Led_SDK_TCHAROF ("Other..."));
286}
287#endif
288
289#if qStroika_Foundation_Common_Platform_Windows
290void StdColorPopupHelper::AppendMenuString (const SDKString& s)
291{
292#if qStroika_Foundation_Common_Platform_Windows
293 Require (::IsWindow (fHWnd));
294 Verify (::SendMessage (fHWnd, CB_ADDSTRING, 0, reinterpret_cast<LPARAM> (s.c_str ())) != CB_ERR);
295#endif
296}
297#endif
298
299#if qSupportLedDialogWidgets
300/*
301 ********************************************************************************
302 ********************************* LedDialogWidget ******************************
303 ********************************************************************************
304 */
305LedDialogWidget::LedDialogWidget ()
306 : inherited ()
307 , fTextStore ()
308{
309 SetDefaultWindowMargins (TWIPS_Rect (TWIPS::kPoint, TWIPS::kPoint, TWIPS::kPoint, TWIPS::kPoint));
310 SpecifyTextStore (&fTextStore);
311 SetCommandHandler (&fCommandHandler);
312}
313
314LedDialogWidget::LedDialogWidget (TS_SET_OUTSIDE_BWA)
315 : inherited ()
316 , fTextStore ()
317{
318 SetDefaultWindowMargins (TWIPS_Rect (TWIPS::kPoint, TWIPS::kPoint, TWIPS::kPoint, TWIPS::kPoint));
319 SetCommandHandler (&fCommandHandler);
320}
321
322LedDialogWidget::~LedDialogWidget ()
323{
324 SetCommandHandler (NULL);
325 SpecifyTextStore (NULL);
326}
327
328/*
329@METHOD: LedDialogWidget::OnBadUserInput
330@DESCRIPTION: <p>Override @'TextInteractor::OnBadUserInputn' - to just beep - not throw (cuz a throw messes up dialogs).</p>
331*/
332void LedDialogWidget::OnBadUserInput ()
333{
334 Led_BeepNotify ();
335}
336
337void LedDialogWidget::OnTypedNormalCharacter (Led_tChar theChar, bool optionPressed, bool shiftPressed, bool commandPressed,
338 bool controlPressed, bool altKeyPressed)
339{
340 CommandNumber c = CharToCommand (theChar);
341 if (c == 0) {
342 inherited::OnTypedNormalCharacter (theChar, optionPressed, shiftPressed, commandPressed, controlPressed, altKeyPressed);
343 }
344 else {
345 OnPerformCommand (c);
346 }
347}
348
349LedDialogWidget::CommandNumber LedDialogWidget::CharToCommand (Led_tChar theChar) const
350{
351#define CNTRL(x) (x - 'a' + 1)
352 switch (theChar) {
353 case CNTRL ('a'):
354 return kSelectAll_CmdID;
355 case CNTRL ('c'):
356 return kCopy_CmdID;
357 case CNTRL ('v'):
358 return kPaste_CmdID;
359 case CNTRL ('x'):
360 return kCut_CmdID;
361 case CNTRL ('z'):
362 return kUndo_CmdID;
363 default:
364 return 0;
365 }
366#undef CNTRL
367}
368
369Led_tString LedDialogWidget::GetText () const
370{
371 size_t len = GetLength ();
372 StackBuffer<Led_tChar> buf{Memory::eUninitialized, len + 1};
373 CopyOut (0, len, buf.data ());
374 buf[len] = '\0';
375 size_t len2 = 2 * len + 1;
376 StackBuffer<Led_tChar> buf2{Memory::eUninitialized, len2};
377 len2 = Characters::NLToNative<Led_tChar> (buf.data (), len, buf2.data (), len2);
378 buf2[len2] = '\0';
379 return Led_tString{buf2.data ()};
380}
381
382void LedDialogWidget::SetText (const Led_tString& t)
383{
384 size_t len = t.length ();
385 StackBuffer<Led_tChar> buf{Memory::eUninitialized, len};
386 len = Characters::NormalizeTextToNL<Led_tChar> (t.c_str (), len, buf.data (), len);
387 Replace (0, GetEnd (), buf.data (), len);
388}
389#endif
390
391#if qSupportLedDialogWidgets
392/*
393 ********************************************************************************
394 ************************** LedComboBoxWidget::MyButton *************************
395 ********************************************************************************
396 */
397LedComboBoxWidget::MyButton::MyButton ()
398 : fComboBox (NULL)
399 , fDropDownArrow ()
400{
401#if qStroika_Foundation_Common_Platform_Windows
402// In case compiled without #define OEMRESOURCE
403#ifndef OBM_COMBO
404#define OBM_COMBO 32738
405#endif
406 fDropDownArrow.LoadBitmap (NULL, MAKEINTRESOURCE (OBM_COMBO));
407#endif
408}
409
410#if qStroika_Foundation_Common_Platform_Windows
411LRESULT LedComboBoxWidget::MyButton::WndProc (UINT message, WPARAM wParam, LPARAM lParam)
412{
413 switch (message) {
414 case WM_SETFOCUS: {
415 AssertNotNull (fComboBox);
416 ::SetFocus (fComboBox->fTextWidget.GetHWND ());
417 return 0;
418 }
419 case WM_LBUTTONDOWN: {
420 SendMessage (BM_SETSTYLE, BS_BITMAP, true); // for some reason - clicking on this button sets the BS_DEFPUSHBUTTON style - which looks bad,
421 // and is even worse for the fact that its only set after the first click on the button.
422 // Just unset it... LGP 2003-12-28
423 AssertNotNull (fComboBox);
424 fComboBox->TogglePopupShown ();
425 }
426 default:
427 return inherited::WndProc (message, wParam, lParam);
428 }
429}
430#endif
431
432#endif
433
434#if qSupportLedDialogWidgets
435/*
436 ********************************************************************************
437 ****************** LedComboBoxWidget::MyComboListBoxPopup **********************
438 ********************************************************************************
439 */
440
441LedComboBoxWidget::MyComboListBoxPopup::MyComboListBoxPopup ()
442 : fComboBox (NULL)
443{
444}
445
446#if qStroika_Foundation_Common_Platform_Windows
447LRESULT LedComboBoxWidget::MyComboListBoxPopup::WndProc (UINT message, WPARAM wParam, LPARAM lParam)
448{
449 switch (message) {
450 case WM_CHAR: {
451 if (wParam == '\t') {
452 SendMessage (WM_NEXTDLGCTL, !!(::GetKeyState (VK_SHIFT) & 0x8000), false);
453 return 0; // return zero to indicate processed the message
454 }
455 else if (wParam == VK_RETURN) {
456 MadeSelection ();
457 return 0; // to indicate proceessed the message
458 }
459 else {
460 return inherited::WndProc (message, wParam, lParam);
461 }
462 }
463 case WM_MOUSEMOVE: {
464 /*
465 * As the mosue moves over the control - automatically select the item (like a menu behaivor)
466 */
467 LRESULT dw = SendMessage (LB_ITEMFROMPOINT, 0, lParam);
468 if (not HIWORD (dw)) {
469 int pos = LOWORD (dw);
470 Verify (SendMessage (LB_SETCURSEL, pos, 0) != LB_ERR);
471 }
472 return 0; // to indicate proceessed the message
473 }
474 case WM_LBUTTONDOWN: {
475 /*
476 * Treat a click as a selection and close the popup.
477 */
478 Led_Rect clientRect;
479 {
480 RECT cr;
481 ::GetClientRect (GetHWND (), &cr);
482 clientRect = AsLedRect (cr);
483 }
484
485#ifndef GET_X_LPARAM
486#define GET_X_LPARAM(lParam) ((int)(short)LOWORD (lParam))
487#endif
488#ifndef GET_Y_LPARAM
489#define GET_Y_LPARAM(lParam) ((int)(short)HIWORD (lParam))
490#endif
491 if (clientRect.Contains (Led_Point (GET_Y_LPARAM (lParam), GET_X_LPARAM (lParam)))) {
492 MadeSelection ();
493 }
494 AssertNotNull (fComboBox);
495 fComboBox->HidePopup ();
496 return 0; // to indicate proceessed the message
497 }
498 case WM_KILLFOCUS: {
499 LRESULT lr = inherited::WndProc (message, wParam, lParam);
500 AssertNotNull (fComboBox);
501 fComboBox->HidePopup ();
502 return lr;
503 }
504 default:
505 return inherited::WndProc (message, wParam, lParam);
506 }
507}
508#endif
509
510void LedComboBoxWidget::MyComboListBoxPopup::UpdatePopupItems ()
511{
512 RequireNotNull (fComboBox);
513 if (IsWindowRealized ()) {
514 SendMessage (LB_RESETCONTENT, 0, 0);
515 bool usingUNICODEWnd = IsWindowUNICODE ();
516 for (auto i = fComboBox->fPopupItems.begin (); i != fComboBox->fPopupItems.end (); ++i) {
517 if (usingUNICODEWnd) {
518 SendMessage (LB_ADDSTRING, 0, reinterpret_cast<LPARAM> (Led_tString2WideString (*i).c_str ()));
519 }
520 else {
521 SendMessage (LB_ADDSTRING, 0, reinterpret_cast<LPARAM> (Led_tString2SDKString (*i).c_str ()));
522 }
523 }
524 }
525}
526
527void LedComboBoxWidget::MyComboListBoxPopup::MadeSelection ()
528{
529 RequireNotNull (fComboBox);
530 LRESULT curSelRel = SendMessage (LB_GETCURSEL, 0, 0);
531 if (curSelRel != LB_ERR) {
532 size_t curSel = static_cast<size_t> (curSelRel);
533 if (curSel < fComboBox->fPopupItems.size ()) {
534 fComboBox->fTextWidget.SetText (fComboBox->fPopupItems[curSel]);
535 fComboBox->SendMessage (EM_SETSEL, 0, -1);
536 }
537 }
538 fComboBox->HidePopup ();
539}
540
541void LedComboBoxWidget::MyComboListBoxPopup::ComputePreferedHeight (DistanceType* prefHeight, size_t* nEltsShown) const
542{
543 RequireNotNull (prefHeight);
544 RequireNotNull (nEltsShown);
545 // Should tune this code to take into account popup position, and height of screen (so not offscreen)
546 const size_t kMaxElts = 10; // don't show more than this - use scrollbar...
547 RequireNotNull (fComboBox);
548 size_t nElts = fComboBox->fPopupItems.size ();
549 if (nElts == 0) {
550 nElts = 1;
551 }
552 if (nElts >= kMaxElts) {
553 nElts = kMaxElts;
554 }
555 DistanceType singleEltHeight = static_cast<DistanceType> (::SendMessage (GetHWND (), LB_GETITEMHEIGHT, 0, 0));
556 constexpr DistanceType kEmpiricalKludge = 2; // LGP 2003-12-28
557 *prefHeight = static_cast<DistanceType> (nElts * singleEltHeight + kEmpiricalKludge);
558 *nEltsShown = nElts;
559}
560#endif
561
562#if qSupportLedDialogWidgets
563/*
564 ********************************************************************************
565 *********************** LedComboBoxWidget::MyTextWidget ************************
566 ********************************************************************************
567 */
568LedComboBoxWidget::MyTextWidget::MyTextWidget ()
569 : inherited (eTS_SET_OUTSIDE_BWA)
570 , fComboBox (NULL)
571{
572 SpecifyTextStore (&fTextStore);
573}
574
575LedComboBoxWidget::MyTextWidget::~MyTextWidget ()
576{
577 SpecifyTextStore (NULL);
578}
579
580#if qStroika_Foundation_Common_Platform_Windows
581LRESULT LedComboBoxWidget::MyTextWidget::WndProc (UINT message, WPARAM wParam, LPARAM lParam)
582{
583 switch (message) {
584 case WM_KEYDOWN: {
585 AssertNotNull (fComboBox);
586 if (wParam == VK_UP or wParam == VK_DOWN) {
587 fComboBox->ShowPopup ();
588 return fComboBox->fComboListBoxPopup.SendMessage (message, wParam, lParam);
589 }
590 return inherited::WndProc (message, wParam, lParam);
591 }
592 case WM_CHAR: {
593 AssertNotNull (fComboBox);
594 // Not called - unfortunately - with MFC - cuz the PreTranslateMessage () maps the ESC key to a CANCEL message
595 // before the event makes it here - LGP 2003-12-27
596 if (wParam == VK_ESCAPE) {
597 fComboBox->HidePopup ();
598 return 0; // to indicate message processed
599 }
600 return inherited::WndProc (message, wParam, lParam);
601 }
602 default:
603 return inherited::WndProc (message, wParam, lParam);
604 }
605}
606#endif
607#endif
608
609#if qSupportLedDialogWidgets
610/*
611 ********************************************************************************
612 ******************************* LedComboBoxWidget ******************************
613 ********************************************************************************
614 */
615LedComboBoxWidget::LedComboBoxWidget ()
616 : fPopupButton ()
617 , fComboListBoxPopup ()
618 , fTextWidget ()
619 , fUseWidgetFont (NULL)
620{
621 fPopupButton.fComboBox = this;
622 fComboListBoxPopup.fComboBox = this;
623 fTextWidget.fComboBox = this;
624}
625
626LedComboBoxWidget::~LedComboBoxWidget ()
627{
628 delete fUseWidgetFont;
629}
630
631#if qStroika_Foundation_Common_Platform_Windows
632bool LedComboBoxWidget::ReplaceWindow (HWND hWnd)
633{
634 Require (GetHWND () == NULL); // don't call after already created! - use this instead of SetHWnd ()!!!
635 RequireNotNull (hWnd);
636 Require (::IsWindow (hWnd));
637
638 HWND parent = ::GetParent (hWnd);
639 int id = ::GetWindowLong (hWnd, GWL_ID);
640 Assert (hWnd == ::GetDlgItem (parent, id));
641
642 DWORD dwStyle = ::GetWindowLong (hWnd, GWL_STYLE);
643 DWORD exStyle = ::GetWindowLong (hWnd, GWL_EXSTYLE);
644
645 // Assume previous widget's position.
646 WINDOWPLACEMENT wp;
647 (void)::memset (&wp, 0, sizeof (wp));
648 wp.length = sizeof (wp);
649 Verify (::GetWindowPlacement (hWnd, &wp));
650
651 // Save (clone since we destory HWND before we use the set it into the new object) HFONT object,
652 // so we can set it into our new control at the end of this procedure.
653 bool useNonSysFont = false;
654 FontObject nonSysFont;
655 {
656 HFONT hFont = NULL;
657 if ((hFont = (HFONT)::SendMessage (hWnd, WM_GETFONT, 0, 0L)) != NULL) {
658 LOGFONT useFont;
659 if (::GetObject (hFont, sizeof (LOGFONT), &useFont) != 0) {
660 Verify (nonSysFont.CreateFontIndirect (&useFont));
661 useNonSysFont = true;
662 }
663 }
664 }
665
666 // Delete the old widget window.
667 ::DestroyWindow (hWnd);
668
669 DISABLE_COMPILER_MSC_WARNING_START (4312)
670 Create (exStyle, NULL, NULL, dwStyle | WS_TABSTOP | WS_CHILD, wp.rcNormalPosition.left, wp.rcNormalPosition.top,
671 wp.rcNormalPosition.right - wp.rcNormalPosition.left, wp.rcNormalPosition.bottom - wp.rcNormalPosition.top, parent, (HMENU)id, NULL);
672 DISABLE_COMPILER_MSC_WARNING_END (4312)
673
674 /*
675 * Copy the font value from the original widget and set it into the replaced one.
676 */
677 (void)SendMessage (WM_SETFONT, useNonSysFont ? reinterpret_cast<WPARAM> (static_cast<HFONT> (nonSysFont)) : NULL, false);
678 return true;
679}
680#endif
681
682Led_tString LedComboBoxWidget::GetText () const
683{
684 return fTextWidget.GetText ();
685}
686
687void LedComboBoxWidget::SetText (const Led_tString& t)
688{
689 fTextWidget.SetText (t);
690}
691
692void LedComboBoxWidget::SetPopupItems (const vector<Led_tString>& pi)
693{
694 fPopupItems = pi;
695 fComboListBoxPopup.UpdatePopupItems ();
696}
697
698#if qStroika_Foundation_Common_Platform_Windows
699LRESULT LedComboBoxWidget::WndProc (UINT message, WPARAM wParam, LPARAM lParam)
700{
701 switch (message) {
702 case WM_SETFOCUS: {
703 (void)::SetFocus (fTextWidget.GetHWND ());
704 return 0;
705 }
706 case WM_GETFONT: {
707 return fUseWidgetFont == NULL ? NULL : reinterpret_cast<LRESULT> (static_cast<HFONT> (*fUseWidgetFont));
708 }
709 case WM_SETFONT: {
710 delete fUseWidgetFont;
711 fUseWidgetFont = NULL;
712
713 HFONT copyFont = reinterpret_cast<HFONT> (wParam);
714 if (copyFont != NULL) {
715 LOGFONT useFont;
716 if (::GetObject (copyFont, sizeof (LOGFONT), &useFont) != 0) {
717 Assert (fUseWidgetFont == NULL);
718 fUseWidgetFont = new FontObject ();
719 Verify (fUseWidgetFont->CreateFontIndirect (&useFont));
720 }
721 }
722
723 HFONT fontToPassDown = fUseWidgetFont == NULL ? NULL : static_cast<HFONT> (*fUseWidgetFont);
724 (void)fPopupButton.SendMessage (WM_SETFONT, reinterpret_cast<WPARAM> (fontToPassDown), lParam);
725 (void)::SendMessage (fTextWidget.GetHWND (), WM_SETFONT, reinterpret_cast<WPARAM> (fontToPassDown), lParam);
726 (void)fComboListBoxPopup.SendMessage (WM_SETFONT, reinterpret_cast<WPARAM> (fontToPassDown), lParam);
727 return 0;
728 }
729 case WM_CREATE: {
730 return OnCreate_Msg (wParam, lParam);
731 }
732 case WM_SIZE: {
733 return OnSize_Msg (wParam, lParam);
734 }
735 // Forward these to the text widget only
736 case EM_GETSEL:
737 case EM_SETSEL:
738 case WM_GETDLGCODE:
739 case WM_GETTEXT:
740 case WM_SETTEXT:
741 case WM_GETTEXTLENGTH: {
742 return ::SendMessage (fTextWidget.GetHWND (), message, wParam, lParam);
743 }
744 // Forward these to all widgets
745 case WM_ENABLE: {
746 LRESULT lr = inherited::WndProc (message, wParam, lParam);
747 (void)fPopupButton.SendMessage (message, wParam, lParam);
748 (void)::SendMessage (fTextWidget.GetHWND (), message, wParam, lParam);
749 (void)fComboListBoxPopup.SendMessage (message, wParam, lParam);
750 return lr;
751 }
752 default:
753 return inherited::WndProc (message, wParam, lParam);
754 }
755}
756
757LRESULT LedComboBoxWidget::OnCreate_Msg (WPARAM wParam, LPARAM lParam)
758{
759 LRESULT lr = inherited::WndProc (WM_CREATE, wParam, lParam);
760 if (lr == 0) {
761 int id = ::GetWindowLong (GetHWND (), GWL_ID);
762 DWORD dwStyle = ::GetWindowLong (GetHWND (), GWL_STYLE);
763
764 // Shrink it slightly to make room for the popup control
765 DISABLE_COMPILER_MSC_WARNING_START (4312)
766 fTextWidget.Create (0, NULL, NULL, dwStyle | WS_VISIBLE | WS_CHILD | WS_TABSTOP, 0, 0, 0, 0, GetHWND (), (HMENU)id, NULL);
767 DISABLE_COMPILER_MSC_WARNING_END (4312)
768
769 // Next - create the POPUP BUTTON
770 fPopupButton.SubclassWindow (
771 ::CreateWindowEx (0, _T("BUTTON"), _T (""), WS_CHILD | WS_VISIBLE | BS_BITMAP, 0, 0, 0, 0, GetHWND (), NULL, NULL, NULL));
772 fPopupButton.SendMessage (BM_SETIMAGE, static_cast<WPARAM> (IMAGE_BITMAP),
773 reinterpret_cast<LPARAM> (static_cast<HBITMAP> (fPopupButton.fDropDownArrow)));
774
775 // Next - create the POPUP Listbox (hidden initially)
776 {
777#if !qTargetPlatformSDKUseswchar_t
778 // Try creating a UNICODE popup window - even if we aren't building a UNICODE app. This is OK - since this window isn't
779 // handled directly through MFC (which doesn't support UNICODE windows in non-UNICODE apps, but just through
780 // Led's code directly - which does support this - LGP 2003-12-29
781 HWND uniWnd = ::CreateWindowExW (WS_EX_TOPMOST, L"ListBox", NULL, WS_POPUP | LBS_NOTIFY | WS_BORDER | WS_TABSTOP, 0, 0, 0, 0,
782 GetHWND (), NULL, NULL, NULL);
783 if (uniWnd != NULL) {
784 fComboListBoxPopup.SubclassWindow (uniWnd);
785 goto alreadyCreated;
786 }
787#endif
788 fComboListBoxPopup.SubclassWindow (::CreateWindowEx (WS_EX_TOPMOST, _T("ListBox"), NULL, WS_POPUP | LBS_NOTIFY | WS_BORDER | WS_TABSTOP,
789 0, 0, 0, 0, GetHWND (), NULL, NULL, NULL));
790#if !qTargetPlatformSDKUseswchar_t
791 alreadyCreated:;
792#endif
793 }
794 fComboListBoxPopup.UpdatePopupItems ();
795 }
796 return lr;
797}
798
799LRESULT LedComboBoxWidget::OnSize_Msg (WPARAM wParam, LPARAM lParam)
800{
801 const DistanceType kPopupIconWidth = fPopupButton.fDropDownArrow.GetImageSize ().h + 4;
802
803 Led_Rect clientRect;
804 {
805 RECT cr;
806 ::GetClientRect (GetHWND (), &cr);
807 clientRect = AsLedRect (cr);
808 }
809
810 // Shrink it slightly to make room for the popup control
811 Verify (::MoveWindow (fTextWidget.GetHWND (), clientRect.left, clientRect.top, clientRect.GetWidth () - kPopupIconWidth,
812 clientRect.GetHeight (), true));
813 // Next - the POPUP BUTTON
814 Verify (::MoveWindow (fPopupButton.GetHWND (), clientRect.right - kPopupIconWidth, clientRect.top, kPopupIconWidth, clientRect.GetHeight (), true));
815 return inherited::WndProc (WM_SIZE, wParam, lParam);
816}
817#endif
818
819void LedComboBoxWidget::ShowPopup ()
820{
821 if (not PopupShown ()) {
822 // Set initial value based on current combo box text
823 vector<Led_tString>::const_iterator i = find (fPopupItems.begin (), fPopupItems.end (), GetText ());
824 if (i == fPopupItems.end ()) {
825 fComboListBoxPopup.SendMessage (LB_SETCURSEL, static_cast<WPARAM> (-1), 0); // none
826 }
827 else {
828 fComboListBoxPopup.SendMessage (LB_SETCURSEL, static_cast<WPARAM> (i - fPopupItems.begin ()), 0);
829 }
830 }
831
832 // Must place the window each time popped up - since the parent could have been moved (esp in global
833 // coordinates)
834 {
835 POINT zero; // convert popup position to screen coordinates...
836 (void)::memset (&zero, 0, sizeof (zero));
837 Verify (::ClientToScreen (::GetParent (GetHWND ()), &zero));
838 Led_Rect clientRect;
839 {
840 RECT cr;
841 ::GetClientRect (GetHWND (), &cr);
842 clientRect = AsLedRect (cr);
843 }
844 DistanceType prefHeight = 0;
845 size_t nEltsShown = 0;
846 fComboListBoxPopup.ComputePreferedHeight (&prefHeight, &nEltsShown);
847
848 if (nEltsShown >= fPopupItems.size ()) {
849 ::SetWindowLong (fComboListBoxPopup.GetHWND (), GWL_STYLE, ::GetWindowLong (fComboListBoxPopup.GetHWND (), GWL_STYLE) & ~WS_VSCROLL);
850 }
851 else {
852 ::SetWindowLong (fComboListBoxPopup.GetHWND (), GWL_STYLE, ::GetWindowLong (fComboListBoxPopup.GetHWND (), GWL_STYLE) | WS_VSCROLL);
853 }
854
855 WINDOWPLACEMENT wp;
856 (void)::memset (&wp, 0, sizeof (wp));
857 wp.length = sizeof (wp);
858 Verify (::GetWindowPlacement (GetHWND (), &wp));
859 Verify (::MoveWindow (fComboListBoxPopup.GetHWND (), wp.rcNormalPosition.left + zero.x, wp.rcNormalPosition.bottom + zero.y,
860 clientRect.GetWidth (), prefHeight, false));
861 }
862
863 /*
864 * Subtle points. We show the window with SW_SHOWNOACTIVEATE so the combobox text
865 * box is still shown activated and so the parent dialog is not deactivated.
866 * Note that thats a logical requiement - just what MS Windows does.
867 *
868 * Also - we do a SetCapture (which we release in HidePopup) so that we can catch any
869 * mouse clicks outside of our window - and hide the popup in that case. Again - this is really
870 * just mimicking the MS Windows UI behavior.
871 */
872 (void)::ShowWindow (fComboListBoxPopup.GetHWND (), SW_SHOWNOACTIVATE);
873 (void)::SetCapture (fComboListBoxPopup.GetHWND ());
874}
875
876void LedComboBoxWidget::HidePopup ()
877{
878 if (::GetCapture () == fComboListBoxPopup.GetHWND ()) {
879 Verify (::ReleaseCapture ());
880 }
881 fComboListBoxPopup.SetWindowVisible (false);
882}
883
884bool LedComboBoxWidget::PopupShown () const
885{
886 return fComboListBoxPopup.IsWindowShown ();
887}
888
889void LedComboBoxWidget::TogglePopupShown ()
890{
891 if (PopupShown ()) {
892 HidePopup ();
893 }
894 else {
895 ShowPopup ();
896 }
897}
898#endif
899
900/*
901 ********************************************************************************
902 ********************************* Led_StdDialogHelper **************************
903 ********************************************************************************
904 */
905#if qStroika_Foundation_Common_Platform_Windows
906Led_StdDialogHelper::Led_StdDialogHelper (HINSTANCE hInstance, const Characters::SDKChar* resID, HWND parentWnd)
907 : fSetFocusItemCalled{false}
908{
909 fHWnd = NULL;
910 fHINSTANCE = hInstance;
911 fResID = resID;
912 fParentWnd = parentWnd;
913 fWasOK = false;
914}
915#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
916Led_StdDialogHelper::Led_StdDialogHelper (GtkWindow* parentWindow)
917 : fWindow{NULL}
918 , fParentWindow{parentWindow}
919 , fOKButton{NULL}
920 , fCancelButton{NULL}
921 , fWasOK{false}
922{
923}
924#endif
925
926Led_StdDialogHelper::~Led_StdDialogHelper ()
927{
928#if qStroika_Foundation_Common_Platform_Windows
929 if (GetHWND () != NULL) {
930 // maybe did a throw out of the scope where this object was declared? Anyhow - blow away the window!
931 ::DestroyWindow (GetHWND ());
932 }
933#endif
934}
935
936bool Led_StdDialogHelper::GetWasOK () const
937{
938 return fWasOK;
939}
940
941bool Led_StdDialogHelper::DoModal ()
942{
943#if qStroika_Foundation_Common_Platform_Windows
944 HWND oldFocusWnd = ::GetFocus ();
945#if qNO_INT_PTR_DefinedCompilerBug
946 using INT_PTR = int;
947#endif
948 [[maybe_unused]] INT_PTR x =
949 ::DialogBoxParam (fHINSTANCE, fResID, fParentWnd, reinterpret_cast<DLGPROC> (StaticDialogProc), reinterpret_cast<LPARAM> (this));
950 if (oldFocusWnd != NULL) {
951 ::SetFocus (oldFocusWnd);
952 }
953#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
954 /* create the main window, and attach delete_event signal to terminating
955 the application */
956 GtkWidget* window = MakeWindow ();
957 SetWindow (window);
958
959 PreDoModalHook ();
960 gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (fParentWindow));
961 gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER_ALWAYS); // or GTK_WIN_POS_CENTER?
962 gtk_window_set_modal (GTK_WINDOW (window), true);
963 gtk_widget_show (window);
964
965 gtk_signal_connect_after (GTK_OBJECT (window), "delete_event", GTK_SIGNAL_FUNC (Static_OnWindowDeleteRequest), (gpointer)this);
966
967 if (fOKButton != NULL) {
968 gtk_signal_connect (GTK_OBJECT (fOKButton), "clicked", GTK_SIGNAL_FUNC (Static_OnOKButtonClick), (gpointer)this);
969 gtk_widget_show (fOKButton);
970 }
971 if (fCancelButton != NULL) {
972 gtk_signal_connect (GTK_OBJECT (fCancelButton), "clicked", GTK_SIGNAL_FUNC (Static_OnCancelButtonClick), (gpointer)this);
973 gtk_widget_show (fCancelButton);
974 }
975 gtk_main ();
976 gtk_widget_destroy (window);
977#endif
978 return GetWasOK ();
979}
980
981void Led_StdDialogHelper::ReplaceAllTokens (SDKString* m, const SDKString& token, const SDKString& with)
982{
983 using Characters::String;
984 RequireNotNull (m);
985 *m = String::FromSDKString (*m).ReplaceAll (String::FromSDKString (token), String::FromSDKString (with)).AsSDKString ();
986}
987
988void Led_StdDialogHelper::PreDoModalHook ()
989{
990}
991
992#if qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
993GtkWidget* Led_StdDialogHelper::MakeWindow ()
994{
995 // return gtk_window_new (GTK_WINDOW_TOPLEVEL);
996 return gtk_dialog_new ();
997}
998#endif
999
1000#if qStroika_Foundation_Common_Platform_Windows
1001BOOL Led_StdDialogHelper::OnInitDialog ()
1002{
1003 Led_CenterWindowInParent (GetHWND ());
1004 PreDoModalHook ();
1005 return fSetFocusItemCalled ? false : true; // let windows set input focus if we have not
1006}
1007#endif
1008
1009#if qStroika_Foundation_Common_Platform_Windows
1010BOOL CALLBACK Led_StdDialogHelper::StaticDialogProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1011{
1012 if (message == WM_INITDIALOG) {
1013 [[maybe_unused]] LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
1014 AssertNotNull (lpcs);
1015 Led_StdDialogHelper* pThis = reinterpret_cast<Led_StdDialogHelper*> (lParam);
1016 Assert (pThis->GetHWND () == NULL); // cuz not set yet...
1017 pThis->SetHWND (hWnd);
1018
1019 return pThis->OnInitDialog ();
1020 }
1021
1022 Led_StdDialogHelper* pThis = reinterpret_cast<Led_StdDialogHelper*> (::GetWindowLongPtr (hWnd, GWLP_USERDATA));
1023
1024 if (pThis == NULL) {
1025 return false;
1026 }
1027
1028 if (message == WM_DESTROY) {
1029 pThis->SetHWND (NULL); // should maybe use OnDestroy () method???
1030 return true;
1031 }
1032
1033 Assert (pThis != NULL);
1034 Assert (pThis->GetHWND () == hWnd);
1035 return pThis->DialogProc (message, wParam, lParam);
1036}
1037
1038BOOL Led_StdDialogHelper::DialogProc (UINT message, [[maybe_unused]] WPARAM wParam, [[maybe_unused]] LPARAM lParam)
1039{
1040 switch (message) {
1041 case WM_COMMAND: {
1042 switch (wParam) {
1043 case IDOK: {
1044 OnOK ();
1045 return true;
1046 } break;
1047 case IDCANCEL: {
1048 OnCancel ();
1049 return true;
1050 } break;
1051 }
1052 } break;
1053 }
1054 return false;
1055}
1056#endif
1057
1058#if qStroika_Foundation_Common_Platform_Windows || (qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs)
1059SDKString Led_StdDialogHelper::GetItemText (DialogItemID itemID) const
1060{
1061#if qStroika_Foundation_Common_Platform_Windows
1062 Characters::SDKChar widgetText[2 * 1024]; // sb big enough for the most part???
1063 (void)::GetDlgItemText (GetHWND (), itemID, widgetText, static_cast<UINT> (std::size (widgetText)));
1064 return widgetText;
1065#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
1066 return (char*)gtk_entry_get_text (GTK_ENTRY (itemID)); // gtk returns internal pointer - DON'T FREE
1067#endif
1068}
1069
1070void Led_StdDialogHelper::SetItemText (DialogItemID itemID, const SDKString& text)
1071{
1072#if qStroika_Foundation_Common_Platform_Windows
1073 (void)::SetDlgItemText (GetHWND (), itemID, text.c_str ());
1074#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
1075 gtk_entry_set_text (GTK_ENTRY (itemID), text.c_str ());
1076#endif
1077}
1078
1079void Led_StdDialogHelper::SelectItemText (DialogItemID itemID, size_t from, size_t to)
1080{
1081#if qStroika_Foundation_Common_Platform_Windows
1082 ::SendDlgItemMessage (GetHWND (), itemID, EM_SETSEL, from, to);
1083#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
1084 gtk_entry_select_region (GTK_ENTRY (itemID), from, to);
1085#endif
1086}
1087
1088bool Led_StdDialogHelper::GetItemChecked (DialogItemID itemID) const
1089{
1090#if qStroika_Foundation_Common_Platform_Windows
1091 return !!::IsDlgButtonChecked (GetHWND (), itemID);
1092#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
1093 Assert (false); //NYI
1094 return false;
1095#endif
1096}
1097
1098void Led_StdDialogHelper::SetItemChecked (DialogItemID itemID, bool checked)
1099{
1100#if qStroika_Foundation_Common_Platform_Windows
1101 ::CheckDlgButton (GetHWND (), itemID, checked);
1102#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
1103 //gtk_entry_set_text (GTK_ENTRY (itemID), text.c_str ());
1104 Assert (false); //NYI
1105#endif
1106}
1107
1108bool Led_StdDialogHelper::GetItemEnabled (DialogItemID itemID) const
1109{
1110#if qStroika_Foundation_Common_Platform_Windows
1111 return !!::IsWindowEnabled (GetDlgItem (GetHWND (), itemID));
1112#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs && 0
1113 Assert (false); //NYI
1114 return false;
1115#else
1116 Assert (false);
1117 return true; // by default - if NYI...
1118#endif
1119}
1120
1121void Led_StdDialogHelper::SetItemEnabled (DialogItemID itemID, bool enabled)
1122{
1123#if qStroika_Foundation_Common_Platform_Windows
1124 ::EnableWindow (GetDlgItem (GetHWND (), itemID), enabled);
1125#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
1126 //gtk_entry_set_text (GTK_ENTRY (itemID), text.c_str ());
1127 Assert (false); //NYI
1128#endif
1129}
1130
1131void Led_StdDialogHelper::SetFocusedItem (DialogItemID itemID)
1132{
1133#if qStroika_Foundation_Common_Platform_Windows
1134 HWND dlgItem = ::GetDlgItem (GetHWND (), itemID);
1135 Assert (dlgItem != NULL);
1136 ::SetFocus (dlgItem);
1137 fSetFocusItemCalled = true;
1138#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
1139 gtk_widget_grab_focus (itemID);
1140#endif
1141}
1142#endif
1143
1144#if qStroika_Foundation_Common_Platform_Windows
1145void Led_StdDialogHelper::SetHWND (HWND hWnd)
1146{
1147 if (fHWnd != NULL) {
1148 ::SetWindowLongPtr (fHWnd, GWLP_USERDATA, 0); // reset back to original value
1149 }
1150 fHWnd = hWnd;
1151 if (fHWnd != NULL) {
1152 ::SetWindowLongPtr (fHWnd, GWLP_USERDATA, reinterpret_cast<DWORD_PTR> (this));
1153 }
1154}
1155
1156HWND Led_StdDialogHelper::GetHWND () const
1157{
1158 return fHWnd;
1159}
1160#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
1161GtkWidget* Led_StdDialogHelper::GetWindow () const
1162{
1163 return fWindow;
1164}
1165
1166void Led_StdDialogHelper::SetWindow (GtkWidget* w)
1167{
1168 if (fWindow != w) {
1169 if (fWindow != NULL) {
1170 gtk_object_set_user_data (GTK_OBJECT (fWindow), NULL);
1171 }
1172 fWindow = w;
1173 if (fWindow != NULL) {
1174 gtk_object_set_user_data (GTK_OBJECT (fWindow), this);
1175 }
1176 }
1177}
1178GtkWidget* Led_StdDialogHelper::GetOKButton () const
1179{
1180 return fOKButton;
1181}
1182void Led_StdDialogHelper::SetOKButton (GtkWidget* okButton)
1183{
1184 fOKButton = okButton;
1185}
1186
1187GtkWidget* Led_StdDialogHelper::GetCancelButton () const
1188{
1189 return fWindow;
1190}
1191void Led_StdDialogHelper::SetCancelButton (GtkWidget* cancelButton)
1192{
1193 fCancelButton = cancelButton;
1194}
1195#endif
1196
1197void Led_StdDialogHelper::OnOK ()
1198{
1199 fWasOK = true;
1200#if qStroika_Foundation_Common_Platform_Windows
1201 ::EndDialog (GetHWND (), IDOK);
1202#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
1203 gtk_main_quit ();
1204#endif
1205}
1206
1207void Led_StdDialogHelper::OnCancel ()
1208{
1209#if qStroika_Foundation_Common_Platform_Windows
1210 ::EndDialog (GetHWND (), IDCANCEL);
1211#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
1212 gtk_main_quit ();
1213#endif
1214}
1215
1216#if qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
1217void Led_StdDialogHelper::Static_OnOKButtonClick (GtkWidget* widget, gpointer data)
1218{
1219 Led_StdDialogHelper* dlg = reinterpret_cast<Led_StdDialogHelper*> (data);
1220 dlg->OnOK ();
1221}
1222
1223void Led_StdDialogHelper::Static_OnCancelButtonClick (GtkWidget* widget, gpointer data)
1224{
1225 Led_StdDialogHelper* dlg = reinterpret_cast<Led_StdDialogHelper*> (data);
1226 dlg->OnCancel ();
1227}
1228
1229void Led_StdDialogHelper::Static_OnWindowDeleteRequest (GtkWidget* widget)
1230{
1231 Led_StdDialogHelper* dlg = reinterpret_cast<Led_StdDialogHelper*> (gtk_object_get_user_data (GTK_OBJECT (widget)));
1232 Assert (dlg->fWindow == widget);
1233 dlg->OnCancel ();
1234}
1235#endif
1236
1237/*
1238 ********************************************************************************
1239 *************************** Led_StdDialogHelper_AboutBox ***********************
1240 ********************************************************************************
1241 */
1242#if qStroika_Foundation_Common_Platform_Windows
1243Led_StdDialogHelper_AboutBox::Led_StdDialogHelper_AboutBox (HINSTANCE hInstance, HWND parentWnd, const Characters::SDKChar* resID)
1244 : inherited (hInstance, resID, parentWnd)
1245{
1246}
1247#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
1248Led_StdDialogHelper_AboutBox::Led_StdDialogHelper_AboutBox (GtkWindow* parentWindow)
1249 : inherited (parentWindow)
1250{
1251}
1252#endif
1253
1254#if qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
1255GtkWidget* Led_StdDialogHelper_AboutBox::MakeWindow ()
1256{
1257 return gtk_window_new (GTK_WINDOW_TOPLEVEL);
1258}
1259#endif
1260
1261#if qStroika_Foundation_Common_Platform_Windows
1262BOOL Led_StdDialogHelper_AboutBox::DialogProc (UINT message, WPARAM wParam, LPARAM lParam)
1263{
1264 switch (message) {
1265 case WM_COMMAND: {
1266 switch (wParam) {
1267 case kLedStdDlg_AboutBox_InfoLedFieldID:
1268 OnClickInInfoField ();
1269 return true;
1270 case kLedStdDlg_AboutBox_LedWebPageFieldID:
1271 OnClickInLedWebPageField ();
1272 return true;
1273 }
1274 }
1275 }
1276 return inherited::DialogProc (message, wParam, lParam);
1277}
1278#endif
1279
1280#if qSupportStdAboutBoxDlg
1281void Led_StdDialogHelper_AboutBox::OnClickInInfoField ()
1282{
1283 OnOK ();
1284}
1285
1286void Led_StdDialogHelper_AboutBox::OnClickInLedWebPageField ()
1287{
1288 OnOK ();
1289}
1290#endif
1291
1292#if qSupportStdFindDlg
1293/*
1294 ********************************************************************************
1295 *************************** Led_StdDialogHelper_FindDialog *********************
1296 ********************************************************************************
1297 */
1298
1299#if qStroika_Foundation_Common_Platform_Windows
1300Led_StdDialogHelper_FindDialog::Led_StdDialogHelper_FindDialog (HINSTANCE hInstance, HWND parentWnd, const Characters::SDKChar* resID)
1301 : inherited (hInstance, resID, parentWnd)
1302 , fFindText ()
1303 , fRecentFindTextStrings ()
1304 , fWrapSearch (false)
1305 , fWholeWordSearch (false)
1306 , fCaseSensativeSearch (false)
1307 , fPressedOK (false)
1308#if qSupportLedDialogWidgets
1309 , fFindTextWidget ()
1310#endif
1311{
1312}
1313#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
1314Led_StdDialogHelper_FindDialog::Led_StdDialogHelper_FindDialog (GtkWindow* parentWindow)
1315 : inherited (parentWindow)
1316 , fFindText ()
1317 , fRecentFindTextStrings ()
1318 , fWrapSearch (false)
1319 , fWholeWordSearch (false)
1320 , fCaseSensativeSearch (false)
1321 , fPressedOK (false)
1322 , fLookupTextWidget (NULL)
1323{
1324}
1325#endif
1326
1327#if qStroika_Foundation_Common_Platform_Windows
1328BOOL Led_StdDialogHelper_FindDialog::DialogProc (UINT message, WPARAM wParam, LPARAM lParam)
1329{
1330 switch (message) {
1331 case WM_COMMAND: {
1332 switch (wParam) {
1333 case kLedStdDlg_FindBox_Find:
1334 OnFindButton ();
1335 return true;
1336 case kLedStdDlg_FindBox_Cancel:
1337 OnDontFindButton ();
1338 return true;
1339 }
1340 }
1341 }
1342 return inherited::DialogProc (message, wParam, lParam);
1343}
1344#endif
1345
1346void Led_StdDialogHelper_FindDialog::PreDoModalHook ()
1347{
1348#if qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
1349 GtkWidget* actionArea = GTK_DIALOG (GetWindow ())->action_area;
1350 {
1351 fLookupTextWidget = gtk_entry_new ();
1352 gtk_container_add (GTK_CONTAINER (actionArea), fLookupTextWidget);
1353 gtk_widget_show (fLookupTextWidget);
1354 // gtk_entry_set_text (GTK_ENTRY (fLookupTextWidget), Led_tString2SDKString (fFindText).c_str ());
1355 // gtk_entry_select_region (GTK_ENTRY (fLookupTextWidget), 0, -1);
1356 // gtk_widget_grab_focus (fLookupTextWidget);
1357 }
1358 {
1359 GtkWidget* button = gtk_button_new_with_label ("Find");
1360 gtk_container_add (GTK_CONTAINER (actionArea), button);
1361 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
1362 gtk_widget_show (button);
1363 gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (Static_OnFindButtonClick), (gpointer)this);
1364 }
1365 {
1366 GtkWidget* button = gtk_button_new_with_label ("Close");
1367 gtk_container_add (GTK_CONTAINER (actionArea), button);
1368 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
1369 gtk_widget_show (button);
1370 gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (Static_OnDontFindButtonClick), (gpointer)this);
1371 }
1372#endif
1373
1374#if qStroika_Foundation_Common_Platform_Windows && qSupportLedDialogWidgets
1375 /*
1376 * ReplaceWindow seems to work better than SubclassWindow - for reasons I don't FULLY understand.
1377 * (see SPR#1266).
1378 */
1379 fFindTextWidget.ReplaceWindow (::GetDlgItem (GetHWND (), kLedStdDlg_FindBox_FindText));
1380#endif
1381
1382#if qStroika_Foundation_Common_Platform_Windows
1383 DialogItemID findText = kLedStdDlg_FindBox_FindText;
1384#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
1385 DialogItemID findText = fLookupTextWidget;
1386#endif
1387
1388#if qSupportLedDialogWidgets
1389 fFindTextWidget.SetText (fFindText);
1390 fFindTextWidget.SetPopupItems (fRecentFindTextStrings);
1391#else
1392 SetItemText (findText, Led_tString2SDKString (fFindText));
1393#endif
1394 SelectItemText (findText);
1395 SetFocusedItem (findText);
1396
1397#if qStroika_Foundation_Common_Platform_Windows
1398 SetItemChecked (kLedStdDlg_FindBox_WrapAtEndOfDoc, fWrapSearch);
1399 SetItemChecked (kLedStdDlg_FindBox_WholeWord, fWholeWordSearch);
1400 SetItemChecked (kLedStdDlg_FindBox_IgnoreCase, not fCaseSensativeSearch);
1401#endif
1402 inherited::PreDoModalHook ();
1403}
1404
1405void Led_StdDialogHelper_FindDialog::OnFindButton ()
1406{
1407 Led_StdDialogHelper_FindDialog::OnDontFindButton (); // for code sharing - could put that common stuff in other routine...
1408 fPressedOK = true;
1409}
1410
1411void Led_StdDialogHelper_FindDialog::OnDontFindButton ()
1412{
1413#if qSupportLedDialogWidgets
1414 fFindText = fFindTextWidget.GetText ();
1415#elif qStroika_Foundation_Common_Platform_Windows
1416 fFindText = Led_SDKString2tString (GetItemText (kLedStdDlg_FindBox_FindText));
1417#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
1418 fFindText = Led_SDKString2tString (GetItemText (fLookupTextWidget));
1419#endif
1420
1421#if qStroika_Foundation_Common_Platform_Windows
1422 fWrapSearch = GetItemChecked (kLedStdDlg_FindBox_WrapAtEndOfDoc);
1423 fWholeWordSearch = GetItemChecked (kLedStdDlg_FindBox_WholeWord);
1424 fCaseSensativeSearch = not GetItemChecked (kLedStdDlg_FindBox_IgnoreCase);
1425#endif
1426 OnOK ();
1427}
1428
1429#if qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
1430void Led_StdDialogHelper_FindDialog::Static_OnFindButtonClick (GtkWidget* widget, gpointer data)
1431{
1432 Led_StdDialogHelper_FindDialog* dlg = reinterpret_cast<Led_StdDialogHelper_FindDialog*> (data);
1433 dlg->OnFindButton ();
1434}
1435
1436void Led_StdDialogHelper_FindDialog::Static_OnDontFindButtonClick (GtkWidget* widget, gpointer data)
1437{
1438 Led_StdDialogHelper_FindDialog* dlg = reinterpret_cast<Led_StdDialogHelper_FindDialog*> (data);
1439 dlg->OnDontFindButton ();
1440}
1441#endif
1442
1443#endif
1444
1445#if qSupportStdReplaceDlg
1446/*
1447 ********************************************************************************
1448 ************************* Led_StdDialogHelper_ReplaceDialog ********************
1449 ********************************************************************************
1450 */
1451#if qStroika_Foundation_Common_Platform_Windows
1452Led_StdDialogHelper_ReplaceDialog::Led_StdDialogHelper_ReplaceDialog (HINSTANCE hInstance, HWND parentWnd, const Characters::SDKChar* resID)
1453 : inherited (hInstance, resID, parentWnd)
1454 , fFindText ()
1455 , fRecentFindTextStrings ()
1456 , fReplaceText ()
1457 , fWrapSearch (false)
1458 , fWholeWordSearch (false)
1459 , fCaseSensativeSearch (false)
1460 , fPressed (eCancel)
1461#if qSupportLedDialogWidgets
1462 , fFindTextWidget ()
1463 , fReplaceTextWidget ()
1464#endif
1465{
1466}
1467#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
1468Led_StdDialogHelper_ReplaceDialog::Led_StdDialogHelper_ReplaceDialog (GtkWindow* parentWindow)
1469 : inherited (parentWindow)
1470 , fFindText ()
1471 , fRecentFindTextStrings ()
1472 , fReplaceText ()
1473 , fWrapSearch (false)
1474 , fWholeWordSearch (false)
1475 , fCaseSensativeSearch (false)
1476 , fPressed (eCancel)
1477 , fLookupTextWidget (NULL)
1478 , fReplaceTextWidget (NULL)
1479{
1480}
1481#endif
1482
1483#if qStroika_Foundation_Common_Platform_Windows
1484BOOL Led_StdDialogHelper_ReplaceDialog::DialogProc (UINT message, WPARAM wParam, LPARAM lParam)
1485{
1486 switch (message) {
1487 case WM_COMMAND: {
1488 switch (wParam) {
1489 case kLedStdDlg_ReplaceBox_Find:
1490 OnFindButton ();
1491 return true;
1492 case kLedStdDlg_ReplaceBox_Replace:
1493 OnReplaceButton ();
1494 return true;
1495 case kLedStdDlg_ReplaceBox_ReplaceAll:
1496 OnReplaceAllButton ();
1497 return true;
1498 case kLedStdDlg_ReplaceBox_ReplaceAllInSelection:
1499 OnReplaceAllInSelectionButton ();
1500 return true;
1501 case kLedStdDlg_ReplaceBox_Cancel:
1502 OnDontFindButton ();
1503 return true;
1504 }
1505 }
1506 }
1507 return inherited::DialogProc (message, wParam, lParam);
1508}
1509#endif
1510
1511void Led_StdDialogHelper_ReplaceDialog::PreDoModalHook ()
1512{
1513#if qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
1514 GtkWidget* actionArea = GTK_DIALOG (GetWindow ())->action_area;
1515 {
1516 fLookupTextWidget = gtk_entry_new ();
1517 gtk_container_add (GTK_CONTAINER (actionArea), fLookupTextWidget);
1518 gtk_widget_show (fLookupTextWidget);
1519 fReplaceTextWidget = gtk_entry_new ();
1520 gtk_container_add (GTK_CONTAINER (actionArea), fReplaceTextWidget);
1521 gtk_widget_show (fReplaceTextWidget);
1522 // gtk_entry_set_text (GTK_ENTRY (fLookupTextWidget), Led_tString2SDKString (fFindText).c_str ());
1523 // gtk_entry_select_region (GTK_ENTRY (fLookupTextWidget), 0, -1);
1524 // gtk_widget_grab_focus (fLookupTextWidget);
1525 }
1526 {
1527 GtkWidget* button = gtk_button_new_with_label ("Find");
1528 gtk_container_add (GTK_CONTAINER (actionArea), button);
1529 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
1530 gtk_widget_show (button);
1531 gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (Static_OnFindButtonClick), (gpointer)this);
1532 }
1533 {
1534 GtkWidget* button = gtk_button_new_with_label ("Close");
1535 gtk_container_add (GTK_CONTAINER (actionArea), button);
1536 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
1537 gtk_widget_show (button);
1538 gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (Static_OnDontFindButtonClick), (gpointer)this);
1539 }
1540 {
1541 GtkWidget* button = gtk_button_new_with_label ("Replace");
1542 gtk_container_add (GTK_CONTAINER (actionArea), button);
1543 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
1544 gtk_widget_show (button);
1545 gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (Static_OnReplaceButtonClick), (gpointer)this);
1546 }
1547 {
1548 GtkWidget* button = gtk_button_new_with_label ("Replace All");
1549 gtk_container_add (GTK_CONTAINER (actionArea), button);
1550 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
1551 gtk_widget_show (button);
1552 gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (Static_OnReplaceAllButtonClick), (gpointer)this);
1553 }
1554 {
1555 GtkWidget* button = gtk_button_new_with_label ("Replace All in Selection");
1556 gtk_container_add (GTK_CONTAINER (actionArea), button);
1557 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
1558 gtk_widget_show (button);
1559 gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (Static_OnReplaceAllInSelectionButtonClick), (gpointer)this);
1560 }
1561#endif
1562
1563#if qStroika_Foundation_Common_Platform_Windows && qSupportLedDialogWidgets
1564 /*
1565 * ReplaceWindow seems to work better than SubclassWindow - for reasons I don't FULLY understand.
1566 * (see SPR#1266).
1567 */
1568 fFindTextWidget.ReplaceWindow (::GetDlgItem (GetHWND (), kLedStdDlg_ReplaceBox_FindText));
1569 fReplaceTextWidget.ReplaceWindow (::GetDlgItem (GetHWND (), kLedStdDlg_ReplaceBox_ReplaceText));
1570#endif
1571
1572#if qStroika_Foundation_Common_Platform_Windows
1573 DialogItemID findText = kLedStdDlg_ReplaceBox_FindText;
1574 DialogItemID replaceText = kLedStdDlg_ReplaceBox_ReplaceText;
1575#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
1576 DialogItemID findText = fLookupTextWidget;
1577 DialogItemID replaceText = fReplaceTextWidget;
1578#endif
1579
1580#if qSupportLedDialogWidgets
1581 fFindTextWidget.SetText (fFindText);
1582 fFindTextWidget.SetPopupItems (fRecentFindTextStrings);
1583 fReplaceTextWidget.SetText (fReplaceText);
1584#else
1585 SetItemText (findText, Led_tString2SDKString (fFindText));
1586 SetItemText (replaceText, Led_tString2SDKString (fReplaceText));
1587#endif
1588 SelectItemText (findText);
1589 SelectItemText (replaceText);
1590 SetFocusedItem (findText);
1591
1592#if qStroika_Foundation_Common_Platform_Windows
1593 SetItemChecked (kLedStdDlg_ReplaceBox_WrapAtEndOfDoc, fWrapSearch);
1594 SetItemChecked (kLedStdDlg_ReplaceBox_WholeWord, fWholeWordSearch);
1595 SetItemChecked (kLedStdDlg_ReplaceBox_IgnoreCase, not fCaseSensativeSearch);
1596#endif
1597 inherited::PreDoModalHook ();
1598}
1599
1600void Led_StdDialogHelper_ReplaceDialog::OnFindButton ()
1601{
1602 SaveItems ();
1603 OnOK ();
1604 fPressed = eFind;
1605}
1606
1607void Led_StdDialogHelper_ReplaceDialog::OnReplaceButton ()
1608{
1609 SaveItems ();
1610 OnOK ();
1611 fPressed = eReplace;
1612}
1613
1614void Led_StdDialogHelper_ReplaceDialog::OnReplaceAllButton ()
1615{
1616 SaveItems ();
1617 OnOK ();
1618 fPressed = eReplaceAll;
1619}
1620
1621void Led_StdDialogHelper_ReplaceDialog::OnReplaceAllInSelectionButton ()
1622{
1623 SaveItems ();
1624 OnOK ();
1625 fPressed = eReplaceAllInSelection;
1626}
1627
1628void Led_StdDialogHelper_ReplaceDialog::OnDontFindButton ()
1629{
1630 SaveItems ();
1631 OnCancel ();
1632}
1633
1634void Led_StdDialogHelper_ReplaceDialog::SaveItems ()
1635{
1636#if qSupportLedDialogWidgets
1637 fFindText = fFindTextWidget.GetText ();
1638 fReplaceText = fReplaceTextWidget.GetText ();
1639#elif qStroika_Foundation_Common_Platform_Windows
1640 fFindText = Led_SDKString2tString (GetItemText (kLedStdDlg_ReplaceBox_FindText));
1641 fReplaceText = Led_SDKString2tString (GetItemText (kLedStdDlg_ReplaceBox_ReplaceText));
1642#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
1643 fFindText = Led_SDKString2tString (GetItemText (fLookupTextWidget));
1644 fReplaceText = Led_SDKString2tString (GetItemText (fReplaceTextWidget));
1645#endif
1646
1647#if qStroika_Foundation_Common_Platform_Windows
1648 fWrapSearch = GetItemChecked (kLedStdDlg_ReplaceBox_WrapAtEndOfDoc);
1649 fWholeWordSearch = GetItemChecked (kLedStdDlg_ReplaceBox_WholeWord);
1650 fCaseSensativeSearch = not GetItemChecked (kLedStdDlg_ReplaceBox_IgnoreCase);
1651#endif
1652}
1653
1654#if qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
1655void Led_StdDialogHelper_ReplaceDialog::Static_OnFindButtonClick (GtkWidget* widget, gpointer data)
1656{
1657 Led_StdDialogHelper_ReplaceDialog* dlg = reinterpret_cast<Led_StdDialogHelper_ReplaceDialog*> (data);
1658 dlg->OnFindButton ();
1659}
1660
1661void Led_StdDialogHelper_ReplaceDialog::Static_OnDontFindButtonClick (GtkWidget* widget, gpointer data)
1662{
1663 Led_StdDialogHelper_ReplaceDialog* dlg = reinterpret_cast<Led_StdDialogHelper_ReplaceDialog*> (data);
1664 dlg->OnDontFindButton ();
1665}
1666
1667void Led_StdDialogHelper_ReplaceDialog::Static_OnReplaceButtonClick (GtkWidget* widget, gpointer data)
1668{
1669 Led_StdDialogHelper_ReplaceDialog* dlg = reinterpret_cast<Led_StdDialogHelper_ReplaceDialog*> (data);
1670 dlg->OnReplaceButton ();
1671}
1672
1673void Led_StdDialogHelper_ReplaceDialog::Static_OnReplaceAllButtonClick (GtkWidget* widget, gpointer data)
1674{
1675 Led_StdDialogHelper_ReplaceDialog* dlg = reinterpret_cast<Led_StdDialogHelper_ReplaceDialog*> (data);
1676 dlg->OnReplaceAllButton ();
1677}
1678
1679void Led_StdDialogHelper_ReplaceDialog::Static_OnReplaceAllInSelectionButtonClick (GtkWidget* widget, gpointer data)
1680{
1681 Led_StdDialogHelper_ReplaceDialog* dlg = reinterpret_cast<Led_StdDialogHelper_ReplaceDialog*> (data);
1682 dlg->OnReplaceAllInSelectionButton ();
1683}
1684#endif
1685
1686#endif
1687
1688#if qUseGTKForLedStandardDialogs && qStroika_FeatureSupported_XWindows
1689/*
1690 ********************************************************************************
1691 ********************************** StdFontPickBox ******************************
1692 ********************************************************************************
1693 */
1694StdFontPickBox::StdFontPickBox (GtkWindow* modalParentWindow, const FontSpecification& initialFont)
1695 : inherited (modalParentWindow)
1696 , fFont (initialFont)
1697{
1698}
1699
1700GtkWidget* StdFontPickBox::MakeWindow ()
1701{
1702 return gtk_font_selection_dialog_new ("Select font");
1703}
1704
1705void StdFontPickBox::PreDoModalHook ()
1706{
1707 inherited::PreDoModalHook ();
1708 SetOKButton (GTK_FONT_SELECTION_DIALOG (GetWindow ())->ok_button);
1709 SetCancelButton (GTK_FONT_SELECTION_DIALOG (GetWindow ())->cancel_button);
1710 Verify (gtk_font_selection_dialog_set_font_name (GTK_FONT_SELECTION_DIALOG (GetWindow ()), fFont.GetOSRep ().c_str ()));
1711}
1712
1713void StdFontPickBox::OnOK ()
1714{
1715 inherited::OnOK ();
1716 gchar* newFontOSName = gtk_font_selection_dialog_get_font_name (GTK_FONT_SELECTION_DIALOG (GetWindow ()));
1717 if (newFontOSName != NULL) {
1718 fFont.SetFromOSRep (newFontOSName);
1719 g_free (newFontOSName);
1720 }
1721}
1722#endif
1723
1724#if qSupportStdColorPickBox
1725/*
1726 ********************************************************************************
1727 ********************************** StdColorPickBox *****************************
1728 ********************************************************************************
1729 */
1730#if qStroika_Foundation_Common_Platform_Windows
1731StdColorPickBox::StdColorPickBox (const Color& initialColor)
1732 : fColor (initialColor)
1733 , fParentWnd (::GetActiveWindow ()) // a good default...
1734{
1735}
1736
1737StdColorPickBox::StdColorPickBox ([[maybe_unused]] HINSTANCE hInstance, HWND parentWnd, const Color& initialColor)
1738 : fColor (initialColor)
1739 , fParentWnd (parentWnd)
1740{
1741}
1742#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
1743StdColorPickBox::StdColorPickBox (GtkWindow* modalParentWindow, const Color& initialColor)
1744 : inherited (modalParentWindow)
1745 , fColor (initialColor)
1746{
1747}
1748#endif
1749
1750#if qStroika_Foundation_Common_Platform_Windows
1751bool StdColorPickBox::DoModal ()
1752{
1753#if qStroika_Foundation_Common_Platform_Windows
1754 CHOOSECOLOR cc;
1755 memset (&cc, 0, sizeof (cc));
1756 cc.lStructSize = sizeof (cc);
1757 cc.Flags |= CC_ANYCOLOR;
1758 cc.rgbResult = fColor.GetOSRep ();
1759 cc.Flags |= CC_RGBINIT;
1760 cc.Flags |= CC_FULLOPEN;
1761
1762 cc.Flags |= CC_ENABLEHOOK;
1763 cc.lpfnHook = ColorPickerINITPROC;
1764
1765 static COLORREF sCustomColors[16];
1766 cc.lpCustColors = sCustomColors;
1767
1768 cc.hwndOwner = fParentWnd;
1769
1770 if (::ChooseColor (&cc)) {
1771 fColor = Color (cc.rgbResult);
1772 return true;
1773 }
1774#endif
1775 return false;
1776}
1777#endif
1778
1779#if qStroika_Foundation_Common_Platform_Windows
1780UINT_PTR CALLBACK StdColorPickBox::ColorPickerINITPROC (HWND hWnd, UINT message, [[maybe_unused]] WPARAM wParam, [[maybe_unused]] LPARAM lParam)
1781{
1782 if (hWnd != NULL and message == WM_INITDIALOG) {
1783 Led_CenterWindowInParent (hWnd);
1784 }
1785 return 0;
1786}
1787#endif
1788
1789#if qUseGTKForLedStandardDialogs && qStroika_FeatureSupported_XWindows
1790GtkWidget* StdColorPickBox::MakeWindow ()
1791{
1792 return gtk_color_selection_dialog_new ("Select color");
1793}
1794
1795void StdColorPickBox::PreDoModalHook ()
1796{
1797 inherited::PreDoModalHook ();
1798 SetOKButton (GTK_COLOR_SELECTION_DIALOG (GetWindow ())->ok_button);
1799 SetCancelButton (GTK_COLOR_SELECTION_DIALOG (GetWindow ())->cancel_button);
1800 gdouble colors[4];
1801 colors[0] = static_cast<double> (fColor.GetRed ()) / Color::kColorValueMax;
1802 colors[1] = static_cast<double> (fColor.GetGreen ()) / Color::kColorValueMax;
1803 colors[2] = static_cast<double> (fColor.GetBlue ()) / Color::kColorValueMax;
1804 colors[3] = 0;
1805 gtk_color_selection_set_color (GTK_COLOR_SELECTION (GTK_COLOR_SELECTION_DIALOG (GetWindow ())->colorsel), colors);
1806}
1807
1808void StdColorPickBox::OnOK ()
1809{
1810 inherited::OnOK ();
1811 gdouble colors[4];
1812 gtk_color_selection_get_color (GTK_COLOR_SELECTION (GTK_COLOR_SELECTION_DIALOG (GetWindow ())->colorsel), colors);
1813 using CV = Color::ColorValue;
1814 fColor = Color (static_cast<CV> (colors[0] * Color::kColorValueMax), static_cast<CV> (colors[1] * Color::kColorValueMax),
1815 static_cast<CV> (colors[2] * Color::kColorValueMax));
1816}
1817#endif
1818#endif
1819
1820#if qSupportStdFileDlg && defined(__cplusplus)
1821/*
1822 ********************************************************************************
1823 ********************************** StdFilePickBox ******************************
1824 ********************************************************************************
1825 */
1826StdFilePickBox::StdFilePickBox (GtkWindow* modalParentWindow, const SDKString& title, bool saveDialog, const SDKString& fileName)
1827 : inherited (modalParentWindow)
1828 , fTitle (title)
1829 , fSaveDialog (saveDialog)
1830 , fFileName (fileName)
1831{
1832}
1833
1834GtkWidget* StdFilePickBox::MakeWindow ()
1835{
1836 return gtk_file_selection_new (fTitle.c_str ());
1837}
1838
1839void StdFilePickBox::PreDoModalHook ()
1840{
1841 inherited::PreDoModalHook ();
1842
1843 SetOKButton (GTK_FILE_SELECTION (GetWindow ())->ok_button);
1844 SetCancelButton (GTK_FILE_SELECTION (GetWindow ())->cancel_button);
1845
1846 gtk_file_selection_hide_fileop_buttons (GTK_FILE_SELECTION (GetWindow ())); // they look terrible...
1847 if (fSaveDialog) {
1848 gtk_file_selection_set_filename (GTK_FILE_SELECTION (GetWindow ()), fFileName.empty () ? Led_SDK_TCHAROF ("untitled") : fFileName.c_str ());
1849 }
1850}
1851
1852void StdFilePickBox::OnOK ()
1853{
1854 inherited::OnOK ();
1855
1856 SDKString fileName = gtk_file_selection_get_filename (GTK_FILE_SELECTION (GetWindow ()));
1857 try {
1858 if (fileName.empty ()) {
1859 throw "EMPTY";
1860 }
1861 fFileName = fileName;
1862 }
1863 catch (...) {
1864 // should print error dialog on errors...
1865 }
1866}
1867
1868SDKString StdFilePickBox::GetFileName () const
1869{
1870 return fFileName;
1871}
1872#endif
1873
1874#if qSupportUpdateWin32FileAssocDlg
1875/*
1876 ********************************************************************************
1877 ******************* Led_StdDialogHelper_UpdateWin32FileAssocsDialog ************
1878 ********************************************************************************
1879 */
1880
1881Led_StdDialogHelper_UpdateWin32FileAssocsDialog::Led_StdDialogHelper_UpdateWin32FileAssocsDialog (HINSTANCE hInstance, HWND parentWnd,
1882 const Characters::SDKChar* resID)
1883 : inherited (hInstance, resID, parentWnd)
1884 , fAppName ()
1885 , fTypeList ()
1886 , fKeepChecking (false)
1887{
1888}
1889
1890void Led_StdDialogHelper_UpdateWin32FileAssocsDialog::PreDoModalHook ()
1891{
1892#if qStroika_Foundation_Common_Platform_Windows
1893 ::SetForegroundWindow (GetHWND ());
1894 Characters::SDKChar messageText[1024];
1895 (void)::GetDlgItemText (GetHWND (), kLedStdDlg_UpdateWin32FileAssocsDialog_Msg, messageText, std::ssize (messageText));
1896 SDKString m = messageText;
1897 ReplaceAllTokens (&m, Led_SDK_TCHAROF ("%0"), fAppName);
1898 ReplaceAllTokens (&m, Led_SDK_TCHAROF ("%1"), fTypeList);
1899 (void)::SetDlgItemText (GetHWND (), kLedStdDlg_UpdateWin32FileAssocsDialog_Msg, m.c_str ());
1900
1901 (void)::GetDlgItemText (GetHWND (), kLedStdDlg_UpdateWin32FileAssocsDialog_KeepCheckingCheckboxMsg, messageText, std::ssize (messageText));
1902 m = messageText;
1903 ReplaceAllTokens (&m, Led_SDK_TCHAROF ("%0"), fAppName);
1904 ReplaceAllTokens (&m, Led_SDK_TCHAROF ("%1"), fTypeList);
1905 (void)::SetDlgItemText (GetHWND (), kLedStdDlg_UpdateWin32FileAssocsDialog_KeepCheckingCheckboxMsg, m.c_str ());
1906
1907 ::CheckDlgButton (GetHWND (), kLedStdDlg_UpdateWin32FileAssocsDialog_KeepCheckingCheckboxMsg, fKeepChecking);
1908#endif
1909 inherited::PreDoModalHook ();
1910}
1911
1912void Led_StdDialogHelper_UpdateWin32FileAssocsDialog::OnOK ()
1913{
1914 fKeepChecking = !!::IsDlgButtonChecked (GetHWND (), kLedStdDlg_UpdateWin32FileAssocsDialog_KeepCheckingCheckboxMsg);
1915 inherited::OnOK ();
1916}
1917
1918void Led_StdDialogHelper_UpdateWin32FileAssocsDialog::OnCancel ()
1919{
1920 fKeepChecking = !!::IsDlgButtonChecked (GetHWND (), kLedStdDlg_UpdateWin32FileAssocsDialog_KeepCheckingCheckboxMsg);
1921 inherited::OnCancel ();
1922}
1923#endif
1924
1925#if qSupportParagraphIndentsDlg
1926/*
1927 ********************************************************************************
1928 ******************* Led_StdDialogHelper_ParagraphIndentsDialog *****************
1929 ********************************************************************************
1930 */
1931#if qStroika_Foundation_Common_Platform_Windows
1932Led_StdDialogHelper_ParagraphIndentsDialog::Led_StdDialogHelper_ParagraphIndentsDialog (HINSTANCE hInstance, HWND parentWnd,
1933 const Characters::SDKChar* resID)
1934 : inherited (hInstance, resID, parentWnd)
1935 , fLeftMargin_Valid (false)
1936 , fLeftMargin_Orig (TWIPS{0})
1937 , fLeftMargin_Result (TWIPS{0})
1938 , fRightMargin_Valid (false)
1939 , fRightMargin_Orig (TWIPS{0})
1940 , fRightMargin_Result (TWIPS{0})
1941 , fFirstIndent_Valid (false)
1942 , fFirstIndent_Orig (TWIPS{0})
1943 , fFirstIndent_Result (TWIPS{0})
1944{
1945}
1946#endif
1947
1948void Led_StdDialogHelper_ParagraphIndentsDialog::InitValues (TWIPS leftMargin, bool leftMarginValid, TWIPS rightMargin,
1949 bool rightMarginValid, TWIPS firstIndent, bool firstIndentValid)
1950{
1951 fLeftMargin_Valid = leftMarginValid;
1952 fLeftMargin_Orig = leftMargin;
1953 fLeftMargin_Result = leftMargin;
1954 fRightMargin_Valid = rightMarginValid;
1955 fRightMargin_Orig = rightMargin;
1956 fRightMargin_Result = rightMargin;
1957 fFirstIndent_Valid = firstIndentValid;
1958 fFirstIndent_Orig = firstIndent;
1959 fFirstIndent_Result = firstIndent;
1960}
1961
1962void Led_StdDialogHelper_ParagraphIndentsDialog::PreDoModalHook ()
1963{
1964 if (fLeftMargin_Valid) {
1965 SetItemText (kLedStdDlg_ParagraphIndents_LeftMarginFieldID, FormatTWIPSAsString (fLeftMargin_Orig));
1966 }
1967 if (fRightMargin_Valid) {
1968 SetItemText (kLedStdDlg_ParagraphIndents_RightMarginFieldID, FormatTWIPSAsString (fRightMargin_Orig));
1969 }
1970 if (fFirstIndent_Valid) {
1971 SetItemText (kLedStdDlg_ParagraphIndents_FirstIndentFieldID, FormatTWIPSAsString (fFirstIndent_Orig));
1972 }
1973 SetFocusedItem (kLedStdDlg_ParagraphIndents_LeftMarginFieldID);
1974 SelectItemText (kLedStdDlg_ParagraphIndents_LeftMarginFieldID);
1975 inherited::PreDoModalHook ();
1976}
1977
1978DISABLE_COMPILER_MSC_WARNING_START (4706)
1979void Led_StdDialogHelper_ParagraphIndentsDialog::OnOK ()
1980{
1981 SDKString leftMargin = GetItemText (kLedStdDlg_ParagraphIndents_LeftMarginFieldID);
1982 if (not(fLeftMargin_Valid = ParseStringToTWIPS (leftMargin, &fLeftMargin_Result))) {
1983 fLeftMargin_Result = fLeftMargin_Orig;
1984 }
1985
1986 SDKString rightMargin = GetItemText (kLedStdDlg_ParagraphIndents_RightMarginFieldID);
1987 if (not(fRightMargin_Valid = ParseStringToTWIPS (rightMargin, &fRightMargin_Result))) {
1988 fRightMargin_Result = fRightMargin_Orig;
1989 }
1990
1991 SDKString firstIndent = GetItemText (kLedStdDlg_ParagraphIndents_FirstIndentFieldID);
1992 if (not(fLeftMargin_Valid = ParseStringToTWIPS (firstIndent, &fFirstIndent_Result))) {
1993 fFirstIndent_Result = fFirstIndent_Orig;
1994 }
1995 inherited::OnOK ();
1996}
1997DISABLE_COMPILER_MSC_WARNING_END (4706)
1998#endif
1999
2000#if qSupportParagraphSpacingDlg
2001/*
2002 ********************************************************************************
2003 ******************* Led_StdDialogHelper_ParagraphSpacingDialog *****************
2004 ********************************************************************************
2005 */
2006#if qStroika_Foundation_Common_Platform_Windows
2007Led_StdDialogHelper_ParagraphSpacingDialog::Led_StdDialogHelper_ParagraphSpacingDialog (HINSTANCE hInstance, HWND parentWnd,
2008 const Characters::SDKChar* resID)
2009 : inherited (hInstance, resID, parentWnd)
2010 , fSpaceBefore_Valid (false)
2011 , fSpaceBefore_Orig (TWIPS{0})
2012 , fSpaceBefore_Result (TWIPS{0})
2013 , fSpaceAfter_Valid (false)
2014 , fSpaceAfter_Orig (TWIPS{0})
2015 , fSpaceAfter_Result (TWIPS{0})
2016 , fLineSpacing_Valid (false)
2017 , fLineSpacing_Orig ()
2018 , fLineSpacing_Result ()
2019{
2020}
2021#endif
2022
2023void Led_StdDialogHelper_ParagraphSpacingDialog::InitValues (TWIPS spaceBefore, bool spaceBeforeValid, TWIPS spaceAfter,
2024 bool spaceAfterValid, LineSpacing lineSpacing, bool lineSpacingValid)
2025{
2026 fSpaceBefore_Valid = spaceBeforeValid;
2027 fSpaceBefore_Orig = spaceBefore;
2028 fSpaceBefore_Result = spaceBefore;
2029 fSpaceAfter_Valid = spaceAfterValid;
2030 fSpaceAfter_Orig = spaceAfter;
2031 fSpaceAfter_Result = spaceAfter;
2032 fLineSpacing_Valid = lineSpacingValid;
2033 fLineSpacing_Orig = lineSpacing;
2034 fLineSpacing_Result = lineSpacing;
2035}
2036
2037void Led_StdDialogHelper_ParagraphSpacingDialog::PreDoModalHook ()
2038{
2039#if qStroika_Foundation_Common_Platform_Windows
2040 HWND popup = ::GetDlgItem (GetHWND (), kParagraphSpacing_Dialog_LineSpaceModeFieldID);
2041 AssertNotNull (popup);
2042 Assert (::IsWindow (popup));
2043 (void)::SendMessage (popup, CB_RESETCONTENT, 0, 0);
2044 Verify (::SendMessage (popup, CB_ADDSTRING, 0, reinterpret_cast<LPARAM> (_T ("Single"))) != CB_ERR);
2045 Verify (::SendMessage (popup, CB_ADDSTRING, 0, reinterpret_cast<LPARAM> (_T ("1.5 lines"))) != CB_ERR);
2046 Verify (::SendMessage (popup, CB_ADDSTRING, 0, reinterpret_cast<LPARAM> (_T ("Double"))) != CB_ERR);
2047 Verify (::SendMessage (popup, CB_ADDSTRING, 0, reinterpret_cast<LPARAM> (_T ("At Least (TWIPS)"))) != CB_ERR);
2048 Verify (::SendMessage (popup, CB_ADDSTRING, 0, reinterpret_cast<LPARAM> (_T ("Exact (TWIPS)"))) != CB_ERR);
2049 Verify (::SendMessage (popup, CB_ADDSTRING, 0, reinterpret_cast<LPARAM> (_T ("Exact (1/20 lines)"))) != CB_ERR);
2050#endif
2051
2052 if (fSpaceBefore_Valid) {
2053 SetItemText (kParagraphSpacing_Dialog_SpaceBeforeFieldID, FormatTWIPSAsString (fSpaceBefore_Orig));
2054 }
2055 if (fSpaceAfter_Valid) {
2056 SetItemText (kParagraphSpacing_Dialog_SpaceAfterFieldID, FormatTWIPSAsString (fSpaceAfter_Orig));
2057 }
2058 if (fLineSpacing_Valid) {
2059#if qStroika_Foundation_Common_Platform_Windows
2060 Verify (::SendMessage (popup, CB_SETCURSEL, fLineSpacing_Orig.fRule, 0) != CB_ERR);
2061#endif
2062 if (fLineSpacing_Orig.fRule == LineSpacing::eAtLeastTWIPSSpacing or fLineSpacing_Orig.fRule == LineSpacing::eExactTWIPSSpacing or
2063 fLineSpacing_Orig.fRule == LineSpacing::eExactLinesSpacing) {
2064 SetItemText (kParagraphSpacing_Dialog_LineSpaceArgFieldID, FormatTWIPSAsString (TWIPS (fLineSpacing_Orig.fArg)));
2065 }
2066 }
2067 SetFocusedItem (kParagraphSpacing_Dialog_SpaceBeforeFieldID);
2068 SelectItemText (kParagraphSpacing_Dialog_SpaceBeforeFieldID);
2069 inherited::PreDoModalHook ();
2070}
2071
2072DISABLE_COMPILER_MSC_WARNING_START (4706)
2073void Led_StdDialogHelper_ParagraphSpacingDialog::OnOK ()
2074{
2075 SDKString spaceBefore = GetItemText (kParagraphSpacing_Dialog_SpaceBeforeFieldID);
2076 if (not(fSpaceBefore_Valid = ParseStringToTWIPS (spaceBefore, &fSpaceBefore_Result))) {
2077 fSpaceBefore_Result = fSpaceBefore_Orig;
2078 }
2079
2080 SDKString spaceAfter = GetItemText (kParagraphSpacing_Dialog_SpaceAfterFieldID);
2081 if (not(fSpaceAfter_Valid = ParseStringToTWIPS (spaceAfter, &fSpaceAfter_Result))) {
2082 fSpaceAfter_Result = fSpaceAfter_Orig;
2083 }
2084
2085#if qStroika_Foundation_Common_Platform_Windows
2086 HWND popup = ::GetDlgItem (GetHWND (), kParagraphSpacing_Dialog_LineSpaceModeFieldID);
2087 AssertNotNull (popup);
2088 Assert (::IsWindow (popup));
2089 int r = static_cast<int> (::SendMessage (popup, CB_GETCURSEL, 0, 0));
2090#endif
2091 if (r >= 0 and r <= 5) {
2092 fLineSpacing_Valid = true;
2093 if (r == LineSpacing::eAtLeastTWIPSSpacing or r == LineSpacing::eExactTWIPSSpacing) {
2094 SDKString arg = GetItemText (kParagraphSpacing_Dialog_SpaceAfterFieldID);
2095 TWIPS argT = TWIPS{0};
2096 if (ParseStringToTWIPS (arg, &argT)) {
2097 fLineSpacing_Result = LineSpacing (LineSpacing::Rule (r), argT);
2098 }
2099 else {
2100 fLineSpacing_Valid = false;
2101 }
2102 }
2103 else if (r == LineSpacing::eExactLinesSpacing) {
2104 SDKString arg = GetItemText (kParagraphSpacing_Dialog_LineSpaceArgFieldID);
2105 int argI = 0;
2106 if (ParseStringToINT (arg, &argI)) {
2107 fLineSpacing_Result = LineSpacing (LineSpacing::Rule (r), argI);
2108 }
2109 else {
2110 fLineSpacing_Valid = false;
2111 }
2112 }
2113 else {
2114 fLineSpacing_Result = LineSpacing::Rule (r);
2115 }
2116 }
2117
2118 inherited::OnOK ();
2119}
2120DISABLE_COMPILER_MSC_WARNING_END (4706)
2121#endif
2122
2123#if qSupportOtherFontSizeDlg
2124/*
2125 ********************************************************************************
2126 ******************** Led_StdDialogHelper_OtherFontSizeDialog *******************
2127 ********************************************************************************
2128 */
2129#if qStroika_Foundation_Common_Platform_Windows
2130Led_StdDialogHelper_OtherFontSizeDialog::Led_StdDialogHelper_OtherFontSizeDialog (HINSTANCE hInstance, HWND parentWnd, const Characters::SDKChar* resID)
2131 : inherited (hInstance, resID, parentWnd)
2132 , fFontSize_Orig (0)
2133 , fFontSize_Result (0)
2134{
2135}
2136#endif
2137
2138void Led_StdDialogHelper_OtherFontSizeDialog::InitValues (DistanceType origFontSize)
2139{
2140 fFontSize_Orig = origFontSize;
2141 fFontSize_Result = origFontSize;
2142}
2143
2144void Led_StdDialogHelper_OtherFontSizeDialog::PreDoModalHook ()
2145{
2146 SetItemText (kOtherFontSize_Dialog_FontSizeEditFieldID, FormatINTAsString (fFontSize_Orig));
2147 SetFocusedItem (kOtherFontSize_Dialog_FontSizeEditFieldID);
2148 SelectItemText (kOtherFontSize_Dialog_FontSizeEditFieldID);
2149 inherited::PreDoModalHook ();
2150}
2151
2152void Led_StdDialogHelper_OtherFontSizeDialog::OnOK ()
2153{
2154 int r = 0;
2155 if (ParseStringToINT (GetItemText (kOtherFontSize_Dialog_FontSizeEditFieldID), &r)) {
2156 fFontSize_Result = r;
2157 }
2158 inherited::OnOK ();
2159}
2160#endif
2161
2162#if qSupportUnknownEmbeddingInfoDlg
2163/*
2164 ********************************************************************************
2165 ******************* Led_StdDialogHelper_UnknownEmbeddingInfoDialog *************
2166 ********************************************************************************
2167 */
2168#if qStroika_Foundation_Common_Platform_Windows
2169Led_StdDialogHelper_UnknownEmbeddingInfoDialog::Led_StdDialogHelper_UnknownEmbeddingInfoDialog (HINSTANCE hInstance, HWND parentWnd,
2170 const Characters::SDKChar* resID)
2171 : inherited (hInstance, resID, parentWnd)
2172 , fEmbeddingTypeName ()
2173{
2174}
2175#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2176Led_StdDialogHelper_UnknownEmbeddingInfoDialog::Led_StdDialogHelper_UnknownEmbeddingInfoDialog (GtkWindow* parentWindow)
2177 : inherited (parentWindow)
2178 , fEmbeddingTypeName ()
2179{
2180}
2181#endif
2182
2183void Led_StdDialogHelper_UnknownEmbeddingInfoDialog::PreDoModalHook ()
2184{
2185#if qStroika_Foundation_Common_Platform_Windows
2186 Characters::SDKChar messageText[1024];
2187 (void)::GetDlgItemText (GetHWND (), kLedStdDlg_UnknownEmbeddingInfoBox_TypeTextMsg, messageText, std::ssize (messageText));
2188
2189 SDKString m = messageText;
2190 ReplaceAllTokens (&m, Led_SDK_TCHAROF ("%0"), fEmbeddingTypeName);
2191 (void)::SetDlgItemText (GetHWND (), kLedStdDlg_UnknownEmbeddingInfoBox_TypeTextMsg, m.c_str ());
2192#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2193 GtkWidget* window = GetWindow ();
2194 gtk_container_set_border_width (GTK_CONTAINER (window), 10);
2195
2196 string message = "Selected object is of type '" + fEmbeddingTypeName + "'.";
2197 GtkWidget* label = gtk_label_new (message.c_str ());
2198
2199 gtk_widget_show (label);
2200
2201 /* a button to contain the pixmap widget */
2202 GtkWidget* button = gtk_button_new_with_label ("OK");
2203 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
2204 gtk_widget_show (button);
2205 SetOKButton (button);
2206#endif
2207 inherited::PreDoModalHook ();
2208}
2209#endif
2210
2211#if qSupportURLXEmbeddingInfoDlg
2212/*
2213 ********************************************************************************
2214 ******************* Led_StdDialogHelper_URLXEmbeddingInfoDialog ****************
2215 ********************************************************************************
2216 */
2217#if qStroika_Foundation_Common_Platform_Windows
2218Led_StdDialogHelper_URLXEmbeddingInfoDialog::Led_StdDialogHelper_URLXEmbeddingInfoDialog (HINSTANCE hInstance, HWND parentWnd,
2219 const Characters::SDKChar* resID)
2220 : inherited (hInstance, resID, parentWnd)
2221 , fEmbeddingTypeName ()
2222 , fTitleText ()
2223 , fURLText ()
2224{
2225}
2226#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2227Led_StdDialogHelper_URLXEmbeddingInfoDialog::Led_StdDialogHelper_URLXEmbeddingInfoDialog (GtkWindow* parentWindow)
2228 : inherited (parentWindow)
2229 , fTitleTextWidget (NULL)
2230 , fURLTextWidget (NULL)
2231 , fEmbeddingTypeName ()
2232 , fTitleText ()
2233 , fURLText ()
2234{
2235}
2236#endif
2237
2238void Led_StdDialogHelper_URLXEmbeddingInfoDialog::PreDoModalHook ()
2239{
2240#if qStroika_Foundation_Common_Platform_Windows
2241 Characters::SDKChar messageText[1024];
2242 (void)::GetDlgItemText (GetHWND (), kLedStdDlg_URLXEmbeddingInfoBox_TypeTextMsg, messageText, std::ssize (messageText));
2243
2244 SDKString m = messageText;
2245 ReplaceAllTokens (&m, Led_SDK_TCHAROF ("%0"), fEmbeddingTypeName);
2246 (void)::SetDlgItemText (GetHWND (), kLedStdDlg_URLXEmbeddingInfoBox_TypeTextMsg, m.c_str ());
2247
2248 (void)::SetDlgItemText (GetHWND (), kLedStdDlg_URLXEmbeddingInfoBox_TitleText, fTitleText.c_str ());
2249 (void)::SetDlgItemText (GetHWND (), kLedStdDlg_URLXEmbeddingInfoBox_URLText, fURLText.c_str ());
2250#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2251 // MUST FIX THIS FOR X-WINDOWS!!!!
2252
2253 GtkWidget* window = GetWindow ();
2254 gtk_container_set_border_width (GTK_CONTAINER (window), 10);
2255
2256 string message = "Selected object is of type '" + fEmbeddingTypeName + "'.";
2257 GtkWidget* label = gtk_label_new (message.c_str ());
2258
2259 gtk_widget_show (label);
2260
2261 /* a button to contain the pixmap widget */
2262 GtkWidget* button = gtk_button_new_with_label ("OK");
2263 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
2264 gtk_widget_show (button);
2265 SetOKButton (button);
2266#endif
2267#if qStroika_Foundation_Common_Platform_Windows
2268 SelectItemText (kLedStdDlg_URLXEmbeddingInfoBox_TitleText);
2269#endif
2270 inherited::PreDoModalHook ();
2271}
2272
2273void Led_StdDialogHelper_URLXEmbeddingInfoDialog::OnOK ()
2274{
2275#if qStroika_Foundation_Common_Platform_Windows
2276 Characters::SDKChar bufText[1024];
2277 (void)::GetDlgItemText (GetHWND (), kLedStdDlg_URLXEmbeddingInfoBox_TitleText, bufText, std::ssize (bufText));
2278 fTitleText = bufText;
2279 (void)::GetDlgItemText (GetHWND (), kLedStdDlg_URLXEmbeddingInfoBox_URLText, bufText, std::ssize (bufText));
2280 fURLText = bufText;
2281#endif
2282#if qStroika_Foundation_Common_Platform_Windows
2283 SelectItemText (kLedStdDlg_URLXEmbeddingInfoBox_TitleText);
2284#endif
2285 inherited::OnOK ();
2286}
2287#endif
2288
2289#if qSupportURLXEmbeddingInfoDlg
2290/*
2291 ********************************************************************************
2292 ******************* Led_StdDialogHelper_AddURLXEmbeddingInfoDialog *************
2293 ********************************************************************************
2294 */
2295#if qStroika_Foundation_Common_Platform_Windows
2296Led_StdDialogHelper_AddURLXEmbeddingInfoDialog::Led_StdDialogHelper_AddURLXEmbeddingInfoDialog (HINSTANCE hInstance, HWND parentWnd,
2297 const Characters::SDKChar* resID)
2298 : inherited (hInstance, resID, parentWnd)
2299 , fTitleText ()
2300 , fURLText ()
2301{
2302}
2303#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2304Led_StdDialogHelper_AddURLXEmbeddingInfoDialog::Led_StdDialogHelper_AddURLXEmbeddingInfoDialog (GtkWindow* parentWindow)
2305 : inherited (parentWindow)
2306 , fTitleTextWidget (NULL)
2307 , fURLTextWidget (NULL)
2308 , fTitleText ()
2309 , fURLText ()
2310{
2311}
2312#endif
2313
2314void Led_StdDialogHelper_AddURLXEmbeddingInfoDialog::PreDoModalHook ()
2315{
2316#if qStroika_Foundation_Common_Platform_Windows
2317 (void)::SetDlgItemText (GetHWND (), kLedStdDlg_AddURLXEmbeddingInfoBox_TitleText, fTitleText.c_str ());
2318 (void)::SetDlgItemText (GetHWND (), kLedStdDlg_AddURLXEmbeddingInfoBox_URLText, fURLText.c_str ());
2319#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2320 // MUST FIX THIS FOR X-WINDOWS!!!!
2321
2322 GtkWidget* window = GetWindow ();
2323 gtk_container_set_border_width (GTK_CONTAINER (window), 10);
2324
2325 string message = "ADD URL.";
2326 GtkWidget* label = gtk_label_new (message.c_str ());
2327
2328 gtk_widget_show (label);
2329
2330 /* a button to contain the pixmap widget */
2331 GtkWidget* button = gtk_button_new_with_label ("OK");
2332 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
2333 gtk_widget_show (button);
2334 SetOKButton (button);
2335#endif
2336 inherited::PreDoModalHook ();
2337}
2338
2339void Led_StdDialogHelper_AddURLXEmbeddingInfoDialog::OnOK ()
2340{
2341#if qStroika_Foundation_Common_Platform_Windows
2342 Characters::SDKChar bufText[1024];
2343 (void)::GetDlgItemText (GetHWND (), kLedStdDlg_AddURLXEmbeddingInfoBox_TitleText, bufText, std::ssize (bufText));
2344 fTitleText = bufText;
2345 (void)::GetDlgItemText (GetHWND (), kLedStdDlg_AddURLXEmbeddingInfoBox_URLText, bufText, std::ssize (bufText));
2346 fURLText = bufText;
2347#endif
2348 inherited::OnOK ();
2349}
2350#endif
2351
2352#if qSupportAddNewTableDlg
2353/*
2354 ********************************************************************************
2355 ********************* Led_StdDialogHelper_AddNewTableDialog ********************
2356 ********************************************************************************
2357 */
2358#if qStroika_Foundation_Common_Platform_Windows
2359Led_StdDialogHelper_AddNewTableDialog::Led_StdDialogHelper_AddNewTableDialog (HINSTANCE hInstance, HWND parentWnd, const Characters::SDKChar* resID)
2360 : inherited (hInstance, resID, parentWnd)
2361 , fRows (0)
2362 , fColumns (0)
2363{
2364}
2365#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2366Led_StdDialogHelper_AddNewTableDialog::Led_StdDialogHelper_AddNewTableDialog (GtkWindow* parentWindow)
2367 : inherited (parentWindow)
2368 , fRows (0)
2369 , fColumns (0)
2370{
2371}
2372#endif
2373
2374void Led_StdDialogHelper_AddNewTableDialog::PreDoModalHook ()
2375{
2376#if qStroika_Foundation_Common_Platform_Windows
2377#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2378#endif
2379#if qStroika_Foundation_Common_Platform_Windows
2380 SetItemText (kLedStdDlg_AddNewTableBox_RowCount, FormatINTAsString (static_cast<int> (fRows)));
2381 SetItemText (kLedStdDlg_AddNewTableBox_ColCount, FormatINTAsString (static_cast<int> (fColumns)));
2382 SetFocusedItem (kLedStdDlg_AddNewTableBox_RowCount);
2383 SelectItemText (kLedStdDlg_AddNewTableBox_RowCount);
2384#endif
2385
2386 inherited::PreDoModalHook ();
2387}
2388
2389void Led_StdDialogHelper_AddNewTableDialog::OnOK ()
2390{
2391#if qStroika_Foundation_Common_Platform_Windows
2392 int r = 0;
2393 int c = 0;
2394 if (ParseStringToINT (GetItemText (kLedStdDlg_AddNewTableBox_RowCount), &r) and
2395 ParseStringToINT (GetItemText (kLedStdDlg_AddNewTableBox_ColCount), &c) and r > 0 and c > 0 and r <= 100 and c <= 25) {
2396 fRows = r;
2397 fColumns = c;
2398 inherited::OnOK ();
2399 }
2400 else {
2401 Led_BeepNotify ();
2402 }
2403#endif
2404}
2405#endif
2406
2407#if qSupportEditTablePropertiesDlg
2408/*
2409 ********************************************************************************
2410 ***************** Led_StdDialogHelper_EditTablePropertiesDialog ****************
2411 ********************************************************************************
2412 */
2413#if qStroika_Foundation_Common_Platform_Windows
2414Led_StdDialogHelper_EditTablePropertiesDialog::Led_StdDialogHelper_EditTablePropertiesDialog (HINSTANCE hInstance, HWND parentWnd,
2415 const Characters::SDKChar* resID)
2416 : inherited (hInstance, resID, parentWnd)
2417 , fInfo ()
2418 , fBorderColorPopup (false)
2419 , fCellBackgroundColorPopup (true)
2420{
2421}
2422#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2423Led_StdDialogHelper_EditTablePropertiesDialog::Led_StdDialogHelper_EditTablePropertiesDialog (GtkWindow* parentWindow)
2424 : inherited (parentWindow)
2425 , fInfo ()
2426 , fBorderColorPopup (false)
2427 , fCellBackgroundColorPopup (true)
2428{
2429}
2430#endif
2431
2432void Led_StdDialogHelper_EditTablePropertiesDialog::PreDoModalHook ()
2433{
2434#if qStroika_Foundation_Common_Platform_Windows
2435 fBorderColorPopup.Attach (::GetDlgItem (GetHWND (), kLedStdDlg_EditTablePropertiesBox_BorderColor));
2436 fCellBackgroundColorPopup.Attach (::GetDlgItem (GetHWND (), kLedStdDlg_EditTablePropertiesBox_CellBackgroundColor));
2437#endif
2438
2439 fBorderColorPopup.SetSelectedColor (fInfo.fTableBorderColor);
2440 if (fInfo.fCellBackgroundColor_Common) {
2441 fCellBackgroundColorPopup.SetSelectedColor (fInfo.fCellBackgroundColor);
2442 }
2443 else {
2444 fCellBackgroundColorPopup.SetNoSelectedColor ();
2445 }
2446
2447#if qStroika_Foundation_Common_Platform_Windows
2448 SetItemText (kLedStdDlg_EditTablePropertiesBox_BorderWidth, FormatINTAsString (fInfo.fTableBorderWidth));
2449
2450 SetItemText (kLedStdDlg_EditTablePropertiesBox_CellMarginTop, FormatINTAsString (fInfo.fDefaultCellMargins.top));
2451 SetItemText (kLedStdDlg_EditTablePropertiesBox_CellMarginLeft, FormatINTAsString (fInfo.fDefaultCellMargins.left));
2452 SetItemText (kLedStdDlg_EditTablePropertiesBox_CellMarginBottom, FormatINTAsString (fInfo.fDefaultCellMargins.bottom));
2453 SetItemText (kLedStdDlg_EditTablePropertiesBox_CellMarginRight, FormatINTAsString (fInfo.fDefaultCellMargins.right));
2454
2455 SetItemText (kLedStdDlg_EditTablePropertiesBox_DefaultCellSpacing, FormatINTAsString (fInfo.fCellSpacing));
2456
2457 if (fInfo.fCellWidth_Common) {
2458 SetItemText (kLedStdDlg_EditTablePropertiesBox_ColumnWidth, FormatINTAsString (fInfo.fCellWidth));
2459 }
2460#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2461#endif
2462#if qStroika_Foundation_Common_Platform_Windows
2463 SetFocusedItem (kLedStdDlg_EditTablePropertiesBox_BorderWidth);
2464 SelectItemText (kLedStdDlg_EditTablePropertiesBox_BorderWidth);
2465#endif
2466 inherited::PreDoModalHook ();
2467}
2468
2469#if qStroika_Foundation_Common_Platform_Windows
2470BOOL Led_StdDialogHelper_EditTablePropertiesDialog::DialogProc (UINT message, WPARAM wParam, LPARAM lParam)
2471{
2472 switch (message) {
2473 case WM_COMMAND: {
2474 if (HIWORD (wParam) == CBN_SELCHANGE) {
2475 int controlID = LOWORD (wParam);
2476 switch (controlID) {
2477 case kLedStdDlg_EditTablePropertiesBox_BorderColor:
2478 fBorderColorPopup.OnSelChange ();
2479 break;
2480 case kLedStdDlg_EditTablePropertiesBox_CellBackgroundColor:
2481 fCellBackgroundColorPopup.OnSelChange ();
2482 break;
2483 }
2484 }
2485 } break;
2486 }
2487 return inherited::DialogProc (message, wParam, lParam);
2488}
2489#endif
2490
2491void Led_StdDialogHelper_EditTablePropertiesDialog::OnOK ()
2492{
2493#if qStroika_Foundation_Common_Platform_Windows
2494 Info result = fInfo;
2495 bool dataValid = true;
2496
2497 dataValid = dataValid and ParseStringToTWIPS (GetItemText (kLedStdDlg_EditTablePropertiesBox_BorderWidth), &result.fTableBorderWidth) and
2498 result.fTableBorderWidth >= 0 and result.fTableBorderWidth <= 1440;
2499
2500 dataValid = dataValid and ParseStringToTWIPS (GetItemText (kLedStdDlg_EditTablePropertiesBox_CellMarginTop), &result.fDefaultCellMargins.top) and
2501 result.fDefaultCellMargins.top >= 0 and result.fDefaultCellMargins.top <= 2 * 1440;
2502 dataValid = dataValid and
2503 ParseStringToTWIPS (GetItemText (kLedStdDlg_EditTablePropertiesBox_CellMarginLeft), &result.fDefaultCellMargins.left) and
2504 result.fDefaultCellMargins.left >= 0 and result.fDefaultCellMargins.left <= 2 * 1440;
2505 dataValid = dataValid and
2506 ParseStringToTWIPS (GetItemText (kLedStdDlg_EditTablePropertiesBox_CellMarginBottom), &result.fDefaultCellMargins.bottom) and
2507 result.fDefaultCellMargins.bottom >= 0 and result.fDefaultCellMargins.bottom <= 2 * 1440;
2508 dataValid = dataValid and
2509 ParseStringToTWIPS (GetItemText (kLedStdDlg_EditTablePropertiesBox_CellMarginRight), &result.fDefaultCellMargins.right) and
2510 result.fDefaultCellMargins.right >= 0 and result.fDefaultCellMargins.right <= 2 * 1440;
2511
2512 dataValid = dataValid and ParseStringToTWIPS (GetItemText (kLedStdDlg_EditTablePropertiesBox_DefaultCellSpacing), &result.fCellSpacing) and
2513 result.fCellSpacing >= 0 and result.fCellSpacing <= 2 * 1440;
2514
2515 result.fCellWidth_Common = ParseStringToTWIPS (GetItemText (kLedStdDlg_EditTablePropertiesBox_ColumnWidth), &result.fCellWidth) and
2516 result.fCellWidth >= 50 and result.fCellWidth <= 8 * 1440;
2517
2518 result.fCellBackgroundColor_Common = fCellBackgroundColorPopup.GetSelectedColor (&result.fCellBackgroundColor);
2519 (void)fBorderColorPopup.GetSelectedColor (&result.fTableBorderColor);
2520
2521 if (dataValid) {
2522 fInfo = result;
2523 inherited::OnOK ();
2524 }
2525 else {
2526 Led_BeepNotify ();
2527 }
2528#endif
2529}
2530#endif
2531
2532#if qSupportStdSpellCheckDlg
2533/*
2534 ********************************************************************************
2535 ************************ Led_StdDialogHelper_SpellCheckDialog ******************
2536 ********************************************************************************
2537 */
2538#if qStroika_Foundation_Common_Platform_Windows
2539Led_StdDialogHelper_SpellCheckDialog::Led_StdDialogHelper_SpellCheckDialog (SpellCheckDialogCallback& callback, HINSTANCE hInstance,
2540 HWND parentWnd, const Characters::SDKChar* resID)
2541 : inherited (hInstance, resID, parentWnd)
2542 , fCallback (callback)
2543 , fCurrentMisspellInfo (NULL)
2544#if qSupportLedDialogWidgets
2545 , fUndefinedWordWidget ()
2546 , fChangeTextWidget ()
2547#endif
2548{
2549}
2550#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2551Led_StdDialogHelper_SpellCheckDialog::Led_StdDialogHelper_SpellCheckDialog (SpellCheckDialogCallback& callback, GtkWindow* parentWindow)
2552 : inherited (parentWindow)
2553 , fCallback (callback)
2554 , fCurrentMisspellInfo (NULL)
2555 , fLookupTextWidget (NULL)
2556 , fChangeTextWidget (NULL)
2557{
2558}
2559#endif
2560
2561Led_StdDialogHelper_SpellCheckDialog::~Led_StdDialogHelper_SpellCheckDialog ()
2562{
2563 delete fCurrentMisspellInfo;
2564}
2565
2566#if qStroika_Foundation_Common_Platform_Windows
2567BOOL Led_StdDialogHelper_SpellCheckDialog::DialogProc (UINT message, WPARAM wParam, LPARAM lParam)
2568{
2569 switch (message) {
2570 case WM_COMMAND: {
2571 WORD notificationCode = HIWORD (wParam);
2572 WORD itemID = LOWORD (wParam);
2573 switch (itemID) {
2574 case kLedStdDlg_SpellCheckBox_IgnoreOnce:
2575 OnIgnoreButton ();
2576 return true;
2577 case kLedStdDlg_SpellCheckBox_IgnoreAll:
2578 OnIgnoreAllButton ();
2579 return true;
2580 case kLedStdDlg_SpellCheckBox_ChangeOnce:
2581 OnChangeButton ();
2582 return true;
2583 case kLedStdDlg_SpellCheckBox_ChangeAll:
2584 OnChangeAllButton ();
2585 return true;
2586 case kLedStdDlg_SpellCheckBox_AddDictionary:
2587 OnAddToDictionaryButton ();
2588 return true;
2589 case kLedStdDlg_SpellCheckBox_LookupOnWeb:
2590 OnLookupOnWebButton ();
2591 return true;
2592 case kLedStdDlg_SpellCheckBox_Options:
2593 OnOptionsDialogButton ();
2594 return true;
2595 case kLedStdDlg_SpellCheckBox_Close:
2596 OnCloseButton ();
2597 return true;
2598 case kLedStdDlg_SpellCheckBox_SuggestedList: {
2599 switch (notificationCode) {
2600 case LBN_DBLCLK:
2601 OnSuggestionListDoubleClick ();
2602 return true;
2603 case LBN_SELCHANGE:
2604 OnSuggestionListChangeSelection ();
2605 return true;
2606 }
2607 // fall through and do default...
2608 }
2609 }
2610 }
2611 }
2612 return inherited::DialogProc (message, wParam, lParam);
2613}
2614#endif
2615
2616void Led_StdDialogHelper_SpellCheckDialog::PreDoModalHook ()
2617{
2618#if qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2619 GtkWidget* actionArea = GTK_DIALOG (GetWindow ())->action_area;
2620 {
2621 fLookupTextWidget = gtk_entry_new ();
2622 gtk_container_add (GTK_CONTAINER (actionArea), fLookupTextWidget);
2623 gtk_widget_show (fLookupTextWidget);
2624 fChangeTextWidget = gtk_entry_new ();
2625 gtk_container_add (GTK_CONTAINER (actionArea), fChangeTextWidget);
2626 gtk_widget_show (fChangeTextWidget);
2627 // gtk_entry_set_text (GTK_ENTRY (fLookupTextWidget), Led_tString2SDKString (fUndefinedWordText).c_str ());
2628 // gtk_entry_select_region (GTK_ENTRY (fLookupTextWidget), 0, -1);
2629 // gtk_widget_grab_focus (fLookupTextWidget);
2630 }
2631 {
2632 GtkWidget* button = gtk_button_new_with_label ("Ignore");
2633 gtk_container_add (GTK_CONTAINER (actionArea), button);
2634 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
2635 gtk_widget_show (button);
2636 gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (Static_OnIgnoreButtonClick), (gpointer)this);
2637 }
2638 {
2639 GtkWidget* button = gtk_button_new_with_label ("Ignore All");
2640 gtk_container_add (GTK_CONTAINER (actionArea), button);
2641 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
2642 gtk_widget_show (button);
2643 gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (Static_OnIgnoreAllButtonClick), (gpointer)this);
2644 }
2645 {
2646 GtkWidget* button = gtk_button_new_with_label ("Change");
2647 gtk_container_add (GTK_CONTAINER (actionArea), button);
2648 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
2649 gtk_widget_show (button);
2650 gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (Static_OnChangeButtonClick), (gpointer)this);
2651 }
2652 {
2653 GtkWidget* button = gtk_button_new_with_label ("Change All");
2654 gtk_container_add (GTK_CONTAINER (actionArea), button);
2655 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
2656 gtk_widget_show (button);
2657 gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (Static_OnChangeAllButtonClick), (gpointer)this);
2658 }
2659 {
2660 GtkWidget* button = gtk_button_new_with_label ("Add to Dictionary");
2661 gtk_container_add (GTK_CONTAINER (actionArea), button);
2662 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
2663 gtk_widget_show (button);
2664 gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (Static_OnAddToDictionaryButtonClick), (gpointer)this);
2665 }
2666 {
2667 GtkWidget* button = gtk_button_new_with_label ("Lookup on Web");
2668 gtk_container_add (GTK_CONTAINER (actionArea), button);
2669 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
2670 gtk_widget_show (button);
2671 gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (Static_OnLookupOnWebButtonClick), (gpointer)this);
2672 }
2673 {
2674 GtkWidget* button = gtk_button_new_with_label ("Options...");
2675 gtk_container_add (GTK_CONTAINER (actionArea), button);
2676 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
2677 gtk_widget_show (button);
2678 gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (Static_OnOptionsDialogButtonClick), (gpointer)this);
2679 }
2680 {
2681 GtkWidget* button = gtk_button_new_with_label ("Close");
2682 gtk_container_add (GTK_CONTAINER (actionArea), button);
2683 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
2684 gtk_widget_show (button);
2685 gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (Static_OnCloseButtonClick), (gpointer)this);
2686 }
2687#endif
2688
2689#if qStroika_Foundation_Common_Platform_Windows && qSupportLedDialogWidgets
2690 /*
2691 * ReplaceWindow seems to work better than SubclassWindow - for reasons I don't FULLY understand.
2692 * (see SPR#1266).
2693 */
2694 fUndefinedWordWidget.ReplaceWindow (::GetDlgItem (GetHWND (), kLedStdDlg_SpellCheckBox_UnknownWordText));
2695 fChangeTextWidget.ReplaceWindow (::GetDlgItem (GetHWND (), kLedStdDlg_SpellCheckBox_ChangeText));
2696#endif
2697
2698#if qStroika_Foundation_Common_Platform_Windows
2699 SetItemEnabled (kLedStdDlg_SpellCheckBox_Options, fCallback.OptionsDialogEnabled ());
2700#endif
2701
2702 DoFindNextCall ();
2703
2704 inherited::PreDoModalHook ();
2705}
2706
2707void Led_StdDialogHelper_SpellCheckDialog::OnIgnoreButton ()
2708{
2709 fCallback.DoIgnore ();
2710 DoFindNextCall ();
2711}
2712
2713void Led_StdDialogHelper_SpellCheckDialog::OnIgnoreAllButton ()
2714{
2715 fCallback.DoIgnoreAll ();
2716 DoFindNextCall ();
2717}
2718
2719void Led_StdDialogHelper_SpellCheckDialog::OnChangeButton ()
2720{
2721#if qSupportLedDialogWidgets
2722 Led_tString changeText = fChangeTextWidget.GetText ();
2723#elif qStroika_Foundation_Common_Platform_Windows
2724 Led_tString changeText = Led_SDKString2tString (GetItemText (kLedStdDlg_SpellCheckBox_ChangeText));
2725#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2726 Led_tString changeText = Led_SDKString2tString (GetItemText (fChangeTextWidget));
2727#endif
2728 fCallback.DoChange (changeText);
2729 DoFindNextCall ();
2730}
2731
2732void Led_StdDialogHelper_SpellCheckDialog::OnChangeAllButton ()
2733{
2734#if qSupportLedDialogWidgets
2735 Led_tString changeText = fChangeTextWidget.GetText ();
2736#elif qStroika_Foundation_Common_Platform_Windows
2737 Led_tString changeText = Led_SDKString2tString (GetItemText (kLedStdDlg_SpellCheckBox_ChangeText));
2738#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2739 Led_tString changeText = Led_SDKString2tString (GetItemText (fChangeTextWidget));
2740#endif
2741 fCallback.DoChangeAll (changeText);
2742 DoFindNextCall ();
2743}
2744
2745void Led_StdDialogHelper_SpellCheckDialog::OnAddToDictionaryButton ()
2746{
2747#if qSupportLedDialogWidgets
2748 Led_tString undefinedWordText = fUndefinedWordWidget.GetText ();
2749#elif qStroika_Foundation_Common_Platform_Windows
2750 Led_tString undefinedWordText = Led_SDKString2tString (GetItemText (kLedStdDlg_SpellCheckBox_UnknownWordText));
2751#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2752 Led_tString undefinedWordText = Led_SDKString2tString (GetItemText (fLookupTextWidget));
2753#endif
2754 fCallback.AddToDictionary (undefinedWordText);
2755 DoFindNextCall ();
2756}
2757
2758void Led_StdDialogHelper_SpellCheckDialog::OnLookupOnWebButton ()
2759{
2760#if qSupportLedDialogWidgets
2761 Led_tString undefinedWordText = fUndefinedWordWidget.GetText ();
2762#elif qStroika_Foundation_Common_Platform_Windows
2763 Led_tString undefinedWordText = Led_SDKString2tString (GetItemText (kLedStdDlg_SpellCheckBox_UnknownWordText));
2764#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2765 Led_tString undefinedWordText = Led_SDKString2tString (GetItemText (fLookupTextWidget));
2766#endif
2767 fCallback.LookupOnWeb (undefinedWordText);
2768}
2769
2770void Led_StdDialogHelper_SpellCheckDialog::OnOptionsDialogButton ()
2771{
2772 fCallback.OptionsDialog ();
2773}
2774
2775void Led_StdDialogHelper_SpellCheckDialog::OnCloseButton ()
2776{
2777 OnCancel ();
2778}
2779
2780void Led_StdDialogHelper_SpellCheckDialog::OnSuggestionListChangeSelection ()
2781{
2782 if (fCurrentMisspellInfo != NULL) {
2783#if qStroika_Foundation_Common_Platform_Windows
2784 DialogItemID changeTextItem = kLedStdDlg_SpellCheckBox_ChangeText;
2785#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2786 DialogItemID changeTextItem = fChangeTextWidget;
2787#endif
2788
2789#if qStroika_Foundation_Common_Platform_Windows
2790 LRESULT itemSelResult = ::SendMessage (GetDlgItem (GetHWND (), kLedStdDlg_SpellCheckBox_SuggestedList), LB_GETCURSEL, 0, 0);
2791#else
2792 Assert (false); // REALLY NYI!!!
2793 int itemSelResult = 0;
2794#endif
2795 if (itemSelResult >= 0 and static_cast<size_t> (itemSelResult) < fCurrentMisspellInfo->fSuggestions.size ()) {
2796 Led_tString changeText = fCurrentMisspellInfo->fSuggestions[itemSelResult];
2797#if qSupportLedDialogWidgets
2798 fChangeTextWidget.SetText (changeText);
2799#else
2800 SetItemText (changeTextItem, Led_tString2SDKString (changeText));
2801#endif
2802 SelectItemText (changeTextItem);
2803 }
2804 }
2805}
2806
2807void Led_StdDialogHelper_SpellCheckDialog::OnSuggestionListDoubleClick ()
2808{
2809 OnChangeButton ();
2810}
2811
2812void Led_StdDialogHelper_SpellCheckDialog::DoFindNextCall ()
2813{
2814 delete fCurrentMisspellInfo;
2815 fCurrentMisspellInfo = NULL;
2816 fCurrentMisspellInfo = fCallback.GetNextMisspelling ();
2817
2818#if qStroika_Foundation_Common_Platform_Windows
2819 DialogItemID undefinedTextItem = kLedStdDlg_SpellCheckBox_UnknownWordText;
2820 DialogItemID changeTextItem = kLedStdDlg_SpellCheckBox_ChangeText;
2821#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2822 DialogItemID undefinedTextItem = fLookupTextWidget;
2823 DialogItemID changeTextItem = fChangeTextWidget;
2824#endif
2825
2826#if qStroika_Foundation_Common_Platform_Windows
2827 ::SendMessage (GetDlgItem (GetHWND (), kLedStdDlg_SpellCheckBox_SuggestedList), LB_RESETCONTENT, 0, 0);
2828#endif
2829
2830 Led_tString undefinedWordText;
2831 Led_tString changeText;
2832 if (fCurrentMisspellInfo != NULL) {
2833 undefinedWordText = fCurrentMisspellInfo->fUndefinedWord;
2834 if (not fCurrentMisspellInfo->fSuggestions.empty ()) {
2835 changeText = fCurrentMisspellInfo->fSuggestions[0];
2836#if qStroika_Foundation_Common_Platform_Windows
2837 for (auto i = fCurrentMisspellInfo->fSuggestions.begin (); i != fCurrentMisspellInfo->fSuggestions.end (); ++i) {
2838 ::SendMessage (GetDlgItem (GetHWND (), kLedStdDlg_SpellCheckBox_SuggestedList), LB_ADDSTRING, 0,
2839 reinterpret_cast<LPARAM> (Led_tString2SDKString (*i).c_str ()));
2840 }
2841#endif
2842 }
2843 }
2844
2845#if qSupportLedDialogWidgets
2846 fUndefinedWordWidget.SetText (undefinedWordText);
2847 fChangeTextWidget.SetText (changeText);
2848#else
2849 SetItemText (undefinedTextItem, Led_tString2SDKString (undefinedWordText));
2850 SetItemText (changeTextItem, Led_tString2SDKString (changeText));
2851#endif
2852
2853#if qStroika_Foundation_Common_Platform_Windows
2854 SetItemEnabled (kLedStdDlg_SpellCheckBox_IgnoreOnce, fCurrentMisspellInfo != NULL);
2855 SetItemEnabled (kLedStdDlg_SpellCheckBox_IgnoreAll, fCurrentMisspellInfo != NULL);
2856 SetItemEnabled (kLedStdDlg_SpellCheckBox_ChangeOnce, fCurrentMisspellInfo != NULL);
2857 SetItemEnabled (kLedStdDlg_SpellCheckBox_ChangeAll, fCurrentMisspellInfo != NULL);
2858 SetItemEnabled (kLedStdDlg_SpellCheckBox_AddDictionary, fCurrentMisspellInfo != NULL and fCallback.AddToDictionaryEnabled ());
2859#endif
2860
2861 SelectItemText (undefinedTextItem);
2862 SelectItemText (changeTextItem);
2863 SetFocusedItem (changeTextItem);
2864}
2865
2866#if qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2867void Led_StdDialogHelper_SpellCheckDialog::Static_OnIgnoreButtonClick (GtkWidget* widget, gpointer data)
2868{
2869 Led_StdDialogHelper_SpellCheckDialog* dlg = reinterpret_cast<Led_StdDialogHelper_SpellCheckDialog*> (data);
2870 dlg->OnIgnoreButton ();
2871}
2872
2873void Led_StdDialogHelper_SpellCheckDialog::Static_OnIgnoreAllButtonClick (GtkWidget* widget, gpointer data)
2874{
2875 Led_StdDialogHelper_SpellCheckDialog* dlg = reinterpret_cast<Led_StdDialogHelper_SpellCheckDialog*> (data);
2876 dlg->OnIgnoreAllButton ();
2877}
2878
2879void Led_StdDialogHelper_SpellCheckDialog::Static_OnChangeButtonClick (GtkWidget* widget, gpointer data)
2880{
2881 Led_StdDialogHelper_SpellCheckDialog* dlg = reinterpret_cast<Led_StdDialogHelper_SpellCheckDialog*> (data);
2882 dlg->OnChangeButton ();
2883}
2884
2885void Led_StdDialogHelper_SpellCheckDialog::Static_OnChangeAllButtonClick (GtkWidget* widget, gpointer data)
2886{
2887 Led_StdDialogHelper_SpellCheckDialog* dlg = reinterpret_cast<Led_StdDialogHelper_SpellCheckDialog*> (data);
2888 dlg->OnChangeAllButton ();
2889}
2890
2891void Led_StdDialogHelper_SpellCheckDialog::Static_OnAddToDictionaryButtonClick (GtkWidget* widget, gpointer data)
2892{
2893 Led_StdDialogHelper_SpellCheckDialog* dlg = reinterpret_cast<Led_StdDialogHelper_SpellCheckDialog*> (data);
2894 dlg->OnAddToDictionaryButton ();
2895}
2896
2897void Led_StdDialogHelper_SpellCheckDialog::Static_OnLookupOnWebButtonClick (GtkWidget* widget, gpointer data)
2898{
2899 Led_StdDialogHelper_SpellCheckDialog* dlg = reinterpret_cast<Led_StdDialogHelper_SpellCheckDialog*> (data);
2900 dlg->OnLookupOnWebButton ();
2901}
2902
2903void Led_StdDialogHelper_SpellCheckDialog::Static_OnOptionsDialogButtonClick (GtkWidget* widget, gpointer data)
2904{
2905 Led_StdDialogHelper_SpellCheckDialog* dlg = reinterpret_cast<Led_StdDialogHelper_SpellCheckDialog*> (data);
2906 dlg->OnOptionsDialogButton ();
2907}
2908
2909void Led_StdDialogHelper_SpellCheckDialog::Static_OnCloseButtonClick (GtkWidget* widget, gpointer data)
2910{
2911 Led_StdDialogHelper_SpellCheckDialog* dlg = reinterpret_cast<Led_StdDialogHelper_SpellCheckDialog*> (data);
2912 dlg->OnCloseButton ();
2913}
2914#endif
2915
2916#endif
#define AssertNotNull(p)
Definition Assertions.h:333
#define qStroika_Foundation_Debug_AssertionsChecked
The qStroika_Foundation_Debug_AssertionsChecked flag determines if assertions are checked and validat...
Definition Assertions.h:48
#define RequireNotNull(p)
Definition Assertions.h:347
#define Verify(c)
Definition Assertions.h:419
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201
Logically halfway between std::array and std::vector; Smart 'direct memory array' - which when needed...
conditional_t< qTargetPlatformSDKUseswchar_t, wchar_t, char > SDKChar
Definition SDKChar.h:71
basic_string< SDKChar > SDKString
Definition SDKString.h:38