home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / Borland / Cplus45 / BC45 / OWLINC.PAK / MENU.H < prev    next >
C/C++ Source or Header  |  1995-08-29  |  9KB  |  278 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // (C) Copyright 1991, 1994 by Borland International, All Rights Reserved
  4. //
  5. //   Definition of Window Menu encapsulation class
  6. //----------------------------------------------------------------------------
  7. #if !defined(OWL_MENU_H)
  8. #define OWL_MENU_H
  9.  
  10. #if !defined(OWL_GDIOBJEC_H)
  11. # include <owl/gdiobjec.h>
  12. #endif
  13.  
  14. //
  15. //  class TMenuItem
  16. //  ----- ---------
  17. //  Representation of a menu item which can be a uint Id/position or a popup
  18. //  menu handle.
  19. //
  20. #if 0  //!CQ A nice idea, but has a couple of snags yet
  21. class TMenuItem {
  22.   public:
  23.     TMenuItem(uint id) {Item = id;}
  24.     TMenuItem(HMENU popup) {Item = reinterpret_cast<uint>(popup);}
  25.     operator uint() {return Item;}
  26.  
  27.   private:
  28.     uint Item;
  29. };
  30. #else
  31. typedef uint TMenuItem;
  32. #endif
  33.  
  34. //
  35. //  class TMenu
  36. //  ----- -----
  37. //
  38. class _OWLCLASS TMenu {
  39.   public:
  40.     TMenu(TAutoDelete autoDelete = AutoDelete);
  41.     TMenu(const TMenu& original, TAutoDelete autoDelete = AutoDelete);
  42.     TMenu(HMENU handle, TAutoDelete autoDelete = NoAutoDelete);
  43.     TMenu(HWND hWnd, TAutoDelete autoDelete = NoAutoDelete);
  44.     TMenu(const void far* menuTemplate);
  45.     TMenu(HINSTANCE instance, TResId resId);
  46.     virtual ~TMenu();
  47.  
  48.     TMenu& operator =(const TMenu&);
  49.     
  50.     class _OWLCLASS_RTL TXMenu : public TXOwl {
  51.       public:
  52.         TXMenu(unsigned resId = IDS_GDIFAILURE);
  53.         TXOwl* Clone();
  54.         void Throw();
  55.     };
  56.     void        CheckValid(uint redId = IDS_MENUFAILURE);
  57.     virtual HMENU GetHandle() const {return Handle;}
  58.  
  59.     operator    uint() const {return reinterpret_cast<uint>(GetHandle());}
  60.     operator    HMENU() const {return GetHandle();}
  61.  
  62.     bool        IsOK() const {return GetHandle() != 0;}
  63.  
  64.     //
  65.     // HMENU encapsulated functions
  66.     //
  67.     bool        AppendMenu(uint flags, TMenuItem newItem=-1, const char far* newStr=0);
  68.     bool        AppendMenu(uint flags, TMenuItem newitem, const TBitmap& newBmp);
  69.     bool        CheckMenuItem(TMenuItem item, uint check);
  70.     bool        DeleteMenu(TMenuItem item, uint flags);
  71.     bool        EnableMenuItem(TMenuItem item, uint enable);
  72.     uint        GetMenuItemCount() const;
  73.     uint        GetMenuItemID(int posItem) const;
  74.     uint        GetMenuState(TMenuItem item, uint flags) const;
  75.     uint        GetMenuString(TMenuItem item, char* str, int count, uint flags) const;
  76.     HMENU       GetSubMenu(int posItem) const;
  77.     bool        InsertMenu(TMenuItem item, uint flags, TMenuItem newItem=-1, const char far* newStr=0);
  78.     bool        InsertMenu(TMenuItem item, uint flags, TMenuItem newItem, const TBitmap& newBmp);
  79.     bool        ModifyMenu(TMenuItem item, uint flags, TMenuItem newItem=-1, const char far* newStr=0);
  80.     bool        ModifyMenu(TMenuItem item, uint flags, TMenuItem newItem, const TBitmap& newBmp);
  81.     bool        RemoveMenu(TMenuItem item, uint flags);
  82.     bool        SetMenuItemBitmaps(TMenuItem item, uint flags,
  83.                                    const TBitmap* bmpUnchecked=0,
  84.                                    const TBitmap* bmpChecked=0);
  85.  
  86.     static bool  GetMenuCheckMarkDimensions(TSize& size);
  87.     static TSize GetMenuCheckMarkDimensions();
  88.  
  89.     //
  90.     // virtual menu functions
  91.     //
  92.     virtual void  MeasureItem(MEASUREITEMSTRUCT far& measureItem);
  93.     virtual void  DrawItem(DRAWITEMSTRUCT far& drawItem);
  94.  
  95.   protected:
  96.     HMENU       Handle;
  97.     bool        ShouldDelete;   // Should this object destroy Menu?
  98.  
  99.     static void DeepCopy(TMenu& dest, const TMenu& source, int offset = 0, int count = -1);
  100.     static void DeepCopy(TMenu& dst, int dstOff, const TMenu& src, int srcOff = 0, int count = -1);
  101.  
  102.   private:
  103. };
  104.  
  105. //
  106. //  class TSystemMenu
  107. //  ----- -----------
  108. //
  109. class _OWLCLASS TSystemMenu : public TMenu {
  110.   public:
  111.     TSystemMenu(HWND wnd, bool revert= false);
  112.  
  113.   private:
  114.     TSystemMenu();
  115.     TSystemMenu(const TSystemMenu&);
  116. };
  117.  
  118. //
  119. //  class TPopupMenu
  120. //  ----- ----------
  121. //
  122. class _OWLCLASS TPopupMenu : public TMenu {
  123.   public:
  124.     TPopupMenu(TAutoDelete autoDelete = AutoDelete);
  125.     TPopupMenu(HMENU handle, TAutoDelete autoDelete = NoAutoDelete);
  126.  
  127.     bool        TrackPopupMenu(uint flags, int x, int y, int rsvd, HWND wnd,
  128.                                const TRect* rect=0);
  129.     bool        TrackPopupMenu(uint flags, const TPoint& point, int rsvd,
  130.                                HWND wnd, const TRect* rect=0);
  131.  
  132.   private:
  133.     TPopupMenu(const TPopupMenu&);
  134. };
  135.  
  136. //
  137. //  class TMenuDescr
  138. //  ----- ----------
  139. //
  140. //  Menu information used to allow merging of two menus
  141. //
  142. class _OWLCLASS TMenuDescr : public TMenu {
  143.   public:
  144.     enum TGroup {
  145.       FileGroup,
  146.       EditGroup,
  147.       ContainerGroup,
  148.       ObjectGroup,
  149.       WindowGroup,
  150.       HelpGroup,
  151.       NumGroups
  152.     };
  153.     TMenuDescr();
  154.     TMenuDescr(const TMenuDescr& original);
  155.     TMenuDescr(TResId id, int fg, int eg, int cg, int og, int wg, int hg,
  156.                TModule* module = ::Module);
  157.     TMenuDescr(TResId id, TModule* module = ::Module);
  158.     TMenuDescr(HMENU hMenu, int fg, int eg, int cg, int og, int wg, int hg,
  159.                TModule* module = ::Module);
  160.    ~TMenuDescr();
  161.  
  162.     TMenuDescr& operator =(const TMenuDescr& original);
  163.  
  164.     HMENU    GetHandle() const {return Handle;}
  165.     TModule* GetModule() const {return Module;}
  166.     void     SetModule(TModule* module) {Module = module;}
  167.     TResId   GetId() const {return Id;}
  168.     int      GetGroupCount(int group) const {return GroupCount[group];}
  169.     void     ClearServerGroupCount();
  170.     void     ClearContainerGroupCount();
  171.  
  172.     bool     Merge(const TMenuDescr& sourceMenuDescr);
  173.     bool     Merge(const TMenuDescr& sourceMenuDescr, TMenu& destMenu);
  174.  
  175.   protected:
  176.     TModule* Module;       // module where menu lives
  177.     TResId   Id;           // resource id of menu
  178.     int      GroupCount[NumGroups];
  179.  
  180.     bool     ExtractGroups();
  181.  
  182.   friend ipstream& operator >>(ipstream& is, TMenuDescr& m);
  183.   friend opstream& operator <<(opstream& os, const TMenuDescr& m);
  184. };
  185.  
  186.  
  187. //----------------------------------------------------------------------------
  188. // Inlines
  189. //----------------------------------------------------------------------------
  190.  
  191. inline bool TMenu::AppendMenu(uint flags, TMenuItem newItem, const char far* newStr) {
  192.   return ::AppendMenu(Handle, flags, newItem, newStr);
  193. }
  194.  
  195. inline bool TMenu::AppendMenu(uint flags, TMenuItem newItem, const TBitmap& newBmp) {
  196.   return ::AppendMenu(Handle, flags|MF_BITMAP, newItem,
  197.          (const char far*)HBITMAP(newBmp));
  198. }
  199.  
  200. inline bool TMenu::CheckMenuItem(TMenuItem item, uint check) {
  201.   return ::CheckMenuItem(Handle, item, check);
  202. }
  203.  
  204. inline bool TMenu::DeleteMenu(TMenuItem item, uint flags) {
  205.   return ::DeleteMenu(Handle, item, flags);
  206. }
  207.  
  208. inline bool TMenu::EnableMenuItem(TMenuItem item, uint enable) {
  209.   return ::EnableMenuItem(Handle, item, enable);
  210. }
  211.  
  212. inline uint TMenu::GetMenuItemCount() const {
  213.   return ::GetMenuItemCount(Handle);
  214. }
  215.  
  216. inline uint TMenu::GetMenuState(TMenuItem item, uint flags) const {
  217.   return ::GetMenuState(Handle, item, flags);
  218. }
  219.  
  220. inline uint TMenu::GetMenuString(TMenuItem item, char* str, int count, uint flags) const {
  221.   return ::GetMenuString(Handle, item, str, count, flags);
  222. }
  223.  
  224. inline HMENU TMenu::GetSubMenu(int posItem) const {
  225.   return ::GetSubMenu(Handle, posItem);
  226. }
  227.  
  228. inline bool TMenu::InsertMenu(TMenuItem item, uint flags, TMenuItem newItem, const char far* newStr) {
  229.   return ::InsertMenu(Handle, item, flags|MF_STRING, newItem, newStr);
  230. }
  231.  
  232. inline bool TMenu::InsertMenu(TMenuItem item, uint flags, TMenuItem newItem, const TBitmap& newBmp) {
  233.   return ::InsertMenu(Handle, item, flags|MF_BITMAP, newItem,
  234.          (const char far*)HBITMAP(newBmp));
  235. }
  236.  
  237. inline bool TMenu::ModifyMenu(TMenuItem item, uint flags, TMenuItem newItem, const char far* newStr) {
  238.   return ::ModifyMenu(Handle, item, flags|MF_STRING, newItem, newStr);
  239. }
  240.  
  241. inline bool TMenu::ModifyMenu(TMenuItem item, uint flags, TMenuItem newItem, const TBitmap& newBmp) {
  242.   return ::ModifyMenu(Handle, item, flags|MF_BITMAP, newItem,
  243.          (const char far*)HBITMAP(newBmp));
  244. }
  245.  
  246. inline bool TMenu::RemoveMenu(TMenuItem item, uint flags) {
  247.   return ::RemoveMenu(Handle, item, flags);
  248. }
  249.  
  250. inline bool TMenu::SetMenuItemBitmaps(TMenuItem item, uint flags,
  251.                                       const TBitmap* bmpUnchecked,
  252.                                       const TBitmap* bmpChecked) {
  253.   return ::SetMenuItemBitmaps(Handle, item, flags,
  254.   bmpUnchecked ? HBITMAP(*bmpUnchecked) : 0,
  255.   bmpChecked ? HBITMAP(*bmpChecked) : 0);
  256. }
  257.  
  258. inline bool TMenu::GetMenuCheckMarkDimensions(TSize& size) {
  259.   size = ::GetMenuCheckMarkDimensions();
  260.   return true;
  261. }
  262.  
  263. inline TSize TMenu::GetMenuCheckMarkDimensions() {
  264.   return ::GetMenuCheckMarkDimensions();
  265. }
  266.  
  267. inline bool TPopupMenu::TrackPopupMenu(uint flags, int x, int y, int rsvd,
  268.                                        HWND wnd, const TRect* rect) {
  269.   return ::TrackPopupMenu(Handle, flags, x, y, rsvd, wnd, rect);
  270. }
  271.  
  272. inline bool TPopupMenu::TrackPopupMenu(uint flags, const TPoint& point,
  273.                                        int rsvd, HWND wnd, const TRect* rect) {
  274.   return ::TrackPopupMenu(Handle, flags, point.x, point.y, rsvd, wnd, rect);
  275. }
  276.  
  277. #endif  // OWL_MENU_H
  278.