nux-1.14.0
View.h
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 ABSTRACTOBJECTBASE_H
00024 #define ABSTRACTOBJECTBASE_H
00025 
00026 #include "Nux.h"
00027 #include "Focusable.h"
00028 #include "NuxCore/Property.h"
00029 
00030 #define NeedRedraw QueueDraw
00031 
00032 namespace nux
00033 {
00034   class Layout;
00035 
00036   enum eControlType
00037   {
00038     eNumericValuator,
00039     eSpinBox,
00040     eVector3Box,
00041     eBooleanBox,
00042     eStaticText,
00043     ePopupBox
00044   };
00045 
00046   class View: public InputArea
00047   {
00048     NUX_DECLARE_OBJECT_TYPE (View, InputArea);
00049   public:
00050     View (NUX_FILE_LINE_DECL);
00051     virtual ~View();
00052 
00053   public:
00054 
00055     // Deprecated
00056     //long BaseProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo);
00057 
00058     virtual long ComputeChildLayout();
00059     virtual void PositionChildLayout (float offsetX, float offsetY);
00060 
00061     // NUXTODO: Find better name
00062     virtual long ComputeLayout2();
00063 
00064     // NUXTODO: Find better name
00065     virtual void ComputePosition2 (float offsetX, float offsetY);
00066 
00067     virtual void PreLayoutManagement();
00068     virtual long PostLayoutManagement (long LayoutResult);
00069     virtual void PreResizeGeometry();
00070     virtual void PostResizeGeometry();
00071 
00072     // NUXTODO: Find better name
00073     virtual long PostProcessEvent2 (IEvent &ievent, long TraverseInfo, long ProcessEventInfo);
00074 
00075     virtual bool IsLayout() const
00076     {
00077       return false;
00078     }
00079     virtual bool IsSpaceLayout() const
00080     {
00081       return false;
00082     }
00083     virtual bool IsArea() const
00084     {
00085       return false;
00086     }
00087     virtual bool IsView() const
00088     {
00089       return true;
00090     }
00091 
00092     void SetUsingStyleDrawing (bool b)
00093     {
00094       m_UseStyleDrawing = b;
00095     };
00096     bool IsUsingStyleDrawing() const
00097     {
00098       return m_UseStyleDrawing;
00099     };
00100 
00104     void DeactivateView ();
00105 
00109     void ActivateView ();
00110 
00114     bool IsViewActive () const;
00115 
00116   public:
00117     virtual void ProcessDraw (GraphicsEngine &GfxContext, bool force_draw);
00119 
00122     virtual void QueueDraw ();
00123 
00125     virtual void NeedSoftRedraw();
00126     virtual bool IsRedrawNeeded();
00127     virtual void DoneRedraw();
00128 
00129     virtual void OverlayDrawing (GraphicsEngine &GfxContext) {}
00130 
00131     //Layout Bridge
00132 
00133     bool SearchInAllSubNodes (Area *bo);
00134     bool SearchInFirstSubNodes (Area *bo);
00135 
00137     /*
00138         Set the Geometry of the View and the geometry of the Default Background Area.
00139         For simple interface control UI classes (RGBValuator...), this is enough.
00140         For others, they have to overwrite the function and do the appropriate computations
00141         for their component.
00142     */
00143     virtual void SetGeometry (const Geometry &geo);
00144 
00146     /*
00147         Return true if this object can break the layout, meaning, the layout can be done on the composition layout only without
00148         recomputing the whole window layout.
00149     */
00150     virtual bool CanBreakLayout()
00151     {
00152       return false;
00153     }
00154 
00155     virtual void SetTextColor(const Color &color);
00156     virtual Color GetTextColor();
00157 
00159 
00163     virtual Layout* GetLayout();
00164 
00166 
00170     virtual bool SetLayout (Layout *layout);
00171 
00172     sigc::signal<void, View*, Layout*> LayoutAdded;
00173     sigc::signal<void, View*, Layout*> LayoutRemoved;
00174 
00175     void SetFont(ObjectPtr<FontTexture> font);
00176     ObjectPtr<FontTexture> GetFont();
00177 
00178     sigc::signal<void, View*> OnQueueDraw;  
00179 
00180     virtual long ProcessFocusEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo);
00181     virtual void DoSetFocused (bool focused);
00182     virtual bool DoCanFocus ();
00183     virtual bool DoGetFocused ();
00184     void SetCanFocus (bool can_focus);
00185     void SetFocusControl (bool focus_control);
00186     bool HasFocusControl ();
00187 
00188     /*
00189         Returns true if the view has a layout and passes focus to that layout
00190     */
00191     bool HasPassiveFocus ();
00192 
00193     virtual Area* KeyNavIteration(KeyNavDirection direction);
00194     virtual bool AcceptKeyNavFocus();
00195 
00196     void IsHitDetectionSkipingChildren(bool skip_children);
00197 
00198 
00199   protected:
00200     bool _can_focus;
00201 
00202     void OnChildFocusChanged (/*Area *parent,*/ Area *child);
00203     sigc::connection _on_focus_changed_handler;
00204 
00205     // ProcessEvent is deprecated. 
00206     virtual long ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo) {return 0;}
00207 
00208     virtual void Draw (GraphicsEngine &GfxContext, bool force_draw) = 0;
00209     virtual void DrawContent (GraphicsEngine &GfxContext, bool force_draw);
00210     virtual void PostDraw (GraphicsEngine &GfxContext, bool force_draw);
00211 
00212     void DoMouseDownOutsideArea (int x, int y,unsigned long mousestate, unsigned long keystate);
00213 
00214     void InitializeWidgets();
00215     void InitializeLayout();
00216 
00217     Color m_TextColor;
00218     ObjectPtr<FontTexture> _font;
00219 
00221     virtual Layout* GetCompositionLayout();
00222 
00224     virtual bool SetCompositionLayout (Layout *layout);
00225 
00226     void RemoveLayout();
00227     void RemoveCompositionLayout();
00228 
00235     bool IsFullRedraw() const;
00236 
00237     virtual void GeometryChangePending ();
00238     virtual void GeometryChanged ();
00239 
00240     virtual Area* FindAreaUnderMouse(const Point& mouse_position, NuxEventType event_type);
00241 
00242     virtual Area* FindKeyFocusArea(unsigned int key_symbol,
00243                           unsigned long x11_key_code,
00244                           unsigned long special_keys_state);
00245 
00246     Layout *m_CompositionLayout;
00247 
00248     bool _need_redraw; //<! The rendering of the view needs to be refreshed.
00249 
00250     bool _full_redraw; //<! True if Draw is called before ContentDraw. It is read-only and can be accessed by calling IsFullRedraw();
00251 
00252     bool _is_active; 
00253 
00254     bool _can_pass_focus_to_composite_layout; //<! Enable this and keynav will pass focus to your composite layout
00255 
00256   private:
00257     bool m_UseStyleDrawing;
00258     bool _is_view_active;
00259 
00260     friend class WindowCompositor;
00261     friend class Layout;
00262     friend class Area;
00263     friend class LayeredLayout;
00264   };
00265 
00266 }
00267 
00268 #endif // ABSTRACTOBJECTBASE_H
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends