home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / central / prefwutil.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  13.5 KB  |  426 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. // prefwutils.h
  20. // Various utilities used by preference window
  21. // They are apart from Prefw, so that our file size is manageable
  22.  
  23. #pragma once
  24.  
  25. #include "MoreMixedMode.h"
  26.  
  27. #include <LTable.h>
  28.  
  29.  
  30. class CValidEditField;
  31. class LArrowControl;
  32. class CApplicationIconInfo;
  33. class CPrefHelpersContain;
  34. class CMimeMapper;
  35. class CStr255;
  36.  
  37. /********************************************************************************
  38.  * Classes
  39.  ********************************************************************************/
  40.  
  41. //======================================
  42. class CFilePicker
  43. //======================================
  44.     :    public LView
  45.     ,    public LListener
  46.     ,    public LBroadcaster
  47. {
  48. public:
  49.     enum                { class_ID = 'fpck' }; // illegal, needs one UC char.- jrm
  50.     
  51.     enum                PickEnum { Folders = 0, Applications, TextFiles,
  52.                             ImageFiles, MailFiles, AnyFile };
  53.  
  54.                         CFilePicker( LStream* inStream );
  55.  
  56.         
  57.     virtual void        ListenToMessage( MessageT inMessage, void* ioParam );
  58.  
  59.     void                SetFSSpec( const FSSpec& fileSpec, Boolean touchSetFlag = true );
  60.     const FSSpec&        GetFSSpec() const { return fCurrentValue; }
  61.  
  62.     void                SetPickType( CFilePicker::PickEnum pickTypes ) { fPickTypes = pickTypes; }
  63.     void                SetCaptionForPath( LCaption* captionToSet, const FSSpec& folderSpec );
  64.     CStr255                FSSpecToPathName( const FSSpec& spec );
  65.     
  66.     Boolean                WasSet() const { return fSet; }
  67.  
  68.     
  69.     static Boolean        DoCustomGetFile( StandardFileReply& spec,
  70.                             CFilePicker::PickEnum fileType,
  71.                             Boolean inited );
  72.     static Boolean        DoCustomPutFile( StandardFileReply& spec,
  73.                             const CStr255& prompt,
  74.                             Boolean inited );
  75. protected:
  76.     struct PickClosure
  77.     {
  78.         StandardFileReply*        reply;
  79.         Boolean                    inited;
  80.     };
  81.  
  82.     enum EPaneIDs {
  83.         kPathNameCaption    = 1,
  84.         kBrowseButton        = 2
  85.     };
  86.  
  87.     virtual void        FinishCreateSelf();
  88.         
  89.     static pascal short        SetCurrDirHook( short item, DialogPtr dialog, void* data );
  90.     PROCDECL( static, SetCurrDirHook )
  91.     static pascal short        DirectoryHook( short item, DialogPtr dialog, void* data );
  92.     PROCDECL( static, DirectoryHook )
  93.  
  94.     static pascal Boolean    OnlyFoldersFileFilter( CInfoPBPtr pBlock, void* data );
  95.     static pascal Boolean    IsMailFileFilter( CInfoPBPtr pBlock, void* data );
  96.     PROCDECL( static, OnlyFoldersFileFilter )
  97.     PROCDECL( static, IsMailFileFilter )
  98.     
  99.     static void            SetButtonTitle( Handle buttonHdl, CStr255& name, const Rect& buttonRect );
  100.     
  101.     static CStr255        sPrevName;
  102.     static Boolean        sResult;
  103.     static Boolean        sUseDefault;
  104.     
  105.     FSSpec                fCurrentValue;
  106.     LControl*            fBrowseButton;
  107.     LCaption*            fPathName;
  108.     Boolean                fSet;
  109.     PickEnum            fPickTypes;
  110. }; // class CFilePicker
  111.  
  112. //    COtherSizeDialog.cp    <- double-click + Command-D to see class implementation
  113. //
  114. //    This is a PowerPlant dialog box to handle the Other╔ command in the Size
  115. //    menu. 
  116.  
  117. class LEditField;
  118.  
  119. class COtherSizeDialog: public LDialogBox, public LBroadcaster
  120. {
  121. public:
  122.     enum { class_ID = 'OFnt' };
  123.                         COtherSizeDialog( LStream* inStream );
  124.     
  125.  
  126.     virtual    void        SetValue( Int32 inFontSize );
  127.     virtual Int32        GetValue() const;
  128.  
  129.     void                SetReference( LControl* which );
  130.  
  131.     virtual void        ListenToMessage( MessageT inMessage, void* ioParam );
  132.  
  133.     LControl*            fRef;
  134. protected:
  135.     virtual void        FinishCreateSelf();
  136.     LEditField*            mSizeField;    
  137. };
  138.  
  139. class LArrowGroup: public LView, public LListener
  140. {
  141. public:
  142.                         LArrowGroup( LStream* inStream );
  143.  
  144.     void                ListenToMessage( MessageT message, void* ioParam );    
  145.  
  146.     void                SetValue( Int32 value );
  147.     Int32                GetValue() const { return fValue; }
  148.     
  149.     void                SetMaxValue( Int32 value );
  150.     void                SetMinValue( Int32 value );
  151.     void                SetStringID(ResIDT stringID);
  152. protected:
  153.     void                BuildControls();
  154.     
  155.     Int32                fValue;
  156.     Int32                fMinValue;
  157.     Int32                fMaxValue;
  158.     ResIDT                fStringID;
  159.     LCaption*            fSize;
  160.     LArrowControl*        fArrows;
  161. };
  162.  
  163. /*****************************************************************************
  164.  * class CColorButton
  165.  * Just a button that pops up a color wheel when pressed
  166.  *****************************************************************************/
  167.     
  168. class CColorButton: public LButton
  169. {
  170. public:
  171.     enum { class_ID = 'pcol' };
  172.     // ÑÑ constructors
  173.                         CColorButton( LStream* inStream );
  174.  
  175.     // ÑÑ colors
  176.     void                SetColor( const RGBColor& color ) { fColor = color; }
  177.     RGBColor            GetColor() { return fColor; }
  178.  
  179.     // ÑÑ control overrides
  180.     virtual void        HotSpotResult( short inHotSpot );
  181.     virtual void        DrawGraphic( ResIDT inGraphicID );
  182. protected:
  183.     RGBColor            fColor;
  184.     Boolean                fInside;
  185. };
  186.  
  187. //-----------------------------------------------------------------------------
  188. #include "PopupBox.h"
  189. class FileIconsLister: public StdPopup {
  190. public:
  191.                     FileIconsLister (CGAPopupMenu * target);
  192.     virtual            ~FileIconsLister();
  193.     CStr255            GetText (short item);
  194.     void            SetIconList(CApplicationIconInfo *);
  195.     short            GetCount();
  196. private:
  197.     CApplicationIconInfo *    fIcons;
  198. };
  199.  
  200. /*****************************************************************************
  201.  * class PrefCellInfo
  202.  * All the information needed to draw a cell. This is what the table stores
  203.  *****************************************************************************/
  204. class PrefCellInfo
  205. {
  206. public:
  207.                     PrefCellInfo();
  208.                     PrefCellInfo(CMimeMapper* mapper, CApplicationIconInfo* iconInfo); 
  209.  
  210.     CMimeMapper*    fMapper;            // The mapper from the preference MIME list
  211.     CApplicationIconInfo* fIconInfo;    // Information about icon to draw
  212. };
  213.  
  214. //-----------------------------------------------------------------------------------
  215. // CApplicationList
  216. // Application list is a list that contains information about 
  217. //-----------------------------------------------------------------------------------
  218. struct BNDLIds
  219. {    // Utility structure for bundle parsing
  220.     Int16 localID;
  221.     Int16 resID;
  222. };
  223.  
  224. class CApplicationList : public LArray
  225. {
  226. public:
  227.     // ÑÑ constructors
  228.                                 CApplicationList();
  229.     virtual                        ~CApplicationList();
  230.  
  231.     // ÑÑ access
  232.     // Gets information specified by the mapper
  233.     CApplicationIconInfo*        GetAppInfo(OSType appSig, CMimeMapper* mapper = NULL);
  234.  
  235. private:
  236.     // Creates application icon info for an app with a given signature
  237.     CApplicationIconInfo*        CreateNewEntry(OSType appSig, CMimeMapper* mapper = NULL);
  238.     // Creates application icon info for an app with given specs
  239.     CApplicationIconInfo*        AppInfoFromFileSpec(OSType appSig, FSSpec appSpec);
  240.     void                        GetResourcePointers(Handle bundle,
  241.                                     BNDLIds* &iconOffset, BNDLIds * &frefOffset,
  242.                                     short& numOfIcons, short & numOfFrefs);
  243. };
  244.  
  245.  
  246. /*****************************************************************************
  247.  * class CMimeTable
  248.  * A container view that contains all the CMimeInfo views. Here we are 
  249.  * faking a list view. This view expands so that it contains all of its 
  250.  * subviews.
  251.  *****************************************************************************/
  252.  
  253. #define msg_LaunchRadio        300        // Launch option changed
  254. #define msg_BrowseApp        301        // Pick a new application
  255. #define msg_FileTypePopup     302        // New file type picked
  256. //msg_EditField                        // User typed in a field
  257. #define msg_NewMimeType        303        // New Mime type
  258. #define msg_NewMimeTypeOK    305        // Sent by newMimeType dialog window
  259. //#define msg_ClearCell        306
  260. #define msg_EditMimeType    307        // Edit Mime type
  261. #define msg_DeleteMimeType    308        // Delete Mime type
  262. #define msg_PluginPopup        309        // Pick a plug-in
  263.  
  264. class CMimeTable : public LTable, public LCommander
  265. {
  266. public:
  267.     // ÑÑ Constructors/destructors/access
  268.  
  269.                         CMimeTable(LStream *inStream);
  270.     void                FinishCreateSelf();
  271.     void                 BindCellToApplication(TableIndexT row, CMimeMapper * mapper);
  272.     CApplicationIconInfo* GetAppInfo(CMimeMapper* mapper);
  273.     
  274.     // ÑÑ access
  275.     void                SetContainer( CPrefHelpersContain* container) { fContainer = container; }
  276.     void                GetCellInfo(PrefCellInfo& cellInfo, int row);
  277.     void                FreeMappers();
  278.  
  279.     // ÑÑ Cell selection
  280.     virtual void        DrawCell( const TableCellT& inCell );
  281.  
  282.     // Drawing
  283.     virtual void        DrawSelf();
  284.     virtual void        HiliteCell(const TableCellT &inCell);
  285.     virtual void        UnhiliteCell(const TableCellT &inCell);
  286.             void         ScrollCellIntoFrame(const TableCellT& inCell);
  287.  
  288.     // Events
  289.     virtual Boolean        HandleKeyPress(const EventRecord &inKeyEvent);
  290.  
  291. protected:
  292.     CApplicationList            fApplList;        // List of application and their icons
  293.     CPrefHelpersContain*        fContainer;        // Containing view
  294.     Handle                        fNetscapeIcon;    // Icon for Netscape
  295.     Handle                        fPluginIcon;    // Icon for plug-ins
  296. };
  297.  
  298. //-----------------------------------------------------------------------------------
  299. // CFileType holds information about a single file type
  300. //-----------------------------------------------------------------------------------
  301. class CFileType
  302. {
  303. public:
  304.                                 CFileType( OSType iconSig );
  305.                                 CFileType( OSType iconSig, Handle icon ) {fIcon = icon; fIconSig = iconSig;}
  306.                                 ~CFileType();
  307.  
  308.     static void                    ClearDefaults();        // Does class globals memory cleanup
  309.     static void                    InitializeDefaults();    // Initializes default values
  310.  
  311.     static Handle                sDefaultDocIcon;
  312.     
  313.     Handle                        fIcon;        // Really an icon suite
  314.     OSType                        fIconSig;
  315. };
  316.  
  317. //-----------------------------------------------------------------------------------
  318. // CApplicationIconInfo
  319. // holds all icon information about an application
  320. //-----------------------------------------------------------------------------------
  321. class CApplicationIconInfo
  322. {
  323. public:
  324.     // ÑÑ╩constructors/destructors
  325.                                 // Call me when application has not been found
  326.                                 CApplicationIconInfo( OSType appSig );
  327.                                 // Call me when app was found
  328.                                 CApplicationIconInfo( OSType appSig, Handle appIcon,
  329.                                     LArray* documentIcons, Boolean handlesAE );
  330.  
  331.                                 ~CApplicationIconInfo();
  332.     // ÑÑ access
  333.     CFileType*                    GetFileType( int i );    // Gets file type by the index
  334.     int                            GetFileTypeArraySize();    // Gets number of file types
  335.     // ÑÑ misc
  336.     static void                    InitializeDefaults();    // Initializes default values
  337.     static void                    ClearDefaults();        // Does class globals memory cleanup
  338.     
  339.     static    Handle                sDefaultAppIcon;    // Defaults, in case that application is not found
  340.     Handle                        fApplicationIcon;    // Handle of application icons (iconSuite)
  341.     LArray*                        fDocumentIcons;        // List of CFileType objects
  342.     Boolean                        fHandlesAE;            // Does it handle apple events
  343.     OSType                        fAppSig;            // Signature of the application
  344.     Boolean                        fApplicationFound;    // Was application found on my disk?
  345.  
  346. private:
  347.     static    LArray*                sDocumentIcons;        // ditto
  348.     static    Boolean                sHandlesAE;            // ditto
  349.  
  350. };
  351.  
  352. /*****************************************************************************
  353.  * Class LFocusEditField
  354.  * ----------------------
  355.  * Just like an LListBox, except that it will send messages on
  356.  * a single click. Used in the Document Encoding Dialog Box.
  357.  *****************************************************************************/
  358.  
  359. class LFocusEditField : public LEditField , public LBroadcaster{
  360. public:
  361.     enum { class_ID = 'Fedi' };
  362.  
  363.     LFocusEditField(
  364.                 const LFocusEditField    &inOriginal);
  365.     LFocusEditField(
  366.                 LStream                *inStream);
  367.     virtual    ~LFocusEditField();
  368.     LFocusBox*        GetFocusBox();
  369.  
  370.     Int16                GetReturnMessage() { return mReturnMessage; }
  371.     virtual void        SetReturnMessage(Int16 inMessage) 
  372.                                             { mReturnMessage = inMessage;}
  373.     virtual Boolean        HandleKeyPress(    const EventRecord    &inKeyEvent);
  374.  
  375.     private:
  376.     Int16                mReturnMessage;
  377.  
  378. protected:
  379.     LFocusBox        *mFocusBox;
  380.  
  381.     virtual void        BeTarget();
  382.     virtual void        DontBeTarget();
  383.  
  384. };
  385.  
  386. /*****************************************************************************
  387.  * Class OneClickLListBox
  388.  * ----------------------
  389.  * Just like an LListBox, except that it will send messages on
  390.  * a single click. Used in the Document Encoding Dialog Box.
  391.  *****************************************************************************/
  392.  
  393.  class OneClickLListBox : public LListBox
  394. {
  395.  
  396.     public:
  397.                         OneClickLListBox(LStream * inStream);
  398.     
  399.     Int16                GetSingleClickMessage() { return mSingleClickMessage; }
  400.     virtual void        SetSingleClickMessage(Int16 inMessage) 
  401.                                             { mSingleClickMessage = inMessage;}
  402.     virtual void        ClickSelf(const SMouseDownEvent &inMouseDown);
  403.  
  404.     protected:
  405.     Int16                mSingleClickMessage;
  406.     
  407. };
  408.  
  409. /*****************************************************************************
  410.  * Class OneRowLListBox
  411.  *****************************************************************************/
  412. class OneRowLListBox : public OneClickLListBox
  413. {
  414.  
  415.     public:
  416.     enum { class_ID = 'ocLB' };
  417.                         OneRowLListBox(LStream * inStream);
  418.     virtual Boolean        HandleKeyPress(const EventRecord &inKeyEvent);
  419.     
  420.     virtual Int16        GetRows();        
  421.     virtual void        AddRow(Int32 rowNum, char* data, Int16 datalen);
  422.     virtual void        RemoveRow(Int32 rowNum);
  423.     virtual void        GetCell(Int32 rowNum, char* data, Int16* datalen);
  424.     virtual void        SetCell(Int32 rowNum, char* data, Int16 datalen);
  425. };
  426.