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