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 BASEOBJECT_H 00024 #define BASEOBJECT_H 00025 00026 #include <sigc++/sigc++.h> 00027 #include "NuxCore/InitiallyUnownedObject.h" 00028 #include "NuxGraphics/Events.h" 00029 #include "Focusable.h" 00030 #include "Utils.h" 00031 #include "WidgetMetrics.h" 00032 00033 namespace nux 00034 { 00035 class WindowThread; 00036 class GraphicsEngine; 00037 00038 // In a Horizontal/Vertical Layout, the following enum have the respective meanings: 00039 // eFull: the object has the full height/width of the parent layout(minus margins) 00040 // ePercentage: the object has a height/width that is a percentage of the parent layout(minus margins) 00041 // eFix: the object has a fixed height/width 00042 00043 // Another way to see it 00044 // eFix = The minor dimension of the object will remain what it is. But the positioning in the 00045 // minor dimension inside the layout can be controlled with MinorDimensionPosition. 00046 // eFull = The minor dimension of the object will take the entire size that is offered by the parent layout. 00047 // MinorDimensionPosition has no effect if MinorDimensionSize = eFull 00048 // eContent = The minor dimension of the object will be set to 1 by its parent and later on, the minor dimension will be 00049 // resized larger by the children of the element if necessary. 00050 // 00051 00052 00053 typedef enum 00054 { 00055 MINOR_SIZE_FULL, 00056 MINOR_SIZE_PERCENTAGE, 00057 MINOR_SIZE_FIX, 00058 MINOR_SIZE_MATCHCONTENT, 00059 eFull = MINOR_SIZE_FULL, 00060 ePercentage = MINOR_SIZE_PERCENTAGE, 00061 eFix = MINOR_SIZE_FIX, 00062 eMatchContent = MINOR_SIZE_MATCHCONTENT, 00063 } MinorDimensionSize; 00064 00066 typedef enum 00067 { 00068 MINOR_POSITION_TOP, 00069 MINOR_POSITION_BOTTOM, 00070 MINOR_POSITION_LEFT, 00071 MINOR_POSITION_RIGHT, 00072 MINOR_POSITION_CENTER, 00073 eAbove = MINOR_POSITION_TOP, 00074 eBelow = MINOR_POSITION_BOTTOM, 00075 eLeft = MINOR_POSITION_LEFT, 00076 eRight = MINOR_POSITION_RIGHT, 00077 eCenter = MINOR_POSITION_CENTER, 00078 } MinorDimensionPosition; 00079 00081 00085 typedef enum 00086 { 00087 MAJOR_POSITION_TOP, 00088 MAJOR_POSITION_BOTTOM, 00089 MAJOR_POSITION_LEFT, 00090 MAJOR_POSITION_RIGHT, 00091 MAJOR_POSITION_CENTER, 00092 MAJOR_POSITION_EXPAND, 00093 00094 eStackTop = MAJOR_POSITION_TOP, 00095 eStackBottom = MAJOR_POSITION_BOTTOM, 00096 eStackLeft = MAJOR_POSITION_LEFT, 00097 eStackRight = MAJOR_POSITION_RIGHT, 00098 eStackCenter = MAJOR_POSITION_CENTER, 00099 eStackExpand = MAJOR_POSITION_EXPAND, 00100 } LayoutContentDistribution; 00101 00103 00106 typedef enum 00107 { 00108 SIZE_EQUAL_WIDTH = (1L), 00109 SIZE_EQUAL_HEIGHT = (1L) << 1, 00110 SIZE_SMALLER_WIDTH = (1L) << 2, 00111 SIZE_SMALLER_HEIGHT = (1L) << 3, 00112 SIZE_LARGER_WIDTH = (1L) << 4, 00113 SIZE_LARGER_HEIGHT = (1L) << 5, 00114 SIZE_FORCE_COMPLY = (1L) << 6, 00115 00116 eCompliantWidth = SIZE_EQUAL_WIDTH, 00117 eCompliantHeight = SIZE_EQUAL_HEIGHT, 00118 eSmallerWidth = SIZE_SMALLER_WIDTH, 00119 eSmallerHeight = SIZE_SMALLER_HEIGHT, 00120 eLargerWidth = SIZE_LARGER_WIDTH, 00121 eLargerHeight = SIZE_LARGER_HEIGHT, 00122 eForceComply = SIZE_FORCE_COMPLY, 00123 } SizeCompliance; 00124 00125 enum KeyNavDirection 00126 { 00127 KEY_NAV_NONE, 00128 KEY_NAV_UP, 00129 KEY_NAV_DOWN, 00130 KEY_NAV_RIGHT, 00131 KEY_NAV_LEFT, 00132 KEY_NAV_TAB_NEXT, 00133 KEY_NAV_TAB_PREVIOUS, 00134 KEY_NAV_ENTER, 00135 }; 00136 00137 class Layout; 00138 class View; 00139 class Area; 00140 00141 class Area: public InitiallyUnownedObject, public Focusable 00142 { 00143 NUX_DECLARE_OBJECT_TYPE (Area, InitiallyUnownedObject); 00144 public: 00145 class LayoutProperties 00146 { 00147 public: 00148 virtual ~LayoutProperties () 00149 { 00150 00151 } 00152 }; 00153 00154 public: 00155 Area (NUX_FILE_LINE_DECL); 00156 virtual ~Area(); 00157 00158 int GetBaseX() const; 00159 int GetBaseY() const; 00160 int GetBaseWidth() const; 00161 int GetBaseHeight() const; 00162 void SetBaseX(int x); 00163 void SetBaseY(int y); 00164 void SetBaseXY(int x, int y); 00165 void SetBaseWidth(int w); 00166 void SetBaseHeight(int h); 00167 00169 /* 00170 Set the size of the object. 00171 The size is adjusted to respect the min and max size policy 00172 \sa SetWidth(), SetHeight(), SetMinimumSize(), SetMaximumSize(). 00173 */ 00174 void SetBaseSize (int w, int h); 00175 00176 void SetMinimumSize(int w, int h); 00177 void SetMaximumSize(int w, int h); 00178 void SetMinMaxSize(int w, int h); 00179 00180 void SetMinimumWidth(int w); 00181 void SetMaximumWidth(int w); 00182 void SetMinimumHeight(int h); 00183 void SetMaximumHeight(int h); 00184 00185 int GetMinimumWidth() const; 00186 int GetMaximumWidth() const; 00187 int GetMinimumHeight() const; 00188 int GetMaximumHeight() const; 00189 00190 void ApplyMinWidth(); 00191 void ApplyMinHeight(); 00192 void ApplyMaxWidth(); 00193 void ApplyMaxHeight(); 00194 00195 Size GetMinimumSize() const; 00196 Size GetMaximumSize() const; 00197 00199 00203 Geometry const& GetGeometry() const; 00204 00206 00215 void SetGeometry (int x, int y, int w, int h); 00216 00218 00225 void SetGeometry (const Geometry &geo); 00226 00227 void IncreaseSize (int x, int y); 00228 00229 void SetBaseString (const TCHAR *Caption); 00230 const NString &GetBaseString() const; 00231 00233 00238 Area * GetToplevel (); 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 00281 virtual long ComputeChildLayout (); 00282 virtual void PositionChildLayout (float offsetX, float offsetY); 00283 virtual long ComputeLayout2 (); 00284 virtual void ComputePosition2 (float offsetX, float offsetY); 00285 00286 virtual bool IsArea () const; 00287 virtual bool IsInputArea () const; 00288 virtual bool IsView () const; 00289 virtual bool IsLayout () const; 00290 virtual bool IsSpaceLayout () const; 00291 virtual bool IsViewWindow () const; 00292 00294 00301 void SetLayoutProperties (LayoutProperties *properties); 00302 00304 00308 LayoutProperties * GetLayoutProperties (); 00309 00310 Area * GetParentObject() const; 00311 00313 00317 void SetVisible (bool visible); 00318 00320 00324 bool IsVisible (); 00325 00327 00331 void SetSensitive (bool sensitive); 00332 00334 00338 bool IsSensitive (); 00339 00340 virtual bool DoGetFocused (); 00341 virtual void DoSetFocused (bool focused); 00342 virtual bool DoCanFocus (); 00343 virtual void DoActivateFocus (); 00344 00345 sigc::signal<void, Area *> FocusActivated; 00346 sigc::signal<void, Area *> FocusChanged; 00347 sigc::signal<void, Area*> ChildFocusChanged; // sends parent + child 00348 00353 sigc::signal<void, Area*> OnKeyNavChangeReconfigure; 00354 sigc::signal<void, Area*> OnKeyNavFocusChange; 00355 sigc::signal<void, Area*> OnKeyNavFocusActivate; 00356 00358 00361 void QueueRelayout (); 00362 00363 virtual unsigned int GetStretchFactor(); 00364 virtual void SetStretchFactor (unsigned int sf); 00365 00366 virtual MinorDimensionPosition GetPositioning(); 00367 virtual void SetPositioning (MinorDimensionPosition p); 00368 00369 virtual MinorDimensionSize GetExtend(); 00370 virtual void SetExtend (MinorDimensionSize ext); 00371 00372 virtual float GetPercentage(); 00373 virtual void SetPercentage (float f); 00374 virtual bool IsLayoutDone(); 00375 virtual void SetLayoutDone (bool b); 00376 00377 void Set2DMatrix (const Matrix4 &mat); 00378 void Set2DTranslation (float tx, float ty, float tz); 00379 Matrix4 Get2DMatrix () const; 00380 00381 Matrix4 Get3DMatrix () const; 00382 bool Is3DArea () const; 00383 00385 00392 virtual Geometry GetAbsoluteGeometry () const; 00393 00395 int GetAbsoluteX () const; 00396 00398 int GetAbsoluteY () const; 00399 00401 00404 int GetAbsoluteWidth () const; 00405 00407 00410 int GetAbsoluteHeight () const; 00411 00413 00417 virtual Geometry GetRootGeometry () const; 00418 00420 int GetRootX () const; 00421 00423 int GetRootY () const; 00424 00426 00429 int GetRootWidth () const; 00430 00432 00435 int GetRootHeight () const; 00436 00437 sigc::signal<void, int, int, int, int> OnResize; 00438 sigc::signal<void, Area *, bool> OnVisibleChanged; 00439 sigc::signal<void, Area *, bool> OnSensitiveChanged; 00440 sigc::signal<void, Area *, Geometry&> OnGeometryChanged; 00441 00451 virtual void SetParentObject (Area *); 00452 00454 00460 virtual void UnParentObject (); 00461 00467 virtual Area* FindAreaUnderMouse(const Point& mouse_position, NuxEventType event_type); 00468 00469 00470 virtual Area* FindKeyFocusArea(unsigned int key_symbol, 00471 unsigned long x11_key_code, 00472 unsigned long special_keys_state); 00473 00474 void SetPathToKeyFocusArea(); 00475 void ResetDownwardPathToKeyFocusArea(); 00476 void ResetUpwardPathToKeyFocusArea(); 00477 00479 virtual bool InspectKeyEvent(unsigned int eventType, 00480 unsigned int keysym, 00481 const char* character); 00482 00483 virtual bool AcceptKeyNavFocus(); 00484 00485 virtual Area* KeyNavIteration(KeyNavDirection direction); 00486 00487 bool HasKeyFocus() const; 00488 00490 00498 void SetReconfigureParentLayoutOnGeometryChange(bool reconfigure_parent_layout); 00499 00501 00504 bool ReconfigureParentLayoutOnGeometryChange(); 00505 00507 00510 void SetAcceptKeyboardEvent(bool accept_key_event); 00511 00513 00516 bool AcceptKeyboardEvent() const; 00517 00519 00522 void SetAcceptMouseWheelEvent(bool accept_mouse_wheel_event); 00523 00525 00528 bool AcceptMouseWheelEvent() const; 00529 00530 protected: 00531 bool _is_focused; 00532 /* 00533 This function is reimplemented in Layout as it need to perform some special operations. 00534 It does nothing for Area and View classes. 00535 */ 00536 //virtual void RemoveChildObject(smptr(Area)); 00537 00538 virtual void GeometryChangePending () {} 00539 virtual void GeometryChanged () {} 00540 00542 /* 00543 When an object size changes, it is necessary for its parent structure to initiate a layout 00544 re computation in order preserve the layout structure defined by the user through the API. 00545 */ 00546 virtual void RequestBottomUpLayoutComputation (Area *bo_initiator); 00547 00549 void InnerGetAbsoluteGeometry (Geometry &geometry); 00550 00552 void InnerGetRootGeometry (Geometry &geometry); 00553 00554 // //! Add a "secondary" child to this Area. The 00555 // /*! 00556 // @return True if the child has been added; False otherwise; 00557 // */ 00558 // bool Secondary (Area *child); 00559 00560 bool _on_geometry_changeg_reconfigure_parent_layout; 00561 00562 bool has_key_focus_; 00563 00564 Area *next_object_to_key_focus_area_; 00565 private: 00566 void ReconfigureParentLayout(Area *child = 0); 00567 void CheckMinSize(); 00568 void CheckMaxSize(); 00569 00570 00571 Geometry _geometry; 00572 00574 /* 00575 An object of the class Area may have another of the class Layout as Parent. 00576 An object of the class View may have an object of the class Layout as parent. 00577 An object of the class Layout may have a parent of the class Layout or View as parent. 00578 A Area cannot have children (that may change later). 00579 */ 00580 Area *_parent_area; 00581 00582 00583 LayoutProperties *_layout_properties; 00584 bool _visible; 00585 bool _sensitive; 00586 00587 NString _base_string; 00588 00589 Size _min_size; 00590 Size _max_size; 00591 00592 unsigned int _stretch_factor; 00593 MinorDimensionPosition _positioning; 00594 MinorDimensionSize _extend; 00595 float _percentage; 00596 bool _layout_done; 00597 00598 00599 Matrix4 _2d_xform; 00600 Matrix4 _3d_xform; 00601 bool _3d_area; 00602 00603 std::list<Area*> _children_list; 00604 00605 bool _accept_mouse_wheel_event; 00606 bool _accept_keyboard_event; 00607 00608 friend class Layout; 00609 friend class View; 00610 friend class WindowThread; 00611 friend class HSplitter; 00612 friend class VSplitter; 00613 friend class WindowCompositor; 00614 }; 00615 00616 } 00617 #endif // BASEOBJECT_H 00618