1 /////////////////////////////////////////////////////////////////////////////
2 // Name: contrib/samples/ogl/studio/dialogs.cpp
3 // Purpose: Implements Studio dialogs
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
27 #include "studio_resources.h"
29 #if wxUSE_WX_RESOURCES
31 IMPLEMENT_CLASS(csLabelEditingDialog
, wxDialog
)
33 BEGIN_EVENT_TABLE(csLabelEditingDialog
, wxDialog
)
34 EVT_BUTTON(wxID_OK
, csLabelEditingDialog::OnOK
)
37 csLabelEditingDialog::csLabelEditingDialog(wxWindow
* parent
)
39 wxLoadFromResource(this, parent
, _T("shape_label_dialog"));
42 wxAcceleratorEntry entries
[1];
43 entries
[0].Set(wxACCEL_CTRL
, WXK_RETURN
, wxID_OK
);
44 wxAcceleratorTable
accel(1, entries
);
45 SetAcceleratorTable(accel
);
49 wxTextCtrl
* textCtrl
= (wxTextCtrl
*) FindWindow(ID_LABELTEXT
);
50 wxASSERT( (textCtrl
!= NULL
) );
52 // textCtrl->SetAcceleratorTable(accel);
57 void csLabelEditingDialog::OnOK(wxCommandEvent
& event
)
59 wxTextCtrl
* textCtrl
= (wxTextCtrl
*) FindWindow(ID_LABELTEXT
);
60 wxASSERT( (textCtrl
!= NULL
) );
62 SetShapeLabel(textCtrl
->GetValue());
64 wxDialog::OnOK(event
);
67 void csLabelEditingDialog::SetShapeLabel(const wxString
& label
)
69 wxTextCtrl
* textCtrl
= (wxTextCtrl
*) FindWindow(ID_LABELTEXT
);
70 wxASSERT( (textCtrl
!= NULL
) );
74 textCtrl
->SetValue(label
);
77 IMPLEMENT_CLASS(csSettingsDialog
, wxDialog
)
79 BEGIN_EVENT_TABLE(csSettingsDialog
, wxDialog
)
80 EVT_BUTTON(wxID_OK
, csSettingsDialog::OnOK
)
83 #define PROPERTY_DIALOG_WIDTH 400
84 #define PROPERTY_DIALOG_HEIGHT 400
86 // For 400x400 settings dialog, size your panels to about 375x325 in dialog editor
88 csSettingsDialog::csSettingsDialog(wxWindow
* parent
):
89 wxDialog(parent
, wxID_ANY
, _T("Settings"), wxPoint(0, 0), wxSize(PROPERTY_DIALOG_WIDTH
, PROPERTY_DIALOG_HEIGHT
))
91 m_generalSettings
= NULL
;
92 m_diagramSettings
= NULL
;
94 m_notebook
= new wxNotebook(this, ID_PROPERTY_NOTEBOOK
,
95 wxPoint(2, 2), wxSize(PROPERTY_DIALOG_WIDTH
- 4, PROPERTY_DIALOG_HEIGHT
- 4));
97 m_generalSettings
= new wxPanel
;
102 wxLoadFromResource(m_generalSettings
, m_notebook
, _T("general_settings_dialog"));
103 wxASSERT_MSG( (success
), _T("Could not load general settings panel."));
104 m_notebook
->AddPage(m_generalSettings
, _T("General"), true);
106 m_diagramSettings
= new wxPanel
;
111 wxLoadFromResource(m_diagramSettings
, m_notebook
, _T("diagram_settings_dialog"));
112 wxASSERT_MSG( (success
), _T("Could not load diagram settings panel."));
113 m_notebook
->AddPage(m_diagramSettings
, _T("Diagram"));
115 int largeButtonWidth
= 70;
116 int largeButtonHeight
= 22;
118 wxButton
* okButton
= new wxButton(this, wxID_OK
, _T("OK"), wxPoint(0, 0), wxSize(largeButtonWidth
, largeButtonHeight
));
119 wxButton
* cancelButton
= new wxButton(this, wxID_CANCEL
, _T("Cancel"), wxPoint(0, 0), wxSize(largeButtonWidth
, largeButtonHeight
));
120 wxButton
* helpButton
= new wxButton(this, wxID_HELP
, _T("Help"), wxPoint(0, 0), wxSize(largeButtonWidth
, largeButtonHeight
));
122 // Constraints for the notebook
123 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
124 c
->top
.SameAs (this, wxTop
, 5);
125 c
->left
.SameAs (this, wxLeft
, 5);
126 c
->right
.SameAs (this, wxRight
, 5);
127 c
->bottom
.SameAs (cancelButton
, wxTop
, 5);
128 m_notebook
->SetConstraints(c
);
130 // Constraints for the Help button
131 c
= new wxLayoutConstraints
;
134 c
->right
.SameAs (this, wxRight
, 5);
135 c
->bottom
.SameAs (this, wxBottom
, 5);
136 helpButton
->SetConstraints(c
);
138 // Constraints for the Cancel button
139 c
= new wxLayoutConstraints
;
142 c
->right
.SameAs (helpButton
, wxLeft
, 5);
143 c
->bottom
.SameAs (this, wxBottom
, 5);
144 cancelButton
->SetConstraints(c
);
146 // Constraints for the OK button
147 c
= new wxLayoutConstraints
;
150 c
->right
.SameAs (cancelButton
, wxLeft
, 5);
151 c
->bottom
.SameAs (this, wxBottom
, 5);
152 okButton
->SetConstraints(c
);
154 okButton
->SetDefault();
155 okButton
->SetFocus();
161 void csSettingsDialog::OnOK(wxCommandEvent
& event
)
163 wxDialog::OnOK(event
);
166 bool csSettingsDialog::TransferDataToWindow()
168 wxTextCtrl
* gridSpacing
= (wxTextCtrl
*) m_diagramSettings
->FindWindow(ID_GRID_SPACING
);
169 wxASSERT_MSG( (gridSpacing
!= (wxTextCtrl
*) NULL
), _T("Could not find grid spacing control."));
171 wxChoice
* gridStyle
= (wxChoice
*) m_diagramSettings
->FindWindow(ID_GRID_STYLE
);
172 wxASSERT_MSG( (gridStyle
!= (wxChoice
*) NULL
), _T("Could not find grid style control."));
174 gridStyle
->SetSelection(wxGetApp().GetGridStyle());
177 str
.Printf(_T("%d"), wxGetApp().GetGridSpacing());
178 gridSpacing
->SetValue(str
);
183 bool csSettingsDialog::TransferDataFromWindow()
185 wxTextCtrl
* gridSpacing
= (wxTextCtrl
*) m_diagramSettings
->FindWindow(ID_GRID_SPACING
);
186 wxASSERT_MSG( (gridSpacing
!= (wxTextCtrl
*) NULL
), _T("Could not find grid spacing control."));
188 wxChoice
* gridStyle
= (wxChoice
*) m_diagramSettings
->FindWindow(ID_GRID_STYLE
);
189 wxASSERT_MSG( (gridStyle
!= (wxChoice
*) NULL
), _T("Could not find grid style control."));
191 wxGetApp().SetGridStyle(gridStyle
->GetSelection());
192 wxString str
= gridSpacing
->GetValue();
194 str
.ToLong( &grid_spacing
);
195 wxGetApp().SetGridSpacing(grid_spacing
);
197 if (wxGetApp().GetGridStyle() == csGRID_STYLE_DOTTED
)
199 wxMessageBox(_T("Dotted grid style not yet implemented."), _T("Studio"), wxICON_EXCLAMATION
);
203 // Apply settings to all open diagram documents
204 wxObjectList::compatibility_iterator node
= wxGetApp().GetDocManager()->GetDocuments().GetFirst();
207 wxDocument
* doc
= (wxDocument
*) node
->GetData();
208 if (doc
->IsKindOf(CLASSINFO(csDiagramDocument
)))
210 csDiagramDocument
* diagramDoc
= (csDiagramDocument
*) doc
;
211 wxDiagram
* diagram
= (wxDiagram
*) diagramDoc
->GetDiagram();
213 diagram
->SetGridSpacing((double) wxGetApp().GetGridSpacing());
214 switch (wxGetApp().GetGridStyle())
216 case csGRID_STYLE_NONE
:
218 diagram
->SetSnapToGrid(false);
221 case csGRID_STYLE_INVISIBLE
:
223 diagram
->SetSnapToGrid(true);
226 case csGRID_STYLE_DOTTED
:
228 // TODO (not implemented in OGL)
233 node
= node
->GetNext();
240 * Shape properties dialog (tabbed)
244 IMPLEMENT_CLASS(csShapePropertiesDialog
, wxDialog
)
246 BEGIN_EVENT_TABLE(csShapePropertiesDialog
, wxDialog
)
247 EVT_BUTTON(wxID_OK
, csShapePropertiesDialog::OnOK
)
250 #define SHAPE_PROPERTY_DIALOG_WIDTH 400
251 #define SHAPE_PROPERTY_DIALOG_HEIGHT 400
253 // For 400x400 settings dialog, size your panels to about 375x325 in dialog editor
255 csShapePropertiesDialog::csShapePropertiesDialog(wxWindow
* parent
, const wxString
& title
,
256 wxPanel
* attributeDialog
, const wxString
& attributeDialogName
):
257 wxDialog(parent
, wxID_ANY
, title
, wxPoint(0, 0), wxSize(SHAPE_PROPERTY_DIALOG_WIDTH
, SHAPE_PROPERTY_DIALOG_HEIGHT
))
259 m_attributeDialog
= attributeDialog
;
260 m_alternativeAttributeDialog
= NULL
;
261 m_generalPropertiesDialog
= NULL
;
263 m_notebook
= new wxNotebook(this, ID_SHAPE_PROPERTY_NOTEBOOK
,
264 wxPoint(2, 2), wxSize(SHAPE_PROPERTY_DIALOG_WIDTH
- 4, SHAPE_PROPERTY_DIALOG_HEIGHT
- 4));
266 m_generalPropertiesDialog
= new csGeneralShapePropertiesDialog
;
270 wxLoadFromResource(m_generalPropertiesDialog
, m_notebook
, _T("general_shape_properties_dialog"));
271 wxASSERT_MSG( (success
), _T("Could not load general properties panel."));
272 m_notebook
->AddPage(m_generalPropertiesDialog
, _T("General"));
274 if (!wxLoadFromResource(m_attributeDialog
, m_notebook
, attributeDialogName
))
276 wxMessageBox(_T("Could not load the attribute dialog for this shape."), _T("Studio"), wxICON_EXCLAMATION
);
277 delete m_attributeDialog
;
278 m_attributeDialog
= NULL
;
282 m_notebook
->AddPage(m_attributeDialog
, _T("Attributes"));
285 // Try the alternative dialog (test code)
286 wxString
str(attributeDialogName
);
288 m_alternativeAttributeDialog
= new wxPanel
;
289 if (wxLoadFromResource(m_alternativeAttributeDialog
, m_notebook
, str
))
291 m_notebook
->AddPage(m_alternativeAttributeDialog
, _T("Attributes (alternative)"));
295 delete m_alternativeAttributeDialog
;
296 m_alternativeAttributeDialog
= NULL
;
299 int largeButtonWidth
= 70;
300 int largeButtonHeight
= 22;
302 wxButton
* okButton
= new wxButton(this, wxID_OK
, _T("OK"), wxPoint(0, 0), wxSize(largeButtonWidth
, largeButtonHeight
));
303 wxButton
* cancelButton
= new wxButton(this, wxID_CANCEL
, _T("Cancel"), wxPoint(0, 0), wxSize(largeButtonWidth
, largeButtonHeight
));
304 wxButton
* helpButton
= new wxButton(this, wxID_HELP
, _T("Help"), wxPoint(0, 0), wxSize(largeButtonWidth
, largeButtonHeight
));
306 // Constraints for the notebook
307 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
308 c
->top
.SameAs (this, wxTop
, 5);
309 c
->left
.SameAs (this, wxLeft
, 5);
310 c
->right
.SameAs (this, wxRight
, 5);
311 c
->bottom
.SameAs (helpButton
, wxTop
, 5);
312 m_notebook
->SetConstraints(c
);
314 // Constraints for the Help button
315 c
= new wxLayoutConstraints
;
318 c
->right
.SameAs (this, wxRight
, 5);
319 c
->bottom
.SameAs (this, wxBottom
, 5);
320 helpButton
->SetConstraints(c
);
322 // Constraints for the Cancel button
323 c
= new wxLayoutConstraints
;
326 c
->right
.SameAs (helpButton
, wxLeft
, 5);
327 c
->bottom
.SameAs (this, wxBottom
, 5);
328 cancelButton
->SetConstraints(c
);
330 // Constraints for the OK button
331 c
= new wxLayoutConstraints
;
334 c
->right
.SameAs (cancelButton
, wxLeft
, 5);
335 c
->bottom
.SameAs (this, wxBottom
, 5);
336 okButton
->SetConstraints(c
);
338 okButton
->SetDefault();
339 okButton
->SetFocus();
347 void csShapePropertiesDialog::OnOK(wxCommandEvent
& event
)
349 wxTextCtrl
* textCtrl
= (wxTextCtrl
*) m_generalPropertiesDialog
->FindWindow(ID_LABELTEXT
);
350 wxASSERT( (textCtrl
!= NULL
) );
352 m_generalPropertiesDialog
->SetShapeLabel(textCtrl
->GetValue());
354 wxDialog::OnOK(event
);
357 // Set some suitable defaults in the attribute dialogs (in the first instance,
358 // just set all wxChoices to the first element)
359 void csShapePropertiesDialog::SetDefaults()
361 if (!m_attributeDialog
)
364 wxWindowList::compatibility_iterator node
= m_attributeDialog
->GetChildren().GetFirst();
367 wxWindow
* child
= (wxWindow
*) node
->GetData();
368 if (child
->IsKindOf(CLASSINFO(wxChoice
)))
370 wxChoice
* choice
= (wxChoice
*) child
;
371 choice
->SetSelection(0);
373 node
= node
->GetNext();
376 if (!m_alternativeAttributeDialog
)
379 node
= m_alternativeAttributeDialog
->GetChildren().GetFirst();
382 wxWindow
* child
= (wxWindow
*) node
->GetData();
383 if (child
->IsKindOf(CLASSINFO(wxChoice
)))
385 wxChoice
* choice
= (wxChoice
*) child
;
386 choice
->SetSelection(0);
388 node
= node
->GetNext();
393 * csGeneralShapePropertiesDialog
396 IMPLEMENT_CLASS(csGeneralShapePropertiesDialog
, wxPanel
)
398 BEGIN_EVENT_TABLE(csGeneralShapePropertiesDialog
, wxPanel
)
401 csGeneralShapePropertiesDialog::csGeneralShapePropertiesDialog()
405 void csGeneralShapePropertiesDialog::SetShapeLabel(const wxString
& label
)
407 wxTextCtrl
* textCtrl
= (wxTextCtrl
*) FindWindow(ID_LABELTEXT
);
408 wxASSERT( (textCtrl
!= NULL
) );
412 textCtrl
->SetValue(label
);
415 #endif // wxUSE_WX_RESOURCES
418 * csThinRectangleDialog
421 IMPLEMENT_CLASS(csThinRectangleDialog
, wxPanel
)
423 BEGIN_EVENT_TABLE(csThinRectangleDialog
, wxPanel
)
426 csThinRectangleDialog::csThinRectangleDialog()
431 * csWideRectangleDialog
434 IMPLEMENT_CLASS(csWideRectangleDialog
, wxPanel
)
436 BEGIN_EVENT_TABLE(csWideRectangleDialog
, wxPanel
)
439 csWideRectangleDialog::csWideRectangleDialog()
447 IMPLEMENT_CLASS(csTriangleDialog
, wxPanel
)
449 BEGIN_EVENT_TABLE(csTriangleDialog
, wxPanel
)
452 csTriangleDialog::csTriangleDialog()
460 IMPLEMENT_CLASS(csSemiCircleDialog
, wxPanel
)
462 BEGIN_EVENT_TABLE(csSemiCircleDialog
, wxPanel
)
465 csSemiCircleDialog::csSemiCircleDialog()
473 IMPLEMENT_CLASS(csCircleDialog
, wxPanel
)
475 BEGIN_EVENT_TABLE(csCircleDialog
, wxPanel
)
478 csCircleDialog::csCircleDialog()
483 * csCircleShadowDialog
486 IMPLEMENT_CLASS(csCircleShadowDialog
, wxPanel
)
488 BEGIN_EVENT_TABLE(csCircleShadowDialog
, wxPanel
)
491 csCircleShadowDialog::csCircleShadowDialog()
499 IMPLEMENT_CLASS(csOctagonDialog
, wxPanel
)
501 BEGIN_EVENT_TABLE(csOctagonDialog
, wxPanel
)
504 csOctagonDialog::csOctagonDialog()
512 IMPLEMENT_CLASS(csGroupDialog
, wxPanel
)
514 BEGIN_EVENT_TABLE(csGroupDialog
, wxPanel
)
517 csGroupDialog::csGroupDialog()
525 IMPLEMENT_CLASS(csTextBoxDialog
, wxPanel
)
527 BEGIN_EVENT_TABLE(csTextBoxDialog
, wxPanel
)
530 csTextBoxDialog::csTextBoxDialog()