6ba23375ebb0d4c537111d3702b924421e235722
[reactos.git] / base / applications / mspaint / toolbox.cpp
1 /*
2 * PROJECT: PAINT for ReactOS
3 * LICENSE: LGPL
4 * FILE: base/applications/mspaint/toolbox.cpp
5 * PURPOSE: Window procedure of the main window and all children apart from
6 * hPalWin, hToolSettings and hSelection
7 * PROGRAMMERS: Benedikt Freisen
8 */
9
10 #include "precomp.h"
11
12 CToolBox toolBoxContainer;
13
14 /* FUNCTIONS ********************************************************/
15
16 BOOL CToolBox::DoCreate(HWND hwndParent)
17 {
18 RECT toolBoxContainerPos = { 0, 0, 0, 0 };
19 DWORD style = WS_CHILD | (registrySettings.ShowToolBox ? WS_VISIBLE : 0);
20 return !!Create(hwndParent, toolBoxContainerPos, NULL, style);
21 }
22
23 LRESULT CToolBox::OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
24 {
25 HIMAGELIST hImageList;
26 HBITMAP tempBm;
27 int i;
28 TCHAR tooltips[NUM_TOOLS][30];
29
30 toolSettingsWindow.DoCreate(m_hWnd);
31
32 /* NOTE: The horizontal line above the toolbar is hidden by CCS_NODIVIDER style. */
33 RECT toolbarPos = {0, 0, CX_TOOLBAR, CY_TOOLBAR};
34 DWORD style = WS_CHILD | WS_VISIBLE | CCS_NOPARENTALIGN | CCS_VERT | CCS_NORESIZE |
35 TBSTYLE_TOOLTIPS | TBSTYLE_FLAT;
36 toolbar.Create(TOOLBARCLASSNAME, m_hWnd, toolbarPos, NULL, style);
37 hImageList = ImageList_Create(16, 16, ILC_COLOR24 | ILC_MASK, 16, 0);
38 toolbar.SendMessage(TB_SETIMAGELIST, 0, (LPARAM) hImageList);
39 tempBm = (HBITMAP) LoadImage(hProgInstance, MAKEINTRESOURCE(IDB_TOOLBARICONS), IMAGE_BITMAP, 256, 16, 0);
40 ImageList_AddMasked(hImageList, tempBm, 0xff00ff);
41 DeleteObject(tempBm);
42 toolbar.SendMessage(TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
43
44 for (i = 0; i < NUM_TOOLS; i++)
45 {
46 TBBUTTON tbbutton;
47 int wrapnow = 0;
48
49 if (i % 2 == 1)
50 wrapnow = TBSTATE_WRAP;
51
52 LoadString(hProgInstance, IDS_TOOLTIP1 + i, tooltips[i], 30);
53 ZeroMemory(&tbbutton, sizeof(TBBUTTON));
54 tbbutton.iString = (INT_PTR) tooltips[i];
55 tbbutton.fsStyle = TBSTYLE_CHECKGROUP;
56 tbbutton.fsState = TBSTATE_ENABLED | wrapnow;
57 tbbutton.idCommand = ID_FREESEL + i;
58 tbbutton.iBitmap = i;
59 toolbar.SendMessage(TB_ADDBUTTONS, 1, (LPARAM) &tbbutton);
60 }
61
62 toolbar.SendMessage(TB_CHECKBUTTON, ID_PEN, MAKELPARAM(TRUE, 0));
63 toolbar.SendMessage(TB_SETMAXTEXTROWS, 0, 0);
64 toolbar.SendMessage(TB_SETBUTTONSIZE, 0, MAKELPARAM(CXY_TB_BUTTON, CXY_TB_BUTTON));
65
66 return 0;
67 }
68
69 LRESULT CToolBox::OnSysColorChange(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
70 {
71 toolbar.SendMessage(WM_SYSCOLORCHANGE, 0, 0);
72 return 0;
73 }
74
75 struct COMMAND_TO_TOOL
76 {
77 UINT id;
78 TOOLTYPE tool;
79 };
80
81 static const COMMAND_TO_TOOL CommandToToolMapping[] =
82 {
83 { ID_FREESEL, TOOL_FREESEL },
84 { ID_RECTSEL, TOOL_RECTSEL },
85 { ID_RUBBER, TOOL_RUBBER },
86 { ID_FILL, TOOL_FILL },
87 { ID_COLOR, TOOL_COLOR },
88 { ID_ZOOM, TOOL_ZOOM },
89 { ID_PEN, TOOL_PEN },
90 { ID_BRUSH, TOOL_BRUSH },
91 { ID_AIRBRUSH, TOOL_AIRBRUSH },
92 { ID_TEXT, TOOL_TEXT },
93 { ID_LINE, TOOL_LINE },
94 { ID_BEZIER, TOOL_BEZIER },
95 { ID_RECT, TOOL_RECT },
96 { ID_SHAPE, TOOL_SHAPE },
97 { ID_ELLIPSE, TOOL_ELLIPSE },
98 { ID_RRECT, TOOL_RRECT },
99 };
100
101 LRESULT CToolBox::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
102 {
103 UINT id = LOWORD(wParam);
104 for (size_t i = 0; i < _countof(CommandToToolMapping); ++i)
105 {
106 if (CommandToToolMapping[i].id == id)
107 {
108 toolsModel.SetActiveTool(CommandToToolMapping[i].tool);
109 break;
110 }
111 }
112 return 0;
113 }
114
115 LRESULT CToolBox::OnToolsModelToolChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
116 {
117 selectionWindow.ShowWindow(SW_HIDE);
118 toolsModel.resetTool(); // resets the point-buffer of the polygon and bezier functions
119
120 // Check the toolbar button
121 TOOLTYPE tool = toolsModel.GetActiveTool();
122 for (size_t i = 0; i < _countof(CommandToToolMapping); ++i)
123 {
124 if (CommandToToolMapping[i].tool == tool)
125 {
126 toolbar.SendMessage(TB_CHECKBUTTON, CommandToToolMapping[i].id, TRUE);
127 break;
128 }
129 }
130
131 return 0;
132 }