gui/widgets/scrollbar_container_private.hpp

Go to the documentation of this file.
00001 /* $Id: scrollbar_container_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_SCROLLBAR_CONTAINER_PRIVATE_HPP_INCLUDED
00017 #define GUI_WIDGETS_SCROLLBAR_CONTAINER_PRIVATE_HPP_INCLUDED
00018 
00019 #include "gui/widgets/scrollbar_container.hpp"
00020 
00021 #include "utils/const_clone.tpp"
00022 
00023 /**
00024  * @file
00025  * Helper for header for the scrollbar_container.
00026  *
00027  * @note This file should only be included by scrollbar_container.cpp.
00028  *
00029  * This file is being used for a small experiment in which some private
00030  * functions of tscrollbar_container are no longer in tscrollbar_container
00031  * but moved in a friend class with static functions. The goal is to have
00032  * less header recompilations, when there's a need to add or remove a private
00033  * function.  Also non-trivial functions like 'const foo& bar() const' and
00034  * 'foo& bar()' are wrapped in a template to avoid code duplication (for
00035  * typing not for the binary) to make maintenance easier.
00036  */
00037 
00038 namespace gui2 {
00039 
00040 /**
00041  * Helper to implement private functions without modifying the header.
00042  *
00043  * The class is a helper to avoid recompilation and only has static
00044  * functions.
00045  */
00046 struct tscrollbar_container_implementation
00047 {
00048     /**
00049      * Implementation for the wrappers for
00050      * [const] twidget* tscrollbar_container::find_at(
00051      * const tpoint&, const bool) [const].
00052      *
00053      * @tparam W                  twidget or const twidget.
00054      */
00055     template<class W>
00056     static W* find_at(
00057             typename utils::tconst_clone<tscrollbar_container, W>::reference
00058                 scrollbar_container,
00059             const tpoint& coordinate, const bool must_be_active)
00060     {
00061 
00062         assert(scrollbar_container.content_
00063                 && scrollbar_container.content_grid_);
00064 
00065         W* result = scrollbar_container.tcontainer_
                ::find_at(coordinate, must_be_active);
00066 
00067         if(result == scrollbar_container.content_) {
00068             return scrollbar_container.content_grid_->
00069                     find_at(coordinate, must_be_active);
00070         }
00071 
00072         return result;
00073     }
00074 
00075     /**
00076      * Implementation for the wrappers for
00077      * [const] twidget* tscrollbar_container::find(
00078      * const std::string&, const bool) [const].
00079      *
00080      * @tparam W                  twidget or const twidget.
00081      */
00082     template<class W>
00083     static W* find(
00084             typename utils::tconst_clone<tscrollbar_container, W>::reference
00085                 scrollbar_container,
00086             const std::string& id, const bool must_be_active)
00087     {
00088         // Inherited.
00089         W* result = scrollbar_container.tcontainer_
                ::find(id, must_be_active);
00090 
00091         // Can be called before finalize so test instead of assert for the grid.
00092         if(!result && scrollbar_container.content_grid_) {
00093             result = scrollbar_container.
00094                 content_grid_->find(id, must_be_active);
00095         }
00096 
00097         return result;
00098     }
00099 };
00100 
00101 } // namespace gui2
00102 
00103 #endif
00104 
00105 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

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