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 BufferView * current_view;
15 FD_form_bullet * fd_form_bullet;
17 static int current_bullet_panel;
18 static int current_bullet_depth;
20 /** Creates or raises the bullet popup and sets appropriate form values
24 if (!fd_form_bullet) {
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."),
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,
41 if (updateBulletForm()) {
43 if (fd_form_bullet->form_bullet->visible) {
44 fl_raise_form(fd_form_bullet->form_bullet);
47 fl_show_form(fd_form_bullet->form_bullet,
48 FL_PLACE_MOUSE, FL_FULLBORDER,
49 _("Itemize Bullet Selection"));
54 bool updateBulletForm()
57 if (!fd_form_bullet) {
60 if (!current_view->available()) {
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);
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);
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);
92 if (fd_form_bullet->form_bullet->visible) {
93 fl_hide_form(fd_form_bullet->form_bullet);
99 /*---------------------------------------*/
100 /* callbacks for form form_bullet */
102 void BulletOKCB(FL_OBJECT *ob, long data)
104 BulletApplyCB(ob, data);
105 BulletCancelCB(ob, data);
109 void BulletApplyCB(FL_OBJECT * /*ob*/, long /*data*/ )
111 // update the bullet settings
112 BufferParams & param = current_view->buffer()->params;
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();
123 void BulletCancelCB(FL_OBJECT * /*ob*/, long /*data*/ )
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];
135 void InputBulletLaTeXCB(FL_OBJECT *, long)
137 // fill-in code for callback
138 BufferParams & param = current_view->buffer()->params;
140 param.temp_bullets[current_bullet_depth].setText(
141 fl_get_input(fd_form_bullet->input_bullet_latex));
145 void ChoiceBulletSizeCB(FL_OBJECT * ob, long /*data*/ )
147 BufferParams & param = current_view->buffer()->params;
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());
156 void BulletDepthCB(FL_OBJECT * ob, long data)
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 */
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;
168 switch (fl_get_button_numb(ob)) {
170 // right mouse button resets to default
171 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
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);
182 void BulletPanelCB(FL_OBJECT * /*ob*/, long data)
184 /* Here we have to change the background pixmap to that selected */
185 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
187 if (data != current_bullet_panel) {
188 fl_freeze_form(fd_form_bullet->form_bullet);
189 current_bullet_panel = data;
191 /* free the current pixmap */
192 fl_free_bmtable_pixmap(fd_form_bullet->bmtable_bullet_panel);
195 /* display the new one */
197 new_panel = "standard";
200 new_panel = "amssymb";
203 new_panel = "psnfss1";
206 new_panel = "psnfss2";
209 new_panel = "psnfss3";
212 new_panel = "psnfss4";
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";
221 fl_set_bmtable_pixmap_file(fd_form_bullet->bmtable_bullet_panel,
223 LibFileSearch("images", new_panel,
225 fl_redraw_object(fd_form_bullet->bmtable_bullet_panel);
226 fl_unfreeze_form(fd_form_bullet->form_bullet);
231 void BulletBMTableCB(FL_OBJECT *ob, long /*data*/ )
233 /* handle the user input by setting the current bullet depth's pixmap */
234 /* to that extracted from the current chosen position of the BMTable */
235 /* Don't forget to free the button's old pixmap first. */
237 BufferParams & param = current_view->buffer()->params;
238 int bmtable_button = fl_get_bmtable(ob);
240 /* try to keep the button held down till another is pushed */
241 /* fl_set_bmtable(ob, 1, bmtable_button); */
242 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
243 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
244 fl_set_input(fd_form_bullet->input_bullet_latex,
245 param.temp_bullets[current_bullet_depth].c_str());