ReactOS 0.4.15-dev-8096-ga0eec98
toolbox.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: PAINT for ReactOS
3 * LICENSE: LGPL-2.0-or-later (https://spdx.org/licenses/LGPL-2.0-or-later)
4 * PURPOSE: Window procedure of the main window and all children apart from
5 * hPalWin, hToolSettings and hSelection
6 * COPYRIGHT: Copyright 2015 Benedikt Freisen <b.freisen@gmx.net>
7 */
8
9#include "precomp.h"
10
12
13/* FUNCTIONS ********************************************************/
14
17{
19 if (uMsg == WM_LBUTTONUP)
20 {
21 // We have to detect clicking on toolbar even if no change of pressed button
24 if (index >= 0)
25 {
29 }
30 }
31 return ::CallWindowProc(oldWndProc, hwnd, uMsg, wParam, lParam);
32}
33
35{
36 // NOTE: The horizontal line above the toolbar is hidden by CCS_NODIVIDER style.
37 RECT toolbarPos =
38 {
39 0, 0,
42 };
46 return FALSE;
47
48 HIMAGELIST hImageList = ImageList_Create(16, 16, ILC_COLOR24 | ILC_MASK, 16, 0);
49 SendMessage(TB_SETIMAGELIST, 0, (LPARAM)hImageList);
50
52 IMAGE_BITMAP, 256, 16, 0);
53 ImageList_AddMasked(hImageList, hbmIcons, RGB(255, 0, 255));
54 ::DeleteObject(hbmIcons);
55
57
58 WCHAR szToolTip[30];
59 TBBUTTON tbbutton;
60 ZeroMemory(&tbbutton, sizeof(tbbutton));
61 tbbutton.fsStyle = TBSTYLE_CHECKGROUP;
62 for (INT i = 0; i < NUM_TOOLS; i++)
63 {
64 ::LoadStringW(g_hinstExe, IDS_TOOLTIP1 + i, szToolTip, _countof(szToolTip));
65 tbbutton.iString = (INT_PTR)szToolTip;
66 tbbutton.fsState = TBSTATE_ENABLED | ((i % 2 == 1) ? TBSTATE_WRAP : 0);
67 tbbutton.idCommand = ID_FREESEL + i;
68 tbbutton.iBitmap = i;
69 SendMessage(TB_ADDBUTTONS, 1, (LPARAM) &tbbutton);
70 }
71
75
77 return TRUE;
78}
79
81{
82 RECT rcToolBox = { 0, 0, 0, 0 }; // Rely on mainWindow's WM_SIZE
84 return !!Create(hwndParent, rcToolBox, NULL, style);
85}
86
88{
89 toolbar.DoCreate(m_hWnd);
91 return 0;
92}
93
95{
96 toolbar.SendMessage(WM_SYSCOLORCHANGE, 0, 0);
97 return 0;
98}
99
101{
104};
105
107{
111 { ID_FILL, TOOL_FILL },
112 { ID_COLOR, TOOL_COLOR },
113 { ID_ZOOM, TOOL_ZOOM },
114 { ID_PEN, TOOL_PEN },
115 { ID_BRUSH, TOOL_BRUSH },
117 { ID_TEXT, TOOL_TEXT },
118 { ID_LINE, TOOL_LINE },
120 { ID_RECT, TOOL_RECT },
121 { ID_SHAPE, TOOL_SHAPE },
123 { ID_RRECT, TOOL_RRECT },
124};
125static_assert(_countof(CommandToToolMapping) == TOOL_MAX, "Logical error");
126
128{
129 UINT id = LOWORD(wParam);
130 for (size_t i = 0; i < _countof(CommandToToolMapping); ++i)
131 {
132 if (CommandToToolMapping[i].id == id)
133 {
135 break;
136 }
137 }
138 return 0;
139}
140
142{
144 toolsModel.resetTool(); // resets the point-buffer of the polygon and bezier functions
145
146 // Check the toolbar button
148 for (size_t i = 0; i < _countof(CommandToToolMapping); ++i)
149 {
150 if (CommandToToolMapping[i].tool == tool)
151 {
153 break;
154 }
155 }
156
157 return 0;
158}
159
161{
162 SetCapture();
163 return 0;
164}
165
167{
168 if (::GetCapture() != m_hWnd)
169 return 0;
172
173 RECT rc;
175
176 POINT ptCenter = { (rc.left + rc.right) / 2, (rc.top + rc.bottom) / 2 };
177
178 DWORD dwExpectedBar2ID = ((pt.x < ptCenter.x) ? BAR2ID_LEFT : BAR2ID_RIGHT);
179
180 if (registrySettings.Bar2ID != dwExpectedBar2ID)
181 {
182 registrySettings.Bar2ID = dwExpectedBar2ID;
184 }
185
186 return 0;
187}
188
190{
191 if (::GetCapture() != m_hWnd)
192 return 0;
193
195 return 0;
196}
Arabic default style
Definition: afstyles.h:94
CMainWindow mainWindow
Definition: main.cpp:25
HINSTANCE g_hinstExe
Definition: main.cpp:17
ToolsModel toolsModel
Definition: toolsmodel.cpp:10
RegistrySettings registrySettings
Definition: registry.cpp:14
SelectionModel selectionModel
CToolSettingsWindow toolSettingsWindow
#define BAR2ID_LEFT
Definition: registry.h:55
#define BAR2ID_RIGHT
Definition: registry.h:56
#define ID_LINE
Definition: resource.h:122
#define ID_RECT
Definition: resource.h:124
#define ID_ELLIPSE
Definition: resource.h:126
#define IDB_TOOLBARICONS
Definition: resource.h:14
#define ID_COLOR
Definition: resource.h:116
#define ID_BRUSH
Definition: resource.h:119
#define ID_FILL
Definition: resource.h:115
#define ID_TEXT
Definition: resource.h:121
#define ID_SHAPE
Definition: resource.h:125
#define IDS_TOOLTIP1
Definition: resource.h:195
#define ID_PEN
Definition: resource.h:118
#define ID_AIRBRUSH
Definition: resource.h:120
#define ID_RUBBER
Definition: resource.h:114
#define NUM_TOOLS
Definition: resource.h:128
#define ID_ZOOM
Definition: resource.h:117
#define ID_BEZIER
Definition: resource.h:123
#define ID_FREESEL
Definition: resource.h:112
#define ID_RECTSEL
Definition: resource.h:113
#define ID_RRECT
Definition: resource.h:127
@ Create
Definition: registry.c:563
HWND Create(LPCTSTR lpstrWndClass, HWND hWndParent, _U_RECT rect=NULL, LPCTSTR szWindowName=NULL, DWORD dwStyle=0, DWORD dwExStyle=0, _U_MENUorID MenuOrID=0U, LPVOID lpCreateParam=NULL)
Definition: atlwin.h:417
BOOL GetWindowRect(LPRECT lpRect) const
Definition: atlwin.h:816
BOOL PostMessage(UINT message, WPARAM wParam=0, LPARAM lParam=0)
Definition: atlwin.h:1044
static LRESULT CALLBACK ToolBarWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: toolbox.cpp:16
BOOL DoCreate(HWND hwndParent)
Definition: toolbox.cpp:34
LRESULT OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: toolbox.cpp:166
LRESULT OnSysColorChange(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: toolbox.cpp:94
LRESULT OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: toolbox.cpp:160
CPaintToolBar toolbar
Definition: toolbox.h:42
LRESULT OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: toolbox.cpp:87
LRESULT OnLButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: toolbox.cpp:189
LRESULT OnToolsModelToolChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: toolbox.cpp:141
BOOL DoCreate(HWND hwndParent)
Definition: toolbox.cpp:80
LRESULT OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: toolbox.cpp:127
BOOL DoCreate(HWND hwndParent)
DWORD ShowToolBox
Definition: registry.h:44
void resetTool()
Definition: toolsmodel.cpp:302
void SetActiveTool(TOOLTYPE nActiveTool)
Definition: toolsmodel.cpp:144
TOOLTYPE GetActiveTool() const
Definition: toolsmodel.cpp:134
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
static HWND hwndParent
Definition: cryptui.c:300
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
INT WINAPI ImageList_AddMasked(HIMAGELIST himl, HBITMAP hBitmap, COLORREF clrMask)
Definition: imagelist.c:563
HIMAGELIST WINAPI ImageList_Create(INT cx, INT cy, UINT flags, INT cInitial, INT cGrow)
Definition: imagelist.c:804
#define CALLBACK
Definition: compat.h:35
#define pt(x, y)
Definition: drawing.c:79
#define RGB(r, g, b)
Definition: precomp.h:71
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
pKey DeleteObject()
GLuint index
Definition: glext.h:6031
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static HBITMAP
Definition: button.c:44
DWORD button
Definition: button.c:166
static WNDPROC oldWndProc
Definition: propsheet.c:637
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
unsigned int UINT
Definition: ndis.h:50
#define LOWORD(l)
Definition: pedump.c:82
#define WS_CHILD
Definition: pedump.c:617
#define WS_VISIBLE
Definition: pedump.c:620
#define INT
Definition: polytest.cpp:20
#define TB_ADDBUTTONS
Definition: commctrl.h:1271
#define TBSTYLE_TOOLTIPS
Definition: commctrl.h:989
#define TB_BUTTONSTRUCTSIZE
Definition: commctrl.h:1134
#define TB_CHECKBUTTON
Definition: commctrl.h:1043
#define CCS_VERT
Definition: commctrl.h:2249
#define TB_SETIMAGELIST
Definition: commctrl.h:1150
#define TB_GETBUTTON
Definition: commctrl.h:1109
#define TBSTYLE_CHECKGROUP
Definition: commctrl.h:985
#define TB_SETBUTTONSIZE
Definition: commctrl.h:1135
#define TOOLBARCLASSNAMEW
Definition: commctrl.h:943
#define TBSTATE_ENABLED
Definition: commctrl.h:974
#define TBSTYLE_FLAT
Definition: commctrl.h:992
#define ILC_MASK
Definition: commctrl.h:351
#define CCS_NOPARENTALIGN
Definition: commctrl.h:2246
#define CCS_NORESIZE
Definition: commctrl.h:2245
#define TBSTATE_WRAP
Definition: commctrl.h:977
#define TB_HITTEST
Definition: commctrl.h:1268
#define ILC_COLOR24
Definition: commctrl.h:357
#define TB_SETMAXTEXTROWS
Definition: commctrl.h:1162
#define _countof(array)
Definition: sndvol32.h:70
TOOLTYPE tool
Definition: toolbox.cpp:103
BYTE fsState
Definition: commctrl.h:951
INT_PTR iString
Definition: commctrl.h:959
int idCommand
Definition: commctrl.h:950
int iBitmap
Definition: commctrl.h:949
BYTE fsStyle
Definition: commctrl.h:952
long x
Definition: polytest.cpp:48
LONG right
Definition: windef.h:308
LONG bottom
Definition: windef.h:309
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
CToolBox toolBoxContainer
Definition: toolbox.cpp:11
static const COMMAND_TO_TOOL CommandToToolMapping[]
Definition: toolbox.cpp:106
#define CXY_TB_BUTTON
Definition: toolbox.h:13
#define CY_TOOLBAR
Definition: toolbox.h:15
#define CX_TOOLBAR
Definition: toolbox.h:14
TOOLTYPE
Definition: toolsmodel.h:11
@ TOOL_AIRBRUSH
Definition: toolsmodel.h:20
@ TOOL_COLOR
Definition: toolsmodel.h:16
@ TOOL_SHAPE
Definition: toolsmodel.h:25
@ TOOL_RUBBER
Definition: toolsmodel.h:14
@ TOOL_MAX
Definition: toolsmodel.h:28
@ TOOL_BRUSH
Definition: toolsmodel.h:19
@ TOOL_RECT
Definition: toolsmodel.h:24
@ TOOL_BEZIER
Definition: toolsmodel.h:23
@ TOOL_FILL
Definition: toolsmodel.h:15
@ TOOL_TEXT
Definition: toolsmodel.h:21
@ TOOL_PEN
Definition: toolsmodel.h:18
@ TOOL_LINE
Definition: toolsmodel.h:22
@ TOOL_FREESEL
Definition: toolsmodel.h:12
@ TOOL_ZOOM
Definition: toolsmodel.h:17
@ TOOL_ELLIPSE
Definition: toolsmodel.h:26
@ TOOL_RRECT
Definition: toolsmodel.h:27
@ TOOL_RECTSEL
Definition: toolsmodel.h:13
#define GetWindowLongPtr
Definition: treelist.c:73
#define SetWindowLongPtr
Definition: treelist.c:70
#define GWLP_WNDPROC
Definition: treelist.c:66
#define GWLP_USERDATA
Definition: treelist.c:63
int32_t INT_PTR
Definition: typedefs.h:64
int32_t INT
Definition: typedefs.h:58
#define ZeroMemory
Definition: winbase.h:1712
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
#define GET_Y_LPARAM(lp)
Definition: windowsx.h:300
#define GET_X_LPARAM(lp)
Definition: windowsx.h:299
HWND WINAPI SetCapture(_In_ HWND hWnd)
#define IMAGE_BITMAP
Definition: winuser.h:211
#define MAKELPARAM(l, h)
Definition: winuser.h:4008
BOOL WINAPI ReleaseCapture(void)
Definition: message.c:2890
BOOL WINAPI PostMessageW(_In_opt_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define WM_SIZE
Definition: winuser.h:1611
#define WM_COMMAND
Definition: winuser.h:1740
HANDLE WINAPI LoadImageW(_In_opt_ HINSTANCE hInst, _In_ LPCWSTR name, _In_ UINT type, _In_ int cx, _In_ int cy, _In_ UINT fuLoad)
Definition: cursoricon.c:2234
HWND WINAPI GetCapture(void)
Definition: message.c:2881
#define WM_SYSCOLORCHANGE
Definition: winuser.h:1626
BOOL WINAPI ClientToScreen(_In_ HWND, _Inout_ LPPOINT)
#define SM_CYBORDER
Definition: winuser.h:965
#define SM_CXBORDER
Definition: winuser.h:964
#define SendMessage
Definition: winuser.h:5843
#define WM_LBUTTONUP
Definition: winuser.h:1777
HWND WINAPI GetParent(_In_ HWND)
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
LRESULT(CALLBACK * WNDPROC)(HWND, UINT, WPARAM, LPARAM)
Definition: winuser.h:2906
int WINAPI GetSystemMetrics(_In_ int)
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
__wchar_t WCHAR
Definition: xmlstorage.h:180