13#include "wx/display.h"
14#include "wx/bookctrl.h"
16#include "scrollingdialog.h"
19#if defined(__WXGTK__) && !wxCHECK_VERSION(2, 9, 0)
20#define wxEXTRA_DIALOG_HEIGHT 30
22#define wxEXTRA_DIALOG_HEIGHT 0
33bool wxDialogHelper::sm_layoutAdaptation =
true;
35void wxDialogHelper::Init() {
36 m_layoutAdaptationLevel = 3;
37 m_layoutLayoutAdaptationDone = FALSE;
42 if (GetLayoutAdapter())
60 return oldLayoutAdapter;
72 if (dialog->GetDialog()->GetSizer()) {
73 wxSize windowSize, displaySize;
74 return MustScroll(dialog->GetDialog(), windowSize, displaySize) != 0;
80 if (dialog->GetDialog()->GetSizer()) {
83#if !wxCHECK_VERSION(2, 8, 8) || \
84 (wxCHECK_VERSION(2, 9, 0) && !wxCHECK_VERSION(3, 0, 0))
85 wxBookCtrlBase* bookContentWindow =
88 wxBookCtrlBase* bookContentWindow =
92 if (bookContentWindow) {
96 for (
size_t i = 0; i < bookContentWindow->GetPageCount(); i++) {
97 wxWindow* page = bookContentWindow->GetPage(i);
99 wxScrolledWindow* scrolledWindow =
100 wxDynamicCast(page, wxScrolledWindow);
102 windows.Append(scrolledWindow);
103 else if (!scrolledWindow && page->GetSizer()) {
105 scrolledWindow =
new wxScrolledWindow(
106 page, wxID_ANY, wxDefaultPosition, wxDefaultSize,
107 wxTAB_TRAVERSAL | wxVSCROLL | wxHSCROLL | wxBORDER_NONE);
108 wxSizer* oldSizer = page->GetSizer();
110 wxSizer* newSizer =
new wxBoxSizer(wxVERTICAL);
111 newSizer->Add(scrolledWindow, 1, wxEXPAND, 0);
113 page->SetSizer(newSizer,
false );
115 scrolledWindow->SetSizer(oldSizer);
119 windows.Append(scrolledWindow);
127 wxScrolledWindow* scrolledWindow =
new wxScrolledWindow(
128 dialog->GetDialog(), wxID_ANY, wxDefaultPosition, wxDefaultSize,
129 wxTAB_TRAVERSAL | wxVSCROLL | wxHSCROLL | wxBORDER_NONE);
131 int buttonSizerBorder = 0;
134 wxSizer* buttonSizer =
136 dialog->GetDialog()->GetSizer(), buttonSizerBorder);
142 dialog->GetDialog()->GetSizer(), buttonSizerBorder);
148 wxStdDialogButtonSizer* stdButtonSizer =
new wxStdDialogButtonSizer;
149 buttonSizer = stdButtonSizer;
152 dialog->GetDialog()->GetSizer(), count);
154 stdButtonSizer->Realize();
161 if (buttonSizerBorder == 0) buttonSizerBorder = 5;
165 wxBoxSizer* newTopSizer =
new wxBoxSizer(wxVERTICAL);
166 wxSizer* oldSizer = dialog->GetDialog()->GetSizer();
168 dialog->GetDialog()->SetSizer(newTopSizer,
171 newTopSizer->Add(scrolledWindow, 1, wxEXPAND | wxALL, 0);
173 newTopSizer->Add(buttonSizer, 0, wxEXPAND | wxALL, buttonSizerBorder);
175 scrolledWindow->SetSizer(oldSizer);
190 int accumlatedBorder) {
191 for (wxSizerItemList::compatibility_iterator node =
192 sizer->GetChildren().GetFirst();
193 node; node = node->GetNext()) {
194 wxSizerItem* item = node->GetData();
195 wxSizer* childSizer = item->GetSizer();
198 int newBorder = accumlatedBorder;
199 if (item->GetFlag() & wxALL) newBorder += item->GetBorder();
203 wxStdDialogButtonSizer* buttonSizer =
204 wxDynamicCast(childSizer, wxStdDialogButtonSizer);
206 sizer->Detach(childSizer);
207 retBorder = newBorder;
212 wxBoxSizer* buttonSizer = wxDynamicCast(childSizer, wxBoxSizer);
214 sizer->Detach(childSizer);
215 retBorder = newBorder;
221 retBorder, newBorder);
232 if (sizer->GetOrientation() != wxHORIZONTAL)
return false;
234 for (wxSizerItemList::compatibility_iterator node =
235 sizer->GetChildren().GetFirst();
236 node; node = node->GetNext()) {
237 wxSizerItem* item = node->GetData();
238 wxButton* childButton = wxDynamicCast(item->GetWindow(), wxButton);
248 wxWindowID
id = button->GetId();
250 return (
id == wxID_OK ||
id == wxID_CANCEL ||
id == wxID_YES ||
251 id == wxID_NO ||
id == wxID_SAVE ||
id == wxID_APPLY ||
252 id == wxID_HELP ||
id == wxID_CONTEXT_HELP ||
259 wxDialogHelper* dialog, wxStdDialogButtonSizer* buttonSizer, wxSizer* sizer,
261 wxSizerItemList::compatibility_iterator node =
262 sizer->GetChildren().GetFirst();
264 wxSizerItemList::compatibility_iterator next = node->GetNext();
265 wxSizerItem* item = node->GetData();
266 wxSizer* childSizer = item->GetSizer();
267 wxButton* childButton = wxDynamicCast(item->GetWindow(), wxButton);
270 sizer->Detach(childButton);
271 buttonSizer->AddButton(childButton);
284 wxWindow* reparentTo,
285 wxSizer* buttonSizer) {
286 wxWindowList::compatibility_iterator node = parent->GetChildren().GetFirst();
288 wxWindowList::compatibility_iterator next = node->GetNext();
290 wxWindow* win = node->GetData();
293 if (win != reparentTo && (!buttonSizer || !buttonSizer->GetItem(win))) {
294 win->Reparent(reparentTo);
297 ::SetWindowPos((HWND)win->GetHWND(), HWND_BOTTOM, -1, -1, -1, -1,
298 SWP_NOMOVE | SWP_NOSIZE);
310 wxSize& displaySize) {
311 wxSize minWindowSize = dialog->GetSizer()->GetMinSize();
312 windowSize = dialog->GetSize();
313 windowSize = wxSize(wxMax(windowSize.x, minWindowSize.x),
314 wxMax(windowSize.y, minWindowSize.y));
316 wxDisplay(wxDisplay::GetFromWindow(dialog)).GetClientArea().GetSize();
320 if (windowSize.y >= (displaySize.y - wxEXTRA_DIALOG_HEIGHT))
322 if (windowSize.x >= displaySize.x) flags |= wxHORIZONTAL;
331 wxWindowList& windows) {
332 wxSizer* sizer = dialog->GetSizer();
333 if (!sizer)
return false;
335 sizer->SetSizeHints(dialog);
337 wxSize windowSize, displaySize;
338 int scrollFlags =
MustScroll(dialog, windowSize, displaySize);
339 int scrollBarSize = 20;
342 int scrollBarExtraX = 0, scrollBarExtraY = 0;
343 bool resizeHorizontally = (scrollFlags & wxHORIZONTAL) != 0;
344 bool resizeVertically = (scrollFlags & wxVERTICAL) != 0;
346 if (windows.GetCount() != 0) {
349 if ((resizeVertically && !resizeHorizontally) &&
350 (windowSize.x < (displaySize.x - scrollBarSize)))
351 scrollBarExtraX = scrollBarSize;
352 if ((resizeHorizontally && !resizeVertically) &&
353 (windowSize.y < (displaySize.y - scrollBarSize)))
354 scrollBarExtraY = scrollBarSize;
357 wxWindowList::compatibility_iterator node = windows.GetFirst();
359 wxWindow* win = node->GetData();
360 wxScrolledWindow* scrolledWindow = wxDynamicCast(win, wxScrolledWindow);
361 if (scrolledWindow) {
362 scrolledWindow->SetScrollRate(resizeHorizontally ? 10 : 0,
363 resizeVertically ? 10 : 0);
365 if (scrolledWindow->GetSizer())
366 scrolledWindow->GetSizer()->Fit(scrolledWindow);
369 node = node->GetNext();
372 wxSize limitTo = windowSize + wxSize(scrollBarExtraX, scrollBarExtraY);
373 if (resizeVertically) limitTo.y = displaySize.y - wxEXTRA_DIALOG_HEIGHT;
374 if (resizeHorizontally) limitTo.x = displaySize.x;
376 dialog->SetMinSize(limitTo);
377 dialog->SetSize(limitTo);
379 dialog->SetSizeHints(limitTo.x, limitTo.y, dialog->GetMaxWidth(),
380 dialog->GetMaxHeight());
390 wxDialog* dialog, wxScrolledWindow* scrolledWindow) {
391 wxWindowList windows;
392 windows.Append(scrolledWindow);
405 virtual bool OnInit() {
421bool wxScrollingDialog::Create(wxWindow* parent,
int id,
const wxString& title,
422 const wxPoint& pos,
const wxSize& size,
424 return wxDialog::Create(parent,
id, title, pos, size, style);
431 return wxDialog::Show(show);
438 return wxDialog::ShowModal();
447void wxScrollingPropertySheetDialog::Init() { wxDialogHelper::SetDialog(
this); }
451 return GetBookCtrl();
458 return wxPropertySheetDialog::Show(show);
465 return wxPropertySheetDialog::ShowModal();
int GetLayoutAdaptationLevel() const
Get level of adaptation.
virtual wxWindow * GetContentWindow() const
Returns a content window if there is one.
void SetLayoutAdaptationDone(bool adaptationDone)
Returns true if the adaptation has been done.
static bool GetLayoutAdaptation()
Global switch for layout adaptation.
static wxDialogLayoutAdapter * sm_layoutAdapter
static wxDialogLayoutAdapter * SetLayoutAdapter(wxDialogLayoutAdapter *adapter)
Set layout adapter class, returning old adapter.
bool IsUserButtonId(wxWindowID id)
Is this id in the custom button id array?
virtual bool DoLayoutAdaptation()
Do the adaptation.
virtual bool CanDoLayoutAdaptation()
Can we do the adaptation?
virtual bool DoLayoutAdaptation(wxDialogHelper *dialog)=0
Override this function to do the adaptation.
virtual bool FitWithScrolling(wxDialog *dialog, wxScrolledWindow *scrolledWindow)
A function to fit the dialog around its contents, and then adjust for screen size.
virtual bool IsOrdinaryButtonSizer(wxDialogHelper *dialog, wxBoxSizer *sizer)
Check if this sizer contains standard buttons, and so can be repositioned in the dialog.
virtual bool FindLooseButtons(wxDialogHelper *dialog, wxStdDialogButtonSizer *buttonSizer, wxSizer *sizer, int &count)
Find 'loose' main buttons in the existing layout and add them to the standard dialog sizer.
virtual bool DoLayoutAdaptation(wxDialogHelper *dialog)
Do layout adaptation.
virtual void ReparentControls(wxWindow *parent, wxWindow *reparentTo, wxSizer *buttonSizer=NULL)
Reparent the controls to the scrolled window, except those in buttonSizer.
virtual bool IsStandardButton(wxDialogHelper *dialog, wxButton *button)
Check if this is a standard button.
virtual int MustScroll(wxDialog *dialog, wxSize &windowSize, wxSize &displaySize)
Find whether scrolling will be necessary for the dialog, returning wxVERTICAL, wxHORIZONTAL or both.
virtual wxSizer * FindButtonSizer(bool stdButtonSizer, wxDialogHelper *dialog, wxSizer *sizer, int &retBorder, int accumlatedBorder=0)
Find a standard or horizontal box sizer.