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
, -1, _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
;
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
);
107 m_diagramSettings
= new wxPanel
;
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"));
113 int largeButtonWidth
= 70;
114 int largeButtonHeight
= 22;
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
));
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
);
128 // Constraints for the Help button
129 c
= new wxLayoutConstraints
;
132 c
->right
.SameAs (this, wxRight
, 5);
133 c
->bottom
.SameAs (this, wxBottom
, 5);
134 helpButton
->SetConstraints(c
);
136 // Constraints for the Cancel button
137 c
= new wxLayoutConstraints
;
140 c
->right
.SameAs (helpButton
, wxLeft
, 5);
141 c
->bottom
.SameAs (this, wxBottom
, 5);
142 cancelButton
->SetConstraints(c
);
144 // Constraints for the OK button
145 c
= new wxLayoutConstraints
;
148 c
->right
.SameAs (cancelButton
, wxLeft
, 5);
149 c
->bottom
.SameAs (this, wxBottom
, 5);
150 okButton
->SetConstraints(c
);
152 okButton
->SetDefault();
153 okButton
->SetFocus();
159 void csSettingsDialog::OnOK(wxCommandEvent
& event
)
161 wxDialog::OnOK(event
);
164 bool csSettingsDialog::TransferDataToWindow()
166 wxTextCtrl
* gridSpacing
= (wxTextCtrl
*) m_diagramSettings
->FindWindow(ID_GRID_SPACING
);
167 wxASSERT_MSG( (gridSpacing
!= (wxTextCtrl
*) NULL
), _T("Could not find grid spacing control."));
169 wxChoice
* gridStyle
= (wxChoice
*) m_diagramSettings
->FindWindow(ID_GRID_STYLE
);
170 wxASSERT_MSG( (gridStyle
!= (wxChoice
*) NULL
), _T("Could not find grid style control."));
172 gridStyle
->SetSelection(wxGetApp().GetGridStyle());
175 str
.Printf(_T("%d"), wxGetApp().GetGridSpacing());
176 gridSpacing
->SetValue(str
);
181 bool csSettingsDialog::TransferDataFromWindow()
183 wxTextCtrl
* gridSpacing
= (wxTextCtrl
*) m_diagramSettings
->FindWindow(ID_GRID_SPACING
);
184 wxASSERT_MSG( (gridSpacing
!= (wxTextCtrl
*) NULL
), _T("Could not find grid spacing control."));
186 wxChoice
* gridStyle
= (wxChoice
*) m_diagramSettings
->FindWindow(ID_GRID_STYLE
);
187 wxASSERT_MSG( (gridStyle
!= (wxChoice
*) NULL
), _T("Could not find grid style control."));
189 wxGetApp().SetGridStyle(gridStyle
->GetSelection());
190 wxString str
= gridSpacing
->GetValue();
192 str
.ToLong( &grid_spacing
);
193 wxGetApp().SetGridSpacing(grid_spacing
);
195 if (wxGetApp().GetGridStyle() == csGRID_STYLE_DOTTED
)
197 wxMessageBox(_T("Dotted grid style not yet implemented."), _T("Studio"), wxICON_EXCLAMATION
);
201 // Apply settings to all open diagram documents
202 wxNode
* node
= wxGetApp().GetDocManager()->GetDocuments().First();
205 wxDocument
* doc
= (wxDocument
*) node
->Data();
206 if (doc
->IsKindOf(CLASSINFO(csDiagramDocument
)))
208 csDiagramDocument
* diagramDoc
= (csDiagramDocument
*) doc
;
209 wxDiagram
* diagram
= (wxDiagram
*) diagramDoc
->GetDiagram();
211 diagram
->SetGridSpacing((double) wxGetApp().GetGridSpacing());
212 switch (wxGetApp().GetGridStyle())
214 case csGRID_STYLE_NONE
:
216 diagram
->SetSnapToGrid(FALSE
);
219 case csGRID_STYLE_INVISIBLE
:
221 diagram
->SetSnapToGrid(TRUE
);
224 case csGRID_STYLE_DOTTED
:
226 // TODO (not implemented in OGL)
238 * Shape properties dialog (tabbed)
242 IMPLEMENT_CLASS(csShapePropertiesDialog
, wxDialog
)
244 BEGIN_EVENT_TABLE(csShapePropertiesDialog
, wxDialog
)
245 EVT_BUTTON(wxID_OK
, csShapePropertiesDialog::OnOK
)
248 #define SHAPE_PROPERTY_DIALOG_WIDTH 400
249 #define SHAPE_PROPERTY_DIALOG_HEIGHT 400
251 // For 400x400 settings dialog, size your panels to about 375x325 in dialog editor
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
))
257 m_attributeDialog
= attributeDialog
;
258 m_alternativeAttributeDialog
= NULL
;
259 m_generalPropertiesDialog
= NULL
;
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));
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"));
269 success
= wxLoadFromResource(m_attributeDialog
, m_notebook
, attributeDialogName
);
272 wxMessageBox(_T("Could not load the attribute dialog for this shape."), _T("Studio"), wxICON_EXCLAMATION
);
273 delete m_attributeDialog
;
274 m_attributeDialog
= NULL
;
278 m_notebook
->AddPage(m_attributeDialog
, _T("Attributes"));
281 // Try the alternative dialog (test code)
282 wxString
str(attributeDialogName
);
284 m_alternativeAttributeDialog
= new wxPanel
;
285 success
= wxLoadFromResource(m_alternativeAttributeDialog
, m_notebook
, str
);
288 m_notebook
->AddPage(m_alternativeAttributeDialog
, _T("Attributes (alternative)"));
292 delete m_alternativeAttributeDialog
;
293 m_alternativeAttributeDialog
= NULL
;
296 int largeButtonWidth
= 70;
297 int largeButtonHeight
= 22;
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
));
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
);
311 // Constraints for the Help button
312 c
= new wxLayoutConstraints
;
315 c
->right
.SameAs (this, wxRight
, 5);
316 c
->bottom
.SameAs (this, wxBottom
, 5);
317 helpButton
->SetConstraints(c
);
319 // Constraints for the Cancel button
320 c
= new wxLayoutConstraints
;
323 c
->right
.SameAs (helpButton
, wxLeft
, 5);
324 c
->bottom
.SameAs (this, wxBottom
, 5);
325 cancelButton
->SetConstraints(c
);
327 // Constraints for the OK button
328 c
= new wxLayoutConstraints
;
331 c
->right
.SameAs (cancelButton
, wxLeft
, 5);
332 c
->bottom
.SameAs (this, wxBottom
, 5);
333 okButton
->SetConstraints(c
);
335 okButton
->SetDefault();
336 okButton
->SetFocus();
344 void csShapePropertiesDialog::OnOK(wxCommandEvent
& event
)
346 wxTextCtrl
* textCtrl
= (wxTextCtrl
*) m_generalPropertiesDialog
->FindWindow(ID_LABELTEXT
);
347 wxASSERT( (textCtrl
!= NULL
) );
349 m_generalPropertiesDialog
->SetShapeLabel(textCtrl
->GetValue());
351 wxDialog::OnOK(event
);
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()
358 if (!m_attributeDialog
)
361 wxNode
* node
= m_attributeDialog
->GetChildren().First();
364 wxWindow
* child
= (wxWindow
*) node
->Data();
365 if (child
->IsKindOf(CLASSINFO(wxChoice
)))
367 wxChoice
* choice
= (wxChoice
*) child
;
368 choice
->SetSelection(0);
373 if (!m_alternativeAttributeDialog
)
376 node
= m_alternativeAttributeDialog
->GetChildren().First();
379 wxWindow
* child
= (wxWindow
*) node
->Data();
380 if (child
->IsKindOf(CLASSINFO(wxChoice
)))
382 wxChoice
* choice
= (wxChoice
*) child
;
383 choice
->SetSelection(0);
390 * csGeneralShapePropertiesDialog
393 IMPLEMENT_CLASS(csGeneralShapePropertiesDialog
, wxPanel
)
395 BEGIN_EVENT_TABLE(csGeneralShapePropertiesDialog
, wxPanel
)
398 csGeneralShapePropertiesDialog::csGeneralShapePropertiesDialog()
402 void csGeneralShapePropertiesDialog::SetShapeLabel(const wxString
& label
)
404 wxTextCtrl
* textCtrl
= (wxTextCtrl
*) FindWindow(ID_LABELTEXT
);
405 wxASSERT( (textCtrl
!= NULL
) );
409 textCtrl
->SetValue(label
);
413 * csThinRectangleDialog
416 IMPLEMENT_CLASS(csThinRectangleDialog
, wxPanel
)
418 BEGIN_EVENT_TABLE(csThinRectangleDialog
, wxPanel
)
421 csThinRectangleDialog::csThinRectangleDialog()
426 * csWideRectangleDialog
429 IMPLEMENT_CLASS(csWideRectangleDialog
, wxPanel
)
431 BEGIN_EVENT_TABLE(csWideRectangleDialog
, wxPanel
)
434 csWideRectangleDialog::csWideRectangleDialog()
442 IMPLEMENT_CLASS(csTriangleDialog
, wxPanel
)
444 BEGIN_EVENT_TABLE(csTriangleDialog
, wxPanel
)
447 csTriangleDialog::csTriangleDialog()
455 IMPLEMENT_CLASS(csSemiCircleDialog
, wxPanel
)
457 BEGIN_EVENT_TABLE(csSemiCircleDialog
, wxPanel
)
460 csSemiCircleDialog::csSemiCircleDialog()
468 IMPLEMENT_CLASS(csCircleDialog
, wxPanel
)
470 BEGIN_EVENT_TABLE(csCircleDialog
, wxPanel
)
473 csCircleDialog::csCircleDialog()
478 * csCircleShadowDialog
481 IMPLEMENT_CLASS(csCircleShadowDialog
, wxPanel
)
483 BEGIN_EVENT_TABLE(csCircleShadowDialog
, wxPanel
)
486 csCircleShadowDialog::csCircleShadowDialog()
494 IMPLEMENT_CLASS(csOctagonDialog
, wxPanel
)
496 BEGIN_EVENT_TABLE(csOctagonDialog
, wxPanel
)
499 csOctagonDialog::csOctagonDialog()
507 IMPLEMENT_CLASS(csGroupDialog
, wxPanel
)
509 BEGIN_EVENT_TABLE(csGroupDialog
, wxPanel
)
512 csGroupDialog::csGroupDialog()
520 IMPLEMENT_CLASS(csTextBoxDialog
, wxPanel
)
522 BEGIN_EVENT_TABLE(csTextBoxDialog
, wxPanel
)
525 csTextBoxDialog::csTextBoxDialog()