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