]> git.saurik.com Git - wxWidgets.git/blame - contrib/samples/ogl/studio/dialogs.cpp
Change 'test -e' to 'test -f' for Sun
[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
1fc25a89
JS
27#include "dialogs.h"
28#include "doc.h"
29#include "view.h"
30#include "studio.h"
31#include "studio_resources.h"
32
cecdcad1
WS
33#if wxUSE_WX_RESOURCES
34
1fc25a89
JS
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 103 #ifdef __WXDEBUG__
cecdcad1 104 bool success =
8552e6f0
MB
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 112 #ifdef __WXDEBUG__
cecdcad1 113 success =
8552e6f0
MB
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
5e0dbc8d 208 wxObjectList::compatibility_iterator 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,
cecdcad1 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 271 #ifdef __WXDEBUG__
cecdcad1 272 bool success =
8552e6f0
MB
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
5e0dbc8d 368 wxWindowList::compatibility_iterator 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
cecdcad1
WS
419#endif // wxUSE_WX_RESOURCES
420
1fc25a89
JS
421/*
422 * csThinRectangleDialog
423 */
424
425IMPLEMENT_CLASS(csThinRectangleDialog, wxPanel)
426
427BEGIN_EVENT_TABLE(csThinRectangleDialog, wxPanel)
428END_EVENT_TABLE()
429
430csThinRectangleDialog::csThinRectangleDialog()
431{
432}
433
434/*
435 * csWideRectangleDialog
436 */
437
438IMPLEMENT_CLASS(csWideRectangleDialog, wxPanel)
439
440BEGIN_EVENT_TABLE(csWideRectangleDialog, wxPanel)
441END_EVENT_TABLE()
442
443csWideRectangleDialog::csWideRectangleDialog()
444{
445}
446
447/*
448 * csTriangleDialog
449 */
450
451IMPLEMENT_CLASS(csTriangleDialog, wxPanel)
452
453BEGIN_EVENT_TABLE(csTriangleDialog, wxPanel)
454END_EVENT_TABLE()
455
456csTriangleDialog::csTriangleDialog()
457{
458}
459
460/*
461 * csSemiCircleDialog
462 */
463
464IMPLEMENT_CLASS(csSemiCircleDialog, wxPanel)
465
466BEGIN_EVENT_TABLE(csSemiCircleDialog, wxPanel)
467END_EVENT_TABLE()
468
469csSemiCircleDialog::csSemiCircleDialog()
470{
471}
472
473/*
474 * csCircleDialog
475 */
476
477IMPLEMENT_CLASS(csCircleDialog, wxPanel)
478
479BEGIN_EVENT_TABLE(csCircleDialog, wxPanel)
480END_EVENT_TABLE()
481
482csCircleDialog::csCircleDialog()
483{
484}
485
486/*
487 * csCircleShadowDialog
488 */
489
490IMPLEMENT_CLASS(csCircleShadowDialog, wxPanel)
491
492BEGIN_EVENT_TABLE(csCircleShadowDialog, wxPanel)
493END_EVENT_TABLE()
494
495csCircleShadowDialog::csCircleShadowDialog()
496{
497}
498
499/*
500 * csOctagonDialog
501 */
502
503IMPLEMENT_CLASS(csOctagonDialog, wxPanel)
504
505BEGIN_EVENT_TABLE(csOctagonDialog, wxPanel)
506END_EVENT_TABLE()
507
508csOctagonDialog::csOctagonDialog()
509{
510}
511
512/*
513 * csGroupDialog
514 */
515
516IMPLEMENT_CLASS(csGroupDialog, wxPanel)
517
518BEGIN_EVENT_TABLE(csGroupDialog, wxPanel)
519END_EVENT_TABLE()
520
521csGroupDialog::csGroupDialog()
522{
523}
524
525/*
526 * csTextBoxDialog
527 */
528
529IMPLEMENT_CLASS(csTextBoxDialog, wxPanel)
530
531BEGIN_EVENT_TABLE(csTextBoxDialog, wxPanel)
532END_EVENT_TABLE()
533
534csTextBoxDialog::csTextBoxDialog()
535{
536}
537
538