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

📄 userdefinedialog.cpp

📁 Notepad++ 源代码,功能强大的编辑软件
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	_keyWordsStyleDlg.updateDlg();
	_commentStyleDlg.updateDlg();
	_symbolsStyleDlg.updateDlg();
}

BOOL CALLBACK UserDefineDialog::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message) 
	{
        case WM_INITDIALOG :
        {
			_ctrlTab.init(_hInst, _hSelf, false);

			_folderStyleDlg.init(_hInst, _hSelf);
			_folderStyleDlg.create(IDD_FOLDER_STYLE_DLG);
			_folderStyleDlg.display();

			_keyWordsStyleDlg.init(_hInst, _hSelf);
			_keyWordsStyleDlg.create(IDD_KEYWORD_STYLE_DLG);
			_keyWordsStyleDlg.display(false);

			_commentStyleDlg.init(_hInst, _hSelf);
			_commentStyleDlg.create(IDD_COMMENT_STYLE_DLG);
			_commentStyleDlg.display(false);

			_symbolsStyleDlg.init(_hInst, _hSelf);
			_symbolsStyleDlg.create(IDD_SYMBOL_STYLE_DLG);
			_symbolsStyleDlg.display(false);

			_wVector.push_back(DlgEtName(&_folderStyleDlg, "Folder && Default"));
			_wVector.push_back(DlgEtName(&_keyWordsStyleDlg, "Keywords Lists"));
			_wVector.push_back(DlgEtName(&_commentStyleDlg, "Comment && Number"));
			_wVector.push_back(DlgEtName(&_symbolsStyleDlg, "Operators"));

			_ctrlTab.createTabs(_wVector);
			_ctrlTab.display();
			RECT rc;
			getClientRect(rc);
			rc.top += 100;	
			rc.bottom -= 100;
			_ctrlTab.reSizeTo(rc);

			_folderStyleDlg.reSizeTo(rc);
			_keyWordsStyleDlg.reSizeTo(rc);
			_commentStyleDlg.reSizeTo(rc);
			_symbolsStyleDlg.reSizeTo(rc);

			::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_ADDSTRING, 0, (LPARAM)"User Define Language");
			for (int i = 0 ; i < NppParameters::getInstance()->getNbUserLang() ; i++)
			{
				UserLangContainer & userLangContainer = NppParameters::getInstance()->getULCFromIndex(i);
				::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_ADDSTRING, 0, (LPARAM)userLangContainer.getName());
			}
			::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_SETCURSEL, 0, 0);
			enableLangAndControlsBy(0);

			_pUserLang = _pCurrentUserLang;
			//_ctrlTab.display(false);

			if ((NppParameters::getInstance())->isTransparentAvailable())
			{
				::ShowWindow(::GetDlgItem(_hSelf, IDC_UD_TRANSPARENT_CHECK), SW_SHOW);
				::ShowWindow(::GetDlgItem(_hSelf, IDC_UD_PERCENTAGE_SLIDER), SW_SHOW);
				
				::SendDlgItemMessage(_hSelf, IDC_UD_PERCENTAGE_SLIDER, TBM_SETRANGE, FALSE, MAKELONG(20, 200));
				::SendDlgItemMessage(_hSelf, IDC_UD_PERCENTAGE_SLIDER, TBM_SETPOS, TRUE, 150);
				if (!(BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_UD_PERCENTAGE_SLIDER, BM_GETCHECK, 0, 0)))
					::EnableWindow(::GetDlgItem(_hSelf, IDC_UD_PERCENTAGE_SLIDER), FALSE);
			}
			SCROLLINFO si;
			si.cbSize = sizeof(si); 
			si.fMask  = SIF_RANGE; //| SIF_PAGE; 
			si.nMin   = 0; 
			si.nMax   = 0; 
			//si.nPage  = _currentHight; 
			//si.nPos = 0;
			::SetScrollInfo(_hSelf, SB_VERT, &si, TRUE);
            return TRUE;
        }

		case WM_NOTIFY :		  
		{
			NMHDR *nmhdr = (NMHDR *)lParam;
			if (nmhdr->code == TCN_SELCHANGE)
			{
				if (nmhdr->hwndFrom == _ctrlTab.getHSelf())
				{
					_ctrlTab.clickedUpdate();
					return TRUE;
				}
			}
			break;
		}

		case WM_HSCROLL :
		{
			if ((HWND)lParam == ::GetDlgItem(_hSelf, IDC_UD_PERCENTAGE_SLIDER))
			{
				int percent = ::SendDlgItemMessage(_hSelf, IDC_UD_PERCENTAGE_SLIDER, TBM_GETPOS, 0, 0);
				(NppParameters::getInstance())->SetTransparent(_hSelf, percent/*HIWORD(wParam)*/);
			}
			return TRUE;
		}

		case WM_COMMAND : 
		{
            if (HIWORD(wParam) == EN_CHANGE)
            {
				::SendDlgItemMessage(_hSelf, IDC_EXT_EDIT, WM_GETTEXT, extsLenMax, (LPARAM)(_pUserLang->_ext));
                return TRUE;
            }
            else if (HIWORD(wParam) == CBN_SELCHANGE)
            {
				if (LOWORD(wParam) == IDC_LANGNAME_COMBO)
				{
					int i = ::SendDlgItemMessage(_hSelf, LOWORD(wParam), CB_GETCURSEL, 0, 0);
					enableLangAndControlsBy(i);
					updateDlg();
				}
                return TRUE;
            }
            else
            {
			    switch (wParam)
			    {
				    case IDC_DOCK_BUTTON :
                    {
						int msg = WM_UNDOCK_USERDEFINE_DLG;
						
						if (_status == UNDOCK)
						{
							if ((NppParameters::getInstance())->isTransparentAvailable())
							{
								(NppParameters::getInstance())->removeTransparent(_hSelf);
								::ShowWindow(::GetDlgItem(_hSelf, IDC_UD_TRANSPARENT_CHECK), SW_HIDE);
								::ShowWindow(::GetDlgItem(_hSelf, IDC_UD_PERCENTAGE_SLIDER), SW_HIDE);
							}
							msg = WM_DOCK_USERDEFINE_DLG;
						}

                        changeStyle();

						if (_status == UNDOCK)
						{
							if ((NppParameters::getInstance())->isTransparentAvailable())
							{
								bool isChecked = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_UD_TRANSPARENT_CHECK, BM_GETCHECK, 0, 0));
								if (isChecked)
								{
									int percent = ::SendDlgItemMessage(_hSelf, IDC_UD_PERCENTAGE_SLIDER, TBM_GETPOS, 0, 0);
									(NppParameters::getInstance())->SetTransparent(_hSelf, percent);
								}
								::ShowWindow(::GetDlgItem(_hSelf, IDC_UD_TRANSPARENT_CHECK), SW_SHOW);
								::ShowWindow(::GetDlgItem(_hSelf, IDC_UD_PERCENTAGE_SLIDER), SW_SHOW);
							}
						}
                        ::SendMessage(_hParent, msg, 0, 0);
					    return TRUE;
                    }
    				case IDCANCEL :
						::SendMessage(_hParent, WM_CLOSE_USERDEFINE_DLG, 0, 0);
					    display(false);
					    return TRUE;

				    case IDC_REMOVELANG_BUTTON :
                    {
						int result = ::MessageBox(_hSelf, "Are you sure?", "Remove the current language", MB_YESNO);
						if (result == IDYES)
						{
							int i = ::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_GETCURSEL, 0, 0);
							char langName[256];
							::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_GETLBTEXT, i, (LPARAM)langName);

							//remove current language from combobox
							::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_DELETESTRING, i, 0);
							::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_SETCURSEL, i-1, 0);
							::SendMessage(_hSelf, WM_COMMAND, MAKELONG(IDC_LANGNAME_COMBO, CBN_SELCHANGE), (LPARAM)::GetDlgItem(_hSelf, IDC_LANGNAME_COMBO));

							//remove current language from userLangArray
							NppParameters::getInstance()->removeUserLang(i-1);

							//remove current language from langMenu
							HWND hNpp = ::GetParent(_hSelf);
							::RemoveMenu(::GetSubMenu(::GetMenu(hNpp), MENUINDEX_LANGUAGE), IDM_LANG_USER + i, MF_BYCOMMAND);
							::DrawMenuBar(hNpp);
							::SendMessage(_hParent, WM_REMOVE_USERLANG, 0, (LPARAM)langName);
						}
					    return TRUE;
                    }
				    case IDC_RENAME_BUTTON :
                    {
						char langName[256];
						int i = ::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_GETCURSEL, 0, 0);
						::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_GETLBTEXT, i, (LPARAM)langName);

						StringDlg strDlg;
						strDlg.init(_hInst, _hSelf, "Rename Current Language Name", "Name : ", langName, langNameLenMax-1);

						char *newName = (char *)strDlg.doDialog();

						if (newName)
						{
							if (NppParameters::getInstance()->isExistingUserLangName(newName))
							{
								::MessageBox(_hSelf, "This name is used by another language,\rplease give another one.", "Err", MB_OK);
								::PostMessage(_hSelf, WM_COMMAND, IDC_RENAME_BUTTON, 0);
								return TRUE;
							}
							//rename current language name in combobox
							::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_DELETESTRING, i, 0);
							::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_INSERTSTRING, i, (LPARAM)newName);
							::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_SETCURSEL, i, 0);
							
							//rename current language name in userLangArray
							UserLangContainer & userLangContainer = NppParameters::getInstance()->getULCFromIndex(i-1);
							strcpy(userLangContainer._name, newName);

							//rename current language name in langMenu
							HWND hNpp = ::GetParent(_hSelf);
							::ModifyMenu(::GetSubMenu(::GetMenu(hNpp), MENUINDEX_LANGUAGE), IDM_LANG_USER + i, MF_BYCOMMAND, IDM_LANG_USER + i, newName);
							::DrawMenuBar(hNpp);
							::SendMessage(_hParent, WM_RENAME_USERLANG, (WPARAM)newName, (LPARAM)langName);
						}

					    return TRUE;
                    }

					case IDC_ADDNEW_BUTTON :
					case IDC_SAVEAS_BUTTON :
                    {
						//char langName[256];
						int i = ::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_GETCURSEL, 0, 0);
						//::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_GETLBTEXT, i, (LPARAM)langName);
						if (i == 0)
							wParam = IDC_ADDNEW_BUTTON;

						StringDlg strDlg;
						if (wParam == IDC_SAVEAS_BUTTON)
							strDlg.init(_hInst, _hSelf, "Save Current Language Name As...", "Name : ", "", langNameLenMax-1);
						else
							strDlg.init(_hInst, _hSelf, "Create New Language...", "Name : ", "", langNameLenMax-1);

						char *newName = (char *)strDlg.doDialog();

						if (newName)
						{
							if (NppParameters::getInstance()->isExistingUserLangName(newName))
							{
								::MessageBox(_hSelf, "This name is used by another language,\rplease give another one.", "Err", MB_OK);
								::PostMessage(_hSelf, WM_COMMAND, IDC_RENAME_BUTTON, 0);
								return TRUE;
							}
							//add current language in userLangArray at the end as a new lang
							UserLangContainer & userLang = (wParam == IDC_SAVEAS_BUTTON)?NppParameters::getInstance()->getULCFromIndex(i-1):*_pCurrentUserLang;
							int newIndex = NppParameters::getInstance()->addUserLangToEnd(userLang, newName);

							//add new language name in combobox
							::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_ADDSTRING, 0, LPARAM(newName));
							::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_SETCURSEL, newIndex + 1, 0);
							::SendMessage(_hSelf, WM_COMMAND, MAKELONG(IDC_LANGNAME_COMBO, CBN_SELCHANGE), (LPARAM)::GetDlgItem(_hSelf, IDC_LANGNAME_COMBO));

							//add new language name in langMenu
							HWND hNpp = ::GetParent(_hSelf);
							::InsertMenu(::GetSubMenu(::GetMenu(hNpp), MENUINDEX_LANGUAGE), IDM_LANG_USER + newIndex /*+ 1*/, MF_BYCOMMAND, IDM_LANG_USER + newIndex + 1, newName);
							::DrawMenuBar(hNpp);
						}

					    return TRUE;
                    }
				
					case IDC_UD_TRANSPARENT_CHECK :
					{
						bool isChecked = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_UD_TRANSPARENT_CHECK, BM_GETCHECK, 0, 0));
						if (isChecked)
						{
							int percent = ::SendDlgItemMessage(_hSelf, IDC_UD_PERCENTAGE_SLIDER, TBM_GETPOS, 0, 0);
							(NppParameters::getInstance())->SetTransparent(_hSelf, percent);
						}
						else
							(NppParameters::getInstance())->removeTransparent(_hSelf);

						::EnableWindow(::GetDlgItem(_hSelf, IDC_UD_PERCENTAGE_SLIDER), isChecked);
						return TRUE;
					}

					case IDC_LANGNAME_IGNORECASE_CHECK :
						return setPropertyByCheck(_hSelf, wParam, _pUserLang->_isCaseIgnored);

				    default :
					    break;
			    }
            }
			return FALSE;
		}

		case WM_DESTROY:
		{
			_folderStyleDlg.destroy();
			_keyWordsStyleDlg.destroy();
			_commentStyleDlg.destroy();
			_symbolsStyleDlg.destroy();

			_ctrlTab.destroy();
			return TRUE;
		}

		case WM_SIZE: 
		{
			int originalHight = _dlgPos.bottom; //- ((_status == DOCK)?_dlgPos.top:0);
			_currentHight = HIWORD (lParam);

			int diff = _currentHight - _prevHightVal;
			_prevHightVal = _currentHight;

			 int maxPos = originalHight - _currentHight;
			// Set the vertical scrolling range and page size
			SCROLLINFO si;
			si.cbSize = sizeof(si); 
			si.fMask  = SIF_RANGE | SIF_PAGE; 
			si.nMin   = 0; 
			si.nMax   = (_status == UNDOCK)?0:originalHight; 
			si.nPage  = _currentHight; 
			//si.nPos = 0;
			::SetScrollInfo(_hSelf, SB_VERT, &si, TRUE);

			if ((_yScrollPos >= maxPos) && (_currentHight < originalHight))
			{
				//int nDelta = min(max(maxPos/10,5), maxPos - _yScrollPos);
				if (_yScrollPos > 0)
				{
					_yScrollPos -= diff;
					::SetScrollPos(_hSelf, SB_VERT, _yScrollPos, TRUE);
					::ScrollWindow(_hSelf, 0, diff, NULL, NULL);
				}
			}
			return TRUE; 
		}

		case WM_VSCROLL :
		{
			int originalHight = _dlgPos.bottom;
			int oldy = _yScrollPos;
			int maxPos = originalHight - _currentHight;

			switch (LOWORD (wParam))
			{
				// user clicked the top arrow
				case SB_LINEUP:
					if (_yScrollPos <= 0)
						return FALSE;
					_yScrollPos = 0;
					break;

				// user clicked the bottom arrow
				case SB_LINEDOWN:
					if (_yScrollPos >= maxPos)
						return FALSE;
					_yScrollPos = maxPos;
					break;

				case SB_PAGEDOWN:
					if (_yScrollPos >= maxPos)
						return FALSE;
					_yScrollPos = maxPos;
					break;

				case SB_PAGEUP:
					if (_yScrollPos <= 0)
						return FALSE;
					_yScrollPos = 0;
					break;

				case SB_THUMBTRACK:
				case SB_THUMBPOSITION:
					_yScrollPos = (int)HIWORD(wParam);
					break;

				default :
					return FALSE;
			}
			::SetScrollPos(_hSelf, SB_VERT, _yScrollPos, TRUE);
			::ScrollWindow(_hSelf, 0, oldy-_yScrollPos, NULL, NULL);
		}
		case WM_MODELESSDIALOG :
			return ::SendMessage(_hParent, WM_MODELESSDIALOG, wParam, lParam);
    }
	
	return FALSE;
}

⌨️ 快捷键说明

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