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 void WorkArea::resize(int xpos, int ypos, int width, int height)
208 fl_freeze_all_forms();
210 const int bw = int(abs(float(fl_get_border_width())));
213 fl_set_object_geometry(backgroundbox, xpos, ypos, width - 15, height);
219 // up - scrollbar button
220 fl_set_object_geometry(button_up, xpos + width - 15,
223 // the scrollbar slider
224 fl_set_object_geometry(scrollbar, xpos + width - 15,
227 // down - scrollbar button
228 fl_set_object_geometry(button_down, xpos + width - 15,
232 // Create the workarea pixmap
233 createPixmap(width - 15 - 2 * bw, height - 2 * bw);
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 if (lyxerr.debugging())
260 lyxerr << "Creating pixmap ("
261 << width << 'x' << height << ")" << endl;
263 workareapixmap = XCreatePixmap(fl_display,
264 RootWindow(fl_display, 0),
267 fl_get_visual_depth());
268 if (lyxerr.debugging())
269 lyxerr << "\tpixmap=" << workareapixmap << endl;
273 void WorkArea::greyOut() const
275 fl_winset(FL_ObjWin(work_area));
276 fl_rectangle(1, work_area->x, work_area->y,
277 work_area->w, work_area->h, FL_GRAY63);
281 void WorkArea::setFocus() const
283 fl_set_focus_object(work_area->form, work_area);
287 void WorkArea::setScrollbar(double pos, double length_fraction) const
289 fl_set_slider_value(scrollbar, pos);
290 fl_set_slider_size(scrollbar, scrollbar->h * length_fraction);
294 void WorkArea::setScrollbarBounds(double l1, double l2) const
296 fl_set_slider_bounds(scrollbar, l1, l2);
300 void WorkArea::setScrollbarIncrements(float inc) const
302 fl_set_slider_increment(scrollbar, work_area->h - inc, inc);
306 void WorkArea::up_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 ev2 = fl_last_event();
312 if (ev2->type == ButtonPress || ev2->type == ButtonRelease)
314 //area->up(time++, fl_get_button_numb(ob));
315 area->owner->upCB(time++, fl_get_button_numb(ob));
319 void WorkArea::down_cb(FL_OBJECT * ob, long)
321 WorkArea * area = static_cast<WorkArea*>(ob->u_vdata);
322 XEvent const * ev2 = fl_last_event();
323 static long time = 0;
324 if (ev2->type == ButtonPress || ev2->type == ButtonRelease)
326 //area->down(time++, fl_get_button_numb(ob));
327 area->owner->downCB(time++, fl_get_button_numb(ob));
331 // Callback for scrollbar slider
332 void WorkArea::scroll_cb(FL_OBJECT * ob, long)
334 WorkArea * area = static_cast<WorkArea*>(ob->u_vdata);
336 //area->scroll(fl_get_slider_value(ob));
337 area->owner->scrollCB(fl_get_slider_value(ob));
341 bool Lgb_bug_find_hack = false;
343 int WorkArea::work_area_handler(FL_OBJECT * ob, int event,
345 int /*key*/, void * xev)
347 static int x_old = -1;
348 static int y_old = -1;
349 static long scrollbar_value_old = -1;
351 XEvent * ev = static_cast<XEvent*>(xev);
352 WorkArea * area = static_cast<WorkArea*>(ob->u_vdata);
358 if (!area->work_area ||
359 !area->work_area->form->visible)
361 lyxerr.debug() << "Workarea event: DRAW" << endl;
362 area->createPixmap(area->workWidth(), area->height());
363 Lgb_bug_find_hack = true;
364 area->owner->workAreaExpose();
365 Lgb_bug_find_hack = false;
369 // Should really have used xbutton.state
370 lyxerr.debug() << "Workarea event: PUSH" << endl;
371 area->owner->workAreaButtonPress(ev->xbutton.x - ob->x,
372 ev->xbutton.y - ob->y,
377 // Should really have used xbutton.state
378 lyxerr.debug() << "Workarea event: RELEASE" << endl;
379 area->owner->workAreaButtonRelease(ev->xbutton.x - ob->x,
380 ev->xbutton.y - ob->y,
384 if (!ev || ! area->scrollbar) break;
385 if (ev->xmotion.x != x_old ||
386 ev->xmotion.y != y_old ||
387 fl_get_slider_value(area->scrollbar) != scrollbar_value_old) {
388 lyxerr.debug() << "Workarea event: MOUSE" << endl;
389 area->owner->workAreaMotionNotify(ev->xmotion.x - ob->x,
390 ev->xmotion.y - ob->y,
394 // Done by the raw callback:
395 // case FL_KEYBOARD: WorkAreaKeyPress(ob, 0,0,0,ev,0); break;
397 lyxerr.debug() << "Workarea event: FOCUS" << endl;
400 lyxerr.debug() << "Workarea event: UNFOCUS" << endl;
403 lyxerr.debug() << "Workarea event: ENTER" << endl;
406 lyxerr.debug() << "Workarea event: LEAVE" << endl;
410 lyxerr.debug() << "Workarea event: DBLCLICK" << endl;
411 area->owner->doubleClick(ev->xbutton.x - ob->x,
412 ev->xbutton.y - ob->y,
417 lyxerr.debug() << "Workarea event: TRPLCLICK" << endl;
418 area->owner->tripleClick(ev->xbutton.x - ob->x,
419 ev->xbutton.y - ob->y,
424 if (ev->type == SelectionNotify) {
425 lyxerr.debug() << "Workarea event: SELECTION" << endl;
426 area->owner->workAreaSelectionNotify(area->work_area->form->window, ev);
428 lyxerr.debug() << "Workarea event: OTHER" << endl;