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