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/deprecated/setup.h>
25 #include <wx/deprecated/resource.h>
26 #include "wx/config.h"
27 #include "wx/laywin.h"
33 #include "cspalette.h"
37 #if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__)
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"
69 m_diagramPalette
= NULL
;
70 m_diagramToolBar
= NULL
;
71 m_projectTreeCtrl
= NULL
;
72 m_diagramPaletteSashWindow
= NULL
;
73 m_projectSashWindow
= NULL
;
74 m_symbolDatabase
= NULL
;
75 m_pointSizeComboBox
= NULL
;
76 m_zoomComboBox
= NULL
;
77 m_shapeEditMenu
= NULL
;
80 m_mainFramePos
.x
= 20;
81 m_mainFramePos
.y
= 20;
82 m_mainFrameSize
.x
= 500;
83 m_mainFrameSize
.y
= 400;
84 m_gridStyle
= csGRID_STYLE_INVISIBLE
;
92 // Initialise this in OnInit, not statically
93 bool csApp::OnInit(void)
95 if (!wxResourceParseFile("studio_resources.wxr"))
97 wxMessageBox("Could not find or parse resource file: studio_resources.wxr", "Studio");
101 m_helpController
.Initialize("studio.hlp");
109 //// Create a document manager
110 m_docManager
= new wxDocManager
;
112 //// Create a template relating drawing documents to their views
113 (void) new wxDocTemplate(m_docManager
, "Diagram", "*.dia", "", "dia", "Diagram Doc", "Diagram View",
114 CLASSINFO(csDiagramDocument
), CLASSINFO(csDiagramView
));
116 // Create the main frame window.
117 // Note that we use a frame style that doesn't have wxCLIP_CHILDREN in it
118 // (the default frame style contains wxCLIP_CHILDREN), otherwise the client
119 // area doesn't refresh properly when we change its position, under Windows.
121 #define wxDEFAULT_FRAME_STYLE_NO_CLIP \
122 (wxSYSTEM_MENU | wxRESIZE_BORDER | wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxTHICK_FRAME | wxSYSTEM_MENU | wxCAPTION)
124 csFrame
* frame
= new csFrame(m_docManager
, NULL
, -1, "OGL Studio", m_mainFramePos
, m_mainFrameSize
,
125 wxDEFAULT_FRAME_STYLE_NO_CLIP
| wxHSCROLL
| wxVSCROLL
);
128 frame
->SetIcon(wxICON(studio
));
131 wxMenu
*fileMenu
= new wxMenu
;
133 fileMenu
->Append(wxID_NEW
, "&New...\tCtrl+N");
134 fileMenu
->Append(wxID_OPEN
, "&Open...\tCtrl+O");
136 fileMenu
->AppendSeparator();
138 fileMenu
->Append(wxID_PRINT
, "&Print...\tCtrl+P");
139 fileMenu
->Append(wxID_PRINT_SETUP
, "Print &Setup...");
140 fileMenu
->Append(wxID_PREVIEW
, "Print Pre&view");
141 fileMenu
->AppendSeparator();
142 fileMenu
->Append(wxID_EXIT
, "E&xit");
144 // A history of files visited. Use this menu.
145 m_docManager
->FileHistoryUseMenu(fileMenu
);
147 wxMenu
*viewMenu
= new wxMenu
;
148 viewMenu
->Append(ID_CS_SETTINGS
, "&Settings...");
150 wxMenu
*helpMenu
= new wxMenu
;
151 helpMenu
->Append(wxID_HELP
, "&Help Contents\tF1");
152 helpMenu
->Append(ID_CS_ABOUT
, "&About");
154 wxMenuBar
*menuBar
= new wxMenuBar
;
156 menuBar
->Append(fileMenu
, "&File");
157 menuBar
->Append(viewMenu
, "&View");
158 menuBar
->Append(helpMenu
, "&Help");
160 // Associate the menu bar with the frame
161 frame
->SetMenuBar(menuBar
);
163 // Load the file history
164 wxConfig
config("OGL Studio", "wxWindows");
165 m_docManager
->FileHistoryLoad(config
);
167 frame
->CreateStatusBar();
169 // The ordering of these is important for layout purposes
170 CreateDiagramToolBar(frame
);
171 CreatePalette(frame
);
174 CreateProjectWindow(frame);
175 FillProjectTreeCtrl();
178 // Create the shape editing menu
179 m_shapeEditMenu
= new ShapeEditMenu
;
180 m_shapeEditMenu
->Append(ID_CS_EDIT_PROPERTIES
, "Edit properties");
181 m_shapeEditMenu
->AppendSeparator();
182 m_shapeEditMenu
->Append(ID_CS_ROTATE_CLOCKWISE
, "Rotate clockwise");
183 m_shapeEditMenu
->Append(ID_CS_ROTATE_ANTICLOCKWISE
, "Rotate anticlockwise");
184 m_shapeEditMenu
->AppendSeparator();
185 m_shapeEditMenu
->Append(ID_CS_CUT
, "Cut");
194 int csApp::OnExit(void)
198 delete m_symbolDatabase
;
199 m_symbolDatabase
= NULL
;
204 delete m_shapeEditMenu
;
205 m_shapeEditMenu
= NULL
;
213 * Centralised code for creating a document frame.
214 * Called from view.cpp, when a view is created.
217 wxMDIChildFrame
*csApp::CreateChildFrame(wxDocument
*doc
, wxView
*view
, wxMenu
** editMenuRet
)
219 //// Make a child frame
220 csMDIChildFrame
*subframe
= new csMDIChildFrame(doc
, view
, ((wxDocMDIParentFrame
*)GetTopWindow()), -1, "Child Frame",
221 wxPoint(10, 10), wxSize(300, 300), wxDEFAULT_FRAME_STYLE
);
224 subframe
->SetIcon(wxString("chart"));
227 subframe
->SetIcon(wxIcon("doc.xbm"));
231 wxMenu
*fileMenu
= new wxMenu
;
233 fileMenu
->Append(wxID_NEW
, "&New...\tCtrl+N");
234 fileMenu
->Append(wxID_OPEN
, "&Open...\tCtrl+O");
235 fileMenu
->Append(wxID_CLOSE
, "&Close\tCtrl+W");
236 fileMenu
->Append(wxID_SAVE
, "&Save\tCtrl+S");
237 fileMenu
->Append(wxID_SAVEAS
, "Save &As...\tF12");
239 fileMenu
->AppendSeparator();
240 fileMenu
->Append(wxID_PRINT
, "&Print...\tCtrl+P");
241 fileMenu
->Append(wxID_PRINT_SETUP
, "Print &Setup...");
242 fileMenu
->Append(wxID_PREVIEW
, "Print Pre&view");
244 fileMenu
->AppendSeparator();
245 fileMenu
->Append(wxID_EXIT
, "E&xit");
247 wxMenu
*editMenu
= NULL
;
249 editMenu
= new wxMenu
;
250 editMenu
->Append(wxID_UNDO
, "&Undo\tCtrl+Z");
251 editMenu
->Append(wxID_REDO
, "&Redo\tCtrl+Y");
252 editMenu
->AppendSeparator();
253 editMenu
->Append(wxID_CUT
, "Cu&t\tCtrl+X");
254 editMenu
->Append(wxID_COPY
, "&Copy\tCtrl+C");
255 editMenu
->Append(wxID_PASTE
, "&Paste\tCtrl+V");
256 editMenu
->Append(wxID_DUPLICATE
, "&Duplicate\tCtrl+D");
257 editMenu
->AppendSeparator();
258 editMenu
->Append(wxID_CLEAR
, "Cle&ar\tDelete");
259 editMenu
->Append(ID_CS_SELECT_ALL
, "Select A&ll\tCtrl+A");
260 editMenu
->AppendSeparator();
261 editMenu
->Append(ID_CS_EDIT_PROPERTIES
, "Edit P&roperties...");
263 *editMenuRet
= editMenu
;
265 m_docManager
->FileHistoryUseMenu(fileMenu
);
266 m_docManager
->FileHistoryAddFilesToMenu(fileMenu
);
268 doc
->GetCommandProcessor()->SetEditMenu(editMenu
);
270 wxMenu
*viewMenu
= new wxMenu
;
271 viewMenu
->Append(ID_CS_SETTINGS
, "&Settings...");
273 wxMenu
*helpMenu
= new wxMenu
;
274 helpMenu
->Append(wxID_HELP
, "&Help Contents\tF1");
275 helpMenu
->Append(ID_CS_ABOUT
, "&About");
277 wxMenuBar
*menuBar
= new wxMenuBar
;
279 menuBar
->Append(fileMenu
, "&File");
280 menuBar
->Append(editMenu
, "&Edit");
281 menuBar
->Append(viewMenu
, "&View");
282 menuBar
->Append(helpMenu
, "&Help");
284 //// Associate the menu bar with the frame
285 subframe
->SetMenuBar(menuBar
);
290 // Creates a canvas. Called by OnInit as a child of the main window
291 csCanvas
*csApp::CreateCanvas(wxView
*view
, wxFrame
*parent
)
294 parent
->GetClientSize(&width
, &height
);
296 // Non-retained canvas
297 csCanvas
*canvas
= new csCanvas((csDiagramView
*) view
, parent
, 1000, wxPoint(0, 0), wxSize(width
, height
), wxSUNKEN_BORDER
);
299 wxColour
bgColour("WHITE");
300 canvas
->SetBackgroundColour(bgColour
);
302 wxCursor
cursor(wxCURSOR_HAND
);
303 canvas
->SetCursor(cursor
);
305 // Give it scrollbars
306 canvas
->SetScrollbars(20, 20, 100, 100);
311 void csApp::InitToolBar(wxToolBar
* toolBar
)
313 wxBitmap
* bitmaps
[10];
316 bitmaps
[0] = new wxBitmap("new", wxBITMAP_TYPE_RESOURCE
);
317 bitmaps
[1] = new wxBitmap("open", wxBITMAP_TYPE_RESOURCE
);
318 bitmaps
[2] = new wxBitmap("save", wxBITMAP_TYPE_RESOURCE
);
319 bitmaps
[3] = new wxBitmap("copy", wxBITMAP_TYPE_RESOURCE
);
320 bitmaps
[4] = new wxBitmap("cut", wxBITMAP_TYPE_RESOURCE
);
321 bitmaps
[5] = new wxBitmap("paste", wxBITMAP_TYPE_RESOURCE
);
322 bitmaps
[6] = new wxBitmap("print", wxBITMAP_TYPE_RESOURCE
);
323 bitmaps
[7] = new wxBitmap("help", wxBITMAP_TYPE_RESOURCE
);
324 bitmaps
[8] = new wxBitmap("undo", wxBITMAP_TYPE_RESOURCE
);
325 bitmaps
[9] = new wxBitmap("redo", wxBITMAP_TYPE_RESOURCE
);
326 #elif defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__)
327 bitmaps
[0] = new wxBitmap( new_xpm
);
328 bitmaps
[1] = new wxBitmap( open_xpm
);
329 bitmaps
[2] = new wxBitmap( save_xpm
);
330 bitmaps
[3] = new wxBitmap( copy_xpm
);
331 bitmaps
[4] = new wxBitmap( cut_xpm
);
332 bitmaps
[5] = new wxBitmap( paste_xpm
);
333 bitmaps
[6] = new wxBitmap( print_xpm
);
334 bitmaps
[7] = new wxBitmap( help_xpm
);
335 bitmaps
[8] = new wxBitmap( undo_xpm
);
336 bitmaps
[9] = new wxBitmap( redo_xpm
);
338 #error "Not implemented for this platform."
341 toolBar
->AddTool(wxID_NEW
, *bitmaps
[0], wxNullBitmap
, FALSE
, -1, -1, NULL
, "New file");
342 toolBar
->AddTool(wxID_OPEN
, *bitmaps
[1], wxNullBitmap
, FALSE
, -1, -1, NULL
, "Open file");
343 toolBar
->AddTool(wxID_SAVE
, *bitmaps
[2], wxNullBitmap
, FALSE
, -1, -1, NULL
, "Save file");
344 toolBar
->AddSeparator();
345 toolBar
->AddTool(wxID_PRINT
, *bitmaps
[6], wxNullBitmap
, FALSE
, -1, -1, NULL
, "Print");
346 toolBar
->AddSeparator();
347 toolBar
->AddTool(wxID_COPY
, *bitmaps
[3], wxNullBitmap
, FALSE
, -1, -1, NULL
, "Copy");
348 toolBar
->AddTool(wxID_CUT
, *bitmaps
[4], wxNullBitmap
, FALSE
, -1, -1, NULL
, "Cut");
349 toolBar
->AddTool(wxID_PASTE
, *bitmaps
[5], wxNullBitmap
, FALSE
, -1, -1, NULL
, "Paste");
350 toolBar
->AddSeparator();
351 toolBar
->AddTool(wxID_UNDO
, *bitmaps
[8], wxNullBitmap
, FALSE
, -1, -1, NULL
, "Undo");
352 toolBar
->AddTool(wxID_REDO
, *bitmaps
[9], wxNullBitmap
, FALSE
, -1, -1, NULL
, "Redo");
353 toolBar
->AddSeparator();
354 toolBar
->AddTool(wxID_HELP
, *bitmaps
[7], wxNullBitmap
, FALSE
, -1, -1, NULL
, "Help");
358 toolBar
->EnableTool(wxID_COPY
, FALSE
);
359 toolBar
->EnableTool(wxID_PASTE
, FALSE
);
360 toolBar
->EnableTool(wxID_PRINT
, FALSE
);
361 toolBar
->EnableTool(wxID_UNDO
, FALSE
);
362 toolBar
->EnableTool(wxID_REDO
, FALSE
);
365 for (i
= 0; i
< 10; i
++)
369 // Create and initialise the diagram toolbar
370 void csApp::CreateDiagramToolBar(wxFrame
* parent
)
372 // First create a layout window
373 wxSashLayoutWindow
* win
= new wxSashLayoutWindow(parent
, ID_LAYOUT_WINDOW_DIAGRAM_TOOLBAR
, wxDefaultPosition
, wxSize(200, 30), wxNO_BORDER
|wxSW_3D
|wxCLIP_CHILDREN
);
374 win
->SetDefaultSize(wxSize(10000, 30));
375 win
->SetOrientation(wxLAYOUT_HORIZONTAL
);
376 win
->SetAlignment(wxLAYOUT_TOP
);
377 win
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
379 m_diagramToolBarSashWindow
= win
;
380 m_diagramToolBarSashWindow
->Show(FALSE
);
382 // Create the actual toolbar
383 m_diagramToolBar
= new wxToolBar(win
, -1, wxDefaultPosition
, wxDefaultSize
, wxTB_HORIZONTAL
|wxNO_BORDER
|wxTB_FLAT
);
385 wxBitmap
* bitmaps
[11];
388 bitmaps
[0] = new wxBitmap("alignl", wxBITMAP_TYPE_RESOURCE
);
389 bitmaps
[1] = new wxBitmap("alignr", wxBITMAP_TYPE_RESOURCE
);
390 bitmaps
[2] = new wxBitmap("alignt", wxBITMAP_TYPE_RESOURCE
);
391 bitmaps
[3] = new wxBitmap("alignb", wxBITMAP_TYPE_RESOURCE
);
392 bitmaps
[4] = new wxBitmap("horiz", wxBITMAP_TYPE_RESOURCE
);
393 bitmaps
[5] = new wxBitmap("vert", wxBITMAP_TYPE_RESOURCE
);
394 bitmaps
[6] = new wxBitmap("copysize", wxBITMAP_TYPE_RESOURCE
);
395 bitmaps
[7] = new wxBitmap("linearrow", wxBITMAP_TYPE_RESOURCE
);
396 bitmaps
[8] = new wxBitmap("newpoint", wxBITMAP_TYPE_RESOURCE
);
397 bitmaps
[9] = new wxBitmap("cutpoint", wxBITMAP_TYPE_RESOURCE
);
398 bitmaps
[10] = new wxBitmap("straighten", wxBITMAP_TYPE_RESOURCE
);
399 #elif defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__)
400 bitmaps
[0] = new wxBitmap( alignl_xpm
);
401 bitmaps
[1] = new wxBitmap( alignr_xpm
);
402 bitmaps
[2] = new wxBitmap( alignt_xpm
);
403 bitmaps
[3] = new wxBitmap( alignb_xpm
);
404 bitmaps
[4] = new wxBitmap( horiz_xpm
);
405 bitmaps
[5] = new wxBitmap( vert_xpm
);
406 bitmaps
[6] = new wxBitmap( copysize_xpm
);
407 bitmaps
[7] = new wxBitmap( linearrow_xpm
);
408 bitmaps
[8] = new wxBitmap( newpoint_xpm
);
409 bitmaps
[9] = new wxBitmap( cutpoint_xpm
);
410 bitmaps
[10] = new wxBitmap( straight_xpm
);
412 #error "Not implemented for this platform."
415 m_diagramToolBar
->AddTool(DIAGRAM_TOOLBAR_ALIGNL
, *bitmaps
[0], wxNullBitmap
, FALSE
, -1, -1, NULL
, "Align left");
416 m_diagramToolBar
->AddTool(DIAGRAM_TOOLBAR_ALIGNR
, *bitmaps
[1], wxNullBitmap
, FALSE
, -1, -1, NULL
, "Align right");
417 m_diagramToolBar
->AddTool(DIAGRAM_TOOLBAR_ALIGNT
, *bitmaps
[2], wxNullBitmap
, FALSE
, -1, -1, NULL
, "Align top");
418 m_diagramToolBar
->AddTool(DIAGRAM_TOOLBAR_ALIGNB
, *bitmaps
[3], wxNullBitmap
, FALSE
, -1, -1, NULL
, "Align bottom");
419 m_diagramToolBar
->AddTool(DIAGRAM_TOOLBAR_ALIGN_HORIZ
, *bitmaps
[4], wxNullBitmap
, FALSE
, -1, -1, NULL
, "Align horizontally");
420 m_diagramToolBar
->AddTool(DIAGRAM_TOOLBAR_ALIGN_VERT
, *bitmaps
[5], wxNullBitmap
, FALSE
, -1, -1, NULL
, "Align vertically");
421 m_diagramToolBar
->AddTool(DIAGRAM_TOOLBAR_COPY_SIZE
, *bitmaps
[6], wxNullBitmap
, FALSE
, -1, -1, NULL
, "Copy size");
422 m_diagramToolBar
->AddSeparator();
423 m_diagramToolBar
->AddTool(DIAGRAM_TOOLBAR_LINE_ARROW
, *bitmaps
[7], wxNullBitmap
, TRUE
, -1, -1, NULL
, "Toggle arrow");
424 m_diagramToolBar
->AddTool(DIAGRAM_TOOLBAR_NEW_POINT
, *bitmaps
[8], wxNullBitmap
, FALSE
, -1, -1, NULL
, "New line point");
425 m_diagramToolBar
->AddTool(DIAGRAM_TOOLBAR_CUT_POINT
, *bitmaps
[9], wxNullBitmap
, FALSE
, -1, -1, NULL
, "Cut line point");
426 m_diagramToolBar
->AddTool(DIAGRAM_TOOLBAR_STRAIGHTEN
, *bitmaps
[10], wxNullBitmap
, FALSE
, -1, -1, NULL
, "Straighten lines");
428 m_diagramToolBar
->Realize();
431 for (i
= 0; i
< 11; i
++)
434 // Create a combobox for point size
435 int maxPointSize
= 40;
436 wxString
*pointSizes
= new wxString
[maxPointSize
];
437 for (i
= 1; i
<= maxPointSize
; i
++)
439 pointSizes
[i
-1].Printf("%d", i
);
455 m_pointSizeComboBox
= new wxComboBox(m_diagramToolBar
, ID_WINDOW_POINT_SIZE_COMBOBOX
,
456 "", wxPoint(controlX
, 1), wxSize(pointSizeW
, pointSizeH
), maxPointSize
, pointSizes
);
460 m_diagramToolBar
->AddControl(m_pointSizeComboBox
);
463 m_pointSizeComboBox
->SetSelection(10 - 1);
465 // Create a combobox for zooming
469 int noStrings
= (maxZoom
- minZoom
)/5 ;
470 wxString
*zoomStrings
= new wxString
[noStrings
];
471 for (i
= 0; i
< noStrings
; i
++)
473 zoomStrings
[noStrings
- i
- 1].Printf("%d%%", (i
*increment
+ minZoom
));
476 controlX
+= pointSizeW
+ 10;
478 m_zoomComboBox
= new wxComboBox(m_diagramToolBar
, ID_WINDOW_ZOOM_COMBOBOX
,
479 "", wxPoint(controlX
, 1), wxSize(zoomW
, zoomH
), noStrings
, zoomStrings
);
480 delete[] zoomStrings
;
483 m_diagramToolBar
->AddControl(m_zoomComboBox
);
486 // i = (zoom - minZoom)/increment
487 // index = noStrings - i - 1
489 i
= (100 - minZoom
)/increment
;
490 m_zoomComboBox
->SetSelection(noStrings
- i
- 1);
493 // Read/write configuration information
494 bool csApp::ReadOptions()
496 wxConfig
config("OGL Studio", "wxWindows");
498 config
.Read("mainX", & m_mainFramePos
.x
);
499 config
.Read("mainY", & m_mainFramePos
.y
);
500 config
.Read("mainWidth", & m_mainFrameSize
.x
);
501 config
.Read("mainHeight", & m_mainFrameSize
.y
);
502 config
.Read("gridStyle", & m_gridStyle
);
503 config
.Read("gridSpacing", & m_gridSpacing
);
508 bool csApp::WriteOptions()
510 wxConfig
config("OGL Studio", "wxWindows");
512 config
.Write("mainX", (long) m_mainFramePos
.x
);
513 config
.Write("mainY", (long) m_mainFramePos
.y
);
514 config
.Write("mainWidth", (long) m_mainFrameSize
.x
);
515 config
.Write("mainHeight", (long) m_mainFrameSize
.y
);
516 config
.Write("gridStyle", (long) m_gridStyle
);
517 config
.Write("gridSpacing", (long) m_gridSpacing
);
519 m_docManager
->FileHistorySave(config
);