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"
47 #include "wx/display.h"
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
54 BEGIN_EVENT_TABLE(wxDialogBase
, wxTopLevelWindow
)
55 EVT_BUTTON(wxID_ANY
, wxDialogBase::OnButton
)
57 EVT_CLOSE(wxDialogBase::OnCloseWindow
)
59 EVT_CHAR_HOOK(wxDialogBase::OnCharHook
)
62 wxDialogLayoutAdapter
* wxDialogBase::sm_layoutAdapter
= NULL
;
63 bool wxDialogBase::sm_layoutAdaptation
= false;
65 void wxDialogBase::Init()
68 m_affirmativeId
= wxID_OK
;
69 m_escapeId
= wxID_ANY
;
70 m_layoutAdaptationLevel
= 3;
71 m_layoutAdaptationDone
= FALSE
;
72 m_layoutAdaptationMode
= wxDIALOG_ADAPTATION_MODE_DEFAULT
;
74 // the dialogs have this flag on by default to prevent the events from the
75 // dialog controls from reaching the parent frame which is usually
76 // undesirable and can lead to unexpected and hard to find bugs
77 SetExtraStyle(GetExtraStyle() | wxWS_EX_BLOCK_EVENTS
);
80 // helper of GetParentForModalDialog()
81 static bool CanBeUsedAsParent(wxWindow
*parent
)
83 extern WXDLLIMPEXP_DATA_CORE(wxList
) wxPendingDelete
;
85 return !parent
->HasExtraStyle(wxWS_EX_TRANSIENT
) &&
86 parent
->IsShownOnScreen() &&
87 !wxPendingDelete
.Member(parent
) &&
88 !parent
->IsBeingDeleted();
91 wxWindow
*wxDialogBase::GetParentForModalDialog(wxWindow
*parent
) const
93 // creating a parent-less modal dialog will result (under e.g. wxGTK2)
94 // in an unfocused dialog, so try to find a valid parent for it:
96 parent
= wxGetTopLevelParent(parent
);
98 if ( !parent
|| !CanBeUsedAsParent(parent
) )
99 parent
= wxTheApp
->GetTopWindow();
101 if ( parent
&& !CanBeUsedAsParent(parent
) )
103 // can't use this one, it's going to disappear
112 class wxTextSizerWrapper
: public wxTextWrapper
115 wxTextSizerWrapper(wxWindow
*win
)
121 wxSizer
*CreateSizer(const wxString
& text
, int widthMax
)
123 m_sizer
= new wxBoxSizer(wxVERTICAL
);
124 Wrap(m_win
, text
, widthMax
);
129 virtual void OnOutputLine(const wxString
& line
)
133 m_sizer
->Add(new wxStaticText(m_win
, wxID_ANY
, line
));
135 else // empty line, no need to create a control for it
138 m_hLine
= m_win
->GetCharHeight();
140 m_sizer
->Add(5, m_hLine
);
150 wxSizer
*wxDialogBase::CreateTextSizer(const wxString
& message
)
152 // I admit that this is complete bogus, but it makes
153 // message boxes work for pda screens temporarily..
155 const bool is_pda
= wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
;
158 widthMax
= wxSystemSettings::GetMetric( wxSYS_SCREEN_X
) - 25;
161 // '&' is used as accel mnemonic prefix in the wxWidgets controls but in
162 // the static messages created by CreateTextSizer() (used by wxMessageBox,
163 // for example), we don't want this special meaning, so we need to quote it
164 wxString
text(message
);
165 text
.Replace(_T("&"), _T("&&"));
167 wxTextSizerWrapper
wrapper(this);
169 return wrapper
.CreateSizer(text
, widthMax
);
172 #endif // wxUSE_STATTEXT
174 wxSizer
*wxDialogBase::CreateButtonSizer(long flags
)
176 wxSizer
*sizer
= NULL
;
178 #ifdef __SMARTPHONE__
179 wxDialog
* dialog
= (wxDialog
*) this;
181 dialog
->SetLeftMenu(wxID_OK
);
183 if ( flags
& wxCANCEL
)
184 dialog
->SetRightMenu(wxID_CANCEL
);
187 dialog
->SetLeftMenu(wxID_YES
);
190 dialog
->SetRightMenu(wxID_NO
);
191 #else // !__SMARTPHONE__
196 // PocketPC guidelines recommend for Ok/Cancel dialogs to use OK button
197 // located inside caption bar and implement Cancel functionality through
198 // Undo outside dialog. As native behaviour this will be default here but
199 // can be replaced with real wxButtons by setting the option below to 1
200 if ( (flags
& ~(wxCANCEL
|wxNO_DEFAULT
)) != wxOK
||
201 wxSystemOptions::GetOptionInt(wxT("wince.dialog.real-ok-cancel")) )
202 #endif // __POCKETPC__
204 sizer
= CreateStdDialogButtonSizer(flags
);
206 #else // !wxUSE_BUTTON
208 #endif // wxUSE_BUTTON/!wxUSE_BUTTON
210 #endif // __SMARTPHONE__/!__SMARTPHONE__
215 wxSizer
*wxDialogBase::CreateSeparatedButtonSizer(long flags
)
217 wxSizer
*sizer
= CreateButtonSizer(flags
);
221 // Mac Human Interface Guidelines recommend not to use static lines as
223 #if wxUSE_STATLINE && !defined(__WXMAC__)
224 wxBoxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
225 topsizer
->Add(new wxStaticLine(this),
226 wxSizerFlags().Expand().DoubleBorder(wxBOTTOM
));
227 topsizer
->Add(sizer
, wxSizerFlags().Expand());
229 #endif // wxUSE_STATLINE
236 wxStdDialogButtonSizer
*wxDialogBase::CreateStdDialogButtonSizer( long flags
)
238 wxStdDialogButtonSizer
*sizer
= new wxStdDialogButtonSizer();
241 wxButton
*yes
= NULL
;
246 ok
= new wxButton(this, wxID_OK
);
247 sizer
->AddButton(ok
);
250 if (flags
& wxCANCEL
)
252 wxButton
*cancel
= new wxButton(this, wxID_CANCEL
);
253 sizer
->AddButton(cancel
);
258 yes
= new wxButton(this, wxID_YES
);
259 sizer
->AddButton(yes
);
264 no
= new wxButton(this, wxID_NO
);
265 sizer
->AddButton(no
);
270 wxButton
*apply
= new wxButton(this, wxID_APPLY
);
271 sizer
->AddButton(apply
);
276 wxButton
*close
= new wxButton(this, wxID_CLOSE
);
277 sizer
->AddButton(close
);
282 wxButton
*help
= new wxButton(this, wxID_HELP
);
283 sizer
->AddButton(help
);
286 if (flags
& wxNO_DEFAULT
)
309 SetAffirmativeId(wxID_OK
);
310 else if (flags
& wxYES
)
311 SetAffirmativeId(wxID_YES
);
318 #endif // wxUSE_BUTTON
320 // ----------------------------------------------------------------------------
321 // standard buttons handling
322 // ----------------------------------------------------------------------------
324 void wxDialogBase::EndDialog(int rc
)
332 void wxDialogBase::AcceptAndClose()
334 if ( Validate() && TransferDataFromWindow() )
336 EndDialog(m_affirmativeId
);
340 void wxDialogBase::SetAffirmativeId(int affirmativeId
)
342 m_affirmativeId
= affirmativeId
;
345 void wxDialogBase::SetEscapeId(int escapeId
)
347 m_escapeId
= escapeId
;
350 bool wxDialogBase::EmulateButtonClickIfPresent(int id
)
353 wxButton
*btn
= wxDynamicCast(FindWindow(id
), wxButton
);
355 if ( !btn
|| !btn
->IsEnabled() || !btn
->IsShown() )
358 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, id
);
359 event
.SetEventObject(btn
);
360 btn
->GetEventHandler()->ProcessEvent(event
);
363 #else // !wxUSE_BUTTON
366 #endif // wxUSE_BUTTON/!wxUSE_BUTTON
369 bool wxDialogBase::IsEscapeKey(const wxKeyEvent
& event
)
371 // for most platforms, Esc key is used to close the dialogs
372 return event
.GetKeyCode() == WXK_ESCAPE
&&
373 event
.GetModifiers() == wxMOD_NONE
;
376 void wxDialogBase::OnCharHook(wxKeyEvent
& event
)
378 if ( event
.GetKeyCode() == WXK_ESCAPE
)
380 int idCancel
= GetEscapeId();
384 // don't handle Esc specially at all
388 // this value is special: it means translate Esc to wxID_CANCEL
389 // but if there is no such button, then fall back to wxID_OK
390 if ( EmulateButtonClickIfPresent(wxID_CANCEL
) )
392 idCancel
= GetAffirmativeId();
396 // translate Esc to button press for the button with given id
397 if ( EmulateButtonClickIfPresent(idCancel
) )
405 void wxDialogBase::OnButton(wxCommandEvent
& event
)
407 const int id
= event
.GetId();
408 if ( id
== GetAffirmativeId() )
412 else if ( id
== wxID_APPLY
)
415 TransferDataFromWindow();
417 // TODO: disable the Apply button until things change again
419 else if ( id
== GetEscapeId() ||
420 (id
== wxID_CANCEL
&& GetEscapeId() == wxID_ANY
) )
422 EndDialog(wxID_CANCEL
);
424 else // not a standard button
430 // ----------------------------------------------------------------------------
431 // other event handlers
432 // ----------------------------------------------------------------------------
434 void wxDialogBase::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
436 // We'll send a Cancel message by default, which may close the dialog.
437 // Check for looping if the Cancel event handler calls Close().
439 // Note that if a cancel button and handler aren't present in the dialog,
440 // nothing will happen when you close the dialog via the window manager, or
441 // via Close(). We wouldn't want to destroy the dialog by default, since
442 // the dialog may have been created on the stack. However, this does mean
443 // that calling dialog->Close() won't delete the dialog unless the handler
444 // for wxID_CANCEL does so. So use Destroy() if you want to be sure to
445 // destroy the dialog. The default OnCancel (above) simply ends a modal
446 // dialog, and hides a modeless dialog.
448 // VZ: this is horrible and MT-unsafe. Can't we reuse some of these global
449 // lists here? don't dare to change it now, but should be done later!
450 static wxList closing
;
452 if ( closing
.Member(this) )
455 closing
.Append(this);
457 wxCommandEvent
cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
);
458 cancelEvent
.SetEventObject( this );
459 GetEventHandler()->ProcessEvent(cancelEvent
); // This may close the dialog
461 closing
.DeleteObject(this);
464 void wxDialogBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
467 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
474 /// Do the adaptation
475 bool wxDialogBase::DoLayoutAdaptation()
477 if (GetLayoutAdapter())
478 return GetLayoutAdapter()->DoLayoutAdaptation((wxDialog
*) this);
483 /// Can we do the adaptation?
484 bool wxDialogBase::CanDoLayoutAdaptation()
486 // Check if local setting overrides the global setting
487 bool layoutEnabled
= (GetLayoutAdaptationMode() == wxDIALOG_ADAPTATION_MODE_ENABLED
) || (IsLayoutAdaptationEnabled() && (GetLayoutAdaptationMode() != wxDIALOG_ADAPTATION_MODE_DISABLED
));
489 return (layoutEnabled
&& !m_layoutAdaptationDone
&& GetLayoutAdaptationLevel() != 0 && GetLayoutAdapter() != NULL
&& GetLayoutAdapter()->CanDoLayoutAdaptation((wxDialog
*) this));
492 /// Set scrolling adapter class, returning old adapter
493 wxDialogLayoutAdapter
* wxDialogBase::SetLayoutAdapter(wxDialogLayoutAdapter
* adapter
)
495 wxDialogLayoutAdapter
* oldLayoutAdapter
= sm_layoutAdapter
;
496 sm_layoutAdapter
= adapter
;
497 return oldLayoutAdapter
;
504 IMPLEMENT_CLASS(wxDialogLayoutAdapter
, wxObject
)
506 IMPLEMENT_CLASS(wxStandardDialogLayoutAdapter
, wxDialogLayoutAdapter
)
508 // Allow for caption size on wxWidgets < 2.9
509 #if defined(__WXGTK__) && !wxCHECK_VERSION(2,9,0)
510 #define wxEXTRA_DIALOG_HEIGHT 30
512 #define wxEXTRA_DIALOG_HEIGHT 0
515 /// Indicate that adaptation should be done
516 bool wxStandardDialogLayoutAdapter::CanDoLayoutAdaptation(wxDialog
* dialog
)
518 if (dialog
->GetSizer())
520 wxSize windowSize
, displaySize
;
521 return MustScroll(dialog
, windowSize
, displaySize
) != 0;
527 bool wxStandardDialogLayoutAdapter::DoLayoutAdaptation(wxDialog
* dialog
)
529 if (dialog
->GetSizer())
531 wxBookCtrlBase
* bookContentWindow
= wxDynamicCast(dialog
->GetContentWindow(), wxBookCtrlBase
);
533 if (bookContentWindow
)
535 // If we have a book control, make all the pages (that use sizers) scrollable
536 wxWindowList windows
;
537 for (size_t i
= 0; i
< bookContentWindow
->GetPageCount(); i
++)
539 wxWindow
* page
= bookContentWindow
->GetPage(i
);
541 wxScrolledWindow
* scrolledWindow
= wxDynamicCast(page
, wxScrolledWindow
);
543 windows
.Append(scrolledWindow
);
544 else if (!scrolledWindow
&& page
->GetSizer())
546 // Create a scrolled window and reparent
547 scrolledWindow
= CreateScrolledWindow(page
);
548 wxSizer
* oldSizer
= page
->GetSizer();
550 wxSizer
* newSizer
= new wxBoxSizer(wxVERTICAL
);
551 newSizer
->Add(scrolledWindow
,1, wxEXPAND
, 0);
553 page
->SetSizer(newSizer
, false /* don't delete the old sizer */);
555 scrolledWindow
->SetSizer(oldSizer
);
557 ReparentControls(page
, scrolledWindow
);
559 windows
.Append(scrolledWindow
);
563 FitWithScrolling(dialog
, windows
);
567 // If we have an arbitrary dialog, create a scrolling area for the main content, and a button sizer
568 // for the main buttons.
569 wxScrolledWindow
* scrolledWindow
= CreateScrolledWindow(dialog
);
571 int buttonSizerBorder
= 0;
573 // First try to find a wxStdDialogButtonSizer
574 wxSizer
* buttonSizer
= FindButtonSizer(true /* find std button sizer */, dialog
, dialog
->GetSizer(), buttonSizerBorder
);
576 // Next try to find a wxBoxSizer containing the controls
577 if (!buttonSizer
&& dialog
->GetLayoutAdaptationLevel() > wxDIALOG_ADAPTATION_STANDARD_SIZER
)
578 buttonSizer
= FindButtonSizer(false /* find ordinary sizer */, dialog
, dialog
->GetSizer(), buttonSizerBorder
);
580 // If we still don't have a button sizer, collect any 'loose' buttons in the layout
581 if (!buttonSizer
&& dialog
->GetLayoutAdaptationLevel() > wxDIALOG_ADAPTATION_ANY_SIZER
)
584 wxStdDialogButtonSizer
* stdButtonSizer
= new wxStdDialogButtonSizer
;
585 buttonSizer
= stdButtonSizer
;
587 FindLooseButtons(dialog
, stdButtonSizer
, dialog
->GetSizer(), count
);
589 stdButtonSizer
->Realize();
597 if (buttonSizerBorder
== 0)
598 buttonSizerBorder
= 5;
600 ReparentControls(dialog
, scrolledWindow
, buttonSizer
);
602 wxBoxSizer
* newTopSizer
= new wxBoxSizer(wxVERTICAL
);
603 wxSizer
* oldSizer
= dialog
->GetSizer();
605 dialog
->SetSizer(newTopSizer
, false /* don't delete old sizer */);
607 newTopSizer
->Add(scrolledWindow
, 1, wxEXPAND
|wxALL
, 0);
609 newTopSizer
->Add(buttonSizer
, 0, wxEXPAND
|wxALL
, buttonSizerBorder
);
611 scrolledWindow
->SetSizer(oldSizer
);
613 FitWithScrolling(dialog
, scrolledWindow
);
617 dialog
->SetLayoutAdaptationDone(true);
621 // Create the scrolled window
622 wxScrolledWindow
* wxStandardDialogLayoutAdapter::CreateScrolledWindow(wxWindow
* parent
)
624 wxScrolledWindow
* scrolledWindow
= new wxScrolledWindow(parent
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, wxTAB_TRAVERSAL
|wxVSCROLL
|wxHSCROLL
|wxBORDER_NONE
);
625 return scrolledWindow
;
628 /// Find and remove the button sizer, if any
629 wxSizer
* wxStandardDialogLayoutAdapter::FindButtonSizer(bool stdButtonSizer
, wxDialog
* dialog
, wxSizer
* sizer
, int& retBorder
, int accumlatedBorder
)
631 for ( wxSizerItemList::compatibility_iterator node
= sizer
->GetChildren().GetFirst();
632 node
; node
= node
->GetNext() )
634 wxSizerItem
*item
= node
->GetData();
635 wxSizer
*childSizer
= item
->GetSizer();
639 int newBorder
= accumlatedBorder
;
640 if (item
->GetFlag() & wxALL
)
641 newBorder
+= item
->GetBorder();
643 if (stdButtonSizer
) // find wxStdDialogButtonSizer
645 wxStdDialogButtonSizer
* buttonSizer
= wxDynamicCast(childSizer
, wxStdDialogButtonSizer
);
648 sizer
->Detach(childSizer
);
649 retBorder
= newBorder
;
653 else // find a horizontal box sizer containing standard buttons
655 wxBoxSizer
* buttonSizer
= wxDynamicCast(childSizer
, wxBoxSizer
);
656 if (buttonSizer
&& IsOrdinaryButtonSizer(dialog
, buttonSizer
))
658 sizer
->Detach(childSizer
);
659 retBorder
= newBorder
;
664 wxSizer
* s
= FindButtonSizer(stdButtonSizer
, dialog
, childSizer
, retBorder
, newBorder
);
672 /// Check if this sizer contains standard buttons, and so can be repositioned in the dialog
673 bool wxStandardDialogLayoutAdapter::IsOrdinaryButtonSizer(wxDialog
* dialog
, wxBoxSizer
* sizer
)
675 if (sizer
->GetOrientation() != wxHORIZONTAL
)
678 for ( wxSizerItemList::compatibility_iterator node
= sizer
->GetChildren().GetFirst();
679 node
; node
= node
->GetNext() )
681 wxSizerItem
*item
= node
->GetData();
682 wxButton
*childButton
= wxDynamicCast(item
->GetWindow(), wxButton
);
684 if (childButton
&& IsStandardButton(dialog
, childButton
))
690 /// Check if this is a standard button
691 bool wxStandardDialogLayoutAdapter::IsStandardButton(wxDialog
* dialog
, wxButton
* button
)
693 wxWindowID id
= button
->GetId();
695 return (id
== wxID_OK
|| id
== wxID_CANCEL
|| id
== wxID_YES
|| id
== wxID_NO
|| id
== wxID_SAVE
||
696 id
== wxID_APPLY
|| id
== wxID_HELP
|| id
== wxID_CONTEXT_HELP
|| dialog
->IsMainButtonId(id
));
699 /// Find 'loose' main buttons in the existing layout and add them to the standard dialog sizer
700 bool wxStandardDialogLayoutAdapter::FindLooseButtons(wxDialog
* dialog
, wxStdDialogButtonSizer
* buttonSizer
, wxSizer
* sizer
, int& count
)
702 wxSizerItemList::compatibility_iterator node
= sizer
->GetChildren().GetFirst();
705 wxSizerItemList::compatibility_iterator next
= node
->GetNext();
706 wxSizerItem
*item
= node
->GetData();
707 wxSizer
*childSizer
= item
->GetSizer();
708 wxButton
*childButton
= wxDynamicCast(item
->GetWindow(), wxButton
);
710 if (childButton
&& IsStandardButton(dialog
, childButton
))
712 sizer
->Detach(childButton
);
713 buttonSizer
->AddButton(childButton
);
718 FindLooseButtons(dialog
, buttonSizer
, childSizer
, count
);
725 /// Reparent the controls to the scrolled window
726 void wxStandardDialogLayoutAdapter::ReparentControls(wxWindow
* parent
, wxWindow
* reparentTo
, wxSizer
* buttonSizer
)
728 DoReparentControls(parent
, reparentTo
, buttonSizer
);
731 void wxStandardDialogLayoutAdapter::DoReparentControls(wxWindow
* parent
, wxWindow
* reparentTo
, wxSizer
* buttonSizer
)
733 wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
736 wxWindowList::compatibility_iterator next
= node
->GetNext();
738 wxWindow
*win
= node
->GetData();
740 // Don't reparent the scrolled window or buttons in the button sizer
741 if (win
!= reparentTo
&& (!buttonSizer
|| !buttonSizer
->GetItem(win
)))
743 win
->Reparent(reparentTo
);
745 // Restore correct tab order
746 ::SetWindowPos((HWND
) win
->GetHWND(), HWND_BOTTOM
, -1, -1, -1, -1, SWP_NOMOVE
|SWP_NOSIZE
);
754 /// Find whether scrolling will be necessary for the dialog, returning wxVERTICAL, wxHORIZONTAL or both
755 int wxStandardDialogLayoutAdapter::MustScroll(wxDialog
* dialog
, wxSize
& windowSize
, wxSize
& displaySize
)
757 return DoMustScroll(dialog
, windowSize
, displaySize
);
760 /// Find whether scrolling will be necessary for the dialog, returning wxVERTICAL, wxHORIZONTAL or both
761 int wxStandardDialogLayoutAdapter::DoMustScroll(wxDialog
* dialog
, wxSize
& windowSize
, wxSize
& displaySize
)
763 wxSize minWindowSize
= dialog
->GetSizer()->GetMinSize();
764 windowSize
= dialog
->GetSize();
765 windowSize
= wxSize(wxMax(windowSize
.x
, minWindowSize
.x
), wxMax(windowSize
.y
, minWindowSize
.y
));
767 displaySize
= wxDisplay(wxDisplay::GetFromWindow(dialog
)).GetClientArea().GetSize();
769 displaySize
= wxGetClientDisplayRect();
774 if (windowSize
.y
>= (displaySize
.y
- wxEXTRA_DIALOG_HEIGHT
))
776 if (windowSize
.x
>= displaySize
.x
)
777 flags
|= wxHORIZONTAL
;
782 // A function to fit the dialog around its contents, and then adjust for screen size.
783 // If scrolled windows are passed, scrolling is enabled in the required orientation(s).
784 bool wxStandardDialogLayoutAdapter::FitWithScrolling(wxDialog
* dialog
, wxWindowList
& windows
)
786 return DoFitWithScrolling(dialog
, windows
);
789 // A function to fit the dialog around its contents, and then adjust for screen size.
790 // If a scrolled window is passed, scrolling is enabled in the required orientation(s).
791 bool wxStandardDialogLayoutAdapter::FitWithScrolling(wxDialog
* dialog
, wxScrolledWindow
* scrolledWindow
)
793 return DoFitWithScrolling(dialog
, scrolledWindow
);
796 // A function to fit the dialog around its contents, and then adjust for screen size.
797 // If a scrolled window is passed, scrolling is enabled in the required orientation(s).
798 bool wxStandardDialogLayoutAdapter::DoFitWithScrolling(wxDialog
* dialog
, wxScrolledWindow
* scrolledWindow
)
800 wxWindowList windows
;
801 windows
.Append(scrolledWindow
);
802 return DoFitWithScrolling(dialog
, windows
);
805 bool wxStandardDialogLayoutAdapter::DoFitWithScrolling(wxDialog
* dialog
, wxWindowList
& windows
)
807 wxSizer
* sizer
= dialog
->GetSizer();
811 sizer
->SetSizeHints(dialog
);
813 wxSize windowSize
, displaySize
;
814 int scrollFlags
= DoMustScroll(dialog
, windowSize
, displaySize
);
815 int scrollBarSize
= 20;
819 int scrollBarExtraX
= 0, scrollBarExtraY
= 0;
820 bool resizeHorizontally
= (scrollFlags
& wxHORIZONTAL
) != 0;
821 bool resizeVertically
= (scrollFlags
& wxVERTICAL
) != 0;
823 if (windows
.GetCount() != 0)
825 // Allow extra for a scrollbar, assuming we resizing in one direction only.
826 if ((resizeVertically
&& !resizeHorizontally
) && (windowSize
.x
< (displaySize
.x
- scrollBarSize
)))
827 scrollBarExtraX
= scrollBarSize
;
828 if ((resizeHorizontally
&& !resizeVertically
) && (windowSize
.y
< (displaySize
.y
- scrollBarSize
)))
829 scrollBarExtraY
= scrollBarSize
;
832 wxWindowList::compatibility_iterator node
= windows
.GetFirst();
835 wxWindow
*win
= node
->GetData();
836 wxScrolledWindow
* scrolledWindow
= wxDynamicCast(win
, wxScrolledWindow
);
839 scrolledWindow
->SetScrollRate(resizeHorizontally
? 10 : 0, resizeVertically
? 10 : 0);
841 if (scrolledWindow
->GetSizer())
842 scrolledWindow
->GetSizer()->Fit(scrolledWindow
);
845 node
= node
->GetNext();
848 wxSize limitTo
= windowSize
+ wxSize(scrollBarExtraX
, scrollBarExtraY
);
849 if (resizeVertically
)
850 limitTo
.y
= displaySize
.y
- wxEXTRA_DIALOG_HEIGHT
;
851 if (resizeHorizontally
)
852 limitTo
.x
= displaySize
.x
;
854 dialog
->SetMinSize(limitTo
);
855 dialog
->SetSize(limitTo
);
857 dialog
->SetSizeHints( limitTo
.x
, limitTo
.y
, dialog
->GetMaxWidth(), dialog
->GetMaxHeight() );
864 * Module to initialise standard adapter
867 class wxDialogLayoutAdapterModule
: public wxModule
869 DECLARE_DYNAMIC_CLASS(wxDialogLayoutAdapterModule
)
871 wxDialogLayoutAdapterModule() {}
872 virtual void OnExit() { delete wxDialogBase::SetLayoutAdapter(NULL
); }
873 virtual bool OnInit() { wxDialogBase::SetLayoutAdapter(new wxStandardDialogLayoutAdapter
); return true; }
876 IMPLEMENT_DYNAMIC_CLASS(wxDialogLayoutAdapterModule
, wxModule
)