mgui/formrbtn.h

Go to the documentation of this file.
00001 /**
00002  * \file mgui/formrbtn.h
00003  * \brief MGUI::FORM_RADIOBUTTONS class definitions
00004  *
00005  * \if NODOC
00006  * $Id: formrbtn.h_v 1.9 2003/10/03 19:58:19 linux32build!build Exp $
00007  *
00008  * $Log: formrbtn.h_v $
00009  * Revision 1.9  2003/10/03 19:58:19  linux32build!build
00010  * Doxygen
00011  *
00012  * Revision 1.8  2003/09/15 13:49:32  fileserver!dwilliss
00013  * Doxygen
00014  *
00015  * Revision 1.7  2003/09/10 21:18:44  mju
00016  * Use MGUI::ID for id.
00017  *
00018  * Revision 1.6  2003/04/09 20:50:49  dwilliss
00019  * Don't use _T in templates.  Mac's ctype.h defines a global _T
00020  *
00021  * Revision 1.4  2003/01/21 17:59:25  mju
00022  * Add ChildSpacing parm to Create.
00023  *
00024  * Revision 1.3  2003/01/16 21:42:35  mju
00025  * Include mgui/listitem.h
00026  *
00027  * Revision 1.2  2002/10/14 20:52:11  mju
00028  * Add CreateButton versions using ICONID.
00029  * Add SetEnabled.
00030  * Add template version.
00031  *
00032  * Revision 1.1  2002/10/09 16:20:27  mju
00033  * Initial revision
00034  * \endif
00035 **/
00036 
00037 #ifndef  INC_MGUI_FORMRBTN_H
00038 #define  INC_MGUI_FORMRBTN_H
00039 
00040 #ifndef  INC_MGUI_CTRL_H
00041 #include <mgui/ctrl.h>
00042 #endif
00043 
00044 #ifndef  INC_MGUI_LISTITEM_H
00045 #include <mgui/listitem.h>
00046 #endif
00047 
00048 
00049 namespace MGUI {
00050 
00051 //===================================================================================================================
00052 //! Container form for set of radio buttons, with enforcement of radio behavior.
00053 class FORM_RADIOBUTTONS : public MGUI::FORM_COMPOSITE {
00054    public:
00055 
00056       //! Constructor.
00057       FORM_RADIOBUTTONS (
00058          );
00059 
00060       //! Destructor.
00061       virtual ~FORM_RADIOBUTTONS (
00062          );
00063 
00064       //! Add button with string from resource lookup.
00065       void AddButton (
00066          ID id,                                 //!< ID to attach to item
00067          const char *string                     //!< String for resource lookup
00068          );
00069 
00070       //! Add button with Unicode string.
00071       void AddButton (
00072          ID id,                                 //!< ID to attach to button
00073          const UNICODE* string                  //!< String for button
00074          );
00075 
00076       //! Add icon button with tooltip from resource lookup.
00077       void AddButton (
00078          ID id,                                 //!< ID to attach to item
00079          ICONID iconid,                         //!< Icon ID
00080          const char *tooltip,                   //!< ToolTip for resource lookup
00081          int iconsize = 0                       //!< Icon size, 0 for default
00082          );
00083 
00084       //! Add icon button with Unicode tooltip.
00085       void AddButton (
00086          ID id,                                 //!< ID to attach to button
00087          ICONID iconid,                         //!< Icon ID
00088          const UNICODE* tooltip,                //!< ToolTip string
00089          int iconsize = 0                       //!< Icon size, 0 for default
00090          );
00091 
00092       //! Add multiple buttons.
00093       void AddButtons (
00094          const MGUI::LISTITEMDEF *buttons       //!< Buttons to add, terminated by button with NULL string
00095          );
00096 
00097       //! Create control.
00098       void Create (
00099          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
00100          const MGUI::LISTITEMDEF *buttons = 0,  //!< Initial button set, 0 for none
00101          MGUI::LAYOUT_ORIENTATION orientation = MGUI::LAYOUT_ORIENTATION_Vertical,
00102          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_FixedSize,
00103          int ChildSpacing = 4                   //!< Spacing between children
00104          );
00105 
00106       //! Get ID of currently selected button.
00107       //! @return ID or -1 if none selected.
00108       ID GetSelectedID (
00109          ) const;
00110 
00111       //! Set whether button is enabled or not.
00112       void SetEnabled (
00113          ID id,                                 //!< ID of button to enable/disable
00114          bool enabled = true                    //!< 'true' to enable, 'false' to disable
00115          );
00116 
00117       //! Select button using ID.
00118       //! If button does not exist then no button will appear selected
00119       void SetSelectedID (
00120          ID id                                  //!< ID of button to select
00121          );
00122 
00123    protected:
00124 
00125       //! Called when user makes selection.
00126       virtual void OnSelection ();
00127 
00128    private:
00129       #ifndef GENERATING_DOXYGEN_OUTPUT
00130 
00131       class BUTTON : public MGUI::CTRL_TOGGLEBUTTON {
00132          public:
00133             BUTTON (FORM_RADIOBUTTONS& Container) : m_Container(Container) { }
00134          private:
00135             FORM_RADIOBUTTONS& m_Container;
00136             virtual void OnPressed ();
00137          };
00138       friend class MGUI::FORM_RADIOBUTTONS::BUTTON;
00139 
00140       typedef MILIST<BUTTON*> BUTTONLIST;
00141 
00142       BUTTONLIST m_ButtonList;
00143       SIMPLE_ARRAY<ID> m_IdArray;
00144 
00145       CTRL_TOGGLEBUTTON::STYLE GetRadioStyle (
00146          ) const {
00147       #ifdef WIN32_MFC
00148          return (m_ButtonList.IsEmpty() ? CTRL_TOGGLEBUTTON::STYLE_RadioFirst : CTRL_TOGGLEBUTTON::STYLE_Radio);
00149       #else
00150          return (CTRL_TOGGLEBUTTON::STYLE_Radio);
00151       #endif
00152          }
00153 
00154       FORM_RADIOBUTTONS (const FORM_RADIOBUTTONS&);
00155       FORM_RADIOBUTTONS& operator= (const FORM_RADIOBUTTONS&);
00156       #endif // GENERATING_DOXYGEN_OUTPUT
00157    };
00158 
00159 //===================================================================================================================
00160 //! Convenience template for FORM_RADIOBUTTONS to allow method in container class to be called.
00161 template <class _CT> class FORM_RADIOBUTTONS_T : public MGUI::FORM_RADIOBUTTONS {
00162    public:
00163 
00164       //! Constructor.
00165       explicit FORM_RADIOBUTTONS_T (
00166          ): m_pContainer(0), m_pfOnSelection(0) { }
00167 
00168       //! Create control with label from resource lookup.
00169       void Create (
00170          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
00171          _CT *pContainer,                       //!< Pointer to callback container class
00172          void (_CT::*pfOnSelection)(),          //! Callback function pointer
00173          const MGUI::LISTITEMDEF *buttons = 0,  //!< Initial button set, 0 for none
00174          MGUI::LAYOUT_ORIENTATION orientation = MGUI::LAYOUT_ORIENTATION_Vertical,
00175          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_FixedSize,
00176          int ChildSpacing = 4                   //!< Spacing between children
00177          ) {
00178          m_pContainer = pContainer;
00179          m_pfOnSelection = pfOnSelection;
00180          FORM_RADIOBUTTONS::Create(ParentPane,buttons,orientation,sizealign,ChildSpacing);
00181          }
00182 
00183    private:
00184       #ifndef GENERATING_DOXYGEN_OUTPUT
00185       _CT *m_pContainer;
00186       void (_CT::*m_pfOnSelection)();
00187 
00188       virtual void OnSelection (
00189          ) { (m_pContainer->*m_pfOnSelection)(); }
00190       #endif // GENERATING_DOXYGEN_OUTPUT
00191    };
00192 
00193 
00194 //===================================================================================================================
00195 
00196 }  // End namespace MGUI
00197 
00198 #endif   // INC_MGUI_FORMRBTN_H

Generated on Thu Aug 12 06:18:29 2004 for TNTsdk by doxygen 1.3.4-20031026