]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/sashtest/sashtest.cpp
Don't crash when creating wxStaticBox in wxGTK.
[wxWidgets.git] / samples / sashtest / sashtest.cpp
index 7db36a819a4b5c939969cff969ffe0a9d26ffddf..13b6a9df3dc3d79e97d92493ee27572e2f8c4853 100644 (file)
@@ -6,7 +6,7 @@
 // Created:     04/01/98
 // RCS-ID:      $Id$
 // Copyright:   (c) Julian Smart
-// Licence:     wxWindows license
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 // For compilers that support precompilation, includes "wx/wx.h".
@@ -40,32 +40,35 @@ int winNumber = 1;
 // Initialise this in OnInit, not statically
 bool MyApp::OnInit(void)
 {
+  if ( !wxApp::OnInit() )
+    return false;
+
   // Create the main frame window
 
-  frame = new MyFrame(NULL, wxID_ANY, _T("Sash Demo"), wxPoint(0, 0), wxSize(500, 400),
+  frame = new MyFrame(NULL, wxID_ANY, wxT("Sash Demo"), wxPoint(0, 0), wxSize(500, 400),
                       wxDEFAULT_FRAME_STYLE |
                       wxNO_FULL_REPAINT_ON_RESIZE |
                       wxHSCROLL | wxVSCROLL);
 
   // Give it an icon (this is ignored in MDI mode: uses resources)
 #ifdef __WXMSW__
-  frame->SetIcon(wxIcon(_T("sashtest_icn")));
+  frame->SetIcon(wxIcon(wxT("sashtest_icn")));
 #endif
 
   // Make a menubar
   wxMenu *file_menu = new wxMenu;
 
-  file_menu->Append(SASHTEST_NEW_WINDOW, _T("&New window"));
-  file_menu->Append(SASHTEST_TOGGLE_WINDOW, _T("&Toggle window"));
-  file_menu->Append(SASHTEST_QUIT, _T("&Exit"));
+  file_menu->Append(SASHTEST_NEW_WINDOW, wxT("&New window"));
+  file_menu->Append(SASHTEST_TOGGLE_WINDOW, wxT("&Toggle window"));
+  file_menu->Append(SASHTEST_QUIT, wxT("&Exit"));
 
   wxMenu *help_menu = new wxMenu;
-  help_menu->Append(SASHTEST_ABOUT, _T("&About"));
+  help_menu->Append(SASHTEST_ABOUT, wxT("&About"));
 
   wxMenuBar *menu_bar = new wxMenuBar;
 
-  menu_bar->Append(file_menu, _T("&File"));
-  menu_bar->Append(help_menu, _T("&Help"));
+  menu_bar->Append(file_menu, wxT("&File"));
+  menu_bar->Append(help_menu, wxT("&Help"));
 
   // Associate the menu bar with the frame
   frame->SetMenuBar(menu_bar);
@@ -76,8 +79,6 @@ bool MyApp::OnInit(void)
 
   frame->Show(true);
 
-  SetTopWindow(frame);
-
   return true;
 }
 
@@ -107,7 +108,7 @@ MyFrame::MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, c
   win->SetDefaultSize(wxSize(1000, 30));
   win->SetOrientation(wxLAYOUT_HORIZONTAL);
   win->SetAlignment(wxLAYOUT_TOP);
-  win->SetBackgroundColour(wxColour(255, 0, 0));
+  win->SetBackgroundColour(*wxRED);
   win->SetSashVisible(wxSASH_BOTTOM, true);
 
   m_topWindow = win;
@@ -119,7 +120,7 @@ MyFrame::MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, c
   win->SetDefaultSize(wxSize(1000, 30));
   win->SetOrientation(wxLAYOUT_HORIZONTAL);
   win->SetAlignment(wxLAYOUT_BOTTOM);
-  win->SetBackgroundColour(wxColour(0, 0, 255));
+  win->SetBackgroundColour(*wxBLUE);
   win->SetSashVisible(wxSASH_TOP, true);
 
   m_bottomWindow = win;
@@ -131,14 +132,14 @@ MyFrame::MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, c
   win->SetDefaultSize(wxSize(120, 1000));
   win->SetOrientation(wxLAYOUT_VERTICAL);
   win->SetAlignment(wxLAYOUT_LEFT);
-  win->SetBackgroundColour(wxColour(0, 255, 0));
+  win->SetBackgroundColour(*wxGREEN);
   win->SetSashVisible(wxSASH_RIGHT, true);
   win->SetExtraBorderSize(10);
 
-  wxTextCtrl* textWindow = new wxTextCtrl(win, wxID_ANY, _T(""), wxDefaultPosition, wxDefaultSize,
+  wxTextCtrl* textWindow = new wxTextCtrl(win, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize,
         wxTE_MULTILINE|wxSUNKEN_BORDER);
 //        wxTE_MULTILINE|wxNO_BORDER);
-  textWindow->SetValue(_T("A help window"));
+  textWindow->SetValue(wxT("A help window"));
 
   m_leftWindow1 = win;
 
@@ -162,7 +163,7 @@ void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
 
 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
 {
-      (void)wxMessageBox(_T("wxWidgets 2.0 Sash Demo\nAuthor: Julian Smart (c) 1998"), _T("About Sash Demo"));
+      (void)wxMessageBox(wxT("wxWidgets 2.0 Sash Demo\nAuthor: Julian Smart (c) 1998"), wxT("About Sash Demo"));
 }
 
 void MyFrame::OnToggleWindow(wxCommandEvent& WXUNUSED(event))
@@ -175,8 +176,10 @@ void MyFrame::OnToggleWindow(wxCommandEvent& WXUNUSED(event))
     {
         m_leftWindow1->Show(true);
     }
+#if wxUSE_MDI_ARCHITECTURE
     wxLayoutAlgorithm layout;
     layout.LayoutMDIFrame(this);
+#endif // wxUSE_MDI_ARCHITECTURE
 }
 
 void MyFrame::OnSashDrag(wxSashEvent& event)
@@ -207,8 +210,11 @@ void MyFrame::OnSashDrag(wxSashEvent& event)
             break;
         }
     }
+
+#if wxUSE_MDI_ARCHITECTURE
     wxLayoutAlgorithm layout;
     layout.LayoutMDIFrame(this);
+#endif // wxUSE_MDI_ARCHITECTURE
 
     // Leaves bits of itself behind sometimes
     GetClientWindow()->Refresh();
@@ -217,17 +223,17 @@ void MyFrame::OnSashDrag(wxSashEvent& event)
 void MyFrame::OnNewWindow(wxCommandEvent& WXUNUSED(event))
 {
       // Make another frame, containing a canvas
-      MyChild *subframe = new MyChild(frame, _T("Canvas Frame"),
+      MyChild *subframe = new MyChild(frame, wxT("Canvas Frame"),
                                       wxPoint(10, 10), wxSize(300, 300),
                                       wxDEFAULT_FRAME_STYLE |
                                       wxNO_FULL_REPAINT_ON_RESIZE);
 
-      subframe->SetTitle(wxString::Format(_T("Canvas Frame %d"), winNumber));
+      subframe->SetTitle(wxString::Format(wxT("Canvas Frame %d"), winNumber));
       winNumber ++;
 
       // Give it an icon (this is ignored in MDI mode: uses resources)
 #ifdef __WXMSW__
-      subframe->SetIcon(wxIcon(_T("sashtest_icn")));
+      subframe->SetIcon(wxIcon(wxT("sashtest_icn")));
 #endif
 
 #if wxUSE_STATUSBAR
@@ -238,23 +244,23 @@ void MyFrame::OnNewWindow(wxCommandEvent& WXUNUSED(event))
       // Make a menubar
       wxMenu *file_menu = new wxMenu;
 
-      file_menu->Append(SASHTEST_NEW_WINDOW, _T("&New window"));
-      file_menu->Append(SASHTEST_CHILD_QUIT, _T("&Close child"));
-      file_menu->Append(SASHTEST_QUIT, _T("&Exit"));
+      file_menu->Append(SASHTEST_NEW_WINDOW, wxT("&New window"));
+      file_menu->Append(SASHTEST_CHILD_QUIT, wxT("&Close child"));
+      file_menu->Append(SASHTEST_QUIT, wxT("&Exit"));
 
       wxMenu *option_menu = new wxMenu;
 
       // Dummy option
-      option_menu->Append(SASHTEST_REFRESH, _T("&Refresh picture"));
+      option_menu->Append(SASHTEST_REFRESH, wxT("&Refresh picture"));
 
       wxMenu *help_menu = new wxMenu;
-      help_menu->Append(SASHTEST_ABOUT, _T("&About"));
+      help_menu->Append(SASHTEST_ABOUT, wxT("&About"));
 
       wxMenuBar *menu_bar = new wxMenuBar;
 
-      menu_bar->Append(file_menu, _T("&File"));
-      menu_bar->Append(option_menu, _T("&Options"));
-      menu_bar->Append(help_menu, _T("&Help"));
+      menu_bar->Append(file_menu, wxT("&File"));
+      menu_bar->Append(option_menu, wxT("&Options"));
+      menu_bar->Append(help_menu, wxT("&Help"));
 
       // Associate the menu bar with the frame
       subframe->SetMenuBar(menu_bar);
@@ -286,29 +292,29 @@ MyCanvas::MyCanvas(wxWindow *parent, const wxPoint& pos, const wxSize& size)
 // Define the repainting behaviour
 void MyCanvas::OnDraw(wxDC& dc)
 {
-  dc.SetFont(*wxSWISS_FONT);
-  dc.SetPen(*wxGREEN_PEN);
-  dc.DrawLine(0, 0, 200, 200);
-  dc.DrawLine(200, 0, 0, 200);
+    dc.SetFont(*wxSWISS_FONT);
+    dc.SetPen(*wxGREEN_PEN);
+    dc.DrawLine(0, 0, 200, 200);
+    dc.DrawLine(200, 0, 0, 200);
 
-  dc.SetBrush(*wxCYAN_BRUSH);
-  dc.SetPen(*wxRED_PEN);
-  dc.DrawRectangle(100, 100, 100, 50);
-  dc.DrawRoundedRectangle(150, 150, 100, 50, 20);
+    dc.SetBrush(*wxCYAN_BRUSH);
+    dc.SetPen(*wxRED_PEN);
+    dc.DrawRectangle(100, 100, 100, 50);
+    dc.DrawRoundedRectangle(150, 150, 100, 50, 20);
 
-  dc.DrawEllipse(250, 250, 100, 50);
+    dc.DrawEllipse(250, 250, 100, 50);
 #if wxUSE_SPLINES
-  dc.DrawSpline(50, 200, 50, 100, 200, 10);
+    dc.DrawSpline(50, 200, 50, 100, 200, 10);
 #endif // wxUSE_SPLINES
-  dc.DrawLine(50, 230, 200, 230);
-  dc.DrawText(_T("This is a test string"), 50, 230);
-
-  wxPoint points[3];
-  points[0].x = 200; points[0].y = 300;
-  points[1].x = 100; points[1].y = 400;
-  points[2].x = 300; points[2].y = 400;
-  
-  dc.DrawPolygon(3, points);
+    dc.DrawLine(50, 230, 200, 230);
+    dc.DrawText(wxT("This is a test string"), 50, 230);
+
+    wxPoint points[3];
+    points[0].x = 200; points[0].y = 300;
+    points[1].x = 100; points[1].y = 400;
+    points[2].x = 300; points[2].y = 400;
+
+    dc.DrawPolygon(3, points);
 }
 
 // This implements a tiny doodling program! Drag the mouse using
@@ -331,8 +337,10 @@ void MyCanvas::OnEvent(wxMouseEvent& event)
 
 void MyFrame::OnSize(wxSizeEvent& WXUNUSED(event))
 {
+#if wxUSE_MDI_ARCHITECTURE
     wxLayoutAlgorithm layout;
     layout.LayoutMDIFrame(this);
+#endif // wxUSE_MDI_ARCHITECTURE
 }
 
 // Note that SASHTEST_NEW_WINDOW and SASHTEST_ABOUT commands get passed
@@ -366,4 +374,3 @@ void MyChild::OnActivate(wxActivateEvent& event)
   if (event.GetActive() && canvas)
     canvas->SetFocus();
 }
-