TupBrushStatus::TupBrushStatus(const QString &label, const QPixmap &pix, bool bg) { background = bg; QHBoxLayout *layout = new QHBoxLayout(this); layout->setMargin(2); layout->setSpacing(2); brush = new TupColorWidget; connect(brush, SIGNAL(clicked()), this, SLOT(updateColour())); QLabel *icon = new QLabel(""); icon->setToolTip(label); icon->setPixmap(pix); layout->addWidget(icon); layout->addSpacing(3); layout->addWidget(brush); }
BOOL CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) { switch (Message) { case WM_INITDIALOG : { NppParameters *nppParamInst = NppParameters::getInstance(); _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); _hSwitch2ThemeCombo = ::GetDlgItem(_hSelf, IDC_SWITCH2THEME_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); _currentThemeIndex = -1; int defaultThemeIndex = 0; ThemeSwitcher & themeSwitcher = nppParamInst->getThemeSwitcher(); for(size_t i = 0 ; i < themeSwitcher.size() ; i++) { std::pair<generic_string, generic_string> & themeInfo = themeSwitcher.getElementFromIndex(i); int j = ::SendMessage(_hSwitch2ThemeCombo, CB_ADDSTRING, 0, (LPARAM)themeInfo.first.c_str()); if (! themeInfo.second.compare( nppParamInst->getNppGUI()._themeName ) ) { _currentThemeIndex = j; } if (! themeInfo.first.compare(TEXT("Default")) ) { defaultThemeIndex = j; } } if (_currentThemeIndex == -1) { _currentThemeIndex = defaultThemeIndex; } ::SendMessage(_hSwitch2ThemeCombo, CB_SETCURSEL, _currentThemeIndex, 0); for(int i = 0 ; i < sizeof(fontSizeStrs)/(3*sizeof(TCHAR)) ; i++) ::SendMessage(_hFontSizeCombo, CB_ADDSTRING, 0, (LPARAM)fontSizeStrs[i]); const std::vector<generic_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(); ::EnableWindow(::GetDlgItem(_hSelf, IDOK), _isDirty); ::EnableWindow(::GetDlgItem(_hSelf, IDC_SAVECLOSE_BUTTON), FALSE/*!_isSync*/); ETDTProc enableDlgTheme = (ETDTProc)nppParamInst->getEnableThemeDlgTexture(); if (enableDlgTheme) { enableDlgTheme(_hSelf, ETDT_ENABLETAB); redraw(); } updateGlobalOverrideCtrls(); loadLangListFromNppParam(); setVisualFromStyleList(); goToCenter(); return TRUE; } case WM_DESTROY: { if (_pFgColour) { _pFgColour->destroy(); delete _pFgColour; _pFgColour = NULL; } if (_pBgColour) { _pBgColour->destroy(); delete _pBgColour; _pBgColour = NULL; } return TRUE; } case WM_HSCROLL : { if ((HWND)lParam == ::GetDlgItem(_hSelf, IDC_SC_PERCENTAGE_SLIDER)) { int percent = ::SendDlgItemMessage(_hSelf, IDC_SC_PERCENTAGE_SLIDER, TBM_GETPOS, 0, 0); (NppParameters::getInstance())->SetTransparent(_hSelf, percent); } 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(); apply(); } } 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, TEXT("cancel"), TEXT(""), MB_OK); if (_isDirty) { NppParameters *nppParamInst = NppParameters::getInstance(); if (_restoreInvalid) { generic_string str( nppParamInst->getNppGUI()._themeName ); nppParamInst->reloadStylers( &str[0] ); } LexerStylerArray & lsArray = nppParamInst->getLStylerArray(); StyleArray & globalStyles = nppParamInst->getGlobalStylers(); if (_restoreInvalid) { _lsArray = _styles2restored = lsArray; _globalStyles = _gstyles2restored = globalStyles; } else { globalStyles = _globalStyles = _gstyles2restored; lsArray = _lsArray = _styles2restored; } restoreGlobalOverrideValues(); _restoreInvalid = false; _isDirty = false; _isThemeDirty = false; setVisualFromStyleList(); //(nppParamInst->getNppGUI())._themeName ::SendMessage(_hSwitch2ThemeCombo, CB_SETCURSEL, _currentThemeIndex, 0); ::SendMessage(_hParent, WM_UPDATESCINTILLAS, 0, 0); } ::EnableWindow(::GetDlgItem(_hSelf, IDC_SAVECLOSE_BUTTON), FALSE/*!_isSync*/); display(false); return TRUE; case IDC_SAVECLOSE_BUTTON : { if (_isDirty) { LexerStylerArray & lsa = (NppParameters::getInstance())->getLStylerArray(); StyleArray & globalStyles = (NppParameters::getInstance())->getGlobalStylers(); _lsArray = lsa; _globalStyles = globalStyles; updateThemeName(_themeName); _restoreInvalid = false; _currentThemeIndex = ::SendMessage(_hSwitch2ThemeCombo, CB_GETCURSEL, 0, 0); ::EnableWindow(::GetDlgItem(_hSelf, IDOK), FALSE); _isDirty = false; } _isThemeDirty = 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) { bool prevThemeState = _isThemeDirty; setStyleListFromLexer(i); _isThemeDirty = prevThemeState; } break; } case IDC_STYLES_LIST : setVisualFromStyleList(); break; case IDC_SWITCH2THEME_COMBO : switchToTheme(); setVisualFromStyleList(); notifyDataModified(); _isThemeDirty = false; apply(); break; NO_DEFAULT_CASE; } return TRUE; } case CPN_COLOURPICKED: { assert(_pFgColour); assert(_pBgColour); if ((HWND)lParam == _pFgColour->getHSelf()) { updateColour(C_FOREGROUND); notifyDataModified(); int tabColourIndex; if ((tabColourIndex = whichTabColourIndex()) != -1) { //::SendMessage(_hParent, WM_UPDATETABBARCOLOUR, tabColourIndex, _pFgColour->getColour()); TabBarPlus::setColour(_pFgColour->getColour(), (TabBarPlus::tabColourIndex)tabColourIndex); return TRUE; } apply(); return TRUE; } else if ((HWND)lParam == _pBgColour->getHSelf()) { updateColour(C_BACKGROUND); notifyDataModified(); int tabColourIndex; if ((tabColourIndex = whichTabColourIndex()) != -1) { tabColourIndex = (int)tabColourIndex == TabBarPlus::inactiveText? TabBarPlus::inactiveBg : tabColourIndex; TabBarPlus::setColour(_pBgColour->getColour(), (TabBarPlus::tabColourIndex)tabColourIndex); return TRUE; } apply(); return TRUE; } else return FALSE; } default : { return FALSE; } } } } } } break; default : break; } return FALSE; }