]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/dialogs/dialogs.cpp
Made wxInfoBar::SetFont() change the text message font.
[wxWidgets.git] / samples / dialogs / dialogs.cpp
index d81a728015e7bbbba7f22da0d251aa28270fb394..a45f416b92e05a50a123594f438a840d90f47d01 100644 (file)
@@ -1,11 +1,12 @@
 /////////////////////////////////////////////////////////////////////////////
 // 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"
 
@@ -133,6 +138,10 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
 #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)
@@ -260,8 +269,6 @@ BEGIN_EVENT_TABLE(StdButtonSizerDialog, wxDialog)
     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()
 {
@@ -272,11 +279,8 @@ 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;
@@ -399,9 +403,14 @@ bool MyApp::OnInit()
        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);
@@ -418,9 +427,9 @@ bool MyApp::OnInit()
 
     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
@@ -475,23 +484,15 @@ bool MyApp::OnInit()
 
     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);
 
@@ -520,6 +521,19 @@ MyFrame::MyFrame(wxWindow *parent,
 #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()
@@ -533,16 +547,16 @@ 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();
     }
 }
 
@@ -551,13 +565,13 @@ void MyFrame::GetColour(wxCommandEvent& WXUNUSED(event))
     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
 }
@@ -568,7 +582,7 @@ void MyFrame::GetColour(wxCommandEvent& WXUNUSED(event))
 #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);
@@ -587,9 +601,9 @@ void MyFrame::ChooseColourGeneric(wxCommandEvent& WXUNUSED(event))
     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();
 }
@@ -599,8 +613,8 @@ void MyFrame::ChooseColourGeneric(wxCommandEvent& WXUNUSED(event))
 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:
     //
@@ -612,9 +626,9 @@ void MyFrame::ChooseFont(wxCommandEvent& WXUNUSED(event) )
     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
 }
@@ -624,16 +638,16 @@ void MyFrame::ChooseFont(wxCommandEvent& WXUNUSED(event) )
 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();
 }
@@ -663,6 +677,24 @@ void MyFrame::LogDialog(wxCommandEvent& WXUNUSED(event))
 }
 #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))
 {
@@ -1689,7 +1721,13 @@ void MyFrame::ShowProgress( 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"));
@@ -1934,8 +1972,6 @@ void MyFrame::OnFindDialog(wxFindDialogEvent& event)
 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")