diff options
Diffstat (limited to 'wx+')
-rw-r--r-- | wx+/focus.h | 11 | ||||
-rw-r--r-- | wx+/popup_dlg.cpp | 87 | ||||
-rw-r--r-- | wx+/popup_dlg.h | 33 | ||||
-rw-r--r-- | wx+/popup_dlg_generated.cpp | 6 | ||||
-rw-r--r-- | wx+/popup_dlg_generated.h | 4 | ||||
-rw-r--r-- | wx+/std_button_layout.h | 8 |
6 files changed, 79 insertions, 70 deletions
diff --git a/wx+/focus.h b/wx+/focus.h index 297d0754..2920828f 100644 --- a/wx+/focus.h +++ b/wx+/focus.h @@ -45,15 +45,14 @@ wxTopLevelWindow* getTopLevelWindow(wxWindow* child) } -/* -Preserving input focus has to be more clever than: - wxWindow* oldFocus = wxWindow::FindFocus(); - ZEN_ON_SCOPE_EXIT(if (oldFocus) oldFocus->SetFocus()); +/* Preserving input focus has to be more clever than: + wxWindow* oldFocus = wxWindow::FindFocus(); + ZEN_ON_SCOPE_EXIT(if (oldFocus) oldFocus->SetFocus()); => wxWindow::SetFocus() internally calls Win32 ::SetFocus, which calls ::SetActiveWindow, which - lord knows why - changes the foreground window to the focus window even if the user is currently busy using a different app! More curiosity: this foreground focus stealing happens only during the *first* SetFocus() after app start! - It also can be avoided by changing focus back and forth with some other app after start => wxWidgets bug or Win32 feature??? -*/ + It also can be avoided by changing focus back and forth with some other app after start => wxWidgets bug or Win32 feature??? */ + struct FocusPreserver { FocusPreserver() diff --git a/wx+/popup_dlg.cpp b/wx+/popup_dlg.cpp index ffde9824..ee682e19 100644 --- a/wx+/popup_dlg.cpp +++ b/wx+/popup_dlg.cpp @@ -21,7 +21,10 @@ namespace { void setBestInitialSize(wxTextCtrl& ctrl, const wxString& text, wxSize maxSize) { - const int scrollbarWidth = fastFromDIP(20); + const int scrollbarWidth = fastFromDIP(25); /*not only scrollbar, but also left/right padding (on macOS)! + better use slightly larger than exact value (Windows: 17, Linux(CentOS): 14, macOS: 25) + => worst case: minor increase in rowCount (no big deal) + slightly larger bestSize.x (good!) */ + if (maxSize.x <= scrollbarWidth) //implicitly checks for non-zero, too! return; maxSize.x -= scrollbarWidth; @@ -69,7 +72,7 @@ class zen::StandardPopupDialog : public PopupDialogGenerated public: StandardPopupDialog(wxWindow* parent, DialogInfoType type, const PopupDialogCfg& cfg, const wxString& labelAccept, // - const wxString& labelAcceptAll, //optional, except: if "decline" or "acceptAll" is passed, so must be "accept" + const wxString& labelAccept2, //optional, except: if "decline" or "accept2" is passed, so must be "accept" const wxString& labelDecline) : // PopupDialogGenerated(parent), checkBoxValue_(cfg.checkBoxValue), @@ -93,10 +96,10 @@ public: break; } } - catch (const TaskbarNotAvailable&) {} + catch (TaskbarNotAvailable&) {} - wxBitmap iconTmp; + wxImage iconTmp; wxString titleTmp; switch (type) { @@ -120,7 +123,8 @@ public: if (!cfg.title.empty()) titleTmp = cfg.title; //----------------------------------------------- - m_bitmapMsgType->SetBitmap(iconTmp); + if (iconTmp.IsOk()) + m_bitmapMsgType->SetBitmap(iconTmp); if (titleTmp.empty()) SetTitle(wxTheApp->GetAppDisplayName()); @@ -158,6 +162,7 @@ public: if (!cfg.textMain.empty()) text += L'\n'; text += trimCpy(cfg.textDetail) + L'\n'; //add empty top/bottom lines *instead* of using border space! + setBestInitialSize(*m_textCtrlTextDetail, text, wxSize(maxWidth, maxHeight)); m_textCtrlTextDetail->ChangeValue(text); } @@ -180,11 +185,11 @@ public: stdBtns.setAffirmative(m_buttonAccept); if (labelAccept.empty()) //notification dialog { - assert(labelAcceptAll.empty() && labelDecline.empty()); + assert(labelAccept2.empty() && labelDecline.empty()); m_buttonAccept->SetLabel(_("Close")); //UX Guide: use "Close" for errors, warnings and windows in which users can't make changes (no ampersand!) - m_buttonAcceptAll->Hide(); + m_buttonAccept2->Hide(); m_buttonDecline->Hide(); - m_buttonCancel->Hide(); + m_buttonCancel ->Hide(); } else { @@ -204,15 +209,22 @@ public: //m_buttonDecline->SetId(wxID_RETRY); -> also wxWidgets docs seem to hide some info: "Normally, the identifier should be provided on creation and should not be modified subsequently." } - if (labelAcceptAll.empty()) - m_buttonAcceptAll->Hide(); + if (labelAccept2.empty()) + m_buttonAccept2->Hide(); else { - assert(contains(labelAcceptAll, L"&")); - m_buttonAcceptAll->SetLabel(labelAcceptAll); - stdBtns.setAffirmativeAll(m_buttonAcceptAll); + assert(contains(labelAccept2, L"&")); + m_buttonAccept2->SetLabel(labelAccept2); + stdBtns.setAffirmativeAll(m_buttonAccept2); } } + + if (cfg.disabledButtons.contains(ConfirmationButton3::accept )) m_buttonAccept ->Disable(); + if (cfg.disabledButtons.contains(ConfirmationButton3::accept2)) m_buttonAccept2->Disable(); + if (cfg.disabledButtons.contains(ConfirmationButton3::decline)) m_buttonDecline->Disable(); + assert(!cfg.disabledButtons.contains(ConfirmationButton3::cancel)); + assert(!cfg.disabledButtons.contains(cfg.buttonToDisableWhenChecked)); + updateGui(); //set std order after button visibility was set @@ -221,7 +233,12 @@ public: GetSizer()->SetSizeHints(this); //~=Fit() + SetMinSize() Center(); //needs to be re-applied after a dialog size change! - m_buttonAccept->SetFocus(); + if (m_buttonAccept->IsEnabled()) + m_buttonAccept->SetFocus(); + else if (m_buttonAccept2->IsEnabled()) + m_buttonAccept2->SetFocus(); + else + m_buttonCancel->SetFocus(); } private: @@ -235,11 +252,11 @@ private: EndModal(static_cast<int>(ConfirmationButton3::accept)); } - void onButtonAcceptAll(wxCommandEvent& event) override + void onButtonAccept2(wxCommandEvent& event) override { if (checkBoxValue_) *checkBoxValue_ = m_checkBoxCustom->GetValue(); - EndModal(static_cast<int>(ConfirmationButton3::acceptAll)); + EndModal(static_cast<int>(ConfirmationButton3::accept2)); } void onButtonDecline(wxCommandEvent& event) override @@ -253,13 +270,6 @@ private: { switch (event.GetKeyCode()) { - case WXK_RETURN: - case WXK_NUMPAD_ENTER: - { - wxCommandEvent dummy(wxEVT_COMMAND_BUTTON_CLICKED); - onButtonAccept(dummy); - return; - } case WXK_ESCAPE: //handle case where cancel button is hidden! EndModal(static_cast<int>(ConfirmationButton3::cancel)); @@ -274,20 +284,17 @@ private: { switch (buttonToDisableWhenChecked_) { - case QuestionButton2::yes: - m_buttonAccept ->Enable(!m_checkBoxCustom->GetValue()); - m_buttonAcceptAll->Enable(!m_checkBoxCustom->GetValue()); - break; - case QuestionButton2::no: - m_buttonDecline->Enable(!m_checkBoxCustom->GetValue()); - break; - case QuestionButton2::cancel: - break; + //*INDENT-OFF* + case ConfirmationButton3::accept: m_buttonAccept ->Enable(!m_checkBoxCustom->GetValue()); break; + case ConfirmationButton3::accept2: m_buttonAccept2->Enable(!m_checkBoxCustom->GetValue()); break; + case ConfirmationButton3::decline: m_buttonDecline->Enable(!m_checkBoxCustom->GetValue()); break; + case ConfirmationButton3::cancel: break; + //*INDENT-ON* } } bool* checkBoxValue_; - const QuestionButton2 buttonToDisableWhenChecked_; + const ConfirmationButton3 buttonToDisableWhenChecked_; std::unique_ptr<Taskbar> taskbar_; }; @@ -295,34 +302,34 @@ private: void zen::showNotificationDialog(wxWindow* parent, DialogInfoType type, const PopupDialogCfg& cfg) { - StandardPopupDialog dlg(parent, type, cfg, wxString() /*labelAccept*/, wxString() /*labelAcceptAll*/, wxString() /*labelDecline*/); + StandardPopupDialog dlg(parent, type, cfg, wxString() /*labelAccept*/, wxString() /*labelAccept2*/, wxString() /*labelDecline*/); dlg.ShowModal(); } ConfirmationButton zen::showConfirmationDialog(wxWindow* parent, DialogInfoType type, const PopupDialogCfg& cfg, const wxString& labelAccept) { - StandardPopupDialog dlg(parent, type, cfg, labelAccept, wxString() /*labelAcceptAll*/, wxString() /*labelDecline*/); + StandardPopupDialog dlg(parent, type, cfg, labelAccept, wxString() /*labelAccept2*/, wxString() /*labelDecline*/); return static_cast<ConfirmationButton>(dlg.ShowModal()); } -ConfirmationButton2 zen::showConfirmationDialog(wxWindow* parent, DialogInfoType type, const PopupDialogCfg& cfg, const wxString& labelAccept, const wxString& labelAcceptAll) +ConfirmationButton2 zen::showConfirmationDialog(wxWindow* parent, DialogInfoType type, const PopupDialogCfg& cfg, const wxString& labelAccept, const wxString& labelAccept2) { - StandardPopupDialog dlg(parent, type, cfg, labelAccept, labelAcceptAll, wxString() /*labelDecline*/); + StandardPopupDialog dlg(parent, type, cfg, labelAccept, labelAccept2, wxString() /*labelDecline*/); return static_cast<ConfirmationButton2>(dlg.ShowModal()); } -ConfirmationButton3 zen::showConfirmationDialog(wxWindow* parent, DialogInfoType type, const PopupDialogCfg& cfg, const wxString& labelAccept, const wxString& labelAcceptAll, const wxString& labelDecline) +ConfirmationButton3 zen::showConfirmationDialog(wxWindow* parent, DialogInfoType type, const PopupDialogCfg& cfg, const wxString& labelAccept, const wxString& labelAccept2, const wxString& labelDecline) { - StandardPopupDialog dlg(parent, type, cfg, labelAccept, labelAcceptAll, labelDecline); + StandardPopupDialog dlg(parent, type, cfg, labelAccept, labelAccept2, labelDecline); return static_cast<ConfirmationButton3>(dlg.ShowModal()); } QuestionButton2 zen::showQuestionDialog(wxWindow* parent, DialogInfoType type, const PopupDialogCfg& cfg, const wxString& labelYes, const wxString& labelNo) { - StandardPopupDialog dlg(parent, type, cfg, labelYes, wxString() /*labelAcceptAll*/, labelNo); + StandardPopupDialog dlg(parent, type, cfg, labelYes, wxString() /*labelAccept2*/, labelNo); return static_cast<QuestionButton2>(dlg.ShowModal()); } diff --git a/wx+/popup_dlg.h b/wx+/popup_dlg.h index 1e0a1656..bb7ba51b 100644 --- a/wx+/popup_dlg.h +++ b/wx+/popup_dlg.h @@ -7,6 +7,7 @@ #ifndef POPUP_DLG_H_820780154723456 #define POPUP_DLG_H_820780154723456 +#include <set> #include <wx/window.h> #include <wx/bitmap.h> #include <wx/string.h> @@ -28,45 +29,46 @@ enum class DialogInfoType enum class ConfirmationButton3 { + cancel, accept, - acceptAll, + accept2, decline, - cancel, }; enum class ConfirmationButton { - accept = static_cast<int>(ConfirmationButton3::accept), //[!] Clang requires a "static_cast" - cancel = static_cast<int>(ConfirmationButton3::cancel), // + cancel = static_cast<int>(ConfirmationButton3::cancel), //[!] Clang requires "static_cast" + accept = static_cast<int>(ConfirmationButton3::accept), // }; enum class ConfirmationButton2 { - accept = static_cast<int>(ConfirmationButton3::accept), - acceptAll = static_cast<int>(ConfirmationButton3::acceptAll), - cancel = static_cast<int>(ConfirmationButton3::cancel), + cancel = static_cast<int>(ConfirmationButton3::cancel), + accept = static_cast<int>(ConfirmationButton3::accept), + accept2 = static_cast<int>(ConfirmationButton3::accept2), }; enum class QuestionButton2 { + cancel = static_cast<int>(ConfirmationButton3::cancel), yes = static_cast<int>(ConfirmationButton3::accept), no = static_cast<int>(ConfirmationButton3::decline), - cancel = static_cast<int>(ConfirmationButton3::cancel), }; void showNotificationDialog(wxWindow* parent, DialogInfoType type, const PopupDialogCfg& cfg); ConfirmationButton showConfirmationDialog(wxWindow* parent, DialogInfoType type, const PopupDialogCfg& cfg, const wxString& labelAccept); -ConfirmationButton2 showConfirmationDialog(wxWindow* parent, DialogInfoType type, const PopupDialogCfg& cfg, const wxString& labelAccept, const wxString& labelAcceptAll); -ConfirmationButton3 showConfirmationDialog(wxWindow* parent, DialogInfoType type, const PopupDialogCfg& cfg, const wxString& labelAccept, const wxString& labelAcceptAll, const wxString& labelDecline); -QuestionButton2 showQuestionDialog (wxWindow* parent, DialogInfoType type, const PopupDialogCfg& cfg, const wxString& labelYes, const wxString& labelNo); +ConfirmationButton2 showConfirmationDialog(wxWindow* parent, DialogInfoType type, const PopupDialogCfg& cfg, const wxString& labelAccept, const wxString& labelAccept2); +ConfirmationButton3 showConfirmationDialog(wxWindow* parent, DialogInfoType type, const PopupDialogCfg& cfg, const wxString& labelAccept, const wxString& labelAccept2, const wxString& labelDecline); +QuestionButton2 showQuestionDialog (wxWindow* parent, DialogInfoType type, const PopupDialogCfg& cfg, const wxString& labelYes, const wxString& labelNo); //---------------------------------------------------------------------------------------------------------------- class StandardPopupDialog; struct PopupDialogCfg { - PopupDialogCfg& setIcon (const wxBitmap& bmp ) { icon = bmp; return *this; } + PopupDialogCfg& setIcon (const wxImage& bmp ) { icon = bmp; return *this; } PopupDialogCfg& setTitle (const wxString& label) { title = label; return *this; } PopupDialogCfg& setMainInstructions (const wxString& label) { textMain = label; return *this; } //set at least one of these! PopupDialogCfg& setDetailInstructions(const wxString& label) { textDetail = label; return *this; } // - PopupDialogCfg& setCheckBox(bool& value, const wxString& label, QuestionButton2 disableWhenChecked = QuestionButton2::cancel) + PopupDialogCfg& disableButton(ConfirmationButton3 button) { disabledButtons.insert(button); return *this; } + PopupDialogCfg& setCheckBox(bool& value, const wxString& label, ConfirmationButton3 disableWhenChecked = ConfirmationButton3::cancel) { checkBoxValue = &value; checkBoxLabel = label; @@ -77,13 +79,14 @@ struct PopupDialogCfg private: friend class StandardPopupDialog; - wxBitmap icon; + wxImage icon; wxString title; wxString textMain; wxString textDetail; + std::set<ConfirmationButton3> disabledButtons; bool* checkBoxValue = nullptr; //in/out wxString checkBoxLabel; - QuestionButton2 buttonToDisableWhenChecked = QuestionButton2::cancel; + ConfirmationButton3 buttonToDisableWhenChecked = ConfirmationButton3::cancel; }; } diff --git a/wx+/popup_dlg_generated.cpp b/wx+/popup_dlg_generated.cpp index b9da4c38..8933b135 100644 --- a/wx+/popup_dlg_generated.cpp +++ b/wx+/popup_dlg_generated.cpp @@ -67,8 +67,8 @@ PopupDialogGenerated::PopupDialogGenerated( wxWindow* parent, wxWindowID id, con m_buttonAccept->SetDefault(); bSizerStdButtons->Add( m_buttonAccept, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); - m_buttonAcceptAll = new wxButton( this, wxID_YESTOALL, _("dummy"), wxDefaultPosition, wxSize( -1, -1 ), 0 ); - bSizerStdButtons->Add( m_buttonAcceptAll, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT, 5 ); + m_buttonAccept2 = new wxButton( this, wxID_YESTOALL, _("dummy"), wxDefaultPosition, wxSize( -1, -1 ), 0 ); + bSizerStdButtons->Add( m_buttonAccept2, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT, 5 ); m_buttonDecline = new wxButton( this, wxID_NO, _("dummy"), wxDefaultPosition, wxSize( -1, -1 ), 0 ); bSizerStdButtons->Add( m_buttonDecline, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT, 5 ); @@ -93,7 +93,7 @@ PopupDialogGenerated::PopupDialogGenerated( wxWindow* parent, wxWindowID id, con this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( PopupDialogGenerated::onClose ) ); m_checkBoxCustom->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( PopupDialogGenerated::onCheckBoxClick ), NULL, this ); m_buttonAccept->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PopupDialogGenerated::onButtonAccept ), NULL, this ); - m_buttonAcceptAll->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PopupDialogGenerated::onButtonAcceptAll ), NULL, this ); + m_buttonAccept2->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PopupDialogGenerated::onButtonAccept2 ), NULL, this ); m_buttonDecline->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PopupDialogGenerated::onButtonDecline ), NULL, this ); m_buttonCancel->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PopupDialogGenerated::onCancel ), NULL, this ); } diff --git a/wx+/popup_dlg_generated.h b/wx+/popup_dlg_generated.h index 52bd593c..87474708 100644 --- a/wx+/popup_dlg_generated.h +++ b/wx+/popup_dlg_generated.h @@ -49,7 +49,7 @@ protected: wxCheckBox* m_checkBoxCustom; wxBoxSizer* bSizerStdButtons; wxButton* m_buttonAccept; - wxButton* m_buttonAcceptAll; + wxButton* m_buttonAccept2; wxButton* m_buttonDecline; wxButton* m_buttonCancel; @@ -57,7 +57,7 @@ protected: virtual void onClose( wxCloseEvent& event ) { event.Skip(); } virtual void onCheckBoxClick( wxCommandEvent& event ) { event.Skip(); } virtual void onButtonAccept( wxCommandEvent& event ) { event.Skip(); } - virtual void onButtonAcceptAll( wxCommandEvent& event ) { event.Skip(); } + virtual void onButtonAccept2( wxCommandEvent& event ) { event.Skip(); } virtual void onButtonDecline( wxCommandEvent& event ) { event.Skip(); } virtual void onCancel( wxCommandEvent& event ) { event.Skip(); } diff --git a/wx+/std_button_layout.h b/wx+/std_button_layout.h index d2c5fc32..25745132 100644 --- a/wx+/std_button_layout.h +++ b/wx+/std_button_layout.h @@ -18,12 +18,12 @@ namespace zen struct StdButtons { StdButtons& setAffirmative (wxButton* btn) { btnYes = btn; return *this; } - StdButtons& setAffirmativeAll(wxButton* btn) { btnYesAll = btn; return *this; } + StdButtons& setAffirmativeAll(wxButton* btn) { btnYes2 = btn; return *this; } StdButtons& setNegative (wxButton* btn) { btnNo = btn; return *this; } StdButtons& setCancel (wxButton* btn) { btnCancel = btn; return *this; } wxButton* btnYes = nullptr; - wxButton* btnYesAll = nullptr; + wxButton* btnYes2 = nullptr; wxButton* btnNo = nullptr; wxButton* btnCancel = nullptr; }; @@ -67,7 +67,7 @@ void setStandardButtonLayout(wxBoxSizer& sizer, const StdButtons& buttons) }; detach(buttonsTmp.btnYes); - detach(buttonsTmp.btnYesAll); + detach(buttonsTmp.btnYes2); detach(buttonsTmp.btnNo); detach(buttonsTmp.btnCancel); @@ -110,7 +110,7 @@ void setStandardButtonLayout(wxBoxSizer& sizer, const StdButtons& buttons) sizer.Add(spaceRimH, 0); attach(buttonsTmp.btnNo); attach(buttonsTmp.btnCancel); - attach(buttonsTmp.btnYesAll); + attach(buttonsTmp.btnYes2); attach(buttonsTmp.btnYes); sizer.Add(spaceRimH, 0); |