nux-1.16.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     void SetViewActive (bool active);
00117 
00118   public:
00119     virtual void ProcessDraw (GraphicsEngine &GfxContext, bool force_draw);
00121 
00124     virtual void QueueDraw ();
00125 
00127     virtual void NeedSoftRedraw();
00128     virtual bool IsRedrawNeeded();
00129     virtual void DoneRedraw();
00130 
00131     virtual void OverlayDrawing (GraphicsEngine &GfxContext) {}
00132 
00133     //Layout Bridge
00134 
00135     bool SearchInAllSubNodes (Area *bo);
00136     bool SearchInFirstSubNodes (Area *bo);
00137 
00139     /*
00140         Set the Geometry of the View and the geometry of the Default Background Area.
00141         For simple interface control UI classes (RGBValuator...), this is enough.
00142         For others, they have to overwrite the function and do the appropriate computations
00143         for their component.
00144     */
00145     virtual void SetGeometry (const Geometry &geo);
00146 
00148     /*
00149         Return true if this object can break the layout, meaning, the layout can be done on the composition layout only without
00150         recomputing the whole window layout.
00151     */
00152     virtual bool CanBreakLayout()
00153     {
00154       return false;
00155     }
00156 
00157     virtual void SetTextColor(const Color &color);
00158     virtual Color GetTextColor();
00159 
00161 
00165     virtual Layout* GetLayout();
00166 
00168 
00172     virtual bool SetLayout (Layout *layout);
00173 
00174     sigc::signal<void, View*, Layout*> LayoutAdded;
00175     sigc::signal<void, View*, Layout*> LayoutRemoved;
00176 
00177     void SetFont(ObjectPtr<FontTexture> font);
00178     ObjectPtr<FontTexture> GetFont();
00179 
00180     sigc::signal<void, View*> OnQueueDraw;  
00181 
00182     virtual long ProcessFocusEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo);
00183     virtual void DoSetFocused (bool focused);
00184     virtual bool DoCanFocus ();
00185     virtual bool DoGetFocused ();
00186     void SetCanFocus (bool can_focus);
00187     void SetFocusControl (bool focus_control);
00188     bool HasFocusControl ();
00189 
00190     /*
00191         Returns true if the view has a layout and passes focus to that layout
00192     */
00193     bool HasPassiveFocus ();
00194 
00195     virtual Area* KeyNavIteration(KeyNavDirection direction);
00196     virtual bool AcceptKeyNavFocus();
00197 
00198     void IsHitDetectionSkipingChildren(bool skip_children);
00199 
00200 
00201   protected:
00202     bool _can_focus;
00203 
00204     void OnChildFocusChanged (/*Area *parent,*/ Area *child);
00205     sigc::connection _on_focus_changed_handler;
00206 
00207     // ProcessEvent is deprecated. 
00208     virtual long ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo) {return 0;}
00209 
00210     virtual void Draw (GraphicsEngine &GfxContext, bool force_draw) = 0;
00211     virtual void DrawContent (GraphicsEngine &GfxContext, bool force_draw);
00212     virtual void PostDraw (GraphicsEngine &GfxContext, bool force_draw);
00213 
00214     void DoMouseDownOutsideArea (int x, int y,unsigned long mousestate, unsigned long keystate);
00215 
00216     void InitializeWidgets();
00217     void InitializeLayout();
00218 
00219     Color m_TextColor;
00220     ObjectPtr<FontTexture> _font;
00221 
00223     virtual Layout* GetCompositionLayout();
00224 
00226     virtual bool SetCompositionLayout (Layout *layout);
00227 
00228     void RemoveLayout();
00229     void RemoveCompositionLayout();
00230 
00237     bool IsFullRedraw() const;
00238 
00239     virtual void GeometryChangePending ();
00240     virtual void GeometryChanged ();
00241 
00242     virtual Area* FindAreaUnderMouse(const Point& mouse_position, NuxEventType event_type);
00243 
00244     virtual Area* FindKeyFocusArea(unsigned int key_symbol,
00245                           unsigned long x11_key_code,
00246                           unsigned long special_keys_state);
00247 
00248     Layout *m_CompositionLayout;
00249 
00250     bool _need_redraw; //<! The rendering of the view needs to be refreshed.
00251 
00252     bool _full_redraw; //<! True if Draw is called before ContentDraw. It is read-only and can be accessed by calling IsFullRedraw();
00253 
00254     bool _is_active; 
00255 
00256     bool _can_pass_focus_to_composite_layout; //<! Enable this and keynav will pass focus to your composite layout
00257 
00258   private:
00259     bool m_UseStyleDrawing;
00260     bool _is_view_active;
00261 
00262     friend class WindowCompositor;
00263     friend class Layout;
00264     friend class Area;
00265     friend class LayeredLayout;
00266   };
00267 
00268 }
00269 
00270 #endif // ABSTRACTOBJECTBASE_H
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends