]> git.lyx.org Git - features.git/blob - src/toolbar.h
More cleanups of the toolbar. The buttons are now toggled/disabled when needed
[features.git] / src / toolbar.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ======================================================
4  * 
5  *           LyX, The Document Processor
6  *           Copyright 1995 Matthias Ettrich
7  *           Copyright 1995-2000 The LyX Team.
8  *
9  *           This file is Copyright 1996-2000
10  *           Lars Gullik Bjønnes
11  *
12  * ====================================================== */
13
14 #ifndef TOOLBAR_H
15 #define TOOLBAR_H
16
17 #ifdef __GNUG__
18 #pragma interface
19 #endif
20
21 #include <vector>
22 #include FORMS_H_LOCATION
23 #include "lyxfunc.h"
24 #include "combox.h"
25
26 /** The LyX toolbar class
27   This class {\em is} the LyX toolbar, and is not likely to be enhanced
28   further until we begin the move to Qt. We will probably have to make our
29   own QToolBar, at least until Troll Tech makes theirs.
30   */
31 class Toolbar {
32 public:
33         ///
34         Toolbar(LyXView * o, int x, int y);
35
36         ///
37         ~Toolbar() {
38                 clean();
39         }
40         
41         ///
42         int get_toolbar_func(string const & func);
43         
44         /// The special toolbar actions
45         enum  TOOLBARITEMS {
46                 /// adds space between buttons in the toolbar
47                 TOOL_SEPARATOR = -1,
48                 /// a special combox insead of a button
49                 TOOL_LAYOUTS = -2,
50                 /// begin a new line of button (not working)
51                 TOOL_NEWLINE = -3
52         };
53
54         ///
55         Combox * combox;
56
57         /// (re)sets the toolbar
58         void set(bool doingmain = false);
59
60         /** this is to be the entry point to the toolbar
61           frame, where you can change the toolbar realtime. */
62         void edit();
63         /// add a new button to the toolbar.
64         void add(int , bool doclean = true);
65         /// name of func instead of kb_action
66         void add(string const & , bool doclean = true);
67         /// invokes the n'th icon in the toolbar
68         void push(int);
69         /// activates the toolbar
70         void activate();
71         /// deactivates the toolbar
72         void deactivate();
73         /// update the state of the icons
74         void update();
75         ///
76         static void ToolbarCB(FL_OBJECT *, long);
77
78 #if FL_REVISION < 89
79         ///
80         static void BubbleTimerCB(FL_OBJECT *, long);
81         ///
82         static int BubblePost(FL_OBJECT * ob, int event,
83                               FL_Coord mx, FL_Coord my, int key, void * xev);
84 #endif
85
86 private:
87         ///
88         struct toolbarItem
89         {
90                 ///
91                 int action;
92                 ///
93                 FL_OBJECT * icon;
94                 ///
95                 toolbarItem() {
96                         action = LFUN_NOACTION;
97                         icon = 0;
98                 }
99                 ///
100                 void clean() {
101                         if (icon) {
102                                 fl_delete_object(icon);
103                                 fl_free_object(icon);
104                                 icon = 0;
105                         }
106                 }
107                 ///
108                 ~toolbarItem() {
109                         clean();
110                 }
111                         
112                 toolbarItem & operator=(const toolbarItem & ti) {
113                         // do we have to check icon and IsBitmap too?
114                         action = ti.action;
115                         icon = 0; // locally we need to get the icon anew
116
117                         return *this;
118                 }
119         };
120
121         /// typedef to simplify things
122         typedef std::vector<toolbarItem> ToolbarList;
123         /// The list containing all the buttons
124         ToolbarList toollist;
125         ///
126         LyXView * owner;
127 #if FL_REVISION < 89
128         ///
129         FL_OBJECT * bubble_timer;
130 #endif
131         /// Starting position
132         int sxpos, sypos;
133         ///
134         int xpos;
135         ///
136         int ypos;
137         ///
138         int buttonwidth;
139         ///
140         int height;
141         ///
142         int standardspacing;
143         ///
144         int sepspace;
145         ///
146         bool cleaned;
147
148         ///
149         char const ** getPixmap(kb_action, string const & arg = string());
150         /// removes all toolbar buttons from the toolbar.
151         void clean();
152
153         /** more...
154          */
155         void reset();// {
156 //              toollist = 0;
157 //              cleaned = false;
158 //              
159 //              lightReset();
160 //      }
161
162         /** more...
163          */
164         void lightReset() {
165                 standardspacing = 2; // the usual space between items
166                 sepspace = 6; // extra space
167                 xpos = sxpos - standardspacing;
168                 ypos = sypos;
169                 buttonwidth = 30; // the standard button width
170                 height = 30; // the height of all items in the toolbar
171         }
172 };
173 #endif