From 2e541270362f41ff96e3967fa60cf6d71a06efaf Mon Sep 17 00:00:00 2001 From: Don Ho Date: Tue, 16 Mar 2010 22:32:58 +0000 Subject: [PATCH] [UPDATE] refactoring (in progress). git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@624 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/Notepad_plus.cpp | 77 ++----------------- PowerEditor/src/Notepad_plus.h | 13 +--- .../src/WinControls/ToolBar/ToolBar.cpp | 69 +++++++++++++++++ PowerEditor/src/WinControls/ToolBar/ToolBar.h | 22 ++++++ 4 files changed, 98 insertions(+), 83 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 78f507ec9..6d78f920f 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -62,76 +62,12 @@ Notepad_plus::Notepad_plus(): Window(), _mainWindowStatus(0), _pDocTab(NULL), _p #endif TiXmlDocument *toolIconsDocRoot = (NppParameters::getInstance())->getToolIcons(); + + if (toolIconsDocRoot) { - _toolIcons = toolIconsDocRoot->FirstChild(TEXT("NotepadPlus")); - if (_toolIcons) - { - _toolIcons = _toolIcons->FirstChild(TEXT("ToolBarIcons")); - if (_toolIcons) - { - _toolIcons = _toolIcons->FirstChild(TEXT("Theme")); - if (_toolIcons) - { - const TCHAR *themeDir = (_toolIcons->ToElement())->Attribute(TEXT("pathPrefix")); - - for (TiXmlNode *childNode = _toolIcons->FirstChildElement(TEXT("Icon")); - childNode ; - childNode = childNode->NextSibling(TEXT("Icon"))) - { - int iIcon; - const TCHAR *res = (childNode->ToElement())->Attribute(TEXT("id"), &iIcon); - if (res) - { - TiXmlNode *grandChildNode = childNode->FirstChildElement(TEXT("normal")); - if (grandChildNode) - { - TiXmlNode *valueNode = grandChildNode->FirstChild(); - //putain, enfin!!! - if (valueNode) - { - generic_string locator = themeDir?themeDir:TEXT(""); - - locator += valueNode->Value(); - _customIconVect.push_back(iconLocator(0, iIcon, locator)); - } - } - - grandChildNode = childNode->FirstChildElement(TEXT("hover")); - if (grandChildNode) - { - TiXmlNode *valueNode = grandChildNode->FirstChild(); - //putain, enfin!!! - if (valueNode) - { - generic_string locator = themeDir?themeDir:TEXT(""); - - locator += valueNode->Value(); - _customIconVect.push_back(iconLocator(1, iIcon, locator)); - } - } - - grandChildNode = childNode->FirstChildElement(TEXT("disabled")); - if (grandChildNode) - { - TiXmlNode *valueNode = grandChildNode->FirstChild(); - //putain, enfin!!! - if (valueNode) - { - generic_string locator = themeDir?themeDir:TEXT(""); - - locator += valueNode->Value(); - _customIconVect.push_back(iconLocator(2, iIcon, locator)); - } - } - } - } - } - } - } - } - else - _toolIcons = NULL; + _toolBar.initTheme(toolIconsDocRoot); + } } // ATTENTION : the order of the destruction is very important @@ -2991,10 +2927,7 @@ bool Notepad_plus::addCurrentMacro() void Notepad_plus::changeToolBarIcons() { - if (!_toolIcons) - return; - for (int i = 0 ; i < int(_customIconVect.size()) ; i++) - _toolBar.changeIcons(_customIconVect[i].listIndex, _customIconVect[i].iconIndex, (_customIconVect[i].iconLocation).c_str()); + _toolBar.changeIcons(); } bool Notepad_plus::switchToFile(BufferID id) diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index 2d013d6ec..b165245fc 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -144,17 +144,8 @@ enum Views { */ - struct TaskListInfo; -struct iconLocator { - int listIndex; - int iconIndex; - generic_string iconLocation; - - iconLocator(int iList, int iIcon, const generic_string iconLoc) - : listIndex(iList), iconIndex(iIcon), iconLocation(iconLoc){}; -}; struct VisibleGUIConf { bool isPostIt; @@ -301,7 +292,7 @@ private: AutoCompletion _autoCompleteSub; //each Scintilla has its own autoComplete SmartHighlighter _smartHighlighter; - TiXmlNode *_toolIcons; + //TiXmlNode *_toolIcons; NativeLangSpeaker _nativeLangSpeaker; DocTabView _mainDocTab; DocTabView _subDocTab; @@ -344,7 +335,7 @@ private: LastRecentFileList _lastRecentFileList; - vector _customIconVect; + //vector _customIconVect; WindowsMenu _windowsMenu; HMENU _mainMenuHandle; diff --git a/PowerEditor/src/WinControls/ToolBar/ToolBar.cpp b/PowerEditor/src/WinControls/ToolBar/ToolBar.cpp index 8925ed324..c4b74bd45 100644 --- a/PowerEditor/src/WinControls/ToolBar/ToolBar.cpp +++ b/PowerEditor/src/WinControls/ToolBar/ToolBar.cpp @@ -22,6 +22,75 @@ 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; +void ToolBar::initTheme(TiXmlDocument *toolIconsDocRoot) +{ + _toolIcons = toolIconsDocRoot->FirstChild(TEXT("NotepadPlus")); + if (_toolIcons) + { + _toolIcons = _toolIcons->FirstChild(TEXT("ToolBarIcons")); + if (_toolIcons) + { + _toolIcons = _toolIcons->FirstChild(TEXT("Theme")); + if (_toolIcons) + { + const TCHAR *themeDir = (_toolIcons->ToElement())->Attribute(TEXT("pathPrefix")); + + for (TiXmlNode *childNode = _toolIcons->FirstChildElement(TEXT("Icon")); + childNode ; + childNode = childNode->NextSibling(TEXT("Icon"))) + { + int iIcon; + const TCHAR *res = (childNode->ToElement())->Attribute(TEXT("id"), &iIcon); + if (res) + { + TiXmlNode *grandChildNode = childNode->FirstChildElement(TEXT("normal")); + if (grandChildNode) + { + TiXmlNode *valueNode = grandChildNode->FirstChild(); + //putain, enfin!!! + if (valueNode) + { + generic_string locator = themeDir?themeDir:TEXT(""); + + locator += valueNode->Value(); + _customIconVect.push_back(iconLocator(0, iIcon, locator)); + } + } + + grandChildNode = childNode->FirstChildElement(TEXT("hover")); + if (grandChildNode) + { + TiXmlNode *valueNode = grandChildNode->FirstChild(); + //putain, enfin!!! + if (valueNode) + { + generic_string locator = themeDir?themeDir:TEXT(""); + + locator += valueNode->Value(); + _customIconVect.push_back(iconLocator(1, iIcon, locator)); + } + } + + grandChildNode = childNode->FirstChildElement(TEXT("disabled")); + if (grandChildNode) + { + TiXmlNode *valueNode = grandChildNode->FirstChild(); + //putain, enfin!!! + if (valueNode) + { + generic_string locator = themeDir?themeDir:TEXT(""); + + locator += valueNode->Value(); + _customIconVect.push_back(iconLocator(2, iIcon, locator)); + } + } + } + } + } + } + } +} + bool ToolBar::init( HINSTANCE hInst, HWND hPere, toolBarStatusType type, ToolBarButtonUnit *buttonUnitArray, int arraySize) { diff --git a/PowerEditor/src/WinControls/ToolBar/ToolBar.h b/PowerEditor/src/WinControls/ToolBar/ToolBar.h index fbad1ad94..42e1462da 100644 --- a/PowerEditor/src/WinControls/ToolBar/ToolBar.h +++ b/PowerEditor/src/WinControls/ToolBar/ToolBar.h @@ -43,7 +43,18 @@ typedef struct { HICON hIcon; // icon for toolbar } tDynamicList; +struct iconLocator { + int listIndex; + int iconIndex; + generic_string iconLocation; + + iconLocator(int iList, int iIcon, const generic_string iconLoc) + : listIndex(iList), iconIndex(iIcon), iconLocation(iconLoc){}; +}; + class ReBar; +class TiXmlDocument; +class TiXmlNode; class ToolBar : public Window { @@ -51,6 +62,7 @@ public : ToolBar():Window(), _pTBB(NULL), _nrButtons(0), _nrDynButtons(0), _nrTotalButtons(0), _nrCurrentButtons(0), _pRebar(NULL) {}; virtual ~ToolBar(){}; + void initTheme(TiXmlDocument *toolIconsDocRoot); virtual bool init(HINSTANCE hInst, HWND hPere, toolBarStatusType type, ToolBarButtonUnit *buttonUnitArray, int arraySize); @@ -103,6 +115,14 @@ public : return _state; }; + bool changeIcons() { + if (!_toolIcons) + return false; + for (int i = 0 ; i < int(_customIconVect.size()) ; i++) + changeIcons(_customIconVect[i].listIndex, _customIconVect[i].iconIndex, (_customIconVect[i].iconLocation).c_str()); + return true; + }; + bool changeIcons(int whichLst, int iconIndex, const TCHAR *iconLocation){ return _toolBarIcons.replaceIcon(whichLst, iconIndex, iconLocation); }; @@ -124,6 +144,8 @@ private : size_t _nrCurrentButtons; ReBar * _pRebar; REBARBANDINFO _rbBand; + vector _customIconVect; + TiXmlNode *_toolIcons; void setDefaultImageList() {