summaryrefslogtreecommitdiff
path: root/wx+/popup_dlg.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'wx+/popup_dlg.cpp')
-rwxr-xr-xwx+/popup_dlg.cpp198
1 files changed, 101 insertions, 97 deletions
diff --git a/wx+/popup_dlg.cpp b/wx+/popup_dlg.cpp
index 5eeebf5e..19c721ad 100755
--- a/wx+/popup_dlg.cpp
+++ b/wx+/popup_dlg.cpp
@@ -72,12 +72,15 @@ void setBestInitialSize(wxTextCtrl& ctrl, const wxString& text, wxSize maxSize)
class zen::StandardPopupDialog : public PopupDialogGenerated
{
public:
- StandardPopupDialog(wxWindow* parent, DialogInfoType type, const PopupDialogCfg& cfg) :
+ 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& labelDecline) : //
PopupDialogGenerated(parent),
- checkBoxValue_(cfg.checkBoxValue)
+ checkBoxValue_(cfg.checkBoxValue),
+ buttonToDisableWhenChecked_(cfg.buttonToDisableWhenChecked)
{
-
wxBitmap iconTmp;
wxString titleTmp;
switch (type)
@@ -153,152 +156,153 @@ public:
m_checkBoxCustom->Hide();
Connect(wxEVT_CHAR_HOOK, wxKeyEventHandler(StandardPopupDialog::OnKeyPressed), nullptr, this); //dialog-specific local key events
- }
-
-private:
- void OnClose (wxCloseEvent& event) override { EndModal(static_cast<int>(ConfirmationButton3::CANCEL)); }
- void OnCancel(wxCommandEvent& event) override { EndModal(static_cast<int>(ConfirmationButton3::CANCEL)); }
- void OnKeyPressed(wxKeyEvent& event)
- {
- switch (event.GetKeyCode())
+ //------------------------------------------------------------------------------
+ StdButtons stdBtns;
+ stdBtns.setAffirmative(m_buttonAccept);
+ if (labelAccept.empty()) //notification dialog
{
- case WXK_RETURN:
- case WXK_NUMPAD_ENTER:
+ assert(labelAcceptAll.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_buttonDecline->Hide();
+ m_buttonCancel->Hide();
+ }
+ else
+ {
+ assert(contains(labelAccept, L"&"));
+ m_buttonAccept->SetLabel(labelAccept);
+ stdBtns.setCancel(m_buttonCancel);
+
+ if (labelDecline.empty()) //confirmation dialog(YES/CANCEL)
+ m_buttonDecline->Hide();
+ else //confirmation dialog(YES/NO/CANCEL)
{
- wxCommandEvent dummy(wxEVT_COMMAND_BUTTON_CLICKED);
- OnButtonAffirmative(dummy);
- return;
+ assert(contains(labelDecline, L"&"));
+ m_buttonDecline->SetLabel(labelDecline);
+ stdBtns.setNegative(m_buttonDecline);
+
+ //m_buttonConfirm->SetId(wxID_IGNORE); -> setting id after button creation breaks "mouse snap to" functionality
+ //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."
}
- case WXK_ESCAPE: //handle case where cancel button is hidden!
- EndModal(static_cast<int>(ConfirmationButton3::CANCEL));
- return;
+ if (labelAcceptAll.empty())
+ m_buttonAcceptAll->Hide();
+ else
+ {
+ assert(contains(labelAcceptAll, L"&"));
+ m_buttonAcceptAll->SetLabel(labelAcceptAll);
+ stdBtns.setAffirmativeAll(m_buttonAcceptAll);
+ }
}
- event.Skip();
+ updateGui();
+
+ //set std order after button visibility was set
+ setStandardButtonLayout(*bSizerStdButtons, stdBtns);
+
+ setAsStandard(*m_buttonAccept);
+ GetSizer()->SetSizeHints(this); //~=Fit() + SetMinSize()
+ Center(); //needs to be re-applied after a dialog size change!
}
- void OnButtonAffirmative(wxCommandEvent& event) override
+private:
+ void OnClose (wxCloseEvent& event) override { EndModal(static_cast<int>(ConfirmationButton3::CANCEL)); }
+ void OnCancel(wxCommandEvent& event) override { EndModal(static_cast<int>(ConfirmationButton3::CANCEL)); }
+
+ void OnButtonAccept(wxCommandEvent& event) override
{
if (checkBoxValue_)
*checkBoxValue_ = m_checkBoxCustom->GetValue();
- EndModal(static_cast<int>(ConfirmationButton3::DO_IT));
+ EndModal(static_cast<int>(ConfirmationButton3::ACCEPT));
}
- void OnButtonNegative(wxCommandEvent& event) override
+ void OnButtonAcceptAll(wxCommandEvent& event) override
{
if (checkBoxValue_)
*checkBoxValue_ = m_checkBoxCustom->GetValue();
- EndModal(static_cast<int>(ConfirmationButton3::DONT_DO_IT));
- }
-
- bool* checkBoxValue_;
-};
-
-
-namespace
-{
-class NotificationDialog : public StandardPopupDialog
-{
-public:
- NotificationDialog(wxWindow* parent, DialogInfoType type, const PopupDialogCfg& cfg) :
- StandardPopupDialog(parent, type, cfg)
- {
- m_buttonAffirmative->SetLabel(_("Close")); //UX Guide: use "Close" for errors, warnings and windows in which users can't make changes (no ampersand!)
- m_buttonNegative->Hide();
- m_buttonCancel->Hide();
-
- //set std order after button visibility was set
- setStandardButtonLayout(*bSizerStdButtons, StdButtons().setAffirmative(m_buttonAffirmative));
- setAsStandard(*m_buttonAffirmative);
- GetSizer()->SetSizeHints(this); //~=Fit() + SetMinSize()
- Center(); //needs to be re-applied after a dialog size change!
+ EndModal(static_cast<int>(ConfirmationButton3::ACCEPT_ALL));
}
-};
-
-class ConfirmationDialog : public StandardPopupDialog
-{
-public:
- ConfirmationDialog(wxWindow* parent, DialogInfoType type, const PopupDialogCfg& cfg, const wxString& labelDoIt) :
- StandardPopupDialog(parent, type, cfg)
+ void OnButtonDecline(wxCommandEvent& event) override
{
- assert(contains(labelDoIt, L"&"));
- m_buttonAffirmative->SetLabel(labelDoIt);
- m_buttonNegative->Hide();
-
- //set std order after button visibility was set
- setStandardButtonLayout(*bSizerStdButtons, StdButtons().setAffirmative(m_buttonAffirmative).setCancel(m_buttonCancel));
- setAsStandard(*m_buttonAffirmative);
- GetSizer()->SetSizeHints(this); //~=Fit() + SetMinSize()
- Center(); //needs to be re-applied after a dialog size change!
+ if (checkBoxValue_)
+ *checkBoxValue_ = m_checkBoxCustom->GetValue();
+ EndModal(static_cast<int>(ConfirmationButton3::DECLINE));
}
-};
-}
-class zen::ConfirmationDialog3 : public StandardPopupDialog
-{
-public:
- ConfirmationDialog3(wxWindow* parent, DialogInfoType type, const PopupDialogCfg3& cfg, const wxString& labelDoIt, const wxString& labelDontDoIt) :
- StandardPopupDialog(parent, type, cfg.pdCfg_),
- buttonToDisableWhenChecked_(cfg.buttonToDisableWhenChecked_)
+ void OnKeyPressed(wxKeyEvent& event)
{
- assert(contains(labelDoIt, L"&"));
- assert(contains(labelDontDoIt, L"&"));
- m_buttonAffirmative->SetLabel(labelDoIt);
- m_buttonNegative ->SetLabel(labelDontDoIt);
-
- //m_buttonAffirmative->SetId(wxID_IGNORE); -> setting id after button creation breaks "mouse snap to" functionality
- //m_buttonNegative ->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."
-
- updateGui();
+ switch (event.GetKeyCode())
+ {
+ case WXK_RETURN:
+ case WXK_NUMPAD_ENTER:
+ {
+ wxCommandEvent dummy(wxEVT_COMMAND_BUTTON_CLICKED);
+ OnButtonAccept(dummy);
+ return;
+ }
- //set std order after button visibility was set
- setStandardButtonLayout(*bSizerStdButtons, StdButtons().setAffirmative(m_buttonAffirmative).setNegative(m_buttonNegative).setCancel(m_buttonCancel));
- setAsStandard(*m_buttonAffirmative);
- GetSizer()->SetSizeHints(this); //~=Fit() + SetMinSize()
- Center(); //needs to be re-applied after a dialog size change!
+ case WXK_ESCAPE: //handle case where cancel button is hidden!
+ EndModal(static_cast<int>(ConfirmationButton3::CANCEL));
+ return;
+ }
+ event.Skip();
}
-private:
void OnCheckBoxClick(wxCommandEvent& event) override { updateGui(); event.Skip(); }
void updateGui()
{
switch (buttonToDisableWhenChecked_)
{
- case ConfirmationButton3::DO_IT:
- m_buttonAffirmative->Enable(!m_checkBoxCustom->GetValue());
+ case QuestionButton2::YES:
+ m_buttonAccept ->Enable(!m_checkBoxCustom->GetValue());
+ m_buttonAcceptAll->Enable(!m_checkBoxCustom->GetValue());
break;
- case ConfirmationButton3::DONT_DO_IT:
- m_buttonNegative->Enable(!m_checkBoxCustom->GetValue());
+ case QuestionButton2::NO:
+ m_buttonDecline->Enable(!m_checkBoxCustom->GetValue());
break;
- case ConfirmationButton3::CANCEL:
+ case QuestionButton2::CANCEL:
break;
}
}
- const ConfirmationButton3 buttonToDisableWhenChecked_;
+ bool* checkBoxValue_;
+ const QuestionButton2 buttonToDisableWhenChecked_;
};
//########################################################################################
void zen::showNotificationDialog(wxWindow* parent, DialogInfoType type, const PopupDialogCfg& cfg)
{
- NotificationDialog dlg(parent, type, cfg);
+ StandardPopupDialog dlg(parent, type, cfg, wxString() /*labelAccept*/, wxString() /*labelAcceptAll*/, wxString() /*labelDecline*/);
dlg.ShowModal();
}
-ConfirmationButton zen::showConfirmationDialog(wxWindow* parent, DialogInfoType type, const PopupDialogCfg& cfg, const wxString& labelDoIt)
+ConfirmationButton zen::showConfirmationDialog(wxWindow* parent, DialogInfoType type, const PopupDialogCfg& cfg, const wxString& labelAccept)
{
- ConfirmationDialog dlg(parent, type, cfg, labelDoIt);
+ StandardPopupDialog dlg(parent, type, cfg, labelAccept, wxString() /*labelAcceptAll*/, wxString() /*labelDecline*/);
return static_cast<ConfirmationButton>(dlg.ShowModal());
}
-ConfirmationButton3 zen::showConfirmationDialog3(wxWindow* parent, DialogInfoType type, const PopupDialogCfg3& cfg, const wxString& labelDoIt, const wxString& labelDontDoIt)
+ConfirmationButton2 zen::showConfirmationDialog(wxWindow* parent, DialogInfoType type, const PopupDialogCfg& cfg, const wxString& labelAccept, const wxString& labelAcceptAll)
{
- ConfirmationDialog3 dlg(parent, type, cfg, labelDoIt, labelDontDoIt);
+ StandardPopupDialog dlg(parent, type, cfg, labelAccept, labelAcceptAll, 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)
+{
+ StandardPopupDialog dlg(parent, type, cfg, labelAccept, labelAcceptAll, 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);
+ return static_cast<QuestionButton2>(dlg.ShowModal());
+}
bgstack15