Stroika Library 3.0d16
 
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> (Memory::NEltsOf (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, static_cast<int> (Memory::NEltsOf (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,
1902 static_cast<int> (Memory::NEltsOf (messageText)));
1903 m = messageText;
1904 ReplaceAllTokens (&m, Led_SDK_TCHAROF ("%0"), fAppName);
1905 ReplaceAllTokens (&m, Led_SDK_TCHAROF ("%1"), fTypeList);
1906 (void)::SetDlgItemText (GetHWND (), kLedStdDlg_UpdateWin32FileAssocsDialog_KeepCheckingCheckboxMsg, m.c_str ());
1907
1908 ::CheckDlgButton (GetHWND (), kLedStdDlg_UpdateWin32FileAssocsDialog_KeepCheckingCheckboxMsg, fKeepChecking);
1909#endif
1910 inherited::PreDoModalHook ();
1911}
1912
1913void Led_StdDialogHelper_UpdateWin32FileAssocsDialog::OnOK ()
1914{
1915 fKeepChecking = !!::IsDlgButtonChecked (GetHWND (), kLedStdDlg_UpdateWin32FileAssocsDialog_KeepCheckingCheckboxMsg);
1916 inherited::OnOK ();
1917}
1918
1919void Led_StdDialogHelper_UpdateWin32FileAssocsDialog::OnCancel ()
1920{
1921 fKeepChecking = !!::IsDlgButtonChecked (GetHWND (), kLedStdDlg_UpdateWin32FileAssocsDialog_KeepCheckingCheckboxMsg);
1922 inherited::OnCancel ();
1923}
1924#endif
1925
1926#if qSupportParagraphIndentsDlg
1927/*
1928 ********************************************************************************
1929 ******************* Led_StdDialogHelper_ParagraphIndentsDialog *****************
1930 ********************************************************************************
1931 */
1932#if qStroika_Foundation_Common_Platform_Windows
1933Led_StdDialogHelper_ParagraphIndentsDialog::Led_StdDialogHelper_ParagraphIndentsDialog (HINSTANCE hInstance, HWND parentWnd,
1934 const Characters::SDKChar* resID)
1935 : inherited (hInstance, resID, parentWnd)
1936 , fLeftMargin_Valid (false)
1937 , fLeftMargin_Orig (TWIPS{0})
1938 , fLeftMargin_Result (TWIPS{0})
1939 , fRightMargin_Valid (false)
1940 , fRightMargin_Orig (TWIPS{0})
1941 , fRightMargin_Result (TWIPS{0})
1942 , fFirstIndent_Valid (false)
1943 , fFirstIndent_Orig (TWIPS{0})
1944 , fFirstIndent_Result (TWIPS{0})
1945{
1946}
1947#endif
1948
1949void Led_StdDialogHelper_ParagraphIndentsDialog::InitValues (TWIPS leftMargin, bool leftMarginValid, TWIPS rightMargin,
1950 bool rightMarginValid, TWIPS firstIndent, bool firstIndentValid)
1951{
1952 fLeftMargin_Valid = leftMarginValid;
1953 fLeftMargin_Orig = leftMargin;
1954 fLeftMargin_Result = leftMargin;
1955 fRightMargin_Valid = rightMarginValid;
1956 fRightMargin_Orig = rightMargin;
1957 fRightMargin_Result = rightMargin;
1958 fFirstIndent_Valid = firstIndentValid;
1959 fFirstIndent_Orig = firstIndent;
1960 fFirstIndent_Result = firstIndent;
1961}
1962
1963void Led_StdDialogHelper_ParagraphIndentsDialog::PreDoModalHook ()
1964{
1965 if (fLeftMargin_Valid) {
1966 SetItemText (kLedStdDlg_ParagraphIndents_LeftMarginFieldID, FormatTWIPSAsString (fLeftMargin_Orig));
1967 }
1968 if (fRightMargin_Valid) {
1969 SetItemText (kLedStdDlg_ParagraphIndents_RightMarginFieldID, FormatTWIPSAsString (fRightMargin_Orig));
1970 }
1971 if (fFirstIndent_Valid) {
1972 SetItemText (kLedStdDlg_ParagraphIndents_FirstIndentFieldID, FormatTWIPSAsString (fFirstIndent_Orig));
1973 }
1974 SetFocusedItem (kLedStdDlg_ParagraphIndents_LeftMarginFieldID);
1975 SelectItemText (kLedStdDlg_ParagraphIndents_LeftMarginFieldID);
1976 inherited::PreDoModalHook ();
1977}
1978
1979DISABLE_COMPILER_MSC_WARNING_START (4706)
1980void Led_StdDialogHelper_ParagraphIndentsDialog::OnOK ()
1981{
1982 SDKString leftMargin = GetItemText (kLedStdDlg_ParagraphIndents_LeftMarginFieldID);
1983 if (not(fLeftMargin_Valid = ParseStringToTWIPS (leftMargin, &fLeftMargin_Result))) {
1984 fLeftMargin_Result = fLeftMargin_Orig;
1985 }
1986
1987 SDKString rightMargin = GetItemText (kLedStdDlg_ParagraphIndents_RightMarginFieldID);
1988 if (not(fRightMargin_Valid = ParseStringToTWIPS (rightMargin, &fRightMargin_Result))) {
1989 fRightMargin_Result = fRightMargin_Orig;
1990 }
1991
1992 SDKString firstIndent = GetItemText (kLedStdDlg_ParagraphIndents_FirstIndentFieldID);
1993 if (not(fLeftMargin_Valid = ParseStringToTWIPS (firstIndent, &fFirstIndent_Result))) {
1994 fFirstIndent_Result = fFirstIndent_Orig;
1995 }
1996 inherited::OnOK ();
1997}
1998DISABLE_COMPILER_MSC_WARNING_END (4706)
1999#endif
2000
2001#if qSupportParagraphSpacingDlg
2002/*
2003 ********************************************************************************
2004 ******************* Led_StdDialogHelper_ParagraphSpacingDialog *****************
2005 ********************************************************************************
2006 */
2007#if qStroika_Foundation_Common_Platform_Windows
2008Led_StdDialogHelper_ParagraphSpacingDialog::Led_StdDialogHelper_ParagraphSpacingDialog (HINSTANCE hInstance, HWND parentWnd,
2009 const Characters::SDKChar* resID)
2010 : inherited (hInstance, resID, parentWnd)
2011 , fSpaceBefore_Valid (false)
2012 , fSpaceBefore_Orig (TWIPS{0})
2013 , fSpaceBefore_Result (TWIPS{0})
2014 , fSpaceAfter_Valid (false)
2015 , fSpaceAfter_Orig (TWIPS{0})
2016 , fSpaceAfter_Result (TWIPS{0})
2017 , fLineSpacing_Valid (false)
2018 , fLineSpacing_Orig ()
2019 , fLineSpacing_Result ()
2020{
2021}
2022#endif
2023
2024void Led_StdDialogHelper_ParagraphSpacingDialog::InitValues (TWIPS spaceBefore, bool spaceBeforeValid, TWIPS spaceAfter,
2025 bool spaceAfterValid, LineSpacing lineSpacing, bool lineSpacingValid)
2026{
2027 fSpaceBefore_Valid = spaceBeforeValid;
2028 fSpaceBefore_Orig = spaceBefore;
2029 fSpaceBefore_Result = spaceBefore;
2030 fSpaceAfter_Valid = spaceAfterValid;
2031 fSpaceAfter_Orig = spaceAfter;
2032 fSpaceAfter_Result = spaceAfter;
2033 fLineSpacing_Valid = lineSpacingValid;
2034 fLineSpacing_Orig = lineSpacing;
2035 fLineSpacing_Result = lineSpacing;
2036}
2037
2038void Led_StdDialogHelper_ParagraphSpacingDialog::PreDoModalHook ()
2039{
2040#if qStroika_Foundation_Common_Platform_Windows
2041 HWND popup = ::GetDlgItem (GetHWND (), kParagraphSpacing_Dialog_LineSpaceModeFieldID);
2042 AssertNotNull (popup);
2043 Assert (::IsWindow (popup));
2044 (void)::SendMessage (popup, CB_RESETCONTENT, 0, 0);
2045 Verify (::SendMessage (popup, CB_ADDSTRING, 0, reinterpret_cast<LPARAM> (_T ("Single"))) != CB_ERR);
2046 Verify (::SendMessage (popup, CB_ADDSTRING, 0, reinterpret_cast<LPARAM> (_T ("1.5 lines"))) != CB_ERR);
2047 Verify (::SendMessage (popup, CB_ADDSTRING, 0, reinterpret_cast<LPARAM> (_T ("Double"))) != CB_ERR);
2048 Verify (::SendMessage (popup, CB_ADDSTRING, 0, reinterpret_cast<LPARAM> (_T ("At Least (TWIPS)"))) != CB_ERR);
2049 Verify (::SendMessage (popup, CB_ADDSTRING, 0, reinterpret_cast<LPARAM> (_T ("Exact (TWIPS)"))) != CB_ERR);
2050 Verify (::SendMessage (popup, CB_ADDSTRING, 0, reinterpret_cast<LPARAM> (_T ("Exact (1/20 lines)"))) != CB_ERR);
2051#endif
2052
2053 if (fSpaceBefore_Valid) {
2054 SetItemText (kParagraphSpacing_Dialog_SpaceBeforeFieldID, FormatTWIPSAsString (fSpaceBefore_Orig));
2055 }
2056 if (fSpaceAfter_Valid) {
2057 SetItemText (kParagraphSpacing_Dialog_SpaceAfterFieldID, FormatTWIPSAsString (fSpaceAfter_Orig));
2058 }
2059 if (fLineSpacing_Valid) {
2060#if qStroika_Foundation_Common_Platform_Windows
2061 Verify (::SendMessage (popup, CB_SETCURSEL, fLineSpacing_Orig.fRule, 0) != CB_ERR);
2062#endif
2063 if (fLineSpacing_Orig.fRule == LineSpacing::eAtLeastTWIPSSpacing or fLineSpacing_Orig.fRule == LineSpacing::eExactTWIPSSpacing or
2064 fLineSpacing_Orig.fRule == LineSpacing::eExactLinesSpacing) {
2065 SetItemText (kParagraphSpacing_Dialog_LineSpaceArgFieldID, FormatTWIPSAsString (TWIPS (fLineSpacing_Orig.fArg)));
2066 }
2067 }
2068 SetFocusedItem (kParagraphSpacing_Dialog_SpaceBeforeFieldID);
2069 SelectItemText (kParagraphSpacing_Dialog_SpaceBeforeFieldID);
2070 inherited::PreDoModalHook ();
2071}
2072
2073DISABLE_COMPILER_MSC_WARNING_START (4706)
2074void Led_StdDialogHelper_ParagraphSpacingDialog::OnOK ()
2075{
2076 SDKString spaceBefore = GetItemText (kParagraphSpacing_Dialog_SpaceBeforeFieldID);
2077 if (not(fSpaceBefore_Valid = ParseStringToTWIPS (spaceBefore, &fSpaceBefore_Result))) {
2078 fSpaceBefore_Result = fSpaceBefore_Orig;
2079 }
2080
2081 SDKString spaceAfter = GetItemText (kParagraphSpacing_Dialog_SpaceAfterFieldID);
2082 if (not(fSpaceAfter_Valid = ParseStringToTWIPS (spaceAfter, &fSpaceAfter_Result))) {
2083 fSpaceAfter_Result = fSpaceAfter_Orig;
2084 }
2085
2086#if qStroika_Foundation_Common_Platform_Windows
2087 HWND popup = ::GetDlgItem (GetHWND (), kParagraphSpacing_Dialog_LineSpaceModeFieldID);
2088 AssertNotNull (popup);
2089 Assert (::IsWindow (popup));
2090 int r = static_cast<int> (::SendMessage (popup, CB_GETCURSEL, 0, 0));
2091#endif
2092 if (r >= 0 and r <= 5) {
2093 fLineSpacing_Valid = true;
2094 if (r == LineSpacing::eAtLeastTWIPSSpacing or r == LineSpacing::eExactTWIPSSpacing) {
2095 SDKString arg = GetItemText (kParagraphSpacing_Dialog_SpaceAfterFieldID);
2096 TWIPS argT = TWIPS{0};
2097 if (ParseStringToTWIPS (arg, &argT)) {
2098 fLineSpacing_Result = LineSpacing (LineSpacing::Rule (r), argT);
2099 }
2100 else {
2101 fLineSpacing_Valid = false;
2102 }
2103 }
2104 else if (r == LineSpacing::eExactLinesSpacing) {
2105 SDKString arg = GetItemText (kParagraphSpacing_Dialog_LineSpaceArgFieldID);
2106 int argI = 0;
2107 if (ParseStringToINT (arg, &argI)) {
2108 fLineSpacing_Result = LineSpacing (LineSpacing::Rule (r), argI);
2109 }
2110 else {
2111 fLineSpacing_Valid = false;
2112 }
2113 }
2114 else {
2115 fLineSpacing_Result = LineSpacing::Rule (r);
2116 }
2117 }
2118
2119 inherited::OnOK ();
2120}
2121DISABLE_COMPILER_MSC_WARNING_END (4706)
2122#endif
2123
2124#if qSupportOtherFontSizeDlg
2125/*
2126 ********************************************************************************
2127 ******************** Led_StdDialogHelper_OtherFontSizeDialog *******************
2128 ********************************************************************************
2129 */
2130#if qStroika_Foundation_Common_Platform_Windows
2131Led_StdDialogHelper_OtherFontSizeDialog::Led_StdDialogHelper_OtherFontSizeDialog (HINSTANCE hInstance, HWND parentWnd, const Characters::SDKChar* resID)
2132 : inherited (hInstance, resID, parentWnd)
2133 , fFontSize_Orig (0)
2134 , fFontSize_Result (0)
2135{
2136}
2137#endif
2138
2139void Led_StdDialogHelper_OtherFontSizeDialog::InitValues (DistanceType origFontSize)
2140{
2141 fFontSize_Orig = origFontSize;
2142 fFontSize_Result = origFontSize;
2143}
2144
2145void Led_StdDialogHelper_OtherFontSizeDialog::PreDoModalHook ()
2146{
2147 SetItemText (kOtherFontSize_Dialog_FontSizeEditFieldID, FormatINTAsString (fFontSize_Orig));
2148 SetFocusedItem (kOtherFontSize_Dialog_FontSizeEditFieldID);
2149 SelectItemText (kOtherFontSize_Dialog_FontSizeEditFieldID);
2150 inherited::PreDoModalHook ();
2151}
2152
2153void Led_StdDialogHelper_OtherFontSizeDialog::OnOK ()
2154{
2155 int r = 0;
2156 if (ParseStringToINT (GetItemText (kOtherFontSize_Dialog_FontSizeEditFieldID), &r)) {
2157 fFontSize_Result = r;
2158 }
2159 inherited::OnOK ();
2160}
2161#endif
2162
2163#if qSupportUnknownEmbeddingInfoDlg
2164/*
2165 ********************************************************************************
2166 ******************* Led_StdDialogHelper_UnknownEmbeddingInfoDialog *************
2167 ********************************************************************************
2168 */
2169#if qStroika_Foundation_Common_Platform_Windows
2170Led_StdDialogHelper_UnknownEmbeddingInfoDialog::Led_StdDialogHelper_UnknownEmbeddingInfoDialog (HINSTANCE hInstance, HWND parentWnd,
2171 const Characters::SDKChar* resID)
2172 : inherited (hInstance, resID, parentWnd)
2173 , fEmbeddingTypeName ()
2174{
2175}
2176#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2177Led_StdDialogHelper_UnknownEmbeddingInfoDialog::Led_StdDialogHelper_UnknownEmbeddingInfoDialog (GtkWindow* parentWindow)
2178 : inherited (parentWindow)
2179 , fEmbeddingTypeName ()
2180{
2181}
2182#endif
2183
2184void Led_StdDialogHelper_UnknownEmbeddingInfoDialog::PreDoModalHook ()
2185{
2186#if qStroika_Foundation_Common_Platform_Windows
2187 Characters::SDKChar messageText[1024];
2188 (void)::GetDlgItemText (GetHWND (), kLedStdDlg_UnknownEmbeddingInfoBox_TypeTextMsg, messageText, static_cast<int> (Memory::NEltsOf (messageText)));
2189
2190 SDKString m = messageText;
2191 ReplaceAllTokens (&m, Led_SDK_TCHAROF ("%0"), fEmbeddingTypeName);
2192 (void)::SetDlgItemText (GetHWND (), kLedStdDlg_UnknownEmbeddingInfoBox_TypeTextMsg, m.c_str ());
2193#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2194 GtkWidget* window = GetWindow ();
2195 gtk_container_set_border_width (GTK_CONTAINER (window), 10);
2196
2197 string message = "Selected object is of type '" + fEmbeddingTypeName + "'.";
2198 GtkWidget* label = gtk_label_new (message.c_str ());
2199
2200 gtk_widget_show (label);
2201
2202 /* a button to contain the pixmap widget */
2203 GtkWidget* button = gtk_button_new_with_label ("OK");
2204 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
2205 gtk_widget_show (button);
2206 SetOKButton (button);
2207#endif
2208 inherited::PreDoModalHook ();
2209}
2210#endif
2211
2212#if qSupportURLXEmbeddingInfoDlg
2213/*
2214 ********************************************************************************
2215 ******************* Led_StdDialogHelper_URLXEmbeddingInfoDialog ****************
2216 ********************************************************************************
2217 */
2218#if qStroika_Foundation_Common_Platform_Windows
2219Led_StdDialogHelper_URLXEmbeddingInfoDialog::Led_StdDialogHelper_URLXEmbeddingInfoDialog (HINSTANCE hInstance, HWND parentWnd,
2220 const Characters::SDKChar* resID)
2221 : inherited (hInstance, resID, parentWnd)
2222 , fEmbeddingTypeName ()
2223 , fTitleText ()
2224 , fURLText ()
2225{
2226}
2227#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2228Led_StdDialogHelper_URLXEmbeddingInfoDialog::Led_StdDialogHelper_URLXEmbeddingInfoDialog (GtkWindow* parentWindow)
2229 : inherited (parentWindow)
2230 , fTitleTextWidget (NULL)
2231 , fURLTextWidget (NULL)
2232 , fEmbeddingTypeName ()
2233 , fTitleText ()
2234 , fURLText ()
2235{
2236}
2237#endif
2238
2239void Led_StdDialogHelper_URLXEmbeddingInfoDialog::PreDoModalHook ()
2240{
2241#if qStroika_Foundation_Common_Platform_Windows
2242 Characters::SDKChar messageText[1024];
2243 (void)::GetDlgItemText (GetHWND (), kLedStdDlg_URLXEmbeddingInfoBox_TypeTextMsg, messageText, static_cast<int> (Memory::NEltsOf (messageText)));
2244
2245 SDKString m = messageText;
2246 ReplaceAllTokens (&m, Led_SDK_TCHAROF ("%0"), fEmbeddingTypeName);
2247 (void)::SetDlgItemText (GetHWND (), kLedStdDlg_URLXEmbeddingInfoBox_TypeTextMsg, m.c_str ());
2248
2249 (void)::SetDlgItemText (GetHWND (), kLedStdDlg_URLXEmbeddingInfoBox_TitleText, fTitleText.c_str ());
2250 (void)::SetDlgItemText (GetHWND (), kLedStdDlg_URLXEmbeddingInfoBox_URLText, fURLText.c_str ());
2251#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2252 // MUST FIX THIS FOR X-WINDOWS!!!!
2253
2254 GtkWidget* window = GetWindow ();
2255 gtk_container_set_border_width (GTK_CONTAINER (window), 10);
2256
2257 string message = "Selected object is of type '" + fEmbeddingTypeName + "'.";
2258 GtkWidget* label = gtk_label_new (message.c_str ());
2259
2260 gtk_widget_show (label);
2261
2262 /* a button to contain the pixmap widget */
2263 GtkWidget* button = gtk_button_new_with_label ("OK");
2264 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
2265 gtk_widget_show (button);
2266 SetOKButton (button);
2267#endif
2268#if qStroika_Foundation_Common_Platform_Windows
2269 SelectItemText (kLedStdDlg_URLXEmbeddingInfoBox_TitleText);
2270#endif
2271 inherited::PreDoModalHook ();
2272}
2273
2274void Led_StdDialogHelper_URLXEmbeddingInfoDialog::OnOK ()
2275{
2276#if qStroika_Foundation_Common_Platform_Windows
2277 Characters::SDKChar bufText[1024];
2278 (void)::GetDlgItemText (GetHWND (), kLedStdDlg_URLXEmbeddingInfoBox_TitleText, bufText, static_cast<int> (Memory::NEltsOf (bufText)));
2279 fTitleText = bufText;
2280 (void)::GetDlgItemText (GetHWND (), kLedStdDlg_URLXEmbeddingInfoBox_URLText, bufText, static_cast<int> (Memory::NEltsOf (bufText)));
2281 fURLText = bufText;
2282#endif
2283#if qStroika_Foundation_Common_Platform_Windows
2284 SelectItemText (kLedStdDlg_URLXEmbeddingInfoBox_TitleText);
2285#endif
2286 inherited::OnOK ();
2287}
2288#endif
2289
2290#if qSupportURLXEmbeddingInfoDlg
2291/*
2292 ********************************************************************************
2293 ******************* Led_StdDialogHelper_AddURLXEmbeddingInfoDialog *************
2294 ********************************************************************************
2295 */
2296#if qStroika_Foundation_Common_Platform_Windows
2297Led_StdDialogHelper_AddURLXEmbeddingInfoDialog::Led_StdDialogHelper_AddURLXEmbeddingInfoDialog (HINSTANCE hInstance, HWND parentWnd,
2298 const Characters::SDKChar* resID)
2299 : inherited (hInstance, resID, parentWnd)
2300 , fTitleText ()
2301 , fURLText ()
2302{
2303}
2304#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2305Led_StdDialogHelper_AddURLXEmbeddingInfoDialog::Led_StdDialogHelper_AddURLXEmbeddingInfoDialog (GtkWindow* parentWindow)
2306 : inherited (parentWindow)
2307 , fTitleTextWidget (NULL)
2308 , fURLTextWidget (NULL)
2309 , fTitleText ()
2310 , fURLText ()
2311{
2312}
2313#endif
2314
2315void Led_StdDialogHelper_AddURLXEmbeddingInfoDialog::PreDoModalHook ()
2316{
2317#if qStroika_Foundation_Common_Platform_Windows
2318 (void)::SetDlgItemText (GetHWND (), kLedStdDlg_AddURLXEmbeddingInfoBox_TitleText, fTitleText.c_str ());
2319 (void)::SetDlgItemText (GetHWND (), kLedStdDlg_AddURLXEmbeddingInfoBox_URLText, fURLText.c_str ());
2320#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2321 // MUST FIX THIS FOR X-WINDOWS!!!!
2322
2323 GtkWidget* window = GetWindow ();
2324 gtk_container_set_border_width (GTK_CONTAINER (window), 10);
2325
2326 string message = "ADD URL.";
2327 GtkWidget* label = gtk_label_new (message.c_str ());
2328
2329 gtk_widget_show (label);
2330
2331 /* a button to contain the pixmap widget */
2332 GtkWidget* button = gtk_button_new_with_label ("OK");
2333 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
2334 gtk_widget_show (button);
2335 SetOKButton (button);
2336#endif
2337 inherited::PreDoModalHook ();
2338}
2339
2340void Led_StdDialogHelper_AddURLXEmbeddingInfoDialog::OnOK ()
2341{
2342#if qStroika_Foundation_Common_Platform_Windows
2343 Characters::SDKChar bufText[1024];
2344 (void)::GetDlgItemText (GetHWND (), kLedStdDlg_AddURLXEmbeddingInfoBox_TitleText, bufText, static_cast<int> (Memory::NEltsOf (bufText)));
2345 fTitleText = bufText;
2346 (void)::GetDlgItemText (GetHWND (), kLedStdDlg_AddURLXEmbeddingInfoBox_URLText, bufText, static_cast<int> (Memory::NEltsOf (bufText)));
2347 fURLText = bufText;
2348#endif
2349 inherited::OnOK ();
2350}
2351#endif
2352
2353#if qSupportAddNewTableDlg
2354/*
2355 ********************************************************************************
2356 ********************* Led_StdDialogHelper_AddNewTableDialog ********************
2357 ********************************************************************************
2358 */
2359#if qStroika_Foundation_Common_Platform_Windows
2360Led_StdDialogHelper_AddNewTableDialog::Led_StdDialogHelper_AddNewTableDialog (HINSTANCE hInstance, HWND parentWnd, const Characters::SDKChar* resID)
2361 : inherited (hInstance, resID, parentWnd)
2362 , fRows (0)
2363 , fColumns (0)
2364{
2365}
2366#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2367Led_StdDialogHelper_AddNewTableDialog::Led_StdDialogHelper_AddNewTableDialog (GtkWindow* parentWindow)
2368 : inherited (parentWindow)
2369 , fRows (0)
2370 , fColumns (0)
2371{
2372}
2373#endif
2374
2375void Led_StdDialogHelper_AddNewTableDialog::PreDoModalHook ()
2376{
2377#if qStroika_Foundation_Common_Platform_Windows
2378#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2379#endif
2380#if qStroika_Foundation_Common_Platform_Windows
2381 SetItemText (kLedStdDlg_AddNewTableBox_RowCount, FormatINTAsString (static_cast<int> (fRows)));
2382 SetItemText (kLedStdDlg_AddNewTableBox_ColCount, FormatINTAsString (static_cast<int> (fColumns)));
2383 SetFocusedItem (kLedStdDlg_AddNewTableBox_RowCount);
2384 SelectItemText (kLedStdDlg_AddNewTableBox_RowCount);
2385#endif
2386
2387 inherited::PreDoModalHook ();
2388}
2389
2390void Led_StdDialogHelper_AddNewTableDialog::OnOK ()
2391{
2392#if qStroika_Foundation_Common_Platform_Windows
2393 int r = 0;
2394 int c = 0;
2395 if (ParseStringToINT (GetItemText (kLedStdDlg_AddNewTableBox_RowCount), &r) and
2396 ParseStringToINT (GetItemText (kLedStdDlg_AddNewTableBox_ColCount), &c) and r > 0 and c > 0 and r <= 100 and c <= 25) {
2397 fRows = r;
2398 fColumns = c;
2399 inherited::OnOK ();
2400 }
2401 else {
2402 Led_BeepNotify ();
2403 }
2404#endif
2405}
2406#endif
2407
2408#if qSupportEditTablePropertiesDlg
2409/*
2410 ********************************************************************************
2411 ***************** Led_StdDialogHelper_EditTablePropertiesDialog ****************
2412 ********************************************************************************
2413 */
2414#if qStroika_Foundation_Common_Platform_Windows
2415Led_StdDialogHelper_EditTablePropertiesDialog::Led_StdDialogHelper_EditTablePropertiesDialog (HINSTANCE hInstance, HWND parentWnd,
2416 const Characters::SDKChar* resID)
2417 : inherited (hInstance, resID, parentWnd)
2418 , fInfo ()
2419 , fBorderColorPopup (false)
2420 , fCellBackgroundColorPopup (true)
2421{
2422}
2423#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2424Led_StdDialogHelper_EditTablePropertiesDialog::Led_StdDialogHelper_EditTablePropertiesDialog (GtkWindow* parentWindow)
2425 : inherited (parentWindow)
2426 , fInfo ()
2427 , fBorderColorPopup (false)
2428 , fCellBackgroundColorPopup (true)
2429{
2430}
2431#endif
2432
2433void Led_StdDialogHelper_EditTablePropertiesDialog::PreDoModalHook ()
2434{
2435#if qStroika_Foundation_Common_Platform_Windows
2436 fBorderColorPopup.Attach (::GetDlgItem (GetHWND (), kLedStdDlg_EditTablePropertiesBox_BorderColor));
2437 fCellBackgroundColorPopup.Attach (::GetDlgItem (GetHWND (), kLedStdDlg_EditTablePropertiesBox_CellBackgroundColor));
2438#endif
2439
2440 fBorderColorPopup.SetSelectedColor (fInfo.fTableBorderColor);
2441 if (fInfo.fCellBackgroundColor_Common) {
2442 fCellBackgroundColorPopup.SetSelectedColor (fInfo.fCellBackgroundColor);
2443 }
2444 else {
2445 fCellBackgroundColorPopup.SetNoSelectedColor ();
2446 }
2447
2448#if qStroika_Foundation_Common_Platform_Windows
2449 SetItemText (kLedStdDlg_EditTablePropertiesBox_BorderWidth, FormatINTAsString (fInfo.fTableBorderWidth));
2450
2451 SetItemText (kLedStdDlg_EditTablePropertiesBox_CellMarginTop, FormatINTAsString (fInfo.fDefaultCellMargins.top));
2452 SetItemText (kLedStdDlg_EditTablePropertiesBox_CellMarginLeft, FormatINTAsString (fInfo.fDefaultCellMargins.left));
2453 SetItemText (kLedStdDlg_EditTablePropertiesBox_CellMarginBottom, FormatINTAsString (fInfo.fDefaultCellMargins.bottom));
2454 SetItemText (kLedStdDlg_EditTablePropertiesBox_CellMarginRight, FormatINTAsString (fInfo.fDefaultCellMargins.right));
2455
2456 SetItemText (kLedStdDlg_EditTablePropertiesBox_DefaultCellSpacing, FormatINTAsString (fInfo.fCellSpacing));
2457
2458 if (fInfo.fCellWidth_Common) {
2459 SetItemText (kLedStdDlg_EditTablePropertiesBox_ColumnWidth, FormatINTAsString (fInfo.fCellWidth));
2460 }
2461#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2462#endif
2463#if qStroika_Foundation_Common_Platform_Windows
2464 SetFocusedItem (kLedStdDlg_EditTablePropertiesBox_BorderWidth);
2465 SelectItemText (kLedStdDlg_EditTablePropertiesBox_BorderWidth);
2466#endif
2467 inherited::PreDoModalHook ();
2468}
2469
2470#if qStroika_Foundation_Common_Platform_Windows
2471BOOL Led_StdDialogHelper_EditTablePropertiesDialog::DialogProc (UINT message, WPARAM wParam, LPARAM lParam)
2472{
2473 switch (message) {
2474 case WM_COMMAND: {
2475 if (HIWORD (wParam) == CBN_SELCHANGE) {
2476 int controlID = LOWORD (wParam);
2477 switch (controlID) {
2478 case kLedStdDlg_EditTablePropertiesBox_BorderColor:
2479 fBorderColorPopup.OnSelChange ();
2480 break;
2481 case kLedStdDlg_EditTablePropertiesBox_CellBackgroundColor:
2482 fCellBackgroundColorPopup.OnSelChange ();
2483 break;
2484 }
2485 }
2486 } break;
2487 }
2488 return inherited::DialogProc (message, wParam, lParam);
2489}
2490#endif
2491
2492void Led_StdDialogHelper_EditTablePropertiesDialog::OnOK ()
2493{
2494#if qStroika_Foundation_Common_Platform_Windows
2495 Info result = fInfo;
2496 bool dataValid = true;
2497
2498 dataValid = dataValid and ParseStringToTWIPS (GetItemText (kLedStdDlg_EditTablePropertiesBox_BorderWidth), &result.fTableBorderWidth) and
2499 result.fTableBorderWidth >= 0 and result.fTableBorderWidth <= 1440;
2500
2501 dataValid = dataValid and ParseStringToTWIPS (GetItemText (kLedStdDlg_EditTablePropertiesBox_CellMarginTop), &result.fDefaultCellMargins.top) and
2502 result.fDefaultCellMargins.top >= 0 and result.fDefaultCellMargins.top <= 2 * 1440;
2503 dataValid = dataValid and
2504 ParseStringToTWIPS (GetItemText (kLedStdDlg_EditTablePropertiesBox_CellMarginLeft), &result.fDefaultCellMargins.left) and
2505 result.fDefaultCellMargins.left >= 0 and result.fDefaultCellMargins.left <= 2 * 1440;
2506 dataValid = dataValid and
2507 ParseStringToTWIPS (GetItemText (kLedStdDlg_EditTablePropertiesBox_CellMarginBottom), &result.fDefaultCellMargins.bottom) and
2508 result.fDefaultCellMargins.bottom >= 0 and result.fDefaultCellMargins.bottom <= 2 * 1440;
2509 dataValid = dataValid and
2510 ParseStringToTWIPS (GetItemText (kLedStdDlg_EditTablePropertiesBox_CellMarginRight), &result.fDefaultCellMargins.right) and
2511 result.fDefaultCellMargins.right >= 0 and result.fDefaultCellMargins.right <= 2 * 1440;
2512
2513 dataValid = dataValid and ParseStringToTWIPS (GetItemText (kLedStdDlg_EditTablePropertiesBox_DefaultCellSpacing), &result.fCellSpacing) and
2514 result.fCellSpacing >= 0 and result.fCellSpacing <= 2 * 1440;
2515
2516 result.fCellWidth_Common = ParseStringToTWIPS (GetItemText (kLedStdDlg_EditTablePropertiesBox_ColumnWidth), &result.fCellWidth) and
2517 result.fCellWidth >= 50 and result.fCellWidth <= 8 * 1440;
2518
2519 result.fCellBackgroundColor_Common = fCellBackgroundColorPopup.GetSelectedColor (&result.fCellBackgroundColor);
2520 (void)fBorderColorPopup.GetSelectedColor (&result.fTableBorderColor);
2521
2522 if (dataValid) {
2523 fInfo = result;
2524 inherited::OnOK ();
2525 }
2526 else {
2527 Led_BeepNotify ();
2528 }
2529#endif
2530}
2531#endif
2532
2533#if qSupportStdSpellCheckDlg
2534/*
2535 ********************************************************************************
2536 ************************ Led_StdDialogHelper_SpellCheckDialog ******************
2537 ********************************************************************************
2538 */
2539#if qStroika_Foundation_Common_Platform_Windows
2540Led_StdDialogHelper_SpellCheckDialog::Led_StdDialogHelper_SpellCheckDialog (SpellCheckDialogCallback& callback, HINSTANCE hInstance,
2541 HWND parentWnd, const Characters::SDKChar* resID)
2542 : inherited (hInstance, resID, parentWnd)
2543 , fCallback (callback)
2544 , fCurrentMisspellInfo (NULL)
2545#if qSupportLedDialogWidgets
2546 , fUndefinedWordWidget ()
2547 , fChangeTextWidget ()
2548#endif
2549{
2550}
2551#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2552Led_StdDialogHelper_SpellCheckDialog::Led_StdDialogHelper_SpellCheckDialog (SpellCheckDialogCallback& callback, GtkWindow* parentWindow)
2553 : inherited (parentWindow)
2554 , fCallback (callback)
2555 , fCurrentMisspellInfo (NULL)
2556 , fLookupTextWidget (NULL)
2557 , fChangeTextWidget (NULL)
2558{
2559}
2560#endif
2561
2562Led_StdDialogHelper_SpellCheckDialog::~Led_StdDialogHelper_SpellCheckDialog ()
2563{
2564 delete fCurrentMisspellInfo;
2565}
2566
2567#if qStroika_Foundation_Common_Platform_Windows
2568BOOL Led_StdDialogHelper_SpellCheckDialog::DialogProc (UINT message, WPARAM wParam, LPARAM lParam)
2569{
2570 switch (message) {
2571 case WM_COMMAND: {
2572 WORD notificationCode = HIWORD (wParam);
2573 WORD itemID = LOWORD (wParam);
2574 switch (itemID) {
2575 case kLedStdDlg_SpellCheckBox_IgnoreOnce:
2576 OnIgnoreButton ();
2577 return true;
2578 case kLedStdDlg_SpellCheckBox_IgnoreAll:
2579 OnIgnoreAllButton ();
2580 return true;
2581 case kLedStdDlg_SpellCheckBox_ChangeOnce:
2582 OnChangeButton ();
2583 return true;
2584 case kLedStdDlg_SpellCheckBox_ChangeAll:
2585 OnChangeAllButton ();
2586 return true;
2587 case kLedStdDlg_SpellCheckBox_AddDictionary:
2588 OnAddToDictionaryButton ();
2589 return true;
2590 case kLedStdDlg_SpellCheckBox_LookupOnWeb:
2591 OnLookupOnWebButton ();
2592 return true;
2593 case kLedStdDlg_SpellCheckBox_Options:
2594 OnOptionsDialogButton ();
2595 return true;
2596 case kLedStdDlg_SpellCheckBox_Close:
2597 OnCloseButton ();
2598 return true;
2599 case kLedStdDlg_SpellCheckBox_SuggestedList: {
2600 switch (notificationCode) {
2601 case LBN_DBLCLK:
2602 OnSuggestionListDoubleClick ();
2603 return true;
2604 case LBN_SELCHANGE:
2605 OnSuggestionListChangeSelection ();
2606 return true;
2607 }
2608 // fall through and do default...
2609 }
2610 }
2611 }
2612 }
2613 return inherited::DialogProc (message, wParam, lParam);
2614}
2615#endif
2616
2617void Led_StdDialogHelper_SpellCheckDialog::PreDoModalHook ()
2618{
2619#if qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2620 GtkWidget* actionArea = GTK_DIALOG (GetWindow ())->action_area;
2621 {
2622 fLookupTextWidget = gtk_entry_new ();
2623 gtk_container_add (GTK_CONTAINER (actionArea), fLookupTextWidget);
2624 gtk_widget_show (fLookupTextWidget);
2625 fChangeTextWidget = gtk_entry_new ();
2626 gtk_container_add (GTK_CONTAINER (actionArea), fChangeTextWidget);
2627 gtk_widget_show (fChangeTextWidget);
2628 // gtk_entry_set_text (GTK_ENTRY (fLookupTextWidget), Led_tString2SDKString (fUndefinedWordText).c_str ());
2629 // gtk_entry_select_region (GTK_ENTRY (fLookupTextWidget), 0, -1);
2630 // gtk_widget_grab_focus (fLookupTextWidget);
2631 }
2632 {
2633 GtkWidget* button = gtk_button_new_with_label ("Ignore");
2634 gtk_container_add (GTK_CONTAINER (actionArea), button);
2635 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
2636 gtk_widget_show (button);
2637 gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (Static_OnIgnoreButtonClick), (gpointer)this);
2638 }
2639 {
2640 GtkWidget* button = gtk_button_new_with_label ("Ignore All");
2641 gtk_container_add (GTK_CONTAINER (actionArea), button);
2642 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
2643 gtk_widget_show (button);
2644 gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (Static_OnIgnoreAllButtonClick), (gpointer)this);
2645 }
2646 {
2647 GtkWidget* button = gtk_button_new_with_label ("Change");
2648 gtk_container_add (GTK_CONTAINER (actionArea), button);
2649 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
2650 gtk_widget_show (button);
2651 gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (Static_OnChangeButtonClick), (gpointer)this);
2652 }
2653 {
2654 GtkWidget* button = gtk_button_new_with_label ("Change All");
2655 gtk_container_add (GTK_CONTAINER (actionArea), button);
2656 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
2657 gtk_widget_show (button);
2658 gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (Static_OnChangeAllButtonClick), (gpointer)this);
2659 }
2660 {
2661 GtkWidget* button = gtk_button_new_with_label ("Add to Dictionary");
2662 gtk_container_add (GTK_CONTAINER (actionArea), button);
2663 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
2664 gtk_widget_show (button);
2665 gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (Static_OnAddToDictionaryButtonClick), (gpointer)this);
2666 }
2667 {
2668 GtkWidget* button = gtk_button_new_with_label ("Lookup on Web");
2669 gtk_container_add (GTK_CONTAINER (actionArea), button);
2670 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
2671 gtk_widget_show (button);
2672 gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (Static_OnLookupOnWebButtonClick), (gpointer)this);
2673 }
2674 {
2675 GtkWidget* button = gtk_button_new_with_label ("Options...");
2676 gtk_container_add (GTK_CONTAINER (actionArea), button);
2677 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
2678 gtk_widget_show (button);
2679 gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (Static_OnOptionsDialogButtonClick), (gpointer)this);
2680 }
2681 {
2682 GtkWidget* button = gtk_button_new_with_label ("Close");
2683 gtk_container_add (GTK_CONTAINER (actionArea), button);
2684 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
2685 gtk_widget_show (button);
2686 gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (Static_OnCloseButtonClick), (gpointer)this);
2687 }
2688#endif
2689
2690#if qStroika_Foundation_Common_Platform_Windows && qSupportLedDialogWidgets
2691 /*
2692 * ReplaceWindow seems to work better than SubclassWindow - for reasons I don't FULLY understand.
2693 * (see SPR#1266).
2694 */
2695 fUndefinedWordWidget.ReplaceWindow (::GetDlgItem (GetHWND (), kLedStdDlg_SpellCheckBox_UnknownWordText));
2696 fChangeTextWidget.ReplaceWindow (::GetDlgItem (GetHWND (), kLedStdDlg_SpellCheckBox_ChangeText));
2697#endif
2698
2699#if qStroika_Foundation_Common_Platform_Windows
2700 SetItemEnabled (kLedStdDlg_SpellCheckBox_Options, fCallback.OptionsDialogEnabled ());
2701#endif
2702
2703 DoFindNextCall ();
2704
2705 inherited::PreDoModalHook ();
2706}
2707
2708void Led_StdDialogHelper_SpellCheckDialog::OnIgnoreButton ()
2709{
2710 fCallback.DoIgnore ();
2711 DoFindNextCall ();
2712}
2713
2714void Led_StdDialogHelper_SpellCheckDialog::OnIgnoreAllButton ()
2715{
2716 fCallback.DoIgnoreAll ();
2717 DoFindNextCall ();
2718}
2719
2720void Led_StdDialogHelper_SpellCheckDialog::OnChangeButton ()
2721{
2722#if qSupportLedDialogWidgets
2723 Led_tString changeText = fChangeTextWidget.GetText ();
2724#elif qStroika_Foundation_Common_Platform_Windows
2725 Led_tString changeText = Led_SDKString2tString (GetItemText (kLedStdDlg_SpellCheckBox_ChangeText));
2726#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2727 Led_tString changeText = Led_SDKString2tString (GetItemText (fChangeTextWidget));
2728#endif
2729 fCallback.DoChange (changeText);
2730 DoFindNextCall ();
2731}
2732
2733void Led_StdDialogHelper_SpellCheckDialog::OnChangeAllButton ()
2734{
2735#if qSupportLedDialogWidgets
2736 Led_tString changeText = fChangeTextWidget.GetText ();
2737#elif qStroika_Foundation_Common_Platform_Windows
2738 Led_tString changeText = Led_SDKString2tString (GetItemText (kLedStdDlg_SpellCheckBox_ChangeText));
2739#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2740 Led_tString changeText = Led_SDKString2tString (GetItemText (fChangeTextWidget));
2741#endif
2742 fCallback.DoChangeAll (changeText);
2743 DoFindNextCall ();
2744}
2745
2746void Led_StdDialogHelper_SpellCheckDialog::OnAddToDictionaryButton ()
2747{
2748#if qSupportLedDialogWidgets
2749 Led_tString undefinedWordText = fUndefinedWordWidget.GetText ();
2750#elif qStroika_Foundation_Common_Platform_Windows
2751 Led_tString undefinedWordText = Led_SDKString2tString (GetItemText (kLedStdDlg_SpellCheckBox_UnknownWordText));
2752#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2753 Led_tString undefinedWordText = Led_SDKString2tString (GetItemText (fLookupTextWidget));
2754#endif
2755 fCallback.AddToDictionary (undefinedWordText);
2756 DoFindNextCall ();
2757}
2758
2759void Led_StdDialogHelper_SpellCheckDialog::OnLookupOnWebButton ()
2760{
2761#if qSupportLedDialogWidgets
2762 Led_tString undefinedWordText = fUndefinedWordWidget.GetText ();
2763#elif qStroika_Foundation_Common_Platform_Windows
2764 Led_tString undefinedWordText = Led_SDKString2tString (GetItemText (kLedStdDlg_SpellCheckBox_UnknownWordText));
2765#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2766 Led_tString undefinedWordText = Led_SDKString2tString (GetItemText (fLookupTextWidget));
2767#endif
2768 fCallback.LookupOnWeb (undefinedWordText);
2769}
2770
2771void Led_StdDialogHelper_SpellCheckDialog::OnOptionsDialogButton ()
2772{
2773 fCallback.OptionsDialog ();
2774}
2775
2776void Led_StdDialogHelper_SpellCheckDialog::OnCloseButton ()
2777{
2778 OnCancel ();
2779}
2780
2781void Led_StdDialogHelper_SpellCheckDialog::OnSuggestionListChangeSelection ()
2782{
2783 if (fCurrentMisspellInfo != NULL) {
2784#if qStroika_Foundation_Common_Platform_Windows
2785 DialogItemID changeTextItem = kLedStdDlg_SpellCheckBox_ChangeText;
2786#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2787 DialogItemID changeTextItem = fChangeTextWidget;
2788#endif
2789
2790#if qStroika_Foundation_Common_Platform_Windows
2791 LRESULT itemSelResult = ::SendMessage (GetDlgItem (GetHWND (), kLedStdDlg_SpellCheckBox_SuggestedList), LB_GETCURSEL, 0, 0);
2792#else
2793 Assert (false); // REALLY NYI!!!
2794 int itemSelResult = 0;
2795#endif
2796 if (itemSelResult >= 0 and static_cast<size_t> (itemSelResult) < fCurrentMisspellInfo->fSuggestions.size ()) {
2797 Led_tString changeText = fCurrentMisspellInfo->fSuggestions[itemSelResult];
2798#if qSupportLedDialogWidgets
2799 fChangeTextWidget.SetText (changeText);
2800#else
2801 SetItemText (changeTextItem, Led_tString2SDKString (changeText));
2802#endif
2803 SelectItemText (changeTextItem);
2804 }
2805 }
2806}
2807
2808void Led_StdDialogHelper_SpellCheckDialog::OnSuggestionListDoubleClick ()
2809{
2810 OnChangeButton ();
2811}
2812
2813void Led_StdDialogHelper_SpellCheckDialog::DoFindNextCall ()
2814{
2815 delete fCurrentMisspellInfo;
2816 fCurrentMisspellInfo = NULL;
2817 fCurrentMisspellInfo = fCallback.GetNextMisspelling ();
2818
2819#if qStroika_Foundation_Common_Platform_Windows
2820 DialogItemID undefinedTextItem = kLedStdDlg_SpellCheckBox_UnknownWordText;
2821 DialogItemID changeTextItem = kLedStdDlg_SpellCheckBox_ChangeText;
2822#elif qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2823 DialogItemID undefinedTextItem = fLookupTextWidget;
2824 DialogItemID changeTextItem = fChangeTextWidget;
2825#endif
2826
2827#if qStroika_Foundation_Common_Platform_Windows
2828 ::SendMessage (GetDlgItem (GetHWND (), kLedStdDlg_SpellCheckBox_SuggestedList), LB_RESETCONTENT, 0, 0);
2829#endif
2830
2831 Led_tString undefinedWordText;
2832 Led_tString changeText;
2833 if (fCurrentMisspellInfo != NULL) {
2834 undefinedWordText = fCurrentMisspellInfo->fUndefinedWord;
2835 if (not fCurrentMisspellInfo->fSuggestions.empty ()) {
2836 changeText = fCurrentMisspellInfo->fSuggestions[0];
2837#if qStroika_Foundation_Common_Platform_Windows
2838 for (auto i = fCurrentMisspellInfo->fSuggestions.begin (); i != fCurrentMisspellInfo->fSuggestions.end (); ++i) {
2839 ::SendMessage (GetDlgItem (GetHWND (), kLedStdDlg_SpellCheckBox_SuggestedList), LB_ADDSTRING, 0,
2840 reinterpret_cast<LPARAM> (Led_tString2SDKString (*i).c_str ()));
2841 }
2842#endif
2843 }
2844 }
2845
2846#if qSupportLedDialogWidgets
2847 fUndefinedWordWidget.SetText (undefinedWordText);
2848 fChangeTextWidget.SetText (changeText);
2849#else
2850 SetItemText (undefinedTextItem, Led_tString2SDKString (undefinedWordText));
2851 SetItemText (changeTextItem, Led_tString2SDKString (changeText));
2852#endif
2853
2854#if qStroika_Foundation_Common_Platform_Windows
2855 SetItemEnabled (kLedStdDlg_SpellCheckBox_IgnoreOnce, fCurrentMisspellInfo != NULL);
2856 SetItemEnabled (kLedStdDlg_SpellCheckBox_IgnoreAll, fCurrentMisspellInfo != NULL);
2857 SetItemEnabled (kLedStdDlg_SpellCheckBox_ChangeOnce, fCurrentMisspellInfo != NULL);
2858 SetItemEnabled (kLedStdDlg_SpellCheckBox_ChangeAll, fCurrentMisspellInfo != NULL);
2859 SetItemEnabled (kLedStdDlg_SpellCheckBox_AddDictionary, fCurrentMisspellInfo != NULL and fCallback.AddToDictionaryEnabled ());
2860#endif
2861
2862 SelectItemText (undefinedTextItem);
2863 SelectItemText (changeTextItem);
2864 SetFocusedItem (changeTextItem);
2865}
2866
2867#if qStroika_FeatureSupported_XWindows && qUseGTKForLedStandardDialogs
2868void Led_StdDialogHelper_SpellCheckDialog::Static_OnIgnoreButtonClick (GtkWidget* widget, gpointer data)
2869{
2870 Led_StdDialogHelper_SpellCheckDialog* dlg = reinterpret_cast<Led_StdDialogHelper_SpellCheckDialog*> (data);
2871 dlg->OnIgnoreButton ();
2872}
2873
2874void Led_StdDialogHelper_SpellCheckDialog::Static_OnIgnoreAllButtonClick (GtkWidget* widget, gpointer data)
2875{
2876 Led_StdDialogHelper_SpellCheckDialog* dlg = reinterpret_cast<Led_StdDialogHelper_SpellCheckDialog*> (data);
2877 dlg->OnIgnoreAllButton ();
2878}
2879
2880void Led_StdDialogHelper_SpellCheckDialog::Static_OnChangeButtonClick (GtkWidget* widget, gpointer data)
2881{
2882 Led_StdDialogHelper_SpellCheckDialog* dlg = reinterpret_cast<Led_StdDialogHelper_SpellCheckDialog*> (data);
2883 dlg->OnChangeButton ();
2884}
2885
2886void Led_StdDialogHelper_SpellCheckDialog::Static_OnChangeAllButtonClick (GtkWidget* widget, gpointer data)
2887{
2888 Led_StdDialogHelper_SpellCheckDialog* dlg = reinterpret_cast<Led_StdDialogHelper_SpellCheckDialog*> (data);
2889 dlg->OnChangeAllButton ();
2890}
2891
2892void Led_StdDialogHelper_SpellCheckDialog::Static_OnAddToDictionaryButtonClick (GtkWidget* widget, gpointer data)
2893{
2894 Led_StdDialogHelper_SpellCheckDialog* dlg = reinterpret_cast<Led_StdDialogHelper_SpellCheckDialog*> (data);
2895 dlg->OnAddToDictionaryButton ();
2896}
2897
2898void Led_StdDialogHelper_SpellCheckDialog::Static_OnLookupOnWebButtonClick (GtkWidget* widget, gpointer data)
2899{
2900 Led_StdDialogHelper_SpellCheckDialog* dlg = reinterpret_cast<Led_StdDialogHelper_SpellCheckDialog*> (data);
2901 dlg->OnLookupOnWebButton ();
2902}
2903
2904void Led_StdDialogHelper_SpellCheckDialog::Static_OnOptionsDialogButtonClick (GtkWidget* widget, gpointer data)
2905{
2906 Led_StdDialogHelper_SpellCheckDialog* dlg = reinterpret_cast<Led_StdDialogHelper_SpellCheckDialog*> (data);
2907 dlg->OnOptionsDialogButton ();
2908}
2909
2910void Led_StdDialogHelper_SpellCheckDialog::Static_OnCloseButtonClick (GtkWidget* widget, gpointer data)
2911{
2912 Led_StdDialogHelper_SpellCheckDialog* dlg = reinterpret_cast<Led_StdDialogHelper_SpellCheckDialog*> (data);
2913 dlg->OnCloseButton ();
2914}
2915#endif
2916
2917#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