Back to index

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