This commit was manufactured by cvs2svn to create tag
[lyx.git] / src / bullet_forms_cb.C
blob04954de7aabfa7d91e64c820c87f899f2abd6493
1 /* Bullet form callbacks */
2 #include <config.h>
3 #include <cstdlib>
4 #include FORMS_H_LOCATION
5 #include XPM_H_LOCATION
6 #include "bullet_forms.h"
7 #include "bmtable.h"
8 #include "buffer.h"
9 #include "bufferparams.h"
10 #include "support/filetools.h"
11 #include "gettext.h"
12 #include "lyx_gui_misc.h" // CancelCloseBoxCB + WriteAlert
14 extern int mono_video;
15 extern BufferView *current_view;
16 FD_form_bullet *fd_form_bullet;
18 static int current_bullet_panel;
19 static int current_bullet_depth;
21 /** Creates or raises the bullet popup and sets appropriate form values
22   */
23 void bulletForm()
25         if (!fd_form_bullet) {
26                 if (!mono_video 
27                     && (XpmVersion < 4
28                         || (XpmVersion == 4 && XpmRevision < 7))) {
29                         WriteAlert(_("Sorry, your libXpm is too old."),
30                         _("This feature requires xpm-4.7 (a.k.a 3.4g) or newer."),
31                         _("Try running LyX in mono mode (lyx  -Mono)."));
32                         return;
33                 }
34                 fd_form_bullet = create_form_form_bullet();
35                 fl_addto_choice(fd_form_bullet->choice_bullet_size,
36                                 _(" default | tiny | script | footnote | small |"
37                                 " normal | large | Large | LARGE | huge | Huge"));
38                 fl_set_choice(fd_form_bullet->choice_bullet_size, 1);
39                 fl_set_form_atclose(fd_form_bullet->form_bullet,
40                                     CancelCloseBoxCB, 0);
41         }
43         if (updateBulletForm()) {
44                 // Show form
45                 if (fd_form_bullet->form_bullet->visible) {
46                         fl_raise_form(fd_form_bullet->form_bullet);
47                 }
48                 else {
49                         fl_show_form(fd_form_bullet->form_bullet,
50                                      FL_PLACE_MOUSE,FL_FULLBORDER,
51                                      _("Itemize Bullet Selection"));
52                 }
53         }
56 bool updateBulletForm()
58         bool update = true;
59         if (!fd_form_bullet) {
60                 return false;
61         }
62         if (!current_view->available()) {
63                 update = false;
64         } else if (current_view->currentBuffer()->isReadonly()
65                    || current_view->currentBuffer()->isLinuxDoc()) {
66                 fl_deactivate_object (fd_form_bullet->button_ok);
67                 fl_deactivate_object (fd_form_bullet->button_apply);
68                 fl_set_object_lcol (fd_form_bullet->button_ok, FL_INACTIVE);
69                 fl_set_object_lcol (fd_form_bullet->button_apply, FL_INACTIVE);
70                 fl_deactivate_object (fd_form_bullet->bmtable_bullet_panel);
71                 fl_deactivate_object (fd_form_bullet->choice_bullet_size);
72                 fl_deactivate_object (fd_form_bullet->input_bullet_latex);
73                 update = false;
74         } else {
75                 fl_activate_object (fd_form_bullet->button_ok);
76                 fl_activate_object (fd_form_bullet->button_apply);
77                 fl_set_object_lcol (fd_form_bullet->button_ok, FL_BLACK);
78                 fl_set_object_lcol (fd_form_bullet->button_apply, FL_BLACK);
79                 fl_activate_object (fd_form_bullet->bmtable_bullet_panel);
80                 fl_activate_object (fd_form_bullet->choice_bullet_size);
81                 fl_activate_object (fd_form_bullet->input_bullet_latex);
82         }
84         if (update) {
85                 // any settings that need doing each time
86                 fl_set_button(fd_form_bullet->radio_bullet_depth_1, 1);
87                 fl_set_input(fd_form_bullet->input_bullet_latex,
88                              current_view->currentBuffer()
89                              ->params.user_defined_bullets[0].c_str());
90                 fl_set_choice(fd_form_bullet->choice_bullet_size,
91                               current_view->currentBuffer()
92                               ->params.user_defined_bullets[0].getSize() + 2);
93         } else {
94                 if (fd_form_bullet->form_bullet->visible) {
95                         fl_hide_form(fd_form_bullet->form_bullet);
96                 }
97         }
98         return update;
101 /*---------------------------------------*/
102 /* callbacks for form form_bullet        */
104 void BulletOKCB(FL_OBJECT *ob, long data)
106         BulletApplyCB(ob, data);
107         BulletCancelCB(ob, data);
111 void BulletApplyCB(FL_OBJECT * /*ob*/, long /*data*/ )
113         /* update the bullet settings */
114         BufferParams & param = current_view->currentBuffer()->params;
116         // a little bit of loop unrolling
117         param.user_defined_bullets[0] = param.temp_bullets[0];
118         param.user_defined_bullets[1] = param.temp_bullets[1];
119         param.user_defined_bullets[2] = param.temp_bullets[2];
120         param.user_defined_bullets[3] = param.temp_bullets[3];
121         current_view->currentBuffer()->markDirty();
125 void BulletCancelCB(FL_OBJECT * /*ob*/, long /*data*/ )
127         fl_hide_form(fd_form_bullet->form_bullet);
128         // this avoids confusion when reopening
129         BufferParams & param = current_view->currentBuffer()->params;
130         param.temp_bullets[0] = param.user_defined_bullets[0];
131         param.temp_bullets[1] = param.user_defined_bullets[1];
132         param.temp_bullets[2] = param.user_defined_bullets[2];
133         param.temp_bullets[3] = param.user_defined_bullets[3];
137 void InputBulletLaTeXCB(FL_OBJECT *, long)
139   /* fill-in code for callback */
140         BufferParams & param = current_view->currentBuffer()->params;
142         param.temp_bullets[current_bullet_depth].setText(
143                 fl_get_input(fd_form_bullet->input_bullet_latex));
147 void ChoiceBulletSizeCB(FL_OBJECT * ob, long /*data*/ )
149         BufferParams & param = current_view->currentBuffer()->params;
151         // convert from 1-6 range to -1-4 
152         param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
153         fl_set_input(fd_form_bullet->input_bullet_latex,
154                                  param.temp_bullets[current_bullet_depth].c_str());
158 void BulletDepthCB(FL_OBJECT *ob, long data)
160         /* Should I do the following:                                 */
161         /*  1. change to the panel that the current bullet belongs in */
162         /*  2. show that bullet as selected                           */
163         /*  3. change the size setting to the size of the bullet in Q.*/
164         /*  4. display the latex equivalent in the latex box          */
165         /*                                                            */
166         /* I'm inclined to just go with 3 and 4 at the moment and     */
167         /* maybe try to support the others later                      */
168         BufferParams & param = current_view->currentBuffer()->params;
170         switch (fl_get_button_numb(ob)) {
171         case 3:
172                 // right mouse button resets to default
173                 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
174         default:
175                 current_bullet_depth = data;
176                 fl_set_input(fd_form_bullet->input_bullet_latex,
177                              param.temp_bullets[data].c_str());
178                 fl_set_choice(fd_form_bullet->choice_bullet_size,
179                               param.temp_bullets[data].getSize() + 2);
180         }
184 void BulletPanelCB(FL_OBJECT * /*ob*/, long data)
186         /* Here we have to change the background pixmap to that selected */
187         /* by the user. (eg. standard.xpm, psnfss1.xpm etc...)           */
189         if (data != current_bullet_panel) {
190                 fl_freeze_form(fd_form_bullet->form_bullet);
191                 current_bullet_panel = data;
193                 /* free the current pixmap */
194                 fl_free_bmtable_pixmap(fd_form_bullet->bmtable_bullet_panel);
195                 string new_panel;
196                 switch (data) {
197                         /* display the new one */
198                 case 0 :
199                         new_panel = "standard";
200                         break;
201                 case 1 :
202                         new_panel = "amssymb";
203                         break;
204                 case 2 :
205                         new_panel = "psnfss1";
206                         break;
207                 case 3 :
208                         new_panel = "psnfss2";
209                         break;
210                 case 4 :
211                         new_panel = "psnfss3";
212                         break;
213                 case 5 :
214                         new_panel = "psnfss4";
215                         break;
216                 default :
217                         /* something very wrong happened */
218                         // play it safe for now but should be an exception
219                         current_bullet_panel = 0;  // standard panel
220                         new_panel = "standard";
221                         break;
222                 }
223                 if (mono_video) {
224                         new_panel += ".xbm";
225                         fl_set_bmtable_file(fd_form_bullet->bmtable_bullet_panel, 6, 6,
226                                LibFileSearch("images", new_panel.c_str()).c_str());
227                 }
228                 else {
229                         new_panel += ".xpm";
230                         fl_set_bmtable_pixmap_file(fd_form_bullet->bmtable_bullet_panel, 6, 6,
231                                LibFileSearch("images", new_panel.c_str()).c_str());
232                 }
233                 fl_redraw_object(fd_form_bullet->bmtable_bullet_panel);
234                 fl_unfreeze_form(fd_form_bullet->form_bullet);
235         }
239 void BulletBMTableCB(FL_OBJECT *ob, long /*data*/ )
241         /* handle the user input by setting the current bullet depth's pixmap */
242         /* to that extracted from the current chosen position of the BMTable  */
243         /* Don't forget to free the button's old pixmap first.                */
245         BufferParams & param = current_view->currentBuffer()->params;
246         int bmtable_button = fl_get_bmtable(ob);
248         /* try to keep the button held down till another is pushed */
249         /*  fl_set_bmtable(ob, 1, bmtable_button); */
250         param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
251         param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
252         fl_set_input(fd_form_bullet->input_bullet_latex,
253                      param.temp_bullets[current_bullet_depth].c_str());