gui/widgets/container.hpp

Go to the documentation of this file.
00001 /* $Id: container.hpp 54180 2012-05-15 18:24:50Z 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_CONTAINER_HPP_INCLUDED
00017 #define GUI_WIDGETS_CONTAINER_HPP_INCLUDED
00018 
00019 #include "gui/widgets/grid.hpp"
00020 #include "gui/widgets/control.hpp"
00021 #include "gui/auxiliary/window_builder.hpp"
00022 
00023 namespace gui2 {
00024 
00025 /**
00026  * A generic container base class.
00027  *
00028  * A container is a class build with multiple items either acting as one
00029  * widget.
00030  *
00031  */
00032 class tcontainer_ : public tcontrol
00033 {
00034     friend class tdebug_layout_graph;
00035 public:
00036     explicit tcontainer_(const unsigned canvas_count) :
00037         tcontrol(canvas_count),
00038         grid_()
00039     {
00040         grid_.set_parent(this);
00041     }
00042 
00043     /**
00044      * Returns the size of the client area.
00045      *
00046      * The client area is the area available for widgets.
00047      */
00048     virtual SDL_Rect get_client_rect() const { return get_rect(); }
00049 
00050     /***** ***** ***** ***** layout functions ***** ***** ***** *****/
00051 
00052     /** Inherited from tcontrol. */
00053     void layout_init(const bool full_initialization);
00054 
00055     /**
00056      * Tries to reduce the width of a container.
00057      *
00058      * @see @ref layout_algorihm for more information.
00059      *
00060      * @param maximum_width       The wanted maximum width.
00061      */
00062     void reduce_width(const unsigned maximum_width);
00063 
00064     /** Inherited from tcontrol. */
00065     void request_reduce_width(const unsigned maximum_width);
00066 
00067     /** Inherited from twidget. */
00068     void demand_reduce_width(const unsigned maximum_width);
00069 
00070     /**
00071      * Tries to reduce the height of a container.
00072      *
00073      * @see @ref layout_algorihm for more information.
00074      *
00075      * @param maximum_height      The wanted maximum height.
00076      */
00077     void reduce_height(const unsigned maximum_height);
00078 
00079     /** Inherited from twidget. */
00080     void request_reduce_height(const unsigned maximum_height);
00081 
00082     /** Inherited from twidget. */
00083     void demand_reduce_height(const unsigned maximum_height);
00084 
00085 private:
00086     /** Inherited from twidget. */
00087     tpoint calculate_best_size() const;
00088 public:
00089 
00090     /** Inherited from twidget. */
00091     bool can_wrap() const { return grid_.can_wrap() || twidget::can_wrap(); }
00092 
00093     /** Inherited from twidget. */
00094     void place(const tpoint& origin, const tpoint& size);
00095 
00096     /***** ***** ***** ***** Inherited ***** ***** ***** *****/
00097 
00098     /** Inherited from twidget.*/
00099     bool has_widget(const twidget* widget) const
00100         { return twidget::has_widget(widget) || grid_.has_widget(widget); }
00101 
00102     /** Inherited from twidget. */
00103     void set_origin(const tpoint& origin);
00104 
00105     /** Inherited from twidget. */
00106     void set_visible_area(const SDL_Rect& area);
00107 
00108     /** Inherited from twidget. */
00109     void impl_draw_children(surface& frame_buffer);
00110     void impl_draw_children(surface& frame_buffer, int x_offset, int y_offset);
00111 
00112 protected:
00113 
00114     /** Inherited from twidget. */
00115     void layout_children();
00116 
00117     /** Inherited from twidget. */
00118     void child_populate_dirty_list(twindow& caller,
00119             const std::vector<twidget*>& call_stack);
00120 
00121 public:
00122 
00123     /** Inherited from tcontrol. */
00124     twidget* find_at(const tpoint& coordinate, const bool must_be_active)
00125         { return grid_.find_at(coordinate, must_be_active); }
00126 
00127     /** Inherited from tcontrol. */
00128     const twidget* find_at(const tpoint& coordinate,
00129             const bool must_be_active) const
00130         { return grid_.find_at(coordinate, must_be_active); }
00131 
00132     /** Inherited from tcontrol.*/
00133     twidget* find(const std::string& id, const bool must_be_active)
00134     {
00135         twidget* result = tcontrol::find(id, must_be_active);
00136         return result ? result : grid_.find(id, must_be_active);
00137     }
00138 
00139     /** Inherited from tcontrol.*/
00140     const twidget* find(const std::string& id, const bool must_be_active) const
00141     {
00142         const twidget* result = tcontrol::find(id, must_be_active);
00143         return result ? result : grid_.find(id, must_be_active);
00144     }
00145 
00146     /** Inherited from tcontrol. */
00147     void set_active(const bool active);
00148 
00149     /** Inherited from tcontrol. */
00150     bool disable_click_dismiss() const;
00151 
00152     /**
00153      * Inherited from twidget.
00154      *
00155      * @todo Implement properly.
00156      */
00157     virtual iterator::twalker_* create_walker() { return NULL; }
00158 
00159     /**
00160      * Initializes and builds the grid.
00161      *
00162      * This function should only be called upon an empty grid. This grid is
00163      * returned by initial_grid();
00164      *
00165      * @param grid_builder        The builder for the grid.
00166      */
00167     void init_grid(const boost::intrusive_ptr<tbuilder_grid>& grid_builder);
00168 
00169     /***** **** ***** ***** wrappers to the grid **** ********* *****/
00170 
00171     tgrid::iterator begin() { return grid_.begin(); }
00172     tgrid::iterator end() { return grid_.end(); }
00173 
00174     unsigned add_row(const unsigned count = 1)
00175         { return grid_.add_row(count); }
00176 
00177     void set_rows(const unsigned rows) { grid_.set_rows(rows); }
00178     unsigned int get_rows() const { return grid_.get_rows(); }
00179 
00180     void set_cols(const unsigned cols) { grid_.set_cols(cols); }
00181     unsigned int get_cols() const { return grid_.get_cols(); }
00182 
00183     void set_rows_cols(const unsigned rows, const unsigned cols)
00184         { grid_.set_rows_cols(rows, cols); }
00185 
00186     void set_child(twidget* widget, const unsigned row,
00187         const unsigned col, const unsigned flags, const unsigned border_size)
00188         { grid_.set_child(widget, row, col, flags, border_size); }
00189 
00190     void set_row_grow_factor(const unsigned row, const unsigned factor)
00191         { grid_.set_row_grow_factor(row, factor); }
00192 
00193     void set_column_grow_factor(const unsigned column, const unsigned factor)
00194         { grid_.set_column_grow_factor(column, factor); }
00195 
00196 public:
00197     /***** ***** ***** setters / getters for members ***** ****** *****/
00198 
00199     // Public due to the fact that window needs to be able to swap the
00200     // children, might be protected again later.
00201     const tgrid& grid() const { return grid_; }
00202     tgrid& grid() { return grid_; }
00203 
00204 private:
00205 
00206     /** The grid which holds the child objects. */
00207     tgrid grid_;
00208 
00209     /**
00210      * Returns the grid to initialize while building.
00211      *
00212      * @todo Evaluate whether this function is overridden if not remove.
00213      */
00214     virtual tgrid& initial_grid() { return grid_; }
00215 
00216     /** Returns the space used by the border. */
00217     virtual tpoint border_space() const { return tpoint(0, 0); }
00218 
00219     /**
00220      * Helper for set_active.
00221      *
00222      * This function should set the control itself active. It's called by
00223      * set_active if the state needs to change. The widget is set to dirty() by
00224      * set_active so we only need to change the state.
00225      */
00226     virtual void set_self_active(const bool active) = 0;
00227 };
00228 
00229 } // namespace gui2
00230 
00231 #endif
00232 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Thu May 24 2012 01:02:43 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs