george82 | b3a4d65 | 2005-07-26 10:22:56 +0000 | [diff] [blame^] | 1 | /* Copyright (C) 2004 TightVNC Team. All Rights Reserved. |
| 2 | * |
| 3 | * This is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License as published by |
| 5 | * the Free Software Foundation; either version 2 of the License, or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * This software is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this software; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
| 16 | * USA. |
| 17 | */ |
| 18 | |
| 19 | // -=- ToolBar.h |
| 20 | |
| 21 | #include <windows.h> |
| 22 | #include <commctrl.h> |
| 23 | #include <assert.h> |
| 24 | |
| 25 | class ToolBar { |
| 26 | public: |
| 27 | ToolBar(); |
| 28 | virtual ~ToolBar(); |
| 29 | |
| 30 | // create() creates a windows toolbar. dwStyle is a combination of |
| 31 | // the toolbar control and button styles. It returns TRUE if successful, |
| 32 | // or FALSE otherwise. |
| 33 | bool create(int tbID, HWND parentHwnd, DWORD dwStyle = WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT); |
| 34 | |
| 35 | // -=- Button images operations |
| 36 | |
| 37 | // addBitmap() adds one or more images from resources to the list of button |
| 38 | // images available for a toolbar. Returns the index of the first new image |
| 39 | // if successful, or -1 otherwise. |
| 40 | int addBitmap(int nButtons, UINT bitmapID); |
| 41 | |
| 42 | // addSystemBitmap() adds the system-defined button bitmaps to the list |
| 43 | // of the toolbar button specifying by stdBitmapID. Returns the index of |
| 44 | // the first new image if successful, or -1 otherwise. |
| 45 | int addSystemBitmap(UINT stdBitmapID); |
| 46 | |
| 47 | // setBitmapSize() sets the size of the bitmapped images to be added |
| 48 | // to a toolbar. It returns TRUE if successful, or FALSE otherwise. |
| 49 | // You must call it before addBitmap(). |
| 50 | bool setBitmapSize(int width, int height); |
| 51 | |
| 52 | // -=- Button operations |
| 53 | |
| 54 | // addButton() adds one button. |
| 55 | bool addButton(int iBitmap, int idCommand, BYTE state=TBSTATE_ENABLED, BYTE style=TBSTYLE_BUTTON, UINT dwData=0, int iString=0); |
| 56 | |
| 57 | // addNButton() adds nButtons buttons to a toolbar. |
| 58 | bool addNButton(int nButtons, LPTBBUTTON tbb); |
| 59 | |
| 60 | // deleteButton() removes a button from the toolbar. |
| 61 | bool deleteButton(int nIndex); |
| 62 | |
| 63 | // insertButton() inserts a button in a toolbar control by index. |
| 64 | bool insertButton(int nIndex, LPTBBUTTON tbb); |
| 65 | |
| 66 | // getButtonInfo() retrieves extended information about a toolbar's button. |
| 67 | // It returns index of the button if successful, or -1 otherwise. |
| 68 | int getButtonInfo(int idButton, TBBUTTONINFO *btnInfo); |
| 69 | |
| 70 | // getButtonsHeight() retrieves the height of the toolbar buttons. |
| 71 | int getButtonsHeight(); |
| 72 | |
| 73 | // getButtonsWidth() retrieves the width of the toolbar buttons. |
| 74 | int getButtonsWidth(); |
| 75 | |
| 76 | // setButtonInfo() sets the information for an existing button in a toolbar. |
| 77 | bool setButtonInfo(int idButton, TBBUTTONINFO* ptbbi); |
| 78 | |
| 79 | // checkButton() checks or unchecks a given button in a toolbar control. |
| 80 | bool checkButton(int idButton, bool check); |
| 81 | |
| 82 | // enableButton() enables or disables the specified button in the toolbar. |
| 83 | bool enableButton(int idButton, bool enable); |
| 84 | |
| 85 | // pressButton() presses or releases the specified button in the toolbar. |
| 86 | bool pressButton(int idButton, bool press); |
| 87 | |
| 88 | // getButtonRect() gets the bounding rectangle of a button in a toolbar. |
| 89 | bool getButtonRect(int nIndex, LPRECT buttonRect); |
| 90 | |
| 91 | // setButtonSize() sets the size of the buttons to be added to a toolbar. |
| 92 | // Button size must be largen the button bitmap. |
| 93 | bool setButtonSize(int width, int height); |
| 94 | |
| 95 | |
| 96 | |
| 97 | // autoSize() resizes the toolbar window. |
| 98 | void autoSize(); |
| 99 | |
| 100 | // getHandle() returns handle to a toolbar window. |
| 101 | HWND getHandle() { return hwndToolBar; } |
| 102 | |
| 103 | // getHeight() returns the toolbar window height. |
| 104 | int getHeight(); |
| 105 | |
| 106 | protected: |
| 107 | HWND hwndToolBar; |
| 108 | HWND parentHwnd; |
| 109 | int tbID; |
| 110 | }; |