Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

CEGUIScrolledContainer.cpp

Go to the documentation of this file.
00001 /************************************************************************
00002         filename:       CEGUIScrolledContainer.cpp
00003         created:        1/3/2005
00004         author:         Paul D Turner
00005 *************************************************************************/
00006 /*************************************************************************
00007     Crazy Eddie's GUI System (http://www.cegui.org.uk)
00008     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
00009 
00010     This library is free software; you can redistribute it and/or
00011     modify it under the terms of the GNU Lesser General Public
00012     License as published by the Free Software Foundation; either
00013     version 2.1 of the License, or (at your option) any later version.
00014 
00015     This library is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018     Lesser General Public License for more details.
00019 
00020     You should have received a copy of the GNU Lesser General Public
00021     License along with this library; if not, write to the Free Software
00022     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 *************************************************************************/
00024 #include "elements/CEGUIScrolledContainer.h"
00025 
00026 // Start of CEGUI namespace section
00027 namespace CEGUI
00028 {   
00029     // static data definitions
00031     // Widget type name string
00032     const String ScrolledContainer::WidgetTypeName("ScrolledContainer");
00033     // Event string constants
00034     const String ScrolledContainer::EventNamespace("ScrolledContainer");
00035     const String ScrolledContainer::EventContentChanged("ContentChanged");
00036     const String ScrolledContainer::EventAutoSizeSettingChanged("AutoSizeSettingChanged");
00037     // properties
00038     ScrolledContainerProperties::ContentPaneAutoSized ScrolledContainer::d_autoSizedProperty;
00039     ScrolledContainerProperties::ContentArea          ScrolledContainer::d_contentAreaProperty;
00040     ScrolledContainerProperties::ChildExtentsArea     ScrolledContainer::d_childExtentsAreaProperty;
00042     
00043     ScrolledContainer::ScrolledContainer(const String& type, const String& name) :
00044         Window(type, name),
00045         d_contentArea(0, 0, 0, 0),
00046         d_autosizePane(true)
00047     {
00048         addScrolledContainerEvents();
00049         addScrolledContainerProperties();
00050     }
00051 
00052     ScrolledContainer::~ScrolledContainer(void)
00053     {
00054     }
00055 
00056     bool ScrolledContainer::isContentPaneAutoSized(void) const
00057     {
00058         return d_autosizePane;
00059     }
00060 
00061     void ScrolledContainer::setContentPaneAutoSized(bool setting)
00062     {
00063         if (d_autosizePane != setting)
00064         {
00065             d_autosizePane = setting;
00066 
00067             // Fire events
00068             WindowEventArgs args1(this);
00069             onAutoSizeSettingChanged(args1);
00070         }
00071     }
00072 
00073     const Rect& ScrolledContainer::getContentArea(void) const
00074     {
00075         return d_contentArea;
00076     }
00077 
00078     void ScrolledContainer::setContentArea(const Rect& area)
00079     {
00080         if (!d_autosizePane)
00081         {
00082             d_contentArea = area;
00083             
00084             // Fire event
00085             WindowEventArgs args(this);
00086             onContentChanged(args);
00087        }
00088 
00089     }
00090 
00091     void ScrolledContainer::addScrolledContainerEvents(void)
00092     {
00093         addEvent(EventContentChanged);
00094         addEvent(EventAutoSizeSettingChanged);
00095     }
00096 
00097     Rect ScrolledContainer::getChildExtentsArea(void) const
00098     {
00099         uint childCount = getChildCount();
00100 
00101         // set up initial content area to match first child.
00102         if (childCount != 0)
00103         {
00104             Window* wnd = getChildAtIdx(0);
00105             Rect extents(wnd->getAbsoluteRect());
00106 
00107             // control var starts at 1 since we already dealt with 0 above
00108             for (uint i = 1; i < childCount; ++i)
00109             {
00110                 wnd = getChildAtIdx(i);
00111                 Rect area(wnd->getAbsoluteRect());
00112 
00113                 if (area.d_left < extents.d_left)
00114                     extents.d_left = area.d_left;
00115 
00116                 if (area.d_top < extents.d_top)
00117                     extents.d_top = area.d_top;
00118 
00119                 if (area.d_right > extents.d_right)
00120                     extents.d_right = area.d_right;
00121 
00122                 if (area.d_bottom > extents.d_bottom)
00123                     extents.d_bottom = area.d_bottom;
00124             }
00125 
00126             return extents;
00127         }
00128         else
00129         {
00130             return Rect(0, 0, 0, 0);
00131         }
00132     }
00133 
00134     void ScrolledContainer::onContentChanged(WindowEventArgs& e)
00135     {
00136         if (d_autosizePane)
00137         {
00138             d_contentArea = getChildExtentsArea();
00139         }
00140 
00141         fireEvent(EventContentChanged, e, EventNamespace);
00142     }
00143 
00144     void ScrolledContainer::onAutoSizeSettingChanged(WindowEventArgs& e)
00145     {
00146         fireEvent(EventAutoSizeSettingChanged, e, EventNamespace);
00147 
00148         if (d_autosizePane)
00149         {
00150             WindowEventArgs args(this);
00151             onContentChanged(args);
00152         }
00153     }
00154 
00155     bool ScrolledContainer::handleChildSized(const EventArgs& e)
00156     {
00157         // Fire event that notifies that a child's area has changed.
00158         WindowEventArgs args(this);
00159         onContentChanged(args);
00160         return true;
00161     }
00162 
00163     bool ScrolledContainer::handleChildMoved(const EventArgs& e)
00164     {
00165         // Fire event that notifies that a child's area has changed.
00166         WindowEventArgs args(this);
00167         onContentChanged(args);
00168         return true;
00169     }
00170 
00171     Rect ScrolledContainer::getUnclippedInnerRect(void) const
00172     {
00173         // return inner rect of our parent when possible,
00174         // or of the screen when not.
00175         return d_parent ?
00176             d_parent->getUnclippedInnerRect() :
00177             System::getSingleton().getRenderer()->getRect();
00178     }
00179 
00180     void ScrolledContainer::onChildAdded(WindowEventArgs& e)
00181     {
00182         Window::onChildAdded(e);
00183 
00184         // subscribe to some events on this child
00185         d_eventConnections.insert(std::make_pair(e.window,
00186             e.window->subscribeEvent(Window::EventSized,
00187                 Event::Subscriber(&ScrolledContainer::handleChildSized, this))));
00188         d_eventConnections.insert(std::make_pair(e.window,
00189             e.window->subscribeEvent(Window::EventMoved,
00190                 Event::Subscriber(&ScrolledContainer::handleChildMoved, this))));
00191 
00192         // perform notification.
00193         WindowEventArgs args(this);
00194         onContentChanged(args);
00195     }
00196 
00197     void ScrolledContainer::onChildRemoved(WindowEventArgs& e)
00198     {
00199         Window::onChildRemoved(e);
00200 
00201         // disconnect from events for this window.
00202         ConnectionTracker::iterator conn;
00203         while ((conn = d_eventConnections.find(e.window)) != d_eventConnections.end())
00204         {
00205             conn->second->disconnect();
00206             d_eventConnections.erase(conn);
00207         }
00208 
00209         // perform notification.
00210         WindowEventArgs args(this);
00211         onContentChanged(args);
00212     }
00213 
00214     void ScrolledContainer::onParentSized(WindowEventArgs& e)
00215     {
00216         Window::onParentSized(e);
00217 
00218         // perform notification.
00219         WindowEventArgs args(this);
00220         onContentChanged(args);
00221     }
00222 
00223     void ScrolledContainer::addScrolledContainerProperties(void)
00224     {
00225         addProperty(&d_autoSizedProperty);
00226         addProperty(&d_contentAreaProperty);
00227         addProperty(&d_childExtentsAreaProperty);
00228     }
00229 
00230 } // End of  CEGUI namespace section

Generated on Wed Sep 7 09:56:33 2005 for Crazy Eddies GUI System by  doxygen 1.4.3