nux-0.9.46

Nux/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 #include "Focusable.h"
00027 
00028 namespace nux
00029 {
00030 
00031 #define DEBUG_LAYOUT 0
00032 #define DEBUG_LAYOUT_COMPUTATION 0
00033 
00034   class Layout: public Area
00035   {
00036     NUX_DECLARE_OBJECT_TYPE (Layout, Area);
00037   public:
00038     Layout (NUX_FILE_LINE_PROTO);
00039     virtual ~Layout();
00040 
00041     virtual void AddLayout (Layout *, unsigned int stretchFactor = 1, MinorDimensionPosition = eAbove, MinorDimensionSize extend = eFull, float percentage = 100.0f);
00042 
00044 
00066     virtual void AddView (Area *baseobject, unsigned int stretchFactor = 1, MinorDimensionPosition positioning = eAbove, MinorDimensionSize extend = eFull, float percentage = 100.0f);
00067     virtual void AddSpace (unsigned int width, unsigned int stretchFactor = 0);
00068 
00069     virtual void Clear();
00070 
00071     virtual unsigned int GetMaxStretchFactor();
00072     unsigned int GetMinStretchFactor();
00073     unsigned int GetNumStretchFactor (unsigned int sf);
00074 
00075     int GetContentWidth() const
00076     {
00077       return m_contentWidth;
00078     };
00079     int GetContentHeight() const
00080     {
00081       return m_contentHeight;
00082     };
00083 
00084     int GetHorizontalInternalMargin() const
00085     {
00086       return m_h_in_margin;
00087     }
00088     int GetHorizontalExternalMargin() const
00089     {
00090       return m_h_out_margin;
00091     }
00092     void SetHorizontalInternalMargin (int m)
00093     {
00094 #if DEBUG_LAYOUT
00095       return;
00096 #endif
00097       m_h_in_margin = m < 0 ? 0 : m;
00098     }
00099     void SetHorizontalExternalMargin (int m)
00100     {
00101 #if DEBUG_LAYOUT
00102       return;
00103 #endif
00104       m_h_out_margin = m < 0 ? 0 : m;
00105     }
00106 
00107     int GetVerticalInternalMargin() const
00108     {
00109       return m_v_in_margin;
00110     };
00111     int GetVerticalExternalMargin() const
00112     {
00113       return m_v_out_margin;
00114     };
00115     void SetVerticalInternalMargin (int m)
00116     {
00117 #if DEBUG_LAYOUT
00118       return;
00119 #endif
00120       m_v_in_margin = m < 0 ? 0 : m;
00121     }
00122     void SetVerticalExternalMargin (int m)
00123     {
00124 #if DEBUG_LAYOUT
00125       return;
00126 #endif
00127       m_v_out_margin = m < 0 ? 0 : m;
00128     }
00129 
00130   public:
00131 
00132     virtual bool IsLayout() const
00133     {
00134       return true;
00135     }
00136     virtual bool IsSpaceLayout() const
00137     {
00138       return false;
00139     }
00140 
00141     virtual void GetCompositeList (std::list<Area *> *ViewList)
00142     {
00143 
00144     }
00145     virtual void Draw() {}
00146 
00147     void removeParentLayout();
00148     void DoneRedraw();
00149 
00150     bool SearchInAllSubNodes (Area *bo);
00151     bool SearchInFirstSubNodes (Area *bo);
00152 
00154 
00161     virtual long ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo);
00162 
00164 
00172     virtual void ProcessDraw (GraphicsEngine &GfxContext, bool force_draw);
00173 
00175 
00180     virtual void QueueDraw ();
00181     virtual void NeedRedraw (); 
00182 
00184 
00187     bool IsQueuedForDraw ();
00188 
00190 
00197     virtual void SetContentDistribution (LayoutContentDistribution stacking_order);
00198     virtual LayoutContentDistribution GetContentDistribution();
00199 
00200     virtual bool FindWidget (Area *WidgetObject) const;
00201     virtual bool IsEmpty() const;
00202     /*
00203         This function is reimplemented in Layout and View classes  they need to perform some special operations.
00204         It does nothing for Area classes (this class cannot have children).
00205     */
00206     virtual void RemoveChildObject (Area *);
00207 
00209     /*
00210         When an object size changes, it is necessary for its parent structure to initiate a layout
00211         re computation in order preserve the layout structure defined by the user through the API.
00212     */
00213     virtual void RequestBottomUpLayoutComputation (Area *bo_initiator);
00214 
00215     std::list<Area *>& GetChildren ()
00216     {
00217       return _layout_element_list;
00218     }
00219 
00220     virtual void ChildViewQueuedDraw (View *view);
00221     virtual void ChildLayoutQueuedDraw (Layout *layout);
00222     virtual void ChildLayoutChildQueuedDraw (Area *area);
00223 
00224     sigc::signal<void, Layout*> OnQueueDraw;  
00225     sigc::signal<void, Area*>   OnChildQueueDraw;
00226     sigc::signal<void, Layout*, Area*> ViewAdded;
00227     sigc::signal<void, Layout*, Area*> ViewRemoved;
00228     
00229     virtual void DoSetFocused (bool focused);
00230     virtual bool DoGetFocused ();
00231     virtual bool DoCanFocus ();
00232     virtual void DoActivateFocus ();
00233 
00234     bool HasFocusableEntries ();
00235 
00236     // this should not be public, but has to be because of nux's object setup
00237     long ProcessFocusEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo);
00238     bool _has_focus_control;
00239     void SetFocusControl (bool focus_control);
00240     bool HasFocusControl ();
00241     bool _ignore_focus;
00242 
00243   protected:
00244     Area*GetFocusedChild ();
00245     virtual long DoFocusPrev  (IEvent &ievent, long TraverseInfo, long ProcessEventInfo);
00246     virtual long DoFocusNext  (IEvent &ievent, long TraverseInfo, long ProcessEventInfo);
00247     virtual long DoFocusUp    (IEvent &ievent, long TraverseInfo, long ProcessEventInfo);
00248     virtual long DoFocusDown  (IEvent &ievent, long TraverseInfo, long ProcessEventInfo);
00249     virtual long DoFocusLeft  (IEvent &ievent, long TraverseInfo, long ProcessEventInfo);
00250     virtual long DoFocusRight (IEvent &ievent, long TraverseInfo, long ProcessEventInfo);
00251     virtual bool FocusFirstChild ();
00252     virtual bool FocusLastChild ();
00253     virtual bool FocusNextChild (Area *child);
00254     virtual bool FocusPreviousChild (Area *child);
00255     void OnChildFocusChanged (Area *parent, Area *child);
00256     
00257     std::map<Area*, sigc::connection> _connection_map; // map our children to connections
00258     
00259     bool _queued_draw; //<! The rendering of the layout needs to be refreshed.
00260 
00261     Size m_ContentSize;
00262     int m_contentWidth;
00263     int m_contentHeight;
00264 
00265     // Apply only to layout element. This is the width and height computed while sizing the child element.
00266     int m_fittingWidth;
00267     int m_fittingHeight;
00268 
00269     int m_h_in_margin;
00270     int m_h_out_margin;
00271     int m_v_in_margin;
00272     int m_v_out_margin;
00273 
00274     std::list<Area *> _layout_element_list;
00275 
00276     NString m_name;
00277 
00278     LayoutContentDistribution m_ContentStacking;
00279 
00280     long SendEventToArea (Area *area, IEvent &ievent, long TraverseInfo, long ProcessEventInfo);
00281   };
00282 
00283 
00284 // The Space layout is a layout object that is used to create fixed or resizable empty space.
00285   class SpaceLayout: public Layout
00286   {
00287   public:
00288     SpaceLayout()
00289     {
00290     };
00291 
00292     SpaceLayout (int minWidth, int maxWidth, int minHeight, int maxHeight)
00293     {
00294       SetMinimumSize (minWidth, minHeight);
00295       SetMaximumSize (maxWidth, maxHeight);
00296     };
00297 
00298     ~SpaceLayout()
00299     {
00300     };
00301 
00302     virtual bool FindWidget (Area *WidgetObject) const
00303     {
00304       return false;
00305     }
00306     virtual bool IsEmpty() const
00307     {
00308       return true;
00309     }
00310 
00311     virtual bool IsSpaceLayout() const
00312     {
00313       return true;
00314     }
00315 
00316     virtual void AddLayout (Layout *, unsigned int stretchFactor = 1, MinorDimensionPosition minor_position = eAbove, MinorDimensionSize minor_size = eFull, float percentage = 100.0f)
00317     {
00318       // Do not allow a WidgetLayout to encapsulate an object of type layout
00319     }
00320 
00321     virtual void AddView (Area *baseobject, unsigned int stretchFactor = 1, MinorDimensionPosition positioning = eAbove, MinorDimensionSize extend = eFull, float percentage = 100.0f)
00322     {
00323       // the baseObject is provided via the constructor.
00324     };
00325 
00326     virtual void AddSpace (unsigned int width, unsigned int stretchFactor = 0)
00327     {
00328       // Do not allow a WidgetLayout to encapsulate an object of type layout
00329     }
00330 
00331     virtual bool CanFocus ()
00332     {
00333       return false;
00334     }
00335 
00336     // Begin: Abstract virtual function member (inherited from class Layout) that must be implemented
00337     virtual long ComputeLayout2()
00338     {
00339       return 0;
00340     }
00341     virtual void ComputePosition2 (float offsetX, float offsetY)
00342     {
00343     }
00344     // End: Abstract virtual function member (inherited from class Layout) that must be implemented
00345 
00346   protected:
00347     Area *Find (long handle);
00348   };
00349 
00350 }
00351 
00352 #endif // LAYOUT_H