From 0d932b764bd83a2880970d9b071a902e9fb1ec67 Mon Sep 17 00:00:00 2001 From: donho Date: Fri, 28 Mar 2008 01:49:51 +0000 Subject: [PATCH] [ENHANCEMENT]Improve toolbar performance. Internals prepped for later extensions. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@156 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/Notepad_plus.cpp | 174 +++++------------- PowerEditor/src/Notepad_plus.h | 21 --- PowerEditor/src/Parameters.cpp | 23 ++- PowerEditor/src/Parameters.h | 5 +- .../src/WinControls/Preference/preference.rc | 2 +- .../WinControls/Preference/preferenceDlg.cpp | 11 +- .../WinControls/Preference/preference_rc.h | 2 +- .../src/WinControls/ToolBar/ToolBar.cpp | 71 ++++--- PowerEditor/src/WinControls/ToolBar/ToolBar.h | 56 ++---- PowerEditor/src/WinControls/Window.h | 5 +- 10 files changed, 137 insertions(+), 233 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 92f17142..b3236ed2 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -153,9 +153,6 @@ Notepad_plus::Notepad_plus(): Window(), _mainWindowStatus(0), _pDocTab(NULL), _p _toolIcons = NULL; } - - - // ATTENTION : the order of the destruction is very important // because if the parent's window hadle is destroyed before // the destruction of its childrens' windows handle, @@ -341,6 +338,7 @@ bool Notepad_plus::saveGUIParams() { NppGUI & nppGUI = (NppGUI &)(NppParameters::getInstance())->getNppGUI(); nppGUI._statusBarShow = _statusBar.isVisible(); + nppGUI._toolbarShow = _rebar.getIDVisible(REBAR_BAR_TOOLBAR); nppGUI._toolBarStatus = _toolBar.getState(); nppGUI._tabStatus = (TabBarPlus::doDragNDropOrNot()?TAB_DRAWTOPBAR:0) | \ @@ -542,10 +540,10 @@ bool Notepad_plus::loadSession(Session & session) allSessionFilesLoaded = false; } } - if (session._activeMainIndex < _mainDocTab.nbItem())//session.nbMainFiles()) + if (session._activeMainIndex < (size_t)_mainDocTab.nbItem())//session.nbMainFiles()) _mainDocTab.activate(session._activeMainIndex); - if (session._activeSubIndex < _subDocTab.nbItem())//session.nbSubFiles()) + if (session._activeSubIndex < (size_t)_subDocTab.nbItem())//session.nbSubFiles()) _subDocTab.activate(session._activeSubIndex); if ((session.nbSubFiles() > 0) && (session._activeView == MAIN_VIEW || session._activeView == SUB_VIEW)) @@ -2253,6 +2251,12 @@ BOOL Notepad_plus::notify(SCNotification *notification) break; } + case RBN_HEIGHTCHANGE: + { + SendMessage(_hSelf, WM_SIZE, 0, 0); + break; + } + default : break; @@ -3143,69 +3147,45 @@ void Notepad_plus::command(int id) case IDM_VIEW_TOOLBAR_HIDE: { - int checkedID = getToolBarState(); - - if (checkedID != IDM_VIEW_TOOLBAR_HIDE) - { - RECT rc; - getClientRect(rc); - _toolBar.display(false); - ::SendMessage(_hSelf, WM_SIZE, SIZE_RESTORED, MAKELONG(rc.bottom, rc.right)); - checkToolBarMenu(id); - } + bool toSet = !_rebar.getIDVisible(REBAR_BAR_TOOLBAR); + _rebar.setIDVisible(REBAR_BAR_TOOLBAR, toSet); } break; case IDM_VIEW_TOOLBAR_REDUCE: { - int checkedID = getToolBarState(); + toolBarStatusType state = _toolBar.getState(); - if (checkedID != IDM_VIEW_TOOLBAR_REDUCE) + if (state != TB_SMALL) { - RECT rc; - getClientRect(rc); _toolBar.reduce(); - _toolBar.display(); _rebar.reNew(); - _rebar.display(); - ::SendMessage(_hSelf, WM_SIZE, SIZE_RESTORED, MAKELONG(rc.bottom, rc.right)); - //changeToolBarIcons(); - checkToolBarMenu(id); + changeToolBarIcons(); } } break; case IDM_VIEW_TOOLBAR_ENLARGE: { - int checkedID = getToolBarState(); - if (checkedID != IDM_VIEW_TOOLBAR_ENLARGE) + toolBarStatusType state = _toolBar.getState(); + + if (state != TB_LARGE) { - RECT rc; - getClientRect(rc); _toolBar.enlarge(); - _toolBar.display(); _rebar.reNew(); - _rebar.display(); - ::SendMessage(_hSelf, WM_SIZE, SIZE_RESTORED, MAKELONG(rc.bottom, rc.right)); - changeToolBarIcons(); - checkToolBarMenu(id); + changeToolBarIcons(); } } break; case IDM_VIEW_TOOLBAR_STANDARD: - { - int checkedID = getToolBarState(); - if (checkedID != IDM_VIEW_TOOLBAR_STANDARD) + { + toolBarStatusType state = _toolBar.getState(); + + if (state != TB_STANDARD) { - RECT rc; - getClientRect(rc); _toolBar.setToUglyIcons(); - _toolBar.display(); _rebar.reNew(); - _rebar.display(); - ::SendMessage(_hSelf, WM_SIZE, SIZE_RESTORED, MAKELONG(rc.bottom, rc.right)); - checkToolBarMenu(id); } } break; @@ -3239,9 +3219,7 @@ void Notepad_plus::command(int id) break; } - - - + case IDM_VIEW_REFRESHTABAR : { RECT rc; @@ -4774,14 +4752,14 @@ void Notepad_plus::reload(const char *fileName) void Notepad_plus::getMainClientRect(RECT &rc) const { Window::getClientRect(rc); - rc.top += _toolBar.getHeight() + 2; - rc.bottom -= _toolBar.getHeight() + 2 +_statusBar.getHeight(); + rc.top += _rebar.getHeight(); + rc.bottom -= _rebar.getHeight() +_statusBar.getHeight(); } void Notepad_plus::getToolBarClientRect(RECT &rc) const { Window::getClientRect(rc); - rc.bottom = _toolBar.getHeight(); + rc.bottom = _rebar.getHeight();//_toolBar.getHeight(); } void Notepad_plus::getStatusBarClientRect(RECT & rc) const @@ -6543,6 +6521,7 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa //-- Tool Bar Section --// toolBarStatusType tbStatus = nppGUI._toolBarStatus; + willBeShown = nppGUI._toolbarShow; // To notify plugins that toolbar icons can be registered SCNotification scnN; @@ -6551,34 +6530,12 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa scnN.nmhdr.idFrom = 0; _pluginsManager.notify(&scnN); - // TB_LARGE par default - int iconSize = 32; - int menuID = IDM_VIEW_TOOLBAR_ENLARGE; - - if (tbStatus == TB_HIDE) - { - willBeShown = false; - menuID = IDM_VIEW_TOOLBAR_HIDE; - } - else if (tbStatus == TB_SMALL) - { - iconSize = 16; - menuID = IDM_VIEW_TOOLBAR_REDUCE; - } - else if (tbStatus == TB_STANDARD) - { - iconSize = 16; - menuID = IDM_VIEW_TOOLBAR_STANDARD; - } - - _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.setIDVisible(REBAR_BAR_TOOLBAR, willBeShown); //launch the plugin dlg memorized at the last session DockingManagerData &dmd = nppGUI._dockingData; @@ -6761,41 +6718,16 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa } break; - case WM_GETMINMAXINFO: - { - MINMAXINFO *pmmi = reinterpret_cast(lParam); -/* - if (_isfullScreen) - { - pmmi->ptMaxSize.x = ::GetSystemMetrics(SM_CXSCREEN) + 2 * ::GetSystemMetrics(SM_CXSIZEFRAME) + 2; - pmmi->ptMaxSize.y = ::GetSystemMetrics(SM_CYSCREEN) + - ::GetSystemMetrics(SM_CYCAPTION) + - ::GetSystemMetrics(SM_CYMENU) + - 2 * ::GetSystemMetrics(SM_CYSIZEFRAME) + - _toolBar.getHeight() + 2 + - 13; - - pmmi->ptMaxTrackSize.x = pmmi->ptMaxSize.x; - pmmi->ptMaxTrackSize.y = pmmi->ptMaxSize.y; - result = 0; // Je sais, c'est bizarre, mais selons le doc... - } - else - { -*/ - result = ::DefWindowProc(_hSelf, Message, wParam, lParam); -// } - } - break; - case WM_SIZE: { + if (lParam == 0) { + RECT winRect; + getClientRect(winRect); + lParam = MAKELPARAM(winRect.right - winRect.left, winRect.bottom - winRect.top); + } RECT rc; - //getToolBarClientRect(rc); - //_toolBar.reSizeTo(rc); - - ::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); @@ -7928,7 +7860,7 @@ LRESULT CALLBACK Notepad_plus::Notepad_plus_Proc(HWND hwnd, UINT Message, WPARAM switch(Message) { - case WM_GETMINMAXINFO : // It's the 1st? msg (even before WM_NCCREATE) + /* case WM_GETMINMAXINFO : // It's the 1st? msg (even before WM_NCCREATE) { if (isFirstGetMinMaxInfoMsg) { @@ -7937,7 +7869,7 @@ LRESULT CALLBACK Notepad_plus::Notepad_plus_Proc(HWND hwnd, UINT Message, WPARAM } else return ((Notepad_plus *)::GetWindowLong(hwnd, GWL_USERDATA))->runProc(hwnd, Message, wParam, lParam); - } + }*/ case WM_NCCREATE : // First message we get the ptr of instantiated object // then stock it into GWL_USERDATA index in order to retrieve afterward @@ -7994,9 +7926,8 @@ void Notepad_plus::fullScreenToggle() //Hide window so windows can properly update it ::ShowWindow(_hSelf, SW_HIDE); - //Get state of toolbar and hide it - _prevTBState = _toolBar.getState(); - SendMessage(_hSelf, WM_COMMAND, IDM_VIEW_TOOLBAR_HIDE, 0); + //Hide rebar + _rebar.display(false); //Set popup style for fullscreen window and store the old style _prevStyles = ::SetWindowLongPtr( _hSelf, GWL_STYLE, WS_POPUP ); @@ -8017,23 +7948,8 @@ void Notepad_plus::fullScreenToggle() ::SetWindowLongPtr( _hSelf, GWL_STYLE, _prevStyles); ::SetWindowPos(_hSelf, HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOREDRAW|SWP_NOZORDER); - //Restore the toolbar to its previous state - int cmdToSend = 0; - switch(_prevTBState) { - case TB_HIDE: - cmdToSend = IDM_VIEW_TOOLBAR_HIDE; - break; - case TB_SMALL: - cmdToSend = IDM_VIEW_TOOLBAR_REDUCE; - break; - case TB_LARGE: - cmdToSend = IDM_VIEW_TOOLBAR_ENLARGE; - break; - case TB_STANDARD: - cmdToSend = IDM_VIEW_TOOLBAR_STANDARD; - break; - } - SendMessage(_hSelf, WM_COMMAND, cmdToSend, 0); + //Show rebar + _rebar.display(true); if (_winPlace.length) { @@ -8180,7 +8096,7 @@ void Notepad_plus::getCurrentOpenedFiles(Session & session) for (size_t i = 0 ; i < _mainEditView.getNbDoc() ; i++) { const Buffer & buf = _mainEditView.getBufferAt((size_t)i); - if (PathFileExists(buf._fullPathName)) + if (!Buffer::isUntitled(buf._fullPathName) && PathFileExists(buf._fullPathName)) { string languageName = getLangFromMenu( buf ); const char *langName = languageName.c_str(); @@ -8431,9 +8347,3 @@ winVer getWindowsVersion() return WV_UNKNOWN; } - - - - - - diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index 5113fb0c..245a4242 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -220,7 +220,6 @@ private: WindowsMenu _windowsMenu; HMENU _mainMenuHandle; LONG_PTR _prevStyles; - toolBarStatusType _prevTBState; // For FullScreen feature bool _isfullScreen; @@ -452,22 +451,6 @@ private: } }; - int getToolBarState() const { - if (::GetMenuState(_mainMenuHandle, IDM_VIEW_TOOLBAR_HIDE, MF_BYCOMMAND) == MF_CHECKED) - return IDM_VIEW_TOOLBAR_HIDE; - - if (::GetMenuState(_mainMenuHandle, IDM_VIEW_TOOLBAR_REDUCE, MF_BYCOMMAND) == MF_CHECKED) - return IDM_VIEW_TOOLBAR_REDUCE; - - if (::GetMenuState(_mainMenuHandle, IDM_VIEW_TOOLBAR_ENLARGE, MF_BYCOMMAND) == MF_CHECKED) - return IDM_VIEW_TOOLBAR_ENLARGE; - - if (::GetMenuState(_mainMenuHandle, IDM_VIEW_TOOLBAR_STANDARD, MF_BYCOMMAND) == MF_CHECKED) - return IDM_VIEW_TOOLBAR_STANDARD; - - return -1; - }; - int getFolderMarginStyle() const { if (::GetMenuState(_mainMenuHandle, IDM_VIEW_FOLDERMAGIN_SIMPLE, MF_BYCOMMAND) == MF_CHECKED) return IDM_VIEW_FOLDERMAGIN_SIMPLE; @@ -484,10 +467,6 @@ private: return 0; }; - void checkToolBarMenu(int id2Check) const { - ::CheckMenuRadioItem(::GetMenu(_hSelf), IDM_VIEW_TOOLBAR_HIDE, IDM_VIEW_TOOLBAR_STANDARD, id2Check, MF_BYCOMMAND); - }; - void checkFolderMarginStyleMenu(int id2Check) const { ::CheckMenuRadioItem(::GetMenu(_hSelf), IDM_VIEW_FOLDERMAGIN_SIMPLE, IDM_VIEW_FOLDERMAGIN_BOX, id2Check, MF_BYCOMMAND); }; diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index 3a8848c4..bb9e12b8 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -2029,19 +2029,28 @@ void NppParameters::feedGUIParameters(TiXmlNode *node) if (!strcmp(nm, "ToolBar")) { + val = element->Attribute("visible"); + if (val) + { + if (!strcmp(val, "no")) + _nppGUI._toolbarShow = false; + else// if (!strcmp(val, "yes")) + _nppGUI._toolbarShow = true; + } TiXmlNode *n = childNode->FirstChild(); if (n) { val = n->Value(); if (val) { - if (!strcmp(val, "hide")) - _nppGUI._toolBarStatus = TB_HIDE; - else if (!strcmp(val, "small")) + //if (!strcmp(val, "hide")) + // _nppGUI._toolBarStatus = TB_HIDE; + //else + if (!strcmp(val, "small")) _nppGUI._toolBarStatus = TB_SMALL; else if (!strcmp(val, "large")) _nppGUI._toolBarStatus = TB_LARGE; - else if (!strcmp(val, "standard")) + else// if (!strcmp(val, "standard")) //assume standard in all other cases _nppGUI._toolBarStatus = TB_STANDARD; } } @@ -2983,7 +2992,10 @@ bool NppParameters::writeGUIParams() if (!strcmp(nm, "ToolBar")) { - const char *pStr = _nppGUI._toolBarStatus == TB_HIDE?"hide":(_nppGUI._toolBarStatus == TB_SMALL?"small":(_nppGUI._toolBarStatus == TB_STANDARD?"standard":"large")); + const char *pStr = (_nppGUI._toolbarShow)?"yes":"no"; + element->SetAttribute("visible", pStr); + + pStr = _nppGUI._toolBarStatus == TB_SMALL?"small":(_nppGUI._toolBarStatus == TB_STANDARD?"standard":"large"); TiXmlNode *n = childNode->FirstChild(); if (n) n->SetValue(pStr); @@ -4000,3 +4012,4 @@ void NppParameters::addScintillaModifiedIndex(int index) + diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index a42dfb38..c0d23942 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -516,7 +516,7 @@ struct PrintSettings { struct NppGUI { - NppGUI() : _toolBarStatus(TB_LARGE), _statusBarShow(true), \ + NppGUI() : _toolBarStatus(TB_LARGE), _toolbarShow(true), _statusBarShow(true), \ _tabStatus(TAB_DRAWTOPBAR | TAB_DRAWINACTIVETAB | TAB_DRAGNDROP),\ _splitterPos(POS_HORIZOTAL), _userDefineDlgStatus(UDD_DOCKED), _tabSize(8),\ _tabReplacedBySpace(false), _fileAutoDetection(cdEnabled), _checkHistoryFiles(true),\ @@ -530,7 +530,8 @@ struct NppGUI _backupDir[0] = '\0'; }; - toolBarStatusType _toolBarStatus; // small, large ou hide + toolBarStatusType _toolBarStatus; // small, large ou standard + bool _toolbarShow; bool _statusBarShow; // show ou hide // 1st bit : draw top bar; diff --git a/PowerEditor/src/WinControls/Preference/preference.rc b/PowerEditor/src/WinControls/Preference/preference.rc index 22877cf5..05db1ccd 100644 --- a/PowerEditor/src/WinControls/Preference/preference.rc +++ b/PowerEditor/src/WinControls/Preference/preference.rc @@ -37,7 +37,7 @@ STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD FONT 8, "MS Shell Dlg", 0, 0, 0x1 BEGIN GROUPBOX "Tool bar",IDC_TOOLBAR_GB_STATIC,17,5,131,68,BS_CENTER - CONTROL "Hide",IDC_RADIO_HIDE,"Button",BS_AUTORADIOBUTTON,24,15,94,10 + CONTROL "Hide",IDC_CHECK_HIDE,"Button",BS_AUTOCHECKBOX,24,15,94,10 CONTROL "Small icons",IDC_RADIO_SMALLICON,"Button",BS_AUTORADIOBUTTON,24,29,114,10 CONTROL "Big icons",IDC_RADIO_BIGICON,"Button",BS_AUTORADIOBUTTON,24,43,109,10 CONTROL "Small standard icons",IDC_RADIO_STANDARD,"Button",BS_AUTORADIOBUTTON,24,57,119,10 diff --git a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp index 7b9f9c6d..45418bc4 100644 --- a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp +++ b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp @@ -116,23 +116,22 @@ BOOL CALLBACK BarsDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) const NppGUI & nppGUI = pNppParam->getNppGUI(); toolBarStatusType tbStatus = nppGUI._toolBarStatus; int tabBarStatus = nppGUI._tabStatus; + bool showTool = nppGUI._toolbarShow; bool showStatus = nppGUI._statusBarShow; + ::SendDlgItemMessage(_hSelf, IDC_CHECK_HIDE, BM_SETCHECK, showTool?BST_UNCHECKED:BST_CHECKED, 0); int ID2Check = 0; switch (tbStatus) { - case TB_HIDE : - ID2Check = IDC_RADIO_HIDE; - break; case TB_SMALL : ID2Check = IDC_RADIO_SMALLICON; break; case TB_LARGE : ID2Check = IDC_RADIO_BIGICON; break; - - default : //TB_STANDARD + case TB_STANDARD: + default : ID2Check = IDC_RADIO_STANDARD; } ::SendDlgItemMessage(_hSelf, ID2Check, BM_SETCHECK, BST_CHECKED, 0); @@ -220,7 +219,7 @@ BOOL CALLBACK BarsDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) ::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_DRAWTABBAR_DBCLK2CLOSE, 0); return TRUE; - case IDC_RADIO_HIDE : + case IDC_CHECK_HIDE : ::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_TOOLBAR_HIDE, 0); return TRUE; diff --git a/PowerEditor/src/WinControls/Preference/preference_rc.h b/PowerEditor/src/WinControls/Preference/preference_rc.h index ad15340e..21b92efa 100644 --- a/PowerEditor/src/WinControls/Preference/preference_rc.h +++ b/PowerEditor/src/WinControls/Preference/preference_rc.h @@ -23,7 +23,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #define IDD_PREFERENCE_BAR_BOX 6100 //(IDD_PREFERENCE_BOX + 100) #define IDC_TOOLBAR_GB_STATIC (IDD_PREFERENCE_BAR_BOX + 1) - #define IDC_RADIO_HIDE (IDD_PREFERENCE_BAR_BOX + 2) + #define IDC_CHECK_HIDE (IDD_PREFERENCE_BAR_BOX + 2) #define IDC_RADIO_SMALLICON (IDD_PREFERENCE_BAR_BOX + 3) #define IDC_RADIO_BIGICON (IDD_PREFERENCE_BAR_BOX + 4) #define IDC_RADIO_STANDARD (IDD_PREFERENCE_BAR_BOX + 5) diff --git a/PowerEditor/src/WinControls/ToolBar/ToolBar.cpp b/PowerEditor/src/WinControls/ToolBar/ToolBar.cpp index 0c58b5ad..d44f1677 100644 --- a/PowerEditor/src/WinControls/ToolBar/ToolBar.cpp +++ b/PowerEditor/src/WinControls/ToolBar/ToolBar.cpp @@ -19,16 +19,12 @@ #include "ToolBar.h" #include "SysMsg.h" -const int WS_TOOLBARSTYLE = WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | TBSTYLE_TOOLTIPS |TBSTYLE_FLAT | CCS_TOP | BTNS_AUTOSIZE | CCS_NOPARENTALIGN | CCS_NORESIZE; +const int WS_TOOLBARSTYLE = WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | TBSTYLE_TOOLTIPS |TBSTYLE_FLAT | CCS_TOP | BTNS_AUTOSIZE | CCS_NOPARENTALIGN | CCS_NORESIZE | CCS_NODIVIDER; bool ToolBar::init( HINSTANCE hInst, HWND hPere, toolBarStatusType type, ToolBarButtonUnit *buttonUnitArray, int arraySize) { Window::init(hInst, hPere); - 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); @@ -179,8 +175,6 @@ void ToolBar::reset(bool create) 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); } @@ -210,7 +204,6 @@ void ReBar::init(HINSTANCE hInst, HWND hPere, ToolBar *pToolBar) 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; @@ -223,26 +216,58 @@ void ReBar::init(HINSTANCE hInst, HWND hPere, ToolBar *pToolBar) 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; + RBBIM_SIZE | RBBIM_IDEALSIZE | RBBIM_ID; + + _rbBand.fStyle = RBBS_VARIABLEHEIGHT;// | RBBS_USECHEVRON; + _rbBand.hwndChild = _pToolBar->getHSelf(); + _rbBand.wID = 0; //ID zero for toolbar + _rbBand.cxMinChild = 0; + _rbBand.cyMinChild = HIWORD(size) + HIWORD(padding); + _rbBand.cyMaxChild = HIWORD(size) + HIWORD(padding); + _rbBand.cyIntegral = REBAR_BAR_TOOLBAR; + _rbBand.cxIdeal = _rbBand.cx = _pToolBar->getWidth(); - _rbBand.hwndChild = _pToolBar->getHSelf(); - _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); +void ReBar::reNew() { //reNew is for toolbar only + int index = (int)SendMessage(_hSelf, RB_IDTOINDEX, (WPARAM)REBAR_BAR_TOOLBAR, 0); + DWORD size = (DWORD)SendMessage(_pToolBar->getHSelf(), TB_GETBUTTONSIZE, 0, 0); + DWORD padding = (DWORD)SendMessage(_pToolBar->getHSelf(), TB_GETPADDING, 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); + _rbBand.fMask = RBBIM_CHILD | RBBIM_SIZE | RBBIM_CHILDSIZE | RBBIM_IDEALSIZE; + _rbBand.hwndChild = _pToolBar->getHSelf(); + _rbBand.cyMinChild = HIWORD(size) + HIWORD(padding); + _rbBand.cyMaxChild = HIWORD(size) + HIWORD(padding); + _rbBand.cxIdeal = _rbBand.cx = _pToolBar->getWidth(); + + ::SendMessage(_hSelf, RB_SETBANDINFO, (WPARAM)index, (LPARAM)&_rbBand); }; +void ReBar::setIDVisible(int id, bool show) { + int index = (int)SendMessage(_hSelf, RB_IDTOINDEX, (WPARAM)id, 0); + if (index == -1 ) + return; //error + REBARBANDINFO rbBand; + rbBand.cbSize = sizeof(rbBand); + rbBand.fMask = RBBIM_STYLE; + ::SendMessage(_hSelf, RB_GETBANDINFO, (WPARAM)index, (LPARAM)&rbBand); + if (show) + rbBand.fStyle &= (RBBS_HIDDEN ^ -1); + else + rbBand.fStyle |= RBBS_HIDDEN; + ::SendMessage(_hSelf, RB_SETBANDINFO, (WPARAM)index, (LPARAM)&rbBand); +} + +bool ReBar::getIDVisible(int id) { + int index = (int)SendMessage(_hSelf, RB_IDTOINDEX, (WPARAM)id, 0); + if (index == -1 ) + return false; //error + REBARBANDINFO rbBand; + rbBand.cbSize = sizeof(rbBand); + rbBand.fMask = RBBIM_STYLE; + ::SendMessage(_hSelf, RB_GETBANDINFO, (WPARAM)index, (LPARAM)&rbBand); + return ((rbBand.fStyle & RBBS_HIDDEN) == 0); +} + diff --git a/PowerEditor/src/WinControls/ToolBar/ToolBar.h b/PowerEditor/src/WinControls/ToolBar/ToolBar.h index fe2a25ac..371c8f4a 100644 --- a/PowerEditor/src/WinControls/ToolBar/ToolBar.h +++ b/PowerEditor/src/WinControls/ToolBar/ToolBar.h @@ -22,7 +22,8 @@ #include "resource.h" #include "Notepad_plus_msgs.h" - +#define REBAR_BAR_TOOLBAR 0 +//#define REBAR_BAR_SEARCH 1 #ifndef _WIN32_IE #define _WIN32_IE 0x0600 @@ -32,20 +33,7 @@ #include using namespace std; - -#ifndef TB_SETIMAGELIST -#define TB_SETIMAGELIST (WM_USER+48) -#endif - -#ifndef TB_SETHOTIMAGELIST -#define TB_SETHOTIMAGELIST (WM_USER+52) -#endif - -#ifndef TB_SETDISABLEDIMAGELIST -#define TB_SETDISABLEDIMAGELIST (WM_USER+54) -#endif - -enum toolBarStatusType {TB_HIDE, TB_SMALL, TB_LARGE, TB_STANDARD}; +enum toolBarStatusType {/*TB_HIDE, */TB_SMALL, TB_LARGE, TB_STANDARD}; #include "ImageListSet.h" @@ -60,7 +48,7 @@ typedef struct { class ToolBar : public Window { public : - ToolBar():Window(), _pTBB(NULL), _nrButtons(0), _nrDynButtons(0), _nrTotalButtons(0), _nrCurrentButtons(0), _visible(true) {}; + ToolBar():Window(), _pTBB(NULL), _nrButtons(0), _nrDynButtons(0), _nrTotalButtons(0), _nrCurrentButtons(0) {}; virtual ~ToolBar(){}; virtual bool init(HINSTANCE hInst, HWND hPere, toolBarStatusType type, @@ -76,12 +64,6 @@ public : ::SendMessage(_hSelf, TB_ENABLEBUTTON, cmdID, (LPARAM)doEnable); }; - int getHeight() const { - if (!::IsWindowVisible(_hSelf)) - return 0; - return Window::getHeight(); - }; - int getWidth() const; void reduce() { @@ -112,16 +94,6 @@ public : 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); - _visible = toShow; - }; bool getCheckState(int ID2Check) const { return bool(::SendMessage(_hSelf, TB_GETSTATE, (WPARAM)ID2Check, 0) & TBSTATE_CHECKED); @@ -132,8 +104,7 @@ public : }; toolBarStatusType getState() const { - bool test = _visible; - return _visible?_state:TB_HIDE; + return _state; }; bool changeIcons(int whichLst, int iconIndex, const char *iconLocation){ @@ -146,7 +117,6 @@ private : TBBUTTON *_pTBB; ToolBarIcons _toolBarIcons; toolBarStatusType _state; - bool _visible; vector _vDynBtnReg; size_t _nrButtons; size_t _nrDynButtons; @@ -166,12 +136,7 @@ private : 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; - } + _state = state; } }; @@ -189,6 +154,15 @@ public : void init(HINSTANCE hInst, HWND hPere, ToolBar *pToolBar); void reNew(); + int getHeight() const { + if (::IsWindowVisible(_hSelf)) + return (int)(UINT)SendMessage(_hSelf, RB_GETBARHEIGHT, 0, 0); + return 0; + }; + + void setIDVisible(int id, bool show); + bool getIDVisible(int id); + private: REBARINFO _rbi; REBARBANDINFO _rbBand; diff --git a/PowerEditor/src/WinControls/Window.h b/PowerEditor/src/WinControls/Window.h index af5368f3..8c9313ec 100644 --- a/PowerEditor/src/WinControls/Window.h +++ b/PowerEditor/src/WinControls/Window.h @@ -72,7 +72,9 @@ public: virtual int getHeight() const { RECT rc; ::GetClientRect(_hSelf, &rc); - return (rc.bottom - rc.top); + if (::IsWindowVisible(_hSelf) == TRUE) + return (rc.bottom - rc.top); + return 0; }; virtual bool isVisible() const { @@ -112,3 +114,4 @@ protected: #endif //WINDOW_CONTROL_H +