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