Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXMenuButton.h

00001 /********************************************************************************
00002 *                                                                               *
00003 *                        M e n u   B u t t o n   W i d g e t                    *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1998,2002 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or                 *
00009 * modify it under the terms of the GNU Lesser General Public                    *
00010 * License as published by the Free Software Foundation; either                  *
00011 * version 2.1 of the License, or (at your option) any later version.            *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU             *
00016 * Lesser General Public License for more details.                               *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public              *
00019 * License along with this library; if not, write to the Free Software           *
00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
00021 *********************************************************************************
00022 * $Id: FXMenuButton.h,v 1.14 2002/01/18 22:42:53 jeroen Exp $                   *
00023 ********************************************************************************/
00024 #ifndef FXMENUBUTTON_H
00025 #define FXMENUBUTTON_H
00026 
00027 #ifndef FXLABEL_H
00028 #include "FXLabel.h"
00029 #endif
00030 
00031 
00032 
00033 class FXPopup;
00034 
00035 
00036 // Menu button options
00037 enum {
00038   MENUBUTTON_AUTOGRAY      = 0x00800000,                                      /// Automatically gray out when no target
00039   MENUBUTTON_AUTOHIDE      = 0x01000000,                                      /// Automatically hide when no target
00040   MENUBUTTON_TOOLBAR       = 0x02000000,                                      /// Toolbar style
00041   MENUBUTTON_DOWN          = 0,                                               /// Popup window appears below menu button
00042   MENUBUTTON_UP            = 0x04000000,                                      /// Popup window appears above menu button
00043   MENUBUTTON_LEFT          = 0x08000000,                                      /// Popup window to the left of the menu button
00044   MENUBUTTON_RIGHT         = MENUBUTTON_LEFT|MENUBUTTON_UP,                   /// Popup window to the right of the menu button
00045   MENUBUTTON_NOARROWS      = 0x10000000,                                      /// Do not show arrows
00046   MENUBUTTON_ATTACH_LEFT   = 0,                                               /// Popup attaches to the left side of the menu button
00047   MENUBUTTON_ATTACH_TOP    = MENUBUTTON_ATTACH_LEFT,                          /// Popup attaches to the top of the menu button
00048   MENUBUTTON_ATTACH_RIGHT  = 0x20000000,                                      /// Popup attaches to the right side of the menu button
00049   MENUBUTTON_ATTACH_BOTTOM = MENUBUTTON_ATTACH_RIGHT,                         /// Popup attaches to the bottom of the menu button
00050   MENUBUTTON_ATTACH_CENTER = 0x40000000,                                      /// Popup attaches to the center of the menu button
00051   MENUBUTTON_ATTACH_BOTH   = MENUBUTTON_ATTACH_CENTER|MENUBUTTON_ATTACH_RIGHT /// Popup attaches to both sides of the menu button
00052   };
00053 
00054 
00055 
00056 /**
00057 * A menu button posts a popup menu when clicked.
00058 * There are many ways to control the placement where the popup will appear;
00059 * first, the popup may be placed on either of the four sides relative to the
00060 * menu button; this is controlled by the flags MENUBUTTON_DOWN, etc.
00061 * Next, there are several attachment modes; the popup's left/bottom edge may
00062 * attach to the menu button's left/top edge, or the popup's right/top edge may
00063 * attach to the menu button's right/bottom edge, or both.
00064 * Also, the popup may apear centered relative to the menu button.
00065 * Finally, a small offset may be specified to displace the location of the
00066 * popup by a few pixels so as to account for borders and so on.
00067 * Normally, the menu button shows an arrow pointing to the direction where
00068 * the popup is set to appear; this can be turned off by passing the option
00069 * MENUBUTTON_NOARROWS.
00070 */
00071 class FXAPI FXMenuButton : public FXLabel {
00072   FXDECLARE(FXMenuButton)
00073 protected:
00074   FXPopup *pane;                  // Pane to pop up
00075   FXint    offsetx;               // Shift attachment point x
00076   FXint    offsety;               // Shift attachment point y
00077   FXbool   state;                 // Pane was popped
00078 protected:
00079   FXMenuButton();
00080 private:
00081   FXMenuButton(const FXMenuButton&);
00082   FXMenuButton &operator=(const FXMenuButton&);
00083 public:
00084   long onPaint(FXObject*,FXSelector,void*);
00085   long onUpdate(FXObject*,FXSelector,void*);
00086   long onEnter(FXObject*,FXSelector,void*);
00087   long onLeave(FXObject*,FXSelector,void*);
00088   long onFocusIn(FXObject*,FXSelector,void*);
00089   long onFocusOut(FXObject*,FXSelector,void*);
00090   long onUngrabbed(FXObject*,FXSelector,void*);
00091   long onMotion(FXObject*,FXSelector,void*);
00092   long onLeftBtnPress(FXObject*,FXSelector,void*);
00093   long onLeftBtnRelease(FXObject*,FXSelector,void*);
00094   long onKeyPress(FXObject*,FXSelector,void*);
00095   long onKeyRelease(FXObject*,FXSelector,void*);
00096   long onHotKeyPress(FXObject*,FXSelector,void*);
00097   long onHotKeyRelease(FXObject*,FXSelector,void*);
00098   long onCmdPost(FXObject*,FXSelector,void*);
00099   long onCmdUnpost(FXObject*,FXSelector,void*);
00100 public:
00101 
00102   /// Constructor
00103   FXMenuButton(FXComposite* p,const FXString& text,FXIcon* ic=NULL,FXPopup* pup=NULL,FXuint opts=JUSTIFY_NORMAL|ICON_BEFORE_TEXT|MENUBUTTON_DOWN,FXint x=0,FXint y=0,FXint w=0,FXint h=0,FXint pl=DEFAULT_PAD,FXint pr=DEFAULT_PAD,FXint pt=DEFAULT_PAD,FXint pb=DEFAULT_PAD);
00104 
00105   /// Create server-side resources
00106   virtual void create();
00107 
00108   /// Detach server-side resources
00109   virtual void detach();
00110 
00111   /// Return default width
00112   virtual FXint getDefaultWidth();
00113 
00114   /// Return default height
00115   virtual FXint getDefaultHeight();
00116 
00117   /// Returns true because a menu button can receive focus
00118   virtual FXbool canFocus() const;
00119 
00120   /// Remove the focus from this window
00121   virtual void killFocus();
00122 
00123   /// Return true if window logically contains the given point
00124   virtual FXbool contains(FXint parentx,FXint parenty) const;
00125 
00126   /// Change the popup menu
00127   void setMenu(FXPopup *pup){ pane = pup; }
00128 
00129   /// Return current popup menu
00130   FXPopup* getMenu() const { return pane; }
00131 
00132   /// Set X offset where menu pops up relative to button
00133   void setXOffset(FXint offx){ offsetx=offx; }
00134 
00135   /// Return current X offset
00136   FXint getXOffset() const { return offsetx; }
00137 
00138   /// Set Y offset where menu pops up relative to button
00139   void setYOffset(FXint offy){ offsety=offy; }
00140 
00141   /// Return current Y offset
00142   FXint getYOffset() const { return offsety; }
00143 
00144   /// Change menu button style
00145   void setButtonStyle(FXuint style);
00146 
00147   /// Get menu button style
00148   FXuint getButtonStyle() const;
00149 
00150   /// Change popup style
00151   void setPopupStyle(FXuint style);
00152 
00153   /// Get popup style
00154   FXuint getPopupStyle() const;
00155 
00156   /// Change attachment
00157   void setAttachment(FXuint att);
00158 
00159   /// Get attachment
00160   FXuint getAttachment() const;
00161 
00162   /// Save menu button to a stream
00163   virtual void save(FXStream& store) const;
00164 
00165   /// Load menu button from a stream
00166   virtual void load(FXStream& store);
00167 
00168   /// Destructor
00169   virtual ~FXMenuButton();
00170   };
00171 
00172 #endif