/////////////////////////////////////////////////////////////////////////////
// Name: dialogs.cpp
// Purpose: Common dialogs demo
-// Author: Julian Smart
-// Modified by: ABX (2004) - adjustements for conditional building + new menu
+// Author: Julian Smart, Vadim Zeitlin, ABX
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
+// (c) 2004 ABX
+// (c) Vadim Zeitlin
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#include "wx/fdrepdlg.h"
#endif // wxUSE_FINDREPLDLG
+#if wxUSE_INFOBAR
+ #include "wx/infobar.h"
+#endif // wxUSE_INFOBAR
+
#include "wx/spinctrl.h"
#include "wx/propdlg.h"
#if wxUSE_LOG_DIALOG
EVT_MENU(DIALOGS_LOG_DIALOG, MyFrame::LogDialog)
#endif // wxUSE_LOG_DIALOG
+#if wxUSE_INFOBAR
+ EVT_MENU(DIALOGS_INFOBAR_SIMPLE, MyFrame::InfoBarSimple)
+ EVT_MENU(DIALOGS_INFOBAR_ADVANCED, MyFrame::InfoBarAdvanced)
+#endif // wxUSE_INFOBAR
#if wxUSE_TEXTDLG
EVT_MENU(DIALOGS_TEXT_ENTRY, MyFrame::TextEntry)
EVT_RADIOBUTTON(wxID_ANY, StdButtonSizerDialog::OnEvent)
END_EVENT_TABLE()
-MyCanvas *myCanvas = (MyCanvas *) NULL;
-
// `Main program' equivalent, creating windows and returning main app frame
bool MyApp::OnInit()
{
wxInitAllImageHandlers();
#endif
- m_canvasTextColour = *wxBLACK;
- m_canvasFont = *wxNORMAL_FONT;
-
// Create the main frame window
- MyFrame *frame = new MyFrame((wxFrame *) NULL, wxT("wxWidgets dialogs example"));
+ MyFrame *frame = new MyFrame(wxT("wxWidgets dialogs example"));
// Make a menubar
wxMenu *menuDlg = new wxMenu;
info_menu->Append(DIALOGS_LOG_DIALOG, wxT("&Log dialog\tCtrl-L"));
#endif // wxUSE_LOG_DIALOG
+ #if wxUSE_INFOBAR
+ info_menu->Append(DIALOGS_INFOBAR_SIMPLE, "Simple &info bar\tCtrl-I");
+ info_menu->Append(DIALOGS_INFOBAR_ADVANCED, "&Advanced info bar\tShift-Ctrl-I");
+ #endif // wxUSE_INFOBAR
+
#if wxUSE_MSGDLG
info_menu->Append(DIALOGS_MESSAGE_BOX_WXINFO,
- wxT("&wxWidgets information\tCtrl-I"));
+ wxT("&wxWidgets information\tCtrl-W"));
#endif // wxUSE_MSGDLG
menuDlg->Append(wxID_ANY,wxT("&Informative dialogs"),info_menu);
wxMenu *dialogs_menu = new wxMenu;
#if USE_MODAL_PRESENTATION
- dialogs_menu->Append(DIALOGS_MODAL, wxT("&Modal dialog\tCtrl-W"));
+ dialogs_menu->Append(DIALOGS_MODAL, wxT("&Modal dialog\tShift-Ctrl-W"));
#endif // USE_MODAL_PRESENTATION
- dialogs_menu->AppendCheckItem(DIALOGS_MODELESS, wxT("Mode&less dialog\tCtrl-Z"));
+ dialogs_menu->AppendCheckItem(DIALOGS_MODELESS, wxT("Mode&less dialog\tShift-Ctrl-Z"));
dialogs_menu->Append(DIALOGS_CENTRE_SCREEN, wxT("Centered on &screen\tShift-Ctrl-1"));
dialogs_menu->Append(DIALOGS_CENTRE_PARENT, wxT("Centered on &parent\tShift-Ctrl-2"));
#if wxUSE_MINIFRAME
frame->SetMenuBar(menubar);
- myCanvas = new MyCanvas(frame);
- myCanvas->SetBackgroundColour(*wxWHITE);
-
frame->Centre(wxBOTH);
-
- // Show the frame
frame->Show(true);
- SetTopWindow(frame);
-
return true;
}
// My frame constructor
-MyFrame::MyFrame(wxWindow *parent,
- const wxString& title)
- : wxFrame(parent, wxID_ANY, title)
+MyFrame::MyFrame(const wxString& title)
+ : wxFrame(NULL, wxID_ANY, title)
{
SetIcon(sample_xpm);
#if wxUSE_STATUSBAR
CreateStatusBar();
#endif // wxUSE_STATUSBAR
+
+ m_canvas = new MyCanvas(this);
+
+#if wxUSE_INFOBAR
+ m_infoBarSimple = new wxInfoBar(this);
+ m_infoBarAdvanced = NULL;
+
+ // to use the info bars we need to use sizer for the window layout
+ wxBoxSizer * const sizer = new wxBoxSizer(wxVERTICAL);
+ sizer->Add(m_infoBarSimple, wxSizerFlags().Expand());
+ sizer->Add(m_canvas, wxSizerFlags(1).Expand());
+ SetSizer(sizer);
+#endif // wxUSE_INFOBAR
}
MyFrame::~MyFrame()
void MyFrame::ChooseColour(wxCommandEvent& WXUNUSED(event))
{
- m_clrData.SetColour(myCanvas->GetBackgroundColour());
+ m_clrData.SetColour(m_canvas->GetBackgroundColour());
wxColourDialog dialog(this, &m_clrData);
dialog.SetTitle(_("Please choose the background colour"));
if ( dialog.ShowModal() == wxID_OK )
{
m_clrData = dialog.GetColourData();
- myCanvas->SetBackgroundColour(m_clrData.GetColour());
- myCanvas->ClearBackground();
- myCanvas->Refresh();
+ m_canvas->SetBackgroundColour(m_clrData.GetColour());
+ m_canvas->ClearBackground();
+ m_canvas->Refresh();
}
}
wxColour clr = wxGetColourFromUser
(
this,
- wxGetApp().m_canvasTextColour,
+ m_canvas->GetForegroundColour(),
"Please choose the foreground colour"
);
if ( clr.IsOk() )
{
- wxGetApp().m_canvasTextColour = clr;
- myCanvas->Refresh();
+ m_canvas->SetForegroundColour(clr);
+ m_canvas->Refresh();
}
//else: dialog cancelled by user
}
#if USE_COLOURDLG_GENERIC
void MyFrame::ChooseColourGeneric(wxCommandEvent& WXUNUSED(event))
{
- m_clrData.SetColour(myCanvas->GetBackgroundColour());
+ m_clrData.SetColour(m_canvas->GetBackgroundColour());
//FIXME:TODO:This has no effect...
m_clrData.SetChooseFull(true);
if (dialog->ShowModal() == wxID_OK)
{
m_clrData = dialog->GetColourData();
- myCanvas->SetBackgroundColour(m_clrData.GetColour());
- myCanvas->ClearBackground();
- myCanvas->Refresh();
+ m_canvas->SetBackgroundColour(m_clrData.GetColour());
+ m_canvas->ClearBackground();
+ m_canvas->Refresh();
}
dialog->Destroy();
}
void MyFrame::ChooseFont(wxCommandEvent& WXUNUSED(event) )
{
wxFontData data;
- data.SetInitialFont(wxGetApp().m_canvasFont);
- data.SetColour(wxGetApp().m_canvasTextColour);
+ data.SetInitialFont(m_canvas->GetFont());
+ data.SetColour(m_canvas->GetForegroundColour());
// you might also do this:
//
if (dialog.ShowModal() == wxID_OK)
{
wxFontData retData = dialog.GetFontData();
- wxGetApp().m_canvasFont = retData.GetChosenFont();
- wxGetApp().m_canvasTextColour = retData.GetColour();
- myCanvas->Refresh();
+ m_canvas->SetFont(retData.GetChosenFont());
+ m_canvas->SetForegroundColour(retData.GetColour());
+ m_canvas->Refresh();
}
//else: cancelled by the user, don't change the font
}
void MyFrame::ChooseFontGeneric(wxCommandEvent& WXUNUSED(event) )
{
wxFontData data;
- data.SetInitialFont(wxGetApp().m_canvasFont);
- data.SetColour(wxGetApp().m_canvasTextColour);
+ data.SetInitialFont(m_canvas->GetFont());
+ data.SetColour(m_canvas->GetForegroundColour());
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();
+ m_canvas->SetFont(retData.GetChosenFont());
+ m_canvas->SetForegroundColour(retData.GetColour());
+ m_canvas->Refresh();
}
dialog->Destroy();
}
}
#endif // wxUSE_LOG_DIALOG
+#if wxUSE_INFOBAR
+
+void MyFrame::InfoBarSimple(wxCommandEvent& WXUNUSED(event))
+{
+ static int s_count = 0;
+ m_infoBarSimple->ShowMessage
+ (
+ wxString::Format("Message #%d in the info bar.", ++s_count)
+ );
+}
+
+void MyFrame::InfoBarAdvanced(wxCommandEvent& WXUNUSED(event))
+{
+}
+
+#endif // wxUSE_INFOBAR
+
+
#if wxUSE_MSGDLG
void MyFrame::MessageBox(wxCommandEvent& WXUNUSED(event))
{
static void InitAboutInfoMinimal(wxAboutDialogInfo& info)
{
info.SetName(wxT("Dialogs Sample"));
- info.SetVersion(wxVERSION_NUM_DOT_STRING_T);
+ info.SetVersion(wxVERSION_NUM_DOT_STRING,
+ wxString::Format
+ (
+ "%s version %s",
+ wxMINOR_VERSION % 2 ? "Development" : "Stable",
+ wxVERSION_NUM_DOT_STRING
+ ));
info.SetDescription(wxT("This sample shows different wxWidgets dialogs"));
info.SetCopyright(wxT("(C) 1998-2006 wxWidgets dev team"));
info.AddDeveloper(wxT("Vadim Zeitlin"));
void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event) )
{
wxPaintDC dc(this);
- dc.SetFont(wxGetApp().m_canvasFont);
- dc.SetTextForeground(wxGetApp().m_canvasTextColour);
dc.SetBackgroundMode(wxTRANSPARENT);
dc.DrawText(
wxT("wxWidgets common dialogs")