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

FXToolbarButton.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *                  Toolbar button widget                                        *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 2003 by Mathew Robertson.   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 #ifndef FXTOOLBARBUTTON_H
00023 #define FXTOOLBARBUTTON_H
00024 
00025 #ifndef FXHORIONTALFRAME_H
00026 #include <fox/FXHorizontalFrame.h>
00027 using namespace FX;
00028 #endif
00029 namespace FXEX {
00030 
00031 /**
00032  * This class is a drop in replacement for FXButton, with the ablity to
00033  * toggle text hiding when needed, such is the case for toolbar buttons, and can
00034  * post a FXPopup (and derived classes) when the drop button is pressed.
00035  *
00036  * Bugs: since FXButton::setText(...) is not virtual, there _may be_ a problem here that
00037  *       the FXToolbarButton will get out of sync with the FXButton state.  We need
00038  *       to be able to overload getText/setText.
00039  */
00040 class FXAPI FXToolbarButton : public FXHorizontalFrame {
00041   FXDECLARE(FXToolbarButton)
00042 
00043 private:
00044   FXButton     *mainbutton;
00045   FXMenuButton *menubutton;
00046   FXString      label;
00047 
00048 protected:
00049   FXToolbarButton(){}
00050 
00051 private:
00052   FXToolbarButton(const FXToolbarButton&);
00053   FXToolbarButton& operator=(const FXToolbarButton&);
00054 
00055 public:
00056   enum {
00057     ID_TOGGLESHOWN=FXHorizontalFrame::ID_LAST,
00058     ID_LAST
00059     };
00060 
00061 public:
00062   long onCmdToggleText(FXObject*,FXSelector,void*);
00063   long onUpdToggleText(FXObject*,FXSelector,void*);
00064 
00065 public:
00066   /// create a button, with a second button which posts a menu pane
00067   FXToolbarButton(FXComposite *p,const FXString& text,FXIcon* ic=NULL,FXPopup *pup=NULL,FXObject *tgt=NULL,FXSelector=0,FXuint opts=BUTTON_NORMAL,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);
00068 
00069   /// create resources
00070   virtual void create();
00071 
00072   /// detach resources
00073   virtual void detach();
00074 
00075   /// destroy resources
00076   virtual void destroy();
00077 
00078   /// returns a pointer to the main button
00079   FXButton* getButton() { return mainbutton; }
00080 
00081   /// returns a pointer to the menu button
00082   FXMenuButton* getMenuButton() { return menubutton; }
00083 
00084   /// set the popup
00085   void setMenu(FXPopup *pup);
00086 
00087   /// get the popup
00088   FXPopup* getMenu() { return menubutton->getMenu(); }
00089 
00090   /// toggle showing text
00091   void textToggle();
00092 
00093   /// is the text shown?
00094   FXbool textShown();
00095 
00096   /// set the text on the main button
00097   void setText(const FXString& text);
00098 
00099   /// get the text on the main button
00100   FXString getText() const;
00101 
00102   /// save object
00103   virtual void save(FXStream& store) const;
00104 
00105   /// load object
00106   virtual void load(FXStream& store);
00107 
00108   /// dtor
00109   virtual ~FXToolbarButton();
00110   };
00111 
00112 } // namespace FXEX
00113 #endif // FXTOOLBARBUTTON_H