]>
Commit | Line | Data |
---|---|---|
f449ef69 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: view.cpp | |
3 | // Purpose: Implements view functionality in OGLEdit | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 12/07/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | // #pragma implementation | |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h". | |
17 | #include <wx/wxprec.h> | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #ifndef WX_PRECOMP | |
24 | #include <wx/wx.h> | |
25 | #endif | |
26 | ||
27 | #include <wx/colordlg.h> | |
28 | ||
29 | #if !USE_DOC_VIEW_ARCHITECTURE | |
30 | #error You must set USE_DOC_VIEW_ARCHITECTURE to 1 in wx_setup.h! | |
31 | #endif | |
32 | ||
33 | #include "ogledit.h" | |
34 | #include "doc.h" | |
35 | #include "view.h" | |
36 | #include "palette.h" | |
37 | ||
38 | IMPLEMENT_DYNAMIC_CLASS(DiagramView, wxView) | |
39 | ||
40 | BEGIN_EVENT_TABLE(DiagramView, wxView) | |
41 | EVT_MENU(OGLEDIT_CUT, DiagramView::OnCut) | |
42 | EVT_MENU(OGLEDIT_CHANGE_BACKGROUND_COLOUR, DiagramView::OnChangeBackgroundColour) | |
43 | EVT_MENU(OGLEDIT_EDIT_LABEL, DiagramView::OnEditLabel) | |
44 | END_EVENT_TABLE() | |
45 | ||
46 | // What to do when a view is created. Creates actual | |
47 | // windows for displaying the view. | |
48 | bool DiagramView::OnCreate(wxDocument *doc, long flags) | |
49 | { | |
50 | frame = GetMainFrame(); | |
51 | canvas = GetMainFrame()->canvas; | |
52 | canvas->view = this; | |
53 | ||
54 | SetFrame(frame); | |
55 | Activate(TRUE); | |
56 | ||
57 | // Initialize the edit menu Undo and Redo items | |
58 | doc->GetCommandProcessor()->SetEditMenu(((MyFrame *)frame)->editMenu); | |
59 | doc->GetCommandProcessor()->Initialize(); | |
60 | ||
61 | wxShapeCanvas *shapeCanvas = (wxShapeCanvas *)canvas; | |
62 | DiagramDocument *diagramDoc = (DiagramDocument *)doc; | |
63 | shapeCanvas->SetDiagram(diagramDoc->GetDiagram()); | |
64 | diagramDoc->GetDiagram()->SetCanvas(shapeCanvas); | |
65 | ||
66 | return TRUE; | |
67 | } | |
68 | ||
69 | // Sneakily gets used for default print/preview | |
70 | // as well as drawing on the screen. | |
71 | void DiagramView::OnDraw(wxDC *dc) | |
72 | { | |
73 | } | |
74 | ||
75 | void DiagramView::OnUpdate(wxView *sender, wxObject *hint) | |
76 | { | |
77 | if (canvas) | |
78 | canvas->Refresh(); | |
79 | } | |
80 | ||
81 | // Clean up windows used for displaying the view. | |
82 | bool DiagramView::OnClose(bool deleteWindow) | |
83 | { | |
84 | if (!GetDocument()->Close()) | |
85 | return FALSE; | |
86 | ||
87 | DiagramDocument *diagramDoc = (DiagramDocument *)GetDocument(); | |
88 | diagramDoc->GetDiagram()->SetCanvas(NULL); | |
89 | ||
90 | canvas->Clear(); | |
91 | canvas->SetDiagram(NULL); | |
92 | canvas->view = NULL; | |
93 | canvas = NULL; | |
94 | ||
95 | wxString s = wxTheApp->GetAppName(); | |
96 | if (frame) | |
97 | frame->SetTitle(s); | |
98 | ||
99 | SetFrame(NULL); | |
100 | ||
101 | Activate(FALSE); | |
102 | ||
103 | return TRUE; | |
104 | } | |
105 | ||
106 | wxShape *DiagramView::FindSelectedShape(void) | |
107 | { | |
108 | DiagramDocument *doc = (DiagramDocument *)GetDocument(); | |
109 | wxShape *theShape = NULL; | |
110 | wxNode *node = doc->GetDiagram()->GetShapeList()->First(); | |
111 | while (node) | |
112 | { | |
113 | wxShape *eachShape = (wxShape *)node->Data(); | |
114 | if ((eachShape->GetParent() == NULL) && eachShape->Selected()) | |
115 | { | |
116 | theShape = eachShape; | |
117 | node = NULL; | |
118 | } | |
119 | else node = node->Next(); | |
120 | } | |
121 | return theShape; | |
122 | } | |
123 | ||
124 | void DiagramView::OnCut(wxCommandEvent& event) | |
125 | { | |
126 | DiagramDocument *doc = (DiagramDocument *)GetDocument(); | |
127 | ||
128 | wxShape *theShape = FindSelectedShape(); | |
129 | if (theShape) | |
130 | doc->GetCommandProcessor()->Submit(new DiagramCommand("Cut", OGLEDIT_CUT, doc, NULL, 0.0, 0.0, TRUE, theShape)); | |
131 | } | |
132 | ||
133 | void DiagramView::OnChangeBackgroundColour(wxCommandEvent& event) | |
134 | { | |
135 | DiagramDocument *doc = (DiagramDocument *)GetDocument(); | |
136 | ||
137 | wxShape *theShape = FindSelectedShape(); | |
138 | if (theShape) | |
139 | { | |
140 | wxColourData data; | |
141 | data.SetChooseFull(TRUE); | |
142 | data.SetColour(theShape->GetBrush()->GetColour()); | |
143 | ||
144 | wxColourDialog *dialog = new wxColourDialog(frame, &data); | |
145 | wxBrush *theBrush = NULL; | |
146 | if (dialog->ShowModal() == wxID_OK) | |
147 | { | |
148 | wxColourData retData = dialog->GetColourData(); | |
149 | wxColour col = retData.GetColour(); | |
150 | theBrush = wxTheBrushList->FindOrCreateBrush(col, wxSOLID); | |
151 | } | |
152 | dialog->Close(); | |
153 | ||
154 | if (theBrush) | |
155 | doc->GetCommandProcessor()->Submit(new DiagramCommand("Change colour", OGLEDIT_CHANGE_BACKGROUND_COLOUR, doc, | |
156 | theBrush, theShape)); | |
157 | } | |
158 | } | |
159 | ||
160 | void DiagramView::OnEditLabel(wxCommandEvent& event) | |
161 | { | |
162 | wxShape *theShape = FindSelectedShape(); | |
163 | if (theShape) | |
164 | { | |
165 | wxString newLabel = wxGetTextFromUser("Enter new label", "Shape Label", ((MyEvtHandler *)theShape->GetEventHandler())->label); | |
166 | GetDocument()->GetCommandProcessor()->Submit(new DiagramCommand("Edit label", OGLEDIT_EDIT_LABEL, (DiagramDocument*) GetDocument(), newLabel, theShape)); | |
167 | } | |
168 | } | |
169 | ||
170 | /* | |
171 | * Window implementations | |
172 | */ | |
173 | ||
174 | BEGIN_EVENT_TABLE(MyCanvas, wxShapeCanvas) | |
175 | EVT_MOUSE_EVENTS(MyCanvas::OnMouseEvent) | |
176 | EVT_PAINT(MyCanvas::OnPaint) | |
177 | END_EVENT_TABLE() | |
178 | ||
179 | // Define a constructor for my canvas | |
180 | MyCanvas::MyCanvas(wxView *v, wxWindow *parent, wxWindowID id, const wxPoint& pos, | |
181 | const wxSize& size, long style): | |
182 | wxShapeCanvas(parent, id, pos, size, style) | |
183 | { | |
184 | view = v; | |
185 | } | |
186 | ||
187 | MyCanvas::~MyCanvas(void) | |
188 | { | |
189 | } | |
190 | ||
42cfaf8c | 191 | void MyCanvas::OnLeftClick(double x, double y, int keys) |
f449ef69 JS |
192 | { |
193 | EditorToolPalette *palette = wxGetApp().frame->palette; | |
194 | wxClassInfo *info = NULL; | |
195 | switch (palette->currentlySelected) | |
196 | { | |
197 | case PALETTE_TOOL1: | |
198 | { | |
199 | info = CLASSINFO(wxRectangleShape); | |
200 | break; | |
201 | } | |
202 | case PALETTE_TOOL2: | |
203 | { | |
204 | info = CLASSINFO(wxRoundedRectangleShape); | |
205 | break; | |
206 | } | |
207 | case PALETTE_TOOL3: | |
208 | { | |
209 | info = CLASSINFO(wxEllipseShape); | |
210 | break; | |
211 | } | |
212 | case PALETTE_TOOL4: | |
213 | { | |
214 | info = CLASSINFO(wxDiamondShape); | |
215 | break; | |
216 | } | |
217 | default: | |
218 | break; | |
219 | } | |
220 | if (info) | |
221 | { | |
222 | view->GetDocument()->GetCommandProcessor()->Submit(new DiagramCommand(info->GetClassName(), OGLEDIT_ADD_SHAPE, (DiagramDocument *)view->GetDocument(), info, | |
223 | x, y)); | |
224 | } | |
225 | } | |
226 | ||
42cfaf8c | 227 | void MyCanvas::OnRightClick(double x, double y, int keys) |
f449ef69 JS |
228 | { |
229 | } | |
230 | ||
42cfaf8c | 231 | void MyCanvas::OnDragLeft(bool draw, double x, double y, int keys) |
f449ef69 JS |
232 | { |
233 | } | |
234 | ||
42cfaf8c | 235 | void MyCanvas::OnBeginDragLeft(double x, double y, int keys) |
f449ef69 JS |
236 | { |
237 | } | |
238 | ||
42cfaf8c | 239 | void MyCanvas::OnEndDragLeft(double x, double y, int keys) |
f449ef69 JS |
240 | { |
241 | } | |
242 | ||
42cfaf8c | 243 | void MyCanvas::OnDragRight(bool draw, double x, double y, int keys) |
f449ef69 JS |
244 | { |
245 | } | |
246 | ||
42cfaf8c | 247 | void MyCanvas::OnBeginDragRight(double x, double y, int keys) |
f449ef69 JS |
248 | { |
249 | } | |
250 | ||
42cfaf8c | 251 | void MyCanvas::OnEndDragRight(double x, double y, int keys) |
f449ef69 JS |
252 | { |
253 | } | |
254 | ||
255 | void MyCanvas::OnMouseEvent(wxMouseEvent& event) | |
256 | { | |
257 | wxShapeCanvas::OnMouseEvent(event); | |
258 | } | |
259 | ||
260 | void MyCanvas::OnPaint(wxPaintEvent& event) | |
261 | { | |
262 | // if (GetDiagram()) | |
263 | wxShapeCanvas::OnPaint(event); | |
264 | } |