home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / utility / UMailFolderMenus.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  11.4 KB  |  365 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. #ifndef __H_UMailFolderMenus
  20. #define __H_UMailFolderMenus
  21. #pragma once
  22. /*======================================================================================
  23.     AUTHOR:            Ted Morris <tmorris@netscape.com> - 12 DEC 96
  24.  
  25.     DESCRIPTION:    Mixin classes for displaying a UI menu containing a list of current 
  26.                     mail folders.
  27.  
  28.     MODIFICATIONS:
  29.  
  30.     Date            Person            Description
  31.     ----            ------            -----------
  32. ======================================================================================*/
  33.  
  34.  
  35. /*====================================================================================*/
  36.     #pragma mark INCLUDE FILES
  37. /*====================================================================================*/
  38.  
  39. #include <LVariableArray.h>
  40.  
  41. #include "LStdControl.h"
  42. #include "CGAIconPopup.h"
  43. #include "LGAIconButtonPopup.h"
  44.  
  45. #include "msgcom.h"
  46.  
  47.  
  48. #pragma mark -
  49. /*====================================================================================*/
  50.     #pragma mark CONSTANTS
  51. /*====================================================================================*/
  52.  
  53. const Int16 cMaxMailFolderNameLength = 511;
  54.  
  55. #pragma mark -
  56. /*====================================================================================*/
  57.     #pragma mark CLASS DECLARATIONS
  58. /*====================================================================================*/
  59.  
  60. class CMessageFolder;
  61. class RichItemDataYadaYada;
  62.  
  63. //======================================
  64. class CMailFolderMixin
  65. // Abstract class for use with basic menu population and management
  66. //======================================
  67. {
  68.     friend pascal void MyMercutioCallback(
  69.         Int16 menuID, Int16 previousModifiers, RichItemDataYadaYada& itemData);
  70.                       
  71. public:
  72.  
  73.     // Public interface
  74.     
  75.                         // Static public method for updating all CMailFolderMixin objects
  76.     static void            UpdateMailFolderMixins();
  77.     static void            UpdateMailFolderMixinsNow(CMailFolderMixin *inSingleMailFolderMixin = nil);
  78.     static void            GetFolderNameForDisplay(char * inName, CMessageFolder& folder);
  79.  
  80.                         enum { eUseFolderIcons = true, eNoFolderIcons = false };
  81.                         CMailFolderMixin(Boolean inIncludeFolderIcons = eUseFolderIcons);
  82.     virtual                ~CMailFolderMixin(void);
  83.     
  84.     // Following two deliberately return by value.  CMessageFolder is only 4 bytes, and
  85.     // is reference counted.  The first indexes only into the folder list.  The second
  86.     // takes account of any initial non-folder items that might be in the menu.
  87.     virtual CMessageFolder    MGetFolder(ArrayIndexT inItemNumber);
  88.     virtual CMessageFolder    MGetFolderFromMenuItem(ArrayIndexT inItemNumber);
  89.  
  90.     virtual const char*    MGetFolderName(ArrayIndexT inItemNumber);
  91.     ResIDT                GetMailFolderIconID(UInt16 inFlags);
  92.     
  93.                         // Get the currently selected folder name
  94.     virtual const char*    MGetSelectedFolderName();
  95.     virtual CMessageFolder MGetSelectedFolder();
  96.  
  97.     virtual Boolean        MSetSelectedFolder(const CMessageFolder&, Boolean inDoBroadcast = true);
  98.     virtual Boolean        MSetSelectedFolder(const MSG_FolderInfo*, Boolean inDoBroadcast = true);
  99.     virtual Boolean        MSetSelectedFolderName(const char* inName, Boolean inDoBroadcast = true);
  100.                             // Needed only by filters.
  101.  
  102.     enum FolderChoices
  103.     {
  104.         eWantPOP =        1 << 0,
  105.         eWantIMAP =        1 << 1,
  106.         eWantNews =        1 << 2,
  107.         eWantHosts =    1 << 3,
  108.         eWantDividers =    1 << 4
  109.     };
  110.     void                MSetFolderChoices(FolderChoices inChoices) { mDesiredFolderFlags = inChoices; }
  111.  
  112. protected:
  113.  
  114.                         // These two methods are called by automatically by CMailFolderMixins 
  115.                         // when they are created and destroyed
  116.     static void            RegisterMailFolderMixin(CMailFolderMixin *inMailFolderMixin);
  117.     static void            UnregisterMailFolderMixin(CMailFolderMixin *inMailFolderMixin);
  118.     
  119.     void                MGetCurrentMenuItemName(Str255 outItemName);
  120.     virtual    Boolean        FolderFilter(const CMessageFolder &folder);
  121.  
  122.                         // Populate the menu with current mail folders
  123.     virtual Boolean        MPopulateWithFolders(const MSG_FolderInfo **inFolderInfoArray,
  124.                                              const Int32 inNumFolders);
  125.  
  126. // Pure virtual methods
  127.     
  128.     virtual Int16        MGetNumMenuItems(void) = 0;
  129.     virtual Int16        MGetSelectedMenuItem(void) = 0;
  130.     virtual void        MSetSelectedMenuItem(Int16 inIndex, Boolean inDoBroadcast = true) = 0;
  131.     virtual Boolean        MUpdateMenuItem(Int16 inMenuItem, ConstStr255Param inName, 
  132.                                         ResIDT inIconID = 0) = 0;
  133.     virtual void        MAppendMenuItem(ConstStr255Param inName, ResIDT inIconID = 0) = 0;
  134.     virtual void        MClipMenuItems(Int16 inStartClipItem) = 0;
  135.     virtual void        MGetMenuItemName(Int16 inIndex, Str255 outItemName) = 0;
  136.     virtual MenuHandle    MGetSystemMenuHandle(void) = 0;
  137.     virtual void        MRefreshMenu(void) = 0;
  138.     
  139. // Instance variables
  140.         
  141.     LArray                mFolderArray;    // ... or must we? jrm 97/03/18
  142.     Boolean                mUseFolderIcons;    // Use icons in the menu?
  143.  
  144.     static LArray        sMailFolderMixinRegisterList;    // List of registered CMailFolderMixins
  145.     FolderChoices        mDesiredFolderFlags;
  146.     static Boolean        sMustRebuild;
  147.     static void*        sMercutioCallback;
  148.     Int32                mInitialMenuCount;
  149. };
  150.  
  151.  
  152. // Abstract class for use with control popup menus
  153. class CMailFolderPopupMixin : public CMailFolderMixin {
  154.                       
  155. public:
  156.  
  157.                         CMailFolderPopupMixin(void) {
  158.                         }
  159.                     
  160. protected:
  161.  
  162.     virtual Int16        MGetNumMenuItems(void);
  163.     virtual Int16        MGetSelectedMenuItem(void);
  164.     virtual void        MSetSelectedMenuItem(Int16 inIndex, Boolean inDoBroadcast = true);
  165.     virtual Boolean        MUpdateMenuItem(Int16 inMenuItem, ConstStr255Param inName, 
  166.                                         ResIDT inIconID = 0);
  167.     virtual void        MAppendMenuItem(ConstStr255Param inName, ResIDT inIconID = 0);
  168.     virtual void        MClipMenuItems(Int16 inStartClipItem);
  169.     virtual void        MGetMenuItemName(Int16 inMenuItem, Str255 outItemName);
  170.     virtual void        MRefreshMenu(void);
  171.     
  172.     LControl            *MGetControl(void) {
  173.                             LControl *theControl = dynamic_cast<LControl *>(this);
  174.                             Assert_(theControl != nil);
  175.                             return theControl;
  176.                         }
  177. };
  178.  
  179.  
  180. /*======================================================================================
  181.     Mixin with a CGAIconPopup class or descendent.
  182.     
  183.     Use as follows:
  184.     
  185.         class MyPopup : public CGAIconPopup,
  186.                         public CGAIconPopupFolderMixin {
  187.                                  
  188.                 ... Methods
  189.         }
  190.         
  191.     Make sure to call CMailFolderMixin::UpdateMailFolderMixins(this) from 
  192.     MyPopup::FinishCreateSelf().
  193. ======================================================================================*/
  194.  
  195. class CGAIconPopupFolderMixin : public CMailFolderPopupMixin {
  196.                       
  197. public:
  198.  
  199.                         CGAIconPopupFolderMixin(void) {
  200.                         }
  201.                     
  202. protected:
  203.  
  204.     virtual MenuHandle    MGetSystemMenuHandle(void);
  205.     virtual void        MRefreshMenu(void);
  206.  
  207.     CGAIconPopup        *MGetControl(void) {
  208.                             CGAIconPopup *theControl = dynamic_cast<CGAIconPopup *>(this);
  209.                             Assert_(theControl != nil);
  210.                             return theControl;
  211.                         }
  212. };
  213.  
  214.  
  215. /*======================================================================================
  216.     Mixin with a LStdPopupMenu class or descendent.
  217.     
  218.     Use as follows:
  219.     
  220.         class MyPopup : public LGAPopup,
  221.                         public CGAdPopupFolderMixin {
  222.                                  
  223.                 ... Methods
  224.         }
  225.         
  226.     Make sure to call CMailFolderMixin::UpdateMailFolderMixins(this) from 
  227.     MyPopup::FinishCreateSelf().
  228. ======================================================================================*/
  229.  
  230. class CGAPopupFolderMixin : public CMailFolderPopupMixin {
  231.  
  232. public:
  233.  
  234.                         CGAPopupFolderMixin(void)
  235.                         {
  236.                         }
  237.                     
  238. protected:
  239.  
  240.     virtual MenuHandle    MGetSystemMenuHandle(void);
  241.  
  242.     LGAPopup        *MGetControl(void) {
  243.                             LGAPopup *theControl = dynamic_cast<LGAPopup *>(this);
  244.                             Assert_(theControl != nil);
  245.                             return theControl;
  246.                         }
  247. };
  248.  
  249.  
  250. /*======================================================================================
  251.     Mixin with a LGAIconButtonPopup class or descendent.
  252.     
  253.     Use as follows:
  254.     
  255.         class MyPopup : public LGAIconButtonPopup,
  256.                         public CGAIconButtonPopupFolderMixin {
  257.                                  
  258.                 ... Methods
  259.         }
  260.         
  261.     Make sure to call CMailFolderMixin::UpdateMailFolderMixins(this) from 
  262.     MyPopup::FinishCreateSelf().
  263. ======================================================================================*/
  264.  
  265. class CGAIconButtonPopupFolderMixin : public CMailFolderPopupMixin {
  266.  
  267. public:
  268.  
  269.                         CGAIconButtonPopupFolderMixin(void) {
  270.                         }
  271.                     
  272. protected:
  273.  
  274.     virtual MenuHandle    MGetSystemMenuHandle(void);
  275.     virtual void        MRefreshMenu(void);
  276.  
  277.     LGAIconButtonPopup    *MGetControl(void) {
  278.                             LGAIconButtonPopup *theControl = dynamic_cast<LGAIconButtonPopup *>(this);
  279.                             Assert_(theControl != nil);
  280.                             return theControl;
  281.                         }
  282. };
  283.  
  284.  
  285. /*======================================================================================
  286.     Mixin with a LMenu class or descendent.
  287.     
  288.     Use as follows:
  289.     
  290.         class MyPopup : public LMenu,
  291.                         public CMenuMailFolderMixin {
  292.                                  
  293.                 ... Methods
  294.         }
  295.         
  296.     After creating the menu, it should be added to the menu bar using the 
  297.     LMenuBar::InstallMenu() method.
  298.     
  299.     For each menu item (i.e. folder) a synthetic command ID is created.
  300.         
  301.     Make sure to call CMailFolderMixin::UpdateMailFolderMixins(this) after constructing
  302.     the object.
  303. ======================================================================================*/
  304.  
  305. class CMenuMailFolderMixin : public CMailFolderMixin {
  306.                       
  307. public:
  308.  
  309.                         CMenuMailFolderMixin(CommandT inMenuCommand = cmd_UseMenuItem) {
  310.                             mMenuCommand = inMenuCommand;
  311.                         }
  312.                     
  313. protected:
  314.  
  315.     virtual Int16        MGetNumMenuItems(void);
  316.     virtual Int16        MGetSelectedMenuItem(void);
  317.     virtual void        MSetSelectedMenuItem(Int16 inIndex, Boolean inDoBroadcast = true);
  318.     virtual Boolean        MUpdateMenuItem(Int16 inMenuItem, ConstStr255Param inName, 
  319.                                         ResIDT inIconID = 0);
  320.     virtual void        MAppendMenuItem(ConstStr255Param inName, ResIDT inIconID = 0);
  321.     virtual void        MClipMenuItems(Int16 inStartClipItem);
  322.     virtual void        MGetMenuItemName(Int16 inMenuItem, Str255 outItemName);
  323.     virtual void        MRefreshMenu(void);
  324.     virtual MenuHandle    MGetSystemMenuHandle(void);
  325.     
  326.     LMenu                *MGetMenu(void) {
  327.                             LMenu *theMenu = dynamic_cast<LMenu *>(this);
  328.                             Assert_(theMenu != nil);
  329.                             return theMenu;
  330.                         }
  331.                         
  332.     // Instance variables
  333.         
  334.     CommandT            mMenuCommand;
  335. };
  336.  
  337.  
  338. #pragma mark
  339. class CSelectFolderMenu : public LGAPopup, public CGAPopupFolderMixin
  340. {
  341.     public:
  342.         enum
  343.         {
  344.             class_ID = 'SelF'
  345.         };
  346.  
  347.                         CSelectFolderMenu(LStream    *inStream);
  348.         virtual            ~CSelectFolderMenu();
  349.         virtual    void    FinishCreateSelf();
  350.         virtual    void    SetupCurrentMenuItem(MenuHandle inMenuH, Int16 inCurrentItem);
  351.         virtual void    SetValue(Int32 inValue);
  352.  
  353.         void            CommitCurrentSelections();
  354.  
  355.     private:
  356.         void            UpdateCommandMarks();
  357.  
  358.         Int16    mSelectedItemCount;
  359.         Int16    mTotalItemCount;
  360.         Int16    mMenuWidth;
  361. };
  362.  
  363. #endif // __H_UMailFolderMenus
  364.  
  365.