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;
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
25 if (!fd_form_bullet) {
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)."));
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,
43 if (updateBulletForm()) {
45 if (fd_form_bullet->form_bullet->visible) {
46 fl_raise_form(fd_form_bullet->form_bullet);
49 fl_show_form(fd_form_bullet->form_bullet,
50 FL_PLACE_MOUSE,FL_FULLBORDER,
51 _("Itemize Bullet Selection"));
56 bool updateBulletForm()
59 if (!fd_form_bullet) {
62 if (!current_view->available()) {
64 } else if (current_view->buffer()->isReadonly()
65 || current_view->buffer()->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);
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);
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->buffer()
89 ->params.user_defined_bullets[0].c_str());
90 fl_set_choice(fd_form_bullet->choice_bullet_size,
91 current_view->buffer()
92 ->params.user_defined_bullets[0].getSize() + 2);
94 if (fd_form_bullet->form_bullet->visible) {
95 fl_hide_form(fd_form_bullet->form_bullet);
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->buffer()->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->buffer()->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->buffer()->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->buffer()->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->buffer()->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 */
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->buffer()->params;
170 switch (fl_get_button_numb(ob)) {
172 // right mouse button resets to default
173 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
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);
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);
197 /* display the new one */
199 new_panel = "standard";
202 new_panel = "amssymb";
205 new_panel = "psnfss1";
208 new_panel = "psnfss2";
211 new_panel = "psnfss3";
214 new_panel = "psnfss4";
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";
225 fl_set_bmtable_file(fd_form_bullet->bmtable_bullet_panel, 6, 6,
226 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());