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/bookctrl.h"
44 #include "wx/scrolwin.h"
45 #include "wx/textwrapper.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_BASE(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
120 wxDialogBase::GetParentForModalDialog(wxWindow
*parent
, long style
) const
122 // creating a parent-less modal dialog will result (under e.g. wxGTK2)
123 // in an unfocused dialog, so try to find a valid parent for it unless we
124 // were explicitly asked not to
125 if ( style
& wxDIALOG_NO_PARENT
)
128 // first try the given parent
130 parent
= CheckIfCanBeUsedAsParent(wxGetTopLevelParent(parent
));
132 // then the currently active window
134 parent
= CheckIfCanBeUsedAsParent(
135 wxGetTopLevelParent(wxGetActiveWindow()));
137 // and finally the application main window
139 parent
= CheckIfCanBeUsedAsParent(wxTheApp
->GetTopWindow());
146 class wxTextSizerWrapper
: public wxTextWrapper
149 wxTextSizerWrapper(wxWindow
*win
)
155 wxSizer
*CreateSizer(const wxString
& text
, int widthMax
)
157 m_sizer
= new wxBoxSizer(wxVERTICAL
);
158 Wrap(m_win
, text
, widthMax
);
163 virtual void OnOutputLine(const wxString
& line
)
167 m_sizer
->Add(new wxStaticText(m_win
, wxID_ANY
, line
));
169 else // empty line, no need to create a control for it
172 m_hLine
= m_win
->GetCharHeight();
174 m_sizer
->Add(5, m_hLine
);
184 wxSizer
*wxDialogBase::CreateTextSizer(const wxString
& message
)
186 // I admit that this is complete bogus, but it makes
187 // message boxes work for pda screens temporarily..
189 const bool is_pda
= wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
;
192 widthMax
= wxSystemSettings::GetMetric( wxSYS_SCREEN_X
) - 25;
195 // '&' is used as accel mnemonic prefix in the wxWidgets controls but in
196 // the static messages created by CreateTextSizer() (used by wxMessageBox,
197 // for example), we don't want this special meaning, so we need to quote it
198 wxString
text(message
);
199 text
.Replace(wxT("&"), wxT("&&"));
201 wxTextSizerWrapper
wrapper(this);
203 return wrapper
.CreateSizer(text
, widthMax
);
206 #endif // wxUSE_STATTEXT
208 wxSizer
*wxDialogBase::CreateButtonSizer(long flags
)
210 #ifdef __SMARTPHONE__
211 wxDialog
* dialog
= (wxDialog
*) this;
213 dialog
->SetLeftMenu(wxID_OK
);
215 if ( flags
& wxCANCEL
)
216 dialog
->SetRightMenu(wxID_CANCEL
);
219 dialog
->SetLeftMenu(wxID_YES
);
222 dialog
->SetRightMenu(wxID_NO
);
225 #else // !__SMARTPHONE__
230 // PocketPC guidelines recommend for Ok/Cancel dialogs to use OK button
231 // located inside caption bar and implement Cancel functionality through
232 // Undo outside dialog. As native behaviour this will be default here but
233 // can be replaced with real wxButtons by setting the option below to 1
234 if ( (flags
& ~(wxCANCEL
|wxNO_DEFAULT
)) != wxOK
||
235 wxSystemOptions::GetOptionInt(wxT("wince.dialog.real-ok-cancel")) )
236 #endif // __POCKETPC__
238 return CreateStdDialogButtonSizer(flags
);
242 #endif // __POCKETPC__
244 #else // !wxUSE_BUTTON
248 #endif // wxUSE_BUTTON/!wxUSE_BUTTON
250 #endif // __SMARTPHONE__/!__SMARTPHONE__
253 wxSizer
*wxDialogBase::CreateSeparatedButtonSizer(long flags
)
255 wxSizer
*sizer
= CreateButtonSizer(flags
);
259 // Mac Human Interface Guidelines recommend not to use static lines as
261 #if wxUSE_STATLINE && !defined(__WXMAC__)
262 wxBoxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
263 topsizer
->Add(new wxStaticLine(this),
264 wxSizerFlags().Expand().DoubleBorder(wxBOTTOM
));
265 topsizer
->Add(sizer
, wxSizerFlags().Expand());
267 #endif // wxUSE_STATLINE
274 wxStdDialogButtonSizer
*wxDialogBase::CreateStdDialogButtonSizer( long flags
)
276 wxStdDialogButtonSizer
*sizer
= new wxStdDialogButtonSizer();
279 wxButton
*yes
= NULL
;
284 ok
= new wxButton(this, wxID_OK
);
285 sizer
->AddButton(ok
);
288 if (flags
& wxCANCEL
)
290 wxButton
*cancel
= new wxButton(this, wxID_CANCEL
);
291 sizer
->AddButton(cancel
);
296 yes
= new wxButton(this, wxID_YES
);
297 sizer
->AddButton(yes
);
302 no
= new wxButton(this, wxID_NO
);
303 sizer
->AddButton(no
);
308 wxButton
*apply
= new wxButton(this, wxID_APPLY
);
309 sizer
->AddButton(apply
);
314 wxButton
*close
= new wxButton(this, wxID_CLOSE
);
315 sizer
->AddButton(close
);
320 wxButton
*help
= new wxButton(this, wxID_HELP
);
321 sizer
->AddButton(help
);
324 if (flags
& wxNO_DEFAULT
)
347 SetAffirmativeId(wxID_OK
);
348 else if (flags
& wxYES
)
349 SetAffirmativeId(wxID_YES
);
356 #endif // wxUSE_BUTTON
358 // ----------------------------------------------------------------------------
359 // standard buttons handling
360 // ----------------------------------------------------------------------------
362 void wxDialogBase::EndDialog(int rc
)
370 void wxDialogBase::AcceptAndClose()
372 if ( Validate() && TransferDataFromWindow() )
374 EndDialog(m_affirmativeId
);
378 void wxDialogBase::SetAffirmativeId(int affirmativeId
)
380 m_affirmativeId
= affirmativeId
;
383 void wxDialogBase::SetEscapeId(int escapeId
)
385 m_escapeId
= escapeId
;
388 bool wxDialogBase::EmulateButtonClickIfPresent(int id
)
391 wxButton
*btn
= wxDynamicCast(FindWindow(id
), wxButton
);
393 if ( !btn
|| !btn
->IsEnabled() || !btn
->IsShown() )
396 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, id
);
397 event
.SetEventObject(btn
);
398 btn
->GetEventHandler()->ProcessEvent(event
);
401 #else // !wxUSE_BUTTON
404 #endif // wxUSE_BUTTON/!wxUSE_BUTTON
407 bool wxDialogBase::IsEscapeKey(const wxKeyEvent
& event
)
409 // for most platforms, Esc key is used to close the dialogs
410 return event
.GetKeyCode() == WXK_ESCAPE
&&
411 event
.GetModifiers() == wxMOD_NONE
;
414 void wxDialogBase::OnCharHook(wxKeyEvent
& event
)
416 if ( event
.GetKeyCode() == WXK_ESCAPE
)
418 int idCancel
= GetEscapeId();
422 // don't handle Esc specially at all
426 // this value is special: it means translate Esc to wxID_CANCEL
427 // but if there is no such button, then fall back to wxID_OK
428 if ( EmulateButtonClickIfPresent(wxID_CANCEL
) )
430 idCancel
= GetAffirmativeId();
434 // translate Esc to button press for the button with given id
435 if ( EmulateButtonClickIfPresent(idCancel
) )
443 void wxDialogBase::OnButton(wxCommandEvent
& event
)
445 const int id
= event
.GetId();
446 if ( id
== GetAffirmativeId() )
450 else if ( id
== wxID_APPLY
)
453 TransferDataFromWindow();
455 // TODO: disable the Apply button until things change again
457 else if ( id
== GetEscapeId() ||
458 (id
== wxID_CANCEL
&& GetEscapeId() == wxID_ANY
) )
460 EndDialog(wxID_CANCEL
);
462 else // not a standard button
468 // ----------------------------------------------------------------------------
469 // compatibility methods for supporting the modality API
470 // ----------------------------------------------------------------------------
472 wxDEFINE_EVENT( wxEVT_WINDOW_MODAL_DIALOG_CLOSED
, wxWindowModalDialogEvent
);
474 IMPLEMENT_DYNAMIC_CLASS(wxWindowModalDialogEvent
, wxCommandEvent
)
476 void wxDialogBase::ShowWindowModal ()
479 SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED
);
482 void wxDialogBase::SendWindowModalDialogEvent ( wxEventType type
)
484 wxWindowModalDialogEvent
event ( type
, GetId());
485 event
.SetEventObject(this);
487 if ( !GetEventHandler()->ProcessEvent(event
) )
489 // the event is not propagated upwards to the parent automatically
490 // because the dialog is a top level window, so do it manually as
491 // in 9 cases of 10 the message must be processed by the dialog
492 // owner and not the dialog itself
493 (void)GetParent()->GetEventHandler()->ProcessEvent(event
);
498 wxDialogModality
wxDialogBase::GetModality() const
500 return IsModal() ? wxDIALOG_MODALITY_APP_MODAL
: wxDIALOG_MODALITY_NONE
;
503 // ----------------------------------------------------------------------------
504 // other event handlers
505 // ----------------------------------------------------------------------------
507 void wxDialogBase::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
509 // We'll send a Cancel message by default, which may close the dialog.
510 // Check for looping if the Cancel event handler calls Close().
512 // Note that if a cancel button and handler aren't present in the dialog,
513 // nothing will happen when you close the dialog via the window manager, or
514 // via Close(). We wouldn't want to destroy the dialog by default, since
515 // the dialog may have been created on the stack. However, this does mean
516 // that calling dialog->Close() won't delete the dialog unless the handler
517 // for wxID_CANCEL does so. So use Destroy() if you want to be sure to
518 // destroy the dialog. The default OnCancel (above) simply ends a modal
519 // dialog, and hides a modeless dialog.
521 int idCancel
= GetEscapeId();
522 if ( idCancel
== wxID_NONE
)
524 if ( idCancel
== wxID_ANY
)
525 idCancel
= wxID_CANCEL
;
527 // VZ: this is horrible and MT-unsafe. Can't we reuse some of these global
528 // lists here? don't dare to change it now, but should be done later!
529 static wxList closing
;
531 if ( closing
.Member(this) )
534 closing
.Append(this);
536 wxCommandEvent
cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED
, idCancel
);
537 cancelEvent
.SetEventObject( this );
538 GetEventHandler()->ProcessEvent(cancelEvent
); // This may close the dialog
540 closing
.DeleteObject(this);
543 void wxDialogBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
546 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
553 /// Do the adaptation
554 bool wxDialogBase::DoLayoutAdaptation()
556 if (GetLayoutAdapter())
558 wxWindow
* focusWindow
= wxFindFocusDescendant(this); // from event.h
559 if (GetLayoutAdapter()->DoLayoutAdaptation((wxDialog
*) this))
562 focusWindow
->SetFocus();
572 /// Can we do the adaptation?
573 bool wxDialogBase::CanDoLayoutAdaptation()
575 // Check if local setting overrides the global setting
576 bool layoutEnabled
= (GetLayoutAdaptationMode() == wxDIALOG_ADAPTATION_MODE_ENABLED
) || (IsLayoutAdaptationEnabled() && (GetLayoutAdaptationMode() != wxDIALOG_ADAPTATION_MODE_DISABLED
));
578 return (layoutEnabled
&& !m_layoutAdaptationDone
&& GetLayoutAdaptationLevel() != 0 && GetLayoutAdapter() != NULL
&& GetLayoutAdapter()->CanDoLayoutAdaptation((wxDialog
*) this));
581 /// Set scrolling adapter class, returning old adapter
582 wxDialogLayoutAdapter
* wxDialogBase::SetLayoutAdapter(wxDialogLayoutAdapter
* adapter
)
584 wxDialogLayoutAdapter
* oldLayoutAdapter
= sm_layoutAdapter
;
585 sm_layoutAdapter
= adapter
;
586 return oldLayoutAdapter
;
593 IMPLEMENT_CLASS(wxDialogLayoutAdapter
, wxObject
)
595 IMPLEMENT_CLASS(wxStandardDialogLayoutAdapter
, wxDialogLayoutAdapter
)
597 // Allow for caption size on wxWidgets < 2.9
598 #if defined(__WXGTK__) && !wxCHECK_VERSION(2,9,0)
599 #define wxEXTRA_DIALOG_HEIGHT 30
601 #define wxEXTRA_DIALOG_HEIGHT 0
604 /// Indicate that adaptation should be done
605 bool wxStandardDialogLayoutAdapter::CanDoLayoutAdaptation(wxDialog
* dialog
)
607 if (dialog
->GetSizer())
609 wxSize windowSize
, displaySize
;
610 return MustScroll(dialog
, windowSize
, displaySize
) != 0;
616 bool wxStandardDialogLayoutAdapter::DoLayoutAdaptation(wxDialog
* dialog
)
618 if (dialog
->GetSizer())
621 wxBookCtrlBase
* bookContentWindow
= wxDynamicCast(dialog
->GetContentWindow(), wxBookCtrlBase
);
623 if (bookContentWindow
)
625 // If we have a book control, make all the pages (that use sizers) scrollable
626 wxWindowList windows
;
627 for (size_t i
= 0; i
< bookContentWindow
->GetPageCount(); i
++)
629 wxWindow
* page
= bookContentWindow
->GetPage(i
);
631 wxScrolledWindow
* scrolledWindow
= wxDynamicCast(page
, wxScrolledWindow
);
633 windows
.Append(scrolledWindow
);
634 else if (!scrolledWindow
&& page
->GetSizer())
636 // Create a scrolled window and reparent
637 scrolledWindow
= CreateScrolledWindow(page
);
638 wxSizer
* oldSizer
= page
->GetSizer();
640 wxSizer
* newSizer
= new wxBoxSizer(wxVERTICAL
);
641 newSizer
->Add(scrolledWindow
,1, wxEXPAND
, 0);
643 page
->SetSizer(newSizer
, false /* don't delete the old sizer */);
645 scrolledWindow
->SetSizer(oldSizer
);
647 ReparentControls(page
, scrolledWindow
);
649 windows
.Append(scrolledWindow
);
653 FitWithScrolling(dialog
, windows
);
656 #endif // wxUSE_BOOKCTRL
658 // If we have an arbitrary dialog, create a scrolling area for the main content, and a button sizer
659 // for the main buttons.
660 wxScrolledWindow
* scrolledWindow
= CreateScrolledWindow(dialog
);
662 int buttonSizerBorder
= 0;
664 // First try to find a wxStdDialogButtonSizer
665 wxSizer
* buttonSizer
= FindButtonSizer(true /* find std button sizer */, dialog
, dialog
->GetSizer(), buttonSizerBorder
);
667 // Next try to find a wxBoxSizer containing the controls
668 if (!buttonSizer
&& dialog
->GetLayoutAdaptationLevel() > wxDIALOG_ADAPTATION_STANDARD_SIZER
)
669 buttonSizer
= FindButtonSizer(false /* find ordinary sizer */, dialog
, dialog
->GetSizer(), buttonSizerBorder
);
671 // If we still don't have a button sizer, collect any 'loose' buttons in the layout
672 if (!buttonSizer
&& dialog
->GetLayoutAdaptationLevel() > wxDIALOG_ADAPTATION_ANY_SIZER
)
675 wxStdDialogButtonSizer
* stdButtonSizer
= new wxStdDialogButtonSizer
;
676 buttonSizer
= stdButtonSizer
;
678 FindLooseButtons(dialog
, stdButtonSizer
, dialog
->GetSizer(), count
);
680 stdButtonSizer
->Realize();
683 wxDELETE(buttonSizer
);
687 if (buttonSizerBorder
== 0)
688 buttonSizerBorder
= 5;
690 ReparentControls(dialog
, scrolledWindow
, buttonSizer
);
692 wxBoxSizer
* newTopSizer
= new wxBoxSizer(wxVERTICAL
);
693 wxSizer
* oldSizer
= dialog
->GetSizer();
695 dialog
->SetSizer(newTopSizer
, false /* don't delete old sizer */);
697 newTopSizer
->Add(scrolledWindow
, 1, wxEXPAND
|wxALL
, 0);
699 newTopSizer
->Add(buttonSizer
, 0, wxEXPAND
|wxALL
, buttonSizerBorder
);
701 scrolledWindow
->SetSizer(oldSizer
);
703 FitWithScrolling(dialog
, scrolledWindow
);
707 dialog
->SetLayoutAdaptationDone(true);
711 // Create the scrolled window
712 wxScrolledWindow
* wxStandardDialogLayoutAdapter::CreateScrolledWindow(wxWindow
* parent
)
714 wxScrolledWindow
* scrolledWindow
= new wxScrolledWindow(parent
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, wxTAB_TRAVERSAL
|wxVSCROLL
|wxHSCROLL
|wxBORDER_NONE
);
715 return scrolledWindow
;
718 /// Find and remove the button sizer, if any
719 wxSizer
* wxStandardDialogLayoutAdapter::FindButtonSizer(bool stdButtonSizer
, wxDialog
* dialog
, wxSizer
* sizer
, int& retBorder
, int accumlatedBorder
)
721 for ( wxSizerItemList::compatibility_iterator node
= sizer
->GetChildren().GetFirst();
722 node
; node
= node
->GetNext() )
724 wxSizerItem
*item
= node
->GetData();
725 wxSizer
*childSizer
= item
->GetSizer();
729 int newBorder
= accumlatedBorder
;
730 if (item
->GetFlag() & wxALL
)
731 newBorder
+= item
->GetBorder();
733 if (stdButtonSizer
) // find wxStdDialogButtonSizer
735 wxStdDialogButtonSizer
* buttonSizer
= wxDynamicCast(childSizer
, wxStdDialogButtonSizer
);
738 sizer
->Detach(childSizer
);
739 retBorder
= newBorder
;
743 else // find a horizontal box sizer containing standard buttons
745 wxBoxSizer
* buttonSizer
= wxDynamicCast(childSizer
, wxBoxSizer
);
746 if (buttonSizer
&& IsOrdinaryButtonSizer(dialog
, buttonSizer
))
748 sizer
->Detach(childSizer
);
749 retBorder
= newBorder
;
754 wxSizer
* s
= FindButtonSizer(stdButtonSizer
, dialog
, childSizer
, retBorder
, newBorder
);
762 /// Check if this sizer contains standard buttons, and so can be repositioned in the dialog
763 bool wxStandardDialogLayoutAdapter::IsOrdinaryButtonSizer(wxDialog
* dialog
, wxBoxSizer
* sizer
)
765 if (sizer
->GetOrientation() != wxHORIZONTAL
)
768 for ( wxSizerItemList::compatibility_iterator node
= sizer
->GetChildren().GetFirst();
769 node
; node
= node
->GetNext() )
771 wxSizerItem
*item
= node
->GetData();
772 wxButton
*childButton
= wxDynamicCast(item
->GetWindow(), wxButton
);
774 if (childButton
&& IsStandardButton(dialog
, childButton
))
780 /// Check if this is a standard button
781 bool wxStandardDialogLayoutAdapter::IsStandardButton(wxDialog
* dialog
, wxButton
* button
)
783 wxWindowID id
= button
->GetId();
785 return (id
== wxID_OK
|| id
== wxID_CANCEL
|| id
== wxID_YES
|| id
== wxID_NO
|| id
== wxID_SAVE
||
786 id
== wxID_APPLY
|| id
== wxID_HELP
|| id
== wxID_CONTEXT_HELP
|| dialog
->IsMainButtonId(id
));
789 /// Find 'loose' main buttons in the existing layout and add them to the standard dialog sizer
790 bool wxStandardDialogLayoutAdapter::FindLooseButtons(wxDialog
* dialog
, wxStdDialogButtonSizer
* buttonSizer
, wxSizer
* sizer
, int& count
)
792 wxSizerItemList::compatibility_iterator node
= sizer
->GetChildren().GetFirst();
795 wxSizerItemList::compatibility_iterator next
= node
->GetNext();
796 wxSizerItem
*item
= node
->GetData();
797 wxSizer
*childSizer
= item
->GetSizer();
798 wxButton
*childButton
= wxDynamicCast(item
->GetWindow(), wxButton
);
800 if (childButton
&& IsStandardButton(dialog
, childButton
))
802 sizer
->Detach(childButton
);
803 buttonSizer
->AddButton(childButton
);
808 FindLooseButtons(dialog
, buttonSizer
, childSizer
, count
);
815 /// Reparent the controls to the scrolled window
816 void wxStandardDialogLayoutAdapter::ReparentControls(wxWindow
* parent
, wxWindow
* reparentTo
, wxSizer
* buttonSizer
)
818 DoReparentControls(parent
, reparentTo
, buttonSizer
);
821 void wxStandardDialogLayoutAdapter::DoReparentControls(wxWindow
* parent
, wxWindow
* reparentTo
, wxSizer
* buttonSizer
)
823 wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
826 wxWindowList::compatibility_iterator next
= node
->GetNext();
828 wxWindow
*win
= node
->GetData();
830 // Don't reparent the scrolled window or buttons in the button sizer
831 if (win
!= reparentTo
&& (!buttonSizer
|| !buttonSizer
->GetItem(win
)))
833 win
->Reparent(reparentTo
);
835 // Restore correct tab order
836 ::SetWindowPos((HWND
) win
->GetHWND(), HWND_BOTTOM
, -1, -1, -1, -1, SWP_NOMOVE
|SWP_NOSIZE
);
844 /// Find whether scrolling will be necessary for the dialog, returning wxVERTICAL, wxHORIZONTAL or both
845 int wxStandardDialogLayoutAdapter::MustScroll(wxDialog
* dialog
, wxSize
& windowSize
, wxSize
& displaySize
)
847 return DoMustScroll(dialog
, windowSize
, displaySize
);
850 /// Find whether scrolling will be necessary for the dialog, returning wxVERTICAL, wxHORIZONTAL or both
851 int wxStandardDialogLayoutAdapter::DoMustScroll(wxDialog
* dialog
, wxSize
& windowSize
, wxSize
& displaySize
)
853 wxSize minWindowSize
= dialog
->GetSizer()->GetMinSize();
854 windowSize
= dialog
->GetSize();
855 windowSize
= wxSize(wxMax(windowSize
.x
, minWindowSize
.x
), wxMax(windowSize
.y
, minWindowSize
.y
));
857 displaySize
= wxDisplay(wxDisplay::GetFromWindow(dialog
)).GetClientArea().GetSize();
859 displaySize
= wxGetClientDisplayRect().GetSize();
864 if (windowSize
.y
>= (displaySize
.y
- wxEXTRA_DIALOG_HEIGHT
))
866 if (windowSize
.x
>= displaySize
.x
)
867 flags
|= wxHORIZONTAL
;
872 // A function to fit the dialog around its contents, and then adjust for screen size.
873 // If scrolled windows are passed, scrolling is enabled in the required orientation(s).
874 bool wxStandardDialogLayoutAdapter::FitWithScrolling(wxDialog
* dialog
, wxWindowList
& windows
)
876 return DoFitWithScrolling(dialog
, windows
);
879 // A function to fit the dialog around its contents, and then adjust for screen size.
880 // If a scrolled window is passed, scrolling is enabled in the required orientation(s).
881 bool wxStandardDialogLayoutAdapter::FitWithScrolling(wxDialog
* dialog
, wxScrolledWindow
* scrolledWindow
)
883 return DoFitWithScrolling(dialog
, scrolledWindow
);
886 // A function to fit the dialog around its contents, and then adjust for screen size.
887 // If a scrolled window is passed, scrolling is enabled in the required orientation(s).
888 bool wxStandardDialogLayoutAdapter::DoFitWithScrolling(wxDialog
* dialog
, wxScrolledWindow
* scrolledWindow
)
890 wxWindowList windows
;
891 windows
.Append(scrolledWindow
);
892 return DoFitWithScrolling(dialog
, windows
);
895 bool wxStandardDialogLayoutAdapter::DoFitWithScrolling(wxDialog
* dialog
, wxWindowList
& windows
)
897 wxSizer
* sizer
= dialog
->GetSizer();
901 sizer
->SetSizeHints(dialog
);
903 wxSize windowSize
, displaySize
;
904 int scrollFlags
= DoMustScroll(dialog
, windowSize
, displaySize
);
905 int scrollBarSize
= 20;
909 int scrollBarExtraX
= 0, scrollBarExtraY
= 0;
910 bool resizeHorizontally
= (scrollFlags
& wxHORIZONTAL
) != 0;
911 bool resizeVertically
= (scrollFlags
& wxVERTICAL
) != 0;
913 if (windows
.GetCount() != 0)
915 // Allow extra for a scrollbar, assuming we resizing in one direction only.
916 if ((resizeVertically
&& !resizeHorizontally
) && (windowSize
.x
< (displaySize
.x
- scrollBarSize
)))
917 scrollBarExtraX
= scrollBarSize
;
918 if ((resizeHorizontally
&& !resizeVertically
) && (windowSize
.y
< (displaySize
.y
- scrollBarSize
)))
919 scrollBarExtraY
= scrollBarSize
;
922 wxWindowList::compatibility_iterator node
= windows
.GetFirst();
925 wxWindow
*win
= node
->GetData();
926 wxScrolledWindow
* scrolledWindow
= wxDynamicCast(win
, wxScrolledWindow
);
929 scrolledWindow
->SetScrollRate(resizeHorizontally
? 10 : 0, resizeVertically
? 10 : 0);
931 if (scrolledWindow
->GetSizer())
932 scrolledWindow
->GetSizer()->Fit(scrolledWindow
);
935 node
= node
->GetNext();
938 wxSize limitTo
= windowSize
+ wxSize(scrollBarExtraX
, scrollBarExtraY
);
939 if (resizeVertically
)
940 limitTo
.y
= displaySize
.y
- wxEXTRA_DIALOG_HEIGHT
;
941 if (resizeHorizontally
)
942 limitTo
.x
= displaySize
.x
;
944 dialog
->SetMinSize(limitTo
);
945 dialog
->SetSize(limitTo
);
947 dialog
->SetSizeHints( limitTo
.x
, limitTo
.y
, dialog
->GetMaxWidth(), dialog
->GetMaxHeight() );
954 * Module to initialise standard adapter
957 class wxDialogLayoutAdapterModule
: public wxModule
959 DECLARE_DYNAMIC_CLASS(wxDialogLayoutAdapterModule
)
961 wxDialogLayoutAdapterModule() {}
962 virtual void OnExit() { delete wxDialogBase::SetLayoutAdapter(NULL
); }
963 virtual bool OnInit() { wxDialogBase::SetLayoutAdapter(new wxStandardDialogLayoutAdapter
); return true; }
966 IMPLEMENT_DYNAMIC_CLASS(wxDialogLayoutAdapterModule
, wxModule
)