nux-1.16.0
Area.cpp
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 #include "Nux.h"
00024 #include "Area.h"
00025 #include "NuxGraphics/GraphicsEngine.h"
00026 #include "Layout.h"
00027 #include "VSplitter.h"
00028 #include "HSplitter.h"
00029 #include "BaseWindow.h"
00030 #include "MenuPage.h"
00031 
00032 namespace nux
00033 {
00034 
00035   NUX_IMPLEMENT_OBJECT_TYPE (Area);
00036 
00037   Area::Area (NUX_FILE_LINE_DECL)
00038     :   InitiallyUnownedObject (NUX_FILE_LINE_PARAM)
00039     ,   _is_focused (0)
00040     ,   _geometry (0, 0, DEFAULT_WIDGET_WIDTH, DEFAULT_WIDGET_HEIGHT)
00041     ,   _min_size (AREA_MIN_WIDTH, AREA_MIN_HEIGHT)
00042     ,   _max_size (AREA_MAX_WIDTH, AREA_MAX_HEIGHT)
00043   {
00044     _parent_area = NULL;
00045     next_object_to_key_focus_area_ = NULL;
00046     has_key_focus_ = false;
00047 
00048     _stretch_factor = 1;
00049     _layout_properties = NULL;
00050     _visible = true;
00051     _sensitive = true;
00052 
00053     _on_geometry_changeg_reconfigure_parent_layout = true;
00054     _accept_mouse_wheel_event = false;
00055     _accept_keyboard_event = false;
00056 
00057     _2d_xform.Identity ();
00058     _3d_xform.Identity ();
00059     _3d_area = false;
00060   }
00061 
00062 
00063   Area::~Area()
00064   {
00065     if (_layout_properties)
00066       delete _layout_properties;
00067   }
00068 
00069   const NString &Area::GetBaseString() const
00070   {
00071     return _base_string;
00072   }
00073 
00074   void Area::SetBaseString (const TCHAR *Caption)
00075   {
00076     _base_string = Caption;
00077   }
00078 
00079   void Area::CheckMinSize()
00080   {
00081     int w = _min_size.width;
00082     w = Max<int>(AREA_MIN_WIDTH, w);
00083     int h = _min_size.height;
00084     h = Max<int>(AREA_MIN_HEIGHT, h);
00085 
00086     _min_size = Size(w, h);
00087 
00088     if (_min_size.width > _max_size.width)
00089     {
00090       _max_size.width = _min_size.width;
00091     }
00092 
00093     if (_min_size.height > _max_size.height)
00094     {
00095       _max_size.height = _min_size.height;
00096     }
00097 
00098     if (_geometry.width < _min_size.width)
00099     {
00100       _geometry.width = _min_size.width;
00101     }
00102 
00103     if (_geometry.height < _min_size.height )
00104     {
00105       _geometry.height = _min_size.height;
00106     }
00107   }
00108 
00109   void Area::CheckMaxSize()
00110   {
00111     int w = _max_size.width;
00112     w = Min<int>(AREA_MAX_WIDTH, w);
00113     int h = _max_size.height;
00114     h = Min<int>(AREA_MAX_HEIGHT, h);
00115 
00116     _max_size = Size(w, h);
00117 
00118     if (_min_size.width > _max_size.width)
00119     {
00120       _min_size.width = _max_size.width;
00121     }
00122 
00123     if (_min_size.height > _max_size.height)
00124     {
00125       _min_size.height = _max_size.height;
00126     }
00127 
00128     if (_geometry.width > _max_size.width)
00129     {
00130       _geometry.width = _max_size.width;
00131     }
00132 
00133     if (_geometry.height > _max_size.height)
00134     {
00135       _geometry.height = _max_size.height;
00136     }
00137   }
00138 
00139   void Area::SetMinimumSize (int w, int h)
00140   {
00141     nuxAssert (w >= 0);
00142     nuxAssert (h >= 0);
00143     _min_size = Size(w, h);
00144 
00145     CheckMinSize();
00146 
00147     ReconfigureParentLayout();
00148   }
00149 
00150   void Area::SetMaximumSize (int w, int h)
00151   {
00152     nuxAssert (w >= 0);
00153     nuxAssert (h >= 0);
00154     _max_size = Size(w, h);
00155 
00156     CheckMaxSize();
00157 
00158     ReconfigureParentLayout();
00159   }
00160 
00161   void Area::SetMinMaxSize (int w, int h)
00162   {
00163     nuxAssert (w >= 0);
00164     nuxAssert (h >= 0);
00165     SetMinimumSize (w, h);
00166     SetMaximumSize (w, h);
00167 
00168     //ReconfigureParentLayout();
00169   }
00170 
00171   void Area::ApplyMinWidth()
00172   {
00173     _geometry.width = _min_size.width;
00174 
00175     ReconfigureParentLayout();
00176   }
00177 
00178   void Area::ApplyMinHeight()
00179   {
00180     _geometry.height = _min_size.height;
00181 
00182     ReconfigureParentLayout();
00183   }
00184 
00185   void Area::ApplyMaxWidth()
00186   {
00187     _geometry.width = _max_size.width;
00188 
00189     ReconfigureParentLayout();
00190   }
00191 
00192   void Area::ApplyMaxHeight()
00193   {
00194     _geometry.height = _max_size.height;
00195 
00196     ReconfigureParentLayout();
00197   }
00198 
00199   Size Area::GetMinimumSize() const
00200   {
00201     return _min_size;
00202   }
00203 
00204   Size Area::GetMaximumSize() const
00205   {
00206     return _max_size;
00207   }
00208 
00209   void Area::SetMinimumWidth (int w)
00210   {
00211     nuxAssert (w >= 0);
00212     _min_size.width = w;
00213     CheckMinSize();
00214     ReconfigureParentLayout();
00215   }
00216 
00217   void Area::SetMaximumWidth (int w)
00218   {
00219     nuxAssert (w >= 0);
00220     _max_size.width = w;
00221     CheckMaxSize();
00222     ReconfigureParentLayout();
00223   }
00224 
00225   void Area::SetMinimumHeight (int h)
00226   {
00227     nuxAssert (h >= 0);
00228     _min_size.height = h;
00229     CheckMinSize();
00230     ReconfigureParentLayout();
00231   }
00232 
00233   void Area::SetMaximumHeight (int h)
00234   {
00235     nuxAssert (h >= 0);
00236     _max_size.height = h;
00237     CheckMaxSize();
00238     ReconfigureParentLayout();
00239   }
00240 
00241   int Area::GetMinimumWidth() const
00242   {
00243     return _min_size.width;
00244   }
00245 
00246   int Area::GetMaximumWidth() const
00247   {
00248     return _max_size.width;
00249   }
00250 
00251   int Area::GetMinimumHeight() const
00252   {
00253     return _min_size.height;
00254   }
00255 
00256   int Area::GetMaximumHeight() const
00257   {
00258     return _max_size.height;
00259   }
00260 
00261   unsigned int Area::GetStretchFactor()
00262   {
00263     return _stretch_factor;
00264   }
00265 
00266   void Area::SetStretchFactor (unsigned int sf)
00267   {
00268     // re implemented by Layout
00269     _stretch_factor = sf;
00270   }
00271 
00272   void Area::SetParentObject (Area *bo)
00273   {
00274     if (bo == 0)
00275     {
00276       nuxAssertMsg (0, TEXT ("[Area::SetParentObject] Invalid parent obejct.") );
00277       return;
00278     }
00279 
00280     if (_parent_area)
00281     {
00282       nuxAssertMsg (0, TEXT ("[Area::SetParentObject] Object already has a parent. You must UnParent the object before you can parenting again.") );
00283       return;
00284     }
00285 
00286     _parent_area = bo;
00287     Reference();
00288   }
00289 
00290   void Area::UnParentObject()
00291   {
00292     if (_parent_area)
00293     {
00294       _parent_area = 0;
00295       UnReference();
00296     }
00297   }
00298 
00299   Area *Area::GetParentObject() const
00300   {
00301     return _parent_area;
00302   }
00303 
00304   int Area::GetBaseX     () const
00305   {
00306     return _geometry.x;
00307   }
00308 
00309   int Area::GetBaseY     () const
00310   {
00311     return _geometry.y;
00312   }
00313 
00314   int Area::GetBaseWidth    () const
00315   {
00316     return _geometry.width;
00317   }
00318 
00319   int Area::GetBaseHeight   () const
00320   {
00321     return _geometry.height;
00322   }
00323 
00324   void Area::SetGeometry(int x, int y, int w, int h)
00325   {
00326     h = nux::Clamp<int> (h, _min_size.height, _max_size.height);
00327     w = nux::Clamp<int> (w, _min_size.width, _max_size.width);
00328 
00329     nux::Geometry geometry(x, y, w, h);
00330     if (_geometry == geometry)
00331       return;
00332 
00333     GeometryChangePending();
00334     _geometry = geometry;
00335     ReconfigureParentLayout();
00336     GeometryChanged();
00337 
00338     OnGeometryChanged.emit(this, _geometry);
00339   }
00340 
00341   void Area::SetGeometry (const Geometry &geo)
00342   {
00343     SetGeometry (geo.x, geo.y, geo.width, geo.height);
00344   }
00345 
00346   Geometry const& Area::GetGeometry() const
00347   {
00348     return _geometry;
00349   }
00350 
00351   void Area::SetBaseX(int x)
00352   {
00353     SetGeometry(x, _geometry.y, _geometry.width, _geometry.height);
00354   }
00355 
00356   void Area::SetBaseY    (int y)
00357   {
00358     SetGeometry (_geometry.x, y, _geometry.width, _geometry.height);
00359   }
00360 
00361   void Area::SetBaseXY    (int x, int y)
00362   {
00363     SetGeometry (x, y, _geometry.width, _geometry.height);
00364   }
00365 
00366   void Area::SetBaseSize (int w, int h)
00367   {
00368     SetGeometry (_geometry.x, _geometry.y, w, h);
00369   }
00370 
00371   void Area::SetBaseWidth (int w)
00372   {
00373     SetGeometry (_geometry.x, _geometry.y, w, _geometry.height);
00374   }
00375 
00376   void Area::SetBaseHeight (int h)
00377   {
00378     SetGeometry (_geometry.x, _geometry.y, _geometry.width, h);
00379   }
00380 
00381   void Area::IncreaseSize (int x, int y)
00382   {
00383     _geometry.OffsetPosition (x, y);
00384     OnResize.emit (_geometry.x, _geometry.y, _geometry.width, _geometry.height );
00385   }
00386 
00387   long Area::ComputeChildLayout()
00388   {
00389     return 0;
00390   }
00391 
00392   void Area::PositionChildLayout (float offsetX, float offsetY)
00393   {
00394 
00395   }
00396 
00397   long Area::ComputeLayout2()
00398   {
00399     return (eCompliantWidth | eCompliantHeight);
00400   }
00401 
00402   void Area::ComputePosition2 (float offsetX, float offsetY)
00403   {
00404 
00405   }
00406 
00407   void Area::SetReconfigureParentLayoutOnGeometryChange(bool reconfigure_parent_layout)
00408   {
00409     _on_geometry_changeg_reconfigure_parent_layout = reconfigure_parent_layout;
00410   }
00411   
00412   bool Area::ReconfigureParentLayoutOnGeometryChange()
00413   {
00414     return _on_geometry_changeg_reconfigure_parent_layout;
00415   }
00416 
00417   void Area::ReconfigureParentLayout(Area *child)
00418   {
00419     if(_on_geometry_changeg_reconfigure_parent_layout == false)
00420       return;
00421 
00422     if (GetWindowThread ()->IsComputingLayout() )
00423     {
00424       // there is no need to do the following while we are already computing the layout.
00425       // If we do, we will end up in an infinite loop.
00426       return;
00427     }
00428 
00429     if (this->Type().IsDerivedFromType (View::StaticObjectType) )
00430     {
00431       // The object that is being resized is a View object and it has a parent.
00432       if (this->OwnsTheReference() == false && this->GetParentObject())
00433       {
00434         // Only reference parented areas.
00435         this->Reference();
00436       }
00437 
00438       View *ic = static_cast<View *>(this);
00439 
00440       if (ic->CanBreakLayout() )
00441       {
00442 
00443         if ( (child != 0) &&
00444              (ic->Type().IsObjectType (VSplitter::StaticObjectType) || ic->Type().IsObjectType (HSplitter::StaticObjectType) ) )
00445         {
00446           // If this element is a Splitter, then we submit its child to the refresh list. We don't want to submit the
00447           // splitter because this will cause a redraw of all parts of the splitter (costly and unnecessary).
00448           GetWindowThread ()->QueueObjectLayout (child);
00449         }
00450         else
00451         {
00452           GetWindowThread ()->QueueObjectLayout (ic);
00453         }
00454       }
00455       else if (ic->_parent_area)
00456         ic->_parent_area->ReconfigureParentLayout (this);
00457       else
00458       {
00459         GetWindowThread ()->QueueObjectLayout (ic);
00460       }
00461     }
00462     else if (this->Type().IsDerivedFromType (Layout::StaticObjectType) )
00463     {
00464       // The object that is being resized is a View object and it has a parent.
00465       if (this->OwnsTheReference() == false && this->GetParentObject())
00466       {
00467         // Only reference parented areas.
00468         this->Reference();
00469       }
00470 
00471       Layout *layout = static_cast<Layout *>(this);
00472 
00473       if (layout->_parent_area)
00474       {
00475         if (layout->_parent_area->Type().IsDerivedFromType (View::StaticObjectType) )
00476         {
00477           View *ic = (View *) (layout->_parent_area);
00478 
00479           if (ic->CanBreakLayout() )
00480           {
00481             if ( (child != 0) &&
00482                  (ic->Type().IsObjectType (VSplitter::StaticObjectType) || ic->Type().IsObjectType (HSplitter::StaticObjectType) ) )
00483             {
00484               // If the parent of this element is a splitter, then we submit its child to the refresh list. We don't want to submit the
00485               // splitter because this will cause a redraw of all parts of the splitter (costly and unnecessary).
00486               GetWindowThread ()->QueueObjectLayout (this);
00487             }
00488             else
00489             {
00490               GetWindowThread ()->QueueObjectLayout (ic);
00491             }
00492           }
00493           else
00494           {
00495             // The parent object of an object of type View is a Layout object type.
00496             layout->_parent_area->ReconfigureParentLayout (this);
00497           }
00498         }
00499         else
00500         {
00501           layout->_parent_area->ReconfigureParentLayout (this);
00502         }
00503       }
00504       else
00505       {
00506         // This is possibly the Main layout or the layout of a floating object (popup for example) unless the layout is not part of the object tree.
00507         GetWindowThread ()->QueueObjectLayout (layout);
00508       }
00509     }
00510     else
00511     {
00512       // The object that is being resized is a InputArea object.
00513       if (this->_parent_area)
00514       {
00515         // The object that is being resized is a View object and it has a parent.
00516         if (this->OwnsTheReference() == false && this->GetParentObject())
00517         {
00518           // Only reference parented areas.
00519           this->Reference();
00520         }
00521 
00522         // The parent object of an object of type InputArea is a Layout object type.
00523         this->_parent_area->ReconfigureParentLayout (this);
00524       }
00525     }
00526   }
00527 
00528   void Area::RequestBottomUpLayoutComputation (Area *bo_initiator)
00529   {
00530     if (_parent_area && _parent_area->IsLayout() )
00531     {
00532       _parent_area->RequestBottomUpLayoutComputation (bo_initiator);
00533     }
00534   }
00535 
00536   void Area::SetLayoutProperties (LayoutProperties *properties)
00537   {
00538     if (_layout_properties)
00539       delete _layout_properties;
00540 
00541     _layout_properties = properties;
00542   }
00543 
00544   Area::LayoutProperties * Area::GetLayoutProperties ()
00545   {
00546     return _layout_properties;
00547   }
00548 
00549   void Area::SetVisible (bool visible)
00550   {
00551     if (_visible == visible)
00552       return;
00553 
00554     _visible = visible;
00555 
00556     OnVisibleChanged.emit (this, _visible);
00557   }
00558 
00559   bool Area::IsVisible ()
00560   {
00561     return _visible;
00562   }
00563 
00564   void Area::SetSensitive (bool sensitive)
00565   {
00566     if (_sensitive == sensitive)
00567       return;
00568 
00569     _sensitive = sensitive;
00570 
00571     OnSensitiveChanged.emit (this, _sensitive);
00572   }
00573 
00574   bool Area::IsSensitive ()
00575   {
00576     return _sensitive;
00577   }
00578 
00579   MinorDimensionPosition Area::GetPositioning()
00580   {
00581     return _positioning;
00582   }
00583 
00584   void Area::SetPositioning (MinorDimensionPosition p)
00585   {
00586     _positioning = p;
00587   }
00588 
00589   MinorDimensionSize Area::GetExtend()
00590   {
00591     return _extend;
00592   }
00593 
00594   void Area::SetExtend (MinorDimensionSize ext)
00595   {
00596     _extend = ext;
00597   }
00598 
00599   float Area::GetPercentage()
00600   {
00601     return _percentage;
00602   }
00603 
00604   void Area::SetPercentage (float p)
00605   {
00606     _percentage = p;
00607   }
00608 
00609   bool Area::IsLayoutDone()
00610   {
00611     return _layout_done;
00612   }
00613 
00614   void Area::SetLayoutDone (bool b)
00615   {
00616     _layout_done = b;
00617   }
00618 
00619   bool Area::IsArea () const
00620   {
00621     return this->Type ().IsDerivedFromType (Area::StaticObjectType);;
00622   }
00623 
00624   bool Area::IsInputArea () const
00625   {
00626     return this->Type ().IsDerivedFromType (InputArea::StaticObjectType);;
00627   }
00628 
00629   bool Area::IsView () const
00630   {
00631     return this->Type ().IsDerivedFromType (View::StaticObjectType);;
00632   }
00633 
00634   bool Area::IsLayout () const
00635   {
00636     return this->Type ().IsDerivedFromType (Layout::StaticObjectType);
00637   }
00638 
00639   bool Area::IsViewWindow () const
00640   {
00641     return this->Type ().IsDerivedFromType (BaseWindow::StaticObjectType);
00642   }
00643 
00644   bool Area::IsSpaceLayout() const
00645   {
00646     return this->Type().IsDerivedFromType(SpaceLayout::StaticObjectType);;
00647   }
00648 
00649   void Area::Set2DMatrix (const Matrix4 &mat)
00650   {
00651     _2d_xform = mat;
00652   }
00653 
00654   void Area::Set2DTranslation (float tx, float ty, float tz)
00655   {
00656     _2d_xform.Translate (tx, ty, tz);
00657   }
00658 
00659   Matrix4 Area::Get2DMatrix () const
00660   {
00661     return _2d_xform;
00662   }
00663 
00664   Matrix4 Area::Get3DMatrix () const
00665   {
00666     return _3d_xform;
00667   }
00668 
00669   bool Area::Is3DArea () const
00670   {
00671     return _3d_area;
00672   }
00673 
00674   static void MatrixXFormGeometry (const Matrix4 &matrix, Geometry &geo)
00675   {
00676     Vector4 in (geo.x, geo.y, 0, 1);
00677     // This is mean only for translation matrices. It will not work with matrices containing rotations or scalings.
00678     Vector4 out = matrix * in;
00679     geo.x = out.x;
00680     geo.y = out.y;
00681   }
00682 
00683   void Area::InnerGetAbsoluteGeometry (Geometry &geometry)
00684   {
00685     if (this->Type ().IsDerivedFromType (BaseWindow::StaticObjectType) || (this == GetWindowThread ()->GetMainLayout ()))
00686     {
00687       geometry.OffsetPosition (_geometry.x, _geometry.y);
00688       return;
00689     }
00690 
00691     MatrixXFormGeometry (_2d_xform, geometry);
00692 
00693     Area *parent = GetParentObject ();
00694     if (parent)
00695       parent->InnerGetAbsoluteGeometry (geometry);
00696   }
00697 
00698   Geometry Area::GetAbsoluteGeometry () const
00699   {
00700     if (Type().IsDerivedFromType(BaseWindow::StaticObjectType) ||
00701       Type().IsDerivedFromType(MenuPage::StaticObjectType) ||
00702       (this == GetWindowThread()->GetMainLayout()))
00703     {
00704       // Do not apply the _2D_xform matrix  to a BaseWindow or the main layout
00705       return _geometry;
00706     }
00707     else
00708     {
00709       nux::Geometry geo = _geometry;
00710       MatrixXFormGeometry (_2d_xform, geo);
00711 
00712       Area *parent = GetParentObject ();
00713       if (parent)
00714         parent->InnerGetAbsoluteGeometry (geo);
00715 
00716       return geo;
00717     }
00718   }
00719 
00720   int Area::GetAbsoluteX () const
00721   {
00722     return GetAbsoluteGeometry ().x;
00723   }
00724 
00725   int Area::GetAbsoluteY () const
00726   {
00727     return GetAbsoluteGeometry ().y;
00728   }
00729 
00730   int Area::GetAbsoluteWidth () const
00731   {
00732     return GetAbsoluteGeometry ().width;
00733   }
00734 
00735   int Area::GetAbsoluteHeight () const
00736   {
00737     return GetAbsoluteGeometry ().height;
00738   }
00739 
00740   void Area::InnerGetRootGeometry (Geometry &geometry)
00741   {
00742     if (this->Type ().IsDerivedFromType (BaseWindow::StaticObjectType) || (this == GetWindowThread ()->GetMainLayout ()))
00743       return;
00744 
00745     MatrixXFormGeometry (_2d_xform, geometry);
00746 
00747     Area *parent = GetParentObject ();
00748     if (parent)
00749       parent->InnerGetRootGeometry (geometry);
00750   }
00751 
00752   Geometry Area::GetRootGeometry () const
00753   {
00754     nux::Geometry geo = _geometry;
00755     MatrixXFormGeometry (_2d_xform, geo);
00756 
00757     if (Type().IsDerivedFromType(BaseWindow::StaticObjectType) || (this == GetWindowThread()->GetMainLayout()))
00758     {
00759       return geo;
00760     }
00761     else
00762     {
00763       Area *parent = GetParentObject ();
00764       if (parent)
00765         parent->InnerGetRootGeometry (geo);
00766 
00767       return geo;
00768     }
00769   }
00770 
00771   int Area::GetRootX () const
00772   {
00773     return GetRootGeometry ().x;
00774   }
00775 
00776   int Area::GetRootY () const
00777   {
00778     return GetRootGeometry ().y;
00779   }
00780 
00781   int Area::GetRootWidth () const
00782   {
00783     return GetRootGeometry ().width;
00784   }
00785 
00786   int Area::GetRootHeight () const
00787   {
00788     return GetRootGeometry ().height;
00789   }
00790 
00791   Area* Area::GetToplevel ()
00792   {
00793     if (Type ().IsDerivedFromType (BaseWindow::StaticObjectType) || (this == GetWindowThread ()->GetMainLayout ()))
00794     {
00795       return this;
00796     }
00797 
00798     Area* parent = GetParentObject ();
00799     if (!parent) //we didn't find a way to salvation!
00800     {
00801       return 0;
00802     }
00803     return parent->GetToplevel ();
00804   }
00805 
00806   Area* Area::GetTopLevelViewWindow ()
00807   {
00808     Area* area = GetToplevel ();
00809 
00810     if (area && area->IsViewWindow ())
00811       return area;
00812 
00813     return NULL;
00814   }
00815 
00816   bool Area::HasTopLevelParent ()
00817   {
00818     if (GetToplevel ())
00819     {
00820       return true;
00821     }
00822     return false;
00823   }
00824 
00825   bool Area::IsChildOf(Area* parent)
00826   {
00827     if (this == parent)
00828       return true;
00829 
00830     if (!parent || !_parent_area)
00831       return false;
00832 
00833     return _parent_area->IsChildOf(parent);    
00834   }
00835 
00836   /* handles our focusable code */
00837   bool Area::DoGetFocused ()
00838   {
00839     return _is_focused;
00840   }
00841 
00842   /* Pretty much everything is going to have to override this */
00843   void Area::DoSetFocused (bool focused)
00844   {
00845     if (_is_focused == focused)
00846       return;
00847     
00848     _is_focused = focused;
00849     FocusChanged.emit (this);
00850   }
00851 
00852   bool Area::DoCanFocus ()
00853   {
00854     return true;
00855   }
00856 
00857   /* override me! */
00858   void Area::DoActivateFocus ()
00859   {
00860     FocusActivated.emit (this);
00861   }
00862 
00863   void Area::QueueRelayout ()
00864   {
00865     nux::GetWindowThread ()->QueueObjectLayout (this);
00866   }
00867   
00868   void Area::SetAcceptKeyboardEvent(bool accept_keyboard_event)
00869   {
00870     _accept_keyboard_event = accept_keyboard_event;
00871   }
00872 
00873   bool Area::AcceptKeyboardEvent() const
00874   {
00875     return _accept_keyboard_event;
00876   }
00877 
00878   void Area::SetAcceptMouseWheelEvent(bool accept_mouse_wheel_event)
00879   {
00880     _accept_mouse_wheel_event = accept_mouse_wheel_event;
00881   }
00882 
00883   bool Area::AcceptMouseWheelEvent() const
00884   {
00885     return _accept_mouse_wheel_event;
00886   }
00887 
00888   bool Area::TestMousePointerInclusion(const Point& mouse_position, NuxEventType event_type)
00889   {
00890     bool mouse_pointer_inside_area = false;
00891 
00892     if (Type().IsDerivedFromType(MenuPage::StaticObjectType))
00893     {
00894       // A MenuPage geometry is already in absolute coordinates.
00895       mouse_pointer_inside_area = _geometry.IsInside(mouse_position);
00896     }
00897     else
00898     {
00899       mouse_pointer_inside_area = GetAbsoluteGeometry().IsInside(mouse_position);
00900     }
00901 
00902     if ((event_type == NUX_MOUSE_WHEEL) && mouse_pointer_inside_area)
00903     {
00904       if (_accept_mouse_wheel_event == false)
00905         return NULL;
00906     }
00907 
00908     return mouse_pointer_inside_area;
00909   }
00910 
00911   bool Area::TestMousePointerInclusionFilterMouseWheel(const Point& mouse_position, NuxEventType event_type)
00912   {
00913     bool mouse_pointer_inside_area = false;
00914 
00915     if (Type().IsDerivedFromType(MenuPage::StaticObjectType))
00916     {
00917       // A MenuPage geometry is already in absolute coordinates.
00918       mouse_pointer_inside_area = _geometry.IsInside(mouse_position);
00919     }
00920     else
00921     {
00922       mouse_pointer_inside_area = GetAbsoluteGeometry().IsInside(mouse_position);
00923     }
00924 
00925     return mouse_pointer_inside_area;
00926   }
00927 
00928   Area* Area::FindAreaUnderMouse(const Point& mouse_position, NuxEventType event_type)
00929   {
00930     return NULL;
00931   }
00932   
00933   Area* Area::FindKeyFocusArea(unsigned int key_symbol,
00934    unsigned long x11_key_code,
00935    unsigned long special_keys_state)
00936   {
00937     if (has_key_focus_)
00938     {
00939       return this;
00940     }
00941     else if (next_object_to_key_focus_area_)
00942     {
00943       return next_object_to_key_focus_area_->FindKeyFocusArea(key_symbol, x11_key_code, special_keys_state);
00944     }
00945     return NULL;
00946   }
00947 
00948   void Area::SetPathToKeyFocusArea()
00949   {
00950     has_key_focus_ = true;
00951     next_object_to_key_focus_area_ = NULL;
00952 
00953     Area* child = this;
00954     Area* parent = GetParentObject();
00955 
00956     while (parent)
00957     {
00958       parent->next_object_to_key_focus_area_ = child;
00959       parent->next_object_to_key_focus_area_->Reference();
00960       parent->has_key_focus_ = false;
00961       child = parent;
00962       parent = parent->GetParentObject();
00963     }
00964   }
00965 
00966   void Area::ResetDownwardPathToKeyFocusArea()
00967   {
00968     has_key_focus_ = false;
00969     if (next_object_to_key_focus_area_)
00970     {
00971       next_object_to_key_focus_area_->ResetDownwardPathToKeyFocusArea();
00972     }
00973     if(next_object_to_key_focus_area_)
00974       next_object_to_key_focus_area_->UnReference();
00975 
00976     next_object_to_key_focus_area_ = NULL;
00977   }
00978 
00979   void Area::ResetUpwardPathToKeyFocusArea()
00980   {
00981     has_key_focus_ = false;
00982     if (_parent_area)
00983     {
00984       _parent_area->ResetUpwardPathToKeyFocusArea();
00985     }
00986     if(next_object_to_key_focus_area_)
00987       next_object_to_key_focus_area_->UnReference();
00988 
00989     next_object_to_key_focus_area_ = NULL;
00990   }
00991 
00992   bool Area::InspectKeyEvent(unsigned int eventType,
00993     unsigned int keysym,
00994     const char* character)
00995   {
00996     return false;
00997   }
00998 
00999   bool Area::AcceptKeyNavFocus()
01000   {
01001     return true;
01002   }
01003 
01004   Area* Area::KeyNavIteration(KeyNavDirection direction)
01005   {
01006     return NULL;
01007   }
01008 
01009   bool Area::HasKeyFocus() const
01010   {
01011     return has_key_focus_;
01012   }
01013 }
01014 
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends