~ubuntu-dev/wxwidgets2.6/upstream-debian

« back to all changes in this revision

Viewing changes to contrib/samples/gizmos/multicell/mtest.cpp

  • Committer: Daniel T Chen
  • Date: 2006-06-26 10:15:11 UTC
  • Revision ID: crimsun@ubuntu.com-20060626101511-a4436cec4c6d9b35
ImportĀ DebianĀ 2.6.3.2.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * File:    mtest.cpp
 
3
 * Purpose: wxMultiCellSizer and wxMultiCellCanvas test
 
4
 * Author:  Alex Andruschak
 
5
 * Created: 2000
 
6
 * Updated:
 
7
 * Copyright:
 
8
 * License: wxWindows licence
 
9
 */
 
10
 
 
11
#if defined(__GNUG__) && !defined(__APPLE__)
 
12
    #pragma implementation
 
13
    #pragma interface
 
14
#endif
 
15
 
 
16
#include "wx/wxprec.h"
 
17
 
 
18
#ifdef __BORLANDC__
 
19
    #pragma hdrstop
 
20
#endif
 
21
 
 
22
#ifndef WX_PRECOMP
 
23
    #include "wx/wx.h"
 
24
#endif
 
25
 
 
26
#include "wx/gizmos/multicell.h"
 
27
 
 
28
class MyApp: public wxApp
 
29
{public:
 
30
    bool OnInit(void);
 
31
};
 
32
 
 
33
class MyFrame: public wxFrame
 
34
{
 
35
 
 
36
public:
 
37
    MyFrame(int type, wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size);
 
38
 
 
39
    void OnCloseWindow(wxCloseEvent& event);
 
40
    void OnPaint(wxPaintEvent& event);
 
41
    wxMultiCellSizer *sizer;
 
42
 
 
43
    DECLARE_EVENT_TABLE()
 
44
};
 
45
 
 
46
IMPLEMENT_APP(MyApp)
 
47
 
 
48
bool MyApp::OnInit(void)
 
49
{
 
50
    MyFrame *frame = new MyFrame(1, (wxFrame *) NULL, wxT("wxMultiCellSizer Sample"), wxPoint(50, 50), wxDefaultSize); //, wxSize(600, 500));
 
51
 
 
52
    frame->Show(true);
 
53
 
 
54
    SetTopWindow(frame);
 
55
    frame = new MyFrame(2, (wxFrame *) NULL, wxT("wxMultiCellCanvas Sample"), wxPoint(100, 100), wxSize(600, 500));
 
56
 
 
57
    frame->Show(true);
 
58
 
 
59
    SetTopWindow(frame);
 
60
    return true;
 
61
}
 
62
 
 
63
 
 
64
 
 
65
MyFrame::MyFrame(int type, wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size):
 
66
wxFrame(frame, wxID_ANY, title, pos, size, wxDEFAULT_FRAME_STYLE | wxVSCROLL | wxHSCROLL)
 
67
{
 
68
#if wxUSE_STATUSBAR
 
69
    CreateStatusBar(1);
 
70
#endif // wxUSE_STATUSBAR
 
71
    sizer = NULL;
 
72
    if (type == 1)
 
73
    {
 
74
        // create sizer 4 columns 5 rows
 
75
        wxSize aa(4,9);
 
76
        sizer = new wxMultiCellSizer(aa);
 
77
        sizer->SetDefaultCellSize(wxSize(15,15));
 
78
        sizer->SetRowHeight(7,5,true);
 
79
        sizer->SetRowHeight(8,5,false);
 
80
        // add first row
 
81
        sizer->Add(
 
82
                  new wxButton( this, wxID_ANY, wxT( "B1 - 0,0, horizontal resizable")),
 
83
                  0, 0, 0, new wxMultiCellItemHandle(0,0,1,1, wxDefaultSize, wxHORIZONTAL_RESIZABLE, wxSize(2,2)));
 
84
        sizer->Add(
 
85
                  new wxButton( this, wxID_ANY, wxT("B2 - 0,1, vertical resizable")),
 
86
                  0, 0, 0, new wxMultiCellItemHandle(0,1,1,1, wxDefaultSize, wxVERTICAL_RESIZABLE, wxSize(2, 2)));
 
87
        sizer->Add(
 
88
                  new wxButton( this, wxID_ANY, wxT("B3 - 0,2")),
 
89
                  0, 0, 0, new wxMultiCellItemHandle(0,2,1,1, wxDefaultSize, wxNOT_RESIZABLE, wxSize(1,1), wxALIGN_CENTER_HORIZONTAL)); //, wxALIGN_CENTER));
 
90
        sizer->Add(
 
91
                  new wxStaticText(this, wxID_ANY, wxT("jbb 0,3, lower-right")),
 
92
                  0, 0, 0, new wxMultiCellItemHandle(0,3,1,1, wxDefaultSize, wxNOT_RESIZABLE, wxSize(1,1), wxALIGN_BOTTOM | wxALIGN_RIGHT));
 
93
 
 
94
        // add button for secord row
 
95
        sizer->Add(
 
96
                  new wxTextCtrl(this, wxID_ANY, wxT("Text control - 1,0, 4 cols wide")),
 
97
                  0, 0, 0, new wxMultiCellItemHandle(1,0,1,4));
 
98
 
 
99
        // add buttons for next row
 
100
        sizer->Add(
 
101
                  new wxButton( this, wxID_ANY, wxT("B6 - 2,0, 2 cols wide")),
 
102
                  0, 0, 0, new wxMultiCellItemHandle(2,0,1,2));
 
103
        sizer->Add(
 
104
                  new wxButton( this, wxID_ANY, wxT("B7 - 2,3")),
 
105
                  0, 0, 0, new wxMultiCellItemHandle(2,3,1,1));
 
106
 
 
107
        // and last additions
 
108
        sizer->Add(
 
109
                  new wxButton( this, wxID_ANY, wxT("B8 - 3,0, 4 rows high, vert resizable")),
 
110
                  0, 0, 0, new wxMultiCellItemHandle(3,0,4,1,wxDefaultSize, wxVERTICAL_RESIZABLE));
 
111
        sizer->Add(
 
112
                  new wxButton( this, wxID_ANY, wxT("B9 - 3,2, 2 cols wide, vert resizable")),
 
113
                  0, 0, 0, new wxMultiCellItemHandle(3,2,1,2,wxDefaultSize, wxVERTICAL_RESIZABLE));
 
114
        sizer->Add(
 
115
                  new wxButton( this, wxID_ANY, wxT("B10 - 4,1, 3 cols wide, vert resizable")),
 
116
                  0, 0, 0, new wxMultiCellItemHandle(4,1,1,3,wxDefaultSize, wxVERTICAL_RESIZABLE));
 
117
 
 
118
        sizer->Add(
 
119
                  new wxButton( this, wxID_ANY, wxT("B11 - 5,1, 3 cols wide")),
 
120
                  0, 0, 0, new wxMultiCellItemHandle(5,1,1,3));
 
121
 
 
122
        sizer->Add(
 
123
                  new wxButton( this, wxID_ANY, wxT("B12 - 6,1, 3 cols wide")),
 
124
                  0, 0, 0, new wxMultiCellItemHandle(6,1,1,3));
 
125
 
 
126
        sizer->Add(
 
127
                  new wxButton( this, wxID_ANY, wxT("B13 - 7,1, 2 cols wide")),
 
128
                  0, 0, 0, new wxMultiCellItemHandle(7,1,1,2));
 
129
 
 
130
        sizer->Add(
 
131
                  new wxButton( this, wxID_ANY, wxT("B14 - 8,1, 3 cols wide")),
 
132
                  0, 0, 0, new wxMultiCellItemHandle(8,1,1,3));
 
133
 
 
134
        SetAutoLayout( true );
 
135
//    sizer->SetMinSize(sizer->CalcMin());
 
136
        SetSizer( sizer );
 
137
        wxSize s = sizer->CalcMin();
 
138
        wxSize c = GetSize() - GetClientSize();
 
139
        SetSizeHints(s.GetWidth() + c.GetWidth() , s.GetHeight() + c.GetHeight());
 
140
        sizer->EnableGridLines(this);
 
141
    }
 
142
    else
 
143
    {
 
144
        // create sizer 4 columns 5 rows
 
145
        wxMultiCellCanvas *sizer = new wxMultiCellCanvas(this, 5,5);
 
146
 
 
147
        // add first row
 
148
        sizer->Add(
 
149
                  new wxButton( this, wxID_ANY, wxT("Button 1")),
 
150
                  0, 0);
 
151
        sizer->Add(
 
152
                  new wxButton( this, wxID_ANY, wxT("Button 2")),
 
153
                  0, 1);
 
154
        sizer->Add(
 
155
                  new wxButton( this, wxID_ANY, wxT("Button 3")),
 
156
                  0, 2);
 
157
        sizer->Add(
 
158
                  new wxStaticText(this, wxID_ANY, wxT("jbb test")),
 
159
                  0, 3);
 
160
 
 
161
        sizer->Add(
 
162
                  new wxStaticText(this, wxID_ANY, wxT("jbb test 2")),
 
163
                  0, 4);
 
164
 
 
165
        // add button for secord row
 
166
        sizer->Add(
 
167
                  new wxTextCtrl(this, wxID_ANY, wxT("Text control")),
 
168
                  1, 0);
 
169
 
 
170
        // add buttons for next row
 
171
        sizer->Add(
 
172
                  new wxButton( this, wxID_ANY, wxT("Button 6")),
 
173
                  2, 0);
 
174
        sizer->Add(
 
175
                  new wxButton( this, wxID_ANY, wxT("Button 7")),
 
176
                  2, 3);
 
177
 
 
178
        // and last additions
 
179
        sizer->Add(
 
180
                  new wxButton( this, wxID_ANY, wxT("Button 8")),
 
181
                  3, 0);
 
182
        sizer->Add(
 
183
                  new wxButton( this, wxID_ANY, wxT("Button 9")),
 
184
                  3, 1);
 
185
        sizer->Add(
 
186
                  new wxButton( this, wxID_ANY, wxT("Button 10")),
 
187
                  4, 1);
 
188
 
 
189
        sizer->CalculateConstraints();
 
190
        SetSizer( sizer );
 
191
        SetAutoLayout( true );
 
192
    }
 
193
}
 
194
// Define the repainting behaviour
 
195
 
 
196
 
 
197
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
 
198
   EVT_PAINT(MyFrame::OnPaint)
 
199
   EVT_CLOSE(MyFrame::OnCloseWindow)
 
200
   END_EVENT_TABLE()
 
201
 
 
202
void MyFrame::OnPaint(wxPaintEvent& WXUNUSED(event) )
 
203
{
 
204
    wxPaintDC dc(this);
 
205
 
 
206
    if (sizer)
 
207
    {
 
208
        sizer->OnPaint(dc);
 
209
    }
 
210
}
 
211
 
 
212
void MyFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
 
213
{
 
214
    Destroy();
 
215
}
 
216