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
, "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, "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
, "general_settings_dialog");
104 wxASSERT_MSG( (success
), "Could not load general settings panel.");
105 m_notebook
->AddPage(m_generalSettings
, "General", TRUE
);
107 m_diagramSettings
= new wxPanel
;
109 success
= wxLoadFromResource(m_diagramSettings
, m_notebook
, "diagram_settings_dialog");
110 wxASSERT_MSG( (success
), "Could not load diagram settings panel.");
111 m_notebook
->AddPage(m_diagramSettings
, "Diagram");
113 int largeButtonWidth
= 70;
114 int largeButtonHeight
= 22;
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
));
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
), "Could not find grid spacing control.");
169 wxChoice
* gridStyle
= (wxChoice
*) m_diagramSettings
->FindWindow(ID_GRID_STYLE
);
170 wxASSERT_MSG( (gridStyle
!= (wxChoice
*) NULL
), "Could not find grid style control.");
172 gridStyle
->SetSelection(wxGetApp().GetGridStyle());
175 str
.Printf("%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
), "Could not find grid spacing control.");
186 wxChoice
* gridStyle
= (wxChoice
*) m_diagramSettings
->FindWindow(ID_GRID_STYLE
);
187 wxASSERT_MSG( (gridStyle
!= (wxChoice
*) NULL
), "Could not find grid style control.");
189 wxGetApp().SetGridStyle(gridStyle
->GetSelection());
190 wxGetApp().SetGridSpacing(atoi(gridSpacing
->GetValue()));
192 if (wxGetApp().GetGridStyle() == csGRID_STYLE_DOTTED
)
194 wxMessageBox("Dotted grid style not yet implemented.", "Studio", wxICON_EXCLAMATION
);
198 // Apply settings to all open diagram documents
199 wxNode
* node
= wxGetApp().GetDocManager()->GetDocuments().First();
202 wxDocument
* doc
= (wxDocument
*) node
->Data();
203 if (doc
->IsKindOf(CLASSINFO(csDiagramDocument
)))
205 csDiagramDocument
* diagramDoc
= (csDiagramDocument
*) doc
;
206 wxDiagram
* diagram
= (wxDiagram
*) diagramDoc
->GetDiagram();
208 diagram
->SetGridSpacing((double) wxGetApp().GetGridSpacing());
209 switch (wxGetApp().GetGridStyle())
211 case csGRID_STYLE_NONE
:
213 diagram
->SetSnapToGrid(FALSE
);
216 case csGRID_STYLE_INVISIBLE
:
218 diagram
->SetSnapToGrid(TRUE
);
221 case csGRID_STYLE_DOTTED
:
223 // TODO (not implemented in OGL)
235 * Shape properties dialog (tabbed)
239 IMPLEMENT_CLASS(csShapePropertiesDialog
, wxDialog
)
241 BEGIN_EVENT_TABLE(csShapePropertiesDialog
, wxDialog
)
242 EVT_BUTTON(wxID_OK
, csShapePropertiesDialog::OnOK
)
245 #define SHAPE_PROPERTY_DIALOG_WIDTH 400
246 #define SHAPE_PROPERTY_DIALOG_HEIGHT 400
248 // For 400x400 settings dialog, size your panels to about 375x325 in dialog editor
250 csShapePropertiesDialog::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
))
254 m_attributeDialog
= attributeDialog
;
255 m_alternativeAttributeDialog
= NULL
;
256 m_generalPropertiesDialog
= NULL
;
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));
261 m_generalPropertiesDialog
= new csGeneralShapePropertiesDialog
;
262 bool success
= wxLoadFromResource(m_generalPropertiesDialog
, m_notebook
, "general_shape_properties_dialog");
263 wxASSERT_MSG( (success
), "Could not load general properties panel.");
264 m_notebook
->AddPage(m_generalPropertiesDialog
, "General");
266 success
= wxLoadFromResource(m_attributeDialog
, m_notebook
, attributeDialogName
);
269 wxMessageBox("Could not load the attribute dialog for this shape.", "Studio", wxICON_EXCLAMATION
);
270 delete m_attributeDialog
;
271 m_attributeDialog
= NULL
;
275 m_notebook
->AddPage(m_attributeDialog
, "Attributes");
278 // Try the alternative dialog (test code)
279 wxString
str(attributeDialogName
);
281 m_alternativeAttributeDialog
= new wxPanel
;
282 success
= wxLoadFromResource(m_alternativeAttributeDialog
, m_notebook
, str
);
285 m_notebook
->AddPage(m_alternativeAttributeDialog
, "Attributes (alternative)");
289 delete m_alternativeAttributeDialog
;
290 m_alternativeAttributeDialog
= NULL
;
293 int largeButtonWidth
= 70;
294 int largeButtonHeight
= 22;
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
));
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
);
308 // Constraints for the Help button
309 c
= new wxLayoutConstraints
;
312 c
->right
.SameAs (this, wxRight
, 5);
313 c
->bottom
.SameAs (this, wxBottom
, 5);
314 helpButton
->SetConstraints(c
);
316 // Constraints for the Cancel button
317 c
= new wxLayoutConstraints
;
320 c
->right
.SameAs (helpButton
, wxLeft
, 5);
321 c
->bottom
.SameAs (this, wxBottom
, 5);
322 cancelButton
->SetConstraints(c
);
324 // Constraints for the OK button
325 c
= new wxLayoutConstraints
;
328 c
->right
.SameAs (cancelButton
, wxLeft
, 5);
329 c
->bottom
.SameAs (this, wxBottom
, 5);
330 okButton
->SetConstraints(c
);
332 okButton
->SetDefault();
333 okButton
->SetFocus();
341 void csShapePropertiesDialog::OnOK(wxCommandEvent
& event
)
343 wxTextCtrl
* textCtrl
= (wxTextCtrl
*) m_generalPropertiesDialog
->FindWindow(ID_LABELTEXT
);
344 wxASSERT( (textCtrl
!= NULL
) );
346 m_generalPropertiesDialog
->SetShapeLabel(textCtrl
->GetValue());
348 wxDialog::OnOK(event
);
351 // Set some suitable defaults in the attribute dialogs (in the first instance,
352 // just set all wxChoices to the first element)
353 void csShapePropertiesDialog::SetDefaults()
355 if (!m_attributeDialog
)
358 wxNode
* node
= m_attributeDialog
->GetChildren().First();
361 wxWindow
* child
= (wxWindow
*) node
->Data();
362 if (child
->IsKindOf(CLASSINFO(wxChoice
)))
364 wxChoice
* choice
= (wxChoice
*) child
;
365 choice
->SetSelection(0);
370 if (!m_alternativeAttributeDialog
)
373 node
= m_alternativeAttributeDialog
->GetChildren().First();
376 wxWindow
* child
= (wxWindow
*) node
->Data();
377 if (child
->IsKindOf(CLASSINFO(wxChoice
)))
379 wxChoice
* choice
= (wxChoice
*) child
;
380 choice
->SetSelection(0);
387 * csGeneralShapePropertiesDialog
390 IMPLEMENT_CLASS(csGeneralShapePropertiesDialog
, wxPanel
)
392 BEGIN_EVENT_TABLE(csGeneralShapePropertiesDialog
, wxPanel
)
395 csGeneralShapePropertiesDialog::csGeneralShapePropertiesDialog()
399 void csGeneralShapePropertiesDialog::SetShapeLabel(const wxString
& label
)
401 wxTextCtrl
* textCtrl
= (wxTextCtrl
*) FindWindow(ID_LABELTEXT
);
402 wxASSERT( (textCtrl
!= NULL
) );
406 textCtrl
->SetValue(label
);
410 * csThinRectangleDialog
413 IMPLEMENT_CLASS(csThinRectangleDialog
, wxPanel
)
415 BEGIN_EVENT_TABLE(csThinRectangleDialog
, wxPanel
)
418 csThinRectangleDialog::csThinRectangleDialog()
423 * csWideRectangleDialog
426 IMPLEMENT_CLASS(csWideRectangleDialog
, wxPanel
)
428 BEGIN_EVENT_TABLE(csWideRectangleDialog
, wxPanel
)
431 csWideRectangleDialog::csWideRectangleDialog()
439 IMPLEMENT_CLASS(csTriangleDialog
, wxPanel
)
441 BEGIN_EVENT_TABLE(csTriangleDialog
, wxPanel
)
444 csTriangleDialog::csTriangleDialog()
452 IMPLEMENT_CLASS(csSemiCircleDialog
, wxPanel
)
454 BEGIN_EVENT_TABLE(csSemiCircleDialog
, wxPanel
)
457 csSemiCircleDialog::csSemiCircleDialog()
465 IMPLEMENT_CLASS(csCircleDialog
, wxPanel
)
467 BEGIN_EVENT_TABLE(csCircleDialog
, wxPanel
)
470 csCircleDialog::csCircleDialog()
475 * csCircleShadowDialog
478 IMPLEMENT_CLASS(csCircleShadowDialog
, wxPanel
)
480 BEGIN_EVENT_TABLE(csCircleShadowDialog
, wxPanel
)
483 csCircleShadowDialog::csCircleShadowDialog()
491 IMPLEMENT_CLASS(csOctagonDialog
, wxPanel
)
493 BEGIN_EVENT_TABLE(csOctagonDialog
, wxPanel
)
496 csOctagonDialog::csOctagonDialog()
504 IMPLEMENT_CLASS(csGroupDialog
, wxPanel
)
506 BEGIN_EVENT_TABLE(csGroupDialog
, wxPanel
)
509 csGroupDialog::csGroupDialog()
517 IMPLEMENT_CLASS(csTextBoxDialog
, wxPanel
)
519 BEGIN_EVENT_TABLE(csTextBoxDialog
, wxPanel
)
522 csTextBoxDialog::csTextBoxDialog()