From 3701d40a8fc099fe12eddd938d769362dc8fbc7f Mon Sep 17 00:00:00 2001 From: donho Date: Fri, 28 Mar 2008 01:11:22 +0000 Subject: [PATCH] [BUG_FIXED] Fix crash bug while a "New 2" is in session.xml. Clean up the toolbar code. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@155 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/Notepad_plus.cpp | 89 ++-- .../WinControls/ImageListSet/ImageListSet.cpp | 14 +- .../WinControls/ImageListSet/ImageListSet.h | 13 +- .../src/WinControls/ToolBar/ToolBar.cpp | 431 +++++++----------- PowerEditor/src/WinControls/ToolBar/ToolBar.h | 97 ++-- 5 files changed, 254 insertions(+), 390 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index b3e6c4f06..92f171426 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -542,10 +542,10 @@ bool Notepad_plus::loadSession(Session & session) allSessionFilesLoaded = false; } } - if (session._activeMainIndex < session.nbMainFiles()) + if (session._activeMainIndex < _mainDocTab.nbItem())//session.nbMainFiles()) _mainDocTab.activate(session._activeMainIndex); - if (session._activeSubIndex < session.nbSubFiles()) + if (session._activeSubIndex < _subDocTab.nbItem())//session.nbSubFiles()) _subDocTab.activate(session._activeSubIndex); if ((session.nbSubFiles() > 0) && (session._activeView == MAIN_VIEW || session._activeView == SUB_VIEW)) @@ -6010,83 +6010,67 @@ bool Notepad_plus::switchToFile(const char *fileName) } ToolBarButtonUnit toolBarIcons[] = { - //{IDM_FILE_NEW, IDI_NEW_OFF_ICON, IDI_NEW_ON_ICON, IDI_NEW_OFF_ICON, STD_FILENEW}, - {IDM_FILE_NEW, IDI_NEW_OFF_ICON, IDI_NEW_ON_ICON, IDI_NEW_OFF_ICON, -1}, - //{IDM_FILE_OPEN, IDI_OPEN_OFF_ICON, IDI_OPEN_ON_ICON, IDI_NEW_OFF_ICON, STD_FILEOPEN}, - {IDM_FILE_OPEN, IDI_OPEN_OFF_ICON, IDI_OPEN_ON_ICON, IDI_NEW_OFF_ICON, -1}, - //{IDM_FILE_SAVE, IDI_SAVE_OFF_ICON, IDI_SAVE_ON_ICON, IDI_SAVE_DISABLE_ICON, STD_FILESAVE}, - {IDM_FILE_SAVE, IDI_SAVE_OFF_ICON, IDI_SAVE_ON_ICON, IDI_SAVE_DISABLE_ICON, -1}, - {IDM_FILE_SAVEALL, IDI_SAVEALL_OFF_ICON, IDI_SAVEALL_ON_ICON, IDI_SAVEALL_DISABLE_ICON, -1}, - {IDM_FILE_CLOSE, IDI_CLOSE_OFF_ICON, IDI_CLOSE_ON_ICON, IDI_CLOSE_OFF_ICON, -1}, - {IDM_FILE_CLOSEALL, IDI_CLOSEALL_OFF_ICON, IDI_CLOSEALL_ON_ICON, IDI_CLOSEALL_OFF_ICON, -1}, + {IDM_FILE_NEW, IDI_NEW_OFF_ICON, IDI_NEW_ON_ICON, IDI_NEW_OFF_ICON, IDR_FILENEW}, + {IDM_FILE_OPEN, IDI_OPEN_OFF_ICON, IDI_OPEN_ON_ICON, IDI_NEW_OFF_ICON, IDR_FILEOPEN}, + {IDM_FILE_SAVE, IDI_SAVE_OFF_ICON, IDI_SAVE_ON_ICON, IDI_SAVE_DISABLE_ICON, IDR_FILESAVE}, + {IDM_FILE_SAVEALL, IDI_SAVEALL_OFF_ICON, IDI_SAVEALL_ON_ICON, IDI_SAVEALL_DISABLE_ICON, IDR_SAVEALL}, + {IDM_FILE_CLOSE, IDI_CLOSE_OFF_ICON, IDI_CLOSE_ON_ICON, IDI_CLOSE_OFF_ICON, IDR_CLOSEFILE}, + {IDM_FILE_CLOSEALL, IDI_CLOSEALL_OFF_ICON, IDI_CLOSEALL_ON_ICON, IDI_CLOSEALL_OFF_ICON, IDR_CLOSEALL}, + {IDM_FILE_PRINTNOW, IDI_PRINT_OFF_ICON, IDI_PRINT_ON_ICON, IDI_PRINT_OFF_ICON, IDR_PRINT}, //-------------------------------------------------------------------------------------// {0, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON}, //-------------------------------------------------------------------------------------// - //{IDM_EDIT_CUT, IDI_CUT_OFF_ICON, IDI_CUT_ON_ICON, IDI_CUT_DISABLE_ICON, STD_CUT}, - //{IDM_EDIT_COPY, IDI_COPY_OFF_ICON, IDI_COPY_ON_ICON, IDI_COPY_DISABLE_ICON, STD_COPY}, - //{IDM_EDIT_PASTE, IDI_PASTE_OFF_ICON, IDI_PASTE_ON_ICON, IDI_PASTE_DISABLE_ICON, STD_PASTE}, - {IDM_EDIT_CUT, IDI_CUT_OFF_ICON, IDI_CUT_ON_ICON, IDI_CUT_DISABLE_ICON, -1}, - {IDM_EDIT_COPY, IDI_COPY_OFF_ICON, IDI_COPY_ON_ICON, IDI_COPY_DISABLE_ICON, -1}, - {IDM_EDIT_PASTE, IDI_PASTE_OFF_ICON, IDI_PASTE_ON_ICON, IDI_PASTE_DISABLE_ICON, -1}, + {IDM_EDIT_CUT, IDI_CUT_OFF_ICON, IDI_CUT_ON_ICON, IDI_CUT_DISABLE_ICON, IDR_CUT}, + {IDM_EDIT_COPY, IDI_COPY_OFF_ICON, IDI_COPY_ON_ICON, IDI_COPY_DISABLE_ICON, IDR_COPY}, + {IDM_EDIT_PASTE, IDI_PASTE_OFF_ICON, IDI_PASTE_ON_ICON, IDI_PASTE_DISABLE_ICON, IDR_PASTE}, //-------------------------------------------------------------------------------------// {0, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON}, //-------------------------------------------------------------------------------------// - //{IDM_EDIT_UNDO, IDI_UNDO_OFF_ICON, IDI_UNDO_ON_ICON, IDI_UNDO_DISABLE_ICON, STD_UNDO}, - //{IDM_EDIT_REDO, IDI_REDO_OFF_ICON, IDI_REDO_ON_ICON, IDI_REDO_DISABLE_ICON, STD_REDOW}, - {IDM_EDIT_UNDO, IDI_UNDO_OFF_ICON, IDI_UNDO_ON_ICON, IDI_UNDO_DISABLE_ICON, -1}, - {IDM_EDIT_REDO, IDI_REDO_OFF_ICON, IDI_REDO_ON_ICON, IDI_REDO_DISABLE_ICON, -1}, + {IDM_EDIT_UNDO, IDI_UNDO_OFF_ICON, IDI_UNDO_ON_ICON, IDI_UNDO_DISABLE_ICON, IDR_UNDO}, + {IDM_EDIT_REDO, IDI_REDO_OFF_ICON, IDI_REDO_ON_ICON, IDI_REDO_DISABLE_ICON, IDR_REDO}, //-------------------------------------------------------------------------------------// {0, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON}, //-------------------------------------------------------------------------------------// - {IDM_SEARCH_FIND, IDI_FIND_OFF_ICON, IDI_FIND_ON_ICON, IDI_FIND_OFF_ICON, -1}, - {IDM_SEARCH_REPLACE, IDI_REPLACE_OFF_ICON, IDI_REPLACE_ON_ICON, IDI_REPLACE_OFF_ICON, -1}, + {IDM_SEARCH_FIND, IDI_FIND_OFF_ICON, IDI_FIND_ON_ICON, IDI_FIND_OFF_ICON, IDR_FIND}, + {IDM_SEARCH_REPLACE, IDI_REPLACE_OFF_ICON, IDI_REPLACE_ON_ICON, IDI_REPLACE_OFF_ICON, IDR_REPLACE}, //-------------------------------------------------------------------------------------// {0, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON}, //-------------------------------------------------------------------------------------// - {IDM_VIEW_ZOOMIN, IDI_ZOOMIN_OFF_ICON, IDI_ZOOMIN_ON_ICON, IDI_ZOOMIN_OFF_ICON, -1}, - {IDM_VIEW_ZOOMOUT, IDI_ZOOMOUT_OFF_ICON, IDI_ZOOMOUT_ON_ICON, IDI_ZOOMOUT_OFF_ICON, -1}, + {IDM_VIEW_ZOOMIN, IDI_ZOOMIN_OFF_ICON, IDI_ZOOMIN_ON_ICON, IDI_ZOOMIN_OFF_ICON, IDR_ZOOMIN}, + {IDM_VIEW_ZOOMOUT, IDI_ZOOMOUT_OFF_ICON, IDI_ZOOMOUT_ON_ICON, IDI_ZOOMOUT_OFF_ICON, IDR_ZOOMOUT}, //-------------------------------------------------------------------------------------// {0, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON}, //-------------------------------------------------------------------------------------// - {IDM_VIEW_SYNSCROLLV, IDI_SYNCV_OFF_ICON, IDI_SYNCV_ON_ICON, IDI_SYNCV_DISABLE_ICON, -1}, - {IDM_VIEW_SYNSCROLLH, IDI_SYNCH_OFF_ICON, IDI_SYNCH_ON_ICON, IDI_SYNCH_DISABLE_ICON, -1}, + {IDM_VIEW_SYNSCROLLV, IDI_SYNCV_OFF_ICON, IDI_SYNCV_ON_ICON, IDI_SYNCV_DISABLE_ICON, IDR_SYNCV}, + {IDM_VIEW_SYNSCROLLH, IDI_SYNCH_OFF_ICON, IDI_SYNCH_ON_ICON, IDI_SYNCH_DISABLE_ICON, IDR_SYNCH}, //-------------------------------------------------------------------------------------// {0, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON}, //-------------------------------------------------------------------------------------// - {IDM_VIEW_WRAP, IDI_VIEW_WRAP_OFF_ICON, IDI_VIEW_WRAP_ON_ICON, IDI_VIEW_WRAP_OFF_ICON, -1}, - {IDM_VIEW_ALL_CHARACTERS, IDI_VIEW_ALL_CHAR_OFF_ICON, IDI_VIEW_ALL_CHAR_ON_ICON, IDI_VIEW_ALL_CHAR_OFF_ICON, -1}, - {IDM_VIEW_INDENT_GUIDE, IDI_VIEW_INDENT_OFF_ICON, IDI_VIEW_INDENT_ON_ICON, IDI_VIEW_INDENT_OFF_ICON, -1}, - {IDM_VIEW_USER_DLG, IDI_VIEW_UD_DLG_OFF_ICON, IDI_VIEW_UD_DLG_ON_ICON, IDI_VIEW_UD_DLG_OFF_ICON, -1}, + {IDM_VIEW_WRAP, IDI_VIEW_WRAP_OFF_ICON, IDI_VIEW_WRAP_ON_ICON, IDI_VIEW_WRAP_OFF_ICON, IDR_WRAP}, + {IDM_VIEW_ALL_CHARACTERS, IDI_VIEW_ALL_CHAR_OFF_ICON, IDI_VIEW_ALL_CHAR_ON_ICON, IDI_VIEW_ALL_CHAR_OFF_ICON, IDR_INVISIBLECHAR}, + {IDM_VIEW_INDENT_GUIDE, IDI_VIEW_INDENT_OFF_ICON, IDI_VIEW_INDENT_ON_ICON, IDI_VIEW_INDENT_OFF_ICON, IDR_INDENTGUIDE}, + {IDM_VIEW_USER_DLG, IDI_VIEW_UD_DLG_OFF_ICON, IDI_VIEW_UD_DLG_ON_ICON, IDI_VIEW_UD_DLG_OFF_ICON, IDR_SHOWPANNEL}, //-------------------------------------------------------------------------------------// {0, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON}, //-------------------------------------------------------------------------------------// - {IDM_MACRO_STARTRECORDINGMACRO, IDI_STARTRECORD_OFF_ICON, IDI_STARTRECORD_ON_ICON, IDI_STARTRECORD_DISABLE_ICON, -1}, - {IDM_MACRO_STOPRECORDINGMACRO, IDI_STOPRECORD_OFF_ICON, IDI_STOPRECORD_ON_ICON, IDI_STOPRECORD_DISABLE_ICON, -1}, - {IDM_MACRO_PLAYBACKRECORDEDMACRO, IDI_PLAYRECORD_OFF_ICON, IDI_PLAYRECORD_ON_ICON, IDI_PLAYRECORD_DISABLE_ICON, -1}, - {IDM_MACRO_RUNMULTIMACRODLG, IDI_MMPLAY_OFF_ICON, IDI_MMPLAY_ON_ICON, IDI_MMPLAY_DIS_ICON, -1}, - {IDM_MACRO_SAVECURRENTMACRO, IDI_SAVERECORD_OFF_ICON, IDI_SAVERECORD_ON_ICON, IDI_SAVERECORD_DISABLE_ICON, -1}, - //-------------------------------------------------------------------------------------// - {0, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON}, - //-------------------------------------------------------------------------------------// - - //{IDM_FILE_PRINTNOW, IDI_PRINT_OFF_ICON, IDI_PRINT_ON_ICON, IDI_PRINT_OFF_ICON, STD_PRINT} - {IDM_FILE_PRINTNOW, IDI_PRINT_OFF_ICON, IDI_PRINT_ON_ICON, IDI_PRINT_OFF_ICON, -1} + {IDM_MACRO_STARTRECORDINGMACRO, IDI_STARTRECORD_OFF_ICON, IDI_STARTRECORD_ON_ICON, IDI_STARTRECORD_DISABLE_ICON, IDR_STARTRECORD}, + {IDM_MACRO_STOPRECORDINGMACRO, IDI_STOPRECORD_OFF_ICON, IDI_STOPRECORD_ON_ICON, IDI_STOPRECORD_DISABLE_ICON, IDR_STOPRECORD}, + {IDM_MACRO_PLAYBACKRECORDEDMACRO, IDI_PLAYRECORD_OFF_ICON, IDI_PLAYRECORD_ON_ICON, IDI_PLAYRECORD_DISABLE_ICON, IDR_PLAYRECORD}, + {IDM_MACRO_RUNMULTIMACRODLG, IDI_MMPLAY_OFF_ICON, IDI_MMPLAY_ON_ICON, IDI_MMPLAY_DIS_ICON, IDR_M_PLAYRECORD}, + {IDM_MACRO_SAVECURRENTMACRO, IDI_SAVERECORD_OFF_ICON, IDI_SAVERECORD_ON_ICON, IDI_SAVERECORD_DISABLE_ICON, IDR_SAVERECORD} + }; -int stdIcons[] = {IDR_FILENEW, IDR_FILEOPEN, IDR_FILESAVE, IDR_SAVEALL, IDR_CLOSEFILE, IDR_CLOSEALL, IDR_CUT, IDR_COPY, IDR_PASTE,\ -IDR_UNDO, IDR_REDO, IDR_FIND, IDR_REPLACE, IDR_ZOOMIN, IDR_ZOOMOUT, IDR_SYNCV, IDR_SYNCH,\ -IDR_WRAP, IDR_INVISIBLECHAR, IDR_INDENTGUIDE, IDR_SHOWPANNEL, IDR_STARTRECORD, IDR_STOPRECORD, IDR_PLAYRECORD, IDR_M_PLAYRECORD, IDR_SAVERECORD, IDR_PRINT}; - void Notepad_plus::getTaskListInfo(TaskListInfo *tli) { int iView = getCurrentView(); @@ -6587,13 +6571,14 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa menuID = IDM_VIEW_TOOLBAR_STANDARD; } - _toolBar.init(_hInst, hwnd, iconSize, toolBarIcons, sizeof(toolBarIcons)/sizeof(ToolBarButtonUnit), (tbStatus == TB_STANDARD), stdIcons, sizeof(stdIcons)/sizeof(int)); + + _toolBar.init(_hInst, hwnd, tbStatus, toolBarIcons, sizeof(toolBarIcons)/sizeof(ToolBarButtonUnit)); _toolBar.display(willBeShown); checkToolBarMenu(menuID); changeToolBarIcons(); _rebar.init(_hInst, hwnd, &_toolBar); - _rebar.display(tbStatus != TB_HIDE); + //_rebar.display(tbStatus != TB_HIDE); //launch the plugin dlg memorized at the last session DockingManagerData &dmd = nppGUI._dockingData; @@ -6805,10 +6790,11 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa case WM_SIZE: { RECT rc; - getToolBarClientRect(rc); - _toolBar.reSizeTo(rc); + //getToolBarClientRect(rc); + //_toolBar.reSizeTo(rc); - ::SetWindowPos(_rebar.getHSelf(), NULL, 0, 0, LOWORD(lParam), rc.bottom - rc.top, SWP_NOZORDER); + ::MoveWindow(_toolBar.getHSelf(), 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE); + ::MoveWindow(_rebar.getHSelf(), 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE); getStatusBarClientRect(rc); _statusBar.reSizeTo(rc); @@ -8450,3 +8436,4 @@ winVer getWindowsVersion() + diff --git a/PowerEditor/src/WinControls/ImageListSet/ImageListSet.cpp b/PowerEditor/src/WinControls/ImageListSet/ImageListSet.cpp index d33900495..365edd9dd 100644 --- a/PowerEditor/src/WinControls/ImageListSet/ImageListSet.cpp +++ b/PowerEditor/src/WinControls/ImageListSet/ImageListSet.cpp @@ -22,6 +22,7 @@ void ToolBarIcons::init(ToolBarButtonUnit *buttonUnitArray, int arraySize) { for (int i = 0 ; i < arraySize ; i++) _tbiis.push_back(buttonUnitArray[i]); + _nbCmd = arraySize; } void ToolBarIcons::create(HINSTANCE hInst, int iconSize) @@ -36,17 +37,7 @@ void ToolBarIcons::create(HINSTANCE hInst, int iconSize) _iconListVector[HLIST_DISABLE].create(hInst, iconSize); //_iconListVector[HLIST_UGLY].create(hInst, 16); - for (size_t i = 0 ; i < _tbiis.size() ; i++) - { - _cmdArray[_nbCmd++] = _tbiis[i]._cmdID; - if (_tbiis[i]._defaultIcon != IDI_SEPARATOR_ICON) - { - _iconListVector[HLIST_DEFAULT].addIcon(_tbiis[i]._defaultIcon); - _iconListVector[HLIST_HOT].addIcon(_tbiis[i]._hotIcon); - _iconListVector[HLIST_DISABLE].addIcon(_tbiis[i]._grayIcon); - //_iconListVector[HLIST_UGLY].addImage(_tbiis[i]._uglyIcon); - } - } + reInit(iconSize); } void ToolBarIcons::destroy() @@ -68,3 +59,4 @@ bool IconList::changeIcon(int index, const char *iconLocation) const } */ + diff --git a/PowerEditor/src/WinControls/ImageListSet/ImageListSet.h b/PowerEditor/src/WinControls/ImageListSet/ImageListSet.h index 3cde5a64c..8297653a6 100644 --- a/PowerEditor/src/WinControls/ImageListSet/ImageListSet.h +++ b/PowerEditor/src/WinControls/ImageListSet/ImageListSet.h @@ -30,9 +30,10 @@ class IconList public : IconList() : _hImglst(NULL) {}; - void create(HINSTANCE hInst, int iconSize) {_iconSize = iconSize; + void create(HINSTANCE hInst, int iconSize) { + InitCommonControls(); _hInst = hInst; - InitCommonControls(); + _iconSize = iconSize; _hImglst = ImageList_Create(iconSize, iconSize, ILC_COLOR32 | ILC_MASK, 0, nbMax); if (!_hImglst) throw int(25); @@ -59,7 +60,7 @@ public : if (!hIcon) throw int(26); ImageList_AddIcon(_hImglst, hIcon); - //ImageList_AddMasked(_hImglst, (HBITMAP)hBmp, RGB(0, 0, 0)); + //ImageList_AddMasked(_hImglst, hBmp, RGB(0, 0, 0)); ::DeleteObject(hIcon); //::DeleteObject(hBmp); }; @@ -112,7 +113,7 @@ typedef struct int _hotIcon; int _grayIcon; - int _uglyIcon; + int _stdIcon; }ToolBarButtonUnit; typedef std::vector ToolBarIconIDs; @@ -183,8 +184,8 @@ public : return int(_tbiis.size()); }; - int getUglyIconAt(int i) const { - return _tbiis[i]._uglyIcon; + int getStdIconAt(int i) const { + return _tbiis[i]._stdIcon; }; bool replaceIcon(int witchList, int iconIndex, const char *iconLocation) const { diff --git a/PowerEditor/src/WinControls/ToolBar/ToolBar.cpp b/PowerEditor/src/WinControls/ToolBar/ToolBar.cpp index 48946e669..0c58b5ad7 100644 --- a/PowerEditor/src/WinControls/ToolBar/ToolBar.cpp +++ b/PowerEditor/src/WinControls/ToolBar/ToolBar.cpp @@ -19,18 +19,18 @@ #include "ToolBar.h" #include "SysMsg.h" -const bool ToolBar::REDUCED = true; -const bool ToolBar::ENLARGED = false; -const int WS_TOOLBARSTYLE = WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | TBSTYLE_TOOLTIPS |TBSTYLE_FLAT | CCS_TOP | BTNS_AUTOSIZE; +const int WS_TOOLBARSTYLE = WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | TBSTYLE_TOOLTIPS |TBSTYLE_FLAT | CCS_TOP | BTNS_AUTOSIZE | CCS_NOPARENTALIGN | CCS_NORESIZE; -bool ToolBar::init(HINSTANCE hInst, HWND hPere, int iconSize, - ToolBarButtonUnit *buttonUnitArray, int arraySize, - bool doUglyStandardIcon, int *bmpArray, int bmpArraySize) +bool ToolBar::init( HINSTANCE hInst, HWND hPere, toolBarStatusType type, + ToolBarButtonUnit *buttonUnitArray, int arraySize) { Window::init(hInst, hPere); - _state = doUglyStandardIcon?TB_STANDARD:(iconSize >= 32?TB_LARGE:TB_SMALL); - _bmpArray = bmpArray; - _bmpArraySize = bmpArraySize; + if (type == TB_HIDE) { + setState(TB_STANDARD); //assume standard + _visible = false; //but set visibility to false + } + _state = type; + int iconSize = (_state == TB_LARGE?32:16); _toolBarIcons.init(buttonUnitArray, arraySize); _toolBarIcons.create(_hInst, iconSize); @@ -40,17 +40,106 @@ bool ToolBar::init(HINSTANCE hInst, HWND hPere, int iconSize, icex.dwICC = ICC_WIN95_CLASSES|ICC_COOL_CLASSES|ICC_BAR_CLASSES|ICC_USEREX_CLASSES; InitCommonControlsEx(&icex); - _hSelf = ::CreateWindowEx( - WS_EX_PALETTEWINDOW , - TOOLBARCLASSNAME, - "", - WS_TOOLBARSTYLE, - 0, 0, - 0, 0, - _hParent, - NULL, - _hInst, - 0); + //Create the list of buttons + _nrButtons = arraySize; + _nrDynButtons = _vDynBtnReg.size(); + _nrTotalButtons = _nrButtons + (_nrDynButtons ? _nrDynButtons + 1 : 0); + _pTBB = new TBBUTTON[_nrTotalButtons]; //add one for the extra separator + + int cmd = 0; + int bmpIndex = -1, style; + size_t i = 0; + for (; i < _nrButtons ; i++) + { + cmd = buttonUnitArray[i]._cmdID; + if (cmd != 0) + { + bmpIndex++; + style = BTNS_BUTTON; + } + else + { + style = BTNS_SEP; + } + + _pTBB[i].iBitmap = (cmd != 0?bmpIndex:0); + _pTBB[i].idCommand = cmd; + _pTBB[i].fsState = TBSTATE_ENABLED; + _pTBB[i].fsStyle = style; + _pTBB[i].dwData = 0; + _pTBB[i].iString = 0; + } + + if (_nrDynButtons > 0) { + //add separator + _pTBB[i].iBitmap = 0; + _pTBB[i].idCommand = 0; + _pTBB[i].fsState = TBSTATE_ENABLED; + _pTBB[i].fsStyle = BTNS_SEP; + _pTBB[i].dwData = 0; + _pTBB[i].iString = 0; + i++; + //add plugin buttons + for (size_t j = 0; j < _nrDynButtons ; j++, i++) + { + cmd = _vDynBtnReg[j].message; + bmpIndex++; + + _pTBB[i].iBitmap = bmpIndex; + _pTBB[i].idCommand = cmd; + _pTBB[i].fsState = TBSTATE_ENABLED; + _pTBB[i].fsStyle = BTNS_BUTTON; + _pTBB[i].dwData = 0; + _pTBB[i].iString = 0; + } + } + + reset(true); //load icons etc + + return true; +} + +int ToolBar::getWidth() const { + RECT btnRect; + int totalWidth = 0; + for(size_t i = 0; i < _nrCurrentButtons; i++) { + ::SendMessage(_hSelf, TB_GETITEMRECT, i, (LPARAM)&btnRect); + totalWidth += btnRect.right - btnRect.left; + } + return totalWidth; +} + +void ToolBar::reset(bool create) +{ + + if(create && _hSelf) { + //Store current button state information + TBBUTTON tempBtn; + for(size_t i = 0; i < _nrCurrentButtons; i++) { + ::SendMessage(_hSelf, TB_GETBUTTON, (WPARAM)i, (LPARAM)&tempBtn); + _pTBB[i].fsState = tempBtn.fsState; + } + ::DestroyWindow(_hSelf); + _hSelf = NULL; + } + + if(!_hSelf) { + _hSelf = ::CreateWindowEx( + WS_EX_PALETTEWINDOW, + TOOLBARCLASSNAME, + "", + WS_TOOLBARSTYLE, + 0, 0, + 0, 0, + _hParent, + NULL, + _hInst, + 0); + // Send the TB_BUTTONSTRUCTSIZE message, which is required for + // backward compatibility. + ::SendMessage(_hSelf, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0); + //::SendMessage(_hSelf, TB_SETEXTENDEDSTYLE, 0, (LPARAM)TBSTYLE_EX_HIDECLIPPEDBUTTONS); + } if (!_hSelf) { @@ -58,266 +147,42 @@ bool ToolBar::init(HINSTANCE hInst, HWND hPere, int iconSize, throw int(9); } - // Send the TB_BUTTONSTRUCTSIZE message, which is required for - // backward compatibility. - ::SendMessage(_hSelf, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0); - - if (!doUglyStandardIcon) + if (_state != TB_STANDARD) { + //If non standard icons, use custom imagelists setDefaultImageList(); setHotImageList(); setDisableImageList(); } else { - ::SendMessage(_hSelf, TB_LOADIMAGES, IDB_STD_SMALL_COLOR, reinterpret_cast(HINST_COMMCTRL)); - - if (bmpArray) - { - TBADDBITMAP addbmp = {_hInst, 0}; - for (int i = 0 ; i < _bmpArraySize ; i++) - { - if ((i == _bmpArraySize - 1) && (_vDynBtnReg.size() != 0)) - { - TBADDBITMAP addbmpdyn = {0, 0}; - for (size_t j = 0; j < _vDynBtnReg.size(); j++) - { - addbmpdyn.nID = (INT_PTR)_vDynBtnReg[j].hBmp; - ::SendMessage(_hSelf, TB_ADDBITMAP, 1, (LPARAM)&addbmpdyn); - } - } - - addbmp.nID = _bmpArray[i]; - ::SendMessage(_hSelf, TB_ADDBITMAP, 1, (LPARAM)&addbmp); - } - } - - } - - _pTBB = new TBBUTTON[_toolBarIcons.getNbCommand() + (_vDynBtnReg.size() ? _vDynBtnReg.size() + 1 : 0)]; - unsigned int nbElement = _toolBarIcons.getNbCommand(); - unsigned int nbDynIncPos = nbElement; - - if (doUglyStandardIcon) - { - nbDynIncPos -= 2; - nbElement += (_vDynBtnReg.size() ? _vDynBtnReg.size() + 1 : 0); - } - - int inc = 1; - - for (size_t i = 0, j = 0, k = 0; i < nbElement; i++) - { - int cmd = 0; - int bmpIndex, style; - - if ((i > nbDynIncPos) && (_vDynBtnReg.size() != 0) && (j <= _vDynBtnReg.size())) - { - if (j < _vDynBtnReg.size()) - { - cmd = _vDynBtnReg[j].message; - bmpIndex = (STD_PRINT + (inc++)); - style = BTNS_BUTTON; - } - else - { - bmpIndex = 0; - style = BTNS_SEP; - } - j++; - } - else - { - if ((cmd = _toolBarIcons.getCommandAt(i - j)) != 0) - { - if (doUglyStandardIcon) - { - int ibmp = _toolBarIcons.getUglyIconAt(i - j); - bmpIndex = (ibmp == -1)?(STD_PRINT + (inc++)):ibmp; - } - else - bmpIndex = k++; - - style = BTNS_BUTTON; - } - else - { - bmpIndex = 0; - style = BTNS_SEP; - } - } - _pTBB[i].iBitmap = bmpIndex; - _pTBB[i].idCommand = cmd; - _pTBB[i].fsState = TBSTATE_ENABLED; - _pTBB[i].fsStyle = style; - _pTBB[i].dwData = 0; - _pTBB[i].iString = 0; - - } - - setButtonSize(iconSize, iconSize); - - ::SendMessage(_hSelf, TB_ADDBUTTONS, (WPARAM)nbElement, (LPARAM)_pTBB); - ::SendMessage(_hSelf, TB_AUTOSIZE, 0, 0); - - return true; -} - -void ToolBar::reset() -{ - setDefaultImageList(); - setHotImageList(); - setDisableImageList(); - - if (_state == TB_STANDARD) - { - int cmdElement = _toolBarIcons.getNbCommand(); - int nbElement = cmdElement + (_vDynBtnReg.size() ? _vDynBtnReg.size() + 1 : 0); - - for (int i = 0, j = 0, k = nbElement-1 ; i < nbElement ; i++, k--) - { - int cmd = 0; - int bmpIndex, style; - - ::SendMessage(_hSelf, TB_DELETEBUTTON, k, 0); - - if (i >= cmdElement) - { - bmpIndex = -1; - cmd = 0; - style = 0; - } - else if ((cmd = _toolBarIcons.getCommandAt(i)) != 0) - { - bmpIndex = j++; - style = BTNS_BUTTON; - } - else - { - bmpIndex = 0; - style = BTNS_SEP; - } - _pTBB[i].iBitmap = bmpIndex; - _pTBB[i].idCommand = cmd; - _pTBB[i].fsState = TBSTATE_ENABLED; - _pTBB[i].fsStyle = style; - _pTBB[i].dwData = 0; - _pTBB[i].iString = 0; - } - - ::SendMessage(_hSelf, TB_ADDBUTTONS, (WPARAM)nbElement, (LPARAM)_pTBB); - } - - ::SendMessage(_hSelf, TB_AUTOSIZE, 0, 0); -} - -void ToolBar::setToUglyIcons() -{ - if (_state == TB_STANDARD) - return; - - // Due to the drawback of toolbar control (in-coexistence of Imagelist - custom icons and Bitmap - Std icons), - // We have to destroy the control then re-initialize it - ::DestroyWindow(_hSelf); - - //_state = REDUCED; - - _hSelf = ::CreateWindowEx( - WS_EX_PALETTEWINDOW , - TOOLBARCLASSNAME, - "", - WS_TOOLBARSTYLE, - 0, 0, - 0, 0, - _hParent, - NULL, - _hInst, - 0); - - if (!_hSelf) - { - systemMessage("System Err"); - throw int(9); - } - - // Send the TB_BUTTONSTRUCTSIZE message, which is required for - // backward compatibility. - ::SendMessage(_hSelf, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0); - - ::SendMessage(_hSelf, TB_LOADIMAGES, IDB_STD_SMALL_COLOR, reinterpret_cast(HINST_COMMCTRL)); - - if (_bmpArray) - { + //Else set the internal imagelist with standard bitmaps TBADDBITMAP addbmp = {_hInst, 0}; - for (int i = 0 ; i < _bmpArraySize ; i++) + TBADDBITMAP addbmpdyn = {0, 0}; + for (size_t i = 0 ; i < _nrButtons ; i++) { - if ((i == _bmpArraySize - 1) && (_vDynBtnReg.size() != 0)) - { - TBADDBITMAP addbmpdyn = {0, 0}; - for (size_t j = 0; j < _vDynBtnReg.size(); j++) - { - addbmpdyn.nID = (INT_PTR)_vDynBtnReg[j].hBmp; - ::SendMessage(_hSelf, TB_ADDBITMAP, 1, (LPARAM)&addbmpdyn); - } - } - - addbmp.nID = _bmpArray[i]; + addbmp.nID = _toolBarIcons.getStdIconAt(i); ::SendMessage(_hSelf, TB_ADDBITMAP, 1, (LPARAM)&addbmp); } - } - - unsigned int nbElement = _toolBarIcons.getNbCommand() + (_vDynBtnReg.size() ? _vDynBtnReg.size() + 1 : 0); - unsigned int nbDynIncPos = _toolBarIcons.getNbCommand() - 2; - int inc = 1; - - for (size_t i = 0, j = 0 ; i < nbElement ; i++) - { - int cmd = 0; - int bmpIndex, style; - - if ((i > nbDynIncPos) && (_vDynBtnReg.size() != 0) && (j <= _vDynBtnReg.size())) - { - if (j < _vDynBtnReg.size()) + if (_nrDynButtons > 0) { + for (size_t j = 0; j < _nrDynButtons; j++) { - cmd = _vDynBtnReg[j].message; - bmpIndex = (STD_PRINT + (inc++)); - style = BTNS_BUTTON; - } - else - { - bmpIndex = 0; - style = BTNS_SEP; - } - j++; - } - else - { - if ((cmd = _toolBarIcons.getCommandAt(i - j)) != 0) - { - int ibmp = _toolBarIcons.getUglyIconAt(i - j); - bmpIndex = (ibmp == -1)?(STD_PRINT + (inc++)):ibmp; - style = BTNS_BUTTON; - } - else - { - bmpIndex = 0; - style = BTNS_SEP; + addbmpdyn.nID = (UINT_PTR)_vDynBtnReg.at(j).hBmp; + ::SendMessage(_hSelf, TB_ADDBITMAP, 1, (LPARAM)&addbmpdyn); } } - _pTBB[i].iBitmap = bmpIndex; - _pTBB[i].idCommand = cmd; - _pTBB[i].fsState = TBSTATE_ENABLED; - _pTBB[i].fsStyle = style; - _pTBB[i].dwData = 0; - _pTBB[i].iString = 0; - } - setButtonSize(16, 16); - - ::SendMessage(_hSelf, TB_ADDBUTTONS, (WPARAM)nbElement, (LPARAM)_pTBB); + if (create) { //if the toolbar has been recreated, readd the buttons + size_t nrBtnToAdd = (_state == TB_STANDARD?_nrTotalButtons:_nrButtons); + _nrCurrentButtons = nrBtnToAdd; + WORD btnSize = (_state == TB_LARGE?32:16); + ::SendMessage(_hSelf, TB_SETBUTTONSIZE , (WPARAM)0, (LPARAM)MAKELONG (btnSize, btnSize)); + ::SendMessage(_hSelf, TB_ADDBUTTONS, (WPARAM)nrBtnToAdd, (LPARAM)_pTBB); + if (_visible) + Window::display(true); + } ::SendMessage(_hSelf, TB_AUTOSIZE, 0, 0); - _state = TB_STANDARD; } void ToolBar::registerDynBtn(UINT messageID, toolbarIcons* tIcon) @@ -337,25 +202,47 @@ void ReBar::init(HINSTANCE hInst, HWND hPere, ToolBar *pToolBar) { Window::init(hInst, hPere); _pToolBar = pToolBar; + _hSelf = CreateWindowEx(WS_EX_TOOLWINDOW, REBARCLASSNAME, NULL, - WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS| - WS_CLIPCHILDREN|RBS_VARHEIGHT| - CCS_NODIVIDER, + WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|RBS_VARHEIGHT| + RBS_BANDBORDERS | CCS_NODIVIDER | CCS_NOPARENTALIGN, 0,0,0,0, _hParent, NULL, _hInst, NULL); + ZeroMemory(&_rbi, sizeof(REBARINFO)); + _rbi.cbSize = sizeof(REBARINFO); + _rbi.fMask = 0; + _rbi.himl = (HIMAGELIST)NULL; ::SendMessage(_hSelf, RB_SETBARINFO, 0, (LPARAM)&_rbi); + DWORD size = (DWORD)SendMessage(_pToolBar->getHSelf(), TB_GETBUTTONSIZE, 0, 0); + DWORD padding = (DWORD)SendMessage(_pToolBar->getHSelf(), TB_GETPADDING, 0,0); + + ZeroMemory(&_rbBand, sizeof(REBARBANDINFO)); + _rbBand.cbSize = sizeof(REBARBANDINFO); + _rbBand.fMask = RBBIM_STYLE | RBBIM_CHILD | RBBIM_CHILDSIZE | + RBBIM_SIZE | RBBIM_IDEALSIZE; + _rbBand.fStyle = 0;//RBBS_USECHEVRON; _rbBand.hwndChild = _pToolBar->getHSelf(); - - int dwBtnSize = SendMessage(_pToolBar->getHSelf(), TB_GETBUTTONSIZE, 0,0); - - _rbBand.cxMinChild = 34;//nbElement; - _rbBand.cyMinChild = HIWORD(dwBtnSize); - _rbBand.cx = 250; + _rbBand.cxMinChild = 0; + _rbBand.cyMinChild = HIWORD(size) + HIWORD(padding); + _rbBand.cyMaxChild = HIWORD(size) + HIWORD(padding); + _rbBand.cyIntegral = 1; + _rbBand.cxIdeal = _rbBand.cx = _pToolBar->getWidth(); ::SendMessage(_hSelf, RB_INSERTBAND, (WPARAM)0, (LPARAM)&_rbBand); } +void ReBar::reNew() { + int dwBtnSize = SendMessage(_pToolBar->getHSelf(), TB_GETBUTTONSIZE, 0,0); + + _rbBand.hwndChild = _pToolBar->getHSelf(); + _rbBand.cyMinChild = HIWORD(dwBtnSize); + _rbBand.cyMaxChild = HIWORD(dwBtnSize); + _rbBand.cxIdeal = _pToolBar->getWidth(); + ::SendMessage(_hSelf, RB_SETBANDINFO, (WPARAM)0, (LPARAM)&_rbBand); +}; + + diff --git a/PowerEditor/src/WinControls/ToolBar/ToolBar.h b/PowerEditor/src/WinControls/ToolBar/ToolBar.h index 2b74c6a6a..fe2a25ac1 100644 --- a/PowerEditor/src/WinControls/ToolBar/ToolBar.h +++ b/PowerEditor/src/WinControls/ToolBar/ToolBar.h @@ -60,14 +60,11 @@ typedef struct { class ToolBar : public Window { public : - const static bool REDUCED; - const static bool ENLARGED; - ToolBar():Window(), _pTBB(NULL){}; + ToolBar():Window(), _pTBB(NULL), _nrButtons(0), _nrDynButtons(0), _nrTotalButtons(0), _nrCurrentButtons(0), _visible(true) {}; virtual ~ToolBar(){}; - virtual bool init(HINSTANCE hInst, HWND hPere, int iconSize, - ToolBarButtonUnit *buttonUnitArray, int arraySize, - bool doUglyStandardIcon = false, int *bmpArray = NULL, int bmpArraySize = 0); + virtual bool init(HINSTANCE hInst, HWND hPere, toolBarStatusType type, + ToolBarButtonUnit *buttonUnitArray, int arraySize); virtual void destroy() { delete [] _pTBB; @@ -85,33 +82,45 @@ public : return Window::getHeight(); }; + int getWidth() const; + void reduce() { if (_state == TB_SMALL) return; - // I really don't know why we have to enlarge then reduce - // to take the effect. - if (_state == TB_STANDARD) - _toolBarIcons.resizeIcon(32); _toolBarIcons.resizeIcon(16); - reset(); - + bool recreate = (_state == TB_STANDARD); + setState(TB_SMALL); + reset(recreate); //recreate toolbar if std icons were used Window::redraw(); - _state = TB_SMALL; }; void enlarge() { if (_state == TB_LARGE) return; + _toolBarIcons.resizeIcon(32); - reset(); + bool recreate = (_state == TB_STANDARD); + setState(TB_LARGE); + reset(recreate); //recreate toolbar if std icons were used Window::redraw(); - _state = TB_LARGE; }; + void setToUglyIcons() { + if (_state == TB_STANDARD) + return; + bool recreate = true; + setState(TB_STANDARD); + reset(recreate); //must recreate toolbar if setting to internal bitmaps + Window::redraw(); + } + void hide() { + if (getState() == TB_HIDE) + return; + display(false); + } void display(bool toShow = true) { Window::display(toShow); - if (!toShow) - _state = TB_HIDE; + _visible = toShow; }; bool getCheckState(int ID2Check) const { @@ -122,9 +131,10 @@ public : ::SendMessage(_hSelf, TB_CHECKBUTTON, (WPARAM)ID2Check, (LPARAM)MAKELONG(willBeChecked, 0)); }; - toolBarStatusType getState() const {return _state;}; - - void setToUglyIcons(); + toolBarStatusType getState() const { + bool test = _visible; + return _visible?_state:TB_HIDE; + }; bool changeIcons(int whichLst, int iconIndex, const char *iconLocation){ return _toolBarIcons.replaceIcon(whichLst, iconIndex, iconLocation); @@ -136,9 +146,12 @@ private : TBBUTTON *_pTBB; ToolBarIcons _toolBarIcons; toolBarStatusType _state; - int *_bmpArray; - int _bmpArraySize; - vector _vDynBtnReg; + bool _visible; + vector _vDynBtnReg; + size_t _nrButtons; + size_t _nrDynButtons; + size_t _nrTotalButtons; + size_t _nrCurrentButtons; void setDefaultImageList() { @@ -151,33 +164,22 @@ private : ::SendMessage(_hSelf, TB_SETDISABLEDIMAGELIST, (WPARAM)0, (LPARAM)_toolBarIcons.getDisableLst()); }; - - - void setButtonSize(int w, int h) { - ::SendMessage(_hSelf, TB_SETBUTTONSIZE , (WPARAM)0, (LPARAM)MAKELONG (w, h)); - }; - - void reset(); + void reset(bool create = false); + void setState(toolBarStatusType state) { + if(state == TB_HIDE) { //do not set the state to something else + _visible = false; + } else { + _visible = true; + _state = state; + } + } }; class ReBar : public Window { public : - ReBar():Window(), _pToolBar(NULL) { - _rbi.cbSize = sizeof(REBARINFO); - _rbi.fMask = 0; - _rbi.himl = (HIMAGELIST)NULL; - - _rbBand.cbSize = sizeof(REBARBANDINFO); - _rbBand.fMask = /*RBBIM_COLORS | RBBIM_TEXT | RBBIM_BACKGROUND | \*/ - RBBIM_STYLE | RBBIM_CHILD | RBBIM_CHILDSIZE | \ - RBBIM_SIZE; - - _rbBand.fStyle = RBBS_FIXEDSIZE | RBBS_CHILDEDGE; - _rbBand.hbmBack = NULL; - _rbBand.lpText = "Toolbar"; - }; + ReBar():Window(), _pToolBar(NULL) {}; virtual void destroy() { ::DestroyWindow(_hSelf); @@ -185,12 +187,7 @@ public : }; void init(HINSTANCE hInst, HWND hPere, ToolBar *pToolBar); - void reNew() { - _rbBand.hwndChild = _pToolBar->getHSelf(); - int dwBtnSize = SendMessage(_pToolBar->getHSelf(), TB_GETBUTTONSIZE, 0,0); - _rbBand.cyMinChild = HIWORD(dwBtnSize); - ::SendMessage(_hSelf, RB_SETBANDINFO, (WPARAM)0, (LPARAM)&_rbBand); - }; + void reNew(); private: REBARINFO _rbi;