1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Studio application class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
24 #include "wx/ogl/ogl.h" // base header of OGL, includes and adjusts wx/deprecated/setup.h
26 #include "wx/config.h"
27 #include "wx/laywin.h"
28 #include "wx/helpwin.h"
34 #include "cspalette.h"
38 #include "bitmaps/new.xpm"
39 #include "bitmaps/open.xpm"
40 #include "bitmaps/save.xpm"
41 #include "bitmaps/copy.xpm"
42 #include "bitmaps/cut.xpm"
43 #include "bitmaps/paste.xpm"
44 #include "bitmaps/print.xpm"
45 #include "bitmaps/help.xpm"
46 #include "bitmaps/undo.xpm"
47 #include "bitmaps/redo.xpm"
49 #include "bitmaps/alignl.xpm"
50 #include "bitmaps/alignr.xpm"
51 #include "bitmaps/alignt.xpm"
52 #include "bitmaps/alignb.xpm"
53 #include "bitmaps/horiz.xpm"
54 #include "bitmaps/vert.xpm"
55 #include "bitmaps/copysize.xpm"
56 #include "bitmaps/linearrow.xpm"
57 #include "bitmaps/newpoint.xpm"
58 #include "bitmaps/cutpoint.xpm"
59 #include "bitmaps/straight.xpm"
68 m_diagramPalette
= NULL
;
69 m_diagramToolBar
= NULL
;
70 m_projectTreeCtrl
= NULL
;
71 m_diagramPaletteSashWindow
= NULL
;
72 m_projectSashWindow
= NULL
;
73 m_symbolDatabase
= NULL
;
74 m_pointSizeComboBox
= NULL
;
75 m_zoomComboBox
= NULL
;
76 m_shapeEditMenu
= NULL
;
79 m_mainFramePos
.x
= 20;
80 m_mainFramePos
.y
= 20;
81 m_mainFrameSize
.x
= 500;
82 m_mainFrameSize
.y
= 400;
83 m_gridStyle
= csGRID_STYLE_INVISIBLE
;
91 // Initialise this in OnInit, not statically
92 bool csApp::OnInit(void)
94 #if wxUSE_WX_RESOURCES
95 if (!wxResourceParseFile(_T("studio_resources.wxr")))
97 wxMessageBox(_T("Could not find or parse resource file: studio_resources.wxr"), _T("Studio"));
102 #if wxUSE_MS_HTML_HELP && !defined(__WXUNIVERSAL__)
103 m_helpController
= new wxWinHelpController
;
105 m_helpController
= new wxHtmlHelpController
;
108 m_helpController
->Initialize(_T("studio.hlp"));
116 //// Create a document manager
117 m_docManager
= new wxDocManager
;
119 //// Create a template relating drawing documents to their views
120 (void) new wxDocTemplate(m_docManager
, _T("Diagram"), _T("*.dia"), wxEmptyString
, _T("dia"), _T("Diagram Doc"), _T("Diagram View"),
121 CLASSINFO(csDiagramDocument
), CLASSINFO(csDiagramView
));
123 // Create the main frame window.
124 // Note that we use a frame style that doesn't have wxCLIP_CHILDREN in it
125 // (the default frame style contains wxCLIP_CHILDREN), otherwise the client
126 // area doesn't refresh properly when we change its position, under Windows.
128 #define wxDEFAULT_FRAME_STYLE_NO_CLIP \
129 (wxDEFAULT_FRAME_STYLE & ~wxCLIP_CHILDREN)
131 csFrame
* frame
= new csFrame(m_docManager
, NULL
, wxID_ANY
, _T("OGL Studio"), m_mainFramePos
, m_mainFrameSize
,
132 wxDEFAULT_FRAME_STYLE_NO_CLIP
| wxHSCROLL
| wxVSCROLL
);
135 frame
->SetIcon(wxIcon(studio_xpm
));
138 wxMenu
*fileMenu
= new wxMenu
;
140 fileMenu
->Append(wxID_NEW
, _T("&New...\tCtrl+N"));
141 fileMenu
->Append(wxID_OPEN
, _T("&Open...\tCtrl+O"));
143 fileMenu
->AppendSeparator();
145 fileMenu
->Append(wxID_PRINT
, _T("&Print...\tCtrl+P"));
146 fileMenu
->Append(wxID_PRINT_SETUP
, _T("Print &Setup..."));
147 fileMenu
->Append(wxID_PREVIEW
, _T("Print Pre&view"));
148 fileMenu
->AppendSeparator();
149 fileMenu
->Append(wxID_EXIT
, _T("E&xit"));
151 // A history of files visited. Use this menu.
152 m_docManager
->FileHistoryUseMenu(fileMenu
);
154 wxMenu
*viewMenu
= new wxMenu
;
155 viewMenu
->Append(ID_CS_SETTINGS
, _T("&Settings..."));
157 wxMenu
*helpMenu
= new wxMenu
;
158 helpMenu
->Append(wxID_HELP
, _T("&Help Contents\tF1"));
159 helpMenu
->Append(ID_CS_ABOUT
, _T("&About"));
161 wxMenuBar
*menuBar
= new wxMenuBar
;
163 menuBar
->Append(fileMenu
, _T("&File"));
164 menuBar
->Append(viewMenu
, _T("&View"));
165 menuBar
->Append(helpMenu
, _T("&Help"));
167 // Associate the menu bar with the frame
168 frame
->SetMenuBar(menuBar
);
170 // Load the file history
171 wxConfig
config(_T("OGL Studio"), _T("wxWidgets"));
172 m_docManager
->FileHistoryLoad(config
);
175 frame
->CreateStatusBar();
176 #endif // wxUSE_STATUSBAR
178 // The ordering of these is important for layout purposes
179 CreateDiagramToolBar(frame
);
180 CreatePalette(frame
);
183 CreateProjectWindow(frame);
184 FillProjectTreeCtrl();
187 // Create the shape editing menu
188 m_shapeEditMenu
= new ShapeEditMenu
;
189 m_shapeEditMenu
->Append(ID_CS_EDIT_PROPERTIES
, _T("Edit properties"));
190 m_shapeEditMenu
->AppendSeparator();
191 m_shapeEditMenu
->Append(ID_CS_ROTATE_CLOCKWISE
, _T("Rotate clockwise"));
192 m_shapeEditMenu
->Append(ID_CS_ROTATE_ANTICLOCKWISE
, _T("Rotate anticlockwise"));
193 m_shapeEditMenu
->AppendSeparator();
194 m_shapeEditMenu
->Append(ID_CS_CUT
, _T("Cut"));
203 int csApp::OnExit(void)
207 delete m_symbolDatabase
;
208 m_symbolDatabase
= NULL
;
213 delete m_shapeEditMenu
;
214 m_shapeEditMenu
= NULL
;
216 delete m_helpController
;
217 m_helpController
= NULL
;
225 * Centralised code for creating a document frame.
226 * Called from view.cpp, when a view is created.
229 wxMDIChildFrame
*csApp::CreateChildFrame(wxDocument
*doc
, wxView
*view
, wxMenu
** editMenuRet
)
231 //// Make a child frame
232 csMDIChildFrame
*subframe
= new csMDIChildFrame(doc
, view
, ((wxDocMDIParentFrame
*)GetTopWindow()), wxID_ANY
, _T("Child Frame"),
233 wxPoint(10, 10), wxSize(300, 300), wxDEFAULT_FRAME_STYLE
);
236 subframe
->SetIcon(wxString(_T("chart")));
239 subframe
->SetIcon(wxIcon(_T("doc.xbm")));
243 wxMenu
*fileMenu
= new wxMenu
;
245 fileMenu
->Append(wxID_NEW
, _T("&New...\tCtrl+N"));
246 fileMenu
->Append(wxID_OPEN
, _T("&Open...\tCtrl+O"));
247 fileMenu
->Append(wxID_CLOSE
, _T("&Close\tCtrl+W"));
248 fileMenu
->Append(wxID_SAVE
, _T("&Save\tCtrl+S"));
249 fileMenu
->Append(wxID_SAVEAS
, _T("Save &As...\tF12"));
251 fileMenu
->AppendSeparator();
252 fileMenu
->Append(wxID_PRINT
, _T("&Print...\tCtrl+P"));
253 fileMenu
->Append(wxID_PRINT_SETUP
, _T("Print &Setup..."));
254 fileMenu
->Append(wxID_PREVIEW
, _T("Print Pre&view"));
256 fileMenu
->AppendSeparator();
257 fileMenu
->Append(wxID_EXIT
, _T("E&xit"));
259 wxMenu
* editMenu
= new wxMenu
;
260 editMenu
->Append(wxID_UNDO
, _T("&Undo\tCtrl+Z"));
261 editMenu
->Append(wxID_REDO
, _T("&Redo\tCtrl+Y"));
262 editMenu
->AppendSeparator();
263 editMenu
->Append(wxID_CUT
, _T("Cu&t\tCtrl+X"));
264 editMenu
->Append(wxID_COPY
, _T("&Copy\tCtrl+C"));
265 editMenu
->Append(wxID_PASTE
, _T("&Paste\tCtrl+V"));
266 editMenu
->Append(wxID_DUPLICATE
, _T("&Duplicate\tCtrl+D"));
267 editMenu
->AppendSeparator();
268 editMenu
->Append(wxID_CLEAR
, _T("Cle&ar\tDelete"));
269 editMenu
->Append(ID_CS_SELECT_ALL
, _T("Select A&ll\tCtrl+A"));
270 editMenu
->AppendSeparator();
271 editMenu
->Append(ID_CS_EDIT_PROPERTIES
, _T("Edit P&roperties..."));
273 *editMenuRet
= editMenu
;
275 m_docManager
->FileHistoryUseMenu(fileMenu
);
276 m_docManager
->FileHistoryAddFilesToMenu(fileMenu
);
278 doc
->GetCommandProcessor()->SetEditMenu(editMenu
);
280 wxMenu
*viewMenu
= new wxMenu
;
281 viewMenu
->Append(ID_CS_SETTINGS
, _T("&Settings..."));
283 wxMenu
*helpMenu
= new wxMenu
;
284 helpMenu
->Append(wxID_HELP
, _T("&Help Contents\tF1"));
285 helpMenu
->Append(ID_CS_ABOUT
, _T("&About"));
287 wxMenuBar
*menuBar
= new wxMenuBar
;
289 menuBar
->Append(fileMenu
, _T("&File"));
290 menuBar
->Append(editMenu
, _T("&Edit"));
291 menuBar
->Append(viewMenu
, _T("&View"));
292 menuBar
->Append(helpMenu
, _T("&Help"));
294 //// Associate the menu bar with the frame
295 subframe
->SetMenuBar(menuBar
);
300 // Creates a canvas. Called by OnInit as a child of the main window
301 csCanvas
*csApp::CreateCanvas(wxView
*view
, wxMDIChildFrame
*parent
)
304 parent
->GetClientSize(&width
, &height
);
306 // Non-retained canvas
307 csCanvas
*canvas
= new csCanvas((csDiagramView
*) view
, parent
, 1000, wxPoint(0, 0), wxSize(width
, height
), wxSUNKEN_BORDER
);
309 wxColour
bgColour(_T("WHITE"));
310 canvas
->SetBackgroundColour(bgColour
);
312 wxCursor
cursor(wxCURSOR_HAND
);
313 canvas
->SetCursor(cursor
);
315 // Give it scrollbars
316 canvas
->SetScrollbars(20, 20, 100, 100);
321 void csApp::InitToolBar(wxToolBar
* toolBar
)
323 wxBitmap
* bitmaps
[10];
325 bitmaps
[0] = new wxBitmap( new_xpm
);
326 bitmaps
[1] = new wxBitmap( open_xpm
);
327 bitmaps
[2] = new wxBitmap( save_xpm
);
328 bitmaps
[3] = new wxBitmap( copy_xpm
);
329 bitmaps
[4] = new wxBitmap( cut_xpm
);
330 bitmaps
[5] = new wxBitmap( paste_xpm
);
331 bitmaps
[6] = new wxBitmap( print_xpm
);
332 bitmaps
[7] = new wxBitmap( help_xpm
);
333 bitmaps
[8] = new wxBitmap( undo_xpm
);
334 bitmaps
[9] = new wxBitmap( redo_xpm
);
336 toolBar
->AddTool(wxID_NEW
, *bitmaps
[0], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, NULL
, _T("New file"));
337 toolBar
->AddTool(wxID_OPEN
, *bitmaps
[1], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, NULL
, _T("Open file"));
338 toolBar
->AddTool(wxID_SAVE
, *bitmaps
[2], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, NULL
, _T("Save file"));
339 toolBar
->AddSeparator();
340 toolBar
->AddTool(wxID_PRINT
, *bitmaps
[6], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, NULL
, _T("Print"));
341 toolBar
->AddSeparator();
342 toolBar
->AddTool(wxID_COPY
, *bitmaps
[3], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, NULL
, _T("Copy"));
343 toolBar
->AddTool(wxID_CUT
, *bitmaps
[4], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, NULL
, _T("Cut"));
344 toolBar
->AddTool(wxID_PASTE
, *bitmaps
[5], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, NULL
, _T("Paste"));
345 toolBar
->AddSeparator();
346 toolBar
->AddTool(wxID_UNDO
, *bitmaps
[8], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, NULL
, _T("Undo"));
347 toolBar
->AddTool(wxID_REDO
, *bitmaps
[9], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, NULL
, _T("Redo"));
348 toolBar
->AddSeparator();
349 toolBar
->AddTool(wxID_HELP
, *bitmaps
[7], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, NULL
, _T("Help"));
353 toolBar
->EnableTool(wxID_COPY
, false);
354 toolBar
->EnableTool(wxID_PASTE
, false);
355 toolBar
->EnableTool(wxID_PRINT
, false);
356 toolBar
->EnableTool(wxID_UNDO
, false);
357 toolBar
->EnableTool(wxID_REDO
, false);
360 for (i
= 0; i
< 10; i
++)
364 // Create and initialise the diagram toolbar
365 void csApp::CreateDiagramToolBar(wxFrame
* parent
)
367 // First create a layout window
368 wxSashLayoutWindow
* win
= new wxSashLayoutWindow(parent
, ID_LAYOUT_WINDOW_DIAGRAM_TOOLBAR
, wxDefaultPosition
, wxSize(200, 30), wxNO_BORDER
|wxSW_3D
|wxCLIP_CHILDREN
);
369 win
->SetDefaultSize(wxSize(10000, 30));
370 win
->SetOrientation(wxLAYOUT_HORIZONTAL
);
371 win
->SetAlignment(wxLAYOUT_TOP
);
372 win
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
374 m_diagramToolBarSashWindow
= win
;
375 m_diagramToolBarSashWindow
->Show(false);
377 // Create the actual toolbar
378 m_diagramToolBar
= new wxToolBar(win
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, wxTB_HORIZONTAL
|wxNO_BORDER
|wxTB_FLAT
);
380 wxBitmap
* bitmaps
[11];
382 bitmaps
[0] = new wxBitmap( alignl_xpm
);
383 bitmaps
[1] = new wxBitmap( alignr_xpm
);
384 bitmaps
[2] = new wxBitmap( alignt_xpm
);
385 bitmaps
[3] = new wxBitmap( alignb_xpm
);
386 bitmaps
[4] = new wxBitmap( horiz_xpm
);
387 bitmaps
[5] = new wxBitmap( vert_xpm
);
388 bitmaps
[6] = new wxBitmap( copysize_xpm
);
389 bitmaps
[7] = new wxBitmap( linearrow_xpm
);
390 bitmaps
[8] = new wxBitmap( newpoint_xpm
);
391 bitmaps
[9] = new wxBitmap( cutpoint_xpm
);
392 bitmaps
[10] = new wxBitmap( straight_xpm
);
394 m_diagramToolBar
->AddTool(DIAGRAM_TOOLBAR_ALIGNL
, *bitmaps
[0], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, NULL
, _T("Align left"));
395 m_diagramToolBar
->AddTool(DIAGRAM_TOOLBAR_ALIGNR
, *bitmaps
[1], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, NULL
, _T("Align right"));
396 m_diagramToolBar
->AddTool(DIAGRAM_TOOLBAR_ALIGNT
, *bitmaps
[2], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, NULL
, _T("Align top"));
397 m_diagramToolBar
->AddTool(DIAGRAM_TOOLBAR_ALIGNB
, *bitmaps
[3], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, NULL
, _T("Align bottom"));
398 m_diagramToolBar
->AddTool(DIAGRAM_TOOLBAR_ALIGN_HORIZ
, *bitmaps
[4], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, NULL
, _T("Align horizontally"));
399 m_diagramToolBar
->AddTool(DIAGRAM_TOOLBAR_ALIGN_VERT
, *bitmaps
[5], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, NULL
, _T("Align vertically"));
400 m_diagramToolBar
->AddTool(DIAGRAM_TOOLBAR_COPY_SIZE
, *bitmaps
[6], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, NULL
, _T("Copy size"));
401 m_diagramToolBar
->AddSeparator();
402 m_diagramToolBar
->AddTool(DIAGRAM_TOOLBAR_LINE_ARROW
, *bitmaps
[7], wxNullBitmap
, true, wxDefaultCoord
, wxDefaultCoord
, NULL
, _T("Toggle arrow"));
403 m_diagramToolBar
->AddTool(DIAGRAM_TOOLBAR_NEW_POINT
, *bitmaps
[8], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, NULL
, _T("New line point"));
404 m_diagramToolBar
->AddTool(DIAGRAM_TOOLBAR_CUT_POINT
, *bitmaps
[9], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, NULL
, _T("Cut line point"));
405 m_diagramToolBar
->AddTool(DIAGRAM_TOOLBAR_STRAIGHTEN
, *bitmaps
[10], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, NULL
, _T("Straighten lines"));
407 m_diagramToolBar
->Realize();
410 for (i
= 0; i
< 11; i
++)
413 // Create a combobox for point size
414 int maxPointSize
= 40;
415 wxString
*pointSizes
= new wxString
[maxPointSize
];
416 for (i
= 1; i
<= maxPointSize
; i
++)
418 pointSizes
[i
-1].Printf(_T("%d"), i
);
434 m_pointSizeComboBox
= new wxComboBox(m_diagramToolBar
, ID_WINDOW_POINT_SIZE_COMBOBOX
,
435 wxEmptyString
, wxPoint(controlX
, 1), wxSize(pointSizeW
, pointSizeH
), maxPointSize
, pointSizes
);
439 m_diagramToolBar
->AddControl(m_pointSizeComboBox
);
442 m_pointSizeComboBox
->SetSelection(10 - 1);
444 // Create a combobox for zooming
448 int noStrings
= (maxZoom
- minZoom
)/5 ;
449 wxString
*zoomStrings
= new wxString
[noStrings
];
450 for (i
= 0; i
< noStrings
; i
++)
452 zoomStrings
[noStrings
- i
- 1].Printf(_T("%d%%"), (i
*increment
+ minZoom
));
455 controlX
+= pointSizeW
+ 10;
457 m_zoomComboBox
= new wxComboBox(m_diagramToolBar
, ID_WINDOW_ZOOM_COMBOBOX
,
458 wxEmptyString
, wxPoint(controlX
, 1), wxSize(zoomW
, zoomH
), noStrings
, zoomStrings
);
459 delete[] zoomStrings
;
462 m_diagramToolBar
->AddControl(m_zoomComboBox
);
465 // i = (zoom - minZoom)/increment
466 // index = noStrings - i - 1
468 i
= (100 - minZoom
)/increment
;
469 m_zoomComboBox
->SetSelection(noStrings
- i
- 1);
472 // Read/write configuration information
473 bool csApp::ReadOptions()
475 wxConfig
config(_T("OGL Studio"), _T("wxWidgets"));
477 config
.Read(_T("mainX"), & m_mainFramePos
.x
);
478 config
.Read(_T("mainY"), & m_mainFramePos
.y
);
479 config
.Read(_T("mainWidth"), & m_mainFrameSize
.x
);
480 config
.Read(_T("mainHeight"), & m_mainFrameSize
.y
);
481 config
.Read(_T("gridStyle"), & m_gridStyle
);
482 config
.Read(_T("gridSpacing"), & m_gridSpacing
);
487 bool csApp::WriteOptions()
489 wxConfig
config(_T("OGL Studio"), _T("wxWidgets"));
491 config
.Write(_T("mainX"), (long) m_mainFramePos
.x
);
492 config
.Write(_T("mainY"), (long) m_mainFramePos
.y
);
493 config
.Write(_T("mainWidth"), (long) m_mainFrameSize
.x
);
494 config
.Write(_T("mainHeight"), (long) m_mainFrameSize
.y
);
495 config
.Write(_T("gridStyle"), (long) m_gridStyle
);
496 config
.Write(_T("gridSpacing"), (long) m_gridSpacing
);
498 m_docManager
->FileHistorySave(config
);