1
2 #include "studiox_includes.h"
3
4 #include "gx_api.h"
5 #include "target_view.h"
6 #include "studiox_util.h"
7 #include "clone_repo_dialog.h"
8 #include "color_edit_dialog.h"
9
10 #ifdef _DEBUG
11 #define new DEBUG_NEW
12 #endif
13
14 CString target_class_name;
15 extern CBrush WinBackBrush;
16 extern INI_INFO StudioXIni;
17
18 //IMPLEMENT_DYNCREATE(target_view, CScrollView)
IMPLEMENT_DYNCREATE(target_view,CView)19 IMPLEMENT_DYNCREATE(target_view, CView)
20
21 //BEGIN_MESSAGE_MAP(target_view, CScrollView)
22 BEGIN_MESSAGE_MAP(target_view, CView)
23 // ON_WM_PAINT()
24 ON_WM_ERASEBKGND()
25 ON_WM_CREATE()
26 ON_WM_SIZE()
27 ON_WM_SETFOCUS()
28 END_MESSAGE_MAP()
29
30 ///////////////////////////////////////////////////////////////////////////////
31 target_view::target_view()
32 {
33 mpRecentDialog = NULL;
34 mpTargetFrame = NULL;
35 mpTargetScreen = NULL;
36 mpToolBar = NULL;
37 }
38
39 ///////////////////////////////////////////////////////////////////////////////
~target_view()40 target_view::~target_view()
41 {
42 delete mpTargetScreen;
43 delete mpRecentDialog;
44 //delete mpTargetHeader;
45 }
46
47 ///////////////////////////////////////////////////////////////////////////////
PreCreateWindow(CREATESTRUCT & cs)48 BOOL target_view::PreCreateWindow(CREATESTRUCT &cs)
49 {
50 cs.style |= WS_CLIPCHILDREN;
51 return CView::PreCreateWindow(cs);
52 //return CScrollView::PreCreateWindow(cs);
53 }
54
55
56 ///////////////////////////////////////////////////////////////////////////////
OnCreate(LPCREATESTRUCT lpCreateStruct)57 int target_view::OnCreate(LPCREATESTRUCT lpCreateStruct)
58 {
59 RECT childrect;
60
61 CView::OnCreate(lpCreateStruct);
62 SetWindowText(_T("Target View"));
63
64 // register class was here
65
66 GetClientRect(&childrect);
67
68 mpTargetFrame = new target_frame();
69 mpTargetFrame->Create(target_class_name, NULL,
70 WS_CHILD, childrect, this, TARGET_FRAME_ID, NULL);
71
72 //GetDialogCtrlID
73
74 // the dimensions used here don't really matter. The target
75 // screen resizes itself to the actual display size automatically.
76
77 mpTargetScreen = new target_screen();
78 childrect.left = 0;
79 childrect.top = 0;
80 childrect.right = 320;
81 childrect.bottom = 240;
82 mpTargetScreen->Create(target_class_name, NULL,
83 WS_CHILD|WS_VISIBLE, childrect, mpTargetFrame, 0, NULL);
84 mpTargetScreen->CenterWindow();
85
86 return 0;
87 }
88
89 ///////////////////////////////////////////////////////////////////////////////
OnInitialUpdate()90 void target_view::OnInitialUpdate()
91 {
92 CView::OnInitialUpdate();
93 CMainFrame *frame = (CMainFrame *) GetParentFrame();
94 frame->SetTargetView(this);
95
96 if (!mpRecentDialog)
97 {
98 int dpi = GetSystemDPI();
99 int text_scaler = GetTextScaler();
100 int width = GetScaledValue(RECENT_WINDOW_WIDTH, dpi, text_scaler);
101 int height = GetScaledValue(RECENT_WINDOW_HEIGHT, dpi, text_scaler);
102
103 mpRecentDialog = new recent_project_win(width, height, frame);
104 mpRecentDialog->Create(IDD_DIALOG_TEMPLATE, frame);
105 }
106 }
107
108
109 ///////////////////////////////////////////////////////////////////////////////
OnEraseBkgnd(CDC * pDC)110 BOOL target_view::OnEraseBkgnd(CDC *pDC)
111 {
112 // Set brush to desired background color
113 //CBrush backBrush(RGB(255, 128, 128));
114
115 // Save old brush
116 CBrush* pOldBrush = pDC->SelectObject(&WinBackBrush);
117
118 CRect rect;
119 pDC->GetClipBox(&rect); // Erase the area needed
120
121 pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(),
122 PATCOPY);
123 pDC->SelectObject(pOldBrush);
124 return TRUE;
125 }
126
127 ///////////////////////////////////////////////////////////////////////////////
OnDraw(CDC * pDC)128 void target_view::OnDraw(CDC *pDC)
129 {
130 CView::OnDraw(pDC);
131 }
132
133 ///////////////////////////////////////////////////////////////////////////////
OnSize(UINT nType,int cx,int cy)134 void target_view::OnSize(UINT nType, int cx, int cy)
135 {
136 CView::OnSize(nType, cx, cy);
137
138 CRect size;
139 GetClientRect(&size);
140 mpTargetFrame->MoveWindow(&size);
141 mpTargetScreen->UpdateWindowPos();
142 }
143
144 ///////////////////////////////////////////////////////////////////////////////
DisplayTarget()145 void target_view::DisplayTarget()
146 {
147 mpRecentDialog->ShowWindow(SW_HIDE);
148 mpTargetScreen->CenterWindow();
149 mpTargetFrame->ShowWindow(SW_SHOW);
150 }
151
152 ///////////////////////////////////////////////////////////////////////////////
DisplayRecentProjects()153 void target_view::DisplayRecentProjects()
154 {
155 mpTargetFrame->ShowWindow(SW_HIDE);
156
157 mpRecentDialog->CenterWindow();
158 mpRecentDialog->ShowWindow(SW_SHOW);
159 }
160
161
162 //////////////////////////////////////////////////////////////////////////////
163 //////////////////////////////////////////////////////////////////////////////
InitialDisplay(void)164 void target_view::InitialDisplay(void)
165 {
166 #if !defined(FORCE_CLONE_DIALOG)
167 if (StudioXIni.first_run)
168 #endif
169 {
170 CWnd *parent = AfxGetApp()->m_pMainWnd;
171 clone_repo_dialog *dlg = new clone_repo_dialog(parent);
172 dlg->DoModal();
173 delete(dlg);
174 }
175 DisplayRecentProjects();
176 }
177
178 //////////////////////////////////////////////////////////////////////////////
179 //////////////////////////////////////////////////////////////////////////////
180
BEGIN_MESSAGE_MAP(target_frame,CScrollView)181 BEGIN_MESSAGE_MAP(target_frame, CScrollView)
182 ON_WM_SIZE()
183 ON_WM_KEYDOWN()
184 ON_WM_LBUTTONDOWN()
185 ON_WM_ERASEBKGND()
186 END_MESSAGE_MAP()
187
188 target_frame::target_frame()
189 {
190 }
191
PreCreateWindow(CREATESTRUCT & cs)192 BOOL target_frame::PreCreateWindow(CREATESTRUCT &cs)
193 {
194 cs.style |= WS_CLIPCHILDREN;
195 return CScrollView::PreCreateWindow(cs);
196 }
197
198 ///////////////////////////////////////////////////////////////////////////////
OnLButtonDown(UINT nFlags,CPoint point)199 void target_frame::OnLButtonDown(UINT nFlags, CPoint point)
200 {
201 GetProjectView()->DeSelect();
202 }
203
204 ///////////////////////////////////////////////////////////////////////////////
OnKeyDown(UINT nChar,UINT Rep,UINT flags)205 void target_frame::OnKeyDown(UINT nChar, UINT Rep, UINT flags)
206 {
207 studiox_project *project = GetOpenProject();
208
209 if (!project)
210 {
211 return;
212 }
213 BOOL snap_enabled = project->mHeader.snap_enabled;
214 int snap_spacing = project->mHeader.snap_spacing;
215
216 switch(nChar)
217 {
218 case VK_DELETE:
219 GetProjectView()->OnDeleteWidget();
220 break;
221
222 case VK_UP:
223 if (snap_enabled)
224 {
225 GetTargetScreen()->ShiftSelectedWidgets(0, -snap_spacing);
226 }
227 else
228 {
229 GetTargetScreen()->ShiftSelectedWidgets(0, -1);
230 }
231 break;
232
233 case VK_DOWN:
234 if (snap_enabled)
235 {
236 GetTargetScreen()->ShiftSelectedWidgets(0, snap_spacing);
237 }
238 else
239 {
240 GetTargetScreen()->ShiftSelectedWidgets(0, 1);
241 }
242 break;
243
244 case VK_LEFT:
245 if (snap_enabled)
246 {
247 GetTargetScreen()->ShiftSelectedWidgets(-snap_spacing, 0);
248 }
249 else
250 {
251 GetTargetScreen()->ShiftSelectedWidgets(-1, 0);
252 }
253 break;
254
255 case VK_RIGHT:
256 if (snap_enabled)
257 {
258 GetTargetScreen()->ShiftSelectedWidgets(snap_spacing, 0);
259 }
260 else
261 {
262 GetTargetScreen()->ShiftSelectedWidgets(1, 0);
263 }
264 break;
265
266 default:
267 break;
268 }
269 }
270
271 ///////////////////////////////////////////////////////////////////////////////
UpdateScrollSize()272 void target_frame::UpdateScrollSize()
273 {
274 CWnd *child = GetWindow(GW_CHILD);
275 CRect size;
276 CSize sizetotal;
277
278 if (child)
279 {
280 child->GetClientRect(&size);
281 sizetotal.cx = size.right - size.left + 2;
282 sizetotal.cy = size.bottom - size.top + 2;
283 SetScrollSizes(MM_TEXT, sizetotal);
284 }
285 }
286
287 ///////////////////////////////////////////////////////////////////////////////
OnInitialUpdate()288 void target_frame::OnInitialUpdate()
289 {
290 CScrollView::OnInitialUpdate();
291 UpdateScrollSize();
292 }
293
294 ///////////////////////////////////////////////////////////////////////////////
OnSize(UINT nType,int cx,int cy)295 void target_frame::OnSize(UINT nType, int cx, int cy)
296 {
297 CView::OnSize(nType, cx, cy);
298 UpdateScrollSize();
299 }
300
301 ///////////////////////////////////////////////////////////////////////////////
OnEraseBkgnd(CDC * dc)302 BOOL target_frame::OnEraseBkgnd(CDC *dc)
303 {
304 CRect client;
305 GetClientRect(&client);
306 TRIVERTEX vertex[2] ;
307 vertex[0].x = client.left;
308 vertex[0].y = client.top;
309 vertex[0].Red = 0xc600;
310 vertex[0].Green = 0xc600;
311 vertex[0].Blue = 0xc600;
312 vertex[0].Alpha = 0x0000;
313
314 vertex[1].x = client.right;
315 vertex[1].y = client.bottom;
316 vertex[1].Red = 0x0000;
317 vertex[1].Green = 0x0000;
318 vertex[1].Blue = 0x0000;
319 vertex[1].Alpha = 0x0000;
320
321 // Create a GRADIENT_RECT structure that
322 // references the TRIVERTEX vertices.
323 GRADIENT_RECT gRect;
324 gRect.UpperLeft = 0;
325 gRect.LowerRight = 1;
326
327 // Draw a shaded rectangle.
328 dc->GradientFill(vertex, 2, &gRect, 1, GRADIENT_FILL_RECT_V);
329 return TRUE;
330 }
331
332 ///////////////////////////////////////////////////////////////////////////////
OnDraw(CDC * pDC)333 void target_frame::OnDraw(CDC* pDC)
334 {
335 // outline the target screen:
336 CWnd *child = GetWindow(GW_CHILD);
337 CRect size;
338 CPen whitepen(PS_SOLID, 1, RGB(215, 215, 215));
339 CPen blackpen(PS_SOLID, 1, RGB(59, 59, 59));
340 CPen graypen(PS_SOLID, 2, RGB(161, 161, 161));
341 CPen *oldpen = pDC->SelectObject(&whitepen);
342
343 if (!child)
344 {
345 return;
346 }
347
348 child->GetWindowRect(&size);
349 ScreenToClient(&size);
350 pDC->MoveTo(size.right + 1, size.top -1);
351 pDC->LineTo(size.right + 1, size.bottom + 1);
352 pDC->LineTo(size.left - 1, size.bottom + 1);
353 pDC->SelectObject(&blackpen);
354 pDC->LineTo(size.left - 1, size.top - 1);
355 pDC->LineTo(size.right + 1, size.top - 1);
356
357 pDC->SelectObject(&blackpen);
358 pDC->MoveTo(size.right + 8, size.top - 1);
359 pDC->LineTo(size.right + 1, size.top - 1);
360 pDC->LineTo(size.right + 1, size.top - 8);
361
362 pDC->MoveTo(size.left - 8, size.top - 1);
363 pDC->LineTo(size.left - 1, size.top - 1);
364 pDC->LineTo(size.left - 1, size.top - 8);
365
366 pDC->SelectObject(&graypen);
367 pDC->MoveTo(size.right + 8, size.bottom + 1);
368 pDC->LineTo(size.right + 1, size.bottom + 1);
369 pDC->LineTo(size.right + 1, size.bottom + 9);
370
371 pDC->MoveTo(size.left - 8, size.bottom + 1);
372 pDC->LineTo(size.left - 1, size.bottom + 1);
373 pDC->LineTo(size.left - 1, size.bottom + 8);
374
375 pDC->SelectObject(oldpen);
376 return;
377 }
378
379 ///////////////////////////////////////////////////////////////////////////////
OnScroll(UINT nScrollCode,UINT nPos,BOOL bDoScroll)380 BOOL target_frame::OnScroll(UINT nScrollCode, UINT nPos, BOOL bDoScroll)
381 {
382 // TODO: Add your specialized code here and/or call the base class
383 Invalidate();
384 return CScrollView::OnScroll(nScrollCode, nPos, bDoScroll);
385 }
386
387
388 ///////////////////////////////////////////////////////////////////////////////
OnSetFocus(CWnd * pOldWnd)389 void target_view::OnSetFocus(CWnd* pOldWnd)
390 {
391 CView::OnSetFocus(pOldWnd);
392
393 // TODO: Add your message handler code here
394 mpTargetFrame->SetFocus();
395 }
396
397 ///////////////////////////////////////////////////////////////////////////////
PreTranslateMessage(MSG * pMsg)398 BOOL target_view::PreTranslateMessage(MSG* pMsg)
399 {
400 // TODO: Add your specialized code here and/or call the base class
401 if (pMsg->message == WM_SYSKEYDOWN)
402 {
403 int nAltKey = GetKeyState(VK_MENU);
404
405 switch (pMsg->wParam)
406 {
407 case VK_UP:
408 case VK_LEFT:
409 if (nAltKey & KEY_STATE_DOWN)
410 {
411 //move focus to project view
412 project_view* view = GetProjectView();
413 if (view)
414 {
415 CMainFrame* frame = (CMainFrame*)GetParentFrame();
416 frame->SetActiveView(view);
417 return TRUE;
418 }
419 }
420 break;
421
422 case VK_DOWN:
423 case VK_RIGHT:
424 if (nAltKey & KEY_STATE_DOWN)
425 {
426 //Move focus to resource window
427 resource_view* view = GetResourceView();
428 if (view)
429 {
430 CMainFrame* frame = (CMainFrame*)GetParentFrame();
431 frame->SetActiveView(view);
432 return TRUE;
433 }
434 }
435 break;
436
437 case VK_MENU:
438 if ((nAltKey & KEY_STATE_DOWN) && mpTargetScreen->OnAltKeyDown())
439 {
440 return TRUE;
441 }
442 break;
443
444 default:
445 break;
446 }
447 }
448
449 return CView::PreTranslateMessage(pMsg);
450 }
451