Styles.c
上传用户:tj_dwf
上传日期:2020-11-17
资源大小:215k
文件大小:151k
源码类别:

RichEdit

开发平台:

Visual C++

  1.       else if (pLexMode = Style_MatchLexer(wchMode,TRUE)) {
  2.         pLexNew = pLexMode;
  3.         bFound = TRUE;
  4.       }
  5.     }
  6.   }
  7.   lpszExt = PathFindExtension(lpszFile);
  8.   if (!bFound && bAutoSelect && /* bAutoSelect == FALSE skips lexer search */
  9.       (lpszFile && lstrlen(lpszFile) > 0 && *lpszExt)) {
  10.     if (*lpszExt == L'.')
  11.       lpszExt++;
  12.     if (!fNoCGIGuess && (lstrcmpi(lpszExt,L"cgi") == 0 || lstrcmpi(lpszExt,L"fcgi") == 0)) {
  13.       char tchText[256];
  14.       SendMessage(hwnd,SCI_GETTEXT,(WPARAM)COUNTOF(tchText)-1,(LPARAM)tchText);
  15.       StrTrimA(tchText," tnr");
  16.       if (pLexSniffed = Style_SniffShebang(tchText)) {
  17.         pLexNew = pLexSniffed;
  18.         bFound = TRUE;
  19.       }
  20.     }
  21.     // check associated extensions
  22.     if (!bFound) {
  23.       if (pLexSniffed = Style_MatchLexer(lpszExt,FALSE)) {
  24.         pLexNew = pLexSniffed;
  25.         bFound = TRUE;
  26.       }
  27.     }
  28.   }
  29.   if (!bFound && bAutoSelect &&
  30.        lstrcmpi(PathFindFileName(lpszFile),L"makefile") == 0) {
  31.     pLexNew = &lexMAK;
  32.     bFound = TRUE;
  33.   }
  34.   if (!bFound && bAutoSelect && (!fNoHTMLGuess || !fNoCGIGuess)) {
  35.     char tchText[512];
  36.     SendMessage(hwnd,SCI_GETTEXT,(WPARAM)COUNTOF(tchText)-1,(LPARAM)tchText);
  37.     StrTrimA(tchText," tnr");
  38.     if (!fNoHTMLGuess && tchText[0] == '<') {
  39.       if (StrStrIA(tchText,"<html"))
  40.         pLexNew = &lexHTML;
  41.       else
  42.         pLexNew = &lexXML;
  43.       bFound = TRUE;
  44.     }
  45.     else if (!fNoCGIGuess && (pLexSniffed = Style_SniffShebang(tchText))) {
  46.       pLexNew = pLexSniffed;
  47.       bFound = TRUE;
  48.     }
  49.   }
  50.   // Apply the new lexer
  51.   Style_SetLexer(hwnd,pLexNew);
  52. }
  53. //=============================================================================
  54. //
  55. //  Style_SetLexerFromName()
  56. //
  57. void Style_SetLexerFromName(HWND hwnd,LPCWSTR lpszFile,LPCWSTR lpszName)
  58. {
  59.   PEDITLEXER pLexNew;
  60.   if (pLexNew = Style_MatchLexer(lpszName,FALSE))
  61.     Style_SetLexer(hwnd,pLexNew);
  62.   else if (pLexNew = Style_MatchLexer(lpszName,TRUE))
  63.     Style_SetLexer(hwnd,pLexNew);
  64.   else
  65.     Style_SetLexerFromFile(hwnd,lpszFile);
  66. }
  67. //=============================================================================
  68. //
  69. //  Style_SetDefaultLexer()
  70. //
  71. void Style_SetDefaultLexer(HWND hwnd)
  72. {
  73.   Style_SetLexer(hwnd,pLexArray[0]);
  74. }
  75. //=============================================================================
  76. //
  77. //  Style_SetHTMLLexer()
  78. //
  79. void Style_SetHTMLLexer(HWND hwnd)
  80. {
  81.   Style_SetLexer(hwnd,pLexArray[1]);
  82. }
  83. //=============================================================================
  84. //
  85. //  Style_SetXMLLexer()
  86. //
  87. void Style_SetXMLLexer(HWND hwnd)
  88. {
  89.   Style_SetLexer(hwnd,pLexArray[2]);
  90. }
  91. //=============================================================================
  92. //
  93. //  Style_SetLexerFromID()
  94. //
  95. void Style_SetLexerFromID(HWND hwnd,int id)
  96. {
  97.   if (id >= 0 && id < NUMLEXERS) {
  98.     Style_SetLexer(hwnd,pLexArray[id]);
  99.   }
  100. }
  101. //=============================================================================
  102. //
  103. //  Style_ToggleUse2ndDefault()
  104. //
  105. void Style_ToggleUse2ndDefault(HWND hwnd)
  106. {
  107.   bUse2ndDefaultStyle = (bUse2ndDefaultStyle) ? 0 : 1;
  108.   Style_SetLexer(hwnd,pLexCurrent);
  109. }
  110. //=============================================================================
  111. //
  112. //  Style_SetDefaultFont()
  113. //
  114. void Style_SetDefaultFont(HWND hwnd)
  115. {
  116.   int iIdx = (bUse2ndDefaultStyle) ? 13 : 0;
  117.   if (Style_SelectFont(hwnd,
  118.         lexDefault.Styles[0+iIdx].szValue,
  119.         COUNTOF(lexDefault.Styles[0+iIdx].szValue),
  120.         TRUE)) {
  121.     fStylesModified = TRUE;
  122.     Style_SetLexer(hwnd,pLexCurrent);
  123.   }
  124. }
  125. //=============================================================================
  126. //
  127. //  Style_GetUse2ndDefault()
  128. //
  129. BOOL Style_GetUse2ndDefault(HWND hwnd)
  130. {
  131.   return (bUse2ndDefaultStyle);
  132. }
  133. //=============================================================================
  134. //
  135. //  Style_SetIndentGuides()
  136. //
  137. extern int flagSimpleIndentGuides;
  138. void Style_SetIndentGuides(HWND hwnd,BOOL bShow)
  139. {
  140.   int iIndentView = SC_IV_NONE;
  141.   if (bShow) {
  142.     if (!flagSimpleIndentGuides) {
  143.       if (SendMessage(hwnd,SCI_GETLEXER,0,0) == SCLEX_PYTHON)
  144.         iIndentView = SC_IV_LOOKFORWARD;
  145.       else
  146.         iIndentView = SC_IV_LOOKBOTH;
  147.     }
  148.     else
  149.       iIndentView = SC_IV_REAL;
  150.   }
  151.   SendMessage(hwnd,SCI_SETINDENTATIONGUIDES,iIndentView,0);
  152. }
  153. //=============================================================================
  154. //
  155. //  Style_GetFileOpenDlgFilter()
  156. //
  157. extern WCHAR tchFileDlgFilters[5*1024];
  158. BOOL Style_GetOpenDlgFilterStr(LPWSTR lpszFilter,int cchFilter)
  159. {
  160.   if (lstrlen(tchFileDlgFilters) == 0)
  161.     GetString(IDS_FILTER_ALL,lpszFilter,cchFilter);
  162.   else {
  163.     lstrcpyn(lpszFilter,tchFileDlgFilters,cchFilter-2);
  164.     lstrcat(lpszFilter,L"||");
  165.   }
  166.   PrepareFilterStr(lpszFilter);
  167.   return TRUE;
  168. }
  169. //=============================================================================
  170. //
  171. //  Style_StrGetFont()
  172. //
  173. BOOL Style_StrGetFont(LPCWSTR lpszStyle,LPWSTR lpszFont,int cchFont)
  174. {
  175.   WCHAR tch[256];
  176.   WCHAR *p;
  177.   if (p = StrStrI(lpszStyle,L"font:"))
  178.   {
  179.     lstrcpy(tch,p + lstrlen(L"font:"));
  180.     if (p = StrChr(tch,L';'))
  181.       *p = L'';
  182.     TrimString(tch);
  183.     lstrcpyn(lpszFont,tch,cchFont);
  184.     return TRUE;
  185.   }
  186.   return FALSE;
  187. }
  188. //=============================================================================
  189. //
  190. //  Style_StrGetFontQuality()
  191. //
  192. BOOL Style_StrGetFontQuality(LPCWSTR lpszStyle,LPWSTR lpszQuality,int cchQuality)
  193. {
  194.   WCHAR tch[256];
  195.   WCHAR *p;
  196.   if (p = StrStrI(lpszStyle,L"smoothing:"))
  197.   {
  198.     lstrcpy(tch,p + lstrlen(L"smoothing:"));
  199.     if (p = StrChr(tch,L';'))
  200.       *p = L'';
  201.     TrimString(tch);
  202.     if (lstrcmpi(tch,L"none") == 0 ||
  203.         lstrcmpi(tch,L"standard") == 0 ||
  204.         lstrcmpi(tch,L"cleartype") == 0 ||
  205.         lstrcmpi(tch,L"default") == 0) {
  206.       lstrcpyn(lpszQuality,tch,cchQuality);
  207.       return TRUE;
  208.     }
  209.   }
  210.   return FALSE;
  211. }
  212. //=============================================================================
  213. //
  214. //  Style_StrGetCharSet()
  215. //
  216. BOOL Style_StrGetCharSet(LPCWSTR lpszStyle,int *i)
  217. {
  218.   WCHAR tch[256];
  219.   WCHAR *p;
  220.   int  iValue;
  221.   int  itok;
  222.   if (p = StrStrI(lpszStyle,L"charset:"))
  223.   {
  224.     lstrcpy(tch,p + lstrlen(L"charset:"));
  225.     if (p = StrChr(tch,L';'))
  226.       *p = L'';
  227.     TrimString(tch);
  228.     itok = swscanf(tch,L"%i",&iValue);
  229.     if (itok == 1)
  230.     {
  231.       *i = iValue;
  232.       return TRUE;
  233.     }
  234.   }
  235.   return FALSE;
  236. }
  237. //=============================================================================
  238. //
  239. //  Style_StrGetSize()
  240. //
  241. BOOL Style_StrGetSize(LPCWSTR lpszStyle,int *i)
  242. {
  243.   WCHAR tch[256];
  244.   WCHAR *p;
  245.   int  iValue;
  246.   int  iSign = 0;
  247.   int  itok;
  248.   if (p = StrStrI(lpszStyle,L"size:"))
  249.   {
  250.     lstrcpy(tch,p + lstrlen(L"size:"));
  251.     if (tch[0] == L'+')
  252.     {
  253.       iSign = 1;
  254.       tch[0] = L' ';
  255.     }
  256.     else if (tch[0] == L'-')
  257.     {
  258.       iSign = -1;
  259.       tch[0] = L' ';
  260.     }
  261.     if (p = StrChr(tch,L';'))
  262.       *p = L'';
  263.     TrimString(tch);
  264.     itok = swscanf(tch,L"%i",&iValue);
  265.     if (itok == 1)
  266.     {
  267.       if (iSign == 0)
  268.         *i = iValue;
  269.       else
  270.         *i = max(0,iBaseFontSize + iValue * iSign); // size must be +
  271.       return TRUE;
  272.     }
  273.   }
  274.   return FALSE;
  275. }
  276. //=============================================================================
  277. //
  278. //  Style_StrGetSizeStr()
  279. //
  280. BOOL Style_StrGetSizeStr(LPCWSTR lpszStyle,LPWSTR lpszSize,int cchSize)
  281. {
  282.   WCHAR tch[256];
  283.   WCHAR *p;
  284.   if (p = StrStrI(lpszStyle,L"size:"))
  285.   {
  286.     lstrcpy(tch,p + lstrlen(L"size:"));
  287.     if (p = StrChr(tch,L';'))
  288.       *p = L'';
  289.     TrimString(tch);
  290.     lstrcpyn(lpszSize,tch,cchSize);
  291.     return TRUE;
  292.   }
  293.   return FALSE;
  294. }
  295. //=============================================================================
  296. //
  297. //  Style_StrGetColor()
  298. //
  299. BOOL Style_StrGetColor(BOOL bFore,LPCWSTR lpszStyle,int *rgb)
  300. {
  301.   WCHAR tch[256];
  302.   WCHAR *p;
  303.   int  iValue;
  304.   int  itok;
  305.   WCHAR *pItem = (bFore) ? L"fore:" : L"back:";
  306.   if (p = StrStrI(lpszStyle,pItem))
  307.   {
  308.     lstrcpy(tch,p + lstrlen(pItem));
  309.     if (tch[0] == L'#')
  310.       tch[0] = L' ';
  311.     if (p = StrChr(tch,L';'))
  312.       *p = L'';
  313.     TrimString(tch);
  314.     itok = swscanf(tch,L"%x",&iValue);
  315.     if (itok == 1)
  316.     {
  317.       *rgb = RGB((iValue&0xFF0000) >> 16,(iValue&0xFF00) >> 8,iValue&0xFF);
  318.       return TRUE;
  319.     }
  320.   }
  321.   return FALSE;
  322. }
  323. //=============================================================================
  324. //
  325. //  Style_StrGetCase()
  326. //
  327. BOOL Style_StrGetCase(LPCWSTR lpszStyle,int *i)
  328. {
  329.   WCHAR tch[256];
  330.   WCHAR *p;
  331.   if (p = StrStrI(lpszStyle,L"case:"))
  332.   {
  333.     lstrcpy(tch,p + lstrlen(L"case:"));
  334.     if (p = StrChr(tch,L';'))
  335.       *p = L'';
  336.     TrimString(tch);
  337.     if (tch[0] == L'u' || tch[0] == L'U') {
  338.       *i = SC_CASE_UPPER;
  339.       return TRUE;
  340.     }
  341.     else if (tch[0] == L'l' || tch[0] == L'L') {
  342.       *i = SC_CASE_LOWER;
  343.       return TRUE;
  344.     }
  345.   }
  346.   return FALSE;
  347. }
  348. //=============================================================================
  349. //
  350. //  Style_StrGetAlpha()
  351. //
  352. BOOL Style_StrGetAlpha(LPCWSTR lpszStyle,int *i)
  353. {
  354.   WCHAR tch[256];
  355.   WCHAR *p;
  356.   int  iValue;
  357.   int  itok;
  358.   if (p = StrStrI(lpszStyle,L"alpha:"))
  359.   {
  360.     lstrcpy(tch,p + lstrlen(L"alpha:"));
  361.     if (p = StrChr(tch,L';'))
  362.       *p = L'';
  363.     TrimString(tch);
  364.     itok = swscanf(tch,L"%i",&iValue);
  365.     if (itok == 1)
  366.     {
  367.       *i = min(max(SC_ALPHA_TRANSPARENT,iValue),SC_ALPHA_OPAQUE);
  368.       return TRUE;
  369.     }
  370.   }
  371.   return FALSE;
  372. }
  373. //=============================================================================
  374. //
  375. //  Style_SelectFont()
  376. //
  377. BOOL Style_SelectFont(HWND hwnd,LPWSTR lpszStyle,int cchStyle,BOOL bDefaultStyle)
  378. {
  379.   CHOOSEFONT cf;
  380.   LOGFONT lf;
  381.   WCHAR szNewStyle[512];
  382.   int  iValue;
  383.   WCHAR tch[32];
  384.   HDC hdc;
  385.   ZeroMemory(&cf,sizeof(CHOOSEFONT));
  386.   ZeroMemory(&lf,sizeof(LOGFONT));
  387.   // Map lpszStyle to LOGFONT
  388.   if (Style_StrGetFont(lpszStyle,tch,COUNTOF(tch)))
  389.     lstrcpyn(lf.lfFaceName,tch,COUNTOF(lf.lfFaceName));
  390.   if (Style_StrGetCharSet(lpszStyle,&iValue))
  391.     lf.lfCharSet = iValue;
  392.   if (Style_StrGetSize(lpszStyle,&iValue)) {
  393.     hdc = GetDC(hwnd);
  394.     lf.lfHeight = -MulDiv(iValue,GetDeviceCaps(hdc,LOGPIXELSY),72);
  395.     ReleaseDC(hwnd,hdc);
  396.   }
  397.   lf.lfWeight = (StrStrI(lpszStyle,L"bold")) ? FW_BOLD : FW_NORMAL;
  398.   lf.lfItalic = (StrStrI(lpszStyle,L"italic")) ? 1 : 0;
  399.   // Init cf
  400.   cf.lStructSize = sizeof(CHOOSEFONT);
  401.   cf.hwndOwner = hwnd;
  402.   cf.lpLogFont = &lf;
  403.   cf.Flags = CF_INITTOLOGFONTSTRUCT /*| CF_NOSCRIPTSEL*/ | CF_SCREENFONTS;
  404.   if (HIBYTE(GetKeyState(VK_SHIFT)))
  405.     cf.Flags |= CF_FIXEDPITCHONLY;
  406.   if (!ChooseFont(&cf) || !lstrlen(lf.lfFaceName))
  407.     return FALSE;
  408.   // Map back to lpszStyle
  409.   lstrcpy(szNewStyle,L"font:");
  410.   lstrcat(szNewStyle,lf.lfFaceName);
  411.   if (Style_StrGetFontQuality(lpszStyle,tch,COUNTOF(tch)))
  412.   {
  413.     lstrcat(szNewStyle,L"; smoothing:");
  414.     lstrcat(szNewStyle,tch);
  415.   }
  416.   if (bDefaultStyle &&
  417.       lf.lfCharSet != DEFAULT_CHARSET &&
  418.       lf.lfCharSet != ANSI_CHARSET &&
  419.       lf.lfCharSet != iDefaultCharSet) {
  420.     lstrcat(szNewStyle,L"; charset:");
  421.     wsprintf(tch,L"%i",lf.lfCharSet);
  422.     lstrcat(szNewStyle,tch);
  423.   }
  424.   lstrcat(szNewStyle,L"; size:");
  425.   wsprintf(tch,L"%i",cf.iPointSize/10);
  426.   lstrcat(szNewStyle,tch);
  427.   if (cf.nFontType & BOLD_FONTTYPE)
  428.     lstrcat(szNewStyle,L"; bold");
  429.   if (cf.nFontType & ITALIC_FONTTYPE)
  430.     lstrcat(szNewStyle,L"; italic");
  431.   if (StrStrI(lpszStyle,L"underline"))
  432.     lstrcat(szNewStyle,L"; underline");
  433.   // save colors
  434.   if (Style_StrGetColor(TRUE,lpszStyle,&iValue))
  435.   {
  436.     wsprintf(tch,L"; fore:#%02X%02X%02X",
  437.       (int)GetRValue(iValue),
  438.       (int)GetGValue(iValue),
  439.       (int)GetBValue(iValue));
  440.     lstrcat(szNewStyle,tch);
  441.   }
  442.   if (Style_StrGetColor(FALSE,lpszStyle,&iValue))
  443.   {
  444.     wsprintf(tch,L"; back:#%02X%02X%02X",
  445.       (int)GetRValue(iValue),
  446.       (int)GetGValue(iValue),
  447.       (int)GetBValue(iValue));
  448.     lstrcat(szNewStyle,tch);
  449.   }
  450.   if (StrStrI(lpszStyle,L"eolfilled"))
  451.     lstrcat(szNewStyle,L"; eolfilled");
  452.   if (Style_StrGetCase(lpszStyle,&iValue)) {
  453.     lstrcat(szNewStyle,L"; case:");
  454.     lstrcat(szNewStyle,(iValue == SC_CASE_UPPER) ? L"u" : L"");
  455.   }
  456.   if (Style_StrGetAlpha(lpszStyle,&iValue)) {
  457.     lstrcat(szNewStyle,L"; alpha:");
  458.     wsprintf(tch,L"%i",iValue);
  459.     lstrcat(szNewStyle,tch);
  460.   }
  461.   lstrcpyn(lpszStyle,szNewStyle,cchStyle);
  462.   return TRUE;
  463. }
  464. //=============================================================================
  465. //
  466. //  Style_SelectColor()
  467. //
  468. BOOL Style_SelectColor(HWND hwnd,BOOL bFore,LPWSTR lpszStyle,int cchStyle)
  469. {
  470.   CHOOSECOLOR cc;
  471.   WCHAR szNewStyle[512];
  472.   int  iRGBResult;
  473.   int  iValue;
  474.   WCHAR tch[32];
  475.   ZeroMemory(&cc,sizeof(CHOOSECOLOR));
  476.   iRGBResult = (bFore) ? GetSysColor(COLOR_WINDOWTEXT) : GetSysColor(COLOR_WINDOW);
  477.   Style_StrGetColor(bFore,lpszStyle,&iRGBResult);
  478.   cc.lStructSize = sizeof(CHOOSECOLOR);
  479.   cc.hwndOwner = hwnd;
  480.   cc.rgbResult = iRGBResult;
  481.   cc.lpCustColors = crCustom;
  482.   cc.Flags = CC_FULLOPEN | CC_RGBINIT | CC_SOLIDCOLOR;
  483.   if (!ChooseColor(&cc))
  484.     return FALSE;
  485.   iRGBResult = cc.rgbResult;
  486.   // Rebuild style string
  487.   lstrcpy(szNewStyle,L"");
  488.   if (Style_StrGetFont(lpszStyle,tch,COUNTOF(tch)))
  489.   {
  490.     lstrcat(szNewStyle,L"font:");
  491.     lstrcat(szNewStyle,tch);
  492.   }
  493.   if (Style_StrGetFontQuality(lpszStyle,tch,COUNTOF(tch)))
  494.   {
  495.     if (lstrlen(szNewStyle))
  496.       lstrcat(szNewStyle,L"; ");
  497.     lstrcat(szNewStyle,L"smoothing:");
  498.     lstrcat(szNewStyle,tch);
  499.   }
  500.   if (Style_StrGetCharSet(lpszStyle,&iValue))
  501.   {
  502.     if (lstrlen(szNewStyle))
  503.       lstrcat(szNewStyle,L"; ");
  504.     wsprintf(tch,L"charset:%i",iValue);
  505.     lstrcat(szNewStyle,tch);
  506.   }
  507.   if (Style_StrGetSizeStr(lpszStyle,tch,COUNTOF(tch)))
  508.   {
  509.     if (lstrlen(szNewStyle))
  510.       lstrcat(szNewStyle,L"; ");
  511.     lstrcat(szNewStyle,L"size:");
  512.     lstrcat(szNewStyle,tch);
  513.   }
  514.   if (StrStrI(lpszStyle,L"bold"))
  515.   {
  516.     if (lstrlen(szNewStyle))
  517.       lstrcat(szNewStyle,L"; ");
  518.     lstrcat(szNewStyle,L"bold");
  519.   }
  520.   if (StrStrI(lpszStyle,L"italic"))
  521.   {
  522.     if (lstrlen(szNewStyle))
  523.       lstrcat(szNewStyle,L"; ");
  524.     lstrcat(szNewStyle,L"italic");
  525.   }
  526.   if (StrStrI(lpszStyle,L"underline"))
  527.   {
  528.     if (lstrlen(szNewStyle))
  529.       lstrcat(szNewStyle,L"; ");
  530.     lstrcat(szNewStyle,L"underline");
  531.   }
  532.   if (bFore)
  533.   {
  534.     if (lstrlen(szNewStyle))
  535.       lstrcat(szNewStyle,L"; ");
  536.     wsprintf(tch,L"fore:#%02X%02X%02X",
  537.       (int)GetRValue(iRGBResult),
  538.       (int)GetGValue(iRGBResult),
  539.       (int)GetBValue(iRGBResult));
  540.     lstrcat(szNewStyle,tch);
  541.     if (Style_StrGetColor(FALSE,lpszStyle,&iValue))
  542.     {
  543.       wsprintf(tch,L"; back:#%02X%02X%02X",
  544.         (int)GetRValue(iValue),
  545.         (int)GetGValue(iValue),
  546.         (int)GetBValue(iValue));
  547.       lstrcat(szNewStyle,tch);
  548.     }
  549.   }
  550.   else
  551.   {
  552.     if (lstrlen(szNewStyle))
  553.       lstrcat(szNewStyle,L"; ");
  554.     if (Style_StrGetColor(TRUE,lpszStyle,&iValue))
  555.     {
  556.       wsprintf(tch,L"fore:#%02X%02X%02X; ",
  557.         (int)GetRValue(iValue),
  558.         (int)GetGValue(iValue),
  559.         (int)GetBValue(iValue));
  560.       lstrcat(szNewStyle,tch);
  561.     }
  562.     wsprintf(tch,L"back:#%02X%02X%02X",
  563.       (int)GetRValue(iRGBResult),
  564.       (int)GetGValue(iRGBResult),
  565.       (int)GetBValue(iRGBResult));
  566.     lstrcat(szNewStyle,tch);
  567.   }
  568.   if (StrStrI(lpszStyle,L"eolfilled"))
  569.     lstrcat(szNewStyle,L"; eolfilled");
  570.   if (Style_StrGetCase(lpszStyle,&iValue)) {
  571.     lstrcat(szNewStyle,L"; case:");
  572.     lstrcat(szNewStyle,(iValue == SC_CASE_UPPER) ? L"u" : L"");
  573.   }
  574.   if (Style_StrGetAlpha(lpszStyle,&iValue)) {
  575.     lstrcat(szNewStyle,L"; alpha:");
  576.     wsprintf(tch,L"%i",iValue);
  577.     lstrcat(szNewStyle,tch);
  578.   }
  579.   lstrcpyn(lpszStyle,szNewStyle,cchStyle);
  580.   return TRUE;
  581. }
  582. //=============================================================================
  583. //
  584. //  Style_SetStyles()
  585. //
  586. void Style_SetStyles(HWND hwnd,int iStyle,LPCWSTR lpszStyle)
  587. {
  588.   WCHAR tch[256];
  589.   WCHAR *p;
  590.   int  iValue;
  591.   // Font
  592.   if (Style_StrGetFont(lpszStyle,tch,COUNTOF(tch))) {
  593.     char mch[256];
  594.     WideCharToMultiByte(CP_ACP,0,tch,-1,mch,COUNTOF(mch),NULL,NULL);
  595.     SendMessage(hwnd,SCI_STYLESETFONT,iStyle,(LPARAM)mch);
  596.   }
  597.   // Size
  598.   if (Style_StrGetSize(lpszStyle,&iValue))
  599.     SendMessage(hwnd,SCI_STYLESETSIZE,iStyle,(LPARAM)iValue);
  600.   // Fore
  601.   if (Style_StrGetColor(TRUE,lpszStyle,&iValue))
  602.     SendMessage(hwnd,SCI_STYLESETFORE,iStyle,(LPARAM)iValue);
  603.   // Back
  604.   if (Style_StrGetColor(FALSE,lpszStyle,&iValue))
  605.     SendMessage(hwnd,SCI_STYLESETBACK,iStyle,(LPARAM)iValue);
  606.   // Bold
  607.   if (p = StrStrI(lpszStyle,L"bold"))
  608.     SendMessage(hwnd,SCI_STYLESETBOLD,iStyle,(LPARAM)TRUE);
  609.   else
  610.     SendMessage(hwnd,SCI_STYLESETBOLD,iStyle,(LPARAM)FALSE);
  611.   // Italic
  612.   if (p = StrStrI(lpszStyle,L"italic"))
  613.     SendMessage(hwnd,SCI_STYLESETITALIC,iStyle,(LPARAM)TRUE);
  614.   else
  615.     SendMessage(hwnd,SCI_STYLESETITALIC,iStyle,(LPARAM)FALSE);
  616.   // Underline
  617.   if (p = StrStrI(lpszStyle,L"underline"))
  618.     SendMessage(hwnd,SCI_STYLESETUNDERLINE,iStyle,(LPARAM)TRUE);
  619.   else
  620.     SendMessage(hwnd,SCI_STYLESETUNDERLINE,iStyle,(LPARAM)FALSE);
  621.   // EOL Filled
  622.   if (p = StrStrI(lpszStyle,L"eolfilled"))
  623.     SendMessage(hwnd,SCI_STYLESETEOLFILLED,iStyle,(LPARAM)TRUE);
  624.   else
  625.     SendMessage(hwnd,SCI_STYLESETEOLFILLED,iStyle,(LPARAM)FALSE);
  626.   // Case
  627.   if (Style_StrGetCase(lpszStyle,&iValue))
  628.     SendMessage(hwnd,SCI_STYLESETCASE,iStyle,(LPARAM)iValue);
  629.   // Character Set
  630.   if (Style_StrGetCharSet(lpszStyle,&iValue))
  631.     SendMessage(hwnd,SCI_STYLESETCHARACTERSET,iStyle,(LPARAM)iValue);
  632. }
  633. //=============================================================================
  634. //
  635. //  Style_SetFontQuality()
  636. //
  637. void Style_SetFontQuality(HWND hwnd,LPCWSTR lpszStyle) {
  638.   WPARAM wQuality = SC_EFF_QUALITY_DEFAULT;
  639.   WCHAR tch[32];
  640.   if (Style_StrGetFontQuality(lpszStyle,tch,COUNTOF(tch))) {
  641.     if (lstrcmpi(tch,L"none") == 0)
  642.       wQuality = SC_EFF_QUALITY_NON_ANTIALIASED;
  643.     else if (lstrcmpi(tch,L"standard") == 0)
  644.       wQuality = SC_EFF_QUALITY_ANTIALIASED;
  645.     else if (lstrcmpi(tch,L"cleartype") == 0)
  646.       wQuality = SC_EFF_QUALITY_LCD_OPTIMIZED;
  647.     else
  648.       wQuality = SC_EFF_QUALITY_DEFAULT;
  649.   }
  650.   else {
  651.     WCHAR tch[32];
  652.     if (Style_StrGetFont(lpszStyle,tch,COUNTOF(tch))) {
  653.       if (lstrcmpi(tch,L"Calibri") == 0 ||
  654.           lstrcmpi(tch,L"Cambria") == 0 ||
  655.           lstrcmpi(tch,L"Candara") == 0 ||
  656.           lstrcmpi(tch,L"Consolas") == 0 ||
  657.           lstrcmpi(tch,L"Constantia") == 0 ||
  658.           lstrcmpi(tch,L"Corbel") == 0 ||
  659.           lstrcmpi(tch,L"Segoe UI") == 0)
  660.         wQuality = SC_EFF_QUALITY_LCD_OPTIMIZED;
  661.     }
  662.     else
  663.       wQuality = SC_EFF_QUALITY_DEFAULT;
  664.   }
  665.   SendMessage(hwnd,SCI_SETFONTQUALITY,wQuality,0);
  666. }
  667. //=============================================================================
  668. //
  669. //  Style_GetCurrentLexerName()
  670. //
  671. void Style_GetCurrentLexerName(LPWSTR lpszName,int cchName)
  672. {
  673.   if (!GetString(pLexCurrent->rid,lpszName,cchName))
  674.     lstrcpyn(lpszName,pLexCurrent->pszName,cchName);
  675. }
  676. //=============================================================================
  677. //
  678. //  Style_GetLexerIconId()
  679. //
  680. int Style_GetLexerIconId(PEDITLEXER plex)
  681. {
  682.   WCHAR *p;
  683.   WCHAR *pszExtensions;
  684.   WCHAR *pszFile;
  685.   SHFILEINFO shfi;
  686.   if (lstrlen(plex->szExtensions))
  687.     pszExtensions = plex->szExtensions;
  688.   else
  689.     pszExtensions = plex->pszDefExt;
  690.   pszFile = GlobalAlloc(GPTR,sizeof(WCHAR)*(lstrlen(pszExtensions) + lstrlen(L"*.txt") + 16));
  691.   lstrcpy(pszFile,L"*.");
  692.   lstrcat(pszFile,pszExtensions);
  693.   if (p = StrChr(pszFile,L';'))
  694.     *p = L'';
  695.   // check for ; at beginning
  696.   if (lstrlen(pszFile) < 3)
  697.     lstrcat(pszFile,L"txt");
  698.   SHGetFileInfo(pszFile,FILE_ATTRIBUTE_NORMAL,&shfi,sizeof(SHFILEINFO),
  699.     SHGFI_SMALLICON | SHGFI_SYSICONINDEX | SHGFI_USEFILEATTRIBUTES);
  700.   GlobalFree(pszFile);
  701.   return (shfi.iIcon);
  702. }
  703. //=============================================================================
  704. //
  705. //  Style_AddLexerToTreeView()
  706. //
  707. void Style_AddLexerToTreeView(HWND hwnd,PEDITLEXER plex)
  708. {
  709.   int i = 0;
  710.   WCHAR tch[128];
  711.   HTREEITEM hTreeNode;
  712.   TVINSERTSTRUCT tvis;
  713.   ZeroMemory(&tvis,sizeof(TVINSERTSTRUCT));
  714.   tvis.hInsertAfter = TVI_LAST;
  715.   tvis.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
  716.   if (GetString(plex->rid,tch,COUNTOF(tch)))
  717.     tvis.item.pszText = tch;
  718.   else
  719.     tvis.item.pszText = plex->pszName;
  720.   tvis.item.iImage = Style_GetLexerIconId(plex);
  721.   tvis.item.iSelectedImage = tvis.item.iImage;
  722.   tvis.item.lParam = (LPARAM)plex;
  723.   hTreeNode = (HTREEITEM)TreeView_InsertItem(hwnd,&tvis);
  724.   tvis.hParent = hTreeNode;
  725.   tvis.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
  726.   //tvis.item.iImage = -1;
  727.   //tvis.item.iSelectedImage = -1;
  728.   while (plex->Styles[i].iStyle != -1) {
  729.     if (GetString(plex->Styles[i].rid,tch,COUNTOF(tch)))
  730.       tvis.item.pszText = tch;
  731.     else
  732.       tvis.item.pszText = plex->Styles[i].pszName;
  733.     tvis.item.lParam = (LPARAM)(&plex->Styles[i]);
  734.     TreeView_InsertItem(hwnd,&tvis);
  735.     i++;
  736.   }
  737. }
  738. //=============================================================================
  739. //
  740. //  Style_AddLexerToListView()
  741. //
  742. void Style_AddLexerToListView(HWND hwnd,PEDITLEXER plex)
  743. {
  744.   WCHAR tch[128];
  745.   LVITEM lvi;
  746.   ZeroMemory(&lvi,sizeof(LVITEM));
  747.   lvi.mask = LVIF_IMAGE | LVIF_PARAM | LVIF_TEXT;
  748.   lvi.iItem = ListView_GetItemCount(hwnd);
  749.   if (GetString(plex->rid,tch,COUNTOF(tch)))
  750.     lvi.pszText = tch;
  751.   else
  752.     lvi.pszText = plex->pszName;
  753.   lvi.iImage = Style_GetLexerIconId(plex);
  754.   lvi.lParam = (LPARAM)plex;
  755.   ListView_InsertItem(hwnd,&lvi);
  756. }
  757. //=============================================================================
  758. //
  759. //  Style_ConfigDlgProc()
  760. //
  761. BOOL CALLBACK Style_ConfigDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam)
  762. {
  763.   static HWND hwndTV;
  764.   static BOOL fDragging;
  765.   static PEDITLEXER pCurrentLexer;
  766.   static PEDITSTYLE pCurrentStyle;
  767.   static HFONT hFontTitle;
  768.   static HBRUSH hbrFore;
  769.   static HBRUSH hbrBack;
  770.   switch(umsg)
  771.   {
  772.     case WM_INITDIALOG:
  773.       {
  774.         int i;
  775.         SHFILEINFO shfi;
  776.         LOGFONT lf;
  777.         hwndTV = GetDlgItem(hwnd,IDC_STYLELIST);
  778.         fDragging = FALSE;
  779.         TreeView_SetImageList(hwndTV,
  780.           (HIMAGELIST)SHGetFileInfo(L"C:\",0,&shfi,sizeof(SHFILEINFO),
  781.           SHGFI_SMALLICON | SHGFI_SYSICONINDEX),TVSIL_NORMAL);
  782.         // Add lexers
  783.         for (i = 0; i < NUMLEXERS; i++)
  784.           Style_AddLexerToTreeView(hwndTV,pLexArray[i]);
  785.         pCurrentLexer = 0;
  786.         pCurrentStyle = 0;
  787.         //SetExplorerTheme(hwndTV);
  788.         //TreeView_Expand(hwndTV,TreeView_GetRoot(hwndTV),TVE_EXPAND);
  789.         TreeView_Select(hwndTV,TreeView_GetRoot(hwndTV),TVGN_CARET);
  790.         SendDlgItemMessage(hwnd,IDC_STYLEEDIT,EM_LIMITTEXT,COUNTOF(lexDefault.Styles[0].szValue)-1,0);
  791.         MakeBitmapButton(hwnd,IDC_PREVSTYLE,g_hInstance,IDB_PREV);
  792.         MakeBitmapButton(hwnd,IDC_NEXTSTYLE,g_hInstance,IDB_NEXT);
  793.         // Setup title font
  794.         if (hFontTitle)
  795.           DeleteObject(hFontTitle);
  796.         if (NULL == (hFontTitle = (HFONT)SendDlgItemMessage(hwnd,IDC_TITLE,WM_GETFONT,0,0)))
  797.           hFontTitle = GetStockObject(DEFAULT_GUI_FONT);
  798.         GetObject(hFontTitle,sizeof(LOGFONT),&lf);
  799.         lf.lfHeight += lf.lfHeight / 5;
  800.         lf.lfWeight = FW_BOLD;
  801.         hFontTitle = CreateFontIndirect(&lf);
  802.         SendDlgItemMessage(hwnd,IDC_TITLE,WM_SETFONT,(WPARAM)hFontTitle,TRUE);
  803.         CenterDlgInParent(hwnd);
  804.       }
  805.       return TRUE;
  806.     case WM_DESTROY:
  807.       DeleteBitmapButton(hwnd,IDC_STYLEFORE);
  808.       DeleteBitmapButton(hwnd,IDC_STYLEBACK);
  809.       DeleteBitmapButton(hwnd,IDC_PREVSTYLE);
  810.       DeleteBitmapButton(hwnd,IDC_NEXTSTYLE);
  811.       return FALSE;
  812.     case WM_NOTIFY:
  813.       if (((LPNMHDR)(lParam))->idFrom == IDC_STYLELIST)
  814.       {
  815.         LPNMTREEVIEW lpnmtv = (LPNMTREEVIEW)lParam;
  816.         switch (lpnmtv->hdr.code)
  817.         {
  818.           case TVN_SELCHANGED:
  819.             {
  820.               if (pCurrentStyle)
  821.                 GetDlgItemText(hwnd,IDC_STYLEEDIT,pCurrentStyle->szValue,COUNTOF(pCurrentStyle->szValue));
  822.               else if (pCurrentLexer) {
  823.                 if (!GetDlgItemText(hwnd,IDC_STYLEEDIT,pCurrentLexer->szExtensions,COUNTOF(pCurrentLexer->szExtensions)))
  824.                   lstrcpy(pCurrentLexer->szExtensions,pCurrentLexer->pszDefExt);
  825.               }
  826.               // a lexer has been selected
  827.               if (!TreeView_GetParent(hwndTV,lpnmtv->itemNew.hItem))
  828.               {
  829.                 WCHAR wch[128];
  830.                 GetDlgItemText(hwnd,IDC_STYLELABELS,wch,COUNTOF(wch));
  831.                 if (StrChr(wch,L'|')) *StrChr(wch,L'|') = 0;
  832.                 pCurrentStyle = 0;
  833.                 if (pCurrentLexer = (PEDITLEXER)lpnmtv->itemNew.lParam)
  834.                 {
  835.                   SetDlgItemText(hwnd,IDC_STYLELABEL,wch);
  836.                   EnableWindow(GetDlgItem(hwnd,IDC_STYLEEDIT),TRUE);
  837.                   EnableWindow(GetDlgItem(hwnd,IDC_STYLEFONT),FALSE);
  838.                   EnableWindow(GetDlgItem(hwnd,IDC_STYLEFORE),FALSE);
  839.                   EnableWindow(GetDlgItem(hwnd,IDC_STYLEBACK),FALSE);
  840.                   EnableWindow(GetDlgItem(hwnd,IDC_STYLEDEFAULT),TRUE);
  841.                   //EnableWindow(GetDlgItem(hwnd,IDC_STYLEBOLD),FALSE);
  842.                   //EnableWindow(GetDlgItem(hwnd,IDC_STYLEITALIC),FALSE);
  843.                   //EnableWindow(GetDlgItem(hwnd,IDC_STYLEUNDERLINE),FALSE);
  844.                   //EnableWindow(GetDlgItem(hwnd,IDC_STYLEEOLFILLED),FALSE);
  845.                   //CheckDlgButton(hwnd,IDC_STYLEBOLD,BST_UNCHECKED);
  846.                   //CheckDlgButton(hwnd,IDC_STYLEITALIC,BST_UNCHECKED);
  847.                   //CheckDlgButton(hwnd,IDC_STYLEUNDERLINE,BST_UNCHECKED);
  848.                   //CheckDlgButton(hwnd,IDC_STYLEEOLFILLED,BST_UNCHECKED);
  849.                   SetDlgItemText(hwnd,IDC_STYLEEDIT,pCurrentLexer->szExtensions);
  850.                 }
  851.                 else
  852.                 {
  853.                   SetDlgItemText(hwnd,IDC_STYLELABEL,L"");
  854.                   EnableWindow(GetDlgItem(hwnd,IDC_STYLEEDIT),FALSE);
  855.                   EnableWindow(GetDlgItem(hwnd,IDC_STYLEFONT),FALSE);
  856.                   EnableWindow(GetDlgItem(hwnd,IDC_STYLEFORE),FALSE);
  857.                   EnableWindow(GetDlgItem(hwnd,IDC_STYLEBACK),FALSE);
  858.                   EnableWindow(GetDlgItem(hwnd,IDC_STYLEDEFAULT),FALSE);
  859.                   //EnableWindow(GetDlgItem(hwnd,IDC_STYLEBOLD),FALSE);
  860.                   //EnableWindow(GetDlgItem(hwnd,IDC_STYLEITALIC),FALSE);
  861.                   //EnableWindow(GetDlgItem(hwnd,IDC_STYLEUNDERLINE),FALSE);
  862.                   //EnableWindow(GetDlgItem(hwnd,IDC_STYLEEOLFILLED),FALSE);
  863.                   //CheckDlgButton(hwnd,IDC_STYLEBOLD,BST_UNCHECKED);
  864.                   //CheckDlgButton(hwnd,IDC_STYLEITALIC,BST_UNCHECKED);
  865.                   //CheckDlgButton(hwnd,IDC_STYLEUNDERLINE,BST_UNCHECKED);
  866.                   //CheckDlgButton(hwnd,IDC_STYLEEOLFILLED,BST_UNCHECKED);
  867.                   SetDlgItemText(hwnd,IDC_STYLEEDIT,L"");
  868.                 }
  869.               }
  870.               // a style has been selected
  871.               else
  872.               {
  873.                 WCHAR wch[128];
  874.                 GetDlgItemText(hwnd,IDC_STYLELABELS,wch,COUNTOF(wch));
  875.                 if (StrChr(wch,L'|')) *StrChr(wch,L'|') = 0;
  876.                 pCurrentLexer = 0;
  877.                 if (pCurrentStyle = (PEDITSTYLE)lpnmtv->itemNew.lParam)
  878.                 {
  879.                   SetDlgItemText(hwnd,IDC_STYLELABEL,StrEnd(wch)+1);
  880.                   EnableWindow(GetDlgItem(hwnd,IDC_STYLEEDIT),TRUE);
  881.                   EnableWindow(GetDlgItem(hwnd,IDC_STYLEFONT),TRUE);
  882.                   EnableWindow(GetDlgItem(hwnd,IDC_STYLEFORE),TRUE);
  883.                   EnableWindow(GetDlgItem(hwnd,IDC_STYLEBACK),TRUE);
  884.                   EnableWindow(GetDlgItem(hwnd,IDC_STYLEDEFAULT),TRUE);
  885.                   //EnableWindow(GetDlgItem(hwnd,IDC_STYLEBOLD),TRUE);
  886.                   //EnableWindow(GetDlgItem(hwnd,IDC_STYLEITALIC),TRUE);
  887.                   //EnableWindow(GetDlgItem(hwnd,IDC_STYLEUNDERLINE),TRUE);
  888.                   //EnableWindow(GetDlgItem(hwnd,IDC_STYLEEOLFILLED),TRUE);
  889.                   //CheckDlgButton(hwnd,IDC_STYLEBOLD,(Style_StrGetAttribute(pCurrentStyle->szValue,L"bold") ? BST_CHECKED : BST_UNCHECKED));
  890.                   //CheckDlgButton(hwnd,IDC_STYLEITALIC,(Style_StrGetAttribute(pCurrentStyle->szValue,L"italic") ? BST_CHECKED : BST_UNCHECKED));
  891.                   //CheckDlgButton(hwnd,IDC_STYLEUNDERLINE,(Style_StrGetAttribute(pCurrentStyle->szValue,L"underline") ? BST_CHECKED : BST_UNCHECKED));
  892.                   //CheckDlgButton(hwnd,IDC_STYLEEOLFILLED,(Style_StrGetAttribute(pCurrentStyle->szValue,L"eolfilled") ? BST_CHECKED : BST_UNCHECKED));
  893.                   SetDlgItemText(hwnd,IDC_STYLEEDIT,pCurrentStyle->szValue);
  894.                 }
  895.                 else
  896.                 {
  897.                   SetDlgItemText(hwnd,IDC_STYLELABEL,L"");
  898.                   EnableWindow(GetDlgItem(hwnd,IDC_STYLEEDIT),FALSE);
  899.                   EnableWindow(GetDlgItem(hwnd,IDC_STYLEFONT),FALSE);
  900.                   EnableWindow(GetDlgItem(hwnd,IDC_STYLEFORE),FALSE);
  901.                   EnableWindow(GetDlgItem(hwnd,IDC_STYLEBACK),FALSE);
  902.                   EnableWindow(GetDlgItem(hwnd,IDC_STYLEDEFAULT),FALSE);
  903.                   //EnableWindow(GetDlgItem(hwnd,IDC_STYLEBOLD),FALSE);
  904.                   //EnableWindow(GetDlgItem(hwnd,IDC_STYLEITALIC),FALSE);
  905.                   //EnableWindow(GetDlgItem(hwnd,IDC_STYLEUNDERLINE),FALSE);
  906.                   //EnableWindow(GetDlgItem(hwnd,IDC_STYLEEOLFILLED),FALSE);
  907.                   //CheckDlgButton(hwnd,IDC_STYLEBOLD,BST_UNCHECKED);
  908.                   //CheckDlgButton(hwnd,IDC_STYLEITALIC,BST_UNCHECKED);
  909.                   //CheckDlgButton(hwnd,IDC_STYLEUNDERLINE,BST_UNCHECKED);
  910.                   //CheckDlgButton(hwnd,IDC_STYLEEOLFILLED,BST_UNCHECKED);
  911.                   SetDlgItemText(hwnd,IDC_STYLEEDIT,L"");
  912.                 }
  913.               }
  914.             }
  915.             break;
  916.           case TVN_BEGINDRAG:
  917.             {
  918.               //HIMAGELIST himl;
  919.               //if (pCurrentStyle)
  920.               //  GetDlgItemText(hwnd,IDC_STYLEEDIT,pCurrentStyle->szValue,COUNTOF(pCurrentStyle->szValue));
  921.               TreeView_Select(hwndTV,lpnmtv->itemNew.hItem,TVGN_CARET);
  922.               //himl = TreeView_CreateDragImage(hwndTV,lpnmtv->itemNew.hItem);
  923.               //ImageList_BeginDrag(himl,0,0,0);
  924.               //ImageList_DragEnter(hwndTV,lpnmtv->ptDrag.x,lpnmtv->ptDrag.y);
  925.               if (pCurrentStyle)
  926.                 DestroyCursor(SetCursor(LoadCursor(g_hInstance,MAKEINTRESOURCE(IDC_COPY))));
  927.               else
  928.                 DestroyCursor(SetCursor(LoadCursor(NULL,IDC_NO)));
  929.               SetCapture(hwnd);
  930.               fDragging = TRUE;
  931.             }
  932.         }
  933.       }
  934.       break;
  935.     case WM_MOUSEMOVE:
  936.       {
  937.         HTREEITEM htiTarget;
  938.         TVHITTESTINFO tvht;
  939.         if (fDragging && pCurrentStyle)
  940.         {
  941.           LONG xCur = LOWORD(lParam);
  942.           LONG yCur = HIWORD(lParam);
  943.           //ImageList_DragMove(xCur,yCur);
  944.           //ImageList_DragShowNolock(FALSE);
  945.           tvht.pt.x = xCur;
  946.           tvht.pt.y = yCur;
  947.           //ClientToScreen(hwnd,&tvht.pt);
  948.           //ScreenToClient(hwndTV,&tvht.pt);
  949.           MapWindowPoints(hwnd,hwndTV,&tvht.pt,1);
  950.           if ((htiTarget = TreeView_HitTest(hwndTV,&tvht)) != NULL &&
  951.                TreeView_GetParent(hwndTV,htiTarget) != NULL)
  952.           {
  953.             TreeView_SelectDropTarget(hwndTV,htiTarget);
  954.             //TreeView_Expand(hwndTV,htiTarget,TVE_EXPAND);
  955.             TreeView_EnsureVisible(hwndTV,htiTarget);
  956.           }
  957.           else
  958.             TreeView_SelectDropTarget(hwndTV,NULL);
  959.           //ImageList_DragShowNolock(TRUE);
  960.         }
  961.       }
  962.       break;
  963.     case WM_LBUTTONUP:
  964.       {
  965.         if (fDragging)
  966.         {
  967.           HTREEITEM htiTarget;
  968.           //ImageList_EndDrag();
  969.           if (htiTarget = TreeView_GetDropHilight(hwndTV))
  970.           {
  971.             WCHAR tchCopy[256];
  972.             TreeView_SelectDropTarget(hwndTV,NULL);
  973.             GetDlgItemText(hwnd,IDC_STYLEEDIT,tchCopy,COUNTOF(tchCopy));
  974.             TreeView_Select(hwndTV,htiTarget,TVGN_CARET);
  975.             // after select, this is new current item
  976.             if (pCurrentStyle)
  977.             {
  978.               lstrcpy(pCurrentStyle->szValue,tchCopy);
  979.               SetDlgItemText(hwnd,IDC_STYLEEDIT,tchCopy);
  980.               //CheckDlgButton(hwnd,IDC_STYLEBOLD,(Style_StrGetAttribute(tchCopy,L"bold") ? BST_CHECKED : BST_UNCHECKED));
  981.               //CheckDlgButton(hwnd,IDC_STYLEITALIC,(Style_StrGetAttribute(tchCopy,L"italic") ? BST_CHECKED : BST_UNCHECKED));
  982.               //CheckDlgButton(hwnd,IDC_STYLEUNDERLINE,(Style_StrGetAttribute(tchCopy,L"underline") ? BST_CHECKED : BST_UNCHECKED));
  983.               //CheckDlgButton(hwnd,IDC_STYLEEOLFILLED,(Style_StrGetAttribute(tchCopy,L"eolfilled") ? BST_CHECKED : BST_UNCHECKED));
  984.             }
  985.           }
  986.           ReleaseCapture();
  987.           DestroyCursor(SetCursor(LoadCursor(NULL,IDC_ARROW)));
  988.           fDragging = FALSE;
  989.         }
  990.       }
  991.       break;
  992.     case WM_CANCELMODE:
  993.       {
  994.         if (fDragging)
  995.         {
  996.           //ImageList_EndDrag();
  997.           TreeView_SelectDropTarget(hwndTV,NULL);
  998.           ReleaseCapture();
  999.           DestroyCursor(SetCursor(LoadCursor(NULL,IDC_ARROW)));
  1000.           fDragging = FALSE;
  1001.         }
  1002.       }
  1003.       break;
  1004.     case WM_COMMAND:
  1005.       switch(LOWORD(wParam))
  1006.       {
  1007.         case IDC_PREVSTYLE:
  1008.           if (TreeView_GetSelection(hwndTV))
  1009.             TreeView_Select(hwndTV,TreeView_GetPrevVisible(hwndTV,
  1010.               TreeView_GetSelection(hwndTV)),TVGN_CARET);
  1011.           PostMessage(hwnd,WM_NEXTDLGCTL,(WPARAM)(GetDlgItem(hwnd,IDC_STYLEEDIT)),1);
  1012.           break;
  1013.         case IDC_NEXTSTYLE:
  1014.           if (TreeView_GetSelection(hwndTV))
  1015.             TreeView_Select(hwndTV,TreeView_GetNextVisible(hwndTV,
  1016.               TreeView_GetSelection(hwndTV)),TVGN_CARET);
  1017.           PostMessage(hwnd,WM_NEXTDLGCTL,(WPARAM)(GetDlgItem(hwnd,IDC_STYLEEDIT)),1);
  1018.           break;
  1019.         case IDC_STYLEFONT:
  1020.           if (pCurrentStyle)
  1021.           {
  1022.             WCHAR tch[256];
  1023.             GetDlgItemText(hwnd,IDC_STYLEEDIT,tch,COUNTOF(tch));
  1024.             if (Style_SelectFont(hwnd,tch,COUNTOF(tch),
  1025.                   lstrcmpi(pCurrentStyle->pszName,L"Default Style") == 0 ||
  1026.                   lstrcmpi(pCurrentStyle->pszName,L"2nd Default Style") == 0)) {
  1027.               SetDlgItemText(hwnd,IDC_STYLEEDIT,tch);
  1028.               //CheckDlgButton(hwnd,IDC_STYLEBOLD,(Style_StrGetAttribute(tch,L"bold") ? BST_CHECKED : BST_UNCHECKED));
  1029.               //CheckDlgButton(hwnd,IDC_STYLEITALIC,(Style_StrGetAttribute(tch,L"italic") ? BST_CHECKED : BST_UNCHECKED));
  1030.               //CheckDlgButton(hwnd,IDC_STYLEUNDERLINE,(Style_StrGetAttribute(tch,L"underline") ? BST_CHECKED : BST_UNCHECKED));
  1031.               //CheckDlgButton(hwnd,IDC_STYLEEOLFILLED,(Style_StrGetAttribute(tch,L"eolfilled") ? BST_CHECKED : BST_UNCHECKED));
  1032.             }
  1033.           }
  1034.           PostMessage(hwnd,WM_NEXTDLGCTL,(WPARAM)(GetDlgItem(hwnd,IDC_STYLEEDIT)),1);
  1035.           break;
  1036.         case IDC_STYLEFORE:
  1037.           if (pCurrentStyle)
  1038.           {
  1039.             WCHAR tch[256];
  1040.             GetDlgItemText(hwnd,IDC_STYLEEDIT,tch,COUNTOF(tch));
  1041.             if (Style_SelectColor(hwnd,TRUE,tch,COUNTOF(tch))) {
  1042.               SetDlgItemText(hwnd,IDC_STYLEEDIT,tch);
  1043.               //CheckDlgButton(hwnd,IDC_STYLEBOLD,(Style_StrGetAttribute(tch,L"bold") ? BST_CHECKED : BST_UNCHECKED));
  1044.               //CheckDlgButton(hwnd,IDC_STYLEITALIC,(Style_StrGetAttribute(tch,L"italic") ? BST_CHECKED : BST_UNCHECKED));
  1045.               //CheckDlgButton(hwnd,IDC_STYLEUNDERLINE,(Style_StrGetAttribute(tch,L"underline") ? BST_CHECKED : BST_UNCHECKED));
  1046.               //CheckDlgButton(hwnd,IDC_STYLEEOLFILLED,(Style_StrGetAttribute(tch,L"eolfilled") ? BST_CHECKED : BST_UNCHECKED));
  1047.             }
  1048.           }
  1049.           PostMessage(hwnd,WM_NEXTDLGCTL,(WPARAM)(GetDlgItem(hwnd,IDC_STYLEEDIT)),1);
  1050.           break;
  1051.         case IDC_STYLEBACK:
  1052.           if (pCurrentStyle)
  1053.           {
  1054.             WCHAR tch[256];
  1055.             GetDlgItemText(hwnd,IDC_STYLEEDIT,tch,COUNTOF(tch));
  1056.             if (Style_SelectColor(hwnd,FALSE,tch,COUNTOF(tch))) {
  1057.               SetDlgItemText(hwnd,IDC_STYLEEDIT,tch);
  1058.               //CheckDlgButton(hwnd,IDC_STYLEBOLD,(Style_StrGetAttribute(tch,L"bold") ? BST_CHECKED : BST_UNCHECKED));
  1059.               //CheckDlgButton(hwnd,IDC_STYLEITALIC,(Style_StrGetAttribute(tch,L"italic") ? BST_CHECKED : BST_UNCHECKED));
  1060.               //CheckDlgButton(hwnd,IDC_STYLEUNDERLINE,(Style_StrGetAttribute(tch,L"underline") ? BST_CHECKED : BST_UNCHECKED));
  1061.               //CheckDlgButton(hwnd,IDC_STYLEEOLFILLED,(Style_StrGetAttribute(tch,L"eolfilled") ? BST_CHECKED : BST_UNCHECKED));
  1062.             }
  1063.           }
  1064.           PostMessage(hwnd,WM_NEXTDLGCTL,(WPARAM)(GetDlgItem(hwnd,IDC_STYLEEDIT)),1);
  1065.           break;
  1066.         case IDC_STYLEDEFAULT:
  1067.           if (pCurrentStyle)
  1068.           {
  1069.             lstrcpy(pCurrentStyle->szValue,pCurrentStyle->pszDefault);
  1070.             SetDlgItemText(hwnd,IDC_STYLEEDIT,pCurrentStyle->szValue);
  1071.             //CheckDlgButton(hwnd,IDC_STYLEBOLD,(Style_StrGetAttribute(pCurrentStyle->szValue,L"bold") ? BST_CHECKED : BST_UNCHECKED));
  1072.             //CheckDlgButton(hwnd,IDC_STYLEITALIC,(Style_StrGetAttribute(pCurrentStyle->szValue,L"italic") ? BST_CHECKED : BST_UNCHECKED));
  1073.             //CheckDlgButton(hwnd,IDC_STYLEUNDERLINE,(Style_StrGetAttribute(pCurrentStyle->szValue,L"underline") ? BST_CHECKED : BST_UNCHECKED));
  1074.             //CheckDlgButton(hwnd,IDC_STYLEEOLFILLED,(Style_StrGetAttribute(pCurrentStyle->szValue,L"eolfilled") ? BST_CHECKED : BST_UNCHECKED));
  1075.           }
  1076.           else if (pCurrentLexer) {
  1077.             lstrcpy(pCurrentLexer->szExtensions,pCurrentLexer->pszDefExt);
  1078.             SetDlgItemText(hwnd,IDC_STYLEEDIT,pCurrentLexer->szExtensions);
  1079.           }
  1080.           PostMessage(hwnd,WM_NEXTDLGCTL,(WPARAM)(GetDlgItem(hwnd,IDC_STYLEEDIT)),1);
  1081.           break;
  1082.         //case IDC_STYLEBOLD:
  1083.         //  if (pCurrentStyle)
  1084.         //  {
  1085.         //    WCHAR tch[256];
  1086.         //    GetDlgItemText(hwnd,IDC_STYLEEDIT,tch,COUNTOF(tch));
  1087.         //    Style_StrSetAttribute(tch,COUNTOF(tch),L"bold",IsDlgButtonChecked(hwnd,IDC_STYLEBOLD));
  1088.         //    SetDlgItemText(hwnd,IDC_STYLEEDIT,tch);
  1089.         //  }
  1090.         //  break;
  1091.         //case IDC_STYLEITALIC:
  1092.         //  if (pCurrentStyle)
  1093.         //  {
  1094.         //    WCHAR tch[256];
  1095.         //    GetDlgItemText(hwnd,IDC_STYLEEDIT,tch,COUNTOF(tch));
  1096.         //    Style_StrSetAttribute(tch,COUNTOF(tch),L"italic",IsDlgButtonChecked(hwnd,IDC_STYLEITALIC));
  1097.         //    SetDlgItemText(hwnd,IDC_STYLEEDIT,tch);
  1098.         //  }
  1099.         //  break;
  1100.         //case IDC_STYLEUNDERLINE:
  1101.         //  if (pCurrentStyle)
  1102.         //  {
  1103.         //    WCHAR tch[256];
  1104.         //    GetDlgItemText(hwnd,IDC_STYLEEDIT,tch,COUNTOF(tch));
  1105.         //    Style_StrSetAttribute(tch,COUNTOF(tch),L"underline",IsDlgButtonChecked(hwnd,IDC_STYLEUNDERLINE));
  1106.         //    SetDlgItemText(hwnd,IDC_STYLEEDIT,tch);
  1107.         //  }
  1108.         //  break;
  1109.         //case IDC_STYLEEOLFILLED:
  1110.         //  if (pCurrentStyle)
  1111.         //  {
  1112.         //    WCHAR tch[256];
  1113.         //    GetDlgItemText(hwnd,IDC_STYLEEDIT,tch,COUNTOF(tch));
  1114.         //    Style_StrSetAttribute(tch,COUNTOF(tch),L"eolfilled",IsDlgButtonChecked(hwnd,IDC_STYLEEOLFILLED));
  1115.         //    SetDlgItemText(hwnd,IDC_STYLEEDIT,tch);
  1116.         //  }
  1117.         //  break;
  1118.         case IDC_STYLEEDIT:
  1119.           {
  1120.             if (HIWORD(wParam) == EN_CHANGE) {
  1121.               int cr;
  1122.               WCHAR tch[256];
  1123.               GetDlgItemText(hwnd,IDC_STYLEEDIT,tch,COUNTOF(tch));
  1124.               cr = -1;
  1125.               Style_StrGetColor(TRUE,tch,&cr);
  1126.               MakeColorPickButton(hwnd,IDC_STYLEFORE,g_hInstance,cr);
  1127.               cr = -1;
  1128.               Style_StrGetColor(FALSE,tch,&cr);
  1129.               MakeColorPickButton(hwnd,IDC_STYLEBACK,g_hInstance,cr);
  1130.             }
  1131.           }
  1132.           break;
  1133.         case IDC_IMPORT:
  1134.           {
  1135.             HWND hwndTV = GetDlgItem(hwnd,IDC_STYLELIST);
  1136.             if (pCurrentStyle)
  1137.               GetDlgItemText(hwnd,IDC_STYLEEDIT,pCurrentStyle->szValue,COUNTOF(pCurrentStyle->szValue));
  1138.             else if (pCurrentLexer) {
  1139.               if (!GetDlgItemText(hwnd,IDC_STYLEEDIT,pCurrentLexer->szExtensions,COUNTOF(pCurrentLexer->szExtensions)))
  1140.                 lstrcpy(pCurrentLexer->szExtensions,pCurrentLexer->pszDefExt);
  1141.             }
  1142.             if (Style_Import(hwnd)) {
  1143.               if (pCurrentStyle)
  1144.                 SetDlgItemText(hwnd,IDC_STYLEEDIT,pCurrentStyle->szValue);
  1145.               else if (pCurrentLexer)
  1146.                 SetDlgItemText(hwnd,IDC_STYLEEDIT,pCurrentLexer->szExtensions);
  1147.               TreeView_Select(hwndTV,TreeView_GetRoot(hwndTV),TVGN_CARET);
  1148.               MsgBox(0,IDS_IMPORT_OK);
  1149.             }
  1150.           }
  1151.           break;
  1152.         case IDC_EXPORT:
  1153.           {
  1154.             if (pCurrentStyle)
  1155.               GetDlgItemText(hwnd,IDC_STYLEEDIT,pCurrentStyle->szValue,COUNTOF(pCurrentStyle->szValue));
  1156.             else if (pCurrentLexer) {
  1157.               if (!GetDlgItemText(hwnd,IDC_STYLEEDIT,pCurrentLexer->szExtensions,COUNTOF(pCurrentLexer->szExtensions)))
  1158.                 lstrcpy(pCurrentLexer->szExtensions,pCurrentLexer->pszDefExt);
  1159.             }
  1160.             if (Style_Export(hwnd))
  1161.               MsgBox(0,IDS_EXPORT_OK);
  1162.           }
  1163.           break;
  1164.         case IDC_PREVIEW:
  1165.           {
  1166.             // Hack from outside
  1167.             extern HWND hwndEdit;
  1168.             extern void UpdateLineNumerWidth();
  1169.             if (pCurrentStyle)
  1170.               GetDlgItemText(hwnd,IDC_STYLEEDIT,pCurrentStyle->szValue,COUNTOF(pCurrentStyle->szValue));
  1171.             else if (pCurrentLexer) {
  1172.               if (!GetDlgItemText(hwnd,IDC_STYLEEDIT,pCurrentLexer->szExtensions,COUNTOF(pCurrentLexer->szExtensions)))
  1173.                 lstrcpy(pCurrentLexer->szExtensions,pCurrentLexer->pszDefExt);
  1174.             }
  1175.             Style_SetLexer(hwndEdit,pLexCurrent);
  1176.             UpdateLineNumberWidth();
  1177.           }
  1178.           break;
  1179.         case IDOK:
  1180.           if (pCurrentStyle)
  1181.             GetDlgItemText(hwnd,IDC_STYLEEDIT,pCurrentStyle->szValue,COUNTOF(pCurrentStyle->szValue));
  1182.           else if (pCurrentLexer) {
  1183.             if (!GetDlgItemText(hwnd,IDC_STYLEEDIT,pCurrentLexer->szExtensions,COUNTOF(pCurrentLexer->szExtensions)))
  1184.               lstrcpy(pCurrentLexer->szExtensions,pCurrentLexer->pszDefExt);
  1185.           }
  1186.           EndDialog(hwnd,IDOK);
  1187.           break;
  1188.         case IDCANCEL:
  1189.           if (fDragging)
  1190.             SendMessage(hwnd,WM_CANCELMODE,0,0);
  1191.           else
  1192.             EndDialog(hwnd,IDCANCEL);
  1193.           break;
  1194.       }
  1195.       return TRUE;
  1196.   }
  1197.   return FALSE;
  1198. }
  1199. //=============================================================================
  1200. //
  1201. //  Style_ConfigDlg()
  1202. //
  1203. void Style_ConfigDlg(HWND hwnd)
  1204. {
  1205.   WCHAR *StyleBackup[1024];
  1206.   int c,cItems,i,iLexer;
  1207.   // Backup Styles
  1208.   c = 0;
  1209.   for (iLexer = 0; iLexer < NUMLEXERS; iLexer++) {
  1210.     StyleBackup[c++] = StrDup(pLexArray[iLexer]->szExtensions);
  1211.     i = 0;
  1212.     while (pLexArray[iLexer]->Styles[i].iStyle != -1) {
  1213.       StyleBackup[c++] = StrDup(pLexArray[iLexer]->Styles[i].szValue);
  1214.       i++;
  1215.     }
  1216.   }
  1217.   cItems = c;
  1218.   if (IDCANCEL == ThemedDialogBoxParam(g_hInstance,
  1219.                     MAKEINTRESOURCE(IDD_STYLECONFIG),
  1220.                     GetParent(hwnd),Style_ConfigDlgProc,
  1221.                     (LPARAM)&StyleBackup))
  1222.   {
  1223.     // Restore Styles
  1224.     c = 0;
  1225.     for (iLexer = 0; iLexer < NUMLEXERS; iLexer++) {
  1226.       lstrcpy(pLexArray[iLexer]->szExtensions,StyleBackup[c++]);
  1227.       i = 0;
  1228.       while (pLexArray[iLexer]->Styles[i].iStyle != -1) {
  1229.         lstrcpy(pLexArray[iLexer]->Styles[i].szValue,StyleBackup[c++]);
  1230.         i++;
  1231.       }
  1232.     }
  1233.   }
  1234.   else {
  1235.     fStylesModified = TRUE;
  1236.     if (lstrlen(szIniFile) == 0 && !fWarnedNoIniFile) {
  1237.       MsgBox(MBINFO,IDS_SETTINGSNOTSAVED);
  1238.       fWarnedNoIniFile = TRUE;
  1239.     }
  1240.   }
  1241.   for (c = 0; c < cItems; c++)
  1242.     LocalFree(StyleBackup[c]);
  1243.   // Apply new (or previous) Styles
  1244.   Style_SetLexer(hwnd,pLexCurrent);
  1245. }
  1246. //=============================================================================
  1247. //
  1248. //  Style_SelectLexerDlgProc()
  1249. //
  1250. BOOL CALLBACK Style_SelectLexerDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam)
  1251. {
  1252.   static int cxClient;
  1253.   static int cyClient;
  1254.   static int mmiPtMaxY;
  1255.   static int mmiPtMinX;
  1256.   static HWND hwndLV;
  1257.   static int  iInternalDefault;
  1258.   switch(umsg)
  1259.   {
  1260.     case WM_INITDIALOG:
  1261.       {
  1262.         int i;
  1263.         int lvItems;
  1264.         LVITEM lvi;
  1265.         SHFILEINFO shfi;
  1266.         LVCOLUMN lvc = { LVCF_FMT|LVCF_TEXT, LVCFMT_LEFT, 0, L"", -1, 0, 0, 0 };
  1267.         RECT rc;
  1268.         WCHAR tch[MAX_PATH];
  1269.         int cGrip;
  1270.         GetClientRect(hwnd,&rc);
  1271.         cxClient = rc.right - rc.left;
  1272.         cyClient = rc.bottom - rc.top;
  1273.         AdjustWindowRectEx(&rc,GetWindowLongPtr(hwnd,GWL_STYLE)|WS_THICKFRAME,FALSE,0);
  1274.         mmiPtMinX = rc.right-rc.left;
  1275.         mmiPtMaxY = rc.bottom-rc.top;
  1276.         if (cxStyleSelectDlg < (rc.right-rc.left))
  1277.           cxStyleSelectDlg = rc.right-rc.left;
  1278.         if (cyStyleSelectDlg < (rc.bottom-rc.top))
  1279.           cyStyleSelectDlg = rc.bottom-rc.top;
  1280.         SetWindowPos(hwnd,NULL,rc.left,rc.top,cxStyleSelectDlg,cyStyleSelectDlg,SWP_NOZORDER);
  1281.         SetWindowLongPtr(hwnd,GWL_STYLE,GetWindowLongPtr(hwnd,GWL_STYLE)|WS_THICKFRAME);
  1282.         SetWindowPos(hwnd,NULL,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_FRAMECHANGED);
  1283.         GetMenuString(GetSystemMenu(GetParent(hwnd),FALSE),SC_SIZE,tch,COUNTOF(tch),MF_BYCOMMAND);
  1284.         InsertMenu(GetSystemMenu(hwnd,FALSE),SC_CLOSE,MF_BYCOMMAND|MF_STRING|MF_ENABLED,SC_SIZE,tch);
  1285.         InsertMenu(GetSystemMenu(hwnd,FALSE),SC_CLOSE,MF_BYCOMMAND|MF_SEPARATOR,0,NULL);
  1286.         SetWindowLongPtr(GetDlgItem(hwnd,IDC_RESIZEGRIP3),GWL_STYLE,
  1287.           GetWindowLongPtr(GetDlgItem(hwnd,IDC_RESIZEGRIP3),GWL_STYLE)|SBS_SIZEGRIP|WS_CLIPSIBLINGS);
  1288.         cGrip = GetSystemMetrics(SM_CXHTHUMB);
  1289.         SetWindowPos(GetDlgItem(hwnd,IDC_RESIZEGRIP3),NULL,cxClient-cGrip,
  1290.                      cyClient-cGrip,cGrip,cGrip,SWP_NOZORDER);
  1291.         hwndLV = GetDlgItem(hwnd,IDC_STYLELIST);
  1292.         ListView_SetImageList(hwndLV,
  1293.           (HIMAGELIST)SHGetFileInfo(L"C:\",0,&shfi,sizeof(SHFILEINFO),SHGFI_SMALLICON | SHGFI_SYSICONINDEX),
  1294.           LVSIL_SMALL);
  1295.         ListView_SetImageList(hwndLV,
  1296.           (HIMAGELIST)SHGetFileInfo(L"C:\",0,&shfi,sizeof(SHFILEINFO),SHGFI_LARGEICON | SHGFI_SYSICONINDEX),
  1297.           LVSIL_NORMAL);
  1298.         //SetExplorerTheme(hwndLV);
  1299.         ListView_SetExtendedListViewStyle(hwndLV,/*LVS_EX_FULLROWSELECT|*/LVS_EX_DOUBLEBUFFER|LVS_EX_LABELTIP);
  1300.         ListView_InsertColumn(hwndLV,0,&lvc);
  1301.         // Add lexers
  1302.         for (i = 0; i < NUMLEXERS; i++)
  1303.           Style_AddLexerToListView(hwndLV,pLexArray[i]);
  1304.         ListView_SetColumnWidth(hwndLV,0,LVSCW_AUTOSIZE_USEHEADER);
  1305.         // Select current lexer
  1306.         lvItems = ListView_GetItemCount(hwndLV);
  1307.         lvi.mask = LVIF_PARAM;
  1308.         for (i = 0; i < lvItems; i++) {
  1309.           lvi.iItem = i;
  1310.           ListView_GetItem(hwndLV,&lvi);;
  1311.           if (lstrcmp(((PEDITLEXER)lvi.lParam)->pszName,pLexCurrent->pszName) == 0) {
  1312.             ListView_SetItemState(hwndLV,i,LVIS_FOCUSED|LVIS_SELECTED,LVIS_FOCUSED|LVIS_SELECTED);
  1313.             ListView_EnsureVisible(hwndLV,i,FALSE);
  1314.             if (iDefaultLexer == i) {
  1315.               CheckDlgButton(hwnd,IDC_DEFAULTSCHEME,BST_CHECKED);
  1316.             }
  1317.           }
  1318.         }
  1319.         iInternalDefault = iDefaultLexer;
  1320.         if (bAutoSelect)
  1321.           CheckDlgButton(hwnd,IDC_AUTOSELECT,BST_CHECKED);
  1322.         CenterDlgInParent(hwnd);
  1323.       }
  1324.       return TRUE;
  1325.     case WM_DESTROY:
  1326.       {
  1327.         RECT rc;
  1328.         GetWindowRect(hwnd,&rc);
  1329.         cxStyleSelectDlg = rc.right-rc.left;
  1330.         cyStyleSelectDlg = rc.bottom-rc.top;
  1331.       }
  1332.       return FALSE;
  1333.     case WM_SIZE:
  1334.       {
  1335.         RECT rc;
  1336.         int dxClient = LOWORD(lParam) - cxClient;
  1337.         int dyClient = HIWORD(lParam) - cyClient;
  1338.         cxClient = LOWORD(lParam);
  1339.         cyClient = HIWORD(lParam);
  1340.         GetWindowRect(GetDlgItem(hwnd,IDC_RESIZEGRIP3),&rc);
  1341.         MapWindowPoints(NULL,hwnd,(LPPOINT)&rc,2);
  1342.         SetWindowPos(GetDlgItem(hwnd,IDC_RESIZEGRIP3),NULL,rc.left+dxClient,rc.top+dyClient,0,0,SWP_NOZORDER|SWP_NOSIZE);
  1343.         InvalidateRect(GetDlgItem(hwnd,IDC_RESIZEGRIP3),NULL,TRUE);
  1344.         GetWindowRect(GetDlgItem(hwnd,IDOK),&rc);
  1345.         MapWindowPoints(NULL,hwnd,(LPPOINT)&rc,2);
  1346.         SetWindowPos(GetDlgItem(hwnd,IDOK),NULL,rc.left+dxClient,rc.top+dyClient,0,0,SWP_NOZORDER|SWP_NOSIZE);
  1347.         InvalidateRect(GetDlgItem(hwnd,IDOK),NULL,TRUE);
  1348.         GetWindowRect(GetDlgItem(hwnd,IDCANCEL),&rc);
  1349.         MapWindowPoints(NULL,hwnd,(LPPOINT)&rc,2);
  1350.         SetWindowPos(GetDlgItem(hwnd,IDCANCEL),NULL,rc.left+dxClient,rc.top+dyClient,0,0,SWP_NOZORDER|SWP_NOSIZE);
  1351.         InvalidateRect(GetDlgItem(hwnd,IDCANCEL),NULL,TRUE);
  1352.         GetWindowRect(GetDlgItem(hwnd,IDC_STYLELIST),&rc);
  1353.         MapWindowPoints(NULL,hwnd,(LPPOINT)&rc,2);
  1354.         SetWindowPos(GetDlgItem(hwnd,IDC_STYLELIST),NULL,0,0,rc.right-rc.left+dxClient,rc.bottom-rc.top+dyClient,SWP_NOZORDER|SWP_NOMOVE);
  1355.         ListView_SetColumnWidth(GetDlgItem(hwnd,IDC_STYLELIST),0,LVSCW_AUTOSIZE_USEHEADER);
  1356.         InvalidateRect(GetDlgItem(hwnd,IDC_STYLELIST),NULL,TRUE);
  1357.         GetWindowRect(GetDlgItem(hwnd,IDC_AUTOSELECT),&rc);
  1358.         MapWindowPoints(NULL,hwnd,(LPPOINT)&rc,2);
  1359.         SetWindowPos(GetDlgItem(hwnd,IDC_AUTOSELECT),NULL,rc.left,rc.top+dyClient,0,0,SWP_NOZORDER|SWP_NOSIZE);
  1360.         InvalidateRect(GetDlgItem(hwnd,IDC_AUTOSELECT),NULL,TRUE);
  1361.         GetWindowRect(GetDlgItem(hwnd,IDC_DEFAULTSCHEME),&rc);
  1362.         MapWindowPoints(NULL,hwnd,(LPPOINT)&rc,2);
  1363.         SetWindowPos(GetDlgItem(hwnd,IDC_DEFAULTSCHEME),NULL,rc.left,rc.top+dyClient,0,0,SWP_NOZORDER|SWP_NOSIZE);
  1364.         InvalidateRect(GetDlgItem(hwnd,IDC_DEFAULTSCHEME),NULL,TRUE);
  1365.       }
  1366.       return TRUE;
  1367.     case WM_GETMINMAXINFO:
  1368.       {
  1369.         LPMINMAXINFO lpmmi = (LPMINMAXINFO)lParam;
  1370.         lpmmi->ptMinTrackSize.x = mmiPtMinX;
  1371.         lpmmi->ptMinTrackSize.y = mmiPtMaxY;
  1372.         //lpmmi->ptMaxTrackSize.y = mmiPtMaxY;
  1373.       }
  1374.       return TRUE;
  1375.     case WM_NOTIFY: {
  1376.       if (((LPNMHDR)(lParam))->idFrom == IDC_STYLELIST) {
  1377.       switch (((LPNMHDR)(lParam))->code) {
  1378.         case NM_DBLCLK:
  1379.           SendMessage(hwnd,WM_COMMAND,MAKELONG(IDOK,1),0);
  1380.           break;
  1381.         case LVN_ITEMCHANGED:
  1382.         case LVN_DELETEITEM: {
  1383.           int i = ListView_GetNextItem(hwndLV,-1,LVNI_ALL | LVNI_SELECTED);
  1384.           if (iInternalDefault == i)
  1385.             CheckDlgButton(hwnd,IDC_DEFAULTSCHEME,BST_CHECKED);
  1386.           else
  1387.             CheckDlgButton(hwnd,IDC_DEFAULTSCHEME,BST_UNCHECKED);
  1388.           EnableWindow(GetDlgItem(hwnd,IDC_DEFAULTSCHEME),i != -1);
  1389.           EnableWindow(GetDlgItem(hwnd,IDOK),i != -1);
  1390.           }
  1391.           break;
  1392.         }
  1393.       }
  1394.     }
  1395.       return TRUE;
  1396.     case WM_COMMAND:
  1397.       switch(LOWORD(wParam))
  1398.       {
  1399.         case IDC_DEFAULTSCHEME:
  1400.           if (IsDlgButtonChecked(hwnd,IDC_DEFAULTSCHEME) == BST_CHECKED)
  1401.             iInternalDefault = ListView_GetNextItem(hwndLV,-1,LVNI_ALL | LVNI_SELECTED);
  1402.           else
  1403.             iInternalDefault = 0;
  1404.           break;
  1405.         case IDOK:
  1406.           {
  1407.             LVITEM lvi;
  1408.             lvi.mask = LVIF_PARAM;
  1409.             lvi.iItem = ListView_GetNextItem(hwndLV,-1,LVNI_ALL | LVNI_SELECTED);
  1410.             if (ListView_GetItem(hwndLV,&lvi)) {
  1411.               pLexCurrent = (PEDITLEXER)lvi.lParam;
  1412.               iDefaultLexer = iInternalDefault;
  1413.               bAutoSelect = (IsDlgButtonChecked(hwnd,IDC_AUTOSELECT) == BST_CHECKED) ? 1 : 0;
  1414.               EndDialog(hwnd,IDOK);
  1415.             }
  1416.           }
  1417.           break;
  1418.         case IDCANCEL:
  1419.           EndDialog(hwnd,IDCANCEL);
  1420.           break;
  1421.       }
  1422.       return TRUE;
  1423.   }
  1424.   return FALSE;
  1425. }
  1426. //=============================================================================
  1427. //
  1428. //  Style_SelectLexerDlg()
  1429. //
  1430. void Style_SelectLexerDlg(HWND hwnd)
  1431. {
  1432.   if (IDOK == ThemedDialogBoxParam(g_hInstance,
  1433.                 MAKEINTRESOURCE(IDD_STYLESELECT),
  1434.                 GetParent(hwnd),Style_SelectLexerDlgProc,0))
  1435.     Style_SetLexer(hwnd,pLexCurrent);
  1436. }
  1437. // End of Styles.c