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

FXMenuButton.h

Go to the documentation of this file.
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,2006 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.24 2006/01/22 17:58:06 fox Exp $                      *
00023 ********************************************************************************/
00024 #ifndef FXMENUBUTTON_H
00025 #define FXMENUBUTTON_H
00026 
00027 #ifndef FXLABEL_H
00028 #include "FXLabel.h"
00029 #endif
00030 
00031 namespace FX {
00032 
00033 
00034 class FXPopup;
00035 
00036 
00037 // Menu button options
00038 enum {
00039   MENUBUTTON_AUTOGRAY      = 0x00800000,                                      /// Automatically gray out when no target
00040   MENUBUTTON_AUTOHIDE      = 0x01000000,                                      /// Automatically hide when no target
00041   MENUBUTTON_TOOLBAR       = 0x02000000,                                      /// Toolbar style
00042   MENUBUTTON_DOWN          = 0,                                               /// Popup window appears below menu button
00043   MENUBUTTON_UP            = 0x04000000,                                      /// Popup window appears above menu button
00044   MENUBUTTON_LEFT          = 0x08000000,                                      /// Popup window to the left of the menu button
00045   MENUBUTTON_RIGHT         = MENUBUTTON_LEFT|MENUBUTTON_UP,                   /// Popup window to the right of the menu button
00046   MENUBUTTON_NOARROWS      = 0x10000000,                                      /// Do not show arrows
00047   MENUBUTTON_ATTACH_LEFT   = 0,                                               /// Popup attaches to the left side of the menu button
00048   MENUBUTTON_ATTACH_TOP    = MENUBUTTON_ATTACH_LEFT,                          /// Popup attaches to the top of the menu button
00049   MENUBUTTON_ATTACH_RIGHT  = 0x20000000,                                      /// Popup attaches to the right side of the menu button
00050   MENUBUTTON_ATTACH_BOTTOM = MENUBUTTON_ATTACH_RIGHT,                         /// Popup attaches to the bottom of the menu button
00051   MENUBUTTON_ATTACH_CENTER = 0x40000000,                                      /// Popup attaches to the center of the menu button
00052   MENUBUTTON_ATTACH_BOTH   = MENUBUTTON_ATTACH_CENTER|MENUBUTTON_ATTACH_RIGHT /// Popup attaches to both sides of the menu button
00053   };
00054 
00055 
00056 
00057 /**
00058 * A menu button posts a popup menu when clicked.
00059 * There are many ways to control the placement where the popup will appear;
00060 * first, the popup may be placed on either of the four sides relative to the
00061 * menu button; this is controlled by the flags MENUBUTTON_DOWN, etc.
00062 * Next, there are several attachment modes; the popup's left/bottom edge may
00063 * attach to the menu button's left/top edge, or the popup's right/top edge may
00064 * attach to the menu button's right/bottom edge, or both.
00065 * Also, the popup may apear centered relative to the menu button.
00066 * Finally, a small offset may be specified to displace the location of the
00067 * popup by a few pixels so as to account for borders and so on.
00068 * Normally, the menu button shows an arrow pointing to the direction where
00069 * the popup is set to appear; this can be turned off by passing the option
00070 * MENUBUTTON_NOARROWS.
00071 */
00072 class FXAPI FXMenuButton : public FXLabel {
00073   FXDECLARE(FXMenuButton)
00074 protected:
00075   FXPopup *pane;                  // Pane to pop up
00076   FXint    offsetx;               // Shift attachment point x
00077   FXint    offsety;               // Shift attachment point y
00078   FXbool   state;                 // Pane was popped
00079 protected:
00080   FXMenuButton();
00081 private:
00082   FXMenuButton(const FXMenuButton&);
00083   FXMenuButton &operator=(const FXMenuButton&);
00084 public:
00085   long onPaint(FXObject*,FXSelector,void*);
00086   long onUpdate(FXObject*,FXSelector,void*);
00087   long onEnter(FXObject*,FXSelector,void*);
00088   long onLeave(FXObject*,FXSelector,void*);
00089   long onFocusIn(FXObject*,FXSelector,void*);
00090   long onFocusOut(FXObject*,FXSelector,void*);
00091   long onUngrabbed(FXObject*,FXSelector,void*);
00092   long onMotion(FXObject*,FXSelector,void*);
00093   long onLeftBtnPress(FXObject*,FXSelector,void*);
00094   long onLeftBtnRelease(FXObject*,FXSelector,void*);
00095   long onKeyPress(FXObject*,FXSelector,void*);
00096   long onKeyRelease(FXObject*,FXSelector,void*);
00097   long onHotKeyPress(FXObject*,FXSelector,void*);
00098   long onHotKeyRelease(FXObject*,FXSelector,void*);
00099   long onCmdPost(FXObject*,FXSelector,void*);
00100   long onCmdUnpost(FXObject*,FXSelector,void*);
00101 public:
00102 
00103   /// Constructor
00104   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);
00105 
00106   /// Create server-side resources
00107   virtual void create();
00108 
00109   /// Detach server-side resources
00110   virtual void detach();
00111 
00112   /// Return default width
00113   virtual FXint getDefaultWidth();
00114 
00115   /// Return default height
00116   virtual FXint getDefaultHeight();
00117 
00118   /// Returns true because a menu button can receive focus
00119   virtual bool canFocus() const;
00120 
00121   /// Remove the focus from this window
00122   virtual void killFocus();
00123 
00124   /// Return true if window logically contains the given point
00125   virtual bool contains(FXint parentx,FXint parenty) const;
00126 
00127   /// Change the popup menu
00128   void setMenu(FXPopup *pup);
00129 
00130   /// Return current popup menu
00131   FXPopup* getMenu() const { return pane; }
00132 
00133   /// Set X offset where menu pops up relative to button
00134   void setXOffset(FXint offx){ offsetx=offx; }
00135 
00136   /// Return current X offset
00137   FXint getXOffset() const { return offsetx; }
00138 
00139   /// Set Y offset where menu pops up relative to button
00140   void setYOffset(FXint offy){ offsety=offy; }
00141 
00142   /// Return current Y offset
00143   FXint getYOffset() const { return offsety; }
00144 
00145   /// Change menu button style
00146   void setButtonStyle(FXuint style);
00147 
00148   /// Get menu button style
00149   FXuint getButtonStyle() const;
00150 
00151   /// Change popup style
00152   void setPopupStyle(FXuint style);
00153 
00154   /// Get popup style
00155   FXuint getPopupStyle() const;
00156 
00157   /// Change attachment
00158   void setAttachment(FXuint att);
00159 
00160   /// Get attachment
00161   FXuint getAttachment() const;
00162 
00163   /// Save menu button to a stream
00164   virtual void save(FXStream& store) const;
00165 
00166   /// Load menu button from a stream
00167   virtual void load(FXStream& store);
00168 
00169   /// Destructor
00170   virtual ~FXMenuButton();
00171   };
00172 
00173 }
00174 
00175 #endif

Copyright © 1997-2005 Jeroen van der Zijp