#include "wx/mdi.h"
#endif
-#ifdef __WINDOWS__
-#ifdef __WIN95__
-#include <wx/tbar95.h>
-#else
-#include <wx/tbarmsw.h>
-#endif
+#include <wx/toolbar.h>
+
+#ifdef __WXGTK__
+#include "mondrian.xpm"
+#include "bitmaps/new.xpm"
+#include "bitmaps/open.xpm"
+#include "bitmaps/save.xpm"
+#include "bitmaps/copy.xpm"
+#include "bitmaps/cut.xpm"
+#include "bitmaps/paste.xpm"
+#include "bitmaps/print.xpm"
+#include "bitmaps/help.xpm"
#endif
+
#include "mdi.h"
MyFrame *frame = NULL;
wxDEFAULT_FRAME | wxHSCROLL | wxVSCROLL);
// Give it an icon (this is ignored in MDI mode: uses resources)
-#ifdef __WINDOWS__
+#ifdef __WXMSW__
frame->SetIcon(wxIcon("mdi_icn"));
#endif
-#ifdef __X__
- frame->SetIcon(wxIcon("aiai.xbm"));
-#endif
// Make a menubar
wxMenu *file_menu = new wxMenu;
}
BEGIN_EVENT_TABLE(MyFrame, wxMDIParentFrame)
- EVT_MENU(MDI_QUIT, MyFrame::OnQuit)
EVT_MENU(MDI_ABOUT, MyFrame::OnAbout)
EVT_MENU(MDI_NEW_WINDOW, MyFrame::OnNewWindow)
EVT_SIZE(MyFrame::OnSize)
+ EVT_MENU(MDI_QUIT, MyFrame::OnQuit)
END_EVENT_TABLE()
// Define my frame constructor
wxTE_MULTILINE|wxSUNKEN_BORDER);
textWindow->SetValue("A help window");
-#ifdef __WINDOWS__
- toolBar = new TestRibbon(this, 0, 0, 100, 30, wxNO_BORDER, wxVERTICAL, 1);
- SetToolBar(toolBar);
+ CreateToolBar(wxNO_BORDER|wxTB_FLAT|wxTB_HORIZONTAL);
+ InitToolBar(GetToolBar());
+
+#ifdef __WXMSW__
+ // Accelerators
+ wxAcceleratorEntry entries[3];
+ entries[0].Set(wxACCEL_CTRL, (int) 'N', MDI_NEW_WINDOW);
+ entries[1].Set(wxACCEL_CTRL, (int) 'X', MDI_QUIT);
+ entries[2].Set(wxACCEL_CTRL, (int) 'A', MDI_ABOUT);
+ wxAcceleratorTable accel(3, entries);
+ SetAcceleratorTable(accel);
#endif
}
-void MyFrame::OnQuit(wxCommandEvent& event)
+void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) )
{
Close(TRUE);
}
-void MyFrame::OnAbout(wxCommandEvent& event)
+void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
{
(void)wxMessageBox("wxWindows 2.0 MDI Demo\nAuthor: Julian Smart (c) 1997\nUsage: mdi.exe", "About MDI Demo");
}
-void MyFrame::OnNewWindow(wxCommandEvent& event)
+void MyFrame::OnNewWindow(wxCommandEvent& WXUNUSED(event) )
{
// Make another frame, containing a canvas
- MyChild *subframe = new MyChild(frame, "Canvas Frame", wxPoint(10, 10), wxSize(300, 300),
+ MyChild *subframe = new MyChild(frame, "Canvas Frame", wxPoint(-1, -1), wxSize(-1, -1),
wxDEFAULT_FRAME);
- char titleBuf[100];
- sprintf(titleBuf, "Canvas Frame %d", winNumber);
- subframe->SetTitle(titleBuf);
+ wxString title;
+ title.Printf("Canvas Frame %d", winNumber);
+ subframe->SetTitle(title);
winNumber ++;
// Give it an icon (this is ignored in MDI mode: uses resources)
-#ifdef __WINDOWS__
+#ifdef __WXMSW__
subframe->SetIcon(wxIcon("chrt_icn"));
-#endif
-#ifdef __X__
- subframe->SetIcon(wxIcon("aiai.xbm"));
+#else
+ subframe->SetIcon(wxIcon(mondrian_xpm));
#endif
// Give it a status line
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);
}
return TRUE;
}
-void MyFrame::OnSize(wxSizeEvent& event)
+void MyFrame::OnSize(wxSizeEvent& WXUNUSED(event) )
{
int w, h;
GetClientSize(&w, &h);
- int tw = 0;
- int th = 0;
-#ifdef __WINDOWS__
- wxWindow* tbar = GetToolBar();
- if (tbar)
- {
- tbar->GetSize(&tw, &th);
- tbar->SetSize(w, th);
- }
-#endif
-
- textWindow->SetSize(0, th, 200, h-th);
- GetClientWindow()->SetSize(200, th, w - 200, h-th);
+ textWindow->SetSize(0, 0, 200, h);
+ GetClientWindow()->SetSize(200, 0, w - 200, h);
}
// Note that MDI_NEW_WINDOW and MDI_ABOUT commands get passed
my_children.DeleteObject(this);
}
-void MyChild::OnQuit(wxCommandEvent& event)
+void MyChild::OnQuit(wxCommandEvent& WXUNUSED(event))
{
Close(TRUE);
}
return TRUE;
}
-#ifdef __WINDOWS__
-
-BEGIN_EVENT_TABLE(TestRibbon, wxToolBar)
- EVT_PAINT(TestRibbon::OnPaint)
-END_EVENT_TABLE()
-
-TestRibbon::TestRibbon(wxFrame *frame, int x, int y, int w, int h,
- long style, int direction, int RowsOrColumns):
- wxToolBar(frame, -1, wxPoint(x, y), wxSize(w, h), style, direction, RowsOrColumns)
+void MyFrame::InitToolBar(wxToolBar* toolBar)
{
wxBitmap* bitmaps[8];
+#ifdef __WXMSW__
bitmaps[0] = new wxBitmap("icon1", wxBITMAP_TYPE_RESOURCE);
bitmaps[1] = new wxBitmap("icon2", wxBITMAP_TYPE_RESOURCE);
bitmaps[2] = new wxBitmap("icon3", wxBITMAP_TYPE_RESOURCE);
bitmaps[5] = new wxBitmap("icon6", wxBITMAP_TYPE_RESOURCE);
bitmaps[6] = new wxBitmap("icon7", wxBITMAP_TYPE_RESOURCE);
bitmaps[7] = new wxBitmap("icon8", wxBITMAP_TYPE_RESOURCE);
+#else
+ bitmaps[0] = new wxBitmap( new_xpm );
+ bitmaps[1] = new wxBitmap( open_xpm );
+ bitmaps[2] = new wxBitmap( save_xpm );
+ bitmaps[3] = new wxBitmap( copy_xpm );
+ bitmaps[4] = new wxBitmap( cut_xpm );
+ bitmaps[5] = new wxBitmap( paste_xpm );
+ bitmaps[6] = new wxBitmap( print_xpm );
+ bitmaps[7] = new wxBitmap( help_xpm );
+#endif
-#ifdef __WINDOWS__
+#ifdef __WXMSW__
int width = 24;
#else
int width = 16;
#endif
- int offX = 5;
int currentX = 5;
- AddTool(0, *bitmaps[0], wxNullBitmap, FALSE, currentX, -1, NULL, "New file");
+ toolBar->AddTool(0, *(bitmaps[0]), wxNullBitmap, FALSE, currentX, -1, NULL, "New file");
currentX += width + 5;
- AddTool(1, *bitmaps[1], wxNullBitmap, FALSE, currentX, -1, NULL, "Open file");
+ toolBar->AddTool(1, *bitmaps[1], wxNullBitmap, FALSE, currentX, -1, NULL, "Open file");
currentX += width + 5;
- AddTool(2, *bitmaps[2], wxNullBitmap, FALSE, currentX, -1, NULL, "Save file");
+ toolBar->AddTool(2, *bitmaps[2], wxNullBitmap, FALSE, currentX, -1, NULL, "Save file");
currentX += width + 5;
- AddSeparator();
- AddTool(3, *bitmaps[3], wxNullBitmap, FALSE, currentX, -1, NULL, "Copy");
+ toolBar->AddSeparator();
+ toolBar->AddTool(3, *bitmaps[3], wxNullBitmap, FALSE, currentX, -1, NULL, "Copy");
currentX += width + 5;
- AddTool(4, *bitmaps[4], wxNullBitmap, FALSE, currentX, -1, NULL, "Cut");
+ toolBar->AddTool(4, *bitmaps[4], wxNullBitmap, FALSE, currentX, -1, NULL, "Cut");
currentX += width + 5;
- AddTool(5, *bitmaps[5], wxNullBitmap, FALSE, currentX, -1, NULL, "Paste");
+ toolBar->AddTool(5, *bitmaps[5], wxNullBitmap, FALSE, currentX, -1, NULL, "Paste");
currentX += width + 5;
- AddSeparator();
- AddTool(6, *bitmaps[6], wxNullBitmap, FALSE, currentX, -1, NULL, "Print");
+ toolBar->AddSeparator();
+ toolBar->AddTool(6, *bitmaps[6], wxNullBitmap, FALSE, currentX, -1, NULL, "Print");
currentX += width + 5;
- AddSeparator();
- AddTool(7, *bitmaps[7], wxNullBitmap, TRUE, currentX, -1, NULL, "Help");
+ toolBar->AddSeparator();
+ toolBar->AddTool(7, *bitmaps[7], wxNullBitmap, TRUE, currentX, -1, NULL, "Help");
- CreateTools();
+ toolBar->Realize();
int i;
for (i = 0; i < 8; i++)
delete bitmaps[i];
}
-bool TestRibbon::OnLeftClick(int toolIndex, bool toggled)
-{
- char buf[200];
- sprintf(buf, "Clicked on tool %d", toolIndex);
- frame->SetStatusText(buf);
- return TRUE;
-}
-
-void TestRibbon::OnMouseEnter(int toolIndex)
-{
- char buf[200];
- if (toolIndex > -1)
- {
- sprintf(buf, "This is tool number %d", toolIndex);
- frame->SetStatusText(buf);
- }
- else frame->SetStatusText("");
-}
-
-void TestRibbon::OnPaint(wxPaintEvent& event)
-{
- wxToolBar::OnPaint(event);
-
- wxPaintDC dc(this);
-
- int w, h;
- GetSize(&w, &h);
- dc.SetPen(*wxBLACK_PEN);
- dc.SetBrush(*wxTRANSPARENT_BRUSH);
- dc.DrawLine(0, h-1, w, h-1);
-}
-
-#endif