home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / PrefsDialog.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  49.7 KB  |  1,932 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. /*
  20.    PrefsDialog.cpp -- class for XFE preferences dialogs.
  21.    Created: Linda Wei <lwei@netscape.com>, 17-Sep-96.
  22.  */
  23.  
  24.  
  25. #define TRUE   1
  26. #define FALSE  0
  27.  
  28. #include "felocale.h"
  29. #include "structs.h"
  30. #include "fonts.h"
  31. #include "xpassert.h"
  32. #include "xfe.h"
  33. #include "PrefsDialog.h"
  34. #include "prefapi.h"
  35.  
  36. #include <Xm/Label.h>
  37. #include <Xm/LabelG.h>
  38. #include <Xm/CascadeBG.h>
  39. #include <Xm/PushB.h>
  40. #include <Xm/PushBG.h>
  41. #include <Xm/ToggleB.h>
  42. #include <Xm/ArrowBG.h>
  43. #include <Xm/Form.h>
  44. #include <Xm/Frame.h>
  45. #include <Xm/RowColumn.h>
  46. #include <Xm/LabelG.h> 
  47. #include <Xm/TextF.h> 
  48. #include <Xm/ToggleBG.h> 
  49. #include <XmL/Grid.h>
  50.  
  51. #include <Xfe/Xfe.h>
  52.  
  53. extern int XFE_ERROR_SAVING_OPTIONS;
  54. extern int XFE_OUT_OF_MEMORY_URL;
  55.  
  56. static const int   NUM_OUTLINER_COLS = 2;
  57. static       int   OUTLINER_COLWIDTHS[] = {4, 20};
  58. static const char *OUTLINER_COLUMN_TYPE = "";
  59. static const char *OUTLINER_COLUMN_NAME = "Category";
  60. static       char *TAG_NORMAL = "NORMAL";
  61. static       char *TAG_BOLD = "BOLD";
  62.  
  63. #define CAT_LAST_CELL            0xFFFF
  64.  
  65. #define CAT_FONTS                "Fonts"
  66. #define CAT_COLORS               "Colors"
  67. #define CAT_APPS                 "Applications"
  68. #define CAT_LANG                 "Languages"
  69. #define CAT_CACHE                "Cache"
  70. #define CAT_PROXIES              "Proxies"
  71. #define CAT_MAILNEWS_IDENTITY    "Identity"
  72. #define CAT_MAILNEWS_COMPOSITION "Composition"
  73. #define CAT_MAILNEWS_MAILSERVER  "Mail Server"
  74. #define CAT_MAILNEWS_NEWSSERVER  "News Server"
  75. #define CAT_MAILNEWS_ADDRBOOK    "Address Book"
  76. #define CAT_EDITOR_PUBLISH       "Publish"
  77. #define CAT_DISKSPACE            "Disk Space"
  78. #define CAT_EDITOR_APPEARANCE    "Appearance"
  79. #ifdef PREFS_UNSUPPORTED
  80. #define CAT_HELPFILES            "Help Files"
  81. #define CAT_OFFLINE_NEWS         "News"
  82. #endif /* PREFS_UNSUPPORTED */
  83.  
  84. #define CAT_RESNAME_APPEARANCE           "pref.appearance"
  85. #define CAT_RESNAME_FONTS                "pref.fonts"
  86. #define CAT_RESNAME_COLORS               "pref.colors"
  87. #define CAT_RESNAME_BROWSER              "pref.browser"
  88. #define CAT_RESNAME_LANG                 "pref.lang"
  89. #define CAT_RESNAME_APPS                 "pref.applications"
  90. #define CAT_RESNAME_MAILNEWS             "pref.mailNews"
  91. #define CAT_RESNAME_MAILNEWS_IDENTITY    "pref.identity"
  92. #define CAT_RESNAME_MAILNEWS_COMPOSITION "pref.composition"
  93. #define CAT_RESNAME_MAILNEWS_MAILSERVER  "pref.mailServer"
  94. #define CAT_RESNAME_MAILNEWS_NEWSSERVER  "pref.newsServer"
  95. #define CAT_RESNAME_MAILNEWS_ADDRBOOK    "pref.addressBook"
  96. #define CAT_RESNAME_EDITOR               "pref.editor"
  97. #define CAT_RESNAME_EDITOR_PUBLISH       "pref.editorPublish"
  98. #define CAT_RESNAME_ADVANCED             "pref.advanced"
  99. #define CAT_RESNAME_CACHE                "pref.cache"
  100. #define CAT_RESNAME_PROXIES              "pref.proxies"
  101. #define CAT_RESNAME_DISKSPACE            "pref.diskSpace"
  102. #define CAT_RESNAME_EDITOR_APPEARANCE    "pref.editorAppearance"
  103. #ifdef PREFS_UNSUPPORTED
  104. #define CAT_RESNAME_HELPFILES            "pref.helpFiles"
  105. #define CAT_RESNAME_OFFLINE              "pref.offline"
  106. #define CAT_RESNAME_OFFLINE_NEWS         "pref.offlineNews"
  107. #endif /* PREFS_UNSUPPORTED */
  108.  
  109. #define CAT_RESCLASS_APPEARANCE           "Pref.Appearance"
  110. #define CAT_RESCLASS_FONTS                "Pref.Fonts"
  111. #define CAT_RESCLASS_COLORS               "Pref.Colors"
  112. #define CAT_RESCLASS_BROWSER              "Pref.Browser"
  113. #define CAT_RESCLASS_LANG                 "Pref.Lang"
  114. #define CAT_RESCLASS_APPS                 "Pref.Applications"
  115. #define CAT_RESCLASS_MAILNEWS             "Pref.MailNews"
  116. #define CAT_RESCLASS_MAILNEWS_IDENTITY    "Pref.Identity"
  117. #define CAT_RESCLASS_MAILNEWS_COMPOSITION "Pref.Composition"
  118. #define CAT_RESCLASS_MAILNEWS_MAILSERVER  "Pref.MailServer"
  119. #define CAT_RESCLASS_MAILNEWS_NEWSSERVER  "Pref.NewsServer"
  120. #define CAT_RESCLASS_MAILNEWS_ADDRBOOK    "Pref.AddressBook"
  121. #define CAT_RESCLASS_EDITOR               "Pref.Editor"
  122. #define CAT_RESCLASS_EDITOR_PUBLISH       "Pref.EditorPublish"
  123. #define CAT_RESCLASS_ADVANCED             "Pref.Advanced"
  124. #define CAT_RESCLASS_CACHE                "Pref.Cache"
  125. #define CAT_RESCLASS_PROXIES              "Pref.Proxies"
  126. #define CAT_RESCLASS_DISKSPACE            "Pref.DiskSpace"
  127. #define CAT_RESCLASS_EDITOR_APPEARANCE    "Pref.EditorAppearance"
  128. #ifdef PREFS_UNSUPPORTED
  129. #define CAT_RESCLASS_HELPFILES            "Pref.HelpFiles"
  130. #define CAT_RESCLASS_OFFLINE              "Pref.Offline"
  131. #define CAT_RESCLASS_OFFLINE_NEWS         "Pref.OfflineNews"
  132. #endif
  133.  
  134. #define DESC_RESNAME_APPEARANCE           "prefDesc.appearance"
  135. #define DESC_RESNAME_FONTS                "prefDesc.fonts"
  136. #define DESC_RESNAME_COLORS               "prefDesc.colors"
  137. #define DESC_RESNAME_BROWSER              "prefDesc.browser"
  138. #define DESC_RESNAME_LANG                 "prefDesc.lang"
  139. #define DESC_RESNAME_APPS                 "prefDesc.applications"
  140. #define DESC_RESNAME_MAILNEWS             "prefDesc.mailNews"
  141. #define DESC_RESNAME_MAILNEWS_IDENTITY    "prefDesc.identity"
  142. #define DESC_RESNAME_MAILNEWS_COMPOSITION "prefDesc.composition"
  143. #define DESC_RESNAME_MAILNEWS_MAILSERVER  "prefDesc.mailServer"
  144. #define DESC_RESNAME_MAILNEWS_NEWSSERVER  "prefDesc.newsServer"
  145. #define DESC_RESNAME_MAILNEWS_ADDRBOOK    "prefDesc.addressBook"
  146. #define DESC_RESNAME_EDITOR               "prefDesc.editor"
  147. #define DESC_RESNAME_EDITOR_PUBLISH       "prefDesc.editorPublish"
  148. #define DESC_RESNAME_ADVANCED             "prefDesc.advanced"
  149. #define DESC_RESNAME_CACHE                "prefDesc.cache"
  150. #define DESC_RESNAME_PROXIES              "prefDesc.proxies"
  151. #define DESC_RESNAME_DISKSPACE            "prefDesc.diskSpace"
  152. #define DESC_RESNAME_EDITOR_APPEARANCE    "prefDesc.editorAppearance"
  153. #ifdef PREFS_UNSUPPORTED
  154. #define DESC_RESNAME_HELPFILES            "prefDesc.helpFiles"
  155. #define DESC_RESNAME_OFFLINE              "prefDesc.offline"
  156. #define DESC_RESNAME_OFFLINE_NEWS         "prefDesc.offlineNews"
  157. #endif /* PREFS_UNSUPPORTED */
  158.  
  159. #define DESC_RESCLASS_APPEARANCE           "PrefDesc.Appearance"
  160. #define DESC_RESCLASS_FONTS                "PrefDesc.Fonts"
  161. #define DESC_RESCLASS_COLORS               "PrefDesc.Colors"
  162. #define DESC_RESCLASS_BROWSER              "PrefDesc.Browser"
  163. #define DESC_RESCLASS_LANG                 "PrefDesc.Lang"
  164. #define DESC_RESCLASS_APPS                 "PrefDesc.Applications"
  165. #define DESC_RESCLASS_MAILNEWS             "PrefDesc.MailNews"
  166. #define DESC_RESCLASS_MAILNEWS_IDENTITY    "PrefDesc.Identity"
  167. #define DESC_RESCLASS_MAILNEWS_COMPOSITION "PrefDesc.Composition"
  168. #define DESC_RESCLASS_MAILNEWS_MAILSERVER  "PrefDesc.MailServer"
  169. #define DESC_RESCLASS_MAILNEWS_NEWSSERVER  "PrefDesc.newsServer"
  170. #define DESC_RESCLASS_MAILNEWS_ADDRBOOK    "PrefDesc.AddressBook"
  171. #define DESC_RESCLASS_EDITOR               "PrefDesc.Editor"
  172. #define DESC_RESCLASS_EDITOR_PUBLISH       "PrefDesc.EditorPublish"
  173. #define DESC_RESCLASS_ADVANCED             "PrefDesc.Advanced"
  174. #define DESC_RESCLASS_CACHE                "PrefDesc.Cache"
  175. #define DESC_RESCLASS_PROXIES              "PrefDesc.Proxies"
  176. #define DESC_RESCLASS_DISKSPACE            "PrefDesc.DiskSpace"
  177. #define DESC_RESCLASS_EDITOR_APPEARANCE    "PrefDesc.EditorAppearance"
  178. #ifdef PREFS_UNSUPPORTED
  179. #define DESC_RESCLASS_HELPFILES            "PrefDesc.HelpFiles"
  180. #define DESC_RESCLASS_OFFLINE              "PrefDesc.Offline"
  181. #define DESC_RESCLASS_OFFLINE_NEWS         "PrefDesc.OfflineNews"
  182. #endif /* PREFS_UNSUPPORTED */
  183.  
  184. typedef enum _prefsPageType {
  185.     PAGE_TYPE_APPEARANCE,
  186.     PAGE_TYPE_FONTS,
  187.     PAGE_TYPE_COLORS,
  188.     PAGE_TYPE_BROWSER,
  189.     PAGE_TYPE_LANG,
  190.     PAGE_TYPE_APPS,
  191.     PAGE_TYPE_MAILNEWS,
  192.     PAGE_TYPE_MAILNEWS_IDENTITY,
  193.     PAGE_TYPE_MAILNEWS_COMPOSITION,
  194.     PAGE_TYPE_MAILNEWS_MAILSERVER,
  195.     PAGE_TYPE_MAILNEWS_NEWSSERVER,
  196.     PAGE_TYPE_MAILNEWS_ADDRBOOK,
  197.     PAGE_TYPE_EDITOR,
  198.     PAGE_TYPE_EDITOR_APPEARANCE,
  199.     PAGE_TYPE_EDITOR_PUBLISH,
  200.     PAGE_TYPE_ADVANCED,
  201.     PAGE_TYPE_CACHE,
  202.     PAGE_TYPE_PROXIES,
  203.     PAGE_TYPE_DISKSPACE
  204. #ifdef PREFS_UNSUPPORTED
  205.     PAGE_TYPE_HELPFILES
  206.     PAGE_TYPE_OFFLINE,
  207.     PAGE_TYPE_OFFLINE_NEWS,
  208. #endif /* PREFS_UNSUPPORTED */
  209. } PrefsPageType;
  210.  
  211. struct _prefsCategory {
  212.     char                  *name;
  213.     char                  *catResName;
  214.     char                  *catResClass;
  215.     char                  *descResName;
  216.     char                  *descResClass;
  217.     Boolean                leaf;
  218.     struct _prefsCategory *children;
  219.     int                    numChildren;
  220.     int                    type;
  221. };
  222.  
  223. struct _prefsCategory prefsAppearance[] = {
  224.     {
  225.         CAT_FONTS,      
  226.         CAT_RESNAME_FONTS,      
  227.         CAT_RESCLASS_FONTS,      
  228.         DESC_RESNAME_FONTS,      
  229.         DESC_RESCLASS_FONTS,      
  230.         TRUE,
  231.         NULL,
  232.         0,
  233.         PAGE_TYPE_FONTS,
  234.     },
  235.     {
  236.         CAT_COLORS,      
  237.         CAT_RESNAME_COLORS,      
  238.         CAT_RESCLASS_COLORS,      
  239.         DESC_RESNAME_COLORS,      
  240.         DESC_RESCLASS_COLORS,      
  241.         TRUE,
  242.         NULL,
  243.         0,
  244.         PAGE_TYPE_COLORS,
  245.     },
  246. };
  247.  
  248. struct _prefsCategory prefsMailNews[] = {
  249.     {
  250.         CAT_MAILNEWS_IDENTITY, 
  251.         CAT_RESNAME_MAILNEWS_IDENTITY, 
  252.         CAT_RESCLASS_MAILNEWS_IDENTITY, 
  253.         DESC_RESNAME_MAILNEWS_IDENTITY, 
  254.         DESC_RESCLASS_MAILNEWS_IDENTITY, 
  255.         TRUE,
  256.         NULL,
  257.         0,
  258.         PAGE_TYPE_MAILNEWS_IDENTITY,
  259.     },
  260.     {
  261.         CAT_MAILNEWS_COMPOSITION,
  262.         CAT_RESNAME_MAILNEWS_COMPOSITION,
  263.         CAT_RESCLASS_MAILNEWS_COMPOSITION,
  264.         DESC_RESNAME_MAILNEWS_COMPOSITION,
  265.         DESC_RESCLASS_MAILNEWS_COMPOSITION,
  266.         TRUE,  
  267.         NULL,
  268.         0,
  269.         PAGE_TYPE_MAILNEWS_COMPOSITION,
  270.     },
  271.     {
  272.         CAT_MAILNEWS_MAILSERVER, 
  273.         CAT_RESNAME_MAILNEWS_MAILSERVER, 
  274.         CAT_RESCLASS_MAILNEWS_MAILSERVER, 
  275.         DESC_RESNAME_MAILNEWS_MAILSERVER, 
  276.         DESC_RESCLASS_MAILNEWS_MAILSERVER, 
  277.         TRUE,  
  278.         NULL, 
  279.         0,
  280.         PAGE_TYPE_MAILNEWS_MAILSERVER,
  281.     },
  282.     {
  283.         CAT_MAILNEWS_NEWSSERVER, 
  284.         CAT_RESNAME_MAILNEWS_NEWSSERVER, 
  285.         CAT_RESCLASS_MAILNEWS_NEWSSERVER, 
  286.         DESC_RESNAME_MAILNEWS_NEWSSERVER, 
  287.         DESC_RESCLASS_MAILNEWS_NEWSSERVER, 
  288.         TRUE,  
  289.         NULL, 
  290.         0,
  291.         PAGE_TYPE_MAILNEWS_NEWSSERVER,
  292.     },
  293.     {
  294.         CAT_MAILNEWS_ADDRBOOK,    
  295.         CAT_RESNAME_MAILNEWS_ADDRBOOK,    
  296.         CAT_RESCLASS_MAILNEWS_ADDRBOOK,    
  297.         DESC_RESNAME_MAILNEWS_ADDRBOOK,    
  298.         DESC_RESCLASS_MAILNEWS_ADDRBOOK,    
  299.         TRUE,  
  300.         NULL,
  301.         0, 
  302.         PAGE_TYPE_MAILNEWS_ADDRBOOK,
  303.     },
  304. };
  305.  
  306. struct _prefsCategory prefsEditor[] = {
  307.     {
  308.         CAT_EDITOR_APPEARANCE,      
  309.         CAT_RESNAME_EDITOR_APPEARANCE,      
  310.         CAT_RESCLASS_EDITOR_APPEARANCE,      
  311.         DESC_RESNAME_EDITOR_APPEARANCE,      
  312.         DESC_RESCLASS_EDITOR_APPEARANCE,      
  313.         TRUE,
  314.         NULL,
  315.         0,
  316.         PAGE_TYPE_EDITOR_APPEARANCE,
  317.     },
  318.     {
  319.         CAT_EDITOR_PUBLISH,      
  320.         CAT_RESNAME_EDITOR_PUBLISH,      
  321.         CAT_RESCLASS_EDITOR_PUBLISH,      
  322.         DESC_RESNAME_EDITOR_PUBLISH,      
  323.         DESC_RESCLASS_EDITOR_PUBLISH,      
  324.         TRUE,
  325.         NULL,
  326.         0,
  327.         PAGE_TYPE_EDITOR_PUBLISH,
  328.     },
  329. };
  330.  
  331. #ifdef PREFS_UNSUPPORTED
  332. struct _prefsCategory prefsOffline[] = {
  333.     {
  334.         CAT_OFFLINE_NEWS,      
  335.         CAT_RESNAME_OFFLINE_NEWS,      
  336.         CAT_RESCLASS_OFFLINE_NEWS,      
  337.         DESC_RESNAME_OFFLINE_NEWS,      
  338.         DESC_RESCLASS_OFFLINE_NEWS,      
  339.         TRUE,
  340.         NULL,
  341.         0,
  342.         PAGE_TYPE_OFFLINE_NEWS,
  343.     },
  344. };
  345. #endif /* PREFS_UNSUPPORTED */
  346.  
  347. struct _prefsCategory prefsBrowser[] = {
  348.     {
  349.         CAT_LANG, 
  350.         CAT_RESNAME_LANG, 
  351.         CAT_RESCLASS_LANG, 
  352.         DESC_RESNAME_LANG, 
  353.         DESC_RESCLASS_LANG, 
  354.         TRUE,
  355.         NULL,
  356.         0,
  357.         PAGE_TYPE_LANG,
  358.     },
  359.     {
  360.         CAT_APPS, 
  361.         CAT_RESNAME_APPS, 
  362.         CAT_RESCLASS_APPS, 
  363.         DESC_RESNAME_APPS, 
  364.         DESC_RESCLASS_APPS, 
  365.         TRUE,
  366.         NULL,
  367.         0,
  368.         PAGE_TYPE_APPS,
  369.     },
  370. };
  371.  
  372. struct _prefsCategory prefsAdvanced[] = {
  373.     {
  374.         CAT_CACHE,
  375.         CAT_RESNAME_CACHE,
  376.         CAT_RESCLASS_CACHE,
  377.         DESC_RESNAME_CACHE,
  378.         DESC_RESCLASS_CACHE,
  379.         TRUE,
  380.         NULL,
  381.         0,
  382.         PAGE_TYPE_CACHE,
  383.     },
  384.     {
  385.         CAT_PROXIES,
  386.         CAT_RESNAME_PROXIES,
  387.         CAT_RESCLASS_PROXIES,
  388.         DESC_RESNAME_PROXIES,
  389.         DESC_RESCLASS_PROXIES,
  390.         TRUE,
  391.         NULL,
  392.         0,
  393.         PAGE_TYPE_PROXIES,
  394.     },
  395. #ifdef MOZ_MAIL_NEWS
  396.     {
  397.         CAT_DISKSPACE,      
  398.         CAT_RESNAME_DISKSPACE,      
  399.         CAT_RESCLASS_DISKSPACE,      
  400.         DESC_RESNAME_DISKSPACE,      
  401.         DESC_RESCLASS_DISKSPACE,      
  402.         TRUE,
  403.         NULL,
  404.         0,
  405.         PAGE_TYPE_DISKSPACE,
  406.     },
  407. #endif // MOZ_MAIL_NEWS
  408. #ifdef PREFS_UNSUPPORTED
  409.     {
  410.         CAT_HELPFILES,      
  411.         CAT_RESNAME_HELPFILES,      
  412.         CAT_RESCLASS_HELPFILES,      
  413.         DESC_RESNAME_HELPFILES,      
  414.         DESC_RESCLASS_HELPFILES,      
  415.         TRUE,
  416.         NULL,
  417.         0,
  418.         PAGE_TYPE_HELPFILES,
  419.     },
  420. #endif /* PREFS_UNSUPPORTED */
  421. };
  422.  
  423. struct _prefsCategory prefsCategories[] = {
  424.     {
  425.         CAT_APPEARANCE,     
  426.         CAT_RESNAME_APPEARANCE,     
  427.         CAT_RESCLASS_APPEARANCE,     
  428.         DESC_RESNAME_APPEARANCE,     
  429.         DESC_RESCLASS_APPEARANCE,     
  430.         FALSE, 
  431.         prefsAppearance,  
  432.         XtNumber(prefsAppearance), 
  433.         PAGE_TYPE_APPEARANCE,
  434.     },
  435.     {
  436.         CAT_BROWSER,         
  437.         CAT_RESNAME_BROWSER,         
  438.         CAT_RESCLASS_BROWSER,         
  439.         DESC_RESNAME_BROWSER,         
  440.         DESC_RESCLASS_BROWSER,         
  441.         FALSE,  
  442.         prefsBrowser,
  443.         XtNumber(prefsBrowser), 
  444.         PAGE_TYPE_BROWSER,
  445.     },
  446. #ifndef MOZ_MAIL_NEWS
  447.     {
  448.         CAT_MAILNEWS_IDENTITY, 
  449.         CAT_RESNAME_MAILNEWS_IDENTITY, 
  450.         CAT_RESCLASS_MAILNEWS_IDENTITY, 
  451.         DESC_RESNAME_MAILNEWS_IDENTITY, 
  452.         DESC_RESCLASS_MAILNEWS_IDENTITY, 
  453.         FALSE,
  454.         NULL,
  455.         0,
  456.         PAGE_TYPE_MAILNEWS_IDENTITY,
  457.     },
  458. #endif // MOZ_MAIL_NEWS
  459. #ifdef MOZ_MAIL_NEWS
  460.     {
  461.         CAT_MAILNEWS,    
  462.         CAT_RESNAME_MAILNEWS,    
  463.         CAT_RESCLASS_MAILNEWS,    
  464.         DESC_RESNAME_MAILNEWS,    
  465.         DESC_RESCLASS_MAILNEWS,    
  466.         FALSE,   
  467.         prefsMailNews, 
  468.         XtNumber(prefsMailNews),
  469.         PAGE_TYPE_MAILNEWS,
  470.     },
  471.     {
  472.         CAT_EDITOR,               
  473.         CAT_RESNAME_EDITOR,               
  474.         CAT_RESCLASS_EDITOR,               
  475.         DESC_RESNAME_EDITOR,               
  476.         DESC_RESCLASS_EDITOR,               
  477.         FALSE,   
  478.         prefsEditor, 
  479.         XtNumber(prefsEditor),
  480.         PAGE_TYPE_EDITOR,
  481.     },
  482. #endif // MOZ_MAIL_NEWS
  483. #ifdef PREFS_UNSUPPORTED
  484.     {
  485.         CAT_OFFLINE,               
  486.         CAT_RESNAME_OFFLINE,               
  487.         CAT_RESCLASS_OFFLINE,               
  488.         DESC_RESNAME_OFFLINE,               
  489.         DESC_RESCLASS_OFFLINE,               
  490.         FALSE,   
  491.         prefsOffline, 
  492.         XtNumber(prefsOffline),
  493.         PAGE_TYPE_OFFLINE,
  494.     },
  495. #endif /* PREFS_UNSUPPORTED */
  496.     {
  497.         CAT_ADVANCED,
  498.         CAT_RESNAME_ADVANCED,               
  499.         CAT_RESCLASS_ADVANCED,               
  500.         DESC_RESNAME_ADVANCED,               
  501.         DESC_RESCLASS_ADVANCED,               
  502.         FALSE,   
  503.         prefsAdvanced, 
  504.         XtNumber(prefsAdvanced),
  505.         PAGE_TYPE_ADVANCED,
  506.     },
  507. };
  508.  
  509. extern "C"
  510. {
  511.     Widget    fe_CreateFramedForm(Widget, char*, Arg*, Cardinal);
  512.     char     *XP_GetString(int i);
  513. }
  514.  
  515. extern "C" void
  516. fe_showPreferences(XFE_Component *topLevel, MWContext *context)
  517. {
  518.     XFE_PrefsDialog   *theDialog = 0;
  519.     Widget             mainw = topLevel->getBaseWidget();
  520.  
  521.     // Instantiate a preferences dialog
  522.  
  523.     if ((theDialog = new XFE_PrefsDialog(mainw, "prefs", context)) == 0) {
  524.         fe_perror(context, XP_GetString(XFE_OUT_OF_MEMORY_URL));
  525.         return;
  526.     }
  527.  
  528.     // Open some categories
  529.  
  530.     theDialog->openCategory(CAT_APPEARANCE);
  531.  
  532.     // Pop up the preferences dialog
  533.  
  534.     theDialog->show();
  535.     
  536.     // Set the page to Appearance
  537.     
  538.     PrefsCategory *appearance = theDialog->getCategoryByName(CAT_APPEARANCE);
  539.     theDialog->setCurrentCategory(appearance);
  540. }
  541.  
  542. extern "C" void
  543. fe_showMailNewsPreferences(XFE_Component *topLevel, MWContext *context)
  544. {
  545.     XFE_PrefsDialog   *theDialog = 0;
  546.     Widget             mainw = topLevel->getBaseWidget();
  547.  
  548.     // Instantiate a preferences dialog
  549.  
  550.     if ((theDialog = new XFE_PrefsDialog(mainw, "prefs", context)) == 0) {
  551.         fe_perror(context, XP_GetString(XFE_OUT_OF_MEMORY_URL));
  552.         return;
  553.     }
  554.  
  555.     // Open some categories
  556.  
  557.     theDialog->openCategory(CAT_APPEARANCE);
  558.     theDialog->openCategory(CAT_MAILNEWS);
  559.  
  560.     // Pop up the preferences dialog
  561.  
  562.     theDialog->show();
  563.  
  564.     // Set the page to Appearance
  565.     
  566.     PrefsCategory *appearance = theDialog->getCategoryByName(CAT_MAILNEWS);
  567.     theDialog->setCurrentCategory(appearance);
  568. }
  569.  
  570. extern "C" void
  571. fe_showMailServerPreferences(XFE_Component *topLevel, MWContext *context)
  572. {
  573.     XFE_PrefsDialog   *theDialog = 0;
  574.     Widget             mainw = topLevel->getBaseWidget();
  575.  
  576.     // Instantiate a preferences dialog
  577.  
  578.     if ((theDialog = new XFE_PrefsDialog(mainw, "prefs", context)) == 0) {
  579.         fe_perror(context, XP_GetString(XFE_OUT_OF_MEMORY_URL));
  580.         return;
  581.     }
  582.  
  583.     // Open some categories
  584.  
  585.     theDialog->openCategory(CAT_MAILNEWS);
  586.  
  587.     // Pop up the preferences dialog
  588.  
  589.     theDialog->show();
  590.  
  591.     // Set the page to Mail Servers
  592.     
  593.     PrefsCategory *mailserver_category = theDialog->getCategoryByName(CAT_MAILNEWS_MAILSERVER);
  594.     theDialog->setCurrentCategory(mailserver_category);
  595. }
  596.  
  597. extern "C" void
  598. fe_showMailIdentityPreferences(XFE_Component *topLevel, MWContext *context)
  599. {
  600.     XFE_PrefsDialog   *theDialog = 0;
  601.     Widget             mainw = topLevel->getBaseWidget();
  602.  
  603.     // Instantiate a preferences dialog
  604.  
  605.     if ((theDialog = new XFE_PrefsDialog(mainw, "prefs", context)) == 0) {
  606.         fe_perror(context, XP_GetString(XFE_OUT_OF_MEMORY_URL));
  607.         return;
  608.     }
  609.  
  610.     // Open some categories
  611.  
  612.     theDialog->openCategory(CAT_MAILNEWS);
  613.  
  614.     // Pop up the preferences dialog
  615.  
  616.     theDialog->show();
  617.  
  618.     // Set the page to Mail Identity
  619.     
  620.     PrefsCategory *identity_category = theDialog->getCategoryByName(CAT_MAILNEWS_IDENTITY);
  621.     theDialog->setCurrentCategory(identity_category);
  622. }
  623.  
  624. extern "C" void
  625. fe_showEditorPreferences(XFE_Component *topLevel, MWContext *context)
  626. {
  627.     XFE_PrefsDialog   *theDialog = 0;
  628.     Widget             mainw = topLevel->getBaseWidget();
  629.  
  630.     // Instantiate a preferences dialog
  631.  
  632.     if ((theDialog = new XFE_PrefsDialog(mainw, "prefs", context)) == 0) {
  633.         fe_perror(context, XP_GetString(XFE_OUT_OF_MEMORY_URL));
  634.         return;
  635.     }
  636.  
  637.     // Open some categories
  638.  
  639.     theDialog->openCategory(CAT_APPEARANCE);
  640.     theDialog->openCategory(CAT_EDITOR);
  641.  
  642.     // Pop up the preferences dialog
  643.  
  644.     theDialog->show();
  645.  
  646.     // Set the page to Appearance
  647.     
  648.     PrefsCategory *appearance = theDialog->getCategoryByName(CAT_EDITOR);
  649.     theDialog->setCurrentCategory(appearance);
  650. }
  651.  
  652. // ==================== Prefs Page Member Functions ====================
  653.  
  654. // Member:       XFE_PrefsPage
  655. // Description:  Constructor
  656. // Inputs:
  657. // Side effects: Creates a preferences page
  658.  
  659. XFE_PrefsPage::XFE_PrefsPage(XFE_PrefsDialog *prefsDialog) :  // prefs dialog
  660.     m_context(0),
  661.     m_prefsDialog(prefsDialog),
  662.     m_wPageForm(0),
  663.     m_wPage(0),
  664.     m_created(FALSE),
  665.     m_initialized(FALSE),
  666.     m_doInitInMap(FALSE),
  667.     m_changed(FALSE)
  668. {
  669.     m_wPageForm = m_prefsDialog->getPageForm();
  670.     m_context = m_prefsDialog->getContext();
  671. }
  672.  
  673. // Member:       ~XFE_PrefsPage
  674. // Description:  Destructor
  675. // Inputs:
  676. // Side effects: Destoy a preferences page
  677.  
  678. XFE_PrefsPage::~XFE_PrefsPage()
  679. {
  680. }
  681.  
  682. // Member:       setCreated
  683. // Description: 
  684. // Inputs:
  685. // Side effects: 
  686.  
  687. void XFE_PrefsPage::setCreated(Boolean flag)
  688. {
  689.     m_created = flag;
  690. }
  691.  
  692. // Member:       setChanged
  693. // Description: 
  694. // Inputs:
  695. // Side effects: 
  696.  
  697. void XFE_PrefsPage::setChanged(Boolean flag)
  698. {
  699.     m_changed = flag;
  700. }
  701.  
  702. // Member:       setInitialized
  703. // Description: 
  704. // Inputs:
  705. // Side effects: 
  706.  
  707. void XFE_PrefsPage::setInitialized(Boolean flag)
  708. {
  709.     m_initialized = flag;
  710. }
  711.  
  712. // Member:       setDoInitInMap
  713. // Description: 
  714. // Inputs:
  715. // Side effects: 
  716.  
  717. void XFE_PrefsPage::setDoInitInMap(Boolean flag)
  718. {
  719.     m_doInitInMap = flag;
  720. }
  721.  
  722. // Member:       isCreated
  723. // Description: 
  724. // Inputs:
  725. // Side effects: 
  726.  
  727. Boolean XFE_PrefsPage::isCreated() 
  728. {
  729.     return m_doInitInMap;
  730. }
  731.  
  732. // Member:       isInitialized
  733. // Description: 
  734. // Inputs:
  735. // Side effects: 
  736.  
  737. Boolean XFE_PrefsPage::isInitialized() 
  738. {
  739.     return m_initialized;
  740. }
  741.  
  742. // Member:       doInitInMap
  743. // Description: 
  744. // Inputs:
  745. // Side effects: 
  746.  
  747. Boolean XFE_PrefsPage::doInitInMap() 
  748. {
  749.     return m_doInitInMap;
  750. }
  751.  
  752. // Member:       isChanged
  753. // Description: 
  754. // Inputs:
  755. // Side effects: 
  756.  
  757. Boolean XFE_PrefsPage::isChanged() 
  758. {
  759.     return m_changed;
  760. }
  761.  
  762. // Member:       getContext
  763. // Description: 
  764. // Inputs:
  765. // Side effects: 
  766.  
  767. MWContext *XFE_PrefsPage::getContext() 
  768. {
  769.     return m_context;
  770. }
  771.  
  772. // Member:       getPrefsDialog
  773. // Description: 
  774. // Inputs:
  775. // Side effects: 
  776.  
  777. XFE_PrefsDialog *XFE_PrefsPage::getPrefsDialog() 
  778. {
  779.     return m_prefsDialog;
  780. }
  781.  
  782. // Member:       getWidth
  783. // Description: 
  784. // Inputs:
  785. // Side effects: 
  786.  
  787. Dimension XFE_PrefsPage::getWidth() 
  788. {
  789.     return XfeWidth(m_wPage);
  790. }
  791.  
  792. // Member:       getHeight
  793. // Description: 
  794. // Inputs:
  795. // Side effects: 
  796.  
  797. Dimension XFE_PrefsPage::getHeight()
  798. {
  799.     return XfeHeight(m_wPage);
  800. }
  801.  
  802. // Member:       map
  803. // Description:  Displays page
  804. // Inputs:
  805. // Side effects: 
  806.  
  807. void XFE_PrefsPage::map()
  808. {
  809.     // Create the page if not created already
  810.  
  811.     if (! isCreated()) create();
  812.     
  813.     // Initialize the page
  814.  
  815.     if (doInitInMap()){
  816.         if (! isInitialized()) init();
  817.         setChanged(TRUE);
  818.     }
  819.     
  820.     // Display the page
  821.  
  822.     XtManageChild(m_wPage);
  823. }
  824.  
  825. // Member:       unmap
  826. // Description:  
  827. // Inputs:
  828. // Side effects: 
  829.  
  830. void XFE_PrefsPage::unmap()
  831. {
  832.     XtUnmanageChild(m_wPage);
  833. }
  834.  
  835. // Member:       verify
  836. // Description:  
  837. // Inputs:
  838. // Side effects: 
  839.  
  840. Boolean XFE_PrefsPage::verify()
  841. {
  842.     return TRUE;
  843. }
  844.  
  845. // ==================== Prefs Dialog Member Functions ====================
  846.  
  847. // Member:       XFE_PrefsDialog
  848. // Description:  Constructor
  849. // Inputs:
  850. // Side effects: Creates a preferences dialog
  851.  
  852. XFE_PrefsDialog::XFE_PrefsDialog(Widget     parent,      // dialog parent
  853.                                  char      *name,        // dialog name
  854.                                  MWContext *context,     // context
  855.                                  Boolean    modal)       // modal dialog?
  856.     : XFE_Dialog(parent, 
  857.                  name,
  858.                  TRUE,     // ok
  859.                  TRUE,     // cancel
  860.                  TRUE,     // help
  861.                  FALSE,    // apply
  862.                  FALSE,    // separator
  863.                  modal     // modal
  864.                  ),
  865.       m_wPageLabel(0),
  866.       m_wPageTitle(0),
  867.       m_wPageForm(0),
  868.       m_wOutline(0),
  869.       m_context(context),
  870.       m_numPages(0),
  871.       m_pages(0),
  872.       m_columnWidths(0),
  873.       m_outlineHeaders(0),
  874.       m_numCategories(0),
  875.       m_categories(0),
  876.       m_visibleCategoryCount(0),
  877.       m_currentCategory(0),
  878.       m_initPageLabel(FALSE)
  879. {
  880.     // Create areas for use later
  881.  
  882.     createRegions();
  883.  
  884.     // Initialize categories
  885.  
  886.     initCategories();
  887.  
  888.     // Add callbacks
  889.  
  890.     XtAddCallback (m_chrome, XmNokCallback, prefsMainCb_ok, this);
  891.     XtAddCallback (m_chrome, XmNcancelCallback, prefsMainCb_cancel, this);
  892.     XtAddCallback (m_chrome, XmNhelpCallback, prefsMainCb_help, this);
  893.     XtAddCallback (m_chrome, XmNdestroyCallback, prefsMainCb_destroy, this);
  894. }
  895.  
  896. // Member:       prefsMainCb_ok
  897. // Description:  
  898. // Inputs:
  899. // Side effects: 
  900.  
  901. void XFE_PrefsDialog::prefsMainCb_ok(Widget    w,
  902.                                      XtPointer closure,
  903.                                      XtPointer callData)
  904. {
  905.     XFE_PrefsDialog *theDialog = (XFE_PrefsDialog *)closure;
  906.  
  907.     // Verify the current page
  908.  
  909.     PrefsCategory *currentCategory = theDialog->getCurrentCategory();
  910.     if (currentCategory &&
  911.         currentCategory->page) {
  912.         if (! currentCategory->page->verify())
  913.             return;
  914.     }
  915.  
  916.     // hide ourself so any dialogs popped up will become children
  917.     // of the parent frame.
  918.     theDialog->hide();
  919.  
  920.     // Save all the changes 
  921.  
  922.     theDialog->saveChanges();
  923.  
  924.     // Simulate a cancel on Ok
  925.     theDialog->prefsMainCb_cancel(w, closure, callData);
  926. }
  927.  
  928. // Member:       prefsMainCb_cancel
  929. // Description:  
  930. // Inputs:
  931. // Side effects: 
  932.  
  933. void XFE_PrefsDialog::prefsMainCb_cancel(Widget    /* w */,
  934.                                          XtPointer closure,
  935.                                          XtPointer /* callData */)
  936. {
  937.     XFE_PrefsDialog *theDialog = (XFE_PrefsDialog *)closure;
  938.  
  939.     // Remove all the callbacks 
  940.  
  941.     XtRemoveCallback(theDialog->m_chrome, XmNokCallback, prefsMainCb_ok, theDialog);
  942.     XtRemoveCallback(theDialog->m_chrome, XmNcancelCallback, prefsMainCb_cancel, theDialog);
  943.     XtRemoveCallback(theDialog->m_chrome, XmNhelpCallback, prefsMainCb_help, theDialog);
  944.     XtRemoveCallback(theDialog->m_chrome, XmNdestroyCallback, prefsMainCb_destroy, theDialog);
  945.  
  946.     // Delete the dialog
  947.  
  948.     delete theDialog;
  949. }
  950.  
  951. // Member:       prefsMainCb_help
  952. // Description:  
  953. // Inputs:
  954. // Side effects: 
  955.  
  956. void XFE_PrefsDialog::prefsMainCb_help(Widget    /* w */,
  957.                                        XtPointer /* closure */,
  958.                                        XtPointer /* callData */)
  959. {
  960.     //    XFE_PrefsDialog *theDialog = (XFE_PrefsDialog *)closure;
  961. }
  962.  
  963. // Member:       prefsMainCb_destroy
  964. // Description:  
  965. // Inputs:
  966. // Side effects: 
  967.  
  968. void XFE_PrefsDialog::prefsMainCb_destroy(Widget    w,
  969.                                           XtPointer closure,
  970.                                           XtPointer callData)
  971. {
  972.     XFE_PrefsDialog *theDialog = (XFE_PrefsDialog *)closure;
  973.  
  974.     // Simulate a cancel on destroy
  975.     theDialog->prefsMainCb_cancel(w, closure, callData);
  976. }
  977.  
  978. // Member:       ~XFE_PrefsDialog
  979. // Description:  Destructor
  980. // Inputs:
  981. // Side effects: 
  982.  
  983. XFE_PrefsDialog::~XFE_PrefsDialog()
  984. {
  985.     // Clean up
  986.  
  987.     for (int i = 0; i < m_numPages; i++)
  988.         delete m_pages[i];
  989.     delete [] m_pages;
  990.  
  991.     delete m_columnWidths;
  992.     if (m_outlineHeaders->header_strings)
  993.         XP_FREE(m_outlineHeaders->header_strings);
  994.     XP_FREE(m_outlineHeaders);
  995. }
  996.  
  997. // Member:       getContext
  998. // Description:  Gets MWContext (for now) 
  999. // Inputs:
  1000. // Side effects: 
  1001.  
  1002. MWContext *XFE_PrefsDialog::getContext()
  1003. {
  1004.     return m_context;
  1005. }
  1006.  
  1007. // Member:       getVisibleCategoryCount
  1008. // Description:  Gets number of visible categories
  1009. // Inputs:
  1010. // Side effects: 
  1011.  
  1012. int XFE_PrefsDialog::getVisibleCategoryCount()
  1013. {
  1014.     if (m_visibleCategoryCount == 0) {
  1015.         calcVisibleCategoryCount();
  1016.     }
  1017.  
  1018.     return m_visibleCategoryCount;
  1019. }
  1020.  
  1021. // Member:       show
  1022. // Description:  Pop up dialog
  1023. // Inputs:
  1024. // Side effects: 
  1025.  
  1026. void XFE_PrefsDialog::show()
  1027. {
  1028.     int i;
  1029.  
  1030.     refreshCategories();
  1031.  
  1032.     // Make sure we create all the pages first, so we can determine
  1033.     // the height and width of the preferences dialog.
  1034.     // Do not initialize the page to save time
  1035.  
  1036.     setDoInitInSetPage(FALSE);
  1037.  
  1038.     for (i = 0; i < m_numPages; i++) {
  1039.         m_pages[i]->map();
  1040.     }
  1041.  
  1042.     setDoInitInSetPage(TRUE);
  1043.  
  1044.     // Manage the top level
  1045.  
  1046.     XFE_Dialog::show();
  1047.  
  1048.     // Determine the height and width of the preferences dialog
  1049.  
  1050.     int page_width = calculateWidth();
  1051.  
  1052.     int page_height = calculateHeight();
  1053.  
  1054.     Dimension margin_width;
  1055.     Dimension margin_height;
  1056.  
  1057.     XtVaGetValues(m_wPageForm,
  1058.                   XmNmarginWidth, &margin_width,
  1059.                   XmNmarginHeight, &margin_height,
  1060.                   NULL);
  1061.  
  1062.     XtVaSetValues(m_wPageForm,
  1063.                   XmNwidth, page_width + 2 * margin_width,
  1064.                   XmNheight, page_height + 2 * margin_height,
  1065.                   XmNresizePolicy, XmRESIZE_NONE,
  1066.                   NULL);
  1067.  
  1068.     // Reset the categories 
  1069.  
  1070.     for (i = 0; i < m_numPages; i++) {
  1071.         m_pages[i]->unmap();
  1072.     }
  1073.  
  1074.     setCurrentCategory(NULL);
  1075.  
  1076.     // Move focus to the OK button
  1077.  
  1078.     XmProcessTraversal(m_okButton, XmTRAVERSE_CURRENT);
  1079. }
  1080.  
  1081. // Member:       setContext
  1082. // Description:  Sets MWContext (for now) 
  1083. // Inputs:
  1084. // Side effects: 
  1085.  
  1086. void XFE_PrefsDialog::setContext(MWContext *context)
  1087. {
  1088.     m_context = context;
  1089. }
  1090.  
  1091. // Member:       calcVisibleCategoryCount
  1092. // Description:  Calculates number of visible categories
  1093. // Inputs:
  1094. // Side effects: 
  1095.  
  1096. void XFE_PrefsDialog::calcVisibleCategoryCount()
  1097. {
  1098.     int  i;
  1099.     int  count = 0;
  1100.  
  1101.     for (i = 0; i < m_numCategories; i++) {
  1102.         count++;
  1103.         if (m_categories[i].open) {
  1104.             count += m_categories[i].numChildren;
  1105.         }
  1106.     }
  1107.     m_visibleCategoryCount = count;
  1108. }
  1109.  
  1110. // Member:       setCurrentCategory
  1111. // Description:  Set currently selected category 
  1112. // Inputs:
  1113. // Side effects: 
  1114.  
  1115. void XFE_PrefsDialog::setCurrentCategory(PrefsCategory *entry)
  1116. {
  1117.     XmString labelString;
  1118.  
  1119.     // If the page label is not set reverse video, do it now.
  1120.     // Reverse video the label if we are setting a real page.
  1121.  
  1122.     if (entry != NULL) {
  1123.         if (m_initPageLabel == FALSE) {
  1124.             Pixel bg;
  1125.             Pixel fg;
  1126.             XtVaGetValues(m_wPageTitle, 
  1127.                           XmNbackground, &bg,
  1128.                           XmNforeground, &fg,
  1129.                           NULL);
  1130.             XtVaSetValues(m_wPageTitle,
  1131.                           XmNforeground, bg,
  1132.                           XmNbackground, fg,
  1133.                           NULL);
  1134.             m_initPageLabel = TRUE;
  1135.         }
  1136.     }
  1137.  
  1138.     // Unset old page
  1139.  
  1140.     if (m_currentCategory) {
  1141.         if (m_currentCategory->page != 0) {
  1142.             if (! m_currentCategory->page->verify())
  1143.                 return;
  1144.             m_currentCategory->page->unmap();
  1145.         }
  1146.     }
  1147.  
  1148.     m_currentCategory = entry;
  1149.  
  1150.     if (! entry) {
  1151.  
  1152.         // unset the page label and description
  1153.  
  1154.         labelString =
  1155.             XmStringCreateLtoR(" ", (XmStringCharSet)XmFONTLIST_DEFAULT_TAG);
  1156.         XtVaSetValues(m_wPageLabel,
  1157.                       XmNlabelString, labelString,
  1158.                       NULL);
  1159.         XmStringFree(labelString);
  1160.  
  1161.         labelString =
  1162.             XmStringCreateLtoR(" ", (XmStringCharSet)XmFONTLIST_DEFAULT_TAG);
  1163.         XtVaSetValues(m_wPageTitle,
  1164.                       XmNlabelString, labelString,
  1165.                       NULL);
  1166.         XmStringFree(labelString);
  1167.  
  1168.         return;
  1169.     }
  1170.  
  1171.     // Set the page label and description.
  1172.     // Page label is not displayed any more.
  1173.  
  1174.     labelString = XmStringCreateLtoR(" ", (XmStringCharSet)XmFONTLIST_DEFAULT_TAG);
  1175.     XtVaSetValues(m_wPageLabel,
  1176.                   XmNlabelString, labelString,
  1177.                   NULL);
  1178.     XmStringFree(labelString);
  1179.  
  1180.     XmString s1;
  1181.     XmString s2;
  1182.     XmString s3;
  1183.     XmString labelString2;
  1184.     
  1185.     s1 = XmStringCreate(entry->categoryName, TAG_BOLD);
  1186.     s2 = XmStringCreate("   ", TAG_NORMAL);
  1187.     if (entry->categoryDesc)
  1188.         s3 = XmStringCreate(entry->categoryDesc, TAG_NORMAL);
  1189.     else
  1190.         s3 = XmStringCreate(" ", TAG_NORMAL);
  1191.     labelString = XmStringConcat(s1, s2);
  1192.     labelString2 = XmStringConcat(labelString, s3);
  1193.     XtVaSetValues(m_wPageTitle,
  1194.                   XmNlabelString, labelString2,
  1195.                   NULL);
  1196.  
  1197.     XmStringFree(s1);
  1198.     XmStringFree(s2);
  1199.     XmStringFree(s3);
  1200.     XmStringFree(labelString);
  1201.     XmStringFree(labelString2);
  1202.  
  1203.     // Set the page
  1204.  
  1205.     if (entry->page != 0) {
  1206.         entry->page->map();
  1207.         refreshCategories();
  1208.     }
  1209. }
  1210.  
  1211. // Member:       openCategory
  1212. // Description:  Open a category
  1213. // Inputs:
  1214. // Side effects: 
  1215.  
  1216. void XFE_PrefsDialog::openCategory(const char *catName)
  1217. {
  1218.     PrefsCategory *entry = getCategoryByName(catName);
  1219.     
  1220.     if (entry) {
  1221.         entry->open = TRUE;
  1222.     }
  1223. }
  1224.  
  1225. // Member:       closeCategory
  1226. // Description:  Close a category
  1227. // Inputs:
  1228. // Side effects: 
  1229.  
  1230. void XFE_PrefsDialog::closeCategory(const char *catName)
  1231. {
  1232.     PrefsCategory *entry = getCategoryByName(catName);
  1233.     
  1234.     if (entry) {
  1235.         entry->open = FALSE;
  1236.     }
  1237. }
  1238.  
  1239. // Member:       setDoInitInSetPage
  1240. // Description:  
  1241. // Inputs:
  1242. // Side effects: 
  1243.  
  1244. void XFE_PrefsDialog::setDoInitInSetPage(Boolean doInit)
  1245. {
  1246.     for (int i = 0; i < m_numPages; i++) {
  1247.         m_pages[i]->setDoInitInMap(doInit);
  1248.     }
  1249. }
  1250.  
  1251. // Member:       saveChanges
  1252. // Description:  
  1253. // Inputs:
  1254. // Side effects: 
  1255.  
  1256. void XFE_PrefsDialog::saveChanges()
  1257. {
  1258.     int32 tempInt; // for news xaction pref below
  1259.  
  1260.     for (int i = 0; i < m_numPages; i++) {
  1261.         if (m_pages[i]->isChanged()) {
  1262.             m_pages[i]->save();
  1263.         }
  1264.     }
  1265.  
  1266.     // Save the preferences at the end, so that if we've found some 
  1267.     // setting that crashes, it won't get saved...
  1268.  
  1269.     if (! fe_CheckVersionAndSavePrefs((char *) fe_globalData.user_prefs_file, &fe_globalPrefs))
  1270.         fe_perror(getContext(), XP_GetString( XFE_ERROR_SAVING_OPTIONS));
  1271.  
  1272.     // ### mwelch 97 July
  1273.     // Since the default news server preference spans across three different
  1274.     // preferences, we need to always tweak the "news.server_change_xaction"
  1275.     // pref, in order to signal to the back end that the news server prefs
  1276.     // have settled into a steady state.
  1277.     PREF_GetIntPref("news.server_change_xaction", &tempInt);
  1278.     PREF_SetIntPref("news.server_change_xaction", ++tempInt);
  1279. }
  1280.  
  1281. // Member:       calculateWidth
  1282. // Description:  
  1283. // Inputs:
  1284. // Side effects: 
  1285.  
  1286. Dimension XFE_PrefsDialog::calculateWidth()
  1287. {
  1288.     Dimension widest = 0;
  1289.     Dimension width;
  1290.  
  1291.     for (int i = 0; i < m_numPages; i++) {
  1292.         width = m_pages[i]->getWidth();
  1293.         if (width > widest) widest = width;
  1294.     }
  1295.     return widest;
  1296. }
  1297.  
  1298. // Member:       calculateHeight
  1299. // Description:  
  1300. // Inputs:
  1301. // Side effects: 
  1302.  
  1303. Dimension XFE_PrefsDialog::calculateHeight()
  1304. {
  1305.     Dimension tallest = 0;
  1306.     Dimension height;
  1307.  
  1308.     for (int i = 0; i < m_numPages; i++) {
  1309.         height = m_pages[i]->getHeight();
  1310.         if (height > tallest) tallest = height;
  1311.     }
  1312.     return tallest;
  1313. }
  1314.  
  1315. // ==================== Prefs Dialog Protected Member Functions ====================
  1316.  
  1317.  
  1318. // ==================== Prefs Dialog Private Member Functions ====================
  1319.  
  1320. // Member:       createRegions
  1321. // Description:  Creates regions for the preferences dialog
  1322. // Inputs:
  1323. // Side effects: 
  1324.  
  1325. void XFE_PrefsDialog::createRegions()
  1326. {
  1327.     Arg      args[50];
  1328.     Cardinal n;
  1329.  
  1330.     // Top level form
  1331.  
  1332.     Widget form;
  1333.  
  1334.     form = XtVaCreateWidget("form", xmFormWidgetClass, m_chrome,
  1335.                             XmNtopAttachment, XmATTACH_FORM,
  1336.                             XmNleftAttachment, XmATTACH_FORM,
  1337.                             XmNrightAttachment, XmATTACH_FORM,
  1338.                             XmNbottomAttachment, XmATTACH_FORM,
  1339.                             NULL);
  1340.  
  1341.     // Category area
  1342.  
  1343.     Widget leftPane;
  1344.  
  1345.     leftPane = XtVaCreateWidget("leftPane", xmFormWidgetClass, form,
  1346.                                 XmNtopAttachment, XmATTACH_FORM,
  1347.                                 XmNleftAttachment, XmATTACH_FORM,
  1348.                                 XmNbottomAttachment, XmATTACH_FORM,
  1349.                                 NULL);
  1350.  
  1351.     // Page area
  1352.  
  1353.     Widget rightPane;
  1354.  
  1355.     rightPane = XtVaCreateWidget("rightPane", xmFormWidgetClass, form,
  1356.                                  XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
  1357.                                  XmNtopWidget, leftPane,
  1358.                                  XmNleftAttachment, XmATTACH_WIDGET,
  1359.                                  XmNleftWidget, leftPane,
  1360.                                  XmNrightAttachment, XmATTACH_FORM,
  1361.                                  XmNbottomAttachment, XmATTACH_FORM,
  1362.                                  NULL);
  1363.  
  1364.     // Category area - category label
  1365.  
  1366.     Widget categoryLabel;
  1367.  
  1368.     n = 0;
  1369.     XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  1370.     XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  1371.     categoryLabel = XmCreateLabelGadget(leftPane, "categoryLabel", args, n);
  1372.     XtManageChild(categoryLabel);
  1373.  
  1374.     // Category area - Categories
  1375.  
  1376. #if 0
  1377.     m_outlinable = new XFE_PrefsOutlinable;
  1378.  
  1379.     // TODO: pass attachments and name to outliner
  1380.     m_outliner = new XFE_Outliner(m_outlinable,        /* outlinable */
  1381.                       this, /* toplevel */
  1382.                                   leftPane,            /* parent */
  1383.                                   TRUE,                /* constantSize */
  1384.                                   NUM_OUTLINER_COLS,   /* number of columns */
  1385.                                   OUTLINER_COLWIDTHS); /* column widths */
  1386. #endif
  1387.  
  1388. #if 0
  1389.     n = 0;
  1390.     XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  1391.     XtSetArg(args[n], XmNtopWidget, categoryLabel); n++;
  1392.     XtSetArg(args[n], XmNleftAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
  1393.     XtSetArg(args[n], XmNleftWidget, categoryLabel); n++;
  1394.     XtSetArg(args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
  1395.     XtSetArg(args[n], XmNrightAttachment, XmATTACH_NONE); n++;
  1396.     n = 0;
  1397.     XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  1398.     XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  1399.     XtSetArg(args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
  1400.     XtSetArg(args[n], XmNrightAttachment, XmATTACH_NONE); n++;
  1401. #endif
  1402.  
  1403.     n = 0;
  1404.     m_wOutline = fe_GridCreate(m_context,        /* context */
  1405.                                leftPane,         /* parent */
  1406.                                "categoryList",   /* name */
  1407.                                args,             /* av */
  1408.                                n,                /* ac */
  1409.                                0,                /* maxindentdepth */
  1410.                                NUM_OUTLINER_COLS,/* num columns */
  1411.                                OUTLINER_COLWIDTHS,/* column widths */
  1412.                                categoryDataFunc, /* data function */
  1413.                                categoryClickFunc,/* click function */
  1414.                                categoryIconFunc, /* icon function */
  1415.                                this,             /* closure */
  1416.                                &m_columnWidths,  /* posinfo */
  1417.                                TRUE,             /* tag */
  1418.                                FALSE);           /* grid */
  1419.   
  1420.     // Category should grow horizontally to show all categories.
  1421.     XtVaSetValues(m_wOutline,
  1422.                   XmNhorizontalSizePolicy, XmVARIABLE,
  1423.                   NULL);
  1424.  
  1425.     m_outlineHeaders = XP_NEW_ZAP(fe_OutlineHeaderDesc);
  1426.     m_outlineHeaders->header_strings = 
  1427.         (const char **)XP_CALLOC(NUM_OUTLINER_COLS, sizeof(char*));
  1428.     m_outlineHeaders->type[0] = FE_OUTLINE_String;
  1429.     m_outlineHeaders->header_strings[0] = OUTLINER_COLUMN_TYPE;
  1430.     m_outlineHeaders->type[1] = FE_OUTLINE_String;
  1431.     m_outlineHeaders->header_strings[1] = OUTLINER_COLUMN_NAME; 
  1432.  
  1433.     fe_OutlineSetHeaders(m_wOutline, m_outlineHeaders);
  1434.     XtVaSetValues(m_wOutline, 
  1435.                   XmNtopAttachment, XmATTACH_FORM,
  1436.                   XmNleftAttachment, XmATTACH_FORM,
  1437.                   XmNrightAttachment, XmATTACH_FORM,
  1438.                   XmNbottomAttachment, XmATTACH_FORM,
  1439.                   NULL);
  1440.     XtManageChild(m_wOutline);
  1441.  
  1442.     // Page area - page label
  1443.  
  1444.     n = 0;
  1445.     XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  1446.     XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  1447.     m_wPageLabel = XmCreateLabelGadget(rightPane, "pageLabel", args, n);
  1448.     XtManageChild(m_wPageLabel);
  1449.  
  1450.     // Page area - page title
  1451.  
  1452.     m_wPageTitle = XtVaCreateManagedWidget("pageTitle", xmLabelWidgetClass, rightPane,
  1453.                                            XmNtopAttachment, XmATTACH_WIDGET,
  1454.                                            XmNtopWidget, m_wPageLabel,
  1455.                                            XmNleftAttachment, XmATTACH_FORM,
  1456.                                            XmNrightAttachment, XmATTACH_FORM,
  1457.                                            NULL);
  1458.  
  1459.     // page area - Page Form
  1460.  
  1461.     m_wPageForm = XtVaCreateManagedWidget("pageForm", xmFormWidgetClass, rightPane,
  1462.                                           XmNtopAttachment, XmATTACH_WIDGET,
  1463.                                           XmNtopWidget, m_wPageTitle,
  1464.                                           XmNleftAttachment, XmATTACH_FORM,
  1465.                                           XmNrightAttachment, XmATTACH_FORM,
  1466.                                           XmNbottomAttachment, XmATTACH_FORM,
  1467.                                           NULL);
  1468.  
  1469.     XtManageChild(leftPane);
  1470.     XtManageChild(rightPane);
  1471.     XtManageChild(form);
  1472. }
  1473.  
  1474. // Member:       initCategories
  1475. // Description:  Initializes categories
  1476. // Inputs:
  1477. // Side effects: 
  1478.  
  1479. void XFE_PrefsDialog::initCategories()
  1480. {
  1481.     XrmDatabase  db = XtDatabase(XtDisplay(m_chrome));
  1482.     char         name[1024];
  1483.     char         clas[1024];
  1484.     XrmValue     value;
  1485.     char        *type = NULL;
  1486.     int          i;
  1487.  
  1488.     if (m_categories) deleteCategories();
  1489.  
  1490.     m_numCategories = XtNumber(prefsCategories);
  1491.  
  1492.     // Calculate the number of pages we have
  1493.  
  1494.     m_numPages = 0;
  1495.     for (i = 0; i < m_numCategories; i++) {
  1496.         m_numPages++;
  1497.         if (prefsCategories[i].numChildren > 0);
  1498.             m_numPages += prefsCategories[i].numChildren;
  1499.     }
  1500.  
  1501.     m_pages = new XFE_PrefsPage *[m_numPages];
  1502.     int page_index = 0;
  1503.  
  1504.     // Well, this is kinda quick and dirty. I am assuming there are only
  1505.     // two levels in the hierarchy.
  1506.  
  1507.     m_categories = new PrefsCategory[m_numCategories];
  1508.  
  1509.     for (i = 0; i < m_numCategories; i++) {
  1510.         newPage(m_pages[page_index], prefsCategories[i].type);
  1511.         m_categories[i].page = m_pages[page_index];
  1512.         page_index++;
  1513.         m_categories[i].open = FALSE;
  1514.         m_categories[i].name = (char *)XtNewString(prefsCategories[i].name);
  1515.  
  1516.         // Get the resources for category name and description
  1517.  
  1518.         PR_snprintf(clas, sizeof (clas),
  1519.                     "%s.%s", fe_progclass, prefsCategories[i].catResClass);
  1520.         PR_snprintf(name, sizeof (name),
  1521.                     "%s.%s", fe_progclass, prefsCategories[i].catResName);
  1522.         if (XrmGetResource(db, name, clas, &type, &value))
  1523.             m_categories[i].categoryName = (char *)XtNewString(value.addr);
  1524.         else
  1525.             m_categories[i].categoryName = (char *)XtNewString(prefsCategories[i].name);
  1526.  
  1527.         PR_snprintf(clas, sizeof (clas),
  1528.                     "%s.%s", fe_progclass, prefsCategories[i].descResClass);
  1529.         PR_snprintf(name, sizeof (name),
  1530.                     "%s.%s", fe_progclass, prefsCategories[i].descResName);
  1531.         if (XrmGetResource(db, name, clas, &type, &value))
  1532.             m_categories[i].categoryDesc = (char *)XtNewString(value.addr);
  1533.         else
  1534.             m_categories[i].categoryDesc = (char *)XtNewString(prefsCategories[i].name);
  1535.  
  1536.         m_categories[i].parent = NULL;
  1537.         m_categories[i].leaf = prefsCategories[i].leaf;
  1538.         int numChildren = m_categories[i].numChildren = prefsCategories[i].numChildren;
  1539.         if (numChildren > 0) {
  1540.             m_categories[i].children = new PrefsCategory[numChildren];
  1541.  
  1542.             struct _prefsCategory *prefs = prefsCategories[i].children;
  1543.             PrefsCategory         *children = m_categories[i].children;
  1544.  
  1545.             for (int j = 0; j < numChildren; j++) {
  1546.                 newPage(m_pages[page_index], prefs[j].type);
  1547.                 children[j].page = m_pages[page_index];
  1548.                 page_index++;
  1549.                 children[j].open = FALSE;
  1550.                 children[j].name = (char *)XtNewString(prefs[j].name);
  1551.  
  1552.                 // Get the resources for category name and description
  1553.  
  1554.                 PR_snprintf(clas, sizeof (clas),
  1555.                             "%s.%s", fe_progclass, prefs[j].catResClass);
  1556.                 PR_snprintf(name, sizeof (name),
  1557.                             "%s.%s", fe_progclass, prefs[j].catResName);
  1558.                 if (XrmGetResource(db, name, clas, &type, &value))
  1559.                     children[j].categoryName = (char *)XtNewString(value.addr);
  1560.                 else
  1561.                     children[j].categoryName = (char *)XtNewString(prefs[j].name);
  1562.  
  1563.                 PR_snprintf(clas, sizeof (clas),
  1564.                             "%s.%s", fe_progclass, prefs[j].descResClass);
  1565.                 PR_snprintf(name, sizeof (name),
  1566.                             "%s.%s", fe_progclass, prefs[j].descResName);
  1567.                 if (XrmGetResource(db, name, clas, &type, &value))
  1568.                     children[j].categoryDesc = (char *)XtNewString(value.addr);
  1569.                 else
  1570.                     children[j].categoryDesc = (char *)XtNewString(prefs[j].name);
  1571.  
  1572.                 children[j].leaf = prefs[j].leaf;
  1573.                 children[j].parent = &m_categories[i];
  1574.                 children[j].numChildren = 0;
  1575.                 children[j].children = 0;
  1576.             }
  1577.         }
  1578.         else {
  1579.             m_categories[i].children = 0;
  1580.         }
  1581.     }
  1582. }
  1583.  
  1584. // Member:       deleteCategories
  1585. // Description:  Deletes categories
  1586. // Inputs:
  1587. // Side effects: 
  1588.  
  1589. void XFE_PrefsDialog::deleteCategories()
  1590. {
  1591.     // Delete
  1592.  
  1593.     for (int i = 0; i < m_numCategories; i++) {
  1594.         if (m_categories[i].children) {
  1595.             PrefsCategory *children = m_categories[i].children;
  1596.             int            numChildren = m_categories[i].numChildren;
  1597.             for (int j = 0; j < numChildren; j++) {
  1598.                 if (children[j].name) free (children[j].name);
  1599.                 if (children[j].categoryName) free (children[j].categoryName);
  1600.                 if (children[j].categoryDesc) free (children[j].categoryDesc);
  1601.             }
  1602.             delete (m_categories[i].children);
  1603.         }
  1604.         if (m_categories[i].name) free (m_categories[i].name);
  1605.         if (m_categories[i].categoryName) free (m_categories[i].categoryName);
  1606.         if (m_categories[i].categoryDesc) free (m_categories[i].categoryDesc);
  1607.     }
  1608.     delete m_categories;
  1609.     m_categories = 0;
  1610.     m_numCategories = 0;
  1611. }
  1612.  
  1613. // Member:       newPage
  1614. // Description:  
  1615. // Inputs:
  1616. // Side effects: 
  1617.  
  1618. void XFE_PrefsDialog::newPage(XFE_PrefsPage *&page, 
  1619.                               int             type)
  1620. {
  1621.     switch (type) {
  1622.     case PAGE_TYPE_APPEARANCE:
  1623.         page = new XFE_PrefsPageGeneralAppearance(this);
  1624.         break;
  1625.     case PAGE_TYPE_FONTS:
  1626.         page = new XFE_PrefsPageGeneralFonts(this);
  1627.         break;
  1628.     case PAGE_TYPE_COLORS:
  1629.         page = new XFE_PrefsPageGeneralColors(this);
  1630.         break;
  1631.     case PAGE_TYPE_APPS:
  1632.         page = new XFE_PrefsPageGeneralAppl(this);
  1633.         break;
  1634.     case PAGE_TYPE_CACHE:
  1635.         page = new XFE_PrefsPageGeneralCache(this);
  1636.         break;
  1637.     case PAGE_TYPE_PROXIES:
  1638.         page = new XFE_PrefsPageGeneralProxies(this);
  1639.         break;
  1640.     case PAGE_TYPE_BROWSER:
  1641.         page = new XFE_PrefsPageBrowser(this);
  1642.         break;
  1643.     case PAGE_TYPE_LANG:
  1644.         page = new XFE_PrefsPageBrowserLang(this);
  1645.         break;
  1646.     case PAGE_TYPE_MAILNEWS_IDENTITY:
  1647.         page = new XFE_PrefsPageMailNewsIdentity(this);
  1648.         break;
  1649. #ifdef MOZ_MAIL_NEWS
  1650.     case PAGE_TYPE_MAILNEWS:
  1651.         page = new XFE_PrefsPageMailNews(this);
  1652.         break;
  1653.     case PAGE_TYPE_MAILNEWS_COMPOSITION:
  1654.         page = new XFE_PrefsPageMailNewsComposition(this);
  1655.         break;
  1656.     case PAGE_TYPE_MAILNEWS_MAILSERVER:
  1657.         page = new XFE_PrefsPageMailNewsMserver(this);
  1658.         break;
  1659.     case PAGE_TYPE_MAILNEWS_NEWSSERVER:
  1660.         page = new XFE_PrefsPageMailNewsNserver(this);
  1661.         break;
  1662.     case PAGE_TYPE_MAILNEWS_ADDRBOOK:
  1663.         page = new XFE_PrefsPageMailNewsAddrBook(this);
  1664.         break;
  1665.     case PAGE_TYPE_EDITOR:
  1666.         page = new XFE_PrefsPageEditor(this);
  1667.         break;
  1668.     case PAGE_TYPE_EDITOR_APPEARANCE:
  1669.         page = new XFE_PrefsPageEditorAppearance(this);
  1670.         break;
  1671.     case PAGE_TYPE_EDITOR_PUBLISH:
  1672.         page = new XFE_PrefsPageEditorPublish(this);
  1673.         break;
  1674.     case PAGE_TYPE_DISKSPACE:
  1675.         page = new XFE_PrefsPageDiskSpace(this);
  1676.         break;
  1677. #endif  // MOZ_MAIL_NEWS
  1678.     case PAGE_TYPE_ADVANCED:
  1679.         page = new XFE_PrefsPageGeneralAdvanced(this);
  1680.         break;
  1681. #ifdef PREFS_UNSUPPORTED
  1682.     case PAGE_TYPE_HELPFILES:
  1683.         page = new XFE_PrefsPageHelpFiles(this);
  1684.         break;
  1685.     case PAGE_TYPE_OFFLINE:
  1686.         page = new XFE_PrefsPageOffline(this);
  1687.         break;
  1688.     case PAGE_TYPE_OFFLINE_NEWS:
  1689.         page = new XFE_PrefsPageOfflineNews(this);
  1690.         break;
  1691. #endif /* PREFS_UNSUPPORTED */
  1692.     }
  1693. }
  1694.  
  1695. // Member:       getCategoryByIndex
  1696. // Description:  Returns category given an index
  1697. // Inputs:
  1698. // Side effects: 
  1699.  
  1700. PrefsCategory *XFE_PrefsDialog::getCategoryByIndex(int index)
  1701. {
  1702.     PrefsCategory   *item = 0;
  1703.     int              count = 0;
  1704.     int              i;
  1705.     int              j;
  1706.     Boolean          found = FALSE;
  1707.  
  1708.     for (i = 0; i < m_numCategories; i++) {
  1709.         count++;
  1710.         if ((index + 1) == count) {
  1711.             item = &m_categories[i];
  1712.             found = TRUE;
  1713.             break;
  1714.         }
  1715.         if (! m_categories[i].open) continue;
  1716.         if ((index + 1 - count) <= m_categories[i].numChildren) {
  1717.             j = index - count;
  1718.             item = &(m_categories[i].children[j]);
  1719.             found = TRUE;
  1720.             break;
  1721.         }
  1722.         count += m_categories[i].numChildren;
  1723.     }
  1724.  
  1725.     return item;
  1726. }
  1727.  
  1728. // Member:       getCategoryByName
  1729. // Description:  Returns category given a name
  1730. // Inputs:
  1731. // Side effects: 
  1732.  
  1733. PrefsCategory *XFE_PrefsDialog::getCategoryByName(const char *name)
  1734. {
  1735.     PrefsCategory   *item = 0;
  1736.     int              i;
  1737.     int              j;
  1738.     int              numChildren;
  1739.     PrefsCategory   *children;
  1740.     Boolean          found = FALSE;
  1741.  
  1742.     for (i = 0; i < m_numCategories; i++) {
  1743.         if (strcmp(m_categories[i].name, name) == 0) {
  1744.             item = &m_categories[i];
  1745.             found = TRUE;
  1746.             break;
  1747.         }
  1748.         if (m_categories[i].numChildren > 0) {
  1749.             numChildren = m_categories[i].numChildren;
  1750.             for (j = 0; j < numChildren; j++) {
  1751.                 children = m_categories[i].children;
  1752.                 if (strcmp(children[j].name, name) == 0) {
  1753.                     item = &children[j];
  1754.                     found = TRUE;
  1755.                     break;
  1756.                 }
  1757.             }
  1758.         }
  1759.     }
  1760.  
  1761.     return item;
  1762. }
  1763.  
  1764. // Member:       getCurrentCategory
  1765. // Description:  Returns currently selected category 
  1766. // Inputs:
  1767. // Side effects: 
  1768.  
  1769. PrefsCategory *XFE_PrefsDialog::getCurrentCategory()
  1770. {
  1771.     return m_currentCategory;
  1772. }
  1773.  
  1774. // Member:       refreshCategories
  1775. // Description:  Refresh categories
  1776. // Inputs:
  1777. // Side effects: 
  1778.  
  1779. void XFE_PrefsDialog::refreshCategories()
  1780. {
  1781.     fe_OutlineChange(m_wOutline, 1, CAT_LAST_CELL, getVisibleCategoryCount());
  1782. }
  1783.  
  1784. // Member:       isCurrentCategory
  1785. // Description:  Is category the one being displayed?
  1786. // Inputs:
  1787. // Side effects: 
  1788.  
  1789. Boolean XFE_PrefsDialog::isCurrentCategory(PrefsCategory *entry)
  1790. {
  1791.     return (entry == m_currentCategory);
  1792. }
  1793.  
  1794. // Member:       getOutline
  1795. // Description:  Returns the outline widget
  1796. // Inputs:
  1797. // Side effects: 
  1798.  
  1799. Widget XFE_PrefsDialog::getOutline()
  1800. {
  1801.     return m_wOutline;
  1802. }
  1803.  
  1804. // Member:       getPrefsParent
  1805. // Description:  Returns the widget from which a prefs dialog is popped up
  1806. // Inputs:
  1807. // Side effects: 
  1808.  
  1809. Widget XFE_PrefsDialog::getPrefsParent()
  1810. {
  1811.     return m_wParent;
  1812. }
  1813.  
  1814. // Member:       getPageForm
  1815. // Description:  Returns the page form
  1816. // Inputs:
  1817. // Side effects: 
  1818.  
  1819. Widget XFE_PrefsDialog::getPageForm()
  1820. {
  1821.     return m_wPageForm;
  1822. }
  1823.  
  1824. // Member:       getDialogChrome
  1825. // Description:  Returns the dialog chrome
  1826. // Inputs:
  1827. // Side effects: 
  1828.  
  1829. Widget XFE_PrefsDialog::getDialogChrome()
  1830. {
  1831.     return m_chrome;
  1832. }
  1833.  
  1834. // ************************************************************************
  1835. // *************************       Outline        *************************
  1836. // ************************************************************************
  1837.  
  1838. Boolean XFE_PrefsDialog::categoryDataFunc(Widget          /* widget */, 
  1839.                                           void           *closure, 
  1840.                                           int             row,
  1841.                                           fe_OutlineDesc *data,
  1842.                                           int             /* tag */)
  1843. {
  1844.     int               c;
  1845.     int               dataColumn;
  1846.     XFE_PrefsDialog  *prefsDialog = (XFE_PrefsDialog *)closure;
  1847.  
  1848.     if (row >= prefsDialog->getVisibleCategoryCount()) return False;
  1849.     PrefsCategory *entry = prefsDialog->getCategoryByIndex(row);
  1850.     if (entry == 0) return False;
  1851.  
  1852.     // Handle selections
  1853.  
  1854.     if (prefsDialog->isCurrentCategory(entry)) {
  1855.         fe_OutlineSelect(prefsDialog->getOutline(), row, True);
  1856.     } 
  1857.     else {
  1858.         fe_OutlineUnselect(prefsDialog->getOutline(), row);
  1859.     }
  1860.  
  1861.     data->style = FE_OUTLINE_Default;
  1862.     if ((entry->leaf) ||
  1863.         (entry->children == 0)) {
  1864.         data->flippy = FE_OUTLINE_Leaf;
  1865.     }
  1866.     else {
  1867.         data->flippy = entry->open ? FE_OUTLINE_Expanded : FE_OUTLINE_Folded;
  1868.     }
  1869.     data->depth = entry->leaf ? 1 : 0;
  1870.  
  1871.     for (c = 1, dataColumn = 0; c < NUM_OUTLINER_COLS ; c++, dataColumn++) {
  1872.         if (data->column_headers[c] == OUTLINER_COLUMN_NAME) {
  1873.             static char label[256];
  1874.             data->type[dataColumn] = FE_OUTLINE_String;
  1875.             if (entry->leaf) 
  1876.                 sprintf(label, "   %s", entry->categoryName);
  1877.             else
  1878.                 strcpy(label, entry->categoryName);
  1879.             data->str[dataColumn] = label;
  1880.             // data->str[dataColumn] = entry->categoryName;
  1881.         }
  1882.     }
  1883.  
  1884.     return True;
  1885. }
  1886.  
  1887. void XFE_PrefsDialog::categoryClickFunc(Widget  /* widget */, 
  1888.                                         void   *closure,
  1889.                                         int     row,
  1890.                                         int     /* column */, 
  1891.                                         const char* /* header */,
  1892.                                         int     /* button */,
  1893.                                         int     /* clicks */,
  1894.                                         Boolean /* shift */, 
  1895.                                         Boolean /* ctrl */,
  1896.                                         int     /* tag */)
  1897. {
  1898.     if (row == (-1)) {
  1899.         // The user is clicking on the header
  1900.         // Do nothing here.
  1901.         return;
  1902.     }
  1903.  
  1904.     XFE_PrefsDialog  *prefsDialog = (XFE_PrefsDialog *)closure;
  1905.     PrefsCategory    *entry = prefsDialog->getCategoryByIndex(row);
  1906.  
  1907.     prefsDialog->setCurrentCategory(entry);
  1908.     XmUpdateDisplay(prefsDialog->getBaseWidget());
  1909. }
  1910.  
  1911. void XFE_PrefsDialog::categoryIconFunc(Widget   /* widget */,
  1912.                                        void    *closure,
  1913.                                        int      row,
  1914.                                        int      /*tag*/)
  1915. {
  1916.     XFE_PrefsDialog  *prefsDialog = (XFE_PrefsDialog *)closure;
  1917.     PrefsCategory    *entry = prefsDialog->getCategoryByIndex(row);
  1918.  
  1919.     if (! entry) return;
  1920.  
  1921.     entry->open = (entry->open) ? FALSE : TRUE;
  1922.     prefsDialog->calcVisibleCategoryCount();
  1923.     prefsDialog->refreshCategories();
  1924.  
  1925.     // Make this the current selection
  1926.     prefsDialog->setCurrentCategory(entry);
  1927.     XmUpdateDisplay(prefsDialog->getBaseWidget());
  1928. }
  1929.  
  1930.  
  1931.  
  1932.