wallet/samples/dialogs/dialogs.h

322 lines
6.7 KiB
C
Raw Permalink Normal View History

/////////////////////////////////////////////////////////////////////////////
// Name: dialogs.h
// Purpose: Common dialogs demo
// Author: Julian Smart, Vadim Zeitlin, ABX
// Created: 04/01/98
// Copyright: (c) Julian Smart
// (c) 2004 ABX
// (c) Vadim Zeitlin
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
/*
This sample shows how to use the common dialogs available from wxWidgets.
It also shows that generic implementations of common dialogs can be exchanged
with native dialogs and can coexist in one application. The need for generic
dialogs addition is recognized thanks to setup of below USE_*** setting. Their
combinations reflects conditions of makefiles and project files to avoid unresolved
references during linking. For now some generic dialogs are added in static builds
of MSW, MAC and OS2
*/#pragma once
#ifndef __DIALOGSH__
#define __DIALOGSH__
#endif
#ifdef __WXUNIVERSAL__
#define USE_WXUNIVERSAL 1
#else
#define USE_WXUNIVERSAL 0
#endif
#ifdef WXUSINGDLL
#define USE_DLL 1
#else
#define USE_DLL 0
#endif
#if defined(__WXMSW__)
#define USE_WXMSW 1
#else
#define USE_WXMSW 0
#endif
#ifdef __WXMAC__
#define USE_WXMAC 1
#else
#define USE_WXMAC 0
#endif
#if USE_NATIVE_FONT_DIALOG_FOR_MACOSX
#define USE_WXMACFONTDLG 1
#else
#define USE_WXMACFONTDLG 0
#endif
#ifdef __WXGTK__
#define USE_WXGTK 1
#else
#define USE_WXGTK 0
#endif
#define USE_GENERIC_DIALOGS (!USE_WXUNIVERSAL && !USE_DLL)
#define USE_COLOURDLG_GENERIC \
((USE_WXMSW || USE_WXMAC) && USE_GENERIC_DIALOGS && wxUSE_COLOURDLG)
#define USE_DIRDLG_GENERIC \
((USE_WXMSW || USE_WXMAC) && USE_GENERIC_DIALOGS && wxUSE_DIRDLG)
#define USE_FILEDLG_GENERIC \
((USE_WXMSW || USE_WXMAC) && USE_GENERIC_DIALOGS && wxUSE_FILEDLG)
#define USE_FONTDLG_GENERIC \
((USE_WXMSW || USE_WXMACFONTDLG) && USE_GENERIC_DIALOGS && wxUSE_FONTDLG)
// Turn USE_MODAL_PRESENTATION to 0 if there is any reason for not presenting difference
// between modal and modeless dialogs (ie. not implemented it in your port yet)
#if !wxUSE_BOOKCTRL
#define USE_MODAL_PRESENTATION 0
#else
#define USE_MODAL_PRESENTATION 1
#endif
// Turn USE_SETTINGS_DIALOG to 0 if supported
#if wxUSE_BOOKCTRL
#define USE_SETTINGS_DIALOG 1
#else
#define USE_SETTINGS_DIALOG 0
#endif
#if USE_MODAL_PRESENTATION
// A custom modeless dialog
class MyModelessDialog : public wxDialog
{
public:
MyModelessDialog(wxWindow *parent);
void OnButton(wxCommandEvent& event);
void OnClose(wxCloseEvent& event);
private:
wxDECLARE_EVENT_TABLE();
};
// A custom modal dialog
class MyModalDialog : public wxDialog
{
public:
MyModalDialog(wxWindow *parent);
void OnButton(wxCommandEvent& event);
private:
wxButton *m_btnModal,
*m_btnModeless,
*m_btnDelete;
wxDECLARE_EVENT_TABLE();
};
#endif // USE_MODAL_PRESENTATION
// A class demonstrating CreateStdDialogButtonSizer()
class StdButtonSizerDialog : public wxDialog
{
public:
StdButtonSizerDialog(wxWindow *parent);
void OnEvent(wxCommandEvent& event);
private:
void EnableDisableControls();
wxCheckBox *m_chkboxAffirmativeButton;
wxRadioButton *m_radiobtnOk,
*m_radiobtnYes;
wxCheckBox *m_chkboxDismissButton;
wxRadioButton *m_radiobtnClose,
*m_radiobtnCancel;
wxCheckBox *m_chkboxApply,
*m_chkboxNo,
*m_chkboxHelp,
*m_chkboxNoDefault;
wxSizer *m_buttonsSizer;
wxDECLARE_EVENT_TABLE();
};
// Test harness for wxMessageDialog.
class TestMessageBoxDialog : public wxDialog
{
public:
TestMessageBoxDialog(wxWindow *parent);
bool Create();
protected:
wxString GetBoxTitle() { return m_textTitle->GetValue(); }
wxString GetMessage() { return m_textMsg->GetValue(); }
long GetStyle();
void PrepareMessageDialog(wxMessageDialogBase &dlg);
virtual void AddAdditionalTextOptions(wxSizer *WXUNUSED(sizer)) { }
virtual void AddAdditionalFlags(wxSizer *WXUNUSED(sizer)) { }
void ShowResult(int res);
void OnApply(wxCommandEvent& event);
void OnClose(wxCommandEvent& event);
void OnUpdateLabelUI(wxUpdateUIEvent& event);
void OnUpdateNoDefaultUI(wxUpdateUIEvent& event);
private:
enum
{
Btn_Yes,
Btn_No,
Btn_Ok,
Btn_Cancel,
Btn_Help,
Btn_Max
};
struct BtnInfo
{
int flag;
const char *name;
};
static const BtnInfo ms_btnInfo[Btn_Max];
enum
{
MsgDlgIcon_No,
MsgDlgIcon_None,
MsgDlgIcon_Info,
MsgDlgIcon_Question,
MsgDlgIcon_Warning,
MsgDlgIcon_Error,
MsgDlgIcon_AuthNeeded,
MsgDlgIcon_Max
};
wxTextCtrl *m_textTitle,
*m_textMsg,
*m_textExtMsg;
wxCheckBox *m_buttons[Btn_Max];
wxTextCtrl *m_labels[Btn_Max];
wxRadioBox *m_icons;
wxCheckBox *m_chkNoDefault,
*m_chkCentre;
wxStaticText *m_labelResult;
wxDECLARE_EVENT_TABLE();
wxDECLARE_NO_COPY_CLASS(TestMessageBoxDialog);
};
#if wxUSE_RICHMSGDLG
class TestRichMessageDialog : public TestMessageBoxDialog
{
public:
TestRichMessageDialog(wxWindow *parent);
protected:
// overrides method in base class
virtual void AddAdditionalTextOptions(wxSizer *sizer) wxOVERRIDE;
virtual void AddAdditionalFlags(wxSizer *sizer) wxOVERRIDE;
void OnApply(wxCommandEvent& event);
private:
wxTextCtrl *m_textCheckBox;
wxCheckBox *m_initialValueCheckBox;
wxTextCtrl *m_textDetailed;
wxTextCtrl *m_textFooter;
wxChoice *m_iconsFooter;
wxDECLARE_EVENT_TABLE();
};
#endif // wxUSE_RICHMSGDLG
class TestDefaultActionDialog: public wxDialog
{
public:
TestDefaultActionDialog( wxWindow *parent );
void OnListBoxDClick(wxCommandEvent& event);
void OnDisableOK(wxCommandEvent& event);
void OnDisableCancel(wxCommandEvent& event);
void OnCatchListBoxDClick(wxCommandEvent& event);
void OnTextEnter(wxCommandEvent& event);
private:
bool m_catchListBoxDClick;
private:
wxDECLARE_EVENT_TABLE();
};
#if USE_SETTINGS_DIALOG
// Struct containing properties edited by SettingsDialog.
struct SettingsData
{
SettingsData() :
m_loadLastOnStartup(false),
m_autoSaveInterval(1),
m_showToolTips(false),
m_applyTo(0),
m_bgStyle(0),
m_titleFontSize(10)
{
}
bool m_loadLastOnStartup;
int m_autoSaveInterval;
bool m_showToolTips;
int m_applyTo;
int m_bgStyle;
int m_titleFontSize;
};
// Property sheet dialog
class SettingsDialog: public wxPropertySheetDialog
{
wxDECLARE_CLASS(SettingsDialog);
public:
SettingsDialog(wxWindow* parent, SettingsData& settingsData, int dialogType);
~SettingsDialog();
wxPanel* CreateGeneralSettingsPage(wxWindow* parent);
wxPanel* CreateAestheticSettingsPage(wxWindow* parent);
protected:
enum {
ID_SHOW_TOOLTIPS = 100,
ID_AUTO_SAVE,
ID_AUTO_SAVE_MINS,
ID_LOAD_LAST_PROJECT,
ID_APPLY_SETTINGS_TO,
ID_BACKGROUND_STYLE,
ID_FONT_SIZE
};
wxImageList* m_imageList;
SettingsData& m_settingsData;
wxDECLARE_EVENT_TABLE();
};
#endif // USE_SETTINGS_DIALOG