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);
167 painter_.setDrawable(workareapixmap);
169 // We add this object as late as possible to avoit problems
171 lyxerr << "\tfree object: +"
172 << xpos + bw << '+' << ypos + bw << ' '
173 << width - 15 - 2 * bw << 'x' << height - 2 * bw << endl;
174 work_area = obj = fl_add_free(FL_INPUT_FREE,
175 xpos + bw, ypos + bw,
176 width - 15 - 2 * bw, // scrollbarwidth
178 C_WorkArea_work_area_handler);
179 obj->wantkey = FL_KEY_TAB;
180 obj->u_vdata = this; /* This is how we pass the WorkArea
181 to the work_area_handler. */
182 fl_set_object_boxtype(obj,FL_DOWN_BOX);
183 fl_set_object_resize(obj, FL_RESIZE_ALL);
184 fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
186 fl_unfreeze_all_forms();
190 WorkArea::~WorkArea()
193 XFreePixmap(fl_display, workareapixmap);
197 void WorkArea::resize(int xpos, int ypos, int width, int height)
199 fl_freeze_all_forms();
201 const int bw = int(abs(float(fl_get_border_width())));
204 fl_set_object_geometry(backgroundbox, xpos, ypos, width - 15, height);
210 // up - scrollbar button
211 fl_set_object_geometry(button_up, xpos + width - 15,
214 // the scrollbar slider
215 fl_set_object_geometry(scrollbar, xpos + width - 15,
218 // down - scrollbar button
219 fl_set_object_geometry(button_down, xpos + width - 15,
223 // Create the workarea pixmap
224 createPixmap(width - 15 - 2 * bw, height - 2 * bw);
227 painter_.setDrawable(workareapixmap);
230 fl_set_object_geometry(work_area, xpos + bw, ypos + bw,
234 fl_unfreeze_all_forms();
239 void WorkArea::createPixmap(int width, int height)
241 static int cur_width = -1;
242 static int cur_height = -1;
244 if (cur_width == width && cur_height == height && workareapixmap)
251 XFreePixmap(fl_display, workareapixmap);
253 lyxerr << "Creating pixmap (" << width << 'x' << height << ")" << endl;
255 workareapixmap = XCreatePixmap(fl_display,
256 RootWindow(fl_display, 0),
259 fl_get_visual_depth());
260 lyxerr << "\tpixmap=" << workareapixmap << endl;
264 void WorkArea::greyOut() const
266 fl_winset(FL_ObjWin(work_area));
267 fl_rectangle(1, work_area->x, work_area->y,
268 work_area->w, work_area->h, FL_GRAY63);
272 void WorkArea::setFocus() const
274 fl_set_focus_object(work_area->form, work_area);
278 void WorkArea::setScrollbar(double pos, double length_fraction) const
280 fl_set_slider_value(scrollbar, pos);
281 fl_set_slider_size(scrollbar, scrollbar->h * length_fraction);
285 void WorkArea::setScrollbarBounds(double l1, double l2) const
287 fl_set_slider_bounds(scrollbar, l1, l2);
291 void WorkArea::setScrollbarIncrements(float inc) const
293 fl_set_slider_increment(scrollbar, work_area->h - inc, inc);
297 void WorkArea::up_cb(FL_OBJECT * ob, long)
299 WorkArea * area = static_cast<WorkArea*>(ob->u_vdata);
300 XEvent const * ev2 = fl_last_event();
301 static long time = 0;
302 ev2 = fl_last_event();
303 if (ev2->type == ButtonPress || ev2->type == ButtonRelease)
305 //area->up(time++, fl_get_button_numb(ob));
306 area->owner->upCB(time++, fl_get_button_numb(ob));
310 void WorkArea::down_cb(FL_OBJECT * ob, long)
312 WorkArea * area = static_cast<WorkArea*>(ob->u_vdata);
313 XEvent const * ev2 = fl_last_event();
314 static long time = 0;
315 if (ev2->type == ButtonPress || ev2->type == ButtonRelease)
317 //area->down(time++, fl_get_button_numb(ob));
318 area->owner->downCB(time++, fl_get_button_numb(ob));
322 // Callback for scrollbar slider
323 void WorkArea::scroll_cb(FL_OBJECT * ob, long)
325 WorkArea * area = static_cast<WorkArea*>(ob->u_vdata);
327 //area->scroll(fl_get_slider_value(ob));
328 area->owner->scrollCB(fl_get_slider_value(ob));
332 bool Lgb_bug_find_hack = false;
334 int WorkArea::work_area_handler(FL_OBJECT * ob, int event,
336 int /*key*/, void * xev)
338 static int x_old = -1;
339 static int y_old = -1;
340 static long scrollbar_value_old = -1;
342 XEvent * ev = static_cast<XEvent*>(xev);
343 WorkArea * area = static_cast<WorkArea*>(ob->u_vdata);
349 if (!area->work_area ||
350 !area->work_area->form->visible)
352 lyxerr.debug() << "Workarea event: DRAW" << endl;
353 area->createPixmap(area->workWidth(), area->height());
354 Lgb_bug_find_hack = true;
355 area->owner->workAreaExpose();
356 Lgb_bug_find_hack = false;
360 // Should really have used xbutton.state
361 lyxerr.debug() << "Workarea event: PUSH" << endl;
362 area->owner->workAreaButtonPress(ev->xbutton.x - ob->x,
363 ev->xbutton.y - ob->y,
368 // Should really have used xbutton.state
369 lyxerr.debug() << "Workarea event: RELEASE" << endl;
370 area->owner->workAreaButtonRelease(ev->xbutton.x - ob->x,
371 ev->xbutton.y - ob->y,
375 if (!ev || ! area->scrollbar) break;
376 if (ev->xmotion.x != x_old ||
377 ev->xmotion.y != y_old ||
378 fl_get_slider_value(area->scrollbar) != scrollbar_value_old) {
379 lyxerr.debug() << "Workarea event: MOUSE" << endl;
380 area->owner->workAreaMotionNotify(ev->xmotion.x - ob->x,
381 ev->xmotion.y - ob->y,
385 // Done by the raw callback:
386 // case FL_KEYBOARD: WorkAreaKeyPress(ob, 0,0,0,ev,0); break;
388 lyxerr.debug() << "Workarea event: FOCUS" << endl;
391 lyxerr.debug() << "Workarea event: UNFOCUS" << endl;
394 lyxerr.debug() << "Workarea event: ENTER" << endl;
397 lyxerr.debug() << "Workarea event: LEAVE" << endl;
401 lyxerr.debug() << "Workarea event: DBLCLICK" << endl;;
405 lyxerr.debug() << "Workarea event: TRPLCLICK" << endl;
409 if (ev->type == SelectionNotify) {
410 lyxerr.debug() << "Workarea event: SELECTION" << endl;
411 area->owner->workAreaSelectionNotify(area->work_area->form->window, ev);
413 lyxerr.debug() << "Workarea event: OTHER" << endl;