home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / prefs / CPrefsMediator.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  6.7 KB  |  205 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 <PP_Types.h>
  20.  
  21. #pragma once
  22.  
  23. #include "CPrefsDialog.h"
  24. #include "prefwutil.h"
  25. #include "uprefd.h"
  26. #include "UMailFolderMenus.h"
  27. #include "CValidEditField.h"
  28.  
  29. #include <LTextColumn.h>
  30.  
  31. class LWindow;
  32. class LView;
  33. class MPreferenceBase;
  34.  
  35. //======================================
  36. #pragma mark
  37. class CPrefsMediator
  38. // The base class of all the panes that go inside the preferences window. This has to be
  39. // an LCommander so that it can handle receiving messages from a dialog put up in front of
  40. // it. 
  41.  
  42. // NOTE: Since it is an LCommander, PowerPlant will clean it up automatically
  43. // when the prefs dialog goes away (since it is a subcommander of the dialog). Do NOT
  44. // explicitly delete any class derived from this base class.
  45.  
  46. // This is not an abstract class.  In fact, it is the mediator you get if you don't register
  47. // your own.  It relies on the controls all being smart and doing their own thing, i.e., all
  48. // controls in the pane are ones defined in, or inheriting from, those in PrefControls.cp.
  49.  
  50. // The only reasons to define your own mediator would be (1) custom controls that are not
  51. // prefapi-aware, or (2) a need to co-ordinate different controls.  e.g., when this checkbox is
  52. // on, I must enable these other controls, or (3) you have a button that does something special,
  53. // such as display an extra dialog.
  54.  
  55. // Concerning reason (2), you don't even need code for this, since the CSlaveEnabler attachment
  56. // can be added in constructor and will handle dimming/undimming in preference to a "master"
  57. // checkbox or radio button.
  58. //======================================
  59.     :    public LListener
  60.     ,    public LCommander
  61. {
  62.     public:
  63.  
  64.     enum
  65.     {
  66.         eCommitPrefs = 12100,
  67.         eCancelPrefs = 12200
  68.     };
  69.         enum            { refNum_Undefined    = -1 };
  70.                         CPrefsMediator(PaneIDT inMainPaneID);
  71.         virtual            ~CPrefsMediator();
  72.  
  73.         static    void    RegisterViewClasses();
  74.         static    Boolean    CanSwitch(LCommander *inNewTarget = nil);
  75.         static    void    SelectFirstEnabledEditField();
  76.  
  77.         virtual    void    StepAside();
  78.         static    void    UseIC(Boolean useIC) {sUseIC = useIC;};
  79.         static    Boolean    UseIC() {return sUseIC;};
  80.  
  81.         virtual    void    LoadPanes();
  82.         virtual    void    StepForward(LCommander *defaultSub);
  83.         PaneIDT            GetMainPaneID() const { return mMainPaneID; }
  84.         virtual    void    LoadMainPane();
  85.         virtual    void    LoadPrefs();
  86.         virtual    void    WritePrefs();
  87.         virtual void    Canceled();
  88.         virtual    void    UpdateFromIC() {};
  89.         virtual void    ListenToMessage(
  90.                             MessageT        inMessage,
  91.                             void            *ioParam);
  92.  
  93.         static    void    SetStatics(    LView *panel,
  94.                                     LWindow *window,
  95.                                     CPrefsDialog::Selection_T selection)
  96.                             {
  97.                                 sPanel = panel;
  98.                                 sWindow = window;
  99.                                 sInitialSelection = selection;
  100.                             }
  101.  
  102.         LWindow*        GetWindow() const { return (LWindow*)mMainPane->GetMacPort(); }
  103.         virtual void    ActivateHelp();
  104.         LPane*            FindPaneByID(PaneIDT inPaneID) const
  105.                             { return mMainPane->FindPaneByID(inPaneID); }
  106.         
  107.     protected:
  108.             // setting controls with prefs
  109.  
  110.         void    SetEditFieldsWithICPref(ConstStr255Param prefName,
  111.                                         PaneIDT editFieldID,
  112.                                         Boolean    stripPortNumber = false,
  113.                                         PaneIDT    portFieldID = 0,
  114.                                         Boolean    portLocked = false,
  115.                                         long    defaultPort = 0);
  116.                                         // If stripPortNumber is false then portFieldID and
  117.                                         // portLocked are ignored.
  118.                                         // If stripPortNumber is true then the first
  119.                                         // colon and any chars following it are stripped.
  120.                                         // If portFieldID is non-zero and portLocked is
  121.                                         // false, then the port value is set.
  122.         int        SetFontSizePopupWithIntPref(const char *prefName,
  123.                                             PaneIDT popupID,
  124.                                             Boolean &locked,
  125.                                             int defaultValue = 12);
  126.         void    SetFolderPopupWithPref(    const char *prefName,
  127.                                         PaneIDT popupID,
  128.                                         Boolean &locked,
  129.                                         const char *defaultValue = "");
  130.  
  131. //        int SetEditFieldWithAliasPref(    const char *prefName,
  132. //                                        PaneIDT editFieldID,
  133. //                                        Alias &alias,
  134. //                                        Boolean &locked);
  135.  
  136.             // setting controls with SFGetFile
  137.  
  138.         Boolean    SetEditFieldWithLocalFileURL(PaneIDT editFieldID, Boolean locked = false);
  139.                 // returns true iff the user selects a file (as opposed to canceling)
  140.  
  141.             // setting prefs with controls
  142.         void    SetIntPrefWithFontSizePopup(
  143.                                         const char *prefName,
  144.                                         PaneIDT popupID,
  145.                                         Boolean locked = false);
  146.         void    SetPrefWithFolderPopup(
  147.                                         const char *prefName,
  148.                                         PaneIDT popupID,
  149.                                         Boolean locked = false);
  150.  
  151.         MPreferenceBase*                GetPreferenceObject(PaneIDT inPaneID) const;
  152.         Boolean    PaneHasLockedPref(PaneIDT inPaneID) const;
  153.         void    ReadDefaultPref(PaneIDT inPaneID);
  154.         void    ChangePrefName(PaneIDT inPaneID, const char* inNewName);
  155.         void    SetValidationFunction(
  156.                                         PaneIDT inPaneID,
  157.                                         CValidEditField::ValidationFunc inFunc) const;
  158.  
  159.  
  160.         static    LWindow    *                    sWindow;
  161.         static    LView *                        sPanel;
  162.         static    CPrefsDialog::Selection_T    sInitialSelection;
  163.  
  164.         Boolean                                mNeedsPrefs;
  165.  
  166.         LView*                                mMainPane;
  167.         PaneIDT                                mMainPaneID;
  168.         LCommander*                            mLatentSub;
  169.     private:
  170.  
  171.         static            Boolean                sUseIC;
  172. }; // class CPrefsMediator
  173.  
  174. //======================================
  175. #pragma mark
  176. class CDragOrderTextList : public LTextColumn
  177. //======================================
  178. {
  179.     public:
  180.         enum
  181.         {
  182.             class_ID = 'DOTL',
  183.             eHandClosedCursorID = 29202,
  184.             msg_ChangedOrder = 'ROrd'
  185.         };
  186.  
  187.                             CDragOrderTextList(LStream *inStream) :
  188.                                               LTextColumn(inStream),
  189.                                               mOrderLocked(false)
  190.                                               {}
  191.         virtual                ~CDragOrderTextList() {}
  192.         virtual void        ClickCell(const STableCell &inCell, const SMouseDownEvent &inMouseDown);
  193.                 void        LockOrder(Boolean lock = true) {mOrderLocked = lock;}
  194.                 Boolean        IsLocked() {return mOrderLocked;}
  195.     protected:
  196.         virtual void        MoveRow(TableIndexT inCurrRow, TableIndexT inNewRow);
  197.         Boolean    mOrderLocked;
  198. }; // class CDragOrderTextList
  199.  
  200. enum
  201. {
  202.     eSelectionChanged = 'selc',
  203.     eDoubleClick = '2clk'
  204. };
  205.