1
2 #include "studiox_includes.h"
3 #include "resource_tree.h"
4 #include "resource_item_provider.h"
5 #include "resource_view_provider.h"
6
7 #ifdef _DEBUG
8 #define new DEBUG_NEW
9 #endif
10
11 #define ITEM_HEIGHT 22
12 #define COLOR_BOX_SPACE 4
13 #define COLOR_TEXT_SPACE 8
14 #define ICON_HORZ_SPACE 8
15 #define ITEM_VERT_SPACE 6
16 #define TREE_INDENT 16
17 #define FONT_PREVIEW_COLUMN_WIDTH 120
18 #define FONT_PIXEL_COLUMN_WIDTH 30
19 #define FONT_STORAGE_COLUMN_WIDTH 50
20
21 #define PIXELMAP_DIMENSION_COLUMN_WIDTH 60
22 #define PIXELMAP_STORAGE_COLUMN_WIDTH 60
23
24 #define STRING_ID_COLUMN_WIDTH 120
25
26 extern CFont TitleFont;
27 extern CFont MediumFont;
28 extern CFont NormalFont;
29 extern CFont ViewHeaderFont;
30
31 extern CString target_class_name;
32
33 ///////////////////////////////////////////////////////////////////////////////
34 // this constructor is used for most items:
resource_item(resource_tree * tree,res_info * get)35 resource_item::resource_item(resource_tree *tree, res_info *get)
36 {
37 Init();
38 mpTree = tree;
39 mpRes = get;
40
41 if (mpRes->type == RES_TYPE_FOLDER)
42 {
43 if ((mpRes->folder_id == CUSTOM_PIXELMAP_FOLDER) ||
44 (mpRes->folder_id == DEFAULT_PIXELMAP_FOLDER))
45 {
46 m_open = FALSE;
47 }
48 else
49 {
50 m_open = TRUE;
51 }
52 }
53 else
54 {
55 switch (mpRes->type)
56 {
57 case RES_TYPE_ADD_COLOR:
58 case RES_TYPE_ADD_FONT:
59 case RES_TYPE_ADD_PIXELMAP:
60 case RES_TYPE_ADD_STRING:
61 SetIcon(IDB_ADD_RESOURCE, IDB_ADD_RESOURCE_HIGHLIGHT);
62 break;
63
64 default:
65 break;
66 }
67 }
68 }
69
70 ///////////////////////////////////////////////////////////////////////////////
71 // this constructor is used for String Table items
resource_item(resource_tree * tree,CString & name,CString & val)72 resource_item::resource_item(resource_tree *tree, CString &name, CString &val)
73 {
74 Init();
75 mpTree = tree;
76 mpRes = NULL;
77 string_id = name;
78 display_id = name;
79 string_val = val;
80 }
81
82
83 ///////////////////////////////////////////////////////////////////////////////
~resource_item()84 resource_item::~resource_item()
85 {
86 // must delete all my children as well as myself
87 resource_item *test;
88
89 while(m_first)
90 {
91 test = m_first->m_next;
92 delete m_first;
93 m_first = test;
94 }
95
96 if (m_preview_mem)
97 {
98 delete [] m_preview_mem;
99 }
100
101 if (m_pResItemProvider)
102 {
103 UiaDisconnectProvider(m_pResItemProvider);
104 m_pResItemProvider->Release();
105 m_pResItemProvider = NULL;
106 }
107 }
108
109 ///////////////////////////////////////////////////////////////////////////////
Init()110 void resource_item::Init()
111 {
112 m_first = m_next = m_parent = NULL;
113 m_indent = 0;
114 m_icon_id = 0;
115 m_icon_id_highlight = 0;
116 m_icon_height = 0;
117 m_icon_width = 0;
118 m_string_arrow_icon_width = 0;
119 m_boxcolor = MakeColorRef(0);
120 m_open = FALSE;
121 m_visible = FALSE;
122 m_selected = FALSE;
123 m_preview_mem = NULL;
124 m_size.SetRect(0, 0, 0, 0);
125
126 m_sys_dpi = GetSystemDPI();
127 int text_scaler = GetTextScaler();
128 m_item_height = GetScaledValue(ITEM_HEIGHT, m_sys_dpi, text_scaler);
129 m_header_height = GetScaledValue(VIEW_HEADER_HEIGHT, m_sys_dpi, text_scaler);
130
131 m_font_preview_width = GetScaledValue(FONT_PREVIEW_COLUMN_WIDTH, m_sys_dpi, text_scaler);
132 m_font_pixel_width = GetScaledValue(FONT_PIXEL_COLUMN_WIDTH, m_sys_dpi, text_scaler);
133 m_font_storage_width = GetScaledValue(FONT_STORAGE_COLUMN_WIDTH, m_sys_dpi, text_scaler);
134 m_pixelmap_dimension_width = GetScaledValue(PIXELMAP_DIMENSION_COLUMN_WIDTH, m_sys_dpi, text_scaler);
135 m_pixelmap_storage_width = GetScaledValue(PIXELMAP_STORAGE_COLUMN_WIDTH, m_sys_dpi, text_scaler);
136 m_thumbnail_size = GetScaledValue(THUMBNAIL_SIZE, m_sys_dpi, text_scaler);
137 m_string_id_width = GetScaledValue(STRING_ID_COLUMN_WIDTH, m_sys_dpi, text_scaler);
138
139 m_pResItemProvider = NULL;
140
141 m_Id = resource_view::CreateUniqueId();
142 }
143
144 ///////////////////////////////////////////////////////////////////////////////
Attach(resource_item * child)145 void resource_item::Attach(resource_item *child)
146 {
147 child->m_next = NULL;
148
149 if (m_first)
150 {
151 resource_item *test = m_first;
152 while(test->Next())
153 {
154 test = test->Next();
155 }
156 test->m_next = child;
157 }
158 else
159 {
160 m_first = child;
161 }
162 child ->m_parent = this;
163
164 if (m_open && m_visible)
165 {
166 child->SetVisible(TRUE);
167 }
168 }
169
170 ///////////////////////////////////////////////////////////////////////////////
Detach()171 void resource_item::Detach()
172 {
173 resource_item *previous;
174
175 if (m_parent)
176 {
177 if (m_parent->m_first == this)
178 {
179 // the easy case, first child:
180 m_parent->m_first = m_next;
181 }
182 else
183 {
184 previous = m_parent->m_first;
185 while(previous->m_next != this)
186 {
187 previous = previous->m_next;
188 }
189 previous->m_next = m_next;
190 }
191 }
192 m_next = NULL;
193 m_parent = NULL;
194 }
195
196 ///////////////////////////////////////////////////////////////////////////////
SetVisible(BOOL bVisible)197 void resource_item::SetVisible(BOOL bVisible)
198 {
199 m_visible = bVisible;
200
201 resource_item* child = First();
202
203 if ((GetResType() >= RES_TYPE_FOLDER) && IsOpen())
204 {
205 while (child)
206 {
207 child->SetVisible(TRUE);
208 child = child->Next();
209 }
210 }
211 }
212
213 ///////////////////////////////////////////////////////////////////////////////
Open()214 void resource_item::Open()
215 {
216 if (!m_open)
217 {
218 m_open = TRUE;
219
220 resource_item* child = First();
221
222 while (child)
223 {
224 child->SetVisible(TRUE);
225 child = child->Next();
226 }
227 mpTree->PositionItems();
228
229 GetResItemProvider()->RaiseExpandCollapseAutomationEvent(FALSE, TRUE);
230 }
231 }
232
233 ///////////////////////////////////////////////////////////////////////////////
Close()234 void resource_item::Close()
235 {
236 if ((mpRes->type <= RES_TYPE_FOLDER) && m_open)
237 {
238 m_open = FALSE;
239 resource_item *child = First();
240
241 while(child)
242 {
243 child->SetVisible(FALSE);
244 child = child->Next();
245 }
246 mpTree->PositionItems();
247
248 GetResItemProvider()->RaiseExpandCollapseAutomationEvent(TRUE, FALSE);
249 }
250 }
251
252 ///////////////////////////////////////////////////////////////////////////////
Previous()253 resource_item *resource_item::Previous()
254 {
255 resource_item* previous = NULL;
256
257 if (m_parent->m_first != this)
258 {
259 previous = m_parent->m_first;
260 while (previous->m_next != this)
261 {
262 previous = previous->m_next;
263 }
264 }
265
266 return previous;
267 }
268
269 ///////////////////////////////////////////////////////////////////////////////
Last()270 resource_item *resource_item::Last()
271 {
272 resource_item* child = First();
273
274 while (child->Next())
275 {
276 child = child->Next();
277 }
278
279 return child;
280 }
281
282 ///////////////////////////////////////////////////////////////////////////////
GetWin32CompatiblePixelWidth(int pixel_width,int color_format)283 int resource_item::GetWin32CompatiblePixelWidth(int pixel_width, int color_format)
284 {
285 switch(color_format)
286 {
287 case GX_COLOR_FORMAT_MONOCHROME:
288 case GX_COLOR_FORMAT_MONOCHROME_INVERTED:
289 pixel_width += 7;
290 pixel_width /= 8; // get bytes
291 pixel_width += 3;
292 pixel_width &= 0xfffc; // multiple of 4 bytes
293 return pixel_width * 8;
294
295 case GX_COLOR_FORMAT_2BIT_GRAY:
296 case GX_COLOR_FORMAT_2BIT_GRAY_INVERTED:
297 pixel_width += 3;
298 pixel_width /= 4; // get bytes
299 pixel_width += 3;
300 pixel_width &= 0xfffc; // multiple of 4 bytes
301 return pixel_width * 4;
302
303 case GX_COLOR_FORMAT_4BIT_GRAY:
304 case GX_COLOR_FORMAT_4BIT_GRAY_INVERTED:
305 case GX_COLOR_FORMAT_4BIT_VGA:
306 pixel_width++;
307 pixel_width /= 2; // bytes
308 pixel_width += 3;
309 pixel_width &= 0xfffc; // multiple of 4 bytes
310 return pixel_width * 2;
311
312 case GX_COLOR_FORMAT_8BIT_GRAY:
313 case GX_COLOR_FORMAT_8BIT_GRAY_INVERTED:
314 case GX_COLOR_FORMAT_8BIT_PALETTE:
315 case GX_COLOR_FORMAT_8BIT_PACKED_PIXEL:
316 pixel_width += 3;
317 pixel_width &= 0xfffc; // multiple of 4 bytes
318 break;
319
320 case GX_COLOR_FORMAT_5551BGRX:
321 case GX_COLOR_FORMAT_1555XRGB:
322 case GX_COLOR_FORMAT_565RGB:
323 case GX_COLOR_FORMAT_4444ARGB:
324 case GX_COLOR_FORMAT_4444BGRA:
325 case GX_COLOR_FORMAT_565BGR:
326 pixel_width *= 2; // bytes
327 pixel_width += 3;
328 pixel_width &= 0xfffc; // multiple of 4 bytes
329 return pixel_width / 2;
330
331 case GX_COLOR_FORMAT_24RGB:
332 case GX_COLOR_FORMAT_24BGR:
333 pixel_width *= 3;
334 pixel_width += 3;
335 pixel_width &= 0xfffc; // multiple of 4 bytes
336 return pixel_width / 3;
337
338 case GX_COLOR_FORMAT_24XRGB:
339 case GX_COLOR_FORMAT_24BGRX:
340 case GX_COLOR_FORMAT_32BGRA:
341 case GX_COLOR_FORMAT_32ARGB:
342 break;
343 }
344 return pixel_width;
345 }
346
347 ///////////////////////////////////////////////////////////////////////////////
348 // grayscale palette
349 GX_COLOR gray_palette[16] = {
350 0x00000000,
351 0x00111111,
352 0x00222222,
353 0x00333333,
354 0x00444444,
355 0x00555555,
356 0x00666666,
357 0x00777777,
358 0x00888888,
359 0x00999999,
360 0x00aaaaaa,
361 0x00bbbbbb,
362 0x00cccccc,
363 0x00dddddd,
364 0x00eeeeee,
365 0x00ffffff
366 };
367
368 ///////////////////////////////////////////////////////////////////////////////
MakeFontPreview()369 void resource_item::MakeFontPreview()
370 {
371 GX_VALUE width;
372 int height;
373 GX_BRUSH *brush;
374 GX_RECTANGLE rect;
375 GX_CANVAS temp_canvas;
376 GX_DISPLAY temp_display;
377 char *prev_string = NULL;
378 studiox_project *project = GetOpenProject();
379
380 if (!project || !mpRes)
381 {
382 return;
383 }
384 if (mpRes->font)
385 {
386 #ifdef _UNICODE
387 int char_count = mpRes->name.GetLength() * 6 + 1;
388 char *utf8buf = new char[char_count];
389
390 // convert Unicode to UTF8
391 WideCharToMultiByte(CP_UTF8, 0, mpRes->name.GetString(), -1, utf8buf, char_count, NULL, NULL);
392
393 prev_string = utf8buf;
394 #else
395 prev_string = mpRes->name.GetBuffer();
396 #endif
397
398 GX_STRING string;
399 string.gx_string_ptr = prev_string;
400 string.gx_string_length = strlen(prev_string);
401
402 gx_system_string_width_get_ext(mpRes->font, &string, &width);
403
404 if (!width)
405 {
406 // maybe this font only has the numeric characters?
407 prev_string = "0123456789";
408 string.gx_string_ptr = prev_string;
409 string.gx_string_length = strlen(prev_string);
410 gx_system_string_width_get_ext(mpRes->font, &string, &width);
411 }
412
413 height = mpRes->font->gx_font_line_height;
414
415 // if we don't have anything to
416 if (!width || !height)
417 {
418 delete[] utf8buf;
419 return;
420 }
421
422 // create a temporary screen and temporary
423 // canvas to make a bitmap:
424 int display_index = project->GetDisplayIndex(mpRes);
425
426 if (display_index >= 0)
427 {
428 int color_format = project->mDisplays[display_index].colorformat;
429 width = GetWin32CompatiblePixelWidth(width, color_format);
430
431 int memsize = guix_studio_create_display(&temp_display, "preview display",
432 width, height, color_format, project->mHeader.target_cpu,
433 IsRenesasDave2D(project), IsDave2dFontFormat(project, display_index), gray_palette, 16, project->mHeader.palette_mode_aa_text_colors);
434
435 if (memsize)
436 {
437 m_preview_mem = new UCHAR[memsize];
438
439 gx_canvas_create(&temp_canvas, "preview",
440 &temp_display, GX_CANVAS_SIMPLE,
441 width, height, (GX_COLOR*)m_preview_mem, memsize);
442
443 gx_utility_rectangle_define(&rect, 0, 0, width - 1, height - 1);
444
445 gx_canvas_drawing_initiate(&temp_canvas, NULL, &rect);
446 gx_context_raw_brush_define(COLOR_BLACK, COLOR_WHITE, GX_BRUSH_SOLID_FILL);
447 gx_context_brush_width_set(0);
448 gx_context_brush_get(&brush);
449 brush->gx_brush_font = mpRes->font;
450
451 gx_canvas_rectangle_draw(&rect);
452 gx_canvas_text_draw_ext(0, 0, &string);
453 gx_canvas_drawing_complete(&temp_canvas, FALSE);
454
455 // destroy the canvas, but keep the memory pointer:
456 gx_canvas_delete(&temp_canvas);
457
458 // copy the screen bitmap info locally:
459 GX_WIN32_DISPLAY_DRIVER_DATA* data = (GX_WIN32_DISPLAY_DRIVER_DATA*)temp_display.gx_display_driver_data;
460 m_bitmap = data->win32_driver_bmpinfo;
461
462 // delete the temporary screen
463 guix_studio_delete_display(&temp_display);
464 }
465 }
466 #ifdef _UNICODE
467 delete[] utf8buf;
468 #endif
469 }
470 }
471
472 ///////////////////////////////////////////////////////////////////////////////
MakePixelmapPreview()473 void resource_item::MakePixelmapPreview()
474 {
475 UINT width;
476 int height;
477 GX_RECTANGLE rect;
478 GX_DISPLAY temp_display;
479 GX_CANVAS temp_canvas;
480 studiox_project *project = GetOpenProject();
481
482 GX_PIXELMAP *map;
483
484 if (!mpRes || !project)
485 {
486 return;
487 }
488
489 if (mpRes->thumbnail)
490 {
491 map = mpRes->thumbnail;
492 }
493 else
494 {
495 map = mpRes->GetPixelmap();
496 }
497
498 if (map)
499 {
500 width = map->gx_pixelmap_width;
501 height = map->gx_pixelmap_height;
502
503 int display_index = project->GetDisplayIndex(mpRes);
504 int color_format = project->mDisplays[display_index].colorformat;
505 int active_theme = project->mDisplays[display_index].active_theme;
506
507 width = GetWin32CompatiblePixelWidth(width, color_format);
508
509 int memsize = guix_studio_create_display(&temp_display, "preview display",
510 width, height, color_format,
511 project->mHeader.target_cpu, IsRenesasDave2D(project), IsDave2dFontFormat(project, display_index),
512 project->mDisplays[display_index].themes[active_theme].palette,
513 project->mDisplays[display_index].themes[active_theme].palette_total_size,
514 project->mHeader.palette_mode_aa_text_colors);
515
516 if (memsize)
517 {
518 m_preview_mem = new UCHAR[memsize];
519
520 gx_canvas_create(&temp_canvas, "preview",
521 &temp_display, GX_CANVAS_SIMPLE,
522 width, height, (GX_COLOR *) m_preview_mem, memsize);
523
524 gx_utility_rectangle_define(&rect, 0, 0, width -1, height - 1);
525
526 gx_canvas_drawing_initiate(&temp_canvas, NULL, &rect);
527 GX_COLOR fill_color = ColorRefToGxColor(GetSysColor(COLOR_WINDOW));
528 gx_context_raw_brush_define(fill_color, fill_color, GX_BRUSH_SOLID_FILL);
529 gx_context_brush_width_set(0);
530 gx_canvas_rectangle_draw(&rect);
531
532 // set the fill color to medium gray, so that alphamap will be drawn to preview canvas in visible manner:
533 fill_color = 0xff808080;
534 gx_context_raw_brush_define(fill_color, fill_color, GX_BRUSH_SOLID_FILL);
535 gx_canvas_pixelmap_draw(0, 0, map);
536 gx_canvas_drawing_complete(&temp_canvas, FALSE);
537
538 // destroy the canvas, but keep the memory pointer:
539 gx_canvas_delete(&temp_canvas);
540
541 // copy the screen bitmap info locally:
542 GX_WIN32_DISPLAY_DRIVER_DATA *data = (GX_WIN32_DISPLAY_DRIVER_DATA *) temp_display.gx_display_driver_data;
543 m_bitmap = data->win32_driver_bmpinfo;
544
545 // delete the temporary screen
546 guix_studio_delete_display(&temp_display);
547 }
548 }
549 }
550
551 ///////////////////////////////////////////////////////////////////////////////
RebuildPreview()552 void resource_item::RebuildPreview()
553 {
554 if (m_preview_mem)
555 {
556 delete [] m_preview_mem;
557 m_preview_mem = NULL;
558 }
559
560 int type = RES_TYPE_STRING;
561
562 if (mpRes)
563 {
564 type = mpRes->type;
565 }
566 switch(type)
567 {
568 case RES_TYPE_FONT:
569 MakeFontPreview();
570 break;
571
572 case RES_TYPE_PIXELMAP:
573 MakePixelmapPreview();
574 break;
575
576 case RES_TYPE_COLOR:
577 m_boxcolor = MakeColorRef(GetRGBColor());
578 break;
579
580 default:
581 break;
582 }
583 }
584
585 ///////////////////////////////////////////////////////////////////////////////
PaintThemeHeader(CDC * dc)586 void resource_item::PaintThemeHeader(CDC *dc)
587 {
588 CRect boxrect;
589 CFont *old_font;
590 CDC dcMemory;
591 CBitmap fillmap;
592 CBitmap rightmap;
593 fillmap.LoadBitmap(IDB_HEADER_BACKGROUND);
594 BITMAP bm;
595 int vspace;
596 int icon_id = m_icon_id;
597 int width, height;
598
599 // go through hoops to get bitmap width:
600 fillmap.GetObject(sizeof(BITMAP), &bm);
601 width = bm.bmWidth;
602
603 dcMemory.CreateCompatibleDC(dc);
604 dcMemory.SelectObject(&fillmap);
605
606 int xpos = m_size.left;
607
608 dc->SetBkColor(RGB(128, 128, 128));
609 while (xpos < m_size.right)
610 {
611 dc->StretchBlt(xpos, m_size.top, width, m_header_height, &dcMemory, 0, 0, width, bm.bmHeight, SRCCOPY);
612 xpos += width;
613 }
614
615 if (IsSelected())
616 {
617 //highlight selected item
618 CBrush brush(GetSysColor(COLOR_HIGHLIGHT));
619 CRect rect = m_size;
620 rect.top += 1;
621 rect.bottom -= 2;
622
623 //FillRect does not include the rectangle's right and bottom sides
624 dc->FillRect(&rect, &brush);
625
626 if (m_icon_id_highlight)
627 {
628 icon_id = m_icon_id_highlight;
629 }
630 }
631
632 boxrect = m_size;
633 boxrect.bottom = boxrect.top + m_header_height;
634 boxrect.left += 8;
635
636 if (icon_id)
637 {
638 vspace = boxrect.bottom - boxrect.top;
639 vspace -= m_icon_height;
640 vspace /= 2;
641 PaintIcon(dc, icon_id, boxrect.left, boxrect.top + vspace);
642 boxrect.left += m_icon_width + ICON_HORZ_SPACE;
643 }
644
645 dc->SetTextColor(RGB(255, 255, 255));
646 dc->SetBkColor(RGB(0, 0, 0));
647 dc->SetBkMode(TRANSPARENT);
648
649 CString title;
650 title.Format(_T("Theme: \"%s\""), mpRes->name);
651
652 old_font = dc->SelectObject(&ViewHeaderFont);
653 dc->DrawText(title, boxrect, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
654 dc->SelectObject(old_font);
655
656 //paint up and down icons
657 CBitmap map;
658 BITMAP bitmap;
659
660 map.LoadBitmap(IDB_UP_ARROW_GRAY);
661 map.GetBitmap(&bitmap);
662 width = MulDiv(bitmap.bmWidth, m_sys_dpi, DEFAULT_DPI_96);
663 height = MulDiv(bitmap.bmHeight, m_sys_dpi, DEFAULT_DPI_96);
664
665 m_up_icon_rect.left = m_size.right - width - 7;
666 m_up_icon_rect.top = m_size.top + 2;
667 m_up_icon_rect.right = m_up_icon_rect.left + width;
668 m_up_icon_rect.bottom = m_up_icon_rect.top + height;
669
670 dcMemory.SelectObject(&map);
671 dc->StretchBlt(m_up_icon_rect.left, m_up_icon_rect.top, width, height, &dcMemory, 0, 0, bitmap.bmWidth, bitmap.bmHeight, SRCCOPY);
672
673 map.DeleteObject();
674 map.LoadBitmap(IDB_DOWN_ARROW_GRAY);
675 map.GetBitmap(&bitmap);
676
677 m_down_icon_rect.left = m_up_icon_rect.left;
678 m_down_icon_rect.top = m_up_icon_rect.bottom;
679 m_down_icon_rect.right = m_down_icon_rect.left + width;
680 m_down_icon_rect.bottom = m_down_icon_rect.top + height;
681
682 dcMemory.SelectObject(&map);
683 dc->StretchBlt(m_down_icon_rect.left, m_down_icon_rect.top, width, height, &dcMemory, 0, 0, bitmap.bmWidth, bitmap.bmHeight, SRCCOPY);
684 }
685
686 ///////////////////////////////////////////////////////////////////////////////
PaintIcon(CDC * dc,int icon_id,int x,int y)687 void resource_item::PaintIcon(CDC *dc, int icon_id, int x, int y)
688 {
689 CDC dcMemory;
690 CBitmap icon;
691 BITMAP bmp;
692 icon.LoadBitmap(icon_id);
693 dcMemory.CreateCompatibleDC(dc);
694 dcMemory.SelectObject(icon);
695 icon.GetObject(sizeof(BITMAP), &bmp);
696
697 dc->StretchBlt(x, y, m_icon_width, m_icon_height, &dcMemory, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
698 }
699
700 ///////////////////////////////////////////////////////////////////////////////
PaintGroupHeader(CDC * dc)701 void resource_item::PaintGroupHeader(CDC *dc)
702 {
703 CRect boxrect;
704 CFont *old_font;
705 CDC dcMemory;
706 CBitmap fillmap;
707 CBitmap rightmap;
708 fillmap.LoadBitmap(IDB_HEADER_BACKGROUND);
709 BITMAP bm;
710 int vspace;
711 int icon_id = m_icon_id;
712 int width, height;
713
714 // go through hoops to get bitmap width:
715 fillmap.GetObject(sizeof(BITMAP), &bm);
716 width = bm.bmWidth;
717
718 dcMemory.CreateCompatibleDC(dc);
719 dcMemory.SelectObject(&fillmap);
720
721 int xpos = m_size.left;
722
723 while(xpos < m_size.right)
724 {
725 dc->StretchBlt(xpos, m_size.top, width, m_header_height, &dcMemory, 0, 0, width, bm.bmHeight, SRCCOPY);
726 xpos += width;
727 }
728
729 if (IsSelected())
730 {
731 //highlight selected item
732 CBrush brush(GetSysColor(COLOR_HIGHLIGHT));
733 CRect rect = m_size;
734 rect.bottom = rect.top + m_header_height - 3;
735 rect.top += 1;
736
737
738 //FillRect does not include the rectangle's right and bottom sides
739 dc->FillRect(&rect, &brush);
740
741 if (m_icon_id_highlight)
742 {
743 icon_id = m_icon_id_highlight;
744 }
745 }
746
747 boxrect = m_size;
748 boxrect.bottom = boxrect.top + m_header_height;
749 boxrect.left += 8;
750
751 if (icon_id)
752 {
753 vspace = boxrect.bottom - boxrect.top;
754 vspace -= m_icon_height;
755 vspace /= 2;
756 PaintIcon(dc, icon_id, boxrect.left, boxrect.top + vspace);
757 boxrect.left += m_icon_width + ICON_HORZ_SPACE;
758 }
759
760 if (IsOpen())
761 {
762 rightmap.LoadBitmap(IDB_MINUS);
763 }
764 else
765 {
766 rightmap.LoadBitmap(IDB_PLUS);
767 }
768
769 rightmap.GetObject(sizeof(BITMAP), &bm);
770
771 width = MulDiv(bm.bmWidth, m_sys_dpi, DEFAULT_DPI_96);
772 height = MulDiv(bm.bmHeight, m_sys_dpi, DEFAULT_DPI_96);
773
774 vspace = boxrect.bottom - boxrect.top;
775 vspace -= height;
776 vspace /= 2;
777
778 dcMemory.SelectObject(&rightmap);
779 dc->StretchBlt(boxrect.right - width - 8, boxrect.top + vspace, width, height,
780 &dcMemory, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
781
782 dc->SetTextColor(RGB(255, 255, 255));
783 dc->SetBkColor(RGB(0, 0, 0));
784 dc->SetBkMode(TRANSPARENT);
785
786 old_font = dc->SelectObject(&ViewHeaderFont);
787 dc->DrawText(mpRes->name, boxrect, DT_LEFT|DT_VCENTER|DT_SINGLELINE);
788 dc->SelectObject(old_font);
789
790 // paint the gray background for the column header
791 if (m_open)
792 {
793 boxrect = m_size;
794 boxrect.top += m_header_height;
795 //CBrush *old_brush;
796 CBrush fillbrush;
797 fillbrush.CreateSolidBrush(RGB(229, 229, 229));
798 dc->FillRect(&boxrect, &fillbrush);
799 }
800 }
801
802 ///////////////////////////////////////////////////////////////////////////////
PaintFolderHeader(CDC * dc)803 void resource_item::PaintFolderHeader(CDC *dc)
804 {
805 CRect boxrect;
806 CFont *old_font;
807 int vspace;
808
809 // Draw folder icon
810 boxrect = m_size;
811 boxrect.bottom = boxrect.top + m_header_height;
812 boxrect.left += 8;
813
814 vspace = boxrect.bottom - boxrect.top;
815 vspace -= m_icon_height;
816 vspace /= 2;
817
818 if (IsOpen())
819 {
820 PaintIcon(dc, IDB_FOLDER_OPEN, boxrect.left, boxrect.top + vspace);
821 }
822 else
823 {
824 PaintIcon(dc, IDB_FOLDER_CLOSE, boxrect.left, boxrect.top + vspace);
825 }
826
827 boxrect.left += m_icon_width + ICON_HORZ_SPACE;
828
829 // Draw folder name
830 if (IsSelected())
831 {
832 //highlight selected item
833 dc->SetTextColor(GetSysColor(COLOR_HIGHLIGHTTEXT));
834
835 CBrush brush(GetSysColor(COLOR_HIGHLIGHT));
836 CRect rect = m_size;
837 rect.left = boxrect.left - 3;
838
839 //FillRect does not include the rectangle's right and bottom sides
840 dc->FillRect(&rect, &brush);
841 }
842 else
843 {
844 dc->SetTextColor(GetSysColor(COLOR_WINDOWTEXT));
845 }
846
847 dc->SetBkColor(RGB(0, 0, 0));
848 dc->SetBkMode(TRANSPARENT);
849
850 old_font = dc->SelectObject(&ViewHeaderFont);
851 dc->DrawText(mpRes->name, boxrect, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
852 dc->SelectObject(old_font);
853
854
855 CPen *old_pen;
856 CPen line_pen(PS_SOLID, 1, RGB(192, 192, 192));
857 old_pen = dc->SelectObject(&line_pen);
858
859 // Draw line across the bottom
860 dc->MoveTo(m_size.left, m_size.bottom);
861 dc->LineTo(m_size.right, m_size.bottom);
862 dc->SelectObject(old_pen);
863 }
864
865 ///////////////////////////////////////////////////////////////////////////////
PaintColorItemLines(CDC * dc,int offset)866 void resource_item::PaintColorItemLines(CDC *dc, int offset)
867 {
868 CPen *old_pen;
869
870 // draw vertical line
871 CPen line_pen(PS_SOLID, 1, RGB(192, 192, 192));
872 old_pen = dc->SelectObject(&line_pen);
873 dc->MoveTo(m_size.left + m_item_height + (COLOR_BOX_SPACE << 1),
874 m_size.top + offset);
875 dc->LineTo(m_size.left + m_item_height + (COLOR_BOX_SPACE << 1),
876 m_size.bottom);
877
878 // draw line across the bottom
879 dc->MoveTo(m_size.left, m_size.bottom);
880 dc->LineTo(m_size.right, m_size.bottom);
881 dc->SelectObject(old_pen);
882 }
883
884 ///////////////////////////////////////////////////////////////////////////////
PaintColorGroupColumnHeader(CDC * dc)885 void resource_item::PaintColorGroupColumnHeader(CDC *dc)
886 {
887 PaintColorItemLines(dc, m_header_height - 1);
888
889 // draw the text:
890 // column headers are always black on gray, no matter system color settings
891 dc->SetTextColor(RGB(0, 0, 0));
892 dc->SetBkMode(TRANSPARENT);
893
894 CFont *old_font = dc->SelectObject(&MediumFont);
895 dc->TextOut(m_size.left + m_item_height + (COLOR_BOX_SPACE << 1) + COLOR_TEXT_SPACE,
896 m_size.top + m_header_height + 2,
897 _T("Name"));
898 dc->SelectObject(old_font);
899 }
900
901 ///////////////////////////////////////////////////////////////////////////////
PaintColorItem(CDC * dc)902 void resource_item::PaintColorItem(CDC *dc)
903 {
904 CBrush boxbrush;
905 CBrush *old_brush;
906 CFont *old_font;
907
908 CPen line_pen(PS_SOLID, 1, RGB(192, 192, 192));
909 UINT nDrawFormat = DT_LEFT|DT_TOP|DT_SINGLELINE|DT_VCENTER;
910
911 PaintColorItemLines(dc, 0);
912
913 CRect boxrect = m_size;
914 boxrect.left += COLOR_BOX_SPACE;
915 boxrect.right = boxrect.left + m_item_height - 1;
916 boxrect.DeflateRect(2, 3);
917
918 boxbrush.CreateSolidBrush(m_boxcolor);
919
920 old_brush = dc->SelectObject(&boxbrush);
921
922 dc->Rectangle(boxrect);
923
924 boxrect.left = m_size.left + m_item_height + (COLOR_BOX_SPACE << 1) + COLOR_TEXT_SPACE;
925 boxrect.right = m_size.left + GetWidth(dc);
926
927 old_font = dc->SelectObject(&NormalFont);
928
929 dc->SetBkColor(GetSysColor(COLOR_WINDOW));
930
931 if (IsSelected())
932 {
933 //highlight selected item
934 dc->SetTextColor(GetSysColor(COLOR_HIGHLIGHTTEXT));
935
936 CBrush brush(GetSysColor(COLOR_HIGHLIGHT));
937 CRect rect = m_size;
938 rect.left = m_size.left + m_item_height + (COLOR_BOX_SPACE << 1) + 1;
939
940 //FillRect does not include the rectangle's right and bottom sides
941 dc->FillRect(&rect, &brush);
942 }
943 else
944 {
945 dc->SetTextColor(GetSysColor(COLOR_WINDOWTEXT));
946 }
947
948 dc->DrawText(mpRes->name, boxrect, nDrawFormat);
949
950 dc->SelectObject(old_font);
951 dc->SelectObject(old_brush);
952 }
953
954 ///////////////////////////////////////////////////////////////////////////////
PaintFontItemLines(CDC * dc,int offset)955 void resource_item::PaintFontItemLines(CDC *dc, int offset)
956 {
957 CPen *old_pen;
958
959 // draw vertical lines
960 CPen line_pen(PS_SOLID, 1, RGB(192, 192, 192));
961 old_pen = dc->SelectObject(&line_pen);
962 dc->MoveTo(m_size.left + m_font_preview_width,
963 m_size.top + offset);
964 dc->LineTo(m_size.left + m_font_preview_width,
965 m_size.bottom);
966 dc->MoveTo(m_size.left + m_font_preview_width + m_font_pixel_width,
967 m_size.top + offset);
968 dc->LineTo(m_size.left + m_font_preview_width + m_font_pixel_width,
969 m_size.bottom);
970 dc->MoveTo(m_size.right - m_font_storage_width,
971 m_size.top + offset);
972 dc->LineTo(m_size.right - m_font_storage_width,
973 m_size.bottom);
974
975 // draw line across the bottom
976 dc->MoveTo(m_size.left, m_size.bottom);
977 dc->LineTo(m_size.right, m_size.bottom);
978 dc->SelectObject(old_pen);
979 }
980
981 ///////////////////////////////////////////////////////////////////////////////
PaintFontGroupColumnHeader(CDC * dc)982 void resource_item::PaintFontGroupColumnHeader(CDC *dc)
983 {
984 PaintFontItemLines(dc, m_header_height - 1);
985
986 // draw the text:
987 // column headers are always black on gray, no matter system color settings
988 dc->SetTextColor(RGB(0, 0, 0));
989 dc->SetBkMode(TRANSPARENT);
990
991 CFont *old_font = dc->SelectObject(&MediumFont);
992 RECT rect = m_size;
993
994 rect.top += m_header_height + 2;
995 rect.left += 4;
996 rect.right = rect.left + m_font_preview_width - 8;
997 dc->DrawText(_T("View"), &rect, DT_LEFT | DT_SINGLELINE | DT_VCENTER);
998
999 rect.left = rect.right + 8;
1000 rect.right = rect.left + m_font_pixel_width - 8;
1001 dc->DrawText(_T("Pix"), &rect, DT_LEFT | DT_SINGLELINE | DT_VCENTER);
1002
1003 rect.left = rect.right + 8;
1004 rect.right = m_size.right - m_font_storage_width - 4;
1005 dc->DrawText(_T("Name"), &rect, DT_LEFT | DT_SINGLELINE | DT_VCENTER);
1006
1007 rect.left = rect.right + 8;
1008 rect.right = m_size.right - 4;
1009 dc->DrawText(_T("Size"), &rect, DT_RIGHT | DT_SINGLELINE | DT_VCENTER);
1010
1011 dc->SelectObject(old_font);
1012 }
1013
1014 ///////////////////////////////////////////////////////////////////////////////
PaintFontItem(CDC * dc)1015 void resource_item::PaintFontItem(CDC *dc)
1016 {
1017 CRect boxrect;
1018 CFont *old_font;
1019 TCHAR pix_size[20];
1020
1021 //Draw font preview
1022 boxrect = m_size;
1023 boxrect.left += 4;
1024 boxrect.right = m_size.left + m_font_preview_width - 4;
1025
1026 if (m_preview_mem)
1027 {
1028 int offset = (boxrect.Height() - m_bitmap.gx_bmp_header.biHeight) / 2;
1029 guix_bitmap_flush(dc->GetSafeHdc(), boxrect.left, boxrect.top + offset,
1030 boxrect.right - boxrect.left + 1, m_preview_mem, &m_bitmap);
1031 }
1032 else
1033 {
1034 dc->SetTextColor(GetSysColor(COLOR_WINDOWTEXT));
1035 dc->SetBkColor(GetSysColor(COLOR_WINDOW));
1036 dc->DrawText(mpRes->name, boxrect, DT_LEFT | DT_TOP | DT_SINGLELINE | DT_VCENTER);
1037 }
1038
1039 //Draw pix size
1040 if (IsSelected())
1041 {
1042 //highlight selected item
1043 dc->SetTextColor(GetSysColor(COLOR_HIGHLIGHTTEXT));
1044
1045 CBrush brush(GetSysColor(COLOR_HIGHLIGHT));
1046 CRect rect = m_size;
1047 rect.left = m_size.left + m_font_preview_width + 1;
1048
1049 //FillRect does not include the rectangle's right and bottom sides
1050 dc->FillRect(&rect, &brush);
1051 }
1052 else
1053 {
1054 dc->SetTextColor(GetSysColor(COLOR_WINDOWTEXT));
1055 }
1056
1057 PaintFontItemLines(dc, 0);
1058
1059 dc->SetBkColor(GetSysColor(COLOR_WINDOW));
1060 old_font = dc->SelectObject(&NormalFont);
1061 boxrect.left = boxrect.right + 8;
1062 boxrect.right = boxrect.left + m_font_pixel_width - 8;
1063 _itot(mpRes->font_height, pix_size, 10);
1064 dc->DrawText(pix_size, boxrect, DT_RIGHT | DT_TOP | DT_SINGLELINE | DT_VCENTER);
1065
1066 //Draw font name
1067 boxrect.left = boxrect.right + 8;
1068 boxrect.right = m_size.right - m_font_storage_width - 4;
1069 dc->DrawText(mpRes->name, boxrect, DT_LEFT | DT_TOP | DT_SINGLELINE | DT_VCENTER);
1070
1071 // Display resource storage.
1072 boxrect.left = boxrect.right + 8;
1073 boxrect.right = m_size.right - 4;
1074 int storage = (mpRes->storage_size + 1023) >> 10;
1075 CString str = NumberFormatWithCommas(storage);
1076 str.Append(_T("KB"));
1077 dc->DrawText(str, &boxrect, DT_RIGHT | DT_SINGLELINE | DT_VCENTER);
1078
1079 dc->SelectObject(old_font);
1080 }
1081
1082 ///////////////////////////////////////////////////////////////////////////////
PaintPixelmapItemLines(CDC * dc,int offset)1083 void resource_item::PaintPixelmapItemLines(CDC *dc, int offset)
1084 {
1085 CPen *old_pen;
1086 int xpos;
1087
1088 // draw vertical line
1089 CPen line_pen(PS_SOLID, 1, RGB(192, 192, 192));
1090 old_pen = dc->SelectObject(&line_pen);
1091
1092 xpos = m_size.left + m_thumbnail_size + (ITEM_VERT_SPACE * 2);
1093 dc->MoveTo(xpos, m_size.top + offset);
1094 dc->LineTo(xpos, m_size.bottom);
1095
1096 xpos += m_pixelmap_dimension_width;
1097 dc->MoveTo(xpos, m_size.top + offset);
1098 dc->LineTo(xpos, m_size.bottom);
1099
1100 xpos = m_size.right - m_pixelmap_storage_width;
1101 dc->MoveTo(xpos, m_size.top + offset);
1102 dc->LineTo(xpos, m_size.bottom);
1103
1104 // draw line across the bottom
1105 dc->MoveTo(m_size.left, m_size.bottom);
1106 dc->LineTo(m_size.right, m_size.bottom);
1107 dc->SelectObject(old_pen);
1108 }
1109
1110 ///////////////////////////////////////////////////////////////////////////////
PaintPixelmapGroupColumnHeader(CDC * dc)1111 void resource_item::PaintPixelmapGroupColumnHeader(CDC *dc)
1112 {
1113 PaintPixelmapItemLines(dc, m_header_height - 1);
1114
1115 // draw the text:
1116 dc->SetTextColor(RGB(0, 0, 0));
1117 dc->SetBkMode(TRANSPARENT);
1118
1119 CFont *old_font = dc->SelectObject(&MediumFont);
1120 RECT rect = m_size;
1121
1122 rect.top += m_header_height + 2;
1123 rect.left += 4;
1124 rect.right = rect.left + m_thumbnail_size + (ITEM_VERT_SPACE * 2) - 8;
1125 dc->DrawText(_T("View"), &rect, DT_LEFT | DT_SINGLELINE | DT_VCENTER);
1126
1127 rect.left = rect.right + 8;
1128 rect.right = rect.left + m_pixelmap_dimension_width - 8;
1129 dc->DrawText(_T("Dims"), &rect, DT_LEFT | DT_SINGLELINE | DT_VCENTER);
1130
1131 rect.left = rect.right + 8;
1132 rect.right = m_size.right - m_pixelmap_storage_width - 4;
1133 dc->DrawText(_T("Name"), &rect, DT_LEFT | DT_SINGLELINE | DT_VCENTER);
1134
1135 rect.left = rect.right + 8;
1136 rect.right = m_size.right - 4;
1137 dc->DrawText(_T("Size"), &rect, DT_RIGHT | DT_SINGLELINE | DT_VCENTER);
1138
1139 dc->SelectObject(old_font);
1140 }
1141
1142 ///////////////////////////////////////////////////////////////////////////////
PaintPixelmapItem(CDC * dc)1143 void resource_item::PaintPixelmapItem(CDC *dc)
1144 {
1145 CRect boxrect = m_size;
1146 boxrect.left += 4;
1147
1148 boxrect.right = boxrect.left + m_thumbnail_size + (ITEM_VERT_SPACE * 2) - 8;
1149
1150 // Draw pixelmap preview
1151 if (m_preview_mem)
1152 {
1153 int vspace = boxrect.bottom - boxrect.top + 1;
1154 vspace -= m_bitmap.gx_bmp_header.biHeight;
1155 vspace /= 2;
1156
1157 int hspace = m_thumbnail_size;
1158 hspace -= m_bitmap.gx_bmp_header.biWidth;
1159 hspace /= 2;
1160
1161 if (hspace < 0)
1162 {
1163 hspace = 0;
1164 }
1165
1166 guix_bitmap_flush(dc->GetSafeHdc(),
1167 boxrect.left + hspace,
1168 boxrect.top + vspace,
1169 boxrect.right - boxrect.left + 1,
1170 m_preview_mem, &m_bitmap);
1171 }
1172
1173 if (IsSelected())
1174 {
1175 //highlight selected item
1176 dc->SetTextColor(GetSysColor(COLOR_HIGHLIGHTTEXT));
1177
1178 CBrush brush(GetSysColor(COLOR_HIGHLIGHT));
1179 CRect rect = m_size;
1180 rect.left = m_size.left + m_thumbnail_size + (ITEM_VERT_SPACE * 2) + 1;
1181
1182 //FillRect does not include the rectangle's right and bottom sides
1183 dc->FillRect(&rect, &brush);
1184 }
1185 else
1186 {
1187 dc->SetTextColor(GetSysColor(COLOR_WINDOWTEXT));
1188 }
1189
1190 PaintPixelmapItemLines(dc, 0);
1191
1192 dc->SetBkMode(TRANSPARENT);
1193
1194 CFont *old_font = dc->SelectObject(&NormalFont);
1195
1196 CString str;
1197
1198 // Draw pixelmap size.
1199 boxrect.left = boxrect.right + 8;
1200 boxrect.right = boxrect.left + m_pixelmap_dimension_width - 8;
1201 GX_PIXELMAP* map = mpRes->GetPixelmap();
1202 if (map)
1203 {
1204 str.Format(_T("%d x %d"), map->gx_pixelmap_width, map->gx_pixelmap_height);
1205 dc->DrawText(str, &boxrect, DT_LEFT | DT_SINGLELINE | DT_VCENTER);
1206 }
1207
1208 // Draw pixelmap name.
1209 boxrect.left = boxrect.right + 8;
1210 boxrect.right = m_size.right - m_pixelmap_storage_width - 4;
1211 dc->DrawText(mpRes->name, &boxrect, DT_LEFT | DT_SINGLELINE | DT_VCENTER);
1212
1213 // Draw resource storage size.
1214 boxrect.left = boxrect.right + 8;
1215 boxrect.right = m_size.right - 8;
1216 int storage = (mpRes->storage_size + 1023) >> 10;
1217 str = NumberFormatWithCommas(storage);
1218 str.Append(_T("KB"));
1219 dc->DrawText(str, &boxrect, DT_RIGHT | DT_SINGLELINE | DT_VCENTER);
1220 dc->SelectObject(old_font);
1221 }
1222
1223 ///////////////////////////////////////////////////////////////////////////////
PaintStringItemLines(CDC * dc,int offset)1224 void resource_item::PaintStringItemLines(CDC *dc, int offset)
1225 {
1226 CPen *old_pen;
1227
1228 // draw vertical lines
1229 CPen line_pen(PS_SOLID, 1, RGB(192, 192, 192));
1230 old_pen = dc->SelectObject(&line_pen);
1231 dc->MoveTo(m_size.left + m_string_id_width,
1232 m_size.top + offset);
1233 dc->LineTo(m_size.left + m_string_id_width,
1234 m_size.bottom);
1235
1236 // draw line across the bottom
1237 dc->MoveTo(m_size.left, m_size.bottom);
1238 dc->LineTo(m_size.right, m_size.bottom);
1239 dc->SelectObject(old_pen);
1240 }
1241
1242 ///////////////////////////////////////////////////////////////////////////////
PaintStringGroupColumnHeader(CDC * dc)1243 void resource_item::PaintStringGroupColumnHeader(CDC *dc)
1244 {
1245 PaintStringItemLines(dc, m_header_height - 1);
1246 CRect textrect;
1247 int xpos;
1248
1249 // draw the text:
1250 // column headers are always white on gray, no matter the system color settings.
1251 dc->SetTextColor(RGB(0, 0, 0));
1252 dc->SetBkMode(TRANSPARENT);
1253
1254 CFont *old_font = dc->SelectObject(&MediumFont);
1255 dc->TextOut(m_size.left + 4,
1256 m_size.top + m_header_height + 2,
1257 _T("String ID"));
1258
1259 studiox_project *project = GetOpenProject();
1260 if (project && mpRes)
1261 {
1262 int display = project->GetDisplayIndex(mpRes);
1263 if (display < 0)
1264 {
1265 return;
1266 }
1267 string_table *table = project->mDisplays[display].stable;
1268 if (!table)
1269 {
1270 return;
1271 }
1272
1273 int language = table->GetActiveLanguage();
1274
1275 xpos = m_size.left + m_string_id_width + 4;
1276 textrect.SetRect(xpos, m_size.top + m_header_height + 2,
1277 m_size.right - 32, m_size.bottom);
1278
1279 dc->DrawText(project->mHeader.languages[language].name, &textrect, DT_LEFT);
1280
1281 CBitmap map;
1282 BITMAP bmp;
1283
1284 map.LoadBitmap(IDB_RIGHT_ARROW);
1285 map.GetBitmap(&bmp);
1286
1287 int dpi = GetSystemDPI();
1288 m_string_arrow_icon_width = MulDiv(bmp.bmWidth, dpi, DEFAULT_DPI_96);
1289
1290 xpos = m_size.right - m_string_arrow_icon_width;
1291 PaintBmp(dc, xpos, m_size.top + m_header_height + 6, IDB_RIGHT_ARROW);
1292 xpos -= m_string_arrow_icon_width;
1293 PaintBmp(dc, xpos, m_size.top + m_header_height + 6, IDB_LEFT_ARROW);
1294 }
1295 dc->SelectObject(old_font);
1296 }
1297
1298
1299 ///////////////////////////////////////////////////////////////////////////////
PaintStringItem(CDC * dc)1300 void resource_item::PaintStringItem(CDC *dc)
1301 {
1302
1303 int left = m_size.left + 4;
1304 CRect textrect = m_size;
1305 textrect.left += 4;
1306 textrect.right = m_size.left + m_string_id_width - 4;
1307
1308
1309 if (IsSelected())
1310 {
1311 //highlight selected item
1312 dc->SetTextColor(GetSysColor(COLOR_HIGHLIGHTTEXT));
1313
1314 CBrush brush(GetSysColor(COLOR_HIGHLIGHT));
1315
1316 //FillRect does not include the rectangle's right and bottom sides
1317 dc->FillRect(&m_size, &brush);
1318 }
1319 else
1320 {
1321 dc->SetTextColor(GetSysColor(COLOR_WINDOWTEXT));
1322 }
1323
1324 PaintStringItemLines(dc, 0);
1325
1326 CFont *old_font = dc->SelectObject(&NormalFont);
1327
1328 dc->DrawText(display_id, &textrect, DT_LEFT|DT_SINGLELINE|DT_VCENTER);
1329
1330 textrect.left = m_size.left + m_string_id_width + 4;
1331 textrect.right = m_size.right - 4;
1332
1333 #ifdef _UNICODE
1334 DrawTextW(*dc, string_val.GetString(), -1, &textrect, DT_LEFT | DT_SINGLELINE | DT_VCENTER);
1335 #else
1336 wchar_t *uni_text = CStringToWideChar(string_val);
1337
1338 if (uni_text)
1339 {
1340 DrawTextW(*dc, uni_text, -1, &textrect, DT_LEFT|DT_SINGLELINE|DT_VCENTER);
1341 delete [] uni_text;
1342 }
1343 #endif
1344 dc->SelectObject(old_font);
1345 }
1346
1347 ///////////////////////////////////////////////////////////////////////////////
PaintAddNewItem(CDC * dc)1348 void resource_item::PaintAddNewItem(CDC* dc)
1349 {
1350 CFont *old_font = dc->SelectObject(&NormalFont);
1351 int icon_id = m_icon_id;
1352
1353 if (IsSelected())
1354 {
1355 //highlight selected item
1356 dc->SetTextColor(GetSysColor(COLOR_HIGHLIGHTTEXT));
1357
1358 CBrush brush(GetSysColor(COLOR_HIGHLIGHT));
1359
1360
1361 //FillRect does not include the rectangle's right and bottom sides
1362 dc->FillRect(&m_size, &brush);
1363
1364 if (m_icon_id_highlight)
1365 {
1366 icon_id = m_icon_id_highlight;
1367 }
1368 }
1369 else
1370 {
1371 dc->SetTextColor(GetSysColor(COLOR_MENUTEXT));
1372 }
1373
1374 if (icon_id)
1375 {
1376 int offset = (m_size.Height() - m_icon_height) >> 1;
1377 PaintIcon(dc, icon_id, m_size.left + 8, m_size.top + offset);
1378 }
1379
1380 CRect boxrect = m_size;
1381 boxrect.left += m_icon_width + 16;
1382
1383 dc->SetBkColor(GetSysColor(COLOR_WINDOW));
1384 dc->DrawText(mpRes->name, &boxrect, DT_LEFT | DT_SINGLELINE | DT_VCENTER);
1385 dc->SelectObject(old_font);
1386 }
1387
1388 ///////////////////////////////////////////////////////////////////////////////
Paint(CDC * dc)1389 void resource_item::Paint(CDC *dc)
1390 {
1391 if (m_visible)
1392 {
1393 int type = GetResType();
1394
1395 switch(type)
1396 {
1397 case RES_TYPE_HEADER:
1398 if (mpRes->folder_id == THEME_HEADER)
1399 {
1400 PaintThemeHeader(dc);
1401 }
1402 break;
1403
1404 case RES_TYPE_GROUP:
1405 PaintGroupHeader(dc);
1406 if (m_open)
1407 {
1408 switch(mpRes->folder_id)
1409 {
1410 case COLOR_GROUP:
1411 PaintColorGroupColumnHeader(dc);
1412 break;
1413
1414 case FONT_GROUP:
1415 PaintFontGroupColumnHeader(dc);
1416 break;
1417
1418 case PIXELMAP_GROUP:
1419 PaintPixelmapGroupColumnHeader(dc);
1420 break;
1421
1422 case STRING_GROUP:
1423 PaintStringGroupColumnHeader(dc);
1424 break;
1425
1426 default:
1427 break;
1428 }
1429 }
1430 break;
1431
1432 case RES_TYPE_FOLDER:
1433 if ((mpRes->folder_id == DEFAULT_PIXELMAP_FOLDER) ||
1434 (mpRes->folder_id == CUSTOM_PIXELMAP_FOLDER))
1435 {
1436 PaintFolderHeader(dc);
1437 }
1438 break;
1439
1440 case RES_TYPE_COLOR:
1441 PaintColorItem(dc);
1442 break;
1443
1444 case RES_TYPE_FONT:
1445 PaintFontItem(dc);
1446 break;
1447
1448 case RES_TYPE_PIXELMAP:
1449 PaintPixelmapItem(dc);
1450 break;
1451
1452 case RES_TYPE_STRING:
1453 PaintStringItem(dc);
1454 break;
1455
1456 case RES_TYPE_ADD_COLOR:
1457 case RES_TYPE_ADD_FONT:
1458 case RES_TYPE_ADD_PIXELMAP:
1459 case RES_TYPE_ADD_STRING:
1460 PaintAddNewItem(dc);
1461 break;
1462
1463 default:
1464 break;
1465 }
1466
1467 if (m_open && m_first)
1468 {
1469 m_first->Paint(dc);
1470 }
1471 }
1472 if (m_next)
1473 {
1474 m_next->Paint(dc);
1475 }
1476 }
1477
1478 ///////////////////////////////////////////////////////////////////////////////
GetItemHeight()1479 int resource_item::GetItemHeight()
1480 {
1481 return m_item_height;
1482 }
1483
1484 ///////////////////////////////////////////////////////////////////////////////
GetHeight()1485 int resource_item::GetHeight()
1486 {
1487 int height = 0;
1488 int type = RES_TYPE_STRING;
1489
1490 if (mpRes)
1491 {
1492 type = mpRes->type;
1493 }
1494 switch(type)
1495 {
1496 case RES_TYPE_HEADER:
1497 if (mpRes->folder_id == THEME_HEADER)
1498 {
1499 return m_header_height;
1500 }
1501 else
1502 {
1503 return 0;
1504 }
1505 break;
1506
1507 case RES_TYPE_GROUP:
1508 if (m_open)
1509 {
1510 return m_header_height + m_item_height;
1511 }
1512 else
1513 {
1514 return m_header_height;
1515 }
1516 break;
1517
1518 case RES_TYPE_STRING:
1519 case RES_TYPE_COLOR:
1520 case RES_TYPE_ADD_COLOR:
1521 case RES_TYPE_ADD_FONT:
1522 case RES_TYPE_ADD_PIXELMAP:
1523 case RES_TYPE_ADD_STRING:
1524 height = m_item_height;
1525 break;
1526
1527 case RES_TYPE_FOLDER:
1528 if ((mpRes->folder_id == DEFAULT_PIXELMAP_FOLDER) ||
1529 (mpRes->folder_id == CUSTOM_PIXELMAP_FOLDER))
1530 {
1531 return m_header_height;
1532 }
1533
1534 return 0;
1535
1536 case RES_TYPE_FONT:
1537 if (!m_preview_mem)
1538 {
1539 MakeFontPreview();
1540 }
1541 if (m_preview_mem)
1542 {
1543 height = MulDiv(m_bitmap.gx_bmp_header.biHeight, m_sys_dpi, DEFAULT_DPI_96) + 4;
1544 }
1545 else
1546 {
1547 height = m_item_height;
1548 }
1549 break;
1550
1551 case RES_TYPE_PIXELMAP:
1552 if (!m_preview_mem)
1553 {
1554 MakePixelmapPreview();
1555 }
1556 height = m_item_height;
1557 if (m_preview_mem)
1558 {
1559 if (m_bitmap.gx_bmp_header.biHeight > height)
1560 {
1561 height = m_bitmap.gx_bmp_header.biHeight;
1562 }
1563 }
1564 height += ITEM_VERT_SPACE * 2;
1565 break;
1566
1567 default:
1568 break;
1569 }
1570 return height;
1571 }
1572
1573 ///////////////////////////////////////////////////////////////////////////////
GetWidth(CDC * dc)1574 int resource_item::GetWidth(CDC *dc)
1575 {
1576 CFont *old_font;
1577 int width = 0;
1578 int type = RES_TYPE_STRING;
1579
1580 if (mpRes)
1581 {
1582 type = mpRes->type;
1583 }
1584 switch(type)
1585 {
1586 case RES_TYPE_HEADER:
1587 break;
1588
1589 case RES_TYPE_GROUP:
1590 width = 8 + (m_indent * TREE_INDENT);
1591 old_font = dc->SelectObject(&MediumFont);
1592 width += dc->GetTextExtent(mpRes->name).cx;
1593 dc->SelectObject(old_font);
1594 break;
1595
1596 case RES_TYPE_COLOR:
1597 width = m_item_height + (COLOR_BOX_SPACE << 1);
1598 width += dc->GetTextExtent(mpRes->name).cx + (COLOR_TEXT_SPACE << 1);
1599 if (width < mpTree->GetViewWidth())
1600 {
1601 width = mpTree->GetViewWidth();
1602 }
1603 break;
1604
1605 case RES_TYPE_FONT:
1606 if (!m_preview_mem)
1607 {
1608 MakeFontPreview();
1609 }
1610 if (m_preview_mem)
1611 {
1612 width = m_bitmap.gx_bmp_header.biWidth + 8;
1613 }
1614 else
1615 {
1616 old_font = dc->SelectObject(&NormalFont);
1617 width = dc->GetTextExtent(mpRes->name).cx;
1618 dc->SelectObject(old_font);
1619 }
1620 if (width < mpTree->GetViewWidth())
1621 {
1622 width = mpTree->GetViewWidth();
1623 }
1624 break;
1625
1626 case RES_TYPE_PIXELMAP:
1627 width = mpTree->GetViewWidth();
1628
1629 break;
1630
1631 case RES_TYPE_STRING:
1632 width = 8 + (m_indent * TREE_INDENT);
1633 width += dc->GetTextExtent(display_id).cx;
1634 width += dc->GetTextExtent(string_val).cx;
1635 break;
1636
1637 default:
1638 width = 8 + (m_indent * TREE_INDENT);
1639 old_font = dc->SelectObject(&NormalFont);
1640 width += dc->GetTextExtent(mpRes->name).cx;
1641 dc->SelectObject(old_font);
1642 break;
1643 }
1644 return width;
1645 }
1646
1647 #if 0
1648 int resource_item::LayoutColorGrid(int top)
1649 {
1650 CRect childsize;
1651 int step = COLOR_BOX_SIZE + COLOR_BOX_SPACE;
1652 top += COLOR_BOX_SPACE;
1653
1654 childsize.SetRect(m_size.left + COLOR_BOX_SPACE,
1655 top,
1656 m_size.left + step - 1,
1657 top + COLOR_BOX_SIZE - 1);
1658
1659 resource_item *child = First();
1660
1661 while(child)
1662 {
1663 child->SetPos(childsize);
1664
1665 if (childsize.right + step > m_size.right)
1666 {
1667 top += step;
1668 childsize.SetRect(m_size.left + COLOR_BOX_SPACE,
1669 top,
1670 m_size.left + step - 1,
1671 top + COLOR_BOX_SIZE - 1);
1672 }
1673 else
1674 {
1675 childsize.OffsetRect(step, 0);
1676 }
1677 child = child->Next();
1678 }
1679
1680 if (mpRes->resource_id == CUSTOM_COLOR_FOLDER)
1681 {
1682 if (childsize.right + step > m_size.right)
1683 {
1684 top += step;
1685 m_add_icon_y = top;
1686 m_add_icon_x = m_size.left + COLOR_BOX_SPACE;
1687 }
1688 else
1689 {
1690 m_add_icon_y = top;
1691 m_add_icon_x = childsize.left;
1692 }
1693 }
1694 return top + step;
1695 }
1696 #endif
1697
1698 ///////////////////////////////////////////////////////////////////////////////
SortFirst()1699 resource_item *resource_item::SortFirst()
1700 {
1701 resource_item *winner = NULL;
1702 resource_item *child = First();
1703
1704 while(child)
1705 {
1706 switch(child->GetResType())
1707 {
1708 case RES_TYPE_ADD_COLOR:
1709 case RES_TYPE_ADD_FONT:
1710 case RES_TYPE_ADD_PIXELMAP:
1711 case RES_TYPE_ADD_STRING:
1712 break;
1713
1714 default:
1715 if (!winner)
1716 {
1717 winner = child;
1718 }
1719 else
1720 {
1721 if (_tcscmp(child->mpRes->name, winner->mpRes->name) < 0)
1722 {
1723 winner = child;
1724 }
1725 }
1726 break;
1727 }
1728
1729 child = child->Next();
1730 }
1731
1732 return winner;
1733 }
1734
1735 ///////////////////////////////////////////////////////////////////////////////
SortNext(resource_item * current)1736 resource_item *resource_item::SortNext(resource_item *current)
1737 {
1738 resource_item *winner = NULL;
1739 resource_item *child = First();
1740
1741 while(child)
1742 {
1743 switch (child->GetResType())
1744 {
1745 case RES_TYPE_ADD_COLOR:
1746 case RES_TYPE_ADD_FONT:
1747 case RES_TYPE_ADD_PIXELMAP:
1748 case RES_TYPE_ADD_STRING:
1749 break;
1750
1751 default:
1752 if (_tcscmp(child->mpRes->name, current->mpRes->name) > 0)
1753 {
1754 if (!winner)
1755 {
1756 winner = child;
1757 }
1758 else
1759 {
1760 if (_tcscmp(child->mpRes->name, winner->mpRes->name) < 0)
1761 {
1762 winner = child;
1763 }
1764 }
1765 }
1766 break;
1767 }
1768
1769 child = child->Next();
1770 }
1771 return winner;
1772 }
1773
1774 ///////////////////////////////////////////////////////////////////////////////
FindAddNewItem()1775 resource_item* resource_item::FindAddNewItem()
1776 {
1777 resource_item* child = First();
1778
1779 while (child)
1780 {
1781 switch (child->GetResType())
1782 {
1783 case RES_TYPE_ADD_COLOR:
1784 case RES_TYPE_ADD_FONT:
1785 case RES_TYPE_ADD_PIXELMAP:
1786 case RES_TYPE_ADD_STRING:
1787 return child;
1788
1789 default:
1790 break;
1791 }
1792
1793 child = child->Next();
1794 }
1795
1796 return NULL;
1797 }
1798
1799 ///////////////////////////////////////////////////////////////////////////////
NavigateFirst()1800 resource_item* resource_item::NavigateFirst()
1801 {
1802 resource_item* first = NULL;
1803
1804 switch (GetResType())
1805 {
1806 case RES_TYPE_FOLDER:
1807 first = SortFirst();
1808 break;
1809
1810 case RES_TYPE_GROUP:
1811 first = First();
1812
1813 if (first->GetResType() == RES_TYPE_FOLDER)
1814 {
1815 switch (first->mpRes->folder_id)
1816 {
1817 case DEFAULT_COLOR_FOLDER:
1818 case CUSTOM_COLOR_FOLDER:
1819 case DEFAULT_FONT_FOLDER:
1820 case CUSTOM_FONT_FOLDER:
1821 // Skip folders which is invisible.
1822 first = first->SortFirst();
1823 break;
1824 }
1825 }
1826 break;
1827
1828 default:
1829 first = First();
1830 break;
1831 }
1832
1833 return first;
1834 }
1835
1836 ///////////////////////////////////////////////////////////////////////////////
NavigateLast()1837 resource_item* resource_item::NavigateLast()
1838 {
1839 resource_item* last = NULL;
1840 resource_item* next;
1841
1842 switch (GetResType())
1843 {
1844 case RES_TYPE_FOLDER:
1845 if (mpRes->folder_id == CUSTOM_PIXELMAP_FOLDER)
1846 {
1847 last = FindAddNewItem();
1848 }
1849 else
1850 {
1851 next = SortFirst();
1852 do
1853 {
1854 last = next;
1855 next = SortNext(last);
1856 } while (next);
1857 }
1858 break;
1859
1860 case RES_TYPE_GROUP:
1861 last = Last();
1862
1863 if (last->GetResType() == RES_TYPE_FOLDER)
1864 {
1865 switch (last->mpRes->folder_id)
1866 {
1867 case DEFAULT_COLOR_FOLDER:
1868 case CUSTOM_COLOR_FOLDER:
1869 case DEFAULT_FONT_FOLDER:
1870 case CUSTOM_FONT_FOLDER:
1871 // Skip folders which is invisible.
1872 last = last->FindAddNewItem();
1873 break;
1874 }
1875 }
1876 break;
1877
1878 default:
1879 last = Last();
1880 break;
1881 }
1882
1883 return last;
1884 }
1885
1886 ///////////////////////////////////////////////////////////////////////////////
NavigateNext()1887 resource_item* resource_item::NavigateNext()
1888 {
1889 resource_item* next = NULL;
1890 resource_item* parent;
1891 switch (GetResType())
1892 {
1893 case RES_TYPE_FONT:
1894 case RES_TYPE_COLOR:
1895 case RES_TYPE_PIXELMAP:
1896 // Pick parent item.
1897 parent = Parent();
1898 if (parent->GetResType() == RES_TYPE_FOLDER)
1899 {
1900 // Sort next item.
1901 next = parent->SortNext(this);
1902
1903 if (next == NULL)
1904 {
1905 switch (parent->mpRes->folder_id)
1906 {
1907 case DEFAULT_COLOR_FOLDER:
1908 case DEFAULT_FONT_FOLDER:
1909 // Set the first custom color/font item to be the next sibling of the last default color/font item.
1910 parent = parent->Next();
1911
1912 if (parent)
1913 {
1914 next = parent->SortFirst();
1915 }
1916 break;
1917 }
1918
1919 if (next == NULL)
1920 {
1921 next = parent->FindAddNewItem();
1922 }
1923 }
1924 }
1925 break;
1926
1927 case RES_TYPE_ADD_COLOR:
1928 case RES_TYPE_ADD_FONT:
1929 case RES_TYPE_ADD_PIXELMAP:
1930 case RES_TYPE_ADD_STRING:
1931 break;
1932
1933 default:
1934 next = Next();
1935 break;
1936 }
1937
1938 return next;
1939 }
1940
1941 ///////////////////////////////////////////////////////////////////////////////
NavigateParent()1942 resource_item* resource_item::NavigateParent()
1943 {
1944 int restype = GetResType();
1945
1946 if (restype == RES_TYPE_HEADER ||
1947 restype == RES_TYPE_GROUP)
1948 {
1949 return NULL;
1950 }
1951
1952 resource_item* parent = Parent();
1953
1954 if (parent && parent->GetResType() == RES_TYPE_FOLDER)
1955 {
1956 switch (parent->mpRes->folder_id)
1957 {
1958 case DEFAULT_COLOR_FOLDER:
1959 case CUSTOM_COLOR_FOLDER:
1960 case DEFAULT_FONT_FOLDER:
1961 case CUSTOM_FONT_FOLDER:
1962 // Skip folders which is invisible
1963 parent = parent->Parent();
1964 break;
1965 }
1966 }
1967
1968 return parent;
1969 }
1970
1971 ///////////////////////////////////////////////////////////////////////////////
LayoutFolderChildren(CDC * dc,int top)1972 int resource_item::LayoutFolderChildren(CDC *dc, int top)
1973 {
1974 resource_item *child;
1975 CRect size;
1976 int height;
1977 int width;
1978
1979 child = SortFirst();
1980 while(child)
1981 {
1982 height = child->GetHeight();
1983 width = child->GetWidth(dc);
1984 size.SetRect(0, top, width, top + height - 1);
1985 child->SetPos(size);
1986 top += height;
1987
1988 child = SortNext(child);
1989 }
1990
1991 resource_item* pAdd = FindAddNewItem();
1992 if (pAdd)
1993 {
1994 //position "Add New" icon
1995 height = pAdd->GetHeight();
1996 width = mpTree->GetViewWidth();
1997 size.SetRect(0, top, width, top + height);
1998 pAdd->SetPos(size);
1999 top += height;
2000 }
2001
2002 return top;
2003 }
2004
2005
2006 ///////////////////////////////////////////////////////////////////////////////
CheckClickCommand(CPoint & click)2007 int resource_item::CheckClickCommand(CPoint &click)
2008 {
2009 CRect size;
2010
2011 if (!mpRes)
2012 {
2013 return CMD_NO_COMMAND;
2014 }
2015
2016 if ((mpRes->type == RES_TYPE_HEADER) &&
2017 (mpRes->folder_id == THEME_HEADER))
2018 {
2019 if (m_up_icon_rect.PtInRect(click))
2020 {
2021 return CMD_INC_THEME;
2022 }
2023 else if (m_down_icon_rect.PtInRect(click))
2024 {
2025 return CMD_DEC_THEME;
2026 }
2027 }
2028 else if (mpRes->type == RES_TYPE_GROUP &&
2029 mpRes->folder_id == STRING_GROUP)
2030 {
2031 // test here for inc/dec language commands:
2032
2033 size.right = m_size.right;
2034 size.left = size.right - m_string_arrow_icon_width;
2035 size.top = m_size.top + m_header_height + 6;
2036 size.bottom = size.top + m_string_arrow_icon_width;
2037
2038 if (size.PtInRect(click))
2039 {
2040 return CMD_INC_LANGUAGE;
2041 }
2042 size.OffsetRect(-12, 0);
2043 if (size.PtInRect(click))
2044 {
2045 return CMD_DEC_LANGUAGE;
2046 }
2047 }
2048
2049 return CMD_NO_COMMAND;
2050 }
2051
2052 ///////////////////////////////////////////////////////////////////////////////
SetColorValue(GX_COLOR val)2053 void resource_item::SetColorValue(GX_COLOR val)
2054 {
2055 if (mpRes)
2056 {
2057 mpRes->colorval = val;
2058 RebuildPreview();
2059 }
2060 }
2061
2062 ///////////////////////////////////////////////////////////////////////////////
SetIcon(int IconId,int IconIdHighlight)2063 void resource_item::SetIcon(int IconId, int IconIdHighlight)
2064 {
2065 m_icon_id = IconId;
2066 m_icon_id_highlight = IconIdHighlight;
2067 CBitmap icon;
2068
2069 BITMAP bmp;
2070
2071 if (IconId)
2072 {
2073 if (icon.LoadBitmap(IconId))
2074 {
2075 icon.GetBitmap(&bmp);
2076 m_icon_width = MulDiv(bmp.bmWidth, m_sys_dpi, DEFAULT_DPI_96);
2077 m_icon_height = MulDiv(bmp.bmHeight, m_sys_dpi, DEFAULT_DPI_96);
2078 }
2079 }
2080 }
2081
2082 ///////////////////////////////////////////////////////////////////////////////
MakeColorRef(GX_COLOR val)2083 COLORREF resource_item::MakeColorRef(GX_COLOR val)
2084 {
2085 UCHAR Red = (UCHAR) (val >> 16);
2086 UCHAR Green = (UCHAR) ((val >> 8) & 0xff);
2087 UCHAR Blue = (UCHAR) (val & 0xff);
2088 return(RGB(Red, Green, Blue));
2089 }
2090
2091 ///////////////////////////////////////////////////////////////////////////////
GetRGBColor(int display_index)2092 GX_COLOR resource_item::GetRGBColor(int display_index)
2093 {
2094 GX_COLOR *palette;
2095 int palsize;
2096 GX_COLOR color = 0;
2097 studiox_project *project = GetOpenProject();
2098
2099 if (mpRes == NULL || project == NULL)
2100 {
2101 return color;
2102 }
2103 if (mpRes->type != RES_TYPE_COLOR)
2104 {
2105 return color;
2106 }
2107
2108 if (display_index == -1)
2109 {
2110 display_index = project->GetDisplayIndex(mpRes);
2111 }
2112
2113 /* only 8bit driver need get rgb color from palette table now.
2114 4bpp driver contains palette table but we can calculate its gray value directly. */
2115 if (project->mDisplays[display_index].colorformat == GX_COLOR_FORMAT_8BIT_PALETTE)
2116 {
2117 int active_theme = project->mDisplays[display_index].active_theme;
2118
2119 // colorval is a palette index, lookup rgb and convert to COLORREF
2120 palette = project->mDisplays[display_index].themes[active_theme].palette;
2121 palsize = project->mDisplays[display_index].themes[active_theme].palette_predefined;
2122
2123 if ((ULONG) mpRes->colorval >= (ULONG) palsize)
2124 {
2125 /* this should not be allowed to happen, but just as a safety check
2126 if the palette size has been changed and we didn't update the color
2127 indexes correctly, do a final safety check here
2128 */
2129 mpRes->colorval = 0;
2130 }
2131
2132 if (palette && ((int) mpRes->colorval >= 0 && (int) mpRes->colorval < palsize))
2133 {
2134 color = palette[mpRes->colorval];
2135 }
2136 }
2137 else
2138 {
2139 color = mpRes->colorval;
2140 }
2141
2142 if (!IsAlphaFormat(project->mDisplays[display_index].colorformat))
2143 {
2144 color |= 0xff000000;
2145 }
2146 return color;
2147 }
2148
2149 ///////////////////////////////////////////////////////////////////////////////
GetResType()2150 int resource_item::GetResType()
2151 {
2152 if (mpRes)
2153 {
2154 return mpRes->type;
2155 }
2156
2157 return RES_TYPE_STRING;
2158 }
2159
2160 ///////////////////////////////////////////////////////////////////////////////
GetResItemProvider()2161 resource_item_provider* resource_item::GetResItemProvider()
2162 {
2163 if (m_pResItemProvider == NULL)
2164 {
2165 m_pResItemProvider = new resource_item_provider(this);
2166 }
2167 return m_pResItemProvider;
2168 }
2169
2170 ///////////////////////////////////////////////////////////////////////////////
GetName()2171 CString resource_item::GetName()
2172 {
2173 int type = GetResType();
2174
2175 switch(type)
2176 {
2177 case RES_TYPE_STRING:
2178 return string_val;
2179 }
2180
2181 if (mpRes)
2182 {
2183 return mpRes->name;
2184 }
2185
2186 return _T("");
2187 }
2188
2189 ///////////////////////////////////////////////////////////////////////////////
GetDescription()2190 CString resource_item::GetDescription()
2191 {
2192 int type = GetResType();
2193 CString description(L"");
2194
2195 switch (type)
2196 {
2197 case RES_TYPE_FONT:
2198 if (mpRes)
2199 {
2200 description.Format(L"Pix: %d, Name: %s, Size: %d kilobyte", mpRes->font_height, mpRes->name, (mpRes->storage_size + 1023) >> 10);
2201 }
2202 break;
2203
2204 case RES_TYPE_PIXELMAP:
2205 if(mpRes)
2206 {
2207 GX_PIXELMAP *map = mpRes->GetPixelmap();
2208 if (map)
2209 {
2210 description.Format(L"Dims: %d by %d, Name: %s, Size: %d kilobyte", map->gx_pixelmap_width, map->gx_pixelmap_height, mpRes->name,
2211 (mpRes->storage_size + 1023) >> 10);
2212 }
2213 }
2214 break;
2215
2216 case RES_TYPE_STRING:
2217 description.Format(L"String ID: %s, String value: %s", string_id, string_val);
2218 break;
2219 }
2220
2221 return description;
2222 }
2223
2224 ///////////////////////////////////////////////////////////////////////////////
PaintHighlightRect(CDC * dc,CRect * rect)2225 void resource_item::PaintHighlightRect(CDC* dc, CRect *rect)
2226 {
2227 //Draw a blue rectangle to highlight the item
2228 CPen penBlue(PS_SOLID, 2, GetSysColor(COLOR_HIGHLIGHT));
2229 CPen *pOldPen = dc->SelectObject(&penBlue);
2230 CBrush *pOldBrush = (CBrush *)dc->SelectStockObject(NULL_BRUSH);
2231
2232 dc->Rectangle(*rect);
2233 dc->SelectObject(pOldPen);
2234 dc->SelectObject(pOldBrush);
2235 }
2236
2237 ///////////////////////////////////////////////////////////////////////////////
IsSelected()2238 BOOL resource_item::IsSelected()
2239 {
2240 resource_view* view = GetResourceView();
2241
2242 if (view && (GetFocus() == view->GetSafeHwnd()) && (mpTree->GetCurrentItem() == this))
2243 {
2244 return TRUE;
2245 }
2246
2247 return FALSE;
2248 }
2249
2250 ///////////////////////////////////////////////////////////////////////////////
IsAlphaFormat(int color_format)2251 BOOL resource_item::IsAlphaFormat(int color_format)
2252 {
2253 if (color_format == GX_COLOR_FORMAT_32ARGB ||
2254 color_format == GX_COLOR_FORMAT_32BGRA ||
2255 color_format == GX_COLOR_FORMAT_4444ARGB ||
2256 color_format == GX_COLOR_FORMAT_4444BGRA)
2257 {
2258 return TRUE;
2259 }
2260 return FALSE;
2261 }