]> git.saurik.com Git - wxWidgets.git/blob - contrib/samples/ogl/studio/dialogs.cpp
Add libs html and xml to bakefiles of samples/contribs/demos using lib adv
[wxWidgets.git] / contrib / samples / ogl / studio / dialogs.cpp
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 // For compilers that support precompilation, includes "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 "dialogs.h"
24 #include "doc.h"
25 #include "view.h"
26 #include "studio.h"
27 #include "studio_resources.h"
28
29 #if wxUSE_WX_RESOURCES
30
31 IMPLEMENT_CLASS(csLabelEditingDialog, wxDialog)
32
33 BEGIN_EVENT_TABLE(csLabelEditingDialog, wxDialog)
34 EVT_BUTTON(wxID_OK, csLabelEditingDialog::OnOK)
35 END_EVENT_TABLE()
36
37 csLabelEditingDialog::csLabelEditingDialog(wxWindow* parent)
38 {
39 wxLoadFromResource(this, parent, _T("shape_label_dialog"));
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
57 void 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
67 void 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
77 IMPLEMENT_CLASS(csSettingsDialog, wxDialog)
78
79 BEGIN_EVENT_TABLE(csSettingsDialog, wxDialog)
80 EVT_BUTTON(wxID_OK, csSettingsDialog::OnOK)
81 END_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
88 csSettingsDialog::csSettingsDialog(wxWindow* parent):
89 wxDialog(parent, wxID_ANY, _T("Settings"), wxPoint(0, 0), wxSize(PROPERTY_DIALOG_WIDTH, PROPERTY_DIALOG_HEIGHT))
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
99 #ifdef __WXDEBUG__
100 bool success =
101 #endif
102 wxLoadFromResource(m_generalSettings, m_notebook, _T("general_settings_dialog"));
103 wxASSERT_MSG( (success), _T("Could not load general settings panel."));
104 m_notebook->AddPage(m_generalSettings, _T("General"), true);
105
106 m_diagramSettings = new wxPanel;
107
108 #ifdef __WXDEBUG__
109 success =
110 #endif
111 wxLoadFromResource(m_diagramSettings, m_notebook, _T("diagram_settings_dialog"));
112 wxASSERT_MSG( (success), _T("Could not load diagram settings panel."));
113 m_notebook->AddPage(m_diagramSettings, _T("Diagram"));
114
115 int largeButtonWidth = 70;
116 int largeButtonHeight = 22;
117
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));
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
161 void csSettingsDialog::OnOK(wxCommandEvent& event)
162 {
163 wxDialog::OnOK(event);
164 }
165
166 bool csSettingsDialog::TransferDataToWindow()
167 {
168 wxTextCtrl* gridSpacing = (wxTextCtrl*) m_diagramSettings->FindWindow(ID_GRID_SPACING);
169 wxASSERT_MSG( (gridSpacing != (wxTextCtrl*) NULL), _T("Could not find grid spacing control."));
170
171 wxChoice* gridStyle = (wxChoice*) m_diagramSettings->FindWindow(ID_GRID_STYLE);
172 wxASSERT_MSG( (gridStyle != (wxChoice*) NULL), _T("Could not find grid style control."));
173
174 gridStyle->SetSelection(wxGetApp().GetGridStyle());
175
176 wxString str;
177 str.Printf(_T("%d"), wxGetApp().GetGridSpacing());
178 gridSpacing->SetValue(str);
179
180 return true;
181 }
182
183 bool csSettingsDialog::TransferDataFromWindow()
184 {
185 wxTextCtrl* gridSpacing = (wxTextCtrl*) m_diagramSettings->FindWindow(ID_GRID_SPACING);
186 wxASSERT_MSG( (gridSpacing != (wxTextCtrl*) NULL), _T("Could not find grid spacing control."));
187
188 wxChoice* gridStyle = (wxChoice*) m_diagramSettings->FindWindow(ID_GRID_STYLE);
189 wxASSERT_MSG( (gridStyle != (wxChoice*) NULL), _T("Could not find grid style control."));
190
191 wxGetApp().SetGridStyle(gridStyle->GetSelection());
192 wxString str = gridSpacing->GetValue();
193 long grid_spacing;
194 str.ToLong( &grid_spacing);
195 wxGetApp().SetGridSpacing(grid_spacing);
196
197 if (wxGetApp().GetGridStyle() == csGRID_STYLE_DOTTED)
198 {
199 wxMessageBox(_T("Dotted grid style not yet implemented."), _T("Studio"), wxICON_EXCLAMATION);
200 return false;
201 }
202
203 // Apply settings to all open diagram documents
204 wxObjectList::compatibility_iterator node = wxGetApp().GetDocManager()->GetDocuments().GetFirst();
205 while (node)
206 {
207 wxDocument* doc = (wxDocument*) node->GetData();
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 {
218 diagram->SetSnapToGrid(false);
219 break;
220 }
221 case csGRID_STYLE_INVISIBLE:
222 {
223 diagram->SetSnapToGrid(true);
224 break;
225 }
226 case csGRID_STYLE_DOTTED:
227 {
228 // TODO (not implemented in OGL)
229 break;
230 }
231 }
232 }
233 node = node->GetNext();
234 }
235
236 return true;
237 }
238
239 /*
240 * Shape properties dialog (tabbed)
241 */
242
243
244 IMPLEMENT_CLASS(csShapePropertiesDialog, wxDialog)
245
246 BEGIN_EVENT_TABLE(csShapePropertiesDialog, wxDialog)
247 EVT_BUTTON(wxID_OK, csShapePropertiesDialog::OnOK)
248 END_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
255 csShapePropertiesDialog::csShapePropertiesDialog(wxWindow* parent, const wxString& title,
256 wxPanel* attributeDialog, const wxString& attributeDialogName):
257 wxDialog(parent, wxID_ANY, title, wxPoint(0, 0), wxSize(SHAPE_PROPERTY_DIALOG_WIDTH, SHAPE_PROPERTY_DIALOG_HEIGHT))
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;
267 #ifdef __WXDEBUG__
268 bool success =
269 #endif
270 wxLoadFromResource(m_generalPropertiesDialog, m_notebook, _T("general_shape_properties_dialog"));
271 wxASSERT_MSG( (success), _T("Could not load general properties panel."));
272 m_notebook->AddPage(m_generalPropertiesDialog, _T("General"));
273
274 if (!wxLoadFromResource(m_attributeDialog, m_notebook, attributeDialogName))
275 {
276 wxMessageBox(_T("Could not load the attribute dialog for this shape."), _T("Studio"), wxICON_EXCLAMATION);
277 delete m_attributeDialog;
278 m_attributeDialog = NULL;
279 }
280 else
281 {
282 m_notebook->AddPage(m_attributeDialog, _T("Attributes"));
283 }
284
285 // Try the alternative dialog (test code)
286 wxString str(attributeDialogName);
287 str += _T("1");
288 m_alternativeAttributeDialog = new wxPanel;
289 if (wxLoadFromResource(m_alternativeAttributeDialog, m_notebook, str))
290 {
291 m_notebook->AddPage(m_alternativeAttributeDialog, _T("Attributes (alternative)"));
292 }
293 else
294 {
295 delete m_alternativeAttributeDialog;
296 m_alternativeAttributeDialog = NULL;
297 }
298
299 int largeButtonWidth = 70;
300 int largeButtonHeight = 22;
301
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));
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
347 void 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)
359 void csShapePropertiesDialog::SetDefaults()
360 {
361 if (!m_attributeDialog)
362 return;
363
364 wxWindowList::compatibility_iterator node = m_attributeDialog->GetChildren().GetFirst();
365 while (node)
366 {
367 wxWindow* child = (wxWindow*) node->GetData();
368 if (child->IsKindOf(CLASSINFO(wxChoice)))
369 {
370 wxChoice* choice = (wxChoice*) child;
371 choice->SetSelection(0);
372 }
373 node = node->GetNext();
374 }
375
376 if (!m_alternativeAttributeDialog)
377 return;
378
379 node = m_alternativeAttributeDialog->GetChildren().GetFirst();
380 while (node)
381 {
382 wxWindow* child = (wxWindow*) node->GetData();
383 if (child->IsKindOf(CLASSINFO(wxChoice)))
384 {
385 wxChoice* choice = (wxChoice*) child;
386 choice->SetSelection(0);
387 }
388 node = node->GetNext();
389 }
390 }
391
392 /*
393 * csGeneralShapePropertiesDialog
394 */
395
396 IMPLEMENT_CLASS(csGeneralShapePropertiesDialog, wxPanel)
397
398 BEGIN_EVENT_TABLE(csGeneralShapePropertiesDialog, wxPanel)
399 END_EVENT_TABLE()
400
401 csGeneralShapePropertiesDialog::csGeneralShapePropertiesDialog()
402 {
403 }
404
405 void 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
415 #endif // wxUSE_WX_RESOURCES
416
417 /*
418 * csThinRectangleDialog
419 */
420
421 IMPLEMENT_CLASS(csThinRectangleDialog, wxPanel)
422
423 BEGIN_EVENT_TABLE(csThinRectangleDialog, wxPanel)
424 END_EVENT_TABLE()
425
426 csThinRectangleDialog::csThinRectangleDialog()
427 {
428 }
429
430 /*
431 * csWideRectangleDialog
432 */
433
434 IMPLEMENT_CLASS(csWideRectangleDialog, wxPanel)
435
436 BEGIN_EVENT_TABLE(csWideRectangleDialog, wxPanel)
437 END_EVENT_TABLE()
438
439 csWideRectangleDialog::csWideRectangleDialog()
440 {
441 }
442
443 /*
444 * csTriangleDialog
445 */
446
447 IMPLEMENT_CLASS(csTriangleDialog, wxPanel)
448
449 BEGIN_EVENT_TABLE(csTriangleDialog, wxPanel)
450 END_EVENT_TABLE()
451
452 csTriangleDialog::csTriangleDialog()
453 {
454 }
455
456 /*
457 * csSemiCircleDialog
458 */
459
460 IMPLEMENT_CLASS(csSemiCircleDialog, wxPanel)
461
462 BEGIN_EVENT_TABLE(csSemiCircleDialog, wxPanel)
463 END_EVENT_TABLE()
464
465 csSemiCircleDialog::csSemiCircleDialog()
466 {
467 }
468
469 /*
470 * csCircleDialog
471 */
472
473 IMPLEMENT_CLASS(csCircleDialog, wxPanel)
474
475 BEGIN_EVENT_TABLE(csCircleDialog, wxPanel)
476 END_EVENT_TABLE()
477
478 csCircleDialog::csCircleDialog()
479 {
480 }
481
482 /*
483 * csCircleShadowDialog
484 */
485
486 IMPLEMENT_CLASS(csCircleShadowDialog, wxPanel)
487
488 BEGIN_EVENT_TABLE(csCircleShadowDialog, wxPanel)
489 END_EVENT_TABLE()
490
491 csCircleShadowDialog::csCircleShadowDialog()
492 {
493 }
494
495 /*
496 * csOctagonDialog
497 */
498
499 IMPLEMENT_CLASS(csOctagonDialog, wxPanel)
500
501 BEGIN_EVENT_TABLE(csOctagonDialog, wxPanel)
502 END_EVENT_TABLE()
503
504 csOctagonDialog::csOctagonDialog()
505 {
506 }
507
508 /*
509 * csGroupDialog
510 */
511
512 IMPLEMENT_CLASS(csGroupDialog, wxPanel)
513
514 BEGIN_EVENT_TABLE(csGroupDialog, wxPanel)
515 END_EVENT_TABLE()
516
517 csGroupDialog::csGroupDialog()
518 {
519 }
520
521 /*
522 * csTextBoxDialog
523 */
524
525 IMPLEMENT_CLASS(csTextBoxDialog, wxPanel)
526
527 BEGIN_EVENT_TABLE(csTextBoxDialog, wxPanel)
528 END_EVENT_TABLE()
529
530 csTextBoxDialog::csTextBoxDialog()
531 {
532 }
533
534