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
15 extern int mono_video;
18 extern BufferView * current_view;
19 FD_form_bullet * fd_form_bullet;
21 static int current_bullet_panel;
22 static int current_bullet_depth;
24 /** Creates or raises the bullet popup and sets appropriate form values
28 if (!fd_form_bullet) {
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)."));
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,
49 if (updateBulletForm()) {
51 if (fd_form_bullet->form_bullet->visible) {
52 fl_raise_form(fd_form_bullet->form_bullet);
55 fl_show_form(fd_form_bullet->form_bullet,
56 FL_PLACE_MOUSE, FL_FULLBORDER,
57 _("Itemize Bullet Selection"));
62 bool updateBulletForm()
65 if (!fd_form_bullet) {
68 if (!current_view->available()) {
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);
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);
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);
100 if (fd_form_bullet->form_bullet->visible) {
101 fl_hide_form(fd_form_bullet->form_bullet);
107 /*---------------------------------------*/
108 /* callbacks for form form_bullet */
110 void BulletOKCB(FL_OBJECT *ob, long data)
112 BulletApplyCB(ob, data);
113 BulletCancelCB(ob, data);
117 void BulletApplyCB(FL_OBJECT * /*ob*/, long /*data*/ )
119 // update the bullet settings
120 BufferParams & param = current_view->buffer()->params;
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();
131 void BulletCancelCB(FL_OBJECT * /*ob*/, long /*data*/ )
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];
143 void InputBulletLaTeXCB(FL_OBJECT *, long)
145 // fill-in code for callback
146 BufferParams & param = current_view->buffer()->params;
148 param.temp_bullets[current_bullet_depth].setText(
149 fl_get_input(fd_form_bullet->input_bullet_latex));
153 void ChoiceBulletSizeCB(FL_OBJECT * ob, long /*data*/ )
155 BufferParams & param = current_view->buffer()->params;
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());
164 void BulletDepthCB(FL_OBJECT * ob, long data)
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 */
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;
176 switch (fl_get_button_numb(ob)) {
178 // right mouse button resets to default
179 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
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);
190 void BulletPanelCB(FL_OBJECT * /*ob*/, long data)
192 /* Here we have to change the background pixmap to that selected */
193 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
195 if (data != current_bullet_panel) {
196 fl_freeze_form(fd_form_bullet->form_bullet);
197 current_bullet_panel = data;
199 /* free the current pixmap */
200 fl_free_bmtable_pixmap(fd_form_bullet->bmtable_bullet_panel);
203 /* display the new one */
205 new_panel = "standard";
208 new_panel = "amssymb";
211 new_panel = "psnfss1";
214 new_panel = "psnfss2";
217 new_panel = "psnfss3";
220 new_panel = "psnfss4";
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";
232 fl_set_bmtable_file(fd_form_bullet->bmtable_bullet_panel, 6, 6,
233 LibFileSearch("images", new_panel.c_str()).c_str());
237 fl_set_bmtable_pixmap_file(fd_form_bullet->bmtable_bullet_panel, 6, 6,
238 LibFileSearch("images", new_panel.c_str()).c_str());
242 fl_redraw_object(fd_form_bullet->bmtable_bullet_panel);
243 fl_unfreeze_form(fd_form_bullet->form_bullet);
248 void BulletBMTableCB(FL_OBJECT *ob, long /*data*/ )
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. */
254 BufferParams & param = current_view->buffer()->params;
255 int bmtable_button = fl_get_bmtable(ob);
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());