home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / prefinfo.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  7.7 KB  |  245 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 "stdafx.h"
  20. #include "prefinfo.h"
  21. #include "prefapi.h"
  22. #include "edt.h"
  23. #include "prefs.h"
  24.  
  25. int PR_CALLBACK prefWatcher(const char *pPrefName, void *pData)
  26. {
  27.     BOOL        bReload = FALSE;
  28.     COLORREF    rgbForegroundColor = prefInfo.m_rgbForegroundColor;
  29.     COLORREF    rgbBackgroundColor = prefInfo.m_rgbBackgroundColor;
  30.  
  31.     switch ((int)pData) {
  32.         case 1:
  33.             PREF_GetColorPrefDWord("browser.anchor_color", &prefInfo.m_rgbAnchorColor);
  34.             wfe_SetLayoutColor(LO_COLOR_LINK, prefInfo.m_rgbAnchorColor);
  35.             bReload = TRUE;
  36.             break;
  37.  
  38.         case 2:
  39.             PREF_GetColorPrefDWord("browser.visited_color", &prefInfo.m_rgbVisitedColor);
  40.             wfe_SetLayoutColor(LO_COLOR_VLINK, prefInfo.m_rgbVisitedColor);
  41.             bReload = TRUE;
  42.             break;
  43.  
  44.         case 3:
  45.             /*
  46.              * PREF_GetBoolPref("browser.underline_anchors", &prefInfo.m_bUnderlineAnchors);
  47.              * bReload = TRUE;  // XXX - we really only need to refresh the page...
  48.              */
  49.             break;
  50.  
  51.         case 4:
  52.             PREF_GetBoolPref("browser.wfe.use_windows_colors", &prefInfo.m_bUseWindowsColors);
  53.             if (prefInfo.m_bUseWindowsColors) {
  54.                 rgbForegroundColor = ::GetSysColor(COLOR_WINDOWTEXT);
  55.                 rgbBackgroundColor = ::GetSysColor(COLOR_WINDOW);
  56.         
  57.             } else {
  58.                 PREF_GetColorPrefDWord("browser.foreground_color", &rgbForegroundColor);
  59.                 PREF_GetColorPrefDWord("browser.background_color", &rgbBackgroundColor);
  60.             }
  61.             break;
  62.  
  63.         case 5:
  64.             PREF_GetColorPrefDWord("browser.foreground_color", &rgbForegroundColor);
  65.             break;
  66.  
  67.         case 6:
  68.             PREF_GetColorPrefDWord("browser.background_color", &rgbBackgroundColor);
  69.             break;
  70.  
  71.         case 7:
  72.             PREF_GetBoolPref("browser.use_document_colors", &prefInfo.m_bUseDocumentColors);
  73.             LO_SetUserOverride(!prefInfo.m_bUseDocumentColors);
  74.             bReload = TRUE;
  75.             break;
  76.  
  77.         case 8:
  78.             PREF_GetBoolPref("general.always_load_images",&prefInfo.m_bAutoLoadImages);
  79.  
  80.             CGenericFrame *pGenFrame;
  81.             for(pGenFrame = theApp.m_pFrameList; pGenFrame; pGenFrame = pGenFrame->m_pNext) {
  82.                 pGenFrame->GetChrome()->ImagesButton(!prefInfo.m_bAutoLoadImages);
  83.             }
  84.             break;
  85.     }
  86.  
  87.     // See whether the foreground or background colors changed
  88.     if (rgbForegroundColor != prefInfo.m_rgbForegroundColor) {
  89.         prefInfo.m_rgbForegroundColor = rgbForegroundColor;
  90.         wfe_SetLayoutColor(LO_COLOR_FG, prefInfo.m_rgbForegroundColor);
  91.         bReload = TRUE;
  92.     }
  93.  
  94.     if (rgbBackgroundColor != prefInfo.m_rgbBackgroundColor) {
  95.         prefInfo.m_rgbBackgroundColor = rgbBackgroundColor;
  96.         wfe_SetLayoutColor(LO_COLOR_BG, prefInfo.m_rgbBackgroundColor);
  97.         bReload = TRUE;
  98.     }
  99.  
  100.     if (bReload)
  101.         g_bReloadAllWindows = TRUE;
  102.  
  103.     return PREF_NOERROR;
  104. }
  105.  
  106. int PR_CALLBACK SetToolbarButtonStyle(const char *newPref, void *data)
  107. {
  108.     int32 prefInt;
  109.  
  110.     PREF_GetIntPref("browser.chrome.button_style",&prefInt);
  111.     theApp.m_pToolbarStyle = CASTINT(prefInt);
  112.  
  113.     CGenericFrame *pGenFrame;
  114.     for(pGenFrame = theApp.m_pFrameList; pGenFrame; pGenFrame = pGenFrame->m_pNext) {
  115.         LPNSTOOLBAR pIToolBar = NULL;
  116.         pGenFrame->GetChrome()->QueryInterface( IID_INSToolBar, (LPVOID *) &pIToolBar );
  117.         if (pIToolBar) {
  118.            pIToolBar->SetToolbarStyle(theApp.m_pToolbarStyle);
  119.            pIToolBar->Release();
  120.         }
  121.         pGenFrame->GetChrome()->SetToolbarStyle(theApp.m_pToolbarStyle);
  122.     }
  123.  
  124. #ifdef MOZ_TASKBAR
  125.     theApp.GetTaskBarMgr().SetTaskBarStyle(theApp.m_pToolbarStyle);
  126. #endif /* MOZ_TASKBAR */
  127.     
  128.     return PREF_NOERROR;
  129. }
  130.  
  131. CPrefInfo prefInfo;
  132.  
  133. CPrefInfo::CPrefInfo()
  134. {
  135.     m_rgbBackgroundColor = 0;
  136.     m_rgbForegroundColor = 0;
  137.     m_bUnderlineAnchors = FALSE;
  138.     m_rgbAnchorColor = 0;
  139.     m_rgbVisitedColor = 0;
  140.     m_bUseWindowsColors = FALSE;
  141.     m_bUseDocumentColors = TRUE;
  142.     m_bAutoLoadImages = TRUE;
  143. }
  144.  
  145. void CPrefInfo::UpdateAllWindows()
  146. {
  147.     // Update layout in all current windows    
  148.     for (CGenericFrame *f = theApp.m_pFrameList; f; f = f->m_pNext) {
  149.         CWinCX *pContext = f->GetMainWinContext();
  150.  
  151.         if (pContext && pContext->GetContext()) {
  152. #ifdef EDITOR
  153.             if (EDT_IS_EDITOR(pContext->GetContext())) {
  154.                 // Edit can relayout page without having to do NET_GetURL
  155.                 EDT_RefreshLayout(pContext->GetContext());
  156.  
  157.             } else 
  158. #endif // EDITOR
  159.             {
  160.                 pContext->NiceReload();
  161.             }
  162.         }
  163.     }
  164. }
  165.  
  166. void CPrefInfo::SysColorChange()
  167. {
  168.     if (m_bUseWindowsColors) {
  169.         COLORREF    rgbForegroundColor = ::GetSysColor(COLOR_WINDOWTEXT);
  170.         COLORREF    rgbBackgroundColor = ::GetSysColor(COLOR_WINDOW);
  171.         BOOL        bReload = FALSE;
  172.  
  173.         // See whether the foreground or background colors changed
  174.         if (rgbForegroundColor != m_rgbForegroundColor) {
  175.             m_rgbForegroundColor = rgbForegroundColor;
  176.             wfe_SetLayoutColor(LO_COLOR_FG, m_rgbForegroundColor);
  177.             bReload = TRUE;
  178.         }
  179.     
  180.         if (rgbBackgroundColor != m_rgbBackgroundColor) {
  181.             m_rgbBackgroundColor = rgbBackgroundColor;
  182.             wfe_SetLayoutColor(LO_COLOR_BG, m_rgbBackgroundColor);
  183.             bReload = TRUE;
  184.         }
  185.  
  186.         if (bReload)
  187.             UpdateAllWindows();
  188.     }
  189. }
  190.  
  191. void CPrefInfo::Initialize()
  192. {
  193.     int32 prefInt;
  194.  
  195.     // Unvisited link color
  196.     PREF_GetColorPrefDWord("browser.anchor_color", &m_rgbAnchorColor);
  197.     wfe_SetLayoutColor(LO_COLOR_LINK, m_rgbAnchorColor);
  198.     PREF_RegisterCallback("browser.anchor_color", prefWatcher, (void *)1);
  199.  
  200.     // Visited link color
  201.     PREF_GetColorPrefDWord("browser.visited_color", &m_rgbVisitedColor);
  202.     wfe_SetLayoutColor(LO_COLOR_VLINK, m_rgbVisitedColor);
  203.     PREF_RegisterCallback("browser.visited_color", prefWatcher, (void *)2);
  204.     
  205.     // Underline links
  206.     /* 
  207.      * PREF_GetBoolPref("browser.underline_anchors", &m_bUnderlineAnchors);
  208.          * PREF_RegisterCallback("browser.underline_anchors", prefWatcher, (void *)3);
  209.      */
  210.     
  211.     // Text and background color. See if we should use the Windows colors
  212.     PREF_GetBoolPref("browser.wfe.use_windows_colors", &m_bUseWindowsColors);
  213.     PREF_RegisterCallback("browser.wfe.use_windows_colors", prefWatcher, (void *)4);
  214.     
  215.     if (m_bUseWindowsColors) {
  216.         m_rgbForegroundColor = ::GetSysColor(COLOR_WINDOWTEXT);
  217.         m_rgbBackgroundColor = ::GetSysColor(COLOR_WINDOW);
  218.  
  219.     } else {
  220.         PREF_GetColorPrefDWord("browser.foreground_color", &m_rgbForegroundColor);
  221.         PREF_GetColorPrefDWord("browser.background_color", &m_rgbBackgroundColor);
  222.     }
  223.  
  224.     wfe_SetLayoutColor(LO_COLOR_FG, m_rgbForegroundColor);
  225.     PREF_RegisterCallback("browser.foreground_color", prefWatcher, (void *)5);
  226.     wfe_SetLayoutColor(LO_COLOR_BG, m_rgbBackgroundColor);
  227.     PREF_RegisterCallback("browser.background_color", prefWatcher, (void *)6);
  228.     
  229.     // See if the user's choices override the document
  230.     PREF_GetBoolPref("browser.use_document_colors", &m_bUseDocumentColors);
  231.     LO_SetUserOverride(!m_bUseDocumentColors);
  232.     PREF_RegisterCallback("browser.use_document_colors", prefWatcher, (void *)7);
  233.     
  234.     // Always Load Images
  235.     PREF_GetBoolPref("general.always_load_images", &m_bAutoLoadImages);
  236.     PREF_RegisterCallback("general.always_load_images", prefWatcher, (void *)8);
  237.  
  238.        // type of toolbar buttons
  239.      PREF_GetIntPref("browser.chrome.button_style",&prefInt);
  240.     theApp.m_pToolbarStyle = CASTINT(prefInt);
  241.     PREF_RegisterCallback("browser.chrome.button_style", SetToolbarButtonStyle, NULL);
  242.  
  243.  
  244. }
  245.