nux-1.16.0
TabView.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 TABVIEW_H
00024 #define TABVIEW_H
00025 
00026 #include "Nux.h"
00027 #include "View.h"
00028 #include "TimerProc.h"
00029 #include "HLayout.h"
00030 
00031 namespace nux
00032 {
00033 
00034   class TabView : public View
00035   {
00036   public:
00037     TabView (NUX_FILE_LINE_PROTO);
00038     ~TabView();
00039 
00040     virtual Area* FindAreaUnderMouse(const Point& mouse_position, NuxEventType event_type);
00041     virtual long ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo);
00042     virtual void Draw (GraphicsEngine &GfxContext, bool force_draw);
00043     virtual void DrawContent (GraphicsEngine &GfxContext, bool force_draw);
00044     virtual void PostDraw (GraphicsEngine &GfxContext, bool force_draw);
00045 
00046     void AddTab (const char *tab_name, Layout *tab_layout);
00047     void SetActiveTad (int index);
00049     /*
00050         Return true if this object can break the layout, meaning, the layout can be done on the composition layout only without
00051         recomputing the whole window layout.
00052         Inherited from View
00053     */
00054     virtual bool CanBreakLayout()
00055     {
00056       return false;
00057     }
00058 
00059     sigc::signal< void, TabView * > sigTabChanged;
00060     sigc::signal< void, int > sigTabIndexChanged;
00061 
00062 
00063   private:
00064     class TabElement
00065     {
00066     public:
00067       TabElement (NString TabName, Layout *TabLayout);
00068       ~TabElement();
00069 
00070       void SetIndex (int index);
00071       int GetIndex() const;
00072       void SetGeometry (const Geometry &geo);
00073       Geometry const& GetGeometry() const;
00074       const NString &GetName() const;
00075 
00076       NString     _tab_name;
00077       Layout     *_tab_content_layout;
00078       InputArea  *_tab_area;
00079       int         _index;
00080     };
00081 
00082   public:
00083     void RecvTabMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags, TabElement *);
00084     void RecvTabMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags, TabElement *);
00085 
00086     void RecvMouseEnter (int x, int y, unsigned long button_flags, unsigned long key_flags);
00087     void RecvMouseLeave (int x, int y, unsigned long button_flags, unsigned long key_flags);
00088 
00089   protected:
00090     virtual bool AcceptKeyNavFocus();
00091   private:
00092 
00093     void RecvTabRightTimerExpired (void *v);
00094     void RecvTabLeftTimerExpired (void *v);
00095     void RecvTabRightMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags);
00096     void RecvTabLeftMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags);
00097     void RecvTabButtonMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags);
00098 
00099     virtual void PreLayoutManagement();
00100     virtual long PostLayoutManagement (long LayoutResult);
00101     virtual void PositionChildLayout (float offsetX, float offsetY);
00102 
00103     void TranslateLeft (int x, int y, unsigned long button_flags, unsigned long key_flags);
00104     void TranslateRight (int x, int y, unsigned long button_flags, unsigned long key_flags);
00105     void TranslateTabLayout (int offset);
00106 
00107     InputArea   *_scroll_right;
00108     InputArea   *_scroll_left;
00109 
00110     Layout     *_visible_tab_content_layout;
00111     HLayout    *_tabview_heads_layout;
00112     HLayout    *_tabview_scroll_button_layout;
00113 
00114     int m_TabPositionOffset;
00115     int m_FocusTabIndex;
00116 
00117     TimerFunctor   *tabright_callback;
00118     TimerFunctor   *tableft_callback;
00119     TimerHandle     m_TabRightTimerHandler;
00120     TimerHandle     m_TabLeftTimerHandler;
00121 
00122     std::vector<TabElement *> _tab_array;
00123 
00124     static Color TAB_HEADER_BACKGROUND_COLOR;
00125     static Color TAB_BACKGROUND_COLOR;
00126     static Color TAB_HEADER_COLOR;
00127     static Color TAB_HEADER_FOCUS_COLOR;
00128 
00129     static int TAB_BUTTON_WIDTH;
00130     static int TAB_BUTTON_HEIGHT;
00131     static int TAB_HEIGHT;
00132     static int TAB_X_BORDER;
00133     static int TAB_Y_BORDER;
00134 
00135     // We need to draw the background on the previous size of the Table if its
00136     // size is set to match the content(IsSizeMatchContent) and an item is close.
00137     Geometry m_PreviousGeometry;
00138     bool m_DrawBackgroundOnPreviousGeometry;
00139   };
00140 }
00141 
00142 #endif // TABVIEW_H
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends