]> git.saurik.com Git - wxWidgets.git/blob - contrib/samples/ogl/studio/dialogs.cpp
Sample update - wxTE_AUTO_URL from Mart R. [patch 1126182]
[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, wxID_ANY, _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 #ifdef __WXDEBUG__
104 bool success =
105 #endif
106 wxLoadFromResource(m_generalSettings, m_notebook, _T("general_settings_dialog"));
107 wxASSERT_MSG( (success), _T("Could not load general settings panel."));
108 m_notebook->AddPage(m_generalSettings, _T("General"), true);
109
110 m_diagramSettings = new wxPanel;
111
112 #ifdef __WXDEBUG__
113 success =
114 #endif
115 wxLoadFromResource(m_diagramSettings, m_notebook, _T("diagram_settings_dialog"));
116 wxASSERT_MSG( (success), _T("Could not load diagram settings panel."));
117 m_notebook->AddPage(m_diagramSettings, _T("Diagram"));
118
119 int largeButtonWidth = 70;
120 int largeButtonHeight = 22;
121
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));
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
165 void csSettingsDialog::OnOK(wxCommandEvent& event)
166 {
167 wxDialog::OnOK(event);
168 }
169
170 bool csSettingsDialog::TransferDataToWindow()
171 {
172 wxTextCtrl* gridSpacing = (wxTextCtrl*) m_diagramSettings->FindWindow(ID_GRID_SPACING);
173 wxASSERT_MSG( (gridSpacing != (wxTextCtrl*) NULL), _T("Could not find grid spacing control."));
174
175 wxChoice* gridStyle = (wxChoice*) m_diagramSettings->FindWindow(ID_GRID_STYLE);
176 wxASSERT_MSG( (gridStyle != (wxChoice*) NULL), _T("Could not find grid style control."));
177
178 gridStyle->SetSelection(wxGetApp().GetGridStyle());
179
180 wxString str;
181 str.Printf(_T("%d"), wxGetApp().GetGridSpacing());
182 gridSpacing->SetValue(str);
183
184 return true;
185 }
186
187 bool csSettingsDialog::TransferDataFromWindow()
188 {
189 wxTextCtrl* gridSpacing = (wxTextCtrl*) m_diagramSettings->FindWindow(ID_GRID_SPACING);
190 wxASSERT_MSG( (gridSpacing != (wxTextCtrl*) NULL), _T("Could not find grid spacing control."));
191
192 wxChoice* gridStyle = (wxChoice*) m_diagramSettings->FindWindow(ID_GRID_STYLE);
193 wxASSERT_MSG( (gridStyle != (wxChoice*) NULL), _T("Could not find grid style control."));
194
195 wxGetApp().SetGridStyle(gridStyle->GetSelection());
196 wxString str = gridSpacing->GetValue();
197 long grid_spacing;
198 str.ToLong( &grid_spacing);
199 wxGetApp().SetGridSpacing(grid_spacing);
200
201 if (wxGetApp().GetGridStyle() == csGRID_STYLE_DOTTED)
202 {
203 wxMessageBox(_T("Dotted grid style not yet implemented."), _T("Studio"), wxICON_EXCLAMATION);
204 return false;
205 }
206
207 // Apply settings to all open diagram documents
208 wxObjectList::compatibility_iterator node = wxGetApp().GetDocManager()->GetDocuments().GetFirst();
209 while (node)
210 {
211 wxDocument* doc = (wxDocument*) node->GetData();
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 {
222 diagram->SetSnapToGrid(false);
223 break;
224 }
225 case csGRID_STYLE_INVISIBLE:
226 {
227 diagram->SetSnapToGrid(true);
228 break;
229 }
230 case csGRID_STYLE_DOTTED:
231 {
232 // TODO (not implemented in OGL)
233 break;
234 }
235 }
236 }
237 node = node->GetNext();
238 }
239
240 return true;
241 }
242
243 /*
244 * Shape properties dialog (tabbed)
245 */
246
247
248 IMPLEMENT_CLASS(csShapePropertiesDialog, wxDialog)
249
250 BEGIN_EVENT_TABLE(csShapePropertiesDialog, wxDialog)
251 EVT_BUTTON(wxID_OK, csShapePropertiesDialog::OnOK)
252 END_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
259 csShapePropertiesDialog::csShapePropertiesDialog(wxWindow* parent, const wxString& title,
260 wxPanel* attributeDialog, const wxString& attributeDialogName):
261 wxDialog(parent, wxID_ANY, title, wxPoint(0, 0), wxSize(SHAPE_PROPERTY_DIALOG_WIDTH, SHAPE_PROPERTY_DIALOG_HEIGHT))
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;
271 #ifdef __WXDEBUG__
272 bool success =
273 #endif
274 wxLoadFromResource(m_generalPropertiesDialog, m_notebook, _T("general_shape_properties_dialog"));
275 wxASSERT_MSG( (success), _T("Could not load general properties panel."));
276 m_notebook->AddPage(m_generalPropertiesDialog, _T("General"));
277
278 if (!wxLoadFromResource(m_attributeDialog, m_notebook, attributeDialogName))
279 {
280 wxMessageBox(_T("Could not load the attribute dialog for this shape."), _T("Studio"), wxICON_EXCLAMATION);
281 delete m_attributeDialog;
282 m_attributeDialog = NULL;
283 }
284 else
285 {
286 m_notebook->AddPage(m_attributeDialog, _T("Attributes"));
287 }
288
289 // Try the alternative dialog (test code)
290 wxString str(attributeDialogName);
291 str += _T("1");
292 m_alternativeAttributeDialog = new wxPanel;
293 if (wxLoadFromResource(m_alternativeAttributeDialog, m_notebook, str))
294 {
295 m_notebook->AddPage(m_alternativeAttributeDialog, _T("Attributes (alternative)"));
296 }
297 else
298 {
299 delete m_alternativeAttributeDialog;
300 m_alternativeAttributeDialog = NULL;
301 }
302
303 int largeButtonWidth = 70;
304 int largeButtonHeight = 22;
305
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));
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
351 void 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)
363 void csShapePropertiesDialog::SetDefaults()
364 {
365 if (!m_attributeDialog)
366 return;
367
368 wxWindowList::compatibility_iterator node = m_attributeDialog->GetChildren().GetFirst();
369 while (node)
370 {
371 wxWindow* child = (wxWindow*) node->GetData();
372 if (child->IsKindOf(CLASSINFO(wxChoice)))
373 {
374 wxChoice* choice = (wxChoice*) child;
375 choice->SetSelection(0);
376 }
377 node = node->GetNext();
378 }
379
380 if (!m_alternativeAttributeDialog)
381 return;
382
383 node = m_alternativeAttributeDialog->GetChildren().GetFirst();
384 while (node)
385 {
386 wxWindow* child = (wxWindow*) node->GetData();
387 if (child->IsKindOf(CLASSINFO(wxChoice)))
388 {
389 wxChoice* choice = (wxChoice*) child;
390 choice->SetSelection(0);
391 }
392 node = node->GetNext();
393 }
394 }
395
396 /*
397 * csGeneralShapePropertiesDialog
398 */
399
400 IMPLEMENT_CLASS(csGeneralShapePropertiesDialog, wxPanel)
401
402 BEGIN_EVENT_TABLE(csGeneralShapePropertiesDialog, wxPanel)
403 END_EVENT_TABLE()
404
405 csGeneralShapePropertiesDialog::csGeneralShapePropertiesDialog()
406 {
407 }
408
409 void 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
423 IMPLEMENT_CLASS(csThinRectangleDialog, wxPanel)
424
425 BEGIN_EVENT_TABLE(csThinRectangleDialog, wxPanel)
426 END_EVENT_TABLE()
427
428 csThinRectangleDialog::csThinRectangleDialog()
429 {
430 }
431
432 /*
433 * csWideRectangleDialog
434 */
435
436 IMPLEMENT_CLASS(csWideRectangleDialog, wxPanel)
437
438 BEGIN_EVENT_TABLE(csWideRectangleDialog, wxPanel)
439 END_EVENT_TABLE()
440
441 csWideRectangleDialog::csWideRectangleDialog()
442 {
443 }
444
445 /*
446 * csTriangleDialog
447 */
448
449 IMPLEMENT_CLASS(csTriangleDialog, wxPanel)
450
451 BEGIN_EVENT_TABLE(csTriangleDialog, wxPanel)
452 END_EVENT_TABLE()
453
454 csTriangleDialog::csTriangleDialog()
455 {
456 }
457
458 /*
459 * csSemiCircleDialog
460 */
461
462 IMPLEMENT_CLASS(csSemiCircleDialog, wxPanel)
463
464 BEGIN_EVENT_TABLE(csSemiCircleDialog, wxPanel)
465 END_EVENT_TABLE()
466
467 csSemiCircleDialog::csSemiCircleDialog()
468 {
469 }
470
471 /*
472 * csCircleDialog
473 */
474
475 IMPLEMENT_CLASS(csCircleDialog, wxPanel)
476
477 BEGIN_EVENT_TABLE(csCircleDialog, wxPanel)
478 END_EVENT_TABLE()
479
480 csCircleDialog::csCircleDialog()
481 {
482 }
483
484 /*
485 * csCircleShadowDialog
486 */
487
488 IMPLEMENT_CLASS(csCircleShadowDialog, wxPanel)
489
490 BEGIN_EVENT_TABLE(csCircleShadowDialog, wxPanel)
491 END_EVENT_TABLE()
492
493 csCircleShadowDialog::csCircleShadowDialog()
494 {
495 }
496
497 /*
498 * csOctagonDialog
499 */
500
501 IMPLEMENT_CLASS(csOctagonDialog, wxPanel)
502
503 BEGIN_EVENT_TABLE(csOctagonDialog, wxPanel)
504 END_EVENT_TABLE()
505
506 csOctagonDialog::csOctagonDialog()
507 {
508 }
509
510 /*
511 * csGroupDialog
512 */
513
514 IMPLEMENT_CLASS(csGroupDialog, wxPanel)
515
516 BEGIN_EVENT_TABLE(csGroupDialog, wxPanel)
517 END_EVENT_TABLE()
518
519 csGroupDialog::csGroupDialog()
520 {
521 }
522
523 /*
524 * csTextBoxDialog
525 */
526
527 IMPLEMENT_CLASS(csTextBoxDialog, wxPanel)
528
529 BEGIN_EVENT_TABLE(csTextBoxDialog, wxPanel)
530 END_EVENT_TABLE()
531
532 csTextBoxDialog::csTextBoxDialog()
533 {
534 }
535
536