nux-1.14.0
|
00001 /* 00002 * Copyright 2010 Inalogic® Inc. 00003 * 00004 * This program is free software: you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License, as 00006 * published by the Free Software Foundation; either version 2.1 or 3.0 00007 * of the License. 00008 * 00009 * This program is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranties of 00011 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 00012 * PURPOSE. See the applicable version of the GNU Lesser General Public 00013 * License for more details. 00014 * 00015 * You should have received a copy of both the GNU Lesser General Public 00016 * License along with this program. If not, see <http://www.gnu.org/licenses/> 00017 * 00018 * Authored by: Jay Taoko <jaytaoko@inalogic.com> 00019 * 00020 */ 00021 00022 00023 #ifndef LAYOUT_H 00024 #define LAYOUT_H 00025 00026 #include "Focusable.h" 00027 00028 namespace nux 00029 { 00030 00031 #define DEBUG_LAYOUT 0 00032 #define DEBUG_LAYOUT_COMPUTATION 0 00033 00034 typedef enum 00035 { 00036 NUX_LAYOUT_BEGIN = 0, 00037 NUX_LAYOUT_END = 0x7fffffff 00038 } LayoutPosition; 00039 00040 class Layout: public Area 00041 { 00042 NUX_DECLARE_OBJECT_TYPE (Layout, Area); 00043 public: 00044 Layout (NUX_FILE_LINE_PROTO); 00045 virtual ~Layout(); 00046 00047 virtual void AddLayout (Layout *, unsigned int stretchFactor = 1, MinorDimensionPosition = eAbove, MinorDimensionSize extend = eFull, float percentage = 100.0f, LayoutPosition = NUX_LAYOUT_END); 00048 00050 00073 virtual void AddView (Area *baseobject, unsigned int stretchFactor = 1, MinorDimensionPosition positioning = eAbove, MinorDimensionSize extend = eFull, float percentage = 100.0f, LayoutPosition index = NUX_LAYOUT_END); 00074 virtual void AddSpace (unsigned int width, unsigned int stretchFactor = 0, LayoutPosition index = NUX_LAYOUT_END); 00075 00076 virtual void Clear(); 00077 00078 virtual unsigned int GetMaxStretchFactor(); 00079 unsigned int GetMinStretchFactor(); 00080 unsigned int GetNumStretchFactor (unsigned int sf); 00081 00082 int GetContentWidth() const 00083 { 00084 return m_contentWidth; 00085 }; 00086 int GetContentHeight() const 00087 { 00088 return m_contentHeight; 00089 }; 00090 00091 int GetHorizontalInternalMargin() const 00092 { 00093 return m_h_in_margin; 00094 } 00095 int GetHorizontalExternalMargin() const 00096 { 00097 return m_h_out_margin; 00098 } 00099 void SetHorizontalInternalMargin (int m) 00100 { 00101 #if DEBUG_LAYOUT 00102 return; 00103 #endif 00104 m_h_in_margin = m < 0 ? 0 : m; 00105 } 00106 void SetHorizontalExternalMargin (int m) 00107 { 00108 #if DEBUG_LAYOUT 00109 return; 00110 #endif 00111 m_h_out_margin = m < 0 ? 0 : m; 00112 } 00113 00114 int GetVerticalInternalMargin() const 00115 { 00116 return m_v_in_margin; 00117 }; 00118 int GetVerticalExternalMargin() const 00119 { 00120 return m_v_out_margin; 00121 }; 00122 void SetVerticalInternalMargin (int m) 00123 { 00124 #if DEBUG_LAYOUT 00125 return; 00126 #endif 00127 m_v_in_margin = m < 0 ? 0 : m; 00128 } 00129 void SetVerticalExternalMargin (int m) 00130 { 00131 #if DEBUG_LAYOUT 00132 return; 00133 #endif 00134 m_v_out_margin = m < 0 ? 0 : m; 00135 } 00136 00137 public: 00138 00139 virtual void GetCompositeList (std::list<Area *> *ViewList) 00140 { 00141 00142 } 00143 virtual void Draw() {} 00144 00145 void DoneRedraw(); 00146 00147 bool SearchInAllSubNodes (Area *bo); 00148 bool SearchInFirstSubNodes (Area *bo); 00149 00150 // Deprectated. Do not use. 00151 virtual long ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo) {return 0;} 00152 00153 Area* FindAreaUnderMouse(const Point& mouse_position, NuxEventType event_type); 00154 00156 00164 virtual void ProcessDraw (GraphicsEngine &GfxContext, bool force_draw); 00165 00167 00172 virtual void QueueDraw (); 00173 00175 00178 bool IsQueuedForDraw (); 00179 00181 00188 virtual void SetContentDistribution (LayoutContentDistribution stacking_order); 00189 virtual LayoutContentDistribution GetContentDistribution(); 00190 00191 virtual bool FindWidget (Area *WidgetObject) const; 00192 virtual bool IsEmpty() const; 00193 /* 00194 This function is reimplemented in Layout and View classes they need to perform some special operations. 00195 It does nothing for Area classes (this class cannot have children). 00196 */ 00197 virtual void RemoveChildObject (Area *); 00198 00200 /* 00201 When an object size changes, it is necessary for its parent structure to initiate a layout 00202 re computation in order preserve the layout structure defined by the user through the API. 00203 */ 00204 virtual void RequestBottomUpLayoutComputation (Area *bo_initiator); 00205 00206 std::list<Area *>& GetChildren () 00207 { 00208 return _layout_element_list; 00209 } 00210 00211 virtual void ChildViewQueuedDraw (View *view); 00212 virtual void ChildLayoutQueuedDraw (Layout *layout); 00213 virtual void ChildLayoutChildQueuedDraw (Area *area); 00214 00215 sigc::signal<void, Layout*> OnQueueDraw; 00216 sigc::signal<void, Area*> OnChildQueueDraw; 00217 sigc::signal<void, Layout*, Area*> ViewAdded; 00218 sigc::signal<void, Layout*, Area*> ViewRemoved; 00219 00220 virtual void DoSetFocused (bool focused); 00221 virtual bool DoGetFocused (); 00222 virtual bool DoCanFocus (); 00223 virtual void DoActivateFocus (); 00224 00225 bool HasFocusableEntries (); 00226 00227 // this should not be public, but has to be because of nux's object setup 00228 long ProcessFocusEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo); 00229 bool _has_focus_control; 00230 void SetFocusControl (bool focus_control); 00231 bool HasFocusControl (); 00232 bool _ignore_focus; 00233 00234 protected: 00235 Area*GetFocusedChild (); 00236 virtual long DoFocusPrev (IEvent &ievent, long TraverseInfo, long ProcessEventInfo); 00237 virtual long DoFocusNext (IEvent &ievent, long TraverseInfo, long ProcessEventInfo); 00238 virtual long DoFocusUp (IEvent &ievent, long TraverseInfo, long ProcessEventInfo); 00239 virtual long DoFocusDown (IEvent &ievent, long TraverseInfo, long ProcessEventInfo); 00240 virtual long DoFocusLeft (IEvent &ievent, long TraverseInfo, long ProcessEventInfo); 00241 virtual long DoFocusRight (IEvent &ievent, long TraverseInfo, long ProcessEventInfo); 00242 virtual bool FocusFirstChild (); 00243 virtual bool FocusLastChild (); 00244 virtual bool FocusNextChild (Area *child); 00245 virtual bool FocusPreviousChild (Area *child); 00246 void OnChildFocusChanged (/*Area *parent,*/ Area *child); 00247 00248 virtual bool AcceptKeyNavFocus(); 00249 std::map<Area*, sigc::connection> _connection_map; // map our children to connections 00250 00251 bool _queued_draw; //<! The rendering of the layout needs to be refreshed. 00252 00253 Size m_ContentSize; 00254 int m_contentWidth; 00255 int m_contentHeight; 00256 00257 // Apply only to layout element. This is the width and height computed while sizing the child element. 00258 int m_fittingWidth; 00259 int m_fittingHeight; 00260 00261 int m_h_in_margin; 00262 int m_h_out_margin; 00263 int m_v_in_margin; 00264 int m_v_out_margin; 00265 00266 std::list<Area *> _layout_element_list; 00267 00268 NString m_name; 00269 00270 LayoutContentDistribution m_ContentStacking; 00271 00272 long SendEventToArea (Area *area, IEvent &ievent, long TraverseInfo, long ProcessEventInfo); 00273 }; 00274 00275 00276 // The Space layout is a layout object that is used to create fixed or resizable empty space. 00277 class SpaceLayout: public Layout 00278 { 00279 NUX_DECLARE_OBJECT_TYPE (SpaceLayout, Layout); 00280 public: 00281 SpaceLayout(NUX_FILE_LINE_PROTO) 00282 : Layout (NUX_FILE_LINE_PARAM) 00283 { 00284 }; 00285 00286 SpaceLayout (int minWidth, int maxWidth, int minHeight, int maxHeight, NUX_FILE_LINE_PROTO) 00287 : Layout (NUX_FILE_LINE_PARAM) 00288 { 00289 SetMinimumSize (minWidth, minHeight); 00290 SetMaximumSize (maxWidth, maxHeight); 00291 }; 00292 00293 ~SpaceLayout() 00294 { 00295 }; 00296 00297 virtual bool FindWidget (Area *WidgetObject) const 00298 { 00299 return false; 00300 } 00301 virtual bool IsEmpty() const 00302 { 00303 return true; 00304 } 00305 00306 00307 virtual void AddLayout (Layout *, unsigned int stretchFactor = 1, MinorDimensionPosition minor_position = eAbove, MinorDimensionSize minor_size = eFull, float percentage = 100.0f, LayoutPosition index = NUX_LAYOUT_END) 00308 { 00309 // Do not allow a WidgetLayout to encapsulate an object of type layout 00310 } 00311 00312 virtual void AddView (Area *baseobject, unsigned int stretchFactor = 1, MinorDimensionPosition positioning = eAbove, MinorDimensionSize extend = eFull, float percentage = 100.0f, LayoutPosition index = NUX_LAYOUT_END) 00313 { 00314 // the baseObject is provided via the constructor. 00315 }; 00316 00317 virtual void AddSpace (unsigned int width, unsigned int stretchFactor = 0, LayoutPosition index = NUX_LAYOUT_END) 00318 { 00319 // Do not allow a WidgetLayout to encapsulate an object of type layout 00320 } 00321 00322 virtual bool CanFocus () 00323 { 00324 return false; 00325 } 00326 00327 // Begin: Abstract virtual function member (inherited from class Layout) that must be implemented 00328 virtual long ComputeLayout2() 00329 { 00330 return 0; 00331 } 00332 virtual void ComputePosition2 (float offsetX, float offsetY) 00333 { 00334 } 00335 // End: Abstract virtual function member (inherited from class Layout) that must be implemented 00336 00337 protected: 00338 Area *Find (long handle); 00339 }; 00340 00341 } 00342 00343 #endif // LAYOUT_H