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