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"
26 FL_OBJECT * figinset_canvas;
32 XSync(fl_get_display(), 0);
36 WorkArea::WorkArea(BufferView * o, int xpos, int ypos, int width, int height)
37 : owner(o), workareapixmap(0)
42 fl_freeze_all_forms();
46 lyxerr << "Creating work area: +"
47 << xpos << '+' << ypos << ' '
48 << width << 'x' << height << endl;
51 const int bw = int(abs(float(fl_get_border_width())));
53 // We really want to get rid of figinset_canvas.
54 ::figinset_canvas = figinset_canvas = obj =
55 fl_add_canvas(FL_NORMAL_CANVAS,
56 xpos + 1, ypos + 1, 1, 1, "");
57 fl_set_object_boxtype(obj, FL_NO_BOX);
58 fl_set_object_resize(obj, FL_RESIZE_ALL);
59 fl_set_object_gravity(obj, NorthWestGravity, NorthWestGravity);
62 lyxerr << "\tbackground box: +"
63 << xpos << '+' << ypos << ' '
64 << width - 15 << 'x' << height << endl;
65 backgroundbox = obj = fl_add_box(FL_BORDER_BOX,
69 fl_set_object_resize(obj, FL_RESIZE_ALL);
70 fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
76 // up - scrollbar button
77 fl_set_border_width(-1);
79 lyxerr << "\tup button: +"
80 << xpos + width - 15 << '+' << ypos << ' '
81 << 15 << 'x' << 15 << endl;
82 button_up = obj = fl_add_pixmapbutton(FL_TOUCH_BUTTON,
86 fl_set_object_boxtype(obj,FL_UP_BOX);
87 fl_set_object_color(obj,FL_MCOL,FL_BLUE);
88 fl_set_object_resize(obj, FL_RESIZE_ALL);
89 fl_set_object_gravity(obj,NorthEastGravity, NorthEastGravity);
91 fl_set_object_callback(obj,up_cb, 0);
92 fl_set_pixmapbutton_data(obj, const_cast<char**>(up_xpm));
94 // Remove the blue feedback rectangle
95 fl_set_pixmapbutton_focus_outline(obj,0);
97 // the scrollbar slider
98 fl_set_border_width(-bw);
99 lyxerr << "\tscrollbar slider: +"
100 << xpos + width - 15 << '+' << ypos + 15 << ' '
101 << 15 << 'x' << height - 30 << endl;
102 scrollbar = obj = fl_add_slider(FL_VERT_SLIDER,
105 15, height - 30, "");
106 fl_set_object_color(obj,FL_COL1,FL_MCOL);
107 fl_set_object_boxtype(obj, FL_UP_BOX);
108 fl_set_object_resize(obj, FL_RESIZE_ALL);
109 fl_set_object_gravity(obj, NorthEastGravity, SouthEastGravity);
111 fl_set_object_callback(obj, scroll_cb, 0);
112 fl_set_slider_precision(obj, 0);
114 // down - scrollbar button
115 fl_set_border_width(-1);
117 lyxerr << "\tdown button: +"
118 << xpos + width - 15 << '+' << ypos + height - 15 << ' '
119 << 15 << 'x' << 15 << endl;
120 button_down = obj = fl_add_pixmapbutton(FL_TOUCH_BUTTON,
124 fl_set_object_boxtype(obj,FL_UP_BOX);
125 fl_set_object_color(obj,FL_MCOL,FL_BLUE);
126 fl_set_object_resize(obj, FL_RESIZE_ALL);
127 fl_set_object_gravity(obj, SouthEastGravity, SouthEastGravity);
129 fl_set_object_callback(obj, down_cb, 0);
130 fl_set_pixmapbutton_data(obj, const_cast<char**>(down_xpm));
132 fl_set_border_width(-bw);
134 // Remove the blue feedback rectangle
135 fl_set_pixmapbutton_focus_outline(obj,0);
140 // Create the workarea pixmap
141 createPixmap(width - 15 - 2 * bw, height - 2 * bw);
144 painter_.setDisplay(fl_display);
145 painter_.setDrawable(workareapixmap);
148 // We add this object as late as possible to avoit problems
150 lyxerr << "\tfree object: +"
151 << xpos + bw << '+' << ypos + bw << ' '
152 << width - 15 - 2 * bw << 'x' << height - 2 * bw << endl;
153 work_area = obj = fl_add_free(FL_INPUT_FREE,
154 xpos + bw, ypos + bw,
155 width - 15 - 2 * bw, // scrollbarwidth
158 obj->wantkey = FL_KEY_TAB;
159 obj->u_vdata = this; /* This is how we pass the WorkArea
160 to the work_area_handler. */
161 fl_set_object_boxtype(obj,FL_DOWN_BOX);
162 fl_set_object_resize(obj, FL_RESIZE_ALL);
163 fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
165 fl_unfreeze_all_forms();
169 WorkArea::~WorkArea()
172 XFreePixmap(fl_display, workareapixmap);
176 void WorkArea::resize(int xpos, int ypos, int width, int height)
178 fl_freeze_all_forms();
180 const int bw = int(abs(float(fl_get_border_width())));
183 fl_set_object_geometry(backgroundbox, xpos, ypos, width - 15, height);
189 // up - scrollbar button
190 fl_set_object_geometry(button_up, xpos + width - 15,
193 // the scrollbar slider
194 fl_set_object_geometry(scrollbar, xpos + width - 15,
197 // down - scrollbar button
198 fl_set_object_geometry(button_down, xpos + width - 15,
202 // Create the workarea pixmap
203 createPixmap(width - 15 - 2 * bw, height - 2 * bw);
207 painter_.setDrawable(workareapixmap);
211 fl_set_object_geometry(work_area, xpos + bw, ypos + bw,
215 fl_unfreeze_all_forms();
220 void WorkArea::createPixmap(int width, int height)
222 static int cur_width = -1;
223 static int cur_height = -1;
225 if (cur_width == width && cur_height == height && workareapixmap)
232 XFreePixmap(fl_display, workareapixmap);
234 lyxerr << "Creating pixmap (" << width << 'x' << height << ")" << endl;
236 workareapixmap = XCreatePixmap(fl_display,
237 RootWindow(fl_display, 0),
240 fl_get_visual_depth());
241 lyxerr << "\tpixmap=" << workareapixmap << endl;
245 void WorkArea::greyOut() const
247 fl_winset(FL_ObjWin(work_area));
248 fl_rectangle(1, work_area->x, work_area->y,
249 work_area->w, work_area->h, FL_GRAY63);
253 void WorkArea::setFocus() const
255 fl_set_focus_object(work_area->form, work_area);
259 void WorkArea::setScrollbar(double pos, double length_fraction) const
261 fl_set_slider_value(scrollbar, pos);
262 fl_set_slider_size(scrollbar, scrollbar->h * length_fraction);
266 void WorkArea::setScrollbarBounds(double l1, double l2) const
268 fl_set_slider_bounds(scrollbar, l1, l2);
272 void WorkArea::setScrollbarIncrements(float inc) const
274 fl_set_slider_increment(scrollbar, work_area->h - inc, inc);
278 void WorkArea::up_cb(FL_OBJECT * ob, long)
280 WorkArea * area = static_cast<WorkArea*>(ob->u_vdata);
281 XEvent const * ev2 = fl_last_event();
282 static long time = 0;
283 ev2 = fl_last_event();
284 if (ev2->type == ButtonPress || ev2->type == ButtonRelease)
286 //area->up(time++, fl_get_button_numb(ob));
287 area->owner->UpCB(time++, fl_get_button_numb(ob));
291 void WorkArea::down_cb(FL_OBJECT * ob, long)
293 WorkArea * area = static_cast<WorkArea*>(ob->u_vdata);
294 XEvent const * ev2 = fl_last_event();
295 static long time = 0;
296 if (ev2->type == ButtonPress || ev2->type == ButtonRelease)
298 //area->down(time++, fl_get_button_numb(ob));
299 area->owner->DownCB(time++, fl_get_button_numb(ob));
303 // Callback for scrollbar slider
304 void WorkArea::scroll_cb(FL_OBJECT * ob, long)
306 WorkArea * area = static_cast<WorkArea*>(ob->u_vdata);
308 //area->scroll(fl_get_slider_value(ob));
309 area->owner->ScrollCB(fl_get_slider_value(ob));
313 bool Lgb_bug_find_hack = false;
315 int WorkArea::work_area_handler(FL_OBJECT * ob, int event,
317 int /*key*/, void * xev)
319 static int x_old = -1;
320 static int y_old = -1;
321 static long scrollbar_value_old = -1;
323 XEvent * ev = static_cast<XEvent*>(xev);
324 WorkArea * area = static_cast<WorkArea*>(ob->u_vdata);
330 if (!area->work_area ||
331 !area->work_area->form->visible)
333 lyxerr.debug() << "Workarea event: DRAW" << endl;
334 area->createPixmap(area->workWidth(), area->height());
335 Lgb_bug_find_hack = true;
337 area->owner->workAreaExpose();
338 Lgb_bug_find_hack = false;
342 // Should really have used xbutton.state
343 lyxerr.debug() << "Workarea event: PUSH" << endl;
344 //area->buttonPress(ev->xbutton.x - ob->x,
345 // ev->xbutton.y - ob->y,
346 // ev->xbutton.button);
347 area->owner->WorkAreaButtonPress(ev->xbutton.x - ob->x,
348 ev->xbutton.y - ob->y,
353 // Should really have used xbutton.state
354 lyxerr.debug() << "Workarea event: RELEASE" << endl;
355 //area->buttonRelease(ev->xbutton.x - ob->x,
356 // ev->xbutton.y - ob->y,
357 // ev->xbutton.button);
358 area->owner->WorkAreaButtonRelease(ev->xbutton.x - ob->x,
359 ev->xbutton.y - ob->y,
363 if (!ev || ! area->scrollbar) break;
364 if (ev->xmotion.x != x_old ||
365 ev->xmotion.y != y_old ||
366 fl_get_slider_value(area->scrollbar) != scrollbar_value_old) {
367 lyxerr.debug() << "Workarea event: MOUSE" << endl;
368 //area->motion(ev->xmotion.x - ob->x,
369 // ev->xmotion.y - ob->y,
370 // ev->xbutton.state);
371 area->owner->WorkAreaMotionNotify(ev->xmotion.x - ob->x,
372 ev->xmotion.y - ob->y,
376 // Done by the raw callback:
377 // case FL_KEYBOARD: WorkAreaKeyPress(ob, 0,0,0,ev,0); break;
379 lyxerr.debug() << "Workarea event: FOCUS" << endl;
383 lyxerr.debug() << "Workarea event: UNFOCUS" << endl;
387 lyxerr.debug() << "Workarea event: ENTER" << endl;
391 lyxerr.debug() << "Workarea event: LEAVE" << endl;
396 lyxerr.debug() << "Workarea event: DBLCLICK" << endl;;
397 //area->doubleclick(ev->xbutton.x,
399 // ev->xbutton.button);
403 lyxerr.debug() << "Workarea event: TRPLCLICK" << endl;
404 //area->trippleclick(ev->xbutton.x,
406 // ev->xbutton.button);
410 if (ev->type == SelectionNotify) {
411 lyxerr.debug() << "Workarea event: SELECTION" << endl;
412 //area->selection(area->work_area->form->window, ev);
413 area->owner->WorkAreaSelectionNotify(area->work_area->form->window, ev);
415 lyxerr.debug() << "Workarea event: OTHER" << endl;