Styles.c
资源名称:np2src.zip [点击查看]
上传用户:tj_dwf
上传日期:2020-11-17
资源大小:215k
文件大小:151k
源码类别:
RichEdit
开发平台:
Visual C++
- else if (pLexMode = Style_MatchLexer(wchMode,TRUE)) {
- pLexNew = pLexMode;
- bFound = TRUE;
- }
- }
- }
- lpszExt = PathFindExtension(lpszFile);
- if (!bFound && bAutoSelect && /* bAutoSelect == FALSE skips lexer search */
- (lpszFile && lstrlen(lpszFile) > 0 && *lpszExt)) {
- if (*lpszExt == L'.')
- lpszExt++;
- if (!fNoCGIGuess && (lstrcmpi(lpszExt,L"cgi") == 0 || lstrcmpi(lpszExt,L"fcgi") == 0)) {
- char tchText[256];
- SendMessage(hwnd,SCI_GETTEXT,(WPARAM)COUNTOF(tchText)-1,(LPARAM)tchText);
- StrTrimA(tchText," tnr");
- if (pLexSniffed = Style_SniffShebang(tchText)) {
- pLexNew = pLexSniffed;
- bFound = TRUE;
- }
- }
- // check associated extensions
- if (!bFound) {
- if (pLexSniffed = Style_MatchLexer(lpszExt,FALSE)) {
- pLexNew = pLexSniffed;
- bFound = TRUE;
- }
- }
- }
- if (!bFound && bAutoSelect &&
- lstrcmpi(PathFindFileName(lpszFile),L"makefile") == 0) {
- pLexNew = &lexMAK;
- bFound = TRUE;
- }
- if (!bFound && bAutoSelect && (!fNoHTMLGuess || !fNoCGIGuess)) {
- char tchText[512];
- SendMessage(hwnd,SCI_GETTEXT,(WPARAM)COUNTOF(tchText)-1,(LPARAM)tchText);
- StrTrimA(tchText," tnr");
- if (!fNoHTMLGuess && tchText[0] == '<') {
- if (StrStrIA(tchText,"<html"))
- pLexNew = &lexHTML;
- else
- pLexNew = &lexXML;
- bFound = TRUE;
- }
- else if (!fNoCGIGuess && (pLexSniffed = Style_SniffShebang(tchText))) {
- pLexNew = pLexSniffed;
- bFound = TRUE;
- }
- }
- // Apply the new lexer
- Style_SetLexer(hwnd,pLexNew);
- }
- //=============================================================================
- //
- // Style_SetLexerFromName()
- //
- void Style_SetLexerFromName(HWND hwnd,LPCWSTR lpszFile,LPCWSTR lpszName)
- {
- PEDITLEXER pLexNew;
- if (pLexNew = Style_MatchLexer(lpszName,FALSE))
- Style_SetLexer(hwnd,pLexNew);
- else if (pLexNew = Style_MatchLexer(lpszName,TRUE))
- Style_SetLexer(hwnd,pLexNew);
- else
- Style_SetLexerFromFile(hwnd,lpszFile);
- }
- //=============================================================================
- //
- // Style_SetDefaultLexer()
- //
- void Style_SetDefaultLexer(HWND hwnd)
- {
- Style_SetLexer(hwnd,pLexArray[0]);
- }
- //=============================================================================
- //
- // Style_SetHTMLLexer()
- //
- void Style_SetHTMLLexer(HWND hwnd)
- {
- Style_SetLexer(hwnd,pLexArray[1]);
- }
- //=============================================================================
- //
- // Style_SetXMLLexer()
- //
- void Style_SetXMLLexer(HWND hwnd)
- {
- Style_SetLexer(hwnd,pLexArray[2]);
- }
- //=============================================================================
- //
- // Style_SetLexerFromID()
- //
- void Style_SetLexerFromID(HWND hwnd,int id)
- {
- if (id >= 0 && id < NUMLEXERS) {
- Style_SetLexer(hwnd,pLexArray[id]);
- }
- }
- //=============================================================================
- //
- // Style_ToggleUse2ndDefault()
- //
- void Style_ToggleUse2ndDefault(HWND hwnd)
- {
- bUse2ndDefaultStyle = (bUse2ndDefaultStyle) ? 0 : 1;
- Style_SetLexer(hwnd,pLexCurrent);
- }
- //=============================================================================
- //
- // Style_SetDefaultFont()
- //
- void Style_SetDefaultFont(HWND hwnd)
- {
- int iIdx = (bUse2ndDefaultStyle) ? 13 : 0;
- if (Style_SelectFont(hwnd,
- lexDefault.Styles[0+iIdx].szValue,
- COUNTOF(lexDefault.Styles[0+iIdx].szValue),
- TRUE)) {
- fStylesModified = TRUE;
- Style_SetLexer(hwnd,pLexCurrent);
- }
- }
- //=============================================================================
- //
- // Style_GetUse2ndDefault()
- //
- BOOL Style_GetUse2ndDefault(HWND hwnd)
- {
- return (bUse2ndDefaultStyle);
- }
- //=============================================================================
- //
- // Style_SetIndentGuides()
- //
- extern int flagSimpleIndentGuides;
- void Style_SetIndentGuides(HWND hwnd,BOOL bShow)
- {
- int iIndentView = SC_IV_NONE;
- if (bShow) {
- if (!flagSimpleIndentGuides) {
- if (SendMessage(hwnd,SCI_GETLEXER,0,0) == SCLEX_PYTHON)
- iIndentView = SC_IV_LOOKFORWARD;
- else
- iIndentView = SC_IV_LOOKBOTH;
- }
- else
- iIndentView = SC_IV_REAL;
- }
- SendMessage(hwnd,SCI_SETINDENTATIONGUIDES,iIndentView,0);
- }
- //=============================================================================
- //
- // Style_GetFileOpenDlgFilter()
- //
- extern WCHAR tchFileDlgFilters[5*1024];
- BOOL Style_GetOpenDlgFilterStr(LPWSTR lpszFilter,int cchFilter)
- {
- if (lstrlen(tchFileDlgFilters) == 0)
- GetString(IDS_FILTER_ALL,lpszFilter,cchFilter);
- else {
- lstrcpyn(lpszFilter,tchFileDlgFilters,cchFilter-2);
- lstrcat(lpszFilter,L"||");
- }
- PrepareFilterStr(lpszFilter);
- return TRUE;
- }
- //=============================================================================
- //
- // Style_StrGetFont()
- //
- BOOL Style_StrGetFont(LPCWSTR lpszStyle,LPWSTR lpszFont,int cchFont)
- {
- WCHAR tch[256];
- WCHAR *p;
- if (p = StrStrI(lpszStyle,L"font:"))
- {
- lstrcpy(tch,p + lstrlen(L"font:"));
- if (p = StrChr(tch,L';'))
- *p = L' ';
- TrimString(tch);
- lstrcpyn(lpszFont,tch,cchFont);
- return TRUE;
- }
- return FALSE;
- }
- //=============================================================================
- //
- // Style_StrGetFontQuality()
- //
- BOOL Style_StrGetFontQuality(LPCWSTR lpszStyle,LPWSTR lpszQuality,int cchQuality)
- {
- WCHAR tch[256];
- WCHAR *p;
- if (p = StrStrI(lpszStyle,L"smoothing:"))
- {
- lstrcpy(tch,p + lstrlen(L"smoothing:"));
- if (p = StrChr(tch,L';'))
- *p = L' ';
- TrimString(tch);
- if (lstrcmpi(tch,L"none") == 0 ||
- lstrcmpi(tch,L"standard") == 0 ||
- lstrcmpi(tch,L"cleartype") == 0 ||
- lstrcmpi(tch,L"default") == 0) {
- lstrcpyn(lpszQuality,tch,cchQuality);
- return TRUE;
- }
- }
- return FALSE;
- }
- //=============================================================================
- //
- // Style_StrGetCharSet()
- //
- BOOL Style_StrGetCharSet(LPCWSTR lpszStyle,int *i)
- {
- WCHAR tch[256];
- WCHAR *p;
- int iValue;
- int itok;
- if (p = StrStrI(lpszStyle,L"charset:"))
- {
- lstrcpy(tch,p + lstrlen(L"charset:"));
- if (p = StrChr(tch,L';'))
- *p = L' ';
- TrimString(tch);
- itok = swscanf(tch,L"%i",&iValue);
- if (itok == 1)
- {
- *i = iValue;
- return TRUE;
- }
- }
- return FALSE;
- }
- //=============================================================================
- //
- // Style_StrGetSize()
- //
- BOOL Style_StrGetSize(LPCWSTR lpszStyle,int *i)
- {
- WCHAR tch[256];
- WCHAR *p;
- int iValue;
- int iSign = 0;
- int itok;
- if (p = StrStrI(lpszStyle,L"size:"))
- {
- lstrcpy(tch,p + lstrlen(L"size:"));
- if (tch[0] == L'+')
- {
- iSign = 1;
- tch[0] = L' ';
- }
- else if (tch[0] == L'-')
- {
- iSign = -1;
- tch[0] = L' ';
- }
- if (p = StrChr(tch,L';'))
- *p = L' ';
- TrimString(tch);
- itok = swscanf(tch,L"%i",&iValue);
- if (itok == 1)
- {
- if (iSign == 0)
- *i = iValue;
- else
- *i = max(0,iBaseFontSize + iValue * iSign); // size must be +
- return TRUE;
- }
- }
- return FALSE;
- }
- //=============================================================================
- //
- // Style_StrGetSizeStr()
- //
- BOOL Style_StrGetSizeStr(LPCWSTR lpszStyle,LPWSTR lpszSize,int cchSize)
- {
- WCHAR tch[256];
- WCHAR *p;
- if (p = StrStrI(lpszStyle,L"size:"))
- {
- lstrcpy(tch,p + lstrlen(L"size:"));
- if (p = StrChr(tch,L';'))
- *p = L' ';
- TrimString(tch);
- lstrcpyn(lpszSize,tch,cchSize);
- return TRUE;
- }
- return FALSE;
- }
- //=============================================================================
- //
- // Style_StrGetColor()
- //
- BOOL Style_StrGetColor(BOOL bFore,LPCWSTR lpszStyle,int *rgb)
- {
- WCHAR tch[256];
- WCHAR *p;
- int iValue;
- int itok;
- WCHAR *pItem = (bFore) ? L"fore:" : L"back:";
- if (p = StrStrI(lpszStyle,pItem))
- {
- lstrcpy(tch,p + lstrlen(pItem));
- if (tch[0] == L'#')
- tch[0] = L' ';
- if (p = StrChr(tch,L';'))
- *p = L' ';
- TrimString(tch);
- itok = swscanf(tch,L"%x",&iValue);
- if (itok == 1)
- {
- *rgb = RGB((iValue&0xFF0000) >> 16,(iValue&0xFF00) >> 8,iValue&0xFF);
- return TRUE;
- }
- }
- return FALSE;
- }
- //=============================================================================
- //
- // Style_StrGetCase()
- //
- BOOL Style_StrGetCase(LPCWSTR lpszStyle,int *i)
- {
- WCHAR tch[256];
- WCHAR *p;
- if (p = StrStrI(lpszStyle,L"case:"))
- {
- lstrcpy(tch,p + lstrlen(L"case:"));
- if (p = StrChr(tch,L';'))
- *p = L' ';
- TrimString(tch);
- if (tch[0] == L'u' || tch[0] == L'U') {
- *i = SC_CASE_UPPER;
- return TRUE;
- }
- else if (tch[0] == L'l' || tch[0] == L'L') {
- *i = SC_CASE_LOWER;
- return TRUE;
- }
- }
- return FALSE;
- }
- //=============================================================================
- //
- // Style_StrGetAlpha()
- //
- BOOL Style_StrGetAlpha(LPCWSTR lpszStyle,int *i)
- {
- WCHAR tch[256];
- WCHAR *p;
- int iValue;
- int itok;
- if (p = StrStrI(lpszStyle,L"alpha:"))
- {
- lstrcpy(tch,p + lstrlen(L"alpha:"));
- if (p = StrChr(tch,L';'))
- *p = L' ';
- TrimString(tch);
- itok = swscanf(tch,L"%i",&iValue);
- if (itok == 1)
- {
- *i = min(max(SC_ALPHA_TRANSPARENT,iValue),SC_ALPHA_OPAQUE);
- return TRUE;
- }
- }
- return FALSE;
- }
- //=============================================================================
- //
- // Style_SelectFont()
- //
- BOOL Style_SelectFont(HWND hwnd,LPWSTR lpszStyle,int cchStyle,BOOL bDefaultStyle)
- {
- CHOOSEFONT cf;
- LOGFONT lf;
- WCHAR szNewStyle[512];
- int iValue;
- WCHAR tch[32];
- HDC hdc;
- ZeroMemory(&cf,sizeof(CHOOSEFONT));
- ZeroMemory(&lf,sizeof(LOGFONT));
- // Map lpszStyle to LOGFONT
- if (Style_StrGetFont(lpszStyle,tch,COUNTOF(tch)))
- lstrcpyn(lf.lfFaceName,tch,COUNTOF(lf.lfFaceName));
- if (Style_StrGetCharSet(lpszStyle,&iValue))
- lf.lfCharSet = iValue;
- if (Style_StrGetSize(lpszStyle,&iValue)) {
- hdc = GetDC(hwnd);
- lf.lfHeight = -MulDiv(iValue,GetDeviceCaps(hdc,LOGPIXELSY),72);
- ReleaseDC(hwnd,hdc);
- }
- lf.lfWeight = (StrStrI(lpszStyle,L"bold")) ? FW_BOLD : FW_NORMAL;
- lf.lfItalic = (StrStrI(lpszStyle,L"italic")) ? 1 : 0;
- // Init cf
- cf.lStructSize = sizeof(CHOOSEFONT);
- cf.hwndOwner = hwnd;
- cf.lpLogFont = &lf;
- cf.Flags = CF_INITTOLOGFONTSTRUCT /*| CF_NOSCRIPTSEL*/ | CF_SCREENFONTS;
- if (HIBYTE(GetKeyState(VK_SHIFT)))
- cf.Flags |= CF_FIXEDPITCHONLY;
- if (!ChooseFont(&cf) || !lstrlen(lf.lfFaceName))
- return FALSE;
- // Map back to lpszStyle
- lstrcpy(szNewStyle,L"font:");
- lstrcat(szNewStyle,lf.lfFaceName);
- if (Style_StrGetFontQuality(lpszStyle,tch,COUNTOF(tch)))
- {
- lstrcat(szNewStyle,L"; smoothing:");
- lstrcat(szNewStyle,tch);
- }
- if (bDefaultStyle &&
- lf.lfCharSet != DEFAULT_CHARSET &&
- lf.lfCharSet != ANSI_CHARSET &&
- lf.lfCharSet != iDefaultCharSet) {
- lstrcat(szNewStyle,L"; charset:");
- wsprintf(tch,L"%i",lf.lfCharSet);
- lstrcat(szNewStyle,tch);
- }
- lstrcat(szNewStyle,L"; size:");
- wsprintf(tch,L"%i",cf.iPointSize/10);
- lstrcat(szNewStyle,tch);
- if (cf.nFontType & BOLD_FONTTYPE)
- lstrcat(szNewStyle,L"; bold");
- if (cf.nFontType & ITALIC_FONTTYPE)
- lstrcat(szNewStyle,L"; italic");
- if (StrStrI(lpszStyle,L"underline"))
- lstrcat(szNewStyle,L"; underline");
- // save colors
- if (Style_StrGetColor(TRUE,lpszStyle,&iValue))
- {
- wsprintf(tch,L"; fore:#%02X%02X%02X",
- (int)GetRValue(iValue),
- (int)GetGValue(iValue),
- (int)GetBValue(iValue));
- lstrcat(szNewStyle,tch);
- }
- if (Style_StrGetColor(FALSE,lpszStyle,&iValue))
- {
- wsprintf(tch,L"; back:#%02X%02X%02X",
- (int)GetRValue(iValue),
- (int)GetGValue(iValue),
- (int)GetBValue(iValue));
- lstrcat(szNewStyle,tch);
- }
- if (StrStrI(lpszStyle,L"eolfilled"))
- lstrcat(szNewStyle,L"; eolfilled");
- if (Style_StrGetCase(lpszStyle,&iValue)) {
- lstrcat(szNewStyle,L"; case:");
- lstrcat(szNewStyle,(iValue == SC_CASE_UPPER) ? L"u" : L"");
- }
- if (Style_StrGetAlpha(lpszStyle,&iValue)) {
- lstrcat(szNewStyle,L"; alpha:");
- wsprintf(tch,L"%i",iValue);
- lstrcat(szNewStyle,tch);
- }
- lstrcpyn(lpszStyle,szNewStyle,cchStyle);
- return TRUE;
- }
- //=============================================================================
- //
- // Style_SelectColor()
- //
- BOOL Style_SelectColor(HWND hwnd,BOOL bFore,LPWSTR lpszStyle,int cchStyle)
- {
- CHOOSECOLOR cc;
- WCHAR szNewStyle[512];
- int iRGBResult;
- int iValue;
- WCHAR tch[32];
- ZeroMemory(&cc,sizeof(CHOOSECOLOR));
- iRGBResult = (bFore) ? GetSysColor(COLOR_WINDOWTEXT) : GetSysColor(COLOR_WINDOW);
- Style_StrGetColor(bFore,lpszStyle,&iRGBResult);
- cc.lStructSize = sizeof(CHOOSECOLOR);
- cc.hwndOwner = hwnd;
- cc.rgbResult = iRGBResult;
- cc.lpCustColors = crCustom;
- cc.Flags = CC_FULLOPEN | CC_RGBINIT | CC_SOLIDCOLOR;
- if (!ChooseColor(&cc))
- return FALSE;
- iRGBResult = cc.rgbResult;
- // Rebuild style string
- lstrcpy(szNewStyle,L"");
- if (Style_StrGetFont(lpszStyle,tch,COUNTOF(tch)))
- {
- lstrcat(szNewStyle,L"font:");
- lstrcat(szNewStyle,tch);
- }
- if (Style_StrGetFontQuality(lpszStyle,tch,COUNTOF(tch)))
- {
- if (lstrlen(szNewStyle))
- lstrcat(szNewStyle,L"; ");
- lstrcat(szNewStyle,L"smoothing:");
- lstrcat(szNewStyle,tch);
- }
- if (Style_StrGetCharSet(lpszStyle,&iValue))
- {
- if (lstrlen(szNewStyle))
- lstrcat(szNewStyle,L"; ");
- wsprintf(tch,L"charset:%i",iValue);
- lstrcat(szNewStyle,tch);
- }
- if (Style_StrGetSizeStr(lpszStyle,tch,COUNTOF(tch)))
- {
- if (lstrlen(szNewStyle))
- lstrcat(szNewStyle,L"; ");
- lstrcat(szNewStyle,L"size:");
- lstrcat(szNewStyle,tch);
- }
- if (StrStrI(lpszStyle,L"bold"))
- {
- if (lstrlen(szNewStyle))
- lstrcat(szNewStyle,L"; ");
- lstrcat(szNewStyle,L"bold");
- }
- if (StrStrI(lpszStyle,L"italic"))
- {
- if (lstrlen(szNewStyle))
- lstrcat(szNewStyle,L"; ");
- lstrcat(szNewStyle,L"italic");
- }
- if (StrStrI(lpszStyle,L"underline"))
- {
- if (lstrlen(szNewStyle))
- lstrcat(szNewStyle,L"; ");
- lstrcat(szNewStyle,L"underline");
- }
- if (bFore)
- {
- if (lstrlen(szNewStyle))
- lstrcat(szNewStyle,L"; ");
- wsprintf(tch,L"fore:#%02X%02X%02X",
- (int)GetRValue(iRGBResult),
- (int)GetGValue(iRGBResult),
- (int)GetBValue(iRGBResult));
- lstrcat(szNewStyle,tch);
- if (Style_StrGetColor(FALSE,lpszStyle,&iValue))
- {
- wsprintf(tch,L"; back:#%02X%02X%02X",
- (int)GetRValue(iValue),
- (int)GetGValue(iValue),
- (int)GetBValue(iValue));
- lstrcat(szNewStyle,tch);
- }
- }
- else
- {
- if (lstrlen(szNewStyle))
- lstrcat(szNewStyle,L"; ");
- if (Style_StrGetColor(TRUE,lpszStyle,&iValue))
- {
- wsprintf(tch,L"fore:#%02X%02X%02X; ",
- (int)GetRValue(iValue),
- (int)GetGValue(iValue),
- (int)GetBValue(iValue));
- lstrcat(szNewStyle,tch);
- }
- wsprintf(tch,L"back:#%02X%02X%02X",
- (int)GetRValue(iRGBResult),
- (int)GetGValue(iRGBResult),
- (int)GetBValue(iRGBResult));
- lstrcat(szNewStyle,tch);
- }
- if (StrStrI(lpszStyle,L"eolfilled"))
- lstrcat(szNewStyle,L"; eolfilled");
- if (Style_StrGetCase(lpszStyle,&iValue)) {
- lstrcat(szNewStyle,L"; case:");
- lstrcat(szNewStyle,(iValue == SC_CASE_UPPER) ? L"u" : L"");
- }
- if (Style_StrGetAlpha(lpszStyle,&iValue)) {
- lstrcat(szNewStyle,L"; alpha:");
- wsprintf(tch,L"%i",iValue);
- lstrcat(szNewStyle,tch);
- }
- lstrcpyn(lpszStyle,szNewStyle,cchStyle);
- return TRUE;
- }
- //=============================================================================
- //
- // Style_SetStyles()
- //
- void Style_SetStyles(HWND hwnd,int iStyle,LPCWSTR lpszStyle)
- {
- WCHAR tch[256];
- WCHAR *p;
- int iValue;
- // Font
- if (Style_StrGetFont(lpszStyle,tch,COUNTOF(tch))) {
- char mch[256];
- WideCharToMultiByte(CP_ACP,0,tch,-1,mch,COUNTOF(mch),NULL,NULL);
- SendMessage(hwnd,SCI_STYLESETFONT,iStyle,(LPARAM)mch);
- }
- // Size
- if (Style_StrGetSize(lpszStyle,&iValue))
- SendMessage(hwnd,SCI_STYLESETSIZE,iStyle,(LPARAM)iValue);
- // Fore
- if (Style_StrGetColor(TRUE,lpszStyle,&iValue))
- SendMessage(hwnd,SCI_STYLESETFORE,iStyle,(LPARAM)iValue);
- // Back
- if (Style_StrGetColor(FALSE,lpszStyle,&iValue))
- SendMessage(hwnd,SCI_STYLESETBACK,iStyle,(LPARAM)iValue);
- // Bold
- if (p = StrStrI(lpszStyle,L"bold"))
- SendMessage(hwnd,SCI_STYLESETBOLD,iStyle,(LPARAM)TRUE);
- else
- SendMessage(hwnd,SCI_STYLESETBOLD,iStyle,(LPARAM)FALSE);
- // Italic
- if (p = StrStrI(lpszStyle,L"italic"))
- SendMessage(hwnd,SCI_STYLESETITALIC,iStyle,(LPARAM)TRUE);
- else
- SendMessage(hwnd,SCI_STYLESETITALIC,iStyle,(LPARAM)FALSE);
- // Underline
- if (p = StrStrI(lpszStyle,L"underline"))
- SendMessage(hwnd,SCI_STYLESETUNDERLINE,iStyle,(LPARAM)TRUE);
- else
- SendMessage(hwnd,SCI_STYLESETUNDERLINE,iStyle,(LPARAM)FALSE);
- // EOL Filled
- if (p = StrStrI(lpszStyle,L"eolfilled"))
- SendMessage(hwnd,SCI_STYLESETEOLFILLED,iStyle,(LPARAM)TRUE);
- else
- SendMessage(hwnd,SCI_STYLESETEOLFILLED,iStyle,(LPARAM)FALSE);
- // Case
- if (Style_StrGetCase(lpszStyle,&iValue))
- SendMessage(hwnd,SCI_STYLESETCASE,iStyle,(LPARAM)iValue);
- // Character Set
- if (Style_StrGetCharSet(lpszStyle,&iValue))
- SendMessage(hwnd,SCI_STYLESETCHARACTERSET,iStyle,(LPARAM)iValue);
- }
- //=============================================================================
- //
- // Style_SetFontQuality()
- //
- void Style_SetFontQuality(HWND hwnd,LPCWSTR lpszStyle) {
- WPARAM wQuality = SC_EFF_QUALITY_DEFAULT;
- WCHAR tch[32];
- if (Style_StrGetFontQuality(lpszStyle,tch,COUNTOF(tch))) {
- if (lstrcmpi(tch,L"none") == 0)
- wQuality = SC_EFF_QUALITY_NON_ANTIALIASED;
- else if (lstrcmpi(tch,L"standard") == 0)
- wQuality = SC_EFF_QUALITY_ANTIALIASED;
- else if (lstrcmpi(tch,L"cleartype") == 0)
- wQuality = SC_EFF_QUALITY_LCD_OPTIMIZED;
- else
- wQuality = SC_EFF_QUALITY_DEFAULT;
- }
- else {
- WCHAR tch[32];
- if (Style_StrGetFont(lpszStyle,tch,COUNTOF(tch))) {
- if (lstrcmpi(tch,L"Calibri") == 0 ||
- lstrcmpi(tch,L"Cambria") == 0 ||
- lstrcmpi(tch,L"Candara") == 0 ||
- lstrcmpi(tch,L"Consolas") == 0 ||
- lstrcmpi(tch,L"Constantia") == 0 ||
- lstrcmpi(tch,L"Corbel") == 0 ||
- lstrcmpi(tch,L"Segoe UI") == 0)
- wQuality = SC_EFF_QUALITY_LCD_OPTIMIZED;
- }
- else
- wQuality = SC_EFF_QUALITY_DEFAULT;
- }
- SendMessage(hwnd,SCI_SETFONTQUALITY,wQuality,0);
- }
- //=============================================================================
- //
- // Style_GetCurrentLexerName()
- //
- void Style_GetCurrentLexerName(LPWSTR lpszName,int cchName)
- {
- if (!GetString(pLexCurrent->rid,lpszName,cchName))
- lstrcpyn(lpszName,pLexCurrent->pszName,cchName);
- }
- //=============================================================================
- //
- // Style_GetLexerIconId()
- //
- int Style_GetLexerIconId(PEDITLEXER plex)
- {
- WCHAR *p;
- WCHAR *pszExtensions;
- WCHAR *pszFile;
- SHFILEINFO shfi;
- if (lstrlen(plex->szExtensions))
- pszExtensions = plex->szExtensions;
- else
- pszExtensions = plex->pszDefExt;
- pszFile = GlobalAlloc(GPTR,sizeof(WCHAR)*(lstrlen(pszExtensions) + lstrlen(L"*.txt") + 16));
- lstrcpy(pszFile,L"*.");
- lstrcat(pszFile,pszExtensions);
- if (p = StrChr(pszFile,L';'))
- *p = L' ';
- // check for ; at beginning
- if (lstrlen(pszFile) < 3)
- lstrcat(pszFile,L"txt");
- SHGetFileInfo(pszFile,FILE_ATTRIBUTE_NORMAL,&shfi,sizeof(SHFILEINFO),
- SHGFI_SMALLICON | SHGFI_SYSICONINDEX | SHGFI_USEFILEATTRIBUTES);
- GlobalFree(pszFile);
- return (shfi.iIcon);
- }
- //=============================================================================
- //
- // Style_AddLexerToTreeView()
- //
- void Style_AddLexerToTreeView(HWND hwnd,PEDITLEXER plex)
- {
- int i = 0;
- WCHAR tch[128];
- HTREEITEM hTreeNode;
- TVINSERTSTRUCT tvis;
- ZeroMemory(&tvis,sizeof(TVINSERTSTRUCT));
- tvis.hInsertAfter = TVI_LAST;
- tvis.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
- if (GetString(plex->rid,tch,COUNTOF(tch)))
- tvis.item.pszText = tch;
- else
- tvis.item.pszText = plex->pszName;
- tvis.item.iImage = Style_GetLexerIconId(plex);
- tvis.item.iSelectedImage = tvis.item.iImage;
- tvis.item.lParam = (LPARAM)plex;
- hTreeNode = (HTREEITEM)TreeView_InsertItem(hwnd,&tvis);
- tvis.hParent = hTreeNode;
- tvis.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
- //tvis.item.iImage = -1;
- //tvis.item.iSelectedImage = -1;
- while (plex->Styles[i].iStyle != -1) {
- if (GetString(plex->Styles[i].rid,tch,COUNTOF(tch)))
- tvis.item.pszText = tch;
- else
- tvis.item.pszText = plex->Styles[i].pszName;
- tvis.item.lParam = (LPARAM)(&plex->Styles[i]);
- TreeView_InsertItem(hwnd,&tvis);
- i++;
- }
- }
- //=============================================================================
- //
- // Style_AddLexerToListView()
- //
- void Style_AddLexerToListView(HWND hwnd,PEDITLEXER plex)
- {
- WCHAR tch[128];
- LVITEM lvi;
- ZeroMemory(&lvi,sizeof(LVITEM));
- lvi.mask = LVIF_IMAGE | LVIF_PARAM | LVIF_TEXT;
- lvi.iItem = ListView_GetItemCount(hwnd);
- if (GetString(plex->rid,tch,COUNTOF(tch)))
- lvi.pszText = tch;
- else
- lvi.pszText = plex->pszName;
- lvi.iImage = Style_GetLexerIconId(plex);
- lvi.lParam = (LPARAM)plex;
- ListView_InsertItem(hwnd,&lvi);
- }
- //=============================================================================
- //
- // Style_ConfigDlgProc()
- //
- BOOL CALLBACK Style_ConfigDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam)
- {
- static HWND hwndTV;
- static BOOL fDragging;
- static PEDITLEXER pCurrentLexer;
- static PEDITSTYLE pCurrentStyle;
- static HFONT hFontTitle;
- static HBRUSH hbrFore;
- static HBRUSH hbrBack;
- switch(umsg)
- {
- case WM_INITDIALOG:
- {
- int i;
- SHFILEINFO shfi;
- LOGFONT lf;
- hwndTV = GetDlgItem(hwnd,IDC_STYLELIST);
- fDragging = FALSE;
- TreeView_SetImageList(hwndTV,
- (HIMAGELIST)SHGetFileInfo(L"C:\",0,&shfi,sizeof(SHFILEINFO),
- SHGFI_SMALLICON | SHGFI_SYSICONINDEX),TVSIL_NORMAL);
- // Add lexers
- for (i = 0; i < NUMLEXERS; i++)
- Style_AddLexerToTreeView(hwndTV,pLexArray[i]);
- pCurrentLexer = 0;
- pCurrentStyle = 0;
- //SetExplorerTheme(hwndTV);
- //TreeView_Expand(hwndTV,TreeView_GetRoot(hwndTV),TVE_EXPAND);
- TreeView_Select(hwndTV,TreeView_GetRoot(hwndTV),TVGN_CARET);
- SendDlgItemMessage(hwnd,IDC_STYLEEDIT,EM_LIMITTEXT,COUNTOF(lexDefault.Styles[0].szValue)-1,0);
- MakeBitmapButton(hwnd,IDC_PREVSTYLE,g_hInstance,IDB_PREV);
- MakeBitmapButton(hwnd,IDC_NEXTSTYLE,g_hInstance,IDB_NEXT);
- // Setup title font
- if (hFontTitle)
- DeleteObject(hFontTitle);
- if (NULL == (hFontTitle = (HFONT)SendDlgItemMessage(hwnd,IDC_TITLE,WM_GETFONT,0,0)))
- hFontTitle = GetStockObject(DEFAULT_GUI_FONT);
- GetObject(hFontTitle,sizeof(LOGFONT),&lf);
- lf.lfHeight += lf.lfHeight / 5;
- lf.lfWeight = FW_BOLD;
- hFontTitle = CreateFontIndirect(&lf);
- SendDlgItemMessage(hwnd,IDC_TITLE,WM_SETFONT,(WPARAM)hFontTitle,TRUE);
- CenterDlgInParent(hwnd);
- }
- return TRUE;
- case WM_DESTROY:
- DeleteBitmapButton(hwnd,IDC_STYLEFORE);
- DeleteBitmapButton(hwnd,IDC_STYLEBACK);
- DeleteBitmapButton(hwnd,IDC_PREVSTYLE);
- DeleteBitmapButton(hwnd,IDC_NEXTSTYLE);
- return FALSE;
- case WM_NOTIFY:
- if (((LPNMHDR)(lParam))->idFrom == IDC_STYLELIST)
- {
- LPNMTREEVIEW lpnmtv = (LPNMTREEVIEW)lParam;
- switch (lpnmtv->hdr.code)
- {
- case TVN_SELCHANGED:
- {
- if (pCurrentStyle)
- GetDlgItemText(hwnd,IDC_STYLEEDIT,pCurrentStyle->szValue,COUNTOF(pCurrentStyle->szValue));
- else if (pCurrentLexer) {
- if (!GetDlgItemText(hwnd,IDC_STYLEEDIT,pCurrentLexer->szExtensions,COUNTOF(pCurrentLexer->szExtensions)))
- lstrcpy(pCurrentLexer->szExtensions,pCurrentLexer->pszDefExt);
- }
- // a lexer has been selected
- if (!TreeView_GetParent(hwndTV,lpnmtv->itemNew.hItem))
- {
- WCHAR wch[128];
- GetDlgItemText(hwnd,IDC_STYLELABELS,wch,COUNTOF(wch));
- if (StrChr(wch,L'|')) *StrChr(wch,L'|') = 0;
- pCurrentStyle = 0;
- if (pCurrentLexer = (PEDITLEXER)lpnmtv->itemNew.lParam)
- {
- SetDlgItemText(hwnd,IDC_STYLELABEL,wch);
- EnableWindow(GetDlgItem(hwnd,IDC_STYLEEDIT),TRUE);
- EnableWindow(GetDlgItem(hwnd,IDC_STYLEFONT),FALSE);
- EnableWindow(GetDlgItem(hwnd,IDC_STYLEFORE),FALSE);
- EnableWindow(GetDlgItem(hwnd,IDC_STYLEBACK),FALSE);
- EnableWindow(GetDlgItem(hwnd,IDC_STYLEDEFAULT),TRUE);
- //EnableWindow(GetDlgItem(hwnd,IDC_STYLEBOLD),FALSE);
- //EnableWindow(GetDlgItem(hwnd,IDC_STYLEITALIC),FALSE);
- //EnableWindow(GetDlgItem(hwnd,IDC_STYLEUNDERLINE),FALSE);
- //EnableWindow(GetDlgItem(hwnd,IDC_STYLEEOLFILLED),FALSE);
- //CheckDlgButton(hwnd,IDC_STYLEBOLD,BST_UNCHECKED);
- //CheckDlgButton(hwnd,IDC_STYLEITALIC,BST_UNCHECKED);
- //CheckDlgButton(hwnd,IDC_STYLEUNDERLINE,BST_UNCHECKED);
- //CheckDlgButton(hwnd,IDC_STYLEEOLFILLED,BST_UNCHECKED);
- SetDlgItemText(hwnd,IDC_STYLEEDIT,pCurrentLexer->szExtensions);
- }
- else
- {
- SetDlgItemText(hwnd,IDC_STYLELABEL,L"");
- EnableWindow(GetDlgItem(hwnd,IDC_STYLEEDIT),FALSE);
- EnableWindow(GetDlgItem(hwnd,IDC_STYLEFONT),FALSE);
- EnableWindow(GetDlgItem(hwnd,IDC_STYLEFORE),FALSE);
- EnableWindow(GetDlgItem(hwnd,IDC_STYLEBACK),FALSE);
- EnableWindow(GetDlgItem(hwnd,IDC_STYLEDEFAULT),FALSE);
- //EnableWindow(GetDlgItem(hwnd,IDC_STYLEBOLD),FALSE);
- //EnableWindow(GetDlgItem(hwnd,IDC_STYLEITALIC),FALSE);
- //EnableWindow(GetDlgItem(hwnd,IDC_STYLEUNDERLINE),FALSE);
- //EnableWindow(GetDlgItem(hwnd,IDC_STYLEEOLFILLED),FALSE);
- //CheckDlgButton(hwnd,IDC_STYLEBOLD,BST_UNCHECKED);
- //CheckDlgButton(hwnd,IDC_STYLEITALIC,BST_UNCHECKED);
- //CheckDlgButton(hwnd,IDC_STYLEUNDERLINE,BST_UNCHECKED);
- //CheckDlgButton(hwnd,IDC_STYLEEOLFILLED,BST_UNCHECKED);
- SetDlgItemText(hwnd,IDC_STYLEEDIT,L"");
- }
- }
- // a style has been selected
- else
- {
- WCHAR wch[128];
- GetDlgItemText(hwnd,IDC_STYLELABELS,wch,COUNTOF(wch));
- if (StrChr(wch,L'|')) *StrChr(wch,L'|') = 0;
- pCurrentLexer = 0;
- if (pCurrentStyle = (PEDITSTYLE)lpnmtv->itemNew.lParam)
- {
- SetDlgItemText(hwnd,IDC_STYLELABEL,StrEnd(wch)+1);
- EnableWindow(GetDlgItem(hwnd,IDC_STYLEEDIT),TRUE);
- EnableWindow(GetDlgItem(hwnd,IDC_STYLEFONT),TRUE);
- EnableWindow(GetDlgItem(hwnd,IDC_STYLEFORE),TRUE);
- EnableWindow(GetDlgItem(hwnd,IDC_STYLEBACK),TRUE);
- EnableWindow(GetDlgItem(hwnd,IDC_STYLEDEFAULT),TRUE);
- //EnableWindow(GetDlgItem(hwnd,IDC_STYLEBOLD),TRUE);
- //EnableWindow(GetDlgItem(hwnd,IDC_STYLEITALIC),TRUE);
- //EnableWindow(GetDlgItem(hwnd,IDC_STYLEUNDERLINE),TRUE);
- //EnableWindow(GetDlgItem(hwnd,IDC_STYLEEOLFILLED),TRUE);
- //CheckDlgButton(hwnd,IDC_STYLEBOLD,(Style_StrGetAttribute(pCurrentStyle->szValue,L"bold") ? BST_CHECKED : BST_UNCHECKED));
- //CheckDlgButton(hwnd,IDC_STYLEITALIC,(Style_StrGetAttribute(pCurrentStyle->szValue,L"italic") ? BST_CHECKED : BST_UNCHECKED));
- //CheckDlgButton(hwnd,IDC_STYLEUNDERLINE,(Style_StrGetAttribute(pCurrentStyle->szValue,L"underline") ? BST_CHECKED : BST_UNCHECKED));
- //CheckDlgButton(hwnd,IDC_STYLEEOLFILLED,(Style_StrGetAttribute(pCurrentStyle->szValue,L"eolfilled") ? BST_CHECKED : BST_UNCHECKED));
- SetDlgItemText(hwnd,IDC_STYLEEDIT,pCurrentStyle->szValue);
- }
- else
- {
- SetDlgItemText(hwnd,IDC_STYLELABEL,L"");
- EnableWindow(GetDlgItem(hwnd,IDC_STYLEEDIT),FALSE);
- EnableWindow(GetDlgItem(hwnd,IDC_STYLEFONT),FALSE);
- EnableWindow(GetDlgItem(hwnd,IDC_STYLEFORE),FALSE);
- EnableWindow(GetDlgItem(hwnd,IDC_STYLEBACK),FALSE);
- EnableWindow(GetDlgItem(hwnd,IDC_STYLEDEFAULT),FALSE);
- //EnableWindow(GetDlgItem(hwnd,IDC_STYLEBOLD),FALSE);
- //EnableWindow(GetDlgItem(hwnd,IDC_STYLEITALIC),FALSE);
- //EnableWindow(GetDlgItem(hwnd,IDC_STYLEUNDERLINE),FALSE);
- //EnableWindow(GetDlgItem(hwnd,IDC_STYLEEOLFILLED),FALSE);
- //CheckDlgButton(hwnd,IDC_STYLEBOLD,BST_UNCHECKED);
- //CheckDlgButton(hwnd,IDC_STYLEITALIC,BST_UNCHECKED);
- //CheckDlgButton(hwnd,IDC_STYLEUNDERLINE,BST_UNCHECKED);
- //CheckDlgButton(hwnd,IDC_STYLEEOLFILLED,BST_UNCHECKED);
- SetDlgItemText(hwnd,IDC_STYLEEDIT,L"");
- }
- }
- }
- break;
- case TVN_BEGINDRAG:
- {
- //HIMAGELIST himl;
- //if (pCurrentStyle)
- // GetDlgItemText(hwnd,IDC_STYLEEDIT,pCurrentStyle->szValue,COUNTOF(pCurrentStyle->szValue));
- TreeView_Select(hwndTV,lpnmtv->itemNew.hItem,TVGN_CARET);
- //himl = TreeView_CreateDragImage(hwndTV,lpnmtv->itemNew.hItem);
- //ImageList_BeginDrag(himl,0,0,0);
- //ImageList_DragEnter(hwndTV,lpnmtv->ptDrag.x,lpnmtv->ptDrag.y);
- if (pCurrentStyle)
- DestroyCursor(SetCursor(LoadCursor(g_hInstance,MAKEINTRESOURCE(IDC_COPY))));
- else
- DestroyCursor(SetCursor(LoadCursor(NULL,IDC_NO)));
- SetCapture(hwnd);
- fDragging = TRUE;
- }
- }
- }
- break;
- case WM_MOUSEMOVE:
- {
- HTREEITEM htiTarget;
- TVHITTESTINFO tvht;
- if (fDragging && pCurrentStyle)
- {
- LONG xCur = LOWORD(lParam);
- LONG yCur = HIWORD(lParam);
- //ImageList_DragMove(xCur,yCur);
- //ImageList_DragShowNolock(FALSE);
- tvht.pt.x = xCur;
- tvht.pt.y = yCur;
- //ClientToScreen(hwnd,&tvht.pt);
- //ScreenToClient(hwndTV,&tvht.pt);
- MapWindowPoints(hwnd,hwndTV,&tvht.pt,1);
- if ((htiTarget = TreeView_HitTest(hwndTV,&tvht)) != NULL &&
- TreeView_GetParent(hwndTV,htiTarget) != NULL)
- {
- TreeView_SelectDropTarget(hwndTV,htiTarget);
- //TreeView_Expand(hwndTV,htiTarget,TVE_EXPAND);
- TreeView_EnsureVisible(hwndTV,htiTarget);
- }
- else
- TreeView_SelectDropTarget(hwndTV,NULL);
- //ImageList_DragShowNolock(TRUE);
- }
- }
- break;
- case WM_LBUTTONUP:
- {
- if (fDragging)
- {
- HTREEITEM htiTarget;
- //ImageList_EndDrag();
- if (htiTarget = TreeView_GetDropHilight(hwndTV))
- {
- WCHAR tchCopy[256];
- TreeView_SelectDropTarget(hwndTV,NULL);
- GetDlgItemText(hwnd,IDC_STYLEEDIT,tchCopy,COUNTOF(tchCopy));
- TreeView_Select(hwndTV,htiTarget,TVGN_CARET);
- // after select, this is new current item
- if (pCurrentStyle)
- {
- lstrcpy(pCurrentStyle->szValue,tchCopy);
- SetDlgItemText(hwnd,IDC_STYLEEDIT,tchCopy);
- //CheckDlgButton(hwnd,IDC_STYLEBOLD,(Style_StrGetAttribute(tchCopy,L"bold") ? BST_CHECKED : BST_UNCHECKED));
- //CheckDlgButton(hwnd,IDC_STYLEITALIC,(Style_StrGetAttribute(tchCopy,L"italic") ? BST_CHECKED : BST_UNCHECKED));
- //CheckDlgButton(hwnd,IDC_STYLEUNDERLINE,(Style_StrGetAttribute(tchCopy,L"underline") ? BST_CHECKED : BST_UNCHECKED));
- //CheckDlgButton(hwnd,IDC_STYLEEOLFILLED,(Style_StrGetAttribute(tchCopy,L"eolfilled") ? BST_CHECKED : BST_UNCHECKED));
- }
- }
- ReleaseCapture();
- DestroyCursor(SetCursor(LoadCursor(NULL,IDC_ARROW)));
- fDragging = FALSE;
- }
- }
- break;
- case WM_CANCELMODE:
- {
- if (fDragging)
- {
- //ImageList_EndDrag();
- TreeView_SelectDropTarget(hwndTV,NULL);
- ReleaseCapture();
- DestroyCursor(SetCursor(LoadCursor(NULL,IDC_ARROW)));
- fDragging = FALSE;
- }
- }
- break;
- case WM_COMMAND:
- switch(LOWORD(wParam))
- {
- case IDC_PREVSTYLE:
- if (TreeView_GetSelection(hwndTV))
- TreeView_Select(hwndTV,TreeView_GetPrevVisible(hwndTV,
- TreeView_GetSelection(hwndTV)),TVGN_CARET);
- PostMessage(hwnd,WM_NEXTDLGCTL,(WPARAM)(GetDlgItem(hwnd,IDC_STYLEEDIT)),1);
- break;
- case IDC_NEXTSTYLE:
- if (TreeView_GetSelection(hwndTV))
- TreeView_Select(hwndTV,TreeView_GetNextVisible(hwndTV,
- TreeView_GetSelection(hwndTV)),TVGN_CARET);
- PostMessage(hwnd,WM_NEXTDLGCTL,(WPARAM)(GetDlgItem(hwnd,IDC_STYLEEDIT)),1);
- break;
- case IDC_STYLEFONT:
- if (pCurrentStyle)
- {
- WCHAR tch[256];
- GetDlgItemText(hwnd,IDC_STYLEEDIT,tch,COUNTOF(tch));
- if (Style_SelectFont(hwnd,tch,COUNTOF(tch),
- lstrcmpi(pCurrentStyle->pszName,L"Default Style") == 0 ||
- lstrcmpi(pCurrentStyle->pszName,L"2nd Default Style") == 0)) {
- SetDlgItemText(hwnd,IDC_STYLEEDIT,tch);
- //CheckDlgButton(hwnd,IDC_STYLEBOLD,(Style_StrGetAttribute(tch,L"bold") ? BST_CHECKED : BST_UNCHECKED));
- //CheckDlgButton(hwnd,IDC_STYLEITALIC,(Style_StrGetAttribute(tch,L"italic") ? BST_CHECKED : BST_UNCHECKED));
- //CheckDlgButton(hwnd,IDC_STYLEUNDERLINE,(Style_StrGetAttribute(tch,L"underline") ? BST_CHECKED : BST_UNCHECKED));
- //CheckDlgButton(hwnd,IDC_STYLEEOLFILLED,(Style_StrGetAttribute(tch,L"eolfilled") ? BST_CHECKED : BST_UNCHECKED));
- }
- }
- PostMessage(hwnd,WM_NEXTDLGCTL,(WPARAM)(GetDlgItem(hwnd,IDC_STYLEEDIT)),1);
- break;
- case IDC_STYLEFORE:
- if (pCurrentStyle)
- {
- WCHAR tch[256];
- GetDlgItemText(hwnd,IDC_STYLEEDIT,tch,COUNTOF(tch));
- if (Style_SelectColor(hwnd,TRUE,tch,COUNTOF(tch))) {
- SetDlgItemText(hwnd,IDC_STYLEEDIT,tch);
- //CheckDlgButton(hwnd,IDC_STYLEBOLD,(Style_StrGetAttribute(tch,L"bold") ? BST_CHECKED : BST_UNCHECKED));
- //CheckDlgButton(hwnd,IDC_STYLEITALIC,(Style_StrGetAttribute(tch,L"italic") ? BST_CHECKED : BST_UNCHECKED));
- //CheckDlgButton(hwnd,IDC_STYLEUNDERLINE,(Style_StrGetAttribute(tch,L"underline") ? BST_CHECKED : BST_UNCHECKED));
- //CheckDlgButton(hwnd,IDC_STYLEEOLFILLED,(Style_StrGetAttribute(tch,L"eolfilled") ? BST_CHECKED : BST_UNCHECKED));
- }
- }
- PostMessage(hwnd,WM_NEXTDLGCTL,(WPARAM)(GetDlgItem(hwnd,IDC_STYLEEDIT)),1);
- break;
- case IDC_STYLEBACK:
- if (pCurrentStyle)
- {
- WCHAR tch[256];
- GetDlgItemText(hwnd,IDC_STYLEEDIT,tch,COUNTOF(tch));
- if (Style_SelectColor(hwnd,FALSE,tch,COUNTOF(tch))) {
- SetDlgItemText(hwnd,IDC_STYLEEDIT,tch);
- //CheckDlgButton(hwnd,IDC_STYLEBOLD,(Style_StrGetAttribute(tch,L"bold") ? BST_CHECKED : BST_UNCHECKED));
- //CheckDlgButton(hwnd,IDC_STYLEITALIC,(Style_StrGetAttribute(tch,L"italic") ? BST_CHECKED : BST_UNCHECKED));
- //CheckDlgButton(hwnd,IDC_STYLEUNDERLINE,(Style_StrGetAttribute(tch,L"underline") ? BST_CHECKED : BST_UNCHECKED));
- //CheckDlgButton(hwnd,IDC_STYLEEOLFILLED,(Style_StrGetAttribute(tch,L"eolfilled") ? BST_CHECKED : BST_UNCHECKED));
- }
- }
- PostMessage(hwnd,WM_NEXTDLGCTL,(WPARAM)(GetDlgItem(hwnd,IDC_STYLEEDIT)),1);
- break;
- case IDC_STYLEDEFAULT:
- if (pCurrentStyle)
- {
- lstrcpy(pCurrentStyle->szValue,pCurrentStyle->pszDefault);
- SetDlgItemText(hwnd,IDC_STYLEEDIT,pCurrentStyle->szValue);
- //CheckDlgButton(hwnd,IDC_STYLEBOLD,(Style_StrGetAttribute(pCurrentStyle->szValue,L"bold") ? BST_CHECKED : BST_UNCHECKED));
- //CheckDlgButton(hwnd,IDC_STYLEITALIC,(Style_StrGetAttribute(pCurrentStyle->szValue,L"italic") ? BST_CHECKED : BST_UNCHECKED));
- //CheckDlgButton(hwnd,IDC_STYLEUNDERLINE,(Style_StrGetAttribute(pCurrentStyle->szValue,L"underline") ? BST_CHECKED : BST_UNCHECKED));
- //CheckDlgButton(hwnd,IDC_STYLEEOLFILLED,(Style_StrGetAttribute(pCurrentStyle->szValue,L"eolfilled") ? BST_CHECKED : BST_UNCHECKED));
- }
- else if (pCurrentLexer) {
- lstrcpy(pCurrentLexer->szExtensions,pCurrentLexer->pszDefExt);
- SetDlgItemText(hwnd,IDC_STYLEEDIT,pCurrentLexer->szExtensions);
- }
- PostMessage(hwnd,WM_NEXTDLGCTL,(WPARAM)(GetDlgItem(hwnd,IDC_STYLEEDIT)),1);
- break;
- //case IDC_STYLEBOLD:
- // if (pCurrentStyle)
- // {
- // WCHAR tch[256];
- // GetDlgItemText(hwnd,IDC_STYLEEDIT,tch,COUNTOF(tch));
- // Style_StrSetAttribute(tch,COUNTOF(tch),L"bold",IsDlgButtonChecked(hwnd,IDC_STYLEBOLD));
- // SetDlgItemText(hwnd,IDC_STYLEEDIT,tch);
- // }
- // break;
- //case IDC_STYLEITALIC:
- // if (pCurrentStyle)
- // {
- // WCHAR tch[256];
- // GetDlgItemText(hwnd,IDC_STYLEEDIT,tch,COUNTOF(tch));
- // Style_StrSetAttribute(tch,COUNTOF(tch),L"italic",IsDlgButtonChecked(hwnd,IDC_STYLEITALIC));
- // SetDlgItemText(hwnd,IDC_STYLEEDIT,tch);
- // }
- // break;
- //case IDC_STYLEUNDERLINE:
- // if (pCurrentStyle)
- // {
- // WCHAR tch[256];
- // GetDlgItemText(hwnd,IDC_STYLEEDIT,tch,COUNTOF(tch));
- // Style_StrSetAttribute(tch,COUNTOF(tch),L"underline",IsDlgButtonChecked(hwnd,IDC_STYLEUNDERLINE));
- // SetDlgItemText(hwnd,IDC_STYLEEDIT,tch);
- // }
- // break;
- //case IDC_STYLEEOLFILLED:
- // if (pCurrentStyle)
- // {
- // WCHAR tch[256];
- // GetDlgItemText(hwnd,IDC_STYLEEDIT,tch,COUNTOF(tch));
- // Style_StrSetAttribute(tch,COUNTOF(tch),L"eolfilled",IsDlgButtonChecked(hwnd,IDC_STYLEEOLFILLED));
- // SetDlgItemText(hwnd,IDC_STYLEEDIT,tch);
- // }
- // break;
- case IDC_STYLEEDIT:
- {
- if (HIWORD(wParam) == EN_CHANGE) {
- int cr;
- WCHAR tch[256];
- GetDlgItemText(hwnd,IDC_STYLEEDIT,tch,COUNTOF(tch));
- cr = -1;
- Style_StrGetColor(TRUE,tch,&cr);
- MakeColorPickButton(hwnd,IDC_STYLEFORE,g_hInstance,cr);
- cr = -1;
- Style_StrGetColor(FALSE,tch,&cr);
- MakeColorPickButton(hwnd,IDC_STYLEBACK,g_hInstance,cr);
- }
- }
- break;
- case IDC_IMPORT:
- {
- HWND hwndTV = GetDlgItem(hwnd,IDC_STYLELIST);
- if (pCurrentStyle)
- GetDlgItemText(hwnd,IDC_STYLEEDIT,pCurrentStyle->szValue,COUNTOF(pCurrentStyle->szValue));
- else if (pCurrentLexer) {
- if (!GetDlgItemText(hwnd,IDC_STYLEEDIT,pCurrentLexer->szExtensions,COUNTOF(pCurrentLexer->szExtensions)))
- lstrcpy(pCurrentLexer->szExtensions,pCurrentLexer->pszDefExt);
- }
- if (Style_Import(hwnd)) {
- if (pCurrentStyle)
- SetDlgItemText(hwnd,IDC_STYLEEDIT,pCurrentStyle->szValue);
- else if (pCurrentLexer)
- SetDlgItemText(hwnd,IDC_STYLEEDIT,pCurrentLexer->szExtensions);
- TreeView_Select(hwndTV,TreeView_GetRoot(hwndTV),TVGN_CARET);
- MsgBox(0,IDS_IMPORT_OK);
- }
- }
- break;
- case IDC_EXPORT:
- {
- if (pCurrentStyle)
- GetDlgItemText(hwnd,IDC_STYLEEDIT,pCurrentStyle->szValue,COUNTOF(pCurrentStyle->szValue));
- else if (pCurrentLexer) {
- if (!GetDlgItemText(hwnd,IDC_STYLEEDIT,pCurrentLexer->szExtensions,COUNTOF(pCurrentLexer->szExtensions)))
- lstrcpy(pCurrentLexer->szExtensions,pCurrentLexer->pszDefExt);
- }
- if (Style_Export(hwnd))
- MsgBox(0,IDS_EXPORT_OK);
- }
- break;
- case IDC_PREVIEW:
- {
- // Hack from outside
- extern HWND hwndEdit;
- extern void UpdateLineNumerWidth();
- if (pCurrentStyle)
- GetDlgItemText(hwnd,IDC_STYLEEDIT,pCurrentStyle->szValue,COUNTOF(pCurrentStyle->szValue));
- else if (pCurrentLexer) {
- if (!GetDlgItemText(hwnd,IDC_STYLEEDIT,pCurrentLexer->szExtensions,COUNTOF(pCurrentLexer->szExtensions)))
- lstrcpy(pCurrentLexer->szExtensions,pCurrentLexer->pszDefExt);
- }
- Style_SetLexer(hwndEdit,pLexCurrent);
- UpdateLineNumberWidth();
- }
- break;
- case IDOK:
- if (pCurrentStyle)
- GetDlgItemText(hwnd,IDC_STYLEEDIT,pCurrentStyle->szValue,COUNTOF(pCurrentStyle->szValue));
- else if (pCurrentLexer) {
- if (!GetDlgItemText(hwnd,IDC_STYLEEDIT,pCurrentLexer->szExtensions,COUNTOF(pCurrentLexer->szExtensions)))
- lstrcpy(pCurrentLexer->szExtensions,pCurrentLexer->pszDefExt);
- }
- EndDialog(hwnd,IDOK);
- break;
- case IDCANCEL:
- if (fDragging)
- SendMessage(hwnd,WM_CANCELMODE,0,0);
- else
- EndDialog(hwnd,IDCANCEL);
- break;
- }
- return TRUE;
- }
- return FALSE;
- }
- //=============================================================================
- //
- // Style_ConfigDlg()
- //
- void Style_ConfigDlg(HWND hwnd)
- {
- WCHAR *StyleBackup[1024];
- int c,cItems,i,iLexer;
- // Backup Styles
- c = 0;
- for (iLexer = 0; iLexer < NUMLEXERS; iLexer++) {
- StyleBackup[c++] = StrDup(pLexArray[iLexer]->szExtensions);
- i = 0;
- while (pLexArray[iLexer]->Styles[i].iStyle != -1) {
- StyleBackup[c++] = StrDup(pLexArray[iLexer]->Styles[i].szValue);
- i++;
- }
- }
- cItems = c;
- if (IDCANCEL == ThemedDialogBoxParam(g_hInstance,
- MAKEINTRESOURCE(IDD_STYLECONFIG),
- GetParent(hwnd),Style_ConfigDlgProc,
- (LPARAM)&StyleBackup))
- {
- // Restore Styles
- c = 0;
- for (iLexer = 0; iLexer < NUMLEXERS; iLexer++) {
- lstrcpy(pLexArray[iLexer]->szExtensions,StyleBackup[c++]);
- i = 0;
- while (pLexArray[iLexer]->Styles[i].iStyle != -1) {
- lstrcpy(pLexArray[iLexer]->Styles[i].szValue,StyleBackup[c++]);
- i++;
- }
- }
- }
- else {
- fStylesModified = TRUE;
- if (lstrlen(szIniFile) == 0 && !fWarnedNoIniFile) {
- MsgBox(MBINFO,IDS_SETTINGSNOTSAVED);
- fWarnedNoIniFile = TRUE;
- }
- }
- for (c = 0; c < cItems; c++)
- LocalFree(StyleBackup[c]);
- // Apply new (or previous) Styles
- Style_SetLexer(hwnd,pLexCurrent);
- }
- //=============================================================================
- //
- // Style_SelectLexerDlgProc()
- //
- BOOL CALLBACK Style_SelectLexerDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam)
- {
- static int cxClient;
- static int cyClient;
- static int mmiPtMaxY;
- static int mmiPtMinX;
- static HWND hwndLV;
- static int iInternalDefault;
- switch(umsg)
- {
- case WM_INITDIALOG:
- {
- int i;
- int lvItems;
- LVITEM lvi;
- SHFILEINFO shfi;
- LVCOLUMN lvc = { LVCF_FMT|LVCF_TEXT, LVCFMT_LEFT, 0, L"", -1, 0, 0, 0 };
- RECT rc;
- WCHAR tch[MAX_PATH];
- int cGrip;
- GetClientRect(hwnd,&rc);
- cxClient = rc.right - rc.left;
- cyClient = rc.bottom - rc.top;
- AdjustWindowRectEx(&rc,GetWindowLongPtr(hwnd,GWL_STYLE)|WS_THICKFRAME,FALSE,0);
- mmiPtMinX = rc.right-rc.left;
- mmiPtMaxY = rc.bottom-rc.top;
- if (cxStyleSelectDlg < (rc.right-rc.left))
- cxStyleSelectDlg = rc.right-rc.left;
- if (cyStyleSelectDlg < (rc.bottom-rc.top))
- cyStyleSelectDlg = rc.bottom-rc.top;
- SetWindowPos(hwnd,NULL,rc.left,rc.top,cxStyleSelectDlg,cyStyleSelectDlg,SWP_NOZORDER);
- SetWindowLongPtr(hwnd,GWL_STYLE,GetWindowLongPtr(hwnd,GWL_STYLE)|WS_THICKFRAME);
- SetWindowPos(hwnd,NULL,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_FRAMECHANGED);
- GetMenuString(GetSystemMenu(GetParent(hwnd),FALSE),SC_SIZE,tch,COUNTOF(tch),MF_BYCOMMAND);
- InsertMenu(GetSystemMenu(hwnd,FALSE),SC_CLOSE,MF_BYCOMMAND|MF_STRING|MF_ENABLED,SC_SIZE,tch);
- InsertMenu(GetSystemMenu(hwnd,FALSE),SC_CLOSE,MF_BYCOMMAND|MF_SEPARATOR,0,NULL);
- SetWindowLongPtr(GetDlgItem(hwnd,IDC_RESIZEGRIP3),GWL_STYLE,
- GetWindowLongPtr(GetDlgItem(hwnd,IDC_RESIZEGRIP3),GWL_STYLE)|SBS_SIZEGRIP|WS_CLIPSIBLINGS);
- cGrip = GetSystemMetrics(SM_CXHTHUMB);
- SetWindowPos(GetDlgItem(hwnd,IDC_RESIZEGRIP3),NULL,cxClient-cGrip,
- cyClient-cGrip,cGrip,cGrip,SWP_NOZORDER);
- hwndLV = GetDlgItem(hwnd,IDC_STYLELIST);
- ListView_SetImageList(hwndLV,
- (HIMAGELIST)SHGetFileInfo(L"C:\",0,&shfi,sizeof(SHFILEINFO),SHGFI_SMALLICON | SHGFI_SYSICONINDEX),
- LVSIL_SMALL);
- ListView_SetImageList(hwndLV,
- (HIMAGELIST)SHGetFileInfo(L"C:\",0,&shfi,sizeof(SHFILEINFO),SHGFI_LARGEICON | SHGFI_SYSICONINDEX),
- LVSIL_NORMAL);
- //SetExplorerTheme(hwndLV);
- ListView_SetExtendedListViewStyle(hwndLV,/*LVS_EX_FULLROWSELECT|*/LVS_EX_DOUBLEBUFFER|LVS_EX_LABELTIP);
- ListView_InsertColumn(hwndLV,0,&lvc);
- // Add lexers
- for (i = 0; i < NUMLEXERS; i++)
- Style_AddLexerToListView(hwndLV,pLexArray[i]);
- ListView_SetColumnWidth(hwndLV,0,LVSCW_AUTOSIZE_USEHEADER);
- // Select current lexer
- lvItems = ListView_GetItemCount(hwndLV);
- lvi.mask = LVIF_PARAM;
- for (i = 0; i < lvItems; i++) {
- lvi.iItem = i;
- ListView_GetItem(hwndLV,&lvi);;
- if (lstrcmp(((PEDITLEXER)lvi.lParam)->pszName,pLexCurrent->pszName) == 0) {
- ListView_SetItemState(hwndLV,i,LVIS_FOCUSED|LVIS_SELECTED,LVIS_FOCUSED|LVIS_SELECTED);
- ListView_EnsureVisible(hwndLV,i,FALSE);
- if (iDefaultLexer == i) {
- CheckDlgButton(hwnd,IDC_DEFAULTSCHEME,BST_CHECKED);
- }
- }
- }
- iInternalDefault = iDefaultLexer;
- if (bAutoSelect)
- CheckDlgButton(hwnd,IDC_AUTOSELECT,BST_CHECKED);
- CenterDlgInParent(hwnd);
- }
- return TRUE;
- case WM_DESTROY:
- {
- RECT rc;
- GetWindowRect(hwnd,&rc);
- cxStyleSelectDlg = rc.right-rc.left;
- cyStyleSelectDlg = rc.bottom-rc.top;
- }
- return FALSE;
- case WM_SIZE:
- {
- RECT rc;
- int dxClient = LOWORD(lParam) - cxClient;
- int dyClient = HIWORD(lParam) - cyClient;
- cxClient = LOWORD(lParam);
- cyClient = HIWORD(lParam);
- GetWindowRect(GetDlgItem(hwnd,IDC_RESIZEGRIP3),&rc);
- MapWindowPoints(NULL,hwnd,(LPPOINT)&rc,2);
- SetWindowPos(GetDlgItem(hwnd,IDC_RESIZEGRIP3),NULL,rc.left+dxClient,rc.top+dyClient,0,0,SWP_NOZORDER|SWP_NOSIZE);
- InvalidateRect(GetDlgItem(hwnd,IDC_RESIZEGRIP3),NULL,TRUE);
- GetWindowRect(GetDlgItem(hwnd,IDOK),&rc);
- MapWindowPoints(NULL,hwnd,(LPPOINT)&rc,2);
- SetWindowPos(GetDlgItem(hwnd,IDOK),NULL,rc.left+dxClient,rc.top+dyClient,0,0,SWP_NOZORDER|SWP_NOSIZE);
- InvalidateRect(GetDlgItem(hwnd,IDOK),NULL,TRUE);
- GetWindowRect(GetDlgItem(hwnd,IDCANCEL),&rc);
- MapWindowPoints(NULL,hwnd,(LPPOINT)&rc,2);
- SetWindowPos(GetDlgItem(hwnd,IDCANCEL),NULL,rc.left+dxClient,rc.top+dyClient,0,0,SWP_NOZORDER|SWP_NOSIZE);
- InvalidateRect(GetDlgItem(hwnd,IDCANCEL),NULL,TRUE);
- GetWindowRect(GetDlgItem(hwnd,IDC_STYLELIST),&rc);
- MapWindowPoints(NULL,hwnd,(LPPOINT)&rc,2);
- SetWindowPos(GetDlgItem(hwnd,IDC_STYLELIST),NULL,0,0,rc.right-rc.left+dxClient,rc.bottom-rc.top+dyClient,SWP_NOZORDER|SWP_NOMOVE);
- ListView_SetColumnWidth(GetDlgItem(hwnd,IDC_STYLELIST),0,LVSCW_AUTOSIZE_USEHEADER);
- InvalidateRect(GetDlgItem(hwnd,IDC_STYLELIST),NULL,TRUE);
- GetWindowRect(GetDlgItem(hwnd,IDC_AUTOSELECT),&rc);
- MapWindowPoints(NULL,hwnd,(LPPOINT)&rc,2);
- SetWindowPos(GetDlgItem(hwnd,IDC_AUTOSELECT),NULL,rc.left,rc.top+dyClient,0,0,SWP_NOZORDER|SWP_NOSIZE);
- InvalidateRect(GetDlgItem(hwnd,IDC_AUTOSELECT),NULL,TRUE);
- GetWindowRect(GetDlgItem(hwnd,IDC_DEFAULTSCHEME),&rc);
- MapWindowPoints(NULL,hwnd,(LPPOINT)&rc,2);
- SetWindowPos(GetDlgItem(hwnd,IDC_DEFAULTSCHEME),NULL,rc.left,rc.top+dyClient,0,0,SWP_NOZORDER|SWP_NOSIZE);
- InvalidateRect(GetDlgItem(hwnd,IDC_DEFAULTSCHEME),NULL,TRUE);
- }
- return TRUE;
- case WM_GETMINMAXINFO:
- {
- LPMINMAXINFO lpmmi = (LPMINMAXINFO)lParam;
- lpmmi->ptMinTrackSize.x = mmiPtMinX;
- lpmmi->ptMinTrackSize.y = mmiPtMaxY;
- //lpmmi->ptMaxTrackSize.y = mmiPtMaxY;
- }
- return TRUE;
- case WM_NOTIFY: {
- if (((LPNMHDR)(lParam))->idFrom == IDC_STYLELIST) {
- switch (((LPNMHDR)(lParam))->code) {
- case NM_DBLCLK:
- SendMessage(hwnd,WM_COMMAND,MAKELONG(IDOK,1),0);
- break;
- case LVN_ITEMCHANGED:
- case LVN_DELETEITEM: {
- int i = ListView_GetNextItem(hwndLV,-1,LVNI_ALL | LVNI_SELECTED);
- if (iInternalDefault == i)
- CheckDlgButton(hwnd,IDC_DEFAULTSCHEME,BST_CHECKED);
- else
- CheckDlgButton(hwnd,IDC_DEFAULTSCHEME,BST_UNCHECKED);
- EnableWindow(GetDlgItem(hwnd,IDC_DEFAULTSCHEME),i != -1);
- EnableWindow(GetDlgItem(hwnd,IDOK),i != -1);
- }
- break;
- }
- }
- }
- return TRUE;
- case WM_COMMAND:
- switch(LOWORD(wParam))
- {
- case IDC_DEFAULTSCHEME:
- if (IsDlgButtonChecked(hwnd,IDC_DEFAULTSCHEME) == BST_CHECKED)
- iInternalDefault = ListView_GetNextItem(hwndLV,-1,LVNI_ALL | LVNI_SELECTED);
- else
- iInternalDefault = 0;
- break;
- case IDOK:
- {
- LVITEM lvi;
- lvi.mask = LVIF_PARAM;
- lvi.iItem = ListView_GetNextItem(hwndLV,-1,LVNI_ALL | LVNI_SELECTED);
- if (ListView_GetItem(hwndLV,&lvi)) {
- pLexCurrent = (PEDITLEXER)lvi.lParam;
- iDefaultLexer = iInternalDefault;
- bAutoSelect = (IsDlgButtonChecked(hwnd,IDC_AUTOSELECT) == BST_CHECKED) ? 1 : 0;
- EndDialog(hwnd,IDOK);
- }
- }
- break;
- case IDCANCEL:
- EndDialog(hwnd,IDCANCEL);
- break;
- }
- return TRUE;
- }
- return FALSE;
- }
- //=============================================================================
- //
- // Style_SelectLexerDlg()
- //
- void Style_SelectLexerDlg(HWND hwnd)
- {
- if (IDOK == ThemedDialogBoxParam(g_hInstance,
- MAKEINTRESOURCE(IDD_STYLESELECT),
- GetParent(hwnd),Style_SelectLexerDlgProc,0))
- Style_SetLexer(hwnd,pLexCurrent);
- }
- // End of Styles.c