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 // helper of GetParentForModalDialog()
82 static bool CanBeUsedAsParent(wxWindow
*parent
)
84 extern WXDLLIMPEXP_DATA_CORE(wxList
) wxPendingDelete
;
86 return !parent
->HasExtraStyle(wxWS_EX_TRANSIENT
) &&
87 parent
->IsShownOnScreen() &&
88 !wxPendingDelete
.Member(parent
) &&
89 !parent
->IsBeingDeleted();
92 wxWindow
*wxDialogBase::GetParentForModalDialog(wxWindow
*parent
) const
94 // creating a parent-less modal dialog will result (under e.g. wxGTK2)
95 // in an unfocused dialog, so try to find a valid parent for it:
97 parent
= wxGetTopLevelParent(parent
);
99 if ( !parent
|| !CanBeUsedAsParent(parent
) )
100 parent
= wxTheApp
->GetTopWindow();
102 if ( parent
&& !CanBeUsedAsParent(parent
) )
104 // can't use this one, it's going to disappear
113 class wxTextSizerWrapper
: public wxTextWrapper
116 wxTextSizerWrapper(wxWindow
*win
)
122 wxSizer
*CreateSizer(const wxString
& text
, int widthMax
)
124 m_sizer
= new wxBoxSizer(wxVERTICAL
);
125 Wrap(m_win
, text
, widthMax
);
130 virtual void OnOutputLine(const wxString
& line
)
134 m_sizer
->Add(new wxStaticText(m_win
, wxID_ANY
, line
));
136 else // empty line, no need to create a control for it
139 m_hLine
= m_win
->GetCharHeight();
141 m_sizer
->Add(5, m_hLine
);
151 wxSizer
*wxDialogBase::CreateTextSizer(const wxString
& message
)
153 // I admit that this is complete bogus, but it makes
154 // message boxes work for pda screens temporarily..
156 const bool is_pda
= wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
;
159 widthMax
= wxSystemSettings::GetMetric( wxSYS_SCREEN_X
) - 25;
162 // '&' is used as accel mnemonic prefix in the wxWidgets controls but in
163 // the static messages created by CreateTextSizer() (used by wxMessageBox,
164 // for example), we don't want this special meaning, so we need to quote it
165 wxString
text(message
);
166 text
.Replace(_T("&"), _T("&&"));
168 wxTextSizerWrapper
wrapper(this);
170 return wrapper
.CreateSizer(text
, widthMax
);
173 #endif // wxUSE_STATTEXT
175 wxSizer
*wxDialogBase::CreateButtonSizer(long flags
)
177 wxSizer
*sizer
= NULL
;
179 #ifdef __SMARTPHONE__
180 wxDialog
* dialog
= (wxDialog
*) this;
182 dialog
->SetLeftMenu(wxID_OK
);
184 if ( flags
& wxCANCEL
)
185 dialog
->SetRightMenu(wxID_CANCEL
);
188 dialog
->SetLeftMenu(wxID_YES
);
191 dialog
->SetRightMenu(wxID_NO
);
192 #else // !__SMARTPHONE__
197 // PocketPC guidelines recommend for Ok/Cancel dialogs to use OK button
198 // located inside caption bar and implement Cancel functionality through
199 // Undo outside dialog. As native behaviour this will be default here but
200 // can be replaced with real wxButtons by setting the option below to 1
201 if ( (flags
& ~(wxCANCEL
|wxNO_DEFAULT
)) != wxOK
||
202 wxSystemOptions::GetOptionInt(wxT("wince.dialog.real-ok-cancel")) )
203 #endif // __POCKETPC__
205 sizer
= CreateStdDialogButtonSizer(flags
);
207 #else // !wxUSE_BUTTON
209 #endif // wxUSE_BUTTON/!wxUSE_BUTTON
211 #endif // __SMARTPHONE__/!__SMARTPHONE__
216 wxSizer
*wxDialogBase::CreateSeparatedButtonSizer(long flags
)
218 wxSizer
*sizer
= CreateButtonSizer(flags
);
222 // Mac Human Interface Guidelines recommend not to use static lines as
224 #if wxUSE_STATLINE && !defined(__WXMAC__)
225 wxBoxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
226 topsizer
->Add(new wxStaticLine(this),
227 wxSizerFlags().Expand().DoubleBorder(wxBOTTOM
));
228 topsizer
->Add(sizer
, wxSizerFlags().Expand());
230 #endif // wxUSE_STATLINE
237 wxStdDialogButtonSizer
*wxDialogBase::CreateStdDialogButtonSizer( long flags
)
239 wxStdDialogButtonSizer
*sizer
= new wxStdDialogButtonSizer();
242 wxButton
*yes
= NULL
;
247 ok
= new wxButton(this, wxID_OK
);
248 sizer
->AddButton(ok
);
251 if (flags
& wxCANCEL
)
253 wxButton
*cancel
= new wxButton(this, wxID_CANCEL
);
254 sizer
->AddButton(cancel
);
259 yes
= new wxButton(this, wxID_YES
);
260 sizer
->AddButton(yes
);
265 no
= new wxButton(this, wxID_NO
);
266 sizer
->AddButton(no
);
271 wxButton
*apply
= new wxButton(this, wxID_APPLY
);
272 sizer
->AddButton(apply
);
277 wxButton
*close
= new wxButton(this, wxID_CLOSE
);
278 sizer
->AddButton(close
);
283 wxButton
*help
= new wxButton(this, wxID_HELP
);
284 sizer
->AddButton(help
);
287 if (flags
& wxNO_DEFAULT
)
310 SetAffirmativeId(wxID_OK
);
311 else if (flags
& wxYES
)
312 SetAffirmativeId(wxID_YES
);
319 #endif // wxUSE_BUTTON
321 // ----------------------------------------------------------------------------
322 // standard buttons handling
323 // ----------------------------------------------------------------------------
325 void wxDialogBase::EndDialog(int rc
)
333 void wxDialogBase::AcceptAndClose()
335 if ( Validate() && TransferDataFromWindow() )
337 EndDialog(m_affirmativeId
);
341 void wxDialogBase::SetAffirmativeId(int affirmativeId
)
343 m_affirmativeId
= affirmativeId
;
346 void wxDialogBase::SetEscapeId(int escapeId
)
348 m_escapeId
= escapeId
;
351 bool wxDialogBase::EmulateButtonClickIfPresent(int id
)
354 wxButton
*btn
= wxDynamicCast(FindWindow(id
), wxButton
);
356 if ( !btn
|| !btn
->IsEnabled() || !btn
->IsShown() )
359 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, id
);
360 event
.SetEventObject(btn
);
361 btn
->GetEventHandler()->ProcessEvent(event
);
364 #else // !wxUSE_BUTTON
367 #endif // wxUSE_BUTTON/!wxUSE_BUTTON
370 bool wxDialogBase::IsEscapeKey(const wxKeyEvent
& event
)
372 // for most platforms, Esc key is used to close the dialogs
373 return event
.GetKeyCode() == WXK_ESCAPE
&&
374 event
.GetModifiers() == wxMOD_NONE
;
377 void wxDialogBase::OnCharHook(wxKeyEvent
& event
)
379 if ( event
.GetKeyCode() == WXK_ESCAPE
)
381 int idCancel
= GetEscapeId();
385 // don't handle Esc specially at all
389 // this value is special: it means translate Esc to wxID_CANCEL
390 // but if there is no such button, then fall back to wxID_OK
391 if ( EmulateButtonClickIfPresent(wxID_CANCEL
) )
393 idCancel
= GetAffirmativeId();
397 // translate Esc to button press for the button with given id
398 if ( EmulateButtonClickIfPresent(idCancel
) )
406 void wxDialogBase::OnButton(wxCommandEvent
& event
)
408 const int id
= event
.GetId();
409 if ( id
== GetAffirmativeId() )
413 else if ( id
== wxID_APPLY
)
416 TransferDataFromWindow();
418 // TODO: disable the Apply button until things change again
420 else if ( id
== GetEscapeId() ||
421 (id
== wxID_CANCEL
&& GetEscapeId() == wxID_ANY
) )
423 EndDialog(wxID_CANCEL
);
425 else // not a standard button
431 // ----------------------------------------------------------------------------
432 // other event handlers
433 // ----------------------------------------------------------------------------
435 void wxDialogBase::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
437 // We'll send a Cancel message by default, which may close the dialog.
438 // Check for looping if the Cancel event handler calls Close().
440 // Note that if a cancel button and handler aren't present in the dialog,
441 // nothing will happen when you close the dialog via the window manager, or
442 // via Close(). We wouldn't want to destroy the dialog by default, since
443 // the dialog may have been created on the stack. However, this does mean
444 // that calling dialog->Close() won't delete the dialog unless the handler
445 // for wxID_CANCEL does so. So use Destroy() if you want to be sure to
446 // destroy the dialog. The default OnCancel (above) simply ends a modal
447 // dialog, and hides a modeless dialog.
449 // VZ: this is horrible and MT-unsafe. Can't we reuse some of these global
450 // lists here? don't dare to change it now, but should be done later!
451 static wxList closing
;
453 if ( closing
.Member(this) )
456 closing
.Append(this);
458 wxCommandEvent
cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
);
459 cancelEvent
.SetEventObject( this );
460 GetEventHandler()->ProcessEvent(cancelEvent
); // This may close the dialog
462 closing
.DeleteObject(this);
465 void wxDialogBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
468 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
475 /// Do the adaptation
476 bool wxDialogBase::DoLayoutAdaptation()
478 if (GetLayoutAdapter())
479 return GetLayoutAdapter()->DoLayoutAdaptation((wxDialog
*) this);
484 /// Can we do the adaptation?
485 bool wxDialogBase::CanDoLayoutAdaptation()
487 // Check if local setting overrides the global setting
488 bool layoutEnabled
= (GetLayoutAdaptationMode() == wxDIALOG_ADAPTATION_MODE_ENABLED
) || (IsLayoutAdaptationEnabled() && (GetLayoutAdaptationMode() != wxDIALOG_ADAPTATION_MODE_DISABLED
));
490 return (layoutEnabled
&& !m_layoutAdaptationDone
&& GetLayoutAdaptationLevel() != 0 && GetLayoutAdapter() != NULL
&& GetLayoutAdapter()->CanDoLayoutAdaptation((wxDialog
*) this));
493 /// Set scrolling adapter class, returning old adapter
494 wxDialogLayoutAdapter
* wxDialogBase::SetLayoutAdapter(wxDialogLayoutAdapter
* adapter
)
496 wxDialogLayoutAdapter
* oldLayoutAdapter
= sm_layoutAdapter
;
497 sm_layoutAdapter
= adapter
;
498 return oldLayoutAdapter
;
505 IMPLEMENT_CLASS(wxDialogLayoutAdapter
, wxObject
)
507 IMPLEMENT_CLASS(wxStandardDialogLayoutAdapter
, wxDialogLayoutAdapter
)
509 // Allow for caption size on wxWidgets < 2.9
510 #if defined(__WXGTK__) && !wxCHECK_VERSION(2,9,0)
511 #define wxEXTRA_DIALOG_HEIGHT 30
513 #define wxEXTRA_DIALOG_HEIGHT 0
516 /// Indicate that adaptation should be done
517 bool wxStandardDialogLayoutAdapter::CanDoLayoutAdaptation(wxDialog
* dialog
)
519 if (dialog
->GetSizer())
521 wxSize windowSize
, displaySize
;
522 return MustScroll(dialog
, windowSize
, displaySize
) != 0;
528 bool wxStandardDialogLayoutAdapter::DoLayoutAdaptation(wxDialog
* dialog
)
530 if (dialog
->GetSizer())
532 wxBookCtrlBase
* bookContentWindow
= wxDynamicCast(dialog
->GetContentWindow(), wxBookCtrlBase
);
534 if (bookContentWindow
)
536 // If we have a book control, make all the pages (that use sizers) scrollable
537 wxWindowList windows
;
538 for (size_t i
= 0; i
< bookContentWindow
->GetPageCount(); i
++)
540 wxWindow
* page
= bookContentWindow
->GetPage(i
);
542 wxScrolledWindow
* scrolledWindow
= wxDynamicCast(page
, wxScrolledWindow
);
544 windows
.Append(scrolledWindow
);
545 else if (!scrolledWindow
&& page
->GetSizer())
547 // Create a scrolled window and reparent
548 scrolledWindow
= CreateScrolledWindow(page
);
549 wxSizer
* oldSizer
= page
->GetSizer();
551 wxSizer
* newSizer
= new wxBoxSizer(wxVERTICAL
);
552 newSizer
->Add(scrolledWindow
,1, wxEXPAND
, 0);
554 page
->SetSizer(newSizer
, false /* don't delete the old sizer */);
556 scrolledWindow
->SetSizer(oldSizer
);
558 ReparentControls(page
, scrolledWindow
);
560 windows
.Append(scrolledWindow
);
564 FitWithScrolling(dialog
, windows
);
568 // If we have an arbitrary dialog, create a scrolling area for the main content, and a button sizer
569 // for the main buttons.
570 wxScrolledWindow
* scrolledWindow
= CreateScrolledWindow(dialog
);
572 int buttonSizerBorder
= 0;
574 // First try to find a wxStdDialogButtonSizer
575 wxSizer
* buttonSizer
= FindButtonSizer(true /* find std button sizer */, dialog
, dialog
->GetSizer(), buttonSizerBorder
);
577 // Next try to find a wxBoxSizer containing the controls
578 if (!buttonSizer
&& dialog
->GetLayoutAdaptationLevel() > wxDIALOG_ADAPTATION_STANDARD_SIZER
)
579 buttonSizer
= FindButtonSizer(false /* find ordinary sizer */, dialog
, dialog
->GetSizer(), buttonSizerBorder
);
581 // If we still don't have a button sizer, collect any 'loose' buttons in the layout
582 if (!buttonSizer
&& dialog
->GetLayoutAdaptationLevel() > wxDIALOG_ADAPTATION_ANY_SIZER
)
585 wxStdDialogButtonSizer
* stdButtonSizer
= new wxStdDialogButtonSizer
;
586 buttonSizer
= stdButtonSizer
;
588 FindLooseButtons(dialog
, stdButtonSizer
, dialog
->GetSizer(), count
);
590 stdButtonSizer
->Realize();
598 if (buttonSizerBorder
== 0)
599 buttonSizerBorder
= 5;
601 ReparentControls(dialog
, scrolledWindow
, buttonSizer
);
603 wxBoxSizer
* newTopSizer
= new wxBoxSizer(wxVERTICAL
);
604 wxSizer
* oldSizer
= dialog
->GetSizer();
606 dialog
->SetSizer(newTopSizer
, false /* don't delete old sizer */);
608 newTopSizer
->Add(scrolledWindow
, 1, wxEXPAND
|wxALL
, 0);
610 newTopSizer
->Add(buttonSizer
, 0, wxEXPAND
|wxALL
, buttonSizerBorder
);
612 scrolledWindow
->SetSizer(oldSizer
);
614 FitWithScrolling(dialog
, scrolledWindow
);
618 dialog
->SetLayoutAdaptationDone(true);
622 // Create the scrolled window
623 wxScrolledWindow
* wxStandardDialogLayoutAdapter::CreateScrolledWindow(wxWindow
* parent
)
625 wxScrolledWindow
* scrolledWindow
= new wxScrolledWindow(parent
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, wxTAB_TRAVERSAL
|wxVSCROLL
|wxHSCROLL
|wxBORDER_NONE
);
626 return scrolledWindow
;
629 /// Find and remove the button sizer, if any
630 wxSizer
* wxStandardDialogLayoutAdapter::FindButtonSizer(bool stdButtonSizer
, wxDialog
* dialog
, wxSizer
* sizer
, int& retBorder
, int accumlatedBorder
)
632 for ( wxSizerItemList::compatibility_iterator node
= sizer
->GetChildren().GetFirst();
633 node
; node
= node
->GetNext() )
635 wxSizerItem
*item
= node
->GetData();
636 wxSizer
*childSizer
= item
->GetSizer();
640 int newBorder
= accumlatedBorder
;
641 if (item
->GetFlag() & wxALL
)
642 newBorder
+= item
->GetBorder();
644 if (stdButtonSizer
) // find wxStdDialogButtonSizer
646 wxStdDialogButtonSizer
* buttonSizer
= wxDynamicCast(childSizer
, wxStdDialogButtonSizer
);
649 sizer
->Detach(childSizer
);
650 retBorder
= newBorder
;
654 else // find a horizontal box sizer containing standard buttons
656 wxBoxSizer
* buttonSizer
= wxDynamicCast(childSizer
, wxBoxSizer
);
657 if (buttonSizer
&& IsOrdinaryButtonSizer(dialog
, buttonSizer
))
659 sizer
->Detach(childSizer
);
660 retBorder
= newBorder
;
665 wxSizer
* s
= FindButtonSizer(stdButtonSizer
, dialog
, childSizer
, retBorder
, newBorder
);
673 /// Check if this sizer contains standard buttons, and so can be repositioned in the dialog
674 bool wxStandardDialogLayoutAdapter::IsOrdinaryButtonSizer(wxDialog
* dialog
, wxBoxSizer
* sizer
)
676 if (sizer
->GetOrientation() != wxHORIZONTAL
)
679 for ( wxSizerItemList::compatibility_iterator node
= sizer
->GetChildren().GetFirst();
680 node
; node
= node
->GetNext() )
682 wxSizerItem
*item
= node
->GetData();
683 wxButton
*childButton
= wxDynamicCast(item
->GetWindow(), wxButton
);
685 if (childButton
&& IsStandardButton(dialog
, childButton
))
691 /// Check if this is a standard button
692 bool wxStandardDialogLayoutAdapter::IsStandardButton(wxDialog
* dialog
, wxButton
* button
)
694 wxWindowID id
= button
->GetId();
696 return (id
== wxID_OK
|| id
== wxID_CANCEL
|| id
== wxID_YES
|| id
== wxID_NO
|| id
== wxID_SAVE
||
697 id
== wxID_APPLY
|| id
== wxID_HELP
|| id
== wxID_CONTEXT_HELP
|| dialog
->IsMainButtonId(id
));
700 /// Find 'loose' main buttons in the existing layout and add them to the standard dialog sizer
701 bool wxStandardDialogLayoutAdapter::FindLooseButtons(wxDialog
* dialog
, wxStdDialogButtonSizer
* buttonSizer
, wxSizer
* sizer
, int& count
)
703 wxSizerItemList::compatibility_iterator node
= sizer
->GetChildren().GetFirst();
706 wxSizerItemList::compatibility_iterator next
= node
->GetNext();
707 wxSizerItem
*item
= node
->GetData();
708 wxSizer
*childSizer
= item
->GetSizer();
709 wxButton
*childButton
= wxDynamicCast(item
->GetWindow(), wxButton
);
711 if (childButton
&& IsStandardButton(dialog
, childButton
))
713 sizer
->Detach(childButton
);
714 buttonSizer
->AddButton(childButton
);
719 FindLooseButtons(dialog
, buttonSizer
, childSizer
, count
);
726 /// Reparent the controls to the scrolled window
727 void wxStandardDialogLayoutAdapter::ReparentControls(wxWindow
* parent
, wxWindow
* reparentTo
, wxSizer
* buttonSizer
)
729 DoReparentControls(parent
, reparentTo
, buttonSizer
);
732 void wxStandardDialogLayoutAdapter::DoReparentControls(wxWindow
* parent
, wxWindow
* reparentTo
, wxSizer
* buttonSizer
)
734 wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
737 wxWindowList::compatibility_iterator next
= node
->GetNext();
739 wxWindow
*win
= node
->GetData();
741 // Don't reparent the scrolled window or buttons in the button sizer
742 if (win
!= reparentTo
&& (!buttonSizer
|| !buttonSizer
->GetItem(win
)))
744 win
->Reparent(reparentTo
);
746 // Restore correct tab order
747 ::SetWindowPos((HWND
) win
->GetHWND(), HWND_BOTTOM
, -1, -1, -1, -1, SWP_NOMOVE
|SWP_NOSIZE
);
755 /// Find whether scrolling will be necessary for the dialog, returning wxVERTICAL, wxHORIZONTAL or both
756 int wxStandardDialogLayoutAdapter::MustScroll(wxDialog
* dialog
, wxSize
& windowSize
, wxSize
& displaySize
)
758 return DoMustScroll(dialog
, windowSize
, displaySize
);
761 /// Find whether scrolling will be necessary for the dialog, returning wxVERTICAL, wxHORIZONTAL or both
762 int wxStandardDialogLayoutAdapter::DoMustScroll(wxDialog
* dialog
, wxSize
& windowSize
, wxSize
& displaySize
)
764 wxSize minWindowSize
= dialog
->GetSizer()->GetMinSize();
765 windowSize
= dialog
->GetSize();
766 windowSize
= wxSize(wxMax(windowSize
.x
, minWindowSize
.x
), wxMax(windowSize
.y
, minWindowSize
.y
));
768 displaySize
= wxDisplay(wxDisplay::GetFromWindow(dialog
)).GetClientArea().GetSize();
770 displaySize
= wxGetClientDisplayRect().GetSize();
775 if (windowSize
.y
>= (displaySize
.y
- wxEXTRA_DIALOG_HEIGHT
))
777 if (windowSize
.x
>= displaySize
.x
)
778 flags
|= wxHORIZONTAL
;
783 // A function to fit the dialog around its contents, and then adjust for screen size.
784 // If scrolled windows are passed, scrolling is enabled in the required orientation(s).
785 bool wxStandardDialogLayoutAdapter::FitWithScrolling(wxDialog
* dialog
, wxWindowList
& windows
)
787 return DoFitWithScrolling(dialog
, windows
);
790 // A function to fit the dialog around its contents, and then adjust for screen size.
791 // If a scrolled window is passed, scrolling is enabled in the required orientation(s).
792 bool wxStandardDialogLayoutAdapter::FitWithScrolling(wxDialog
* dialog
, wxScrolledWindow
* scrolledWindow
)
794 return DoFitWithScrolling(dialog
, scrolledWindow
);
797 // A function to fit the dialog around its contents, and then adjust for screen size.
798 // If a scrolled window is passed, scrolling is enabled in the required orientation(s).
799 bool wxStandardDialogLayoutAdapter::DoFitWithScrolling(wxDialog
* dialog
, wxScrolledWindow
* scrolledWindow
)
801 wxWindowList windows
;
802 windows
.Append(scrolledWindow
);
803 return DoFitWithScrolling(dialog
, windows
);
806 bool wxStandardDialogLayoutAdapter::DoFitWithScrolling(wxDialog
* dialog
, wxWindowList
& windows
)
808 wxSizer
* sizer
= dialog
->GetSizer();
812 sizer
->SetSizeHints(dialog
);
814 wxSize windowSize
, displaySize
;
815 int scrollFlags
= DoMustScroll(dialog
, windowSize
, displaySize
);
816 int scrollBarSize
= 20;
820 int scrollBarExtraX
= 0, scrollBarExtraY
= 0;
821 bool resizeHorizontally
= (scrollFlags
& wxHORIZONTAL
) != 0;
822 bool resizeVertically
= (scrollFlags
& wxVERTICAL
) != 0;
824 if (windows
.GetCount() != 0)
826 // Allow extra for a scrollbar, assuming we resizing in one direction only.
827 if ((resizeVertically
&& !resizeHorizontally
) && (windowSize
.x
< (displaySize
.x
- scrollBarSize
)))
828 scrollBarExtraX
= scrollBarSize
;
829 if ((resizeHorizontally
&& !resizeVertically
) && (windowSize
.y
< (displaySize
.y
- scrollBarSize
)))
830 scrollBarExtraY
= scrollBarSize
;
833 wxWindowList::compatibility_iterator node
= windows
.GetFirst();
836 wxWindow
*win
= node
->GetData();
837 wxScrolledWindow
* scrolledWindow
= wxDynamicCast(win
, wxScrolledWindow
);
840 scrolledWindow
->SetScrollRate(resizeHorizontally
? 10 : 0, resizeVertically
? 10 : 0);
842 if (scrolledWindow
->GetSizer())
843 scrolledWindow
->GetSizer()->Fit(scrolledWindow
);
846 node
= node
->GetNext();
849 wxSize limitTo
= windowSize
+ wxSize(scrollBarExtraX
, scrollBarExtraY
);
850 if (resizeVertically
)
851 limitTo
.y
= displaySize
.y
- wxEXTRA_DIALOG_HEIGHT
;
852 if (resizeHorizontally
)
853 limitTo
.x
= displaySize
.x
;
855 dialog
->SetMinSize(limitTo
);
856 dialog
->SetSize(limitTo
);
858 dialog
->SetSizeHints( limitTo
.x
, limitTo
.y
, dialog
->GetMaxWidth(), dialog
->GetMaxHeight() );
865 * Module to initialise standard adapter
868 class wxDialogLayoutAdapterModule
: public wxModule
870 DECLARE_DYNAMIC_CLASS(wxDialogLayoutAdapterModule
)
872 wxDialogLayoutAdapterModule() {}
873 virtual void OnExit() { delete wxDialogBase::SetLayoutAdapter(NULL
); }
874 virtual bool OnInit() { wxDialogBase::SetLayoutAdapter(new wxStandardDialogLayoutAdapter
); return true; }
877 IMPLEMENT_DYNAMIC_CLASS(wxDialogLayoutAdapterModule
, wxModule
)