1 // rich_text_edit_dlg.cpp : implementation file
2 //
3 
4 #include "studiox_includes.h"
5 #include "rich_text_edit_dlg.h"
6 #include "color_edit_dialog.h"
7 
8 #define MENU_BAR_HEIGHT_96DPI 29
9 #define LABLE_WIDTH_96DPI     60
10 #define COLOR_BUTTON_WIDTH_96DPI 30
11 #define MIN_RICH_TEXT_EDIT_DLG_WIDTH_96DPI 800
12 
13 extern CString target_class_name;
14 extern CFont NormalFont;
15 
16 extern "C" {
17     #include "gx_multi_line_text_view.h"
18     #include "gx_rich_text_view.h"
19     #include "gx_utility.h"
20     extern GX_DISPLAY  target_win_display;
21     extern VOID *_win32_canvas_memory_prepare(GX_CANVAS *canvas, GX_RECTANGLE *dirty);
22 }
23 
24 enum rich_text_edit_dlg_test_commands {
25     TEST_SET_STRING = 1,
26     TEST_SAVE,
27     TEST_CANCEL
28 };
29 
30 #define DEFINE_GUIDXXX(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
31         EXTERN_C const GUID CDECL name \
32                 = { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }
33 DEFINE_GUIDXXX(IID_ITextDocument, 0x8CC497C0, 0xA1DF, 0x11CE, 0x80, 0x98,
34     0x00, 0xAA, 0x00, 0x47, 0xBE, 0x5D);
35 
36 enum button_ids {
37     ID_BOLD_BUTTON = 1024,
38     ID_ITALIC_BUTTON,
39     ID_UNDERLINE_BUTTON,
40     ID_FONT_LABLE,
41     ID_FONT_COMBO,
42     ID_HIGHLIGHT_COLOR_LABLE,
43     ID_HIGHLIGHT_COLOR_COMBO,
44     ID_HIGHLIGHT_COLOR_BUTTON,
45     ID_TEXT_COLOR_LABLE,
46     ID_TEXT_COLOR_COMBO,
47     ID_TEXT_COLOR_BUTTON,
48     ID_LEFT_ALIGN_BUTTON,
49     ID_CENTER_ALIGN_BUTTON,
50     ID_RIGHT_ALIGN_BUTTON,
51     ID_RICH_EDIT
52 };
53 
BEGIN_MESSAGE_MAP(custom_rich_edit,CRichEditCtrl)54 BEGIN_MESSAGE_MAP(custom_rich_edit, CRichEditCtrl)
55     ON_WM_KILLFOCUS()
56     ON_WM_SETFOCUS()
57 END_MESSAGE_MAP()
58 
59 ///////////////////////////////////////////////////////////////////////////////
60 custom_rich_edit::custom_rich_edit()
61 {
62     mSelStart = 0;
63     mSelEnd = 0;
64 }
65 
66 ///////////////////////////////////////////////////////////////////////////////
OnSetFocus(CWnd * pOldWnd)67 void custom_rich_edit::OnSetFocus(CWnd* pOldWnd)
68 {
69     CRichEditCtrl::OnSetFocus(pOldWnd);
70 
71     // TODO: Add your message handler code here
72     HideSelection(FALSE, TRUE);
73     SetSel(mSelStart, mSelEnd);
74 }
75 
76 ///////////////////////////////////////////////////////////////////////////////
OnKillFocus(CWnd * pNewWnd)77 void custom_rich_edit::OnKillFocus(CWnd* pNewWnd)
78 {
79     CRichEditCtrl::OnKillFocus(pNewWnd);
80 
81     // TODO: Add your message handler code here
82     HideSelection(FALSE, TRUE);
83 
84     GetSel(mSelStart, mSelEnd);
85 }
86 
BEGIN_MESSAGE_MAP(text_edit_button_frame,CWnd)87 BEGIN_MESSAGE_MAP(text_edit_button_frame, CWnd)
88     ON_WM_ERASEBKGND()
89     ON_WM_CREATE()
90     ON_WM_SIZE()
91     ON_WM_CTLCOLOR()
92     ON_BN_CLICKED(ID_BOLD_BUTTON, OnClickBold)
93     ON_BN_CLICKED(ID_ITALIC_BUTTON, OnClickItalic)
94     ON_BN_CLICKED(ID_UNDERLINE_BUTTON, OnClickUnderline)
95     ON_BN_CLICKED(ID_LEFT_ALIGN_BUTTON, OnClickLeftAlign)
96     ON_BN_CLICKED(ID_CENTER_ALIGN_BUTTON, OnClickCenterAlign)
97     ON_BN_CLICKED(ID_RIGHT_ALIGN_BUTTON, OnClickRightAlign)
98     ON_BN_CLICKED(ID_HIGHLIGHT_COLOR_BUTTON, OnClickHighlightColor)
99     ON_BN_CLICKED(ID_TEXT_COLOR_BUTTON, OnClickTextColor)
100     ON_CBN_SELCHANGE(ID_TEXT_COLOR_COMBO, OnChangeTextColor)
101     ON_CBN_SELCHANGE(ID_FONT_COMBO, OnChangeFont)
102     ON_CBN_SELCHANGE(ID_HIGHLIGHT_COLOR_COMBO, OnChangeHighlightColor)
103 END_MESSAGE_MAP()
104 
105 ///////////////////////////////////////////////////////////////////////////////
106 text_edit_button_frame::text_edit_button_frame(widget_info *info, CWnd *pParent)
107 {
108     mpInfo = info;
109     mHighlightColorName = "";
110     mTextColorName="";
111     mFontName = "";
112 
113     int dpi = GetSystemDPI();
114 
115     mLableWidth = MulDiv(LABLE_WIDTH_96DPI, dpi, DEFAULT_DPI_96);
116     mColorButtonWidth = MulDiv(COLOR_BUTTON_WIDTH_96DPI, dpi, DEFAULT_DPI_96);
117 }
118 
119 ///////////////////////////////////////////////////////////////////////////////
~text_edit_button_frame()120 text_edit_button_frame::~text_edit_button_frame()
121 {
122 
123 }
124 
125 ///////////////////////////////////////////////////////////////////////////////
OnCreate(LPCREATESTRUCT lpCreateStruct)126 int text_edit_button_frame::OnCreate(LPCREATESTRUCT lpCreateStruct)
127 {
128     if (CWnd::OnCreate(lpCreateStruct) == -1)
129         return -1;
130 
131     CFont* font = &NormalFont;
132 
133     mBtnBold.Create(_T(""), WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON | BS_OWNERDRAW | MAX_TAB_STOPS, CRect(0, 0, 0, 0), this, ID_BOLD_BUTTON);
134     mBtnBold.LoadBitmaps(IDB_BOLD, IDB_BOLD);
135     SetControlAccessibleName(mBtnBold.GetSafeHwnd(), _T("Bold"));
136 
137     mBtnItalic.Create(_T(""), WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON | BS_OWNERDRAW | MAX_TAB_STOPS, CRect(0, 0, 0, 0), this, ID_ITALIC_BUTTON);
138     mBtnItalic.LoadBitmaps(IDB_ITALIC, IDB_ITALIC);
139     SetControlAccessibleName(mBtnItalic.GetSafeHwnd(), _T("Italic"));
140 
141     mBtnUnderline.Create(_T(""), WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON | BS_OWNERDRAW | MAX_TAB_STOPS, CRect(0, 0, 0, 0), this, ID_UNDERLINE_BUTTON);
142     mBtnUnderline.LoadBitmaps(IDB_UNDERLINE, IDB_UNDERLINE);
143     SetControlAccessibleName(mBtnUnderline.GetSafeHwnd(), _T("Underline"));
144 
145     mBtnLeftAlign.Create(_T(""), WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON | BS_OWNERDRAW | MAX_TAB_STOPS, CRect(0, 0, 0, 0), this, ID_LEFT_ALIGN_BUTTON);
146     mBtnLeftAlign.LoadBitmaps(IDB_LEFTALIGN, IDB_LEFTALIGN);
147     SetControlAccessibleName(mBtnLeftAlign.GetSafeHwnd(), _T("Left Align"));
148 
149     mBtnCenterAlign.Create(_T(""), WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON | BS_OWNERDRAW | MAX_TAB_STOPS, CRect(0, 0, 0, 0), this, ID_CENTER_ALIGN_BUTTON);
150     mBtnCenterAlign.LoadBitmaps(IDB_CENTERALIGN, IDB_CENTERALIGN);
151     SetControlAccessibleName(mBtnItalic.GetSafeHwnd(), _T("Center Align"));
152 
153     mBtnRightAlign.Create(_T(""), WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON | BS_OWNERDRAW | MAX_TAB_STOPS, CRect(0, 0, 0, 0), this, ID_RIGHT_ALIGN_BUTTON);
154     mBtnRightAlign.LoadBitmaps(IDB_RIGHTALIGN, IDB_RIGHTALIGN);
155     SetControlAccessibleName(mBtnUnderline.GetSafeHwnd(), _T("Right Align"));
156 
157     mFontBox.Create(WS_VISIBLE | WS_CHILD | WS_TABSTOP | CBS_DROPDOWNLIST | CBS_SORT, CRect(0, 0, 0, 0), this, ID_FONT_COMBO);
158     mFontBox.SetFont(font);
159 
160     mHighlightColorBox.Create(WS_VISIBLE | WS_CHILD | WS_TABSTOP | CBS_DROPDOWNLIST | CBS_SORT, CRect(0, 0, 0, 0), this, ID_HIGHLIGHT_COLOR_COMBO);
161     mHighlightColorBox.SetFont(font);
162 
163     mHighlightColorButton.Create(_T(""), WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON, CRect(0, 0, 0, 0), this, ID_HIGHLIGHT_COLOR_BUTTON);
164 
165     mTextColorBox.Create(WS_VISIBLE | WS_CHILD | WS_TABSTOP | CBS_DROPDOWNLIST | CBS_SORT, CRect(0, 0, 0, 0), this, ID_TEXT_COLOR_COMBO);
166     mTextColorBox.SetFont(font);
167 
168     mFontLable.Create(_T("Font:"), WS_VISIBLE | WS_CHILD | SS_RIGHT, CRect(0, 0, 0, 0), this, ID_FONT_LABLE);
169     mFontLable.SetFont(font);
170 
171     mHighlightColorLable.Create(_T("Highlight:"), WS_VISIBLE | WS_CHILD | SS_RIGHT, CRect(0, 0, 0, 0), this, ID_HIGHLIGHT_COLOR_LABLE);
172     mHighlightColorLable.SetFont(font);
173 
174     mTextColorLable.Create(_T("Text Color:"), WS_VISIBLE | WS_CHILD | SS_RIGHT, CRect(0, 0, 0, 0), this, ID_TEXT_COLOR_LABLE);
175     mTextColorLable.SetFont(font);
176 
177     mTextColorButton.Create(_T(""), WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON, CRect(0, 0, 0, 0), this, ID_TEXT_COLOR_BUTTON);
178 
179     rich_text_edit_dlg* dlg = (rich_text_edit_dlg*)GetParent();
180     COLORREF color = dlg->MakeColorRef(mpInfo->color_id[NORMAL_FILL_COLOR_INDEX]);
181     mHighlightColorButton.SetBoxColor(color);
182     color = dlg->MakeColorRef(mpInfo->color_id[NORMAL_TEXT_COLOR_INDEX]);
183     mTextColorButton.SetBoxColor(color);
184 
185     mFontName = InitResList(&mFontBox, RES_TYPE_FONT, mpInfo->font_id[NORMAL_FONT_INDEX]);
186     mHighlightColorName = InitResList(&mHighlightColorBox, RES_TYPE_COLOR, mpInfo->color_id[NORMAL_FILL_COLOR_INDEX]);
187     mTextColorName = InitResList(&mTextColorBox, RES_TYPE_COLOR, mpInfo->color_id[NORMAL_TEXT_COLOR_INDEX]);
188 
189     return 0;
190 }
191 
192 ///////////////////////////////////////////////////////////////////////////////
OnSize(UINT nType,int cx,int cy)193 void text_edit_button_frame::OnSize(UINT nType, int cx, int cy)
194 {
195     CWnd::OnSize(nType, cx, cy);
196 
197     CRect size;
198     CRect client;
199     GetClientRect(&client);
200 
201     CBitmap icon;
202     BITMAP bmp;
203     icon.LoadBitmap(IDB_BOLD);
204     icon.GetObject(sizeof(BITMAP), &bmp);
205 
206     //Position bold button
207     size.top = (client.Height() - bmp.bmHeight) >> 1;
208     size.bottom = size.top + bmp.bmHeight;
209     size.left = client.left + 10;
210     size.right = size.left + bmp.bmWidth;
211 
212     mBtnBold.MoveWindow(size);
213 
214     //Position italic button
215     size.OffsetRect(CPoint(bmp.bmWidth + 10, 0));
216     mBtnItalic.MoveWindow(size);
217 
218     //Position underline button
219     size.OffsetRect(CPoint(bmp.bmWidth + 10, 0));
220     mBtnUnderline.MoveWindow(size);
221 
222     //Position left align button
223     size.OffsetRect(CPoint(bmp.bmWidth + 10, 0));
224     mBtnLeftAlign.MoveWindow(size);
225 
226     //Position center align button
227     size.OffsetRect(CPoint(bmp.bmWidth + 10, 0));
228     mBtnCenterAlign.MoveWindow(size);
229 
230     //Position right align button
231     size.OffsetRect(CPoint(bmp.bmWidth + 10, 0));
232     mBtnRightAlign.MoveWindow(size);
233 
234     int width = (client.right - size.left - 10) / 3 - mLableWidth - mColorButtonWidth;
235 
236     size.right = size.left + mLableWidth;
237     mFontLable.MoveWindow(&size);
238 
239     //position font combo box
240     size.left = size.right + 5;
241     size.right = size.left + width;
242     mFontBox.MoveWindow(&size);
243 
244     size.left = size.right + 5;
245     size.right = size.left + mLableWidth;
246     mHighlightColorLable.MoveWindow(&size);
247 
248     //position highlight color combo box
249     size.left = size.right + 5;
250     size.right = size.left + width;
251     mHighlightColorBox.MoveWindow(&size);
252 
253     size.left = size.right + 5;
254     size.right = size.left + mColorButtonWidth;
255     mHighlightColorButton.MoveWindow(&size);
256 
257     size.left = size.right + 5;
258     size.right = size.left + mLableWidth;
259     mTextColorLable.MoveWindow(&size);
260 
261     //position text color box
262     size.left = size.right + 5;
263     size.right = size.left + width;
264     mTextColorBox.MoveWindow(&size);
265 
266     size.left = size.right + 5;
267     size.right = size.left + mColorButtonWidth;
268     mTextColorButton.MoveWindow(&size);
269 }
270 
271 ///////////////////////////////////////////////////////////////////////////////
OnClickBold()272 void text_edit_button_frame::OnClickBold()
273 {
274     rich_text_edit_dlg* dlg = (rich_text_edit_dlg*)GetParent();
275 
276     dlg->SetSelectedBold();
277 
278     Invalidate();
279 }
280 
281 ///////////////////////////////////////////////////////////////////////////////
OnClickItalic()282 void text_edit_button_frame::OnClickItalic()
283 {
284     rich_text_edit_dlg *dlg = (rich_text_edit_dlg*)GetParent();
285 
286     dlg->SetSelectedItalic();
287 
288     Invalidate();
289 }
290 
291 ///////////////////////////////////////////////////////////////////////////////
OnClickUnderline()292 void text_edit_button_frame::OnClickUnderline()
293 {
294     rich_text_edit_dlg* dlg = (rich_text_edit_dlg*)GetParent();
295 
296     dlg->SetSelectedUnderline();
297 
298     Invalidate();
299 }
300 
301 ///////////////////////////////////////////////////////////////////////////////
OnClickLeftAlign()302 void text_edit_button_frame::OnClickLeftAlign()
303 {
304     rich_text_edit_dlg* dlg = (rich_text_edit_dlg*)GetParent();
305 
306     dlg->SetSelectedLeftAlign();
307 
308     Invalidate();
309 }
310 
311 ///////////////////////////////////////////////////////////////////////////////
OnClickCenterAlign()312 void text_edit_button_frame::OnClickCenterAlign()
313 {
314     rich_text_edit_dlg* dlg = (rich_text_edit_dlg*)GetParent();
315 
316     dlg->SetSelectedCenterAlign();
317 
318     Invalidate();
319 }
320 
321 ///////////////////////////////////////////////////////////////////////////////
OnClickRightAlign()322 void text_edit_button_frame::OnClickRightAlign()
323 {
324     rich_text_edit_dlg* dlg = (rich_text_edit_dlg*)GetParent();
325 
326     dlg->SetSelectedRightAlign();
327 
328     Invalidate();
329 }
330 
331 ///////////////////////////////////////////////////////////////////////////////
OnClickHighlightColor()332 void text_edit_button_frame::OnClickHighlightColor()
333 {
334     rich_text_edit_dlg* dlg = (rich_text_edit_dlg*)GetParent();
335 
336     dlg->SetSelectedHighlightColor(mHighlightColorName);
337 
338     Invalidate();
339 }
340 
341 ///////////////////////////////////////////////////////////////////////////////
OnClickTextColor()342 void text_edit_button_frame::OnClickTextColor()
343 {
344     rich_text_edit_dlg* dlg = (rich_text_edit_dlg*)GetParent();
345 
346     dlg->SetSelectedTextColor(mTextColorName);
347 
348     Invalidate();
349 }
350 
351 ///////////////////////////////////////////////////////////////////////////////
OnChangeFont()352 void text_edit_button_frame::OnChangeFont()
353 {
354     int box_index = mFontBox.GetCurSel();
355     mFontBox.GetLBText(box_index, mFontName);
356 
357     rich_text_edit_dlg* dlg = (rich_text_edit_dlg*)GetParent();
358     dlg->SetSelectedFont(mFontName);
359 }
360 
361 ///////////////////////////////////////////////////////////////////////////////
OnChangeTextColor()362 void text_edit_button_frame::OnChangeTextColor()
363 {
364     int box_index = mTextColorBox.GetCurSel();
365     int color_id;
366     mTextColorBox.GetLBText(box_index, mTextColorName);
367     color_id = mTextColorBox.GetItemData(box_index);
368 
369 
370     rich_text_edit_dlg* dlg = (rich_text_edit_dlg*)GetParent();
371     dlg->SetSelectedTextColor(mTextColorName);
372 
373     COLORREF color = dlg->MakeColorRef(color_id);
374 
375     mTextColorButton.SetBoxColor(color);
376     mTextColorButton.Invalidate();
377 }
378 
379 ///////////////////////////////////////////////////////////////////////////////
OnChangeHighlightColor()380 void text_edit_button_frame::OnChangeHighlightColor()
381 {
382     int box_index = mHighlightColorBox.GetCurSel();
383     int color_id;
384     mHighlightColorBox.GetLBText(box_index, mHighlightColorName);
385     color_id = mHighlightColorBox.GetItemData(box_index);
386 
387     rich_text_edit_dlg* dlg = (rich_text_edit_dlg*)GetParent();
388     dlg->SetSelectedHighlightColor(mHighlightColorName);
389 
390     COLORREF color = dlg->MakeColorRef(color_id);
391 
392     mHighlightColorButton.SetBoxColor(color);
393     mHighlightColorButton.Invalidate();
394 }
395 
396 ///////////////////////////////////////////////////////////////////////////////
OnEraseBkgnd(CDC * pDC)397 BOOL text_edit_button_frame::OnEraseBkgnd(CDC* pDC)
398 {
399     CRect size;
400 
401     CBrush grayBrush(GetSysColor(COLOR_BTNFACE));
402     CBrush* oldBrush = pDC->SelectObject(&grayBrush);
403 
404     GetClientRect(&size);
405     pDC->Rectangle(size);
406     pDC->SelectObject(oldBrush);
407     return TRUE;
408 }
409 
410 ///////////////////////////////////////////////////////////////////////////////
OnCtlColor(CDC * pDC,CWnd * pWnd,UINT nCtlColor)411 HBRUSH text_edit_button_frame::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
412 {
413     HBRUSH hbr = CWnd::OnCtlColor(pDC, pWnd, nCtlColor);
414 
415     if (nCtlColor == CTLCOLOR_STATIC)
416     {
417         pDC->SetBkMode(TRANSPARENT);
418 
419         // Set background brush
420         return (HBRUSH)::GetStockObject(NULL_BRUSH);
421     }
422 
423     // TODO:  Return a different brush if the default is not desired
424     return hbr;
425 }
426 
427 ///////////////////////////////////////////////////////////////////////////////
InitResList(CComboBox * box,int res_type,int sel_res_id)428 CString text_edit_button_frame::InitResList(CComboBox *box, int res_type, int sel_res_id)
429 {
430     studiox_project *project = GetOpenProject();
431     project_view *pview = GetProjectView();
432     CString select_string("");
433 
434     if (!project || !pview)
435     {
436         return select_string;
437     }
438 
439     int active_display = pview->GetActiveDisplay();
440     int res_id;
441     int start_id = 0;
442     int end_id = project->CountResources(active_display, res_type);
443     int active_theme = project->mDisplays[active_display].active_theme;
444     int list_index;
445     CString name;
446 
447     for (res_id = start_id; res_id < end_id; res_id++)
448     {
449         res_info *info = project->FindResource(active_display, active_theme, res_type, res_id);
450 
451         if (info)
452         {
453             list_index = box->AddString(info->name);
454             box->SetItemData(list_index, res_id);
455 
456             if (res_id == sel_res_id)
457             {
458                 select_string = info->name;
459                 box->SetCurSel(list_index);
460             }
461         }
462     }
463 
464     return select_string;
465 }
466 
BEGIN_MESSAGE_MAP(rich_text_preview_win,CWnd)467 BEGIN_MESSAGE_MAP(rich_text_preview_win, CWnd)
468     ON_WM_CREATE()
469     ON_WM_HSCROLL()
470     ON_WM_VSCROLL()
471     ON_WM_PAINT()
472     ON_WM_SIZE()
473 END_MESSAGE_MAP()
474 
475 ///////////////////////////////////////////////////////////////////////////////
476 rich_text_preview_win::rich_text_preview_win(widget_info *info, CWnd *parent)
477 {
478     mpDisplay = NULL;
479     mpWidget = NULL;
480     mpCanvas = NULL;
481     mpRoot = NULL;
482     mpMem = NULL;
483     mpInfo = info;
484 
485     m_scroll_helper = new CScrollHelper();
486     m_scroll_helper->AttachWnd(this);
487 
488     CreateDisplay();
489     MakeWidgetPreview();
490 }
491 
492 ///////////////////////////////////////////////////////////////////////////////
~rich_text_preview_win()493 rich_text_preview_win::~rich_text_preview_win()
494 {
495     if (m_scroll_helper)
496     {
497         delete m_scroll_helper;
498     }
499 
500     if (mpDisplay)
501     {
502         resource_view::CleanupDisplayResources(mpDisplay);
503         guix_studio_delete_display(mpDisplay);
504         delete mpDisplay;
505     }
506 
507     if (mpWidget)
508     {
509         DeleteWidgetString();
510         widget_factory::DeleteWidgets(mpWidget);
511     }
512 
513     if (mpRoot)
514     {
515         gx_window_root_delete(mpRoot);
516         delete mpRoot;
517     }
518 
519     if (mpCanvas)
520     {
521         if (mpCanvas->gx_canvas_memory)
522         {
523             delete mpCanvas->gx_canvas_memory;
524         }
525         gx_canvas_delete(mpCanvas);
526         delete mpCanvas;
527     }
528 }
529 
530 ///////////////////////////////////////////////////////////////////////////////
OnCreate(LPCREATESTRUCT lpCreateStruct)531 int rich_text_preview_win::OnCreate(LPCREATESTRUCT lpCreateStruct)
532 {
533     if (CWnd::OnCreate(lpCreateStruct) == -1)
534         return -1;
535 
536     return 0;
537 }
538 
OnSize(UINT nType,int cx,int cy)539 void rich_text_preview_win::OnSize(UINT nType, int cx, int cy)
540 {
541     CWnd::OnSize(nType, cx, cy);
542 
543     GX_VALUE width, height;
544 
545     gx_widget_width_get(mpInfo->widget, &width);
546     gx_widget_height_get(mpInfo->widget, &height);
547 
548     m_scroll_helper->SetDisplaySize(width, height);
549 }
550 
551 ///////////////////////////////////////////////////////////////////////////////
OnHScroll(UINT nSBCode,UINT nPos,CScrollBar * pScrollBar)552 void rich_text_preview_win::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
553 {
554     // TODO: Add your message handler code here and/or call default
555 
556     m_scroll_helper->OnHScroll(nSBCode, nPos, pScrollBar);
557 }
558 
559 ///////////////////////////////////////////////////////////////////////////////
OnVScroll(UINT nSBCode,UINT nPos,CScrollBar * pScrollBar)560 void rich_text_preview_win::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
561 {
562     // TODO: Add your message handler code here and/or call default
563 
564     m_scroll_helper->OnVScroll(nSBCode, nPos, pScrollBar);
565 }
566 
567 ///////////////////////////////////////////////////////////////////////////////
CreateDisplay()568 void rich_text_preview_win::CreateDisplay()
569 {
570     studiox_project *project = GetOpenProject();
571     project_view *pview = GetProjectView();
572 
573     if (!project || !pview)
574     {
575         return;
576     }
577 
578     if (!mpDisplay)
579     {
580         // create a temporary screen and temporary
581         // canvas to make a bitmap:
582         GX_CANVAS *target_canvas = get_target_win_canvas();
583 
584         int canvas_width = target_canvas->gx_canvas_x_resolution;
585         int canvas_height = target_canvas->gx_canvas_y_resolution;
586 
587         int active_display = pview->GetActiveDisplay();
588         int active_theme = project->mDisplays[active_display].active_theme;
589         int memsize = 0;
590 
591         display_info *info = &project->mDisplays[active_display];
592 
593         mpDisplay = new GX_DISPLAY;
594 
595         guix_create_app_display(mpDisplay, "text_preview_display",
596             canvas_width, canvas_height,
597             info->colorformat,
598             project->mHeader.target_cpu,
599             IsRenesasDave2D(project),
600             IsDave2dFontFormat(project, active_display),
601             info->themes[active_theme].palette,
602             info->themes[active_theme].palette_total_size,
603             project->mHeader.palette_mode_aa_text_colors);
604 
605         GetResourceView()->BuildResourceTables(active_display, mpDisplay, FALSE);
606     }
607 }
608 
609 
610 ///////////////////////////////////////////////////////////////////////////////
MakeWidgetPreview()611 void rich_text_preview_win::MakeWidgetPreview()
612 {
613     studiox_project *project = GetOpenProject();
614     project_view *pview = GetProjectView();
615 
616     if (!project || !pview)
617     {
618         return;
619     }
620 
621     int active_display = pview->GetActiveDisplay();
622 
623     if (!mpWidget)
624     {
625         int widget_width = mpInfo->size.gx_rectangle_right - mpInfo->size.gx_rectangle_left + 1;
626         int widget_height = mpInfo->size.gx_rectangle_bottom - mpInfo->size.gx_rectangle_top + 1;
627         GX_RECTANGLE fill_rect;
628         gx_utility_rectangle_define(&fill_rect, 0, 0, widget_width - 1, widget_height - 1);
629 
630         int bpp = project->mDisplays[active_display].bits_per_pix;
631         switch (bpp)
632         {
633         case 24:
634             bpp = 32;
635             break;
636         }
637 
638         //calculate memory size
639         int  memsize = widget_width * widget_height * bpp;
640         memsize >>= 3;
641 
642         UCHAR *mem = new UCHAR[memsize];
643         mpCanvas = new GX_CANVAS;
644         mpRoot = new GX_WINDOW_ROOT;
645 
646         //create canvas and root window for widget drawing
647         gx_canvas_create(mpCanvas, "string_test_canvas",
648             mpDisplay, GX_CANVAS_SIMPLE,
649             widget_width, widget_height, (GX_COLOR *)mem, memsize);
650 
651         gx_window_root_create(mpRoot, "string_test_root", mpCanvas,
652             GX_STYLE_BORDER_NONE, GX_ID_NONE, &fill_rect);
653 
654         mpWidget = widget_factory::GenerateAppScreen(NULL, mpInfo);
655 
656         if (mpWidget)
657         {
658             gx_widget_attach(mpRoot, mpWidget);
659 
660             int xpos = mpInfo->size.gx_rectangle_left;
661             int ypos = mpInfo->size.gx_rectangle_top;
662 
663             if (xpos || ypos)
664             {
665                 gx_widget_shift(mpWidget, -xpos, -ypos, FALSE);
666             }
667 
668             GX_WIN32_DISPLAY_DRIVER_DATA *data = (GX_WIN32_DISPLAY_DRIVER_DATA *)target_win_display.gx_display_driver_data;
669             m_bitmap = data->win32_driver_bmpinfo;
670             m_bitmap.gx_bmp_header.biWidth = widget_width;
671             m_bitmap.gx_bmp_header.biHeight = widget_height;
672         }
673     }
674 
675     if (mpWidget)
676     {
677         //Draw widget
678         gx_canvas_drawing_initiate(mpCanvas, NULL, &mpWidget->gx_widget_size);
679 
680         //Fill background with gray color.
681         GX_BRUSH* brush;
682         gx_context_brush_get(&brush);
683 
684         int old_brush_width = brush->gx_brush_width;
685         int old_brush_style = brush->gx_brush_style;
686         brush->gx_brush_style |= GX_BRUSH_SOLID_FILL;
687         brush->gx_brush_width = 0;
688         gx_context_raw_fill_color_set(GX_COLOR_LIGHTGRAY);
689         gx_canvas_rectangle_draw(&mpWidget->gx_widget_size);
690 
691         brush->gx_brush_width = old_brush_width;
692         brush->gx_brush_style = old_brush_style;
693 
694         gx_widget_show(mpWidget);
695         mpWidget->gx_widget_draw_function(mpWidget);
696         gx_widget_hide(mpWidget);
697 
698         gx_canvas_drawing_complete(mpCanvas, FALSE);
699 
700         mpMem = (UCHAR *)_win32_canvas_memory_prepare(mpCanvas, &mpWidget->gx_widget_size);
701     }
702 }
703 
704 ///////////////////////////////////////////////////////////////////////////////
DeleteWidgetString()705 void rich_text_preview_win::DeleteWidgetString()
706 {
707     if (mpWidget)
708     {
709         GX_RICH_TEXT_VIEW* view = (GX_RICH_TEXT_VIEW*)mpWidget;
710         if (view->gx_multi_line_text_view_text.gx_string_ptr)
711         {
712             delete view->gx_multi_line_text_view_text.gx_string_ptr;
713         }
714     }
715 }
716 
717 ///////////////////////////////////////////////////////////////////////////////
UpdateRichText(CString & richtext)718 void rich_text_preview_win::UpdateRichText(CString &richtext)
719 {
720     if (mpWidget)
721     {
722         GX_STRING string;
723 
724         int max_length = richtext.GetLength() * 6 + 1;
725         string.gx_string_ptr = new char[max_length];
726         strcpy_s((char*)string.gx_string_ptr, max_length, CT2A(richtext.GetString(), CP_UTF8));
727         string.gx_string_length = strnlen_s(string.gx_string_ptr, max_length);
728 
729         DeleteWidgetString();
730         gx_multi_line_text_view_text_set_ext((GX_MULTI_LINE_TEXT_VIEW*)mpWidget, &string);
731 
732         MakeWidgetPreview();
733 
734         Invalidate();
735     }
736 }
737 
738 ///////////////////////////////////////////////////////////////////////////////
OnPaint()739 void rich_text_preview_win::OnPaint()
740 {
741     CPaintDC dc(this); // device context for painting
742     // TODO: Add your message handler code here
743     // Do not call CWnd::OnPaint() for painting messages
744 
745     if (mpInfo && mpCanvas && mpMem)
746     {
747         CSize scrollpos = m_scroll_helper->GetScrollPos();
748         GX_VALUE width;
749 
750         gx_widget_width_get(mpWidget, &width);
751 
752         guix_bitmap_flush(dc.GetSafeHdc(), mpWidget->gx_widget_size.gx_rectangle_left - scrollpos.cx,
753             mpWidget->gx_widget_size.gx_rectangle_top - scrollpos.cy, width, mpMem, &m_bitmap);
754     }
755 }
756 
757 // rich_text_edit_dlg dialog
758 
IMPLEMENT_DYNAMIC(rich_text_edit_dlg,express_dialog)759 IMPLEMENT_DYNAMIC(rich_text_edit_dlg, express_dialog)
760 
761 BEGIN_MESSAGE_MAP(rich_text_edit_dlg, express_dialog)
762     ON_WM_CREATE()
763     ON_WM_SIZE()
764     ON_WM_GETMINMAXINFO()
765     ON_CONTROL(EN_CHANGE, ID_RICH_EDIT, OnChangeRichText)
766     ON_MESSAGE(STUDIO_TEST, OnTestMessage)
767 END_MESSAGE_MAP()
768 
769 ///////////////////////////////////////////////////////////////////////////////
770 rich_text_edit_dlg::rich_text_edit_dlg(widget_info *info, CWnd* pParent /*=NULL*/)
771     : express_dialog(rich_text_edit_dlg::IDD, pParent)
772 {
773     IconId = IDB_STRINGS;
774     SetTitleText("Edit Rich Text");
775 
776     mpButtonFrame = NULL;
777     mpPreview = NULL;
778     mpInfo = info;
779 
780     mpProject = GetOpenProject();
781     mDisplay = mpProject->GetDisplayIndex(mpInfo);
782 
783     int active_theme;
784     switch (mpProject->mDisplays[mDisplay].colorformat)
785     {
786     case GX_COLOR_FORMAT_8BIT_PALETTE:
787         active_theme = mpProject->mDisplays[mDisplay].active_theme;
788         mPalette.palette = mpProject->mDisplays[mDisplay].themes[active_theme].palette;
789         mPalette.total_size = mpProject->mDisplays[mDisplay].themes[active_theme].palette_total_size;
790         mPalette.used_size = mpProject->mDisplays[mDisplay].themes[active_theme].palette_predefined;
791         break;
792 
793     case GX_COLOR_FORMAT_4BIT_GRAY:
794         ProjectConfigDlg::CreateDefault4BppPalette(mPalette);
795         break;
796 
797     case GX_COLOR_FORMAT_MONOCHROME:
798         ProjectConfigDlg::CreateDefault1BppPalette(mPalette);
799         break;
800 
801     default:
802         break;
803     }
804 
805     int dpi = GetSystemDPI();
806     mMenubarHeight = MulDiv(MENU_BAR_HEIGHT_96DPI, dpi, DEFAULT_DPI_96);
807     mMinDlgWidth = MulDiv(MIN_RICH_TEXT_EDIT_DLG_WIDTH_96DPI, dpi, DEFAULT_DPI_96);
808 
809     mpIRich = NULL;
810     mpIDoc = NULL;
811 }
812 
813 ///////////////////////////////////////////////////////////////////////////////
~rich_text_edit_dlg()814 rich_text_edit_dlg::~rich_text_edit_dlg()
815 {
816     if (mpButtonFrame)
817     {
818         delete mpButtonFrame;
819     }
820 
821     if (mpPreview)
822     {
823         delete mpPreview;
824     }
825     switch (mpProject->mDisplays[mDisplay].colorformat)
826     {
827     case GX_COLOR_FORMAT_4BIT_GRAY:
828     case GX_COLOR_FORMAT_MONOCHROME:
829         if (mPalette.palette)
830         {
831             delete mPalette.palette;
832         }
833         break;
834 
835     default:
836         break;
837     }
838 
839     if (mpIRich)
840     {
841         mpIRich->Release();
842     }
843 
844     if (mpIDoc)
845     {
846         mpIDoc->Release();
847     }
848 }
849 
850 ///////////////////////////////////////////////////////////////////////////////
PositionChildren()851 void rich_text_edit_dlg::PositionChildren()
852 {
853     CRect client;
854     CRect size;
855     INT width;
856 
857     GetClientRect(&client);
858     size = client;
859     size.left = client.left + 10;
860     size.top = client.top + m_title_bar_height + 10;
861     size.right = size.right - 10;
862     size.bottom = size.top + mMenubarHeight;
863 
864     // position button frame
865     mpButtonFrame->MoveWindow(&size);
866 
867     // position rich edit
868     width = (client.right - size.left - 20) / 2;
869     size.right = size.left + width;
870     size.top = client.top + m_title_bar_height + mMenubarHeight + 20;
871     size.bottom = client.bottom - m_status_bar_height - 20;
872     mRichEdit.MoveWindow(&size);
873 
874     // position preview
875     size.OffsetRect(CPoint(width + 10, 0));
876     mpPreview->MoveWindow(&size);
877 
878     Invalidate();
879 }
880 
881 
882 // rich_text_edit_dlg message handlers
883 ///////////////////////////////////////////////////////////////////////////////
OnInitDialog()884 BOOL rich_text_edit_dlg::OnInitDialog()
885 {
886     express_dialog::OnInitDialog();
887 
888     RichEditInit();
889 
890     return TRUE;  // return TRUE unless you set the focus to a control
891     // EXCEPTION: OCX Property Pages should return FALSE
892 }
893 
894 
895 ///////////////////////////////////////////////////////////////////////////////
OnCreate(LPCREATESTRUCT lpCreateStruct)896 int rich_text_edit_dlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
897 {
898     if (express_dialog::OnCreate(lpCreateStruct) == -1)
899         return -1;
900 
901     mpPreview = new rich_text_preview_win(mpInfo, this);
902     mpPreview->Create(target_class_name, _T("text_view_preview"), WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | WS_BORDER, CRect(0, 0, 0, 0), this, 0);
903 
904     mRichEdit.Create(WS_VISIBLE | WS_CHILD | WS_BORDER | ES_LEFT | ES_MULTILINE | ES_WANTRETURN | ES_AUTOVSCROLL | WS_TABSTOP, CRect(0, 0, 0, 0), this, ID_RICH_EDIT);
905 
906     AddSaveButton();
907     AddCancelButton();
908 
909     mpButtonFrame = new text_edit_button_frame(mpInfo, this);
910     mpButtonFrame->CreateEx(WS_EX_CONTROLPARENT, target_class_name, _T("text_edit_button_frame"), WS_VISIBLE | WS_CHILD, CRect(0, 0, 0, 0), this, 0);
911 
912     return 0;
913 }
914 
915 ///////////////////////////////////////////////////////////////////////////////
OnSize(UINT nType,int cx,int cy)916 void rich_text_edit_dlg::OnSize(UINT nType, int cx, int cy)
917 {
918     express_dialog::OnSize(nType, cx, cy);
919 
920     PositionChildren();
921 }
922 
923 ///////////////////////////////////////////////////////////////////////////////
OnGetMinMaxInfo(MINMAXINFO * lpMMI)924 void rich_text_edit_dlg::OnGetMinMaxInfo(MINMAXINFO* lpMMI)
925 {
926     lpMMI->ptMinTrackSize.x = mMinDlgWidth;
927 
928     express_dialog::OnGetMinMaxInfo(lpMMI);
929 }
930 
931 ///////////////////////////////////////////////////////////////////////////////
RichEditInit()932 void rich_text_edit_dlg::RichEditInit()
933 {
934     // Retrieve rich edit ole
935     mpIRich = mRichEdit.GetIRichEditOle();
936     mpIRich->QueryInterface(IID_ITextDocument, (void**)&mpIDoc);
937 
938     string_table* table = GetActiveStringTable();
939 
940     if (table)
941     {
942         CString id_name = table->GetResourceIdName(mpInfo->string_id[0]);
943 
944         CString string = table->GetString(id_name);
945         mRichEdit.SetSel(0, -1);
946         mRichEdit.ReplaceSel(string);
947         //FormatRichText();
948     }
949 
950     mRichEdit.SetEventMask(ENM_CHANGE);
951 }
952 
953 ///////////////////////////////////////////////////////////////////////////////
OnChangeRichText()954 void rich_text_edit_dlg::OnChangeRichText()
955 {
956     CString text;
957 
958     mRichEdit.GetWindowText(text);
959 
960     text = resource_gen::RichTextResIdName2ResId(mpProject, mDisplay, text);
961 
962     mpPreview->UpdateRichText(text);
963     //FormatRichText();
964 }
965 
966 ///////////////////////////////////////////////////////////////////////////////
967 #if 0
968 void rich_text_edit_dlg::FormatRichText()
969 {
970     // Suspend undo processing
971     mpIDoc->Undo(tomSuspend, NULL);
972 
973     CString string;
974     mRichEdit.GetWindowText(string);
975 
976     // It seems CRichEditCtrl treat "\r\n" as a single character.
977     // Seplace it to "\n" here to simple the charcter processing.
978     string.Replace(_T("\r\n"), _T("\n"));
979 
980     // Convert wide string to utf8 string.
981     int max_length = string.GetLength() * 6 + 1;
982     char *utf8_buf = new char[max_length];
983     strcpy_s(utf8_buf, max_length, CT2A(string.GetString(), CP_UTF8));
984 
985     CHARFORMAT tag_cf;
986     CHARFORMAT def_cf;
987 
988     // Initiate tag format
989     def_cf.cbSize = sizeof(CHARFORMAT);
990     def_cf.dwMask = CFM_COLOR;
991     def_cf.dwEffects = 0;
992     def_cf.crTextColor = GetSysColor(COLOR_BLACK);
993 
994     tag_cf = def_cf;
995     tag_cf.crTextColor = GetSysColor(COLOR_HIGHLIGHT);
996 
997     GX_STRING text;
998 
999     text.gx_string_ptr = utf8_buf;
1000     text.gx_string_length = strlen(utf8_buf);
1001 
1002     GX_STRING tmpstr;
1003     GX_RICH_TEXT_FORMAT format;
1004     GX_UBYTE processed_count;
1005     UINT glyph_len;
1006     GX_BOOL escape = GX_FALSE;
1007     INT start_index = 0;
1008     INT end_index = 0;
1009     INT tag_index = 0;
1010 
1011     long selstart, selend;
1012 
1013     mRichEdit.GetSel(selstart, selend);
1014     mRichEdit.HideSelection(TRUE, TRUE);
1015     int old_first_visible_line = mRichEdit.GetFirstVisibleLine();
1016     mRichEdit.SetRedraw(FALSE);
1017 
1018 
1019     while (text.gx_string_length)
1020     {
1021         if ((!escape) && (text.gx_string_ptr[0] == '\\'))
1022         {
1023             escape = GX_TRUE;
1024             processed_count = 1;
1025         }
1026         else
1027         {
1028             // Test rich text tags.
1029             if ((!escape) &&
1030                 (text.gx_string_ptr[0] == '<') &&
1031                 (_gx_rich_text_view_tag_enter((GX_RICH_TEXT_VIEW*)mpInfo->widget, &text, &format, &processed_count) == GX_SUCCESS))
1032             {
1033                 if (start_index != end_index)
1034                 {
1035                     utf8_buf[end_index] = '\0';
1036                     CString tostring(CA2T(utf8_buf + start_index, CP_UTF8));
1037 
1038                     mRichEdit.SetSel(tag_index, tag_index + tostring.GetLength());
1039                     mRichEdit.SetSelectionCharFormat(def_cf);
1040 
1041                     // Calcualte tag start position.
1042                     tag_index += tostring.GetLength();
1043                 }
1044 
1045                 // Set tags hightlight color.
1046                 mRichEdit.SetSel(tag_index, tag_index + processed_count);
1047                 mRichEdit.SetSelectionCharFormat(tag_cf);
1048 
1049                 tag_index += processed_count;
1050                 start_index = end_index + processed_count;
1051             }
1052             else
1053             {
1054 
1055                 tmpstr = text;
1056 
1057                 // Pick up glyph length.
1058                 if (_gx_utility_utf8_string_character_get(&tmpstr, GX_NULL, &glyph_len) != GX_SUCCESS)
1059                 {
1060                     // Invalid UTF8 string.
1061                     return;
1062                 }
1063 
1064                 processed_count = glyph_len;
1065             }
1066 
1067             escape = GX_FALSE;
1068         }
1069 
1070         end_index += processed_count;
1071         text.gx_string_ptr+= processed_count;
1072         text.gx_string_length-= processed_count;
1073     }
1074 
1075     if (start_index != end_index)
1076     {
1077         utf8_buf[end_index] = '\0';
1078         CString tostring(CA2T(utf8_buf + start_index, CP_UTF8));
1079 
1080         mRichEdit.SetSel(tag_index, tag_index + tostring.GetLength());
1081         mRichEdit.SetSelectionCharFormat(def_cf);
1082 
1083         // Calcualte tag start position.
1084         tag_index += tostring.GetLength();
1085     }
1086 
1087     delete utf8_buf;
1088     mRichEdit.SetSel(selstart, selend);
1089     mRichEdit.HideSelection(FALSE, TRUE);
1090 
1091     int new_first_visible_line = mRichEdit.GetFirstVisibleLine();
1092     if (old_first_visible_line != new_first_visible_line)
1093     {
1094         mRichEdit.LineScroll(old_first_visible_line - new_first_visible_line);
1095     }
1096 
1097     mRichEdit.SetRedraw();
1098     mRichEdit.Invalidate();
1099     mRichEdit.UpdateWindow();
1100 
1101     // Restore undo processing
1102     mpIDoc->Undo(tomResume, NULL);
1103 }
1104 #endif
1105 
1106 ///////////////////////////////////////////////////////////////////////////////
InsertTag(CString & tag_start,CString & tag_end)1107 void rich_text_edit_dlg::InsertTag(CString& tag_start, CString& tag_end)
1108 {
1109     long sel_start, sel_end;
1110 
1111     // Get current selection
1112     mRichEdit.GetSel(sel_start, sel_end);
1113 
1114     // Insert tag
1115     CString text = mRichEdit.GetSelText();
1116     text.Insert(0, tag_start);
1117     text.Append(tag_end);
1118     mRichEdit.ReplaceSel(text, TRUE);
1119 
1120     mRichEdit.HideSelection(TRUE, TRUE);
1121 
1122     // Set focus to rich text edit control
1123     mRichEdit.SetFocus();
1124 
1125     // Reset selection
1126     int tag_len = tag_start.GetLength();
1127     mRichEdit.SetSel(sel_start + tag_len, sel_end + tag_len);
1128     mRichEdit.HideSelection(FALSE, TRUE);
1129 }
1130 
1131 ///////////////////////////////////////////////////////////////////////////////
SetSelectedBold()1132 void rich_text_edit_dlg::SetSelectedBold()
1133 {
1134     CString tag_start(_T("<b>"));
1135     CString tag_end(_T("</b>"));
1136 
1137     InsertTag(tag_start, tag_end);
1138 }
1139 
1140 ///////////////////////////////////////////////////////////////////////////////
SetSelectedItalic()1141 void rich_text_edit_dlg::SetSelectedItalic()
1142 {
1143     CString tag_start(_T("<i>"));
1144     CString tag_end(_T("</i>"));
1145 
1146     InsertTag(tag_start, tag_end);
1147 }
1148 
1149 ///////////////////////////////////////////////////////////////////////////////
SetSelectedUnderline()1150 void rich_text_edit_dlg::SetSelectedUnderline()
1151 {
1152     CString tag_start(_T("<u>"));
1153     CString tag_end(_T("</u>"));
1154 
1155     InsertTag(tag_start, tag_end);
1156 }
1157 
1158 ///////////////////////////////////////////////////////////////////////////////
SetSelectedLeftAlign()1159 void rich_text_edit_dlg::SetSelectedLeftAlign()
1160 {
1161     CString tag_start(_T("<align left>"));
1162     CString tag_end(_T("</align>"));
1163 
1164     InsertTag(tag_start, tag_end);
1165 }
1166 
1167 ///////////////////////////////////////////////////////////////////////////////
SetSelectedCenterAlign()1168 void rich_text_edit_dlg::SetSelectedCenterAlign()
1169 {
1170     CString tag_start(_T("<align center>"));
1171     CString tag_end(_T("</align>"));
1172 
1173     InsertTag(tag_start, tag_end);
1174 }
1175 
1176 ///////////////////////////////////////////////////////////////////////////////
SetSelectedRightAlign()1177 void rich_text_edit_dlg::SetSelectedRightAlign()
1178 {
1179     CString tag_start(_T("<align right>"));
1180     CString tag_end(_T("</align>"));
1181 
1182     InsertTag(tag_start, tag_end);
1183 }
1184 
1185 ///////////////////////////////////////////////////////////////////////////////
SetSelectedHighlightColor(CString & id_name)1186 void rich_text_edit_dlg::SetSelectedHighlightColor(CString &id_name)
1187 {
1188     CString tag_start;
1189     CString tag_end(_T("</hc>"));
1190 
1191     tag_start.Format(_T("<hc GX_COLOR_ID_%s>"), id_name);
1192 
1193     InsertTag(tag_start, tag_end);
1194 }
1195 
1196 ///////////////////////////////////////////////////////////////////////////////
SetSelectedTextColor(CString & id_name)1197 void rich_text_edit_dlg::SetSelectedTextColor(CString &id_name)
1198 {
1199     CString tag_start;
1200     CString tag_end(_T("</c>"));
1201 
1202     tag_start.Format(_T("<c GX_COLOR_ID_%s>"), id_name);
1203 
1204     InsertTag(tag_start, tag_end);
1205 }
1206 
1207 ///////////////////////////////////////////////////////////////////////////////
SetSelectedFont(CString & id_name)1208 void rich_text_edit_dlg::SetSelectedFont(CString &id_name)
1209 {
1210     CString tag_start;
1211     CString tag_end(_T("</f>"));
1212 
1213     tag_start.Format(_T("<f GX_FONT_ID_%s>"), id_name);
1214 
1215     InsertTag(tag_start, tag_end);
1216 }
1217 
1218 ///////////////////////////////////////////////////////////////////////////////
PreTranslateMessage(MSG * pMsg)1219 BOOL rich_text_edit_dlg::PreTranslateMessage(MSG* pMsg)
1220 {
1221     if ((pMsg->message == WM_KEYDOWN) ||
1222         (pMsg->wParam == VK_RETURN))
1223     {
1224         INT ctrl_id = GetFocus()->GetDlgCtrlID();
1225         if (ctrl_id == ID_RICH_EDIT)
1226         {
1227             return CDialog::PreTranslateMessage(pMsg);
1228         }
1229     }
1230 
1231     return express_dialog::PreTranslateMessage(pMsg);
1232 }
1233 
1234 ///////////////////////////////////////////////////////////////////////////////
OnOK()1235 void rich_text_edit_dlg::OnOK()
1236 {
1237     mRichEdit.GetWindowText(mText);
1238 
1239     express_dialog::OnOK();
1240 }
1241 
1242 ///////////////////////////////////////////////////////////////////////////////
MakeColorRef(int color_id)1243 COLORREF rich_text_edit_dlg::MakeColorRef(int color_id)
1244 {
1245     GX_WIDGET* widget = mpInfo->widget;
1246 
1247     if (!widget)
1248     {
1249         return 0;
1250     }
1251 
1252     GX_WINDOW_ROOT *root = get_root_window();
1253 
1254     if (!root)
1255     {
1256         return 0;
1257     }
1258 
1259     GX_COLOR gx_color;
1260     gx_widget_color_get(widget, color_id, &gx_color);
1261 
1262     COLORREF color_ref;
1263 
1264     color_ref = resource_view::GetColorRef(gx_color, root->gx_window_root_canvas->gx_canvas_display->gx_display_color_format, mPalette.palette, mPalette.used_size);
1265 
1266     return color_ref;
1267 }
1268 
1269 ///////////////////////////////////////////////////////////////////////////////
GetText()1270 CString rich_text_edit_dlg::GetText()
1271 {
1272     return mText;
1273 }
1274 
1275 //////////////////////////////////////////////////////////////////////////////
OnTestMessage(WPARAM wParam,LPARAM lParam)1276 LRESULT rich_text_edit_dlg::OnTestMessage(WPARAM wParam, LPARAM lParam)
1277 {
1278     switch (wParam)
1279     {
1280     case TEST_SET_STRING:
1281         mRichEdit.SetWindowText(GetTestingParam(0));
1282         break;
1283 
1284     case TEST_SAVE:
1285         OnOK();
1286         break;
1287 
1288     case TEST_CANCEL:
1289         OnCancel();
1290         break;
1291     }
1292 
1293     return 0;
1294 }
1295