d59729f396
fixed it by looking for funny things that deviated from the sameples, and doing various recommended safe things, and found a few sql errors, and one by one the crashes went away. The new wxWidgets just seems less tolerant of little careless stuff that is not right.
894 lines
25 KiB
C++
894 lines
25 KiB
C++
/////////////////////////////////////////////////////////////////////////////
|
|
// Name: dialogs.cpp
|
|
// Purpose: updating to make it more relevant to my code
|
|
// and more similar to my code.
|
|
//
|
|
// Leaving most of useless to me examples in place
|
|
// unless I am completely sure they are will never
|
|
// be useful.
|
|
//
|
|
// Some of the stuff here does not quite work
|
|
// Only half implemented.
|
|
//
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
#include "stdafx.h"
|
|
|
|
#if USE_MODAL_PRESENTATION
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// MyModelessDialog
|
|
// ----------------------------------------------------------------------------
|
|
|
|
MyModelessDialog::MyModelessDialog(wxWindow *parent)
|
|
: wxDialog(parent, wxID_ANY, wxString("Modeless dialog"))
|
|
{
|
|
wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
|
|
|
|
wxButton *btn = new wxButton(this, DIALOGS_MODELESS_BTN, "Press me");
|
|
wxCheckBox *check = new wxCheckBox(this, wxID_ANY, "Should be disabled");
|
|
check->Disable();
|
|
|
|
sizerTop->Add(btn, 1, wxEXPAND | wxALL, 5);
|
|
sizerTop->Add(check, 1, wxEXPAND | wxALL, 5);
|
|
|
|
SetSizerAndFit(sizerTop);
|
|
}
|
|
|
|
void MyModelessDialog::OnButton(wxCommandEvent& WXUNUSED(event))
|
|
{
|
|
wxMessageBox("Button pressed in modeless dialog", "Info",
|
|
wxOK | wxICON_INFORMATION, this);
|
|
}
|
|
|
|
void MyModelessDialog::OnClose(wxCloseEvent& event)
|
|
{
|
|
if ( event.CanVeto() )
|
|
{
|
|
wxMessageBox("Use the menu item to close this dialog",
|
|
"Modeless dialog",
|
|
wxOK | wxICON_INFORMATION, this);
|
|
|
|
event.Veto();
|
|
}
|
|
}
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// MyModalDialog
|
|
// ----------------------------------------------------------------------------
|
|
|
|
MyModalDialog::MyModalDialog(wxWindow *parent)
|
|
: wxDialog(parent, wxID_ANY, wxString("Modal dialog"))
|
|
{
|
|
wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
m_btnModal = new wxButton(this, wxID_ANY, "&Modal dialog...");
|
|
m_btnModeless = new wxButton(this, wxID_ANY, "Mode&less dialog");
|
|
m_btnDelete = new wxButton(this, wxID_ANY, "&Delete button");
|
|
|
|
sizerTop->Add(m_btnModal, 0, wxALIGN_CENTER | wxALL, 5);
|
|
sizerTop->Add(m_btnModeless, 0, wxALIGN_CENTER | wxALL, 5);
|
|
sizerTop->Add(m_btnDelete, 0, wxALIGN_CENTER | wxALL, 5);
|
|
sizerTop->Add(new wxButton(this, wxID_CLOSE), 0, wxALIGN_CENTER | wxALL, 5);
|
|
|
|
SetSizerAndFit(sizerTop);
|
|
|
|
SetEscapeId(wxID_CLOSE);
|
|
|
|
m_btnModal->SetFocus();
|
|
m_btnModal->SetDefault();
|
|
}
|
|
|
|
void MyModalDialog::OnButton(wxCommandEvent& event)
|
|
{
|
|
if ( event.GetEventObject() == m_btnDelete )
|
|
{
|
|
wxDELETE(m_btnModal);
|
|
m_btnDelete->Disable();
|
|
}
|
|
else if ( event.GetEventObject() == m_btnModal )
|
|
{
|
|
#if wxUSE_TEXTDLG
|
|
wxGetTextFromUser("Dummy prompt",
|
|
"Modal dialog called from dialog",
|
|
wxEmptyString, this);
|
|
#else
|
|
wxMessageBox("Modal dialog called from dialog");
|
|
#endif // wxUSE_TEXTDLG
|
|
}
|
|
else if ( event.GetEventObject() == m_btnModeless )
|
|
{
|
|
(new MyModelessDialog(this))->Show();
|
|
}
|
|
else
|
|
{
|
|
event.Skip();
|
|
}
|
|
}
|
|
|
|
#endif // USE_MODAL_PRESENTATION
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// StdButtonSizerDialog
|
|
// ----------------------------------------------------------------------------
|
|
|
|
StdButtonSizerDialog::StdButtonSizerDialog(wxWindow *parent)
|
|
: wxDialog(parent, wxID_ANY, wxString("StdButtonSizer dialog"),
|
|
wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER),
|
|
m_buttonsSizer(NULL)
|
|
{
|
|
wxBoxSizer *const sizerTop = new wxBoxSizer(wxVERTICAL);
|
|
|
|
wxBoxSizer *const sizer = new wxBoxSizer(wxHORIZONTAL);
|
|
wxBoxSizer *const sizerInside1 = new wxBoxSizer(wxVERTICAL);
|
|
|
|
m_chkboxAffirmativeButton = new wxCheckBox(this, wxID_ANY, "Enable Affirmative Button");
|
|
|
|
wxStaticBoxSizer *const sizer1 = new wxStaticBoxSizer(wxVERTICAL, this, "Affirmative Button");
|
|
|
|
m_radiobtnOk = new wxRadioButton(this, wxID_ANY, "Ok", wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
|
|
m_radiobtnYes = new wxRadioButton(this, wxID_ANY, "Yes");
|
|
|
|
wxBoxSizer *const sizerInside2 = new wxBoxSizer(wxVERTICAL);
|
|
|
|
m_chkboxDismissButton = new wxCheckBox(this, wxID_ANY, "Enable Dismiss Button");
|
|
|
|
wxStaticBoxSizer *const sizer2 = new wxStaticBoxSizer(wxVERTICAL, this, "Dismiss Button");
|
|
|
|
m_radiobtnCancel = new wxRadioButton(this, wxID_ANY, "Cancel", wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
|
|
m_radiobtnClose = new wxRadioButton(this, wxID_ANY, "Close");
|
|
|
|
wxBoxSizer *const sizer3 = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
m_chkboxNo = new wxCheckBox(this, wxID_ANY, "No");
|
|
m_chkboxHelp = new wxCheckBox(this, wxID_ANY, "Help");
|
|
m_chkboxApply = new wxCheckBox(this, wxID_ANY, "Apply");
|
|
|
|
m_chkboxNoDefault = new wxCheckBox(this, wxID_ANY, "No Default");
|
|
|
|
sizer1->Add(m_radiobtnOk, 0, wxALL, 5);
|
|
sizer1->Add(m_radiobtnYes, 0, wxALL, 5);
|
|
|
|
sizer->Add(sizerInside1, 0, 0, 0);
|
|
sizerInside1->Add(m_chkboxAffirmativeButton, 0, wxALL, 5);
|
|
sizerInside1->Add(sizer1, 0, wxALL, 5);
|
|
sizerInside1->SetItemMinSize(sizer1, sizer1->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
|
|
|
|
sizer2->Add(m_radiobtnCancel, 0, wxALL, 5);
|
|
sizer2->Add(m_radiobtnClose, 0, wxALL, 5);
|
|
|
|
sizer->Add(sizerInside2, 0, 0, 0);
|
|
sizerInside2->Add(m_chkboxDismissButton, 0, wxALL, 5);
|
|
sizerInside2->Add(sizer2, 0, wxALL, 5);
|
|
sizerInside2->SetItemMinSize(sizer2, sizer2->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
|
|
|
|
sizerTop->Add(sizer, 0, wxALL, 5);
|
|
|
|
sizer3->Add(m_chkboxNo, 0, wxALL, 5);
|
|
sizer3->Add(m_chkboxHelp, 0, wxALL, 5);
|
|
sizer3->Add(m_chkboxApply, 0, wxALL, 5);
|
|
|
|
sizerTop->Add(sizer3, 0, wxALL, 5);
|
|
|
|
sizerTop->Add(m_chkboxNoDefault, 0, wxLEFT|wxRIGHT, 10);
|
|
|
|
EnableDisableControls();
|
|
|
|
SetSizerAndFit(sizerTop);
|
|
|
|
wxCommandEvent ev;
|
|
OnEvent(ev);
|
|
}
|
|
|
|
void StdButtonSizerDialog::OnEvent(wxCommandEvent& WXUNUSED(event))
|
|
{
|
|
if (m_buttonsSizer)
|
|
{
|
|
m_buttonsSizer->DeleteWindows();
|
|
GetSizer()->Remove(m_buttonsSizer);
|
|
}
|
|
|
|
EnableDisableControls();
|
|
|
|
long flags = 0;
|
|
unsigned long numButtons = 0;
|
|
|
|
if (m_chkboxAffirmativeButton->IsChecked())
|
|
{
|
|
if (m_radiobtnOk->GetValue())
|
|
{
|
|
flags |= wxOK;
|
|
numButtons ++;
|
|
}
|
|
else if (m_radiobtnYes->GetValue())
|
|
{
|
|
flags |= wxYES;
|
|
numButtons ++;
|
|
}
|
|
}
|
|
|
|
if (m_chkboxDismissButton->IsChecked())
|
|
{
|
|
if (m_radiobtnCancel->GetValue())
|
|
{
|
|
flags |= wxCANCEL;
|
|
numButtons ++;
|
|
}
|
|
|
|
else if (m_radiobtnClose->GetValue())
|
|
{
|
|
flags |= wxCLOSE;
|
|
numButtons ++;
|
|
}
|
|
|
|
}
|
|
|
|
if (m_chkboxApply->IsChecked())
|
|
{
|
|
flags |= wxAPPLY;
|
|
numButtons ++;
|
|
}
|
|
|
|
if (m_chkboxNo->IsChecked())
|
|
{
|
|
flags |= wxNO;
|
|
numButtons ++;
|
|
}
|
|
|
|
if (m_chkboxHelp->IsChecked())
|
|
{
|
|
flags |= wxHELP;
|
|
numButtons ++;
|
|
}
|
|
|
|
if (m_chkboxNoDefault->IsChecked())
|
|
{
|
|
flags |= wxNO_DEFAULT;
|
|
}
|
|
|
|
m_buttonsSizer = CreateStdDialogButtonSizer(flags);
|
|
GetSizer()->Add(m_buttonsSizer, 0, wxGROW|wxALL, 5);
|
|
|
|
Layout();
|
|
GetSizer()->SetSizeHints(this);
|
|
}
|
|
|
|
void StdButtonSizerDialog::EnableDisableControls()
|
|
{
|
|
const bool affButtonEnabled = m_chkboxAffirmativeButton->IsChecked();
|
|
|
|
m_radiobtnOk->Enable(affButtonEnabled);
|
|
m_radiobtnYes->Enable(affButtonEnabled);
|
|
|
|
const bool dismissButtonEnabled = m_chkboxDismissButton->IsChecked();
|
|
|
|
m_radiobtnCancel->Enable(dismissButtonEnabled);
|
|
m_radiobtnClose->Enable(dismissButtonEnabled);
|
|
}
|
|
|
|
#if USE_SETTINGS_DIALOG
|
|
// ----------------------------------------------------------------------------
|
|
// SettingsDialog
|
|
// ----------------------------------------------------------------------------
|
|
|
|
wxIMPLEMENT_CLASS(SettingsDialog, wxPropertySheetDialog);
|
|
|
|
wxBEGIN_EVENT_TABLE(SettingsDialog, wxPropertySheetDialog)
|
|
wxEND_EVENT_TABLE()
|
|
|
|
SettingsDialog::SettingsDialog(wxWindow* win, SettingsData& settingsData, int dialogType)
|
|
: m_settingsData(settingsData)
|
|
{
|
|
SetExtraStyle(wxDIALOG_EX_CONTEXTHELP);
|
|
|
|
int tabImage1 = -1;
|
|
int tabImage2 = -1;
|
|
|
|
bool useToolBook = (dialogType == DIALOGS_PROPERTY_SHEET_TOOLBOOK || dialogType == DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK);
|
|
int resizeBorder = wxRESIZE_BORDER;
|
|
|
|
if (useToolBook)
|
|
{
|
|
resizeBorder = 0;
|
|
tabImage1 = 0;
|
|
tabImage2 = 1;
|
|
|
|
int sheetStyle = wxPROPSHEET_SHRINKTOFIT;
|
|
if (dialogType == DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK)
|
|
sheetStyle |= wxPROPSHEET_BUTTONTOOLBOOK;
|
|
else
|
|
sheetStyle |= wxPROPSHEET_TOOLBOOK;
|
|
|
|
SetSheetStyle(sheetStyle);
|
|
SetSheetInnerBorder(0);
|
|
SetSheetOuterBorder(0);
|
|
|
|
// create a dummy image list with a few icons
|
|
const wxSize imageSize(32, 32);
|
|
|
|
m_imageList = new wxImageList(imageSize.GetWidth(), imageSize.GetHeight());
|
|
m_imageList->
|
|
Add(wxArtProvider::GetIcon(wxART_INFORMATION, wxART_OTHER, imageSize));
|
|
m_imageList->
|
|
Add(wxArtProvider::GetIcon(wxART_QUESTION, wxART_OTHER, imageSize));
|
|
m_imageList->
|
|
Add(wxArtProvider::GetIcon(wxART_WARNING, wxART_OTHER, imageSize));
|
|
m_imageList->
|
|
Add(wxArtProvider::GetIcon(wxART_ERROR, wxART_OTHER, imageSize));
|
|
}
|
|
else
|
|
m_imageList = NULL;
|
|
|
|
Create(win, wxID_ANY, "Preferences", wxDefaultPosition, wxDefaultSize,
|
|
wxDEFAULT_DIALOG_STYLE | resizeBorder);
|
|
|
|
// If using a toolbook, also follow Mac style and don't create buttons
|
|
if (!useToolBook)
|
|
CreateButtons(wxOK | wxCANCEL | wxHELP);
|
|
|
|
wxBookCtrlBase* notebook = GetBookCtrl();
|
|
notebook->SetImageList(m_imageList);
|
|
|
|
wxPanel* generalSettings = CreateGeneralSettingsPage(notebook);
|
|
wxPanel* aestheticSettings = CreateAestheticSettingsPage(notebook);
|
|
|
|
notebook->AddPage(generalSettings, "General", true, tabImage1);
|
|
notebook->AddPage(aestheticSettings, "Aesthetics", false, tabImage2);
|
|
|
|
LayoutDialog();
|
|
}
|
|
|
|
SettingsDialog::~SettingsDialog()
|
|
{
|
|
delete m_imageList;
|
|
}
|
|
|
|
wxPanel* SettingsDialog::CreateGeneralSettingsPage(wxWindow* parent)
|
|
{
|
|
wxPanel* panel = new wxPanel(parent, wxID_ANY);
|
|
|
|
wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
|
|
wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
|
|
|
|
//// LOAD LAST FILE
|
|
|
|
wxBoxSizer* itemSizer3 = new wxBoxSizer( wxHORIZONTAL );
|
|
wxCheckBox* checkBox3 = new wxCheckBox(panel, ID_LOAD_LAST_PROJECT, "&Load last project on startup", wxDefaultPosition, wxDefaultSize);
|
|
checkBox3->SetValidator(wxGenericValidator(&m_settingsData.m_loadLastOnStartup));
|
|
itemSizer3->Add(checkBox3, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
|
|
item0->Add(itemSizer3, 0, wxGROW|wxALL, 0);
|
|
|
|
//// AUTOSAVE
|
|
|
|
wxString autoSaveLabel = "&Auto-save every";
|
|
wxString minsLabel = "mins";
|
|
|
|
wxBoxSizer* itemSizer12 = new wxBoxSizer( wxHORIZONTAL );
|
|
wxCheckBox* checkBox12 = new wxCheckBox(panel, ID_AUTO_SAVE, autoSaveLabel, wxDefaultPosition, wxDefaultSize);
|
|
|
|
#if wxUSE_SPINCTRL
|
|
wxSpinCtrl* spinCtrl12 = new wxSpinCtrl(panel, ID_AUTO_SAVE_MINS, wxEmptyString,
|
|
wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 60, 1);
|
|
spinCtrl12->SetValidator(wxGenericValidator(&m_settingsData.m_autoSaveInterval));
|
|
#endif
|
|
|
|
itemSizer12->Add(checkBox12, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
|
|
#if wxUSE_SPINCTRL
|
|
itemSizer12->Add(spinCtrl12, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
|
|
#endif
|
|
itemSizer12->Add(new wxStaticText(panel, wxID_STATIC, minsLabel), 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
|
|
item0->Add(itemSizer12, 0, wxGROW|wxALL, 0);
|
|
|
|
//// TOOLTIPS
|
|
|
|
wxBoxSizer* itemSizer8 = new wxBoxSizer( wxHORIZONTAL );
|
|
wxCheckBox* checkBox6 = new wxCheckBox(panel, ID_SHOW_TOOLTIPS, "Show &tooltips", wxDefaultPosition, wxDefaultSize);
|
|
checkBox6->SetValidator(wxGenericValidator(&m_settingsData.m_showToolTips));
|
|
itemSizer8->Add(checkBox6, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
|
|
item0->Add(itemSizer8, 0, wxGROW|wxALL, 0);
|
|
|
|
topSizer->Add( item0, wxSizerFlags(1).Expand().Border(wxALL, 5) );
|
|
|
|
panel->SetSizerAndFit(topSizer);
|
|
|
|
return panel;
|
|
}
|
|
|
|
wxPanel* SettingsDialog::CreateAestheticSettingsPage(wxWindow* parent)
|
|
{
|
|
wxPanel* panel = new wxPanel(parent, wxID_ANY);
|
|
|
|
wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
|
|
wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
|
|
|
|
//// PROJECT OR GLOBAL
|
|
wxString globalOrProjectChoices[2];
|
|
globalOrProjectChoices[0] = "&New projects";
|
|
globalOrProjectChoices[1] = "&This project";
|
|
|
|
wxRadioBox* projectOrGlobal = new wxRadioBox(panel, ID_APPLY_SETTINGS_TO, "&Apply settings to:",
|
|
wxDefaultPosition, wxDefaultSize, 2, globalOrProjectChoices);
|
|
projectOrGlobal->SetValidator(wxGenericValidator(&m_settingsData.m_applyTo));
|
|
item0->Add(projectOrGlobal, 0, wxGROW|wxALL, 5);
|
|
|
|
projectOrGlobal->SetSelection(0);
|
|
|
|
//// BACKGROUND STYLE
|
|
wxArrayString backgroundStyleChoices;
|
|
backgroundStyleChoices.Add("Colour");
|
|
backgroundStyleChoices.Add("Image");
|
|
wxStaticBox* staticBox3 = new wxStaticBox(panel, wxID_ANY, "Background style:");
|
|
|
|
wxBoxSizer* styleSizer = new wxStaticBoxSizer( staticBox3, wxVERTICAL );
|
|
item0->Add(styleSizer, 0, wxGROW|wxALL, 5);
|
|
|
|
wxBoxSizer* itemSizer2 = new wxBoxSizer( wxHORIZONTAL );
|
|
|
|
wxChoice* choice2 = new wxChoice(panel, ID_BACKGROUND_STYLE, wxDefaultPosition, wxDefaultSize, backgroundStyleChoices);
|
|
choice2->SetValidator(wxGenericValidator(&m_settingsData.m_bgStyle));
|
|
|
|
itemSizer2->Add(new wxStaticText(panel, wxID_ANY, "&Window:"), 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
|
|
itemSizer2->Add(5, 5, 1, wxALL, 0);
|
|
itemSizer2->Add(choice2, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
|
|
|
|
styleSizer->Add(itemSizer2, 0, wxGROW|wxALL, 5);
|
|
|
|
#if wxUSE_SPINCTRL
|
|
//// FONT SIZE SELECTION
|
|
|
|
wxStaticBox* staticBox1 = new wxStaticBox(panel, wxID_ANY, "Tile font size:");
|
|
wxBoxSizer* itemSizer5 = new wxStaticBoxSizer( staticBox1, wxHORIZONTAL );
|
|
|
|
wxSpinCtrl* spinCtrl = new wxSpinCtrl(panel, ID_FONT_SIZE, wxEmptyString);
|
|
spinCtrl->SetValidator(wxGenericValidator(&m_settingsData.m_titleFontSize));
|
|
itemSizer5->Add(spinCtrl, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
|
|
|
|
item0->Add(itemSizer5, 0, wxGROW|wxLEFT|wxRIGHT, 5);
|
|
#endif
|
|
|
|
topSizer->Add( item0, wxSizerFlags(1).Expand().Border(wxALL, 5) );
|
|
topSizer->AddSpacer(5);
|
|
|
|
panel->SetSizerAndFit(topSizer);
|
|
|
|
return panel;
|
|
}
|
|
|
|
#endif // USE_SETTINGS_DIALOG
|
|
|
|
#if wxUSE_MSGDLG
|
|
// ----------------------------------------------------------------------------
|
|
// TestMessageBoxDialog
|
|
// ----------------------------------------------------------------------------
|
|
|
|
/* static */
|
|
const TestMessageBoxDialog::BtnInfo TestMessageBoxDialog::ms_btnInfo[] =
|
|
{
|
|
{ wxYES, "&Yes" },
|
|
{ wxNO, "&No" },
|
|
{ wxOK, "&Ok" },
|
|
{ wxCANCEL, "&Cancel" },
|
|
{ wxHELP, "&Help" },
|
|
};
|
|
|
|
wxBEGIN_EVENT_TABLE(TestMessageBoxDialog, wxDialog)
|
|
EVT_BUTTON(wxID_APPLY, TestMessageBoxDialog::OnApply)
|
|
EVT_BUTTON(wxID_CLOSE, TestMessageBoxDialog::OnClose)
|
|
wxEND_EVENT_TABLE()
|
|
|
|
TestMessageBoxDialog::TestMessageBoxDialog(wxWindow *parent)
|
|
: wxDialog(parent, wxID_ANY, "Message Box Test Dialog",
|
|
wxDefaultPosition, wxDefaultSize,
|
|
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
|
|
{
|
|
}
|
|
|
|
bool TestMessageBoxDialog::Create()
|
|
{
|
|
wxSizer * const sizerTop = new wxBoxSizer(wxVERTICAL);
|
|
|
|
// this sizer allows to configure the messages shown in the message box
|
|
wxSizer * const
|
|
sizerMsgs = new wxStaticBoxSizer(wxVERTICAL, this, "&Messages");
|
|
sizerMsgs->Add(new wxStaticText(this, wxID_ANY, "&Title:"));
|
|
m_textTitle = new wxTextCtrl(this, wxID_ANY, "Test Message Box");
|
|
sizerMsgs->Add(m_textTitle, wxSizerFlags().Expand().Border(wxBOTTOM));
|
|
|
|
sizerMsgs->Add(new wxStaticText(this, wxID_ANY, "&Main message:"));
|
|
m_textMsg = new wxTextCtrl(this, wxID_ANY, "Hello from a box!",
|
|
wxDefaultPosition, wxDefaultSize,
|
|
wxTE_MULTILINE);
|
|
sizerMsgs->Add(m_textMsg, wxSizerFlags(1).Expand().Border(wxBOTTOM));
|
|
|
|
sizerMsgs->Add(new wxStaticText(this, wxID_ANY, "&Extended message:"));
|
|
m_textExtMsg = new wxTextCtrl(this, wxID_ANY, "",
|
|
wxDefaultPosition, wxDefaultSize,
|
|
wxTE_MULTILINE);
|
|
sizerMsgs->Add(m_textExtMsg, wxSizerFlags().Expand());
|
|
|
|
sizerTop->Add(sizerMsgs, wxSizerFlags(1).Expand().Border());
|
|
|
|
// if a derived class provides more message configurations, add these.
|
|
AddAdditionalTextOptions(sizerTop);
|
|
|
|
// this one is for configuring the buttons
|
|
wxSizer * const
|
|
sizerBtnsBox = new wxStaticBoxSizer(wxVERTICAL, this, "&Buttons");
|
|
|
|
wxFlexGridSizer * const sizerBtns = new wxFlexGridSizer(2, 5, 5);
|
|
sizerBtns->AddGrowableCol(1);
|
|
|
|
sizerBtns->Add(new wxStaticText(this, wxID_ANY, "Button(s)"));
|
|
sizerBtns->Add(new wxStaticText(this, wxID_ANY, "Custom label"));
|
|
|
|
for ( int n = 0; n < Btn_Max; n++ )
|
|
{
|
|
m_buttons[n] = new wxCheckBox(this, wxID_ANY, ms_btnInfo[n].name);
|
|
sizerBtns->Add(m_buttons[n], wxSizerFlags().Centre().Left());
|
|
|
|
m_labels[n] = new wxTextCtrl(this, wxID_ANY);
|
|
sizerBtns->Add(m_labels[n], wxSizerFlags().Expand());
|
|
|
|
m_labels[n]->Bind(wxEVT_UPDATE_UI,
|
|
&TestMessageBoxDialog::OnUpdateLabelUI, this);
|
|
}
|
|
|
|
sizerBtnsBox->Add(sizerBtns, wxSizerFlags().Expand());
|
|
sizerTop->Add(sizerBtnsBox, wxSizerFlags().Expand().Border());
|
|
|
|
|
|
// icon choice
|
|
const wxString icons[] =
|
|
{
|
|
"&Not specified",
|
|
"E&xplicitly none",
|
|
"&Information icon",
|
|
"&Question icon",
|
|
"&Warning icon",
|
|
"&Error icon",
|
|
"A&uth needed icon"
|
|
};
|
|
|
|
wxCOMPILE_TIME_ASSERT( WXSIZEOF(icons) == MsgDlgIcon_Max, IconMismatch );
|
|
|
|
m_icons = new wxRadioBox(this, wxID_ANY, "&Icon style",
|
|
wxDefaultPosition, wxDefaultSize,
|
|
WXSIZEOF(icons), icons,
|
|
2, wxRA_SPECIFY_ROWS);
|
|
// Make the 'Information' icon the default one:
|
|
m_icons->SetSelection(MsgDlgIcon_Info);
|
|
sizerTop->Add(m_icons, wxSizerFlags().Expand().Border());
|
|
|
|
|
|
// miscellaneous other stuff
|
|
wxSizer * const
|
|
sizerFlags = new wxStaticBoxSizer(wxHORIZONTAL, this, "&Other flags");
|
|
|
|
m_chkNoDefault = new wxCheckBox(this, wxID_ANY, "Make \"No\" &default");
|
|
m_chkNoDefault->Bind(wxEVT_UPDATE_UI,
|
|
&TestMessageBoxDialog::OnUpdateNoDefaultUI, this);
|
|
sizerFlags->Add(m_chkNoDefault, wxSizerFlags().Border());
|
|
|
|
m_chkCentre = new wxCheckBox(this, wxID_ANY, "Centre on &parent");
|
|
sizerFlags->Add(m_chkCentre, wxSizerFlags().Border());
|
|
|
|
// add any additional flag from subclasses
|
|
AddAdditionalFlags(sizerFlags);
|
|
|
|
sizerTop->Add(sizerFlags, wxSizerFlags().Expand().Border());
|
|
|
|
// add the currently unused zone for displaying the dialog result
|
|
m_labelResult = new wxStaticText(this, wxID_ANY, "",
|
|
wxDefaultPosition, wxDefaultSize,
|
|
wxST_NO_AUTORESIZE | wxALIGN_CENTRE);
|
|
m_labelResult->SetForegroundColour(*wxBLUE);
|
|
sizerTop->Add(m_labelResult, wxSizerFlags().Expand().DoubleBorder());
|
|
|
|
// finally buttons to show the resulting message box and close this dialog
|
|
sizerTop->Add(CreateStdDialogButtonSizer(wxAPPLY | wxCLOSE),
|
|
wxSizerFlags().Right().Border());
|
|
|
|
SetSizerAndFit(sizerTop);
|
|
|
|
m_buttons[Btn_Ok]->SetValue(true);
|
|
|
|
CentreOnScreen();
|
|
|
|
return true;
|
|
}
|
|
|
|
void TestMessageBoxDialog::OnUpdateLabelUI(wxUpdateUIEvent& event)
|
|
{
|
|
for ( int n = 0; n < Btn_Max; n++ )
|
|
{
|
|
if ( event.GetEventObject() == m_labels[n] )
|
|
{
|
|
event.Enable( m_buttons[n]->IsChecked() );
|
|
return;
|
|
}
|
|
}
|
|
|
|
wxFAIL_MSG( "called for unknown label" );
|
|
}
|
|
|
|
void TestMessageBoxDialog::OnUpdateNoDefaultUI(wxUpdateUIEvent& event)
|
|
{
|
|
event.Enable( m_buttons[Btn_No]->IsChecked() );
|
|
}
|
|
|
|
long TestMessageBoxDialog::GetStyle()
|
|
{
|
|
long style = 0;
|
|
|
|
for ( int n = 0; n < Btn_Max; n++ )
|
|
{
|
|
if ( m_buttons[n]->IsChecked() )
|
|
style |= ms_btnInfo[n].flag;
|
|
}
|
|
|
|
switch ( m_icons->GetSelection() )
|
|
{
|
|
case MsgDlgIcon_Max:
|
|
wxFAIL_MSG( "unexpected selection" );
|
|
wxFALLTHROUGH;
|
|
|
|
case MsgDlgIcon_No:
|
|
break;
|
|
|
|
case MsgDlgIcon_None:
|
|
style |= wxICON_NONE;
|
|
break;
|
|
|
|
case MsgDlgIcon_Info:
|
|
style |= wxICON_INFORMATION;
|
|
break;
|
|
|
|
case MsgDlgIcon_Question:
|
|
style |= wxICON_QUESTION;
|
|
break;
|
|
|
|
case MsgDlgIcon_Warning:
|
|
style |= wxICON_WARNING;
|
|
break;
|
|
|
|
case MsgDlgIcon_Error:
|
|
style |= wxICON_ERROR;
|
|
break;
|
|
|
|
case MsgDlgIcon_AuthNeeded:
|
|
style |= wxICON_AUTH_NEEDED;
|
|
break;
|
|
}
|
|
|
|
if ( m_chkCentre->IsChecked() )
|
|
style |= wxCENTRE;
|
|
|
|
if ( m_chkNoDefault->IsEnabled() && m_chkNoDefault->IsChecked() )
|
|
style |= wxNO_DEFAULT;
|
|
|
|
return style;
|
|
}
|
|
|
|
void TestMessageBoxDialog::PrepareMessageDialog(wxMessageDialogBase &dlg)
|
|
{
|
|
long style = dlg.GetMessageDialogStyle();
|
|
|
|
if ( !m_textExtMsg->IsEmpty() )
|
|
dlg.SetExtendedMessage(m_textExtMsg->GetValue());
|
|
|
|
if ( style & wxYES_NO )
|
|
{
|
|
if ( style & wxCANCEL )
|
|
{
|
|
dlg.SetYesNoCancelLabels(m_labels[Btn_Yes]->GetValue(),
|
|
m_labels[Btn_No]->GetValue(),
|
|
m_labels[Btn_Cancel]->GetValue());
|
|
}
|
|
else
|
|
{
|
|
dlg.SetYesNoLabels(m_labels[Btn_Yes]->GetValue(),
|
|
m_labels[Btn_No]->GetValue());
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if ( style & wxCANCEL )
|
|
{
|
|
dlg.SetOKCancelLabels(m_labels[Btn_Ok]->GetValue(),
|
|
m_labels[Btn_Cancel]->GetValue());
|
|
}
|
|
else
|
|
{
|
|
dlg.SetOKLabel(m_labels[Btn_Ok]->GetValue());
|
|
}
|
|
}
|
|
|
|
if ( style & wxHELP )
|
|
{
|
|
dlg.SetHelpLabel(m_labels[Btn_Help]->GetValue());
|
|
}
|
|
}
|
|
|
|
void TestMessageBoxDialog::OnApply(wxCommandEvent& WXUNUSED(event))
|
|
{
|
|
wxMessageDialog dlg(this, GetMessage(), GetBoxTitle(), GetStyle());
|
|
PrepareMessageDialog(dlg);
|
|
|
|
ShowResult(dlg.ShowModal());
|
|
}
|
|
|
|
void TestMessageBoxDialog::ShowResult(int res)
|
|
{
|
|
wxString btnName;
|
|
switch ( res )
|
|
{
|
|
case wxID_OK:
|
|
btnName = "OK";
|
|
break;
|
|
|
|
case wxID_CANCEL:
|
|
btnName = "Cancel";
|
|
break;
|
|
|
|
case wxID_YES:
|
|
btnName = "Yes";
|
|
break;
|
|
|
|
case wxID_NO:
|
|
btnName = "No";
|
|
break;
|
|
|
|
case wxID_HELP:
|
|
btnName = "Help";
|
|
break;
|
|
|
|
default:
|
|
btnName = "Unknown";
|
|
}
|
|
|
|
m_labelResult->SetLabel(
|
|
wxString::Format("Dialog was closed with the \"%s\" button.", btnName)
|
|
);
|
|
}
|
|
|
|
void TestMessageBoxDialog::OnClose(wxCommandEvent& WXUNUSED(event))
|
|
{
|
|
EndModal(wxID_CANCEL);
|
|
}
|
|
#endif // wxUSE_MSGDLG
|
|
|
|
#if wxUSE_RICHMSGDLG
|
|
// ----------------------------------------------------------------------------
|
|
// TestRichMessageDialog
|
|
// ----------------------------------------------------------------------------
|
|
|
|
wxBEGIN_EVENT_TABLE(TestRichMessageDialog, TestMessageBoxDialog)
|
|
EVT_BUTTON(wxID_APPLY, TestRichMessageDialog::OnApply)
|
|
wxEND_EVENT_TABLE()
|
|
|
|
TestRichMessageDialog::TestRichMessageDialog(wxWindow *parent)
|
|
: TestMessageBoxDialog(parent)
|
|
{
|
|
SetTitle("Rich Message Dialog Test Dialog");
|
|
}
|
|
|
|
void TestRichMessageDialog::AddAdditionalTextOptions(wxSizer *sizer)
|
|
{
|
|
wxSizer * const sizerMsgs = new wxStaticBoxSizer(wxVERTICAL, this,
|
|
"&Additional Elements");
|
|
|
|
// add an option to show a check box.
|
|
wxSizer * const sizerCheckBox = new wxBoxSizer(wxHORIZONTAL);
|
|
sizerCheckBox->Add(new wxStaticText(this, wxID_ANY, "&Check box:"),
|
|
wxSizerFlags().Centre().Border(wxRIGHT));
|
|
m_textCheckBox = new wxTextCtrl(this, wxID_ANY);
|
|
sizerCheckBox->Add(m_textCheckBox, wxSizerFlags(1).Centre());
|
|
sizerMsgs->Add(sizerCheckBox, wxSizerFlags().Expand().Border(wxBOTTOM));
|
|
|
|
// add option to show a detailed text.
|
|
sizerMsgs->Add(new wxStaticText(this, wxID_ANY, "&Detailed message:"));
|
|
m_textDetailed = new wxTextCtrl(this, wxID_ANY, "",
|
|
wxDefaultPosition, wxDefaultSize,
|
|
wxTE_MULTILINE);
|
|
sizerMsgs->Add(m_textDetailed, wxSizerFlags().Expand());
|
|
|
|
// add option to show footer text
|
|
wxSizer * const sizerFooter = new wxBoxSizer(wxHORIZONTAL);
|
|
sizerFooter->Add(new wxStaticText(this, wxID_ANY, "&Footer Text:"),
|
|
wxSizerFlags().Centre().Border(wxRIGHT));
|
|
m_textFooter = new wxTextCtrl(this, wxID_ANY);
|
|
sizerFooter->Add(m_textFooter, wxSizerFlags(1).Centre());
|
|
|
|
// add option to select footer icon
|
|
const wxString icons[] =
|
|
{
|
|
"None",
|
|
"Info",
|
|
"Warning",
|
|
"Error",
|
|
"Auth needed"
|
|
};
|
|
|
|
sizerFooter->Add(new wxStaticText(this, wxID_ANY, "Icon:"),
|
|
wxSizerFlags().Centre().Border(wxLEFT));
|
|
m_iconsFooter = new wxChoice(this, wxID_ANY,
|
|
wxDefaultPosition, wxDefaultSize,
|
|
WXSIZEOF(icons), icons);
|
|
// Make the None the default:
|
|
m_iconsFooter->SetSelection(0);
|
|
sizerFooter->Add(m_iconsFooter, wxSizerFlags().Expand().Border());
|
|
|
|
sizerMsgs->Add(sizerFooter, wxSizerFlags().Expand().Border(wxTOP));
|
|
|
|
sizer->Add(sizerMsgs, wxSizerFlags().Expand().Border());
|
|
}
|
|
|
|
void TestRichMessageDialog::AddAdditionalFlags(wxSizer *sizer)
|
|
{
|
|
// add checkbox to set the initial state for the checkbox shown
|
|
// in the dialog.
|
|
m_initialValueCheckBox =
|
|
new wxCheckBox(this, wxID_ANY, "Checkbox initially checked");
|
|
sizer->Add(m_initialValueCheckBox, wxSizerFlags().Border());
|
|
}
|
|
|
|
void TestRichMessageDialog::OnApply(wxCommandEvent& WXUNUSED(event))
|
|
{
|
|
wxRichMessageDialog dlg(this, GetMessage(), GetBoxTitle(), GetStyle());
|
|
PrepareMessageDialog(dlg);
|
|
|
|
dlg.ShowCheckBox(m_textCheckBox->GetValue(),
|
|
m_initialValueCheckBox->GetValue());
|
|
dlg.ShowDetailedText(m_textDetailed->GetValue());
|
|
dlg.SetFooterText(m_textFooter->GetValue());
|
|
switch ( m_iconsFooter->GetSelection() )
|
|
{
|
|
case 1:
|
|
dlg.SetFooterIcon(wxICON_INFORMATION);
|
|
break;
|
|
|
|
case 2:
|
|
dlg.SetFooterIcon(wxICON_WARNING);
|
|
break;
|
|
|
|
case 3:
|
|
dlg.SetFooterIcon(wxICON_ERROR);
|
|
break;
|
|
|
|
case 4:
|
|
dlg.SetFooterIcon(wxICON_AUTH_NEEDED);
|
|
break;
|
|
}
|
|
|
|
ShowResult(dlg.ShowModal());
|
|
}
|
|
|
|
#endif // wxUSE_RICHMSGDLG
|
|
|
|
#if wxUSE_LOG
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// custom log target
|
|
// ----------------------------------------------------------------------------
|
|
|
|
class MyLogGui : public wxLogGui
|
|
{
|
|
private:
|
|
virtual void DoShowSingleLogMessage(const wxString& message,
|
|
const wxString& title,
|
|
int style) wxOVERRIDE
|
|
{
|
|
wxMessageDialog dlg(NULL, message, title,
|
|
wxOK | wxCANCEL | wxCANCEL_DEFAULT | style);
|
|
dlg.SetOKCancelLabels(wxID_COPY, wxID_OK);
|
|
dlg.SetExtendedMessage("Note that this is a custom log dialog.");
|
|
dlg.ShowModal();
|
|
}
|
|
};
|
|
|
|
wxLog *MyAppTraits::CreateLogTarget()
|
|
{
|
|
return new MyLogGui;
|
|
}
|
|
|
|
#endif // wxUSE_LOG
|