home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / prefs / edpref / src / edpages.cpp next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  8.7 KB  |  275 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 "resource.h"
  24. #include "structs.h"
  25. #include "xp_core.h"
  26. #include "xp_help.h"
  27. #include "prefapi.h"
  28.  
  29. /////////////////////////////////////////////////////////////////////////////
  30. // Helper functions
  31.  
  32. static void NEAR
  33. EnableDlgItem(HWND hdlg, UINT nID, BOOL bEnable)
  34. {
  35.     HWND hCtl = GetDlgItem(hdlg, nID);
  36.  
  37.     assert(hCtl);
  38.     EnableWindow(hCtl, bEnable);
  39. }
  40.  
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CEditorPrefs implementation
  43.  
  44. CEditorPrefs::CEditorPrefs()
  45.     : CEditorPropertyPage(IDD_PREF_EDITOR, HELP_EDIT_PREFS_EDITOR_GENERAL)
  46. {
  47. }
  48.  
  49. STDMETHODIMP
  50. CEditorPrefs::Activate(HWND hwndParent, LPCRECT lprc, BOOL bModal)
  51. {
  52.     if (!m_bHasBeenActivated) {
  53.         PREF_GetStringPref("editor.author",m_strAuthor);
  54.         PREF_GetStringPref("editor.html_editor",m_strHTML_Editor);
  55.         PREF_GetStringPref("editor.image_editor",m_strImageEditor);
  56.         int32 n;
  57.         PREF_GetIntPref("editor.fontsize_mode", &n);
  58.         m_iFontSizeMode = (int)n;
  59.  
  60.         PREF_GetIntPref("editor.auto_save_delay",&n);
  61.         m_iAutoSaveMinutes = (int)n;
  62.  
  63.         m_bAutoSave = n > 0;
  64.     }
  65.  
  66.     return CEditorPropertyPage::Activate(hwndParent, lprc, bModal);
  67. }
  68.  
  69. BOOL
  70. CEditorPrefs::InitDialog()
  71. {
  72.     // Composer preferences
  73.     EnableDlgItem(IDC_HTML_EDITOR, !PREF_PrefIsLocked("editor.html_editor"));
  74.     EnableDlgItem(IDC_CHOOSE_HTML_EDITOR, !PREF_PrefIsLocked("editor.html_editor"));
  75.     EnableDlgItem(IDC_IMAGE_EDITOR, !PREF_PrefIsLocked("editor.image_editor"));
  76.     EnableDlgItem(IDC_CHOOSE_IMAGE_EDITOR, !PREF_PrefIsLocked("editor.image_editor"));
  77.     EnableDlgItem(IDC_AUTO_SAVE, !PREF_PrefIsLocked("editor.auto_save"));
  78.     EnableDlgItem(IDC_AUTO_SAVE_MINUTES, !PREF_PrefIsLocked("editor.auto_save_delay"));
  79.     EnableDlgItem(IDC_FONTSIZE_MODE, !PREF_PrefIsLocked("editor.fontsize_mode"));
  80.     EnableDlgItem(IDC_FONTSIZE_MODE2, !PREF_PrefIsLocked("editor.fontsize_mode"));
  81.     EnableDlgItem(IDC_FONTSIZE_MODE3, !PREF_PrefIsLocked("editor.fontsize_mode"));
  82.     
  83.     return CEditorPropertyPage::InitDialog();;
  84. }
  85.  
  86. BOOL
  87. CEditorPrefs::DoTransfer(BOOL bSaveAndValidate)
  88. {
  89.     EditFieldTransfer(IDC_EDIT_AUTHOR, m_strAuthor, bSaveAndValidate);
  90.     EditFieldTransfer(IDC_HTML_EDITOR, m_strHTML_Editor, bSaveAndValidate);
  91.     EditFieldTransfer(IDC_IMAGE_EDITOR, m_strImageEditor, bSaveAndValidate);
  92.     CheckBoxTransfer(IDC_AUTO_SAVE, m_bAutoSave, bSaveAndValidate);
  93.     RadioButtonTransfer(IDC_FONTSIZE_MODE, m_iFontSizeMode, bSaveAndValidate);
  94.     EditFieldTransfer(IDC_AUTO_SAVE_MINUTES, m_iAutoSaveMinutes, bSaveAndValidate);
  95.     return TRUE;
  96. }
  97.  
  98. BOOL
  99. CEditorPrefs::ApplyChanges()
  100. {
  101.     // TODO: Need TrimLeft() and TrimRight() or just Trim() functions for CString
  102.     PREF_SetCharPref("editor.author",LPCSTR(m_strAuthor));
  103.     PREF_SetCharPref("editor.html_editor",LPCSTR(m_strHTML_Editor));
  104.     PREF_SetCharPref("editor.image_editor",LPCSTR(m_strImageEditor));
  105.     
  106.     if ( m_bAutoSave ){
  107.         PREF_SetIntPref("editor.auto_save_delay",m_iAutoSaveMinutes);
  108.     } else {
  109.         PREF_SetIntPref("editor.auto_save_delay",0);
  110.     }
  111.     PREF_SetIntPref("editor.fontsize_mode", (int32)m_iFontSizeMode);
  112.     return TRUE;
  113. }
  114.  
  115. BOOL
  116. CEditorPrefs::GetApplicationFilename(CString& strFilename, UINT nIDCaption)
  117. {
  118.     OPENFILENAME fname;
  119.  
  120.     // Dialog caption
  121.     CString  strCaption;
  122.     strCaption.LoadString(m_hInstance, nIDCaption);
  123.  
  124.     // space for the full path name    
  125.     char szFullPath[_MAX_PATH];
  126.     szFullPath[0] = '\0';
  127.  
  128.     // Filter string
  129.     char     szFilter[256];
  130.     ::LoadString(m_hInstance, IDS_APP_FILTER, szFilter, 256);
  131.     char * szTemp = szFilter;
  132.     // Replace '\n' with '\0' in filter
  133.     while( *szTemp != '\0' ) {
  134.         if( *szTemp == '\n' ) *szTemp = '\0';
  135.         szTemp++;
  136.     }
  137.     
  138.     // set up the entries
  139.     fname.lStructSize = sizeof(OPENFILENAME);
  140.     fname.hwndOwner = m_hwndDlg;
  141.     fname.lpstrFilter = szFilter;
  142.     fname.lpstrCustomFilter = NULL;
  143.     fname.nFilterIndex = 0;
  144.     fname.lpstrFile = szFullPath;
  145.     fname.nMaxFile = _MAX_PATH;
  146.     fname.lpstrFileTitle = NULL;
  147.     fname.nMaxFileTitle = 0;
  148.     fname.lpstrInitialDir = NULL;
  149.     fname.lpstrTitle = LPCSTR(strCaption);
  150.     fname.lpstrDefExt = NULL;
  151.     fname.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;
  152.     if( GetOpenFileName(&fname) ){
  153.         strFilename = szFullPath;
  154.         return TRUE;
  155.     }
  156.     return FALSE;
  157. }
  158.  
  159. BOOL 
  160. CEditorPrefs::OnCommand(int id, HWND hwndCtl, UINT notifyCode)
  161. {
  162.     // Get current data from dialog
  163.     if(notifyCode == BN_CLICKED){
  164.         DoTransfer(TRUE);
  165.  
  166.         if (id == IDC_CHOOSE_HTML_EDITOR &&
  167.             GetApplicationFilename(m_strHTML_Editor, IDS_CHOOSE_HTML_EDITOR) ){
  168.             DoTransfer(FALSE);
  169.             return TRUE;
  170.         } else if (id == IDC_CHOOSE_IMAGE_EDITOR &&
  171.             GetApplicationFilename(m_strImageEditor, IDS_CHOOSE_IMAGE_EDITOR) ){
  172.             DoTransfer(FALSE);
  173.             return TRUE;
  174.         }
  175.     }
  176.     return CEditorPropertyPage::OnCommand(id, hwndCtl, notifyCode);
  177. }
  178.  
  179.  
  180. /////////////////////////////////////////////////////////////////////////////
  181. // CPublishPrefs implementation
  182.  
  183. CPublishPrefs::CPublishPrefs()
  184.     : CEditorPropertyPage(IDD_PREF_PUBLISH, HELP_EDIT_PREFS_EDITOR_PUBLISH)
  185. {
  186. }
  187.  
  188. BOOL
  189. CPublishPrefs::InitDialog()
  190. {
  191.  
  192.     // Composer/Publishing Preferences
  193.     EnableDlgItem(IDC_AUTOADJUST_LINKS, !PREF_PrefIsLocked("editor.publish_keep_links"));
  194.     EnableDlgItem(IDC_KEEP_IMAGE_WITH_DOC, !PREF_PrefIsLocked("editor.publish_keep_images"));
  195.     EnableDlgItem(IDC_PUBLISH_FTP, !PREF_PrefIsLocked("editor.publish_location"));
  196.     EnableDlgItem(IDC_PUBLISH_HTTP, !PREF_PrefIsLocked("editor.publish_browse_location"));
  197.     
  198.     return CEditorPropertyPage::InitDialog();;
  199. }
  200.  
  201. STDMETHODIMP
  202. CPublishPrefs::Activate(HWND hwndParent, LPCRECT lprc, BOOL bModal)
  203. {
  204.     if (!m_bHasBeenActivated) {
  205.         PREF_GetBoolPref("editor.publish_keep_links",&m_bAutoAdjustLinks);
  206.         PREF_GetBoolPref("editor.publish_keep_images",&m_bKeepImagesWithDoc);
  207.         PREF_GetStringPref("editor.publish_location",m_strPublishLocation);
  208.         PREF_GetStringPref("editor.publish_browse_location",m_strBrowseLocation);
  209.     }
  210.  
  211.     return CEditorPropertyPage::Activate(hwndParent, lprc, bModal);
  212. }
  213.  
  214. BOOL
  215. CPublishPrefs::DoTransfer(BOOL bSaveAndValidate)
  216. {
  217.     CheckBoxTransfer(IDC_AUTOADJUST_LINKS, m_bAutoAdjustLinks, bSaveAndValidate);
  218.     CheckBoxTransfer(IDC_KEEP_IMAGE_WITH_DOC, m_bKeepImagesWithDoc, bSaveAndValidate);
  219.     EditFieldTransfer(IDC_PUBLISH_FTP, m_strPublishLocation, bSaveAndValidate);
  220.     EditFieldTransfer(IDC_PUBLISH_HTTP, m_strBrowseLocation, bSaveAndValidate);
  221.     return TRUE;
  222. }
  223.  
  224. BOOL
  225. CPublishPrefs::ApplyChanges()
  226. {
  227.     PREF_SetBoolPref("editor.publish_keep_links",(XP_Bool)m_bAutoAdjustLinks);
  228.     PREF_SetBoolPref("editor.publish_keep_images",(XP_Bool)m_bKeepImagesWithDoc);
  229.     PREF_SetCharPref("editor.publish_location",LPCSTR(m_strPublishLocation));
  230.     PREF_SetCharPref("editor.publish_browse_location",LPCSTR(m_strBrowseLocation));
  231.     return TRUE;
  232. }
  233.  
  234.  
  235. /////////////////////////////////////////////////////////////////////////////
  236. // CEditorPrefs2 implementation
  237.  
  238. CEditorPrefs2::CEditorPrefs2()
  239.     : CEditorPropertyPage(IDD_PREF_EDITOR2, HELP_EDIT_PREFS_EDITOR_PUBLISH)
  240. {
  241. }
  242.  
  243. BOOL
  244. CEditorPrefs2::InitDialog()
  245. {
  246.     // Composer/Publishing Preferences
  247.     EnableDlgItem(IDC_PAGEUPDOWN, !PREF_PrefIsLocked("editor.page_updown_move_cursor"));
  248.     return CEditorPropertyPage::InitDialog();;
  249. }
  250.  
  251. STDMETHODIMP
  252. CEditorPrefs2::Activate(HWND hwndParent, LPCRECT lprc, BOOL bModal)
  253. {
  254.     if (!m_bHasBeenActivated) {
  255.         PREF_GetBoolPref("editor.page_updown_move_cursor",&m_bUpDownMoveCursor);
  256.     }
  257.  
  258.     return CEditorPropertyPage::Activate(hwndParent, lprc, bModal);
  259. }
  260.  
  261. BOOL
  262. CEditorPrefs2::DoTransfer(BOOL bSaveAndValidate)
  263. {
  264.     CheckBoxTransfer(IDC_PAGEUPDOWN, m_bUpDownMoveCursor, bSaveAndValidate);
  265.     return TRUE;
  266. }
  267.  
  268. BOOL
  269. CEditorPrefs2::ApplyChanges()
  270. {
  271.     PREF_SetBoolPref("editor.page_updown_move_cursor",(XP_Bool)m_bUpDownMoveCursor);
  272.     return TRUE;
  273. }
  274.  
  275.