]> git.saurik.com Git - wxWidgets.git/blame - contrib/samples/ogl/studio/dialogs.cpp
Added SWIG patches to allow compiling the generated code with
[wxWidgets.git] / contrib / samples / ogl / studio / dialogs.cpp
CommitLineData
1fc25a89 1/////////////////////////////////////////////////////////////////////////////
f4ec6bd2 2// Name: contrib/samples/ogl/studio/dialogs.cpp
1fc25a89
JS
3// Purpose: Implements Studio dialogs
4// Author: Julian Smart
5// Modified by:
6// Created: 12/07/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
f4ec6bd2 9// Licence: wxWindows licence
1fc25a89
JS
10/////////////////////////////////////////////////////////////////////////////
11
1fc25a89 12// For compilers that support precompilation, includes "wx.h".
92a19c2e 13#include "wx/wxprec.h"
1fc25a89
JS
14
15#ifdef __BORLANDC__
16#pragma hdrstop
17#endif
18
19#ifndef WX_PRECOMP
f4ec6bd2 20#include "wx/wx.h"
1fc25a89
JS
21#endif
22
1fc25a89
JS
23#include "dialogs.h"
24#include "doc.h"
25#include "view.h"
26#include "studio.h"
27#include "studio_resources.h"
28
cecdcad1
WS
29#if wxUSE_WX_RESOURCES
30
1fc25a89
JS
31IMPLEMENT_CLASS(csLabelEditingDialog, wxDialog)
32
33BEGIN_EVENT_TABLE(csLabelEditingDialog, wxDialog)
34 EVT_BUTTON(wxID_OK, csLabelEditingDialog::OnOK)
35END_EVENT_TABLE()
36
37csLabelEditingDialog::csLabelEditingDialog(wxWindow* parent)
38{
1484b5cc 39 wxLoadFromResource(this, parent, _T("shape_label_dialog"));
1fc25a89
JS
40
41 // Accelerators
42 wxAcceleratorEntry entries[1];
43 entries[0].Set(wxACCEL_CTRL, WXK_RETURN, wxID_OK);
44 wxAcceleratorTable accel(1, entries);
45 SetAcceleratorTable(accel);
46
47 Centre();
48
49 wxTextCtrl* textCtrl = (wxTextCtrl*) FindWindow(ID_LABELTEXT);
50 wxASSERT( (textCtrl != NULL) );
51
52// textCtrl->SetAcceleratorTable(accel);
53
54 textCtrl->SetFocus();
55}
56
57void csLabelEditingDialog::OnOK(wxCommandEvent& event)
58{
59 wxTextCtrl* textCtrl = (wxTextCtrl*) FindWindow(ID_LABELTEXT);
60 wxASSERT( (textCtrl != NULL) );
61
62 SetShapeLabel(textCtrl->GetValue());
63
64 wxDialog::OnOK(event);
65}
66
67void csLabelEditingDialog::SetShapeLabel(const wxString& label)
68{
69 wxTextCtrl* textCtrl = (wxTextCtrl*) FindWindow(ID_LABELTEXT);
70 wxASSERT( (textCtrl != NULL) );
71
72 m_label = label;
73
74 textCtrl->SetValue(label);
75}
76
77IMPLEMENT_CLASS(csSettingsDialog, wxDialog)
78
79BEGIN_EVENT_TABLE(csSettingsDialog, wxDialog)
80 EVT_BUTTON(wxID_OK, csSettingsDialog::OnOK)
81END_EVENT_TABLE()
82
83#define PROPERTY_DIALOG_WIDTH 400
84#define PROPERTY_DIALOG_HEIGHT 400
85
86// For 400x400 settings dialog, size your panels to about 375x325 in dialog editor
87
88csSettingsDialog::csSettingsDialog(wxWindow* parent):
2ba06d5a 89 wxDialog(parent, wxID_ANY, _T("Settings"), wxPoint(0, 0), wxSize(PROPERTY_DIALOG_WIDTH, PROPERTY_DIALOG_HEIGHT))
1fc25a89
JS
90{
91 m_generalSettings = NULL;
92 m_diagramSettings = NULL;
93
94 m_notebook = new wxNotebook(this, ID_PROPERTY_NOTEBOOK,
95 wxPoint(2, 2), wxSize(PROPERTY_DIALOG_WIDTH - 4, PROPERTY_DIALOG_HEIGHT - 4));
96
97 m_generalSettings = new wxPanel;
98
8552e6f0 99 #ifdef __WXDEBUG__
cecdcad1 100 bool success =
8552e6f0
MB
101 #endif
102 wxLoadFromResource(m_generalSettings, m_notebook, _T("general_settings_dialog"));
1484b5cc 103 wxASSERT_MSG( (success), _T("Could not load general settings panel."));
2ba06d5a 104 m_notebook->AddPage(m_generalSettings, _T("General"), true);
1fc25a89
JS
105
106 m_diagramSettings = new wxPanel;
107
8552e6f0 108 #ifdef __WXDEBUG__
cecdcad1 109 success =
8552e6f0
MB
110 #endif
111 wxLoadFromResource(m_diagramSettings, m_notebook, _T("diagram_settings_dialog"));
1484b5cc
VS
112 wxASSERT_MSG( (success), _T("Could not load diagram settings panel."));
113 m_notebook->AddPage(m_diagramSettings, _T("Diagram"));
1fc25a89
JS
114
115 int largeButtonWidth = 70;
116 int largeButtonHeight = 22;
117
1484b5cc
VS
118 wxButton* okButton = new wxButton(this, wxID_OK, _T("OK"), wxPoint(0, 0), wxSize(largeButtonWidth, largeButtonHeight));
119 wxButton* cancelButton = new wxButton(this, wxID_CANCEL, _T("Cancel"), wxPoint(0, 0), wxSize(largeButtonWidth, largeButtonHeight));
120 wxButton* helpButton = new wxButton(this, wxID_HELP, _T("Help"), wxPoint(0, 0), wxSize(largeButtonWidth, largeButtonHeight));
1fc25a89
JS
121
122 // Constraints for the notebook
123 wxLayoutConstraints *c = new wxLayoutConstraints;
124 c->top.SameAs (this, wxTop, 5);
125 c->left.SameAs (this, wxLeft, 5);
126 c->right.SameAs (this, wxRight, 5);
127 c->bottom.SameAs (cancelButton, wxTop, 5);
128 m_notebook->SetConstraints(c);
129
130 // Constraints for the Help button
131 c = new wxLayoutConstraints;
132 c->width.AsIs();
133 c->height.AsIs();
134 c->right.SameAs (this, wxRight, 5);
135 c->bottom.SameAs (this, wxBottom, 5);
136 helpButton->SetConstraints(c);
137
138 // Constraints for the Cancel button
139 c = new wxLayoutConstraints;
140 c->width.AsIs();
141 c->height.AsIs();
142 c->right.SameAs (helpButton, wxLeft, 5);
143 c->bottom.SameAs (this, wxBottom, 5);
144 cancelButton->SetConstraints(c);
145
146 // Constraints for the OK button
147 c = new wxLayoutConstraints;
148 c->width.AsIs();
149 c->height.AsIs();
150 c->right.SameAs (cancelButton, wxLeft, 5);
151 c->bottom.SameAs (this, wxBottom, 5);
152 okButton->SetConstraints(c);
153
154 okButton->SetDefault();
155 okButton->SetFocus();
156
157 Layout();
158 Centre(wxBOTH);
159}
160
161void csSettingsDialog::OnOK(wxCommandEvent& event)
162{
163 wxDialog::OnOK(event);
164}
165
166bool csSettingsDialog::TransferDataToWindow()
167{
168 wxTextCtrl* gridSpacing = (wxTextCtrl*) m_diagramSettings->FindWindow(ID_GRID_SPACING);
1484b5cc 169 wxASSERT_MSG( (gridSpacing != (wxTextCtrl*) NULL), _T("Could not find grid spacing control."));
1fc25a89
JS
170
171 wxChoice* gridStyle = (wxChoice*) m_diagramSettings->FindWindow(ID_GRID_STYLE);
1484b5cc 172 wxASSERT_MSG( (gridStyle != (wxChoice*) NULL), _T("Could not find grid style control."));
1fc25a89
JS
173
174 gridStyle->SetSelection(wxGetApp().GetGridStyle());
175
176 wxString str;
1484b5cc 177 str.Printf(_T("%d"), wxGetApp().GetGridSpacing());
1fc25a89
JS
178 gridSpacing->SetValue(str);
179
2ba06d5a 180 return true;
1fc25a89
JS
181}
182
183bool csSettingsDialog::TransferDataFromWindow()
184{
185 wxTextCtrl* gridSpacing = (wxTextCtrl*) m_diagramSettings->FindWindow(ID_GRID_SPACING);
1484b5cc 186 wxASSERT_MSG( (gridSpacing != (wxTextCtrl*) NULL), _T("Could not find grid spacing control."));
1fc25a89
JS
187
188 wxChoice* gridStyle = (wxChoice*) m_diagramSettings->FindWindow(ID_GRID_STYLE);
1484b5cc 189 wxASSERT_MSG( (gridStyle != (wxChoice*) NULL), _T("Could not find grid style control."));
1fc25a89
JS
190
191 wxGetApp().SetGridStyle(gridStyle->GetSelection());
1484b5cc
VS
192 wxString str = gridSpacing->GetValue();
193 long grid_spacing;
194 str.ToLong( &grid_spacing);
195 wxGetApp().SetGridSpacing(grid_spacing);
1fc25a89
JS
196
197 if (wxGetApp().GetGridStyle() == csGRID_STYLE_DOTTED)
198 {
1484b5cc 199 wxMessageBox(_T("Dotted grid style not yet implemented."), _T("Studio"), wxICON_EXCLAMATION);
2ba06d5a 200 return false;
1fc25a89
JS
201 }
202
203 // Apply settings to all open diagram documents
5e0dbc8d 204 wxObjectList::compatibility_iterator node = wxGetApp().GetDocManager()->GetDocuments().GetFirst();
1fc25a89
JS
205 while (node)
206 {
8552e6f0 207 wxDocument* doc = (wxDocument*) node->GetData();
1fc25a89
JS
208 if (doc->IsKindOf(CLASSINFO(csDiagramDocument)))
209 {
210 csDiagramDocument* diagramDoc = (csDiagramDocument*) doc;
211 wxDiagram* diagram = (wxDiagram*) diagramDoc->GetDiagram();
212
213 diagram->SetGridSpacing((double) wxGetApp().GetGridSpacing());
214 switch (wxGetApp().GetGridStyle())
215 {
216 case csGRID_STYLE_NONE:
217 {
2ba06d5a 218 diagram->SetSnapToGrid(false);
1fc25a89
JS
219 break;
220 }
221 case csGRID_STYLE_INVISIBLE:
222 {
2ba06d5a 223 diagram->SetSnapToGrid(true);
1fc25a89
JS
224 break;
225 }
226 case csGRID_STYLE_DOTTED:
227 {
228 // TODO (not implemented in OGL)
229 break;
230 }
231 }
232 }
8552e6f0 233 node = node->GetNext();
1fc25a89
JS
234 }
235
2ba06d5a 236 return true;
1fc25a89
JS
237}
238
239/*
240 * Shape properties dialog (tabbed)
241 */
242
243
244IMPLEMENT_CLASS(csShapePropertiesDialog, wxDialog)
245
246BEGIN_EVENT_TABLE(csShapePropertiesDialog, wxDialog)
247 EVT_BUTTON(wxID_OK, csShapePropertiesDialog::OnOK)
248END_EVENT_TABLE()
249
250#define SHAPE_PROPERTY_DIALOG_WIDTH 400
251#define SHAPE_PROPERTY_DIALOG_HEIGHT 400
252
253// For 400x400 settings dialog, size your panels to about 375x325 in dialog editor
254
255csShapePropertiesDialog::csShapePropertiesDialog(wxWindow* parent, const wxString& title,
cecdcad1 256 wxPanel* attributeDialog, const wxString& attributeDialogName):
2ba06d5a 257 wxDialog(parent, wxID_ANY, title, wxPoint(0, 0), wxSize(SHAPE_PROPERTY_DIALOG_WIDTH, SHAPE_PROPERTY_DIALOG_HEIGHT))
1fc25a89
JS
258{
259 m_attributeDialog = attributeDialog;
260 m_alternativeAttributeDialog = NULL;
261 m_generalPropertiesDialog = NULL;
262
263 m_notebook = new wxNotebook(this, ID_SHAPE_PROPERTY_NOTEBOOK,
264 wxPoint(2, 2), wxSize(SHAPE_PROPERTY_DIALOG_WIDTH - 4, SHAPE_PROPERTY_DIALOG_HEIGHT - 4));
265
266 m_generalPropertiesDialog = new csGeneralShapePropertiesDialog;
8552e6f0 267 #ifdef __WXDEBUG__
cecdcad1 268 bool success =
8552e6f0
MB
269 #endif
270 wxLoadFromResource(m_generalPropertiesDialog, m_notebook, _T("general_shape_properties_dialog"));
1484b5cc
VS
271 wxASSERT_MSG( (success), _T("Could not load general properties panel."));
272 m_notebook->AddPage(m_generalPropertiesDialog, _T("General"));
1fc25a89 273
8552e6f0 274 if (!wxLoadFromResource(m_attributeDialog, m_notebook, attributeDialogName))
1fc25a89 275 {
1484b5cc 276 wxMessageBox(_T("Could not load the attribute dialog for this shape."), _T("Studio"), wxICON_EXCLAMATION);
1fc25a89
JS
277 delete m_attributeDialog;
278 m_attributeDialog = NULL;
279 }
280 else
281 {
1484b5cc 282 m_notebook->AddPage(m_attributeDialog, _T("Attributes"));
1fc25a89
JS
283 }
284
285 // Try the alternative dialog (test code)
286 wxString str(attributeDialogName);
1484b5cc 287 str += _T("1");
1fc25a89 288 m_alternativeAttributeDialog = new wxPanel;
8552e6f0 289 if (wxLoadFromResource(m_alternativeAttributeDialog, m_notebook, str))
1fc25a89 290 {
1484b5cc 291 m_notebook->AddPage(m_alternativeAttributeDialog, _T("Attributes (alternative)"));
1fc25a89
JS
292 }
293 else
294 {
295 delete m_alternativeAttributeDialog;
296 m_alternativeAttributeDialog = NULL;
297 }
298
299 int largeButtonWidth = 70;
300 int largeButtonHeight = 22;
301
1484b5cc
VS
302 wxButton* okButton = new wxButton(this, wxID_OK, _T("OK"), wxPoint(0, 0), wxSize(largeButtonWidth, largeButtonHeight));
303 wxButton* cancelButton = new wxButton(this, wxID_CANCEL, _T("Cancel"), wxPoint(0, 0), wxSize(largeButtonWidth, largeButtonHeight));
304 wxButton* helpButton = new wxButton(this, wxID_HELP, _T("Help"), wxPoint(0, 0), wxSize(largeButtonWidth, largeButtonHeight));
1fc25a89
JS
305
306 // Constraints for the notebook
307 wxLayoutConstraints *c = new wxLayoutConstraints;
308 c->top.SameAs (this, wxTop, 5);
309 c->left.SameAs (this, wxLeft, 5);
310 c->right.SameAs (this, wxRight, 5);
311 c->bottom.SameAs (helpButton, wxTop, 5);
312 m_notebook->SetConstraints(c);
313
314 // Constraints for the Help button
315 c = new wxLayoutConstraints;
316 c->width.AsIs();
317 c->height.AsIs();
318 c->right.SameAs (this, wxRight, 5);
319 c->bottom.SameAs (this, wxBottom, 5);
320 helpButton->SetConstraints(c);
321
322 // Constraints for the Cancel button
323 c = new wxLayoutConstraints;
324 c->width.AsIs();
325 c->height.AsIs();
326 c->right.SameAs (helpButton, wxLeft, 5);
327 c->bottom.SameAs (this, wxBottom, 5);
328 cancelButton->SetConstraints(c);
329
330 // Constraints for the OK button
331 c = new wxLayoutConstraints;
332 c->width.AsIs();
333 c->height.AsIs();
334 c->right.SameAs (cancelButton, wxLeft, 5);
335 c->bottom.SameAs (this, wxBottom, 5);
336 okButton->SetConstraints(c);
337
338 okButton->SetDefault();
339 okButton->SetFocus();
340
341 SetDefaults();
342
343 Layout();
344 Centre(wxBOTH);
345}
346
347void csShapePropertiesDialog::OnOK(wxCommandEvent& event)
348{
349 wxTextCtrl* textCtrl = (wxTextCtrl*) m_generalPropertiesDialog->FindWindow(ID_LABELTEXT);
350 wxASSERT( (textCtrl != NULL) );
351
352 m_generalPropertiesDialog->SetShapeLabel(textCtrl->GetValue());
353
354 wxDialog::OnOK(event);
355}
356
357// Set some suitable defaults in the attribute dialogs (in the first instance,
358// just set all wxChoices to the first element)
359void csShapePropertiesDialog::SetDefaults()
360{
361 if (!m_attributeDialog)
362 return;
363
5e0dbc8d 364 wxWindowList::compatibility_iterator node = m_attributeDialog->GetChildren().GetFirst();
1fc25a89
JS
365 while (node)
366 {
8552e6f0 367 wxWindow* child = (wxWindow*) node->GetData();
1fc25a89
JS
368 if (child->IsKindOf(CLASSINFO(wxChoice)))
369 {
370 wxChoice* choice = (wxChoice*) child;
371 choice->SetSelection(0);
372 }
8552e6f0 373 node = node->GetNext();
1fc25a89
JS
374 }
375
376 if (!m_alternativeAttributeDialog)
377 return;
378
8552e6f0 379 node = m_alternativeAttributeDialog->GetChildren().GetFirst();
1fc25a89
JS
380 while (node)
381 {
8552e6f0 382 wxWindow* child = (wxWindow*) node->GetData();
1fc25a89
JS
383 if (child->IsKindOf(CLASSINFO(wxChoice)))
384 {
385 wxChoice* choice = (wxChoice*) child;
386 choice->SetSelection(0);
387 }
8552e6f0 388 node = node->GetNext();
1fc25a89
JS
389 }
390}
391
392/*
393 * csGeneralShapePropertiesDialog
394 */
395
396IMPLEMENT_CLASS(csGeneralShapePropertiesDialog, wxPanel)
397
398BEGIN_EVENT_TABLE(csGeneralShapePropertiesDialog, wxPanel)
399END_EVENT_TABLE()
400
401csGeneralShapePropertiesDialog::csGeneralShapePropertiesDialog()
402{
403}
404
405void csGeneralShapePropertiesDialog::SetShapeLabel(const wxString& label)
406{
407 wxTextCtrl* textCtrl = (wxTextCtrl*) FindWindow(ID_LABELTEXT);
408 wxASSERT( (textCtrl != NULL) );
409
410 m_label = label;
411
412 textCtrl->SetValue(label);
413}
414
cecdcad1
WS
415#endif // wxUSE_WX_RESOURCES
416
1fc25a89
JS
417/*
418 * csThinRectangleDialog
419 */
420
421IMPLEMENT_CLASS(csThinRectangleDialog, wxPanel)
422
423BEGIN_EVENT_TABLE(csThinRectangleDialog, wxPanel)
424END_EVENT_TABLE()
425
426csThinRectangleDialog::csThinRectangleDialog()
427{
428}
429
430/*
431 * csWideRectangleDialog
432 */
433
434IMPLEMENT_CLASS(csWideRectangleDialog, wxPanel)
435
436BEGIN_EVENT_TABLE(csWideRectangleDialog, wxPanel)
437END_EVENT_TABLE()
438
439csWideRectangleDialog::csWideRectangleDialog()
440{
441}
442
443/*
444 * csTriangleDialog
445 */
446
447IMPLEMENT_CLASS(csTriangleDialog, wxPanel)
448
449BEGIN_EVENT_TABLE(csTriangleDialog, wxPanel)
450END_EVENT_TABLE()
451
452csTriangleDialog::csTriangleDialog()
453{
454}
455
456/*
457 * csSemiCircleDialog
458 */
459
460IMPLEMENT_CLASS(csSemiCircleDialog, wxPanel)
461
462BEGIN_EVENT_TABLE(csSemiCircleDialog, wxPanel)
463END_EVENT_TABLE()
464
465csSemiCircleDialog::csSemiCircleDialog()
466{
467}
468
469/*
470 * csCircleDialog
471 */
472
473IMPLEMENT_CLASS(csCircleDialog, wxPanel)
474
475BEGIN_EVENT_TABLE(csCircleDialog, wxPanel)
476END_EVENT_TABLE()
477
478csCircleDialog::csCircleDialog()
479{
480}
481
482/*
483 * csCircleShadowDialog
484 */
485
486IMPLEMENT_CLASS(csCircleShadowDialog, wxPanel)
487
488BEGIN_EVENT_TABLE(csCircleShadowDialog, wxPanel)
489END_EVENT_TABLE()
490
491csCircleShadowDialog::csCircleShadowDialog()
492{
493}
494
495/*
496 * csOctagonDialog
497 */
498
499IMPLEMENT_CLASS(csOctagonDialog, wxPanel)
500
501BEGIN_EVENT_TABLE(csOctagonDialog, wxPanel)
502END_EVENT_TABLE()
503
504csOctagonDialog::csOctagonDialog()
505{
506}
507
508/*
509 * csGroupDialog
510 */
511
512IMPLEMENT_CLASS(csGroupDialog, wxPanel)
513
514BEGIN_EVENT_TABLE(csGroupDialog, wxPanel)
515END_EVENT_TABLE()
516
517csGroupDialog::csGroupDialog()
518{
519}
520
521/*
522 * csTextBoxDialog
523 */
524
525IMPLEMENT_CLASS(csTextBoxDialog, wxPanel)
526
527BEGIN_EVENT_TABLE(csTextBoxDialog, wxPanel)
528END_EVENT_TABLE()
529
530csTextBoxDialog::csTextBoxDialog()
531{
532}