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 /* INCLUDES *********************************************************/ 11 12 #include "precomp.h" 13 14 /* FUNCTIONS ********************************************************/ 15 16 LRESULT CToolBox::OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 17 { 18 HIMAGELIST hImageList; 19 HBITMAP tempBm; 20 int i; 21 TCHAR tooltips[16][30]; 22 23 /* 24 * FIXME: Unintentionally there is a line above the tool bar (hidden by y-offset). 25 * To prevent cropping of the buttons height has been increased from 200 to 205 26 */ 27 RECT toolbarPos = {1, -2, 1 + 50, -2 + 205}; 28 toolbar.Create(TOOLBARCLASSNAME, m_hWnd, toolbarPos, NULL, 29 WS_CHILD | WS_VISIBLE | CCS_NOPARENTALIGN | CCS_VERT | CCS_NORESIZE | TBSTYLE_TOOLTIPS); 30 hImageList = ImageList_Create(16, 16, ILC_COLOR24 | ILC_MASK, 16, 0); 31 toolbar.SendMessage(TB_SETIMAGELIST, 0, (LPARAM) hImageList); 32 tempBm = (HBITMAP) LoadImage(hProgInstance, MAKEINTRESOURCE(IDB_TOOLBARICONS), IMAGE_BITMAP, 256, 16, 0); 33 ImageList_AddMasked(hImageList, tempBm, 0xff00ff); 34 DeleteObject(tempBm); 35 toolbar.SendMessage(TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0); 36 37 for(i = 0; i < 16; i++) 38 { 39 TBBUTTON tbbutton; 40 int wrapnow = 0; 41 42 if (i % 2 == 1) 43 wrapnow = TBSTATE_WRAP; 44 45 LoadString(hProgInstance, IDS_TOOLTIP1 + i, tooltips[i], 30); 46 ZeroMemory(&tbbutton, sizeof(TBBUTTON)); 47 tbbutton.iString = (INT_PTR) tooltips[i]; 48 tbbutton.fsStyle = TBSTYLE_CHECKGROUP; 49 tbbutton.fsState = TBSTATE_ENABLED | wrapnow; 50 tbbutton.idCommand = ID_FREESEL + i; 51 tbbutton.iBitmap = i; 52 toolbar.SendMessage(TB_ADDBUTTONS, 1, (LPARAM) &tbbutton); 53 } 54 55 toolbar.SendMessage(TB_CHECKBUTTON, ID_PEN, MAKELPARAM(TRUE, 0)); 56 toolbar.SendMessage(TB_SETMAXTEXTROWS, 0, 0); 57 toolbar.SendMessage(TB_SETBUTTONSIZE, 0, MAKELPARAM(25, 25)); 58 59 return 0; 60 } 61 62 LRESULT CToolBox::OnSetCursor(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 63 { 64 SetCursor(LoadCursor(NULL, IDC_ARROW)); 65 return 0; 66 } 67 68 LRESULT CToolBox::OnSysColorChange(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 69 { 70 toolbar.SendMessage(WM_SYSCOLORCHANGE, 0, 0); 71 return 0; 72 } 73 74 struct COMMAND_TO_TOOL 75 { 76 UINT id; 77 TOOLTYPE tool; 78 }; 79 80 static const COMMAND_TO_TOOL CommandToToolMapping[] = 81 { 82 { ID_FREESEL, TOOL_FREESEL }, 83 { ID_RECTSEL, TOOL_RECTSEL }, 84 { ID_RUBBER, TOOL_RUBBER }, 85 { ID_FILL, TOOL_FILL }, 86 { ID_COLOR, TOOL_COLOR }, 87 { ID_ZOOM, TOOL_ZOOM }, 88 { ID_PEN, TOOL_PEN }, 89 { ID_BRUSH, TOOL_BRUSH }, 90 { ID_AIRBRUSH, TOOL_AIRBRUSH }, 91 { ID_TEXT, TOOL_TEXT }, 92 { ID_LINE, TOOL_LINE }, 93 { ID_BEZIER, TOOL_BEZIER }, 94 { ID_RECT, TOOL_RECT }, 95 { ID_SHAPE, TOOL_SHAPE }, 96 { ID_ELLIPSE, TOOL_ELLIPSE }, 97 { ID_RRECT, TOOL_RRECT }, 98 }; 99 100 LRESULT CToolBox::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 101 { 102 UINT id = LOWORD(wParam); 103 for (size_t i = 0; i < _countof(CommandToToolMapping); ++i) 104 { 105 if (CommandToToolMapping[i].id == id) 106 { 107 toolsModel.SetActiveTool(CommandToToolMapping[i].tool); 108 break; 109 } 110 } 111 return 0; 112 } 113 114 LRESULT CToolBox::OnToolsModelToolChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 115 { 116 selectionWindow.ShowWindow(SW_HIDE); 117 toolsModel.resetTool(); // resets the point-buffer of the polygon and bezier functions 118 119 // Check the toolbar button 120 TOOLTYPE tool = toolsModel.GetActiveTool(); 121 for (size_t i = 0; i < _countof(CommandToToolMapping); ++i) 122 { 123 if (CommandToToolMapping[i].tool == tool) 124 { 125 toolbar.SendMessage(TB_CHECKBUTTON, CommandToToolMapping[i].id, TRUE); 126 break; 127 } 128 } 129 130 return 0; 131 } 132