gui/widgets/toggle_panel.hpp

Go to the documentation of this file.
00001 /* $Id: toggle_panel.hpp 54007 2012-04-28 19:16:10Z mordante $ */
00002 /*
00003    Copyright (C) 2008 - 2012 by Mark de Wever <koraq@xs4all.nl>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 
00016 #ifndef GUI_WIDGETS_TOGGLE_PANEL_HPP_INCLUDED
00017 #define GUI_WIDGETS_TOGGLE_PANEL_HPP_INCLUDED
00018 
00019 #include "gui/widgets/panel.hpp"
00020 #include "gui/widgets/selectable.hpp"
00021 
00022 namespace gui2 {
00023 
00024 /**
00025  * Class for a toggle button.
00026  *
00027  * Quite some code looks like ttoggle_button maybe we should inherit from that but let's test first.
00028  * the problem is that the toggle_button has an icon we don't want, but maybe look at refactoring later.
00029  * but maybe we should also ditch the icon, not sure however since it's handy for checkboxes...
00030  */
00031 class ttoggle_panel : public tpanel, public tselectable_
00032 {
00033 public:
00034     ttoggle_panel();
00035 
00036     /**
00037      * Sets the members of the child controls.
00038      *
00039      * Sets the members for all controls which have the proper member id. See
00040      * tcontrol::set_members for more info.
00041      *
00042      * @param data                Map with the key value pairs to set the members.
00043      */
00044     void set_child_members(const std::map<std::string /* widget id */, string_map>& data);
00045 
00046     /***** ***** ***** ***** Inherited ***** ***** ***** *****/
00047 
00048     /** Inherited from tcontainer_ */
00049     twidget* find_at(const tpoint& coordinate, const bool must_be_active)
00050     {
00051         /**
00052          * @todo since there is no mouse event nesting (or event nesting at all)
00053          * we need to capture all events. This means items on the panel will
00054          * never receive an event, which gives problems with for example the
00055          * intended button on the addon panel. So we need to chain mouse events
00056          * as well and also add a handled flag for them.
00057          */
00058 
00059         twidget* result = tcontainer_::find_at(coordinate, must_be_active);
00060         return result ? result : tcontrol::find_at(coordinate, must_be_active);
00061     }
00062 
00063     /** Inherited from tcontainer_ */
00064     const twidget* find_at(
00065             const tpoint& coordinate, const bool must_be_active) const
00066     {
00067         const twidget* result =
00068                 tcontainer_::find_at(coordinate, must_be_active);
00069         return result ? result : tcontrol::find_at(coordinate, must_be_active);
00070     }
00071 
00072     /** Inherited from tpanel. */
00073     void set_active(const bool active);
00074 
00075     /** Inherited from tpanel. */
00076     bool get_active() const
00077         { return state_ != DISABLED && state_ != DISABLED_SELECTED; }
00078 
00079     /** Inherited from tpanel. */
00080     unsigned get_state() const { return state_; }
00081 
00082     /**
00083      * Inherited from tpanel.
00084      *
00085      * @todo only due to the fact our definition is slightly different from
00086      * tpanel_definition we need to override this function and do about the same,
00087      * look at a way to 'fix' that.
00088      */
00089     SDL_Rect get_client_rect() const;
00090 
00091     /**
00092      * Inherited from tpanel.
00093      *
00094      * @todo only due to the fact our definition is slightly different from
00095      * tpanel_definition we need to override this function and do about the same,
00096      * look at a way to 'fix' that.
00097      */
00098     tpoint border_space() const;
00099 
00100     /** Inherited from tselectable_ */
00101     bool get_value() const { return state_ >= ENABLED_SELECTED; }
00102 
00103     /** Inherited from tselectable_ */
00104     void set_value(const bool selected);
00105 
00106     /***** ***** ***** setters / getters for members ***** ****** *****/
00107 
00108     void set_retval(const int retval);
00109 
00110     /** Inherited from tselectable_. */
00111     void set_callback_state_change(boost::function<void (twidget*)> callback)
00112         { callback_state_change_ = callback; }
00113 
00114     void set_callback_mouse_left_double_click(boost::function<void (twidget*)> callback)
00115         { callback_mouse_left_double_click_ = callback; }
00116 private:
00117 
00118     /**
00119      * Possible states of the widget.
00120      *
00121      * Note the order of the states must be the same as defined in settings.hpp.
00122      * Also note the internals do assume the order for 'up' and 'down' to be the
00123      * same and also that 'up' is before 'down'. 'up' has no suffix, 'down' has
00124      * the SELECTED suffix.
00125      */
00126     enum tstate {
00127         ENABLED,          DISABLED,          FOCUSSED,
00128         ENABLED_SELECTED, DISABLED_SELECTED, FOCUSSED_SELECTED,
00129         COUNT};
00130 
00131     void set_state(const tstate state);
00132 
00133     /**
00134      * Current state of the widget.
00135      *
00136      * The state of the widget determines what to render and how the widget
00137      * reacts to certain 'events'.
00138      */
00139     tstate state_;
00140 
00141     /**
00142      * The return value of the button.
00143      *
00144      * If this value is not 0 and the button is double clicked it sets the
00145      * retval of the window and the window closes itself.
00146      */
00147     int retval_;
00148 
00149     /** See tselectable_::set_callback_state_change. */
00150     boost::function<void (twidget*)> callback_state_change_;
00151 
00152     /** Mouse left double click callback */
00153     boost::function<void (twidget*)> callback_mouse_left_double_click_;
00154 
00155     /** Inherited from tpanel. */
00156     void impl_draw_background(surface& frame_buffer)
00157     {
00158         // We don't have a fore and background and need to draw depending on
00159         // our state, like a control. So we use the controls drawing method.
00160         tcontrol::impl_draw_background(frame_buffer);
00161     }
00162 
00163     /** Inherited from tpanel. */
00164     void impl_draw_background(surface& frame_buffer, int x_offset, int y_offset)
00165     {
00166         // We don't have a fore and background and need to draw depending on
00167         // our state, like a control. So we use the controls drawing method.
00168         tcontrol::impl_draw_background(frame_buffer, x_offset, y_offset);
00169     }
00170 
00171     /** Inherited from tpanel. */
00172     void impl_draw_foreground(surface& frame_buffer)
00173     {
00174         // We don't have a fore and background and need to draw depending on
00175         // our state, like a control. So we use the controls drawing method.
00176         tcontrol::impl_draw_foreground(frame_buffer);
00177     }
00178 
00179     /** Inherited from tpanel. */
00180     void impl_draw_foreground(surface& frame_buffer, int x_offset, int y_offset)
00181     {
00182         // We don't have a fore and background and need to draw depending on
00183         // our state, like a control. So we use the controls drawing method.
00184         tcontrol::impl_draw_foreground(frame_buffer, x_offset, y_offset);
00185     }
00186 
00187 
00188     /** Inherited from tpanel. */
00189     const std::string& get_control_type() const;
00190 
00191     /***** ***** ***** signal handlers ***** ****** *****/
00192 
00193     void signal_handler_mouse_enter(const event::tevent event, bool& handled);
00194 
00195     void signal_handler_mouse_leave(const event::tevent event, bool& handled);
00196 
00197     void signal_handler_pre_left_button_click(const event::tevent event);
00198 
00199     void signal_handler_left_button_click(
00200             const event::tevent event, bool& handled);
00201 
00202     void signal_handler_left_button_double_click(
00203             const event::tevent event, bool& handled);
00204 };
00205 
00206 } // namespace gui2
00207 
00208 #endif
00209 
00210 
00211 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:02:56 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs