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), painter_(*this)
64 fl_freeze_all_forms();
68 if (lyxerr.debugging())
69 lyxerr << "Creating work area: +"
70 << xpos << '+' << ypos << ' '
71 << width << 'x' << height << endl;
74 const int bw = int(abs(float(fl_get_border_width())));
76 // We really want to get rid of figinset_canvas.
77 ::figinset_canvas = figinset_canvas = obj =
78 fl_add_canvas(FL_NORMAL_CANVAS,
79 xpos + 1, ypos + 1, 1, 1, "");
80 fl_set_object_boxtype(obj, FL_NO_BOX);
81 fl_set_object_resize(obj, FL_RESIZE_ALL);
82 fl_set_object_gravity(obj, NorthWestGravity, NorthWestGravity);
85 if (lyxerr.debugging())
86 lyxerr << "\tbackground box: +"
87 << xpos << '+' << ypos << ' '
88 << width - 15 << 'x' << height << endl;
89 backgroundbox = obj = fl_add_box(FL_BORDER_BOX,
93 fl_set_object_resize(obj, FL_RESIZE_ALL);
94 fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
100 // up - scrollbar button
101 fl_set_border_width(-1);
103 if (lyxerr.debugging())
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);
125 if (lyxerr.debugging())
126 lyxerr << "\tscrollbar slider: +"
127 << xpos + width - 15 << '+' << ypos + 15 << ' '
128 << 15 << 'x' << height - 30 << endl;
129 scrollbar = obj = fl_add_slider(FL_VERT_SLIDER,
132 15, height - 30, "");
133 fl_set_object_color(obj,FL_COL1,FL_MCOL);
134 fl_set_object_boxtype(obj, FL_UP_BOX);
135 fl_set_object_resize(obj, FL_RESIZE_ALL);
136 fl_set_object_gravity(obj, NorthEastGravity, SouthEastGravity);
138 fl_set_object_callback(obj, C_WorkArea_scroll_cb, 0);
139 fl_set_slider_precision(obj, 0);
141 // down - scrollbar button
142 fl_set_border_width(-1);
144 if (lyxerr.debugging())
145 lyxerr << "\tdown button: +"
146 << xpos + width - 15 << '+'
147 << ypos + height - 15 << ' '
148 << 15 << 'x' << 15 << endl;
149 button_down = obj = fl_add_pixmapbutton(FL_TOUCH_BUTTON,
153 fl_set_object_boxtype(obj,FL_UP_BOX);
154 fl_set_object_color(obj,FL_MCOL,FL_BLUE);
155 fl_set_object_resize(obj, FL_RESIZE_ALL);
156 fl_set_object_gravity(obj, SouthEastGravity, SouthEastGravity);
158 fl_set_object_callback(obj, C_WorkArea_down_cb, 0);
159 fl_set_pixmapbutton_data(obj, const_cast<char**>(down_xpm));
161 fl_set_border_width(-bw);
163 // Remove the blue feedback rectangle
164 fl_set_pixmapbutton_focus_outline(obj,0);
169 // Create the workarea pixmap
170 createPixmap(width - 15 - 2 * bw, height - 2 * bw);
173 painter_.setDisplay(fl_display);
175 // We add this object as late as possible to avoit problems
177 if (lyxerr.debugging())
178 lyxerr << "\tfree object: +"
179 << xpos + bw << '+' << ypos + bw << ' '
180 << width - 15 - 2 * bw << 'x'
181 << height - 2 * bw << endl;
183 work_area = obj = fl_add_free(FL_INPUT_FREE,
184 xpos + bw, ypos + bw,
185 width - 15 - 2 * bw, // scrollbarwidth
187 C_WorkArea_work_area_handler);
188 obj->wantkey = FL_KEY_TAB;
189 obj->u_vdata = this; /* This is how we pass the WorkArea
190 to the work_area_handler. */
191 fl_set_object_boxtype(obj,FL_DOWN_BOX);
192 fl_set_object_resize(obj, FL_RESIZE_ALL);
193 fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
195 fl_unfreeze_all_forms();
199 WorkArea::~WorkArea()
202 XFreePixmap(fl_display, workareapixmap);
206 bool WorkArea::belowMouse() const
208 lyxerr << "Below mouse: " << work_area->belowmouse << endl;
209 return work_area->belowmouse;
213 void WorkArea::resize(int xpos, int ypos, int width, int height)
215 fl_freeze_all_forms();
217 const int bw = int(abs(float(fl_get_border_width())));
220 fl_set_object_geometry(backgroundbox, xpos, ypos, width - 15, height);
226 // up - scrollbar button
227 fl_set_object_geometry(button_up, xpos + width - 15,
230 // the scrollbar slider
231 fl_set_object_geometry(scrollbar, xpos + width - 15,
234 // down - scrollbar button
235 fl_set_object_geometry(button_down, xpos + width - 15,
239 // Create the workarea pixmap
240 createPixmap(width - 15 - 2 * bw, height - 2 * bw);
243 fl_set_object_geometry(work_area, xpos + bw, ypos + bw,
247 fl_unfreeze_all_forms();
252 void WorkArea::createPixmap(int width, int height)
254 static int cur_width = -1;
255 static int cur_height = -1;
257 if (cur_width == width && cur_height == height && workareapixmap)
264 XFreePixmap(fl_display, workareapixmap);
266 if (lyxerr.debugging())
267 lyxerr << "Creating pixmap ("
268 << width << 'x' << height << ")" << endl;
270 workareapixmap = XCreatePixmap(fl_display,
271 RootWindow(fl_display, 0),
274 fl_get_visual_depth());
275 if (lyxerr.debugging())
276 lyxerr << "\tpixmap=" << workareapixmap << endl;
280 void WorkArea::greyOut() const
282 fl_winset(FL_ObjWin(work_area));
283 fl_rectangle(1, work_area->x, work_area->y,
284 work_area->w, work_area->h, FL_GRAY63);
288 void WorkArea::setFocus() const
290 fl_set_focus_object(work_area->form, work_area);
294 void WorkArea::setScrollbar(double pos, double length_fraction) const
296 fl_set_slider_value(scrollbar, pos);
297 fl_set_slider_size(scrollbar, scrollbar->h * length_fraction);
301 void WorkArea::setScrollbarBounds(double l1, double l2) const
303 fl_set_slider_bounds(scrollbar, l1, l2);
307 void WorkArea::setScrollbarIncrements(float inc) const
309 fl_set_slider_increment(scrollbar, work_area->h - inc, inc);
313 void WorkArea::up_cb(FL_OBJECT * ob, long)
315 WorkArea * area = static_cast<WorkArea*>(ob->u_vdata);
316 XEvent const * ev2 = fl_last_event();
317 static long time = 0;
318 ev2 = fl_last_event();
319 if (ev2->type == ButtonPress || ev2->type == ButtonRelease)
321 //area->up(time++, fl_get_button_numb(ob));
322 area->owner->upCB(time++, fl_get_button_numb(ob));
326 void WorkArea::down_cb(FL_OBJECT * ob, long)
328 WorkArea * area = static_cast<WorkArea*>(ob->u_vdata);
329 XEvent const * ev2 = fl_last_event();
330 static long time = 0;
331 if (ev2->type == ButtonPress || ev2->type == ButtonRelease)
333 //area->down(time++, fl_get_button_numb(ob));
334 area->owner->downCB(time++, fl_get_button_numb(ob));
338 // Callback for scrollbar slider
339 void WorkArea::scroll_cb(FL_OBJECT * ob, long)
341 WorkArea * area = static_cast<WorkArea*>(ob->u_vdata);
343 //area->scroll(fl_get_slider_value(ob));
344 area->owner->scrollCB(fl_get_slider_value(ob));
348 bool Lgb_bug_find_hack = false;
350 int WorkArea::work_area_handler(FL_OBJECT * ob, int event,
352 int /*key*/, void * xev)
354 static int x_old = -1;
355 static int y_old = -1;
356 static long scrollbar_value_old = -1;
358 XEvent * ev = static_cast<XEvent*>(xev);
359 WorkArea * area = static_cast<WorkArea*>(ob->u_vdata);
365 if (!area->work_area ||
366 !area->work_area->form->visible)
368 lyxerr.debug() << "Workarea event: DRAW" << endl;
369 area->createPixmap(area->workWidth(), area->height());
370 Lgb_bug_find_hack = true;
371 area->owner->workAreaExpose();
372 Lgb_bug_find_hack = false;
376 // Should really have used xbutton.state
377 lyxerr.debug() << "Workarea event: PUSH" << endl;
378 area->owner->workAreaButtonPress(ev->xbutton.x - ob->x,
379 ev->xbutton.y - ob->y,
384 // Should really have used xbutton.state
385 lyxerr.debug() << "Workarea event: RELEASE" << endl;
386 area->owner->workAreaButtonRelease(ev->xbutton.x - ob->x,
387 ev->xbutton.y - ob->y,
391 if (!ev || ! area->scrollbar) break;
392 if (ev->xmotion.x != x_old ||
393 ev->xmotion.y != y_old ||
394 fl_get_slider_value(area->scrollbar) != scrollbar_value_old) {
395 lyxerr.debug() << "Workarea event: MOUSE" << endl;
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;
407 lyxerr.debug() << "Workarea event: UNFOCUS" << endl;
410 lyxerr.debug() << "Workarea event: ENTER" << endl;
413 lyxerr.debug() << "Workarea event: LEAVE" << endl;
417 lyxerr.debug() << "Workarea event: DBLCLICK" << endl;
418 area->owner->doubleClick(ev->xbutton.x - ob->x,
419 ev->xbutton.y - ob->y,
424 lyxerr.debug() << "Workarea event: TRPLCLICK" << endl;
425 area->owner->tripleClick(ev->xbutton.x - ob->x,
426 ev->xbutton.y - ob->y,
431 if (ev->type == SelectionNotify) {
432 lyxerr.debug() << "Workarea event: SELECTION" << endl;
433 area->owner->workAreaSelectionNotify(area->work_area->form->window, ev);
435 lyxerr.debug() << "Workarea event: OTHER" << endl;