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,2009 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or modify          *
00009 * it under the terms of the GNU Lesser General Public License as published by   *
00010 * the Free Software Foundation; either version 3 of the License, or             *
00011 * (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                 *
00016 * GNU Lesser General Public License for more details.                           *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public License      *
00019 * along with this program.  If not, see <http://www.gnu.org/licenses/>          *
00020 *********************************************************************************
00021 * $Id: FXMenuButton.h,v 1.33 2009/01/06 13:07:25 fox Exp $                      *
00022 ********************************************************************************/
00023 #ifndef FXMENUBUTTON_H
00024 #define FXMENUBUTTON_H
00025 
00026 #ifndef FXLABEL_H
00027 #include "FXLabel.h"
00028 #endif
00029 
00030 namespace FX {
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 onButtonPress(FXObject*,FXSelector,void*);
00093   long onButtonRelease(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);
00128 
00129   /// Return current popup menu
00130   FXPopup* getMenu() const { return pane; }
00131 
00132   /// Show or hide menu
00133   void showMenu(FXbool shw);
00134 
00135   /// Is the pane shown
00136   FXbool isMenuShown() const;
00137 
00138   /// Set X offset where menu pops up relative to button
00139   void setXOffset(FXint offx){ offsetx=offx; }
00140 
00141   /// Return current X offset
00142   FXint getXOffset() const { return offsetx; }
00143 
00144   /// Set Y offset where menu pops up relative to button
00145   void setYOffset(FXint offy){ offsety=offy; }
00146 
00147   /// Return current Y offset
00148   FXint getYOffset() const { return offsety; }
00149 
00150   /// Change menu button style
00151   void setButtonStyle(FXuint style);
00152 
00153   /// Get menu button style
00154   FXuint getButtonStyle() const;
00155 
00156   /// Change popup style
00157   void setPopupStyle(FXuint style);
00158 
00159   /// Get popup style
00160   FXuint getPopupStyle() const;
00161 
00162   /// Change attachment
00163   void setAttachment(FXuint att);
00164 
00165   /// Get attachment
00166   FXuint getAttachment() const;
00167 
00168   /// Save menu button to a stream
00169   virtual void save(FXStream& store) const;
00170 
00171   /// Load menu button from a stream
00172   virtual void load(FXStream& store);
00173 
00174   /// Destructor
00175   virtual ~FXMenuButton();
00176   };
00177 
00178 }
00179 
00180 #endif

Copyright © 1997-2009 Jeroen van der Zijp