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