container.hpp

Go to the documentation of this file.
00001 /* $Id: container.hpp 26774 2008-05-22 16:30:51Z mordante $ */
00002 /*
00003    copyright (C) 2008 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 version 2
00008    or at your option any later version.
00009    this program is distributed in the hope that it will be useful,
00010    but without any warranty.
00011 
00012    see the copying file for more details.
00013 */
00014 
00015 #ifndef __GUI_WIDGETS_CONTAINER_HPP_INCLUDED__
00016 #define __GUI_WIDGETS_CONTAINER_HPP_INCLUDED__
00017 
00018 #include "gui/widgets/grid.hpp"
00019 #include "gui/widgets/control.hpp"
00020 
00021 namespace gui2 {
00022 
00023 /**
00024  * A generic container base class.
00025  *
00026  * A container is a class build with multiple items either acting as one 
00027  * widget.
00028  *
00029  */
00030 class tcontainer_ : public tcontrol
00031 {
00032 public:
00033     tcontainer_(const unsigned canvas_count) :
00034         tcontrol(canvas_count)
00035     {
00036         grid_.set_parent(this);
00037     }
00038 
00039     /** Inherited from twidget. */
00040     bool dirty() const { return twidget::dirty() || grid_.dirty(); }
00041 
00042     /** Inherited from tcontrol. */
00043     twidget* find_widget(const tpoint& coordinate, const bool must_be_active) 
00044         { return grid_.find_widget(coordinate, must_be_active); }
00045 
00046     /** Inherited from tcontrol. */
00047     const twidget* find_widget(const tpoint& coordinate, 
00048             const bool must_be_active) const
00049         { return grid_.find_widget(coordinate, must_be_active); }
00050 
00051     /** Inherited from tcontrol.*/
00052     twidget* find_widget(const std::string& id, const bool must_be_active)
00053     { 
00054         twidget* result = tcontrol::find_widget(id, must_be_active);
00055         return result ? result : grid_.find_widget(id, must_be_active); 
00056     }
00057 
00058     /** Inherited from tcontrol.*/
00059     const twidget* find_widget(const std::string& id, const bool must_be_active) const
00060     { 
00061         const twidget* result = tcontrol::find_widget(id, must_be_active);
00062         return result ? result : grid_.find_widget(id, must_be_active); 
00063     }
00064 
00065     /** Inherited from twidget.*/
00066     bool has_widget(const twidget* widget) const 
00067         { return grid_.has_widget(widget); }
00068 
00069     /** 
00070      * Inherited from twidget. 
00071      * 
00072      * Since we can't define a good default behaviour we force the inheriting
00073      * classes to define this function. So inheriting classes act as one widget
00074      * others as a collection of multiple objects.
00075      */
00076     bool has_vertical_scrollbar() const = 0;
00077 
00078     /** Inherited from tcontrol. */
00079     tpoint get_minimum_size() const;
00080 
00081     /** Inherited from tcontrol. */
00082     tpoint get_best_size() const;
00083 
00084     /** Inherited from tcontrol. */
00085     void set_size(const SDL_Rect& rect) 
00086     {   
00087         tcontrol::set_size(rect);
00088         set_client_size(get_client_rect());
00089     }
00090 
00091     /** FIXME see whether needed to be exported. */
00092     void set_client_size(const SDL_Rect& rect) { grid_.set_size(rect); }
00093 
00094     /** Inherited from tcontrol. */
00095     void draw(surface& surface);
00096     
00097     /***** **** wrappers to the grid **** ****/
00098 
00099     tgrid::iterator begin() { return grid_.begin(); }
00100     tgrid::iterator end() { return grid_.end(); }
00101 
00102     unsigned add_row(const unsigned count = 1) 
00103         { return grid_.add_row(count); }
00104 
00105     void set_rows(const unsigned rows) { grid_.set_rows(rows); }
00106     unsigned int get_rows() const { return grid_.get_rows(); }
00107 
00108     void set_cols(const unsigned cols) { grid_.set_cols(cols); }
00109     unsigned int get_cols() const { return grid_.get_cols(); }
00110 
00111     void set_rows_cols(const unsigned rows, const unsigned cols)
00112         { grid_.set_rows_cols(rows, cols); }
00113 
00114     void add_child(twidget* widget, const unsigned row, 
00115         const unsigned col, const unsigned flags, const unsigned border_size)
00116         { grid_.add_child(widget, row, col, flags, border_size); }
00117 
00118     void set_row_grow_factor(const unsigned row, const unsigned factor) 
00119         { grid_.set_row_grow_factor(row, factor); }
00120 
00121     void set_col_grow_factor(const unsigned col, const unsigned factor)
00122         { grid_.set_col_grow_factor(col, factor); }
00123 
00124     virtual SDL_Rect get_client_rect() const { return get_rect(); }
00125 protected:
00126     const tgrid& grid() const { return grid_; }
00127     tgrid& grid() { return grid_; }
00128         
00129 private:
00130 
00131     tgrid grid_;
00132 
00133     //! Returns the space used by the border.
00134     virtual tpoint border_space() const { return tpoint(0, 0); }
00135 };
00136 
00137 } // namespace gui2
00138 
00139 #endif
00140 
00141 

Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs