2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-1999 The LyX Team.
10 * ====================================================== */
20 #include "support/lstrings.h"
23 #pragma implementation
26 #include "commandtags.h"
27 #include "BufferView.h"
28 #include "bufferlist.h"
31 #include "insets/lyxinset.h"
32 #include "minibuffer.h"
33 #include "lyxscreen.h"
38 #include "lyx_gui_misc.h"
39 #include "BackStack.h"
45 extern BufferList bufferlist;
46 void sigchldhandler(pid_t pid, int *status);
48 extern void SetXtermCursor(Window win);
49 extern bool input_prohibited;
50 extern bool selection_possible;
51 extern void BeforeChange();
52 extern char ascii_type;
53 extern int UnlockInset(UpdatableInset* inset);
54 extern void ToggleFloat();
55 extern void MenuPasteSelection(char at);
56 extern InsetUpdateStruct *InsetUpdateList;
57 extern void UpdateInsetUpdateList();
58 extern void FreeUpdateTimer();
60 // This is _very_ temporary
61 FL_OBJECT * figinset_canvas;
63 BufferView::BufferView(LyXView *o, int xpos, int ypos,
64 int width, int height)
78 current_scrollbar_value = 0;
79 create_view(xpos, ypos, width, height);
80 // Activate the timer for the cursor
81 fl_set_timer(timer_cursor, 0.4);
82 fl_set_focus_object(owner_->getForm(), work_area);
83 work_area_focus = true;
88 BufferView::~BufferView()
96 void BufferView::buffer(Buffer *b)
98 lyxerr[Debug::INFO] << "Setting buffer in BufferView" << endl;
100 buffer_->InsetSleep();
101 buffer_->delUser(this);
108 // Set current buffer
111 if (bufferlist.getState() == BufferList::CLOSING) return;
118 // If we are closing the buffer, use the first buffer as current
120 buffer_ = bufferlist.first();
124 lyxerr[Debug::INFO] << " Buffer addr: " << buffer_ << endl;
125 buffer_->addUser(this);
126 owner_->getMenus()->showMenus();
127 // If we don't have a text object for this, we make one
130 resizeCurrentBuffer();
136 if (buffer_->text == 0)
137 resizeCurrentBuffer();
143 screen->first = screen->TopCursorVisible();
145 updateAllVisibleBufferRelatedPopups();
146 buffer_->InsetWakeup();
148 lyxerr[Debug::INFO] << " No Buffer!" << endl;
149 owner_->getMenus()->hideMenus();
151 fl_redraw_object(work_area);
153 // should update layoutchoice even if we don't have a buffer.
154 owner_->updateLayoutChoice();
155 owner_->getMiniBuffer()->Init();
156 owner_->updateWindowTitle();
160 void BufferView::updateScreen()
162 // Regenerate the screen.
166 screen = new LyXScreen(FL_ObjWin(work_area),
173 screen = new LyXScreen(FL_ObjWin(work_area),
183 void BufferView::resize()
185 // This will resize the buffer. (Asger)
187 resizeCurrentBuffer();
191 static bool lgb_hack = false;
193 void BufferView::redraw()
195 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
197 fl_redraw_object(work_area);
198 fl_redraw_object(scrollbar);
199 fl_redraw_object(button_down);
200 fl_redraw_object(button_up);
205 void BufferView::fitCursor()
207 if (screen) screen->FitCursor();
211 void BufferView::update()
213 if (screen) screen->Update();
217 void BufferView::updateScrollbar()
219 /* If the text is smaller than the working area, the scrollbar
220 * maximum must be the working area height. No scrolling will
224 fl_set_slider_value(scrollbar, 0);
225 fl_set_slider_size(scrollbar, scrollbar->h);
229 static long max2 = 0;
230 static long height2 = 0;
240 cbth = buffer_->text->height;
243 cbsf = screen->first;
245 // check if anything has changed.
247 height2 == work_area->h &&
248 current_scrollbar_value == cbsf)
252 height2 = work_area->h;
253 current_scrollbar_value = cbsf;
255 if (cbth <= height2) { // text is smaller than screen
256 fl_set_slider_size(scrollbar, scrollbar->h);
260 long maximum_height = work_area->h * 3/4 + cbth;
264 double hfloat = work_area->h;
265 double maxfloat = maximum_height;
267 fl_set_slider_value(scrollbar, value);
268 fl_set_slider_bounds(scrollbar, 0,
269 maximum_height - work_area->h);
272 double lineh = text->DefaultHeight();
274 double lineh = buffer_->text->DefaultHeight();
276 fl_set_slider_increment(scrollbar, work_area->h-lineh, lineh);
279 if ((hfloat / maxfloat) * float(height2) < 3)
280 fl_set_slider_size(scrollbar,
283 fl_set_slider_size(scrollbar,
286 fl_set_slider_size(scrollbar, hfloat);
287 fl_set_slider_precision(scrollbar, 0);
291 void BufferView::redoCurrentBuffer()
293 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
295 if (buffer_ && text) {
297 owner_->updateLayoutChoice();
300 if (buffer_ && buffer_->text) {
302 owner_->updateLayoutChoice();
308 int BufferView::resizeCurrentBuffer()
310 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
312 LyXParagraph * par = 0;
313 LyXParagraph * selstartpar = 0;
314 LyXParagraph * selendpar = 0;
323 owner_->getMiniBuffer()->Set(_("Formatting document..."));
327 par = text->cursor.par;
328 pos = text->cursor.pos;
329 selstartpar = text->sel_start_cursor.par;
330 selstartpos = text->sel_start_cursor.pos;
331 selendpar = text->sel_end_cursor.par;
332 selendpos = text->sel_end_cursor.pos;
333 selection = text->selection;
334 mark_set = text->mark_set;
337 text = new LyXText(work_area->w, buffer_);
340 par = buffer_->text->cursor.par;
341 pos = buffer_->text->cursor.pos;
342 selstartpar = buffer_->text->sel_start_cursor.par;
343 selstartpos = buffer_->text->sel_start_cursor.pos;
344 selendpar = buffer_->text->sel_end_cursor.par;
345 selendpos = buffer_->text->sel_end_cursor.pos;
346 selection = buffer_->text->selection;
347 mark_set = buffer_->text->mark_set;
348 delete buffer_->text;
350 buffer_->text = new LyXText(work_area->w, buffer_);
357 text->selection = true;
358 /* at this point just
359 * to avoid the Delete-
362 * setting the cursor */
363 text->mark_set = mark_set;
365 text->SetCursor(selstartpar, selstartpos);
366 text->sel_cursor = text->cursor;
367 text->SetCursor(selendpar, selendpos);
368 text->SetSelection();
369 text->SetCursor(par, pos);
371 text->SetCursor(par, pos);
372 text->sel_cursor = text->cursor;
373 text->selection = false;
378 buffer_->text->selection = true;
379 /* at this point just
380 * to avoid the Delete-
383 * setting the cursor */
384 buffer_->text->mark_set = mark_set;
386 buffer_->text->SetCursor(selstartpar, selstartpos);
387 buffer_->text->sel_cursor = buffer_->text->cursor;
388 buffer_->text->SetCursor(selendpar, selendpos);
389 buffer_->text->SetSelection();
390 buffer_->text->SetCursor(par, pos);
392 buffer_->text->SetCursor(par, pos);
393 buffer_->text->sel_cursor = buffer_->text->cursor;
394 buffer_->text->selection = false;
398 screen->first = screen->TopCursorVisible(); /* this will scroll the
399 * screen such that the
404 owner_->getMiniBuffer()->Init();
407 // Now if the title form still exist kill it
414 void BufferView::gotoError()
419 screen->HideCursor();
429 if (!text->GotoNextError()) {
431 || text->cursor.par != text->FirstParagraph()) {
433 text->cursor.par = text->FirstParagraph();
434 text->cursor.pos = 0;
435 if (!text->GotoNextError()) {
437 owner_->getMiniBuffer()->Set(_("No more errors"));
441 owner_->getMiniBuffer()->Set(_("No more errors"));
446 text->sel_cursor = text->cursor;
448 if (!buffer_->text->GotoNextError()) {
449 if (buffer_->text->cursor.pos
450 || buffer_->text->cursor.par !=
451 buffer_->text->FirstParagraph()) {
452 tmp = buffer_->text->cursor;
453 buffer_->text->cursor.par =
454 buffer_->text->FirstParagraph();
455 buffer_->text->cursor.pos = 0;
456 if (!buffer_->text->GotoNextError()) {
457 buffer_->text->cursor = tmp;
458 owner_->getMiniBuffer()->Set(_("No more errors"));
462 owner_->getMiniBuffer()->Set(_("No more errors"));
467 buffer_->text->sel_cursor =
468 buffer_->text->cursor;
473 // Just a bunch of C wrappers around static members of BufferView
474 extern "C" void C_BufferView_UpCB(FL_OBJECT * ob, long buf) {
475 BufferView::UpCB(ob, buf);
478 extern "C" void C_BufferView_DownCB(FL_OBJECT * ob, long buf) {
479 BufferView::DownCB(ob, buf);
482 extern "C" void C_BufferView_ScrollCB(FL_OBJECT * ob, long buf) {
483 BufferView::ScrollCB(ob, buf);
486 extern "C" void C_BufferView_CursorToggleCB(FL_OBJECT * ob, long buf) {
487 BufferView::CursorToggleCB(ob, buf);
490 extern "C" int C_BufferView_work_area_handler(FL_OBJECT * ob, int event,
492 int key, void * xev) {
493 return BufferView::work_area_handler(ob, event, 0, 0, key, xev);
497 void BufferView::create_view(int xpos, int ypos, int width, int height)
500 const int bw = abs(fl_get_border_width());
502 // a hack for the figinsets (Matthias)
503 // This one first, then it will probably be invisible. (Lgb)
504 ::figinset_canvas = figinset_canvas = obj =
505 fl_add_canvas(FL_NORMAL_CANVAS,
508 fl_set_object_boxtype(obj, FL_NO_BOX);
509 fl_set_object_resize(obj, FL_RESIZE_ALL);
510 fl_set_object_gravity(obj, NorthWestGravity, NorthWestGravity);
513 obj = fl_add_box(FL_BORDER_BOX, xpos, ypos,
516 fl_set_object_resize(obj, FL_RESIZE_ALL);
517 fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
520 work_area = obj = fl_add_free(FL_INPUT_FREE,
522 width-15-2*bw /* scrollbarwidth */,
524 C_BufferView_work_area_handler);
525 obj->wantkey = FL_KEY_TAB;
526 obj->u_vdata = this; /* This is how we pass the BufferView
527 to the work_area_handler. */
528 fl_set_object_boxtype(obj, FL_DOWN_BOX);
529 fl_set_object_resize(obj, FL_RESIZE_ALL);
530 fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
536 // up - scrollbar button
538 fl_set_border_width(-1);
540 fl_set_border_width(-2); // to get visible feedback
542 button_up = obj = fl_add_pixmapbutton(FL_TOUCH_BUTTON,
546 fl_set_object_boxtype(obj, FL_UP_BOX);
547 fl_set_object_color(obj, FL_MCOL, FL_BLUE);
548 fl_set_object_resize(obj, FL_RESIZE_ALL);
549 fl_set_object_gravity(obj, NorthEastGravity, NorthEastGravity);
550 fl_set_object_callback(obj, C_BufferView_UpCB, 0);
552 fl_set_pixmapbutton_data(obj, const_cast<char**>(up_xpm));
555 // Remove the blue feedback rectangle
556 fl_set_pixmapbutton_focus_outline(obj, 0);
559 // the scrollbar slider
560 fl_set_border_width(-bw);
561 scrollbar = obj = fl_add_slider(FL_VERT_SLIDER,
565 fl_set_object_color(obj, FL_COL1, FL_MCOL);
566 fl_set_object_boxtype(obj, FL_UP_BOX);
567 fl_set_object_resize(obj, FL_RESIZE_ALL);
568 fl_set_object_gravity(obj, NorthEastGravity, SouthEastGravity);
569 fl_set_object_callback(obj, C_BufferView_ScrollCB, 0);
572 // down - scrollbar button
574 fl_set_border_width(-1);
576 fl_set_border_width(-2); // to get visible feedback
578 button_down = obj = fl_add_pixmapbutton(FL_TOUCH_BUTTON,
582 fl_set_object_boxtype(obj, FL_UP_BOX);
583 fl_set_object_color(obj, FL_MCOL, FL_BLUE);
584 fl_set_object_resize(obj, FL_RESIZE_ALL);
585 fl_set_object_gravity(obj, SouthEastGravity, SouthEastGravity);
586 fl_set_object_callback(obj, C_BufferView_DownCB, 0);
588 fl_set_pixmapbutton_data(obj, const_cast<char**>(down_xpm));
589 fl_set_border_width(-bw);
592 // Remove the blue feedback rectangle
593 fl_set_pixmapbutton_focus_outline(obj, 0);
601 timer_cursor = obj = fl_add_timer(FL_HIDDEN_TIMER,
602 0, 0, 0, 0, "Timer");
603 fl_set_object_callback(obj, C_BufferView_CursorToggleCB, 0);
608 // Callback for scrollbar up button
609 void BufferView::UpCB(FL_OBJECT * ob, long)
611 BufferView * view = static_cast<BufferView*>(ob->u_vdata);
613 if (view->buffer_ == 0) return;
616 static long time = 0;
617 ev2 = fl_last_event();
618 if (ev2->type == ButtonPress || ev2->type == ButtonRelease)
620 int button = fl_get_button_numb(ob);
623 view->ScrollUpOnePage(time++); break;
625 view->ScrollDownOnePage(time++); break;
627 view->ScrollUp(time++); break;
639 a = XInternAtom(fl_display, "WAIT_FOR_X", False);
642 XSetWindowAttributes attr;
643 mask = CWOverrideRedirect;
644 attr.override_redirect = 1;
645 w = XCreateWindow(fl_display, fl_root,
646 0, 0, 1, 1, 0, CopyFromParent,
647 InputOnly, CopyFromParent, mask, &attr);
648 XSelectInput(fl_display, w, PropertyChangeMask);
649 XMapWindow(fl_display, w);
652 XChangeProperty(fl_display, w, a, a, 8,
653 PropModeAppend, reinterpret_cast<unsigned char*>(""), 0);
654 XWindowEvent(fl_display, w, PropertyChangeMask, &ev);
656 XSync(fl_get_display(), 0);
660 // Callback for scrollbar slider
661 void BufferView::ScrollCB(FL_OBJECT * ob, long)
663 BufferView * view = static_cast<BufferView*>(ob->u_vdata);
664 extern bool cursor_follows_scrollbar;
666 if (view->buffer_ == 0) return;
668 view->current_scrollbar_value = long(fl_get_slider_value(ob));
669 if (view->current_scrollbar_value < 0)
670 view->current_scrollbar_value = 0;
675 view->screen->Draw(view->current_scrollbar_value);
677 if (cursor_follows_scrollbar) {
679 LyXText * vbt = view->text;
681 LyXText * vbt = view->buffer_->text;
683 int height = vbt->DefaultHeight();
685 if (vbt->cursor.y < view->screen->first + height) {
686 vbt->SetCursorFromCoordinates(0,
687 view->screen->first +
690 else if (vbt->cursor.y >
691 view->screen->first + view->work_area->h - height) {
692 vbt->SetCursorFromCoordinates(0,
693 view->screen->first +
702 // Callback for scrollbar down button
703 void BufferView::DownCB(FL_OBJECT * ob, long)
705 BufferView * view = static_cast<BufferView*>(ob->u_vdata);
707 if (view->buffer_ == 0) return;
710 static long time = 0;
711 ev2 = fl_last_event();
712 if (ev2->type == ButtonPress || ev2->type == ButtonRelease)
714 int button = fl_get_button_numb(ob);
717 view->ScrollUpOnePage(time++); break;
719 view->ScrollDownOnePage(time++); break;
721 view->ScrollDown(time++); break;
726 int BufferView::ScrollUp(long time)
728 if (buffer_ == 0) return 0;
732 double value= fl_get_slider_value(scrollbar);
738 float add_value = (text->DefaultHeight()
739 + float(time) * float(time) * 0.125);
741 if (add_value > work_area->h)
742 add_value = float(work_area->h -
743 text->DefaultHeight());
745 float add_value = (buffer_->text->DefaultHeight()
746 + float(time) * float(time) * 0.125);
748 if (add_value > work_area->h)
749 add_value = float(work_area->h -
750 buffer_->text->DefaultHeight());
758 fl_set_slider_value(scrollbar, value);
760 ScrollCB(scrollbar, 0);
765 int BufferView::ScrollDown(long time)
767 if (buffer_ == 0) return 0;
771 double value= fl_get_slider_value(scrollbar);
773 fl_get_slider_bounds(scrollbar, &min, &max);
779 float add_value = (text->DefaultHeight()
780 + float(time) * float(time) * 0.125);
782 if (add_value > work_area->h)
783 add_value = float(work_area->h -
784 text->DefaultHeight());
786 float add_value = (buffer_->text->DefaultHeight()
787 + float(time) * float(time) * 0.125);
789 if (add_value > work_area->h)
790 add_value = float(work_area->h -
791 buffer_->text->DefaultHeight());
799 fl_set_slider_value(scrollbar, value);
801 ScrollCB(scrollbar, 0);
806 void BufferView::ScrollUpOnePage(long /*time*/)
808 if (buffer_ == 0) return;
812 long y = screen->first;
816 Row * row = text->GetRowNearY(y);
818 Row * row = buffer_->text->GetRowNearY(y);
820 y = y - work_area->h + row->height;
822 fl_set_slider_value(scrollbar, y);
824 ScrollCB(scrollbar, 0);
828 void BufferView::ScrollDownOnePage(long /*time*/)
830 if (buffer_ == 0) return;
835 fl_get_slider_bounds(scrollbar, &min, &max);
836 long y = screen->first;
839 if (y > text->height - work_area->h)
843 text->GetRowNearY(y);
845 if (y > buffer_->text->height - work_area->h)
849 buffer_->text->GetRowNearY(y);
851 fl_set_slider_value(scrollbar, y);
853 ScrollCB(scrollbar, 0);
857 int BufferView::work_area_handler(FL_OBJECT * ob, int event,
859 int /*key*/, void *xev)
861 static int x_old = -1;
862 static int y_old = -1;
863 static long scrollbar_value_old = -1;
865 XEvent * ev = static_cast<XEvent*>(xev);
866 BufferView * view = static_cast<BufferView*>(ob->u_vdata);
868 // If we don't have a view yet; return
869 if (!view || quitting) return 0;
873 view->workAreaExpose();
876 view->WorkAreaButtonPress(ob, 0, 0, 0, ev, 0);
879 view->WorkAreaButtonRelease(ob, 0, 0, 0, ev, 0);
882 if (ev->xmotion.x != x_old ||
883 ev->xmotion.y != y_old ||
884 view->current_scrollbar_value != scrollbar_value_old) {
885 x_old = ev->xmotion.x;
886 y_old = ev->xmotion.y;
887 scrollbar_value_old = view->current_scrollbar_value;
888 view->WorkAreaMotionNotify(ob, 0, 0, 0, ev, 0);
891 // Done by the raw callback:
892 // case FL_KEYBOARD: WorkAreaKeyPress(ob, 0, 0, 0, ev, 0); break;
894 if (!view->owner_->getMiniBuffer()->shows_no_match)
895 view->owner_->getMiniBuffer()->Init();
896 view->owner_->getMiniBuffer()->shows_no_match = false;
897 view->work_area_focus = true;
898 fl_set_timer(view->timer_cursor, 0.4);
901 view->owner_->getMiniBuffer()->ExecCommand();
902 view->work_area_focus = false;
905 SetXtermCursor(view->owner_->getForm()->window);
907 view->lyx_focus = true;
908 fl_set_timer(view->timer_cursor, 0.4);
911 if (!input_prohibited)
912 XUndefineCursor(fl_display,
913 view->owner_->getForm()->window);
914 view->lyx_focus = false; // This is not an absolute truth
915 // but if it is not true, it will be changed within a blink
916 // of an eye. ... Not good enough... use regulare timeperiod
917 //fl_set_timer(view->timer_cursor, 0.01); // 0.1 sec blink
918 fl_set_timer(view->timer_cursor, 0.4); // 0.4 sec blink
922 if (view->buffer_ && !view->buffer_->the_locking_inset) {
923 if (view->screen && ev->xbutton.button == 1) {
924 view->screen->HideCursor();
925 view->screen->ToggleSelection();
927 view->text->SelectWord();
929 view->buffer_->text->SelectWord();
931 view->screen->ToggleSelection(false);
932 /* This will fit the cursor on the screen
937 view->buffer_->update(0);
944 if (view->buffer_ && view->screen && ev->xbutton.button == 1) {
945 view->screen->HideCursor();
946 view->screen->ToggleSelection();
948 view->text->CursorHome();
949 view->text->sel_cursor = view->text->cursor;
950 view->text->CursorEnd();
951 view->text->SetSelection();
953 view->buffer_->text->CursorHome();
954 view->buffer_->text->sel_cursor =
955 view->buffer_->text->cursor;
956 view->buffer_->text->CursorEnd();
957 view->buffer_->text->SetSelection();
959 view->screen->ToggleSelection(false);
960 /* This will fit the cursor on the screen
965 view->buffer_->update(0);
970 view->WorkAreaSelectionNotify(ob,
971 view->owner_->getForm()->window,
978 int BufferView::WorkAreaMotionNotify(FL_OBJECT *ob, Window,
979 int /*w*/, int /*h*/,
980 XEvent *ev, void */*d*/)
983 if (buffer_ == 0) return 0;
984 if (!screen) return 0;
986 // Check for inset locking
987 if (buffer_->the_locking_inset) {
989 LyXCursor cursor = text->cursor;
991 LyXCursor cursor = buffer_->text->cursor;
993 buffer_->the_locking_inset->
994 InsetMotionNotify(ev->xbutton.x - ob->x - cursor.x,
995 ev->xbutton.y - ob->y -
1001 // Only use motion with button 1
1002 if (!ev->xmotion.state & Button1MotionMask)
1005 /* The selection possible is needed, that only motion events are
1006 * used, where the bottom press event was on the drawing area too */
1007 if (selection_possible) {
1008 screen->HideCursor();
1011 text->SetCursorFromCoordinates(ev->xbutton.x - ob->x,
1012 ev->xbutton.y - ob->y +
1015 if (!text->selection)
1016 update(-3); // Maybe an empty line was deleted
1018 text->SetSelection();
1021 SetCursorFromCoordinates(ev->xbutton.x - ob->x,
1022 ev->xbutton.y - ob->y +
1025 if (!buffer_->text->selection)
1026 buffer_->update(-3); // Maybe an empty line was deleted
1028 buffer_->text->SetSelection();
1030 screen->ToggleToggle();
1031 if (screen->FitCursor())
1033 screen->ShowCursor();
1039 extern int bibitemMaxWidth(LyXFont const &);
1042 // Single-click on work area
1043 int BufferView::WorkAreaButtonPress(FL_OBJECT *ob, Window,
1044 int /*w*/, int /*h*/, XEvent *ev, void */*d*/)
1049 if (buffer_ == 0) return 0;
1050 if (!screen) return 0;
1052 int const x = ev->xbutton.x - ob->x;
1053 int const y = ev->xbutton.y - ob->y;
1054 // If we hit an inset, we have the inset coordinates in these
1055 // and inset_hit points to the inset. If we do not hit an
1056 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
1059 Inset * inset_hit = checkInsetHit(inset_x, inset_y);
1061 // ok ok, this is a hack.
1062 int button = ev->xbutton.button;
1063 if (button == 4 || button == 5) goto wheel;
1067 if (buffer_->the_locking_inset) {
1068 // We are in inset locking mode
1070 /* Check whether the inset was hit. If not reset mode,
1071 otherwise give the event to the inset */
1072 if (inset_hit != 0) {
1073 buffer_->the_locking_inset->
1074 InsetButtonPress(inset_x, inset_y, button);
1077 UnlockInset(buffer_->the_locking_inset);
1081 selection_possible = true;
1082 screen->HideCursor();
1084 // Right button mouse click on a table
1086 (text->cursor.par->table ||
1087 text->MouseHitInTable(x, y + screen->first))) {
1088 // Set the cursor to the press-position
1089 text->SetCursorFromCoordinates(x, y + screen->first);
1092 // Only show the table popup if the hit is in the table, too
1093 if (!text->HitInTable(text->cursor.row, x))
1096 // Hit above or below the table?
1098 if (!text->selection) {
1099 screen->ToggleSelection();
1100 text->ClearSelection();
1101 text->FullRebreak();
1105 // Popup table popup when on a table.
1106 // This is obviously temporary, since we should be
1108 // popup various context-sensitive-menus with the
1109 // the right mouse. So this should be done more
1110 // general in the future. Matthias.
1111 selection_possible = false;
1112 owner_->getLyXFunc()->Dispatch(LFUN_LAYOUT_TABLE,
1118 int screen_first = screen->first;
1120 // Middle button press pastes if we have a selection
1121 bool paste_internally = false;
1122 if (button == 2 // && !buffer_->the_locking_inset
1123 && text->selection) {
1124 owner_->getLyXFunc()->Dispatch(LFUN_COPY);
1125 paste_internally = true;
1128 // Clear the selection
1129 screen->ToggleSelection();
1130 text->ClearSelection();
1131 text->FullRebreak();
1135 // Single left click in math inset?
1136 if (inset_hit != 0 && inset_hit->Editable() == 2) {
1137 // Highly editable inset, like math
1138 selection_possible = false;
1139 owner_->updateLayoutChoice();
1140 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
1141 inset_hit->Edit(inset_x, inset_y);
1145 // Right click on a footnote flag opens float menu
1147 selection_possible = false;
1151 text->SetCursorFromCoordinates(x, y + screen_first);
1153 text->sel_cursor = text->cursor;
1154 text->cursor.x_fix = text->cursor.x;
1156 owner_->updateLayoutChoice();
1157 if (screen->FitCursor()){
1159 selection_possible = false;
1162 // Insert primary selection with middle mouse
1163 // if there is a local selection in the current buffer, insert this
1164 if (button == 2) { // && !buffer_->the_locking_inset){
1165 if (paste_internally)
1166 owner_->getLyXFunc()->Dispatch(LFUN_PASTE);
1168 owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION,
1170 selection_possible = false;
1176 // I am not quite sure if this is the correct place to put this,
1177 // but it will not cause any harm.
1178 // Patch from Mark Huang (markman@mit.edu) to make LyX recognise
1179 // button 4 and 5. This enables LyX use use the scrollwhell on
1180 // certain mice for something useful. (Lgb)
1181 // Added wheel acceleration detection code. (Rvdk)
1182 static Time lastTime = 0;
1183 int diff = ev->xbutton.time - lastTime;
1184 int scroll = int(1.0 + (4.0/(abs(diff)+1.0))*200.0);
1193 lastTime = ev->xbutton.time;
1203 // Single-click on work area
1204 int BufferView::WorkAreaButtonPress(FL_OBJECT *ob, Window,
1205 int /*w*/, int /*h*/, XEvent *ev, void */*d*/)
1210 if (buffer_ == 0) return 0;
1211 if (!screen) return 0;
1213 int const x = ev->xbutton.x - ob->x;
1214 int const y = ev->xbutton.y - ob->y;
1215 // If we hit an inset, we have the inset coordinates in these
1216 // and inset_hit points to the inset. If we do not hit an
1217 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
1220 Inset * inset_hit = checkInsetHit(inset_x, inset_y);
1222 // ok ok, this is a hack.
1223 int button = ev->xbutton.button;
1224 if (button == 4 || button == 5) goto wheel;
1228 if (buffer_->the_locking_inset) {
1229 // We are in inset locking mode
1231 /* Check whether the inset was hit. If not reset mode,
1232 otherwise give the event to the inset */
1233 if (inset_hit != 0) {
1234 buffer_->the_locking_inset->
1235 InsetButtonPress(inset_x, inset_y, button);
1238 UnlockInset(buffer_->the_locking_inset);
1242 selection_possible = true;
1243 screen->HideCursor();
1245 // Right button mouse click on a table
1247 (buffer_->text->cursor.par->table ||
1248 buffer_->text->MouseHitInTable(x, y+screen->first))) {
1249 // Set the cursor to the press-position
1250 buffer_->text->SetCursorFromCoordinates(x, y + screen->first);
1253 // Only show the table popup if the hit is in the table, too
1254 if (!buffer_->text->HitInTable(buffer_->text->cursor.row, x))
1257 // Hit above or below the table?
1259 if (!buffer_->text->selection) {
1260 screen->ToggleSelection();
1261 buffer_->text->ClearSelection();
1262 buffer_->text->FullRebreak();
1266 // Popup table popup when on a table.
1267 // This is obviously temporary, since we should be
1269 // popup various context-sensitive-menus with the
1270 // the right mouse. So this should be done more
1271 // general in the future. Matthias.
1272 selection_possible = false;
1273 owner_->getLyXFunc()->Dispatch(LFUN_LAYOUT_TABLE,
1279 int screen_first = screen->first;
1281 // Middle button press pastes if we have a selection
1282 bool paste_internally = false;
1283 if (button == 2 // && !buffer_->the_locking_inset
1284 && buffer_->text->selection) {
1285 owner_->getLyXFunc()->Dispatch(LFUN_COPY);
1286 paste_internally = true;
1289 // Clear the selection
1290 screen->ToggleSelection();
1291 buffer_->text->ClearSelection();
1292 buffer_->text->FullRebreak();
1296 // Single left click in math inset?
1297 if (inset_hit != 0 && inset_hit->Editable() == 2) {
1298 // Highly editable inset, like math
1299 selection_possible = false;
1300 owner_->updateLayoutChoice();
1301 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
1302 inset_hit->Edit(inset_x, inset_y);
1306 // Right click on a footnote flag opens float menu
1308 selection_possible = false;
1312 buffer_->text->SetCursorFromCoordinates(x, y + screen_first);
1313 buffer_->text->FinishUndo();
1314 buffer_->text->sel_cursor = buffer_->text->cursor;
1315 buffer_->text->cursor.x_fix = buffer_->text->cursor.x;
1317 owner_->updateLayoutChoice();
1318 if (screen->FitCursor()){
1320 selection_possible = false;
1323 // Insert primary selection with middle mouse
1324 // if there is a local selection in the current buffer, insert this
1325 if (button == 2) { // && !buffer_->the_locking_inset){
1326 if (paste_internally)
1327 owner_->getLyXFunc()->Dispatch(LFUN_PASTE);
1329 owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION,
1331 selection_possible = false;
1337 // I am not quite sure if this is the correct place to put this,
1338 // but it will not cause any harm.
1339 // Patch from Mark Huang (markman@mit.edu) to make LyX recognise
1340 // button 4 and 5. This enables LyX use use the scrollwhell on
1341 // certain mice for something useful. (Lgb)
1342 // Added wheel acceleration detection code. (Rvdk)
1343 static Time lastTime = 0;
1344 int diff = ev->xbutton.time - lastTime;
1345 int scroll = int(1.0 + (4.0/(abs(diff)+1.0))*200.0);
1354 lastTime = ev->xbutton.time;
1366 int BufferView::WorkAreaButtonRelease(FL_OBJECT * ob, Window ,
1367 int /*w*/, int /*h*/, XEvent * ev, void * /*d*/)
1369 if (buffer_ == 0 || screen == 0) return 0;
1371 int const x = ev->xbutton.x - ob->x;
1372 int const y = ev->xbutton.y - ob->y;
1374 // If we hit an inset, we have the inset coordinates in these
1375 // and inset_hit points to the inset. If we do not hit an
1376 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
1379 Inset * inset_hit = checkInsetHit(inset_x, inset_y);
1381 if (buffer_->the_locking_inset) {
1382 // We are in inset locking mode.
1384 /* LyX does a kind of work-area grabbing for insets.
1385 Only a ButtonPress Event outside the inset will
1386 force a InsetUnlock. */
1387 buffer_->the_locking_inset->
1388 InsetButtonRelease(inset_x, inset_y,
1389 ev->xbutton.button);
1393 selection_possible = false;
1394 if (text->cursor.par->table) {
1396 NumberOfCell(text->cursor.par,
1398 if (text->cursor.par->table->IsContRow(cell) &&
1399 text->cursor.par->table->
1400 CellHasContRow(text->cursor.par->table->
1401 GetCellAbove(cell))<0) {
1406 if (ev->xbutton.button >= 2)
1409 // Make sure that the press was not far from the release
1410 if ((abs(last_click_x - x) >= 5) ||
1411 (abs(last_click_y - y) >= 5)) {
1415 // Did we hit an editable inset?
1416 if (inset_hit != 0) {
1417 // Inset like error, notes and figures
1418 selection_possible = false;
1419 #ifdef WITH_WARNINGS
1420 #warning fix this proper in 0.13
1422 // Following a ref shouldn't issue
1423 // a push on the undo-stack
1424 // anylonger, now that we have
1425 // keybindings for following
1426 // references and returning from
1427 // references. IMHO though, it
1428 // should be the inset's own business
1429 // to push or not push on the undo
1430 // stack. They don't *have* to
1431 // alter the document...
1433 // ...or maybe the SetCursorParUndo()
1434 // below isn't necessary at all anylonger?
1435 if (inset_hit->LyxCode() == Inset::REF_CODE) {
1436 text->SetCursorParUndo();
1439 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
1440 inset_hit->Edit(inset_x, inset_y);
1444 // check whether we want to open a float
1448 if (text->cursor.pos <
1449 text->cursor.par->Last()) {
1450 c = text->cursor.par->
1451 GetChar(text->cursor.pos);
1453 if (c == LyXParagraph::META_FOOTNOTE
1454 || c == LyXParagraph::META_MARGIN
1455 || c == LyXParagraph::META_FIG
1456 || c == LyXParagraph::META_TAB
1457 || c == LyXParagraph::META_WIDE_FIG
1458 || c == LyXParagraph::META_WIDE_TAB
1459 || c == LyXParagraph::META_ALGORITHM){
1461 } else if (text->cursor.pos - 1 >= 0) {
1462 c = text->cursor.par->
1463 GetChar(text->cursor.pos - 1);
1464 if (c == LyXParagraph::META_FOOTNOTE
1465 || c == LyXParagraph::META_MARGIN
1466 || c == LyXParagraph::META_FIG
1467 || c == LyXParagraph::META_TAB
1468 || c == LyXParagraph::META_WIDE_FIG
1469 || c == LyXParagraph::META_WIDE_TAB
1470 || c == LyXParagraph::META_ALGORITHM){
1471 // We are one step too far to the right
1478 selection_possible = false;
1483 // Do we want to close a float? (click on the float-label)
1484 if (text->cursor.row->par->footnoteflag ==
1485 LyXParagraph::OPEN_FOOTNOTE
1486 && text->cursor.pos == 0
1487 && text->cursor.row->previous &&
1488 text->cursor.row->previous->par->
1489 footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
1490 LyXFont font (LyXFont::ALL_SANE);
1491 font.setSize(LyXFont::SIZE_SMALL);
1493 int box_x = 20; // LYX_PAPER_MARGIN;
1494 box_x += font.textWidth("Mwide-figM", 10);
1496 int screen_first = screen->first;
1499 && y + screen_first > text->cursor.y -
1500 text->cursor.row->baseline
1501 && y + screen_first < text->cursor.y -
1502 text->cursor.row->baseline
1503 + font.maxAscent()*1.2 + font.maxDescent()*1.2) {
1505 selection_possible = false;
1510 // Maybe we want to edit a bibitem ale970302
1511 if (text->cursor.par->bibkey && x < 20 +
1512 bibitemMaxWidth(textclasslist.TextClass(buffer_->
1513 params.textclass).defaultfont())) {
1514 text->cursor.par->bibkey->Edit(0, 0);
1520 int BufferView::WorkAreaButtonRelease(FL_OBJECT *ob, Window ,
1521 int /*w*/, int /*h*/, XEvent *ev, void */*d*/)
1523 if (buffer_ == 0 || screen == 0) return 0;
1525 int const x = ev->xbutton.x - ob->x;
1526 int const y = ev->xbutton.y - ob->y;
1528 // If we hit an inset, we have the inset coordinates in these
1529 // and inset_hit points to the inset. If we do not hit an
1530 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
1533 Inset * inset_hit = checkInsetHit(inset_x, inset_y);
1535 if (buffer_->the_locking_inset) {
1536 // We are in inset locking mode.
1538 /* LyX does a kind of work-area grabbing for insets.
1539 Only a ButtonPress Event outside the inset will
1540 force a InsetUnlock. */
1541 buffer_->the_locking_inset->
1542 InsetButtonRelease(inset_x, inset_y,
1543 ev->xbutton.button);
1547 selection_possible = false;
1548 if (buffer_->text->cursor.par->table) {
1549 int cell = buffer_->text->
1550 NumberOfCell(buffer_->text->cursor.par,
1551 buffer_->text->cursor.pos);
1552 if (buffer_->text->cursor.par->table->IsContRow(cell) &&
1553 buffer_->text->cursor.par->table->
1554 CellHasContRow(buffer_->text->cursor.par->table->
1555 GetCellAbove(cell))<0) {
1556 buffer_->text->CursorUp();
1560 if (ev->xbutton.button >= 2)
1563 // Make sure that the press was not far from the release
1564 if ((abs(last_click_x - x) >= 5) ||
1565 (abs(last_click_y - y) >= 5)) {
1569 // Did we hit an editable inset?
1570 if (inset_hit != 0) {
1571 // Inset like error, notes and figures
1572 selection_possible = false;
1573 #ifdef WITH_WARNINGS
1574 #warning fix this proper in 0.13
1576 // Following a ref shouldn't issue
1577 // a push on the undo-stack
1578 // anylonger, now that we have
1579 // keybindings for following
1580 // references and returning from
1581 // references. IMHO though, it
1582 // should be the inset's own business
1583 // to push or not push on the undo
1584 // stack. They don't *have* to
1585 // alter the document...
1587 // ...or maybe the SetCursorParUndo()
1588 // below isn't necessary at all anylonger?
1589 if (inset_hit->LyxCode() == Inset::REF_CODE) {
1590 buffer_->text->SetCursorParUndo();
1593 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
1594 inset_hit->Edit(inset_x, inset_y);
1598 // check whether we want to open a float
1599 if (buffer_->text) {
1602 if (buffer_->text->cursor.pos <
1603 buffer_->text->cursor.par->Last()) {
1604 c = buffer_->text->cursor.par->
1605 GetChar(buffer_->text->cursor.pos);
1607 if (c == LyXParagraph::META_FOOTNOTE
1608 || c == LyXParagraph::META_MARGIN
1609 || c == LyXParagraph::META_FIG
1610 || c == LyXParagraph::META_TAB
1611 || c == LyXParagraph::META_WIDE_FIG
1612 || c == LyXParagraph::META_WIDE_TAB
1613 || c == LyXParagraph::META_ALGORITHM){
1615 } else if (buffer_->text->cursor.pos - 1 >= 0) {
1616 c = buffer_->text->cursor.par->
1617 GetChar(buffer_->text->cursor.pos - 1);
1618 if (c == LyXParagraph::META_FOOTNOTE
1619 || c == LyXParagraph::META_MARGIN
1620 || c == LyXParagraph::META_FIG
1621 || c == LyXParagraph::META_TAB
1622 || c == LyXParagraph::META_WIDE_FIG
1623 || c == LyXParagraph::META_WIDE_TAB
1624 || c == LyXParagraph::META_ALGORITHM){
1625 // We are one step too far to the right
1626 buffer_->text->CursorLeft();
1632 selection_possible = false;
1637 // Do we want to close a float? (click on the float-label)
1638 if (buffer_->text->cursor.row->par->footnoteflag ==
1639 LyXParagraph::OPEN_FOOTNOTE
1640 && buffer_->text->cursor.pos == 0
1641 && buffer_->text->cursor.row->previous &&
1642 buffer_->text->cursor.row->previous->par->
1643 footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
1644 LyXFont font (LyXFont::ALL_SANE);
1645 font.setSize(LyXFont::SIZE_SMALL);
1647 int box_x = 20; // LYX_PAPER_MARGIN;
1648 box_x += font.textWidth("Mwide-figM", 10);
1650 int screen_first = screen->first;
1653 && y + screen_first > buffer_->text->cursor.y -
1654 buffer_->text->cursor.row->baseline
1655 && y + screen_first < buffer_->text->cursor.y -
1656 buffer_->text->cursor.row->baseline
1657 + font.maxAscent()*1.2 + font.maxDescent()*1.2) {
1659 selection_possible = false;
1664 // Maybe we want to edit a bibitem ale970302
1665 if (buffer_->text->cursor.par->bibkey && x < 20 +
1666 bibitemMaxWidth(textclasslist.TextClass(buffer_->
1667 params.textclass).defaultfont())) {
1668 buffer_->text->cursor.par->bibkey->Edit(0, 0);
1676 * Returns an inset if inset was hit. 0 otherwise.
1677 * If hit, the coordinates are changed relative to the inset.
1678 * Otherwise coordinates are not changed, and false is returned.
1681 Inset * BufferView::checkInsetHit(int & x, int & y)
1686 int y_tmp = y + getScreen()->first;
1688 LyXCursor cursor = text->cursor;
1689 if (cursor.pos < cursor.par->Last()
1690 && cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET
1691 && cursor.par->GetInset(cursor.pos)
1692 && cursor.par->GetInset(cursor.pos)->Editable()) {
1694 // Check whether the inset really was hit
1695 Inset * tmpinset = cursor.par->GetInset(cursor.pos);
1696 LyXFont font = text->GetFont(cursor.par, cursor.pos);
1698 && x < cursor.x + tmpinset->Width(font)
1699 && y_tmp > cursor.y - tmpinset->Ascent(font)
1700 && y_tmp < cursor.y + tmpinset->Descent(font)) {
1702 // The origin of an inset is on the baseline
1703 y = y_tmp - (cursor.y);
1706 } else if (cursor.pos - 1 >= 0
1707 && cursor.par->GetChar(cursor.pos - 1) == LyXParagraph::META_INSET
1708 && cursor.par->GetInset(cursor.pos - 1)
1709 && cursor.par->GetInset(cursor.pos - 1)->Editable()) {
1711 Inset * result = checkInsetHit(x, y);
1713 text->CursorRight();
1722 Inset * BufferView::checkInsetHit(int & x, int & y)
1727 int y_tmp = y + getScreen()->first;
1729 LyXCursor cursor = buffer_->text->cursor;
1730 if (cursor.pos < cursor.par->Last()
1731 && cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET
1732 && cursor.par->GetInset(cursor.pos)
1733 && cursor.par->GetInset(cursor.pos)->Editable()) {
1735 // Check whether the inset really was hit
1736 Inset * tmpinset = cursor.par->GetInset(cursor.pos);
1737 LyXFont font = buffer_->text->GetFont(cursor.par, cursor.pos);
1739 && x < cursor.x + tmpinset->Width(font)
1740 && y_tmp > cursor.y - tmpinset->Ascent(font)
1741 && y_tmp < cursor.y + tmpinset->Descent(font)) {
1743 // The origin of an inset is on the baseline
1744 y = y_tmp - (cursor.y);
1747 } else if (cursor.pos - 1 >= 0
1748 && cursor.par->GetChar(cursor.pos - 1) == LyXParagraph::META_INSET
1749 && cursor.par->GetInset(cursor.pos - 1)
1750 && cursor.par->GetInset(cursor.pos - 1)->Editable()) {
1751 buffer_->text->CursorLeft();
1752 Inset * result = checkInsetHit(x, y);
1754 buffer_->text->CursorRight();
1764 int BufferView::workAreaExpose()
1766 if (!work_area || !work_area->form->visible)
1769 // this is a hack to ensure that we only call this through
1770 // BufferView::redraw().
1775 static int work_area_width = work_area->w;
1776 static int work_area_height = work_area->h;
1778 bool widthChange = work_area->w != work_area_width;
1779 bool heightChange = work_area->h != work_area_height;
1781 // update from work area
1782 work_area_width = work_area->w;
1783 work_area_height = work_area->h;
1786 // All buffers need a resize
1787 bufferlist.resize();
1788 } else if (heightChange) {
1789 // Rebuild image of current screen
1791 // fitCursor() ensures we don't jump back
1792 // to the start of the document on vertical
1796 // The main window size has changed, repaint most stuff
1798 // ...including the minibuffer
1799 owner_->getMiniBuffer()->Init();
1801 } else if (screen) screen->Redraw();
1803 // Grey box when we don't have a buffer
1804 fl_winset(FL_ObjWin(work_area));
1805 fl_rectangle(1, work_area->x, work_area->y,
1806 work_area->w, work_area->h, FL_GRAY63);
1809 // always make sure that the scrollbar is sane.
1811 owner_->updateLayoutChoice();
1816 // Callback for cursor timer
1817 void BufferView::CursorToggleCB(FL_OBJECT * ob, long)
1819 BufferView *view = static_cast<BufferView*>(ob->u_vdata);
1821 /* quite a nice place for asyncron Inset updating, isn't it? */
1822 // actually no! This is run even if no buffer exist... so (Lgb)
1823 if (view && !view->buffer_) {
1824 goto set_timer_and_return;
1828 // On my quest to solve the gs rendre hangups I am now
1829 // disabling the SIGHUP completely, and will do a wait
1830 // now and then instead. If the guess that xforms somehow
1831 // destroys something is true, this is likely (hopefully)
1832 // to solve the problem...at least I hope so. Lgb
1834 // ...Ok this seems to work...at least it does not make things
1835 // worse so far. However I still see gs processes that hangs.
1836 // I would really like to know _why_ they are hanging. Anyway
1837 // the solution without the SIGCHLD handler seems to be easier
1840 // When attaching gdb to a a running gs that hangs it shows
1841 // that it is waiting for input(?) Is it possible for us to
1842 // provide that input somehow? Or figure what it is expecing
1845 // One solution is to, after some time, look if there are some
1846 // old gs processes still running and if there are: kill them
1849 // Another solution is to provide the user an option to rerender
1850 // a picture. This would, for the picture in question, check if
1851 // there is a gs running for it, if so kill it, and start a new
1852 // rendering process.
1854 // these comments posted to lyx@via
1857 int pid = waitpid((pid_t)0, &status, WNOHANG);
1858 if (pid == -1) // error find out what is wrong
1859 ; // ignore it for now.
1861 sigchldhandler(pid, &status);
1863 if (InsetUpdateList)
1864 UpdateInsetUpdateList();
1866 if (view && !view->screen){
1867 goto set_timer_and_return;
1870 if (view->lyx_focus && view->work_area_focus) {
1871 if (!view->buffer_->the_locking_inset){
1872 view->screen->CursorToggle();
1874 view->buffer_->the_locking_inset->
1875 ToggleInsetCursor();
1877 goto set_timer_and_return;
1879 // Make sure that the cursor is visible.
1880 if (!view->buffer_->the_locking_inset){
1881 view->screen->ShowCursor();
1883 if (!view->buffer_->the_locking_inset->isCursorVisible())
1884 view->buffer_->the_locking_inset->
1885 ToggleInsetCursor();
1888 // This is only run when work_area_focus or lyx_focus is false.
1891 XGetInputFocus(fl_display, &tmpwin, &tmp);
1892 if (lyxerr.debugging()) {
1893 lyxerr << "tmpwin: " << tmpwin
1894 << "\nwindow: " << view->owner_->getForm()->window
1895 << "\nwork_area_focus: " << view->work_area_focus
1896 << "\nlyx_focus : " << view->lyx_focus
1899 if (tmpwin != view->owner_->getForm()->window) {
1900 view->lyx_focus = false;
1903 view->lyx_focus = true;
1904 if (!view->work_area_focus)
1907 goto set_timer_and_return;
1911 set_timer_and_return:
1912 fl_set_timer(ob, 0.4);
1918 int BufferView::WorkAreaSelectionNotify(FL_OBJECT *, Window win,
1919 int /*w*/, int /*h*/, XEvent *event, void */*d*/)
1921 if (buffer_ == 0) return 0;
1922 if (event->type != SelectionNotify)
1928 unsigned char * uc = 0;
1930 screen->HideCursor();
1932 if (event->xselection.type == XA_STRING
1933 && event->xselection.property) {
1935 if (XGetWindowProperty(
1936 fl_display /* display */,
1938 event->xselection.property /* property */,
1939 0 /* long_offset */,
1940 0 /* long_length */,
1942 XA_STRING /* req_type */,
1943 &tmpatom /* actual_type_return */,
1944 &tmpint /* actual_format_return */,
1945 &ul1 /* nitems_return */,
1946 &ul2 /* bytes_after_return */,
1947 &uc /* prop_return */
1958 if (XGetWindowProperty(
1959 fl_display /* display */,
1961 event->xselection.property /* property */,
1962 0 /* long_offset */,
1963 ul2/4+1 /* long_length */,
1965 XA_STRING /* req_type */,
1966 &tmpatom /* actual_type_return */,
1967 &tmpint /* actual_format_return */,
1968 &ul1 /* nitems_return */,
1969 &ul2 /* bytes_after_return */,
1970 &uc /* prop_return */
1979 text->InsertStringA(reinterpret_cast<char*>(uc));
1981 text->InsertStringB(reinterpret_cast<char*>(uc));
1986 InsertStringA(reinterpret_cast<char*>(uc));
1989 InsertStringB(reinterpret_cast<char*>(uc));
2007 void BufferView::cursorPrevious()
2009 if (!text->cursor.row->previous) return;
2011 long y = getScreen()->first;
2012 Row * cursorrow = text->cursor.row;
2013 text->SetCursorFromCoordinates(text->cursor.x_fix, y);
2015 // this is to allow jumping over large insets
2016 if ((cursorrow == text->cursor.row))
2019 if (text->cursor.row->height < work_area->h)
2020 getScreen()->Draw(text->cursor.y
2021 - text->cursor.row->baseline
2022 + text->cursor.row->height
2023 - work_area->h +1 );
2027 void BufferView::cursorNext()
2029 if (!text->cursor.row->next) return;
2031 long y = getScreen()->first;
2032 text->GetRowNearY(y);
2033 Row * cursorrow = text->cursor.row;
2034 text->SetCursorFromCoordinates(text->cursor.x_fix, y + work_area->h);
2036 /* this is to allow jumping over large insets */
2037 if ((cursorrow == text->cursor.row))
2040 if (text->cursor.row->height < work_area->h)
2041 getScreen()->Draw(text->cursor.y
2042 - text->cursor.row->baseline);
2045 void BufferView::cursorPrevious()
2047 if (!buffer()->text->cursor.row->previous) return;
2049 long y = getScreen()->first;
2050 Row * cursorrow = buffer()->text->cursor.row;
2052 SetCursorFromCoordinates(buffer()->text->
2055 buffer()->text->FinishUndo();
2056 // this is to allow jumping over large insets
2057 if ((cursorrow == buffer()->text->cursor.row))
2058 buffer()->text->CursorUp();
2060 if (buffer()->text->cursor.row->height < work_area->h)
2061 getScreen()->Draw(buffer()->text->cursor.y
2062 - buffer()->text->cursor.row->baseline
2063 + buffer()->text->cursor.row->height
2064 - work_area->h +1 );
2068 void BufferView::cursorNext()
2070 if (!buffer()->text->cursor.row->next) return;
2072 long y = getScreen()->first;
2073 buffer()->text->GetRowNearY(y);
2074 Row * cursorrow = buffer()->text->cursor.row;
2076 SetCursorFromCoordinates(buffer()->text->
2079 buffer()->text->FinishUndo();
2080 /* this is to allow jumping over large insets */
2081 if ((cursorrow == buffer()->text->cursor.row))
2082 buffer()->text->CursorDown();
2084 if (buffer()->text->cursor.row->height < work_area->h)
2085 getScreen()->Draw(buffer()->text->cursor.y
2086 - buffer()->text->cursor.row->baseline);
2090 bool BufferView::available() const
2093 if (buffer_ && text) return true;
2095 if (buffer_ && buffer_->text) return true;
2101 void BufferView::savePosition()
2104 backstack.push(buffer()->fileName(),
2108 backstack.push(buffer()->getFileName(),
2109 buffer()->text->cursor.x,
2110 buffer()->text->cursor.y);
2115 void BufferView::restorePosition()
2117 if (backstack.empty()) return;
2120 string fname = backstack.pop(&x, &y);
2123 Buffer * b = (bufferlist.exists(fname)) ? bufferlist.getBuffer(fname):
2124 bufferlist.loadLyXFile(fname); // don't ask, just load it
2127 text->SetCursorFromCoordinates(x, y);
2130 buffer()->text->SetCursorFromCoordinates(x, y);
2131 buffer()->update(0);
2137 // candidate for move to BufferView
2138 void BufferView::update(signed char f)
2140 owner()->updateLayoutChoice();
2142 if (!text->selection && f > -3)
2143 text->sel_cursor = text->cursor;
2146 text->FullRebreak();
2150 if (f != 3 && f != -3) {
2155 if (f == 1 || f == -1) {
2156 if (buffer()->isLyxClean()) {
2157 buffer()->markDirty();
2158 owner()->getMiniBuffer()->setTimer(4);
2160 buffer()->markDirty();