2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2000 The LyX Team.
10 * ====================================================== */
23 #include "support/lstrings.h"
26 #pragma implementation
29 #include "commandtags.h"
30 #include "BufferView.h"
31 #include "bufferlist.h"
34 #include "insets/lyxinset.h"
35 #include "minibuffer.h"
36 #include "lyxscreen.h"
44 #include "lyx_gui_misc.h"
45 #include "BackStack.h"
50 #include "TextCache.h"
61 extern BufferList bufferlist;
64 void sigchldhandler(pid_t pid, int * status);
66 extern void SetXtermCursor(Window win);
67 extern bool input_prohibited;
68 extern bool selection_possible;
69 extern char ascii_type;
70 extern void MenuPasteSelection(char at);
71 extern InsetUpdateStruct * InsetUpdateList;
72 extern void UpdateInsetUpdateList();
73 extern void FreeUpdateTimer();
76 // This is _very_ temporary
77 FL_OBJECT * figinset_canvas;
80 BufferView::BufferView(LyXView * o, int xpos, int ypos,
81 int width, int height)
88 workarea = new WorkArea(this, xpos, ypos, width, height);
97 create_view(xpos, ypos, width, height);
98 current_scrollbar_value = 0;
99 // Activate the timer for the cursor
100 fl_set_timer(timer_cursor, 0.4);
102 workarea->setFocus();
104 fl_set_focus_object(owner_->getForm(), work_area);
106 work_area_focus = true;
108 the_locking_inset = 0;
113 BufferView::~BufferView()
120 Painter & BufferView::painter()
122 return workarea->getPainter();
127 void BufferView::buffer(Buffer * b)
129 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
133 buffer_->delUser(this);
135 // Put the old text into the TextCache, but
136 // only if the buffer is still loaded.
137 // Also set the owner of the test to 0
140 if (lyxerr.debugging())
141 textcache.show(lyxerr, "BufferView::buffer");
146 // Set current buffer
149 if (bufferlist.getState() == BufferList::CLOSING) return;
152 // screen is always deleted when the buffer is changed.
156 // If we are closing the buffer, use the first buffer as current
158 buffer_ = bufferlist.first();
162 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
163 buffer_->addUser(this);
164 owner_->getMenus()->showMenus();
165 // If we don't have a text object for this, we make one
167 resizeCurrentBuffer();
172 screen->first = screen->TopCursorVisible();
174 updateAllVisibleBufferRelatedPopups();
177 lyxerr[Debug::INFO] << " No Buffer!" << endl;
178 owner_->getMenus()->hideMenus();
183 fl_redraw_object(work_area);
186 // Also remove all remaining text's from the testcache.
187 // (there should not be any!) (if there is any it is a
189 if (lyxerr.debugging())
190 textcache.show(lyxerr, "buffer delete all");
193 // should update layoutchoice even if we don't have a buffer.
194 owner_->updateLayoutChoice();
195 owner_->getMiniBuffer()->Init();
196 owner_->updateWindowTitle();
200 void BufferView::updateScreen()
202 // Regenerate the screen.
205 screen = new LyXScreen(this,
207 workarea->getPixmap(),
208 workarea->workWidth(),
214 screen = new LyXScreen(FL_ObjWin(work_area),
225 void BufferView::resize(int xpos, int ypos, int width, int height)
227 workarea->resize(xpos, ypos, width, height);
234 void BufferView::resize()
236 // This will resize the buffer. (Asger)
238 resizeCurrentBuffer();
243 static bool lgb_hack = false;
246 void BufferView::redraw()
248 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
253 fl_redraw_object(work_area);
254 fl_redraw_object(scrollbar);
255 fl_redraw_object(button_down);
256 fl_redraw_object(button_up);
262 void BufferView::fitCursor()
264 if (screen) screen->FitCursor();
269 void BufferView::update()
271 if (screen) screen->Update();
275 void BufferView::updateScrollbar()
277 /* If the text is smaller than the working area, the scrollbar
278 * maximum must be the working area height. No scrolling will
283 workarea->setScrollbar(0, 1.0);
285 fl_set_slider_value(scrollbar, 0);
286 fl_set_slider_size(scrollbar, scrollbar->h);
291 static long max2 = 0;
292 static long height2 = 0;
300 cbsf = screen->first;
302 // check if anything has changed.
305 height2 == workarea->height() &&
306 current_scrollbar_value == cbsf)
309 height2 = workarea->height();
310 current_scrollbar_value = cbsf;
313 height2 == work_area->h &&
314 current_scrollbar_value == cbsf)
317 height2 = work_area->h;
318 current_scrollbar_value = cbsf;
321 if (cbth <= height2) { // text is smaller than screen
323 workarea->setScrollbar(0, 1.0); // right?
325 fl_set_slider_size(scrollbar, scrollbar->h);
331 long maximum_height = workarea->height() * 3 / 4 + cbth;
333 long maximum_height = work_area->h * 3 / 4 + cbth;
339 double hfloat = workarea->height();
341 double hfloat = work_area->h;
343 double maxfloat = maximum_height;
346 float slider_size = 0.0;
347 int slider_value = value;
349 workarea->setScrollbarBounds(0, text->height - workarea->height());
350 double lineh = text->DefaultHeight();
351 workarea->setScrollbarIncrements(lineh);
352 if (maxfloat > 0.0) {
353 if ((hfloat / maxfloat) * float(height2) < 3)
354 slider_size = 3.0/float(height2);
356 slider_size = hfloat / maxfloat;
358 slider_size = hfloat;
360 workarea->setScrollbar(slider_value, slider_size / workarea->height());
362 fl_set_slider_value(scrollbar, value);
363 fl_set_slider_bounds(scrollbar, 0,
364 maximum_height - work_area->h);
366 double lineh = text->DefaultHeight();
367 fl_set_slider_increment(scrollbar, work_area->h-lineh, lineh);
370 if ((hfloat / maxfloat) * float(height2) < 3)
371 fl_set_slider_size(scrollbar,
374 fl_set_slider_size(scrollbar,
377 fl_set_slider_size(scrollbar, hfloat);
378 fl_set_slider_precision(scrollbar, 0);
383 void BufferView::redoCurrentBuffer()
385 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
386 if (buffer_ && text) {
388 owner_->updateLayoutChoice();
393 int BufferView::resizeCurrentBuffer()
395 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
397 LyXParagraph * par = 0;
398 LyXParagraph * selstartpar = 0;
399 LyXParagraph * selendpar = 0;
408 owner_->getMiniBuffer()->Set(_("Formatting document..."));
411 par = text->cursor.par;
412 pos = text->cursor.pos;
413 selstartpar = text->sel_start_cursor.par;
414 selstartpos = text->sel_start_cursor.pos;
415 selendpar = text->sel_end_cursor.par;
416 selendpos = text->sel_end_cursor.pos;
417 selection = text->selection;
418 mark_set = text->mark_set;
421 text = new LyXText(this, workarea->workWidth(), buffer_);
423 text = new LyXText(work_area->w, buffer_);
426 // See if we have a text in TextCache that fits
427 // the new buffer_ with the correct width.
429 text = textcache.findFit(buffer_, workarea->workWidth());
431 text = textcache.findFit(buffer_, work_area->w);
434 if (lyxerr.debugging()) {
435 lyxerr << "Found a LyXText that fits:\n";
436 textcache.show(lyxerr, text);
438 // Set the owner of the newly found text
440 if (lyxerr.debugging())
441 textcache.show(lyxerr, "resizeCurrentBuffer");
444 text = new LyXText(this, workarea->workWidth(), buffer_);
446 text = new LyXText(work_area->w, buffer_);
453 text->selection = true;
454 /* at this point just to avoid the Delete-Empty-Paragraph
455 * Mechanism when setting the cursor */
456 text->mark_set = mark_set;
458 text->SetCursor(selstartpar, selstartpos);
459 text->sel_cursor = text->cursor;
460 text->SetCursor(selendpar, selendpos);
461 text->SetSelection();
462 text->SetCursor(par, pos);
464 text->SetCursor(par, pos);
465 text->sel_cursor = text->cursor;
466 text->selection = false;
469 screen->first = screen->TopCursorVisible(); /* this will scroll the
470 * screen such that the
475 owner_->getMiniBuffer()->Init();
479 // Now if the title form still exist kill it
486 void BufferView::gotoError()
491 screen->HideCursor();
496 if (!text->GotoNextError()) {
498 || text->cursor.par != text->FirstParagraph()) {
500 text->cursor.par = text->FirstParagraph();
501 text->cursor.pos = 0;
502 if (!text->GotoNextError()) {
504 owner_->getMiniBuffer()
505 ->Set(_("No more errors"));
509 owner_->getMiniBuffer()->Set(_("No more errors"));
514 text->sel_cursor = text->cursor;
520 void C_BufferView_CursorToggleCB(FL_OBJECT * ob, long buf)
522 BufferView::CursorToggleCB(ob, buf);
527 // Just a bunch of C wrappers around static members of BufferView
528 void C_BufferView_UpCB(FL_OBJECT * ob, long buf)
530 BufferView::UpCB(ob, buf);
534 void C_BufferView_DownCB(FL_OBJECT * ob, long buf)
536 BufferView::DownCB(ob, buf);
540 void C_BufferView_ScrollCB(FL_OBJECT * ob, long buf)
542 BufferView::ScrollCB(ob, buf);
546 void C_BufferView_CursorToggleCB(FL_OBJECT * ob, long buf)
548 BufferView::CursorToggleCB(ob, buf);
552 int C_BufferView_work_area_handler(FL_OBJECT * ob, int event,
556 return BufferView::work_area_handler(ob, event,
563 void BufferView::create_view(int xpos, int ypos, int width, int height)
567 int const bw = abs(fl_get_border_width());
569 // a hack for the figinsets (Matthias)
570 // This one first, then it will probably be invisible. (Lgb)
571 ::figinset_canvas = figinset_canvas = obj =
572 fl_add_canvas(FL_NORMAL_CANVAS,
575 fl_set_object_boxtype(obj, FL_NO_BOX);
576 fl_set_object_resize(obj, FL_RESIZE_ALL);
577 fl_set_object_gravity(obj, NorthWestGravity, NorthWestGravity);
580 obj = fl_add_box(FL_BORDER_BOX, xpos, ypos,
583 fl_set_object_resize(obj, FL_RESIZE_ALL);
584 fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
587 work_area = obj = fl_add_free(FL_INPUT_FREE,
588 xpos + bw, ypos + bw,
589 width - 15 - 2 * bw /* scrollbarwidth */,
591 C_BufferView_work_area_handler);
592 obj->wantkey = FL_KEY_TAB;
593 obj->u_vdata = this; /* This is how we pass the BufferView
594 to the work_area_handler. */
595 fl_set_object_boxtype(obj, FL_DOWN_BOX);
596 fl_set_object_resize(obj, FL_RESIZE_ALL);
597 fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
603 // up - scrollbar button
604 fl_set_border_width(-1); // to get visual feedback
606 button_up = obj = fl_add_pixmapbutton(FL_TOUCH_BUTTON,
610 fl_set_object_boxtype(obj, FL_UP_BOX);
611 fl_set_object_color(obj, FL_MCOL, FL_BLUE);
612 fl_set_object_resize(obj, FL_RESIZE_ALL);
613 fl_set_object_gravity(obj, NorthEastGravity, NorthEastGravity);
614 fl_set_object_callback(obj, C_BufferView_UpCB, 0);
616 fl_set_pixmapbutton_data(obj, const_cast<char**>(up_xpm));
618 // Remove the blue feedback rectangle
619 fl_set_pixmapbutton_focus_outline(obj, 0);
621 // the scrollbar slider
622 fl_set_border_width(-bw);
623 scrollbar = obj = fl_add_slider(FL_VERT_SLIDER,
626 15, height - 30, "");
627 fl_set_object_color(obj, FL_COL1, FL_MCOL);
628 fl_set_object_boxtype(obj, FL_UP_BOX);
629 fl_set_object_resize(obj, FL_RESIZE_ALL);
630 fl_set_object_gravity(obj, NorthEastGravity, SouthEastGravity);
631 fl_set_object_callback(obj, C_BufferView_ScrollCB, 0);
634 // down - scrollbar button
635 fl_set_border_width(-1); // to get visible feedback
637 button_down = obj = fl_add_pixmapbutton(FL_TOUCH_BUTTON,
641 fl_set_object_boxtype(obj, FL_UP_BOX);
642 fl_set_object_color(obj, FL_MCOL, FL_BLUE);
643 fl_set_object_resize(obj, FL_RESIZE_ALL);
644 fl_set_object_gravity(obj, SouthEastGravity, SouthEastGravity);
645 fl_set_object_callback(obj, C_BufferView_DownCB, 0);
647 fl_set_pixmapbutton_data(obj, const_cast<char**>(down_xpm));
648 fl_set_border_width(-bw);
650 // Remove the blue feedback rectangle
651 fl_set_pixmapbutton_focus_outline(obj, 0);
658 timer_cursor = obj = fl_add_timer(FL_HIDDEN_TIMER,
659 0, 0, 0, 0, "Timer");
660 fl_set_object_callback(obj, C_BufferView_CursorToggleCB, 0);
665 // Callback for scrollbar up button
667 void BufferView::UpCB(long time, int button)
669 if (buffer_ == 0) return;
684 void BufferView::UpCB(FL_OBJECT * ob, long)
686 BufferView * view = static_cast<BufferView*>(ob->u_vdata);
688 if (view->buffer_ == 0) return;
690 static long time = 0;
691 XEvent const * ev2 = fl_last_event();
692 if (ev2->type == ButtonPress || ev2->type == ButtonRelease)
694 int button = fl_get_button_numb(ob);
697 view->ScrollUpOnePage(time++); break;
699 view->ScrollDownOnePage(time++); break;
701 view->ScrollUp(time++); break;
710 XSync(fl_get_display(), 0);
714 // Callback for scrollbar slider
716 void BufferView::ScrollCB(double value)
718 extern bool cursor_follows_scrollbar;
720 if (buffer_ == 0) return;
722 current_scrollbar_value = long(value);
723 if (current_scrollbar_value < 0)
724 current_scrollbar_value = 0;
729 screen->Draw(current_scrollbar_value);
731 if (cursor_follows_scrollbar) {
732 LyXText * vbt = text;
733 int height = vbt->DefaultHeight();
735 if (vbt->cursor.y < screen->first + height) {
736 vbt->SetCursorFromCoordinates(0,
739 } else if (vbt->cursor.y >
740 screen->first + workarea->height() - height) {
741 vbt->SetCursorFromCoordinates(0,
750 void BufferView::ScrollCB(FL_OBJECT * ob, long)
752 BufferView * view = static_cast<BufferView*>(ob->u_vdata);
753 extern bool cursor_follows_scrollbar;
755 if (view->buffer_ == 0) return;
757 view->current_scrollbar_value = long(fl_get_slider_value(ob));
758 if (view->current_scrollbar_value < 0)
759 view->current_scrollbar_value = 0;
764 view->screen->Draw(view->current_scrollbar_value);
766 if (cursor_follows_scrollbar) {
767 LyXText * vbt = view->text;
768 int height = vbt->DefaultHeight();
770 if (vbt->cursor.y < view->screen->first + height) {
771 vbt->SetCursorFromCoordinates(0,
772 view->screen->first +
775 else if (vbt->cursor.y >
776 view->screen->first + view->work_area->h - height) {
777 vbt->SetCursorFromCoordinates(0,
778 view->screen->first +
788 // Callback for scrollbar down button
790 void BufferView::DownCB(long time, int button)
792 if (buffer_ == 0) return;
807 void BufferView::DownCB(FL_OBJECT * ob, long)
809 BufferView * view = static_cast<BufferView*>(ob->u_vdata);
811 if (view->buffer_ == 0) return;
814 static long time = 0;
815 ev2 = fl_last_event();
816 if (ev2->type == ButtonPress || ev2->type == ButtonRelease)
818 int button = fl_get_button_numb(ob);
821 view->ScrollUpOnePage(time++); break;
823 view->ScrollDownOnePage(time++); break;
825 view->ScrollDown(time++); break;
832 int BufferView::ScrollUp(long time)
834 if (buffer_ == 0) return 0;
835 if (!screen) return 0;
837 double value = workarea->getScrollbarValue();
839 if (value == 0) return 0;
841 float add_value = (text->DefaultHeight()
842 + float(time) * float(time) * 0.125);
844 if (add_value > workarea->height())
845 add_value = float(workarea->height() -
846 text->DefaultHeight());
853 workarea->setScrollbarValue(value);
859 int BufferView::ScrollUp(long time)
861 if (buffer_ == 0) return 0;
862 if (!screen) return 0;
864 double value = fl_get_slider_value(scrollbar);
866 if (value == 0) return 0;
868 float add_value = (text->DefaultHeight()
869 + float(time) * float(time) * 0.125);
871 if (add_value > work_area->h)
872 add_value = float(work_area->h -
873 text->DefaultHeight());
880 fl_set_slider_value(scrollbar, value);
882 ScrollCB(scrollbar, 0);
889 int BufferView::ScrollDown(long time)
891 if (buffer_ == 0) return 0;
892 if (!screen) return 0;
894 double value= workarea->getScrollbarValue();
895 pair<double, double> p = workarea->getScrollbarBounds();
896 double max = p.second;
898 if (value == max) return 0;
900 float add_value = (text->DefaultHeight()
901 + float(time) * float(time) * 0.125);
903 if (add_value > workarea->height())
904 add_value = float(workarea->height() -
905 text->DefaultHeight());
912 workarea->setScrollbarValue(value);
918 int BufferView::ScrollDown(long time)
920 if (buffer_ == 0) return 0;
921 if (!screen) return 0;
923 double value= fl_get_slider_value(scrollbar);
925 fl_get_slider_bounds(scrollbar, &min, &max);
927 if (value == max) return 0;
929 float add_value = (text->DefaultHeight()
930 + float(time) * float(time) * 0.125);
932 if (add_value > work_area->h)
933 add_value = float(work_area->h -
934 text->DefaultHeight());
941 fl_set_slider_value(scrollbar, value);
943 ScrollCB(scrollbar, 0);
950 void BufferView::ScrollUpOnePage()
952 if (buffer_ == 0) return;
955 long y = screen->first;
959 Row * row = text->GetRowNearY(y);
961 y = y - workarea->height() + row->height;
963 workarea->setScrollbarValue(y);
968 void BufferView::ScrollUpOnePage(long /*time*/)
970 if (buffer_ == 0) return;
973 long y = screen->first;
977 Row * row = text->GetRowNearY(y);
979 y = y - work_area->h + row->height;
981 fl_set_slider_value(scrollbar, y);
983 ScrollCB(scrollbar, 0);
989 void BufferView::ScrollDownOnePage()
991 if (buffer_ == 0) return;
994 long y = screen->first;
996 if (y > text->height - workarea->height())
999 y += workarea->height();
1000 text->GetRowNearY(y);
1002 workarea->setScrollbarValue(y);
1007 void BufferView::ScrollDownOnePage(long /*time*/)
1009 if (buffer_ == 0) return;
1010 if (!screen) return;
1013 fl_get_slider_bounds(scrollbar, &min, &max);
1014 long y = screen->first;
1016 if (y > text->height - work_area->h)
1020 text->GetRowNearY(y);
1022 fl_set_slider_value(scrollbar, y);
1024 ScrollCB(scrollbar, 0);
1030 int BufferView::work_area_handler(FL_OBJECT * ob, int event,
1031 FL_Coord, FL_Coord ,
1032 int /*key*/, void * xev)
1034 static int x_old = -1;
1035 static int y_old = -1;
1036 static long scrollbar_value_old = -1;
1038 XEvent * ev = static_cast<XEvent*>(xev);
1039 BufferView * view = static_cast<BufferView*>(ob->u_vdata);
1041 // If we don't have a view yet; return
1042 if (!view || quitting) return 0;
1046 view->workAreaExpose();
1049 view->WorkAreaButtonPress(ob, 0, 0, 0, ev, 0);
1052 view->WorkAreaButtonRelease(ob, 0, 0, 0, ev, 0);
1055 if (ev->xmotion.x != x_old ||
1056 ev->xmotion.y != y_old ||
1057 view->current_scrollbar_value != scrollbar_value_old) {
1058 x_old = ev->xmotion.x;
1059 y_old = ev->xmotion.y;
1060 scrollbar_value_old = view->current_scrollbar_value;
1061 view->WorkAreaMotionNotify(ob, 0, 0, 0, ev, 0);
1064 // Done by the raw callback:
1065 // case FL_KEYBOARD:
1066 // WorkAreaKeyPress(ob, 0, 0, 0, ev, 0); break;
1068 if (!view->owner_->getMiniBuffer()->shows_no_match)
1069 view->owner_->getMiniBuffer()->Init();
1070 view->owner_->getMiniBuffer()->shows_no_match = false;
1071 view->work_area_focus = true;
1072 fl_set_timer(view->timer_cursor, 0.4);
1075 view->owner_->getMiniBuffer()->ExecCommand();
1076 view->work_area_focus = false;
1079 SetXtermCursor(view->owner_->getForm()->window);
1081 view->lyx_focus = true;
1082 fl_set_timer(view->timer_cursor, 0.4);
1085 if (!input_prohibited)
1086 XUndefineCursor(fl_display,
1087 view->owner_->getForm()->window);
1088 view->lyx_focus = false; // This is not an absolute truth
1089 // but if it is not true, it will be changed within a blink
1090 // of an eye. ... Not good enough... use regulare timeperiod
1091 //fl_set_timer(view->timer_cursor, 0.01); // 0.1 sec blink
1092 fl_set_timer(view->timer_cursor, 0.4); // 0.4 sec blink
1096 if (!view->the_locking_inset) {
1097 if (view->screen && ev->xbutton.button == 1) {
1098 view->screen->HideCursor();
1099 view->screen->ToggleSelection();
1100 view->text->SelectWord();
1101 view->screen->ToggleSelection(false);
1102 /* This will fit the cursor on the screen
1110 if (view->buffer_ && view->screen && ev->xbutton.button == 1) {
1111 view->screen->HideCursor();
1112 view->screen->ToggleSelection();
1113 view->text->CursorHome();
1114 view->text->sel_cursor = view->text->cursor;
1115 view->text->CursorEnd();
1116 view->text->SetSelection();
1117 view->screen->ToggleSelection(false);
1118 /* This will fit the cursor on the screen
1124 view->WorkAreaSelectionNotify(ob,
1125 view->owner_->getForm()->window,
1135 void BufferView::WorkAreaMotionNotify(int x, int y, unsigned int state)
1137 if (buffer_ == 0 || !screen) return;
1139 // Check for inset locking
1140 if (the_locking_inset) {
1141 LyXCursor cursor = text->cursor;
1143 InsetMotionNotify(x - cursor.x,
1149 // Only use motion with button 1
1150 if (!state & Button1MotionMask)
1153 /* The selection possible is needed, that only motion events are
1154 * used, where the bottom press event was on the drawing area too */
1155 if (selection_possible) {
1156 screen->HideCursor();
1158 text->SetCursorFromCoordinates(x, y + screen->first);
1160 if (!text->selection)
1161 update(-3); // Maybe an empty line was deleted
1163 text->SetSelection();
1164 screen->ToggleToggle();
1165 if (screen->FitCursor())
1167 screen->ShowCursor();
1172 int BufferView::WorkAreaMotionNotify(FL_OBJECT * ob, Window,
1173 int /*w*/, int /*h*/,
1174 XEvent * ev, void * /*d*/)
1176 if (buffer_ == 0) return 0;
1177 if (!screen) return 0;
1179 // Check for inset locking
1180 if (the_locking_inset) {
1181 LyXCursor cursor = text->cursor;
1183 InsetMotionNotify(ev->xbutton.x - ob->x - cursor.x,
1184 ev->xbutton.y - ob->y -
1190 // Only use motion with button 1
1191 if (!ev->xmotion.state & Button1MotionMask)
1194 /* The selection possible is needed, that only motion events are
1195 * used, where the bottom press event was on the drawing area too */
1196 if (selection_possible) {
1197 screen->HideCursor();
1199 text->SetCursorFromCoordinates(ev->xbutton.x - ob->x,
1200 ev->xbutton.y - ob->y +
1203 if (!text->selection)
1204 update(-3); // Maybe an empty line was deleted
1206 text->SetSelection();
1207 screen->ToggleToggle();
1208 if (screen->FitCursor())
1210 screen->ShowCursor();
1217 extern int bibitemMaxWidth(Painter &, LyXFont const &);
1219 extern int bibitemMaxWidth(LyXFont const &);
1222 // Single-click on work area
1224 void BufferView::WorkAreaButtonPress(int xpos, int ypos, unsigned int button)
1229 if (buffer_ == 0 || !screen) return;
1231 Inset * inset_hit = checkInsetHit(xpos, ypos);
1233 // ok ok, this is a hack.
1234 if (button == 4 || button == 5) {
1237 ScrollUp(100); // This number is only temporary
1245 if (the_locking_inset) {
1246 // We are in inset locking mode
1248 /* Check whether the inset was hit. If not reset mode,
1249 otherwise give the event to the inset */
1252 InsetButtonPress(xpos, ypos,
1256 unlockInset(the_locking_inset);
1260 selection_possible = true;
1261 screen->HideCursor();
1263 // Right button mouse click on a table
1265 (text->cursor.par->table ||
1266 text->MouseHitInTable(xpos, ypos + screen->first))) {
1267 // Set the cursor to the press-position
1268 text->SetCursorFromCoordinates(xpos, ypos + screen->first);
1271 // Only show the table popup if the hit is in
1273 if (!text->HitInTable(text->cursor.row, xpos))
1276 // Hit above or below the table?
1278 if (!text->selection) {
1279 screen->ToggleSelection();
1280 text->ClearSelection();
1281 text->FullRebreak();
1285 // Popup table popup when on a table.
1286 // This is obviously temporary, since we
1287 // should be able to popup various
1288 // context-sensitive-menus with the
1289 // the right mouse. So this should be done more
1290 // general in the future. Matthias.
1291 selection_possible = false;
1292 owner_->getLyXFunc()
1293 ->Dispatch(LFUN_LAYOUT_TABLE,
1299 int screen_first = screen->first;
1301 // Middle button press pastes if we have a selection
1302 bool paste_internally = false;
1304 && text->selection) {
1305 owner_->getLyXFunc()->Dispatch(LFUN_COPY);
1306 paste_internally = true;
1309 // Clear the selection
1310 screen->ToggleSelection();
1311 text->ClearSelection();
1312 text->FullRebreak();
1316 // Single left click in math inset?
1317 if (inset_hit != 0 && inset_hit->Editable() == 2) {
1318 // Highly editable inset, like math
1319 selection_possible = false;
1320 owner_->updateLayoutChoice();
1321 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
1322 inset_hit->Edit(xpos, ypos);
1326 // Right click on a footnote flag opens float menu
1328 selection_possible = false;
1332 text->SetCursorFromCoordinates(xpos, ypos + screen_first);
1334 text->sel_cursor = text->cursor;
1335 text->cursor.x_fix = text->cursor.x;
1337 owner_->updateLayoutChoice();
1338 if (screen->FitCursor()){
1340 selection_possible = false;
1343 // Insert primary selection with middle mouse
1344 // if there is a local selection in the current buffer,
1347 if (paste_internally)
1348 owner_->getLyXFunc()->Dispatch(LFUN_PASTE);
1350 owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION,
1352 selection_possible = false;
1357 int BufferView::WorkAreaButtonPress(FL_OBJECT * ob, Window,
1358 int /*w*/, int /*h*/,
1359 XEvent * ev, void */*d*/)
1364 if (buffer_ == 0) return 0;
1365 if (!screen) return 0;
1367 int const x = ev->xbutton.x - ob->x;
1368 int const y = ev->xbutton.y - ob->y;
1369 // If we hit an inset, we have the inset coordinates in these
1370 // and inset_hit points to the inset. If we do not hit an
1371 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
1374 Inset * inset_hit = checkInsetHit(inset_x, inset_y);
1376 // ok ok, this is a hack.
1377 int button = ev->xbutton.button;
1378 if (button == 4 || button == 5) goto wheel;
1381 if (the_locking_inset) {
1382 // We are in inset locking mode
1384 /* Check whether the inset was hit. If not reset mode,
1385 otherwise give the event to the inset */
1386 if (inset_hit != 0) {
1388 InsetButtonPress(inset_x, inset_y,
1392 unlockInset(the_locking_inset);
1396 selection_possible = true;
1397 screen->HideCursor();
1399 // Right button mouse click on a table
1401 (text->cursor.par->table ||
1402 text->MouseHitInTable(x, y + screen->first))) {
1403 // Set the cursor to the press-position
1404 text->SetCursorFromCoordinates(x, y + screen->first);
1407 // Only show the table popup if the hit is in
1409 if (!text->HitInTable(text->cursor.row, x))
1412 // Hit above or below the table?
1414 if (!text->selection) {
1415 screen->ToggleSelection();
1416 text->ClearSelection();
1417 text->FullRebreak();
1421 // Popup table popup when on a table.
1422 // This is obviously temporary, since we
1423 // should be able to popup various
1424 // context-sensitive-menus with the
1425 // the right mouse. So this should be done more
1426 // general in the future. Matthias.
1427 selection_possible = false;
1428 owner_->getLyXFunc()
1429 ->Dispatch(LFUN_LAYOUT_TABLE,
1435 int screen_first = screen->first;
1437 // Middle button press pastes if we have a selection
1438 bool paste_internally = false;
1439 if (button == 2 // && !buffer_->the_locking_inset
1440 && text->selection) {
1441 owner_->getLyXFunc()->Dispatch(LFUN_COPY);
1442 paste_internally = true;
1445 // Clear the selection
1446 screen->ToggleSelection();
1447 text->ClearSelection();
1448 text->FullRebreak();
1452 // Single left click in math inset?
1453 if (inset_hit != 0 && inset_hit->Editable() == 2) {
1454 // Highly editable inset, like math
1455 selection_possible = false;
1456 owner_->updateLayoutChoice();
1457 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
1458 inset_hit->Edit(inset_x, inset_y);
1462 // Right click on a footnote flag opens float menu
1464 selection_possible = false;
1468 text->SetCursorFromCoordinates(x, y + screen_first);
1470 text->sel_cursor = text->cursor;
1471 text->cursor.x_fix = text->cursor.x;
1473 owner_->updateLayoutChoice();
1474 if (screen->FitCursor()){
1476 selection_possible = false;
1479 // Insert primary selection with middle mouse
1480 // if there is a local selection in the current buffer,
1482 if (button == 2) { // && !buffer_->the_locking_inset){
1483 if (paste_internally)
1484 owner_->getLyXFunc()->Dispatch(LFUN_PASTE);
1486 owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION,
1488 selection_possible = false;
1495 // I am not quite sure if this is the correct place to put
1496 // this, but it will not cause any harm.
1497 // Patch from Mark Huang (markman@mit.edu) to make LyX
1498 // recognise button 4 and 5. This enables LyX use use
1499 // the scrollwhell on certain mice for something useful. (Lgb)
1500 // Added wheel acceleration detection code. (Rvdk)
1501 static Time lastTime = 0;
1502 int diff = ev->xbutton.time - lastTime;
1503 int scroll = int(1.0 + (4.0 / (abs(diff) + 1.0)) * 200.0);
1512 lastTime = ev->xbutton.time;
1525 void BufferView::WorkAreaButtonRelease(int x, int y, unsigned int button)
1527 if (buffer_ == 0 || screen == 0) return;
1529 // If we hit an inset, we have the inset coordinates in these
1530 // and inset_hit points to the inset. If we do not hit an
1531 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
1532 Inset * inset_hit = checkInsetHit(x, y);
1534 if (the_locking_inset) {
1535 // We are in inset locking mode.
1537 /* LyX does a kind of work-area grabbing for insets.
1538 Only a ButtonPress Event outside the inset will
1539 force a InsetUnlock. */
1541 InsetButtonRelease(x, x, button);
1545 selection_possible = false;
1546 if (text->cursor.par->table) {
1548 NumberOfCell(text->cursor.par,
1550 if (text->cursor.par->table->IsContRow(cell) &&
1551 text->cursor.par->table->
1552 CellHasContRow(text->cursor.par->table->
1553 GetCellAbove(cell))<0) {
1558 if (button >= 2) return;
1561 owner_->getMiniBuffer()->Set(CurrentState());
1563 // Did we hit an editable inset?
1564 if (inset_hit != 0) {
1565 // Inset like error, notes and figures
1566 selection_possible = false;
1567 #ifdef WITH_WARNINGS
1568 #warning fix this proper in 0.13
1570 // Following a ref shouldn't issue
1571 // a push on the undo-stack
1572 // anylonger, now that we have
1573 // keybindings for following
1574 // references and returning from
1575 // references. IMHO though, it
1576 // should be the inset's own business
1577 // to push or not push on the undo
1578 // stack. They don't *have* to
1579 // alter the document...
1581 // ...or maybe the SetCursorParUndo()
1582 // below isn't necessary at all anylonger?
1583 if (inset_hit->LyxCode() == Inset::REF_CODE) {
1584 text->SetCursorParUndo();
1587 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
1588 inset_hit->Edit(x, y);
1592 // check whether we want to open a float
1596 if (text->cursor.pos <
1597 text->cursor.par->Last()) {
1598 c = text->cursor.par->
1599 GetChar(text->cursor.pos);
1601 if (c == LyXParagraph::META_FOOTNOTE
1602 || c == LyXParagraph::META_MARGIN
1603 || c == LyXParagraph::META_FIG
1604 || c == LyXParagraph::META_TAB
1605 || c == LyXParagraph::META_WIDE_FIG
1606 || c == LyXParagraph::META_WIDE_TAB
1607 || c == LyXParagraph::META_ALGORITHM){
1609 } else if (text->cursor.pos - 1 >= 0) {
1610 c = text->cursor.par->
1611 GetChar(text->cursor.pos - 1);
1612 if (c == LyXParagraph::META_FOOTNOTE
1613 || c == LyXParagraph::META_MARGIN
1614 || c == LyXParagraph::META_FIG
1615 || c == LyXParagraph::META_TAB
1616 || c == LyXParagraph::META_WIDE_FIG
1617 || c == LyXParagraph::META_WIDE_TAB
1618 || c == LyXParagraph::META_ALGORITHM){
1619 // We are one step too far to the right
1626 selection_possible = false;
1631 // Do we want to close a float? (click on the float-label)
1632 if (text->cursor.row->par->footnoteflag ==
1633 LyXParagraph::OPEN_FOOTNOTE
1634 //&& text->cursor.pos == 0
1635 && text->cursor.row->previous &&
1636 text->cursor.row->previous->par->
1637 footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
1638 LyXFont font (LyXFont::ALL_SANE);
1639 font.setSize(LyXFont::SIZE_FOOTNOTE);
1641 int box_x = 20; // LYX_PAPER_MARGIN;
1642 box_x += font.textWidth(" wide-tab ", 10);
1644 int screen_first = screen->first;
1647 && y + screen_first > text->cursor.y -
1648 text->cursor.row->baseline
1649 && y + screen_first < text->cursor.y -
1650 text->cursor.row->baseline
1651 + font.maxAscent() * 1.2 + font.maxDescent() * 1.2) {
1653 selection_possible = false;
1658 // Maybe we want to edit a bibitem ale970302
1660 if (text->cursor.par->bibkey && x < 20 +
1661 bibitemMaxWidth(painter(),
1663 .TextClass(buffer_->
1664 params.textclass).defaultfont())) {
1665 text->cursor.par->bibkey->Edit(0, 0);
1668 if (text->cursor.par->bibkey && x < 20 +
1669 bibitemMaxWidth(textclasslist
1670 .TextClass(buffer_->
1671 params.textclass).defaultfont())) {
1672 text->cursor.par->bibkey->Edit(0, 0);
1679 int BufferView::WorkAreaButtonRelease(FL_OBJECT * ob, Window ,
1680 int /*w*/, int /*h*/,
1681 XEvent * ev, void * /*d*/)
1683 if (buffer_ == 0 || screen == 0) return 0;
1685 int const x = ev->xbutton.x - ob->x;
1686 int const y = ev->xbutton.y - ob->y;
1688 // If we hit an inset, we have the inset coordinates in these
1689 // and inset_hit points to the inset. If we do not hit an
1690 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
1693 Inset * inset_hit = checkInsetHit(inset_x, inset_y);
1695 if (the_locking_inset) {
1696 // We are in inset locking mode.
1698 /* LyX does a kind of work-area grabbing for insets.
1699 Only a ButtonPress Event outside the inset will
1700 force a InsetUnlock. */
1702 InsetButtonRelease(inset_x, inset_y,
1703 ev->xbutton.button);
1707 selection_possible = false;
1708 if (text->cursor.par->table) {
1710 NumberOfCell(text->cursor.par,
1712 if (text->cursor.par->table->IsContRow(cell) &&
1713 text->cursor.par->table->
1714 CellHasContRow(text->cursor.par->table->
1715 GetCellAbove(cell))<0) {
1720 if (ev->xbutton.button >= 2)
1723 // Make sure that the press was not far from the release
1724 if ((abs(last_click_x - x) >= 5) ||
1725 (abs(last_click_y - y) >= 5)) {
1729 owner_->getMiniBuffer()->Set(CurrentState());
1731 // Did we hit an editable inset?
1732 if (inset_hit != 0) {
1733 // Inset like error, notes and figures
1734 selection_possible = false;
1735 #ifdef WITH_WARNINGS
1736 #warning fix this proper in 0.13
1738 // Following a ref shouldn't issue
1739 // a push on the undo-stack
1740 // anylonger, now that we have
1741 // keybindings for following
1742 // references and returning from
1743 // references. IMHO though, it
1744 // should be the inset's own business
1745 // to push or not push on the undo
1746 // stack. They don't *have* to
1747 // alter the document...
1749 // ...or maybe the SetCursorParUndo()
1750 // below isn't necessary at all anylonger?
1751 if (inset_hit->LyxCode() == Inset::REF_CODE) {
1752 text->SetCursorParUndo();
1755 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
1756 inset_hit->Edit(inset_x, inset_y);
1760 // check whether we want to open a float
1764 if (text->cursor.pos <
1765 text->cursor.par->Last()) {
1766 c = text->cursor.par->
1767 GetChar(text->cursor.pos);
1769 if (c == LyXParagraph::META_FOOTNOTE
1770 || c == LyXParagraph::META_MARGIN
1771 || c == LyXParagraph::META_FIG
1772 || c == LyXParagraph::META_TAB
1773 || c == LyXParagraph::META_WIDE_FIG
1774 || c == LyXParagraph::META_WIDE_TAB
1775 || c == LyXParagraph::META_ALGORITHM){
1777 } else if (text->cursor.pos - 1 >= 0) {
1778 c = text->cursor.par->
1779 GetChar(text->cursor.pos - 1);
1780 if (c == LyXParagraph::META_FOOTNOTE
1781 || c == LyXParagraph::META_MARGIN
1782 || c == LyXParagraph::META_FIG
1783 || c == LyXParagraph::META_TAB
1784 || c == LyXParagraph::META_WIDE_FIG
1785 || c == LyXParagraph::META_WIDE_TAB
1786 || c == LyXParagraph::META_ALGORITHM){
1787 // We are one step too far to the right
1794 selection_possible = false;
1799 // Do we want to close a float? (click on the float-label)
1800 if (text->cursor.row->par->footnoteflag ==
1801 LyXParagraph::OPEN_FOOTNOTE
1802 //&& text->cursor.pos == 0
1803 && text->cursor.row->previous &&
1804 text->cursor.row->previous->par->
1805 footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
1806 LyXFont font (LyXFont::ALL_SANE);
1807 font.setSize(LyXFont::SIZE_FOOTNOTE);
1809 int box_x = 20; // LYX_PAPER_MARGIN;
1810 box_x += font.textWidth(" wide-tab ", 10);
1812 int screen_first = screen->first;
1815 && y + screen_first > text->cursor.y -
1816 text->cursor.row->baseline
1817 && y + screen_first < text->cursor.y -
1818 text->cursor.row->baseline
1819 + font.maxAscent() * 1.2 + font.maxDescent() * 1.2) {
1821 selection_possible = false;
1826 // Maybe we want to edit a bibitem ale970302
1827 if (text->cursor.par->bibkey && x < 20 +
1828 bibitemMaxWidth(textclasslist
1829 .TextClass(buffer_->
1830 params.textclass).defaultfont())) {
1831 text->cursor.par->bibkey->Edit(0, 0);
1839 * Returns an inset if inset was hit. 0 otherwise.
1840 * If hit, the coordinates are changed relative to the inset.
1841 * Otherwise coordinates are not changed, and false is returned.
1844 Inset * BufferView::checkInsetHit(int & x, int & y)
1849 int y_tmp = y + getScreen()->first;
1851 LyXCursor & cursor = text->cursor;
1852 LyXDirection direction = text->real_current_font.getFontDirection();
1854 if (cursor.pos < cursor.par->Last()
1855 && cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET
1856 && cursor.par->GetInset(cursor.pos)
1857 && cursor.par->GetInset(cursor.pos)->Editable()) {
1859 // Check whether the inset really was hit
1860 Inset * tmpinset = cursor.par->GetInset(cursor.pos);
1861 LyXFont font = text->GetFont(cursor.par, cursor.pos);
1863 if (direction == LYX_DIR_LEFT_TO_RIGHT) {
1865 end_x = cursor.x + tmpinset->width(painter(), font);
1867 start_x = cursor.x - tmpinset->width(painter(), font);
1871 if (x > start_x && x < end_x
1872 && y_tmp > cursor.y - tmpinset->ascent(painter(), font)
1873 && y_tmp < cursor.y + tmpinset->descent(painter(), font)) {
1875 // The origin of an inset is on the baseline
1876 y = y_tmp - (cursor.y);
1881 if (cursor.pos - 1 >= 0
1882 && cursor.par->GetChar(cursor.pos - 1) == LyXParagraph::META_INSET
1883 && cursor.par->GetInset(cursor.pos - 1)
1884 && cursor.par->GetInset(cursor.pos - 1)->Editable()) {
1886 Inset * tmpinset = cursor.par->GetInset(cursor.pos);
1887 LyXFont font = text->GetFont(cursor.par, cursor.pos);
1889 if (direction == LYX_DIR_LEFT_TO_RIGHT) {
1891 end_x = cursor.x + tmpinset->width(painter(), font);
1893 start_x = cursor.x - tmpinset->width(painter(), font);
1896 if (x > start_x && x < end_x
1897 && y_tmp > cursor.y - tmpinset->ascent(painter(), font)
1898 && y_tmp < cursor.y + tmpinset->descent(painter(), font)) {
1900 // The origin of an inset is on the baseline
1901 y = y_tmp - (cursor.y);
1904 text->CursorRight();
1911 Inset * BufferView::checkInsetHit(int & x, int & y)
1916 int y_tmp = y + getScreen()->first;
1918 LyXCursor & cursor = text->cursor;
1919 LyXDirection direction = text->real_current_font.getFontDirection();
1921 if (cursor.pos < cursor.par->Last()
1922 && cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET
1923 && cursor.par->GetInset(cursor.pos)
1924 && cursor.par->GetInset(cursor.pos)->Editable()) {
1926 // Check whether the inset really was hit
1927 Inset * tmpinset = cursor.par->GetInset(cursor.pos);
1928 LyXFont font = text->GetFont(cursor.par, cursor.pos);
1930 if (direction == LYX_DIR_LEFT_TO_RIGHT) {
1932 end_x = cursor.x + tmpinset->Width(font);
1934 start_x = cursor.x - tmpinset->Width(font);
1938 if (x > start_x && x < end_x
1939 && y_tmp > cursor.y - tmpinset->Ascent(font)
1940 && y_tmp < cursor.y + tmpinset->Descent(font)) {
1942 // The origin of an inset is on the baseline
1943 y = y_tmp - (cursor.y);
1948 if (cursor.pos - 1 >= 0
1949 && cursor.par->GetChar(cursor.pos - 1) == LyXParagraph::META_INSET
1950 && cursor.par->GetInset(cursor.pos - 1)
1951 && cursor.par->GetInset(cursor.pos - 1)->Editable()) {
1953 Inset * tmpinset = cursor.par->GetInset(cursor.pos);
1954 LyXFont font = text->GetFont(cursor.par, cursor.pos);
1956 if (direction == LYX_DIR_LEFT_TO_RIGHT) {
1958 end_x = cursor.x + tmpinset->Width(font);
1960 start_x = cursor.x - tmpinset->Width(font);
1963 if (x > start_x && x < end_x
1964 && y_tmp > cursor.y - tmpinset->Ascent(font)
1965 && y_tmp < cursor.y + tmpinset->Descent(font)) {
1967 // The origin of an inset is on the baseline
1968 y = y_tmp - (cursor.y);
1971 text->CursorRight();
1980 void BufferView::workAreaExpose()
1982 // this is a hack to ensure that we only call this through
1983 // BufferView::redraw().
1988 static int work_area_width = -1;
1989 static int work_area_height = -1;
1991 bool widthChange = workarea->workWidth() != work_area_width;
1992 bool heightChange = workarea->height() != work_area_height;
1994 // update from work area
1995 work_area_width = workarea->workWidth();
1996 work_area_height = workarea->height();
1999 // All buffers need a resize
2000 bufferlist.resize();
2002 // Remove all texts from the textcache
2003 // This is not _really_ what we want to do. What
2004 // we really want to do is to delete in textcache
2005 // that does not have a BufferView with matching
2006 // width, but as long as we have only one BufferView
2007 // deleting all gives the same result.
2008 if (lyxerr.debugging())
2009 textcache.show(lyxerr, "Expose delete all");
2011 } else if (heightChange) {
2012 // Rebuild image of current screen
2014 // fitCursor() ensures we don't jump back
2015 // to the start of the document on vertical
2019 // The main window size has changed, repaint most stuff
2021 // ...including the minibuffer
2022 owner_->getMiniBuffer()->Init();
2024 } else if (screen) screen->Redraw();
2026 // Grey box when we don't have a buffer
2027 workarea->greyOut();
2030 // always make sure that the scrollbar is sane.
2032 owner_->updateLayoutChoice();
2036 int BufferView::workAreaExpose()
2038 if (!work_area || !work_area->form->visible)
2041 // this is a hack to ensure that we only call this through
2042 // BufferView::redraw().
2047 static int work_area_width = work_area->w;
2048 static int work_area_height = work_area->h;
2050 bool widthChange = work_area->w != work_area_width;
2051 bool heightChange = work_area->h != work_area_height;
2053 // update from work area
2054 work_area_width = work_area->w;
2055 work_area_height = work_area->h;
2058 // All buffers need a resize
2059 bufferlist.resize();
2061 // Remove all texts from the textcache
2062 // This is not _really_ what we want to do. What
2063 // we really want to do is to delete in textcache
2064 // that does not have a BufferView with matching
2065 // width, but as long as we have only one BufferView
2066 // deleting all gives the same result.
2067 if (lyxerr.debugging())
2068 textcache.show(lyxerr, "Expose delete all");
2070 } else if (heightChange) {
2071 // Rebuild image of current screen
2073 // fitCursor() ensures we don't jump back
2074 // to the start of the document on vertical
2078 // The main window size has changed, repaint most stuff
2080 // ...including the minibuffer
2081 owner_->getMiniBuffer()->Init();
2083 } else if (screen) screen->Redraw();
2085 // Grey box when we don't have a buffer
2086 fl_winset(FL_ObjWin(work_area));
2087 fl_rectangle(1, work_area->x, work_area->y,
2088 work_area->w, work_area->h, FL_GRAY63);
2091 // always make sure that the scrollbar is sane.
2093 owner_->updateLayoutChoice();
2099 // Callback for cursor timer
2100 void BufferView::CursorToggleCB(FL_OBJECT * ob, long)
2102 BufferView * view = static_cast<BufferView*>(ob->u_vdata);
2104 // Quite a nice place for asyncron Inset updating, isn't it?
2105 // Actually no! This is run even if no buffer exist... so (Lgb)
2106 if (view && !view->buffer_) {
2107 goto set_timer_and_return;
2111 // On my quest to solve the gs render hangups I am now
2112 // disabling the SIGHUP completely, and will do a wait
2113 // now and then instead. If the guess that xforms somehow
2114 // destroys something is true, this is likely (hopefully)
2115 // to solve the problem...at least I hope so. Lgb
2117 // ...Ok this seems to work...at least it does not make things
2118 // worse so far. However I still see gs processes that hangs.
2119 // I would really like to know _why_ they are hanging. Anyway
2120 // the solution without the SIGCHLD handler seems to be easier
2123 // When attaching gdb to a a running gs that hangs it shows
2124 // that it is waiting for input(?) Is it possible for us to
2125 // provide that input somehow? Or figure what it is expecing
2128 // One solution is to, after some time, look if there are some
2129 // old gs processes still running and if there are: kill them
2132 // Another solution is to provide the user an option to rerender
2133 // a picture. This would, for the picture in question, check if
2134 // there is a gs running for it, if so kill it, and start a new
2135 // rendering process.
2137 // these comments posted to lyx@via
2140 int pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
2141 if (pid == -1) // error find out what is wrong
2142 ; // ignore it for now.
2144 sigchldhandler(pid, &status);
2146 if (InsetUpdateList)
2147 UpdateInsetUpdateList();
2149 if (view && !view->screen){
2150 goto set_timer_and_return;
2153 if (view->lyx_focus && view->work_area_focus) {
2154 if (!view->the_locking_inset) {
2155 view->screen->CursorToggle();
2157 view->the_locking_inset->
2158 ToggleInsetCursor();
2160 goto set_timer_and_return;
2162 // Make sure that the cursor is visible.
2163 if (!view->the_locking_inset) {
2164 view->screen->ShowCursor();
2166 if (!view->the_locking_inset->isCursorVisible())
2167 view->the_locking_inset->
2168 ToggleInsetCursor();
2170 // This is only run when work_area_focus or lyx_focus is false.
2173 XGetInputFocus(fl_display, &tmpwin, &tmp);
2174 // Commenting this out, we have not had problems with this
2175 // for a long time. We will probably work on this code later
2176 // and we can reenable this debug code then. Now it only
2177 // anoying when debugging. (Lgb)
2178 //if (lyxerr.debugging(Debug::INFO)) {
2179 // lyxerr << "tmpwin: " << tmpwin
2180 // << "\nwindow: " << view->owner_->getForm()->window
2181 // << "\nwork_area_focus: " << view->work_area_focus
2182 // << "\nlyx_focus : " << view->lyx_focus
2185 if (tmpwin != view->owner_->getForm()->window) {
2186 view->lyx_focus = false;
2189 view->lyx_focus = true;
2190 if (!view->work_area_focus)
2193 goto set_timer_and_return;
2197 set_timer_and_return:
2198 fl_set_timer(ob, 0.4);
2206 string fromClipboard(Window win, XEvent * event)
2209 if (event->xselection.type == XA_STRING
2210 && event->xselection.property) {
2214 unsigned char * uc = 0;
2216 if (XGetWindowProperty(
2217 event->xselection.display, // display
2219 event->xselection.property, // property
2223 XA_STRING, // req_type
2224 &tmpatom, // actual_type_return
2225 &tmpint, // actual_format_return
2236 if (XGetWindowProperty(
2237 event->xselection.display, // display
2239 event->xselection.property, // property
2241 ul2/4+1, // long_length
2243 XA_STRING, // req_type
2244 &tmpatom, // actual_type_return
2245 &tmpint, // actual_format_return
2246 &ul1, // nitems_return
2247 &ul2, // bytes_after_return
2248 &uc // prop_return */
2253 strret = reinterpret_cast<char*>(uc);
2254 free(uc); // yes free!
2262 void BufferView::WorkAreaSelectionNotify(Window win, XEvent * event)
2264 if (buffer_ == 0) return;
2266 screen->HideCursor();
2268 string clb = fromClipboard(win, event);
2271 text->InsertStringA(clb.c_str());
2273 text->InsertStringB(clb.c_str());
2281 int BufferView::WorkAreaSelectionNotify(FL_OBJECT *, Window win,
2282 int /*w*/, int /*h*/,
2283 XEvent * event, void */*d*/)
2285 if (buffer_ == 0) return 0;
2286 if (event->type != SelectionNotify)
2292 unsigned char * uc = 0;
2294 screen->HideCursor();
2296 if (event->xselection.type == XA_STRING
2297 && event->xselection.property) {
2299 if (XGetWindowProperty(
2300 fl_display /* display */,
2302 event->xselection.property /* property */,
2303 0 /* long_offset */,
2304 0 /* long_length */,
2306 XA_STRING /* req_type */,
2307 &tmpatom /* actual_type_return */,
2308 &tmpint /* actual_format_return */,
2309 &ul1 /* nitems_return */,
2310 &ul2 /* bytes_after_return */,
2311 &uc /* prop_return */
2322 if (XGetWindowProperty(
2323 fl_display /* display */,
2325 event->xselection.property /* property */,
2326 0 /* long_offset */,
2327 ul2/4+1 /* long_length */,
2329 XA_STRING /* req_type */,
2330 &tmpatom /* actual_type_return */,
2331 &tmpint /* actual_format_return */,
2332 &ul1 /* nitems_return */,
2333 &ul2 /* bytes_after_return */,
2334 &uc /* prop_return */
2342 text->InsertStringA(reinterpret_cast<char*>(uc));
2344 text->InsertStringB(reinterpret_cast<char*>(uc));
2358 void BufferView::cursorPrevious()
2360 if (!text->cursor.row->previous) return;
2362 long y = getScreen()->first;
2363 Row * cursorrow = text->cursor.row;
2364 text->SetCursorFromCoordinates(text->cursor.x_fix, y);
2366 // This is to allow jumping over large insets
2367 if ((cursorrow == text->cursor.row))
2370 if (text->cursor.row->height < workarea->height())
2371 getScreen()->Draw(text->cursor.y
2372 - text->cursor.row->baseline
2373 + text->cursor.row->height
2374 - workarea->height() + 1 );
2377 void BufferView::cursorPrevious()
2379 if (!text->cursor.row->previous) return;
2381 long y = getScreen()->first;
2382 Row * cursorrow = text->cursor.row;
2383 text->SetCursorFromCoordinates(text->cursor.x_fix, y);
2385 // This is to allow jumping over large insets
2386 if ((cursorrow == text->cursor.row))
2389 if (text->cursor.row->height < work_area->h)
2390 getScreen()->Draw(text->cursor.y
2391 - text->cursor.row->baseline
2392 + text->cursor.row->height
2393 - work_area->h +1 );
2399 void BufferView::cursorNext()
2401 if (!text->cursor.row->next) return;
2403 long y = getScreen()->first;
2404 text->GetRowNearY(y);
2405 Row * cursorrow = text->cursor.row;
2406 text->SetCursorFromCoordinates(text->cursor.x_fix, y
2407 + workarea->height());
2409 // This is to allow jumping over large insets
2410 if ((cursorrow == text->cursor.row))
2413 if (text->cursor.row->height < workarea->height())
2414 getScreen()->Draw(text->cursor.y
2415 - text->cursor.row->baseline);
2418 void BufferView::cursorNext()
2420 if (!text->cursor.row->next) return;
2422 long y = getScreen()->first;
2423 text->GetRowNearY(y);
2424 Row * cursorrow = text->cursor.row;
2425 text->SetCursorFromCoordinates(text->cursor.x_fix, y + work_area->h);
2427 // This is to allow jumping over large insets
2428 if ((cursorrow == text->cursor.row))
2431 if (text->cursor.row->height < work_area->h)
2432 getScreen()->Draw(text->cursor.y
2433 - text->cursor.row->baseline);
2438 bool BufferView::available() const
2440 if (buffer_ && text) return true;
2445 void BufferView::beforeChange()
2447 getScreen()->ToggleSelection();
2448 text->ClearSelection();
2453 void BufferView::savePosition()
2455 backstack.push(buffer()->fileName(),
2461 void BufferView::restorePosition()
2463 if (backstack.empty()) return;
2466 string fname = backstack.pop(&x, &y);
2469 Buffer * b = bufferlist.exists(fname) ?
2470 bufferlist.getBuffer(fname) :
2471 bufferlist.loadLyXFile(fname); // don't ask, just load it
2473 text->SetCursorFromCoordinates(x, y);
2478 void BufferView::update(signed char f)
2480 owner()->updateLayoutChoice();
2482 if (!text->selection && f > -3)
2483 text->sel_cursor = text->cursor;
2486 text->FullRebreak();
2490 if (f != 3 && f != -3) {
2495 if (f == 1 || f == -1) {
2496 if (buffer()->isLyxClean()) {
2497 buffer()->markDirty();
2498 owner()->getMiniBuffer()->setTimer(4);
2500 buffer()->markDirty();
2506 void BufferView::smallUpdate(signed char f)
2508 getScreen()->SmallUpdate();
2509 if (getScreen()->TopCursorVisible()
2510 != getScreen()->first) {
2518 if (!text->selection)
2519 text->sel_cursor = text->cursor;
2521 if (f == 1 || f == -1) {
2522 if (buffer()->isLyxClean()) {
2523 buffer()->markDirty();
2524 owner()->getMiniBuffer()->setTimer(4);
2526 buffer()->markDirty();
2532 void BufferView::SetState()
2534 if (!lyxrc->rtl_support)
2537 if (text->real_current_font.getFontDirection()
2538 == LYX_DIR_LEFT_TO_RIGHT) {
2539 if (!owner_->getIntl()->primarykeymap)
2540 owner_->getIntl()->KeyMapPrim();
2542 if (owner_->getIntl()->primarykeymap)
2543 owner_->getIntl()->KeyMapSec();
2548 void BufferView::insetSleep()
2550 if (the_locking_inset && !inset_slept) {
2551 the_locking_inset->GetCursorPos(slx, sly);
2552 the_locking_inset->InsetUnlock();
2558 void BufferView::insetWakeup()
2560 if (the_locking_inset && inset_slept) {
2561 the_locking_inset->Edit(slx, sly);
2562 inset_slept = false;
2567 void BufferView::insetUnlock()
2569 if (the_locking_inset) {
2570 if (!inset_slept) the_locking_inset->InsetUnlock();
2571 the_locking_inset = 0;
2573 inset_slept = false;
2578 bool BufferView::focus() const
2580 return workarea->hasFocus();
2584 void BufferView::focus(bool f)
2586 if (f) workarea->setFocus();
2590 bool BufferView::active() const
2592 return workarea->active();