?? wordstyledlg.cpp
字號:
/*
this file is part of notepad++
Copyright (C)2003 Don HO < donho@altern.org >
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "WordStyleDlg.h"
#include "ScintillaEditView.h"
#include "SysMsg.h"
BOOL CALLBACK ColourStaticTextHooker::colourStaticProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_PAINT:
{
RECT rect;
::GetClientRect(hwnd, &rect);
PAINTSTRUCT ps;
HDC hdc = ::BeginPaint(hwnd, &ps);
::SetTextColor(hdc, _colour);
// Get the default GUI font
HFONT hf = (HFONT)::GetStockObject(DEFAULT_GUI_FONT);
HANDLE hOld = SelectObject(hdc, hf);
// Draw the text!
char text[MAX_PATH];
::GetWindowText(hwnd, text, sizeof(text));
::DrawText(hdc, text, -1, &rect, DT_LEFT);
::SelectObject(hdc, hOld);
::EndPaint(hwnd, &ps);
return TRUE;
}
}
return ::CallWindowProc(_oldProc, hwnd, Message, wParam, lParam);
}
void WordStyleDlg::updateGlobalOverrideCtrls()
{
const NppGUI & nppGUI = (NppParameters::getInstance())->getNppGUI();
::SendDlgItemMessage(_hSelf, IDC_GLOBAL_FG_CHECK, BM_SETCHECK, nppGUI._globalOverride.enableFg, 0);
::SendDlgItemMessage(_hSelf, IDC_GLOBAL_BG_CHECK, BM_SETCHECK, nppGUI._globalOverride.enableBg, 0);
::SendDlgItemMessage(_hSelf, IDC_GLOBAL_FONT_CHECK, BM_SETCHECK, nppGUI._globalOverride.enableFont, 0);
::SendDlgItemMessage(_hSelf, IDC_GLOBAL_FONTSIZE_CHECK, BM_SETCHECK, nppGUI._globalOverride.enableFontSize, 0);
::SendDlgItemMessage(_hSelf, IDC_GLOBAL_BOLD_CHECK, BM_SETCHECK, nppGUI._globalOverride.enableBold, 0);
::SendDlgItemMessage(_hSelf, IDC_GLOBAL_ITALIC_CHECK, BM_SETCHECK, nppGUI._globalOverride.enableItalic, 0);
::SendDlgItemMessage(_hSelf, IDC_GLOBAL_UNDERLINE_CHECK, BM_SETCHECK, nppGUI._globalOverride.enableUnderLine, 0);
}
BOOL CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam)
{
switch (Message)
{
case WM_INITDIALOG :
{
_lsArray = (NppParameters::getInstance())->getLStylerArray();
_globalStyles = (NppParameters::getInstance())->getGlobalStylers();
::SendDlgItemMessage(_hSelf, IDC_LANGUAGES_LIST, LB_ADDSTRING, 0, (LPARAM)"Global Styles");
// All the lexers
for (int i = 0 ; i < _lsArray.getNbLexer() ; i++)
{
::SendDlgItemMessage(_hSelf, IDC_LANGUAGES_LIST, LB_ADDSTRING, 0, (LPARAM)_lsArray.getLexerDescFromIndex(i));
}
_hCheckBold = ::GetDlgItem(_hSelf, IDC_BOLD_CHECK);
_hCheckItalic = ::GetDlgItem(_hSelf, IDC_ITALIC_CHECK);
_hCheckUnderline = ::GetDlgItem(_hSelf, IDC_UNDERLINE_CHECK);
_hFontNameCombo = ::GetDlgItem(_hSelf, IDC_FONT_COMBO);
_hFontSizeCombo = ::GetDlgItem(_hSelf, IDC_FONTSIZE_COMBO);
_hFgColourStaticText = ::GetDlgItem(_hSelf, IDC_FG_STATIC);
_hBgColourStaticText = ::GetDlgItem(_hSelf, IDC_BG_STATIC);
_hFontNameStaticText = ::GetDlgItem(_hSelf, IDC_FONTNAME_STATIC);
_hFontSizeStaticText = ::GetDlgItem(_hSelf, IDC_FONTSIZE_STATIC);
_hStyleInfoStaticText = ::GetDlgItem(_hSelf, IDC_STYLEDESCRIPTION_STATIC);
colourHooker.setColour(RGB(0xFF, 0x00, 0x00));
colourHooker.hookOn(_hStyleInfoStaticText);
for(int i = 0 ; i < sizeof(fontSizeStrs)/3 ; i++)
::SendMessage(_hFontSizeCombo, CB_ADDSTRING, 0, (LPARAM)fontSizeStrs[i]);
const std::vector<std::string> & fontlist = (NppParameters::getInstance())->getFontList();
for (size_t i = 0 ; i < fontlist.size() ; i++)
{
int j = ::SendMessage(_hFontNameCombo, CB_ADDSTRING, 0, (LPARAM)fontlist[i].c_str());
::SendMessage(_hFontNameCombo, CB_SETITEMDATA, j, (LPARAM)fontlist[i].c_str());
}
_pFgColour = new ColourPicker;
_pBgColour = new ColourPicker;
_pFgColour->init(_hInst, _hSelf);
_pBgColour->init(_hInst, _hSelf);
POINT p1, p2;
alignWith(_hFgColourStaticText, _pFgColour->getHSelf(), ALIGNPOS_RIGHT, p1);
alignWith(_hBgColourStaticText, _pBgColour->getHSelf(), ALIGNPOS_RIGHT, p2);
p1.x = p2.x = ((p1.x > p2.x)?p1.x:p2.x) + 10;
p1.y -= 4; p2.y -= 4;
::MoveWindow((HWND)_pFgColour->getHSelf(), p1.x, p1.y, 25, 25, TRUE);
::MoveWindow((HWND)_pBgColour->getHSelf(), p2.x, p2.y, 25, 25, TRUE);
_pFgColour->display();
_pBgColour->display();
const int index2Begin = 0;
::SendDlgItemMessage(_hSelf, IDC_LANGUAGES_LIST, LB_SETCURSEL, 0, index2Begin);
setStyleListFromLexer(index2Begin);
::EnableWindow(::GetDlgItem(_hSelf, IDOK), _isDirty);
::EnableWindow(::GetDlgItem(_hSelf, IDC_SAVECLOSE_BUTTON), !_isSync);
NppParameters *pNppParam = NppParameters::getInstance();
ETDTProc enableDlgTheme = (ETDTProc)pNppParam->getEnableThemeDlgTexture();
if (enableDlgTheme)
{
enableDlgTheme(_hSelf, ETDT_ENABLETAB);
redraw();
}
updateGlobalOverrideCtrls();
setVisualFromStyleList();
goToCenter();
return TRUE;
}
case WM_DESTROY:
{
_pFgColour->destroy();
_pBgColour->destroy();
delete _pFgColour;
delete _pBgColour;
return TRUE;
}
case WM_COMMAND :
{
if (HIWORD(wParam) == EN_CHANGE)
{
int editID = LOWORD(wParam);
if (editID == IDC_USER_KEYWORDS_EDIT)
{
updateUserKeywords();
notifyDataModified();
apply();
}
else if (editID == IDC_USER_EXT_EDIT)
{
updateExtension();
notifyDataModified();
}
}
else
{
switch (wParam)
{
case IDC_BOLD_CHECK :
updateFontStyleStatus(BOLD_STATUS);
notifyDataModified();
apply();
break;
case IDC_ITALIC_CHECK :
updateFontStyleStatus(ITALIC_STATUS);
notifyDataModified();
apply();
break;
case IDC_UNDERLINE_CHECK :
updateFontStyleStatus(UNDERLINE_STATUS);
notifyDataModified();
apply();
break;
case IDCANCEL :
//::MessageBox(NULL, "cancel", "", MB_OK);
if (_isDirty)
{
//::MessageBox(NULL, "dirty", "", MB_OK);
LexerStylerArray & lsArray = (NppParameters::getInstance())->getLStylerArray();
StyleArray & globalStyles = (NppParameters::getInstance())->getGlobalStylers();
globalStyles = _globalStyles = _gstyles2restored;
lsArray = _lsArray = _styles2restored;
restoreGlobalOverrideValues();
_isDirty = false;
setVisualFromStyleList();
::SendMessage(_hParent, WM_UPDATESCINTILLAS, 0, 0);
}
//else
//::MessageBox(NULL, "no dirty", "", MB_OK);
//::EnableWindow(::GetDlgItem(_hSelf, IDOK), FALSE);
::EnableWindow(::GetDlgItem(_hSelf, IDC_SAVECLOSE_BUTTON), !_isSync);
display(false);
return TRUE;
/*
case IDOK : //_isDirty == true;
{
LexerStylerArray & lsa = (NppParameters::getInstance())->getLStylerArray();
StyleArray & globalStyles = (NppParameters::getInstance())->getGlobalStylers();
lsa = _lsArray;
globalStyles = _globalStyles;
::EnableWindow(::GetDlgItem(_hSelf, IDOK), FALSE);
_isDirty = false;
_isSync = false;
::SendMessage(_hParent, WM_UPDATESCINTILLAS, 0, 0);
return TRUE;
}
*/
case IDC_SAVECLOSE_BUTTON :
{
if (_isDirty)
{
LexerStylerArray & lsa = (NppParameters::getInstance())->getLStylerArray();
StyleArray & globalStyles = (NppParameters::getInstance())->getGlobalStylers();
lsa = _lsArray;
globalStyles = _globalStyles;
::EnableWindow(::GetDlgItem(_hSelf, IDOK), FALSE);
_isDirty = false;
}
(NppParameters::getInstance())->writeStyles(_lsArray, _globalStyles);
::EnableWindow(::GetDlgItem(_hSelf, IDC_SAVECLOSE_BUTTON), FALSE);
_isSync = true;
display(false);
::SendMessage(_hParent, WM_UPDATESCINTILLAS, 0, 0);
return TRUE;
}
case IDC_SC_TRANSPARENT_CHECK :
{
bool isChecked = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_SC_TRANSPARENT_CHECK, BM_GETCHECK, 0, 0));
if (isChecked)
{
int percent = ::SendDlgItemMessage(_hSelf, IDC_SC_PERCENTAGE_SLIDER, TBM_GETPOS, 0, 0);
(NppParameters::getInstance())->SetTransparent(_hSelf, percent);
}
else
(NppParameters::getInstance())->removeTransparent(_hSelf);
::EnableWindow(::GetDlgItem(_hSelf, IDC_SC_PERCENTAGE_SLIDER), isChecked);
return TRUE;
}
case IDC_GLOBAL_FG_CHECK :
{
GlobalOverride & glo = (NppParameters::getInstance())->getGlobalOverrideStyle();
glo.enableFg = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, wParam, BM_GETCHECK, 0, 0));
notifyDataModified();
apply();
return TRUE;
}
case IDC_GLOBAL_BG_CHECK:
{
GlobalOverride & glo = (NppParameters::getInstance())->getGlobalOverrideStyle();
glo.enableBg = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, wParam, BM_GETCHECK, 0, 0));
notifyDataModified();
apply();
return TRUE;
}
case IDC_GLOBAL_FONT_CHECK :
{
GlobalOverride & glo = (NppParameters::getInstance())->getGlobalOverrideStyle();
glo.enableFont = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, wParam, BM_GETCHECK, 0, 0));
notifyDataModified();
apply();
return TRUE;
}
case IDC_GLOBAL_FONTSIZE_CHECK :
{
GlobalOverride & glo = (NppParameters::getInstance())->getGlobalOverrideStyle();
glo.enableFontSize = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, wParam, BM_GETCHECK, 0, 0));
notifyDataModified();
apply();
return TRUE;
}
case IDC_GLOBAL_BOLD_CHECK :
{
GlobalOverride & glo = (NppParameters::getInstance())->getGlobalOverrideStyle();
glo.enableBold = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, wParam, BM_GETCHECK, 0, 0));
notifyDataModified();
apply();
return TRUE;
}
case IDC_GLOBAL_ITALIC_CHECK :
{
GlobalOverride & glo = (NppParameters::getInstance())->getGlobalOverrideStyle();
glo.enableItalic = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, wParam, BM_GETCHECK, 0, 0));
notifyDataModified();
apply();
return TRUE;
}
case IDC_GLOBAL_UNDERLINE_CHECK :
{
GlobalOverride & glo = (NppParameters::getInstance())->getGlobalOverrideStyle();
glo.enableUnderLine = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, wParam, BM_GETCHECK, 0, 0));
notifyDataModified();
apply();
return TRUE;
}
default:
switch (HIWORD(wParam))
{
case CBN_SELCHANGE : // == case LBN_SELCHANGE :
{
switch (LOWORD(wParam))
{
case IDC_FONT_COMBO :
updateFontName();
notifyDataModified();
apply();
break;
case IDC_FONTSIZE_COMBO :
updateFontSize();
notifyDataModified();
apply();
break;
case IDC_LANGUAGES_LIST :
{
int i = ::SendDlgItemMessage(_hSelf, LOWORD(wParam), LB_GETCURSEL, 0, 0);
if (i != LB_ERR)
setStyleListFromLexer(i);
break;
}
case IDC_STYLES_LIST :
setVisualFromStyleList();
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -