1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
15 #pragma implementation
22 #include "support/lstrings.h"
23 #include "BufferView.h"
25 FL_OBJECT * figinset_canvas;
30 XSync(fl_get_display(), 0);
34 // Just a bunch of C wrappers around static members of WorkArea
35 void C_WorkArea_up_cb(FL_OBJECT * ob, long buf)
37 WorkArea::up_cb(ob, buf);
40 void C_WorkArea_down_cb(FL_OBJECT * ob, long buf)
42 WorkArea::down_cb(ob, buf);
45 void C_WorkArea_scroll_cb(FL_OBJECT * ob, long buf)
47 WorkArea::scroll_cb(ob, buf);
50 int C_WorkArea_work_area_handler(FL_OBJECT * ob, int event,
54 return WorkArea::work_area_handler(ob, event,
61 WorkArea::WorkArea(BufferView * o, int xpos, int ypos, int width, int height)
62 : owner(o), workareapixmap(0)
67 fl_freeze_all_forms();
71 lyxerr << "Creating work area: +"
72 << xpos << '+' << ypos << ' '
73 << width << 'x' << height << endl;
76 const int bw = int(abs(float(fl_get_border_width())));
78 // We really want to get rid of figinset_canvas.
79 ::figinset_canvas = figinset_canvas = obj =
80 fl_add_canvas(FL_NORMAL_CANVAS,
81 xpos + 1, ypos + 1, 1, 1, "");
82 fl_set_object_boxtype(obj, FL_NO_BOX);
83 fl_set_object_resize(obj, FL_RESIZE_ALL);
84 fl_set_object_gravity(obj, NorthWestGravity, NorthWestGravity);
87 lyxerr << "\tbackground box: +"
88 << xpos << '+' << ypos << ' '
89 << width - 15 << 'x' << height << endl;
90 backgroundbox = obj = fl_add_box(FL_BORDER_BOX,
94 fl_set_object_resize(obj, FL_RESIZE_ALL);
95 fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
101 // up - scrollbar button
102 fl_set_border_width(-1);
104 lyxerr << "\tup button: +"
105 << xpos + width - 15 << '+' << ypos << ' '
106 << 15 << 'x' << 15 << endl;
107 button_up = obj = fl_add_pixmapbutton(FL_TOUCH_BUTTON,
111 fl_set_object_boxtype(obj,FL_UP_BOX);
112 fl_set_object_color(obj,FL_MCOL,FL_BLUE);
113 fl_set_object_resize(obj, FL_RESIZE_ALL);
114 fl_set_object_gravity(obj,NorthEastGravity, NorthEastGravity);
116 fl_set_object_callback(obj,C_WorkArea_up_cb, 0);
117 fl_set_pixmapbutton_data(obj, const_cast<char**>(up_xpm));
119 // Remove the blue feedback rectangle
120 fl_set_pixmapbutton_focus_outline(obj,0);
122 // the scrollbar slider
123 fl_set_border_width(-bw);
124 lyxerr << "\tscrollbar slider: +"
125 << xpos + width - 15 << '+' << ypos + 15 << ' '
126 << 15 << 'x' << height - 30 << endl;
127 scrollbar = obj = fl_add_slider(FL_VERT_SLIDER,
130 15, height - 30, "");
131 fl_set_object_color(obj,FL_COL1,FL_MCOL);
132 fl_set_object_boxtype(obj, FL_UP_BOX);
133 fl_set_object_resize(obj, FL_RESIZE_ALL);
134 fl_set_object_gravity(obj, NorthEastGravity, SouthEastGravity);
136 fl_set_object_callback(obj, C_WorkArea_scroll_cb, 0);
137 fl_set_slider_precision(obj, 0);
139 // down - scrollbar button
140 fl_set_border_width(-1);
142 lyxerr << "\tdown button: +"
143 << xpos + width - 15 << '+' << ypos + height - 15 << ' '
144 << 15 << 'x' << 15 << endl;
145 button_down = obj = fl_add_pixmapbutton(FL_TOUCH_BUTTON,
149 fl_set_object_boxtype(obj,FL_UP_BOX);
150 fl_set_object_color(obj,FL_MCOL,FL_BLUE);
151 fl_set_object_resize(obj, FL_RESIZE_ALL);
152 fl_set_object_gravity(obj, SouthEastGravity, SouthEastGravity);
154 fl_set_object_callback(obj, C_WorkArea_down_cb, 0);
155 fl_set_pixmapbutton_data(obj, const_cast<char**>(down_xpm));
157 fl_set_border_width(-bw);
159 // Remove the blue feedback rectangle
160 fl_set_pixmapbutton_focus_outline(obj,0);
165 // Create the workarea pixmap
166 createPixmap(width - 15 - 2 * bw, height - 2 * bw);
169 painter_.setDisplay(fl_display);
170 painter_.setDrawable(workareapixmap);
173 // We add this object as late as possible to avoit problems
175 lyxerr << "\tfree object: +"
176 << xpos + bw << '+' << ypos + bw << ' '
177 << width - 15 - 2 * bw << 'x' << height - 2 * bw << endl;
178 work_area = obj = fl_add_free(FL_INPUT_FREE,
179 xpos + bw, ypos + bw,
180 width - 15 - 2 * bw, // scrollbarwidth
182 C_WorkArea_work_area_handler);
183 obj->wantkey = FL_KEY_TAB;
184 obj->u_vdata = this; /* This is how we pass the WorkArea
185 to the work_area_handler. */
186 fl_set_object_boxtype(obj,FL_DOWN_BOX);
187 fl_set_object_resize(obj, FL_RESIZE_ALL);
188 fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
190 fl_unfreeze_all_forms();
194 WorkArea::~WorkArea()
197 XFreePixmap(fl_display, workareapixmap);
201 void WorkArea::resize(int xpos, int ypos, int width, int height)
203 fl_freeze_all_forms();
205 const int bw = int(abs(float(fl_get_border_width())));
208 fl_set_object_geometry(backgroundbox, xpos, ypos, width - 15, height);
214 // up - scrollbar button
215 fl_set_object_geometry(button_up, xpos + width - 15,
218 // the scrollbar slider
219 fl_set_object_geometry(scrollbar, xpos + width - 15,
222 // down - scrollbar button
223 fl_set_object_geometry(button_down, xpos + width - 15,
227 // Create the workarea pixmap
228 createPixmap(width - 15 - 2 * bw, height - 2 * bw);
232 painter_.setDrawable(workareapixmap);
236 fl_set_object_geometry(work_area, xpos + bw, ypos + bw,
240 fl_unfreeze_all_forms();
245 void WorkArea::createPixmap(int width, int height)
247 static int cur_width = -1;
248 static int cur_height = -1;
250 if (cur_width == width && cur_height == height && workareapixmap)
257 XFreePixmap(fl_display, workareapixmap);
259 lyxerr << "Creating pixmap (" << width << 'x' << height << ")" << endl;
261 workareapixmap = XCreatePixmap(fl_display,
262 RootWindow(fl_display, 0),
265 fl_get_visual_depth());
266 lyxerr << "\tpixmap=" << workareapixmap << endl;
270 void WorkArea::greyOut() const
272 fl_winset(FL_ObjWin(work_area));
273 fl_rectangle(1, work_area->x, work_area->y,
274 work_area->w, work_area->h, FL_GRAY63);
278 void WorkArea::setFocus() const
280 fl_set_focus_object(work_area->form, work_area);
284 void WorkArea::setScrollbar(double pos, double length_fraction) const
286 fl_set_slider_value(scrollbar, pos);
287 fl_set_slider_size(scrollbar, scrollbar->h * length_fraction);
291 void WorkArea::setScrollbarBounds(double l1, double l2) const
293 fl_set_slider_bounds(scrollbar, l1, l2);
297 void WorkArea::setScrollbarIncrements(float inc) const
299 fl_set_slider_increment(scrollbar, work_area->h - inc, inc);
303 void WorkArea::up_cb(FL_OBJECT * ob, long)
305 WorkArea * area = static_cast<WorkArea*>(ob->u_vdata);
306 XEvent const * ev2 = fl_last_event();
307 static long time = 0;
308 ev2 = fl_last_event();
309 if (ev2->type == ButtonPress || ev2->type == ButtonRelease)
311 //area->up(time++, fl_get_button_numb(ob));
312 area->owner->UpCB(time++, fl_get_button_numb(ob));
316 void WorkArea::down_cb(FL_OBJECT * ob, long)
318 WorkArea * area = static_cast<WorkArea*>(ob->u_vdata);
319 XEvent const * ev2 = fl_last_event();
320 static long time = 0;
321 if (ev2->type == ButtonPress || ev2->type == ButtonRelease)
323 //area->down(time++, fl_get_button_numb(ob));
324 area->owner->DownCB(time++, fl_get_button_numb(ob));
328 // Callback for scrollbar slider
329 void WorkArea::scroll_cb(FL_OBJECT * ob, long)
331 WorkArea * area = static_cast<WorkArea*>(ob->u_vdata);
333 //area->scroll(fl_get_slider_value(ob));
334 area->owner->ScrollCB(fl_get_slider_value(ob));
338 bool Lgb_bug_find_hack = false;
340 int WorkArea::work_area_handler(FL_OBJECT * ob, int event,
342 int /*key*/, void * xev)
344 static int x_old = -1;
345 static int y_old = -1;
346 static long scrollbar_value_old = -1;
348 XEvent * ev = static_cast<XEvent*>(xev);
349 WorkArea * area = static_cast<WorkArea*>(ob->u_vdata);
355 if (!area->work_area ||
356 !area->work_area->form->visible)
358 lyxerr.debug() << "Workarea event: DRAW" << endl;
359 area->createPixmap(area->workWidth(), area->height());
360 Lgb_bug_find_hack = true;
362 area->owner->workAreaExpose();
363 Lgb_bug_find_hack = false;
367 // Should really have used xbutton.state
368 lyxerr.debug() << "Workarea event: PUSH" << endl;
369 //area->buttonPress(ev->xbutton.x - ob->x,
370 // ev->xbutton.y - ob->y,
371 // ev->xbutton.button);
372 area->owner->WorkAreaButtonPress(ev->xbutton.x - ob->x,
373 ev->xbutton.y - ob->y,
378 // Should really have used xbutton.state
379 lyxerr.debug() << "Workarea event: RELEASE" << endl;
380 //area->buttonRelease(ev->xbutton.x - ob->x,
381 // ev->xbutton.y - ob->y,
382 // ev->xbutton.button);
383 area->owner->WorkAreaButtonRelease(ev->xbutton.x - ob->x,
384 ev->xbutton.y - ob->y,
388 if (!ev || ! area->scrollbar) break;
389 if (ev->xmotion.x != x_old ||
390 ev->xmotion.y != y_old ||
391 fl_get_slider_value(area->scrollbar) != scrollbar_value_old) {
392 lyxerr.debug() << "Workarea event: MOUSE" << endl;
393 //area->motion(ev->xmotion.x - ob->x,
394 // ev->xmotion.y - ob->y,
395 // ev->xbutton.state);
396 area->owner->WorkAreaMotionNotify(ev->xmotion.x - ob->x,
397 ev->xmotion.y - ob->y,
401 // Done by the raw callback:
402 // case FL_KEYBOARD: WorkAreaKeyPress(ob, 0,0,0,ev,0); break;
404 lyxerr.debug() << "Workarea event: FOCUS" << endl;
408 lyxerr.debug() << "Workarea event: UNFOCUS" << endl;
412 lyxerr.debug() << "Workarea event: ENTER" << endl;
416 lyxerr.debug() << "Workarea event: LEAVE" << endl;
421 lyxerr.debug() << "Workarea event: DBLCLICK" << endl;;
422 //area->doubleclick(ev->xbutton.x,
424 // ev->xbutton.button);
428 lyxerr.debug() << "Workarea event: TRPLCLICK" << endl;
429 //area->trippleclick(ev->xbutton.x,
431 // ev->xbutton.button);
435 if (ev->type == SelectionNotify) {
436 lyxerr.debug() << "Workarea event: SELECTION" << endl;
437 //area->selection(area->work_area->form->window, ev);
438 area->owner->WorkAreaSelectionNotify(area->work_area->form->window, ev);
440 lyxerr.debug() << "Workarea event: OTHER" << endl;