1 // MainFrm.cpp : implementation of the CMainFrame class
2 //
3 
4 #include "studiox_includes.h"
5 #include "config_languages_dlg.h"
6 #include "splash_screen.h"
7 #include "clone_repo_dialog.h"
8 #include "MainFrm.h"
9 #include "app_runner.h"
10 #include "gx_win32_studio_display_driver.h"
11 
12 #ifdef _DEBUG
13 #define new DEBUG_NEW
14 #endif
15 
16 extern INI_INFO StudioXIni;
17 extern CString target_class_name;
18 extern CBrush WinBackBrush;
19 
20 #define MACRO_FILE_FLAG   _T("<macro head>")
21 #define MACRO_RECORD_SPEED  1
22 #define ID_SINGLEMACRO 1
23 #define ID_SUPERMACRO  2
24 
25 int          WM_SET_LAYOUT;
26 HHOOK        mouse_hook = 0;
27 HHOOK        keybd_hook = 0;
28 CWinThread   *macro_play_thread = NULL;
29 CFile        *recorder;
30 ULONG        start_time;
31 WPARAM       premsg = 0;
32 POINT        prept = { 0, 0 };
33 CString      macro_name;
34 int          macro_filetype;
35 int          pre_key_state = -1;//record previous key state, pressed or released
36 int          pre_vkey = -1;//record previous virtual key value
37 CArray<int>  proj_tree_state;
38 
39 enum main_frame_test_commands{
40     TEST_ZOOM_IN = 1,
41     TEST_TOOLBAR_CREATE,
42     TEST_TOOLBAR_OPEN,
43     TEST_TOOLBAR_SAVE,
44     TEST_TOOLBAR_CUT,
45     TEST_TOOLBAR_COPY,
46     TEST_TOOLBAR_PASTE,
47     TEST_TOOLBAR_ALIGN_LEFT,
48     TEST_TOOLBAR_ALIGN_RIGHT,
49     TEST_TOOLBAR_ALIGN_TOP,
50     TEST_TOOLBAR_ALIGN_BOTTOM,
51     TEST_TOOLBAR_VSPACE_EQUALLY,
52     TEST_TOOLBAR_HSPACE_EQUALLY,
53     TEST_TOOLBAR_EQUAL_WIDTH,
54     TEST_TOOLBAR_EQUAL_HEIGHT,
55     TEST_TOOLBAR_MOVE_TO_FRONT,
56     TEST_TOOLBAR_MOVE_TO_BACK,
57     TEST_TOOLBAR_SIZE_TO_FIT,
58     TEST_TOOLBAR_ZOOM_IN,
59     TEST_TOOLBAR_ZOOM_OUT,
60     TEST_TOOLBAR_MACRO_RECORD,
61     TEST_TOOLBAR_MACRO_PLAYBACK,
62     TEST_TOOLBAR_ABOUT,
63     TEST_UNDO,
64     TEST_CONFIGURE_LANGUAGES,
65     TEST_CONFIGURE_DISPLAYS,
66     TEST_CONFIGURE_THEMES,
67     TEST_CONFIGURE_SCREEN_FLOW,
68     TEST_GENERATE_ALL,
69     TEST_GENERATE_RESOURCES,
70     TEST_GET_MENU_STATUS,
71     TEST_GRID_SNAP_SETTING,
72     TEST_FIND_DIALOG,
73     TEST_LOCK_UNLOCK_WIDGET_POSITIONS,
74     TEST_RUN_APPLICATION,
75     TEST_IS_WAIT_DIALOG_RUNNING
76 };
77 
78 // CMainFrame
79 
80 IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
81 
82 BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
83     ON_WM_CREATE()
84     ON_WM_ERASEBKGND()
85     ON_WM_SIZE()
86     ON_WM_MOVING()
87     ON_WM_CLOSE()
88     ON_WM_SHOWWINDOW()
89     ON_COMMAND(ID_ADD_BUTTON, &CMainFrame::OnAddButton)
90     ON_COMMAND(ID_ADD_PROMPT, &CMainFrame::OnAddPrompt)
91     ON_COMMAND(ID_ADD_NUMERIC_PROMPT, &CMainFrame::OnAddNumericPrompt)
92     ON_COMMAND(ID_ADD_ICON, &CMainFrame::OnAddIcon)
93     ON_COMMAND(ID_ADD_TEXTBUTTON, &CMainFrame::OnAddTextButton)
94     ON_COMMAND(ID_ADD_MLT_BUTTON, &CMainFrame::OnAddMltButton)
95     ON_COMMAND(ID_ADD_CHECKBOX, &CMainFrame::OnAddCheckbox)
96     ON_COMMAND(ID_ADD_RADIO_BUTTON, &CMainFrame::OnAddRadioButton)
97     ON_COMMAND(ID_ADD_ICON_BUTTON, &CMainFrame::OnAddIconButton)
98     ON_COMMAND(ID_ADD_PIXMAP_BUTTON, &CMainFrame::OnAddPixelmapButton)
99     ON_COMMAND(ID_ADD_PIXMAP_PROMPT, &CMainFrame::OnAddPixelmapPrompt)
100     ON_COMMAND(ID_ADD_NUMERIC_PIXELMAP_PROMPT, &CMainFrame::OnAddNumericPixelmapPrompt)
101     ON_COMMAND(ID_ADD_SLIDER, &CMainFrame::OnAddSlider)
102     ON_COMMAND(ID_ADD_PIXELMAP_SLIDER, &CMainFrame::OnAddPixelmapSlider)
103     ON_COMMAND(ID_ADD_RADIAL_SLIDER, &CMainFrame::OnAddRadialSlider)
104     ON_COMMAND(ID_ADD_PROGRESS_BAR, &CMainFrame::OnAddProgressBar)
105     ON_COMMAND(ID_ADD_RADIAL_PROGRES_BAR, &CMainFrame::OnAddRadialProgressBar)
106     ON_COMMAND(ID_ADD_SPRITE, &CMainFrame::OnAddSprite)
107 
108     ON_COMMAND(ID_ADD_HSCROLL, &CMainFrame::OnAddHScroll)
109     ON_COMMAND(ID_ADD_VSCROLL, &CMainFrame::OnAddVScroll)
110 
111     ON_COMMAND(ID_ADD_STRING_SCROLL_WHEEL, &CMainFrame::OnAddStringScrollWheel)
112     ON_COMMAND(ID_ADD_NUMERIC_SCROLL_WHEEL, &CMainFrame::OnAddNumericScrollWheel)
113     ON_COMMAND(ID_ADD_GENERIC_SCROLL_WHEEL, &CMainFrame::OnAddGenericScrollWheel)
114 
115     ON_COMMAND(ID_ADD_WINDOW, &CMainFrame::OnAddWindow)
116     ON_COMMAND(ID_ADD_VERTICAL_LIST, &CMainFrame::OnAddVerticalList)
117     ON_COMMAND(ID_ADD_HORIZONTAL_LIST, &CMainFrame::OnAddHorizontalList)
118     ON_COMMAND(ID_ADD_DROP_DOWN_LIST, &CMainFrame::OnAddDropDownList)
119     ON_COMMAND(ID_INSERT_LINECHART, &CMainFrame::OnAddLineChart)
120 
121     ON_COMMAND(ID_ADD_TEXT_INPUT, &CMainFrame::OnAddTextInput)
122     ON_COMMAND(ID_ADD_MULTI_LINE_VIEW, &CMainFrame::OnAddMLTextView)
123     ON_COMMAND(ID_ADD_MULTI_LINE_INPUT, &CMainFrame::OnAddMLTextInput)
124     ON_COMMAND(ID_ADD_RICH_TEXT_VIEW, &CMainFrame::OnAddRichTextView)
125 
126     ON_COMMAND(ID_ADD_CIRCULAR_GAUGE, &CMainFrame::OnAddCircularGauge)
127     ON_COMMAND_RANGE(ID_ADD_TEMPLATE_BASE, ID_ADD_TEMPLATE_BASE + MAX_TEMPLATES, &CMainFrame::OnAddTemplate)
128 
129     ON_COMMAND(ID_ADD_MENU, &CMainFrame::OnAddMenu)
130     ON_COMMAND(ID_ADD_ACCORDION_MENU, &CMainFrame::OnAddAccordionMenu)
131     ON_COMMAND(ID_ADD_TREE_VIEW, &CMainFrame::OnAddTreeView)
132 
133     ON_COMMAND(ID_WIDGET_DELETE, &CMainFrame::OnDeleteWidget)
134     ON_COMMAND(ID_WIDGET_CUT, &CMainFrame::OnCutWidget)
135     ON_COMMAND(ID_EDIT_CUT, &CMainFrame::OnCutWidget)
136     ON_COMMAND(ID_WIDGET_COPY, &CMainFrame::OnCopyWidget)
137     ON_COMMAND(ID_EDIT_COPY, &CMainFrame::OnCopyWidget)
138     ON_COMMAND(ID_WIDGET_PASTE, &CMainFrame::OnPasteWidget)
139     ON_COMMAND(ID_EDIT_PASTE, &CMainFrame::OnPasteWidget)
140     ON_COMMAND(ID_INSERT_FOLDER, &CMainFrame::OnInsertFolder)
141 
142     ON_COMMAND(ID_ALIGN_LEFT, &CMainFrame::OnAlignLeft)
143     ON_COMMAND(ID_ALIGN_TOP, &CMainFrame::OnAlignTop)
144     ON_COMMAND(ID_ALIGN_RIGHT, &CMainFrame::OnAlignRight)
145     ON_COMMAND(ID_ALIGN_BOTTOM, &CMainFrame::OnAlignBottom)
146     ON_COMMAND(ID_HSPACE_EQUALLY, &CMainFrame::OnHSpaceEqually)
147     ON_COMMAND(ID_VSPACE_EQUALLY, &CMainFrame::OnVSpaceEqually)
148     ON_COMMAND(ID_EQUAL_WIDTH, &CMainFrame::OnEqualWidth)
149     ON_COMMAND(ID_EQUAL_HEIGHT, &CMainFrame::OnEqualHeight)
150     ON_COMMAND(ID_MOVE_TO_FRONT, &CMainFrame::OnMoveToFront)
151     ON_COMMAND(ID_MOVE_TO_BACK, &CMainFrame::OnMoveToBack)
152     ON_COMMAND(ID_SIZE_TO_FIT, &CMainFrame::OnSizeToFit)
153     ON_COMMAND(ID_ZOOM_IN, &CMainFrame::OnZoom)
154     ON_COMMAND(ID_ZOOM_OUT, &CMainFrame::OnZoom)
155     ON_COMMAND(ID_ZOOM_100, &CMainFrame::OnZoom)
156     ON_COMMAND(ID_ZOOM_200, &CMainFrame::OnZoom)
157     ON_COMMAND(ID_ZOOM_300, &CMainFrame::OnZoom)
158     ON_COMMAND(ID_ZOOM_400, &CMainFrame::OnZoom)
159     ON_COMMAND(ID_TARGETVIEW_GRID_SNAP, &CMainFrame::OnGridSetting)
160 
161     ON_COMMAND(ID_CONFIGURE_DISPLAYS, &CMainFrame::OnConfigureDisplays)
162     ON_COMMAND(ID_CONFIGURE_LANGUAGES, &CMainFrame::OnConfigureLanguages)
163     ON_COMMAND(ID_CONFIGURE_THEMES, &CMainFrame::OnConfigureThemes)
164     ON_COMMAND(ID_CONFIGURE_SCREENFLOW, &CMainFrame::OnConfigureScreenFlow)
165     ON_COMMAND(ID_CONFIGURE_GUIX_REPOSITORY, &CMainFrame::OnConfigureGuixRepository)
166 
167     ON_COMMAND_RANGE(ID_FILE_MRU_FILE2, ID_FILE_MRU_FILE6, &CMainFrame::OnOpenHistoryProject)
168     ON_COMMAND(ID_GENERATE_ALL, &CMainFrame::OnGenerateAll)
169     ON_COMMAND(ID_GENERATE_RESOURCES, &CMainFrame::OnGenResources)
170     ON_COMMAND(ID_GENERATE_APPLICATION, &CMainFrame::OnGenApplication)
171     ON_COMMAND(ID_EDIT_UNDO, &CMainFrame::OnUndo)
172 
173     ON_COMMAND(ID_RECORDMACRO, &CMainFrame::OnRecordmacro)
174     ON_COMMAND(ID_PLAYBACKMACRO, &CMainFrame::OnPlaybackmacro)
175     ON_COMMAND(ID_ENDMACRO, &CMainFrame::OnEndmacro)
176     ON_COMMAND(ID_STOPMACRO, &CMainFrame::OnStopMacro)
177 
178     ON_COMMAND(ID_RUN_APPLICATION, &CMainFrame::OnRunApplication)
179     ON_COMMAND(ID_RUN_STRING_FIT_CHECK, &CMainFrame::OnRunStringFitCheck)
180     ON_COMMAND(ID_LOCK_WIDGET_POSITIONS, &CMainFrame::OnLockUlockWidgetPositions)
181 
182     ON_MESSAGE(STUDIO_TEST, OnTestMessage)
183     ON_REGISTERED_MESSAGE(WM_SET_LAYOUT, &CMainFrame::OnSetLayout)
184 
185     ON_WM_INITMENUPOPUP()
186         ON_WM_SETTINGCHANGE()
187         END_MESSAGE_MAP()
188 
189 #define ID_COMPANY 1000
190 #define ID_SEATS   1001
191 static UINT indicators[] =
192 {
193     ID_SEPARATOR,           // status line indicator
194     ID_INDICATOR_CAPS,
195     ID_INDICATOR_NUM,
196     ID_INDICATOR_SCRL
197 };
198 
BEGIN_MESSAGE_MAP(CustomToolBar,CToolBar)199 BEGIN_MESSAGE_MAP(CustomToolBar, CToolBar)
200     //ON_WM_CREATE()
201     ON_WM_ERASEBKGND()
202     //ON_WM_PAINT()
203 END_MESSAGE_MAP()
204 
205 CustomToolBar::CustomToolBar()
206 {
207 }
208 
209 
210 ///////////////////////////////////////////////////////////////////////////////
OnEraseBkgnd(CDC * pDC)211 BOOL CustomToolBar::OnEraseBkgnd(CDC* pDC)
212 {
213     CRect boxrect;
214     CDC dcMemory;
215     CBitmap fillmap;
216     fillmap.LoadBitmap(IDB_TOOLBAR_FILL);
217     BITMAP bm;
218 
219     // go through hoops to get bitmap width:
220     fillmap.GetObject(sizeof(BITMAP), &bm);
221     int width = bm.bmWidth;
222     int height = bm.bmHeight;
223 
224     dcMemory.CreateCompatibleDC(pDC);
225     dcMemory.SelectObject(&fillmap);
226 
227     pDC->GetClipBox(&boxrect);     // Erase the area needed
228     int xpos = boxrect.left;
229 
230     while(xpos < boxrect.right)
231     {
232         pDC->BitBlt(xpos, boxrect.top, width, height, &dcMemory, 0, 0, SRCCOPY);
233         xpos += width;
234     }
235     return TRUE;
236 }
237 #if 0
238 void CustomToolBar::OnPaint()
239 {
240     //CDC *dc = GetDC();
241     //CWnd::OnPaint();
242 
243 //    PaintHeader(dc, size);
244     //ReleaseDC(dc);
245    PAINTSTRUCT ps;
246    CDC* pDC = BeginPaint(&ps);
247 
248    //pDC->Rectangle(CRect(0, 0, 100, 100));
249     CToolBar::OnPaint();
250    EndPaint(&ps);
251 }
252 #endif
253 
254 #if 1
255 
studiox_splitter()256 studiox_splitter::studiox_splitter()
257 {
258     m_proj_width = m_res_width = 200;
259 }
260 
FixColumnWidths()261 void studiox_splitter::FixColumnWidths()
262 {
263     CRect rect;
264     GetWindowRect(rect);
265     int target_width = 1;
266     int total_width = rect.right - rect.left - 18;
267 //    int width_sum;
268 
269     //if (m_pColInfo[0].nIdealSize == 0)
270     //{
271     //    m_pColInfo[0].nIdealSize = 200;
272     //    m_pColInfo[1].nIdealSize = total_width - 400;
273     //}
274 
275     if (m_pColInfo[0].nIdealSize < 200)
276     {
277         m_pColInfo[0].nIdealSize = 200;
278     }
279 
280     if(m_pColInfo[1].nIdealSize == 0)
281     {
282         m_pColInfo[1].nIdealSize = total_width - (m_pColInfo[0].nIdealSize + m_pColInfo[2].nIdealSize);
283     }
284 
285     m_res_width = total_width - (m_pColInfo[0].nIdealSize + m_pColInfo[1].nIdealSize);
286 
287     if (m_res_width < 200)
288     {
289         m_res_width = 200;
290         target_width = total_width - m_pColInfo[0].nIdealSize - m_res_width;
291 
292         if (target_width <= 0)
293         {
294             target_width = 1;
295         }
296         m_pColInfo[1].nIdealSize = target_width;
297     }
298     m_pColInfo[2].nIdealSize = m_res_width;
299 }
300 
RecalcLayout()301 void studiox_splitter::RecalcLayout()
302 {
303     FixColumnWidths();
304     CSplitterWnd::RecalcLayout();
305     //m_proj_width = m_pColInfo[0].nCurSize;
306     //m_res_width = m_pColInfo[2].nCurSize;
307 }
308 
309 #endif
310 
311 // CMainFrame construction/destruction
312 
CMainFrame()313 CMainFrame::CMainFrame()
314 {
315     // TODO: add member initialization code here
316     m_splitter_created = FALSE;
317     mpTargetView = NULL;
318     mpResourceView = NULL;
319     mpProjectView = NULL;
320     mpCmdInfo = new CCommandInfo();
321     m_bAutoMenuEnable = FALSE;
322 
323     widget_factory::InitServiceProviders();
324     mpUndoManager = new undo_manager();
325 
326     target_class_name = AfxRegisterWndClass(
327       CS_VREDRAW | CS_HREDRAW,
328       ::LoadCursor(NULL, IDC_ARROW),
329       (HBRUSH) WinBackBrush,
330       ::LoadIcon(NULL, IDI_APPLICATION));
331 
332     mpBaseMenu = new CMenu;
333     mpBaseMenu->CreateMenu();
334 
335     mpRecentMenu = new CMenu;
336     mpRecentMenu->CreateMenu();
337 
338     m_text_scaler = GetTextScaler();
339 
340     // Create accessibility property service
341     CreateAccPropService();
342 }
343 
~CMainFrame()344 CMainFrame::~CMainFrame()
345 {
346     widget_factory::DeleteServiceProviders();
347     delete mpUndoManager;
348     delete mpCmdInfo;
349     delete mpBaseMenu;
350     delete mpRecentMenu;
351 
352     // Release accessibility property service
353     ReleaseAccPropService();
354 }
355 
OnAddButton()356 void CMainFrame::OnAddButton()
357 {
358     mpTargetView->GetTargetScreen()->OnAddWidget(GX_TYPE_BUTTON);
359 }
OnAddTextButton()360 void CMainFrame::OnAddTextButton()
361 {
362     mpTargetView->GetTargetScreen()->OnAddWidget(GX_TYPE_TEXT_BUTTON);
363 }
OnAddMltButton()364 void CMainFrame::OnAddMltButton()
365 {
366     if (project_lib_version() >= 50201)
367     {
368         mpTargetView->GetTargetScreen()->OnAddWidget(GX_TYPE_MULTI_LINE_TEXT_BUTTON);
369     }
370     else
371     {
372         ErrorMsg("This widget is not supported by your GUIX library release");
373     }
374 }
375 
OnAddCheckbox()376 void CMainFrame::OnAddCheckbox()
377 {
378     mpTargetView->GetTargetScreen()->OnAddWidget(GX_TYPE_CHECKBOX);
379 }
OnAddRadioButton()380 void CMainFrame::OnAddRadioButton()
381 {
382     mpTargetView->GetTargetScreen()->OnAddWidget(GX_TYPE_RADIO_BUTTON);
383 }
384 
OnAddIconButton()385 void CMainFrame::OnAddIconButton()
386 {
387     mpTargetView->GetTargetScreen()->OnAddWidget(GX_TYPE_ICON_BUTTON);
388 }
389 
OnAddPixelmapButton()390 void CMainFrame::OnAddPixelmapButton()
391 {
392     mpTargetView->GetTargetScreen()->OnAddWidget(GX_TYPE_PIXELMAP_BUTTON);
393 }
394 
395 
OnAddPrompt()396 void CMainFrame::OnAddPrompt()
397 {
398     mpTargetView->GetTargetScreen()->OnAddWidget(GX_TYPE_PROMPT);
399 }
400 
401 
OnAddNumericPrompt()402 void CMainFrame::OnAddNumericPrompt()
403 {
404     mpTargetView->GetTargetScreen()->OnAddWidget(GX_TYPE_NUMERIC_PROMPT);
405 }
406 
OnAddPixelmapPrompt()407 void CMainFrame::OnAddPixelmapPrompt()
408 {
409     mpTargetView->GetTargetScreen()->OnAddWidget(GX_TYPE_PIXELMAP_PROMPT);
410 }
411 
OnAddNumericPixelmapPrompt()412 void CMainFrame::OnAddNumericPixelmapPrompt()
413 {
414     mpTargetView->GetTargetScreen()->OnAddWidget(GX_TYPE_NUMERIC_PIXELMAP_PROMPT);
415 }
416 
OnAddIcon()417 void CMainFrame::OnAddIcon()
418 {
419     mpTargetView->GetTargetScreen()->OnAddWidget(GX_TYPE_ICON);
420 }
421 
422 
OnAddSlider()423 void CMainFrame::OnAddSlider()
424 {
425     mpTargetView->GetTargetScreen()->OnAddWidget(GX_TYPE_SLIDER);
426 }
OnAddPixelmapSlider()427 void CMainFrame::OnAddPixelmapSlider()
428 {
429     mpTargetView->GetTargetScreen()->OnAddWidget(GX_TYPE_PIXELMAP_SLIDER);
430 }
431 
OnAddRadialSlider()432 void CMainFrame::OnAddRadialSlider()
433 {
434     mpTargetView->GetTargetScreen()->OnAddWidget(GX_TYPE_RADIAL_SLIDER);
435 }
436 
OnAddProgressBar()437 void CMainFrame::OnAddProgressBar()
438 {
439     mpTargetView->GetTargetScreen()->OnAddWidget(GX_TYPE_PROGRESS_BAR);
440 }
441 
OnAddRadialProgressBar()442 void CMainFrame::OnAddRadialProgressBar()
443 {
444     mpTargetView->GetTargetScreen()->OnAddWidget(GX_TYPE_RADIAL_PROGRESS_BAR);
445 }
446 
OnAddSprite()447 void CMainFrame::OnAddSprite()
448 {
449     mpTargetView->GetTargetScreen()->OnAddWidget(GX_TYPE_SPRITE);
450 }
451 
OnAddHScroll()452 void CMainFrame::OnAddHScroll()
453 {
454     mpTargetView->GetTargetScreen()->OnAddWidget(GX_TYPE_HORIZONTAL_SCROLL);
455 }
456 
OnAddVScroll()457 void CMainFrame::OnAddVScroll()
458 {
459     mpTargetView->GetTargetScreen()->OnAddWidget(GX_TYPE_VERTICAL_SCROLL);
460 }
461 
462 
OnAddStringScrollWheel()463 void CMainFrame::OnAddStringScrollWheel()
464 {
465     mpTargetView->GetTargetScreen()->OnAddWidget(GX_TYPE_STRING_SCROLL_WHEEL);
466 }
467 
OnAddNumericScrollWheel()468 void CMainFrame::OnAddNumericScrollWheel()
469 {
470     mpTargetView->GetTargetScreen()->OnAddWidget(GX_TYPE_NUMERIC_SCROLL_WHEEL);
471 }
472 
OnAddGenericScrollWheel()473 void CMainFrame::OnAddGenericScrollWheel()
474 {
475     mpTargetView->GetTargetScreen()->OnAddWidget(GX_TYPE_GENERIC_SCROLL_WHEEL);
476 }
477 
478 
OnAddWindow()479 void CMainFrame::OnAddWindow()
480 {
481     mpTargetView->GetTargetScreen()->OnAddWidget(GX_TYPE_WINDOW);
482 }
OnAddVerticalList()483 void CMainFrame::OnAddVerticalList()
484 {
485     mpTargetView->GetTargetScreen()->OnAddWidget(GX_TYPE_VERTICAL_LIST);
486 }
OnAddHorizontalList()487 void CMainFrame::OnAddHorizontalList()
488 {
489     mpTargetView->GetTargetScreen()->OnAddWidget(GX_TYPE_HORIZONTAL_LIST);
490 }
OnAddDropDownList()491 void CMainFrame::OnAddDropDownList()
492 {
493     mpTargetView->GetTargetScreen()->OnAddWidget(GX_TYPE_DROP_LIST);
494 }
OnAddLineChart()495 void CMainFrame::OnAddLineChart()
496 {
497     mpTargetView->GetTargetScreen()->OnAddWidget(GX_TYPE_LINE_CHART);
498 }
499 
OnAddTextInput()500 void CMainFrame::OnAddTextInput()
501 {
502     mpTargetView->GetTargetScreen()->OnAddWidget(GX_TYPE_SINGLE_LINE_TEXT_INPUT);
503 }
OnAddMLTextView()504 void CMainFrame::OnAddMLTextView()
505 {
506     mpTargetView->GetTargetScreen()->OnAddWidget(GX_TYPE_MULTI_LINE_TEXT_VIEW);
507 }
OnAddMLTextInput()508 void CMainFrame::OnAddMLTextInput()
509 {
510     mpTargetView->GetTargetScreen()->OnAddWidget(GX_TYPE_MULTI_LINE_TEXT_INPUT);
511 }
512 
OnAddRichTextView()513 void CMainFrame::OnAddRichTextView()
514 {
515     mpTargetView->GetTargetScreen()->OnAddWidget(GX_TYPE_RICH_TEXT_VIEW);
516 }
517 
OnAddCircularGauge()518 void CMainFrame::OnAddCircularGauge()
519 {
520     mpTargetView->GetTargetScreen()->OnAddWidget(GX_TYPE_CIRCULAR_GAUGE);
521 }
522 
OnAddTemplate(UINT nID)523 void CMainFrame::OnAddTemplate(UINT nID)
524 {
525     widget_info *info = GetProjectView()->GetTemplateInfo(nID - ID_ADD_TEMPLATE_BASE);
526 
527     if (info)
528     {
529         mpTargetView->GetTargetScreen()->OnAddTemplate(info);
530     }
531 }
532 
OnAddMenu()533 void CMainFrame::OnAddMenu()
534 {
535     mpTargetView->GetTargetScreen()->OnAddWidget(GX_TYPE_MENU);
536 }
537 
OnAddAccordionMenu()538 void CMainFrame::OnAddAccordionMenu()
539 {
540     mpTargetView->GetTargetScreen()->OnAddWidget(GX_TYPE_ACCORDION_MENU);
541 }
542 
OnAddTreeView()543 void CMainFrame::OnAddTreeView()
544 {
545     mpTargetView->GetTargetScreen()->OnAddWidget(GX_TYPE_TREE_VIEW);
546 }
547 
OnCutWidget()548 void CMainFrame::OnCutWidget()
549 {
550     GetProjectView()->OnCutWidget();
551 }
OnCopyWidget()552 void CMainFrame::OnCopyWidget()
553 {
554     GetProjectView()->OnCopyWidget();
555 }
OnPasteWidget()556 void CMainFrame::OnPasteWidget()
557 {
558     GetProjectView()->OnPasteWidget();
559 }
OnDeleteWidget()560 void CMainFrame::OnDeleteWidget()
561 {
562     GetProjectView()->OnDeleteWidget();
563 }
OnInsertFolder()564 void CMainFrame::OnInsertFolder()
565 {
566     GetProjectView()->OnInsertFolder();
567 }
568 
OnAlignLeft()569 void CMainFrame::OnAlignLeft()
570 {
571     mpTargetView->GetTargetScreen()->OnAlignLeft();
572 }
573 
OnAlignTop()574 void CMainFrame::OnAlignTop()
575 {
576     mpTargetView->GetTargetScreen()->OnAlignTop();
577 }
578 
OnAlignRight()579 void CMainFrame::OnAlignRight()
580 {
581     mpTargetView->GetTargetScreen()->OnAlignRight();
582 }
583 
OnAlignBottom()584 void CMainFrame::OnAlignBottom()
585 {
586     mpTargetView->GetTargetScreen()->OnAlignBottom();
587 
588 }
589 
OnHSpaceEqually()590 void CMainFrame::OnHSpaceEqually()
591 {
592     mpTargetView->GetTargetScreen()->OnHSpaceEqually();
593 }
594 
OnVSpaceEqually()595 void CMainFrame::OnVSpaceEqually()
596 {
597     mpTargetView->GetTargetScreen()->OnVSpaceEqually();
598 }
599 
OnEqualWidth()600 void CMainFrame::OnEqualWidth()
601 {
602     mpTargetView->GetTargetScreen()->OnMakeEqualWidth();
603 }
604 
OnEqualHeight()605 void CMainFrame::OnEqualHeight()
606 {
607     mpTargetView->GetTargetScreen()->OnMakeEqualHeight();
608 }
609 
OnMoveToFront()610 void CMainFrame::OnMoveToFront()
611 {
612     GetProjectView()->MoveSelectedToFront();
613 }
614 
OnMoveToBack()615 void CMainFrame::OnMoveToBack()
616 {
617     GetProjectView()->MoveSelectedToBack();
618 }
619 
OnSizeToFit()620 void CMainFrame::OnSizeToFit()
621 {
622     mpTargetView->GetTargetScreen()->OnAutosize();
623 }
624 
OnZoom()625 void CMainFrame::OnZoom()
626 {
627     int scale = 100;
628 
629     UINT nID = (UINT)LOWORD(GetCurrentMessage()->wParam);
630 
631     switch (nID)
632     {
633     case ID_ZOOM_IN:
634         scale = mpTargetView->GetTargetScreen()->GetZoomScale();
635         scale += 100;
636 
637         if (scale > 400)
638         {
639             return;
640         }
641         break;
642     case ID_ZOOM_OUT:
643         scale = mpTargetView->GetTargetScreen()->GetZoomScale();
644         scale -= 100;
645 
646         if (scale <= 0)
647         {
648             return;
649         }
650         break;
651     case ID_ZOOM_100:
652         scale = 100;
653         break;
654     case ID_ZOOM_200:
655         scale = 200;
656         break;
657     case ID_ZOOM_300:
658         scale = 300;
659         break;
660     case ID_ZOOM_400:
661         scale = 400;
662         break;
663     }
664 
665     mpTargetView->GetTargetScreen()->ZoomIn(scale);
666 }
667 
OnGridSetting()668 void CMainFrame::OnGridSetting()
669 {
670     grid_setting_dlg dlg(this);
671 
672     dlg.DoModal();
673 }
674 
OnConfigureDisplays()675 void CMainFrame::OnConfigureDisplays()
676 {
677     GetProjectView()->OnConfigureDisplays();
678 }
679 
OnConfigureLanguages()680 void CMainFrame::OnConfigureLanguages()
681 {
682     if (GetOpenProject())
683     {
684         config_languages_dlg dlg;
685         dlg.DoModal();
686     }
687 }
688 
OnConfigureThemes()689 void CMainFrame::OnConfigureThemes()
690 {
691     if (GetOpenProject())
692     {
693         GetProjectView()->OnConfigureThemes();
694     }
695 }
696 
OnConfigureGuixRepository()697 void CMainFrame::OnConfigureGuixRepository()
698 {
699     clone_repo_dialog* dlg = new clone_repo_dialog(this);
700     dlg->DoModal();
701     delete(dlg);
702 
703     if (GetOpenProject() == NULL)
704     {
705         GetTargetView()->DisplayRecentProjects();
706     }
707 }
708 
OnUndo()709 void CMainFrame::OnUndo()
710 {
711     if (mpUndoManager->CountEntries() > 0)
712     {
713         mpUndoManager->Undo();
714     }
715     else
716     {
717         ErrorMsg("Nothing to Undo");
718     }
719 }
720 
OnOpenHistoryProject(UINT nID)721 void CMainFrame::OnOpenHistoryProject(UINT nID)
722 {
723     if (GetProjectView())
724     {
725         GetProjectView()->OpenHistoryProject(nID - ID_FILE_MRU_FILE2);
726     }
727 }
728 
OnGenerateAll()729 void CMainFrame::OnGenerateAll()
730 {
731     resource_export_dlg dlg(AfxGetMainWnd());
732     studiox_project *project = GetOpenProject();
733 
734     if (project != GX_NULL)
735     {
736         if (dlg.DoModal() == IDOK)
737         {
738             GetProjectView()->OnGenerateAll();
739         }
740     }
741 
742 }
743 
OnGenResources()744 void CMainFrame::OnGenResources()
745 {
746     resource_export_dlg dlg(AfxGetMainWnd());
747     studiox_project *project = GetOpenProject();
748 
749     if (project != GX_NULL)
750     {
751         if (dlg.DoModal() == IDOK)
752         {
753             if (project->mHeader.gen_binary)
754             {
755                 GetProjectView()->OnGenBinary();
756             }
757             else
758             {
759                 GetProjectView()->OnGenResources();
760             }
761         }
762     }
763 }
764 
OnGenApplication()765 void CMainFrame::OnGenApplication()
766 {
767     if (GetOpenProject())
768     {
769         GetProjectView()->OnGenApplication();
770     }
771 }
772 
OnConfigureScreenFlow()773 void CMainFrame::OnConfigureScreenFlow()
774 {
775     //transition_dialog dlg(GetOpenProject()->mDisplays[0].first_widget, this);
776 
777     studiox_project *project = GetOpenProject();
778 
779     if (!project)
780     {
781         return;
782     }
783 
784     if (project_lib_version() < 50400)
785     {
786         Notify("Not supported. Please update GUIX Library to at least 5.4.0.");
787         return;
788     }
789 
790     //dlg.DoModal();
791     if (GetProjectView())
792     {
793 
794         screen_flow_edit_dlg dlg(GetProjectView()->GetActiveDisplay(), this);
795         if (dlg.DoModal() == IDOK)
796         {
797             project->SetModified();
798         }
799     }
800 }
801 
OnRunApplication()802 void CMainFrame::OnRunApplication()
803 {
804     project_view *project_view = GetProjectView();
805 
806     if (project_view)
807     {
808         project_view->RunApplication();
809     }
810 }
811 
812 ///////////////////////////////////////////////////////////////////////////////
TestOneWidgetStringsFit(int display_index,widget_info * info)813 void CMainFrame::TestOneWidgetStringsFit(int display_index, widget_info* info)
814 {
815     project_view* pview = GetProjectView();
816 
817     if (!pview)
818     {
819         return;
820     }
821 
822     studiox_project *project = GetOpenProject();
823 
824     GX_RECTANGLE newsize = widget_service_provider::CalculateTextFitSize(info, display_index);
825 
826     if (newsize.gx_rectangle_right > info->size.gx_rectangle_right ||
827         newsize.gx_rectangle_bottom > info->size.gx_rectangle_bottom)
828     {
829         if (m_strings_fit_msg.IsEmpty())
830         {
831             m_strings_fit_msg.Append(_T("String(s) in following widgets do not fit within the widget:\n"));
832         }
833 
834         m_strings_fit_msg.Append(_T("    "));
835 
836         if (project->mHeader.num_displays > 1)
837         {
838             m_strings_fit_msg.Append(project->mDisplays[display_index].name);
839             m_strings_fit_msg.Append(_T("."));
840         }
841 
842         widget_info* screen = pview->FindTopLevelWidget(info);
843         if (screen && (screen != info))
844         {
845             m_strings_fit_msg.Append(screen->app_name);
846             m_strings_fit_msg.Append(_T("."));
847         }
848         m_strings_fit_msg.Append(info->app_name);
849         m_strings_fit_msg.Append(_T("\n"));
850     }
851 }
852 
853 ///////////////////////////////////////////////////////////////////////////////
TestStringsFit(int display_index,widget_info * info)854 void CMainFrame::TestStringsFit(int display_index, widget_info* info)
855 {
856     widget_info* child;
857 
858     while (info)
859     {
860         switch (info->basetype)
861         {
862         case GX_TYPE_TEXT_BUTTON:
863         case GX_TYPE_RADIO_BUTTON:
864         case GX_TYPE_CHECKBOX:
865         case GX_TYPE_MULTI_LINE_TEXT_BUTTON:
866         case GX_TYPE_PROMPT:
867         case GX_TYPE_NUMERIC_PROMPT:
868         case GX_TYPE_PIXELMAP_PROMPT:
869         case GX_TYPE_NUMERIC_PIXELMAP_PROMPT:
870         case GX_TYPE_STRING_SCROLL_WHEEL:
871         case GX_TYPE_MENU:
872             TestOneWidgetStringsFit(display_index, info);
873             break;
874         }
875 
876         child = info->GetChildWidgetInfo();
877 
878         if (child)
879         {
880             TestStringsFit(display_index, child);
881         }
882         info = info->GetNextWidgetInfo();
883     }
884 }
885 
886 ///////////////////////////////////////////////////////////////////////////////
OnRunStringFitCheck()887 void CMainFrame::OnRunStringFitCheck()
888 {
889     studiox_project *project = GetOpenProject();
890     m_strings_fit_msg.Empty();
891 
892     display_info *display;
893     folder_info *folder;
894     widget_info *info;
895 
896     for (int index = 0; index < project->mHeader.num_displays; index++)
897     {
898         display = &project->mDisplays[index];
899         folder = NULL;
900         info = NULL;
901 
902         if (display)
903         {
904             folder = display->GetFirstChildFolder();
905         }
906 
907         while (folder)
908         {
909             info = folder->GetFirstChildWidget();
910 
911             if (info)
912             {
913                 TestStringsFit(index, info);
914             }
915 
916             folder = folder->GetNextFolder();
917         }
918     }
919 
920     if (m_strings_fit_msg.IsEmpty())
921     {
922         m_strings_fit_msg = "String fit check passed!";
923     }
924 
925     Notify(CT2A(m_strings_fit_msg.GetBuffer()));
926 }
927 
OnLockUlockWidgetPositions()928 void CMainFrame::OnLockUlockWidgetPositions()
929 {
930     studiox_project *project = GetOpenProject();
931 
932     if (project)
933     {
934         if (project->IsWidgetPositionLocked())
935         {
936             project->LockUlockWidgetPositions(FALSE);
937         }
938         else
939         {
940             project->LockUlockWidgetPositions(TRUE);
941         }
942     }
943 }
944 
OnClose()945 void CMainFrame::OnClose()
946 {
947     CRect rect;
948 
949     CCommandInfo *pCmdInfo = GetCmdInfo();
950 
951     if(pCmdInfo->IsNoGui())
952     {
953         if (GetProjectView())
954         {
955             GetProjectView()->CloseProject(FALSE, FALSE);
956         }
957     }
958     else
959     {
960         GetWindowRect(rect);
961         StudioXIni.xpos = rect.left;
962         StudioXIni.ypos = rect.top;
963 
964         int cxMin;
965 
966         m_splitter.GetColumnInfo(0, StudioXIni.proj_view_width, cxMin);
967         m_splitter.GetColumnInfo(2, StudioXIni.resource_view_width, cxMin);
968         m_splitter2.GetRowInfo(0, StudioXIni.proj_view_height, cxMin);
969 
970         WriteIniInfo();
971 
972         if (GetProjectView())
973         {
974             GetProjectView()->CloseProject(FALSE);
975         }
976 
977         if (recorder)
978         {
979             OnEndmacro();
980         }
981     }
982 
983     CFrameWnd::OnClose();
984 }
985 
OnCreateClient(LPCREATESTRUCT lpcs,CCreateContext * pContext)986 BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext *pContext)
987 {
988     m_splitter.CreateStatic(this, 1, 3);
989     m_splitter.CreateView(0, 1, RUNTIME_CLASS(target_view), CSize(0, 0), pContext);
990     m_splitter.CreateView(0, 2, RUNTIME_CLASS(right_panel_frame), CSize(200, 200), pContext);
991 
992     m_splitter.SetColumnInfo(0, StudioXIni.proj_view_width, 0);
993     m_splitter.SetColumnInfo(1, 0, 0);
994     m_splitter.SetColumnInfo(2, StudioXIni.resource_view_width, 0);
995 
996     // add the second splitter pane which is nested in the first splitter
997     if (!m_splitter2.CreateStatic(
998         &m_splitter, // parent window is the first splitter
999         2, 1, //the new splitter is 2 rows, 1 column
1000         WS_CHILD | WS_VISIBLE | WS_BORDER, // style
1001         m_splitter.IdFromRowCol(0, 0) // new splitter is in the first row, first column of first splitter
1002         ))
1003     {
1004         TRACE0("Failed to created nested splitter\n");
1005         return FALSE;
1006     }
1007 
1008     if (!m_splitter2.CreateView(0, 0, RUNTIME_CLASS(left_top_panel_frame), CSize(0, 0), pContext))
1009     {
1010         TRACE0("Failed to create project view pane\n");
1011         return FALSE;
1012     }
1013 
1014     if (!m_splitter2.CreateView(1, 0, RUNTIME_CLASS(left_bottom_panel_frame), CSize(0, 0), pContext))
1015     {
1016         TRACE0("Failed to create properties view pane\n");
1017         return FALSE;
1018     }
1019 
1020     m_splitter2.SetRowInfo(0, StudioXIni.proj_view_height, 0);
1021 
1022     m_splitter_created = TRUE;
1023     return TRUE;
1024 }
1025 
OnMoving(UINT nSide,LPRECT lpRect)1026 void CMainFrame::OnMoving(UINT nSide, LPRECT lpRect)
1027 {
1028     CFrameWnd::OnMoving(nSide, lpRect);
1029     if (mpTargetView)
1030     {
1031         CDialog *dlg = mpTargetView->GetRecentDialog();
1032         if (dlg)
1033         {
1034             dlg->CenterWindow();
1035         }
1036     }
1037 }
1038 
OnSize(UINT ntype,int cx,int cy)1039 void CMainFrame::OnSize(UINT ntype, int cx, int cy)
1040 {
1041     CFrameWnd::OnSize(ntype, cx, cy);
1042 
1043     CRect rect;
1044     GetWindowRect(rect);
1045 
1046     StudioXIni.width = rect.Width();
1047     StudioXIni.height = rect.Height();
1048 
1049     if (mpTargetView)
1050     {
1051         CDialog *dlg = mpTargetView->GetRecentDialog();
1052         if (dlg)
1053         {
1054             dlg->CenterWindow();
1055         }
1056     }
1057     if (m_splitter_created)
1058     {
1059         m_splitter.FixColumnWidths();
1060     }
1061 }
1062 
OnCreate(LPCREATESTRUCT lpCreateStruct)1063 int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
1064 {
1065     if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
1066         return -1;
1067 
1068     if (!m_wndToolBar.CreateEx(this, TBSTYLE_LIST, WS_CHILD | WS_VISIBLE | CBRS_TOP
1069         | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
1070         !m_wndToolBar.LoadToolBar(IDR_TOOLBAR_1BIT))
1071     {
1072         TRACE0("Failed to create toolbar\n");
1073         return -1;      // fail to create
1074     }
1075 
1076     SetControlAccessibleName(m_wndToolBar.GetSafeHwnd(), _T("mainframe_toolbar"));
1077 
1078     // TODO: Delete these three lines if you don't want the toolbar to be dockable
1079     HBITMAP hBitmap = (HBITMAP) ::LoadImage(AfxGetInstanceHandle(),
1080     MAKEINTRESOURCE(IDR_MAINFRAME), IMAGE_BITMAP,
1081     0,0, LR_CREATEDIBSECTION | LR_LOADMAP3DCOLORS);
1082 
1083     CBitmap bm;
1084     bm.Attach(hBitmap);
1085 
1086     m_imagelist.Create(30, 22, ILC_COLOR32, 4, 4);
1087     m_imagelist.Add(&bm, (CBitmap*) NULL);
1088 
1089     m_wndToolBar.GetToolBarCtrl().SetImageList(&m_imagelist);
1090     m_imagelist.Detach();
1091     bm.Detach();
1092 
1093     HICON hIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_MAINFRAME));
1094     SetIcon(hIcon, TRUE);
1095 
1096     hIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_SMALL_ICON));
1097     SetIcon(hIcon, FALSE);
1098 
1099     // Load insert popup menu
1100     mInsertMenu.LoadMenu(IDR_INSERT_MENU);
1101 
1102     // Attach insert popup menu to mainframe menu
1103     CString string;
1104     int index;
1105     for (index = 0; index < GetMenu()->GetMenuItemCount(); index++)
1106     {
1107         if (GetMenu()->GetMenuItemID(index) == ID_INSERT)
1108         {
1109             GetMenu()->GetMenuString(ID_INSERT, string, 0);
1110             GetMenu()->RemoveMenu(index, MF_BYPOSITION);
1111 
1112             GetMenu()->InsertMenu(index, MF_POPUP | MF_BYPOSITION | MF_DISABLED, (UINT)mInsertMenu.GetSubMenu(0)->m_hMenu, string);
1113             break;
1114         }
1115     }
1116 
1117     index = GetSubMenuIndex(GetMenu(), _T("&Project"));
1118     CMenu *mpProjectMenu = GetMenu()->GetSubMenu(index);
1119 
1120     if (mpProjectMenu)
1121     {
1122 
1123         // Attach recent projects popup menu to mainframe menu
1124         for (index = 0; index < mpProjectMenu->GetMenuItemCount(); index++)
1125         {
1126             if (mpProjectMenu->GetMenuItemID(index) == ID_RECENT_PROJECTS)
1127             {
1128                 mpProjectMenu->GetMenuString(ID_RECENT_PROJECTS, string, 0);
1129                 mpProjectMenu->RemoveMenu(index, MF_BYPOSITION);
1130 
1131                 mpProjectMenu->InsertMenu(index, MF_POPUP | MF_BYPOSITION, (UINT)mpRecentMenu->m_hMenu, string);
1132                 break;
1133             }
1134         }
1135 
1136         UpdateRecentProjectsMenu();
1137     }
1138 
1139     mStatusMsg.Create(L"Saved", WS_CHILD | WS_VISIBLE, CRect(0, 0, 0, 0), this);
1140     SetLiveRegion(mStatusMsg.GetSafeHwnd());
1141     return 0;
1142 }
1143 
PreCreateWindow(CREATESTRUCT & cs)1144 BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
1145 {
1146     cs.cx = StudioXIni.width;
1147     cs.cy = StudioXIni.height;
1148     cs.x = StudioXIni.xpos;
1149     cs.y = StudioXIni.ypos;
1150 
1151     if( !CFrameWnd::PreCreateWindow(cs) )
1152         return FALSE;
1153     // TODO: Modify the Window class or styles here by modifying
1154     //  the CREATESTRUCT cs
1155 
1156     return TRUE;
1157 }
1158 
OnShowWindow(BOOL bShow,UINT nStatus)1159 void CMainFrame::OnShowWindow(BOOL bShow, UINT nStatus)
1160 {
1161     CWnd::OnShowWindow(bShow, nStatus);
1162 }
1163 
1164 
OnEraseBkgnd(CDC * pDC)1165 BOOL CMainFrame::OnEraseBkgnd(CDC *pDC)
1166 {
1167     return TRUE;
1168 }
1169 
OnSettingChange(UINT uFlags,LPCTSTR lpszSection)1170 void CMainFrame::OnSettingChange(UINT uFlags, LPCTSTR lpszSection)
1171 {
1172     CFrameWnd::OnSettingChange(uFlags, lpszSection);
1173 
1174     int new_text_scaler = GetTextScaler();
1175 
1176     if (new_text_scaler != m_text_scaler)
1177     {
1178         theApp.DeleteSystemFonts();
1179         theApp.CreateSystemFonts();
1180         m_text_scaler = new_text_scaler;
1181     }
1182 }
1183 
1184 // CMainFrame diagnostics
1185 
1186 #ifdef _DEBUG
AssertValid() const1187 void CMainFrame::AssertValid() const
1188 {
1189     CFrameWnd::AssertValid();
1190 }
1191 
Dump(CDumpContext & dc) const1192 void CMainFrame::Dump(CDumpContext& dc) const
1193 {
1194     CFrameWnd::Dump(dc);
1195 }
1196 
1197 #endif //_DEBUG
1198 
1199 
1200 // CMainFrame message handlers
1201 
1202 
1203 
1204 
1205 
HtmlHelp(DWORD_PTR dwData,UINT nCmd)1206 void CMainFrame::HtmlHelp(DWORD_PTR dwData, UINT nCmd)
1207 {
1208     // TODO: Add your specialized code here and/or call the base class
1209 
1210     CFrameWnd::HtmlHelp(dwData, nCmd);
1211 }
1212 
MouseHook(int nCode,WPARAM wParam,LPARAM lParam)1213 LRESULT CALLBACK MouseHook(int nCode, WPARAM wParam, LPARAM lParam)
1214 {
1215     if (nCode < 0)
1216     {
1217         CallNextHookEx(NULL, nCode, wParam, lParam);
1218         return 0;
1219     }
1220 
1221     MOUSEHOOKSTRUCT *mhs = (MOUSEHOOKSTRUCT *)lParam;
1222 
1223     /* Retrive pointer to main window class. */
1224 
1225     CMainFrame *m_hwnd = (CMainFrame *)AfxGetApp()->m_pMainWnd;
1226     POINT pt = mhs->pt;
1227 
1228     CToolBar *m_wndToolbar = m_hwnd->GetToolBar();
1229     UINT nIndex = m_wndToolbar->CommandToIndex(ID_ENDMACRO);
1230     CRect toolbar_rect, macro_end_rect, macro_playback_rect;
1231 
1232     /* Calculate the rect of macro end tool button. */
1233     m_wndToolbar->GetWindowRect(&toolbar_rect);
1234     m_wndToolbar->GetItemRect(nIndex, &macro_end_rect);
1235     macro_end_rect.left += toolbar_rect.left;
1236     macro_end_rect.right += toolbar_rect.left;
1237     macro_end_rect.top += toolbar_rect.top;
1238     macro_end_rect.bottom += toolbar_rect.top;
1239 
1240     /* Calculate the rect of macro play tool button. */
1241     nIndex = m_wndToolbar->CommandToIndex(ID_PLAYBACKMACRO);
1242     m_wndToolbar->GetItemRect(nIndex, &macro_playback_rect);
1243     macro_playback_rect.left += toolbar_rect.left;
1244     macro_playback_rect.right += toolbar_rect.left;
1245     macro_playback_rect.top += toolbar_rect.top;
1246     macro_playback_rect.bottom += toolbar_rect.top;
1247 
1248     /* Skip 'macro end' and 'macro playback'click event. */
1249     if (!PtInRect(macro_end_rect, pt) && !PtInRect(macro_playback_rect, pt))
1250     {
1251 
1252         /* Converts the screen coordinates of a specified point on the screen to
1253            client-area coordinates. */
1254         m_hwnd->ScreenToClient(&pt);
1255         CString str;
1256         INPUT input;
1257 
1258         switch (wParam)
1259         {
1260         case WM_LBUTTONDBLCLK:
1261         case WM_LBUTTONDOWN:
1262         case WM_LBUTTONUP:
1263         case WM_RBUTTONDOWN:
1264         case WM_RBUTTONUP:
1265         case WM_NCLBUTTONDBLCLK:
1266         case WM_NCLBUTTONUP:
1267         case WM_NCLBUTTONDOWN:
1268         case WM_MOUSEMOVE:
1269 
1270             /* One button click action may generate several button down messages,
1271                unable to figure out the reason, just check the previous message with
1272                the current one to excude repeated messages. */
1273             if ((premsg == wParam) && (prept.x == pt.x) && (prept.y == pt.y))
1274             {
1275                 break;
1276             }
1277 
1278             premsg = wParam;
1279             prept = pt;
1280 
1281             input.type = INPUT_MOUSE;
1282             input.mi.dx = pt.x;
1283             input.mi.dy = pt.y;
1284             input.mi.mouseData = 0;
1285             input.mi.dwFlags = wParam;
1286             input.mi.time = (GetTickCount() - start_time) / MACRO_RECORD_SPEED;
1287             input.mi.dwExtraInfo = 0;
1288             recorder->Write(&input, sizeof(INPUT));
1289 
1290             start_time = GetTickCount();
1291             break;
1292 
1293         case WM_MOUSEWHEEL:
1294         {
1295             MOUSEHOOKSTRUCTEX *hook_structex = (MOUSEHOOKSTRUCTEX *)lParam;
1296             pt = hook_structex->pt;
1297             m_hwnd->ScreenToClient(&pt);
1298 
1299             input.type = INPUT_MOUSE;
1300             input.mi.dx = pt.x;
1301             input.mi.dy = pt.y;
1302             input.mi.mouseData = ((signed int)hook_structex->mouseData >> 16);
1303             input.mi.dwFlags = wParam;
1304             input.mi.time = (GetTickCount() - start_time) / MACRO_RECORD_SPEED;
1305             input.mi.dwExtraInfo = 0;
1306 
1307             recorder->Write(&input, sizeof(INPUT));
1308 
1309             start_time = GetTickCount();
1310         }
1311         break;
1312         }
1313     }
1314 
1315     return CallNextHookEx(NULL, nCode, wParam, lParam);
1316 }
1317 
KeybdHook(int nCode,WPARAM wParam,LPARAM lParam)1318 LRESULT CALLBACK KeybdHook(int nCode, WPARAM wParam, LPARAM lParam)
1319 {
1320     if(nCode < 0)
1321     {
1322         CallNextHookEx(NULL, nCode, wParam, lParam);
1323         return 0;
1324     }
1325 
1326     INPUT input;
1327 
1328     int extended_key = (lParam & 0x01000000) >> 16;
1329 
1330     input.type = INPUT_KEYBOARD;
1331     input.ki.wVk = wParam;
1332     input.ki.wScan = (lParam & 0x0000ff00)>>8;;
1333     input.ki.dwFlags = (lParam & 0x80000000) >> 31;
1334 
1335     if ((pre_key_state != input.ki.dwFlags) ||
1336         (pre_vkey != input.ki.wVk))
1337     {
1338         pre_key_state = input.ki.dwFlags;
1339         pre_vkey = input.ki.wVk;
1340 
1341         if (input.ki.dwFlags)
1342         {
1343             input.ki.dwFlags = KEYEVENTF_KEYUP;
1344         }
1345 
1346         if (extended_key)
1347         {
1348             input.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
1349         }
1350 
1351         input.ki.time = (GetTickCount() - start_time) / MACRO_RECORD_SPEED;
1352         recorder->Write(&input, sizeof(INPUT));
1353     }
1354     start_time = GetTickCount();
1355 
1356     return CallNextHookEx(NULL, nCode, wParam, lParam);
1357 }
1358 
PlaybackOnemacro(CMainFrame * m_hwnd,CString pathname)1359 BOOL PlaybackOnemacro(CMainFrame *m_hwnd, CString pathname)
1360 {
1361     CFile *playback = new CFile();
1362 
1363     if (!playback->Open(pathname.GetBuffer(), CFile::modeRead))
1364     {
1365         return FALSE;
1366     }
1367 
1368     /* Read layout information. */
1369     TCHAR head_flag[50];
1370     playback->Read(&head_flag, sizeof(MACRO_FILE_FLAG));
1371 
1372     if (_tcscmp(head_flag, MACRO_FILE_FLAG) != 0)
1373     {
1374         playback->Close();
1375         delete playback;
1376 
1377         return FALSE;
1378     }
1379 
1380     /* Set layout. */
1381     MACRO_HEAD_INFO macro_info;
1382     playback->Read(&macro_info, sizeof(MACRO_HEAD_INFO));
1383 
1384     proj_tree_state.RemoveAll();
1385     int state;
1386     for (int i = 0; i < macro_info.proj_tree_item_count; i++)
1387     {
1388         playback->Read(&state, sizeof(int));
1389         proj_tree_state.Add(state);
1390     }
1391 
1392     m_hwnd->SendMessage(WM_SET_LAYOUT, (WPARAM)&macro_info, NULL);
1393 
1394     /* Retrieve desktop window class. */
1395     int screenx;
1396     int screeny;
1397 
1398     /* Retrieve screen resolution.  */
1399     screenx = GetSystemMetrics(SM_CXSCREEN);
1400     screeny = GetSystemMetrics(SM_CYSCREEN);
1401 
1402     INPUT input;
1403     int interval_time = 0;
1404     int ret = playback->Read(&input, sizeof(INPUT));
1405 
1406     /* Handle mouse events.  */
1407     while (ret == sizeof(INPUT))
1408     {
1409         if (input.type == INPUT_MOUSE)
1410         {
1411             POINT pt;
1412 
1413             pt.x = input.mi.dx;
1414             pt.y = input.mi.dy;
1415 
1416             /* Convert client coordinate to screen coordinate. */
1417             m_hwnd->ClientToScreen(&pt);
1418 
1419             input.mi.dx = (65536 * pt.x + screenx / 2) / screenx;
1420             input.mi.dy = (65536 * pt.y + screeny / 2) / screeny;
1421 
1422             switch (input.mi.dwFlags)
1423             {
1424             case WM_LBUTTONDBLCLK:
1425             case WM_LBUTTONDOWN:
1426             case WM_NCLBUTTONDOWN:
1427             case WM_NCLBUTTONDBLCLK:
1428                 input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
1429                 break;
1430             case WM_LBUTTONUP:
1431             case WM_NCLBUTTONUP:
1432                 input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
1433                 break;
1434             case WM_RBUTTONDOWN:
1435                 input.mi.dwFlags = MOUSEEVENTF_RIGHTDOWN;
1436                 break;
1437             case WM_RBUTTONUP:
1438                 input.mi.dwFlags = MOUSEEVENTF_RIGHTUP;
1439                 break;
1440             case WM_MOUSEWHEEL:
1441                 input.mi.dwFlags = MOUSEEVENTF_WHEEL;
1442                 break;
1443             }
1444 
1445             input.mi.dwFlags |= MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;
1446             interval_time = input.mi.time;
1447             input.mi.time = 0;
1448         }
1449         else if (input.type == INPUT_KEYBOARD)
1450         {
1451             interval_time = input.ki.time;
1452             input.ki.time = 0;
1453 
1454             switch (input.ki.wVk)
1455             {
1456             case VK_LWIN:
1457             case VK_RWIN:
1458                 /* Read next message. */
1459                 ret = playback->Read(&input, sizeof(INPUT));
1460                 continue;
1461             }
1462         }
1463 
1464         Sleep(interval_time);
1465 
1466         /* Post message.  */
1467         SendInput(1, &input, sizeof(INPUT));
1468 
1469         /* Read next message. */
1470         ret = playback->Read(&input, sizeof(INPUT));
1471     }
1472 
1473     playback->Close();
1474     delete playback;
1475 
1476     return TRUE;
1477 }
1478 
MacroPlayThread(LPVOID lParam)1479 DWORD MacroPlayThread(LPVOID lParam)
1480 {
1481     CMainFrame *m_hwnd = (CMainFrame *)lParam;
1482 
1483     /* Sleep 500 tick count to initiating. */
1484     Sleep(500);
1485 
1486     CString str;
1487 
1488     str = macro_name;
1489 
1490     if (macro_filetype == ID_SUPERMACRO)
1491     {
1492         /* Play multi macro files.  */
1493         CStdioFile *pSuperMacro = new CStdioFile();
1494         if(pSuperMacro->Open(str, CStdioFile::modeRead))
1495         {
1496 
1497             int index = str.ReverseFind('/');
1498             if(index == -1)
1499             {
1500                 index = str.ReverseFind('\\');
1501             }
1502 
1503             if(index)
1504             {
1505                 str = str.Left(index + 1);
1506             }
1507 
1508             CString pathname;
1509             while(pSuperMacro->ReadString(pathname))
1510             {
1511                 if (pathname.IsEmpty())
1512                 {
1513                     continue;
1514                 }
1515 
1516                 str.Append(pathname);
1517 
1518                 if (!PlaybackOnemacro(m_hwnd, str))
1519                 {
1520                     m_hwnd->MessageBox(_T("Failed to open macro file."), _T("Error"), MB_ICONERROR | MB_OK);
1521                     break;
1522                 }
1523 
1524                 str = str.Left(index + 1);
1525             }
1526 
1527             pSuperMacro->Close();
1528             delete pSuperMacro;
1529         }
1530         else
1531         {
1532             m_hwnd->MessageBox(_T("Failed to open macro file."), _T("Error"), MB_ICONERROR | MB_OK);
1533         }
1534     }
1535     else
1536     {
1537         /* Play one macro file.  */
1538         PlaybackOnemacro(m_hwnd, str);
1539     }
1540 
1541     WPARAM wParam = MAKEWPARAM(ID_STOPMACRO, BN_CLICKED);
1542 
1543     BOOL ret = m_hwnd->PostMessage(WM_COMMAND, wParam, NULL);
1544 
1545     return 0;
1546 }
1547 
OnRecordmacro()1548 void CMainFrame::OnRecordmacro()
1549 {
1550     // TODO: Add your command handler code here
1551     MacroRecordDlg mrdlg(this);
1552 
1553     mrdlg.SetOwner(this);
1554     mrdlg.DoModal();
1555 
1556     if(!mrdlg.Getmacro_path().IsEmpty() && !mrdlg.Getmacro_name().IsEmpty())
1557     {
1558         macro_name.Format(_T("%s\\%s"), mrdlg.Getmacro_path(), mrdlg.Getmacro_name());
1559 
1560         recorder = new CFile();
1561 
1562         if(recorder == NULL)
1563         {
1564             return;
1565         }
1566 
1567         if(recorder->Open(macro_name.GetBuffer(), CFile::modeCreate | CFile::modeWrite))
1568         {
1569             UINT nIndex, nID, nStyle;
1570             int iImage;
1571             nIndex = m_wndToolBar.CommandToIndex(ID_RECORDMACRO);
1572             m_wndToolBar.GetButtonInfo(nIndex, nID, nStyle, iImage);
1573             m_wndToolBar.SetButtonInfo(nIndex, ID_ENDMACRO, nStyle, iImage);
1574 
1575             CImageList *pList = m_wndToolBar.GetToolBarCtrl().GetImageList();
1576 
1577             CBitmap bmImage;
1578             bmImage.LoadBitmap(IDB_MACRO_END);
1579 
1580             /* Change image of record button in toolbar. */
1581             pList->Replace(iImage, &bmImage, NULL);
1582             m_wndToolBar.Invalidate();
1583 
1584             CRect rect;
1585             m_splitter.GetWindowRect(rect);
1586 
1587             int total_width = rect.right - rect.left - 20;
1588             int cxMin;
1589 
1590             GetWindowRect(rect);
1591             StudioXIni.xpos = rect.left;
1592             StudioXIni.ypos = rect.top;
1593             StudioXIni.width = rect.Width();
1594             StudioXIni.height = rect.Height();
1595             m_splitter.GetColumnInfo(0, StudioXIni.proj_view_width, cxMin);
1596             m_splitter.GetColumnInfo(2, StudioXIni.resource_view_width, cxMin);
1597 
1598             /* Write a file flag to distinguish it from other files. */
1599             recorder->Write(MACRO_FILE_FLAG, sizeof(MACRO_FILE_FLAG));
1600 
1601             MACRO_HEAD_INFO info;
1602             info.ini_version = StudioXIni.ini_version;
1603             info.xpos = StudioXIni.xpos;
1604             info.ypos = StudioXIni.ypos;
1605             info.width = StudioXIni.width;
1606             info.height = StudioXIni.height;
1607             info.proj_view_width = StudioXIni.proj_view_width;
1608             info.resource_view_width = StudioXIni.resource_view_width;
1609             info.string_open = GetResourceView()->IsOpen(STRING_GROUP);
1610             info.color_open = GetResourceView()->IsOpen(COLOR_GROUP);
1611             info.font_open = GetResourceView()->IsOpen(FONT_GROUP);
1612             info.pixelmap_open = GetResourceView()->IsOpen(PIXELMAP_GROUP);
1613             info.proj_view_scrollpos = GetProjectView()->GetScrollPos(SB_VERT);
1614             info.res_view_scrollpos = GetResourceView()->GetScrollPos(SB_VERT);
1615             info.props_win_scrollpos = GetPropsWin()->GetScrollPos(SB_VERT);
1616 
1617             GetProjectView()->GetTreeState(&proj_tree_state);
1618             info.proj_tree_item_count = proj_tree_state.GetCount();
1619 
1620             /* Write layout information. */
1621             recorder->Write(&info, sizeof(MACRO_HEAD_INFO));
1622 
1623             /* Write project tree item state array.  */
1624             recorder->Write((int *)proj_tree_state.GetData(), sizeof(int) * proj_tree_state.GetCount());
1625 
1626             mouse_hook = SetWindowsHookEx(WH_MOUSE, MouseHook, NULL, GetCurrentThreadId());
1627 
1628             keybd_hook = SetWindowsHookEx(WH_KEYBOARD, KeybdHook, NULL, GetCurrentThreadId());
1629 
1630             start_time = GetTickCount();
1631         }
1632         else
1633         {
1634             CString msg;
1635             msg.Format(_T("Unable to open \"%d\"."), macro_name);
1636             ErrorMsg(msg);
1637         }
1638     }
1639 }
1640 
OnPlaybackmacro()1641 void CMainFrame::OnPlaybackmacro()
1642 {
1643     // TODO: Add your command handler code here
1644     MacroPlaybackDlg mpbdlg(this);
1645 
1646     mpbdlg.SetOwner(this);
1647     mpbdlg.DoModal();
1648 
1649     macro_name = mpbdlg.Getmacro_pathname();
1650 
1651     if(!macro_name.IsEmpty())
1652     {
1653 
1654         CStdioFile *pMacroFile = new CStdioFile();
1655 
1656         if (pMacroFile->Open(macro_name, CStdioFile::modeRead))
1657         {
1658 
1659             TCHAR head[50];
1660 
1661             /* Read file head. */
1662             pMacroFile->Read(head, sizeof(MACRO_FILE_FLAG));
1663 
1664             if (_tcscmp(head, MACRO_FILE_FLAG) == 0)
1665             {
1666                 /* Single macro file. */
1667                 macro_filetype = ID_SINGLEMACRO;
1668 
1669             }
1670             else
1671             {
1672                 /* Super macro file. */
1673                 macro_filetype = ID_SUPERMACRO;
1674             }
1675 
1676             pMacroFile->Close();
1677             delete pMacroFile;
1678 
1679             UINT nIndex, nID, nStyle;
1680             int iImage;
1681             nIndex = m_wndToolBar.CommandToIndex(ID_PLAYBACKMACRO);
1682             m_wndToolBar.GetButtonInfo(nIndex, nID, nStyle, iImage);
1683             m_wndToolBar.SetButtonInfo(nIndex, ID_STOPMACRO, nStyle, iImage);
1684 
1685             CImageList *pList = m_wndToolBar.GetToolBarCtrl().GetImageList();
1686 
1687             CBitmap bmImage;
1688             bmImage.LoadBitmap(IDB_MACRO_STOP);
1689 
1690             /* Change image of record button in toolbar. */
1691             pList->Replace(iImage, &bmImage, NULL);
1692             m_wndToolBar.Invalidate();
1693 
1694             /* Registr window message. */
1695             WM_SET_LAYOUT = RegisterWindowMessage(_T("MSG_SET_LAYOUT"));
1696 
1697             /* Start macro playback thread. */
1698             macro_play_thread = AfxBeginThread((AFX_THREADPROC)&MacroPlayThread, (LPVOID)this);
1699         }
1700         else
1701         {
1702             ErrorMsg("Failed to open macro file");
1703         }
1704     }
1705 }
1706 
OnStopMacro()1707 void CMainFrame::OnStopMacro()
1708 {
1709 
1710     UINT nIndex, nID, nStyle;
1711     int iImage;
1712     nIndex = m_wndToolBar.CommandToIndex(ID_STOPMACRO);
1713     m_wndToolBar.GetButtonInfo(nIndex, nID, nStyle, iImage);
1714     m_wndToolBar.SetButtonInfo(nIndex, ID_PLAYBACKMACRO, nStyle, iImage);
1715 
1716     CImageList *pList = m_wndToolBar.GetToolBarCtrl().GetImageList();
1717 
1718     CBitmap bmImage;
1719     bmImage.LoadBitmap(IDB_MACRO_PLAYBACK);
1720     pList->Replace(iImage, &bmImage, NULL);
1721     m_wndToolBar.Invalidate();
1722 
1723     if (macro_play_thread)
1724     {
1725         /* Terminate macro playback thread. */
1726         TerminateThread(macro_play_thread, NULL);
1727         macro_play_thread = NULL;
1728     }
1729 }
1730 
OnEndmacro()1731 void CMainFrame::OnEndmacro()
1732 {
1733     // TODO: Add your command handler code here
1734 
1735     UINT nIndex, nID, nStyle;
1736     int iImage;
1737     nIndex = m_wndToolBar.CommandToIndex(ID_ENDMACRO);
1738     m_wndToolBar.GetButtonInfo(nIndex, nID, nStyle, iImage);
1739     m_wndToolBar.SetButtonInfo(nIndex, ID_RECORDMACRO, nStyle, iImage);
1740 
1741     CImageList *pList = m_wndToolBar.GetToolBarCtrl().GetImageList();
1742 
1743     CBitmap bmImage;
1744     bmImage.LoadBitmap(IDB_MACRO_RECORD);
1745     pList->Replace(iImage, &bmImage, NULL);
1746     m_wndToolBar.Invalidate();
1747 
1748     if (mouse_hook)
1749     {
1750         UnhookWindowsHookEx(mouse_hook);
1751         mouse_hook = 0;
1752     }
1753 
1754     if (keybd_hook)
1755     {
1756         UnhookWindowsHookEx(keybd_hook);
1757         keybd_hook = 0;
1758     }
1759 
1760     if(recorder)
1761     {
1762         recorder->Close();
1763 
1764         delete recorder;
1765         recorder = NULL;
1766     }
1767 }
1768 
IsTestMode()1769 BOOL CMainFrame::IsTestMode()
1770 {
1771     if (macro_play_thread || recorder)
1772     {
1773         return TRUE;
1774     }
1775 
1776     return FALSE;
1777 }
1778 
OnSetLayout(WPARAM wParam,LPARAM lParam)1779 LRESULT CMainFrame::OnSetLayout(WPARAM wParam, LPARAM lParam)
1780 {
1781     MACRO_HEAD_INFO *ini_info = (MACRO_HEAD_INFO *)wParam;
1782 
1783     /* Reset studio layout. */
1784     MoveWindow(ini_info->xpos, ini_info->ypos, ini_info->width, ini_info->height);
1785 
1786     m_splitter.SetColumnInfo(0, ini_info->proj_view_width, 200);
1787     m_splitter.SetColumnInfo(1, 0, 0);
1788     m_splitter.SetColumnInfo(2, ini_info->resource_view_width, 200);
1789     m_splitter.RecalcLayout();
1790 
1791     GetResourceView()->SetResFolderStatus(COLOR_GROUP, ini_info->color_open);
1792     GetResourceView()->SetResFolderStatus(FONT_GROUP, ini_info->font_open);
1793     GetResourceView()->SetResFolderStatus(PIXELMAP_GROUP, ini_info->pixelmap_open);
1794     GetResourceView()->SetResFolderStatus(STRING_GROUP, ini_info->string_open);
1795 
1796     /* Set project view state. */
1797     GetProjectView()->SetTreeState(&proj_tree_state);
1798 
1799     /* Set scrollbar position.  */
1800     GetProjectView()->SetScrollPos(SB_VERT, ini_info->proj_view_scrollpos);
1801     GetResourceView()->SetScrollPos(SB_VERT, ini_info->res_view_scrollpos);
1802     GetPropsWin()->SetScrollPos(SB_VERT, ini_info->props_win_scrollpos);
1803 
1804     return 0;
1805 }
1806 
1807 
OnInitMenuPopup(CMenu * pPopupMenu,UINT nIndex,BOOL bSysMenu)1808 void CMainFrame::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
1809 {
1810     CFrameWnd::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
1811 
1812     if (mInsertMenu.GetSubMenu(0) == pPopupMenu)
1813     {
1814         int insert_folder_style;
1815         int insert_widget_style;
1816         project_view *view = GetProjectView();
1817         int selected_node_level = PROJECT_NODE_LEVEL;
1818 
1819         if (view)
1820         {
1821             selected_node_level = view->GetSelectedNodeLevel();
1822         }
1823 
1824         switch (selected_node_level)
1825         {
1826         case PROJECT_NODE_LEVEL:
1827             //all items are disabled
1828             insert_folder_style = MF_BYPOSITION | MF_DISABLED | MF_GRAYED;
1829             insert_widget_style = MF_BYPOSITION | MF_DISABLED | MF_GRAYED;
1830             break;
1831         case DISPLAY_NODE_LEVEL:
1832             //enabled insert folder item, disable insert widget items
1833             insert_folder_style = MF_BYPOSITION | MF_ENABLED;
1834             insert_widget_style = MF_BYPOSITION | MF_DISABLED | MF_GRAYED;
1835             break;
1836         default:
1837             //disabled insert folder item, enable insert widget items
1838             insert_folder_style = MF_BYPOSITION | MF_DISABLED | MF_GRAYED;
1839             insert_widget_style = MF_BYPOSITION | MF_ENABLED;
1840         }
1841 
1842         int count = pPopupMenu->GetMenuItemCount();
1843         int id;
1844         for (int pos = 0; pos < count; pos++)
1845         {
1846             id = pPopupMenu->GetMenuItemID(pos);
1847             if (id == ID_INSERT_FOLDER)
1848             {
1849                 pPopupMenu->EnableMenuItem(pos, insert_folder_style);
1850             }
1851             else
1852             {
1853                 pPopupMenu->EnableMenuItem(pos, insert_widget_style);
1854             }
1855         }
1856 
1857         ULONG flags = GetMenu()->GetMenuState(nIndex, MF_BYPOSITION);
1858         // If menu is disabled or grayed, Should handle nothing.
1859         if (!(flags & (MF_DISABLED | MF_GRAYED)))
1860         {
1861             GetProjectView()->UpdateBaseMenu(&mInsertMenu);
1862         }
1863     }
1864     else
1865     {
1866         int index = GetSubMenuIndex(GetMenu(), _T("&Project"));
1867         CMenu *p_project_menu = GetMenu()->GetSubMenu(index);
1868 
1869         index = GetSubMenuIndex(GetMenu(), _T("&Configure"));
1870         CMenu *p_configure_menu = GetMenu()->GetSubMenu(index);
1871 
1872         if (p_project_menu == pPopupMenu)
1873         {
1874             if (GetOpenProject())
1875             {
1876                 EnableMenuItem(p_project_menu, ID_PROJECT_SAVE);
1877                 EnableMenuItem(p_project_menu, ID_PROJECT_SAVE_AS);
1878                 EnableMenuItem(p_project_menu, ID_PROJECT_CLOSE);
1879                 EnableMenuItem(p_project_menu, ID_GENERATE_ALL);
1880                 EnableMenuItem(p_project_menu, ID_GENERATE_RESOURCES);
1881                 EnableMenuItem(p_project_menu, ID_GENERATE_APPLICATION);
1882                 if (GetProjectView()->IsFolderSelected())
1883                 {
1884                     // import project must specify the target folder. So only enable import button while folder selected.
1885                     EnableMenuItem(p_project_menu, ID_PROJECT_IMPORT);
1886                 }
1887                 else
1888                 {
1889                     DisableMenuItem(p_project_menu, ID_PROJECT_IMPORT);
1890                 }
1891             }
1892             else
1893             {
1894                 DisableMenuItem(p_project_menu, ID_PROJECT_SAVE);
1895                 DisableMenuItem(p_project_menu, ID_PROJECT_SAVE_AS);
1896                 DisableMenuItem(p_project_menu, ID_PROJECT_CLOSE);
1897                 DisableMenuItem(p_project_menu, ID_GENERATE_ALL);
1898                 DisableMenuItem(p_project_menu, ID_GENERATE_RESOURCES);
1899                 DisableMenuItem(p_project_menu, ID_GENERATE_APPLICATION);
1900                 DisableMenuItem(p_project_menu, ID_PROJECT_IMPORT);
1901             }
1902         }
1903         else if (p_configure_menu == pPopupMenu)
1904         {
1905             studiox_project *project = GetOpenProject();
1906 
1907             if (project)
1908             {
1909                 if (project->IsWidgetPositionLocked())
1910                 {
1911                     p_configure_menu->CheckMenuItem(ID_LOCK_WIDGET_POSITIONS, MF_CHECKED);
1912                 }
1913                 else
1914                 {
1915                     p_configure_menu->CheckMenuItem(ID_LOCK_WIDGET_POSITIONS, MF_UNCHECKED);
1916                 }
1917             }
1918         }
1919     }
1920 
1921     // TODO: Add your message handler code here
1922 }
1923 
DisableMenus()1924 void CMainFrame::DisableMenus()
1925 {
1926     CMenu *p_menu = GetMenu();
1927     if (p_menu)
1928     {
1929         DisableMenuItem(p_menu, _T("&Insert"));
1930         DisableMenuItem(p_menu, _T("&Edit"));
1931 //        DisableMenuItem(p_menu, _T("&Configure"));
1932 
1933         int index = GetSubMenuIndex(p_menu, _T("&Configure"));
1934         CMenu* p_configure_menu = p_menu->GetSubMenu(index);
1935 
1936         DisableMenuItem(p_configure_menu, _T("Project/Displays"));
1937         DisableMenuItem(p_configure_menu, _T("Languages"));
1938         DisableMenuItem(p_configure_menu, _T("Themes"));
1939         DisableMenuItem(p_configure_menu, _T("Target View"));
1940         DisableMenuItem(p_configure_menu, _T("Screen Flow"));
1941     }
1942 }
1943 
EnableMenus()1944 void CMainFrame::EnableMenus()
1945 {
1946     CMenu *p_menu = GetMenu();
1947 
1948     if (p_menu)
1949     {
1950         EnableMenuItem(p_menu, _T("&Insert"));
1951         EnableMenuItem(p_menu, _T("&Edit"));
1952         //EnableMenuItem(p_menu, _T("&Configure"));
1953 
1954         int index = GetSubMenuIndex(p_menu, _T("&Configure"));
1955         CMenu* p_configure_menu = p_menu->GetSubMenu(index);
1956 
1957         EnableMenuItem(p_configure_menu, _T("Project/Displays"));
1958         EnableMenuItem(p_configure_menu, _T("Languages"));
1959         EnableMenuItem(p_configure_menu, _T("Themes"));
1960         EnableMenuItem(p_configure_menu, _T("Target View"));
1961         EnableMenuItem(p_configure_menu, _T("Screen Flow"));
1962     }
1963 }
1964 
DisableMenuItem(CMenu * menu,CString string)1965 void CMainFrame::DisableMenuItem(CMenu *menu, CString string)
1966 {
1967     if (menu)
1968     {
1969         int index = GetSubMenuIndex(menu, string);
1970         menu->EnableMenuItem( index, MF_BYPOSITION | MF_DISABLED | MF_GRAYED);
1971     }
1972 }
1973 
EnableMenuItem(CMenu * menu,CString string)1974 void CMainFrame::EnableMenuItem(CMenu *menu, CString string)
1975 {
1976     if (menu)
1977     {
1978         int index = GetSubMenuIndex(menu, string);
1979         menu->EnableMenuItem(index, MF_BYPOSITION | MF_ENABLED);
1980         DrawMenuBar();
1981     }
1982 }
1983 
DisableMenuItem(CMenu * menu,INT id)1984 void CMainFrame::DisableMenuItem(CMenu *menu, INT id)
1985 {
1986     if (menu)
1987     {
1988         menu->EnableMenuItem(id, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1989     }
1990 }
1991 
EnableMenuItem(CMenu * menu,INT id)1992 void CMainFrame::EnableMenuItem(CMenu *menu, INT id)
1993 {
1994     if (menu)
1995     {
1996         menu->EnableMenuItem(id, MF_BYCOMMAND | MF_ENABLED);
1997         DrawMenuBar();
1998     }
1999 }
2000 
2001 
UpdateRecentProjectsMenu()2002 void CMainFrame::UpdateRecentProjectsMenu()
2003 {
2004     if (mpRecentMenu)
2005     {
2006         int index = mpRecentMenu->GetMenuItemCount();
2007 
2008         while (index)
2009         {
2010             mpRecentMenu->RemoveMenu(index - 1, MF_BYPOSITION);
2011             index--;
2012         }
2013 
2014         for (index = 0; index < MAX_RECENT_PROJECTS; index++)
2015         {
2016             if (!StudioXIni.recent_project_paths[index].IsEmpty())
2017             {
2018                 mpRecentMenu->AppendMenu(MF_STRING, ID_FILE_MRU_FILE2 + index, StudioXIni.recent_project_paths[index]);
2019             }
2020         }
2021     }
2022 }
2023 
OnTestMessage(WPARAM wParam,LPARAM lParam)2024 LRESULT CMainFrame::OnTestMessage(WPARAM wParam, LPARAM lParam)
2025 {
2026     LRESULT result = 0;
2027     CStringArray param;
2028     CString classname;
2029     CString title;
2030     CString parent_owner;
2031     CWnd *pWnd;
2032     studiox_project *project;
2033 
2034     switch (wParam)
2035     {
2036     case TEST_TOOLBAR_CREATE:
2037         GetProjectView()->CloseProject(FALSE, FALSE);
2038         theApp.OnProjectNew();
2039         break;
2040 
2041     case TEST_TOOLBAR_OPEN:
2042         break;
2043 
2044     case TEST_TOOLBAR_SAVE:
2045         theApp.OnProjectSave();
2046         break;
2047 
2048     case TEST_TOOLBAR_CUT:
2049         OnCutWidget();
2050         break;
2051 
2052     case TEST_TOOLBAR_COPY:
2053         OnCopyWidget();
2054         break;
2055 
2056     case TEST_TOOLBAR_PASTE:
2057         OnPasteWidget();
2058         break;
2059 
2060     case TEST_TOOLBAR_ALIGN_LEFT:
2061         OnAlignLeft();
2062         break;
2063 
2064     case TEST_TOOLBAR_ALIGN_RIGHT:
2065         OnAlignRight();
2066         break;
2067 
2068     case TEST_TOOLBAR_ALIGN_TOP:
2069         OnAlignTop();
2070         break;
2071 
2072     case TEST_TOOLBAR_ALIGN_BOTTOM:
2073         OnAlignBottom();
2074         break;
2075 
2076     case TEST_TOOLBAR_VSPACE_EQUALLY:
2077         OnVSpaceEqually();
2078         break;
2079 
2080     case TEST_TOOLBAR_HSPACE_EQUALLY:
2081         OnHSpaceEqually();
2082         break;
2083 
2084     case TEST_TOOLBAR_EQUAL_WIDTH:
2085         OnEqualWidth();
2086         break;
2087 
2088     case TEST_TOOLBAR_EQUAL_HEIGHT:
2089         OnEqualHeight();
2090         break;
2091 
2092     case TEST_TOOLBAR_MOVE_TO_FRONT:
2093         OnMoveToFront();
2094         break;
2095 
2096     case TEST_TOOLBAR_MOVE_TO_BACK:
2097         OnMoveToBack();
2098         break;
2099 
2100     case TEST_TOOLBAR_SIZE_TO_FIT:
2101         OnSizeToFit();
2102         break;
2103 
2104     case TEST_TOOLBAR_ZOOM_IN:
2105         SendMessage(WM_COMMAND, ID_ZOOM_IN, 0);
2106         break;
2107 
2108     case TEST_TOOLBAR_ZOOM_OUT:
2109         SendMessage(WM_COMMAND, ID_ZOOM_OUT, 0);
2110         break;
2111 
2112     case TEST_TOOLBAR_MACRO_RECORD:
2113         OnRecordmacro();
2114         break;
2115 
2116     case TEST_TOOLBAR_MACRO_PLAYBACK:
2117         OnPlaybackmacro();
2118         break;
2119 
2120     case TEST_TOOLBAR_ABOUT:
2121         theApp.OnAppAbout();
2122         break;
2123 
2124     case TEST_UNDO:
2125         OnUndo();
2126         break;
2127 
2128     case TEST_CONFIGURE_LANGUAGES:
2129         OnConfigureLanguages();
2130         break;
2131 
2132     case TEST_CONFIGURE_DISPLAYS:
2133         OnConfigureDisplays();
2134         break;
2135 
2136     case TEST_CONFIGURE_THEMES:
2137         OnConfigureThemes();
2138         break;
2139 
2140     case TEST_CONFIGURE_SCREEN_FLOW:
2141         OnConfigureScreenFlow();
2142         break;
2143 
2144     case TEST_GENERATE_ALL:
2145         OnGenerateAll();
2146         break;
2147 
2148     case TEST_GENERATE_RESOURCES:
2149         OnGenResources();
2150         break;
2151 
2152     case TEST_GET_MENU_STATUS:
2153     {
2154         int index = GetSubMenuIndex(GetMenu(), GetTestingParam(0));
2155         int status;
2156 
2157         //get menu status
2158         status = GetMenu()->GetMenuState(index, MF_BYPOSITION);
2159 
2160         if (status & MF_DISABLED)
2161         {
2162             //disabled
2163             return 1;
2164         }
2165         else
2166         {
2167             //enabled
2168             return 0;
2169         }
2170     }
2171 
2172     case TEST_GRID_SNAP_SETTING:
2173         OnGridSetting();
2174         break;
2175 
2176     case TEST_FIND_DIALOG:
2177         SplitString(GetTestingParam(0), ';', &param);
2178         classname = param.GetAt(0);
2179         title = param.GetAt(1);
2180         parent_owner = param.GetAt(2);
2181 
2182         // Retrieve a handle to the top-level window whose class name and window name match the specified strings.
2183         pWnd = FindWindow(classname, title);
2184 
2185         while (pWnd)
2186         {
2187             CWnd *owner = pWnd->GetOwner();
2188 
2189             if (classname == "GUIX")
2190             {
2191                 GX_WIN32_DISPLAY_DRIVER_DATA *data = gx_win32_get_data_instance_head();
2192                 for (int index = 0; index < GX_MAX_WIN32_DISPLAYS; index++)
2193                 {
2194                     if ((data->win32_driver_winhandle == pWnd->GetSafeHwnd()) &&
2195                         (pWnd->IsWindowVisible()))
2196                     {
2197                         result = (LRESULT)pWnd->GetSafeHwnd();
2198                         break;
2199                     }
2200                     data++;
2201                 }
2202 
2203                 break;
2204             }
2205             else
2206             {
2207                 HWND handle = 0;
2208 
2209                 if (owner)
2210                 {
2211                     handle = owner->GetSafeHwnd();
2212                 }
2213 
2214                 if (handle == (HWND)_tstoi(parent_owner))
2215                 {
2216                     // The parent handle match, found the dialog
2217                     if (pWnd->IsWindowVisible())
2218                     {
2219                         result = (LRESULT)pWnd->GetSafeHwnd();
2220                     }
2221                     break;
2222                 }
2223 
2224                 // Retrieve a handle to a window whose class name and window name match the specified strings.
2225                 pWnd = FindWindowEx(NULL, // Search among windows that are child windows of the desktop.
2226                                     handle,// A handle to a child window. The search begins with the next windnow in the Z order. If the parameter is NULL, the search begings with the first child window,
2227                                     classname, // The class name.
2228                                     title); // The window name.
2229             }
2230         }
2231         break;
2232 
2233     case TEST_LOCK_UNLOCK_WIDGET_POSITIONS:
2234         project = GetOpenProject();
2235         if (project)
2236         {
2237             project->LockUlockWidgetPositions(lParam);
2238         }
2239         break;
2240 
2241     case TEST_RUN_APPLICATION:
2242         OnRunApplication();
2243         break;
2244 
2245     case TEST_IS_WAIT_DIALOG_RUNNING:
2246         result = IsWaitDialogRunning();
2247         break;
2248 
2249     default:
2250         break;
2251     }
2252     return result;
2253 }
2254