1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/dlgcmn.cpp
3 // Purpose: common (to all ports) wxDialog functions
4 // Author: Vadim Zeitlin
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #include "wx/dialog.h"
31 #include "wx/button.h"
32 #include "wx/dcclient.h"
34 #include "wx/settings.h"
35 #include "wx/stattext.h"
37 #include "wx/containr.h"
40 #include "wx/statline.h"
41 #include "wx/sysopt.h"
42 #include "wx/module.h"
43 #include "wx/private/stattext.h"
44 #include "wx/bookctrl.h"
45 #include "wx/scrolwin.h"
48 #include "wx/display.h"
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
55 BEGIN_EVENT_TABLE(wxDialogBase
, wxTopLevelWindow
)
56 EVT_BUTTON(wxID_ANY
, wxDialogBase::OnButton
)
58 EVT_CLOSE(wxDialogBase::OnCloseWindow
)
60 EVT_CHAR_HOOK(wxDialogBase::OnCharHook
)
63 wxDialogLayoutAdapter
* wxDialogBase::sm_layoutAdapter
= NULL
;
64 bool wxDialogBase::sm_layoutAdaptation
= false;
66 void wxDialogBase::Init()
69 m_affirmativeId
= wxID_OK
;
70 m_escapeId
= wxID_ANY
;
71 m_layoutAdaptationLevel
= 3;
72 m_layoutAdaptationDone
= FALSE
;
73 m_layoutAdaptationMode
= wxDIALOG_ADAPTATION_MODE_DEFAULT
;
75 // the dialogs have this flag on by default to prevent the events from the
76 // dialog controls from reaching the parent frame which is usually
77 // undesirable and can lead to unexpected and hard to find bugs
78 SetExtraStyle(GetExtraStyle() | wxWS_EX_BLOCK_EVENTS
);
81 wxWindow
*wxDialogBase::CheckIfCanBeUsedAsParent(wxWindow
*parent
) const
86 extern WXDLLIMPEXP_DATA_CORE(wxList
) wxPendingDelete
;
87 if ( wxPendingDelete
.Member(parent
) || parent
->IsBeingDeleted() )
89 // this window is being deleted and we shouldn't create any children
94 if ( parent
->HasExtraStyle(wxWS_EX_TRANSIENT
) )
96 // this window is not being deleted yet but it's going to disappear
97 // soon so still don't parent this window under it
101 if ( !parent
->IsShownOnScreen() )
103 // using hidden parent won't work correctly neither
107 if ( parent
== this )
109 // not sure if this can really happen but it doesn't hurt to guard
110 // against this clearly invalid situation
117 wxWindow
*wxDialogBase::GetParentForModalDialog(wxWindow
*parent
) const
119 // creating a parent-less modal dialog will result (under e.g. wxGTK2)
120 // in an unfocused dialog, so try to find a valid parent for it unless we
121 // were explicitly asked not to
122 if ( HasFlag(wxDIALOG_NO_PARENT
) )
125 // first try the given parent
127 parent
= CheckIfCanBeUsedAsParent(wxGetTopLevelParent(parent
));
129 // then the currently active window
131 parent
= CheckIfCanBeUsedAsParent(
132 wxGetTopLevelParent(wxGetActiveWindow()));
134 // and finally the application main window
136 parent
= CheckIfCanBeUsedAsParent(wxTheApp
->GetTopWindow());
143 class wxTextSizerWrapper
: public wxTextWrapper
146 wxTextSizerWrapper(wxWindow
*win
)
152 wxSizer
*CreateSizer(const wxString
& text
, int widthMax
)
154 m_sizer
= new wxBoxSizer(wxVERTICAL
);
155 Wrap(m_win
, text
, widthMax
);
160 virtual void OnOutputLine(const wxString
& line
)
164 m_sizer
->Add(new wxStaticText(m_win
, wxID_ANY
, line
));
166 else // empty line, no need to create a control for it
169 m_hLine
= m_win
->GetCharHeight();
171 m_sizer
->Add(5, m_hLine
);
181 wxSizer
*wxDialogBase::CreateTextSizer(const wxString
& message
)
183 // I admit that this is complete bogus, but it makes
184 // message boxes work for pda screens temporarily..
186 const bool is_pda
= wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
;
189 widthMax
= wxSystemSettings::GetMetric( wxSYS_SCREEN_X
) - 25;
192 // '&' is used as accel mnemonic prefix in the wxWidgets controls but in
193 // the static messages created by CreateTextSizer() (used by wxMessageBox,
194 // for example), we don't want this special meaning, so we need to quote it
195 wxString
text(message
);
196 text
.Replace(_T("&"), _T("&&"));
198 wxTextSizerWrapper
wrapper(this);
200 return wrapper
.CreateSizer(text
, widthMax
);
203 #endif // wxUSE_STATTEXT
205 wxSizer
*wxDialogBase::CreateButtonSizer(long flags
)
207 #ifdef __SMARTPHONE__
208 wxDialog
* dialog
= (wxDialog
*) this;
210 dialog
->SetLeftMenu(wxID_OK
);
212 if ( flags
& wxCANCEL
)
213 dialog
->SetRightMenu(wxID_CANCEL
);
216 dialog
->SetLeftMenu(wxID_YES
);
219 dialog
->SetRightMenu(wxID_NO
);
222 #else // !__SMARTPHONE__
227 // PocketPC guidelines recommend for Ok/Cancel dialogs to use OK button
228 // located inside caption bar and implement Cancel functionality through
229 // Undo outside dialog. As native behaviour this will be default here but
230 // can be replaced with real wxButtons by setting the option below to 1
231 if ( (flags
& ~(wxCANCEL
|wxNO_DEFAULT
)) != wxOK
||
232 wxSystemOptions::GetOptionInt(wxT("wince.dialog.real-ok-cancel")) )
233 #endif // __POCKETPC__
235 return CreateStdDialogButtonSizer(flags
);
239 #endif // __POCKETPC__
241 #else // !wxUSE_BUTTON
245 #endif // wxUSE_BUTTON/!wxUSE_BUTTON
247 #endif // __SMARTPHONE__/!__SMARTPHONE__
250 wxSizer
*wxDialogBase::CreateSeparatedButtonSizer(long flags
)
252 wxSizer
*sizer
= CreateButtonSizer(flags
);
256 // Mac Human Interface Guidelines recommend not to use static lines as
258 #if wxUSE_STATLINE && !defined(__WXMAC__)
259 wxBoxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
260 topsizer
->Add(new wxStaticLine(this),
261 wxSizerFlags().Expand().DoubleBorder(wxBOTTOM
));
262 topsizer
->Add(sizer
, wxSizerFlags().Expand());
264 #endif // wxUSE_STATLINE
271 wxStdDialogButtonSizer
*wxDialogBase::CreateStdDialogButtonSizer( long flags
)
273 wxStdDialogButtonSizer
*sizer
= new wxStdDialogButtonSizer();
276 wxButton
*yes
= NULL
;
281 ok
= new wxButton(this, wxID_OK
);
282 sizer
->AddButton(ok
);
285 if (flags
& wxCANCEL
)
287 wxButton
*cancel
= new wxButton(this, wxID_CANCEL
);
288 sizer
->AddButton(cancel
);
293 yes
= new wxButton(this, wxID_YES
);
294 sizer
->AddButton(yes
);
299 no
= new wxButton(this, wxID_NO
);
300 sizer
->AddButton(no
);
305 wxButton
*apply
= new wxButton(this, wxID_APPLY
);
306 sizer
->AddButton(apply
);
311 wxButton
*close
= new wxButton(this, wxID_CLOSE
);
312 sizer
->AddButton(close
);
317 wxButton
*help
= new wxButton(this, wxID_HELP
);
318 sizer
->AddButton(help
);
321 if (flags
& wxNO_DEFAULT
)
344 SetAffirmativeId(wxID_OK
);
345 else if (flags
& wxYES
)
346 SetAffirmativeId(wxID_YES
);
353 #endif // wxUSE_BUTTON
355 // ----------------------------------------------------------------------------
356 // standard buttons handling
357 // ----------------------------------------------------------------------------
359 void wxDialogBase::EndDialog(int rc
)
367 void wxDialogBase::AcceptAndClose()
369 if ( Validate() && TransferDataFromWindow() )
371 EndDialog(m_affirmativeId
);
375 void wxDialogBase::SetAffirmativeId(int affirmativeId
)
377 m_affirmativeId
= affirmativeId
;
380 void wxDialogBase::SetEscapeId(int escapeId
)
382 m_escapeId
= escapeId
;
385 bool wxDialogBase::EmulateButtonClickIfPresent(int id
)
388 wxButton
*btn
= wxDynamicCast(FindWindow(id
), wxButton
);
390 if ( !btn
|| !btn
->IsEnabled() || !btn
->IsShown() )
393 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, id
);
394 event
.SetEventObject(btn
);
395 btn
->GetEventHandler()->ProcessEvent(event
);
398 #else // !wxUSE_BUTTON
401 #endif // wxUSE_BUTTON/!wxUSE_BUTTON
404 bool wxDialogBase::IsEscapeKey(const wxKeyEvent
& event
)
406 // for most platforms, Esc key is used to close the dialogs
407 return event
.GetKeyCode() == WXK_ESCAPE
&&
408 event
.GetModifiers() == wxMOD_NONE
;
411 void wxDialogBase::OnCharHook(wxKeyEvent
& event
)
413 if ( event
.GetKeyCode() == WXK_ESCAPE
)
415 int idCancel
= GetEscapeId();
419 // don't handle Esc specially at all
423 // this value is special: it means translate Esc to wxID_CANCEL
424 // but if there is no such button, then fall back to wxID_OK
425 if ( EmulateButtonClickIfPresent(wxID_CANCEL
) )
427 idCancel
= GetAffirmativeId();
431 // translate Esc to button press for the button with given id
432 if ( EmulateButtonClickIfPresent(idCancel
) )
440 void wxDialogBase::OnButton(wxCommandEvent
& event
)
442 const int id
= event
.GetId();
443 if ( id
== GetAffirmativeId() )
447 else if ( id
== wxID_APPLY
)
450 TransferDataFromWindow();
452 // TODO: disable the Apply button until things change again
454 else if ( id
== GetEscapeId() ||
455 (id
== wxID_CANCEL
&& GetEscapeId() == wxID_ANY
) )
457 EndDialog(wxID_CANCEL
);
459 else // not a standard button
465 // ----------------------------------------------------------------------------
466 // other event handlers
467 // ----------------------------------------------------------------------------
469 void wxDialogBase::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
471 // We'll send a Cancel message by default, which may close the dialog.
472 // Check for looping if the Cancel event handler calls Close().
474 // Note that if a cancel button and handler aren't present in the dialog,
475 // nothing will happen when you close the dialog via the window manager, or
476 // via Close(). We wouldn't want to destroy the dialog by default, since
477 // the dialog may have been created on the stack. However, this does mean
478 // that calling dialog->Close() won't delete the dialog unless the handler
479 // for wxID_CANCEL does so. So use Destroy() if you want to be sure to
480 // destroy the dialog. The default OnCancel (above) simply ends a modal
481 // dialog, and hides a modeless dialog.
483 int idCancel
= GetEscapeId();
484 if ( idCancel
== wxID_NONE
)
486 if ( idCancel
== wxID_ANY
)
487 idCancel
= wxID_CANCEL
;
489 // VZ: this is horrible and MT-unsafe. Can't we reuse some of these global
490 // lists here? don't dare to change it now, but should be done later!
491 static wxList closing
;
493 if ( closing
.Member(this) )
496 closing
.Append(this);
498 wxCommandEvent
cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED
, idCancel
);
499 cancelEvent
.SetEventObject( this );
500 GetEventHandler()->ProcessEvent(cancelEvent
); // This may close the dialog
502 closing
.DeleteObject(this);
505 void wxDialogBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
508 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
515 /// Do the adaptation
516 bool wxDialogBase::DoLayoutAdaptation()
518 if (GetLayoutAdapter())
520 wxWindow
* focusWindow
= wxFindFocusDescendant(this); // from event.h
521 if (GetLayoutAdapter()->DoLayoutAdaptation((wxDialog
*) this))
524 focusWindow
->SetFocus();
534 /// Can we do the adaptation?
535 bool wxDialogBase::CanDoLayoutAdaptation()
537 // Check if local setting overrides the global setting
538 bool layoutEnabled
= (GetLayoutAdaptationMode() == wxDIALOG_ADAPTATION_MODE_ENABLED
) || (IsLayoutAdaptationEnabled() && (GetLayoutAdaptationMode() != wxDIALOG_ADAPTATION_MODE_DISABLED
));
540 return (layoutEnabled
&& !m_layoutAdaptationDone
&& GetLayoutAdaptationLevel() != 0 && GetLayoutAdapter() != NULL
&& GetLayoutAdapter()->CanDoLayoutAdaptation((wxDialog
*) this));
543 /// Set scrolling adapter class, returning old adapter
544 wxDialogLayoutAdapter
* wxDialogBase::SetLayoutAdapter(wxDialogLayoutAdapter
* adapter
)
546 wxDialogLayoutAdapter
* oldLayoutAdapter
= sm_layoutAdapter
;
547 sm_layoutAdapter
= adapter
;
548 return oldLayoutAdapter
;
555 IMPLEMENT_CLASS(wxDialogLayoutAdapter
, wxObject
)
557 IMPLEMENT_CLASS(wxStandardDialogLayoutAdapter
, wxDialogLayoutAdapter
)
559 // Allow for caption size on wxWidgets < 2.9
560 #if defined(__WXGTK__) && !wxCHECK_VERSION(2,9,0)
561 #define wxEXTRA_DIALOG_HEIGHT 30
563 #define wxEXTRA_DIALOG_HEIGHT 0
566 /// Indicate that adaptation should be done
567 bool wxStandardDialogLayoutAdapter::CanDoLayoutAdaptation(wxDialog
* dialog
)
569 if (dialog
->GetSizer())
571 wxSize windowSize
, displaySize
;
572 return MustScroll(dialog
, windowSize
, displaySize
) != 0;
578 bool wxStandardDialogLayoutAdapter::DoLayoutAdaptation(wxDialog
* dialog
)
580 if (dialog
->GetSizer())
583 wxBookCtrlBase
* bookContentWindow
= wxDynamicCast(dialog
->GetContentWindow(), wxBookCtrlBase
);
585 if (bookContentWindow
)
587 // If we have a book control, make all the pages (that use sizers) scrollable
588 wxWindowList windows
;
589 for (size_t i
= 0; i
< bookContentWindow
->GetPageCount(); i
++)
591 wxWindow
* page
= bookContentWindow
->GetPage(i
);
593 wxScrolledWindow
* scrolledWindow
= wxDynamicCast(page
, wxScrolledWindow
);
595 windows
.Append(scrolledWindow
);
596 else if (!scrolledWindow
&& page
->GetSizer())
598 // Create a scrolled window and reparent
599 scrolledWindow
= CreateScrolledWindow(page
);
600 wxSizer
* oldSizer
= page
->GetSizer();
602 wxSizer
* newSizer
= new wxBoxSizer(wxVERTICAL
);
603 newSizer
->Add(scrolledWindow
,1, wxEXPAND
, 0);
605 page
->SetSizer(newSizer
, false /* don't delete the old sizer */);
607 scrolledWindow
->SetSizer(oldSizer
);
609 ReparentControls(page
, scrolledWindow
);
611 windows
.Append(scrolledWindow
);
615 FitWithScrolling(dialog
, windows
);
618 #endif // wxUSE_BOOKCTRL
620 // If we have an arbitrary dialog, create a scrolling area for the main content, and a button sizer
621 // for the main buttons.
622 wxScrolledWindow
* scrolledWindow
= CreateScrolledWindow(dialog
);
624 int buttonSizerBorder
= 0;
626 // First try to find a wxStdDialogButtonSizer
627 wxSizer
* buttonSizer
= FindButtonSizer(true /* find std button sizer */, dialog
, dialog
->GetSizer(), buttonSizerBorder
);
629 // Next try to find a wxBoxSizer containing the controls
630 if (!buttonSizer
&& dialog
->GetLayoutAdaptationLevel() > wxDIALOG_ADAPTATION_STANDARD_SIZER
)
631 buttonSizer
= FindButtonSizer(false /* find ordinary sizer */, dialog
, dialog
->GetSizer(), buttonSizerBorder
);
633 // If we still don't have a button sizer, collect any 'loose' buttons in the layout
634 if (!buttonSizer
&& dialog
->GetLayoutAdaptationLevel() > wxDIALOG_ADAPTATION_ANY_SIZER
)
637 wxStdDialogButtonSizer
* stdButtonSizer
= new wxStdDialogButtonSizer
;
638 buttonSizer
= stdButtonSizer
;
640 FindLooseButtons(dialog
, stdButtonSizer
, dialog
->GetSizer(), count
);
642 stdButtonSizer
->Realize();
650 if (buttonSizerBorder
== 0)
651 buttonSizerBorder
= 5;
653 ReparentControls(dialog
, scrolledWindow
, buttonSizer
);
655 wxBoxSizer
* newTopSizer
= new wxBoxSizer(wxVERTICAL
);
656 wxSizer
* oldSizer
= dialog
->GetSizer();
658 dialog
->SetSizer(newTopSizer
, false /* don't delete old sizer */);
660 newTopSizer
->Add(scrolledWindow
, 1, wxEXPAND
|wxALL
, 0);
662 newTopSizer
->Add(buttonSizer
, 0, wxEXPAND
|wxALL
, buttonSizerBorder
);
664 scrolledWindow
->SetSizer(oldSizer
);
666 FitWithScrolling(dialog
, scrolledWindow
);
670 dialog
->SetLayoutAdaptationDone(true);
674 // Create the scrolled window
675 wxScrolledWindow
* wxStandardDialogLayoutAdapter::CreateScrolledWindow(wxWindow
* parent
)
677 wxScrolledWindow
* scrolledWindow
= new wxScrolledWindow(parent
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, wxTAB_TRAVERSAL
|wxVSCROLL
|wxHSCROLL
|wxBORDER_NONE
);
678 return scrolledWindow
;
681 /// Find and remove the button sizer, if any
682 wxSizer
* wxStandardDialogLayoutAdapter::FindButtonSizer(bool stdButtonSizer
, wxDialog
* dialog
, wxSizer
* sizer
, int& retBorder
, int accumlatedBorder
)
684 for ( wxSizerItemList::compatibility_iterator node
= sizer
->GetChildren().GetFirst();
685 node
; node
= node
->GetNext() )
687 wxSizerItem
*item
= node
->GetData();
688 wxSizer
*childSizer
= item
->GetSizer();
692 int newBorder
= accumlatedBorder
;
693 if (item
->GetFlag() & wxALL
)
694 newBorder
+= item
->GetBorder();
696 if (stdButtonSizer
) // find wxStdDialogButtonSizer
698 wxStdDialogButtonSizer
* buttonSizer
= wxDynamicCast(childSizer
, wxStdDialogButtonSizer
);
701 sizer
->Detach(childSizer
);
702 retBorder
= newBorder
;
706 else // find a horizontal box sizer containing standard buttons
708 wxBoxSizer
* buttonSizer
= wxDynamicCast(childSizer
, wxBoxSizer
);
709 if (buttonSizer
&& IsOrdinaryButtonSizer(dialog
, buttonSizer
))
711 sizer
->Detach(childSizer
);
712 retBorder
= newBorder
;
717 wxSizer
* s
= FindButtonSizer(stdButtonSizer
, dialog
, childSizer
, retBorder
, newBorder
);
725 /// Check if this sizer contains standard buttons, and so can be repositioned in the dialog
726 bool wxStandardDialogLayoutAdapter::IsOrdinaryButtonSizer(wxDialog
* dialog
, wxBoxSizer
* sizer
)
728 if (sizer
->GetOrientation() != wxHORIZONTAL
)
731 for ( wxSizerItemList::compatibility_iterator node
= sizer
->GetChildren().GetFirst();
732 node
; node
= node
->GetNext() )
734 wxSizerItem
*item
= node
->GetData();
735 wxButton
*childButton
= wxDynamicCast(item
->GetWindow(), wxButton
);
737 if (childButton
&& IsStandardButton(dialog
, childButton
))
743 /// Check if this is a standard button
744 bool wxStandardDialogLayoutAdapter::IsStandardButton(wxDialog
* dialog
, wxButton
* button
)
746 wxWindowID id
= button
->GetId();
748 return (id
== wxID_OK
|| id
== wxID_CANCEL
|| id
== wxID_YES
|| id
== wxID_NO
|| id
== wxID_SAVE
||
749 id
== wxID_APPLY
|| id
== wxID_HELP
|| id
== wxID_CONTEXT_HELP
|| dialog
->IsMainButtonId(id
));
752 /// Find 'loose' main buttons in the existing layout and add them to the standard dialog sizer
753 bool wxStandardDialogLayoutAdapter::FindLooseButtons(wxDialog
* dialog
, wxStdDialogButtonSizer
* buttonSizer
, wxSizer
* sizer
, int& count
)
755 wxSizerItemList::compatibility_iterator node
= sizer
->GetChildren().GetFirst();
758 wxSizerItemList::compatibility_iterator next
= node
->GetNext();
759 wxSizerItem
*item
= node
->GetData();
760 wxSizer
*childSizer
= item
->GetSizer();
761 wxButton
*childButton
= wxDynamicCast(item
->GetWindow(), wxButton
);
763 if (childButton
&& IsStandardButton(dialog
, childButton
))
765 sizer
->Detach(childButton
);
766 buttonSizer
->AddButton(childButton
);
771 FindLooseButtons(dialog
, buttonSizer
, childSizer
, count
);
778 /// Reparent the controls to the scrolled window
779 void wxStandardDialogLayoutAdapter::ReparentControls(wxWindow
* parent
, wxWindow
* reparentTo
, wxSizer
* buttonSizer
)
781 DoReparentControls(parent
, reparentTo
, buttonSizer
);
784 void wxStandardDialogLayoutAdapter::DoReparentControls(wxWindow
* parent
, wxWindow
* reparentTo
, wxSizer
* buttonSizer
)
786 wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
789 wxWindowList::compatibility_iterator next
= node
->GetNext();
791 wxWindow
*win
= node
->GetData();
793 // Don't reparent the scrolled window or buttons in the button sizer
794 if (win
!= reparentTo
&& (!buttonSizer
|| !buttonSizer
->GetItem(win
)))
796 win
->Reparent(reparentTo
);
798 // Restore correct tab order
799 ::SetWindowPos((HWND
) win
->GetHWND(), HWND_BOTTOM
, -1, -1, -1, -1, SWP_NOMOVE
|SWP_NOSIZE
);
807 /// Find whether scrolling will be necessary for the dialog, returning wxVERTICAL, wxHORIZONTAL or both
808 int wxStandardDialogLayoutAdapter::MustScroll(wxDialog
* dialog
, wxSize
& windowSize
, wxSize
& displaySize
)
810 return DoMustScroll(dialog
, windowSize
, displaySize
);
813 /// Find whether scrolling will be necessary for the dialog, returning wxVERTICAL, wxHORIZONTAL or both
814 int wxStandardDialogLayoutAdapter::DoMustScroll(wxDialog
* dialog
, wxSize
& windowSize
, wxSize
& displaySize
)
816 wxSize minWindowSize
= dialog
->GetSizer()->GetMinSize();
817 windowSize
= dialog
->GetSize();
818 windowSize
= wxSize(wxMax(windowSize
.x
, minWindowSize
.x
), wxMax(windowSize
.y
, minWindowSize
.y
));
820 displaySize
= wxDisplay(wxDisplay::GetFromWindow(dialog
)).GetClientArea().GetSize();
822 displaySize
= wxGetClientDisplayRect().GetSize();
827 if (windowSize
.y
>= (displaySize
.y
- wxEXTRA_DIALOG_HEIGHT
))
829 if (windowSize
.x
>= displaySize
.x
)
830 flags
|= wxHORIZONTAL
;
835 // A function to fit the dialog around its contents, and then adjust for screen size.
836 // If scrolled windows are passed, scrolling is enabled in the required orientation(s).
837 bool wxStandardDialogLayoutAdapter::FitWithScrolling(wxDialog
* dialog
, wxWindowList
& windows
)
839 return DoFitWithScrolling(dialog
, windows
);
842 // A function to fit the dialog around its contents, and then adjust for screen size.
843 // If a scrolled window is passed, scrolling is enabled in the required orientation(s).
844 bool wxStandardDialogLayoutAdapter::FitWithScrolling(wxDialog
* dialog
, wxScrolledWindow
* scrolledWindow
)
846 return DoFitWithScrolling(dialog
, scrolledWindow
);
849 // A function to fit the dialog around its contents, and then adjust for screen size.
850 // If a scrolled window is passed, scrolling is enabled in the required orientation(s).
851 bool wxStandardDialogLayoutAdapter::DoFitWithScrolling(wxDialog
* dialog
, wxScrolledWindow
* scrolledWindow
)
853 wxWindowList windows
;
854 windows
.Append(scrolledWindow
);
855 return DoFitWithScrolling(dialog
, windows
);
858 bool wxStandardDialogLayoutAdapter::DoFitWithScrolling(wxDialog
* dialog
, wxWindowList
& windows
)
860 wxSizer
* sizer
= dialog
->GetSizer();
864 sizer
->SetSizeHints(dialog
);
866 wxSize windowSize
, displaySize
;
867 int scrollFlags
= DoMustScroll(dialog
, windowSize
, displaySize
);
868 int scrollBarSize
= 20;
872 int scrollBarExtraX
= 0, scrollBarExtraY
= 0;
873 bool resizeHorizontally
= (scrollFlags
& wxHORIZONTAL
) != 0;
874 bool resizeVertically
= (scrollFlags
& wxVERTICAL
) != 0;
876 if (windows
.GetCount() != 0)
878 // Allow extra for a scrollbar, assuming we resizing in one direction only.
879 if ((resizeVertically
&& !resizeHorizontally
) && (windowSize
.x
< (displaySize
.x
- scrollBarSize
)))
880 scrollBarExtraX
= scrollBarSize
;
881 if ((resizeHorizontally
&& !resizeVertically
) && (windowSize
.y
< (displaySize
.y
- scrollBarSize
)))
882 scrollBarExtraY
= scrollBarSize
;
885 wxWindowList::compatibility_iterator node
= windows
.GetFirst();
888 wxWindow
*win
= node
->GetData();
889 wxScrolledWindow
* scrolledWindow
= wxDynamicCast(win
, wxScrolledWindow
);
892 scrolledWindow
->SetScrollRate(resizeHorizontally
? 10 : 0, resizeVertically
? 10 : 0);
894 if (scrolledWindow
->GetSizer())
895 scrolledWindow
->GetSizer()->Fit(scrolledWindow
);
898 node
= node
->GetNext();
901 wxSize limitTo
= windowSize
+ wxSize(scrollBarExtraX
, scrollBarExtraY
);
902 if (resizeVertically
)
903 limitTo
.y
= displaySize
.y
- wxEXTRA_DIALOG_HEIGHT
;
904 if (resizeHorizontally
)
905 limitTo
.x
= displaySize
.x
;
907 dialog
->SetMinSize(limitTo
);
908 dialog
->SetSize(limitTo
);
910 dialog
->SetSizeHints( limitTo
.x
, limitTo
.y
, dialog
->GetMaxWidth(), dialog
->GetMaxHeight() );
917 * Module to initialise standard adapter
920 class wxDialogLayoutAdapterModule
: public wxModule
922 DECLARE_DYNAMIC_CLASS(wxDialogLayoutAdapterModule
)
924 wxDialogLayoutAdapterModule() {}
925 virtual void OnExit() { delete wxDialogBase::SetLayoutAdapter(NULL
); }
926 virtual bool OnInit() { wxDialogBase::SetLayoutAdapter(new wxStandardDialogLayoutAdapter
); return true; }
929 IMPLEMENT_DYNAMIC_CLASS(wxDialogLayoutAdapterModule
, wxModule
)