nux-0.9.48
|
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 "Focusable.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_TOP, 00068 MINOR_POSITION_BOTTOM, 00069 MINOR_POSITION_LEFT, 00070 MINOR_POSITION_RIGHT, 00071 MINOR_POSITION_CENTER, 00072 eAbove = MINOR_POSITION_TOP, 00073 eBelow = MINOR_POSITION_BOTTOM, 00074 eLeft = MINOR_POSITION_LEFT, 00075 eRight = MINOR_POSITION_RIGHT, 00076 eCenter = MINOR_POSITION_CENTER, 00077 } MinorDimensionPosition; 00078 00080 00084 typedef enum 00085 { 00086 MAJOR_POSITION_TOP, 00087 MAJOR_POSITION_BOTTOM, 00088 MAJOR_POSITION_LEFT, 00089 MAJOR_POSITION_RIGHT, 00090 MAJOR_POSITION_CENTER, 00091 MAJOR_POSITION_EXPAND, 00092 00093 eStackTop = MAJOR_POSITION_TOP, 00094 eStackBottom = MAJOR_POSITION_BOTTOM, 00095 eStackLeft = MAJOR_POSITION_LEFT, 00096 eStackRight = MAJOR_POSITION_RIGHT, 00097 eStackCenter = MAJOR_POSITION_CENTER, 00098 eStackExpand = MAJOR_POSITION_EXPAND, 00099 } LayoutContentDistribution; 00100 00102 00105 typedef enum 00106 { 00107 SIZE_EQUAL_WIDTH = (1L), 00108 SIZE_EQUAL_HEIGHT = (1L) << 1, 00109 SIZE_SMALLER_WIDTH = (1L) << 2, 00110 SIZE_SMALLER_HEIGHT = (1L) << 3, 00111 SIZE_LARGER_WIDTH = (1L) << 4, 00112 SIZE_LARGER_HEIGHT = (1L) << 5, 00113 SIZE_FORCE_COMPLY = (1L) << 6, 00114 00115 eCompliantWidth = SIZE_EQUAL_WIDTH, 00116 eCompliantHeight = SIZE_EQUAL_HEIGHT, 00117 eSmallerWidth = SIZE_SMALLER_WIDTH, 00118 eSmallerHeight = SIZE_SMALLER_HEIGHT, 00119 eLargerWidth = SIZE_LARGER_WIDTH, 00120 eLargerHeight = SIZE_LARGER_HEIGHT, 00121 eForceComply = SIZE_FORCE_COMPLY, 00122 } SizeCompliance; 00123 00124 class Layout; 00125 class View; 00126 class Area; 00127 00128 class Area: public InitiallyUnownedObject, public Focusable 00129 { 00130 NUX_DECLARE_OBJECT_TYPE (Area, InitiallyUnownedObject); 00131 public: 00132 class LayoutProperties 00133 { 00134 public: 00135 virtual ~LayoutProperties () 00136 { 00137 00138 } 00139 }; 00140 00141 public: 00142 Area (NUX_FILE_LINE_DECL); 00143 virtual ~Area(); 00144 00145 int GetBaseX() const; 00146 int GetBaseY() const; 00147 int GetBaseWidth() const; 00148 int GetBaseHeight() const; 00149 void SetBaseX(int x); 00150 void SetBaseY(int y); 00151 void SetBaseXY(int x, int y); 00152 void SetBaseWidth(int w); 00153 void SetBaseHeight(int h); 00154 00156 /* 00157 Set the size of the object. 00158 The size is adjusted to respect the min and max size policy 00159 \sa SetWidth(), SetHeight(), SetMinimumSize(), SetMaximumSize(). 00160 */ 00161 void SetBaseSize (int w, int h); 00162 00163 void SetMinimumSize(int w, int h); 00164 void SetMaximumSize(int w, int h); 00165 void SetMinMaxSize(int w, int h); 00166 00167 void SetMinimumWidth(int w); 00168 void SetMaximumWidth(int w); 00169 void SetMinimumHeight(int h); 00170 void SetMaximumHeight(int h); 00171 00172 int GetMinimumWidth() const; 00173 int GetMaximumWidth() const; 00174 int GetMinimumHeight() const; 00175 int GetMaximumHeight() const; 00176 00177 void ApplyMinWidth(); 00178 void ApplyMinHeight(); 00179 void ApplyMaxWidth(); 00180 void ApplyMaxHeight(); 00181 00182 Size GetMinimumSize() const; 00183 Size GetMaximumSize() const; 00184 00186 00190 Geometry GetGeometry() const; 00191 00193 00202 void SetGeometry (int x, int y, int w, int h); 00203 00205 00212 void SetGeometry (const Geometry &geo); 00213 00214 void IncreaseSize (int x, int y); 00215 00216 void SetBaseString (const TCHAR *Caption); 00217 const NString &GetBaseString() const; 00218 00220 00225 Area * GetToplevel (); 00226 00228 00231 Area * GetTopLevelViewWindow (); 00232 00234 00237 bool HasTopLevelParent (); 00238 00239 virtual long ComputeChildLayout (); 00240 virtual void PositionChildLayout (float offsetX, float offsetY); 00241 virtual long ComputeLayout2 (); 00242 virtual void ComputePosition2 (float offsetX, float offsetY); 00243 00244 virtual bool IsArea () const; 00245 virtual bool IsInputArea () const; 00246 virtual bool IsView () const; 00247 virtual bool IsLayout () const; 00248 virtual bool IsSpaceLayout () const; 00249 virtual bool IsViewWindow () const; 00250 00252 00259 void SetLayoutProperties (LayoutProperties *properties); 00260 00262 00266 LayoutProperties * GetLayoutProperties (); 00267 00268 Area * GetParentObject() const; 00269 00271 00275 void SetVisible (bool visible); 00276 00278 00282 bool IsVisible (); 00283 00285 00289 void SetSensitive (bool sensitive); 00290 00292 00296 bool IsSensitive (); 00297 00298 virtual bool DoGetFocused (); 00299 virtual void DoSetFocused (bool focused); 00300 virtual bool DoCanFocus (); 00301 virtual void DoActivateFocus (); 00302 00303 sigc::signal <void, Area *> FocusActivated; 00304 sigc::signal <void, Area *> FocusChanged; 00305 sigc::signal <void, Area*, Area*> ChildFocusChanged; // sends parent + child 00306 00308 00311 void QueueRelayout (); 00312 00313 virtual unsigned int GetStretchFactor(); 00314 virtual void SetStretchFactor (unsigned int sf); 00315 00316 virtual MinorDimensionPosition GetPositioning(); 00317 virtual void SetPositioning (MinorDimensionPosition p); 00318 00319 virtual MinorDimensionSize GetExtend(); 00320 virtual void SetExtend (MinorDimensionSize ext); 00321 00322 virtual float GetPercentage(); 00323 virtual void SetPercentage (float f); 00324 virtual bool IsLayoutDone(); 00325 virtual void SetLayoutDone (bool b); 00326 00327 void Set2DMatrix (const Matrix4 &mat); 00328 void Set2DTranslation (float tx, float ty, float tz); 00329 Matrix4 Get2DMatrix () const; 00330 00331 Matrix4 Get3DMatrix () const; 00332 bool Is3DArea () const; 00333 00335 00342 Geometry GetAbsoluteGeometry () const; 00343 00345 int GetAbsoluteX () const; 00346 00348 int GetAbsoluteY () const; 00349 00351 00354 int GetAbsoluteWidth () const; 00355 00357 00360 int GetAbsoluteHeight () const; 00361 00363 00367 Geometry GetRootGeometry () const; 00368 00370 int GetRootX () const; 00371 00373 int GetRootY () const; 00374 00376 00379 int GetRootWidth () const; 00380 00382 00385 int GetRootHeight () const; 00386 00387 sigc::signal<void, int, int, int, int> OnResize; 00388 sigc::signal<void, Area *, bool> OnVisibleChanged; 00389 sigc::signal<void, Area *, bool> OnSensitiveChanged; 00390 sigc::signal<void, Area *, Geometry&> OnGeometryChanged; 00391 00401 virtual void SetParentObject (Area *); 00402 00404 00410 virtual void UnParentObject (); 00411 00412 protected: 00413 bool _is_focused; 00414 /* 00415 This function is reimplemented in Layout as it need to perform some special operations. 00416 It does nothing for Area and View classes. 00417 */ 00418 //virtual void RemoveChildObject(smptr(Area)); 00419 00420 virtual void GeometryChangePending () {} 00421 virtual void GeometryChanged () {} 00422 00424 /* 00425 When an object size changes, it is necessary for its parent structure to initiate a layout 00426 re computation in order preserve the layout structure defined by the user through the API. 00427 */ 00428 virtual void RequestBottomUpLayoutComputation (Area *bo_initiator); 00429 00431 Geometry InnerGetAbsoluteGeometry (const Geometry &geometry); 00432 00434 Geometry InnerGetRootGeometry (const Geometry &geometry); 00435 00436 // //! Add a "secondary" child to this Area. The 00437 // /*! 00438 // @return True if the child has been added; False otherwise; 00439 // */ 00440 // bool Secondary (Area *child); 00441 00442 private: 00443 void InitiateResizeLayout (Area *child = 0); 00444 void CheckMinSize(); 00445 void CheckMaxSize(); 00446 00447 00448 Geometry _geometry; 00449 00451 /* 00452 An object of the class Area may have another of the class Layout as Parent. 00453 An object of the class View may have an object of the class Layout as parent. 00454 An object of the class Layout may have a parent of the class Layout or View as parent. 00455 A Area cannot have children (that may change later). 00456 */ 00457 Area *_parent_area; 00458 00459 LayoutProperties *_layout_properties; 00460 bool _visible; 00461 bool _sensitive; 00462 00463 NString _base_string; 00464 00465 Size _min_size; 00466 Size _max_size; 00467 00468 unsigned int _stretch_factor; 00469 MinorDimensionPosition _positioning; 00470 MinorDimensionSize _extend; 00471 float _percentage; 00472 bool _layout_done; 00473 00474 00475 Matrix4 _2d_xform; 00476 Matrix4 _3d_xform; 00477 bool _3d_area; 00478 00479 std::list<Area*> _children_list; 00480 00481 friend class Layout; 00482 friend class View; 00483 friend class WindowThread; 00484 friend class HSplitter; 00485 friend class VSplitter; 00486 friend class WindowCompositor; 00487 }; 00488 00489 } 00490 #endif // BASEOBJECT_H 00491