00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "elements/CEGUIScrolledContainer.h"
00025
00026
00027 namespace CEGUI
00028 {
00029
00031
00032 const String ScrolledContainer::WidgetTypeName("ScrolledContainer");
00033
00034 const String ScrolledContainer::EventNamespace("ScrolledContainer");
00035 const String ScrolledContainer::EventContentChanged("ContentChanged");
00036 const String ScrolledContainer::EventAutoSizeSettingChanged("AutoSizeSettingChanged");
00037
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
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
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
00102 if (childCount != 0)
00103 {
00104 Window* wnd = getChildAtIdx(0);
00105 Rect extents(wnd->getAbsoluteRect());
00106
00107
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
00158 WindowEventArgs args(this);
00159 onContentChanged(args);
00160 return true;
00161 }
00162
00163 bool ScrolledContainer::handleChildMoved(const EventArgs& e)
00164 {
00165
00166 WindowEventArgs args(this);
00167 onContentChanged(args);
00168 return true;
00169 }
00170
00171 Rect ScrolledContainer::getUnclippedInnerRect(void) const
00172 {
00173
00174
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
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
00193 WindowEventArgs args(this);
00194 onContentChanged(args);
00195 }
00196
00197 void ScrolledContainer::onChildRemoved(WindowEventArgs& e)
00198 {
00199 Window::onChildRemoved(e);
00200
00201
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
00210 WindowEventArgs args(this);
00211 onContentChanged(args);
00212 }
00213
00214 void ScrolledContainer::onParentSized(WindowEventArgs& e)
00215 {
00216 Window::onParentSized(e);
00217
00218
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 }