1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Implements Studio dialogs
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
10 /////////////////////////////////////////////////////////////////////////////
13 // #pragma implementation
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
27 #include <wx/deprecated/setup.h>
28 #include <wx/deprecated/resource.h>
33 #include "studio_resources.h"
35 IMPLEMENT_CLASS(csLabelEditingDialog
, wxDialog
)
37 BEGIN_EVENT_TABLE(csLabelEditingDialog
, wxDialog
)
38 EVT_BUTTON(wxID_OK
, csLabelEditingDialog::OnOK
)
41 csLabelEditingDialog::csLabelEditingDialog(wxWindow
* parent
)
43 wxLoadFromResource(this, parent
, _T("shape_label_dialog"));
46 wxAcceleratorEntry entries
[1];
47 entries
[0].Set(wxACCEL_CTRL
, WXK_RETURN
, wxID_OK
);
48 wxAcceleratorTable
accel(1, entries
);
49 SetAcceleratorTable(accel
);
53 wxTextCtrl
* textCtrl
= (wxTextCtrl
*) FindWindow(ID_LABELTEXT
);
54 wxASSERT( (textCtrl
!= NULL
) );
56 // textCtrl->SetAcceleratorTable(accel);
61 void csLabelEditingDialog::OnOK(wxCommandEvent
& event
)
63 wxTextCtrl
* textCtrl
= (wxTextCtrl
*) FindWindow(ID_LABELTEXT
);
64 wxASSERT( (textCtrl
!= NULL
) );
66 SetShapeLabel(textCtrl
->GetValue());
68 wxDialog::OnOK(event
);
71 void csLabelEditingDialog::SetShapeLabel(const wxString
& label
)
73 wxTextCtrl
* textCtrl
= (wxTextCtrl
*) FindWindow(ID_LABELTEXT
);
74 wxASSERT( (textCtrl
!= NULL
) );
78 textCtrl
->SetValue(label
);
81 IMPLEMENT_CLASS(csSettingsDialog
, wxDialog
)
83 BEGIN_EVENT_TABLE(csSettingsDialog
, wxDialog
)
84 EVT_BUTTON(wxID_OK
, csSettingsDialog::OnOK
)
87 #define PROPERTY_DIALOG_WIDTH 400
88 #define PROPERTY_DIALOG_HEIGHT 400
90 // For 400x400 settings dialog, size your panels to about 375x325 in dialog editor
92 csSettingsDialog::csSettingsDialog(wxWindow
* parent
):
93 wxDialog(parent
, wxID_ANY
, _T("Settings"), wxPoint(0, 0), wxSize(PROPERTY_DIALOG_WIDTH
, PROPERTY_DIALOG_HEIGHT
))
95 m_generalSettings
= NULL
;
96 m_diagramSettings
= NULL
;
98 m_notebook
= new wxNotebook(this, ID_PROPERTY_NOTEBOOK
,
99 wxPoint(2, 2), wxSize(PROPERTY_DIALOG_WIDTH
- 4, PROPERTY_DIALOG_HEIGHT
- 4));
101 m_generalSettings
= new wxPanel
;
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);
110 m_diagramSettings
= new wxPanel
;
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"));
119 int largeButtonWidth
= 70;
120 int largeButtonHeight
= 22;
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
));
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
);
134 // Constraints for the Help button
135 c
= new wxLayoutConstraints
;
138 c
->right
.SameAs (this, wxRight
, 5);
139 c
->bottom
.SameAs (this, wxBottom
, 5);
140 helpButton
->SetConstraints(c
);
142 // Constraints for the Cancel button
143 c
= new wxLayoutConstraints
;
146 c
->right
.SameAs (helpButton
, wxLeft
, 5);
147 c
->bottom
.SameAs (this, wxBottom
, 5);
148 cancelButton
->SetConstraints(c
);
150 // Constraints for the OK button
151 c
= new wxLayoutConstraints
;
154 c
->right
.SameAs (cancelButton
, wxLeft
, 5);
155 c
->bottom
.SameAs (this, wxBottom
, 5);
156 okButton
->SetConstraints(c
);
158 okButton
->SetDefault();
159 okButton
->SetFocus();
165 void csSettingsDialog::OnOK(wxCommandEvent
& event
)
167 wxDialog::OnOK(event
);
170 bool csSettingsDialog::TransferDataToWindow()
172 wxTextCtrl
* gridSpacing
= (wxTextCtrl
*) m_diagramSettings
->FindWindow(ID_GRID_SPACING
);
173 wxASSERT_MSG( (gridSpacing
!= (wxTextCtrl
*) NULL
), _T("Could not find grid spacing control."));
175 wxChoice
* gridStyle
= (wxChoice
*) m_diagramSettings
->FindWindow(ID_GRID_STYLE
);
176 wxASSERT_MSG( (gridStyle
!= (wxChoice
*) NULL
), _T("Could not find grid style control."));
178 gridStyle
->SetSelection(wxGetApp().GetGridStyle());
181 str
.Printf(_T("%d"), wxGetApp().GetGridSpacing());
182 gridSpacing
->SetValue(str
);
187 bool csSettingsDialog::TransferDataFromWindow()
189 wxTextCtrl
* gridSpacing
= (wxTextCtrl
*) m_diagramSettings
->FindWindow(ID_GRID_SPACING
);
190 wxASSERT_MSG( (gridSpacing
!= (wxTextCtrl
*) NULL
), _T("Could not find grid spacing control."));
192 wxChoice
* gridStyle
= (wxChoice
*) m_diagramSettings
->FindWindow(ID_GRID_STYLE
);
193 wxASSERT_MSG( (gridStyle
!= (wxChoice
*) NULL
), _T("Could not find grid style control."));
195 wxGetApp().SetGridStyle(gridStyle
->GetSelection());
196 wxString str
= gridSpacing
->GetValue();
198 str
.ToLong( &grid_spacing
);
199 wxGetApp().SetGridSpacing(grid_spacing
);
201 if (wxGetApp().GetGridStyle() == csGRID_STYLE_DOTTED
)
203 wxMessageBox(_T("Dotted grid style not yet implemented."), _T("Studio"), wxICON_EXCLAMATION
);
207 // Apply settings to all open diagram documents
208 wxNode
* node
= wxGetApp().GetDocManager()->GetDocuments().GetFirst();
211 wxDocument
* doc
= (wxDocument
*) node
->GetData();
212 if (doc
->IsKindOf(CLASSINFO(csDiagramDocument
)))
214 csDiagramDocument
* diagramDoc
= (csDiagramDocument
*) doc
;
215 wxDiagram
* diagram
= (wxDiagram
*) diagramDoc
->GetDiagram();
217 diagram
->SetGridSpacing((double) wxGetApp().GetGridSpacing());
218 switch (wxGetApp().GetGridStyle())
220 case csGRID_STYLE_NONE
:
222 diagram
->SetSnapToGrid(false);
225 case csGRID_STYLE_INVISIBLE
:
227 diagram
->SetSnapToGrid(true);
230 case csGRID_STYLE_DOTTED
:
232 // TODO (not implemented in OGL)
237 node
= node
->GetNext();
244 * Shape properties dialog (tabbed)
248 IMPLEMENT_CLASS(csShapePropertiesDialog
, wxDialog
)
250 BEGIN_EVENT_TABLE(csShapePropertiesDialog
, wxDialog
)
251 EVT_BUTTON(wxID_OK
, csShapePropertiesDialog::OnOK
)
254 #define SHAPE_PROPERTY_DIALOG_WIDTH 400
255 #define SHAPE_PROPERTY_DIALOG_HEIGHT 400
257 // For 400x400 settings dialog, size your panels to about 375x325 in dialog editor
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
))
263 m_attributeDialog
= attributeDialog
;
264 m_alternativeAttributeDialog
= NULL
;
265 m_generalPropertiesDialog
= NULL
;
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));
270 m_generalPropertiesDialog
= new csGeneralShapePropertiesDialog
;
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"));
278 if (!wxLoadFromResource(m_attributeDialog
, m_notebook
, attributeDialogName
))
280 wxMessageBox(_T("Could not load the attribute dialog for this shape."), _T("Studio"), wxICON_EXCLAMATION
);
281 delete m_attributeDialog
;
282 m_attributeDialog
= NULL
;
286 m_notebook
->AddPage(m_attributeDialog
, _T("Attributes"));
289 // Try the alternative dialog (test code)
290 wxString
str(attributeDialogName
);
292 m_alternativeAttributeDialog
= new wxPanel
;
293 if (wxLoadFromResource(m_alternativeAttributeDialog
, m_notebook
, str
))
295 m_notebook
->AddPage(m_alternativeAttributeDialog
, _T("Attributes (alternative)"));
299 delete m_alternativeAttributeDialog
;
300 m_alternativeAttributeDialog
= NULL
;
303 int largeButtonWidth
= 70;
304 int largeButtonHeight
= 22;
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
));
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
);
318 // Constraints for the Help button
319 c
= new wxLayoutConstraints
;
322 c
->right
.SameAs (this, wxRight
, 5);
323 c
->bottom
.SameAs (this, wxBottom
, 5);
324 helpButton
->SetConstraints(c
);
326 // Constraints for the Cancel button
327 c
= new wxLayoutConstraints
;
330 c
->right
.SameAs (helpButton
, wxLeft
, 5);
331 c
->bottom
.SameAs (this, wxBottom
, 5);
332 cancelButton
->SetConstraints(c
);
334 // Constraints for the OK button
335 c
= new wxLayoutConstraints
;
338 c
->right
.SameAs (cancelButton
, wxLeft
, 5);
339 c
->bottom
.SameAs (this, wxBottom
, 5);
340 okButton
->SetConstraints(c
);
342 okButton
->SetDefault();
343 okButton
->SetFocus();
351 void csShapePropertiesDialog::OnOK(wxCommandEvent
& event
)
353 wxTextCtrl
* textCtrl
= (wxTextCtrl
*) m_generalPropertiesDialog
->FindWindow(ID_LABELTEXT
);
354 wxASSERT( (textCtrl
!= NULL
) );
356 m_generalPropertiesDialog
->SetShapeLabel(textCtrl
->GetValue());
358 wxDialog::OnOK(event
);
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()
365 if (!m_attributeDialog
)
368 wxWindowListNode
* node
= m_attributeDialog
->GetChildren().GetFirst();
371 wxWindow
* child
= (wxWindow
*) node
->GetData();
372 if (child
->IsKindOf(CLASSINFO(wxChoice
)))
374 wxChoice
* choice
= (wxChoice
*) child
;
375 choice
->SetSelection(0);
377 node
= node
->GetNext();
380 if (!m_alternativeAttributeDialog
)
383 node
= m_alternativeAttributeDialog
->GetChildren().GetFirst();
386 wxWindow
* child
= (wxWindow
*) node
->GetData();
387 if (child
->IsKindOf(CLASSINFO(wxChoice
)))
389 wxChoice
* choice
= (wxChoice
*) child
;
390 choice
->SetSelection(0);
392 node
= node
->GetNext();
397 * csGeneralShapePropertiesDialog
400 IMPLEMENT_CLASS(csGeneralShapePropertiesDialog
, wxPanel
)
402 BEGIN_EVENT_TABLE(csGeneralShapePropertiesDialog
, wxPanel
)
405 csGeneralShapePropertiesDialog::csGeneralShapePropertiesDialog()
409 void csGeneralShapePropertiesDialog::SetShapeLabel(const wxString
& label
)
411 wxTextCtrl
* textCtrl
= (wxTextCtrl
*) FindWindow(ID_LABELTEXT
);
412 wxASSERT( (textCtrl
!= NULL
) );
416 textCtrl
->SetValue(label
);
420 * csThinRectangleDialog
423 IMPLEMENT_CLASS(csThinRectangleDialog
, wxPanel
)
425 BEGIN_EVENT_TABLE(csThinRectangleDialog
, wxPanel
)
428 csThinRectangleDialog::csThinRectangleDialog()
433 * csWideRectangleDialog
436 IMPLEMENT_CLASS(csWideRectangleDialog
, wxPanel
)
438 BEGIN_EVENT_TABLE(csWideRectangleDialog
, wxPanel
)
441 csWideRectangleDialog::csWideRectangleDialog()
449 IMPLEMENT_CLASS(csTriangleDialog
, wxPanel
)
451 BEGIN_EVENT_TABLE(csTriangleDialog
, wxPanel
)
454 csTriangleDialog::csTriangleDialog()
462 IMPLEMENT_CLASS(csSemiCircleDialog
, wxPanel
)
464 BEGIN_EVENT_TABLE(csSemiCircleDialog
, wxPanel
)
467 csSemiCircleDialog::csSemiCircleDialog()
475 IMPLEMENT_CLASS(csCircleDialog
, wxPanel
)
477 BEGIN_EVENT_TABLE(csCircleDialog
, wxPanel
)
480 csCircleDialog::csCircleDialog()
485 * csCircleShadowDialog
488 IMPLEMENT_CLASS(csCircleShadowDialog
, wxPanel
)
490 BEGIN_EVENT_TABLE(csCircleShadowDialog
, wxPanel
)
493 csCircleShadowDialog::csCircleShadowDialog()
501 IMPLEMENT_CLASS(csOctagonDialog
, wxPanel
)
503 BEGIN_EVENT_TABLE(csOctagonDialog
, wxPanel
)
506 csOctagonDialog::csOctagonDialog()
514 IMPLEMENT_CLASS(csGroupDialog
, wxPanel
)
516 BEGIN_EVENT_TABLE(csGroupDialog
, wxPanel
)
519 csGroupDialog::csGroupDialog()
527 IMPLEMENT_CLASS(csTextBoxDialog
, wxPanel
)
529 BEGIN_EVENT_TABLE(csTextBoxDialog
, wxPanel
)
532 csTextBoxDialog::csTextBoxDialog()