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 lyxerr << "Creating work area: +"
69 << xpos << '+' << ypos << ' '
70 << width << 'x' << height << endl;
73 const int bw = int(abs(float(fl_get_border_width())));
75 // We really want to get rid of figinset_canvas.
76 ::figinset_canvas = figinset_canvas = obj =
77 fl_add_canvas(FL_NORMAL_CANVAS,
78 xpos + 1, ypos + 1, 1, 1, "");
79 fl_set_object_boxtype(obj, FL_NO_BOX);
80 fl_set_object_resize(obj, FL_RESIZE_ALL);
81 fl_set_object_gravity(obj, NorthWestGravity, NorthWestGravity);
84 lyxerr << "\tbackground box: +"
85 << xpos << '+' << ypos << ' '
86 << width - 15 << 'x' << height << endl;
87 backgroundbox = obj = fl_add_box(FL_BORDER_BOX,
91 fl_set_object_resize(obj, FL_RESIZE_ALL);
92 fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
98 // up - scrollbar button
99 fl_set_border_width(-1);
101 lyxerr << "\tup button: +"
102 << xpos + width - 15 << '+' << ypos << ' '
103 << 15 << 'x' << 15 << endl;
104 button_up = obj = fl_add_pixmapbutton(FL_TOUCH_BUTTON,
108 fl_set_object_boxtype(obj,FL_UP_BOX);
109 fl_set_object_color(obj,FL_MCOL,FL_BLUE);
110 fl_set_object_resize(obj, FL_RESIZE_ALL);
111 fl_set_object_gravity(obj,NorthEastGravity, NorthEastGravity);
113 fl_set_object_callback(obj,C_WorkArea_up_cb, 0);
114 fl_set_pixmapbutton_data(obj, const_cast<char**>(up_xpm));
116 // Remove the blue feedback rectangle
117 fl_set_pixmapbutton_focus_outline(obj,0);
119 // the scrollbar slider
120 fl_set_border_width(-bw);
121 lyxerr << "\tscrollbar slider: +"
122 << xpos + width - 15 << '+' << ypos + 15 << ' '
123 << 15 << 'x' << height - 30 << endl;
124 scrollbar = obj = fl_add_slider(FL_VERT_SLIDER,
127 15, height - 30, "");
128 fl_set_object_color(obj,FL_COL1,FL_MCOL);
129 fl_set_object_boxtype(obj, FL_UP_BOX);
130 fl_set_object_resize(obj, FL_RESIZE_ALL);
131 fl_set_object_gravity(obj, NorthEastGravity, SouthEastGravity);
133 fl_set_object_callback(obj, C_WorkArea_scroll_cb, 0);
134 fl_set_slider_precision(obj, 0);
136 // down - scrollbar button
137 fl_set_border_width(-1);
139 lyxerr << "\tdown button: +"
140 << xpos + width - 15 << '+' << ypos + height - 15 << ' '
141 << 15 << 'x' << 15 << endl;
142 button_down = obj = fl_add_pixmapbutton(FL_TOUCH_BUTTON,
146 fl_set_object_boxtype(obj,FL_UP_BOX);
147 fl_set_object_color(obj,FL_MCOL,FL_BLUE);
148 fl_set_object_resize(obj, FL_RESIZE_ALL);
149 fl_set_object_gravity(obj, SouthEastGravity, SouthEastGravity);
151 fl_set_object_callback(obj, C_WorkArea_down_cb, 0);
152 fl_set_pixmapbutton_data(obj, const_cast<char**>(down_xpm));
154 fl_set_border_width(-bw);
156 // Remove the blue feedback rectangle
157 fl_set_pixmapbutton_focus_outline(obj,0);
162 // Create the workarea pixmap
163 createPixmap(width - 15 - 2 * bw, height - 2 * bw);
166 painter_.setDisplay(fl_display);
168 // We add this object as late as possible to avoit problems
170 lyxerr << "\tfree object: +"
171 << xpos + bw << '+' << ypos + bw << ' '
172 << width - 15 - 2 * bw << 'x' << height - 2 * bw << endl;
173 work_area = obj = fl_add_free(FL_INPUT_FREE,
174 xpos + bw, ypos + bw,
175 width - 15 - 2 * bw, // scrollbarwidth
177 C_WorkArea_work_area_handler);
178 obj->wantkey = FL_KEY_TAB;
179 obj->u_vdata = this; /* This is how we pass the WorkArea
180 to the work_area_handler. */
181 fl_set_object_boxtype(obj,FL_DOWN_BOX);
182 fl_set_object_resize(obj, FL_RESIZE_ALL);
183 fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
185 fl_unfreeze_all_forms();
189 WorkArea::~WorkArea()
192 XFreePixmap(fl_display, workareapixmap);
196 void WorkArea::resize(int xpos, int ypos, int width, int height)
198 fl_freeze_all_forms();
200 const int bw = int(abs(float(fl_get_border_width())));
203 fl_set_object_geometry(backgroundbox, xpos, ypos, width - 15, height);
209 // up - scrollbar button
210 fl_set_object_geometry(button_up, xpos + width - 15,
213 // the scrollbar slider
214 fl_set_object_geometry(scrollbar, xpos + width - 15,
217 // down - scrollbar button
218 fl_set_object_geometry(button_down, xpos + width - 15,
222 // Create the workarea pixmap
223 createPixmap(width - 15 - 2 * bw, height - 2 * bw);
226 fl_set_object_geometry(work_area, xpos + bw, ypos + bw,
230 fl_unfreeze_all_forms();
235 void WorkArea::createPixmap(int width, int height)
237 static int cur_width = -1;
238 static int cur_height = -1;
240 if (cur_width == width && cur_height == height && workareapixmap)
247 XFreePixmap(fl_display, workareapixmap);
249 lyxerr << "Creating pixmap (" << width << 'x' << height << ")" << endl;
251 workareapixmap = XCreatePixmap(fl_display,
252 RootWindow(fl_display, 0),
255 fl_get_visual_depth());
256 lyxerr << "\tpixmap=" << workareapixmap << endl;
260 void WorkArea::greyOut() const
262 fl_winset(FL_ObjWin(work_area));
263 fl_rectangle(1, work_area->x, work_area->y,
264 work_area->w, work_area->h, FL_GRAY63);
268 void WorkArea::setFocus() const
270 fl_set_focus_object(work_area->form, work_area);
274 void WorkArea::setScrollbar(double pos, double length_fraction) const
276 fl_set_slider_value(scrollbar, pos);
277 fl_set_slider_size(scrollbar, scrollbar->h * length_fraction);
281 void WorkArea::setScrollbarBounds(double l1, double l2) const
283 fl_set_slider_bounds(scrollbar, l1, l2);
287 void WorkArea::setScrollbarIncrements(float inc) const
289 fl_set_slider_increment(scrollbar, work_area->h - inc, inc);
293 void WorkArea::up_cb(FL_OBJECT * ob, long)
295 WorkArea * area = static_cast<WorkArea*>(ob->u_vdata);
296 XEvent const * ev2 = fl_last_event();
297 static long time = 0;
298 ev2 = fl_last_event();
299 if (ev2->type == ButtonPress || ev2->type == ButtonRelease)
301 //area->up(time++, fl_get_button_numb(ob));
302 area->owner->upCB(time++, fl_get_button_numb(ob));
306 void WorkArea::down_cb(FL_OBJECT * ob, long)
308 WorkArea * area = static_cast<WorkArea*>(ob->u_vdata);
309 XEvent const * ev2 = fl_last_event();
310 static long time = 0;
311 if (ev2->type == ButtonPress || ev2->type == ButtonRelease)
313 //area->down(time++, fl_get_button_numb(ob));
314 area->owner->downCB(time++, fl_get_button_numb(ob));
318 // Callback for scrollbar slider
319 void WorkArea::scroll_cb(FL_OBJECT * ob, long)
321 WorkArea * area = static_cast<WorkArea*>(ob->u_vdata);
323 //area->scroll(fl_get_slider_value(ob));
324 area->owner->scrollCB(fl_get_slider_value(ob));
328 bool Lgb_bug_find_hack = false;
330 int WorkArea::work_area_handler(FL_OBJECT * ob, int event,
332 int /*key*/, void * xev)
334 static int x_old = -1;
335 static int y_old = -1;
336 static long scrollbar_value_old = -1;
338 XEvent * ev = static_cast<XEvent*>(xev);
339 WorkArea * area = static_cast<WorkArea*>(ob->u_vdata);
345 if (!area->work_area ||
346 !area->work_area->form->visible)
348 lyxerr.debug() << "Workarea event: DRAW" << endl;
349 area->createPixmap(area->workWidth(), area->height());
350 Lgb_bug_find_hack = true;
351 area->owner->workAreaExpose();
352 Lgb_bug_find_hack = false;
356 // Should really have used xbutton.state
357 lyxerr.debug() << "Workarea event: PUSH" << endl;
358 area->owner->workAreaButtonPress(ev->xbutton.x - ob->x,
359 ev->xbutton.y - ob->y,
364 // Should really have used xbutton.state
365 lyxerr.debug() << "Workarea event: RELEASE" << endl;
366 area->owner->workAreaButtonRelease(ev->xbutton.x - ob->x,
367 ev->xbutton.y - ob->y,
371 if (!ev || ! area->scrollbar) break;
372 if (ev->xmotion.x != x_old ||
373 ev->xmotion.y != y_old ||
374 fl_get_slider_value(area->scrollbar) != scrollbar_value_old) {
375 lyxerr.debug() << "Workarea event: MOUSE" << endl;
376 area->owner->workAreaMotionNotify(ev->xmotion.x - ob->x,
377 ev->xmotion.y - ob->y,
381 // Done by the raw callback:
382 // case FL_KEYBOARD: WorkAreaKeyPress(ob, 0,0,0,ev,0); break;
384 lyxerr.debug() << "Workarea event: FOCUS" << endl;
387 lyxerr.debug() << "Workarea event: UNFOCUS" << endl;
390 lyxerr.debug() << "Workarea event: ENTER" << endl;
393 lyxerr.debug() << "Workarea event: LEAVE" << endl;
397 lyxerr.debug() << "Workarea event: DBLCLICK" << endl;
398 area->owner->doubleClick(ev->xbutton.x - ob->x,
399 ev->xbutton.y - ob->y,
404 lyxerr.debug() << "Workarea event: TRPLCLICK" << endl;
405 area->owner->trippleClick(ev->xbutton.x - ob->x,
406 ev->xbutton.y - ob->y,
411 if (ev->type == SelectionNotify) {
412 lyxerr.debug() << "Workarea event: SELECTION" << endl;
413 area->owner->workAreaSelectionNotify(area->work_area->form->window, ev);
415 lyxerr.debug() << "Workarea event: OTHER" << endl;