⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wordstyledlg.cpp

📁 非常好的彩色代码编辑器(支持c/c++/java/html/xml/php/js/makefile/asp/VB/SQL/ObjC/Perl/Python/CSS...)
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    // Before filling out, we clean it
    ::SendMessage(_hStyleCombo, CB_RESETCONTENT, 0, 0);

	if (index)
	{
		const char *langName = _pLexerStylerArray->getLexerNameFromIndex(index - 1);
		const char *ext = NppParameters::getInstance()->getLangExtFromName(langName);
		const char *userExt = (_pLexerStylerArray->getLexerStylerByName(langName))->getLexerUserExt();
		::SendDlgItemMessage(_hSelf, IDC_DEF_EXT_EDIT, WM_SETTEXT, 0, (LPARAM)(ext));
		::SendDlgItemMessage(_hSelf, IDC_USER_EXT_EDIT, WM_SETTEXT, 0, (LPARAM)(userExt));
	}
	::ShowWindow(::GetDlgItem(_hSelf, IDC_DEF_EXT_EDIT), index?SW_SHOW:SW_HIDE);
    ::ShowWindow(::GetDlgItem(_hSelf, IDC_DEF_EXT_STATIC), index?SW_SHOW:SW_HIDE);
	::ShowWindow(::GetDlgItem(_hSelf, IDC_USER_EXT_EDIT), index?SW_SHOW:SW_HIDE);
    ::ShowWindow(::GetDlgItem(_hSelf, IDC_USER_EXT_STATIC), index?SW_SHOW:SW_HIDE);

	StyleArray & lexerStyler = index?_pLexerStylerArray->getLexerFromIndex(index-1):*_pStylerArray;

    for (int i = 0 ; i < lexerStyler.getNbStyler() ; i++)
    {
        Style & style = lexerStyler.getStyler(i);
        ::SendMessage(_hStyleCombo, CB_ADDSTRING, 0, (LPARAM)style._styleDesc);	
    }
    ::SendMessage(_hStyleCombo, CB_SETCURSEL, 0, 0);
    setVisualFromStyleCombo();
}

void WordStyleDlg::setVisualFromStyleCombo() 
{

    Style & style = getCurrentStyler();

    //--Warning text
    int showWarning = ((_currentLexerIndex == 0) && (style._styleID == STYLE_DEFAULT))?SW_SHOW:SW_HIDE;
    ::ShowWindow(::GetDlgItem(_hSelf, IDC_STYLEDEFAULT_WARNING_STATIC), showWarning);

	//-- 2 couleurs : fg et bg
	bool isEnable = false;
	if (HIBYTE(HIWORD(style._fgColor)) != 0xFF)
	{
		_pFgColour->setColour(style._fgColor);
		isEnable = true;
	}
	enableFg(isEnable);

	isEnable = false;
	if (HIBYTE(HIWORD(style._bgColor)) != 0xFF)
	{
		_pBgColour->setColour(style._bgColor);
		isEnable = true;
	}
	enableBg(isEnable);

	//-- font name
	isEnable = false;
	int iFontName;
	if (style._fontName != NULL)
	{
		iFontName = ::SendMessage(_hFontNameCombo, CB_FINDSTRING, 1, (LPARAM)style._fontName);
		if (iFontName == CB_ERR)
			iFontName = 0;
		isEnable = true;
	}
	else
	{
		iFontName = 0;
	}
	::SendMessage(_hFontNameCombo, CB_SETCURSEL, iFontName, 0);
	enableFontName(isEnable);

	//-- font size
	isEnable = false;
	char intStr[5] = "";
	int iFontSize = 0;
	if (style._fontSize != -1)
	{
		sprintf(intStr, "%d", style._fontSize);
		iFontSize = ::SendMessage(_hFontSizeCombo, CB_FINDSTRING, 1, (LPARAM)intStr);
		isEnable = true;
	}
	::SendMessage(_hFontSizeCombo, CB_SETCURSEL, iFontSize, 0);
	enableFontSize(isEnable);

	//-- font style : bold et italic
	isEnable = false;
	int isBold, isItalic, isUnderline;
	if (style._fontStyle != -1)
	{
		isBold = (style._fontStyle & FONTSTYLE_BOLD)?BST_CHECKED:BST_UNCHECKED;
		isItalic = (style._fontStyle & FONTSTYLE_ITALIC)?BST_CHECKED:BST_UNCHECKED;
		isUnderline = (style._fontStyle & FONTSTYLE_UNDERLINE)?BST_CHECKED:BST_UNCHECKED;
		::SendMessage(_hCheckBold, BM_SETCHECK, isBold, 0);
		::SendMessage(_hCheckItalic, BM_SETCHECK, isItalic, 0);
		::SendMessage(_hCheckUnderline, BM_SETCHECK, isUnderline, 0);
		isEnable = true;
	}
	else // -1 est comme 0
	{
		::SendMessage(_hCheckBold, BM_SETCHECK, BST_UNCHECKED, 0);
		::SendMessage(_hCheckItalic, BM_SETCHECK, BST_UNCHECKED, 0);
		::SendMessage(_hCheckUnderline, BM_SETCHECK, BST_UNCHECKED, 0);
	}

    enableFontStyle(isEnable);


	//-- Default Keywords
	bool shouldBeDisplayed = style._keywordClass != -1;
	if (shouldBeDisplayed)
	{
		LexerStyler & lexerStyler = _pLexerStylerArray->getLexerFromIndex(_currentLexerIndex - 1);

		NppParameters *pNppParams = NppParameters::getInstance();
		LangType lType = pNppParams->getLangIDFromStr(lexerStyler.getLexerName());
		const char *kws = pNppParams->getWordList(lType, style._keywordClass);
		if (!kws)
			kws = "";
		::SendDlgItemMessage(_hSelf, IDC_DEF_KEYWORDS_EDIT, WM_SETTEXT, 0, (LPARAM)(kws));

		const char *ckwStr = (style._keywords)?style._keywords->c_str():"";
		::SendDlgItemMessage(_hSelf, IDC_USER_KEYWORDS_EDIT, WM_SETTEXT, 0, (LPARAM)(ckwStr));
	}
	int showOption = shouldBeDisplayed?SW_SHOW:SW_HIDE;
	::ShowWindow(::GetDlgItem(_hSelf, IDC_DEF_KEYWORDS_EDIT), showOption);
	::ShowWindow(::GetDlgItem(_hSelf, IDC_USER_KEYWORDS_EDIT),showOption);
	::ShowWindow(::GetDlgItem(_hSelf, IDC_DEF_KEYWORDS_STATIC), showOption);
	::ShowWindow(::GetDlgItem(_hSelf, IDC_USER_KEYWORDS_STATIC),showOption);
	::ShowWindow(::GetDlgItem(_hSelf, IDC_PLUSSYMBOL_STATIC),showOption);

    redraw();
}

void GlobalStyleDlg::create(int dialogID)
{
	StaticDialog::create(dialogID);

	if ((NppParameters::getInstance())->isTransparentAvailable())
	{
		::ShowWindow(::GetDlgItem(_hSelf, IDC_SC_TRANSPARENT_CHECK), SW_SHOW);
		::ShowWindow(::GetDlgItem(_hSelf, IDC_SC_PERCENTAGE_SLIDER), SW_SHOW);
		
		::SendDlgItemMessage(_hSelf, IDC_SC_PERCENTAGE_SLIDER, TBM_SETRANGE, FALSE, MAKELONG(20, 200));
		::SendDlgItemMessage(_hSelf, IDC_SC_PERCENTAGE_SLIDER, TBM_SETPOS, TRUE, 150);
		if (!(BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_SC_PERCENTAGE_SLIDER, BM_GETCHECK, 0, 0)))
			::EnableWindow(::GetDlgItem(_hSelf, IDC_SC_PERCENTAGE_SLIDER), FALSE);
	}
}

BOOL CALLBACK GlobalStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam)
{
	switch (Message)
	{
		case WM_INITDIALOG :
		{
			RECT rc;
			_styleTab.init(_hInst, _hSelf, false, true, true);

			_stylesControls.init(_hInst, _hSelf, &_lsArray, &_globalStyles);
			_stylesControls.doDialog();

            _lsArray = (NppParameters::getInstance())->getLStylerArray();
            _globalStyles = (NppParameters::getInstance())->getGlobalStylers();

            // Global Style
            _styleTab.insertAtEnd("Global Styles");

            // All the lexers
            for (int i = 0 ; i < _lsArray.getNbLexer() ; i++)
            {
			    //_styleTab.insertAtEnd(_lsArray.getLexerNameFromIndex(i));
				_styleTab.insertAtEnd(_lsArray.getLexerDescFromIndex(i));
            }
			
			getClientRect(rc);
			
            HWND hButton = ::GetDlgItem(_hSelf, IDCANCEL);
            POINT p;
            StaticDialog::alignWith(hButton, hButton, ALIGNPOS_TOP, p);
            rc.bottom = p.y;

            _styleTab.reSizeTo(rc);
            rc.top += 10;
            rc.bottom -= 100;
            rc.left += 5;
            rc.right -= 20;
            _stylesControls.reSizeTo(rc);

            _stylesControls.setStyleComboFromLexer(0);

			::EnableWindow(::GetDlgItem(_hSelf, IDOK), _isDirty);
			::EnableWindow(::GetDlgItem(_hSelf, IDC_SAVECLOSE_BUTTON), !_isSync);

			_styleTab.display();
			_stylesControls.display();
			return TRUE;
		}

		case WM_DESTROY:
		{
			_styleTab.destroy();
			_stylesControls.destroy();
			return TRUE;
		}

        case WM_NOTIFY :
        {
            NMHDR *nmhdr = (NMHDR *)lParam;
            if (nmhdr->code == TCN_SELCHANGE)
	        {
                int indexClicked = int(::SendMessage(_styleTab.getHSelf(), TCM_GETCURSEL, 0, 0));
                _stylesControls.setStyleComboFromLexer(indexClicked);
            }
            return TRUE;
        }

		case WM_DATA_MODIFIED:
		{
			_isDirty = true;
			::EnableWindow(::GetDlgItem(_hSelf, IDOK), TRUE);
			::EnableWindow(::GetDlgItem(_hSelf, IDC_SAVECLOSE_BUTTON), TRUE);
			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/*HIWORD(wParam)*/);
			}
			return TRUE;
		}

		case WM_COMMAND : 
		{
			switch (wParam)
			{
				case IDCANCEL :
					if (_isDirty)
					{
						_lsArray = (NppParameters::getInstance())->getLStylerArray();
						_globalStyles = (NppParameters::getInstance())->getGlobalStylers();
						_isDirty = false;
                        _stylesControls.setVisualFromStyleCombo();
					}
					::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;
				}

				default :
				{
					
					return FALSE;
				}
			}
		}

		default :
			return FALSE;
	}
	return FALSE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -