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;
474 // Just a bunch of C wrappers around static members of BufferView
475 void C_BufferView_UpCB(FL_OBJECT * ob, long buf)
477 BufferView::UpCB(ob, buf);
481 void C_BufferView_DownCB(FL_OBJECT * ob, long buf)
483 BufferView::DownCB(ob, buf);
487 void C_BufferView_ScrollCB(FL_OBJECT * ob, long buf)
489 BufferView::ScrollCB(ob, buf);
493 void C_BufferView_CursorToggleCB(FL_OBJECT * ob, long buf)
495 BufferView::CursorToggleCB(ob, buf);
499 int C_BufferView_work_area_handler(FL_OBJECT * ob, int event,
503 return BufferView::work_area_handler(ob, event,
509 void BufferView::create_view(int xpos, int ypos, int width, int height)
512 const int bw = abs(fl_get_border_width());
514 // a hack for the figinsets (Matthias)
515 // This one first, then it will probably be invisible. (Lgb)
516 ::figinset_canvas = figinset_canvas = obj =
517 fl_add_canvas(FL_NORMAL_CANVAS,
520 fl_set_object_boxtype(obj, FL_NO_BOX);
521 fl_set_object_resize(obj, FL_RESIZE_ALL);
522 fl_set_object_gravity(obj, NorthWestGravity, NorthWestGravity);
525 obj = fl_add_box(FL_BORDER_BOX, xpos, ypos,
528 fl_set_object_resize(obj, FL_RESIZE_ALL);
529 fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
532 work_area = obj = fl_add_free(FL_INPUT_FREE,
534 width-15-2*bw /* scrollbarwidth */,
536 C_BufferView_work_area_handler);
537 obj->wantkey = FL_KEY_TAB;
538 obj->u_vdata = this; /* This is how we pass the BufferView
539 to the work_area_handler. */
540 fl_set_object_boxtype(obj, FL_DOWN_BOX);
541 fl_set_object_resize(obj, FL_RESIZE_ALL);
542 fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
548 // up - scrollbar button
550 fl_set_border_width(-1);
552 fl_set_border_width(-2); // to get visible feedback
554 button_up = obj = fl_add_pixmapbutton(FL_TOUCH_BUTTON,
558 fl_set_object_boxtype(obj, FL_UP_BOX);
559 fl_set_object_color(obj, FL_MCOL, FL_BLUE);
560 fl_set_object_resize(obj, FL_RESIZE_ALL);
561 fl_set_object_gravity(obj, NorthEastGravity, NorthEastGravity);
562 fl_set_object_callback(obj, C_BufferView_UpCB, 0);
564 fl_set_pixmapbutton_data(obj, const_cast<char**>(up_xpm));
567 // Remove the blue feedback rectangle
568 fl_set_pixmapbutton_focus_outline(obj, 0);
571 // the scrollbar slider
572 fl_set_border_width(-bw);
573 scrollbar = obj = fl_add_slider(FL_VERT_SLIDER,
577 fl_set_object_color(obj, FL_COL1, FL_MCOL);
578 fl_set_object_boxtype(obj, FL_UP_BOX);
579 fl_set_object_resize(obj, FL_RESIZE_ALL);
580 fl_set_object_gravity(obj, NorthEastGravity, SouthEastGravity);
581 fl_set_object_callback(obj, C_BufferView_ScrollCB, 0);
584 // down - scrollbar button
586 fl_set_border_width(-1);
588 fl_set_border_width(-2); // to get visible feedback
590 button_down = obj = fl_add_pixmapbutton(FL_TOUCH_BUTTON,
594 fl_set_object_boxtype(obj, FL_UP_BOX);
595 fl_set_object_color(obj, FL_MCOL, FL_BLUE);
596 fl_set_object_resize(obj, FL_RESIZE_ALL);
597 fl_set_object_gravity(obj, SouthEastGravity, SouthEastGravity);
598 fl_set_object_callback(obj, C_BufferView_DownCB, 0);
600 fl_set_pixmapbutton_data(obj, const_cast<char**>(down_xpm));
601 fl_set_border_width(-bw);
604 // Remove the blue feedback rectangle
605 fl_set_pixmapbutton_focus_outline(obj, 0);
613 timer_cursor = obj = fl_add_timer(FL_HIDDEN_TIMER,
614 0, 0, 0, 0, "Timer");
615 fl_set_object_callback(obj, C_BufferView_CursorToggleCB, 0);
620 // Callback for scrollbar up button
621 void BufferView::UpCB(FL_OBJECT * ob, long)
623 BufferView * view = static_cast<BufferView*>(ob->u_vdata);
625 if (view->buffer_ == 0) return;
627 static long time = 0;
628 XEvent const * ev2 = fl_last_event();
629 if (ev2->type == ButtonPress || ev2->type == ButtonRelease)
631 int button = fl_get_button_numb(ob);
634 view->ScrollUpOnePage(time++); break;
636 view->ScrollDownOnePage(time++); break;
638 view->ScrollUp(time++); break;
650 a = XInternAtom(fl_display, "WAIT_FOR_X", False);
653 XSetWindowAttributes attr;
654 mask = CWOverrideRedirect;
655 attr.override_redirect = 1;
656 w = XCreateWindow(fl_display, fl_root,
657 0, 0, 1, 1, 0, CopyFromParent,
658 InputOnly, CopyFromParent, mask, &attr);
659 XSelectInput(fl_display, w, PropertyChangeMask);
660 XMapWindow(fl_display, w);
663 XChangeProperty(fl_display, w, a, a, 8,
664 PropModeAppend, reinterpret_cast<unsigned char*>(""), 0);
665 XWindowEvent(fl_display, w, PropertyChangeMask, &ev);
667 XSync(fl_get_display(), 0);
671 // Callback for scrollbar slider
672 void BufferView::ScrollCB(FL_OBJECT * ob, long)
674 BufferView * view = static_cast<BufferView*>(ob->u_vdata);
675 extern bool cursor_follows_scrollbar;
677 if (view->buffer_ == 0) return;
679 view->current_scrollbar_value = long(fl_get_slider_value(ob));
680 if (view->current_scrollbar_value < 0)
681 view->current_scrollbar_value = 0;
686 view->screen->Draw(view->current_scrollbar_value);
688 if (cursor_follows_scrollbar) {
690 LyXText * vbt = view->text;
692 LyXText * vbt = view->buffer_->text;
694 int height = vbt->DefaultHeight();
696 if (vbt->cursor.y < view->screen->first + height) {
697 vbt->SetCursorFromCoordinates(0,
698 view->screen->first +
701 else if (vbt->cursor.y >
702 view->screen->first + view->work_area->h - height) {
703 vbt->SetCursorFromCoordinates(0,
704 view->screen->first +
713 // Callback for scrollbar down button
714 void BufferView::DownCB(FL_OBJECT * ob, long)
716 BufferView * view = static_cast<BufferView*>(ob->u_vdata);
718 if (view->buffer_ == 0) return;
721 static long time = 0;
722 ev2 = fl_last_event();
723 if (ev2->type == ButtonPress || ev2->type == ButtonRelease)
725 int button = fl_get_button_numb(ob);
728 view->ScrollUpOnePage(time++); break;
730 view->ScrollDownOnePage(time++); break;
732 view->ScrollDown(time++); break;
737 int BufferView::ScrollUp(long time)
739 if (buffer_ == 0) return 0;
743 double value= fl_get_slider_value(scrollbar);
749 float add_value = (text->DefaultHeight()
750 + float(time) * float(time) * 0.125);
752 if (add_value > work_area->h)
753 add_value = float(work_area->h -
754 text->DefaultHeight());
756 float add_value = (buffer_->text->DefaultHeight()
757 + float(time) * float(time) * 0.125);
759 if (add_value > work_area->h)
760 add_value = float(work_area->h -
761 buffer_->text->DefaultHeight());
769 fl_set_slider_value(scrollbar, value);
771 ScrollCB(scrollbar, 0);
776 int BufferView::ScrollDown(long time)
778 if (buffer_ == 0) return 0;
782 double value= fl_get_slider_value(scrollbar);
784 fl_get_slider_bounds(scrollbar, &min, &max);
790 float add_value = (text->DefaultHeight()
791 + float(time) * float(time) * 0.125);
793 if (add_value > work_area->h)
794 add_value = float(work_area->h -
795 text->DefaultHeight());
797 float add_value = (buffer_->text->DefaultHeight()
798 + float(time) * float(time) * 0.125);
800 if (add_value > work_area->h)
801 add_value = float(work_area->h -
802 buffer_->text->DefaultHeight());
810 fl_set_slider_value(scrollbar, value);
812 ScrollCB(scrollbar, 0);
817 void BufferView::ScrollUpOnePage(long /*time*/)
819 if (buffer_ == 0) return;
823 long y = screen->first;
827 Row * row = text->GetRowNearY(y);
829 Row * row = buffer_->text->GetRowNearY(y);
831 y = y - work_area->h + row->height;
833 fl_set_slider_value(scrollbar, y);
835 ScrollCB(scrollbar, 0);
839 void BufferView::ScrollDownOnePage(long /*time*/)
841 if (buffer_ == 0) return;
846 fl_get_slider_bounds(scrollbar, &min, &max);
847 long y = screen->first;
850 if (y > text->height - work_area->h)
854 text->GetRowNearY(y);
856 if (y > buffer_->text->height - work_area->h)
860 buffer_->text->GetRowNearY(y);
862 fl_set_slider_value(scrollbar, y);
864 ScrollCB(scrollbar, 0);
868 int BufferView::work_area_handler(FL_OBJECT * ob, int event,
870 int /*key*/, void *xev)
872 static int x_old = -1;
873 static int y_old = -1;
874 static long scrollbar_value_old = -1;
876 XEvent * ev = static_cast<XEvent*>(xev);
877 BufferView * view = static_cast<BufferView*>(ob->u_vdata);
879 // If we don't have a view yet; return
880 if (!view || quitting) return 0;
884 view->workAreaExpose();
887 view->WorkAreaButtonPress(ob, 0, 0, 0, ev, 0);
890 view->WorkAreaButtonRelease(ob, 0, 0, 0, ev, 0);
893 if (ev->xmotion.x != x_old ||
894 ev->xmotion.y != y_old ||
895 view->current_scrollbar_value != scrollbar_value_old) {
896 x_old = ev->xmotion.x;
897 y_old = ev->xmotion.y;
898 scrollbar_value_old = view->current_scrollbar_value;
899 view->WorkAreaMotionNotify(ob, 0, 0, 0, ev, 0);
902 // Done by the raw callback:
903 // case FL_KEYBOARD: WorkAreaKeyPress(ob, 0, 0, 0, ev, 0); break;
905 if (!view->owner_->getMiniBuffer()->shows_no_match)
906 view->owner_->getMiniBuffer()->Init();
907 view->owner_->getMiniBuffer()->shows_no_match = false;
908 view->work_area_focus = true;
909 fl_set_timer(view->timer_cursor, 0.4);
912 view->owner_->getMiniBuffer()->ExecCommand();
913 view->work_area_focus = false;
916 SetXtermCursor(view->owner_->getForm()->window);
918 view->lyx_focus = true;
919 fl_set_timer(view->timer_cursor, 0.4);
922 if (!input_prohibited)
923 XUndefineCursor(fl_display,
924 view->owner_->getForm()->window);
925 view->lyx_focus = false; // This is not an absolute truth
926 // but if it is not true, it will be changed within a blink
927 // of an eye. ... Not good enough... use regulare timeperiod
928 //fl_set_timer(view->timer_cursor, 0.01); // 0.1 sec blink
929 fl_set_timer(view->timer_cursor, 0.4); // 0.4 sec blink
933 if (view->buffer_ && !view->buffer_->the_locking_inset) {
934 if (view->screen && ev->xbutton.button == 1) {
935 view->screen->HideCursor();
936 view->screen->ToggleSelection();
938 view->text->SelectWord();
940 view->buffer_->text->SelectWord();
942 view->screen->ToggleSelection(false);
943 /* This will fit the cursor on the screen
948 view->buffer_->update(0);
955 if (view->buffer_ && view->screen && ev->xbutton.button == 1) {
956 view->screen->HideCursor();
957 view->screen->ToggleSelection();
959 view->text->CursorHome();
960 view->text->sel_cursor = view->text->cursor;
961 view->text->CursorEnd();
962 view->text->SetSelection();
964 view->buffer_->text->CursorHome();
965 view->buffer_->text->sel_cursor =
966 view->buffer_->text->cursor;
967 view->buffer_->text->CursorEnd();
968 view->buffer_->text->SetSelection();
970 view->screen->ToggleSelection(false);
971 /* This will fit the cursor on the screen
976 view->buffer_->update(0);
981 view->WorkAreaSelectionNotify(ob,
982 view->owner_->getForm()->window,
989 int BufferView::WorkAreaMotionNotify(FL_OBJECT *ob, Window,
990 int /*w*/, int /*h*/,
991 XEvent *ev, void */*d*/)
994 if (buffer_ == 0) return 0;
995 if (!screen) return 0;
997 // Check for inset locking
998 if (buffer_->the_locking_inset) {
1000 LyXCursor cursor = text->cursor;
1002 LyXCursor cursor = buffer_->text->cursor;
1004 buffer_->the_locking_inset->
1005 InsetMotionNotify(ev->xbutton.x - ob->x - cursor.x,
1006 ev->xbutton.y - ob->y -
1012 // Only use motion with button 1
1013 if (!ev->xmotion.state & Button1MotionMask)
1016 /* The selection possible is needed, that only motion events are
1017 * used, where the bottom press event was on the drawing area too */
1018 if (selection_possible) {
1019 screen->HideCursor();
1022 text->SetCursorFromCoordinates(ev->xbutton.x - ob->x,
1023 ev->xbutton.y - ob->y +
1026 if (!text->selection)
1027 update(-3); // Maybe an empty line was deleted
1029 text->SetSelection();
1032 SetCursorFromCoordinates(ev->xbutton.x - ob->x,
1033 ev->xbutton.y - ob->y +
1036 if (!buffer_->text->selection)
1037 buffer_->update(-3); // Maybe an empty line was deleted
1039 buffer_->text->SetSelection();
1041 screen->ToggleToggle();
1042 if (screen->FitCursor())
1044 screen->ShowCursor();
1050 extern int bibitemMaxWidth(LyXFont const &);
1053 // Single-click on work area
1054 int BufferView::WorkAreaButtonPress(FL_OBJECT *ob, Window,
1055 int /*w*/, int /*h*/, XEvent *ev, void */*d*/)
1060 if (buffer_ == 0) return 0;
1061 if (!screen) return 0;
1063 int const x = ev->xbutton.x - ob->x;
1064 int const y = ev->xbutton.y - ob->y;
1065 // If we hit an inset, we have the inset coordinates in these
1066 // and inset_hit points to the inset. If we do not hit an
1067 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
1070 Inset * inset_hit = checkInsetHit(inset_x, inset_y);
1072 // ok ok, this is a hack.
1073 int button = ev->xbutton.button;
1074 if (button == 4 || button == 5) goto wheel;
1078 if (buffer_->the_locking_inset) {
1079 // We are in inset locking mode
1081 /* Check whether the inset was hit. If not reset mode,
1082 otherwise give the event to the inset */
1083 if (inset_hit != 0) {
1084 buffer_->the_locking_inset->
1085 InsetButtonPress(inset_x, inset_y, button);
1088 UnlockInset(buffer_->the_locking_inset);
1092 selection_possible = true;
1093 screen->HideCursor();
1095 // Right button mouse click on a table
1097 (text->cursor.par->table ||
1098 text->MouseHitInTable(x, y + screen->first))) {
1099 // Set the cursor to the press-position
1100 text->SetCursorFromCoordinates(x, y + screen->first);
1103 // Only show the table popup if the hit is in the table, too
1104 if (!text->HitInTable(text->cursor.row, x))
1107 // Hit above or below the table?
1109 if (!text->selection) {
1110 screen->ToggleSelection();
1111 text->ClearSelection();
1112 text->FullRebreak();
1116 // Popup table popup when on a table.
1117 // This is obviously temporary, since we should be
1119 // popup various context-sensitive-menus with the
1120 // the right mouse. So this should be done more
1121 // general in the future. Matthias.
1122 selection_possible = false;
1123 owner_->getLyXFunc()->Dispatch(LFUN_LAYOUT_TABLE,
1129 int screen_first = screen->first;
1131 // Middle button press pastes if we have a selection
1132 bool paste_internally = false;
1133 if (button == 2 // && !buffer_->the_locking_inset
1134 && text->selection) {
1135 owner_->getLyXFunc()->Dispatch(LFUN_COPY);
1136 paste_internally = true;
1139 // Clear the selection
1140 screen->ToggleSelection();
1141 text->ClearSelection();
1142 text->FullRebreak();
1146 // Single left click in math inset?
1147 if (inset_hit != 0 && inset_hit->Editable() == 2) {
1148 // Highly editable inset, like math
1149 selection_possible = false;
1150 owner_->updateLayoutChoice();
1151 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
1152 inset_hit->Edit(inset_x, inset_y);
1156 // Right click on a footnote flag opens float menu
1158 selection_possible = false;
1162 text->SetCursorFromCoordinates(x, y + screen_first);
1164 text->sel_cursor = text->cursor;
1165 text->cursor.x_fix = text->cursor.x;
1167 owner_->updateLayoutChoice();
1168 if (screen->FitCursor()){
1170 selection_possible = false;
1173 // Insert primary selection with middle mouse
1174 // if there is a local selection in the current buffer, insert this
1175 if (button == 2) { // && !buffer_->the_locking_inset){
1176 if (paste_internally)
1177 owner_->getLyXFunc()->Dispatch(LFUN_PASTE);
1179 owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION,
1181 selection_possible = false;
1187 // I am not quite sure if this is the correct place to put this,
1188 // but it will not cause any harm.
1189 // Patch from Mark Huang (markman@mit.edu) to make LyX recognise
1190 // button 4 and 5. This enables LyX use use the scrollwhell on
1191 // certain mice for something useful. (Lgb)
1192 // Added wheel acceleration detection code. (Rvdk)
1193 static Time lastTime = 0;
1194 int diff = ev->xbutton.time - lastTime;
1195 int scroll = int(1.0 + (4.0/(abs(diff)+1.0))*200.0);
1204 lastTime = ev->xbutton.time;
1214 // Single-click on work area
1215 int BufferView::WorkAreaButtonPress(FL_OBJECT *ob, Window,
1216 int /*w*/, int /*h*/, XEvent *ev, void */*d*/)
1221 if (buffer_ == 0) return 0;
1222 if (!screen) return 0;
1224 int const x = ev->xbutton.x - ob->x;
1225 int const y = ev->xbutton.y - ob->y;
1226 // If we hit an inset, we have the inset coordinates in these
1227 // and inset_hit points to the inset. If we do not hit an
1228 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
1231 Inset * inset_hit = checkInsetHit(inset_x, inset_y);
1233 // ok ok, this is a hack.
1234 int button = ev->xbutton.button;
1235 if (button == 4 || button == 5) goto wheel;
1239 if (buffer_->the_locking_inset) {
1240 // We are in inset locking mode
1242 /* Check whether the inset was hit. If not reset mode,
1243 otherwise give the event to the inset */
1244 if (inset_hit != 0) {
1245 buffer_->the_locking_inset->
1246 InsetButtonPress(inset_x, inset_y, button);
1249 UnlockInset(buffer_->the_locking_inset);
1253 selection_possible = true;
1254 screen->HideCursor();
1256 // Right button mouse click on a table
1258 (buffer_->text->cursor.par->table ||
1259 buffer_->text->MouseHitInTable(x, y+screen->first))) {
1260 // Set the cursor to the press-position
1261 buffer_->text->SetCursorFromCoordinates(x, y + screen->first);
1264 // Only show the table popup if the hit is in the table, too
1265 if (!buffer_->text->HitInTable(buffer_->text->cursor.row, x))
1268 // Hit above or below the table?
1270 if (!buffer_->text->selection) {
1271 screen->ToggleSelection();
1272 buffer_->text->ClearSelection();
1273 buffer_->text->FullRebreak();
1277 // Popup table popup when on a table.
1278 // This is obviously temporary, since we should be
1280 // popup various context-sensitive-menus with the
1281 // the right mouse. So this should be done more
1282 // general in the future. Matthias.
1283 selection_possible = false;
1284 owner_->getLyXFunc()->Dispatch(LFUN_LAYOUT_TABLE,
1290 int screen_first = screen->first;
1292 // Middle button press pastes if we have a selection
1293 bool paste_internally = false;
1294 if (button == 2 // && !buffer_->the_locking_inset
1295 && buffer_->text->selection) {
1296 owner_->getLyXFunc()->Dispatch(LFUN_COPY);
1297 paste_internally = true;
1300 // Clear the selection
1301 screen->ToggleSelection();
1302 buffer_->text->ClearSelection();
1303 buffer_->text->FullRebreak();
1307 // Single left click in math inset?
1308 if (inset_hit != 0 && inset_hit->Editable() == 2) {
1309 // Highly editable inset, like math
1310 selection_possible = false;
1311 owner_->updateLayoutChoice();
1312 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
1313 inset_hit->Edit(inset_x, inset_y);
1317 // Right click on a footnote flag opens float menu
1319 selection_possible = false;
1323 buffer_->text->SetCursorFromCoordinates(x, y + screen_first);
1324 buffer_->text->FinishUndo();
1325 buffer_->text->sel_cursor = buffer_->text->cursor;
1326 buffer_->text->cursor.x_fix = buffer_->text->cursor.x;
1328 owner_->updateLayoutChoice();
1329 if (screen->FitCursor()){
1331 selection_possible = false;
1334 // Insert primary selection with middle mouse
1335 // if there is a local selection in the current buffer, insert this
1336 if (button == 2) { // && !buffer_->the_locking_inset){
1337 if (paste_internally)
1338 owner_->getLyXFunc()->Dispatch(LFUN_PASTE);
1340 owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION,
1342 selection_possible = false;
1348 // I am not quite sure if this is the correct place to put this,
1349 // but it will not cause any harm.
1350 // Patch from Mark Huang (markman@mit.edu) to make LyX recognise
1351 // button 4 and 5. This enables LyX use use the scrollwhell on
1352 // certain mice for something useful. (Lgb)
1353 // Added wheel acceleration detection code. (Rvdk)
1354 static Time lastTime = 0;
1355 int diff = ev->xbutton.time - lastTime;
1356 int scroll = int(1.0 + (4.0/(abs(diff)+1.0))*200.0);
1365 lastTime = ev->xbutton.time;
1377 int BufferView::WorkAreaButtonRelease(FL_OBJECT * ob, Window ,
1378 int /*w*/, int /*h*/, XEvent * ev, void * /*d*/)
1380 if (buffer_ == 0 || screen == 0) return 0;
1382 int const x = ev->xbutton.x - ob->x;
1383 int const y = ev->xbutton.y - ob->y;
1385 // If we hit an inset, we have the inset coordinates in these
1386 // and inset_hit points to the inset. If we do not hit an
1387 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
1390 Inset * inset_hit = checkInsetHit(inset_x, inset_y);
1392 if (buffer_->the_locking_inset) {
1393 // We are in inset locking mode.
1395 /* LyX does a kind of work-area grabbing for insets.
1396 Only a ButtonPress Event outside the inset will
1397 force a InsetUnlock. */
1398 buffer_->the_locking_inset->
1399 InsetButtonRelease(inset_x, inset_y,
1400 ev->xbutton.button);
1404 selection_possible = false;
1405 if (text->cursor.par->table) {
1407 NumberOfCell(text->cursor.par,
1409 if (text->cursor.par->table->IsContRow(cell) &&
1410 text->cursor.par->table->
1411 CellHasContRow(text->cursor.par->table->
1412 GetCellAbove(cell))<0) {
1417 if (ev->xbutton.button >= 2)
1420 // Make sure that the press was not far from the release
1421 if ((abs(last_click_x - x) >= 5) ||
1422 (abs(last_click_y - y) >= 5)) {
1426 // Did we hit an editable inset?
1427 if (inset_hit != 0) {
1428 // Inset like error, notes and figures
1429 selection_possible = false;
1430 #ifdef WITH_WARNINGS
1431 #warning fix this proper in 0.13
1433 // Following a ref shouldn't issue
1434 // a push on the undo-stack
1435 // anylonger, now that we have
1436 // keybindings for following
1437 // references and returning from
1438 // references. IMHO though, it
1439 // should be the inset's own business
1440 // to push or not push on the undo
1441 // stack. They don't *have* to
1442 // alter the document...
1444 // ...or maybe the SetCursorParUndo()
1445 // below isn't necessary at all anylonger?
1446 if (inset_hit->LyxCode() == Inset::REF_CODE) {
1447 text->SetCursorParUndo();
1450 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
1451 inset_hit->Edit(inset_x, inset_y);
1455 // check whether we want to open a float
1459 if (text->cursor.pos <
1460 text->cursor.par->Last()) {
1461 c = text->cursor.par->
1462 GetChar(text->cursor.pos);
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){
1472 } else if (text->cursor.pos - 1 >= 0) {
1473 c = text->cursor.par->
1474 GetChar(text->cursor.pos - 1);
1475 if (c == LyXParagraph::META_FOOTNOTE
1476 || c == LyXParagraph::META_MARGIN
1477 || c == LyXParagraph::META_FIG
1478 || c == LyXParagraph::META_TAB
1479 || c == LyXParagraph::META_WIDE_FIG
1480 || c == LyXParagraph::META_WIDE_TAB
1481 || c == LyXParagraph::META_ALGORITHM){
1482 // We are one step too far to the right
1489 selection_possible = false;
1494 // Do we want to close a float? (click on the float-label)
1495 if (text->cursor.row->par->footnoteflag ==
1496 LyXParagraph::OPEN_FOOTNOTE
1497 && text->cursor.pos == 0
1498 && text->cursor.row->previous &&
1499 text->cursor.row->previous->par->
1500 footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
1501 LyXFont font (LyXFont::ALL_SANE);
1502 font.setSize(LyXFont::SIZE_SMALL);
1504 int box_x = 20; // LYX_PAPER_MARGIN;
1505 box_x += font.textWidth("Mwide-figM", 10);
1507 int screen_first = screen->first;
1510 && y + screen_first > text->cursor.y -
1511 text->cursor.row->baseline
1512 && y + screen_first < text->cursor.y -
1513 text->cursor.row->baseline
1514 + font.maxAscent()*1.2 + font.maxDescent()*1.2) {
1516 selection_possible = false;
1521 // Maybe we want to edit a bibitem ale970302
1522 if (text->cursor.par->bibkey && x < 20 +
1523 bibitemMaxWidth(textclasslist.TextClass(buffer_->
1524 params.textclass).defaultfont())) {
1525 text->cursor.par->bibkey->Edit(0, 0);
1531 int BufferView::WorkAreaButtonRelease(FL_OBJECT *ob, Window ,
1532 int /*w*/, int /*h*/, XEvent *ev, void */*d*/)
1534 if (buffer_ == 0 || screen == 0) return 0;
1536 int const x = ev->xbutton.x - ob->x;
1537 int const y = ev->xbutton.y - ob->y;
1539 // If we hit an inset, we have the inset coordinates in these
1540 // and inset_hit points to the inset. If we do not hit an
1541 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
1544 Inset * inset_hit = checkInsetHit(inset_x, inset_y);
1546 if (buffer_->the_locking_inset) {
1547 // We are in inset locking mode.
1549 /* LyX does a kind of work-area grabbing for insets.
1550 Only a ButtonPress Event outside the inset will
1551 force a InsetUnlock. */
1552 buffer_->the_locking_inset->
1553 InsetButtonRelease(inset_x, inset_y,
1554 ev->xbutton.button);
1558 selection_possible = false;
1559 if (buffer_->text->cursor.par->table) {
1560 int cell = buffer_->text->
1561 NumberOfCell(buffer_->text->cursor.par,
1562 buffer_->text->cursor.pos);
1563 if (buffer_->text->cursor.par->table->IsContRow(cell) &&
1564 buffer_->text->cursor.par->table->
1565 CellHasContRow(buffer_->text->cursor.par->table->
1566 GetCellAbove(cell))<0) {
1567 buffer_->text->CursorUp();
1571 if (ev->xbutton.button >= 2)
1574 // Make sure that the press was not far from the release
1575 if ((abs(last_click_x - x) >= 5) ||
1576 (abs(last_click_y - y) >= 5)) {
1580 // Did we hit an editable inset?
1581 if (inset_hit != 0) {
1582 // Inset like error, notes and figures
1583 selection_possible = false;
1584 #ifdef WITH_WARNINGS
1585 #warning fix this proper in 0.13
1587 // Following a ref shouldn't issue
1588 // a push on the undo-stack
1589 // anylonger, now that we have
1590 // keybindings for following
1591 // references and returning from
1592 // references. IMHO though, it
1593 // should be the inset's own business
1594 // to push or not push on the undo
1595 // stack. They don't *have* to
1596 // alter the document...
1598 // ...or maybe the SetCursorParUndo()
1599 // below isn't necessary at all anylonger?
1600 if (inset_hit->LyxCode() == Inset::REF_CODE) {
1601 buffer_->text->SetCursorParUndo();
1604 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
1605 inset_hit->Edit(inset_x, inset_y);
1609 // check whether we want to open a float
1610 if (buffer_->text) {
1613 if (buffer_->text->cursor.pos <
1614 buffer_->text->cursor.par->Last()) {
1615 c = buffer_->text->cursor.par->
1616 GetChar(buffer_->text->cursor.pos);
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){
1626 } else if (buffer_->text->cursor.pos - 1 >= 0) {
1627 c = buffer_->text->cursor.par->
1628 GetChar(buffer_->text->cursor.pos - 1);
1629 if (c == LyXParagraph::META_FOOTNOTE
1630 || c == LyXParagraph::META_MARGIN
1631 || c == LyXParagraph::META_FIG
1632 || c == LyXParagraph::META_TAB
1633 || c == LyXParagraph::META_WIDE_FIG
1634 || c == LyXParagraph::META_WIDE_TAB
1635 || c == LyXParagraph::META_ALGORITHM){
1636 // We are one step too far to the right
1637 buffer_->text->CursorLeft();
1643 selection_possible = false;
1648 // Do we want to close a float? (click on the float-label)
1649 if (buffer_->text->cursor.row->par->footnoteflag ==
1650 LyXParagraph::OPEN_FOOTNOTE
1651 && buffer_->text->cursor.pos == 0
1652 && buffer_->text->cursor.row->previous &&
1653 buffer_->text->cursor.row->previous->par->
1654 footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
1655 LyXFont font (LyXFont::ALL_SANE);
1656 font.setSize(LyXFont::SIZE_SMALL);
1658 int box_x = 20; // LYX_PAPER_MARGIN;
1659 box_x += font.textWidth("Mwide-figM", 10);
1661 int screen_first = screen->first;
1664 && y + screen_first > buffer_->text->cursor.y -
1665 buffer_->text->cursor.row->baseline
1666 && y + screen_first < buffer_->text->cursor.y -
1667 buffer_->text->cursor.row->baseline
1668 + font.maxAscent()*1.2 + font.maxDescent()*1.2) {
1670 selection_possible = false;
1675 // Maybe we want to edit a bibitem ale970302
1676 if (buffer_->text->cursor.par->bibkey && x < 20 +
1677 bibitemMaxWidth(textclasslist.TextClass(buffer_->
1678 params.textclass).defaultfont())) {
1679 buffer_->text->cursor.par->bibkey->Edit(0, 0);
1687 * Returns an inset if inset was hit. 0 otherwise.
1688 * If hit, the coordinates are changed relative to the inset.
1689 * Otherwise coordinates are not changed, and false is returned.
1692 Inset * BufferView::checkInsetHit(int & x, int & y)
1697 int y_tmp = y + getScreen()->first;
1699 LyXCursor cursor = text->cursor;
1700 if (cursor.pos < cursor.par->Last()
1701 && cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET
1702 && cursor.par->GetInset(cursor.pos)
1703 && cursor.par->GetInset(cursor.pos)->Editable()) {
1705 // Check whether the inset really was hit
1706 Inset * tmpinset = cursor.par->GetInset(cursor.pos);
1707 LyXFont font = text->GetFont(cursor.par, cursor.pos);
1709 && x < cursor.x + tmpinset->Width(font)
1710 && y_tmp > cursor.y - tmpinset->Ascent(font)
1711 && y_tmp < cursor.y + tmpinset->Descent(font)) {
1713 // The origin of an inset is on the baseline
1714 y = y_tmp - (cursor.y);
1717 } else if (cursor.pos - 1 >= 0
1718 && cursor.par->GetChar(cursor.pos - 1) == LyXParagraph::META_INSET
1719 && cursor.par->GetInset(cursor.pos - 1)
1720 && cursor.par->GetInset(cursor.pos - 1)->Editable()) {
1722 Inset * result = checkInsetHit(x, y);
1724 text->CursorRight();
1733 Inset * BufferView::checkInsetHit(int & x, int & y)
1738 int y_tmp = y + getScreen()->first;
1740 LyXCursor cursor = buffer_->text->cursor;
1741 if (cursor.pos < cursor.par->Last()
1742 && cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET
1743 && cursor.par->GetInset(cursor.pos)
1744 && cursor.par->GetInset(cursor.pos)->Editable()) {
1746 // Check whether the inset really was hit
1747 Inset * tmpinset = cursor.par->GetInset(cursor.pos);
1748 LyXFont font = buffer_->text->GetFont(cursor.par, cursor.pos);
1750 && x < cursor.x + tmpinset->Width(font)
1751 && y_tmp > cursor.y - tmpinset->Ascent(font)
1752 && y_tmp < cursor.y + tmpinset->Descent(font)) {
1754 // The origin of an inset is on the baseline
1755 y = y_tmp - (cursor.y);
1758 } else if (cursor.pos - 1 >= 0
1759 && cursor.par->GetChar(cursor.pos - 1) == LyXParagraph::META_INSET
1760 && cursor.par->GetInset(cursor.pos - 1)
1761 && cursor.par->GetInset(cursor.pos - 1)->Editable()) {
1762 buffer_->text->CursorLeft();
1763 Inset * result = checkInsetHit(x, y);
1765 buffer_->text->CursorRight();
1775 int BufferView::workAreaExpose()
1777 if (!work_area || !work_area->form->visible)
1780 // this is a hack to ensure that we only call this through
1781 // BufferView::redraw().
1786 static int work_area_width = work_area->w;
1787 static int work_area_height = work_area->h;
1789 bool widthChange = work_area->w != work_area_width;
1790 bool heightChange = work_area->h != work_area_height;
1792 // update from work area
1793 work_area_width = work_area->w;
1794 work_area_height = work_area->h;
1797 // All buffers need a resize
1798 bufferlist.resize();
1799 } else if (heightChange) {
1800 // Rebuild image of current screen
1802 // fitCursor() ensures we don't jump back
1803 // to the start of the document on vertical
1807 // The main window size has changed, repaint most stuff
1809 // ...including the minibuffer
1810 owner_->getMiniBuffer()->Init();
1812 } else if (screen) screen->Redraw();
1814 // Grey box when we don't have a buffer
1815 fl_winset(FL_ObjWin(work_area));
1816 fl_rectangle(1, work_area->x, work_area->y,
1817 work_area->w, work_area->h, FL_GRAY63);
1820 // always make sure that the scrollbar is sane.
1822 owner_->updateLayoutChoice();
1827 // Callback for cursor timer
1828 void BufferView::CursorToggleCB(FL_OBJECT * ob, long)
1830 BufferView *view = static_cast<BufferView*>(ob->u_vdata);
1832 /* quite a nice place for asyncron Inset updating, isn't it? */
1833 // actually no! This is run even if no buffer exist... so (Lgb)
1834 if (view && !view->buffer_) {
1835 goto set_timer_and_return;
1839 // On my quest to solve the gs rendre hangups I am now
1840 // disabling the SIGHUP completely, and will do a wait
1841 // now and then instead. If the guess that xforms somehow
1842 // destroys something is true, this is likely (hopefully)
1843 // to solve the problem...at least I hope so. Lgb
1845 // ...Ok this seems to work...at least it does not make things
1846 // worse so far. However I still see gs processes that hangs.
1847 // I would really like to know _why_ they are hanging. Anyway
1848 // the solution without the SIGCHLD handler seems to be easier
1851 // When attaching gdb to a a running gs that hangs it shows
1852 // that it is waiting for input(?) Is it possible for us to
1853 // provide that input somehow? Or figure what it is expecing
1856 // One solution is to, after some time, look if there are some
1857 // old gs processes still running and if there are: kill them
1860 // Another solution is to provide the user an option to rerender
1861 // a picture. This would, for the picture in question, check if
1862 // there is a gs running for it, if so kill it, and start a new
1863 // rendering process.
1865 // these comments posted to lyx@via
1868 int pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1869 if (pid == -1) // error find out what is wrong
1870 ; // ignore it for now.
1872 sigchldhandler(pid, &status);
1874 if (InsetUpdateList)
1875 UpdateInsetUpdateList();
1877 if (view && !view->screen){
1878 goto set_timer_and_return;
1881 if (view->lyx_focus && view->work_area_focus) {
1882 if (!view->buffer_->the_locking_inset){
1883 view->screen->CursorToggle();
1885 view->buffer_->the_locking_inset->
1886 ToggleInsetCursor();
1888 goto set_timer_and_return;
1890 // Make sure that the cursor is visible.
1891 if (!view->buffer_->the_locking_inset){
1892 view->screen->ShowCursor();
1894 if (!view->buffer_->the_locking_inset->isCursorVisible())
1895 view->buffer_->the_locking_inset->
1896 ToggleInsetCursor();
1899 // This is only run when work_area_focus or lyx_focus is false.
1902 XGetInputFocus(fl_display, &tmpwin, &tmp);
1903 if (lyxerr.debugging()) {
1904 lyxerr << "tmpwin: " << tmpwin
1905 << "\nwindow: " << view->owner_->getForm()->window
1906 << "\nwork_area_focus: " << view->work_area_focus
1907 << "\nlyx_focus : " << view->lyx_focus
1910 if (tmpwin != view->owner_->getForm()->window) {
1911 view->lyx_focus = false;
1914 view->lyx_focus = true;
1915 if (!view->work_area_focus)
1918 goto set_timer_and_return;
1922 set_timer_and_return:
1923 fl_set_timer(ob, 0.4);
1929 int BufferView::WorkAreaSelectionNotify(FL_OBJECT *, Window win,
1930 int /*w*/, int /*h*/, XEvent *event, void */*d*/)
1932 if (buffer_ == 0) return 0;
1933 if (event->type != SelectionNotify)
1939 unsigned char * uc = 0;
1941 screen->HideCursor();
1943 if (event->xselection.type == XA_STRING
1944 && event->xselection.property) {
1946 if (XGetWindowProperty(
1947 fl_display /* display */,
1949 event->xselection.property /* property */,
1950 0 /* long_offset */,
1951 0 /* long_length */,
1953 XA_STRING /* req_type */,
1954 &tmpatom /* actual_type_return */,
1955 &tmpint /* actual_format_return */,
1956 &ul1 /* nitems_return */,
1957 &ul2 /* bytes_after_return */,
1958 &uc /* prop_return */
1969 if (XGetWindowProperty(
1970 fl_display /* display */,
1972 event->xselection.property /* property */,
1973 0 /* long_offset */,
1974 ul2/4+1 /* long_length */,
1976 XA_STRING /* req_type */,
1977 &tmpatom /* actual_type_return */,
1978 &tmpint /* actual_format_return */,
1979 &ul1 /* nitems_return */,
1980 &ul2 /* bytes_after_return */,
1981 &uc /* prop_return */
1990 text->InsertStringA(reinterpret_cast<char*>(uc));
1992 text->InsertStringB(reinterpret_cast<char*>(uc));
1997 InsertStringA(reinterpret_cast<char*>(uc));
2000 InsertStringB(reinterpret_cast<char*>(uc));
2018 void BufferView::cursorPrevious()
2020 if (!text->cursor.row->previous) return;
2022 long y = getScreen()->first;
2023 Row * cursorrow = text->cursor.row;
2024 text->SetCursorFromCoordinates(text->cursor.x_fix, y);
2026 // this is to allow jumping over large insets
2027 if ((cursorrow == text->cursor.row))
2030 if (text->cursor.row->height < work_area->h)
2031 getScreen()->Draw(text->cursor.y
2032 - text->cursor.row->baseline
2033 + text->cursor.row->height
2034 - work_area->h +1 );
2038 void BufferView::cursorNext()
2040 if (!text->cursor.row->next) return;
2042 long y = getScreen()->first;
2043 text->GetRowNearY(y);
2044 Row * cursorrow = text->cursor.row;
2045 text->SetCursorFromCoordinates(text->cursor.x_fix, y + work_area->h);
2047 /* this is to allow jumping over large insets */
2048 if ((cursorrow == text->cursor.row))
2051 if (text->cursor.row->height < work_area->h)
2052 getScreen()->Draw(text->cursor.y
2053 - text->cursor.row->baseline);
2056 void BufferView::cursorPrevious()
2058 if (!buffer()->text->cursor.row->previous) return;
2060 long y = getScreen()->first;
2061 Row * cursorrow = buffer()->text->cursor.row;
2063 SetCursorFromCoordinates(buffer()->text->
2066 buffer()->text->FinishUndo();
2067 // this is to allow jumping over large insets
2068 if ((cursorrow == buffer()->text->cursor.row))
2069 buffer()->text->CursorUp();
2071 if (buffer()->text->cursor.row->height < work_area->h)
2072 getScreen()->Draw(buffer()->text->cursor.y
2073 - buffer()->text->cursor.row->baseline
2074 + buffer()->text->cursor.row->height
2075 - work_area->h +1 );
2079 void BufferView::cursorNext()
2081 if (!buffer()->text->cursor.row->next) return;
2083 long y = getScreen()->first;
2084 buffer()->text->GetRowNearY(y);
2085 Row * cursorrow = buffer()->text->cursor.row;
2087 SetCursorFromCoordinates(buffer()->text->
2090 buffer()->text->FinishUndo();
2091 /* this is to allow jumping over large insets */
2092 if ((cursorrow == buffer()->text->cursor.row))
2093 buffer()->text->CursorDown();
2095 if (buffer()->text->cursor.row->height < work_area->h)
2096 getScreen()->Draw(buffer()->text->cursor.y
2097 - buffer()->text->cursor.row->baseline);
2101 bool BufferView::available() const
2104 if (buffer_ && text) return true;
2106 if (buffer_ && buffer_->text) return true;
2112 void BufferView::savePosition()
2115 backstack.push(buffer()->fileName(),
2119 backstack.push(buffer()->getFileName(),
2120 buffer()->text->cursor.x,
2121 buffer()->text->cursor.y);
2126 void BufferView::restorePosition()
2128 if (backstack.empty()) return;
2131 string fname = backstack.pop(&x, &y);
2134 Buffer * b = (bufferlist.exists(fname)) ? bufferlist.getBuffer(fname):
2135 bufferlist.loadLyXFile(fname); // don't ask, just load it
2138 text->SetCursorFromCoordinates(x, y);
2141 buffer()->text->SetCursorFromCoordinates(x, y);
2142 buffer()->update(0);
2148 // candidate for move to BufferView
2149 void BufferView::update(signed char f)
2151 owner()->updateLayoutChoice();
2153 if (!text->selection && f > -3)
2154 text->sel_cursor = text->cursor;
2157 text->FullRebreak();
2161 if (f != 3 && f != -3) {
2166 if (f == 1 || f == -1) {
2167 if (buffer()->isLyxClean()) {
2168 buffer()->markDirty();
2169 owner()->getMiniBuffer()->setTimer(4);
2171 buffer()->markDirty();