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"
45 #include "lyx_gui_misc.h"
46 #include "BackStack.h"
51 #include "TextCache.h"
59 extern BufferList bufferlist;
62 void sigchldhandler(pid_t pid, int * status);
64 extern void SetXtermCursor(Window win);
65 extern bool input_prohibited;
66 extern bool selection_possible;
67 extern char ascii_type;
68 extern void MenuPasteSelection(char at);
69 extern InsetUpdateStruct * InsetUpdateList;
70 extern void UpdateInsetUpdateList();
71 extern void FreeUpdateTimer();
74 // This is _very_ temporary
75 FL_OBJECT * figinset_canvas;
78 BufferView::BufferView(LyXView * o, int xpos, int ypos,
79 int width, int height)
86 workarea = new WorkArea(this, xpos, ypos, width, height);
95 create_view(xpos, ypos, width, height);
96 current_scrollbar_value = 0;
97 // Activate the timer for the cursor
98 fl_set_timer(timer_cursor, 0.4);
100 workarea->setFocus();
102 fl_set_focus_object(owner_->getForm(), work_area);
104 work_area_focus = true;
106 the_locking_inset = 0;
111 BufferView::~BufferView()
118 Painter & BufferView::painter()
120 return workarea->getPainter();
125 void BufferView::buffer(Buffer * b)
127 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
131 buffer_->delUser(this);
133 // Put the old text into the TextCache, but
134 // only if the buffer is still loaded.
135 // Also set the owner of the test to 0
138 if (lyxerr.debugging())
139 textcache.show(lyxerr, "BufferView::buffer");
144 // Set current buffer
147 if (bufferlist.getState() == BufferList::CLOSING) return;
150 // screen is always deleted when the buffer is changed.
154 // If we are closing the buffer, use the first buffer as current
156 buffer_ = bufferlist.first();
160 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
161 buffer_->addUser(this);
162 owner_->getMenus()->showMenus();
163 // If we don't have a text object for this, we make one
165 resizeCurrentBuffer();
170 screen->first = screen->TopCursorVisible();
172 updateAllVisibleBufferRelatedPopups();
175 lyxerr[Debug::INFO] << " No Buffer!" << endl;
176 owner_->getMenus()->hideMenus();
181 fl_redraw_object(work_area);
184 // Also remove all remaining text's from the testcache.
185 // (there should not be any!) (if there is any it is a
187 if (lyxerr.debugging())
188 textcache.show(lyxerr, "buffer delete all");
191 // should update layoutchoice even if we don't have a buffer.
192 owner_->updateLayoutChoice();
193 owner_->getMiniBuffer()->Init();
194 owner_->updateWindowTitle();
198 void BufferView::updateScreen()
200 // Regenerate the screen.
203 screen = new LyXScreen(this,
205 workarea->getPixmap(),
206 workarea->workWidth(),
212 screen = new LyXScreen(FL_ObjWin(work_area),
223 void BufferView::resize(int xpos, int ypos, int width, int height)
225 workarea->resize(xpos, ypos, width, height);
232 void BufferView::resize()
234 // This will resize the buffer. (Asger)
236 resizeCurrentBuffer();
241 static bool lgb_hack = false;
244 void BufferView::redraw()
246 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
251 fl_redraw_object(work_area);
252 fl_redraw_object(scrollbar);
253 fl_redraw_object(button_down);
254 fl_redraw_object(button_up);
260 void BufferView::fitCursor()
262 if (screen) screen->FitCursor();
267 void BufferView::update()
269 if (screen) screen->Update();
273 void BufferView::updateScrollbar()
275 /* If the text is smaller than the working area, the scrollbar
276 * maximum must be the working area height. No scrolling will
281 workarea->setScrollbar(0, 1.0);
283 fl_set_slider_value(scrollbar, 0);
284 fl_set_slider_size(scrollbar, scrollbar->h);
289 static long max2 = 0;
290 static long height2 = 0;
298 cbsf = screen->first;
300 // check if anything has changed.
303 height2 == workarea->height() &&
304 current_scrollbar_value == cbsf)
307 height2 = workarea->height();
308 current_scrollbar_value = cbsf;
311 height2 == work_area->h &&
312 current_scrollbar_value == cbsf)
315 height2 = work_area->h;
316 current_scrollbar_value = cbsf;
319 if (cbth <= height2) { // text is smaller than screen
321 workarea->setScrollbar(0, 1.0); // right?
323 fl_set_slider_size(scrollbar, scrollbar->h);
329 long maximum_height = workarea->height() * 3 / 4 + cbth;
331 long maximum_height = work_area->h * 3 / 4 + cbth;
337 double hfloat = workarea->height();
339 double hfloat = work_area->h;
341 double maxfloat = maximum_height;
344 float slider_size = 0.0;
345 int slider_value = value;
347 workarea->setScrollbarBounds(0, text->height - workarea->height());
348 double lineh = text->DefaultHeight();
349 workarea->setScrollbarIncrements(lineh);
350 if (maxfloat > 0.0) {
351 if ((hfloat / maxfloat) * float(height2) < 3)
352 slider_size = 3.0/float(height2);
354 slider_size = hfloat / maxfloat;
356 slider_size = hfloat;
358 workarea->setScrollbar(slider_value, slider_size / workarea->height());
360 fl_set_slider_value(scrollbar, value);
361 fl_set_slider_bounds(scrollbar, 0,
362 maximum_height - work_area->h);
364 double lineh = text->DefaultHeight();
365 fl_set_slider_increment(scrollbar, work_area->h-lineh, lineh);
368 if ((hfloat / maxfloat) * float(height2) < 3)
369 fl_set_slider_size(scrollbar,
372 fl_set_slider_size(scrollbar,
375 fl_set_slider_size(scrollbar, hfloat);
376 fl_set_slider_precision(scrollbar, 0);
381 void BufferView::redoCurrentBuffer()
383 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
384 if (buffer_ && text) {
386 owner_->updateLayoutChoice();
391 int BufferView::resizeCurrentBuffer()
393 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
395 LyXParagraph * par = 0;
396 LyXParagraph * selstartpar = 0;
397 LyXParagraph * selendpar = 0;
406 owner_->getMiniBuffer()->Set(_("Formatting document..."));
409 par = text->cursor.par;
410 pos = text->cursor.pos;
411 selstartpar = text->sel_start_cursor.par;
412 selstartpos = text->sel_start_cursor.pos;
413 selendpar = text->sel_end_cursor.par;
414 selendpos = text->sel_end_cursor.pos;
415 selection = text->selection;
416 mark_set = text->mark_set;
419 text = new LyXText(this, workarea->workWidth(), buffer_);
421 text = new LyXText(work_area->w, buffer_);
424 // See if we have a text in TextCache that fits
425 // the new buffer_ with the correct width.
427 text = textcache.findFit(buffer_, workarea->workWidth());
429 text = textcache.findFit(buffer_, work_area->w);
432 if (lyxerr.debugging()) {
433 lyxerr << "Found a LyXText that fits:\n";
434 textcache.show(lyxerr, text);
436 // Set the owner of the newly found text
438 if (lyxerr.debugging())
439 textcache.show(lyxerr, "resizeCurrentBuffer");
442 text = new LyXText(this, workarea->workWidth(), buffer_);
444 text = new LyXText(work_area->w, buffer_);
451 text->selection = true;
452 /* at this point just to avoid the Delete-Empty-Paragraph
453 * Mechanism when setting the cursor */
454 text->mark_set = mark_set;
456 text->SetCursor(selstartpar, selstartpos);
457 text->sel_cursor = text->cursor;
458 text->SetCursor(selendpar, selendpos);
459 text->SetSelection();
460 text->SetCursor(par, pos);
462 text->SetCursor(par, pos);
463 text->sel_cursor = text->cursor;
464 text->selection = false;
467 screen->first = screen->TopCursorVisible(); /* this will scroll the
468 * screen such that the
473 owner_->getMiniBuffer()->Init();
477 // Now if the title form still exist kill it
484 void BufferView::gotoError()
489 screen->HideCursor();
494 if (!text->GotoNextError()) {
496 || text->cursor.par != text->FirstParagraph()) {
498 text->cursor.par = text->FirstParagraph();
499 text->cursor.pos = 0;
500 if (!text->GotoNextError()) {
502 owner_->getMiniBuffer()
503 ->Set(_("No more errors"));
507 owner_->getMiniBuffer()->Set(_("No more errors"));
512 text->sel_cursor = text->cursor;
518 void C_BufferView_CursorToggleCB(FL_OBJECT * ob, long buf)
520 BufferView::CursorToggleCB(ob, buf);
525 // Just a bunch of C wrappers around static members of BufferView
526 void C_BufferView_UpCB(FL_OBJECT * ob, long buf)
528 BufferView::UpCB(ob, buf);
532 void C_BufferView_DownCB(FL_OBJECT * ob, long buf)
534 BufferView::DownCB(ob, buf);
538 void C_BufferView_ScrollCB(FL_OBJECT * ob, long buf)
540 BufferView::ScrollCB(ob, buf);
544 void C_BufferView_CursorToggleCB(FL_OBJECT * ob, long buf)
546 BufferView::CursorToggleCB(ob, buf);
550 int C_BufferView_work_area_handler(FL_OBJECT * ob, int event,
554 return BufferView::work_area_handler(ob, event,
561 void BufferView::create_view(int xpos, int ypos, int width, int height)
565 int const bw = abs(fl_get_border_width());
567 // a hack for the figinsets (Matthias)
568 // This one first, then it will probably be invisible. (Lgb)
569 ::figinset_canvas = figinset_canvas = obj =
570 fl_add_canvas(FL_NORMAL_CANVAS,
573 fl_set_object_boxtype(obj, FL_NO_BOX);
574 fl_set_object_resize(obj, FL_RESIZE_ALL);
575 fl_set_object_gravity(obj, NorthWestGravity, NorthWestGravity);
578 obj = fl_add_box(FL_BORDER_BOX, xpos, ypos,
581 fl_set_object_resize(obj, FL_RESIZE_ALL);
582 fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
585 work_area = obj = fl_add_free(FL_INPUT_FREE,
586 xpos + bw, ypos + bw,
587 width - 15 - 2 * bw /* scrollbarwidth */,
589 C_BufferView_work_area_handler);
590 obj->wantkey = FL_KEY_TAB;
591 obj->u_vdata = this; /* This is how we pass the BufferView
592 to the work_area_handler. */
593 fl_set_object_boxtype(obj, FL_DOWN_BOX);
594 fl_set_object_resize(obj, FL_RESIZE_ALL);
595 fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
601 // up - scrollbar button
602 fl_set_border_width(-1); // to get visual feedback
604 button_up = obj = fl_add_pixmapbutton(FL_TOUCH_BUTTON,
608 fl_set_object_boxtype(obj, FL_UP_BOX);
609 fl_set_object_color(obj, FL_MCOL, FL_BLUE);
610 fl_set_object_resize(obj, FL_RESIZE_ALL);
611 fl_set_object_gravity(obj, NorthEastGravity, NorthEastGravity);
612 fl_set_object_callback(obj, C_BufferView_UpCB, 0);
614 fl_set_pixmapbutton_data(obj, const_cast<char**>(up_xpm));
616 // Remove the blue feedback rectangle
617 fl_set_pixmapbutton_focus_outline(obj, 0);
619 // the scrollbar slider
620 fl_set_border_width(-bw);
621 scrollbar = obj = fl_add_slider(FL_VERT_SLIDER,
624 15, height - 30, "");
625 fl_set_object_color(obj, FL_COL1, FL_MCOL);
626 fl_set_object_boxtype(obj, FL_UP_BOX);
627 fl_set_object_resize(obj, FL_RESIZE_ALL);
628 fl_set_object_gravity(obj, NorthEastGravity, SouthEastGravity);
629 fl_set_object_callback(obj, C_BufferView_ScrollCB, 0);
632 // down - scrollbar button
633 fl_set_border_width(-1); // to get visible feedback
635 button_down = obj = fl_add_pixmapbutton(FL_TOUCH_BUTTON,
639 fl_set_object_boxtype(obj, FL_UP_BOX);
640 fl_set_object_color(obj, FL_MCOL, FL_BLUE);
641 fl_set_object_resize(obj, FL_RESIZE_ALL);
642 fl_set_object_gravity(obj, SouthEastGravity, SouthEastGravity);
643 fl_set_object_callback(obj, C_BufferView_DownCB, 0);
645 fl_set_pixmapbutton_data(obj, const_cast<char**>(down_xpm));
646 fl_set_border_width(-bw);
648 // Remove the blue feedback rectangle
649 fl_set_pixmapbutton_focus_outline(obj, 0);
656 timer_cursor = obj = fl_add_timer(FL_HIDDEN_TIMER,
657 0, 0, 0, 0, "Timer");
658 fl_set_object_callback(obj, C_BufferView_CursorToggleCB, 0);
663 // Callback for scrollbar up button
665 void BufferView::UpCB(long time, int button)
667 if (buffer_ == 0) return;
682 void BufferView::UpCB(FL_OBJECT * ob, long)
684 BufferView * view = static_cast<BufferView*>(ob->u_vdata);
686 if (view->buffer_ == 0) return;
688 static long time = 0;
689 XEvent const * ev2 = fl_last_event();
690 if (ev2->type == ButtonPress || ev2->type == ButtonRelease)
692 int button = fl_get_button_numb(ob);
695 view->ScrollUpOnePage(time++); break;
697 view->ScrollDownOnePage(time++); break;
699 view->ScrollUp(time++); break;
708 XSync(fl_get_display(), 0);
712 // Callback for scrollbar slider
714 void BufferView::ScrollCB(double value)
716 extern bool cursor_follows_scrollbar;
718 if (buffer_ == 0) return;
720 current_scrollbar_value = long(value);
721 if (current_scrollbar_value < 0)
722 current_scrollbar_value = 0;
727 screen->Draw(current_scrollbar_value);
729 if (cursor_follows_scrollbar) {
730 LyXText * vbt = text;
731 int height = vbt->DefaultHeight();
733 if (vbt->cursor.y < screen->first + height) {
734 vbt->SetCursorFromCoordinates(0,
737 } else if (vbt->cursor.y >
738 screen->first + workarea->height() - height) {
739 vbt->SetCursorFromCoordinates(0,
748 void BufferView::ScrollCB(FL_OBJECT * ob, long)
750 BufferView * view = static_cast<BufferView*>(ob->u_vdata);
751 extern bool cursor_follows_scrollbar;
753 if (view->buffer_ == 0) return;
755 view->current_scrollbar_value = long(fl_get_slider_value(ob));
756 if (view->current_scrollbar_value < 0)
757 view->current_scrollbar_value = 0;
762 view->screen->Draw(view->current_scrollbar_value);
764 if (cursor_follows_scrollbar) {
765 LyXText * vbt = view->text;
766 int height = vbt->DefaultHeight();
768 if (vbt->cursor.y < view->screen->first + height) {
769 vbt->SetCursorFromCoordinates(0,
770 view->screen->first +
773 else if (vbt->cursor.y >
774 view->screen->first + view->work_area->h - height) {
775 vbt->SetCursorFromCoordinates(0,
776 view->screen->first +
786 // Callback for scrollbar down button
788 void BufferView::DownCB(long time, int button)
790 if (buffer_ == 0) return;
805 void BufferView::DownCB(FL_OBJECT * ob, long)
807 BufferView * view = static_cast<BufferView*>(ob->u_vdata);
809 if (view->buffer_ == 0) return;
812 static long time = 0;
813 ev2 = fl_last_event();
814 if (ev2->type == ButtonPress || ev2->type == ButtonRelease)
816 int button = fl_get_button_numb(ob);
819 view->ScrollUpOnePage(time++); break;
821 view->ScrollDownOnePage(time++); break;
823 view->ScrollDown(time++); break;
830 int BufferView::ScrollUp(long time)
832 if (buffer_ == 0) return 0;
833 if (!screen) return 0;
835 double value = workarea->getScrollbarValue();
837 if (value == 0) return 0;
839 float add_value = (text->DefaultHeight()
840 + float(time) * float(time) * 0.125);
842 if (add_value > workarea->height())
843 add_value = float(workarea->height() -
844 text->DefaultHeight());
851 workarea->setScrollbarValue(value);
857 int BufferView::ScrollUp(long time)
859 if (buffer_ == 0) return 0;
860 if (!screen) return 0;
862 double value = fl_get_slider_value(scrollbar);
864 if (value == 0) return 0;
866 float add_value = (text->DefaultHeight()
867 + float(time) * float(time) * 0.125);
869 if (add_value > work_area->h)
870 add_value = float(work_area->h -
871 text->DefaultHeight());
878 fl_set_slider_value(scrollbar, value);
880 ScrollCB(scrollbar, 0);
887 int BufferView::ScrollDown(long time)
889 if (buffer_ == 0) return 0;
890 if (!screen) return 0;
892 double value= workarea->getScrollbarValue();
893 pair<double, double> p = workarea->getScrollbarBounds();
894 double max = p.second;
896 if (value == max) return 0;
898 float add_value = (text->DefaultHeight()
899 + float(time) * float(time) * 0.125);
901 if (add_value > workarea->height())
902 add_value = float(workarea->height() -
903 text->DefaultHeight());
910 workarea->setScrollbarValue(value);
916 int BufferView::ScrollDown(long time)
918 if (buffer_ == 0) return 0;
919 if (!screen) return 0;
921 double value= fl_get_slider_value(scrollbar);
923 fl_get_slider_bounds(scrollbar, &min, &max);
925 if (value == max) return 0;
927 float add_value = (text->DefaultHeight()
928 + float(time) * float(time) * 0.125);
930 if (add_value > work_area->h)
931 add_value = float(work_area->h -
932 text->DefaultHeight());
939 fl_set_slider_value(scrollbar, value);
941 ScrollCB(scrollbar, 0);
948 void BufferView::ScrollUpOnePage()
950 if (buffer_ == 0) return;
953 long y = screen->first;
957 Row * row = text->GetRowNearY(y);
959 y = y - workarea->height() + row->height;
961 workarea->setScrollbarValue(y);
966 void BufferView::ScrollUpOnePage(long /*time*/)
968 if (buffer_ == 0) return;
971 long y = screen->first;
975 Row * row = text->GetRowNearY(y);
977 y = y - work_area->h + row->height;
979 fl_set_slider_value(scrollbar, y);
981 ScrollCB(scrollbar, 0);
987 void BufferView::ScrollDownOnePage()
989 if (buffer_ == 0) return;
992 long y = screen->first;
994 if (y > text->height - workarea->height())
997 y += workarea->height();
998 text->GetRowNearY(y);
1000 workarea->setScrollbarValue(y);
1005 void BufferView::ScrollDownOnePage(long /*time*/)
1007 if (buffer_ == 0) return;
1008 if (!screen) return;
1011 fl_get_slider_bounds(scrollbar, &min, &max);
1012 long y = screen->first;
1014 if (y > text->height - work_area->h)
1018 text->GetRowNearY(y);
1020 fl_set_slider_value(scrollbar, y);
1022 ScrollCB(scrollbar, 0);
1028 int BufferView::work_area_handler(FL_OBJECT * ob, int event,
1029 FL_Coord, FL_Coord ,
1030 int /*key*/, void * xev)
1032 static int x_old = -1;
1033 static int y_old = -1;
1034 static long scrollbar_value_old = -1;
1036 XEvent * ev = static_cast<XEvent*>(xev);
1037 BufferView * view = static_cast<BufferView*>(ob->u_vdata);
1039 // If we don't have a view yet; return
1040 if (!view || quitting) return 0;
1044 view->workAreaExpose();
1047 view->WorkAreaButtonPress(ob, 0, 0, 0, ev, 0);
1050 view->WorkAreaButtonRelease(ob, 0, 0, 0, ev, 0);
1053 if (ev->xmotion.x != x_old ||
1054 ev->xmotion.y != y_old ||
1055 view->current_scrollbar_value != scrollbar_value_old) {
1056 x_old = ev->xmotion.x;
1057 y_old = ev->xmotion.y;
1058 scrollbar_value_old = view->current_scrollbar_value;
1059 view->WorkAreaMotionNotify(ob, 0, 0, 0, ev, 0);
1062 // Done by the raw callback:
1063 // case FL_KEYBOARD:
1064 // WorkAreaKeyPress(ob, 0, 0, 0, ev, 0); break;
1066 if (!view->owner_->getMiniBuffer()->shows_no_match)
1067 view->owner_->getMiniBuffer()->Init();
1068 view->owner_->getMiniBuffer()->shows_no_match = false;
1069 view->work_area_focus = true;
1070 fl_set_timer(view->timer_cursor, 0.4);
1073 view->owner_->getMiniBuffer()->ExecCommand();
1074 view->work_area_focus = false;
1077 SetXtermCursor(view->owner_->getForm()->window);
1079 view->lyx_focus = true;
1080 fl_set_timer(view->timer_cursor, 0.4);
1083 if (!input_prohibited)
1084 XUndefineCursor(fl_display,
1085 view->owner_->getForm()->window);
1086 view->lyx_focus = false; // This is not an absolute truth
1087 // but if it is not true, it will be changed within a blink
1088 // of an eye. ... Not good enough... use regulare timeperiod
1089 //fl_set_timer(view->timer_cursor, 0.01); // 0.1 sec blink
1090 fl_set_timer(view->timer_cursor, 0.4); // 0.4 sec blink
1094 if (!view->the_locking_inset) {
1095 if (view->screen && ev->xbutton.button == 1) {
1096 view->screen->HideCursor();
1097 view->screen->ToggleSelection();
1098 view->text->SelectWord();
1099 view->screen->ToggleSelection(false);
1100 /* This will fit the cursor on the screen
1108 if (view->buffer_ && view->screen && ev->xbutton.button == 1) {
1109 view->screen->HideCursor();
1110 view->screen->ToggleSelection();
1111 view->text->CursorHome();
1112 view->text->sel_cursor = view->text->cursor;
1113 view->text->CursorEnd();
1114 view->text->SetSelection();
1115 view->screen->ToggleSelection(false);
1116 /* This will fit the cursor on the screen
1122 view->WorkAreaSelectionNotify(ob,
1123 view->owner_->getForm()->window,
1133 void BufferView::WorkAreaMotionNotify(int x, int y, unsigned int state)
1135 if (buffer_ == 0 || !screen) return;
1137 // Check for inset locking
1138 if (the_locking_inset) {
1139 LyXCursor cursor = text->cursor;
1141 InsetMotionNotify(x - cursor.x,
1147 // Only use motion with button 1
1148 if (!state & Button1MotionMask)
1151 /* The selection possible is needed, that only motion events are
1152 * used, where the bottom press event was on the drawing area too */
1153 if (selection_possible) {
1154 screen->HideCursor();
1156 text->SetCursorFromCoordinates(x, y + screen->first);
1158 if (!text->selection)
1159 update(-3); // Maybe an empty line was deleted
1161 text->SetSelection();
1162 screen->ToggleToggle();
1163 if (screen->FitCursor())
1165 screen->ShowCursor();
1170 int BufferView::WorkAreaMotionNotify(FL_OBJECT * ob, Window,
1171 int /*w*/, int /*h*/,
1172 XEvent * ev, void * /*d*/)
1174 if (buffer_ == 0) return 0;
1175 if (!screen) return 0;
1177 // Check for inset locking
1178 if (the_locking_inset) {
1179 LyXCursor cursor = text->cursor;
1181 InsetMotionNotify(ev->xbutton.x - ob->x - cursor.x,
1182 ev->xbutton.y - ob->y -
1188 // Only use motion with button 1
1189 if (!ev->xmotion.state & Button1MotionMask)
1192 /* The selection possible is needed, that only motion events are
1193 * used, where the bottom press event was on the drawing area too */
1194 if (selection_possible) {
1195 screen->HideCursor();
1197 text->SetCursorFromCoordinates(ev->xbutton.x - ob->x,
1198 ev->xbutton.y - ob->y +
1201 if (!text->selection)
1202 update(-3); // Maybe an empty line was deleted
1204 text->SetSelection();
1205 screen->ToggleToggle();
1206 if (screen->FitCursor())
1208 screen->ShowCursor();
1215 extern int bibitemMaxWidth(Painter &, LyXFont const &);
1217 extern int bibitemMaxWidth(LyXFont const &);
1220 // Single-click on work area
1222 void BufferView::WorkAreaButtonPress(int xpos, int ypos, unsigned int button)
1227 if (buffer_ == 0 || !screen) return;
1229 Inset * inset_hit = checkInsetHit(xpos, ypos);
1231 // ok ok, this is a hack.
1232 if (button == 4 || button == 5) {
1235 ScrollUp(100); // This number is only temporary
1243 if (the_locking_inset) {
1244 // We are in inset locking mode
1246 /* Check whether the inset was hit. If not reset mode,
1247 otherwise give the event to the inset */
1250 InsetButtonPress(xpos, ypos,
1254 unlockInset(the_locking_inset);
1258 selection_possible = true;
1259 screen->HideCursor();
1261 // Right button mouse click on a table
1263 (text->cursor.par->table ||
1264 text->MouseHitInTable(xpos, ypos + screen->first))) {
1265 // Set the cursor to the press-position
1266 text->SetCursorFromCoordinates(xpos, ypos + screen->first);
1269 // Only show the table popup if the hit is in
1271 if (!text->HitInTable(text->cursor.row, xpos))
1274 // Hit above or below the table?
1276 if (!text->selection) {
1277 screen->ToggleSelection();
1278 text->ClearSelection();
1279 text->FullRebreak();
1283 // Popup table popup when on a table.
1284 // This is obviously temporary, since we
1285 // should be able to popup various
1286 // context-sensitive-menus with the
1287 // the right mouse. So this should be done more
1288 // general in the future. Matthias.
1289 selection_possible = false;
1290 owner_->getLyXFunc()
1291 ->Dispatch(LFUN_LAYOUT_TABLE,
1297 int screen_first = screen->first;
1299 // Middle button press pastes if we have a selection
1300 bool paste_internally = false;
1302 && text->selection) {
1303 owner_->getLyXFunc()->Dispatch(LFUN_COPY);
1304 paste_internally = true;
1307 // Clear the selection
1308 screen->ToggleSelection();
1309 text->ClearSelection();
1310 text->FullRebreak();
1314 // Single left click in math inset?
1315 if (inset_hit != 0 && inset_hit->Editable() == 2) {
1316 // Highly editable inset, like math
1317 selection_possible = false;
1318 owner_->updateLayoutChoice();
1319 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
1320 inset_hit->Edit(xpos, ypos);
1324 // Right click on a footnote flag opens float menu
1326 selection_possible = false;
1330 text->SetCursorFromCoordinates(xpos, ypos + screen_first);
1332 text->sel_cursor = text->cursor;
1333 text->cursor.x_fix = text->cursor.x;
1335 owner_->updateLayoutChoice();
1336 if (screen->FitCursor()){
1338 selection_possible = false;
1341 // Insert primary selection with middle mouse
1342 // if there is a local selection in the current buffer,
1345 if (paste_internally)
1346 owner_->getLyXFunc()->Dispatch(LFUN_PASTE);
1348 owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION,
1350 selection_possible = false;
1355 int BufferView::WorkAreaButtonPress(FL_OBJECT * ob, Window,
1356 int /*w*/, int /*h*/,
1357 XEvent * ev, void */*d*/)
1362 if (buffer_ == 0) return 0;
1363 if (!screen) return 0;
1365 int const x = ev->xbutton.x - ob->x;
1366 int const y = ev->xbutton.y - ob->y;
1367 // If we hit an inset, we have the inset coordinates in these
1368 // and inset_hit points to the inset. If we do not hit an
1369 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
1372 Inset * inset_hit = checkInsetHit(inset_x, inset_y);
1374 // ok ok, this is a hack.
1375 int button = ev->xbutton.button;
1376 if (button == 4 || button == 5) goto wheel;
1379 if (the_locking_inset) {
1380 // We are in inset locking mode
1382 /* Check whether the inset was hit. If not reset mode,
1383 otherwise give the event to the inset */
1384 if (inset_hit != 0) {
1386 InsetButtonPress(inset_x, inset_y,
1390 unlockInset(the_locking_inset);
1394 selection_possible = true;
1395 screen->HideCursor();
1397 // Right button mouse click on a table
1399 (text->cursor.par->table ||
1400 text->MouseHitInTable(x, y + screen->first))) {
1401 // Set the cursor to the press-position
1402 text->SetCursorFromCoordinates(x, y + screen->first);
1405 // Only show the table popup if the hit is in
1407 if (!text->HitInTable(text->cursor.row, x))
1410 // Hit above or below the table?
1412 if (!text->selection) {
1413 screen->ToggleSelection();
1414 text->ClearSelection();
1415 text->FullRebreak();
1419 // Popup table popup when on a table.
1420 // This is obviously temporary, since we
1421 // should be able to popup various
1422 // context-sensitive-menus with the
1423 // the right mouse. So this should be done more
1424 // general in the future. Matthias.
1425 selection_possible = false;
1426 owner_->getLyXFunc()
1427 ->Dispatch(LFUN_LAYOUT_TABLE,
1433 int screen_first = screen->first;
1435 // Middle button press pastes if we have a selection
1436 bool paste_internally = false;
1437 if (button == 2 // && !buffer_->the_locking_inset
1438 && text->selection) {
1439 owner_->getLyXFunc()->Dispatch(LFUN_COPY);
1440 paste_internally = true;
1443 // Clear the selection
1444 screen->ToggleSelection();
1445 text->ClearSelection();
1446 text->FullRebreak();
1450 // Single left click in math inset?
1451 if (inset_hit != 0 && inset_hit->Editable() == 2) {
1452 // Highly editable inset, like math
1453 selection_possible = false;
1454 owner_->updateLayoutChoice();
1455 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
1456 inset_hit->Edit(inset_x, inset_y);
1460 // Right click on a footnote flag opens float menu
1462 selection_possible = false;
1466 text->SetCursorFromCoordinates(x, y + screen_first);
1468 text->sel_cursor = text->cursor;
1469 text->cursor.x_fix = text->cursor.x;
1471 owner_->updateLayoutChoice();
1472 if (screen->FitCursor()){
1474 selection_possible = false;
1477 // Insert primary selection with middle mouse
1478 // if there is a local selection in the current buffer,
1480 if (button == 2) { // && !buffer_->the_locking_inset){
1481 if (paste_internally)
1482 owner_->getLyXFunc()->Dispatch(LFUN_PASTE);
1484 owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION,
1486 selection_possible = false;
1493 // I am not quite sure if this is the correct place to put
1494 // this, but it will not cause any harm.
1495 // Patch from Mark Huang (markman@mit.edu) to make LyX
1496 // recognise button 4 and 5. This enables LyX use use
1497 // the scrollwhell on certain mice for something useful. (Lgb)
1498 // Added wheel acceleration detection code. (Rvdk)
1499 static Time lastTime = 0;
1500 int diff = ev->xbutton.time - lastTime;
1501 int scroll = int(1.0 + (4.0 / (abs(diff) + 1.0)) * 200.0);
1510 lastTime = ev->xbutton.time;
1523 void BufferView::WorkAreaButtonRelease(int x, int y, unsigned int button)
1525 if (buffer_ == 0 || screen == 0) return;
1527 // If we hit an inset, we have the inset coordinates in these
1528 // and inset_hit points to the inset. If we do not hit an
1529 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
1530 Inset * inset_hit = checkInsetHit(x, y);
1532 if (the_locking_inset) {
1533 // We are in inset locking mode.
1535 /* LyX does a kind of work-area grabbing for insets.
1536 Only a ButtonPress Event outside the inset will
1537 force a InsetUnlock. */
1539 InsetButtonRelease(x, x, button);
1543 selection_possible = false;
1544 if (text->cursor.par->table) {
1546 NumberOfCell(text->cursor.par,
1548 if (text->cursor.par->table->IsContRow(cell) &&
1549 text->cursor.par->table->
1550 CellHasContRow(text->cursor.par->table->
1551 GetCellAbove(cell))<0) {
1556 if (button >= 2) return;
1559 owner_->getMiniBuffer()->Set(CurrentState());
1561 // Did we hit an editable inset?
1562 if (inset_hit != 0) {
1563 // Inset like error, notes and figures
1564 selection_possible = false;
1565 #ifdef WITH_WARNINGS
1566 #warning fix this proper in 0.13
1568 // Following a ref shouldn't issue
1569 // a push on the undo-stack
1570 // anylonger, now that we have
1571 // keybindings for following
1572 // references and returning from
1573 // references. IMHO though, it
1574 // should be the inset's own business
1575 // to push or not push on the undo
1576 // stack. They don't *have* to
1577 // alter the document...
1579 // ...or maybe the SetCursorParUndo()
1580 // below isn't necessary at all anylonger?
1581 if (inset_hit->LyxCode() == Inset::REF_CODE) {
1582 text->SetCursorParUndo();
1585 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
1586 inset_hit->Edit(x, y);
1590 // check whether we want to open a float
1594 if (text->cursor.pos <
1595 text->cursor.par->Last()) {
1596 c = text->cursor.par->
1597 GetChar(text->cursor.pos);
1599 if (c == LyXParagraph::META_FOOTNOTE
1600 || c == LyXParagraph::META_MARGIN
1601 || c == LyXParagraph::META_FIG
1602 || c == LyXParagraph::META_TAB
1603 || c == LyXParagraph::META_WIDE_FIG
1604 || c == LyXParagraph::META_WIDE_TAB
1605 || c == LyXParagraph::META_ALGORITHM){
1607 } else if (text->cursor.pos - 1 >= 0) {
1608 c = text->cursor.par->
1609 GetChar(text->cursor.pos - 1);
1610 if (c == LyXParagraph::META_FOOTNOTE
1611 || c == LyXParagraph::META_MARGIN
1612 || c == LyXParagraph::META_FIG
1613 || c == LyXParagraph::META_TAB
1614 || c == LyXParagraph::META_WIDE_FIG
1615 || c == LyXParagraph::META_WIDE_TAB
1616 || c == LyXParagraph::META_ALGORITHM){
1617 // We are one step too far to the right
1624 selection_possible = false;
1629 // Do we want to close a float? (click on the float-label)
1630 if (text->cursor.row->par->footnoteflag ==
1631 LyXParagraph::OPEN_FOOTNOTE
1632 //&& text->cursor.pos == 0
1633 && text->cursor.row->previous &&
1634 text->cursor.row->previous->par->
1635 footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
1636 LyXFont font (LyXFont::ALL_SANE);
1637 font.setSize(LyXFont::SIZE_FOOTNOTE);
1639 int box_x = 20; // LYX_PAPER_MARGIN;
1640 box_x += font.textWidth(" wide-tab ", 10);
1642 int screen_first = screen->first;
1645 && y + screen_first > text->cursor.y -
1646 text->cursor.row->baseline
1647 && y + screen_first < text->cursor.y -
1648 text->cursor.row->baseline
1649 + font.maxAscent() * 1.2 + font.maxDescent() * 1.2) {
1651 selection_possible = false;
1656 // Maybe we want to edit a bibitem ale970302
1658 if (text->cursor.par->bibkey && x < 20 +
1659 bibitemMaxWidth(painter(),
1661 .TextClass(buffer_->
1662 params.textclass).defaultfont())) {
1663 text->cursor.par->bibkey->Edit(0, 0);
1666 if (text->cursor.par->bibkey && x < 20 +
1667 bibitemMaxWidth(textclasslist
1668 .TextClass(buffer_->
1669 params.textclass).defaultfont())) {
1670 text->cursor.par->bibkey->Edit(0, 0);
1677 int BufferView::WorkAreaButtonRelease(FL_OBJECT * ob, Window ,
1678 int /*w*/, int /*h*/,
1679 XEvent * ev, void * /*d*/)
1681 if (buffer_ == 0 || screen == 0) return 0;
1683 int const x = ev->xbutton.x - ob->x;
1684 int const y = ev->xbutton.y - ob->y;
1686 // If we hit an inset, we have the inset coordinates in these
1687 // and inset_hit points to the inset. If we do not hit an
1688 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
1691 Inset * inset_hit = checkInsetHit(inset_x, inset_y);
1693 if (the_locking_inset) {
1694 // We are in inset locking mode.
1696 /* LyX does a kind of work-area grabbing for insets.
1697 Only a ButtonPress Event outside the inset will
1698 force a InsetUnlock. */
1700 InsetButtonRelease(inset_x, inset_y,
1701 ev->xbutton.button);
1705 selection_possible = false;
1706 if (text->cursor.par->table) {
1708 NumberOfCell(text->cursor.par,
1710 if (text->cursor.par->table->IsContRow(cell) &&
1711 text->cursor.par->table->
1712 CellHasContRow(text->cursor.par->table->
1713 GetCellAbove(cell))<0) {
1718 if (ev->xbutton.button >= 2)
1721 // Make sure that the press was not far from the release
1722 if ((abs(last_click_x - x) >= 5) ||
1723 (abs(last_click_y - y) >= 5)) {
1727 owner_->getMiniBuffer()->Set(CurrentState());
1729 // Did we hit an editable inset?
1730 if (inset_hit != 0) {
1731 // Inset like error, notes and figures
1732 selection_possible = false;
1733 #ifdef WITH_WARNINGS
1734 #warning fix this proper in 0.13
1736 // Following a ref shouldn't issue
1737 // a push on the undo-stack
1738 // anylonger, now that we have
1739 // keybindings for following
1740 // references and returning from
1741 // references. IMHO though, it
1742 // should be the inset's own business
1743 // to push or not push on the undo
1744 // stack. They don't *have* to
1745 // alter the document...
1747 // ...or maybe the SetCursorParUndo()
1748 // below isn't necessary at all anylonger?
1749 if (inset_hit->LyxCode() == Inset::REF_CODE) {
1750 text->SetCursorParUndo();
1753 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
1754 inset_hit->Edit(inset_x, inset_y);
1758 // check whether we want to open a float
1762 if (text->cursor.pos <
1763 text->cursor.par->Last()) {
1764 c = text->cursor.par->
1765 GetChar(text->cursor.pos);
1767 if (c == LyXParagraph::META_FOOTNOTE
1768 || c == LyXParagraph::META_MARGIN
1769 || c == LyXParagraph::META_FIG
1770 || c == LyXParagraph::META_TAB
1771 || c == LyXParagraph::META_WIDE_FIG
1772 || c == LyXParagraph::META_WIDE_TAB
1773 || c == LyXParagraph::META_ALGORITHM){
1775 } else if (text->cursor.pos - 1 >= 0) {
1776 c = text->cursor.par->
1777 GetChar(text->cursor.pos - 1);
1778 if (c == LyXParagraph::META_FOOTNOTE
1779 || c == LyXParagraph::META_MARGIN
1780 || c == LyXParagraph::META_FIG
1781 || c == LyXParagraph::META_TAB
1782 || c == LyXParagraph::META_WIDE_FIG
1783 || c == LyXParagraph::META_WIDE_TAB
1784 || c == LyXParagraph::META_ALGORITHM){
1785 // We are one step too far to the right
1792 selection_possible = false;
1797 // Do we want to close a float? (click on the float-label)
1798 if (text->cursor.row->par->footnoteflag ==
1799 LyXParagraph::OPEN_FOOTNOTE
1800 //&& text->cursor.pos == 0
1801 && text->cursor.row->previous &&
1802 text->cursor.row->previous->par->
1803 footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
1804 LyXFont font (LyXFont::ALL_SANE);
1805 font.setSize(LyXFont::SIZE_FOOTNOTE);
1807 int box_x = 20; // LYX_PAPER_MARGIN;
1808 box_x += font.textWidth(" wide-tab ", 10);
1810 int screen_first = screen->first;
1813 && y + screen_first > text->cursor.y -
1814 text->cursor.row->baseline
1815 && y + screen_first < text->cursor.y -
1816 text->cursor.row->baseline
1817 + font.maxAscent() * 1.2 + font.maxDescent() * 1.2) {
1819 selection_possible = false;
1824 // Maybe we want to edit a bibitem ale970302
1825 if (text->cursor.par->bibkey && x < 20 +
1826 bibitemMaxWidth(textclasslist
1827 .TextClass(buffer_->
1828 params.textclass).defaultfont())) {
1829 text->cursor.par->bibkey->Edit(0, 0);
1837 * Returns an inset if inset was hit. 0 otherwise.
1838 * If hit, the coordinates are changed relative to the inset.
1839 * Otherwise coordinates are not changed, and false is returned.
1842 Inset * BufferView::checkInsetHit(int & x, int & y)
1847 int y_tmp = y + getScreen()->first;
1849 LyXCursor & cursor = text->cursor;
1850 LyXDirection direction = text->real_current_font.getFontDirection();
1852 if (cursor.pos < cursor.par->Last()
1853 && cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET
1854 && cursor.par->GetInset(cursor.pos)
1855 && cursor.par->GetInset(cursor.pos)->Editable()) {
1857 // Check whether the inset really was hit
1858 Inset * tmpinset = cursor.par->GetInset(cursor.pos);
1859 LyXFont font = text->GetFont(cursor.par, cursor.pos);
1861 if (direction == LYX_DIR_LEFT_TO_RIGHT) {
1863 end_x = cursor.x + tmpinset->width(painter(), font);
1865 start_x = cursor.x - tmpinset->width(painter(), font);
1869 if (x > start_x && x < end_x
1870 && y_tmp > cursor.y - tmpinset->ascent(painter(), font)
1871 && y_tmp < cursor.y + tmpinset->descent(painter(), font)) {
1873 // The origin of an inset is on the baseline
1874 y = y_tmp - (cursor.y);
1879 if (cursor.pos - 1 >= 0
1880 && cursor.par->GetChar(cursor.pos - 1) == LyXParagraph::META_INSET
1881 && cursor.par->GetInset(cursor.pos - 1)
1882 && cursor.par->GetInset(cursor.pos - 1)->Editable()) {
1884 Inset * tmpinset = cursor.par->GetInset(cursor.pos);
1885 LyXFont font = text->GetFont(cursor.par, cursor.pos);
1887 if (direction == LYX_DIR_LEFT_TO_RIGHT) {
1889 end_x = cursor.x + tmpinset->width(painter(), font);
1891 start_x = cursor.x - tmpinset->width(painter(), font);
1894 if (x > start_x && x < end_x
1895 && y_tmp > cursor.y - tmpinset->ascent(painter(), font)
1896 && y_tmp < cursor.y + tmpinset->descent(painter(), font)) {
1898 // The origin of an inset is on the baseline
1899 y = y_tmp - (cursor.y);
1902 text->CursorRight();
1909 Inset * BufferView::checkInsetHit(int & x, int & y)
1914 int y_tmp = y + getScreen()->first;
1916 LyXCursor & cursor = text->cursor;
1917 LyXDirection direction = text->real_current_font.getFontDirection();
1919 if (cursor.pos < cursor.par->Last()
1920 && cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET
1921 && cursor.par->GetInset(cursor.pos)
1922 && cursor.par->GetInset(cursor.pos)->Editable()) {
1924 // Check whether the inset really was hit
1925 Inset * tmpinset = cursor.par->GetInset(cursor.pos);
1926 LyXFont font = text->GetFont(cursor.par, cursor.pos);
1928 if (direction == LYX_DIR_LEFT_TO_RIGHT) {
1930 end_x = cursor.x + tmpinset->Width(font);
1932 start_x = cursor.x - tmpinset->Width(font);
1936 if (x > start_x && x < end_x
1937 && y_tmp > cursor.y - tmpinset->Ascent(font)
1938 && y_tmp < cursor.y + tmpinset->Descent(font)) {
1940 // The origin of an inset is on the baseline
1941 y = y_tmp - (cursor.y);
1946 if (cursor.pos - 1 >= 0
1947 && cursor.par->GetChar(cursor.pos - 1) == LyXParagraph::META_INSET
1948 && cursor.par->GetInset(cursor.pos - 1)
1949 && cursor.par->GetInset(cursor.pos - 1)->Editable()) {
1951 Inset * tmpinset = cursor.par->GetInset(cursor.pos);
1952 LyXFont font = text->GetFont(cursor.par, cursor.pos);
1954 if (direction == LYX_DIR_LEFT_TO_RIGHT) {
1956 end_x = cursor.x + tmpinset->Width(font);
1958 start_x = cursor.x - tmpinset->Width(font);
1961 if (x > start_x && x < end_x
1962 && y_tmp > cursor.y - tmpinset->Ascent(font)
1963 && y_tmp < cursor.y + tmpinset->Descent(font)) {
1965 // The origin of an inset is on the baseline
1966 y = y_tmp - (cursor.y);
1969 text->CursorRight();
1978 void BufferView::workAreaExpose()
1980 // this is a hack to ensure that we only call this through
1981 // BufferView::redraw().
1986 static int work_area_width = -1;
1987 static int work_area_height = -1;
1989 bool widthChange = workarea->workWidth() != work_area_width;
1990 bool heightChange = workarea->height() != work_area_height;
1992 // update from work area
1993 work_area_width = workarea->workWidth();
1994 work_area_height = workarea->height();
1997 // All buffers need a resize
1998 bufferlist.resize();
2000 // Remove all texts from the textcache
2001 // This is not _really_ what we want to do. What
2002 // we really want to do is to delete in textcache
2003 // that does not have a BufferView with matching
2004 // width, but as long as we have only one BufferView
2005 // deleting all gives the same result.
2006 if (lyxerr.debugging())
2007 textcache.show(lyxerr, "Expose delete all");
2009 } else if (heightChange) {
2010 // Rebuild image of current screen
2012 // fitCursor() ensures we don't jump back
2013 // to the start of the document on vertical
2017 // The main window size has changed, repaint most stuff
2019 // ...including the minibuffer
2020 owner_->getMiniBuffer()->Init();
2022 } else if (screen) screen->Redraw();
2024 // Grey box when we don't have a buffer
2025 workarea->greyOut();
2028 // always make sure that the scrollbar is sane.
2030 owner_->updateLayoutChoice();
2034 int BufferView::workAreaExpose()
2036 if (!work_area || !work_area->form->visible)
2039 // this is a hack to ensure that we only call this through
2040 // BufferView::redraw().
2045 static int work_area_width = work_area->w;
2046 static int work_area_height = work_area->h;
2048 bool widthChange = work_area->w != work_area_width;
2049 bool heightChange = work_area->h != work_area_height;
2051 // update from work area
2052 work_area_width = work_area->w;
2053 work_area_height = work_area->h;
2056 // All buffers need a resize
2057 bufferlist.resize();
2059 // Remove all texts from the textcache
2060 // This is not _really_ what we want to do. What
2061 // we really want to do is to delete in textcache
2062 // that does not have a BufferView with matching
2063 // width, but as long as we have only one BufferView
2064 // deleting all gives the same result.
2065 if (lyxerr.debugging())
2066 textcache.show(lyxerr, "Expose delete all");
2068 } else if (heightChange) {
2069 // Rebuild image of current screen
2071 // fitCursor() ensures we don't jump back
2072 // to the start of the document on vertical
2076 // The main window size has changed, repaint most stuff
2078 // ...including the minibuffer
2079 owner_->getMiniBuffer()->Init();
2081 } else if (screen) screen->Redraw();
2083 // Grey box when we don't have a buffer
2084 fl_winset(FL_ObjWin(work_area));
2085 fl_rectangle(1, work_area->x, work_area->y,
2086 work_area->w, work_area->h, FL_GRAY63);
2089 // always make sure that the scrollbar is sane.
2091 owner_->updateLayoutChoice();
2097 // Callback for cursor timer
2098 void BufferView::CursorToggleCB(FL_OBJECT * ob, long)
2100 BufferView * view = static_cast<BufferView*>(ob->u_vdata);
2102 // Quite a nice place for asyncron Inset updating, isn't it?
2103 // Actually no! This is run even if no buffer exist... so (Lgb)
2104 if (view && !view->buffer_) {
2105 goto set_timer_and_return;
2109 // On my quest to solve the gs render hangups I am now
2110 // disabling the SIGHUP completely, and will do a wait
2111 // now and then instead. If the guess that xforms somehow
2112 // destroys something is true, this is likely (hopefully)
2113 // to solve the problem...at least I hope so. Lgb
2115 // ...Ok this seems to work...at least it does not make things
2116 // worse so far. However I still see gs processes that hangs.
2117 // I would really like to know _why_ they are hanging. Anyway
2118 // the solution without the SIGCHLD handler seems to be easier
2121 // When attaching gdb to a a running gs that hangs it shows
2122 // that it is waiting for input(?) Is it possible for us to
2123 // provide that input somehow? Or figure what it is expecing
2126 // One solution is to, after some time, look if there are some
2127 // old gs processes still running and if there are: kill them
2130 // Another solution is to provide the user an option to rerender
2131 // a picture. This would, for the picture in question, check if
2132 // there is a gs running for it, if so kill it, and start a new
2133 // rendering process.
2135 // these comments posted to lyx@via
2138 int pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
2139 if (pid == -1) // error find out what is wrong
2140 ; // ignore it for now.
2142 sigchldhandler(pid, &status);
2144 if (InsetUpdateList)
2145 UpdateInsetUpdateList();
2147 if (view && !view->screen){
2148 goto set_timer_and_return;
2151 if (view->lyx_focus && view->work_area_focus) {
2152 if (!view->the_locking_inset) {
2153 view->screen->CursorToggle();
2155 view->the_locking_inset->
2156 ToggleInsetCursor();
2158 goto set_timer_and_return;
2160 // Make sure that the cursor is visible.
2161 if (!view->the_locking_inset) {
2162 view->screen->ShowCursor();
2164 if (!view->the_locking_inset->isCursorVisible())
2165 view->the_locking_inset->
2166 ToggleInsetCursor();
2168 // This is only run when work_area_focus or lyx_focus is false.
2171 XGetInputFocus(fl_display, &tmpwin, &tmp);
2172 // Commenting this out, we have not had problems with this
2173 // for a long time. We will probably work on this code later
2174 // and we can reenable this debug code then. Now it only
2175 // anoying when debugging. (Lgb)
2176 //if (lyxerr.debugging(Debug::INFO)) {
2177 // lyxerr << "tmpwin: " << tmpwin
2178 // << "\nwindow: " << view->owner_->getForm()->window
2179 // << "\nwork_area_focus: " << view->work_area_focus
2180 // << "\nlyx_focus : " << view->lyx_focus
2183 if (tmpwin != view->owner_->getForm()->window) {
2184 view->lyx_focus = false;
2187 view->lyx_focus = true;
2188 if (!view->work_area_focus)
2191 goto set_timer_and_return;
2195 set_timer_and_return:
2196 fl_set_timer(ob, 0.4);
2204 string fromClipboard(Window win, XEvent * event)
2207 if (event->xselection.type == XA_STRING
2208 && event->xselection.property) {
2212 unsigned char * uc = 0;
2214 if (XGetWindowProperty(
2215 event->xselection.display, // display
2217 event->xselection.property, // property
2221 XA_STRING, // req_type
2222 &tmpatom, // actual_type_return
2223 &tmpint, // actual_format_return
2234 if (XGetWindowProperty(
2235 event->xselection.display, // display
2237 event->xselection.property, // property
2239 ul2/4+1, // long_length
2241 XA_STRING, // req_type
2242 &tmpatom, // actual_type_return
2243 &tmpint, // actual_format_return
2244 &ul1, // nitems_return
2245 &ul2, // bytes_after_return
2246 &uc // prop_return */
2251 strret = reinterpret_cast<char*>(uc);
2252 free(uc); // yes free!
2260 void BufferView::WorkAreaSelectionNotify(Window win, XEvent * event)
2262 if (buffer_ == 0) return;
2264 screen->HideCursor();
2266 string clb = fromClipboard(win, event);
2269 text->InsertStringA(clb.c_str());
2271 text->InsertStringB(clb.c_str());
2279 int BufferView::WorkAreaSelectionNotify(FL_OBJECT *, Window win,
2280 int /*w*/, int /*h*/,
2281 XEvent * event, void */*d*/)
2283 if (buffer_ == 0) return 0;
2284 if (event->type != SelectionNotify)
2290 unsigned char * uc = 0;
2292 screen->HideCursor();
2294 if (event->xselection.type == XA_STRING
2295 && event->xselection.property) {
2297 if (XGetWindowProperty(
2298 fl_display /* display */,
2300 event->xselection.property /* property */,
2301 0 /* long_offset */,
2302 0 /* long_length */,
2304 XA_STRING /* req_type */,
2305 &tmpatom /* actual_type_return */,
2306 &tmpint /* actual_format_return */,
2307 &ul1 /* nitems_return */,
2308 &ul2 /* bytes_after_return */,
2309 &uc /* prop_return */
2320 if (XGetWindowProperty(
2321 fl_display /* display */,
2323 event->xselection.property /* property */,
2324 0 /* long_offset */,
2325 ul2/4+1 /* long_length */,
2327 XA_STRING /* req_type */,
2328 &tmpatom /* actual_type_return */,
2329 &tmpint /* actual_format_return */,
2330 &ul1 /* nitems_return */,
2331 &ul2 /* bytes_after_return */,
2332 &uc /* prop_return */
2340 text->InsertStringA(reinterpret_cast<char*>(uc));
2342 text->InsertStringB(reinterpret_cast<char*>(uc));
2356 void BufferView::cursorPrevious()
2358 if (!text->cursor.row->previous) return;
2360 long y = getScreen()->first;
2361 Row * cursorrow = text->cursor.row;
2362 text->SetCursorFromCoordinates(text->cursor.x_fix, y);
2364 // This is to allow jumping over large insets
2365 if ((cursorrow == text->cursor.row))
2368 if (text->cursor.row->height < workarea->height())
2369 getScreen()->Draw(text->cursor.y
2370 - text->cursor.row->baseline
2371 + text->cursor.row->height
2372 - workarea->height() + 1 );
2375 void BufferView::cursorPrevious()
2377 if (!text->cursor.row->previous) return;
2379 long y = getScreen()->first;
2380 Row * cursorrow = text->cursor.row;
2381 text->SetCursorFromCoordinates(text->cursor.x_fix, y);
2383 // This is to allow jumping over large insets
2384 if ((cursorrow == text->cursor.row))
2387 if (text->cursor.row->height < work_area->h)
2388 getScreen()->Draw(text->cursor.y
2389 - text->cursor.row->baseline
2390 + text->cursor.row->height
2391 - work_area->h +1 );
2397 void BufferView::cursorNext()
2399 if (!text->cursor.row->next) return;
2401 long y = getScreen()->first;
2402 text->GetRowNearY(y);
2403 Row * cursorrow = text->cursor.row;
2404 text->SetCursorFromCoordinates(text->cursor.x_fix, y
2405 + workarea->height());
2407 // This is to allow jumping over large insets
2408 if ((cursorrow == text->cursor.row))
2411 if (text->cursor.row->height < workarea->height())
2412 getScreen()->Draw(text->cursor.y
2413 - text->cursor.row->baseline);
2416 void BufferView::cursorNext()
2418 if (!text->cursor.row->next) return;
2420 long y = getScreen()->first;
2421 text->GetRowNearY(y);
2422 Row * cursorrow = text->cursor.row;
2423 text->SetCursorFromCoordinates(text->cursor.x_fix, y + work_area->h);
2425 // This is to allow jumping over large insets
2426 if ((cursorrow == text->cursor.row))
2429 if (text->cursor.row->height < work_area->h)
2430 getScreen()->Draw(text->cursor.y
2431 - text->cursor.row->baseline);
2436 bool BufferView::available() const
2438 if (buffer_ && text) return true;
2443 void BufferView::beforeChange()
2445 getScreen()->ToggleSelection();
2446 text->ClearSelection();
2451 void BufferView::savePosition()
2453 backstack.push(buffer()->fileName(),
2459 void BufferView::restorePosition()
2461 if (backstack.empty()) return;
2464 string fname = backstack.pop(&x, &y);
2467 Buffer * b = bufferlist.exists(fname) ?
2468 bufferlist.getBuffer(fname) :
2469 bufferlist.loadLyXFile(fname); // don't ask, just load it
2471 text->SetCursorFromCoordinates(x, y);
2476 void BufferView::update(signed char f)
2478 owner()->updateLayoutChoice();
2480 if (!text->selection && f > -3)
2481 text->sel_cursor = text->cursor;
2484 text->FullRebreak();
2488 if (f != 3 && f != -3) {
2493 if (f == 1 || f == -1) {
2494 if (buffer()->isLyxClean()) {
2495 buffer()->markDirty();
2496 owner()->getMiniBuffer()->setTimer(4);
2498 buffer()->markDirty();
2504 void BufferView::smallUpdate(signed char f)
2506 getScreen()->SmallUpdate();
2507 if (getScreen()->TopCursorVisible()
2508 != getScreen()->first) {
2516 if (!text->selection)
2517 text->sel_cursor = text->cursor;
2519 if (f == 1 || f == -1) {
2520 if (buffer()->isLyxClean()) {
2521 buffer()->markDirty();
2522 owner()->getMiniBuffer()->setTimer(4);
2524 buffer()->markDirty();
2530 void BufferView::SetState()
2532 if (!lyxrc->rtl_support)
2535 if (text->real_current_font.getFontDirection()
2536 == LYX_DIR_LEFT_TO_RIGHT) {
2537 if (!owner_->getIntl()->primarykeymap)
2538 owner_->getIntl()->KeyMapPrim();
2540 if (owner_->getIntl()->primarykeymap)
2541 owner_->getIntl()->KeyMapSec();
2546 void BufferView::insetSleep()
2548 if (the_locking_inset && !inset_slept) {
2549 the_locking_inset->GetCursorPos(slx, sly);
2550 the_locking_inset->InsetUnlock();
2556 void BufferView::insetWakeup()
2558 if (the_locking_inset && inset_slept) {
2559 the_locking_inset->Edit(slx, sly);
2560 inset_slept = false;
2565 void BufferView::insetUnlock()
2567 if (the_locking_inset) {
2568 if (!inset_slept) the_locking_inset->InsetUnlock();
2569 the_locking_inset = 0;
2571 inset_slept = false;
2576 bool BufferView::focus() const
2578 return workarea->hasFocus();
2582 void BufferView::focus(bool f)
2584 if (f) workarea->setFocus();
2588 bool BufferView::active() const
2590 return workarea->active();