Back to index

nux  3.0.0
Layout.h
Go to the documentation of this file.
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 namespace nux
00027 {
00028 
00029 #define DEBUG_LAYOUT 0
00030 #define DEBUG_LAYOUT_COMPUTATION 0
00031 
00032   typedef enum
00033   {
00034     NUX_LAYOUT_BEGIN = 0,
00035     NUX_LAYOUT_END = 0x7fffffff
00036   } LayoutPosition;
00037 
00038   class Layout: public Area
00039   {
00040     NUX_DECLARE_OBJECT_TYPE(Layout, Area);
00041   public:
00042     Layout(NUX_FILE_LINE_PROTO);
00043     virtual ~Layout();
00044 
00045     virtual void AddLayout(Layout *, unsigned int stretchFactor = 1, MinorDimensionPosition = eAbove, MinorDimensionSize extend = eFull, float percentage = 100.0f, LayoutPosition = NUX_LAYOUT_END);
00046 
00048 
00071     virtual void AddView(Area *baseobject, unsigned int stretchFactor = 1, MinorDimensionPosition positioning = eAbove, MinorDimensionSize extend = eFull, float percentage = 100.0f, LayoutPosition index = NUX_LAYOUT_END);
00072     virtual void AddSpace(unsigned int width, unsigned int stretchFactor = 0, LayoutPosition index = NUX_LAYOUT_END);
00073 
00074     virtual void Clear();
00075 
00077 
00083     void SetLeftAndRightPadding(int padding);
00084 
00086 
00093     void SetLeftAndRightPadding(int left, int right);
00094 
00096 
00102     void SetTopAndBottomPadding(int padding);
00103 
00104 
00106 
00113     void SetTopAndBottomPadding(int top, int bottom);
00114 
00116 
00123     void SetPadding(int top_bottom_padding, int left_right_padding);
00124 
00125     virtual unsigned int GetMaxStretchFactor();
00126     unsigned int GetMinStretchFactor();
00127     unsigned int GetNumStretchFactor(unsigned int sf);
00128 
00129     int GetContentWidth() const
00130     {
00131       return m_contentWidth;
00132     };
00133 
00134     int GetContentHeight() const
00135     {
00136       return m_contentHeight;
00137     };
00138 
00139 
00141     void SetHorizontalExternalMargin(int m);
00142 
00144     void SetVerticalExternalMargin(int m);
00145 
00147 
00156     void SetPadding(int top, int right, int bottom, int left);
00157 
00159 
00165     void SetPadding(int padding);
00166 
00167     int GetLeftPadding() const;
00168     int GetRightPadding() const;
00169     int GetTopPadding() const;
00170     int GetBottomPadding() const;
00171 
00172   public:
00173 
00174     virtual void GetCompositeList(std::list<Area *> *ViewList)
00175     {
00176 
00177     }
00178     virtual void Draw() {}
00179 
00180     void DoneRedraw();
00181 
00182     bool SearchInAllSubNodes(Area *bo);
00183     bool SearchInFirstSubNodes(Area *bo);
00184 
00185     Area* FindAreaUnderMouse(const Point& mouse_position, NuxEventType event_type);
00186 
00188 
00196     virtual void ProcessDraw(GraphicsEngine &graphics_engine, bool force_draw);
00197 
00199 
00204     virtual void QueueDraw();
00205 
00207 
00210     bool IsQueuedForDraw();
00211 
00213 
00220     virtual void SetContentDistribution(LayoutContentDistribution stacking_order);
00221     virtual LayoutContentDistribution GetContentDistribution();
00222 
00223     virtual bool FindWidget(Area *WidgetObject) const;
00224     virtual bool IsEmpty() const;
00225     /*
00226         This function is reimplemented in Layout and View classes  they need to perform some special operations.
00227         It does nothing for Area classes(this class cannot have children).
00228     */
00229     virtual void RemoveChildObject(Area *);
00230 
00232     /*
00233         When an object size changes, it is necessary for its parent structure to initiate a layout
00234         re computation in order preserve the layout structure defined by the user through the API.
00235     */
00236     virtual void RequestBottomUpLayoutComputation(Area *bo_initiator);
00237 
00238     std::list<Area *>& GetChildren()
00239     {
00240       return _layout_element_list;
00241     }
00242 
00243     virtual void ChildViewQueuedDraw(View *view);
00244     virtual void ChildLayoutQueuedDraw(Layout *layout);
00245     virtual void ChildLayoutChildQueuedDraw(Area *area);
00246 
00247     sigc::signal<void, Layout*> OnQueueDraw;  
00248     sigc::signal<void, Area*>   OnChildQueueDraw;
00249     sigc::signal<void, Layout*, Area*> ViewAdded;
00250     sigc::signal<void, Layout*, Area*> ViewRemoved;
00251 
00252   protected:
00253     virtual bool AcceptKeyNavFocus();
00254     
00255     bool _queued_draw; //<! The rendering of the layout needs to be refreshed.
00256 
00257     Size m_ContentSize;
00258     int m_contentWidth;
00259     int m_contentHeight;
00260 
00261     // Apply only to layout element. This is the width and height computed while sizing the child element.
00262     int m_fittingWidth;
00263     int m_fittingHeight;
00264 
00265     //int m_h_in_margin;
00266     //int m_v_in_margin;
00267 
00268     int space_between_children_;
00269     int top_padding_;
00270     int bottom_padding_;
00271     int left_padding_;
00272     int right_padding_;
00273 
00274     std::list<Area *> _layout_element_list;
00275 
00276     NString m_name;
00277 
00278     LayoutContentDistribution m_ContentStacking;
00279   };
00280 
00281 
00282 // The Space layout is a layout object that is used to create fixed or re-sizable empty space.
00283   class SpaceLayout: public Layout
00284   {
00285     NUX_DECLARE_OBJECT_TYPE(SpaceLayout, Layout);
00286   public:
00287     SpaceLayout(NUX_FILE_LINE_PROTO)
00288       : Layout(NUX_FILE_LINE_PARAM)
00289     {
00290     };
00291 
00292     SpaceLayout(int minWidth, int maxWidth, int minHeight, int maxHeight, NUX_FILE_LINE_PROTO)
00293       : Layout(NUX_FILE_LINE_PARAM)
00294     {
00295       SetMinimumSize(minWidth, minHeight);
00296       SetMaximumSize(maxWidth, maxHeight);
00297     };
00298 
00299     ~SpaceLayout()
00300     {
00301     };
00302 
00303     virtual bool FindWidget(Area *WidgetObject) const
00304     {
00305       return false;
00306     }
00307     virtual bool IsEmpty() const
00308     {
00309       return true;
00310     }
00311 
00312 
00313     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)
00314     {
00315       // Do not allow a WidgetLayout to encapsulate an object of type layout
00316     }
00317 
00318     virtual void AddView(Area *baseobject, unsigned int stretchFactor = 1, MinorDimensionPosition positioning = eAbove, MinorDimensionSize extend = eFull, float percentage = 100.0f, LayoutPosition index = NUX_LAYOUT_END)
00319     {
00320       // the baseObject is provided via the constructor.
00321     };
00322 
00323     virtual void AddSpace(unsigned int width, unsigned int stretchFactor = 0, LayoutPosition index = NUX_LAYOUT_END)
00324     {
00325       // Do not allow a WidgetLayout to encapsulate an object of type layout
00326     }
00327 
00328     virtual bool CanFocus()
00329     {
00330       return false;
00331     }
00332 
00333     // Begin: Abstract virtual function member(inherited from class Layout) that must be implemented
00334     virtual long ComputeContentSize()
00335     {
00336       return 0;
00337     }
00338     virtual void ComputeContentPosition(float offsetX, float offsetY)
00339     {
00340     }
00341     // End: Abstract virtual function member(inherited from class Layout) that must be implemented
00342 
00343   protected:
00344     Area *Find(long handle);
00345   };
00346 }
00347 
00348 #endif // LAYOUT_H