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

Generated on Tue Dec 14 13:18:17 2004 for TNTsdk by  doxygen 1.3.8-20040913