[NEW_FEATURE] Add 2 new plugins APIs: NPPM_GETEDITORDEFAULTBACKGROUNDCOLOR & NPPM_GETEDITORDEFAULTFOREGROUNDCOLOR

[NEW_FEATURE] Make internal docking dialog match/follow the selected theme's background and foreground colors.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1259 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
Don Ho 2014-07-16 11:20:58 +00:00
parent e9ada08611
commit f3407442db
14 changed files with 240 additions and 32 deletions

View File

@ -395,6 +395,15 @@ enum winVer{WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, WV
// VOID NPPM_DOCSWITCHERDISABLECOLUMN(0, BOOL disableOrNot)
// Disable or enable extension column of doc switcher
#define NPPM_GETEDITORDEFAULTFOREGROUNDCOLOR (NPPMSG + 90)
// INT NPPM_GETEDITORDEFAULTFOREGROUNDCOLOR(0, 0)
// Return: current editor default foreground color. You should convert the returned value in COLORREF
#define NPPM_GETEDITORDEFAULTBACKGROUNDCOLOR (NPPMSG + 91)
// INT NPPM_GETEDITORDEFAULTBACKGROUNDCOLOR(0, 0)
// Return: current editor default background color. You should convert the returned value in COLORREF
#define RUNCOMMAND_USER (WM_USER + 3000)
#define NPPM_GETFULLCURRENTPATH (RUNCOMMAND_USER + FULL_CURRENT_PATH)
#define NPPM_GETCURRENTDIRECTORY (RUNCOMMAND_USER + CURRENT_DIRECTORY)

View File

@ -654,12 +654,25 @@ LRESULT Notepad_plus::init(HWND hwnd)
default : // hide & undocked
break;
}
// UserDefine Dialog
//
// Menu & toolbar for UserDefine Dialog
//
checkMenuItem(IDM_LANG_USER_DLG, uddShow);
_toolBar.setCheck(IDM_LANG_USER_DLG, uddShow);
//launch the plugin dlg memorized at the last session
//
// Initialize the default forground & background color
//
StyleArray & globalStyles = (NppParameters::getInstance())->getGlobalStylers();
int i = globalStyles.getStylerIndexByID(STYLE_DEFAULT);
Style & style = globalStyles.getStyler(i);
(NppParameters::getInstance())->setCurrentDefaultFgColor(style._fgColor);
(NppParameters::getInstance())->setCurrentDefaultBgColor(style._bgColor);
//
// launch the plugin dlg memorized at the last session
//
DockingManagerData &dmd = nppGUI._dockingData;
_dockingManager.setDockedContSize(CONT_LEFT , nppGUI._dockingData._leftWidth);
@ -5026,7 +5039,14 @@ void Notepad_plus::launchClipboardHistoryPanel()
data.pszName = title;
}
::SendMessage(_pPublicInterface->getHSelf(), NPPM_DMMREGASDCKDLG, 0, (LPARAM)&data);
COLORREF fgColor = (NppParameters::getInstance())->getCurrentDefaultFgColor();
COLORREF bgColor = (NppParameters::getInstance())->getCurrentDefaultBgColor();
_pClipboardHistoryPanel->setBackgroundColor(bgColor);
_pClipboardHistoryPanel->setForegroundColor(fgColor);
}
_pClipboardHistoryPanel->display();
}
@ -5061,6 +5081,12 @@ void Notepad_plus::launchFileSwitcherPanel()
data.pszName = title;
}
::SendMessage(_pPublicInterface->getHSelf(), NPPM_DMMREGASDCKDLG, 0, (LPARAM)&data);
COLORREF fgColor = (NppParameters::getInstance())->getCurrentDefaultFgColor();
COLORREF bgColor = (NppParameters::getInstance())->getCurrentDefaultBgColor();
_pFileSwitcherPanel->setBackgroundColor(bgColor);
_pFileSwitcherPanel->setForegroundColor(fgColor);
}
_pFileSwitcherPanel->display();
}
@ -5096,7 +5122,14 @@ void Notepad_plus::launchAnsiCharPanel()
data.pszName = title;
}
::SendMessage(_pPublicInterface->getHSelf(), NPPM_DMMREGASDCKDLG, 0, (LPARAM)&data);
COLORREF fgColor = (NppParameters::getInstance())->getCurrentDefaultFgColor();
COLORREF bgColor = (NppParameters::getInstance())->getCurrentDefaultBgColor();
_pAnsiCharPanel->setBackgroundColor(bgColor);
_pAnsiCharPanel->setForegroundColor(fgColor);
}
_pAnsiCharPanel->display();
}
@ -5136,6 +5169,12 @@ void Notepad_plus::launchProjectPanel(int cmdID, ProjectPanel ** pProjPanel, int
data.pszName = title;
}
::SendMessage(_pPublicInterface->getHSelf(), NPPM_DMMREGASDCKDLG, 0, (LPARAM)&data);
COLORREF fgColor = (NppParameters::getInstance())->getCurrentDefaultFgColor();
COLORREF bgColor = (NppParameters::getInstance())->getCurrentDefaultBgColor();
(*pProjPanel)->setBackgroundColor(bgColor);
(*pProjPanel)->setForegroundColor(fgColor);
}
(*pProjPanel)->display();
}
@ -5217,9 +5256,16 @@ void Notepad_plus::launchFunctionList()
}
::SendMessage(_pPublicInterface->getHSelf(), NPPM_DMMREGASDCKDLG, 0, (LPARAM)&data);
COLORREF fgColor = (NppParameters::getInstance())->getCurrentDefaultFgColor();
COLORREF bgColor = (NppParameters::getInstance())->getCurrentDefaultBgColor();
_pFuncList->setBackgroundColor(bgColor);
_pFuncList->setForegroundColor(fgColor);
}
_pFuncList->display();
_pFuncList->reload();
_pEditView->getFocus();
}

View File

@ -31,8 +31,12 @@
#include "TaskListDlg.h"
#include "ImageListSet.h"
#include "ShortcutMapper.h"
#include "ansiCharPanel.h"
#include "clipboardHistoryPanel.h"
#include "VerticalFileSwitcher.h"
#include "ProjectPanel.h"
#include "documentMap.h"
#include "functionListPanel.h"
#define WM_DPICHANGED 0x02E0
@ -1401,6 +1405,54 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
drawTabbarColoursFromStylerArray();
// Update default fg/bg colors in Parameters for both internal/plugins docking dialog
StyleArray & globalStyles = (NppParameters::getInstance())->getGlobalStylers();
int i = globalStyles.getStylerIndexByID(STYLE_DEFAULT);
Style & style = globalStyles.getStyler(i);
(NppParameters::getInstance())->setCurrentDefaultFgColor(style._fgColor);
(NppParameters::getInstance())->setCurrentDefaultBgColor(style._bgColor);
// Set default fg/bg colors on internal docking dialog
if (_pFuncList)
{
_pFuncList->setBackgroundColor(style._bgColor);
_pFuncList->setForegroundColor(style._fgColor);
}
if (_pAnsiCharPanel)
{
_pAnsiCharPanel->setBackgroundColor(style._bgColor);
_pAnsiCharPanel->setForegroundColor(style._fgColor);
}
if (_pFileSwitcherPanel)
{
_pFileSwitcherPanel->setBackgroundColor(style._bgColor);
_pFileSwitcherPanel->setForegroundColor(style._fgColor);
}
if (_pClipboardHistoryPanel)
{
_pClipboardHistoryPanel->setBackgroundColor(style._bgColor);
_pClipboardHistoryPanel->setForegroundColor(style._fgColor);
}
if (_pProjectPanel_1)
{
_pProjectPanel_1->setBackgroundColor(style._bgColor);
_pProjectPanel_1->setForegroundColor(style._fgColor);
}
if (_pProjectPanel_2)
{
_pProjectPanel_2->setBackgroundColor(style._bgColor);
_pProjectPanel_2->setForegroundColor(style._fgColor);
}
if (_pProjectPanel_3)
{
_pProjectPanel_3->setBackgroundColor(style._bgColor);
_pProjectPanel_3->setForegroundColor(style._fgColor);
}
// Notify plugins of update to styles xml
SCNotification scnN;
scnN.nmhdr.code = NPPN_WORDSTYLESUPDATED;
@ -1907,6 +1959,18 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
return TRUE;
}
case NPPM_GETEDITORDEFAULTFOREGROUNDCOLOR:
case NPPM_GETEDITORDEFAULTBACKGROUNDCOLOR:
{
return (Message == NPPM_GETEDITORDEFAULTFOREGROUNDCOLOR?(NppParameters::getInstance())->getCurrentDefaultFgColor():(NppParameters::getInstance())->getCurrentDefaultBgColor());
/*
StyleArray & globalStyles = (NppParameters::getInstance())->getGlobalStylers();
int i = globalStyles.getStylerIndexByID(STYLE_DEFAULT);
Style & style = globalStyles.getStyler(i);
return (Message == NPPM_GETEDITORDEFAULTFOREGROUNDCOLOR?style._fgColor:style._bgColor);
*/
}
case NPPM_SHOWDOCSWITCHER:
{
BOOL toShow = lParam;

View File

@ -1090,9 +1090,6 @@ struct FindHistory {
bool _isFolderFollowDoc;
};
#ifdef UNICODE
class LocalizationSwitcher {
friend class NppParameters;
public :
@ -1133,7 +1130,6 @@ private :
wstring _nativeLangPath;
string _fileName;
};
#endif
class ThemeSwitcher {
friend class NppParameters;
@ -1507,17 +1503,14 @@ public:
bool _isFindReplacing; // an on the fly variable for find/replace functions
void safeWow64EnableWow64FsRedirection(BOOL Wow64FsEnableRedirection);
#ifdef UNICODE
LocalizationSwitcher & getLocalizationSwitcher() {
return _localizationSwitcher;
};
#endif
ThemeSwitcher & getThemeSwitcher() {
return _themeSwitcher;
};
vector<generic_string> & getBlackList() {return _blacklist;};
bool isInBlackList(TCHAR *fn) {
for (size_t i = 0, len = _blacklist.size(); i < len ; ++i)
@ -1549,7 +1542,23 @@ public:
};
void writeSettingsFilesOnCloudForThe1stTime(CloudChoice choice);
COLORREF getCurrentDefaultBgColor() const {
return _currentDefaultBgColor;
};
COLORREF getCurrentDefaultFgColor() const {
return _currentDefaultFgColor;
};
void setCurrentDefaultBgColor(COLORREF c) {
_currentDefaultBgColor = c;
};
void setCurrentDefaultFgColor(COLORREF c) {
_currentDefaultFgColor = c;
};
DPIManager _dpiManager;
private:
@ -1651,6 +1660,9 @@ private:
NativeLangSpeaker *_pNativeLangSpeaker;
COLORREF _currentDefaultBgColor;
COLORREF _currentDefaultFgColor;
static int CALLBACK EnumFontFamExProc(ENUMLOGFONTEX *lpelfe, NEWTEXTMETRICEX *, int, LPARAM lParam) {
vector<generic_string> *pStrVect = (vector<generic_string> *)lParam;
size_t vectSize = pStrVect->size();

View File

@ -299,6 +299,7 @@ public :
void execSavedCommand(int cmd, int intValue, generic_string stringValue);
void setStatusbarMessage(const generic_string & msg, FindStatus staus);
protected :
virtual BOOL CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);
void addText2Combo(const TCHAR * txt2add, HWND comboID, bool isUTF8 = false);

View File

@ -49,11 +49,11 @@ public:
DockingDlgInterface::init(hInst, hPere);
_ppEditView = ppEditView;
};
/*
virtual void display(bool toShow = true) const {
DockingDlgInterface::display(toShow);
};
*/
void setParent(HWND parent2set){
_hParent = parent2set;
};
@ -61,6 +61,14 @@ public:
void switchEncoding();
void insertChar(unsigned char char2insert) const;
virtual void setBackgroundColor(int bgColour) const {
ListView_SetBkColor(_listView.getHSelf(), bgColour);
ListView_SetTextBkColor(_listView.getHSelf(), bgColour);
};
virtual void setForegroundColor(int fgColour) const {
ListView_SetTextColor(_listView.getHSelf(), fgColour);
};
protected:
virtual BOOL CALLBACK AnsiCharPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);

View File

@ -31,11 +31,9 @@
#include "ScintillaEditView.h"
#include "clipboardFormats.h"
#ifdef UNICODE
#define CLIPBOARD_TEXTFORMAT CF_UNICODETEXT
#else
#define CLIPBOARD_TEXTFORMAT CF_TEXT
#endif
#define MAX_DISPLAY_LENGTH 64
ClipboardData ClipboardHistoryPanel::getClipboadData()
{
@ -174,11 +172,28 @@ void ClipboardHistoryPanel::addToClipboadHistory(ClipboardData cbd)
}
_clipboardDataVector.insert(_clipboardDataVector.begin(), cbd);
StringArray sa(cbd, 64);
StringArray sa(cbd, MAX_DISPLAY_LENGTH);
TCHAR *displayStr = (TCHAR *)sa.getPointer();
::SendDlgItemMessage(_hSelf, IDC_LIST_CLIPBOARD, LB_INSERTSTRING, 0, (LPARAM)displayStr);
}
void ClipboardHistoryPanel::drawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
//printStr(TEXT("OK"));
COLORREF fgColor = _lbFgColor == -1?black:_lbFgColor; // fg black by default
COLORREF bgColor = _lbBgColor == -1?white:_lbBgColor; // bg white by default
StringArray sa(_clipboardDataVector[lpDrawItemStruct->itemID], MAX_DISPLAY_LENGTH);
TCHAR *ptStr = (TCHAR *)sa.getPointer();
//printStr(ptStr);
::SetTextColor(lpDrawItemStruct->hDC, fgColor);
::SetBkColor(lpDrawItemStruct->hDC, bgColor);
::DrawText(lpDrawItemStruct->hDC, ptStr, lstrlen(ptStr), &(lpDrawItemStruct->rcItem), DT_SINGLELINE | DT_VCENTER | DT_LEFT);
}
BOOL CALLBACK ClipboardHistoryPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
@ -221,7 +236,6 @@ BOOL CALLBACK ClipboardHistoryPanel::run_dlgProc(UINT message, WPARAM wParam, LP
int i = ::SendDlgItemMessage(_hSelf, IDC_LIST_CLIPBOARD, LB_GETCURSEL, 0, 0);
if (i != LB_ERR)
{
#ifdef UNICODE
int codepage = (*_ppEditView)->getCurrentBuffer()->getEncoding();
if (codepage == -1)
{
@ -242,14 +256,6 @@ BOOL CALLBACK ClipboardHistoryPanel::run_dlgProc(UINT message, WPARAM wParam, LP
(*_ppEditView)->execute(SCI_ADDTEXT, strlen(c), (LPARAM)c);
(*_ppEditView)->getFocus();
delete [] c;
#else
ByteArray ba(_clipboardDataVector[i]);
char *str = (char *)ba.getPointer();
(*_ppEditView)->execute(SCI_REPLACESEL, 0, (LPARAM)"");
(*_ppEditView)->execute(SCI_ADDTEXT, strlen(str), (LPARAM)str);
(*_ppEditView)->getFocus();
#endif
}
}
return TRUE;
@ -277,9 +283,21 @@ BOOL CALLBACK ClipboardHistoryPanel::run_dlgProc(UINT message, WPARAM wParam, LP
break;
}
*/
case WM_CTLCOLORLISTBOX:
{
if (_lbBgColor != -1)
return (LRESULT)::CreateSolidBrush((COLORREF)_lbBgColor);
break;
}
case WM_DRAWITEM:
{
drawItem((DRAWITEMSTRUCT *)lParam);
break;
}
default :
return DockingDlgInterface::run_dlgProc(message, wParam, lParam);
}
return DockingDlgInterface::run_dlgProc(message, wParam, lParam);
}

View File

@ -68,16 +68,17 @@ public:
class ClipboardHistoryPanel : public DockingDlgInterface {
public:
ClipboardHistoryPanel(): DockingDlgInterface(IDD_CLIPBOARDHISTORY_PANEL), _ppEditView(NULL), _hwndNextCbViewer(NULL) {};
ClipboardHistoryPanel(): DockingDlgInterface(IDD_CLIPBOARDHISTORY_PANEL), _ppEditView(NULL), _hwndNextCbViewer(NULL), _lbBgColor(-1), _lbFgColor(-1) {};
void init(HINSTANCE hInst, HWND hPere, ScintillaEditView **ppEditView) {
DockingDlgInterface::init(hInst, hPere);
_ppEditView = ppEditView;
};
/*
virtual void display(bool toShow = true) const {
DockingDlgInterface::display(toShow);
};
*/
void setParent(HWND parent2set){
_hParent = parent2set;
@ -88,6 +89,15 @@ public:
void addToClipboadHistory(ClipboardData cbd);
int getClipboardDataIndex(ClipboardData cbd);
virtual void setBackgroundColor(COLORREF bgColour) {
_lbBgColor = bgColour;
};
virtual void setForegroundColor(COLORREF fgColour) {
_lbFgColor = fgColour;
};
void drawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
protected:
virtual BOOL CALLBACK ClipboardHistoryPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);
@ -95,5 +105,8 @@ private:
ScintillaEditView **_ppEditView;
std::vector<ClipboardData> _clipboardDataVector;
HWND _hwndNextCbViewer;
int _lbBgColor;
int _lbFgColor;
};
#endif // CLIPBOARDHISTORYPANEL_H

View File

@ -35,5 +35,5 @@ EXSTYLE WS_EX_TOOLWINDOW | WS_EX_WINDOWEDGE
CAPTION "Clipboard History"
FONT 8, "MS Sans Serif", 0, 0, 0x0
BEGIN
LISTBOX IDC_LIST_CLIPBOARD,50,44,78,120,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
LISTBOX IDC_LIST_CLIPBOARD,50,44,78,120,LBS_OWNERDRAWFIXED | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
END

View File

@ -75,6 +75,12 @@ public:
virtual void destroy() {
};
virtual void setBackgroundColor(COLORREF) {
};
virtual void setForegroundColor(COLORREF) {
};
virtual void display(bool toShow = true) const {
::SendMessage(_hParent, toShow?NPPM_DMMSHOW:NPPM_DMMHIDE, 0, (LPARAM)_hSelf);
};

View File

@ -102,6 +102,13 @@ public:
DockingDlgInterface::display(toShow);
};
virtual void setBackgroundColor(COLORREF bgColour) {
TreeView_SetBkColor(_treeView.getHSelf(), bgColour);
};
virtual void setForegroundColor(COLORREF fgColour) {
TreeView_SetTextColor(_treeView.getHSelf(), fgColour);
};
void setParent(HWND parent2set){
_hParent = parent2set;
};
@ -116,7 +123,7 @@ public:
void searchFuncAndSwitchView();
protected:
virtual BOOL CALLBACK FunctionListPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);
virtual BOOL CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);
private:
HWND _hToolbarMenu;

View File

@ -103,6 +103,13 @@ public:
};
void checkIfNeedSave(const TCHAR *title);
virtual void setBackgroundColor(COLORREF bgColour) {
TreeView_SetBkColor(_treeView.getHSelf(), bgColour);
};
virtual void setForegroundColor(COLORREF fgColour) {
TreeView_SetTextColor(_treeView.getHSelf(), fgColour);
};
protected:
TreeView _treeView;
HIMAGELIST _hImaLst;

View File

@ -95,6 +95,14 @@ public:
_fileListView.reload();
};
virtual void setBackgroundColor(COLORREF bgColour) {
_fileListView.setBackgroundColor(bgColour);
};
virtual void setForegroundColor(COLORREF fgColour) {
_fileListView.setForegroundColor(fgColour);
};
protected:
virtual BOOL CALLBACK VerticalFileSwitcher::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);

View File

@ -71,6 +71,15 @@ public:
std::vector<SwitcherFileInfo> getSelectedFiles(bool reverse = false) const;
void reload();
void setBackgroundColor(COLORREF bgColour) {
ListView_SetBkColor(_hSelf, bgColour);
ListView_SetTextBkColor(_hSelf, bgColour);
};
void setForegroundColor(COLORREF fgColour) {
ListView_SetTextColor(_hSelf, fgColour);
};
protected:
HIMAGELIST _hImaLst;
WNDPROC _defaultProc;