00001 /* $Id: grid_private.hpp 54259 2012-05-20 14:00:17Z mordante $ */ 00002 /* 00003 Copyright (C) 2009 - 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_GRID_PRIVATE_HPP_INCLUDED 00017 #define GUI_WIDGETS_GRID_PRIVATE_HPP_INCLUDED 00018 00019 /** 00020 * @file 00021 * Helper for header for the grid. 00022 * 00023 * @note This file should only be included by grid.cpp. 00024 * 00025 * This file is being used for a small experiment in which some private 00026 * functions of tgrid are no longer in tgrid but moved in a friend class with 00027 * static functions. The goal is to have less header recompilations, when 00028 * there's a need to add or remove a private function. 00029 * Also non-trivial functions like 'const foo& bar() const' and 'foo& bar()' 00030 * are wrapped in a template to avoid code duplication (for typing not for the 00031 * binary) to make maintenance easier. 00032 */ 00033 00034 #include "gui/widgets/grid.hpp" 00035 00036 #include "foreach.hpp" 00037 #include "utils/const_clone.tpp" 00038 00039 namespace gui2 { 00040 00041 /** 00042 * Helper to implement private functions without modifying the header. 00043 * 00044 * The class is a helper to avoid recompilation and only has static 00045 * functions. 00046 */ 00047 struct tgrid_implementation 00048 { 00049 /** 00050 * Implementation for the wrappers for 00051 * [const] twidget* tgrid::find_at(const tpoint&, const bool) [const]. 00052 * 00053 * @tparam W twidget or const twidget. 00054 */ 00055 template<class W> 00056 static W* find_at(typename utils::tconst_clone<tgrid, W>::reference grid, 00057 const tpoint& coordinate, const bool must_be_active) 00058 { 00059 typedef typename utils::tconst_clone<tgrid::tchild, W>::type hack; 00060 foreach(hack& child, grid.children_) { 00061 00062 W* widget = child.widget(); 00063 if(!widget) { 00064 continue; 00065 } 00066 00067 widget = widget->find_at(coordinate, must_be_active); 00068 if(widget) { 00069 return widget; 00070 } 00071 00072 } 00073 00074 return 0; 00075 } 00076 00077 /** 00078 * Implementation for the wrappers for 00079 * [const] twidget* tgrid::find(const std::string&, 00080 * const bool) [const]. 00081 * 00082 * @tparam W twidget or const twidget. 00083 */ 00084 template<class W> 00085 static W* find(typename utils::tconst_clone<tgrid, W>::reference grid, 00086 const std::string& id, const bool must_be_active) 00087 { 00088 // Inherited. 00089 W* widget = grid.twidget::find(id, must_be_active); 00090 if(widget) { 00091 return widget; 00092 } 00093 00094 typedef typename utils::tconst_clone<tgrid::tchild, W>::type hack; 00095 foreach(hack& child, grid.children_) { 00096 00097 widget = child.widget(); 00098 if(!widget) { 00099 continue; 00100 } 00101 00102 widget = widget->find(id, must_be_active); 00103 if(widget) { 00104 return widget; 00105 } 00106 00107 } 00108 00109 return 0; 00110 } 00111 00112 /** 00113 * Helper function to do the resizing of a row. 00114 * 00115 * @param grid The grid to operate upon. 00116 * @param row The row to resize. 00117 * @param maximum_height The wanted maximum height. 00118 * 00119 * @returns The required row height after resizing. 00120 */ 00121 static unsigned row_request_reduce_height(tgrid& grid, 00122 const unsigned row, const unsigned maximum_height); 00123 00124 /** 00125 * Helper function to do the resizing of a column. 00126 * 00127 * @param grid The grid to operate upon. 00128 * @param column The column to resize. 00129 * @param maximum_width The wanted maximum width. 00130 * 00131 * @returns The required column width after resizing. 00132 */ 00133 static unsigned column_request_reduce_width(tgrid& grid, 00134 const unsigned column, const unsigned maximum_width); 00135 00136 private: 00137 00138 /** 00139 * Helper function to do the resizing of a widget. 00140 * 00141 * @param child The cell whose widget needs to be resized. 00142 * @param maximum_height The wanted maximum height. 00143 */ 00144 static void cell_request_reduce_height(tgrid::tchild& child, 00145 const unsigned maximum_height); 00146 00147 /** 00148 * Helper function to do the resizing of a widget. 00149 * 00150 * @param child The cell whose widget needs to be resized. 00151 * @param maximum_width The wanted maximum width. 00152 */ 00153 static void cell_request_reduce_width(tgrid::tchild& child, 00154 const unsigned maximum_width); 00155 }; 00156 00157 } // namespace gui2 00158 00159 #endif
| Generated by doxygen 1.7.1 on Fri May 25 2012 01:02:59 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |