[UPDATE] refactoring (in progress).

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@624 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
Don Ho 2010-03-16 22:32:58 +00:00
parent bffdb9f4fe
commit 2e54127036
4 changed files with 98 additions and 83 deletions

View File

@ -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)

View File

@ -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<iconLocator> _customIconVect;
//vector<iconLocator> _customIconVect;
WindowsMenu _windowsMenu;
HMENU _mainMenuHandle;

View File

@ -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)
{

View File

@ -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<iconLocator> _customIconVect;
TiXmlNode *_toolIcons;
void setDefaultImageList() {