1 /* Bullet form callbacks */
4 #include FORMS_H_LOCATION
5 #include XPM_H_LOCATION
6 #include "bullet_forms.h"
9 #include "bufferparams.h"
10 #include "support/filetools.h"
12 #include "lyx_gui_misc.h" // CancelCloseBoxCB + WriteAlert
14 extern int mono_video;
16 extern BufferView * current_view;
17 FD_form_bullet * fd_form_bullet;
19 static int current_bullet_panel;
20 static int current_bullet_depth;
22 /** Creates or raises the bullet popup and sets appropriate form values
26 if (!fd_form_bullet) {
29 || (XpmVersion == 4 && XpmRevision < 7))) {
30 WriteAlert(_("Sorry, your libXpm is too old."),
31 _("This feature requires xpm-4.7 (a.k.a 3.4g) or newer."),
32 _("Try running LyX in mono mode (lyx -Mono)."));
35 fd_form_bullet = create_form_form_bullet();
36 fl_addto_choice(fd_form_bullet->choice_bullet_size,
37 _(" default | tiny | script | footnote | small |"
38 " normal | large | Large | LARGE | huge | Huge"));
39 fl_set_choice(fd_form_bullet->choice_bullet_size, 1);
40 fl_set_form_atclose(fd_form_bullet->form_bullet,
44 if (updateBulletForm()) {
46 if (fd_form_bullet->form_bullet->visible) {
47 fl_raise_form(fd_form_bullet->form_bullet);
50 fl_show_form(fd_form_bullet->form_bullet,
51 FL_PLACE_MOUSE, FL_FULLBORDER,
52 _("Itemize Bullet Selection"));
57 bool updateBulletForm()
60 if (!fd_form_bullet) {
63 if (!current_view->available()) {
65 } else if (current_view->buffer()->isReadonly()
66 || current_view->buffer()->isLinuxDoc()) {
67 fl_deactivate_object (fd_form_bullet->button_ok);
68 fl_deactivate_object (fd_form_bullet->button_apply);
69 fl_set_object_lcol (fd_form_bullet->button_ok, FL_INACTIVE);
70 fl_set_object_lcol (fd_form_bullet->button_apply, FL_INACTIVE);
71 fl_deactivate_object (fd_form_bullet->bmtable_bullet_panel);
72 fl_deactivate_object (fd_form_bullet->choice_bullet_size);
73 fl_deactivate_object (fd_form_bullet->input_bullet_latex);
76 fl_activate_object (fd_form_bullet->button_ok);
77 fl_activate_object (fd_form_bullet->button_apply);
78 fl_set_object_lcol (fd_form_bullet->button_ok, FL_BLACK);
79 fl_set_object_lcol (fd_form_bullet->button_apply, FL_BLACK);
80 fl_activate_object (fd_form_bullet->bmtable_bullet_panel);
81 fl_activate_object (fd_form_bullet->choice_bullet_size);
82 fl_activate_object (fd_form_bullet->input_bullet_latex);
86 // any settings that need doing each time
87 fl_set_button(fd_form_bullet->radio_bullet_depth_1, 1);
88 fl_set_input(fd_form_bullet->input_bullet_latex,
89 current_view->buffer()
90 ->params.user_defined_bullets[0].c_str());
91 fl_set_choice(fd_form_bullet->choice_bullet_size,
92 current_view->buffer()
93 ->params.user_defined_bullets[0].getSize() + 2);
95 if (fd_form_bullet->form_bullet->visible) {
96 fl_hide_form(fd_form_bullet->form_bullet);
102 /*---------------------------------------*/
103 /* callbacks for form form_bullet */
105 void BulletOKCB(FL_OBJECT *ob, long data)
107 BulletApplyCB(ob, data);
108 BulletCancelCB(ob, data);
112 void BulletApplyCB(FL_OBJECT * /*ob*/, long /*data*/ )
114 // update the bullet settings
115 BufferParams & param = current_view->buffer()->params;
117 // a little bit of loop unrolling
118 param.user_defined_bullets[0] = param.temp_bullets[0];
119 param.user_defined_bullets[1] = param.temp_bullets[1];
120 param.user_defined_bullets[2] = param.temp_bullets[2];
121 param.user_defined_bullets[3] = param.temp_bullets[3];
122 current_view->buffer()->markDirty();
126 void BulletCancelCB(FL_OBJECT * /*ob*/, long /*data*/ )
128 fl_hide_form(fd_form_bullet->form_bullet);
129 // this avoids confusion when reopening
130 BufferParams & param = current_view->buffer()->params;
131 param.temp_bullets[0] = param.user_defined_bullets[0];
132 param.temp_bullets[1] = param.user_defined_bullets[1];
133 param.temp_bullets[2] = param.user_defined_bullets[2];
134 param.temp_bullets[3] = param.user_defined_bullets[3];
138 void InputBulletLaTeXCB(FL_OBJECT *, long)
140 // fill-in code for callback
141 BufferParams & param = current_view->buffer()->params;
143 param.temp_bullets[current_bullet_depth].setText(
144 fl_get_input(fd_form_bullet->input_bullet_latex));
148 void ChoiceBulletSizeCB(FL_OBJECT * ob, long /*data*/ )
150 BufferParams & param = current_view->buffer()->params;
152 // convert from 1-6 range to -1-4
153 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
154 fl_set_input(fd_form_bullet->input_bullet_latex,
155 param.temp_bullets[current_bullet_depth].c_str());
159 void BulletDepthCB(FL_OBJECT * ob, long data)
161 /* Should I do the following: */
162 /* 1. change to the panel that the current bullet belongs in */
163 /* 2. show that bullet as selected */
164 /* 3. change the size setting to the size of the bullet in Q.*/
165 /* 4. display the latex equivalent in the latex box */
167 /* I'm inclined to just go with 3 and 4 at the moment and */
168 /* maybe try to support the others later */
169 BufferParams & param = current_view->buffer()->params;
171 switch (fl_get_button_numb(ob)) {
173 // right mouse button resets to default
174 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
176 current_bullet_depth = data;
177 fl_set_input(fd_form_bullet->input_bullet_latex,
178 param.temp_bullets[data].c_str());
179 fl_set_choice(fd_form_bullet->choice_bullet_size,
180 param.temp_bullets[data].getSize() + 2);
185 void BulletPanelCB(FL_OBJECT * /*ob*/, long data)
187 /* Here we have to change the background pixmap to that selected */
188 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
190 if (data != current_bullet_panel) {
191 fl_freeze_form(fd_form_bullet->form_bullet);
192 current_bullet_panel = data;
194 /* free the current pixmap */
195 fl_free_bmtable_pixmap(fd_form_bullet->bmtable_bullet_panel);
198 /* display the new one */
200 new_panel = "standard";
203 new_panel = "amssymb";
206 new_panel = "psnfss1";
209 new_panel = "psnfss2";
212 new_panel = "psnfss3";
215 new_panel = "psnfss4";
218 /* something very wrong happened */
219 // play it safe for now but should be an exception
220 current_bullet_panel = 0; // standard panel
221 new_panel = "standard";
226 fl_set_bmtable_file(fd_form_bullet->bmtable_bullet_panel, 6, 6,
227 LibFileSearch("images", new_panel.c_str()).c_str());
230 fl_set_bmtable_pixmap_file(fd_form_bullet->bmtable_bullet_panel, 6, 6,
231 LibFileSearch("images", new_panel.c_str()).c_str());
233 fl_redraw_object(fd_form_bullet->bmtable_bullet_panel);
234 fl_unfreeze_form(fd_form_bullet->form_bullet);
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->buffer()->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());