]> git.saurik.com Git - wxWidgets.git/blame - contrib/samples/ogl/studio/dialogs.cpp
IsDialogMessage fix
[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{
1484b5cc 43 wxLoadFromResource(this, parent, _T("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):
1484b5cc 93 wxDialog(parent, -1, _T("Settings"), wxPoint(0, 0), wxSize(PROPERTY_DIALOG_WIDTH, PROPERTY_DIALOG_HEIGHT))
1fc25a89
JS
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
1484b5cc
VS
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);
1fc25a89
JS
106
107 m_diagramSettings = new wxPanel;
108
1484b5cc
VS
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"));
1fc25a89
JS
112
113 int largeButtonWidth = 70;
114 int largeButtonHeight = 22;
115
1484b5cc
VS
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));
1fc25a89
JS
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);
1484b5cc 167 wxASSERT_MSG( (gridSpacing != (wxTextCtrl*) NULL), _T("Could not find grid spacing control."));
1fc25a89
JS
168
169 wxChoice* gridStyle = (wxChoice*) m_diagramSettings->FindWindow(ID_GRID_STYLE);
1484b5cc 170 wxASSERT_MSG( (gridStyle != (wxChoice*) NULL), _T("Could not find grid style control."));
1fc25a89
JS
171
172 gridStyle->SetSelection(wxGetApp().GetGridStyle());
173
174 wxString str;
1484b5cc 175 str.Printf(_T("%d"), wxGetApp().GetGridSpacing());
1fc25a89
JS
176 gridSpacing->SetValue(str);
177
178 return TRUE;
179}
180
181bool csSettingsDialog::TransferDataFromWindow()
182{
183 wxTextCtrl* gridSpacing = (wxTextCtrl*) m_diagramSettings->FindWindow(ID_GRID_SPACING);
1484b5cc 184 wxASSERT_MSG( (gridSpacing != (wxTextCtrl*) NULL), _T("Could not find grid spacing control."));
1fc25a89
JS
185
186 wxChoice* gridStyle = (wxChoice*) m_diagramSettings->FindWindow(ID_GRID_STYLE);
1484b5cc 187 wxASSERT_MSG( (gridStyle != (wxChoice*) NULL), _T("Could not find grid style control."));
1fc25a89
JS
188
189 wxGetApp().SetGridStyle(gridStyle->GetSelection());
1484b5cc
VS
190 wxString str = gridSpacing->GetValue();
191 long grid_spacing;
192 str.ToLong( &grid_spacing);
193 wxGetApp().SetGridSpacing(grid_spacing);
1fc25a89
JS
194
195 if (wxGetApp().GetGridStyle() == csGRID_STYLE_DOTTED)
196 {
1484b5cc 197 wxMessageBox(_T("Dotted grid style not yet implemented."), _T("Studio"), wxICON_EXCLAMATION);
1fc25a89
JS
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
242IMPLEMENT_CLASS(csShapePropertiesDialog, wxDialog)
243
244BEGIN_EVENT_TABLE(csShapePropertiesDialog, wxDialog)
245 EVT_BUTTON(wxID_OK, csShapePropertiesDialog::OnOK)
246END_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
253csShapePropertiesDialog::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;
1484b5cc
VS
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"));
1fc25a89 268
7c9955d1 269 success = wxLoadFromResource(m_attributeDialog, m_notebook, attributeDialogName);
1fc25a89
JS
270 if (!success)
271 {
1484b5cc 272 wxMessageBox(_T("Could not load the attribute dialog for this shape."), _T("Studio"), wxICON_EXCLAMATION);
1fc25a89
JS
273 delete m_attributeDialog;
274 m_attributeDialog = NULL;
275 }
276 else
277 {
1484b5cc 278 m_notebook->AddPage(m_attributeDialog, _T("Attributes"));
1fc25a89
JS
279 }
280
281 // Try the alternative dialog (test code)
282 wxString str(attributeDialogName);
1484b5cc 283 str += _T("1");
1fc25a89 284 m_alternativeAttributeDialog = new wxPanel;
7c9955d1 285 success = wxLoadFromResource(m_alternativeAttributeDialog, m_notebook, str);
1fc25a89
JS
286 if (success)
287 {
1484b5cc 288 m_notebook->AddPage(m_alternativeAttributeDialog, _T("Attributes (alternative)"));
1fc25a89
JS
289 }
290 else
291 {
292 delete m_alternativeAttributeDialog;
293 m_alternativeAttributeDialog = NULL;
294 }
295
296 int largeButtonWidth = 70;
297 int largeButtonHeight = 22;
298
1484b5cc
VS
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));
1fc25a89
JS
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
344void 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)
356void 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
393IMPLEMENT_CLASS(csGeneralShapePropertiesDialog, wxPanel)
394
395BEGIN_EVENT_TABLE(csGeneralShapePropertiesDialog, wxPanel)
396END_EVENT_TABLE()
397
398csGeneralShapePropertiesDialog::csGeneralShapePropertiesDialog()
399{
400}
401
402void 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
416IMPLEMENT_CLASS(csThinRectangleDialog, wxPanel)
417
418BEGIN_EVENT_TABLE(csThinRectangleDialog, wxPanel)
419END_EVENT_TABLE()
420
421csThinRectangleDialog::csThinRectangleDialog()
422{
423}
424
425/*
426 * csWideRectangleDialog
427 */
428
429IMPLEMENT_CLASS(csWideRectangleDialog, wxPanel)
430
431BEGIN_EVENT_TABLE(csWideRectangleDialog, wxPanel)
432END_EVENT_TABLE()
433
434csWideRectangleDialog::csWideRectangleDialog()
435{
436}
437
438/*
439 * csTriangleDialog
440 */
441
442IMPLEMENT_CLASS(csTriangleDialog, wxPanel)
443
444BEGIN_EVENT_TABLE(csTriangleDialog, wxPanel)
445END_EVENT_TABLE()
446
447csTriangleDialog::csTriangleDialog()
448{
449}
450
451/*
452 * csSemiCircleDialog
453 */
454
455IMPLEMENT_CLASS(csSemiCircleDialog, wxPanel)
456
457BEGIN_EVENT_TABLE(csSemiCircleDialog, wxPanel)
458END_EVENT_TABLE()
459
460csSemiCircleDialog::csSemiCircleDialog()
461{
462}
463
464/*
465 * csCircleDialog
466 */
467
468IMPLEMENT_CLASS(csCircleDialog, wxPanel)
469
470BEGIN_EVENT_TABLE(csCircleDialog, wxPanel)
471END_EVENT_TABLE()
472
473csCircleDialog::csCircleDialog()
474{
475}
476
477/*
478 * csCircleShadowDialog
479 */
480
481IMPLEMENT_CLASS(csCircleShadowDialog, wxPanel)
482
483BEGIN_EVENT_TABLE(csCircleShadowDialog, wxPanel)
484END_EVENT_TABLE()
485
486csCircleShadowDialog::csCircleShadowDialog()
487{
488}
489
490/*
491 * csOctagonDialog
492 */
493
494IMPLEMENT_CLASS(csOctagonDialog, wxPanel)
495
496BEGIN_EVENT_TABLE(csOctagonDialog, wxPanel)
497END_EVENT_TABLE()
498
499csOctagonDialog::csOctagonDialog()
500{
501}
502
503/*
504 * csGroupDialog
505 */
506
507IMPLEMENT_CLASS(csGroupDialog, wxPanel)
508
509BEGIN_EVENT_TABLE(csGroupDialog, wxPanel)
510END_EVENT_TABLE()
511
512csGroupDialog::csGroupDialog()
513{
514}
515
516/*
517 * csTextBoxDialog
518 */
519
520IMPLEMENT_CLASS(csTextBoxDialog, wxPanel)
521
522BEGIN_EVENT_TABLE(csTextBoxDialog, wxPanel)
523END_EVENT_TABLE()
524
525csTextBoxDialog::csTextBoxDialog()
526{
527}
528
529