1998-05-22 15:57:05 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: dialogs.cpp
|
|
|
|
// Purpose: Common dialogs demo
|
|
|
|
// Author: Julian Smart
|
|
|
|
// Modified by:
|
|
|
|
// Created: 04/01/98
|
|
|
|
// RCS-ID: $Id$
|
2003-03-17 06:55:54 -05:00
|
|
|
// Copyright: (c) Julian Smart
|
1999-06-28 17:39:49 -04:00
|
|
|
// Licence: wxWindows license
|
1998-05-22 15:57:05 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2003-07-28 13:56:33 -04:00
|
|
|
#if defined(__GNUG__) && !defined(__APPLE__)
|
1998-05-22 15:57:05 -04:00
|
|
|
#pragma implementation
|
|
|
|
#pragma interface
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
2003-07-15 09:15:48 -04:00
|
|
|
#ifdef __WXWINCE__
|
|
|
|
#include "wx/msw/wince/time.h"
|
|
|
|
#endif
|
|
|
|
|
1999-07-03 12:40:54 -04:00
|
|
|
#include "wx/colordlg.h"
|
|
|
|
#include "wx/filedlg.h"
|
|
|
|
#include "wx/dirdlg.h"
|
|
|
|
#include "wx/fontdlg.h"
|
|
|
|
#include "wx/choicdlg.h"
|
|
|
|
#include "wx/tipdlg.h"
|
2000-02-24 21:20:44 -05:00
|
|
|
#include "wx/progdlg.h"
|
2001-07-31 22:29:35 -04:00
|
|
|
#include "wx/fdrepdlg.h"
|
2001-10-29 08:21:29 -05:00
|
|
|
#include "wx/busyinfo.h"
|
1998-05-22 15:57:05 -04:00
|
|
|
|
1998-10-02 08:50:01 -04:00
|
|
|
#define wxTEST_GENERIC_DIALOGS_IN_MSW 0
|
|
|
|
|
|
|
|
#if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
|
2002-01-19 09:50:37 -05:00
|
|
|
#include "wx/generic/colrdlgg.h"
|
|
|
|
#include "wx/generic/fontdlgg.h"
|
1998-05-22 15:57:05 -04:00
|
|
|
#endif
|
|
|
|
|
2002-02-10 14:04:22 -05:00
|
|
|
#define wxUSE_DIRDLGG 0
|
2002-01-08 09:15:57 -05:00
|
|
|
|
2003-10-23 17:51:33 -04:00
|
|
|
#if !(defined(__WXMSW__) || defined(__WXMAC__)) || wxUSE_DIRDLGG
|
2002-01-08 09:15:57 -05:00
|
|
|
#include "wx/generic/dirdlgg.h"
|
2000-11-25 17:44:55 -05:00
|
|
|
#endif
|
|
|
|
|
1998-05-22 15:57:05 -04:00
|
|
|
#include "dialogs.h"
|
|
|
|
|
|
|
|
IMPLEMENT_APP(MyApp)
|
|
|
|
|
2000-01-29 20:33:02 -05:00
|
|
|
BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
|
|
|
|
EVT_PAINT(MyCanvas::OnPaint)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
|
|
|
EVT_MENU(DIALOGS_CHOOSE_COLOUR, MyFrame::ChooseColour)
|
|
|
|
EVT_MENU(DIALOGS_CHOOSE_FONT, MyFrame::ChooseFont)
|
|
|
|
EVT_MENU(DIALOGS_LOG_DIALOG, MyFrame::LogDialog)
|
|
|
|
EVT_MENU(DIALOGS_MESSAGE_BOX, MyFrame::MessageBox)
|
|
|
|
EVT_MENU(DIALOGS_TEXT_ENTRY, MyFrame::TextEntry)
|
|
|
|
EVT_MENU(DIALOGS_PASSWORD_ENTRY, MyFrame::PasswordEntry)
|
|
|
|
EVT_MENU(DIALOGS_NUM_ENTRY, MyFrame::NumericEntry)
|
|
|
|
EVT_MENU(DIALOGS_SINGLE_CHOICE, MyFrame::SingleChoice)
|
2000-11-03 15:52:17 -05:00
|
|
|
EVT_MENU(DIALOGS_MULTI_CHOICE, MyFrame::MultiChoice)
|
2000-01-29 20:33:02 -05:00
|
|
|
EVT_MENU(DIALOGS_FILE_OPEN, MyFrame::FileOpen)
|
2000-08-23 18:47:33 -04:00
|
|
|
EVT_MENU(DIALOGS_FILE_OPEN2, MyFrame::FileOpen2)
|
2000-01-29 20:33:02 -05:00
|
|
|
EVT_MENU(DIALOGS_FILES_OPEN, MyFrame::FilesOpen)
|
|
|
|
EVT_MENU(DIALOGS_FILE_SAVE, MyFrame::FileSave)
|
|
|
|
EVT_MENU(DIALOGS_DIR_CHOOSE, MyFrame::DirChoose)
|
2003-02-01 17:51:07 -05:00
|
|
|
EVT_MENU(DIALOGS_DIRNEW_CHOOSE, MyFrame::DirChooseNew)
|
2002-04-03 11:01:44 -05:00
|
|
|
#if defined(__WXMSW__) || defined(__WXMAC__)
|
2000-07-23 15:10:27 -04:00
|
|
|
EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE, MyFrame::GenericDirChoose)
|
2002-04-03 11:01:44 -05:00
|
|
|
#endif // wxMSW || wxMAC
|
2000-07-15 15:51:35 -04:00
|
|
|
EVT_MENU(DIALOGS_MODAL, MyFrame::ModalDlg)
|
2000-01-29 20:33:02 -05:00
|
|
|
EVT_MENU(DIALOGS_MODELESS, MyFrame::ModelessDlg)
|
|
|
|
EVT_MENU(DIALOGS_TIP, MyFrame::ShowTip)
|
|
|
|
#if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
|
|
|
|
EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC, MyFrame::ChooseColourGeneric)
|
|
|
|
EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC, MyFrame::ChooseFontGeneric)
|
2000-02-24 21:20:44 -05:00
|
|
|
#endif
|
2001-10-29 08:21:29 -05:00
|
|
|
|
2000-02-24 21:20:44 -05:00
|
|
|
#if wxUSE_PROGRESSDLG
|
|
|
|
EVT_MENU(DIALOGS_PROGRESS, MyFrame::ShowProgress)
|
2001-07-31 22:29:35 -04:00
|
|
|
#endif // wxUSE_PROGRESSDLG
|
2001-10-29 08:21:29 -05:00
|
|
|
|
|
|
|
#if wxUSE_BUSYINFO
|
|
|
|
EVT_MENU(DIALOGS_BUSYINFO, MyFrame::ShowBusyInfo)
|
|
|
|
#endif // wxUSE_BUSYINFO
|
|
|
|
|
2001-07-31 22:29:35 -04:00
|
|
|
#if wxUSE_FINDREPLDLG
|
|
|
|
EVT_MENU(DIALOGS_FIND, MyFrame::ShowFindDialog)
|
|
|
|
EVT_MENU(DIALOGS_REPLACE, MyFrame::ShowReplaceDialog)
|
|
|
|
|
|
|
|
EVT_FIND(-1, MyFrame::OnFindDialog)
|
|
|
|
EVT_FIND_NEXT(-1, MyFrame::OnFindDialog)
|
|
|
|
EVT_FIND_REPLACE(-1, MyFrame::OnFindDialog)
|
|
|
|
EVT_FIND_REPLACE_ALL(-1, MyFrame::OnFindDialog)
|
|
|
|
EVT_FIND_CLOSE(-1, MyFrame::OnFindDialog)
|
|
|
|
#endif // wxUSE_FINDREPLDLG
|
2000-01-29 20:33:02 -05:00
|
|
|
EVT_MENU(wxID_EXIT, MyFrame::OnExit)
|
|
|
|
END_EVENT_TABLE()
|
2000-02-24 21:20:44 -05:00
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
BEGIN_EVENT_TABLE(MyModalDialog, wxDialog)
|
|
|
|
EVT_BUTTON(-1, MyModalDialog::OnButton)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2000-02-24 21:20:44 -05:00
|
|
|
BEGIN_EVENT_TABLE(MyModelessDialog, wxDialog)
|
2001-08-20 19:01:17 -04:00
|
|
|
EVT_BUTTON(DIALOGS_MODELESS_BTN, MyModelessDialog::OnButton)
|
|
|
|
|
2000-02-24 21:20:44 -05:00
|
|
|
EVT_CLOSE(MyModelessDialog::OnClose)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
1998-08-22 23:22:56 -04:00
|
|
|
MyCanvas *myCanvas = (MyCanvas *) NULL;
|
1998-05-22 15:57:05 -04:00
|
|
|
|
|
|
|
// `Main program' equivalent, creating windows and returning main app frame
|
2000-01-29 20:33:02 -05:00
|
|
|
bool MyApp::OnInit()
|
1998-05-22 15:57:05 -04:00
|
|
|
{
|
1999-04-26 16:48:39 -04:00
|
|
|
#if defined(__WXGTK__) && defined(wxUSE_UNICODE)
|
1999-06-14 19:04:05 -04:00
|
|
|
wxConvCurrent = &wxConvLibc;
|
1999-04-26 16:48:39 -04:00
|
|
|
#endif
|
|
|
|
|
2002-12-13 16:33:14 -05:00
|
|
|
m_canvasTextColour = wxColour(_T("BLACK"));
|
1998-08-02 16:38:05 -04:00
|
|
|
m_canvasFont = *wxNORMAL_FONT;
|
1998-05-22 15:57:05 -04:00
|
|
|
|
|
|
|
// Create the main frame window
|
2002-06-21 07:18:19 -04:00
|
|
|
MyFrame *frame = new MyFrame((wxFrame *) NULL, _T("wxWindows dialogs example"), wxPoint(20, 20), wxSize(400, 300));
|
1998-05-22 15:57:05 -04:00
|
|
|
|
|
|
|
// Make a menubar
|
|
|
|
wxMenu *file_menu = new wxMenu;
|
|
|
|
|
2002-06-09 18:19:24 -04:00
|
|
|
file_menu->Append(DIALOGS_CHOOSE_COLOUR, _T("&Choose colour"));
|
1998-05-22 15:57:05 -04:00
|
|
|
|
1998-10-02 08:50:01 -04:00
|
|
|
#if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
|
2002-06-09 18:19:24 -04:00
|
|
|
file_menu->Append(DIALOGS_CHOOSE_COLOUR_GENERIC, _T("Choose colour (&generic)"));
|
1998-05-22 15:57:05 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
file_menu->AppendSeparator();
|
2002-06-09 18:19:24 -04:00
|
|
|
file_menu->Append(DIALOGS_CHOOSE_FONT, _T("Choose &font"));
|
1998-05-22 15:57:05 -04:00
|
|
|
|
1998-10-02 08:50:01 -04:00
|
|
|
#if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
|
2002-06-09 18:19:24 -04:00
|
|
|
file_menu->Append(DIALOGS_CHOOSE_FONT_GENERIC, _T("Choose f&ont (generic)"));
|
1998-05-22 15:57:05 -04:00
|
|
|
#endif
|
2003-02-01 17:51:07 -05:00
|
|
|
|
1998-05-22 15:57:05 -04:00
|
|
|
file_menu->AppendSeparator();
|
2002-06-09 18:19:24 -04:00
|
|
|
file_menu->Append(DIALOGS_LOG_DIALOG, _T("&Log dialog\tCtrl-L"));
|
|
|
|
file_menu->Append(DIALOGS_MESSAGE_BOX, _T("&Message box\tCtrl-M"));
|
|
|
|
file_menu->Append(DIALOGS_TEXT_ENTRY, _T("Text &entry\tCtrl-E"));
|
|
|
|
file_menu->Append(DIALOGS_PASSWORD_ENTRY, _T("&Password entry\tCtrl-P"));
|
|
|
|
file_menu->Append(DIALOGS_NUM_ENTRY, _T("&Numeric entry\tCtrl-N"));
|
|
|
|
file_menu->Append(DIALOGS_SINGLE_CHOICE, _T("&Single choice\tCtrl-C"));
|
|
|
|
file_menu->Append(DIALOGS_MULTI_CHOICE, _T("M&ultiple choice\tCtrl-U"));
|
1998-05-22 15:57:05 -04:00
|
|
|
file_menu->AppendSeparator();
|
2002-06-09 18:19:24 -04:00
|
|
|
file_menu->Append(DIALOGS_TIP, _T("&Tip of the day\tCtrl-T"));
|
1999-06-28 17:39:49 -04:00
|
|
|
file_menu->AppendSeparator();
|
2002-06-09 18:19:24 -04:00
|
|
|
file_menu->Append(DIALOGS_FILE_OPEN, _T("&Open file\tCtrl-O"));
|
|
|
|
file_menu->Append(DIALOGS_FILE_OPEN2, _T("&Second open file\tCtrl-2"));
|
|
|
|
file_menu->Append(DIALOGS_FILES_OPEN, _T("Open &files\tCtrl-Q"));
|
|
|
|
file_menu->Append(DIALOGS_FILE_SAVE, _T("Sa&ve file\tCtrl-S"));
|
|
|
|
file_menu->Append(DIALOGS_DIR_CHOOSE, _T("&Choose a directory\tCtrl-D"));
|
2003-02-01 17:51:07 -05:00
|
|
|
file_menu->Append(DIALOGS_DIRNEW_CHOOSE, _T("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
|
2002-04-03 11:01:44 -05:00
|
|
|
#if defined(__WXMSW__) || defined(__WXMAC__)
|
2002-06-09 18:19:24 -04:00
|
|
|
file_menu->Append(DIALOGS_GENERIC_DIR_CHOOSE, _T("&Choose a directory (generic implementation)"));
|
2002-04-03 11:01:44 -05:00
|
|
|
#endif // wxMSW || wxMAC
|
2003-02-01 17:51:07 -05:00
|
|
|
file_menu->AppendSeparator();
|
|
|
|
|
2000-02-24 21:20:44 -05:00
|
|
|
#if wxUSE_PROGRESSDLG
|
2002-06-09 18:19:24 -04:00
|
|
|
file_menu->Append(DIALOGS_PROGRESS, _T("Pro&gress dialog\tCtrl-G"));
|
2000-02-24 21:20:44 -05:00
|
|
|
#endif // wxUSE_PROGRESSDLG
|
2001-10-29 08:21:29 -05:00
|
|
|
#if wxUSE_BUSYINFO
|
2002-06-09 18:19:24 -04:00
|
|
|
file_menu->Append(DIALOGS_BUSYINFO, _T("&Busy info dialog\tCtrl-B"));
|
2001-10-29 08:21:29 -05:00
|
|
|
#endif // wxUSE_BUSYINFO
|
2001-07-31 22:29:35 -04:00
|
|
|
#if wxUSE_FINDREPLDLG
|
2002-12-13 16:33:14 -05:00
|
|
|
file_menu->Append(DIALOGS_FIND, _T("&Find dialog\tCtrl-F"), _T(""), TRUE);
|
|
|
|
file_menu->Append(DIALOGS_REPLACE, _T("Find and &replace dialog\tShift-Ctrl-F"), _T(""), TRUE);
|
2001-07-31 22:29:35 -04:00
|
|
|
#endif // wxUSE_FINDREPLDLG
|
2000-07-15 15:51:35 -04:00
|
|
|
file_menu->AppendSeparator();
|
2003-02-01 17:51:07 -05:00
|
|
|
|
2002-06-09 18:19:24 -04:00
|
|
|
file_menu->Append(DIALOGS_MODAL, _T("Mo&dal dialog\tCtrl-W"));
|
2002-12-13 16:33:14 -05:00
|
|
|
file_menu->Append(DIALOGS_MODELESS, _T("Modeless &dialog\tCtrl-Z"), _T(""), TRUE);
|
2000-01-29 20:33:02 -05:00
|
|
|
file_menu->AppendSeparator();
|
2003-02-01 17:51:07 -05:00
|
|
|
|
2002-06-09 18:19:24 -04:00
|
|
|
file_menu->Append(wxID_EXIT, _T("E&xit\tAlt-X"));
|
1998-05-22 15:57:05 -04:00
|
|
|
wxMenuBar *menu_bar = new wxMenuBar;
|
2002-06-09 18:19:24 -04:00
|
|
|
menu_bar->Append(file_menu, _T("&File"));
|
1998-05-22 15:57:05 -04:00
|
|
|
frame->SetMenuBar(menu_bar);
|
|
|
|
|
|
|
|
myCanvas = new MyCanvas(frame);
|
|
|
|
myCanvas->SetBackgroundColour(*wxWHITE);
|
|
|
|
|
|
|
|
frame->Centre(wxBOTH);
|
2000-01-20 21:31:49 -05:00
|
|
|
|
1998-05-22 15:57:05 -04:00
|
|
|
// Show the frame
|
|
|
|
frame->Show(TRUE);
|
|
|
|
|
|
|
|
SetTopWindow(frame);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// My frame constructor
|
2000-01-29 20:33:02 -05:00
|
|
|
MyFrame::MyFrame(wxWindow *parent,
|
|
|
|
const wxString& title,
|
|
|
|
const wxPoint& pos,
|
|
|
|
const wxSize& size)
|
|
|
|
: wxFrame(parent, -1, title, pos, size)
|
|
|
|
{
|
|
|
|
m_dialog = (MyModelessDialog *)NULL;
|
2001-10-07 17:33:49 -04:00
|
|
|
|
2001-11-23 08:34:13 -05:00
|
|
|
#if wxUSE_FINDREPLDLG
|
2001-11-18 18:06:43 -05:00
|
|
|
m_dlgFind =
|
|
|
|
m_dlgReplace = NULL;
|
2001-11-23 08:34:13 -05:00
|
|
|
#endif
|
|
|
|
|
2001-10-07 17:33:49 -04:00
|
|
|
CreateStatusBar();
|
2000-01-29 20:33:02 -05:00
|
|
|
}
|
1998-05-22 15:57:05 -04:00
|
|
|
|
1998-07-27 19:01:43 -04:00
|
|
|
void MyFrame::ChooseColour(wxCommandEvent& WXUNUSED(event) )
|
1998-05-22 15:57:05 -04:00
|
|
|
{
|
2001-11-23 17:24:30 -05:00
|
|
|
wxColour col = myCanvas->GetBackgroundColour();
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
wxColourData data;
|
2001-11-23 17:24:30 -05:00
|
|
|
data.SetColour(col);
|
2000-07-15 15:51:35 -04:00
|
|
|
data.SetChooseFull(TRUE);
|
|
|
|
for (int i = 0; i < 16; i++)
|
|
|
|
{
|
1998-05-22 15:57:05 -04:00
|
|
|
wxColour colour(i*16, i*16, i*16);
|
|
|
|
data.SetCustomColour(i, colour);
|
2000-07-15 15:51:35 -04:00
|
|
|
}
|
2000-01-20 21:31:49 -05:00
|
|
|
|
2001-11-23 17:24:30 -05:00
|
|
|
wxColourDialog dialog(this, &data);
|
2002-12-13 16:33:14 -05:00
|
|
|
dialog.SetTitle(_T("Choose the background colour"));
|
2001-11-23 17:24:30 -05:00
|
|
|
if (dialog.ShowModal() == wxID_OK)
|
2000-07-15 15:51:35 -04:00
|
|
|
{
|
2001-11-23 17:24:30 -05:00
|
|
|
wxColourData retData = dialog.GetColourData();
|
|
|
|
col = retData.GetColour();
|
1998-05-22 15:57:05 -04:00
|
|
|
myCanvas->SetBackgroundColour(col);
|
2003-08-14 12:29:34 -04:00
|
|
|
myCanvas->ClearBackground();
|
1998-05-22 15:57:05 -04:00
|
|
|
myCanvas->Refresh();
|
2000-07-15 15:51:35 -04:00
|
|
|
}
|
1998-05-22 15:57:05 -04:00
|
|
|
}
|
|
|
|
|
1998-07-27 19:01:43 -04:00
|
|
|
void MyFrame::ChooseFont(wxCommandEvent& WXUNUSED(event) )
|
1998-05-22 15:57:05 -04:00
|
|
|
{
|
2002-05-12 15:35:33 -04:00
|
|
|
wxFontData data;
|
|
|
|
data.SetInitialFont(wxGetApp().m_canvasFont);
|
|
|
|
data.SetColour(wxGetApp().m_canvasTextColour);
|
2000-01-20 21:31:49 -05:00
|
|
|
|
2002-05-12 15:35:33 -04:00
|
|
|
// you might also do this:
|
|
|
|
//
|
|
|
|
// wxFontDialog dialog;
|
|
|
|
// if ( !dialog.Create(this, data) { ... error ... }
|
|
|
|
//
|
|
|
|
wxFontDialog dialog(this, data);
|
|
|
|
|
|
|
|
if (dialog.ShowModal() == wxID_OK)
|
|
|
|
{
|
|
|
|
wxFontData retData = dialog.GetFontData();
|
1998-05-22 15:57:05 -04:00
|
|
|
wxGetApp().m_canvasFont = retData.GetChosenFont();
|
|
|
|
wxGetApp().m_canvasTextColour = retData.GetColour();
|
|
|
|
myCanvas->Refresh();
|
2002-05-12 15:35:33 -04:00
|
|
|
}
|
|
|
|
//else: cancelled by the user, don't change the font
|
1998-05-22 15:57:05 -04:00
|
|
|
}
|
|
|
|
|
1998-10-02 08:50:01 -04:00
|
|
|
#if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
|
1998-07-27 19:01:43 -04:00
|
|
|
void MyFrame::ChooseColourGeneric(wxCommandEvent& WXUNUSED(event))
|
1998-05-22 15:57:05 -04:00
|
|
|
{
|
|
|
|
wxColourData data;
|
|
|
|
data.SetChooseFull(TRUE);
|
|
|
|
for (int i = 0; i < 16; i++)
|
|
|
|
{
|
|
|
|
wxColour colour(i*16, i*16, i*16);
|
|
|
|
data.SetCustomColour(i, colour);
|
|
|
|
}
|
2000-01-20 21:31:49 -05:00
|
|
|
|
1998-05-22 15:57:05 -04:00
|
|
|
wxGenericColourDialog *dialog = new wxGenericColourDialog(this, &data);
|
|
|
|
if (dialog->ShowModal() == wxID_OK)
|
|
|
|
{
|
|
|
|
wxColourData retData = dialog->GetColourData();
|
|
|
|
wxColour col = retData.GetColour();
|
|
|
|
// wxBrush *brush = wxTheBrushList->FindOrCreateBrush(&col, wxSOLID);
|
|
|
|
myCanvas->SetBackgroundColour(col);
|
2003-08-14 12:29:34 -04:00
|
|
|
myCanvas->ClearBackground();
|
1998-05-22 15:57:05 -04:00
|
|
|
myCanvas->Refresh();
|
|
|
|
}
|
1999-03-23 10:52:39 -05:00
|
|
|
dialog->Destroy();
|
1998-05-22 15:57:05 -04:00
|
|
|
}
|
|
|
|
|
1998-07-27 19:01:43 -04:00
|
|
|
void MyFrame::ChooseFontGeneric(wxCommandEvent& WXUNUSED(event) )
|
1998-05-22 15:57:05 -04:00
|
|
|
{
|
|
|
|
wxFontData data;
|
|
|
|
data.SetInitialFont(wxGetApp().m_canvasFont);
|
|
|
|
data.SetColour(wxGetApp().m_canvasTextColour);
|
|
|
|
|
|
|
|
wxGenericFontDialog *dialog = new wxGenericFontDialog(this, &data);
|
|
|
|
if (dialog->ShowModal() == wxID_OK)
|
|
|
|
{
|
|
|
|
wxFontData retData = dialog->GetFontData();
|
|
|
|
wxGetApp().m_canvasFont = retData.GetChosenFont();
|
|
|
|
wxGetApp().m_canvasTextColour = retData.GetColour();
|
|
|
|
myCanvas->Refresh();
|
|
|
|
}
|
1999-03-23 10:52:39 -05:00
|
|
|
dialog->Destroy();
|
1998-05-22 15:57:05 -04:00
|
|
|
}
|
2000-01-20 21:31:49 -05:00
|
|
|
#endif // wxTEST_GENERIC_DIALOGS_IN_MSW
|
|
|
|
|
2003-09-09 16:24:34 -04:00
|
|
|
void MyFrame::LogDialog(wxCommandEvent& WXUNUSED(event))
|
2000-01-20 21:31:49 -05:00
|
|
|
{
|
2000-03-03 05:31:34 -05:00
|
|
|
// calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
|
|
|
|
// being flushed -- test it
|
|
|
|
{
|
|
|
|
wxBusyCursor bc;
|
2001-09-21 16:21:44 -04:00
|
|
|
wxLogMessage(wxT("This is some message - everything is ok so far."));
|
|
|
|
wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
|
|
|
|
wxLogWarning(wxT("And then something went wrong!"));
|
2001-07-26 11:09:35 -04:00
|
|
|
|
|
|
|
// and if ~wxBusyCursor doesn't do it, then call it manually
|
|
|
|
wxYield();
|
2000-03-03 05:31:34 -05:00
|
|
|
}
|
|
|
|
|
2001-09-21 16:21:44 -04:00
|
|
|
wxLogError(wxT("Intermediary error handler decided to abort."));
|
|
|
|
wxLogError(wxT("The top level caller detected an unrecoverable error."));
|
2000-02-15 18:57:33 -05:00
|
|
|
|
2000-01-28 15:56:19 -05:00
|
|
|
wxLog::FlushActive();
|
|
|
|
|
2001-09-21 16:21:44 -04:00
|
|
|
wxLogMessage(wxT("And this is the same dialog but with only one message."));
|
2000-01-20 21:31:49 -05:00
|
|
|
}
|
1998-05-22 15:57:05 -04:00
|
|
|
|
1998-07-27 19:01:43 -04:00
|
|
|
void MyFrame::MessageBox(wxCommandEvent& WXUNUSED(event) )
|
1998-05-22 15:57:05 -04:00
|
|
|
{
|
2002-06-09 18:19:24 -04:00
|
|
|
wxMessageDialog dialog( NULL, _T("This is a message box\nA long, long string to test out the message box properly"),
|
|
|
|
_T("Message box text"), wxNO_DEFAULT|wxYES_NO|wxCANCEL|wxICON_INFORMATION);
|
1998-05-22 15:57:05 -04:00
|
|
|
|
2002-04-16 15:29:52 -04:00
|
|
|
switch ( dialog.ShowModal() )
|
|
|
|
{
|
|
|
|
case wxID_YES:
|
2002-05-10 08:26:30 -04:00
|
|
|
wxLogStatus(wxT("You pressed \"Yes\""));
|
2002-04-16 15:29:52 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case wxID_NO:
|
2002-05-10 08:26:30 -04:00
|
|
|
wxLogStatus(wxT("You pressed \"No\""));
|
2002-04-16 15:29:52 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case wxID_CANCEL:
|
2002-05-10 08:26:30 -04:00
|
|
|
wxLogStatus(wxT("You pressed \"Cancel\""));
|
2002-04-16 15:29:52 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2002-05-10 08:26:30 -04:00
|
|
|
wxLogError(wxT("Unexpected wxMessageDialog return code!"));
|
2002-04-16 15:29:52 -04:00
|
|
|
}
|
1998-05-22 15:57:05 -04:00
|
|
|
}
|
|
|
|
|
1999-07-22 19:39:47 -04:00
|
|
|
void MyFrame::NumericEntry(wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
2002-06-09 18:19:24 -04:00
|
|
|
long res = wxGetNumberFromUser( _T("This is some text, actually a lot of text.\n")
|
|
|
|
_T("Even two rows of text."),
|
|
|
|
_T("Enter a number:"), _T("Numeric input test"),
|
1999-08-04 10:41:41 -04:00
|
|
|
50, 0, 100, this );
|
1999-07-22 19:39:47 -04:00
|
|
|
|
|
|
|
wxString msg;
|
|
|
|
int icon;
|
|
|
|
if ( res == -1 )
|
|
|
|
{
|
2002-06-09 18:19:24 -04:00
|
|
|
msg = _T("Invalid number entered or dialog cancelled.");
|
1999-07-22 19:39:47 -04:00
|
|
|
icon = wxICON_HAND;
|
|
|
|
}
|
|
|
|
else
|
2000-01-20 21:31:49 -05:00
|
|
|
{
|
|
|
|
msg.Printf(_T("You've entered %lu"), res );
|
1999-07-22 19:39:47 -04:00
|
|
|
icon = wxICON_INFORMATION;
|
|
|
|
}
|
|
|
|
|
2002-06-09 18:19:24 -04:00
|
|
|
wxMessageBox(msg, _T("Numeric test result"), wxOK | icon, this);
|
1999-07-22 19:39:47 -04:00
|
|
|
}
|
|
|
|
|
2000-01-24 13:26:54 -05:00
|
|
|
void MyFrame::PasswordEntry(wxCommandEvent& WXUNUSED(event))
|
1998-05-22 15:57:05 -04:00
|
|
|
{
|
2002-06-21 07:18:19 -04:00
|
|
|
wxString pwd = wxGetPasswordFromUser(_T("Enter password:"),
|
2002-06-09 18:19:24 -04:00
|
|
|
_T("Password entry dialog"),
|
2002-12-13 16:33:14 -05:00
|
|
|
_T(""),
|
2000-01-24 13:26:54 -05:00
|
|
|
this);
|
|
|
|
if ( !!pwd )
|
|
|
|
{
|
2001-09-21 16:21:44 -04:00
|
|
|
wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd.c_str()),
|
2002-06-09 18:19:24 -04:00
|
|
|
_T("Got password"), wxOK | wxICON_INFORMATION, this);
|
2000-01-24 13:26:54 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::TextEntry(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxTextEntryDialog dialog(this,
|
2002-06-09 18:19:24 -04:00
|
|
|
_T("This is a small sample\n")
|
|
|
|
_T("A long, long string to test out the text entrybox"),
|
|
|
|
_T("Please enter a string"),
|
|
|
|
_T("Default value"),
|
2000-01-24 13:26:54 -05:00
|
|
|
wxOK | wxCANCEL);
|
1998-05-22 15:57:05 -04:00
|
|
|
|
|
|
|
if (dialog.ShowModal() == wxID_OK)
|
|
|
|
{
|
2002-06-09 18:19:24 -04:00
|
|
|
wxMessageDialog dialog2(this, dialog.GetValue(), _T("Got string"));
|
1999-06-28 17:39:49 -04:00
|
|
|
dialog2.ShowModal();
|
1998-05-22 15:57:05 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-07-27 19:01:43 -04:00
|
|
|
void MyFrame::SingleChoice(wxCommandEvent& WXUNUSED(event) )
|
1998-05-22 15:57:05 -04:00
|
|
|
{
|
2002-06-09 18:19:24 -04:00
|
|
|
const wxString choices[] = { _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five") } ;
|
1998-05-22 15:57:05 -04:00
|
|
|
|
2001-11-27 09:46:18 -05:00
|
|
|
wxSingleChoiceDialog dialog(this,
|
2002-06-09 18:19:24 -04:00
|
|
|
_T("This is a small sample\n")
|
|
|
|
_T("A single-choice convenience dialog"),
|
|
|
|
_T("Please select a value"),
|
2001-11-27 09:46:18 -05:00
|
|
|
WXSIZEOF(choices), choices);
|
1998-05-22 15:57:05 -04:00
|
|
|
|
1998-05-28 07:13:25 -04:00
|
|
|
dialog.SetSelection(2);
|
|
|
|
|
|
|
|
if (dialog.ShowModal() == wxID_OK)
|
|
|
|
{
|
2002-06-09 18:19:24 -04:00
|
|
|
wxMessageDialog dialog2(this, dialog.GetStringSelection(), _T("Got string"));
|
1998-05-28 07:13:25 -04:00
|
|
|
dialog2.ShowModal();
|
|
|
|
}
|
1998-05-22 15:57:05 -04:00
|
|
|
}
|
|
|
|
|
2000-11-03 15:52:17 -05:00
|
|
|
void MyFrame::MultiChoice(wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
2001-11-27 09:46:18 -05:00
|
|
|
const wxString choices[] =
|
|
|
|
{
|
2002-06-09 18:19:24 -04:00
|
|
|
_T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five"),
|
|
|
|
_T("Six"), _T("Seven"), _T("Eight"), _T("Nine"), _T("Ten"),
|
|
|
|
_T("Eleven"), _T("Twelve"), _T("Seventeen"),
|
2001-11-27 09:46:18 -05:00
|
|
|
};
|
2000-11-03 15:52:17 -05:00
|
|
|
|
|
|
|
wxArrayInt selections;
|
|
|
|
size_t count = wxGetMultipleChoices(selections,
|
2002-06-09 18:19:24 -04:00
|
|
|
_T("This is a small sample\n")
|
|
|
|
_T("A multi-choice convenience dialog"),
|
|
|
|
_T("Please select a value"),
|
2001-11-27 09:46:18 -05:00
|
|
|
WXSIZEOF(choices), choices,
|
2000-11-03 15:52:17 -05:00
|
|
|
this);
|
|
|
|
if ( count )
|
|
|
|
{
|
2000-11-03 16:11:41 -05:00
|
|
|
wxString msg;
|
2003-04-12 22:08:03 -04:00
|
|
|
msg.Printf(wxT("You selected %u items:\n"), (unsigned)count);
|
2000-11-03 15:52:17 -05:00
|
|
|
for ( size_t n = 0; n < count; n++ )
|
|
|
|
{
|
2003-04-12 22:08:03 -04:00
|
|
|
msg += wxString::Format(wxT("\t%u: %u (%s)\n"),
|
|
|
|
(unsigned)n, (unsigned)selections[n],
|
2000-11-03 16:11:41 -05:00
|
|
|
choices[selections[n]].c_str());
|
2000-11-03 15:52:17 -05:00
|
|
|
}
|
2000-11-03 16:11:41 -05:00
|
|
|
wxLogMessage(msg);
|
2000-11-03 15:52:17 -05:00
|
|
|
}
|
|
|
|
//else: cancelled or nothing selected
|
|
|
|
}
|
|
|
|
|
1998-07-27 19:01:43 -04:00
|
|
|
void MyFrame::FileOpen(wxCommandEvent& WXUNUSED(event) )
|
1998-05-22 15:57:05 -04:00
|
|
|
{
|
2001-11-25 09:32:01 -05:00
|
|
|
wxFileDialog dialog
|
|
|
|
(
|
|
|
|
this,
|
|
|
|
_T("Testing open file dialog"),
|
|
|
|
_T(""),
|
|
|
|
_T(""),
|
2003-01-11 09:36:25 -05:00
|
|
|
#ifdef __WXMOTIF__
|
|
|
|
_T("C++ files (*.cpp)|*.cpp")
|
|
|
|
#else
|
2001-11-25 09:32:01 -05:00
|
|
|
_T("C++ files (*.h;*.cpp)|*.h;*.cpp")
|
2003-01-11 09:36:25 -05:00
|
|
|
#endif
|
2001-11-25 09:32:01 -05:00
|
|
|
);
|
1998-05-22 15:57:05 -04:00
|
|
|
|
2002-09-07 15:24:17 -04:00
|
|
|
dialog.SetDirectory(wxGetHomeDir());
|
|
|
|
|
1999-06-28 17:39:49 -04:00
|
|
|
if (dialog.ShowModal() == wxID_OK)
|
|
|
|
{
|
1999-03-23 10:52:39 -05:00
|
|
|
wxString info;
|
1999-04-25 12:31:27 -04:00
|
|
|
info.Printf(_T("Full file name: %s\n")
|
|
|
|
_T("Path: %s\n")
|
|
|
|
_T("Name: %s"),
|
1999-03-23 10:52:39 -05:00
|
|
|
dialog.GetPath().c_str(),
|
|
|
|
dialog.GetDirectory().c_str(),
|
|
|
|
dialog.GetFilename().c_str());
|
2002-06-09 18:19:24 -04:00
|
|
|
wxMessageDialog dialog2(this, info, _T("Selected file"));
|
1999-06-28 17:39:49 -04:00
|
|
|
dialog2.ShowModal();
|
|
|
|
}
|
1998-05-22 15:57:05 -04:00
|
|
|
}
|
|
|
|
|
2000-08-23 18:47:33 -04:00
|
|
|
// this shows how to take advantage of specifying a default extension in the
|
|
|
|
// call to wxFileSelector: it is remembered after each new call and the next
|
|
|
|
// one will use it by default
|
|
|
|
void MyFrame::FileOpen2(wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
|
|
|
static wxString s_extDef;
|
|
|
|
wxString path = wxFileSelector(
|
|
|
|
_T("Select the file to load"),
|
2002-06-21 07:18:19 -04:00
|
|
|
_T(""), _T(""),
|
2000-08-23 18:47:33 -04:00
|
|
|
s_extDef,
|
|
|
|
_T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (*.*)|*.*"),
|
2001-11-25 09:32:01 -05:00
|
|
|
wxCHANGE_DIR,
|
2000-08-23 18:47:33 -04:00
|
|
|
this
|
|
|
|
);
|
|
|
|
|
|
|
|
if ( !path )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// it is just a sample, would use wxSplitPath in real program
|
|
|
|
s_extDef = path.AfterLast(_T('.'));
|
|
|
|
|
|
|
|
wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
|
2000-09-01 04:35:30 -04:00
|
|
|
(const wxChar*) path, (const wxChar*) s_extDef);
|
2000-08-23 18:47:33 -04:00
|
|
|
}
|
|
|
|
|
1999-12-06 19:48:45 -05:00
|
|
|
void MyFrame::FilesOpen(wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
2002-06-09 18:19:24 -04:00
|
|
|
wxFileDialog dialog(this, _T("Testing open multiple file dialog"),
|
2002-07-02 05:05:45 -04:00
|
|
|
_T(""), _T(""), wxFileSelectorDefaultWildcardStr,
|
1999-12-07 09:15:23 -05:00
|
|
|
wxMULTIPLE);
|
1999-12-06 19:48:45 -05:00
|
|
|
|
|
|
|
if (dialog.ShowModal() == wxID_OK)
|
|
|
|
{
|
|
|
|
wxArrayString paths, filenames;
|
|
|
|
|
|
|
|
dialog.GetPaths(paths);
|
|
|
|
dialog.GetFilenames(filenames);
|
|
|
|
|
|
|
|
wxString msg, s;
|
|
|
|
size_t count = paths.GetCount();
|
|
|
|
for ( size_t n = 0; n < count; n++ )
|
|
|
|
{
|
|
|
|
s.Printf(_T("File %d: %s (%s)\n"),
|
2003-04-12 22:08:03 -04:00
|
|
|
(int)n, paths[n].c_str(), filenames[n].c_str());
|
1999-12-06 19:48:45 -05:00
|
|
|
|
|
|
|
msg += s;
|
|
|
|
}
|
|
|
|
|
2002-06-09 18:19:24 -04:00
|
|
|
wxMessageDialog dialog2(this, msg, _T("Selected files"));
|
1999-12-06 19:48:45 -05:00
|
|
|
dialog2.ShowModal();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-07-27 19:01:43 -04:00
|
|
|
void MyFrame::FileSave(wxCommandEvent& WXUNUSED(event) )
|
1998-05-22 15:57:05 -04:00
|
|
|
{
|
2002-06-21 07:18:19 -04:00
|
|
|
wxFileDialog dialog(this,
|
|
|
|
_T("Testing save file dialog"),
|
|
|
|
_T(""),
|
2002-12-04 09:11:26 -05:00
|
|
|
_T("myletter.doc"),
|
2002-06-21 07:18:19 -04:00
|
|
|
_T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"),
|
|
|
|
wxSAVE|wxOVERWRITE_PROMPT);
|
1999-06-28 17:39:49 -04:00
|
|
|
|
2002-12-04 09:11:26 -05:00
|
|
|
dialog.SetFilterIndex(1);
|
|
|
|
|
1999-06-28 17:39:49 -04:00
|
|
|
if (dialog.ShowModal() == wxID_OK)
|
|
|
|
{
|
2002-12-04 09:11:26 -05:00
|
|
|
wxLogMessage(_T("%s, filter %d"),
|
|
|
|
dialog.GetPath().c_str(), dialog.GetFilterIndex());
|
1999-06-28 17:39:49 -04:00
|
|
|
}
|
1998-05-22 15:57:05 -04:00
|
|
|
}
|
|
|
|
|
2003-02-01 17:51:07 -05:00
|
|
|
void MyFrame::DoDirChoose(int style)
|
1998-05-22 15:57:05 -04:00
|
|
|
{
|
1999-11-10 19:25:57 -05:00
|
|
|
// pass some initial dir to wxDirDialog
|
|
|
|
wxString dirHome;
|
|
|
|
wxGetHomeDir(&dirHome);
|
|
|
|
|
2003-02-01 17:51:07 -05:00
|
|
|
wxDirDialog dialog(this, _T("Testing directory picker"), dirHome, style);
|
1999-06-28 17:39:49 -04:00
|
|
|
|
|
|
|
if (dialog.ShowModal() == wxID_OK)
|
|
|
|
{
|
2002-12-04 09:11:26 -05:00
|
|
|
wxLogMessage(_T("Selected path: %s"), dialog.GetPath().c_str());
|
1999-06-28 17:39:49 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-01 17:51:07 -05:00
|
|
|
void MyFrame::DirChoose(wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
|
|
|
DoDirChoose(wxDD_DEFAULT_STYLE & ~wxDD_NEW_DIR_BUTTON);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::DirChooseNew(wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
2003-03-30 14:18:56 -05:00
|
|
|
DoDirChoose(wxDD_DEFAULT_STYLE | wxDD_NEW_DIR_BUTTON);
|
2003-02-01 17:51:07 -05:00
|
|
|
}
|
|
|
|
|
2002-04-03 11:01:44 -05:00
|
|
|
#if defined(__WXMSW__) || defined(__WXMAC__)
|
|
|
|
|
2000-07-23 15:10:27 -04:00
|
|
|
void MyFrame::GenericDirChoose(wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
2003-10-23 17:51:33 -04:00
|
|
|
#if !(defined(__WXMSW__) || defined(__WXMAC__)) || wxUSE_DIRDLGG
|
2000-07-23 15:10:27 -04:00
|
|
|
// pass some initial dir to wxDirDialog
|
|
|
|
wxString dirHome;
|
|
|
|
wxGetHomeDir(&dirHome);
|
|
|
|
|
2002-06-09 18:19:24 -04:00
|
|
|
wxGenericDirDialog dialog(this, _T("Testing generic directory picker"), dirHome);
|
2000-07-23 15:10:27 -04:00
|
|
|
|
|
|
|
if (dialog.ShowModal() == wxID_OK)
|
|
|
|
{
|
2002-06-09 18:19:24 -04:00
|
|
|
wxMessageDialog dialog2(this, dialog.GetPath(), _T("Selected path"));
|
2000-07-23 15:10:27 -04:00
|
|
|
dialog2.ShowModal();
|
|
|
|
}
|
2000-11-25 17:44:55 -05:00
|
|
|
#else
|
2001-09-21 16:21:44 -04:00
|
|
|
wxLogError(wxT("Sorry, generic dir dialog not available:\n")
|
|
|
|
wxT("set wxUSE_DIRDLGG to 1 and recompile"));
|
2000-11-25 17:44:55 -05:00
|
|
|
#endif
|
2000-07-23 15:10:27 -04:00
|
|
|
}
|
|
|
|
|
2002-04-03 11:01:44 -05:00
|
|
|
#endif // wxMSW || wxMAC
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
void MyFrame::ModalDlg(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
MyModalDialog dlg(this);
|
|
|
|
dlg.ShowModal();
|
|
|
|
}
|
|
|
|
|
2000-01-29 20:33:02 -05:00
|
|
|
void MyFrame::ModelessDlg(wxCommandEvent& event)
|
|
|
|
{
|
2000-08-25 11:51:23 -04:00
|
|
|
bool show = GetMenuBar()->IsChecked(event.GetId());
|
2000-01-29 20:33:02 -05:00
|
|
|
|
|
|
|
if ( show )
|
|
|
|
{
|
|
|
|
if ( !m_dialog )
|
|
|
|
{
|
|
|
|
m_dialog = new MyModelessDialog(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_dialog->Show(TRUE);
|
|
|
|
}
|
|
|
|
else // hide
|
|
|
|
{
|
|
|
|
m_dialog->Hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-09 16:24:34 -04:00
|
|
|
void MyFrame::ShowTip(wxCommandEvent& WXUNUSED(event))
|
1999-06-28 17:39:49 -04:00
|
|
|
{
|
1999-07-10 16:05:30 -04:00
|
|
|
#if wxUSE_STARTUP_TIPS
|
1999-06-28 17:39:49 -04:00
|
|
|
static size_t s_index = (size_t)-1;
|
|
|
|
|
|
|
|
if ( s_index == (size_t)-1 )
|
|
|
|
{
|
|
|
|
srand(time(NULL));
|
|
|
|
|
|
|
|
// this is completely bogus, we don't know how many lines are there
|
|
|
|
// in the file, but who cares, it's a demo only...
|
|
|
|
s_index = rand() % 5;
|
|
|
|
}
|
|
|
|
|
2002-06-21 07:18:19 -04:00
|
|
|
wxTipProvider *tipProvider = wxCreateFileTipProvider(_T("tips.txt"), s_index);
|
1999-06-28 17:39:49 -04:00
|
|
|
|
|
|
|
bool showAtStartup = wxShowTip(this, tipProvider);
|
|
|
|
|
|
|
|
if ( showAtStartup )
|
|
|
|
{
|
2002-06-21 07:18:19 -04:00
|
|
|
wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"),
|
1999-06-28 17:39:49 -04:00
|
|
|
wxOK | wxICON_INFORMATION, this);
|
|
|
|
}
|
1998-05-22 15:57:05 -04:00
|
|
|
|
1999-06-28 17:39:49 -04:00
|
|
|
s_index = tipProvider->GetCurrentTip();
|
|
|
|
delete tipProvider;
|
1999-07-10 16:05:30 -04:00
|
|
|
#endif
|
1998-05-22 15:57:05 -04:00
|
|
|
}
|
|
|
|
|
1998-07-27 19:01:43 -04:00
|
|
|
void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event) )
|
1998-05-22 15:57:05 -04:00
|
|
|
{
|
1999-06-28 17:39:49 -04:00
|
|
|
Close(TRUE);
|
1998-05-22 15:57:05 -04:00
|
|
|
}
|
|
|
|
|
2000-02-24 21:20:44 -05:00
|
|
|
#if wxUSE_PROGRESSDLG
|
|
|
|
|
|
|
|
void MyFrame::ShowProgress( wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
|
|
|
static const int max = 10;
|
|
|
|
|
2002-06-21 07:18:19 -04:00
|
|
|
wxProgressDialog dialog(_T("Progress dialog example"),
|
2002-06-09 18:19:24 -04:00
|
|
|
_T("An informative message"),
|
2000-02-24 21:20:44 -05:00
|
|
|
max, // range
|
|
|
|
this, // parent
|
|
|
|
wxPD_CAN_ABORT |
|
|
|
|
wxPD_APP_MODAL |
|
2002-07-02 18:30:31 -04:00
|
|
|
// wxPD_AUTO_HIDE | -- try this as well
|
2000-02-24 21:20:44 -05:00
|
|
|
wxPD_ELAPSED_TIME |
|
|
|
|
wxPD_ESTIMATED_TIME |
|
|
|
|
wxPD_REMAINING_TIME);
|
|
|
|
|
|
|
|
bool cont = TRUE;
|
2002-06-04 14:14:26 -04:00
|
|
|
for ( int i = 0; i <= max; i++ )
|
2000-02-24 21:20:44 -05:00
|
|
|
{
|
|
|
|
wxSleep(1);
|
|
|
|
if ( i == max )
|
|
|
|
{
|
2002-06-09 18:19:24 -04:00
|
|
|
cont = dialog.Update(i, _T("That's all, folks!"));
|
2000-02-24 21:20:44 -05:00
|
|
|
}
|
|
|
|
else if ( i == max / 2 )
|
|
|
|
{
|
2002-06-09 18:19:24 -04:00
|
|
|
cont = dialog.Update(i, _T("Only a half left (very long message)!"));
|
2000-02-24 21:20:44 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cont = dialog.Update(i);
|
|
|
|
}
|
2002-06-04 14:14:26 -04:00
|
|
|
|
|
|
|
if ( !cont )
|
|
|
|
{
|
2002-06-09 18:19:24 -04:00
|
|
|
if ( wxMessageBox(_T("Do you really want to cancel?"),
|
|
|
|
_T("Progress dialog question"), // caption
|
|
|
|
wxYES_NO | wxICON_QUESTION) == wxYES )
|
2002-06-04 14:14:26 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
dialog.Resume();
|
|
|
|
}
|
2000-02-24 21:20:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( !cont )
|
|
|
|
{
|
2001-09-21 16:21:44 -04:00
|
|
|
wxLogStatus(wxT("Progress dialog aborted!"));
|
2000-02-24 21:20:44 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-09-21 16:21:44 -04:00
|
|
|
wxLogStatus(wxT("Countdown from %d finished"), max);
|
2000-02-24 21:20:44 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // wxUSE_PROGRESSDLG
|
|
|
|
|
2001-10-29 08:21:29 -05:00
|
|
|
#if wxUSE_BUSYINFO
|
|
|
|
|
|
|
|
void MyFrame::ShowBusyInfo(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2001-10-29 09:32:42 -05:00
|
|
|
wxWindowDisabler disableAll;
|
|
|
|
|
2002-12-13 16:33:14 -05:00
|
|
|
wxBusyInfo info(_T("Working, please wait..."), this);
|
2001-10-29 08:21:29 -05:00
|
|
|
|
2002-09-07 15:24:17 -04:00
|
|
|
for ( int i = 0; i < 18; i++ )
|
2001-10-29 08:21:29 -05:00
|
|
|
{
|
2002-09-07 15:24:17 -04:00
|
|
|
//wxUsleep(100);
|
2001-10-29 08:21:29 -05:00
|
|
|
wxTheApp->Yield();
|
|
|
|
}
|
2002-09-07 15:24:17 -04:00
|
|
|
|
|
|
|
wxSleep(2);
|
|
|
|
//wxWakeUpIdle();
|
2001-10-29 08:21:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // wxUSE_BUSYINFO
|
|
|
|
|
2001-07-31 22:29:35 -04:00
|
|
|
#if wxUSE_FINDREPLDLG
|
|
|
|
|
|
|
|
void MyFrame::ShowReplaceDialog( wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
2001-11-18 18:06:43 -05:00
|
|
|
if ( m_dlgReplace )
|
|
|
|
{
|
|
|
|
delete m_dlgReplace;
|
|
|
|
m_dlgReplace = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_dlgReplace = new wxFindReplaceDialog
|
|
|
|
(
|
|
|
|
this,
|
|
|
|
&m_findData,
|
2002-06-09 18:19:24 -04:00
|
|
|
_T("Find and replace dialog"),
|
2001-11-18 18:06:43 -05:00
|
|
|
wxFR_REPLACEDIALOG
|
|
|
|
);
|
|
|
|
|
|
|
|
m_dlgReplace->Show(TRUE);
|
|
|
|
}
|
2001-07-31 22:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::ShowFindDialog( wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
2001-11-18 18:06:43 -05:00
|
|
|
if ( m_dlgFind )
|
|
|
|
{
|
|
|
|
delete m_dlgFind;
|
|
|
|
m_dlgFind = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_dlgFind = new wxFindReplaceDialog
|
|
|
|
(
|
|
|
|
this,
|
|
|
|
&m_findData,
|
2002-06-09 18:19:24 -04:00
|
|
|
_T("Find dialog"),
|
2001-11-18 18:06:43 -05:00
|
|
|
// just for testing
|
|
|
|
wxFR_NOWHOLEWORD
|
|
|
|
);
|
|
|
|
|
|
|
|
m_dlgFind->Show(TRUE);
|
|
|
|
}
|
2001-07-31 22:29:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static wxString DecodeFindDialogEventFlags(int flags)
|
|
|
|
{
|
|
|
|
wxString str;
|
2002-06-09 18:19:24 -04:00
|
|
|
str << (flags & wxFR_DOWN ? _T("down") : _T("up")) << _T(", ")
|
2002-06-21 07:18:19 -04:00
|
|
|
<< (flags & wxFR_WHOLEWORD ? _T("whole words only, ") : _T(""))
|
|
|
|
<< (flags & wxFR_MATCHCASE ? _T("") : _T("not "))
|
2002-06-09 18:19:24 -04:00
|
|
|
<< _T("case sensitive");
|
2001-07-31 22:29:35 -04:00
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnFindDialog(wxFindDialogEvent& event)
|
|
|
|
{
|
|
|
|
wxEventType type = event.GetEventType();
|
|
|
|
|
|
|
|
if ( type == wxEVT_COMMAND_FIND || type == wxEVT_COMMAND_FIND_NEXT )
|
|
|
|
{
|
2001-09-21 16:21:44 -04:00
|
|
|
wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
|
2002-08-17 12:29:05 -04:00
|
|
|
type == wxEVT_COMMAND_FIND_NEXT ? wxT("next ") : wxT(""),
|
2001-07-31 22:29:35 -04:00
|
|
|
event.GetFindString().c_str(),
|
|
|
|
DecodeFindDialogEventFlags(event.GetFlags()).c_str());
|
|
|
|
}
|
|
|
|
else if ( type == wxEVT_COMMAND_FIND_REPLACE ||
|
|
|
|
type == wxEVT_COMMAND_FIND_REPLACE_ALL )
|
|
|
|
{
|
2001-09-21 16:21:44 -04:00
|
|
|
wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
|
2002-08-17 12:29:05 -04:00
|
|
|
type == wxEVT_COMMAND_FIND_REPLACE_ALL ? _T("all ") : wxT(""),
|
2001-07-31 22:29:35 -04:00
|
|
|
event.GetFindString().c_str(),
|
|
|
|
event.GetReplaceString().c_str(),
|
|
|
|
DecodeFindDialogEventFlags(event.GetFlags()).c_str());
|
|
|
|
}
|
|
|
|
else if ( type == wxEVT_COMMAND_FIND_CLOSE )
|
|
|
|
{
|
2001-11-18 18:06:43 -05:00
|
|
|
wxFindReplaceDialog *dlg = event.GetDialog();
|
|
|
|
|
2002-07-02 18:30:31 -04:00
|
|
|
int idMenu;
|
2001-11-18 18:06:43 -05:00
|
|
|
const wxChar *txt;
|
|
|
|
if ( dlg == m_dlgFind )
|
|
|
|
{
|
|
|
|
txt = _T("Find");
|
2002-07-02 18:30:31 -04:00
|
|
|
idMenu = DIALOGS_FIND;
|
2001-11-18 18:06:43 -05:00
|
|
|
m_dlgFind = NULL;
|
|
|
|
}
|
|
|
|
else if ( dlg == m_dlgReplace )
|
|
|
|
{
|
|
|
|
txt = _T("Replace");
|
2002-07-02 18:30:31 -04:00
|
|
|
idMenu = DIALOGS_REPLACE;
|
2001-11-18 18:06:43 -05:00
|
|
|
m_dlgReplace = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
txt = _T("Unknown");
|
2002-07-02 18:30:31 -04:00
|
|
|
idMenu = -1;
|
2001-11-18 18:06:43 -05:00
|
|
|
|
2002-06-21 07:18:19 -04:00
|
|
|
wxFAIL_MSG( _T("unexpected event") );
|
2001-11-18 18:06:43 -05:00
|
|
|
}
|
|
|
|
|
2002-07-02 18:30:31 -04:00
|
|
|
wxLogMessage(wxT("%s dialog is being closed."), txt);
|
|
|
|
|
|
|
|
if ( idMenu != -1 )
|
|
|
|
{
|
|
|
|
GetMenuBar()->Check(idMenu, FALSE);
|
|
|
|
}
|
2001-07-31 22:29:35 -04:00
|
|
|
|
2001-11-18 18:06:43 -05:00
|
|
|
dlg->Destroy();
|
2001-07-31 22:29:35 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-09-21 16:21:44 -04:00
|
|
|
wxLogError(wxT("Unknown find dialog event!"));
|
2001-07-31 22:29:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // wxUSE_FINDREPLDLG
|
|
|
|
|
2000-02-24 21:20:44 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyCanvas
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
1998-07-27 19:01:43 -04:00
|
|
|
void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event) )
|
1998-05-22 15:57:05 -04:00
|
|
|
{
|
1999-06-28 17:39:49 -04:00
|
|
|
wxPaintDC dc(this);
|
1998-05-22 15:57:05 -04:00
|
|
|
dc.SetFont(wxGetApp().m_canvasFont);
|
|
|
|
dc.SetTextForeground(wxGetApp().m_canvasTextColour);
|
|
|
|
dc.SetBackgroundMode(wxTRANSPARENT);
|
2002-12-13 16:33:14 -05:00
|
|
|
dc.DrawText(_T("wxWindows common dialogs test application"), 10, 10);
|
1998-05-22 15:57:05 -04:00
|
|
|
}
|
|
|
|
|
2000-01-29 20:33:02 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyModelessDialog
|
|
|
|
// ----------------------------------------------------------------------------
|
1998-05-22 15:57:05 -04:00
|
|
|
|
2000-01-29 20:33:02 -05:00
|
|
|
MyModelessDialog::MyModelessDialog(wxWindow *parent)
|
2002-12-13 16:33:14 -05:00
|
|
|
: wxDialog(parent, -1, wxString(_T("Modeless dialog")))
|
2000-01-29 20:33:02 -05:00
|
|
|
{
|
2000-03-11 19:26:21 -05:00
|
|
|
wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
|
|
|
|
|
2002-06-09 18:19:24 -04:00
|
|
|
wxButton *btn = new wxButton(this, DIALOGS_MODELESS_BTN, _T("Press me"));
|
|
|
|
wxCheckBox *check = new wxCheckBox(this, -1, _T("Should be disabled"));
|
2000-03-11 19:26:21 -05:00
|
|
|
check->Disable();
|
|
|
|
|
|
|
|
sizerTop->Add(btn, 1, wxEXPAND | wxALL, 5);
|
|
|
|
sizerTop->Add(check, 1, wxEXPAND | wxALL, 5);
|
|
|
|
|
|
|
|
SetAutoLayout(TRUE);
|
|
|
|
SetSizer(sizerTop);
|
|
|
|
|
|
|
|
sizerTop->SetSizeHints(this);
|
|
|
|
sizerTop->Fit(this);
|
2000-01-29 20:33:02 -05:00
|
|
|
}
|
2000-02-24 21:20:44 -05:00
|
|
|
|
2001-08-20 19:01:17 -04:00
|
|
|
void MyModelessDialog::OnButton(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2002-06-21 07:18:19 -04:00
|
|
|
wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"),
|
2001-08-20 19:01:17 -04:00
|
|
|
wxOK | wxICON_INFORMATION, this);
|
|
|
|
}
|
|
|
|
|
2000-02-24 21:20:44 -05:00
|
|
|
void MyModelessDialog::OnClose(wxCloseEvent& event)
|
|
|
|
{
|
|
|
|
if ( event.CanVeto() )
|
|
|
|
{
|
2002-06-21 07:18:19 -04:00
|
|
|
wxMessageBox(_T("Use the menu item to close this dialog"),
|
2002-06-09 18:19:24 -04:00
|
|
|
_T("Modeless dialog"),
|
2000-02-24 21:20:44 -05:00
|
|
|
wxOK | wxICON_INFORMATION, this);
|
|
|
|
|
|
|
|
event.Veto();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyModalDialog
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
MyModalDialog::MyModalDialog(wxWindow *parent)
|
2002-06-23 14:55:43 -04:00
|
|
|
: wxDialog(parent, -1, wxString(_T("Modal dialog")))
|
2000-07-15 15:51:35 -04:00
|
|
|
{
|
|
|
|
wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
|
2003-02-25 07:33:35 -05:00
|
|
|
m_btnModal = new wxButton(this, -1, _T("&Modal dialog..."));
|
|
|
|
m_btnModeless = new wxButton(this, -1, _T("Mode&less dialog"));
|
2002-06-09 18:19:24 -04:00
|
|
|
m_btnDelete = new wxButton(this, -1, _T("&Delete button"));
|
2003-02-25 07:33:35 -05:00
|
|
|
|
2002-06-09 18:19:24 -04:00
|
|
|
wxButton *btnOk = new wxButton(this, wxID_CANCEL, _T("&Close"));
|
2003-02-25 07:33:35 -05:00
|
|
|
sizerTop->Add(m_btnModal, 0, wxALIGN_CENTER | wxALL, 5);
|
|
|
|
sizerTop->Add(m_btnModeless, 0, wxALIGN_CENTER | wxALL, 5);
|
2000-07-15 15:51:35 -04:00
|
|
|
sizerTop->Add(m_btnDelete, 0, wxALIGN_CENTER | wxALL, 5);
|
2002-03-05 20:24:27 -05:00
|
|
|
sizerTop->Add(btnOk, 0, wxALIGN_CENTER | wxALL, 5);
|
2000-07-15 15:51:35 -04:00
|
|
|
|
|
|
|
SetAutoLayout(TRUE);
|
|
|
|
SetSizer(sizerTop);
|
|
|
|
|
|
|
|
sizerTop->SetSizeHints(this);
|
|
|
|
sizerTop->Fit(this);
|
|
|
|
|
2003-02-25 07:33:35 -05:00
|
|
|
m_btnModal->SetFocus();
|
|
|
|
m_btnModal->SetDefault();
|
2000-07-15 15:51:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyModalDialog::OnButton(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
if ( event.GetEventObject() == m_btnDelete )
|
|
|
|
{
|
2003-02-25 07:33:35 -05:00
|
|
|
delete m_btnModal;
|
|
|
|
m_btnModal = NULL;
|
2000-07-15 15:51:35 -04:00
|
|
|
|
|
|
|
m_btnDelete->Disable();
|
|
|
|
}
|
2003-02-25 07:33:35 -05:00
|
|
|
else if ( event.GetEventObject() == m_btnModal )
|
2000-07-15 15:51:35 -04:00
|
|
|
{
|
2002-06-09 18:19:24 -04:00
|
|
|
wxGetTextFromUser(_T("Dummy prompt"),
|
|
|
|
_T("Modal dialog called from dialog"),
|
|
|
|
_T(""), this);
|
2000-07-15 15:51:35 -04:00
|
|
|
}
|
2003-02-25 07:33:35 -05:00
|
|
|
else if ( event.GetEventObject() == m_btnModeless )
|
|
|
|
{
|
|
|
|
(new MyModelessDialog(this))->Show();
|
|
|
|
}
|
2000-07-15 15:51:35 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
}
|