bool CDefaultFileExistsDlg::Load(wxWindow *parent, bool fromQueue) { if (!wxDialogEx::Load(parent, _T("ID_DEFAULTFILEEXISTSDLG"))) return false; if (fromQueue) XRCCTRL(*this, "ID_DESCRIPTION", wxStaticText)->SetLabel(_("Select default file exists action only for the currently selected files in the queue.")); else XRCCTRL(*this, "ID_DESCRIPTION", wxStaticText)->SetLabel(_("Select default file exists action if the target file already exists. This selection is valid only for the current session.")); WrapRecursive(this, 1.8, "DEFAULTFILEEXISTS"); if (fromQueue) return true; SelectDefaults(&m_defaults[0], &m_defaults[1]); return true; }
bool CInputDialog::Create(wxWindow* parent, const wxString& title, wxString text) { m_allowEmpty = false; SetParent(parent); if (!Load(parent, _T("ID_INPUTDIALOG"))) { return false; } SetTitle(title); if (!XRCCTRL(*this, "wxID_OK", wxButton)) return false; if (!XRCCTRL(*this, "wxID_CANCEL", wxButton)) return false; m_pTextCtrl = XRCCTRL(*this, "ID_STRING", wxTextCtrl); if (!m_pTextCtrl) return false; if (!XRCCTRL(*this, "ID_STRING_PW", wxTextCtrl)) return false; wxStaticText* pText = XRCCTRL(*this, "ID_TEXT", wxStaticText); if (!pText) return false; WrapRecursive(this, 2.0); pText->SetLabel(text); GetSizer()->Fit(this); GetSizer()->SetSizeHints(this); XRCCTRL(*this, "ID_STRING", wxTextCtrl)->SetFocus(); XRCCTRL(*this, "wxID_OK", wxButton)->Enable(false); return true; }
bool CWrapEngine::WrapRecursive(wxWindow* wnd, double ratio, const char* name /*=""*/, wxSize canvas /*=wxSize()*/, wxSize minRequestedSize /*wxSize()*/) { std::vector<wxWindow*> windows; windows.push_back(wnd); return (WrapRecursive(windows, ratio, name, canvas, minRequestedSize) & wrap_failed) == 0; }
bool CWrapEngine::WrapRecursive(std::vector<wxWindow*>& windows, double ratio, const char* name /*=""*/, wxSize canvas /*=wxSize()*/, wxSize minRequestedSize /*wxSize()*/) { int maxWidth = GetWidthFromCache(name); if (maxWidth) { for (std::vector<wxWindow*>::iterator iter = windows.begin(); iter != windows.end(); ++iter) { wxSizer* pSizer = (*iter)->GetSizer(); if (!pSizer) continue; pSizer->Layout(); #ifdef __WXMAC__ const int offset = 6; #elif defined(__WXGTK__) const int offset = 0; #else const int offset = 0; #endif #ifdef __WXDEBUG__ int res = #endif WrapRecursive(*iter, pSizer, maxWidth - offset); wxASSERT(!(res & wrap_failed)); pSizer->Layout(); pSizer->Fit(*iter); #ifdef __WXDEBUG__ wxSize size = pSizer->GetMinSize(); #endif wxASSERT(size.x <= maxWidth); } return true; } std::vector<wxWindow*> all_windows = windows; wxSize size = minRequestedSize; for (std::vector<wxWindow*>::iterator iter = windows.begin(); iter != windows.end(); ++iter) { wxSizer* pSizer = (*iter)->GetSizer(); if (!pSizer) return false; pSizer->Layout(); size.IncTo(pSizer->GetMinSize()); } double currentRatio = ((double)(size.GetWidth() + canvas.x) / (size.GetHeight() + canvas.y)); if (ratio >= currentRatio) { // Nothing to do, can't wrap anything return true; } int max = size.GetWidth(); int min = wxMin(size.GetWidth(), size.GetHeight()); if (ratio < 0) min = (int)(min * ratio); if (min > canvas.x) min -= canvas.x; int desiredWidth = (min + max) / 2; int actualWidth = size.GetWidth(); double bestRatioDiff = currentRatio - ratio; int bestWidth = max; #if WRAPDEBUG > 0 printf("Target ratio: %f\n", (float)ratio); printf("Canvas: % 4d % 4d\n", canvas.x, canvas.y); printf("Initial min and max: %d %d\n", min, max); #endif for (;;) { std::list<int> didwrap; wxSize size = minRequestedSize; for (std::vector<wxWindow*>::iterator iter = windows.begin(); iter != windows.end(); ++iter) { wxSizer* pSizer = (*iter)->GetSizer(); #ifdef __WXMAC__ const int offset = 6; #elif defined(__WXGTK__) const int offset = 0; #else const int offset = 0; #endif int res = WrapRecursive(*iter, pSizer, desiredWidth - offset); if (res & wrap_didwrap) pSizer->Layout(); didwrap.push_back(res); wxSize minSize = pSizer->GetMinSize(); if (minSize.x > desiredWidth) res |= wrap_failed; size.IncTo(minSize); if (res & wrap_failed) break; } #if WRAPDEBUG > 0 printf("Current: % 4d % 4d desiredWidth: %d, min: %d, max: %d\n", size.GetWidth(), size.GetHeight(), desiredWidth, min, max); #endif if (size.GetWidth() > desiredWidth) { // Wrapping failed UnwrapRecursive_Wrapped(didwrap, windows, true); min = desiredWidth; if (max - min < 5) break; desiredWidth = (min + max) / 2; #if WRAPDEBUG > 0 printf("Wrapping failed, new min: %d\n", min); #endif continue; } actualWidth = size.GetWidth(); double newRatio = ((double)(size.GetWidth() + canvas.x) / (size.GetHeight() + canvas.y)); #if WRAPDEBUG > 0 printf("Ratio: %f\n", (float)newRatio); #endif if (newRatio < ratio) { UnwrapRecursive_Wrapped(didwrap, windows, true); if (ratio - newRatio < bestRatioDiff) { bestRatioDiff = ratio - newRatio; bestWidth = actualWidth; } if (min >= actualWidth) min = desiredWidth; else min = actualWidth; } else if (newRatio > ratio) { UnwrapRecursive_Wrapped(didwrap, windows); if (newRatio - ratio < bestRatioDiff) { bestRatioDiff = newRatio - ratio; bestWidth = actualWidth; } if (max == actualWidth) break; max = actualWidth; } else { UnwrapRecursive_Wrapped(didwrap, windows); bestRatioDiff = ratio - newRatio; bestWidth = actualWidth; break; } if (max - min < 2) break; desiredWidth = (min + max) / 2; currentRatio = newRatio; } #if WRAPDEBUG > 0 printf("Performing final wrap with bestwidth %d\n", bestWidth); #endif #ifdef __WXMAC__ const int offset = 6; #elif defined(__WXGTK__) const int offset = 0; #else const int offset = 0; #endif for (std::vector<wxWindow*>::iterator iter = all_windows.begin(); iter != all_windows.end(); ++iter) { wxSizer *pSizer = (*iter)->GetSizer(); int res = WrapRecursive(*iter, pSizer, bestWidth - offset); if (res & wrap_didwrap) { pSizer->Layout(); pSizer->Fit(*iter); } #ifdef __WXDEBUG__ size = pSizer->GetMinSize(); wxASSERT(size.x <= bestWidth); #endif } SetWidthToCache(name, bestWidth); return true; }
int CWrapEngine::WrapRecursive(wxWindow* wnd, wxSizer* sizer, int max) { // This function auto-wraps static texts. #if WRAPDEBUG >= 3 static int level = 1; plvl printf("Enter with max = %d\n", max); #endif if (max <= 0) { #if WRAPDEBUG >= 3 plvl printf("Leave: max <= 0\n"); #endif return wrap_failed; } int result = 0; for (unsigned int i = 0; i < sizer->GetChildren().GetCount(); i++) { wxSizerItem* item = sizer->GetItem(i); if (!item || !item->IsShown()) continue; int rborder = 0; if (item->GetFlag() & wxRIGHT) rborder = item->GetBorder(); int lborder = 0; if (item->GetFlag() & wxLEFT) lborder = item->GetBorder(); wxRect rect = item->GetRect(); wxSize min = item->GetMinSize(); if (!min.IsFullySpecified()) min = item->CalcMin(); wxASSERT(min.GetWidth() + rborder + lborder <= sizer->GetMinSize().GetWidth()); if (min.GetWidth() + item->GetPosition().x + lborder + rborder <= max) continue; wxWindow* window; wxSizer* subSizer = 0; if ((window = item->GetWindow())) { wxStaticText* text = wxDynamicCast(window, wxStaticText); if (text) { #ifdef __WXMAC__ const int offset = 3; #else const int offset = 2; #endif if (max - rect.GetLeft() - rborder - offset <= 0) continue; wxString str = text->GetLabel(); if (!WrapText(text, str, max - wxMax(0, rect.GetLeft()) - rborder - offset)) { #if WRAPDEBUG >= 3 plvl printf("Leave: WrapText failed\n"); #endif return result | wrap_failed; } text->SetLabel(str); result |= wrap_didwrap; continue; } wxNotebook* book = wxDynamicCast(window, wxNotebook); if (book) { int maxPageWidth = 0; for (unsigned int i = 0; i < book->GetPageCount(); i++) { wxNotebookPage* page = book->GetPage(i); maxPageWidth = wxMax(maxPageWidth, page->GetRect().GetWidth()); } for (unsigned int i = 0; i < book->GetPageCount(); i++) { wxNotebookPage* page = book->GetPage(i); wxRect pageRect = page->GetRect(); int pageMax = max - rect.GetLeft() - pageRect.GetLeft() - rborder - rect.GetWidth() + maxPageWidth; result |= WrapRecursive(wnd, page->GetSizer(), pageMax); if (result & wrap_failed) { #if WRAPDEBUG >= 3 plvl printf("Leave: WrapRecursive on notebook page failed\n"); #endif return result; } } continue; } if (wxDynamicCast(window, wxCheckBox) || wxDynamicCast(window, wxRadioButton) || wxDynamicCast(window, wxChoice)) { #if WRAPDEBUG >= 3 plvl printf("Leave: WrapRecursive on unshrinkable controls failed\n"); #endif result |= wrap_failed; return result; } // We assume here that all other oversized controls can scale } else if ((subSizer = item->GetSizer())) { int subBorder = 0; // Add border of static box sizer wxStaticBoxSizer* sboxSizer; if ((sboxSizer = wxDynamicCast(subSizer, wxStaticBoxSizer))) { int top, other; sboxSizer->GetStaticBox()->GetBordersForSizer(&top, &other); subBorder += other; } #if WRAPDEBUG >= 3 level++; #endif result |= WrapRecursive(0, subSizer, max - rborder - subBorder); #if WRAPDEBUG >= 3 level--; #endif if (result & wrap_failed) { #if WRAPDEBUG >= 3 plvl printf("Leave: WrapRecursive on sizer failed\n"); #endif return result; } } } #if WRAPDEBUG >= 3 plvl printf("Leave: Success\n"); #endif return result; }