home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / prefs / brpref / src / appages.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  23.3 KB  |  818 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #include "pch.h"
  20. #include <assert.h>
  21. #include "dllcom.h"
  22. #include "pages.h"
  23. #include "colorbtn.h"
  24. #include "resource.h"
  25. #include "xp_core.h"
  26. #include "xp_help.h"
  27. #include "prefapi.h"
  28. #include "brprefid.h"
  29. #include "csid.h"
  30.  
  31. #include "fe_proto.h"
  32.  
  33.  
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CAppearancePrefs implementation
  36.  
  37. CAppearancePrefs::CAppearancePrefs()
  38.     : CBrowserPropertyPage(IDD_APPEARANCE, HELP_PREFS_APPEARANCE)
  39. {
  40. }
  41.  
  42. BOOL
  43. CAppearancePrefs::InitDialog()
  44. {
  45.     // Only enable the Use Current Page button if we were given a URL
  46.     //EnableDlgItem(IDC_CHECK5, FE_IsNetcasterInstalled());
  47.  
  48.     BOOL result = CBrowserPropertyPage::InitDialog();
  49.  
  50.     EnableDlgItem(IDC_CHECK1, !PREF_PrefIsLocked("general.startup.browser"));
  51. #ifdef MOZ_MAIL_NEWS
  52.     EnableDlgItem(IDC_CHECK2, !PREF_PrefIsLocked("general.startup.mail"));
  53.     EnableDlgItem(IDC_CHECK3, !PREF_PrefIsLocked("general.startup.news"));
  54. #ifdef EDITOR
  55.     EnableDlgItem(IDC_CHECK4, !PREF_PrefIsLocked("general.startup.editor"));
  56. #endif /* EDITOR */
  57. #endif /* MOZ_MAIL_NEWS */
  58. #if !defined(WIN16)   
  59.     EnableDlgItem(IDC_CHECK5, !PREF_PrefIsLocked("general.startup.netcaster"));
  60. #endif   
  61.     if (PREF_PrefIsLocked("browser.chrome.button_style"))
  62.     {
  63.         DisableRadioButtonGroup(IDC_RADIO1);
  64.     }
  65.     return result;
  66.     
  67.     
  68. }
  69.  
  70. // Initialize member data using XP preferences
  71. STDMETHODIMP
  72. CAppearancePrefs::Activate(HWND hwndParent, LPCRECT lprc, BOOL bModal)
  73. {
  74.     if (!m_bHasBeenActivated) {
  75.         // Startup mode
  76.         PREF_GetBoolPref("general.startup.browser", &m_bStartupBrowser);
  77.         PREF_GetBoolPref("general.startup.mail", &m_bStartupMail);
  78.         PREF_GetBoolPref("general.startup.news", &m_bStartupNews);
  79.         PREF_GetBoolPref("general.startup.editor", &m_bStartupEditor);
  80. #if !defined(WIN16)      
  81.         PREF_GetBoolPref("general.startup.netcaster", &m_bStartupNetcaster);
  82. #endif      
  83.  
  84.         if (!m_bStartupMail && !m_bStartupNews && !m_bStartupEditor && !m_bStartupNetcaster)
  85.             m_bStartupBrowser = TRUE;  // make sure something is set
  86.  
  87.         // Toolbar style
  88.         int32    nToolbarStyle;
  89.         
  90.         PREF_GetIntPref("browser.chrome.button_style", &nToolbarStyle);
  91.         m_nShowToolbarAs = (int)nToolbarStyle;
  92.     }
  93.  
  94.     return CBrowserPropertyPage::Activate(hwndParent, lprc, bModal);
  95. }
  96.  
  97. BOOL
  98. CAppearancePrefs::DoTransfer(BOOL bSaveAndValidate)
  99. {
  100.     CheckBoxTransfer(IDC_CHECK1, m_bStartupBrowser, bSaveAndValidate);
  101. #ifdef MOZ_MAIL_NEWS
  102.     CheckBoxTransfer(IDC_CHECK2, m_bStartupMail, bSaveAndValidate);
  103.     CheckBoxTransfer(IDC_CHECK3, m_bStartupNews, bSaveAndValidate);
  104. #endif /* MOZ_MAIL_NEWS */
  105. #ifdef EDITOR
  106.     CheckBoxTransfer(IDC_CHECK4, m_bStartupEditor, bSaveAndValidate);
  107. #endif /* EDITOR */
  108. #if !defined(WIN16)
  109.     CheckBoxTransfer(IDC_CHECK5, m_bStartupNetcaster, bSaveAndValidate);
  110. #endif   
  111.     RadioButtonTransfer(IDC_RADIO1, m_nShowToolbarAs, bSaveAndValidate);
  112.     return TRUE;
  113. }
  114.  
  115. // Apply changes using XP preferences
  116. BOOL
  117. CAppearancePrefs::ApplyChanges()
  118. {
  119.     if (!m_bStartupMail && !m_bStartupNews && !m_bStartupEditor && !m_bStartupNetcaster)
  120.         m_bStartupBrowser = TRUE;  // make sure something is set
  121.     
  122.     PREF_SetBoolPref("general.startup.browser", m_bStartupBrowser);
  123. #ifdef MOZ_MAIL_NEWS
  124.     PREF_SetBoolPref("general.startup.mail", m_bStartupMail);
  125.     PREF_SetBoolPref("general.startup.news", m_bStartupNews);
  126. #endif /* MOZ_MAIL_NEWS */
  127. #ifdef EDITOR
  128.     PREF_SetBoolPref("general.startup.editor", m_bStartupEditor);
  129. #endif /* EDITOR */
  130. #if !defined(WIN16)
  131.     PREF_SetBoolPref("general.startup.netcaster", m_bStartupNetcaster);
  132. #endif   
  133.  
  134.     PREF_SetIntPref("browser.chrome.button_style", (int32)m_nShowToolbarAs);
  135.     return TRUE;
  136. }
  137.  
  138. /////////////////////////////////////////////////////////////////////////////
  139. // CFontsPrefs implementation
  140.  
  141. CFontsPrefs::CFontsPrefs()
  142.     : CBrowserPropertyPage(IDD_FONTS, HELP_PREFS_APPEARANCE_FONTS)
  143. {
  144.     m_lpIntlFont = NULL;
  145.     m_nMaxFontHeight = 0;
  146.     m_bDBCSEnabled = GetSystemMetrics(SM_DBCSENABLED);
  147. }
  148.  
  149.  
  150.  
  151. // Override SetObjects() member function to acquire/release the IIntlFont
  152. // interface pointer
  153. STDMETHODIMP
  154. CFontsPrefs::SetObjects(ULONG cObjects, LPUNKNOWN FAR* ppunk)
  155. {
  156.     HRESULT    hres = CBrowserPropertyPage::SetObjects(cObjects, ppunk);
  157.  
  158.     if (SUCCEEDED(hres)) {
  159.         if (cObjects == 0) {
  160.             assert(m_lpIntlFont);
  161.             if (m_lpIntlFont) {
  162.                 // Release the interface pointer
  163.                 m_lpIntlFont->Release();
  164.                 m_lpIntlFont = NULL;
  165.             }
  166.  
  167.         } else {
  168.             assert(!m_lpIntlFont);
  169.             if (!m_lpIntlFont) {
  170.                 m_pObject->QueryInterface(IID_IIntlFont, (void **)&m_lpIntlFont);
  171.                 assert(m_lpIntlFont);
  172.             }
  173.         }
  174.     }
  175.  
  176.     return hres;
  177. }
  178.  
  179. // Initialize member data using XP preferences
  180. STDMETHODIMP
  181. CFontsPrefs::Activate(HWND hwndParent, LPCRECT lprc, BOOL bModal)
  182. {
  183.     if (!m_bHasBeenActivated) {
  184.         // Webfont preference
  185.         int32    nUseDocFonts;
  186.         
  187.         PREF_GetIntPref("browser.use_document_fonts", &nUseDocFonts);
  188.         m_nUseDocumentFonts = (int)nUseDocFonts;
  189.  
  190.         // Font encoding
  191.         assert(m_lpIntlFont);
  192.         if (m_lpIntlFont) {
  193.             // Get the number of encodings
  194.             m_lpIntlFont->GetNumEncodings(&m_dwEncodings);
  195.  
  196.             // Get the current charset num
  197.             DWORD    dwCharsetNum;
  198.  
  199.             m_lpIntlFont->GetCurrentCharset(&dwCharsetNum);
  200.             m_nCharset = (int)dwCharsetNum;
  201.         }
  202.     }
  203.  
  204.     return CBrowserPropertyPage::Activate(hwndParent, lprc, bModal);
  205. }
  206.  
  207. // Called whenever the value of the encoding combo box is changed.
  208. // Also explicitly called from InitDialog()
  209. void
  210. CFontsPrefs::OnEncodingChanged()
  211. {
  212.     // Get the font and font sizes to use for this encoding
  213.     assert(m_lpIntlFont);
  214.     if (m_lpIntlFont) {
  215.         ENCODINGINFO    info;
  216.  
  217.         // Get the face name and size to use for this encoding
  218.         m_lpIntlFont->GetEncodingInfo(m_nCharset, &info);
  219.         m_strVariableFaceName = info.szVariableWidthFont;
  220.         m_nVariableSize = info.nVariableWidthSize;
  221.         m_strFixedFaceName = info.szFixedWidthFont;
  222.         m_nFixedSize = info.nFixedWidthSize;
  223.         
  224.         // Update the list of fonts from which to choose. The reason we do this
  225.         // here is that for some encodings we show both proportional and fixed
  226.         // fonts in both font lists. The reason for this is that multi-byte fonts
  227.         // are huge and some people don't have both a proportional and fixed font
  228.         FillFontFace(info.bIgnorePitch);
  229.     }
  230. }
  231.  
  232. int CALLBACK
  233. EnumVariableWidthFonts(LPLOGFONT lpnlf, LPTEXTMETRIC lpntm, int nFontType, LPARAM lParam)
  234. {
  235.     if (lpntm->tmPitchAndFamily & TMPF_FIXED_PITCH) {
  236.         // Ignore fonts with SYMBOL charset and ignore raster fonts
  237.         if ((lpntm->tmCharSet != SYMBOL_CHARSET) && (lpntm->tmPitchAndFamily & (TMPF_VECTOR|TMPF_DEVICE|TMPF_TRUETYPE))) {
  238.             ComboBox_AddString((HWND)lParam, lpnlf->lfFaceName);
  239.         }
  240.     }
  241.     
  242.     return TRUE;
  243. }
  244.  
  245. int CALLBACK
  246. EnumFixedWidthFonts(LPLOGFONT lpnlf, LPTEXTMETRIC lpntm, int nFontType, LPARAM lParam)
  247. {
  248.     if ((lpntm->tmPitchAndFamily & TMPF_FIXED_PITCH) == 0) {
  249.         // Ignore fonts with SYMBOL charset and ignore raster fonts
  250.         if ((lpntm->tmCharSet != SYMBOL_CHARSET) && (lpntm->tmPitchAndFamily & (TMPF_VECTOR|TMPF_DEVICE|TMPF_TRUETYPE))) {
  251.             ComboBox_AddString((HWND)lParam, lpnlf->lfFaceName);
  252.         }
  253.     }
  254.  
  255.     return TRUE;
  256. }
  257.  
  258. int CALLBACK
  259. EnumFontsIgnorePitch(LPLOGFONT lpnlf, LPTEXTMETRIC lpntm, int nFontType, LPARAM lParam)
  260. {
  261.     // Ignore fonts with SYMBOL charset and ignore raster fonts
  262.     if ((lpntm->tmCharSet != SYMBOL_CHARSET) && (lpntm->tmPitchAndFamily & (TMPF_VECTOR|TMPF_DEVICE|TMPF_TRUETYPE)))
  263.         ComboBox_AddString((HWND)lParam, lpnlf->lfFaceName);
  264.     
  265.     return TRUE;
  266. }
  267.  
  268. static void
  269. FillFontSizes(HWND hCombo)
  270. {
  271.     static int    nSizes[] = {8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72,-1};
  272.  
  273.     for (int *pSize = nSizes; *pSize != -1; pSize++) {
  274.         char    szBuf[16];
  275.  
  276.         wsprintf(szBuf, "%i", *pSize);
  277.         ComboBox_AddString(hCombo, szBuf);
  278.     }
  279. }
  280.  
  281. // Ignore pitch if we are doing this for Multibyte text. Multibyte fonts are huge
  282. // and so some people only have one font for both proportional and fixed
  283. void CFontsPrefs::FillFontFace(BOOL bIgnorePitch)
  284. {
  285.     // Load up the list of variable-width fonts
  286.     HDC                hdc = GetDC(m_hwndDlg);
  287.     HWND            hCombo;
  288.     FONTENUMPROC    lpfnEnumProc;
  289.     
  290.     // Fill the list of variable width fonts
  291.     lpfnEnumProc = bIgnorePitch ? (FONTENUMPROC)EnumFontsIgnorePitch :
  292.         (FONTENUMPROC)EnumVariableWidthFonts;
  293.  
  294.     // Clear out the contents of the combo box
  295.     hCombo = GetDlgItem(m_hwndDlg, IDC_COMBO2);
  296.     ComboBox_ResetContent(hCombo);
  297.  
  298. #ifdef _WIN32
  299.     EnumFontFamilies(hdc, NULL, lpfnEnumProc, (LPARAM)hCombo);
  300. #else
  301.     EnumFontFamilies(hdc, NULL, lpfnEnumProc, (LPSTR)hCombo);
  302. #endif
  303.  
  304.     // Fill the list of fixed-width fonts
  305.     lpfnEnumProc = bIgnorePitch ? (FONTENUMPROC)EnumFontsIgnorePitch :
  306.         (FONTENUMPROC)EnumFixedWidthFonts;
  307.     
  308.     hCombo = GetDlgItem(m_hwndDlg, IDC_COMBO4);
  309.     ComboBox_ResetContent(hCombo);
  310.  
  311. #ifdef _WIN32
  312.     EnumFontFamilies(hdc, NULL, lpfnEnumProc, (LPARAM)hCombo);
  313. #else
  314.     EnumFontFamilies(hdc, NULL, lpfnEnumProc, (LPSTR)hCombo);
  315. #endif
  316.     
  317.     ReleaseDC(m_hwndDlg, hdc);
  318. }
  319.  
  320. // If we're on a double-byte character system and the dialog font
  321. // is "MS Sans Serif" or "Helv" then use the system font
  322. BOOL
  323. CFontsPrefs::UseSystemFont()
  324. {
  325.     if (m_bDBCSEnabled) {
  326.         HFONT    hFont = GetWindowFont(m_hwndDlg);
  327.         LOGFONT    font;
  328.     
  329.         font.lfFaceName[0] = '\0';
  330.         GetObject(hFont, sizeof(font), &font);
  331.         return lstrcmp(font.lfFaceName, "MS Sans Serif") == 0 ||
  332.                lstrcmp(font.lfFaceName, "Helv") == 0;
  333.     }
  334.  
  335.     return FALSE;
  336. }
  337.  
  338. void
  339. CFontsPrefs::FillEncodingNames()
  340. {
  341.     assert(m_lpIntlFont);
  342.     if (m_lpIntlFont) {
  343.         HWND    hwndCombo = GetDlgItem(m_hwndDlg, IDC_COMBO1);
  344.  
  345.         // NOTE: we retrieved the number of encodings in member function
  346.         // Activate()
  347.         for (DWORD i = 0; i < m_dwEncodings; i++) {
  348.             LPOLESTR    lpoleName;
  349.             LPCSTR        lpszName;
  350.  
  351.             m_lpIntlFont->GetEncodingName(i, &lpoleName);
  352.             lpszName = AllocTaskAnsiString(lpoleName);  // UNICODE -> ANSI
  353.             CoTaskMemFree(lpoleName);
  354.             ComboBox_AddString(hwndCombo, lpszName);
  355.         }
  356.     }
  357. }
  358.  
  359. BOOL
  360. CFontsPrefs::InitDialog()
  361. {
  362.     // See if we should use the system font for the two font name
  363.     // combo boxes
  364.     if (UseSystemFont()) {
  365.         HFONT    hFont = NULL;
  366.  
  367. #ifdef _WIN32
  368.         hFont = GetStockFont(DEFAULT_GUI_FONT);
  369. #endif
  370.  
  371.         if (!hFont)
  372.             hFont = GetStockFont(SYSTEM_FONT);
  373.  
  374.         SetWindowFont(GetDlgItem(m_hwndDlg, IDC_COMBO2), hFont, FALSE);
  375.         SetWindowFont(GetDlgItem(m_hwndDlg, IDC_COMBO4), hFont, FALSE);
  376.     }
  377.  
  378.     // We don't want the height of the edit-field part of the owner draw
  379.     // combo boxes to be less than the edit-field part of the encoding combo box
  380.     m_nMaxFontHeight = (int)SendMessage(GetDlgItem(m_hwndDlg, IDC_COMBO1),
  381.         CB_GETITEMHEIGHT, (WPARAM)(int)-1, 0);
  382.  
  383.     // Fill in the list of font sizes
  384.     FillFontSizes(GetDlgItem(m_hwndDlg, IDC_COMBO3));
  385.     FillFontSizes(GetDlgItem(m_hwndDlg, IDC_COMBO5));
  386.  
  387.     // Fill the combo box with the list of encoding names
  388.     FillEncodingNames();
  389.  
  390.     // Update the font names and sizes for this encoding. This will
  391.     // also fill the combo boxes that display the list of proportional
  392.     // and fixed fonts from which to choose
  393.     OnEncodingChanged();
  394.     
  395.     // Set the height of the selection field for the proportional and fixed
  396.     // face combo boxes
  397.     SendMessage(GetDlgItem(m_hwndDlg, IDC_COMBO2), CB_SETITEMHEIGHT, (WPARAM)(int)-1,
  398.         (LPARAM)m_nMaxFontHeight);
  399.     SendMessage(GetDlgItem(m_hwndDlg, IDC_COMBO4), CB_SETITEMHEIGHT, (WPARAM)(int)-1,
  400.         (LPARAM)m_nMaxFontHeight);
  401.  
  402.     // See if the preference for using WebFonts is locked
  403.     if (PREF_PrefIsLocked("browser.use_document_fonts")) {
  404.         // Disable all the radio buttons in the group
  405.         DisableRadioButtonGroup(IDC_RADIO1);
  406.     }
  407.  
  408.     return CBrowserPropertyPage::InitDialog();
  409. }
  410.  
  411. BOOL
  412. CFontsPrefs::DoTransfer(BOOL bSaveAndValidate)
  413. {
  414.     if (bSaveAndValidate) {
  415.         CString    strFontSize;
  416.  
  417.         ComboBoxTransfer(IDC_COMBO3, strFontSize, bSaveAndValidate);
  418.         m_nVariableSize = atoi((LPCSTR)strFontSize);
  419.  
  420.         ComboBoxTransfer(IDC_COMBO5, strFontSize, bSaveAndValidate);
  421.         m_nFixedSize = atoi((LPCSTR)strFontSize);
  422.  
  423.     } else {
  424.         char    szBuf[32];
  425.  
  426.         wsprintf(szBuf, "%i", m_nVariableSize);
  427.         ComboBox_SelectString(GetDlgItem(m_hwndDlg, IDC_COMBO3), -1, szBuf);
  428.  
  429.         wsprintf(szBuf, "%i", m_nFixedSize);
  430.         ComboBox_SelectString(GetDlgItem(m_hwndDlg, IDC_COMBO5), -1, szBuf);
  431.     }
  432.  
  433.     ComboBoxTransfer(IDC_COMBO1, m_nCharset, bSaveAndValidate);
  434.     ComboBoxTransfer(IDC_COMBO2, m_strVariableFaceName, bSaveAndValidate);
  435.     ComboBoxTransfer(IDC_COMBO4, m_strFixedFaceName, bSaveAndValidate);
  436.     RadioButtonTransfer(IDC_RADIO1, m_nUseDocumentFonts, bSaveAndValidate);
  437.     return TRUE;
  438. }
  439.  
  440. BOOL
  441. CFontsPrefs::OnCommand(int id, HWND hwndCtl, UINT notifyCode)
  442. {
  443.     if (id == IDC_COMBO1 && notifyCode == CBN_SELCHANGE) {
  444.         // Get the new encoding
  445.         ComboBoxTransfer(IDC_COMBO1, m_nCharset, TRUE);
  446.  
  447.         // Update the font names and sizes for this encoding
  448.         OnEncodingChanged();
  449.         DoTransfer(FALSE);
  450.         return TRUE;
  451.     }
  452.  
  453.     return CBrowserPropertyPage::OnCommand(id, hwndCtl, notifyCode);
  454. }
  455.  
  456. #define LEFT_PADDING    2
  457.  
  458. void
  459. CFontsPrefs::MeasureComboBoxItem(LPMEASUREITEMSTRUCT lpmis)
  460. {
  461.     LOGFONT        lf;
  462.     int            nLen;
  463.     SIZE        size;
  464.     HWND        hwndCtl = GetDlgItem(m_hwndDlg, lpmis->CtlID);
  465.     HFONT        hFont, hOldFont;
  466.     HDC            hDC = GetDC(hwndCtl);
  467.     TEXTMETRIC    tm;
  468.  
  469.     assert(lpmis->itemID != -1);
  470.     if (lpmis->itemID == -1)
  471.         return;
  472.     
  473.     // Initialize the LOGFONT structure
  474.     memset(&lf, 0, sizeof(lf));
  475.  
  476.     // Get the font face name
  477.     nLen = ComboBox_GetLBText(hwndCtl, lpmis->itemID, lf.lfFaceName);
  478.  
  479.     if (m_bDBCSEnabled) {
  480.         // Just use the combo box font
  481.         hFont = GetWindowFont(hwndCtl);
  482.  
  483.     } else {
  484.         // Assume an 8-point font
  485.         lf.lfHeight = (LONG)-MulDiv(8, GetDeviceCaps(hDC, LOGPIXELSY), 72);
  486.         
  487.         // Create a logical font for this face name
  488.         lf.lfWeight = FW_NORMAL;
  489.         lf.lfCharSet = DEFAULT_CHARSET;
  490.         lf.lfQuality = PROOF_QUALITY;
  491.         hFont = CreateFontIndirect(&lf);
  492.     }
  493.     assert(hFont);
  494.  
  495.     // Measure the font face name
  496.     hOldFont = SelectFont(hDC, hFont);
  497. #ifdef _WIN32
  498.     GetTextExtentPoint32(hDC, lf.lfFaceName, nLen, &size);
  499. #else
  500.     GetTextExtentPoint(hDC, lf.lfFaceName, nLen, &size);
  501. #endif
  502.     lpmis->itemWidth = (UINT)size.cx;
  503.  
  504.     GetTextMetrics(hDC, &tm);
  505.     lpmis->itemHeight = tm.tmHeight;
  506.  
  507.     // We need to keep track of the largest font height so we can size the
  508.     // combo box accordingly
  509.     if ((int)lpmis->itemHeight > m_nMaxFontHeight)
  510.         m_nMaxFontHeight = (int)lpmis->itemHeight;
  511.  
  512.     // Cleanup
  513.     SelectFont(hDC, hOldFont);
  514.     if (!m_bDBCSEnabled)
  515.         DeleteFont(hFont);
  516.     ReleaseDC(hwndCtl, hDC);
  517. }
  518.  
  519. void
  520. CFontsPrefs::DrawComboBoxItem(LPDRAWITEMSTRUCT lpdis)
  521. {
  522.     LOGFONT    lf;
  523.     HFONT    hFont, hOldFont;
  524.     int        nLen;
  525.     SIZE    size;
  526.     int     y;
  527.  
  528.     switch (lpdis->itemAction) {
  529.         case ODA_DRAWENTIRE:
  530.         case ODA_SELECT:
  531.             if (lpdis->itemID == (UINT)-1)
  532.                 break;
  533.  
  534.             // Set up the text and background colors
  535.             SetTextColor(lpdis->hDC, GetSysColor(lpdis->itemState & ODS_SELECTED ?
  536.                 COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT));
  537.  
  538.             SetBkColor(lpdis->hDC, GetSysColor(lpdis->itemState & ODS_SELECTED ?
  539.                 COLOR_HIGHLIGHT : COLOR_WINDOW));
  540.             SetBkMode(lpdis->hDC, TRANSPARENT);
  541.     
  542.             // Initialize the LOGFONT structure
  543.             memset(&lf, 0, sizeof(lf));
  544.             
  545.             // Get the string to display
  546.             nLen = ComboBox_GetLBText(lpdis->hwndItem, lpdis->itemID, lf.lfFaceName);
  547.  
  548.             if (m_bDBCSEnabled) {
  549.                 hFont = GetWindowFont(lpdis->hwndItem);
  550.  
  551.             } else {
  552.                 // Assume an 8-point font
  553.                 lf.lfHeight = (LONG)-MulDiv(8, GetDeviceCaps(lpdis->hDC, LOGPIXELSY), 72);
  554.                 
  555.                 // Create the font
  556.                 lf.lfWeight = FW_NORMAL;
  557.                 lf.lfCharSet = DEFAULT_CHARSET;
  558.                 lf.lfQuality = PROOF_QUALITY;
  559.                 hFont = CreateFontIndirect(&lf);
  560.             }
  561.             assert(hFont);
  562.             
  563.             // Draw the text centered vertically in the bounding rect
  564.             hOldFont = SelectFont(lpdis->hDC, hFont);
  565. #ifdef _WIN32
  566.             GetTextExtentPoint32(lpdis->hDC, lf.lfFaceName, nLen, &size);
  567. #else
  568.             GetTextExtentPoint(lpdis->hDC, lf.lfFaceName, nLen, &size);
  569. #endif
  570.             y = ((lpdis->rcItem.bottom - lpdis->rcItem.top) - size.cy) / 2;
  571.             ExtTextOut(lpdis->hDC, lpdis->rcItem.left + LEFT_PADDING, lpdis->rcItem.top + y,
  572.                 ETO_OPAQUE, &lpdis->rcItem, lf.lfFaceName, nLen, NULL);
  573.  
  574.             // Cleanup the HDC
  575.             SelectFont(lpdis->hDC, hOldFont);
  576.             if (!m_bDBCSEnabled)
  577.                 DeleteFont(hFont);
  578.             
  579.             // Draw the focus rect if necessary
  580.             if (lpdis->itemState & ODS_FOCUS)
  581.                 DrawFocusRect(lpdis->hDC, &lpdis->rcItem);
  582.             break;
  583.  
  584.         case ODA_FOCUS:
  585.             DrawFocusRect(lpdis->hDC, &lpdis->rcItem);
  586.             break;
  587.     }
  588. }
  589.  
  590. LRESULT
  591. CFontsPrefs::WindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
  592. {
  593.     LPDRAWITEMSTRUCT    lpdis;
  594.     LPMEASUREITEMSTRUCT    lpmis;
  595.  
  596.     switch (uMsg) {
  597.         case WM_MEASUREITEM:
  598.             lpmis = (LPMEASUREITEMSTRUCT)lParam;
  599.  
  600.             if (lpmis->CtlID == IDC_COMBO2 || lpmis->CtlID == IDC_COMBO4)
  601.                 MeasureComboBoxItem(lpmis);
  602.             return TRUE;
  603.  
  604.         case WM_DRAWITEM:
  605.             lpdis = (LPDRAWITEMSTRUCT)lParam;
  606.  
  607.             if (lpdis->CtlID == IDC_COMBO2 || lpdis->CtlID == IDC_COMBO4)
  608.                 DrawComboBoxItem(lpdis);
  609.             return TRUE;
  610.     }
  611.  
  612.     return CBrowserPropertyPage::WindowProc(uMsg, wParam, lParam);
  613. }
  614.  
  615. // Apply changes using XP preferences
  616. BOOL
  617. CFontsPrefs::ApplyChanges()
  618. {
  619.     PREF_SetIntPref("browser.use_document_fonts", (int32)m_nUseDocumentFonts);
  620.     
  621.     // Request the IIntlFont interface from our data object
  622.     assert(m_pObject);
  623.     if (m_pObject) {
  624.         LPINTLFONT    lpIntlFont;
  625.         
  626.         if (SUCCEEDED(m_pObject->QueryInterface(IID_IIntlFont, (void **)&lpIntlFont))) {
  627.             ENCODINGINFO    info;
  628.     
  629.             info.nVariableWidthSize = m_nVariableSize;
  630.             lstrcpy(info.szVariableWidthFont, (LPCSTR)m_strVariableFaceName);
  631.             info.nFixedWidthSize = m_nFixedSize;
  632.             lstrcpy(info.szFixedWidthFont, (LPCSTR)m_strFixedFaceName);
  633.     
  634.             lpIntlFont->SetEncodingFonts(m_nCharset, &info);
  635.             lpIntlFont->Release();
  636.         }
  637.     }
  638.     
  639.     return TRUE;
  640. }
  641.  
  642. /////////////////////////////////////////////////////////////////////////////
  643. // CColorsPrefs implementation
  644.  
  645. CColorsPrefs::CColorsPrefs()
  646.     : CBrowserPropertyPage(IDD_COLORS, HELP_PREFS_APPEARANCE_COLORS)
  647. {
  648. }
  649.  
  650. // Initialize member data using XP preferences
  651. STDMETHODIMP
  652. CColorsPrefs::Activate(HWND hwndParent, LPCRECT lprc, BOOL bModal)
  653. {
  654.     if (!m_bHasBeenActivated) {
  655.         PREF_GetBoolPref("browser.underline_anchors", &m_bUnderlineLinks);
  656.         PREF_GetColorPrefDWord("browser.anchor_color", &m_rgbUnvisitedLinks);
  657.         PREF_GetColorPrefDWord("browser.visited_color", &m_rgbVisitedLinks);
  658.         PREF_GetBoolPref("browser.wfe.use_windows_colors", &m_bUseWindowsColors);
  659.         PREF_GetColorPrefDWord("browser.foreground_color", &m_rgbTextColor);
  660.         PREF_GetColorPrefDWord("browser.background_color", &m_rgbBackgroundColor);
  661.         
  662.         BOOL    bUseDocumentColors;
  663.  
  664.         PREF_GetBoolPref("browser.use_document_colors", &bUseDocumentColors);
  665.         m_bOverrideDocumentColors = !bUseDocumentColors;
  666.     }
  667.  
  668.     return CBrowserPropertyPage::Activate(hwndParent, lprc, bModal);
  669. }
  670.  
  671. BOOL
  672. CColorsPrefs::DoTransfer(BOOL bSaveAndValidate)
  673. {
  674.     CheckBoxTransfer(IDC_CHECK1, m_bUseWindowsColors, bSaveAndValidate);
  675.     CheckBoxTransfer(IDC_CHECK2, m_bUnderlineLinks, bSaveAndValidate);
  676.     CheckBoxTransfer(IDC_CHECK3, m_bOverrideDocumentColors, bSaveAndValidate);
  677.  
  678.     if (!bSaveAndValidate)
  679.         EnableColorButtons();
  680.  
  681.     return TRUE;
  682. }
  683.  
  684. void
  685. CColorsPrefs::EnableColorButtons()
  686. {
  687.     BOOL    bUseWindowsColors;
  688.  
  689.     // Disable the foreground/background color buttons if they're
  690.     // using the Windows colors
  691.     CheckBoxTransfer(IDC_CHECK1, bUseWindowsColors, TRUE);
  692.  
  693.     EnableDlgItem(IDC_BUTTON1, !bUseWindowsColors);
  694.     EnableDlgItem(IDC_BUTTON2, !bUseWindowsColors);
  695. }
  696.  
  697. // Apply changes using XP preferences
  698. BOOL
  699. CColorsPrefs::ApplyChanges()
  700. {
  701.     PREF_SetBoolPref("browser.underline_anchors", m_bUnderlineLinks);
  702.     PREF_SetColorPrefDWord("browser.anchor_color", m_rgbUnvisitedLinks);
  703.     PREF_SetColorPrefDWord("browser.visited_color", m_rgbVisitedLinks);
  704.     PREF_SetBoolPref("browser.wfe.use_windows_colors", m_bUseWindowsColors);
  705.     PREF_SetColorPrefDWord("browser.foreground_color", m_rgbTextColor);
  706.     PREF_SetColorPrefDWord("browser.background_color", m_rgbBackgroundColor);
  707.     PREF_SetBoolPref("browser.use_document_colors", !m_bOverrideDocumentColors);
  708.     return TRUE;
  709. }
  710.  
  711. BOOL
  712. CColorsPrefs::InitDialog()
  713. {
  714.     BOOL result = CBrowserPropertyPage::InitDialog();
  715.  
  716.     // Enable controls based on which prefs are locked.
  717.     EnableDlgItem(IDC_CHECK2, !PREF_PrefIsLocked("browser.underline_anchors"));
  718.     EnableDlgItem(IDC_BUTTON3, !PREF_PrefIsLocked("browser.anchor_color"));
  719.     EnableDlgItem(IDC_BUTTON4, !PREF_PrefIsLocked("browser.visited_color"));
  720.     EnableDlgItem(IDC_CHECK1, !PREF_PrefIsLocked("browser.wfe.use_windows_colors"));
  721.     EnableDlgItem(IDC_BUTTON1, !PREF_PrefIsLocked("browser.foreground_color"));
  722.     EnableDlgItem(IDC_BUTTON2, !PREF_PrefIsLocked("browser.background_color"));
  723.     EnableDlgItem(IDC_CHECK3, !PREF_PrefIsLocked("browser.use_document_colors"));
  724.  
  725.     return result; 
  726. }
  727.  
  728. COLORREF
  729. CColorsPrefs::GetColorButtonColor(UINT nCtlID)
  730. {
  731.     if (nCtlID == IDC_BUTTON1)
  732.         return m_rgbTextColor;
  733.     else if (nCtlID == IDC_BUTTON2)
  734.         return m_rgbBackgroundColor;
  735.     else if (nCtlID == IDC_BUTTON3)
  736.         return m_rgbUnvisitedLinks;
  737.     else if (nCtlID == IDC_BUTTON4)
  738.         return m_rgbVisitedLinks;
  739.  
  740.     assert(FALSE);
  741.     return 0;
  742. }
  743.  
  744. void
  745. CColorsPrefs::SetColorButtonColor(UINT nCtlID, COLORREF cr)
  746. {
  747.     if (nCtlID == IDC_BUTTON1)
  748.         m_rgbTextColor = cr;
  749.     else if (nCtlID == IDC_BUTTON2)
  750.         m_rgbBackgroundColor = cr;
  751.     else if (nCtlID == IDC_BUTTON3)
  752.         m_rgbUnvisitedLinks = cr;
  753.     else if (nCtlID == IDC_BUTTON4)
  754.         m_rgbVisitedLinks = cr;
  755.     else
  756.         assert(FALSE);
  757. }
  758.  
  759. LRESULT
  760. CColorsPrefs::WindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
  761. {
  762.     HBRUSH    hBrush;
  763.  
  764.     switch (uMsg) {
  765.         case WM_DRAWITEM:
  766.             hBrush = CreateSolidBrush(GetColorButtonColor(((LPDRAWITEMSTRUCT)lParam)->CtlID));
  767.             DrawColorButtonControl((LPDRAWITEMSTRUCT)lParam, hBrush);
  768.             DeleteBrush(hBrush);
  769.             return TRUE;
  770.  
  771.         default:
  772.             return CBrowserPropertyPage::WindowProc(uMsg, wParam, lParam);
  773.     }
  774. }
  775.  
  776. BOOL
  777. CColorsPrefs::OnCommand(int id, HWND hwndCtl, UINT notifyCode)
  778. {
  779.     switch (id) {
  780.         case IDC_CHECK1:
  781.             if (notifyCode == BN_CLICKED)
  782.                 EnableColorButtons();
  783.             break;
  784.  
  785.         case IDC_BUTTON1:
  786.         case IDC_BUTTON2:
  787.         case IDC_BUTTON3:
  788.         case IDC_BUTTON4:
  789.             if (notifyCode == BN_CLICKED) {
  790.                 CHOOSECOLOR    cc;
  791.                 COLORREF    custColors[16];
  792.  
  793.                 // Initialize the structure
  794.                 memset(&cc, 0, sizeof(cc));
  795.                 cc.lStructSize = sizeof(cc);
  796.                 cc.rgbResult = GetColorButtonColor(id);
  797.                 cc.hwndOwner = GetParent(m_hwndDlg);
  798.                 cc.lpCustColors = custColors;
  799.                 cc.Flags = CC_RGBINIT;
  800.  
  801.                 // Initialize the custom colors to white
  802.                 for (int i = 0; i < 16; i++)
  803.                     custColors[i] = RGB(255,255,255);
  804.  
  805.                 if (ChooseColor(&cc) == IDOK) {
  806.                     SetColorButtonColor(id, cc.rgbResult);
  807.                     InvalidateRect(hwndCtl, NULL, FALSE);
  808.                 }
  809.  
  810.                 return TRUE;
  811.             }
  812.             break;
  813.     }
  814.  
  815.     return CBrowserPropertyPage::OnCommand(id, hwndCtl, notifyCode);
  816. }
  817.  
  818.