home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c083 / 19.ddi / OWLINC.PAK / MENU.H < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-02  |  6.6 KB  |  187 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1991, 1993 by Borland International
  3. //   include\owl\menu.h
  4. //   Definition of Window Menu encapsulation class
  5. //----------------------------------------------------------------------------
  6. #if !defined(__OWL_MENU_H)
  7. #define __OWL_MENU_H
  8.  
  9. #if !defined(__OWL_GDIOBJEC_H)
  10.   #include <owl\gdiobjec.h>
  11. #endif
  12.  
  13. class _OWLCLASS TMenu {
  14.   public:
  15.     TMenu(TAutoDelete autoDelete = AutoDelete);
  16.     TMenu(HMENU handle, TAutoDelete autoDelete = NoAutoDelete);
  17.     TMenu(HWND hWnd, TAutoDelete autoDelete = NoAutoDelete);
  18.     TMenu(LPCVOID* menuTemplate);
  19.     TMenu(HINSTANCE instance, TResId resId);
  20.     virtual ~TMenu();
  21.  
  22.     class _OWLCLASS_RTL TXMenu : public TXOwl {
  23.       public:
  24.         TXMenu(unsigned resId = IDS_GDIFAILURE);
  25.         TXOwl* Clone();
  26.         void Throw();
  27.     };
  28.     void        CheckValid(UINT redId = IDS_MENUFAILURE);
  29.  
  30.     operator    UINT() {return (UINT)Handle;}
  31.     operator    HMENU() {return Handle;}
  32.  
  33.     BOOL        IsOK() const {return Handle != 0;}
  34.  
  35.     //
  36.     // HMENU encapsulated functions
  37.     //
  38.     BOOL        AppendMenu(UINT flags, UINT idNewItem=-1, const char far* newItem=0);
  39.     BOOL        AppendMenu(UINT flags, UINT idNewItem, const TBitmap& newBmp);
  40.     BOOL        CheckMenuItem(UINT idItem, UINT check);
  41.     BOOL        DeleteMenu(UINT idItem, UINT flags);
  42.     BOOL        EnableMenuItem(UINT idItem, UINT enable);
  43.     UINT        GetMenuItemCount() const;
  44.     UINT        GetMenuItemID(int posItem) const;
  45.     UINT        GetMenuState(UINT idItem, UINT flags) const;
  46.     UINT        GetMenuString(UINT idItem, char* str, int count, UINT flags) const;
  47.     HMENU       GetSubMenu(int posItem) const;
  48.     BOOL        InsertMenu(UINT idItem, UINT flags, UINT idNewItem=-1, const char far* newItem=0);
  49.     BOOL        InsertMenu(UINT idItem, UINT flags, UINT idNewItem, const TBitmap& newBmp);
  50.     BOOL        ModifyMenu(UINT idItem, UINT flags, UINT idNewItem=-1, const char far* newItem=0);
  51.     BOOL        ModifyMenu(UINT idItem, UINT flags, UINT idNewItem, const TBitmap& newBmp);
  52.     BOOL        RemoveMenu(UINT idItem, UINT flags);
  53.     BOOL        SetMenuItemBitmaps(UINT idItem, UINT flags,
  54.                                    const TBitmap* bmpUnchecked=0,
  55.                                    const TBitmap* bmpChecked=0);
  56.     static BOOL GetMenuCheckMarkDimensions(TSize& size);
  57.  
  58.     //
  59.     // virtual menu functions
  60.     //
  61.     virtual void  MeasureItem(MEASUREITEMSTRUCT far& measureItem);
  62.     virtual void  DrawItem(DRAWITEMSTRUCT far& drawItem);
  63.  
  64.   protected:
  65.     HMENU       Handle;
  66.     BOOL        ShouldDelete;   // Did C++ object create Menu?
  67.  
  68.   private:
  69.     //
  70.     // hidden to prevent accidental copying or assignment
  71.     //
  72.     TMenu(const TMenu&);
  73.     TMenu& operator =(const TMenu&);
  74. };
  75.  
  76. class _OWLCLASS TSystemMenu : public TMenu {
  77.   public:
  78.     TSystemMenu(HWND wnd, BOOL revert= FALSE);
  79.  
  80.   private:
  81.     TSystemMenu();
  82.     TSystemMenu(const TSystemMenu&);
  83. };
  84.  
  85. class _OWLCLASS TPopupMenu : public TMenu {
  86.   public:
  87.     TPopupMenu(TAutoDelete autoDelete = AutoDelete);
  88.     TPopupMenu(HMENU handle, TAutoDelete autoDelete = NoAutoDelete);
  89.  
  90.     BOOL        TrackPopupMenu(UINT flags, int x, int y, int rsvd, HWND wnd, TRect* rect=0);
  91.     BOOL        TrackPopupMenu(UINT flags, TPoint& point, int rsvd, HWND wnd, TRect* rect=0);
  92.  
  93.   private:
  94.     TPopupMenu(const TPopupMenu&);
  95. };
  96.  
  97.  
  98. //----------------------------------------------------------------------------
  99. // Inlines
  100. //----------------------------------------------------------------------------
  101.  
  102. inline BOOL TMenu::AppendMenu(UINT flags, UINT idNewItem, const char far* newItem) {
  103.   return ::AppendMenu(Handle, flags, idNewItem, newItem);
  104. }
  105.  
  106. inline BOOL TMenu::AppendMenu(UINT flags, UINT idNewItem, const TBitmap& newBmp) {
  107.   return ::AppendMenu(Handle, flags|MF_BITMAP, idNewItem,
  108.          (const char far*)HBITMAP(newBmp));
  109. }
  110.  
  111. inline BOOL TMenu::CheckMenuItem(UINT idItem, UINT check) {
  112.   return ::CheckMenuItem(Handle, idItem, check);
  113. }
  114.  
  115. inline BOOL TMenu::DeleteMenu(UINT idItem, UINT flags) {
  116.   return ::DeleteMenu(Handle, idItem, flags);
  117. }
  118.  
  119. inline BOOL TMenu::EnableMenuItem(UINT idItem, UINT enable) {
  120.   return ::EnableMenuItem(Handle, idItem, enable);
  121. }
  122.  
  123. inline UINT TMenu::GetMenuItemCount() const {
  124.   return ::GetMenuItemCount(Handle);
  125. }
  126.  
  127. inline UINT TMenu::GetMenuItemID(int PosItem) const {
  128.   return ::GetMenuItemID(Handle, PosItem);
  129. }
  130.  
  131. inline UINT TMenu::GetMenuState(UINT idItem, UINT flags) const {
  132.   return ::GetMenuState(Handle, idItem, flags);
  133. }
  134.  
  135. inline UINT TMenu::GetMenuString(UINT idItem, char* str, int count, UINT flags) const {
  136.   return ::GetMenuString(Handle, idItem, str, count, flags);
  137. }
  138.  
  139. inline HMENU TMenu::GetSubMenu(int posItem) const {
  140.   return ::GetSubMenu(Handle, posItem);
  141. }
  142.  
  143. inline BOOL TMenu::InsertMenu(UINT idItem, UINT flags, UINT idNewItem, const char far* newItem) {
  144.   return ::InsertMenu(Handle, idItem, flags|MF_STRING, idNewItem, newItem);
  145. }
  146.  
  147. inline BOOL TMenu::InsertMenu(UINT idItem, UINT flags, UINT idNewItem, const TBitmap& newBmp) {
  148.   return ::InsertMenu(Handle, idItem, flags|MF_BITMAP, idNewItem,
  149.          (const char far*)HBITMAP(newBmp));
  150. }
  151.  
  152. inline BOOL TMenu::ModifyMenu(UINT idItem, UINT flags, UINT idNewItem, const char far* newItem) {
  153.   return ::ModifyMenu(Handle, idItem, flags|MF_STRING, idNewItem, newItem);
  154. }
  155.  
  156. inline BOOL TMenu::ModifyMenu(UINT idItem, UINT flags, UINT idNewItem, const TBitmap& newBmp) {
  157.   return ::ModifyMenu(Handle, idItem, flags|MF_BITMAP, idNewItem,
  158.          (const char far*)HBITMAP(newBmp));
  159. }
  160.  
  161. inline BOOL TMenu::RemoveMenu(UINT idItem, UINT flags) {
  162.   return ::RemoveMenu(Handle, idItem, flags);
  163. }
  164.  
  165. inline BOOL TMenu::SetMenuItemBitmaps(UINT idItem, UINT flags,
  166.                                       const TBitmap* bmpUnchecked,
  167.                                       const TBitmap* bmpChecked) {
  168.   return ::SetMenuItemBitmaps(Handle, idItem, flags,
  169.   bmpUnchecked ? HBITMAP(*bmpUnchecked) : 0,
  170.   bmpChecked ? HBITMAP(*bmpChecked) : 0);
  171. }
  172.  
  173. inline BOOL TMenu::GetMenuCheckMarkDimensions(TSize& size) {
  174.   size = ::GetMenuCheckMarkDimensions();
  175.   return TRUE;
  176. }
  177.  
  178. inline BOOL TPopupMenu::TrackPopupMenu(UINT flags, int x, int y, int rsvd, HWND wnd, TRect* rect) {
  179.   return ::TrackPopupMenu(Handle, flags, x, y, rsvd, wnd, rect);
  180. }
  181.  
  182. inline BOOL TPopupMenu::TrackPopupMenu(UINT flags, TPoint& point, int rsvd, HWND wnd, TRect* rect) {
  183.   return ::TrackPopupMenu(Handle, flags, point.x, point.y, rsvd, wnd, rect);
  184. }
  185.  
  186. #endif  // __OWL_MENU_H
  187.