summaryrefslogtreecommitdiffstats
path: root/fltk/fltk/TabGroup.h
blob: b6810f5e0825f17334361bb8449186cdb77f6ab3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//
// "$Id: TabGroup.h 5575 2007-01-02 17:31:40Z spitzak $"
//
// For making a "tabbed dialog box". Each child widget creates a tab.
// Only one is visible at a time. This works best if all the children
// have the same size and they don't cover a strip at the top for the
// tabs.
//
// Copyright 1998-2006 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
// Please report all bugs and problems to "fltk-bugs@fltk.org".
//

#ifndef fltk_TabGroup_h
#define fltk_TabGroup_h

#include "Group.h"

#define MIN_TABSIZE 30

namespace fltk {

class TabGroup;


enum {TAB_LEFT, TAB_RIGHT, TAB_SELECTED};

class FL_API TabGroupPager {
public:

    TabGroupPager() : shift_(0), border_(10), slope_(5), extra_space_(5),_noclip(false) {}
    
    /* Pager template methods definition */

    /*! this method must update the tab positions and width array, returns the selected tab    */
    virtual int update_positions(TabGroup* g, int numchildren, int& selected, 
	int& cumulated_width, int& available_width , int* tab_pos, int* tab_width) { return selected;}
    /*! draw the tabs for this custom pager, return false means no custom draw is made */
    virtual bool draw_tabs(TabGroup* g, int selected, int* tab_pos, int* tab_width) { return false;}
    /*! determine and return the index of the child group at the corresponding pos */
    virtual int which(TabGroup* g, int m_x,int m_y)=0;
    /*! virtual copy from a prototype */
    virtual TabGroupPager* clone() const=0;

    virtual const char * mode_name() const = 0;
    virtual int id() const = 0;

    /*! return max width available for drawing tab thumbnails */
    virtual int available_width(TabGroup *g ) const;

    // tab appearance
    int  border()	const {return border_;}
    int  slope()		const {return slope_;}
    int  extra_space()	const {return extra_space_;}
    void border(int v)	{border_=v;}
    void slope(int v)	{slope_=v;}
    void extra_space(int v) {extra_space_=v;}
    
    /*! shifting to nth+1 tab to draw, permit to 'keep' a position while 
	changing tabs and tab is in the interval
    */
    int  shift()	const {return shift_;}
    void shift(int v)	{shift_=v;}
    int spacing()	const {return slope_+extra_space_;}
    /*! determines if we forbid partial tabs drawing with clipping */
    void noclip(bool v) {_noclip=v;}
  
private:
    int shift_, border_, slope_, extra_space_;
    bool _noclip; 
  
};

// fltk default factory pagers
const int PAGER_MENU   = 0; //<-- two left and right buttons  provide prev page  and next page 
const int PAGER_SHRINK = 1; //<-- tabs outside rect are shrinked to very small slice to fit


class FL_API TabGroup : public Group {

public:
  int handle(int);

  TabGroup(int,int,int,int,const char * = 0, bool begin=false);
  ~TabGroup() {delete pager_;}
  static NamedStyle* default_style;

  int value() const;
  bool value(int);
  int which(int event_x, int event_y);
  Widget *selected_child();
  bool selected_child(Widget *);
  void set_draw_outline( bool draw_outline );
  
  //! setting the pager_ to a tabgroup, pager is _never_ null by design
  void pager(TabGroupPager * value);
  //! returning the current pager_ responsible of this instance
  TabGroupPager * pager() const {return pager_;}
  //! setting the default pager_ for future tabgroups, a default pager is _never_ null by design
  static void default_pager(TabGroupPager * v);
  //! setting the default pager_ from the built-in ones
  static void default_pager(int factory_pager_index);

  int tab_height();
  int tab_positions(int*, int*);

  void draw_tab(int x1, int x2, int W, int H, Widget* o, int sel=0);
  void draw_tab_background();

protected:
  void draw();

private:
  int push(Widget *);
  bool _drawOutline;
  TabGroupPager* pager_;
  static TabGroupPager* default_pager_;
};

}

#endif

//
// End of "$Id: TabGroup.h 5575 2007-01-02 17:31:40Z spitzak $".
//