Back to index

nux  3.0.0
Area.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 BASEOBJECT_H
00024 #define BASEOBJECT_H
00025 
00026 #include <sigc++/sigc++.h>
00027 #include "NuxCore/InitiallyUnownedObject.h"
00028 #include "NuxGraphics/Events.h"
00029 #include "Utils.h"
00030 #include "WidgetMetrics.h"
00031 
00032 namespace nux
00033 {
00034   class WindowThread;
00035   class GraphicsEngine;
00036 
00037 // In a Horizontal/Vertical Layout, the following enum have the respective meanings:
00038 // eFull: the object has the full height/width of the parent layout(minus margins)
00039 // ePercentage: the object has a height/width that is a percentage of the parent layout(minus margins)
00040 // eFix: the object has a fixed height/width
00041 
00042 // Another way to see it
00043 // eFix = The minor dimension of the object will remain what it is. But the positioning in the
00044 //        minor dimension inside the layout can be controlled with MinorDimensionPosition.
00045 // eFull = The minor dimension of the object will take the entire size that is offered by the parent layout.
00046 //         MinorDimensionPosition has no effect if MinorDimensionSize = eFull
00047 // eContent = The minor dimension of the object will be set to 1 by its parent and later on, the minor dimension will be
00048 //         resized larger by the children of the element if necessary.
00049 //
00050 
00051 
00052   typedef enum
00053   {
00054     MINOR_SIZE_FULL,
00055     MINOR_SIZE_PERCENTAGE,
00056     MINOR_SIZE_FIX,
00057     MINOR_SIZE_MATCHCONTENT,
00058     eFull = MINOR_SIZE_FULL,                  
00059     ePercentage = MINOR_SIZE_PERCENTAGE,      
00060     eFix  = MINOR_SIZE_FIX,                   
00061     eMatchContent = MINOR_SIZE_MATCHCONTENT,  
00062   } MinorDimensionSize;
00063 
00065   typedef enum
00066   {
00067     MINOR_POSITION_START,         
00068     MINOR_POSITION_CENTER,        
00069     MINOR_POSITION_END,           
00070     MINOR_POSITION_TOP = MINOR_POSITION_START,   
00071     MINOR_POSITION_LEFT = MINOR_POSITION_START,  
00072     MINOR_POSITION_BOTTOM = MINOR_POSITION_END,  
00073     MINOR_POSITION_RIGHT = MINOR_POSITION_END,   
00074 
00075     eAbove = MINOR_POSITION_TOP,      
00076     eBelow = MINOR_POSITION_BOTTOM,   
00077     eLeft = MINOR_POSITION_LEFT,      
00078     eRight = MINOR_POSITION_RIGHT,    
00079     eCenter = MINOR_POSITION_CENTER,  
00080   } MinorDimensionPosition;
00081 
00083 
00087   typedef enum
00088   {
00089     MAJOR_POSITION_CENTER,   
00090     MAJOR_POSITION_START,    
00091     MAJOR_POSITION_END,      
00092     MAJOR_POSITION_SPREAD,   
00093 
00094     MAJOR_POSITION_TOP = MAJOR_POSITION_START,    
00095     MAJOR_POSITION_BOTTOM = MAJOR_POSITION_END,   
00096     MAJOR_POSITION_LEFT = MAJOR_POSITION_START,   
00097     MAJOR_POSITION_RIGHT = MAJOR_POSITION_END,    
00098 
00099 
00100     eStackTop = MAJOR_POSITION_TOP,         
00101     eStackBottom = MAJOR_POSITION_BOTTOM,   
00102     eStackLeft = MAJOR_POSITION_LEFT,       
00103     eStackRight = MAJOR_POSITION_RIGHT,     
00104     eStackCenter = MAJOR_POSITION_CENTER,   
00105     eStackExpand = MAJOR_POSITION_SPREAD,   
00106   }  LayoutContentDistribution;
00107 
00109 
00112   typedef enum
00113   {
00114     SIZE_EQUAL_WIDTH     = (1L),
00115     SIZE_EQUAL_HEIGHT    = (1L) << 1,
00116     SIZE_SMALLER_WIDTH   = (1L) << 2,
00117     SIZE_SMALLER_HEIGHT  = (1L) << 3,
00118     SIZE_LARGER_WIDTH    = (1L) << 4,
00119     SIZE_LARGER_HEIGHT   = (1L) << 5,
00120     SIZE_FORCE_COMPLY    = (1L) << 6,
00121 
00122     eCompliantWidth     = SIZE_EQUAL_WIDTH,     
00123     eCompliantHeight    = SIZE_EQUAL_HEIGHT,    
00124     eSmallerWidth       = SIZE_SMALLER_WIDTH,   
00125     eSmallerHeight      = SIZE_SMALLER_HEIGHT,  
00126     eLargerWidth        = SIZE_LARGER_WIDTH,    
00127     eLargerHeight       = SIZE_LARGER_HEIGHT,   
00128     eForceComply        = SIZE_FORCE_COMPLY,    
00129   } SizeCompliance;
00130 
00131   enum KeyNavDirection
00132   {
00133     KEY_NAV_NONE,
00134     KEY_NAV_UP,
00135     KEY_NAV_DOWN,
00136     KEY_NAV_RIGHT,
00137     KEY_NAV_LEFT,
00138     KEY_NAV_TAB_NEXT,
00139     KEY_NAV_TAB_PREVIOUS,
00140     KEY_NAV_ENTER,
00141   };
00142 
00143   class Layout;
00144   class View;
00145   class Area;
00146 
00147   class Area: public InitiallyUnownedObject
00148   {
00149     NUX_DECLARE_OBJECT_TYPE(Area, InitiallyUnownedObject);
00150   public:
00151     Area(NUX_FILE_LINE_DECL);
00152     virtual ~Area();
00153 
00154     int GetBaseX() const;
00155     int GetBaseY() const;
00156     int GetBaseWidth() const;
00157     int GetBaseHeight() const;
00158     void SetBaseX(int x);
00159     void SetBaseY(int y);
00160     void SetBaseXY(int x, int y);
00161     void SetBaseWidth(int w);
00162     void SetBaseHeight(int h);
00163 
00165     /*
00166         Set the size of the object.
00167         The size is adjusted to respect the min and max size policy
00168         \sa SetWidth(), SetHeight(), SetMinimumSize(), SetMaximumSize().
00169     */
00170     virtual void SetBaseSize(int w, int h);
00171 
00172     virtual void SetMinimumSize(int w, int h);
00173     virtual void SetMaximumSize(int w, int h);
00174     virtual void SetMinMaxSize(int w, int h);
00175 
00176     virtual void SetMinimumWidth(int w);
00177     virtual void SetMaximumWidth(int w);
00178     virtual void SetMinimumHeight(int h);
00179     virtual void SetMaximumHeight(int h);
00180 
00181     virtual int GetMinimumWidth() const;
00182     virtual int GetMaximumWidth() const;
00183     virtual int GetMinimumHeight() const;
00184     virtual int GetMaximumHeight() const;
00185 
00186     virtual void ApplyMinWidth();
00187     virtual void ApplyMinHeight();
00188     virtual void ApplyMaxWidth();
00189     virtual void ApplyMaxHeight();
00190 
00191     virtual Size GetMinimumSize() const;
00192     virtual Size GetMaximumSize() const;
00193 
00195 
00199     Geometry const& GetGeometry() const;
00200 
00202 
00211     void SetGeometry(int x, int y, int w, int h);
00212 
00214 
00221     void SetGeometry(const Geometry &geo);
00222 
00223     void IncreaseSize(int x, int y);
00224 
00225     void SetBaseString(const char *Caption);
00226     const NString &GetBaseString() const;
00227 
00229     Area* GetToplevel();
00230 
00232 
00238     Area* GetRootParent();
00239 
00241 
00244     Area* GetTopLevelViewWindow();
00245 
00247 
00250     bool HasTopLevelParent();
00251 
00253 
00257     bool IsChildOf(Area* parent);
00258 
00267     bool TestMousePointerInclusion(const Point& mouse_position, NuxEventType event_type);
00268 
00279     bool TestMousePointerInclusionFilterMouseWheel(const Point& mouse_position, NuxEventType event);
00280 
00282 
00287     bool IsMousePointerInside() const;
00288 
00289     virtual long ComputeContentSize();
00290     virtual void ComputeContentPosition(float offsetX, float offsetY);
00291 
00292     virtual bool IsArea() const;
00293     virtual bool IsInputArea() const;
00294     virtual bool IsView() const;
00295     virtual bool IsLayout() const;
00296     virtual bool IsSpaceLayout() const;
00297     virtual bool IsViewWindow() const;
00298 
00299     Area * GetParentObject() const;
00300 
00302 
00306     void SetVisible(bool visible);
00307 
00309 
00313     bool IsVisible();
00314 
00316     void SetSensitive(bool);
00317 
00319 
00329     void SetInputEventSensitivity(bool sensitive);
00330 
00332     bool IsSensitive() const;
00333 
00335 
00339     bool GetInputEventSensitivity() const;
00340 
00341     sigc::signal<void, Area*> ChildFocusChanged; // sends parent + child
00342 
00349     sigc::signal<void, Area*, bool, KeyNavDirection> key_nav_focus_change;
00350 
00354     sigc::signal<void, Area*> key_nav_focus_activate;
00355 
00357 
00360     void QueueRelayout();
00361 
00363 
00369     virtual unsigned int GetScaleFactor();
00370 
00372 
00378     virtual void SetScaleFactor(unsigned int sf);
00379 
00380     virtual MinorDimensionPosition GetPositioning();
00381     virtual void SetPositioning(MinorDimensionPosition p);
00382 
00383     virtual MinorDimensionSize GetExtend();
00384     virtual void SetExtend(MinorDimensionSize ext);
00385 
00386     virtual float GetPercentage();
00387     virtual void SetPercentage(float f);
00388     virtual bool IsLayoutDone();
00389     virtual void SetLayoutDone(bool b);
00390 
00391     void Set2DMatrix(const Matrix4 &mat);
00392     void Set2DTranslation(float tx, float ty, float tz);
00393     Matrix4 Get2DMatrix() const;
00394 
00395     Matrix4 Get3DMatrix() const;
00396     bool Is3DArea() const;
00397 
00399 
00406     virtual Geometry GetAbsoluteGeometry() const;
00407 
00409     int GetAbsoluteX() const;
00410     
00412     int GetAbsoluteY() const;
00413     
00415 
00418     int GetAbsoluteWidth() const;
00419     
00421 
00424     int GetAbsoluteHeight() const;
00425 
00427 
00431     virtual Geometry GetRootGeometry() const;
00432 
00434     int GetRootX() const;
00435 
00437     int GetRootY() const;
00438 
00440 
00443     int GetRootWidth() const;
00444 
00446 
00449     int GetRootHeight() const;
00450 
00451     sigc::signal<void, int, int, int, int> OnResize; 
00452     sigc::signal<void, Area *, bool> OnVisibleChanged;
00453     sigc::signal<void, Area *, bool> OnSensitiveChanged;
00454 
00459     sigc::signal<void, Area *, Geometry&> OnGeometryChanged;
00460 
00476     virtual bool SetParentObject(Area *parent);
00477 
00479 
00485     virtual void UnParentObject();
00486 
00492     virtual Area* FindAreaUnderMouse(const Point& mouse_position, NuxEventType event_type);
00493 
00494 
00495     virtual Area* FindKeyFocusArea(unsigned int key_symbol,
00496         unsigned long x11_key_code,
00497         unsigned long special_keys_state);
00498 
00503     void SetPathToKeyFocusArea();
00504 
00508     void ResetDownwardPathToKeyFocusArea();
00509 
00514     void ResetUpwardPathToKeyFocusArea();
00515 
00517 
00526     virtual bool InspectKeyEvent(unsigned int event_type,
00527       unsigned int keysym,
00528       const char* character);
00529 
00530     virtual Area* KeyNavIteration(KeyNavDirection direction);
00531 
00532     bool HasKeyFocus() const;
00533 
00535 
00543     void SetReconfigureParentLayoutOnGeometryChange(bool reconfigure_parent_layout);
00544 
00546 
00549     bool ReconfigureParentLayoutOnGeometryChange();
00550 
00552 
00555     void SetAcceptKeyboardEvent(bool accept_key_event);
00556 
00558 
00561     bool AcceptKeyboardEvent() const;
00562 
00564 
00567     void SetAcceptMouseWheelEvent(bool accept_mouse_wheel_event);
00568 
00570 
00573     bool AcceptMouseWheelEvent() const;
00574 
00575   protected:
00576     /*
00577         This function is reimplemented in Layout as it need to perform some special operations.
00578         It does nothing for Area and View classes.
00579     */
00580     //virtual void RemoveChildObject(smptr(Area));
00581 
00586     virtual void GeometryChangePending() {}
00587     
00592     virtual void GeometryChanged() {}
00593 
00595     /*
00596         When an object size changes, it is necessary for its parent structure to initiate a layout
00597         re computation in order preserve the layout structure defined by the user through the API.
00598     */
00599     virtual void RequestBottomUpLayoutComputation(Area *bo_initiator);
00600 
00602     void InnerGetAbsoluteGeometry(Geometry &geometry);
00603 
00605     void InnerGetRootGeometry(Geometry &geometry);
00606 
00607     bool on_geometry_change_reconfigure_parent_layout_;
00608 
00610     bool has_key_focus_;
00611 
00612     void SetNextObjectToKeyFocusArea(Area*);
00613 
00615 
00621     Area* GetNextObjectToKeyFocusArea();
00622 
00624     Area* next_object_to_key_focus_area_;
00625 
00626   private:
00627     void ReconfigureParentLayout(Area *child = 0);
00628     void CheckMinSize();
00629     void CheckMaxSize();
00630 
00631 
00632     Geometry                geometry_;        
00633 
00635     /*
00636         An object of the class Area may have another of the class Layout as Parent.
00637         An object of the class View may have an object of the class Layout as parent.
00638         An object of the class Layout may have a parent of the class Layout or View as parent.
00639         A Area cannot have children(that may change later).
00640     */
00641     Area*             parent_area_;
00642 
00643     bool              visible_;       
00644     bool              sensitive_;     
00645     bool              view_enabled_;  
00646 
00647     NString                 _base_string;     
00648 
00649     Size                    min_size_;        
00650     Size                    max_size_;        
00651 
00652     // Parameters used in layouts
00653     unsigned int            scale_factor_;          
00654     MinorDimensionPosition  minor_axis_position_;   
00655     MinorDimensionSize      minor_axis_size_;       
00656     float                   minor_axis_size_scale_; 
00657     bool                    layout_done_;           
00658 
00659 
00660     Matrix4                 _2d_xform;        
00661     Matrix4                 _3d_xform;        
00662     bool                    _3d_area;         
00663 
00664     std::list<Area*>        _children_list;
00665 
00666     bool                    accept_mouse_wheel_event_;
00667     bool                    accept_keyboard_event_;
00668 
00669     WindowThread*           window_thread_;
00670 
00671     friend class Layout;
00672     friend class View;
00673     friend class WindowThread;
00674     friend class HSplitter;
00675     friend class VSplitter;
00676     friend class WindowCompositor;
00677   };
00678 
00679 }
00680 #endif // BASEOBJECT_H
00681