]> git.saurik.com Git - wxWidgets.git/blame - samples/minifram/test.cpp
now we can even edit again
[wxWidgets.git] / samples / minifram / test.cpp
CommitLineData
b2b3ccc5
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: test.cpp
3// Purpose: wxMiniFrame sample
4// Author: Robert Roebling
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Robert Roebling
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// For compilers that support precompilation, includes "wx/wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16#pragma hdrstop
17#endif
18
19#ifndef WX_PRECOMP
20#include "wx/wx.h"
21#endif
22
23#include "wx/toolbar.h"
24#include "test.h"
25
26#if defined(__WXGTK__) || defined(__WXMOTIF__)
27#include "mondrian.xpm"
28#include "bitmaps/new.xpm"
29#include "bitmaps/open.xpm"
30#include "bitmaps/save.xpm"
31#include "bitmaps/copy.xpm"
32#include "bitmaps/cut.xpm"
33// #include "bitmaps/paste.xpm"
34#include "bitmaps/print.xpm"
35#include "bitmaps/preview.xpm"
36#include "bitmaps/help.xpm"
37#endif
38
39IMPLEMENT_APP(MyApp)
40
41
42// The `main program' equivalent, creating the windows and returning the
43// main frame
44bool MyApp::OnInit(void)
45{
46 // Create the main frame window
47 MyFrame* frame = new MyFrame((wxFrame *) NULL, -1, (const wxString) "wxMiniFrame sample",
907789a0 48 wxPoint(100, 100), wxSize(205, 45));
b2b3ccc5
RR
49
50#ifdef __WXMSW__
51 frame->SetIcon(wxIcon("mondrian"));
52#else
53 frame->SetIcon( wxIcon(mondrian_xpm) );
54#endif
55
56 // Create the toolbar
57 frame->CreateToolBar(wxNO_BORDER|wxHORIZONTAL|wxTB_FLAT, ID_TOOLBAR);
58
59 InitToolbar(frame->GetToolBar());
60
61 frame->Show(TRUE);
62 SetTopWindow(frame);
63
64 return TRUE;
65}
66
67bool MyApp::InitToolbar(wxToolBar* toolBar)
68{
69 toolBar->SetMargins(5, 5);
70
71 // Set up toolbar
72 wxBitmap* toolBarBitmaps[8];
73
74#ifdef __WXMSW__
75 toolBarBitmaps[0] = new wxBitmap("icon1");
76 toolBarBitmaps[1] = new wxBitmap("icon2");
77 toolBarBitmaps[2] = new wxBitmap("icon3");
78 toolBarBitmaps[3] = new wxBitmap("icon4");
79 toolBarBitmaps[4] = new wxBitmap("icon5");
80 toolBarBitmaps[5] = new wxBitmap("icon6");
81 toolBarBitmaps[6] = new wxBitmap("icon7");
82 toolBarBitmaps[7] = new wxBitmap("icon8");
83#else
84 toolBarBitmaps[0] = new wxBitmap( new_xpm );
85 toolBarBitmaps[1] = new wxBitmap( open_xpm );
86 toolBarBitmaps[2] = new wxBitmap( save_xpm );
87 toolBarBitmaps[3] = new wxBitmap( copy_xpm );
88 toolBarBitmaps[4] = new wxBitmap( cut_xpm );
89// toolBarBitmaps[5] = new wxBitmap( paste_xpm );
90 toolBarBitmaps[5] = new wxBitmap( preview_xpm );
91 toolBarBitmaps[6] = new wxBitmap( print_xpm );
92 toolBarBitmaps[7] = new wxBitmap( help_xpm );
93#endif
94
95#ifdef __WXMSW__
96 int width = 24;
97#else
98 int width = 16;
99#endif
100 int currentX = 5;
101
102 toolBar->AddTool(wxID_NEW, *(toolBarBitmaps[0]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "New file");
103 currentX += width + 5;
104 toolBar->AddTool(wxID_OPEN, *(toolBarBitmaps[1]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Open file");
105 currentX += width + 5;
106 toolBar->AddTool(wxID_SAVE, *(toolBarBitmaps[2]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Save file");
107 currentX += width + 5;
108 toolBar->AddSeparator();
109 toolBar->AddTool(wxID_COPY, *(toolBarBitmaps[3]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Copy");
110 currentX += width + 5;
111 toolBar->AddTool(wxID_CUT, *(toolBarBitmaps[4]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Cut");
112 currentX += width + 5;
113 toolBar->AddTool(wxID_PASTE, *(toolBarBitmaps[5]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Paste");
114 currentX += width + 5;
115 toolBar->AddSeparator();
116 toolBar->AddTool(wxID_PRINT, *(toolBarBitmaps[6]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Print");
117 currentX += width + 5;
118 toolBar->AddSeparator();
119 toolBar->AddTool(wxID_HELP, *(toolBarBitmaps[7]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Help");
120
121 toolBar->Realize();
2b1c162e
RR
122
123 toolBar->EnableTool( wxID_HELP, FALSE );
b2b3ccc5
RR
124
125 // Can delete the bitmaps since they're reference counted
126 int i;
127 for (i = 0; i < 8; i++)
128 delete toolBarBitmaps[i];
129
130 return TRUE;
131}
132
133BEGIN_EVENT_TABLE(MyFrame, wxMiniFrame)
134 EVT_CLOSE(MyFrame::OnCloseWindow)
135END_EVENT_TABLE()
136
137// Define my frame constructor
138MyFrame::MyFrame(wxFrame* parent, wxWindowID id, const wxString& title, const wxPoint& pos,
139 const wxSize& size ) :
140 wxMiniFrame(parent, id, title, pos, size )
141{
142}
143
144// - must delete all frames except for the main one.
145void MyFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
146{
147 Destroy();
148}
149