1998-05-22 19:57:05 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: dialogs.cpp
|
|
|
|
// Purpose: Common dialogs demo
|
|
|
|
// Author: Julian Smart
|
|
|
|
// Modified by:
|
|
|
|
// Created: 04/01/98
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) Julian Smart and Markus Holzem
|
1999-06-28 21:39:49 +00:00
|
|
|
// Licence: wxWindows license
|
1998-05-22 19:57:05 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#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
|
|
|
|
|
1999-07-03 16:40:54 +00: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-25 02:20:44 +00:00
|
|
|
#include "wx/progdlg.h"
|
1998-05-22 19:57:05 +00:00
|
|
|
|
1998-10-02 12:50:01 +00:00
|
|
|
#define wxTEST_GENERIC_DIALOGS_IN_MSW 0
|
|
|
|
|
|
|
|
#if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
|
1998-05-22 19:57:05 +00:00
|
|
|
#include <wx/generic/colrdlgg.h>
|
|
|
|
#include <wx/generic/fontdlgg.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "dialogs.h"
|
|
|
|
|
|
|
|
IMPLEMENT_APP(MyApp)
|
|
|
|
|
2000-01-30 01:33:02 +00: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)
|
|
|
|
EVT_MENU(DIALOGS_FILE_OPEN, MyFrame::FileOpen)
|
|
|
|
EVT_MENU(DIALOGS_FILES_OPEN, MyFrame::FilesOpen)
|
|
|
|
EVT_MENU(DIALOGS_FILE_SAVE, MyFrame::FileSave)
|
|
|
|
EVT_MENU(DIALOGS_DIR_CHOOSE, MyFrame::DirChoose)
|
|
|
|
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-25 02:20:44 +00:00
|
|
|
#endif
|
|
|
|
#if wxUSE_PROGRESSDLG
|
|
|
|
EVT_MENU(DIALOGS_PROGRESS, MyFrame::ShowProgress)
|
2000-01-30 01:33:02 +00:00
|
|
|
#endif
|
|
|
|
EVT_MENU(wxID_EXIT, MyFrame::OnExit)
|
|
|
|
|
|
|
|
EVT_BUTTON(DIALOGS_MODELESS_BTN, MyFrame::OnButton)
|
|
|
|
END_EVENT_TABLE()
|
2000-02-25 02:20:44 +00:00
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(MyModelessDialog, wxDialog)
|
|
|
|
EVT_CLOSE(MyModelessDialog::OnClose)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
1998-08-23 03:22:56 +00:00
|
|
|
MyCanvas *myCanvas = (MyCanvas *) NULL;
|
1998-05-22 19:57:05 +00:00
|
|
|
|
|
|
|
// `Main program' equivalent, creating windows and returning main app frame
|
2000-01-30 01:33:02 +00:00
|
|
|
bool MyApp::OnInit()
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
1999-04-26 20:48:39 +00:00
|
|
|
#if defined(__WXGTK__) && defined(wxUSE_UNICODE)
|
1999-06-14 23:04:05 +00:00
|
|
|
wxConvCurrent = &wxConvLibc;
|
1999-04-26 20:48:39 +00:00
|
|
|
#endif
|
|
|
|
|
1998-05-22 19:57:05 +00:00
|
|
|
m_canvasTextColour = wxColour("BLACK");
|
1998-08-02 20:38:05 +00:00
|
|
|
m_canvasFont = *wxNORMAL_FONT;
|
1998-05-22 19:57:05 +00:00
|
|
|
|
|
|
|
// Create the main frame window
|
1999-11-05 15:54:10 +00:00
|
|
|
MyFrame *frame = new MyFrame((wxFrame *) NULL, (char *) "wxWindows dialogs example", wxPoint(20, 20), wxSize(400, 300));
|
1998-05-22 19:57:05 +00:00
|
|
|
|
|
|
|
// Make a menubar
|
|
|
|
wxMenu *file_menu = new wxMenu;
|
|
|
|
|
|
|
|
file_menu->Append(DIALOGS_CHOOSE_COLOUR, "&Choose colour");
|
|
|
|
|
1998-10-02 12:50:01 +00:00
|
|
|
#if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
|
1998-05-22 19:57:05 +00:00
|
|
|
file_menu->Append(DIALOGS_CHOOSE_COLOUR_GENERIC, "Choose colour (&generic)");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
file_menu->AppendSeparator();
|
|
|
|
file_menu->Append(DIALOGS_CHOOSE_FONT, "Choose &font");
|
|
|
|
|
1998-10-02 12:50:01 +00:00
|
|
|
#if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
|
1998-05-22 19:57:05 +00:00
|
|
|
file_menu->Append(DIALOGS_CHOOSE_FONT_GENERIC, "Choose f&ont (generic)");
|
|
|
|
|
|
|
|
#endif
|
|
|
|
file_menu->AppendSeparator();
|
2000-01-21 02:31:49 +00:00
|
|
|
file_menu->Append(DIALOGS_LOG_DIALOG, "&Log dialog\tCtrl-L");
|
1999-12-07 00:48:45 +00:00
|
|
|
file_menu->Append(DIALOGS_MESSAGE_BOX, "&Message box\tCtrl-M");
|
|
|
|
file_menu->Append(DIALOGS_TEXT_ENTRY, "Text &entry\tCtrl-E");
|
2000-01-24 18:26:54 +00:00
|
|
|
file_menu->Append(DIALOGS_PASSWORD_ENTRY, "&Password entry\tCtrl-P");
|
1999-07-22 23:39:47 +00:00
|
|
|
file_menu->Append(DIALOGS_NUM_ENTRY, "&Numeric entry\tCtrl-N");
|
2000-01-30 01:33:02 +00:00
|
|
|
file_menu->Append(DIALOGS_SINGLE_CHOICE, "&Single choice\tCtrl-C");
|
1998-05-22 19:57:05 +00:00
|
|
|
file_menu->AppendSeparator();
|
1999-12-07 00:48:45 +00:00
|
|
|
file_menu->Append(DIALOGS_TIP, "&Tip of the day\tCtrl-T");
|
1999-06-28 21:39:49 +00:00
|
|
|
file_menu->AppendSeparator();
|
1999-12-07 00:48:45 +00:00
|
|
|
file_menu->Append(DIALOGS_FILE_OPEN, "&Open file\tCtrl-O");
|
2000-01-24 18:26:54 +00:00
|
|
|
file_menu->Append(DIALOGS_FILES_OPEN, "Open &files\tCtrl-Q");
|
2000-01-30 01:33:02 +00:00
|
|
|
file_menu->Append(DIALOGS_FILE_SAVE, "Sa&ve file\tCtrl-S");
|
1999-12-07 00:48:45 +00:00
|
|
|
file_menu->Append(DIALOGS_DIR_CHOOSE, "&Choose a directory\tCtrl-D");
|
1998-05-22 19:57:05 +00:00
|
|
|
file_menu->AppendSeparator();
|
2000-02-25 02:20:44 +00:00
|
|
|
#if wxUSE_PROGRESSDLG
|
|
|
|
file_menu->Append(DIALOGS_PROGRESS, "Pro&gress dialog\tCtrl-G");
|
|
|
|
#endif // wxUSE_PROGRESSDLG
|
2000-01-30 01:33:02 +00:00
|
|
|
file_menu->Append(DIALOGS_MODELESS, "Modeless &dialog\tCtrl-Z", "", TRUE);
|
|
|
|
file_menu->AppendSeparator();
|
1999-12-07 00:48:45 +00:00
|
|
|
file_menu->Append(wxID_EXIT, "E&xit\tAlt-X");
|
1998-05-22 19:57:05 +00:00
|
|
|
wxMenuBar *menu_bar = new wxMenuBar;
|
|
|
|
menu_bar->Append(file_menu, "&File");
|
|
|
|
frame->SetMenuBar(menu_bar);
|
|
|
|
|
|
|
|
myCanvas = new MyCanvas(frame);
|
|
|
|
myCanvas->SetBackgroundColour(*wxWHITE);
|
|
|
|
|
|
|
|
frame->Centre(wxBOTH);
|
2000-01-21 02:31:49 +00:00
|
|
|
|
1998-05-22 19:57:05 +00:00
|
|
|
// Show the frame
|
|
|
|
frame->Show(TRUE);
|
|
|
|
|
|
|
|
SetTopWindow(frame);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// My frame constructor
|
2000-01-30 01:33:02 +00:00
|
|
|
MyFrame::MyFrame(wxWindow *parent,
|
|
|
|
const wxString& title,
|
|
|
|
const wxPoint& pos,
|
|
|
|
const wxSize& size)
|
|
|
|
: wxFrame(parent, -1, title, pos, size)
|
|
|
|
{
|
|
|
|
m_dialog = (MyModelessDialog *)NULL;
|
|
|
|
}
|
1998-05-22 19:57:05 +00:00
|
|
|
|
1998-07-27 23:01:43 +00:00
|
|
|
void MyFrame::ChooseColour(wxCommandEvent& WXUNUSED(event) )
|
1998-05-22 19:57:05 +00: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-21 02:31:49 +00:00
|
|
|
|
1998-05-22 19:57:05 +00:00
|
|
|
wxColourDialog *dialog = new wxColourDialog(this, &data);
|
|
|
|
if (dialog->ShowModal() == wxID_OK)
|
|
|
|
{
|
|
|
|
wxColourData retData = dialog->GetColourData();
|
|
|
|
wxColour col = retData.GetColour();
|
|
|
|
// wxBrush *brush = wxTheBrushList->FindOrCreateBrush(&col, wxSOLID);
|
|
|
|
myCanvas->SetBackgroundColour(col);
|
|
|
|
myCanvas->Clear();
|
|
|
|
myCanvas->Refresh();
|
|
|
|
}
|
1999-03-23 15:52:39 +00:00
|
|
|
dialog->Destroy();
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
1998-07-27 23:01:43 +00:00
|
|
|
void MyFrame::ChooseFont(wxCommandEvent& WXUNUSED(event) )
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
|
|
|
wxFontData data;
|
|
|
|
data.SetInitialFont(wxGetApp().m_canvasFont);
|
|
|
|
data.SetColour(wxGetApp().m_canvasTextColour);
|
2000-01-21 02:31:49 +00:00
|
|
|
|
1998-05-22 19:57:05 +00:00
|
|
|
wxFontDialog *dialog = new wxFontDialog(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 15:52:39 +00:00
|
|
|
dialog->Destroy();
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
1998-10-02 12:50:01 +00:00
|
|
|
#if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
|
1998-07-27 23:01:43 +00:00
|
|
|
void MyFrame::ChooseColourGeneric(wxCommandEvent& WXUNUSED(event))
|
1998-05-22 19:57:05 +00: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-21 02:31:49 +00:00
|
|
|
|
1998-05-22 19:57:05 +00: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);
|
|
|
|
myCanvas->Clear();
|
|
|
|
myCanvas->Refresh();
|
|
|
|
}
|
1999-03-23 15:52:39 +00:00
|
|
|
dialog->Destroy();
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
1998-07-27 23:01:43 +00:00
|
|
|
void MyFrame::ChooseFontGeneric(wxCommandEvent& WXUNUSED(event) )
|
1998-05-22 19:57:05 +00: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 15:52:39 +00:00
|
|
|
dialog->Destroy();
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
2000-01-21 02:31:49 +00:00
|
|
|
#endif // wxTEST_GENERIC_DIALOGS_IN_MSW
|
|
|
|
|
|
|
|
void MyFrame::LogDialog(wxCommandEvent& event)
|
|
|
|
{
|
2000-03-03 10:31:34 +00:00
|
|
|
// calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
|
|
|
|
// being flushed -- test it
|
|
|
|
{
|
|
|
|
wxBusyCursor bc;
|
|
|
|
wxLogMessage("This is some message - everything is ok so far.");
|
|
|
|
wxLogMessage("Another message...\n... this one is on multiple lines");
|
|
|
|
wxLogWarning("And then something went wrong!");
|
|
|
|
}
|
|
|
|
|
2000-01-21 02:31:49 +00:00
|
|
|
wxLogError("Intermediary error handler decided to abort.");
|
2000-02-15 23:57:33 +00:00
|
|
|
wxLogError("The top level caller detected an unrecoverable error.");
|
|
|
|
|
2000-01-28 20:56:19 +00:00
|
|
|
wxLog::FlushActive();
|
|
|
|
|
2000-02-08 19:22:40 +00:00
|
|
|
wxLogMessage("And this is the same dialog but with only one message.");
|
2000-01-21 02:31:49 +00:00
|
|
|
}
|
1998-05-22 19:57:05 +00:00
|
|
|
|
1998-07-27 23:01:43 +00:00
|
|
|
void MyFrame::MessageBox(wxCommandEvent& WXUNUSED(event) )
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
1999-11-03 14:24:42 +00:00
|
|
|
wxMessageDialog dialog( this, "This is a message box\nA long, long string to test out the message box properly",
|
1999-06-28 21:39:49 +00:00
|
|
|
"Message box text", wxYES_NO|wxCANCEL|wxICON_INFORMATION);
|
1998-05-22 19:57:05 +00:00
|
|
|
|
|
|
|
dialog.ShowModal();
|
|
|
|
}
|
|
|
|
|
1999-07-22 23:39:47 +00:00
|
|
|
void MyFrame::NumericEntry(wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
1999-08-04 14:41:41 +00:00
|
|
|
long res = wxGetNumberFromUser( "This is some text, actually a lot of text.\n"
|
|
|
|
"Even two rows of text.",
|
2000-01-21 02:31:49 +00:00
|
|
|
"Enter a number:", "Numeric input test",
|
1999-08-04 14:41:41 +00:00
|
|
|
50, 0, 100, this );
|
1999-07-22 23:39:47 +00:00
|
|
|
|
|
|
|
wxString msg;
|
|
|
|
int icon;
|
|
|
|
if ( res == -1 )
|
|
|
|
{
|
|
|
|
msg = "Invalid number entered or dialog cancelled.";
|
|
|
|
icon = wxICON_HAND;
|
|
|
|
}
|
|
|
|
else
|
2000-01-21 02:31:49 +00:00
|
|
|
{
|
|
|
|
msg.Printf(_T("You've entered %lu"), res );
|
1999-07-22 23:39:47 +00:00
|
|
|
icon = wxICON_INFORMATION;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxMessageBox(msg, "Numeric test result", wxOK | icon, this);
|
|
|
|
}
|
|
|
|
|
2000-01-24 18:26:54 +00:00
|
|
|
void MyFrame::PasswordEntry(wxCommandEvent& WXUNUSED(event))
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
2000-01-24 18:26:54 +00:00
|
|
|
wxString pwd = wxGetPasswordFromUser("Enter password:",
|
|
|
|
"Passowrd entry dialog",
|
|
|
|
"",
|
|
|
|
this);
|
|
|
|
if ( !!pwd )
|
|
|
|
{
|
|
|
|
wxMessageBox(wxString::Format("Your password is '%s'", pwd.c_str()),
|
|
|
|
"Got password", wxOK | wxICON_INFORMATION, this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::TextEntry(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxTextEntryDialog dialog(this,
|
|
|
|
"This is a small sample\n"
|
|
|
|
"A long, long string to test out the text entrybox",
|
|
|
|
"Please enter a string",
|
|
|
|
"Default value",
|
|
|
|
wxOK | wxCANCEL);
|
1998-05-22 19:57:05 +00:00
|
|
|
|
|
|
|
if (dialog.ShowModal() == wxID_OK)
|
|
|
|
{
|
1999-06-28 21:39:49 +00:00
|
|
|
wxMessageDialog dialog2(this, dialog.GetValue(), "Got string");
|
|
|
|
dialog2.ShowModal();
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-07-27 23:01:43 +00:00
|
|
|
void MyFrame::SingleChoice(wxCommandEvent& WXUNUSED(event) )
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
1998-05-28 11:13:25 +00:00
|
|
|
const wxString choices[] = { "One", "Two", "Three", "Four", "Five" } ;
|
|
|
|
int n = 5;
|
1998-05-22 19:57:05 +00:00
|
|
|
|
1998-05-28 11:13:25 +00:00
|
|
|
wxSingleChoiceDialog dialog(this, "This is a small sample\nA single-choice convenience dialog",
|
|
|
|
"Please select a value", n, (const wxString *)choices);
|
1998-05-22 19:57:05 +00:00
|
|
|
|
1998-05-28 11:13:25 +00:00
|
|
|
dialog.SetSelection(2);
|
|
|
|
|
|
|
|
if (dialog.ShowModal() == wxID_OK)
|
|
|
|
{
|
|
|
|
wxMessageDialog dialog2(this, dialog.GetStringSelection(), "Got string");
|
|
|
|
dialog2.ShowModal();
|
|
|
|
}
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
1998-07-27 23:01:43 +00:00
|
|
|
void MyFrame::FileOpen(wxCommandEvent& WXUNUSED(event) )
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
1999-06-28 21:39:49 +00:00
|
|
|
wxFileDialog dialog(this, "Testing open file dialog", "", "", "*.txt", 0);
|
1998-05-22 19:57:05 +00:00
|
|
|
|
1999-06-28 21:39:49 +00:00
|
|
|
if (dialog.ShowModal() == wxID_OK)
|
|
|
|
{
|
1999-03-23 15:52:39 +00:00
|
|
|
wxString info;
|
1999-04-25 16:31:27 +00:00
|
|
|
info.Printf(_T("Full file name: %s\n")
|
|
|
|
_T("Path: %s\n")
|
|
|
|
_T("Name: %s"),
|
1999-03-23 15:52:39 +00:00
|
|
|
dialog.GetPath().c_str(),
|
|
|
|
dialog.GetDirectory().c_str(),
|
|
|
|
dialog.GetFilename().c_str());
|
1999-06-28 21:39:49 +00:00
|
|
|
wxMessageDialog dialog2(this, info, "Selected file");
|
|
|
|
dialog2.ShowModal();
|
|
|
|
}
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
1999-12-07 00:48:45 +00:00
|
|
|
void MyFrame::FilesOpen(wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
|
|
|
wxFileDialog dialog(this, "Testing open multiple file dialog",
|
1999-12-07 14:15:23 +00:00
|
|
|
"", "", wxFileSelectorDefaultWildcardStr,
|
|
|
|
wxMULTIPLE);
|
1999-12-07 00:48:45 +00: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"),
|
|
|
|
n, paths[n].c_str(), filenames[n].c_str());
|
|
|
|
|
|
|
|
msg += s;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxMessageDialog dialog2(this, msg, "Selected files");
|
|
|
|
dialog2.ShowModal();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-07-27 23:01:43 +00:00
|
|
|
void MyFrame::FileSave(wxCommandEvent& WXUNUSED(event) )
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
1999-08-20 22:52:21 +00:00
|
|
|
wxFileDialog dialog(this, "Testing save file dialog", "", "myletter.txt",
|
1999-06-28 21:39:49 +00:00
|
|
|
"Text files (*.txt)|*.txt|Document files (*.doc)|*.doc",
|
|
|
|
wxSAVE|wxOVERWRITE_PROMPT);
|
|
|
|
|
|
|
|
if (dialog.ShowModal() == wxID_OK)
|
|
|
|
{
|
|
|
|
wxChar buf[400];
|
|
|
|
wxSprintf(buf, _T("%s, filter %d"), (const wxChar*)dialog.GetPath(), dialog.GetFilterIndex());
|
|
|
|
wxMessageDialog dialog2(this, wxString(buf), "Selected path");
|
|
|
|
dialog2.ShowModal();
|
|
|
|
}
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
1998-07-27 23:01:43 +00:00
|
|
|
void MyFrame::DirChoose(wxCommandEvent& WXUNUSED(event) )
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
1999-11-11 00:25:57 +00:00
|
|
|
// pass some initial dir to wxDirDialog
|
|
|
|
wxString dirHome;
|
|
|
|
wxGetHomeDir(&dirHome);
|
|
|
|
|
|
|
|
wxDirDialog dialog(this, "Testing directory picker", dirHome);
|
1999-06-28 21:39:49 +00:00
|
|
|
|
|
|
|
if (dialog.ShowModal() == wxID_OK)
|
|
|
|
{
|
|
|
|
wxMessageDialog dialog2(this, dialog.GetPath(), "Selected path");
|
|
|
|
dialog2.ShowModal();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-01-30 01:33:02 +00:00
|
|
|
void MyFrame::ModelessDlg(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
bool show = GetMenuBar()->IsChecked(event.GetInt());
|
|
|
|
|
|
|
|
if ( show )
|
|
|
|
{
|
|
|
|
if ( !m_dialog )
|
|
|
|
{
|
|
|
|
m_dialog = new MyModelessDialog(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_dialog->Show(TRUE);
|
|
|
|
}
|
|
|
|
else // hide
|
|
|
|
{
|
|
|
|
m_dialog->Hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnButton(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxMessageBox("Button pressed in modeless dialog", "Info",
|
|
|
|
wxOK | wxICON_INFORMATION, this);
|
|
|
|
}
|
|
|
|
|
1999-06-28 21:39:49 +00:00
|
|
|
void MyFrame::ShowTip(wxCommandEvent& event)
|
|
|
|
{
|
1999-07-10 20:05:30 +00:00
|
|
|
#if wxUSE_STARTUP_TIPS
|
1999-06-28 21:39:49 +00: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxTipProvider *tipProvider = wxCreateFileTipProvider("tips.txt", s_index);
|
|
|
|
|
|
|
|
bool showAtStartup = wxShowTip(this, tipProvider);
|
|
|
|
|
|
|
|
if ( showAtStartup )
|
|
|
|
{
|
|
|
|
wxMessageBox("Will show tips on startup", "Tips dialog",
|
|
|
|
wxOK | wxICON_INFORMATION, this);
|
|
|
|
}
|
1998-05-22 19:57:05 +00:00
|
|
|
|
1999-06-28 21:39:49 +00:00
|
|
|
s_index = tipProvider->GetCurrentTip();
|
|
|
|
delete tipProvider;
|
1999-07-10 20:05:30 +00:00
|
|
|
#endif
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
1998-07-27 23:01:43 +00:00
|
|
|
void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event) )
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
1999-06-28 21:39:49 +00:00
|
|
|
Close(TRUE);
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
2000-02-25 02:20:44 +00:00
|
|
|
#if wxUSE_PROGRESSDLG
|
|
|
|
|
|
|
|
void MyFrame::ShowProgress( wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
|
|
|
static const int max = 10;
|
|
|
|
|
|
|
|
wxProgressDialog dialog("Progress dialog example",
|
|
|
|
"An informative message",
|
|
|
|
max, // range
|
|
|
|
this, // parent
|
|
|
|
wxPD_CAN_ABORT |
|
|
|
|
wxPD_APP_MODAL |
|
|
|
|
wxPD_ELAPSED_TIME |
|
|
|
|
wxPD_ESTIMATED_TIME |
|
|
|
|
wxPD_REMAINING_TIME);
|
|
|
|
|
|
|
|
bool cont = TRUE;
|
|
|
|
for ( int i = 0; i <= max && cont; i++ )
|
|
|
|
{
|
|
|
|
wxSleep(1);
|
|
|
|
if ( i == max )
|
|
|
|
{
|
|
|
|
cont = dialog.Update(i, "That's all, folks!");
|
|
|
|
}
|
|
|
|
else if ( i == max / 2 )
|
|
|
|
{
|
|
|
|
cont = dialog.Update(i, "Only a half left (very long message)!");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cont = dialog.Update(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !cont )
|
|
|
|
{
|
|
|
|
wxLogStatus("Progress dialog aborted!");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxLogStatus("Countdown from %d finished", max);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // wxUSE_PROGRESSDLG
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyCanvas
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
1998-07-27 23:01:43 +00:00
|
|
|
void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event) )
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
1999-06-28 21:39:49 +00:00
|
|
|
wxPaintDC dc(this);
|
1998-05-22 19:57:05 +00:00
|
|
|
dc.SetFont(wxGetApp().m_canvasFont);
|
|
|
|
dc.SetTextForeground(wxGetApp().m_canvasTextColour);
|
|
|
|
dc.SetBackgroundMode(wxTRANSPARENT);
|
|
|
|
dc.DrawText("wxWindows common dialogs test application", 10, 10);
|
|
|
|
}
|
|
|
|
|
2000-01-30 01:33:02 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyModelessDialog
|
|
|
|
// ----------------------------------------------------------------------------
|
1998-05-22 19:57:05 +00:00
|
|
|
|
2000-01-30 01:33:02 +00:00
|
|
|
MyModelessDialog::MyModelessDialog(wxWindow *parent)
|
|
|
|
: wxDialog(parent, -1, wxString("Modeless dialog"))
|
|
|
|
{
|
2000-03-12 00:26:21 +00:00
|
|
|
wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
|
|
|
|
|
|
|
|
wxButton *btn = new wxButton(this, DIALOGS_MODELESS_BTN, "Press me");
|
|
|
|
wxCheckBox *check = new wxCheckBox(this, -1, "Should be disabled");
|
|
|
|
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-30 01:33:02 +00:00
|
|
|
}
|
2000-02-25 02:20:44 +00:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|