2 * PROJECT: PAINT for ReactOS
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
12 CToolBox toolBoxContainer
;
14 /* FUNCTIONS ********************************************************/
16 BOOL
CToolBox::DoCreate(HWND hwndParent
)
18 RECT toolBoxContainerPos
= { 0, 0, 0, 0 };
19 DWORD style
= WS_CHILD
| (registrySettings
.ShowToolBox
? WS_VISIBLE
: 0);
20 return !!Create(hwndParent
, toolBoxContainerPos
, NULL
, style
);
23 LRESULT
CToolBox::OnCreate(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
25 HIMAGELIST hImageList
;
28 TCHAR tooltips
[NUM_TOOLS
][30];
30 toolSettingsWindow
.DoCreate(m_hWnd
);
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);
42 toolbar
.SendMessage(TB_BUTTONSTRUCTSIZE
, sizeof(TBBUTTON
), 0);
44 for (i
= 0; i
< NUM_TOOLS
; i
++)
50 wrapnow
= TBSTATE_WRAP
;
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
;
59 toolbar
.SendMessage(TB_ADDBUTTONS
, 1, (LPARAM
) &tbbutton
);
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
));
69 LRESULT
CToolBox::OnSysColorChange(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
71 toolbar
.SendMessage(WM_SYSCOLORCHANGE
, 0, 0);
75 struct COMMAND_TO_TOOL
81 static const COMMAND_TO_TOOL CommandToToolMapping
[] =
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
},
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
},
101 LRESULT
CToolBox::OnCommand(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
103 UINT id
= LOWORD(wParam
);
104 for (size_t i
= 0; i
< _countof(CommandToToolMapping
); ++i
)
106 if (CommandToToolMapping
[i
].id
== id
)
108 toolsModel
.SetActiveTool(CommandToToolMapping
[i
].tool
);
115 LRESULT
CToolBox::OnToolsModelToolChanged(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
117 selectionWindow
.ShowWindow(SW_HIDE
);
118 toolsModel
.resetTool(); // resets the point-buffer of the polygon and bezier functions
120 // Check the toolbar button
121 TOOLTYPE tool
= toolsModel
.GetActiveTool();
122 for (size_t i
= 0; i
< _countof(CommandToToolMapping
); ++i
)
124 if (CommandToToolMapping
[i
].tool
== tool
)
126 toolbar
.SendMessage(TB_CHECKBUTTON
, CommandToToolMapping
[i
].id
, TRUE
);