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 // FIXME-VC6: this compiler requires an explicit const cast or it fails
109 if ( const_cast<const wxWindow
*>(parent
) == this )
111 // not sure if this can really happen but it doesn't hurt to guard
112 // against this clearly invalid situation
119 wxWindow
*wxDialogBase::GetParentForModalDialog(wxWindow
*parent
) const
121 // creating a parent-less modal dialog will result (under e.g. wxGTK2)
122 // in an unfocused dialog, so try to find a valid parent for it unless we
123 // were explicitly asked not to
124 if ( HasFlag(wxDIALOG_NO_PARENT
) )
127 // first try the given parent
129 parent
= CheckIfCanBeUsedAsParent(wxGetTopLevelParent(parent
));
131 // then the currently active window
133 parent
= CheckIfCanBeUsedAsParent(
134 wxGetTopLevelParent(wxGetActiveWindow()));
136 // and finally the application main window
138 parent
= CheckIfCanBeUsedAsParent(wxTheApp
->GetTopWindow());
145 class wxTextSizerWrapper
: public wxTextWrapper
148 wxTextSizerWrapper(wxWindow
*win
)
154 wxSizer
*CreateSizer(const wxString
& text
, int widthMax
)
156 m_sizer
= new wxBoxSizer(wxVERTICAL
);
157 Wrap(m_win
, text
, widthMax
);
162 virtual void OnOutputLine(const wxString
& line
)
166 m_sizer
->Add(new wxStaticText(m_win
, wxID_ANY
, line
));
168 else // empty line, no need to create a control for it
171 m_hLine
= m_win
->GetCharHeight();
173 m_sizer
->Add(5, m_hLine
);
183 wxSizer
*wxDialogBase::CreateTextSizer(const wxString
& message
)
185 // I admit that this is complete bogus, but it makes
186 // message boxes work for pda screens temporarily..
188 const bool is_pda
= wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
;
191 widthMax
= wxSystemSettings::GetMetric( wxSYS_SCREEN_X
) - 25;
194 // '&' is used as accel mnemonic prefix in the wxWidgets controls but in
195 // the static messages created by CreateTextSizer() (used by wxMessageBox,
196 // for example), we don't want this special meaning, so we need to quote it
197 wxString
text(message
);
198 text
.Replace(_T("&"), _T("&&"));
200 wxTextSizerWrapper
wrapper(this);
202 return wrapper
.CreateSizer(text
, widthMax
);
205 #endif // wxUSE_STATTEXT
207 wxSizer
*wxDialogBase::CreateButtonSizer(long flags
)
209 #ifdef __SMARTPHONE__
210 wxDialog
* dialog
= (wxDialog
*) this;
212 dialog
->SetLeftMenu(wxID_OK
);
214 if ( flags
& wxCANCEL
)
215 dialog
->SetRightMenu(wxID_CANCEL
);
218 dialog
->SetLeftMenu(wxID_YES
);
221 dialog
->SetRightMenu(wxID_NO
);
224 #else // !__SMARTPHONE__
229 // PocketPC guidelines recommend for Ok/Cancel dialogs to use OK button
230 // located inside caption bar and implement Cancel functionality through
231 // Undo outside dialog. As native behaviour this will be default here but
232 // can be replaced with real wxButtons by setting the option below to 1
233 if ( (flags
& ~(wxCANCEL
|wxNO_DEFAULT
)) != wxOK
||
234 wxSystemOptions::GetOptionInt(wxT("wince.dialog.real-ok-cancel")) )
235 #endif // __POCKETPC__
237 return CreateStdDialogButtonSizer(flags
);
241 #endif // __POCKETPC__
243 #else // !wxUSE_BUTTON
247 #endif // wxUSE_BUTTON/!wxUSE_BUTTON
249 #endif // __SMARTPHONE__/!__SMARTPHONE__
252 wxSizer
*wxDialogBase::CreateSeparatedButtonSizer(long flags
)
254 wxSizer
*sizer
= CreateButtonSizer(flags
);
258 // Mac Human Interface Guidelines recommend not to use static lines as
260 #if wxUSE_STATLINE && !defined(__WXMAC__)
261 wxBoxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
262 topsizer
->Add(new wxStaticLine(this),
263 wxSizerFlags().Expand().DoubleBorder(wxBOTTOM
));
264 topsizer
->Add(sizer
, wxSizerFlags().Expand());
266 #endif // wxUSE_STATLINE
273 wxStdDialogButtonSizer
*wxDialogBase::CreateStdDialogButtonSizer( long flags
)
275 wxStdDialogButtonSizer
*sizer
= new wxStdDialogButtonSizer();
278 wxButton
*yes
= NULL
;
283 ok
= new wxButton(this, wxID_OK
);
284 sizer
->AddButton(ok
);
287 if (flags
& wxCANCEL
)
289 wxButton
*cancel
= new wxButton(this, wxID_CANCEL
);
290 sizer
->AddButton(cancel
);
295 yes
= new wxButton(this, wxID_YES
);
296 sizer
->AddButton(yes
);
301 no
= new wxButton(this, wxID_NO
);
302 sizer
->AddButton(no
);
307 wxButton
*apply
= new wxButton(this, wxID_APPLY
);
308 sizer
->AddButton(apply
);
313 wxButton
*close
= new wxButton(this, wxID_CLOSE
);
314 sizer
->AddButton(close
);
319 wxButton
*help
= new wxButton(this, wxID_HELP
);
320 sizer
->AddButton(help
);
323 if (flags
& wxNO_DEFAULT
)
346 SetAffirmativeId(wxID_OK
);
347 else if (flags
& wxYES
)
348 SetAffirmativeId(wxID_YES
);
355 #endif // wxUSE_BUTTON
357 // ----------------------------------------------------------------------------
358 // standard buttons handling
359 // ----------------------------------------------------------------------------
361 void wxDialogBase::EndDialog(int rc
)
369 void wxDialogBase::AcceptAndClose()
371 if ( Validate() && TransferDataFromWindow() )
373 EndDialog(m_affirmativeId
);
377 void wxDialogBase::SetAffirmativeId(int affirmativeId
)
379 m_affirmativeId
= affirmativeId
;
382 void wxDialogBase::SetEscapeId(int escapeId
)
384 m_escapeId
= escapeId
;
387 bool wxDialogBase::EmulateButtonClickIfPresent(int id
)
390 wxButton
*btn
= wxDynamicCast(FindWindow(id
), wxButton
);
392 if ( !btn
|| !btn
->IsEnabled() || !btn
->IsShown() )
395 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, id
);
396 event
.SetEventObject(btn
);
397 btn
->GetEventHandler()->ProcessEvent(event
);
400 #else // !wxUSE_BUTTON
403 #endif // wxUSE_BUTTON/!wxUSE_BUTTON
406 bool wxDialogBase::IsEscapeKey(const wxKeyEvent
& event
)
408 // for most platforms, Esc key is used to close the dialogs
409 return event
.GetKeyCode() == WXK_ESCAPE
&&
410 event
.GetModifiers() == wxMOD_NONE
;
413 void wxDialogBase::OnCharHook(wxKeyEvent
& event
)
415 if ( event
.GetKeyCode() == WXK_ESCAPE
)
417 int idCancel
= GetEscapeId();
421 // don't handle Esc specially at all
425 // this value is special: it means translate Esc to wxID_CANCEL
426 // but if there is no such button, then fall back to wxID_OK
427 if ( EmulateButtonClickIfPresent(wxID_CANCEL
) )
429 idCancel
= GetAffirmativeId();
433 // translate Esc to button press for the button with given id
434 if ( EmulateButtonClickIfPresent(idCancel
) )
442 void wxDialogBase::OnButton(wxCommandEvent
& event
)
444 const int id
= event
.GetId();
445 if ( id
== GetAffirmativeId() )
449 else if ( id
== wxID_APPLY
)
452 TransferDataFromWindow();
454 // TODO: disable the Apply button until things change again
456 else if ( id
== GetEscapeId() ||
457 (id
== wxID_CANCEL
&& GetEscapeId() == wxID_ANY
) )
459 EndDialog(wxID_CANCEL
);
461 else // not a standard button
467 // ----------------------------------------------------------------------------
468 // other event handlers
469 // ----------------------------------------------------------------------------
471 void wxDialogBase::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
473 // We'll send a Cancel message by default, which may close the dialog.
474 // Check for looping if the Cancel event handler calls Close().
476 // Note that if a cancel button and handler aren't present in the dialog,
477 // nothing will happen when you close the dialog via the window manager, or
478 // via Close(). We wouldn't want to destroy the dialog by default, since
479 // the dialog may have been created on the stack. However, this does mean
480 // that calling dialog->Close() won't delete the dialog unless the handler
481 // for wxID_CANCEL does so. So use Destroy() if you want to be sure to
482 // destroy the dialog. The default OnCancel (above) simply ends a modal
483 // dialog, and hides a modeless dialog.
485 int idCancel
= GetEscapeId();
486 if ( idCancel
== wxID_NONE
)
488 if ( idCancel
== wxID_ANY
)
489 idCancel
= wxID_CANCEL
;
491 // VZ: this is horrible and MT-unsafe. Can't we reuse some of these global
492 // lists here? don't dare to change it now, but should be done later!
493 static wxList closing
;
495 if ( closing
.Member(this) )
498 closing
.Append(this);
500 wxCommandEvent
cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED
, idCancel
);
501 cancelEvent
.SetEventObject( this );
502 GetEventHandler()->ProcessEvent(cancelEvent
); // This may close the dialog
504 closing
.DeleteObject(this);
507 void wxDialogBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
510 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
517 /// Do the adaptation
518 bool wxDialogBase::DoLayoutAdaptation()
520 if (GetLayoutAdapter())
522 wxWindow
* focusWindow
= wxFindFocusDescendant(this); // from event.h
523 if (GetLayoutAdapter()->DoLayoutAdaptation((wxDialog
*) this))
526 focusWindow
->SetFocus();
536 /// Can we do the adaptation?
537 bool wxDialogBase::CanDoLayoutAdaptation()
539 // Check if local setting overrides the global setting
540 bool layoutEnabled
= (GetLayoutAdaptationMode() == wxDIALOG_ADAPTATION_MODE_ENABLED
) || (IsLayoutAdaptationEnabled() && (GetLayoutAdaptationMode() != wxDIALOG_ADAPTATION_MODE_DISABLED
));
542 return (layoutEnabled
&& !m_layoutAdaptationDone
&& GetLayoutAdaptationLevel() != 0 && GetLayoutAdapter() != NULL
&& GetLayoutAdapter()->CanDoLayoutAdaptation((wxDialog
*) this));
545 /// Set scrolling adapter class, returning old adapter
546 wxDialogLayoutAdapter
* wxDialogBase::SetLayoutAdapter(wxDialogLayoutAdapter
* adapter
)
548 wxDialogLayoutAdapter
* oldLayoutAdapter
= sm_layoutAdapter
;
549 sm_layoutAdapter
= adapter
;
550 return oldLayoutAdapter
;
557 IMPLEMENT_CLASS(wxDialogLayoutAdapter
, wxObject
)
559 IMPLEMENT_CLASS(wxStandardDialogLayoutAdapter
, wxDialogLayoutAdapter
)
561 // Allow for caption size on wxWidgets < 2.9
562 #if defined(__WXGTK__) && !wxCHECK_VERSION(2,9,0)
563 #define wxEXTRA_DIALOG_HEIGHT 30
565 #define wxEXTRA_DIALOG_HEIGHT 0
568 /// Indicate that adaptation should be done
569 bool wxStandardDialogLayoutAdapter::CanDoLayoutAdaptation(wxDialog
* dialog
)
571 if (dialog
->GetSizer())
573 wxSize windowSize
, displaySize
;
574 return MustScroll(dialog
, windowSize
, displaySize
) != 0;
580 bool wxStandardDialogLayoutAdapter::DoLayoutAdaptation(wxDialog
* dialog
)
582 if (dialog
->GetSizer())
585 wxBookCtrlBase
* bookContentWindow
= wxDynamicCast(dialog
->GetContentWindow(), wxBookCtrlBase
);
587 if (bookContentWindow
)
589 // If we have a book control, make all the pages (that use sizers) scrollable
590 wxWindowList windows
;
591 for (size_t i
= 0; i
< bookContentWindow
->GetPageCount(); i
++)
593 wxWindow
* page
= bookContentWindow
->GetPage(i
);
595 wxScrolledWindow
* scrolledWindow
= wxDynamicCast(page
, wxScrolledWindow
);
597 windows
.Append(scrolledWindow
);
598 else if (!scrolledWindow
&& page
->GetSizer())
600 // Create a scrolled window and reparent
601 scrolledWindow
= CreateScrolledWindow(page
);
602 wxSizer
* oldSizer
= page
->GetSizer();
604 wxSizer
* newSizer
= new wxBoxSizer(wxVERTICAL
);
605 newSizer
->Add(scrolledWindow
,1, wxEXPAND
, 0);
607 page
->SetSizer(newSizer
, false /* don't delete the old sizer */);
609 scrolledWindow
->SetSizer(oldSizer
);
611 ReparentControls(page
, scrolledWindow
);
613 windows
.Append(scrolledWindow
);
617 FitWithScrolling(dialog
, windows
);
620 #endif // wxUSE_BOOKCTRL
622 // If we have an arbitrary dialog, create a scrolling area for the main content, and a button sizer
623 // for the main buttons.
624 wxScrolledWindow
* scrolledWindow
= CreateScrolledWindow(dialog
);
626 int buttonSizerBorder
= 0;
628 // First try to find a wxStdDialogButtonSizer
629 wxSizer
* buttonSizer
= FindButtonSizer(true /* find std button sizer */, dialog
, dialog
->GetSizer(), buttonSizerBorder
);
631 // Next try to find a wxBoxSizer containing the controls
632 if (!buttonSizer
&& dialog
->GetLayoutAdaptationLevel() > wxDIALOG_ADAPTATION_STANDARD_SIZER
)
633 buttonSizer
= FindButtonSizer(false /* find ordinary sizer */, dialog
, dialog
->GetSizer(), buttonSizerBorder
);
635 // If we still don't have a button sizer, collect any 'loose' buttons in the layout
636 if (!buttonSizer
&& dialog
->GetLayoutAdaptationLevel() > wxDIALOG_ADAPTATION_ANY_SIZER
)
639 wxStdDialogButtonSizer
* stdButtonSizer
= new wxStdDialogButtonSizer
;
640 buttonSizer
= stdButtonSizer
;
642 FindLooseButtons(dialog
, stdButtonSizer
, dialog
->GetSizer(), count
);
644 stdButtonSizer
->Realize();
652 if (buttonSizerBorder
== 0)
653 buttonSizerBorder
= 5;
655 ReparentControls(dialog
, scrolledWindow
, buttonSizer
);
657 wxBoxSizer
* newTopSizer
= new wxBoxSizer(wxVERTICAL
);
658 wxSizer
* oldSizer
= dialog
->GetSizer();
660 dialog
->SetSizer(newTopSizer
, false /* don't delete old sizer */);
662 newTopSizer
->Add(scrolledWindow
, 1, wxEXPAND
|wxALL
, 0);
664 newTopSizer
->Add(buttonSizer
, 0, wxEXPAND
|wxALL
, buttonSizerBorder
);
666 scrolledWindow
->SetSizer(oldSizer
);
668 FitWithScrolling(dialog
, scrolledWindow
);
672 dialog
->SetLayoutAdaptationDone(true);
676 // Create the scrolled window
677 wxScrolledWindow
* wxStandardDialogLayoutAdapter::CreateScrolledWindow(wxWindow
* parent
)
679 wxScrolledWindow
* scrolledWindow
= new wxScrolledWindow(parent
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, wxTAB_TRAVERSAL
|wxVSCROLL
|wxHSCROLL
|wxBORDER_NONE
);
680 return scrolledWindow
;
683 /// Find and remove the button sizer, if any
684 wxSizer
* wxStandardDialogLayoutAdapter::FindButtonSizer(bool stdButtonSizer
, wxDialog
* dialog
, wxSizer
* sizer
, int& retBorder
, int accumlatedBorder
)
686 for ( wxSizerItemList::compatibility_iterator node
= sizer
->GetChildren().GetFirst();
687 node
; node
= node
->GetNext() )
689 wxSizerItem
*item
= node
->GetData();
690 wxSizer
*childSizer
= item
->GetSizer();
694 int newBorder
= accumlatedBorder
;
695 if (item
->GetFlag() & wxALL
)
696 newBorder
+= item
->GetBorder();
698 if (stdButtonSizer
) // find wxStdDialogButtonSizer
700 wxStdDialogButtonSizer
* buttonSizer
= wxDynamicCast(childSizer
, wxStdDialogButtonSizer
);
703 sizer
->Detach(childSizer
);
704 retBorder
= newBorder
;
708 else // find a horizontal box sizer containing standard buttons
710 wxBoxSizer
* buttonSizer
= wxDynamicCast(childSizer
, wxBoxSizer
);
711 if (buttonSizer
&& IsOrdinaryButtonSizer(dialog
, buttonSizer
))
713 sizer
->Detach(childSizer
);
714 retBorder
= newBorder
;
719 wxSizer
* s
= FindButtonSizer(stdButtonSizer
, dialog
, childSizer
, retBorder
, newBorder
);
727 /// Check if this sizer contains standard buttons, and so can be repositioned in the dialog
728 bool wxStandardDialogLayoutAdapter::IsOrdinaryButtonSizer(wxDialog
* dialog
, wxBoxSizer
* sizer
)
730 if (sizer
->GetOrientation() != wxHORIZONTAL
)
733 for ( wxSizerItemList::compatibility_iterator node
= sizer
->GetChildren().GetFirst();
734 node
; node
= node
->GetNext() )
736 wxSizerItem
*item
= node
->GetData();
737 wxButton
*childButton
= wxDynamicCast(item
->GetWindow(), wxButton
);
739 if (childButton
&& IsStandardButton(dialog
, childButton
))
745 /// Check if this is a standard button
746 bool wxStandardDialogLayoutAdapter::IsStandardButton(wxDialog
* dialog
, wxButton
* button
)
748 wxWindowID id
= button
->GetId();
750 return (id
== wxID_OK
|| id
== wxID_CANCEL
|| id
== wxID_YES
|| id
== wxID_NO
|| id
== wxID_SAVE
||
751 id
== wxID_APPLY
|| id
== wxID_HELP
|| id
== wxID_CONTEXT_HELP
|| dialog
->IsMainButtonId(id
));
754 /// Find 'loose' main buttons in the existing layout and add them to the standard dialog sizer
755 bool wxStandardDialogLayoutAdapter::FindLooseButtons(wxDialog
* dialog
, wxStdDialogButtonSizer
* buttonSizer
, wxSizer
* sizer
, int& count
)
757 wxSizerItemList::compatibility_iterator node
= sizer
->GetChildren().GetFirst();
760 wxSizerItemList::compatibility_iterator next
= node
->GetNext();
761 wxSizerItem
*item
= node
->GetData();
762 wxSizer
*childSizer
= item
->GetSizer();
763 wxButton
*childButton
= wxDynamicCast(item
->GetWindow(), wxButton
);
765 if (childButton
&& IsStandardButton(dialog
, childButton
))
767 sizer
->Detach(childButton
);
768 buttonSizer
->AddButton(childButton
);
773 FindLooseButtons(dialog
, buttonSizer
, childSizer
, count
);
780 /// Reparent the controls to the scrolled window
781 void wxStandardDialogLayoutAdapter::ReparentControls(wxWindow
* parent
, wxWindow
* reparentTo
, wxSizer
* buttonSizer
)
783 DoReparentControls(parent
, reparentTo
, buttonSizer
);
786 void wxStandardDialogLayoutAdapter::DoReparentControls(wxWindow
* parent
, wxWindow
* reparentTo
, wxSizer
* buttonSizer
)
788 wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
791 wxWindowList::compatibility_iterator next
= node
->GetNext();
793 wxWindow
*win
= node
->GetData();
795 // Don't reparent the scrolled window or buttons in the button sizer
796 if (win
!= reparentTo
&& (!buttonSizer
|| !buttonSizer
->GetItem(win
)))
798 win
->Reparent(reparentTo
);
800 // Restore correct tab order
801 ::SetWindowPos((HWND
) win
->GetHWND(), HWND_BOTTOM
, -1, -1, -1, -1, SWP_NOMOVE
|SWP_NOSIZE
);
809 /// Find whether scrolling will be necessary for the dialog, returning wxVERTICAL, wxHORIZONTAL or both
810 int wxStandardDialogLayoutAdapter::MustScroll(wxDialog
* dialog
, wxSize
& windowSize
, wxSize
& displaySize
)
812 return DoMustScroll(dialog
, windowSize
, displaySize
);
815 /// Find whether scrolling will be necessary for the dialog, returning wxVERTICAL, wxHORIZONTAL or both
816 int wxStandardDialogLayoutAdapter::DoMustScroll(wxDialog
* dialog
, wxSize
& windowSize
, wxSize
& displaySize
)
818 wxSize minWindowSize
= dialog
->GetSizer()->GetMinSize();
819 windowSize
= dialog
->GetSize();
820 windowSize
= wxSize(wxMax(windowSize
.x
, minWindowSize
.x
), wxMax(windowSize
.y
, minWindowSize
.y
));
822 displaySize
= wxDisplay(wxDisplay::GetFromWindow(dialog
)).GetClientArea().GetSize();
824 displaySize
= wxGetClientDisplayRect().GetSize();
829 if (windowSize
.y
>= (displaySize
.y
- wxEXTRA_DIALOG_HEIGHT
))
831 if (windowSize
.x
>= displaySize
.x
)
832 flags
|= wxHORIZONTAL
;
837 // A function to fit the dialog around its contents, and then adjust for screen size.
838 // If scrolled windows are passed, scrolling is enabled in the required orientation(s).
839 bool wxStandardDialogLayoutAdapter::FitWithScrolling(wxDialog
* dialog
, wxWindowList
& windows
)
841 return DoFitWithScrolling(dialog
, windows
);
844 // A function to fit the dialog around its contents, and then adjust for screen size.
845 // If a scrolled window is passed, scrolling is enabled in the required orientation(s).
846 bool wxStandardDialogLayoutAdapter::FitWithScrolling(wxDialog
* dialog
, wxScrolledWindow
* scrolledWindow
)
848 return DoFitWithScrolling(dialog
, scrolledWindow
);
851 // A function to fit the dialog around its contents, and then adjust for screen size.
852 // If a scrolled window is passed, scrolling is enabled in the required orientation(s).
853 bool wxStandardDialogLayoutAdapter::DoFitWithScrolling(wxDialog
* dialog
, wxScrolledWindow
* scrolledWindow
)
855 wxWindowList windows
;
856 windows
.Append(scrolledWindow
);
857 return DoFitWithScrolling(dialog
, windows
);
860 bool wxStandardDialogLayoutAdapter::DoFitWithScrolling(wxDialog
* dialog
, wxWindowList
& windows
)
862 wxSizer
* sizer
= dialog
->GetSizer();
866 sizer
->SetSizeHints(dialog
);
868 wxSize windowSize
, displaySize
;
869 int scrollFlags
= DoMustScroll(dialog
, windowSize
, displaySize
);
870 int scrollBarSize
= 20;
874 int scrollBarExtraX
= 0, scrollBarExtraY
= 0;
875 bool resizeHorizontally
= (scrollFlags
& wxHORIZONTAL
) != 0;
876 bool resizeVertically
= (scrollFlags
& wxVERTICAL
) != 0;
878 if (windows
.GetCount() != 0)
880 // Allow extra for a scrollbar, assuming we resizing in one direction only.
881 if ((resizeVertically
&& !resizeHorizontally
) && (windowSize
.x
< (displaySize
.x
- scrollBarSize
)))
882 scrollBarExtraX
= scrollBarSize
;
883 if ((resizeHorizontally
&& !resizeVertically
) && (windowSize
.y
< (displaySize
.y
- scrollBarSize
)))
884 scrollBarExtraY
= scrollBarSize
;
887 wxWindowList::compatibility_iterator node
= windows
.GetFirst();
890 wxWindow
*win
= node
->GetData();
891 wxScrolledWindow
* scrolledWindow
= wxDynamicCast(win
, wxScrolledWindow
);
894 scrolledWindow
->SetScrollRate(resizeHorizontally
? 10 : 0, resizeVertically
? 10 : 0);
896 if (scrolledWindow
->GetSizer())
897 scrolledWindow
->GetSizer()->Fit(scrolledWindow
);
900 node
= node
->GetNext();
903 wxSize limitTo
= windowSize
+ wxSize(scrollBarExtraX
, scrollBarExtraY
);
904 if (resizeVertically
)
905 limitTo
.y
= displaySize
.y
- wxEXTRA_DIALOG_HEIGHT
;
906 if (resizeHorizontally
)
907 limitTo
.x
= displaySize
.x
;
909 dialog
->SetMinSize(limitTo
);
910 dialog
->SetSize(limitTo
);
912 dialog
->SetSizeHints( limitTo
.x
, limitTo
.y
, dialog
->GetMaxWidth(), dialog
->GetMaxHeight() );
919 * Module to initialise standard adapter
922 class wxDialogLayoutAdapterModule
: public wxModule
924 DECLARE_DYNAMIC_CLASS(wxDialogLayoutAdapterModule
)
926 wxDialogLayoutAdapterModule() {}
927 virtual void OnExit() { delete wxDialogBase::SetLayoutAdapter(NULL
); }
928 virtual bool OnInit() { wxDialogBase::SetLayoutAdapter(new wxStandardDialogLayoutAdapter
); return true; }
931 IMPLEMENT_DYNAMIC_CLASS(wxDialogLayoutAdapterModule
, wxModule
)