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/resource.h"
25 #include "wx/config.h"
26 #include "wx/laywin.h"
36 #include "cspalette.h"
40 #if defined(__WXGTK__) || defined(__WXMOTIF__)
41 #include "bitmaps/new.xpm"
42 #include "bitmaps/open.xpm"
43 #include "bitmaps/save.xpm"
44 #include "bitmaps/copy.xpm"
45 #include "bitmaps/cut.xpm"
46 #include "bitmaps/paste.xpm"
47 #include "bitmaps/print.xpm"
48 #include "bitmaps/help.xpm"
49 #include "bitmaps/undo.xpm"
50 #include "bitmaps/redo.xpm"
52 #include "bitmaps/alignl.xpm"
53 #include "bitmaps/alignr.xpm"
54 #include "bitmaps/alignt.xpm"
55 #include "bitmaps/alignb.xpm"
56 #include "bitmaps/horiz.xpm"
57 #include "bitmaps/vert.xpm"
58 #include "bitmaps/copysize.xpm"
59 #include "bitmaps/linearrow.xpm"
60 #include "bitmaps/newpoint.xpm"
61 #include "bitmaps/cutpoint.xpm"
62 #include "bitmaps/straight.xpm"
72 m_diagramPalette
= NULL
;
73 m_diagramToolBar
= NULL
;
74 m_projectTreeCtrl
= NULL
;
75 m_diagramPaletteSashWindow
= NULL
;
76 m_projectSashWindow
= NULL
;
77 m_symbolDatabase
= NULL
;
78 m_pointSizeComboBox
= NULL
;
79 m_zoomComboBox
= NULL
;
80 m_shapeEditMenu
= NULL
;
83 m_mainFramePos
.x
= 20;
84 m_mainFramePos
.y
= 20;
85 m_mainFrameSize
.x
= 500;
86 m_mainFrameSize
.y
= 400;
87 m_gridStyle
= csGRID_STYLE_INVISIBLE
;
95 // Initialise this in OnInit, not statically
96 bool csApp::OnInit(void)
98 if (!wxResourceParseFile("studio_resources.wxr"))
100 wxMessageBox("Could not find or parse resource file: studio_resources.wxr", "Studio");
104 m_helpController
.Initialize("studio.hlp");
112 //// Create a document manager
113 m_docManager
= new wxDocManager
;
115 //// Create a template relating drawing documents to their views
116 (void) new wxDocTemplate(m_docManager
, "Diagram", "*.dia", "", "dia", "Diagram Doc", "Diagram View",
117 CLASSINFO(csDiagramDocument
), CLASSINFO(csDiagramView
));
119 // Create the main frame window
121 csFrame
* frame
= new csFrame(m_docManager
, NULL
, -1, "OGL Studio", m_mainFramePos
, m_mainFrameSize
,
122 wxDEFAULT_FRAME_STYLE
| wxHSCROLL
| wxVSCROLL
);
125 frame
->SetIcon(wxICON(studio
));
128 wxMenu
*fileMenu
= new wxMenu
;
130 fileMenu
->Append(wxID_NEW
, "&New...\tCtrl+N");
131 fileMenu
->Append(wxID_OPEN
, "&Open...\tCtrl+O");
133 fileMenu
->AppendSeparator();
135 fileMenu
->Append(wxID_PRINT
, "&Print...\tCtrl+P");
136 fileMenu
->Append(wxID_PRINT_SETUP
, "Print &Setup...");
137 fileMenu
->Append(wxID_PREVIEW
, "Print Pre&view");
138 fileMenu
->AppendSeparator();
139 fileMenu
->Append(wxID_EXIT
, "E&xit");
141 // A history of files visited. Use this menu.
142 m_docManager
->FileHistoryUseMenu(fileMenu
);
144 wxMenu
*viewMenu
= new wxMenu
;
145 viewMenu
->Append(ID_CS_SETTINGS
, "&Settings...");
147 wxMenu
*helpMenu
= new wxMenu
;
148 helpMenu
->Append(wxID_HELP
, "&Help Contents\tF1");
149 helpMenu
->Append(ID_CS_ABOUT
, "&About");
151 wxMenuBar
*menuBar
= new wxMenuBar
;
153 menuBar
->Append(fileMenu
, "&File");
154 menuBar
->Append(viewMenu
, "&View");
155 menuBar
->Append(helpMenu
, "&Help");
157 // Associate the menu bar with the frame
158 frame
->SetMenuBar(menuBar
);
160 // Load the file history
161 wxConfig
config("OGL Studio", "wxWindows");
162 m_docManager
->FileHistoryLoad(config
);
164 frame
->CreateStatusBar();
166 // The ordering of these is important for layout purposes
167 CreateDiagramToolBar(frame
);
168 CreatePalette(frame
);
169 CreateProjectWindow(frame
);
171 FillProjectTreeCtrl();
173 // Create the shape editing menu
174 m_shapeEditMenu
= new wxMenu("", (wxFunction
)studioShapeEditProc
);
175 m_shapeEditMenu
->Append(ID_CS_EDIT_PROPERTIES
, "Edit properties");
176 m_shapeEditMenu
->AppendSeparator();
177 m_shapeEditMenu
->Append(ID_CS_ROTATE_CLOCKWISE
, "Rotate clockwise");
178 m_shapeEditMenu
->Append(ID_CS_ROTATE_ANTICLOCKWISE
, "Rotate anticlockwise");
179 m_shapeEditMenu
->AppendSeparator();
180 m_shapeEditMenu
->Append(ID_CS_CUT
, "Cut");
189 int csApp::OnExit(void)
193 delete m_symbolDatabase
;
194 m_symbolDatabase
= NULL
;
199 delete m_shapeEditMenu
;
200 m_shapeEditMenu
= NULL
;
208 * Centralised code for creating a document frame.
209 * Called from view.cpp, when a view is created.
212 wxMDIChildFrame
*csApp::CreateChildFrame(wxDocument
*doc
, wxView
*view
, wxMenu
** editMenuRet
)
214 //// Make a child frame
215 csMDIChildFrame
*subframe
= new csMDIChildFrame(doc
, view
, ((wxDocMDIParentFrame
*)GetTopWindow()), -1, "Child Frame",
216 wxPoint(10, 10), wxSize(300, 300), wxDEFAULT_FRAME_STYLE
);
219 subframe
->SetIcon(wxString("chart"));
222 subframe
->SetIcon(wxIcon("doc.xbm"));
226 wxMenu
*fileMenu
= new wxMenu
;
228 fileMenu
->Append(wxID_NEW
, "&New...\tCtrl+N");
229 fileMenu
->Append(wxID_OPEN
, "&Open...\tCtrl+O");
230 fileMenu
->Append(wxID_CLOSE
, "&Close\tCtrl+W");
231 fileMenu
->Append(wxID_SAVE
, "&Save\tCtrl+S");
232 fileMenu
->Append(wxID_SAVEAS
, "Save &As...\tF12");
234 fileMenu
->AppendSeparator();
235 fileMenu
->Append(wxID_PRINT
, "&Print...\tCtrl+P");
236 fileMenu
->Append(wxID_PRINT_SETUP
, "Print &Setup...");
237 fileMenu
->Append(wxID_PREVIEW
, "Print Pre&view");
239 fileMenu
->AppendSeparator();
240 fileMenu
->Append(wxID_EXIT
, "E&xit");
242 wxMenu
*editMenu
= NULL
;
244 editMenu
= new wxMenu
;
245 editMenu
->Append(wxID_UNDO
, "&Undo\tCtrl+Z");
246 editMenu
->Append(wxID_REDO
, "&Redo\tCtrl+Y");
247 editMenu
->AppendSeparator();
248 editMenu
->Append(wxID_CUT
, "Cu&t\tCtrl+X");
249 editMenu
->Append(wxID_COPY
, "&Copy\tCtrl+C");
250 editMenu
->Append(wxID_PASTE
, "&Paste\tCtrl+V");
251 editMenu
->Append(wxID_DUPLICATE
, "&Duplicate\tCtrl+D");
252 editMenu
->AppendSeparator();
253 editMenu
->Append(wxID_CLEAR
, "Cle&ar\tDelete");
254 editMenu
->Append(ID_CS_SELECT_ALL
, "Select A&ll\tCtrl+A");
255 editMenu
->AppendSeparator();
256 editMenu
->Append(ID_CS_EDIT_PROPERTIES
, "Edit P&roperties...");
258 *editMenuRet
= editMenu
;
260 m_docManager
->FileHistoryUseMenu(fileMenu
);
261 m_docManager
->FileHistoryAddFilesToMenu(fileMenu
);
263 doc
->GetCommandProcessor()->SetEditMenu(editMenu
);
265 wxMenu
*viewMenu
= new wxMenu
;
266 viewMenu
->Append(ID_CS_SETTINGS
, "&Settings...");
268 wxMenu
*helpMenu
= new wxMenu
;
269 helpMenu
->Append(wxID_HELP
, "&Help Contents\tF1");
270 helpMenu
->Append(ID_CS_ABOUT
, "&About");
272 wxMenuBar
*menuBar
= new wxMenuBar
;
274 menuBar
->Append(fileMenu
, "&File");
275 menuBar
->Append(editMenu
, "&Edit");
276 menuBar
->Append(viewMenu
, "&View");
277 menuBar
->Append(helpMenu
, "&Help");
279 //// Associate the menu bar with the frame
280 subframe
->SetMenuBar(menuBar
);
285 // Creates a canvas. Called by OnInit as a child of the main window
286 csCanvas
*csApp::CreateCanvas(wxView
*view
, wxFrame
*parent
)
289 parent
->GetClientSize(&width
, &height
);
291 // Non-retained canvas
292 csCanvas
*canvas
= new csCanvas((csDiagramView
*) view
, parent
, 1000, wxPoint(0, 0), wxSize(width
, height
), 0);
294 wxColour
bgColour("WHITE");
295 canvas
->SetBackgroundColour(bgColour
);
297 wxCursor
cursor(wxCURSOR_HAND
);
298 canvas
->SetCursor(cursor
);
300 // Give it scrollbars
301 canvas
->SetScrollbars(20, 20, 100, 100);
306 void csApp::InitToolBar(wxToolBar
* toolBar
)
308 wxBitmap
* bitmaps
[10];
311 bitmaps
[0] = new wxBitmap("new", wxBITMAP_TYPE_RESOURCE
);
312 bitmaps
[1] = new wxBitmap("open", wxBITMAP_TYPE_RESOURCE
);
313 bitmaps
[2] = new wxBitmap("save", wxBITMAP_TYPE_RESOURCE
);
314 bitmaps
[3] = new wxBitmap("copy", wxBITMAP_TYPE_RESOURCE
);
315 bitmaps
[4] = new wxBitmap("cut", wxBITMAP_TYPE_RESOURCE
);
316 bitmaps
[5] = new wxBitmap("paste", wxBITMAP_TYPE_RESOURCE
);
317 bitmaps
[6] = new wxBitmap("print", wxBITMAP_TYPE_RESOURCE
);
318 bitmaps
[7] = new wxBitmap("help", wxBITMAP_TYPE_RESOURCE
);
319 bitmaps
[8] = new wxBitmap("undo", wxBITMAP_TYPE_RESOURCE
);
320 bitmaps
[9] = new wxBitmap("redo", wxBITMAP_TYPE_RESOURCE
);
321 #elif defined(__WXGTK__) || defined(__WXMOTIF__)
322 bitmaps
[0] = new wxBitmap( new_xpm
);
323 bitmaps
[1] = new wxBitmap( open_xpm
);
324 bitmaps
[2] = new wxBitmap( save_xpm
);
325 bitmaps
[3] = new wxBitmap( copy_xpm
);
326 bitmaps
[4] = new wxBitmap( cut_xpm
);
327 bitmaps
[5] = new wxBitmap( paste_xpm
);
328 bitmaps
[6] = new wxBitmap( print_xpm
);
329 bitmaps
[7] = new wxBitmap( help_xpm
);
330 bitmaps
[8] = new wxBitmap( undo_xpm
);
331 bitmaps
[9] = new wxBitmap( redo_xpm
);
333 #error "Not implemented for this platform."
336 toolBar
->AddTool(wxID_NEW
, *bitmaps
[0], wxNullBitmap
, FALSE
, -1, -1, NULL
, "New file");
337 toolBar
->AddTool(wxID_OPEN
, *bitmaps
[1], wxNullBitmap
, FALSE
, -1, -1, NULL
, "Open file");
338 toolBar
->AddTool(wxID_SAVE
, *bitmaps
[2], wxNullBitmap
, FALSE
, -1, -1, NULL
, "Save file");
339 toolBar
->AddSeparator();
340 toolBar
->AddTool(wxID_PRINT
, *bitmaps
[6], wxNullBitmap
, FALSE
, -1, -1, NULL
, "Print");
341 toolBar
->AddSeparator();
342 toolBar
->AddTool(wxID_COPY
, *bitmaps
[3], wxNullBitmap
, FALSE
, -1, -1, NULL
, "Copy");
343 toolBar
->AddTool(wxID_CUT
, *bitmaps
[4], wxNullBitmap
, FALSE
, -1, -1, NULL
, "Cut");
344 toolBar
->AddTool(wxID_PASTE
, *bitmaps
[5], wxNullBitmap
, FALSE
, -1, -1, NULL
, "Paste");
345 toolBar
->AddSeparator();
346 toolBar
->AddTool(wxID_UNDO
, *bitmaps
[8], wxNullBitmap
, FALSE
, -1, -1, NULL
, "Undo");
347 toolBar
->AddTool(wxID_REDO
, *bitmaps
[9], wxNullBitmap
, FALSE
, -1, -1, NULL
, "Redo");
348 toolBar
->AddSeparator();
349 toolBar
->AddTool(wxID_HELP
, *bitmaps
[7], wxNullBitmap
, FALSE
, -1, -1, NULL
, "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::GetSystemColour(wxSYS_COLOUR_3DFACE
));
374 m_diagramToolBarSashWindow
= win
;
375 m_diagramToolBarSashWindow
->Show(FALSE
);
377 // Create the actual toolbar
378 m_diagramToolBar
= new wxToolBar(win
, -1, wxDefaultPosition
, wxDefaultSize
, wxTB_HORIZONTAL
|wxNO_BORDER
|wxTB_FLAT
);
380 wxBitmap
* bitmaps
[11];
383 bitmaps
[0] = new wxBitmap("alignl", wxBITMAP_TYPE_RESOURCE
);
384 bitmaps
[1] = new wxBitmap("alignr", wxBITMAP_TYPE_RESOURCE
);
385 bitmaps
[2] = new wxBitmap("alignt", wxBITMAP_TYPE_RESOURCE
);
386 bitmaps
[3] = new wxBitmap("alignb", wxBITMAP_TYPE_RESOURCE
);
387 bitmaps
[4] = new wxBitmap("horiz", wxBITMAP_TYPE_RESOURCE
);
388 bitmaps
[5] = new wxBitmap("vert", wxBITMAP_TYPE_RESOURCE
);
389 bitmaps
[6] = new wxBitmap("copysize", wxBITMAP_TYPE_RESOURCE
);
390 bitmaps
[7] = new wxBitmap("linearrow", wxBITMAP_TYPE_RESOURCE
);
391 bitmaps
[8] = new wxBitmap("newpoint", wxBITMAP_TYPE_RESOURCE
);
392 bitmaps
[9] = new wxBitmap("cutpoint", wxBITMAP_TYPE_RESOURCE
);
393 bitmaps
[10] = new wxBitmap("straighten", wxBITMAP_TYPE_RESOURCE
);
394 #elif defined(__WXGTK__) || defined(__WXMOTIF__)
395 bitmaps
[0] = new wxBitmap( alignl_xpm
);
396 bitmaps
[1] = new wxBitmap( alignr_xpm
);
397 bitmaps
[2] = new wxBitmap( alignt_xpm
);
398 bitmaps
[3] = new wxBitmap( alignb_xpm
);
399 bitmaps
[4] = new wxBitmap( horiz_xpm
);
400 bitmaps
[5] = new wxBitmap( vert_xpm
);
401 bitmaps
[6] = new wxBitmap( copysize_xpm
);
402 bitmaps
[7] = new wxBitmap( linearrow_xpm
);
403 bitmaps
[8] = new wxBitmap( newpoint_xpm
);
404 bitmaps
[9] = new wxBitmap( cutpoint_xpm
);
405 bitmaps
[10] = new wxBitmap( straight_xpm
);
407 #error "Not implemented for this platform."
410 m_diagramToolBar
->AddTool(DIAGRAM_TOOLBAR_ALIGNL
, *bitmaps
[0], wxNullBitmap
, FALSE
, -1, -1, NULL
, "Align left");
411 m_diagramToolBar
->AddTool(DIAGRAM_TOOLBAR_ALIGNR
, *bitmaps
[1], wxNullBitmap
, FALSE
, -1, -1, NULL
, "Align right");
412 m_diagramToolBar
->AddTool(DIAGRAM_TOOLBAR_ALIGNT
, *bitmaps
[2], wxNullBitmap
, FALSE
, -1, -1, NULL
, "Align top");
413 m_diagramToolBar
->AddTool(DIAGRAM_TOOLBAR_ALIGNB
, *bitmaps
[3], wxNullBitmap
, FALSE
, -1, -1, NULL
, "Align bottom");
414 m_diagramToolBar
->AddTool(DIAGRAM_TOOLBAR_ALIGN_HORIZ
, *bitmaps
[4], wxNullBitmap
, FALSE
, -1, -1, NULL
, "Align horizontally");
415 m_diagramToolBar
->AddTool(DIAGRAM_TOOLBAR_ALIGN_VERT
, *bitmaps
[5], wxNullBitmap
, FALSE
, -1, -1, NULL
, "Align vertically");
416 m_diagramToolBar
->AddTool(DIAGRAM_TOOLBAR_COPY_SIZE
, *bitmaps
[6], wxNullBitmap
, FALSE
, -1, -1, NULL
, "Copy size");
417 m_diagramToolBar
->AddSeparator();
418 m_diagramToolBar
->AddTool(DIAGRAM_TOOLBAR_LINE_ARROW
, *bitmaps
[7], wxNullBitmap
, TRUE
, -1, -1, NULL
, "Toggle arrow");
419 m_diagramToolBar
->AddTool(DIAGRAM_TOOLBAR_NEW_POINT
, *bitmaps
[8], wxNullBitmap
, FALSE
, -1, -1, NULL
, "New line point");
420 m_diagramToolBar
->AddTool(DIAGRAM_TOOLBAR_CUT_POINT
, *bitmaps
[9], wxNullBitmap
, FALSE
, -1, -1, NULL
, "Cut line point");
421 m_diagramToolBar
->AddTool(DIAGRAM_TOOLBAR_STRAIGHTEN
, *bitmaps
[10], wxNullBitmap
, FALSE
, -1, -1, NULL
, "Straighten lines");
423 m_diagramToolBar
->Realize();
426 for (i
= 0; i
< 11; i
++)
429 // Create a combobox for point size
430 int maxPointSize
= 40;
431 wxString
*pointSizes
= new wxString
[maxPointSize
];
432 for (i
= 1; i
<= maxPointSize
; i
++)
434 pointSizes
[i
-1].Printf("%d", i
);
450 m_pointSizeComboBox
= new wxComboBox(m_diagramToolBar
, ID_WINDOW_POINT_SIZE_COMBOBOX
,
451 "", wxPoint(controlX
, 1), wxSize(pointSizeW
, pointSizeH
), maxPointSize
, pointSizes
);
454 m_pointSizeComboBox
->SetSelection(10 - 1);
456 // Create a combobox for zooming
460 int noStrings
= (maxZoom
- minZoom
)/5 ;
461 wxString
*zoomStrings
= new wxString
[noStrings
];
462 for (i
= 0; i
< noStrings
; i
++)
464 zoomStrings
[noStrings
- i
- 1].Printf("%d%%", (i
*increment
+ minZoom
));
467 controlX
+= pointSizeW
+ 10;
469 m_zoomComboBox
= new wxComboBox(m_diagramToolBar
, ID_WINDOW_ZOOM_COMBOBOX
,
470 "", wxPoint(controlX
, 1), wxSize(zoomW
, zoomH
), noStrings
, zoomStrings
);
471 delete[] zoomStrings
;
473 // i = (zoom - minZoom)/increment
474 // index = noStrings - i - 1
476 i
= (100 - minZoom
)/increment
;
477 m_zoomComboBox
->SetSelection(noStrings
- i
- 1);
480 // Read/write configuration information
481 bool csApp::ReadOptions()
483 wxConfig
config("OGL Studio", "wxWindows");
485 config
.Read("mainX", & m_mainFramePos
.x
);
486 config
.Read("mainY", & m_mainFramePos
.y
);
487 config
.Read("mainWidth", & m_mainFrameSize
.x
);
488 config
.Read("mainHeight", & m_mainFrameSize
.y
);
489 config
.Read("gridStyle", & m_gridStyle
);
490 config
.Read("gridSpacing", & m_gridSpacing
);
495 bool csApp::WriteOptions()
497 wxConfig
config("OGL Studio", "wxWindows");
499 config
.Write("mainX", m_mainFramePos
.x
);
500 config
.Write("mainY", m_mainFramePos
.y
);
501 config
.Write("mainWidth", m_mainFrameSize
.x
);
502 config
.Write("mainHeight", m_mainFrameSize
.y
);
503 config
.Write("gridStyle", m_gridStyle
);
504 config
.Write("gridSpacing", m_gridSpacing
);
506 m_docManager
->FileHistorySave(config
);