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/resource.h>
32 #include "studio_resources.h"
34 IMPLEMENT_CLASS(csLabelEditingDialog
, wxDialog
)
36 BEGIN_EVENT_TABLE(csLabelEditingDialog
, wxDialog
)
37 EVT_BUTTON(wxID_OK
, csLabelEditingDialog::OnOK
)
40 csLabelEditingDialog::csLabelEditingDialog(wxWindow
* parent
)
42 LoadFromResource(parent
, "shape_label_dialog");
45 wxAcceleratorEntry entries
[1];
46 entries
[0].Set(wxACCEL_CTRL
, WXK_RETURN
, wxID_OK
);
47 wxAcceleratorTable
accel(1, entries
);
48 SetAcceleratorTable(accel
);
52 wxTextCtrl
* textCtrl
= (wxTextCtrl
*) FindWindow(ID_LABELTEXT
);
53 wxASSERT( (textCtrl
!= NULL
) );
55 // textCtrl->SetAcceleratorTable(accel);
60 void csLabelEditingDialog::OnOK(wxCommandEvent
& event
)
62 wxTextCtrl
* textCtrl
= (wxTextCtrl
*) FindWindow(ID_LABELTEXT
);
63 wxASSERT( (textCtrl
!= NULL
) );
65 SetShapeLabel(textCtrl
->GetValue());
67 wxDialog::OnOK(event
);
70 void csLabelEditingDialog::SetShapeLabel(const wxString
& label
)
72 wxTextCtrl
* textCtrl
= (wxTextCtrl
*) FindWindow(ID_LABELTEXT
);
73 wxASSERT( (textCtrl
!= NULL
) );
77 textCtrl
->SetValue(label
);
80 IMPLEMENT_CLASS(csSettingsDialog
, wxDialog
)
82 BEGIN_EVENT_TABLE(csSettingsDialog
, wxDialog
)
83 EVT_BUTTON(wxID_OK
, csSettingsDialog::OnOK
)
86 #define PROPERTY_DIALOG_WIDTH 400
87 #define PROPERTY_DIALOG_HEIGHT 400
89 // For 400x400 settings dialog, size your panels to about 375x325 in dialog editor
91 csSettingsDialog::csSettingsDialog(wxWindow
* parent
):
92 wxDialog(parent
, -1, "Settings", wxPoint(0, 0), wxSize(PROPERTY_DIALOG_WIDTH
, PROPERTY_DIALOG_HEIGHT
))
94 m_generalSettings
= NULL
;
95 m_diagramSettings
= NULL
;
97 m_notebook
= new wxNotebook(this, ID_PROPERTY_NOTEBOOK
,
98 wxPoint(2, 2), wxSize(PROPERTY_DIALOG_WIDTH
- 4, PROPERTY_DIALOG_HEIGHT
- 4));
100 m_generalSettings
= new wxPanel
;
102 bool success
= m_generalSettings
->LoadFromResource(m_notebook
, "general_settings_dialog");
103 wxASSERT_MSG( (success
), "Could not load general settings panel.");
104 m_notebook
->AddPage(m_generalSettings
, "General", TRUE
);
106 m_diagramSettings
= new wxPanel
;
108 success
= m_diagramSettings
->LoadFromResource(m_notebook
, "diagram_settings_dialog");
109 wxASSERT_MSG( (success
), "Could not load diagram settings panel.");
110 m_notebook
->AddPage(m_diagramSettings
, "Diagram");
112 int largeButtonWidth
= 70;
113 int largeButtonHeight
= 22;
115 wxButton
* okButton
= new wxButton(this, wxID_OK
, "OK", wxPoint(0, 0), wxSize(largeButtonWidth
, largeButtonHeight
));
116 wxButton
* cancelButton
= new wxButton(this, wxID_CANCEL
, "Cancel", wxPoint(0, 0), wxSize(largeButtonWidth
, largeButtonHeight
));
117 wxButton
* helpButton
= new wxButton(this, wxID_HELP
, "Help", wxPoint(0, 0), wxSize(largeButtonWidth
, largeButtonHeight
));
119 // Constraints for the notebook
120 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
121 c
->top
.SameAs (this, wxTop
, 5);
122 c
->left
.SameAs (this, wxLeft
, 5);
123 c
->right
.SameAs (this, wxRight
, 5);
124 c
->bottom
.SameAs (cancelButton
, wxTop
, 5);
125 m_notebook
->SetConstraints(c
);
127 // Constraints for the Help button
128 c
= new wxLayoutConstraints
;
131 c
->right
.SameAs (this, wxRight
, 5);
132 c
->bottom
.SameAs (this, wxBottom
, 5);
133 helpButton
->SetConstraints(c
);
135 // Constraints for the Cancel button
136 c
= new wxLayoutConstraints
;
139 c
->right
.SameAs (helpButton
, wxLeft
, 5);
140 c
->bottom
.SameAs (this, wxBottom
, 5);
141 cancelButton
->SetConstraints(c
);
143 // Constraints for the OK button
144 c
= new wxLayoutConstraints
;
147 c
->right
.SameAs (cancelButton
, wxLeft
, 5);
148 c
->bottom
.SameAs (this, wxBottom
, 5);
149 okButton
->SetConstraints(c
);
151 okButton
->SetDefault();
152 okButton
->SetFocus();
158 void csSettingsDialog::OnOK(wxCommandEvent
& event
)
160 wxDialog::OnOK(event
);
163 bool csSettingsDialog::TransferDataToWindow()
165 wxTextCtrl
* gridSpacing
= (wxTextCtrl
*) m_diagramSettings
->FindWindow(ID_GRID_SPACING
);
166 wxASSERT_MSG( (gridSpacing
!= (wxTextCtrl
*) NULL
), "Could not find grid spacing control.");
168 wxChoice
* gridStyle
= (wxChoice
*) m_diagramSettings
->FindWindow(ID_GRID_STYLE
);
169 wxASSERT_MSG( (gridStyle
!= (wxChoice
*) NULL
), "Could not find grid style control.");
171 gridStyle
->SetSelection(wxGetApp().GetGridStyle());
174 str
.Printf("%d", wxGetApp().GetGridSpacing());
175 gridSpacing
->SetValue(str
);
180 bool csSettingsDialog::TransferDataFromWindow()
182 wxTextCtrl
* gridSpacing
= (wxTextCtrl
*) m_diagramSettings
->FindWindow(ID_GRID_SPACING
);
183 wxASSERT_MSG( (gridSpacing
!= (wxTextCtrl
*) NULL
), "Could not find grid spacing control.");
185 wxChoice
* gridStyle
= (wxChoice
*) m_diagramSettings
->FindWindow(ID_GRID_STYLE
);
186 wxASSERT_MSG( (gridStyle
!= (wxChoice
*) NULL
), "Could not find grid style control.");
188 wxGetApp().SetGridStyle(gridStyle
->GetSelection());
189 wxGetApp().SetGridSpacing(atoi(gridSpacing
->GetValue()));
191 if (wxGetApp().GetGridStyle() == csGRID_STYLE_DOTTED
)
193 wxMessageBox("Dotted grid style not yet implemented.", "Studio", wxICON_EXCLAMATION
);
197 // Apply settings to all open diagram documents
198 wxNode
* node
= wxGetApp().GetDocManager()->GetDocuments().First();
201 wxDocument
* doc
= (wxDocument
*) node
->Data();
202 if (doc
->IsKindOf(CLASSINFO(csDiagramDocument
)))
204 csDiagramDocument
* diagramDoc
= (csDiagramDocument
*) doc
;
205 wxDiagram
* diagram
= (wxDiagram
*) diagramDoc
->GetDiagram();
207 diagram
->SetGridSpacing((double) wxGetApp().GetGridSpacing());
208 switch (wxGetApp().GetGridStyle())
210 case csGRID_STYLE_NONE
:
212 diagram
->SetSnapToGrid(FALSE
);
215 case csGRID_STYLE_INVISIBLE
:
217 diagram
->SetSnapToGrid(TRUE
);
220 case csGRID_STYLE_DOTTED
:
222 // TODO (not implemented in OGL)
234 * Shape properties dialog (tabbed)
238 IMPLEMENT_CLASS(csShapePropertiesDialog
, wxDialog
)
240 BEGIN_EVENT_TABLE(csShapePropertiesDialog
, wxDialog
)
241 EVT_BUTTON(wxID_OK
, csShapePropertiesDialog::OnOK
)
244 #define SHAPE_PROPERTY_DIALOG_WIDTH 400
245 #define SHAPE_PROPERTY_DIALOG_HEIGHT 400
247 // For 400x400 settings dialog, size your panels to about 375x325 in dialog editor
249 csShapePropertiesDialog::csShapePropertiesDialog(wxWindow
* parent
, const wxString
& title
,
250 wxPanel
* attributeDialog
, const wxString
& attributeDialogName
):
251 wxDialog(parent
, -1, title
, wxPoint(0, 0), wxSize(SHAPE_PROPERTY_DIALOG_WIDTH
, SHAPE_PROPERTY_DIALOG_HEIGHT
))
253 m_attributeDialog
= attributeDialog
;
254 m_alternativeAttributeDialog
= NULL
;
255 m_generalPropertiesDialog
= NULL
;
257 m_notebook
= new wxNotebook(this, ID_SHAPE_PROPERTY_NOTEBOOK
,
258 wxPoint(2, 2), wxSize(SHAPE_PROPERTY_DIALOG_WIDTH
- 4, SHAPE_PROPERTY_DIALOG_HEIGHT
- 4));
260 m_generalPropertiesDialog
= new csGeneralShapePropertiesDialog
;
261 bool success
= m_generalPropertiesDialog
->LoadFromResource(m_notebook
, "general_shape_properties_dialog");
262 wxASSERT_MSG( (success
), "Could not load general properties panel.");
263 m_notebook
->AddPage(m_generalPropertiesDialog
, "General");
265 success
= m_attributeDialog
->LoadFromResource(m_notebook
, attributeDialogName
);
268 wxMessageBox("Could not load the attribute dialog for this shape.", "Studio", wxICON_EXCLAMATION
);
269 delete m_attributeDialog
;
270 m_attributeDialog
= NULL
;
274 m_notebook
->AddPage(m_attributeDialog
, "Attributes");
277 // Try the alternative dialog (test code)
278 wxString
str(attributeDialogName
);
280 m_alternativeAttributeDialog
= new wxPanel
;
281 success
= m_alternativeAttributeDialog
->LoadFromResource(m_notebook
, str
);
284 m_notebook
->AddPage(m_alternativeAttributeDialog
, "Attributes (alternative)");
288 delete m_alternativeAttributeDialog
;
289 m_alternativeAttributeDialog
= NULL
;
292 int largeButtonWidth
= 70;
293 int largeButtonHeight
= 22;
295 wxButton
* okButton
= new wxButton(this, wxID_OK
, "OK", wxPoint(0, 0), wxSize(largeButtonWidth
, largeButtonHeight
));
296 wxButton
* cancelButton
= new wxButton(this, wxID_CANCEL
, "Cancel", wxPoint(0, 0), wxSize(largeButtonWidth
, largeButtonHeight
));
297 wxButton
* helpButton
= new wxButton(this, wxID_HELP
, "Help", wxPoint(0, 0), wxSize(largeButtonWidth
, largeButtonHeight
));
299 // Constraints for the notebook
300 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
301 c
->top
.SameAs (this, wxTop
, 5);
302 c
->left
.SameAs (this, wxLeft
, 5);
303 c
->right
.SameAs (this, wxRight
, 5);
304 c
->bottom
.SameAs (helpButton
, wxTop
, 5);
305 m_notebook
->SetConstraints(c
);
307 // Constraints for the Help button
308 c
= new wxLayoutConstraints
;
311 c
->right
.SameAs (this, wxRight
, 5);
312 c
->bottom
.SameAs (this, wxBottom
, 5);
313 helpButton
->SetConstraints(c
);
315 // Constraints for the Cancel button
316 c
= new wxLayoutConstraints
;
319 c
->right
.SameAs (helpButton
, wxLeft
, 5);
320 c
->bottom
.SameAs (this, wxBottom
, 5);
321 cancelButton
->SetConstraints(c
);
323 // Constraints for the OK button
324 c
= new wxLayoutConstraints
;
327 c
->right
.SameAs (cancelButton
, wxLeft
, 5);
328 c
->bottom
.SameAs (this, wxBottom
, 5);
329 okButton
->SetConstraints(c
);
331 okButton
->SetDefault();
332 okButton
->SetFocus();
340 void csShapePropertiesDialog::OnOK(wxCommandEvent
& event
)
342 wxTextCtrl
* textCtrl
= (wxTextCtrl
*) m_generalPropertiesDialog
->FindWindow(ID_LABELTEXT
);
343 wxASSERT( (textCtrl
!= NULL
) );
345 m_generalPropertiesDialog
->SetShapeLabel(textCtrl
->GetValue());
347 wxDialog::OnOK(event
);
350 // Set some suitable defaults in the attribute dialogs (in the first instance,
351 // just set all wxChoices to the first element)
352 void csShapePropertiesDialog::SetDefaults()
354 if (!m_attributeDialog
)
357 wxNode
* node
= m_attributeDialog
->GetChildren().First();
360 wxWindow
* child
= (wxWindow
*) node
->Data();
361 if (child
->IsKindOf(CLASSINFO(wxChoice
)))
363 wxChoice
* choice
= (wxChoice
*) child
;
364 choice
->SetSelection(0);
369 if (!m_alternativeAttributeDialog
)
372 node
= m_alternativeAttributeDialog
->GetChildren().First();
375 wxWindow
* child
= (wxWindow
*) node
->Data();
376 if (child
->IsKindOf(CLASSINFO(wxChoice
)))
378 wxChoice
* choice
= (wxChoice
*) child
;
379 choice
->SetSelection(0);
386 * csGeneralShapePropertiesDialog
389 IMPLEMENT_CLASS(csGeneralShapePropertiesDialog
, wxPanel
)
391 BEGIN_EVENT_TABLE(csGeneralShapePropertiesDialog
, wxPanel
)
394 csGeneralShapePropertiesDialog::csGeneralShapePropertiesDialog()
398 void csGeneralShapePropertiesDialog::SetShapeLabel(const wxString
& label
)
400 wxTextCtrl
* textCtrl
= (wxTextCtrl
*) FindWindow(ID_LABELTEXT
);
401 wxASSERT( (textCtrl
!= NULL
) );
405 textCtrl
->SetValue(label
);
409 * csThinRectangleDialog
412 IMPLEMENT_CLASS(csThinRectangleDialog
, wxPanel
)
414 BEGIN_EVENT_TABLE(csThinRectangleDialog
, wxPanel
)
417 csThinRectangleDialog::csThinRectangleDialog()
422 * csWideRectangleDialog
425 IMPLEMENT_CLASS(csWideRectangleDialog
, wxPanel
)
427 BEGIN_EVENT_TABLE(csWideRectangleDialog
, wxPanel
)
430 csWideRectangleDialog::csWideRectangleDialog()
438 IMPLEMENT_CLASS(csTriangleDialog
, wxPanel
)
440 BEGIN_EVENT_TABLE(csTriangleDialog
, wxPanel
)
443 csTriangleDialog::csTriangleDialog()
451 IMPLEMENT_CLASS(csSemiCircleDialog
, wxPanel
)
453 BEGIN_EVENT_TABLE(csSemiCircleDialog
, wxPanel
)
456 csSemiCircleDialog::csSemiCircleDialog()
464 IMPLEMENT_CLASS(csCircleDialog
, wxPanel
)
466 BEGIN_EVENT_TABLE(csCircleDialog
, wxPanel
)
469 csCircleDialog::csCircleDialog()
474 * csCircleShadowDialog
477 IMPLEMENT_CLASS(csCircleShadowDialog
, wxPanel
)
479 BEGIN_EVENT_TABLE(csCircleShadowDialog
, wxPanel
)
482 csCircleShadowDialog::csCircleShadowDialog()
490 IMPLEMENT_CLASS(csOctagonDialog
, wxPanel
)
492 BEGIN_EVENT_TABLE(csOctagonDialog
, wxPanel
)
495 csOctagonDialog::csOctagonDialog()
503 IMPLEMENT_CLASS(csGroupDialog
, wxPanel
)
505 BEGIN_EVENT_TABLE(csGroupDialog
, wxPanel
)
508 csGroupDialog::csGroupDialog()
516 IMPLEMENT_CLASS(csTextBoxDialog
, wxPanel
)
518 BEGIN_EVENT_TABLE(csTextBoxDialog
, wxPanel
)
521 csTextBoxDialog::csTextBoxDialog()