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.
136 if (lyxerr.debugging())
137 textcache.show(lyxerr, "BufferView::buffer");
142 // Set current buffer
145 if (bufferlist.getState() == BufferList::CLOSING) return;
148 // screen is always deleted when the buffer is changed.
152 // If we are closing the buffer, use the first buffer as current
154 buffer_ = bufferlist.first();
158 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
159 buffer_->addUser(this);
160 owner_->getMenus()->showMenus();
161 // If we don't have a text object for this, we make one
163 resizeCurrentBuffer();
168 screen->first = screen->TopCursorVisible();
170 updateAllVisibleBufferRelatedPopups();
173 lyxerr[Debug::INFO] << " No Buffer!" << endl;
174 owner_->getMenus()->hideMenus();
179 fl_redraw_object(work_area);
182 // Also remove all remaining text's from the testcache.
183 // (there should not be any!) (if there is any it is a
185 if (lyxerr.debugging())
186 textcache.show(lyxerr, "buffer delete all");
189 // should update layoutchoice even if we don't have a buffer.
190 owner_->updateLayoutChoice();
191 owner_->getMiniBuffer()->Init();
192 owner_->updateWindowTitle();
196 void BufferView::updateScreen()
198 // Regenerate the screen.
201 screen = new LyXScreen(this,
203 workarea->getPixmap(),
204 workarea->workWidth(),
210 screen = new LyXScreen(FL_ObjWin(work_area),
221 void BufferView::resize(int xpos, int ypos, int width, int height)
223 workarea->resize(xpos, ypos, width, height);
230 void BufferView::resize()
232 // This will resize the buffer. (Asger)
234 resizeCurrentBuffer();
239 static bool lgb_hack = false;
242 void BufferView::redraw()
244 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
249 fl_redraw_object(work_area);
250 fl_redraw_object(scrollbar);
251 fl_redraw_object(button_down);
252 fl_redraw_object(button_up);
258 void BufferView::fitCursor()
260 if (screen) screen->FitCursor();
265 void BufferView::update()
267 if (screen) screen->Update();
271 void BufferView::updateScrollbar()
273 /* If the text is smaller than the working area, the scrollbar
274 * maximum must be the working area height. No scrolling will
279 workarea->setScrollbar(0, 1.0);
281 fl_set_slider_value(scrollbar, 0);
282 fl_set_slider_size(scrollbar, scrollbar->h);
287 static long max2 = 0;
288 static long height2 = 0;
296 cbsf = screen->first;
298 // check if anything has changed.
301 height2 == workarea->height() &&
302 current_scrollbar_value == cbsf)
305 height2 = workarea->height();
306 current_scrollbar_value = cbsf;
309 height2 == work_area->h &&
310 current_scrollbar_value == cbsf)
313 height2 = work_area->h;
314 current_scrollbar_value = cbsf;
317 if (cbth <= height2) { // text is smaller than screen
319 workarea->setScrollbar(0, 1.0); // right?
321 fl_set_slider_size(scrollbar, scrollbar->h);
327 long maximum_height = workarea->height() * 3 / 4 + cbth;
329 long maximum_height = work_area->h * 3 / 4 + cbth;
335 double hfloat = workarea->height();
337 double hfloat = work_area->h;
339 double maxfloat = maximum_height;
342 float slider_size = 0.0;
343 int slider_value = value;
345 workarea->setScrollbarBounds(0, text->height - workarea->height());
346 double lineh = text->DefaultHeight();
347 workarea->setScrollbarIncrements(lineh);
348 if (maxfloat > 0.0) {
349 if ((hfloat / maxfloat) * float(height2) < 3)
350 slider_size = 3.0/float(height2);
352 slider_size = hfloat / maxfloat;
354 slider_size = hfloat;
356 workarea->setScrollbar(slider_value, slider_size / workarea->height());
358 fl_set_slider_value(scrollbar, value);
359 fl_set_slider_bounds(scrollbar, 0,
360 maximum_height - work_area->h);
362 double lineh = text->DefaultHeight();
363 fl_set_slider_increment(scrollbar, work_area->h-lineh, lineh);
366 if ((hfloat / maxfloat) * float(height2) < 3)
367 fl_set_slider_size(scrollbar,
370 fl_set_slider_size(scrollbar,
373 fl_set_slider_size(scrollbar, hfloat);
374 fl_set_slider_precision(scrollbar, 0);
379 void BufferView::redoCurrentBuffer()
381 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
382 if (buffer_ && text) {
384 owner_->updateLayoutChoice();
389 int BufferView::resizeCurrentBuffer()
391 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
393 LyXParagraph * par = 0;
394 LyXParagraph * selstartpar = 0;
395 LyXParagraph * selendpar = 0;
404 owner_->getMiniBuffer()->Set(_("Formatting document..."));
407 par = text->cursor.par;
408 pos = text->cursor.pos;
409 selstartpar = text->sel_start_cursor.par;
410 selstartpos = text->sel_start_cursor.pos;
411 selendpar = text->sel_end_cursor.par;
412 selendpos = text->sel_end_cursor.pos;
413 selection = text->selection;
414 mark_set = text->mark_set;
417 text = new LyXText(this, workarea->workWidth(), buffer_);
419 text = new LyXText(work_area->w, buffer_);
422 // See if we have a text in TextCache that fits
423 // the new buffer_ with the correct width.
425 text = textcache.findFit(buffer_, workarea->workWidth());
427 text = textcache.findFit(buffer_, work_area->w);
430 if (lyxerr.debugging()) {
431 lyxerr << "Found a LyXText that fits:\n";
432 textcache.show(lyxerr, text);
434 if (lyxerr.debugging())
435 textcache.show(lyxerr, "resizeCurrentBuffer");
438 text = new LyXText(this, workarea->workWidth(), buffer_);
440 text = new LyXText(work_area->w, buffer_);
447 text->selection = true;
448 /* at this point just to avoid the Delete-Empty-Paragraph
449 * Mechanism when setting the cursor */
450 text->mark_set = mark_set;
452 text->SetCursor(selstartpar, selstartpos);
453 text->sel_cursor = text->cursor;
454 text->SetCursor(selendpar, selendpos);
455 text->SetSelection();
456 text->SetCursor(par, pos);
458 text->SetCursor(par, pos);
459 text->sel_cursor = text->cursor;
460 text->selection = false;
463 screen->first = screen->TopCursorVisible(); /* this will scroll the
464 * screen such that the
469 owner_->getMiniBuffer()->Init();
473 // Now if the title form still exist kill it
480 void BufferView::gotoError()
485 screen->HideCursor();
490 if (!text->GotoNextError()) {
492 || text->cursor.par != text->FirstParagraph()) {
494 text->cursor.par = text->FirstParagraph();
495 text->cursor.pos = 0;
496 if (!text->GotoNextError()) {
498 owner_->getMiniBuffer()
499 ->Set(_("No more errors"));
503 owner_->getMiniBuffer()->Set(_("No more errors"));
508 text->sel_cursor = text->cursor;
514 void C_BufferView_CursorToggleCB(FL_OBJECT * ob, long buf)
516 BufferView::CursorToggleCB(ob, buf);
521 // Just a bunch of C wrappers around static members of BufferView
522 void C_BufferView_UpCB(FL_OBJECT * ob, long buf)
524 BufferView::UpCB(ob, buf);
528 void C_BufferView_DownCB(FL_OBJECT * ob, long buf)
530 BufferView::DownCB(ob, buf);
534 void C_BufferView_ScrollCB(FL_OBJECT * ob, long buf)
536 BufferView::ScrollCB(ob, buf);
540 void C_BufferView_CursorToggleCB(FL_OBJECT * ob, long buf)
542 BufferView::CursorToggleCB(ob, buf);
546 int C_BufferView_work_area_handler(FL_OBJECT * ob, int event,
550 return BufferView::work_area_handler(ob, event,
557 void BufferView::create_view(int xpos, int ypos, int width, int height)
561 int const bw = abs(fl_get_border_width());
563 // a hack for the figinsets (Matthias)
564 // This one first, then it will probably be invisible. (Lgb)
565 ::figinset_canvas = figinset_canvas = obj =
566 fl_add_canvas(FL_NORMAL_CANVAS,
569 fl_set_object_boxtype(obj, FL_NO_BOX);
570 fl_set_object_resize(obj, FL_RESIZE_ALL);
571 fl_set_object_gravity(obj, NorthWestGravity, NorthWestGravity);
574 obj = fl_add_box(FL_BORDER_BOX, xpos, ypos,
577 fl_set_object_resize(obj, FL_RESIZE_ALL);
578 fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
581 work_area = obj = fl_add_free(FL_INPUT_FREE,
582 xpos + bw, ypos + bw,
583 width - 15 - 2 * bw /* scrollbarwidth */,
585 C_BufferView_work_area_handler);
586 obj->wantkey = FL_KEY_TAB;
587 obj->u_vdata = this; /* This is how we pass the BufferView
588 to the work_area_handler. */
589 fl_set_object_boxtype(obj, FL_DOWN_BOX);
590 fl_set_object_resize(obj, FL_RESIZE_ALL);
591 fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
597 // up - scrollbar button
598 fl_set_border_width(-1); // to get visual feedback
600 button_up = obj = fl_add_pixmapbutton(FL_TOUCH_BUTTON,
604 fl_set_object_boxtype(obj, FL_UP_BOX);
605 fl_set_object_color(obj, FL_MCOL, FL_BLUE);
606 fl_set_object_resize(obj, FL_RESIZE_ALL);
607 fl_set_object_gravity(obj, NorthEastGravity, NorthEastGravity);
608 fl_set_object_callback(obj, C_BufferView_UpCB, 0);
610 fl_set_pixmapbutton_data(obj, const_cast<char**>(up_xpm));
612 // Remove the blue feedback rectangle
613 fl_set_pixmapbutton_focus_outline(obj, 0);
615 // the scrollbar slider
616 fl_set_border_width(-bw);
617 scrollbar = obj = fl_add_slider(FL_VERT_SLIDER,
620 15, height - 30, "");
621 fl_set_object_color(obj, FL_COL1, FL_MCOL);
622 fl_set_object_boxtype(obj, FL_UP_BOX);
623 fl_set_object_resize(obj, FL_RESIZE_ALL);
624 fl_set_object_gravity(obj, NorthEastGravity, SouthEastGravity);
625 fl_set_object_callback(obj, C_BufferView_ScrollCB, 0);
628 // down - scrollbar button
629 fl_set_border_width(-1); // to get visible feedback
631 button_down = obj = fl_add_pixmapbutton(FL_TOUCH_BUTTON,
635 fl_set_object_boxtype(obj, FL_UP_BOX);
636 fl_set_object_color(obj, FL_MCOL, FL_BLUE);
637 fl_set_object_resize(obj, FL_RESIZE_ALL);
638 fl_set_object_gravity(obj, SouthEastGravity, SouthEastGravity);
639 fl_set_object_callback(obj, C_BufferView_DownCB, 0);
641 fl_set_pixmapbutton_data(obj, const_cast<char**>(down_xpm));
642 fl_set_border_width(-bw);
644 // Remove the blue feedback rectangle
645 fl_set_pixmapbutton_focus_outline(obj, 0);
652 timer_cursor = obj = fl_add_timer(FL_HIDDEN_TIMER,
653 0, 0, 0, 0, "Timer");
654 fl_set_object_callback(obj, C_BufferView_CursorToggleCB, 0);
659 // Callback for scrollbar up button
661 void BufferView::UpCB(long time, int button)
663 if (buffer_ == 0) return;
678 void BufferView::UpCB(FL_OBJECT * ob, long)
680 BufferView * view = static_cast<BufferView*>(ob->u_vdata);
682 if (view->buffer_ == 0) return;
684 static long time = 0;
685 XEvent const * ev2 = fl_last_event();
686 if (ev2->type == ButtonPress || ev2->type == ButtonRelease)
688 int button = fl_get_button_numb(ob);
691 view->ScrollUpOnePage(time++); break;
693 view->ScrollDownOnePage(time++); break;
695 view->ScrollUp(time++); break;
704 XSync(fl_get_display(), 0);
708 // Callback for scrollbar slider
710 void BufferView::ScrollCB(double value)
712 extern bool cursor_follows_scrollbar;
714 if (buffer_ == 0) return;
716 current_scrollbar_value = long(value);
717 if (current_scrollbar_value < 0)
718 current_scrollbar_value = 0;
723 screen->Draw(current_scrollbar_value);
725 if (cursor_follows_scrollbar) {
726 LyXText * vbt = text;
727 int height = vbt->DefaultHeight();
729 if (vbt->cursor.y < screen->first + height) {
730 vbt->SetCursorFromCoordinates(0,
733 } else if (vbt->cursor.y >
734 screen->first + workarea->height() - height) {
735 vbt->SetCursorFromCoordinates(0,
744 void BufferView::ScrollCB(FL_OBJECT * ob, long)
746 BufferView * view = static_cast<BufferView*>(ob->u_vdata);
747 extern bool cursor_follows_scrollbar;
749 if (view->buffer_ == 0) return;
751 view->current_scrollbar_value = long(fl_get_slider_value(ob));
752 if (view->current_scrollbar_value < 0)
753 view->current_scrollbar_value = 0;
758 view->screen->Draw(view->current_scrollbar_value);
760 if (cursor_follows_scrollbar) {
761 LyXText * vbt = view->text;
762 int height = vbt->DefaultHeight();
764 if (vbt->cursor.y < view->screen->first + height) {
765 vbt->SetCursorFromCoordinates(0,
766 view->screen->first +
769 else if (vbt->cursor.y >
770 view->screen->first + view->work_area->h - height) {
771 vbt->SetCursorFromCoordinates(0,
772 view->screen->first +
782 // Callback for scrollbar down button
784 void BufferView::DownCB(long time, int button)
786 if (buffer_ == 0) return;
801 void BufferView::DownCB(FL_OBJECT * ob, long)
803 BufferView * view = static_cast<BufferView*>(ob->u_vdata);
805 if (view->buffer_ == 0) return;
808 static long time = 0;
809 ev2 = fl_last_event();
810 if (ev2->type == ButtonPress || ev2->type == ButtonRelease)
812 int button = fl_get_button_numb(ob);
815 view->ScrollUpOnePage(time++); break;
817 view->ScrollDownOnePage(time++); break;
819 view->ScrollDown(time++); break;
826 int BufferView::ScrollUp(long time)
828 if (buffer_ == 0) return 0;
829 if (!screen) return 0;
831 double value = workarea->getScrollbarValue();
833 if (value == 0) return 0;
835 float add_value = (text->DefaultHeight()
836 + float(time) * float(time) * 0.125);
838 if (add_value > workarea->height())
839 add_value = float(workarea->height() -
840 text->DefaultHeight());
847 workarea->setScrollbarValue(value);
853 int BufferView::ScrollUp(long time)
855 if (buffer_ == 0) return 0;
856 if (!screen) return 0;
858 double value = fl_get_slider_value(scrollbar);
860 if (value == 0) return 0;
862 float add_value = (text->DefaultHeight()
863 + float(time) * float(time) * 0.125);
865 if (add_value > work_area->h)
866 add_value = float(work_area->h -
867 text->DefaultHeight());
874 fl_set_slider_value(scrollbar, value);
876 ScrollCB(scrollbar, 0);
883 int BufferView::ScrollDown(long time)
885 if (buffer_ == 0) return 0;
886 if (!screen) return 0;
888 double value= workarea->getScrollbarValue();
889 pair<double, double> p = workarea->getScrollbarBounds();
890 double max = p.second;
892 if (value == max) return 0;
894 float add_value = (text->DefaultHeight()
895 + float(time) * float(time) * 0.125);
897 if (add_value > workarea->height())
898 add_value = float(workarea->height() -
899 text->DefaultHeight());
906 workarea->setScrollbarValue(value);
912 int BufferView::ScrollDown(long time)
914 if (buffer_ == 0) return 0;
915 if (!screen) return 0;
917 double value= fl_get_slider_value(scrollbar);
919 fl_get_slider_bounds(scrollbar, &min, &max);
921 if (value == max) return 0;
923 float add_value = (text->DefaultHeight()
924 + float(time) * float(time) * 0.125);
926 if (add_value > work_area->h)
927 add_value = float(work_area->h -
928 text->DefaultHeight());
935 fl_set_slider_value(scrollbar, value);
937 ScrollCB(scrollbar, 0);
944 void BufferView::ScrollUpOnePage()
946 if (buffer_ == 0) return;
949 long y = screen->first;
953 Row * row = text->GetRowNearY(y);
955 y = y - workarea->height() + row->height;
957 workarea->setScrollbarValue(y);
962 void BufferView::ScrollUpOnePage(long /*time*/)
964 if (buffer_ == 0) return;
967 long y = screen->first;
971 Row * row = text->GetRowNearY(y);
973 y = y - work_area->h + row->height;
975 fl_set_slider_value(scrollbar, y);
977 ScrollCB(scrollbar, 0);
983 void BufferView::ScrollDownOnePage()
985 if (buffer_ == 0) return;
988 long y = screen->first;
990 if (y > text->height - workarea->height())
993 y += workarea->height();
994 text->GetRowNearY(y);
996 workarea->setScrollbarValue(y);
1001 void BufferView::ScrollDownOnePage(long /*time*/)
1003 if (buffer_ == 0) return;
1004 if (!screen) return;
1007 fl_get_slider_bounds(scrollbar, &min, &max);
1008 long y = screen->first;
1010 if (y > text->height - work_area->h)
1014 text->GetRowNearY(y);
1016 fl_set_slider_value(scrollbar, y);
1018 ScrollCB(scrollbar, 0);
1024 int BufferView::work_area_handler(FL_OBJECT * ob, int event,
1025 FL_Coord, FL_Coord ,
1026 int /*key*/, void * xev)
1028 static int x_old = -1;
1029 static int y_old = -1;
1030 static long scrollbar_value_old = -1;
1032 XEvent * ev = static_cast<XEvent*>(xev);
1033 BufferView * view = static_cast<BufferView*>(ob->u_vdata);
1035 // If we don't have a view yet; return
1036 if (!view || quitting) return 0;
1040 view->workAreaExpose();
1043 view->WorkAreaButtonPress(ob, 0, 0, 0, ev, 0);
1046 view->WorkAreaButtonRelease(ob, 0, 0, 0, ev, 0);
1049 if (ev->xmotion.x != x_old ||
1050 ev->xmotion.y != y_old ||
1051 view->current_scrollbar_value != scrollbar_value_old) {
1052 x_old = ev->xmotion.x;
1053 y_old = ev->xmotion.y;
1054 scrollbar_value_old = view->current_scrollbar_value;
1055 view->WorkAreaMotionNotify(ob, 0, 0, 0, ev, 0);
1058 // Done by the raw callback:
1059 // case FL_KEYBOARD:
1060 // WorkAreaKeyPress(ob, 0, 0, 0, ev, 0); break;
1062 if (!view->owner_->getMiniBuffer()->shows_no_match)
1063 view->owner_->getMiniBuffer()->Init();
1064 view->owner_->getMiniBuffer()->shows_no_match = false;
1065 view->work_area_focus = true;
1066 fl_set_timer(view->timer_cursor, 0.4);
1069 view->owner_->getMiniBuffer()->ExecCommand();
1070 view->work_area_focus = false;
1073 SetXtermCursor(view->owner_->getForm()->window);
1075 view->lyx_focus = true;
1076 fl_set_timer(view->timer_cursor, 0.4);
1079 if (!input_prohibited)
1080 XUndefineCursor(fl_display,
1081 view->owner_->getForm()->window);
1082 view->lyx_focus = false; // This is not an absolute truth
1083 // but if it is not true, it will be changed within a blink
1084 // of an eye. ... Not good enough... use regulare timeperiod
1085 //fl_set_timer(view->timer_cursor, 0.01); // 0.1 sec blink
1086 fl_set_timer(view->timer_cursor, 0.4); // 0.4 sec blink
1090 if (!view->the_locking_inset) {
1091 if (view->screen && ev->xbutton.button == 1) {
1092 view->screen->HideCursor();
1093 view->screen->ToggleSelection();
1094 view->text->SelectWord();
1095 view->screen->ToggleSelection(false);
1096 /* This will fit the cursor on the screen
1104 if (view->buffer_ && view->screen && ev->xbutton.button == 1) {
1105 view->screen->HideCursor();
1106 view->screen->ToggleSelection();
1107 view->text->CursorHome();
1108 view->text->sel_cursor = view->text->cursor;
1109 view->text->CursorEnd();
1110 view->text->SetSelection();
1111 view->screen->ToggleSelection(false);
1112 /* This will fit the cursor on the screen
1118 view->WorkAreaSelectionNotify(ob,
1119 view->owner_->getForm()->window,
1129 void BufferView::WorkAreaMotionNotify(int x, int y, unsigned int state)
1131 if (buffer_ == 0 || !screen) return;
1133 // Check for inset locking
1134 if (the_locking_inset) {
1135 LyXCursor cursor = text->cursor;
1137 InsetMotionNotify(x - cursor.x,
1143 // Only use motion with button 1
1144 if (!state & Button1MotionMask)
1147 /* The selection possible is needed, that only motion events are
1148 * used, where the bottom press event was on the drawing area too */
1149 if (selection_possible) {
1150 screen->HideCursor();
1152 text->SetCursorFromCoordinates(x, y + screen->first);
1154 if (!text->selection)
1155 update(-3); // Maybe an empty line was deleted
1157 text->SetSelection();
1158 screen->ToggleToggle();
1159 if (screen->FitCursor())
1161 screen->ShowCursor();
1166 int BufferView::WorkAreaMotionNotify(FL_OBJECT * ob, Window,
1167 int /*w*/, int /*h*/,
1168 XEvent * ev, void * /*d*/)
1170 if (buffer_ == 0) return 0;
1171 if (!screen) return 0;
1173 // Check for inset locking
1174 if (the_locking_inset) {
1175 LyXCursor cursor = text->cursor;
1177 InsetMotionNotify(ev->xbutton.x - ob->x - cursor.x,
1178 ev->xbutton.y - ob->y -
1184 // Only use motion with button 1
1185 if (!ev->xmotion.state & Button1MotionMask)
1188 /* The selection possible is needed, that only motion events are
1189 * used, where the bottom press event was on the drawing area too */
1190 if (selection_possible) {
1191 screen->HideCursor();
1193 text->SetCursorFromCoordinates(ev->xbutton.x - ob->x,
1194 ev->xbutton.y - ob->y +
1197 if (!text->selection)
1198 update(-3); // Maybe an empty line was deleted
1200 text->SetSelection();
1201 screen->ToggleToggle();
1202 if (screen->FitCursor())
1204 screen->ShowCursor();
1211 extern int bibitemMaxWidth(Painter &, LyXFont const &);
1213 extern int bibitemMaxWidth(LyXFont const &);
1216 // Single-click on work area
1218 void BufferView::WorkAreaButtonPress(int xpos, int ypos, unsigned int button)
1223 if (buffer_ == 0 || !screen) return;
1225 Inset * inset_hit = checkInsetHit(xpos, ypos);
1227 // ok ok, this is a hack.
1228 if (button == 4 || button == 5) {
1231 ScrollUp(100); // This number is only temporary
1239 if (the_locking_inset) {
1240 // We are in inset locking mode
1242 /* Check whether the inset was hit. If not reset mode,
1243 otherwise give the event to the inset */
1246 InsetButtonPress(xpos, ypos,
1250 unlockInset(the_locking_inset);
1254 selection_possible = true;
1255 screen->HideCursor();
1257 // Right button mouse click on a table
1259 (text->cursor.par->table ||
1260 text->MouseHitInTable(xpos, ypos + screen->first))) {
1261 // Set the cursor to the press-position
1262 text->SetCursorFromCoordinates(xpos, ypos + screen->first);
1265 // Only show the table popup if the hit is in
1267 if (!text->HitInTable(text->cursor.row, xpos))
1270 // Hit above or below the table?
1272 if (!text->selection) {
1273 screen->ToggleSelection();
1274 text->ClearSelection();
1275 text->FullRebreak();
1279 // Popup table popup when on a table.
1280 // This is obviously temporary, since we
1281 // should be able to popup various
1282 // context-sensitive-menus with the
1283 // the right mouse. So this should be done more
1284 // general in the future. Matthias.
1285 selection_possible = false;
1286 owner_->getLyXFunc()
1287 ->Dispatch(LFUN_LAYOUT_TABLE,
1293 int screen_first = screen->first;
1295 // Middle button press pastes if we have a selection
1296 bool paste_internally = false;
1298 && text->selection) {
1299 owner_->getLyXFunc()->Dispatch(LFUN_COPY);
1300 paste_internally = true;
1303 // Clear the selection
1304 screen->ToggleSelection();
1305 text->ClearSelection();
1306 text->FullRebreak();
1310 // Single left click in math inset?
1311 if (inset_hit != 0 && inset_hit->Editable() == 2) {
1312 // Highly editable inset, like math
1313 selection_possible = false;
1314 owner_->updateLayoutChoice();
1315 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
1316 inset_hit->Edit(xpos, ypos);
1320 // Right click on a footnote flag opens float menu
1322 selection_possible = false;
1326 text->SetCursorFromCoordinates(xpos, ypos + screen_first);
1328 text->sel_cursor = text->cursor;
1329 text->cursor.x_fix = text->cursor.x;
1331 owner_->updateLayoutChoice();
1332 if (screen->FitCursor()){
1334 selection_possible = false;
1337 // Insert primary selection with middle mouse
1338 // if there is a local selection in the current buffer,
1341 if (paste_internally)
1342 owner_->getLyXFunc()->Dispatch(LFUN_PASTE);
1344 owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION,
1346 selection_possible = false;
1351 int BufferView::WorkAreaButtonPress(FL_OBJECT * ob, Window,
1352 int /*w*/, int /*h*/,
1353 XEvent * ev, void */*d*/)
1358 if (buffer_ == 0) return 0;
1359 if (!screen) return 0;
1361 int const x = ev->xbutton.x - ob->x;
1362 int const y = ev->xbutton.y - ob->y;
1363 // If we hit an inset, we have the inset coordinates in these
1364 // and inset_hit points to the inset. If we do not hit an
1365 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
1368 Inset * inset_hit = checkInsetHit(inset_x, inset_y);
1370 // ok ok, this is a hack.
1371 int button = ev->xbutton.button;
1372 if (button == 4 || button == 5) goto wheel;
1375 if (the_locking_inset) {
1376 // We are in inset locking mode
1378 /* Check whether the inset was hit. If not reset mode,
1379 otherwise give the event to the inset */
1380 if (inset_hit != 0) {
1382 InsetButtonPress(inset_x, inset_y,
1386 unlockInset(the_locking_inset);
1390 selection_possible = true;
1391 screen->HideCursor();
1393 // Right button mouse click on a table
1395 (text->cursor.par->table ||
1396 text->MouseHitInTable(x, y + screen->first))) {
1397 // Set the cursor to the press-position
1398 text->SetCursorFromCoordinates(x, y + screen->first);
1401 // Only show the table popup if the hit is in
1403 if (!text->HitInTable(text->cursor.row, x))
1406 // Hit above or below the table?
1408 if (!text->selection) {
1409 screen->ToggleSelection();
1410 text->ClearSelection();
1411 text->FullRebreak();
1415 // Popup table popup when on a table.
1416 // This is obviously temporary, since we
1417 // should be able to popup various
1418 // context-sensitive-menus with the
1419 // the right mouse. So this should be done more
1420 // general in the future. Matthias.
1421 selection_possible = false;
1422 owner_->getLyXFunc()
1423 ->Dispatch(LFUN_LAYOUT_TABLE,
1429 int screen_first = screen->first;
1431 // Middle button press pastes if we have a selection
1432 bool paste_internally = false;
1433 if (button == 2 // && !buffer_->the_locking_inset
1434 && text->selection) {
1435 owner_->getLyXFunc()->Dispatch(LFUN_COPY);
1436 paste_internally = true;
1439 // Clear the selection
1440 screen->ToggleSelection();
1441 text->ClearSelection();
1442 text->FullRebreak();
1446 // Single left click in math inset?
1447 if (inset_hit != 0 && inset_hit->Editable() == 2) {
1448 // Highly editable inset, like math
1449 selection_possible = false;
1450 owner_->updateLayoutChoice();
1451 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
1452 inset_hit->Edit(inset_x, inset_y);
1456 // Right click on a footnote flag opens float menu
1458 selection_possible = false;
1462 text->SetCursorFromCoordinates(x, y + screen_first);
1464 text->sel_cursor = text->cursor;
1465 text->cursor.x_fix = text->cursor.x;
1467 owner_->updateLayoutChoice();
1468 if (screen->FitCursor()){
1470 selection_possible = false;
1473 // Insert primary selection with middle mouse
1474 // if there is a local selection in the current buffer,
1476 if (button == 2) { // && !buffer_->the_locking_inset){
1477 if (paste_internally)
1478 owner_->getLyXFunc()->Dispatch(LFUN_PASTE);
1480 owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION,
1482 selection_possible = false;
1489 // I am not quite sure if this is the correct place to put
1490 // this, but it will not cause any harm.
1491 // Patch from Mark Huang (markman@mit.edu) to make LyX
1492 // recognise button 4 and 5. This enables LyX use use
1493 // the scrollwhell on certain mice for something useful. (Lgb)
1494 // Added wheel acceleration detection code. (Rvdk)
1495 static Time lastTime = 0;
1496 int diff = ev->xbutton.time - lastTime;
1497 int scroll = int(1.0 + (4.0 / (abs(diff) + 1.0)) * 200.0);
1506 lastTime = ev->xbutton.time;
1519 void BufferView::WorkAreaButtonRelease(int x, int y, unsigned int button)
1521 if (buffer_ == 0 || screen == 0) return;
1523 // If we hit an inset, we have the inset coordinates in these
1524 // and inset_hit points to the inset. If we do not hit an
1525 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
1526 Inset * inset_hit = checkInsetHit(x, y);
1528 if (the_locking_inset) {
1529 // We are in inset locking mode.
1531 /* LyX does a kind of work-area grabbing for insets.
1532 Only a ButtonPress Event outside the inset will
1533 force a InsetUnlock. */
1535 InsetButtonRelease(x, x, button);
1539 selection_possible = false;
1540 if (text->cursor.par->table) {
1542 NumberOfCell(text->cursor.par,
1544 if (text->cursor.par->table->IsContRow(cell) &&
1545 text->cursor.par->table->
1546 CellHasContRow(text->cursor.par->table->
1547 GetCellAbove(cell))<0) {
1552 if (button >= 2) return;
1555 owner_->getMiniBuffer()->Set(CurrentState());
1557 // Did we hit an editable inset?
1558 if (inset_hit != 0) {
1559 // Inset like error, notes and figures
1560 selection_possible = false;
1561 #ifdef WITH_WARNINGS
1562 #warning fix this proper in 0.13
1564 // Following a ref shouldn't issue
1565 // a push on the undo-stack
1566 // anylonger, now that we have
1567 // keybindings for following
1568 // references and returning from
1569 // references. IMHO though, it
1570 // should be the inset's own business
1571 // to push or not push on the undo
1572 // stack. They don't *have* to
1573 // alter the document...
1575 // ...or maybe the SetCursorParUndo()
1576 // below isn't necessary at all anylonger?
1577 if (inset_hit->LyxCode() == Inset::REF_CODE) {
1578 text->SetCursorParUndo();
1581 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
1582 inset_hit->Edit(x, y);
1586 // check whether we want to open a float
1590 if (text->cursor.pos <
1591 text->cursor.par->Last()) {
1592 c = text->cursor.par->
1593 GetChar(text->cursor.pos);
1595 if (c == LyXParagraph::META_FOOTNOTE
1596 || c == LyXParagraph::META_MARGIN
1597 || c == LyXParagraph::META_FIG
1598 || c == LyXParagraph::META_TAB
1599 || c == LyXParagraph::META_WIDE_FIG
1600 || c == LyXParagraph::META_WIDE_TAB
1601 || c == LyXParagraph::META_ALGORITHM){
1603 } else if (text->cursor.pos - 1 >= 0) {
1604 c = text->cursor.par->
1605 GetChar(text->cursor.pos - 1);
1606 if (c == LyXParagraph::META_FOOTNOTE
1607 || c == LyXParagraph::META_MARGIN
1608 || c == LyXParagraph::META_FIG
1609 || c == LyXParagraph::META_TAB
1610 || c == LyXParagraph::META_WIDE_FIG
1611 || c == LyXParagraph::META_WIDE_TAB
1612 || c == LyXParagraph::META_ALGORITHM){
1613 // We are one step too far to the right
1620 selection_possible = false;
1625 // Do we want to close a float? (click on the float-label)
1626 if (text->cursor.row->par->footnoteflag ==
1627 LyXParagraph::OPEN_FOOTNOTE
1628 //&& text->cursor.pos == 0
1629 && text->cursor.row->previous &&
1630 text->cursor.row->previous->par->
1631 footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
1632 LyXFont font (LyXFont::ALL_SANE);
1633 font.setSize(LyXFont::SIZE_FOOTNOTE);
1635 int box_x = 20; // LYX_PAPER_MARGIN;
1636 box_x += font.textWidth(" wide-tab ", 10);
1638 int screen_first = screen->first;
1641 && y + screen_first > text->cursor.y -
1642 text->cursor.row->baseline
1643 && y + screen_first < text->cursor.y -
1644 text->cursor.row->baseline
1645 + font.maxAscent() * 1.2 + font.maxDescent() * 1.2) {
1647 selection_possible = false;
1652 // Maybe we want to edit a bibitem ale970302
1654 if (text->cursor.par->bibkey && x < 20 +
1655 bibitemMaxWidth(painter(),
1657 .TextClass(buffer_->
1658 params.textclass).defaultfont())) {
1659 text->cursor.par->bibkey->Edit(0, 0);
1662 if (text->cursor.par->bibkey && x < 20 +
1663 bibitemMaxWidth(textclasslist
1664 .TextClass(buffer_->
1665 params.textclass).defaultfont())) {
1666 text->cursor.par->bibkey->Edit(0, 0);
1673 int BufferView::WorkAreaButtonRelease(FL_OBJECT * ob, Window ,
1674 int /*w*/, int /*h*/,
1675 XEvent * ev, void * /*d*/)
1677 if (buffer_ == 0 || screen == 0) return 0;
1679 int const x = ev->xbutton.x - ob->x;
1680 int const y = ev->xbutton.y - ob->y;
1682 // If we hit an inset, we have the inset coordinates in these
1683 // and inset_hit points to the inset. If we do not hit an
1684 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
1687 Inset * inset_hit = checkInsetHit(inset_x, inset_y);
1689 if (the_locking_inset) {
1690 // We are in inset locking mode.
1692 /* LyX does a kind of work-area grabbing for insets.
1693 Only a ButtonPress Event outside the inset will
1694 force a InsetUnlock. */
1696 InsetButtonRelease(inset_x, inset_y,
1697 ev->xbutton.button);
1701 selection_possible = false;
1702 if (text->cursor.par->table) {
1704 NumberOfCell(text->cursor.par,
1706 if (text->cursor.par->table->IsContRow(cell) &&
1707 text->cursor.par->table->
1708 CellHasContRow(text->cursor.par->table->
1709 GetCellAbove(cell))<0) {
1714 if (ev->xbutton.button >= 2)
1717 // Make sure that the press was not far from the release
1718 if ((abs(last_click_x - x) >= 5) ||
1719 (abs(last_click_y - y) >= 5)) {
1723 owner_->getMiniBuffer()->Set(CurrentState());
1725 // Did we hit an editable inset?
1726 if (inset_hit != 0) {
1727 // Inset like error, notes and figures
1728 selection_possible = false;
1729 #ifdef WITH_WARNINGS
1730 #warning fix this proper in 0.13
1732 // Following a ref shouldn't issue
1733 // a push on the undo-stack
1734 // anylonger, now that we have
1735 // keybindings for following
1736 // references and returning from
1737 // references. IMHO though, it
1738 // should be the inset's own business
1739 // to push or not push on the undo
1740 // stack. They don't *have* to
1741 // alter the document...
1743 // ...or maybe the SetCursorParUndo()
1744 // below isn't necessary at all anylonger?
1745 if (inset_hit->LyxCode() == Inset::REF_CODE) {
1746 text->SetCursorParUndo();
1749 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
1750 inset_hit->Edit(inset_x, inset_y);
1754 // check whether we want to open a float
1758 if (text->cursor.pos <
1759 text->cursor.par->Last()) {
1760 c = text->cursor.par->
1761 GetChar(text->cursor.pos);
1763 if (c == LyXParagraph::META_FOOTNOTE
1764 || c == LyXParagraph::META_MARGIN
1765 || c == LyXParagraph::META_FIG
1766 || c == LyXParagraph::META_TAB
1767 || c == LyXParagraph::META_WIDE_FIG
1768 || c == LyXParagraph::META_WIDE_TAB
1769 || c == LyXParagraph::META_ALGORITHM){
1771 } else if (text->cursor.pos - 1 >= 0) {
1772 c = text->cursor.par->
1773 GetChar(text->cursor.pos - 1);
1774 if (c == LyXParagraph::META_FOOTNOTE
1775 || c == LyXParagraph::META_MARGIN
1776 || c == LyXParagraph::META_FIG
1777 || c == LyXParagraph::META_TAB
1778 || c == LyXParagraph::META_WIDE_FIG
1779 || c == LyXParagraph::META_WIDE_TAB
1780 || c == LyXParagraph::META_ALGORITHM){
1781 // We are one step too far to the right
1788 selection_possible = false;
1793 // Do we want to close a float? (click on the float-label)
1794 if (text->cursor.row->par->footnoteflag ==
1795 LyXParagraph::OPEN_FOOTNOTE
1796 //&& text->cursor.pos == 0
1797 && text->cursor.row->previous &&
1798 text->cursor.row->previous->par->
1799 footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
1800 LyXFont font (LyXFont::ALL_SANE);
1801 font.setSize(LyXFont::SIZE_FOOTNOTE);
1803 int box_x = 20; // LYX_PAPER_MARGIN;
1804 box_x += font.textWidth(" wide-tab ", 10);
1806 int screen_first = screen->first;
1809 && y + screen_first > text->cursor.y -
1810 text->cursor.row->baseline
1811 && y + screen_first < text->cursor.y -
1812 text->cursor.row->baseline
1813 + font.maxAscent() * 1.2 + font.maxDescent() * 1.2) {
1815 selection_possible = false;
1820 // Maybe we want to edit a bibitem ale970302
1821 if (text->cursor.par->bibkey && x < 20 +
1822 bibitemMaxWidth(textclasslist
1823 .TextClass(buffer_->
1824 params.textclass).defaultfont())) {
1825 text->cursor.par->bibkey->Edit(0, 0);
1833 * Returns an inset if inset was hit. 0 otherwise.
1834 * If hit, the coordinates are changed relative to the inset.
1835 * Otherwise coordinates are not changed, and false is returned.
1838 Inset * BufferView::checkInsetHit(int & x, int & y)
1843 int y_tmp = y + getScreen()->first;
1845 LyXCursor & cursor = text->cursor;
1846 LyXDirection direction = text->real_current_font.getFontDirection();
1848 if (cursor.pos < cursor.par->Last()
1849 && cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET
1850 && cursor.par->GetInset(cursor.pos)
1851 && cursor.par->GetInset(cursor.pos)->Editable()) {
1853 // Check whether the inset really was hit
1854 Inset * tmpinset = cursor.par->GetInset(cursor.pos);
1855 LyXFont font = text->GetFont(cursor.par, cursor.pos);
1857 if (direction == LYX_DIR_LEFT_TO_RIGHT) {
1859 end_x = cursor.x + tmpinset->width(painter(), font);
1861 start_x = cursor.x - tmpinset->width(painter(), font);
1865 if (x > start_x && x < end_x
1866 && y_tmp > cursor.y - tmpinset->ascent(painter(), font)
1867 && y_tmp < cursor.y + tmpinset->descent(painter(), font)) {
1869 // The origin of an inset is on the baseline
1870 y = y_tmp - (cursor.y);
1875 if (cursor.pos - 1 >= 0
1876 && cursor.par->GetChar(cursor.pos - 1) == LyXParagraph::META_INSET
1877 && cursor.par->GetInset(cursor.pos - 1)
1878 && cursor.par->GetInset(cursor.pos - 1)->Editable()) {
1880 Inset * tmpinset = cursor.par->GetInset(cursor.pos);
1881 LyXFont font = text->GetFont(cursor.par, cursor.pos);
1883 if (direction == LYX_DIR_LEFT_TO_RIGHT) {
1885 end_x = cursor.x + tmpinset->width(painter(), font);
1887 start_x = cursor.x - tmpinset->width(painter(), font);
1890 if (x > start_x && x < end_x
1891 && y_tmp > cursor.y - tmpinset->ascent(painter(), font)
1892 && y_tmp < cursor.y + tmpinset->descent(painter(), font)) {
1894 // The origin of an inset is on the baseline
1895 y = y_tmp - (cursor.y);
1898 text->CursorRight();
1905 Inset * BufferView::checkInsetHit(int & x, int & y)
1910 int y_tmp = y + getScreen()->first;
1912 LyXCursor & cursor = text->cursor;
1913 LyXDirection direction = text->real_current_font.getFontDirection();
1915 if (cursor.pos < cursor.par->Last()
1916 && cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET
1917 && cursor.par->GetInset(cursor.pos)
1918 && cursor.par->GetInset(cursor.pos)->Editable()) {
1920 // Check whether the inset really was hit
1921 Inset * tmpinset = cursor.par->GetInset(cursor.pos);
1922 LyXFont font = text->GetFont(cursor.par, cursor.pos);
1924 if (direction == LYX_DIR_LEFT_TO_RIGHT) {
1926 end_x = cursor.x + tmpinset->Width(font);
1928 start_x = cursor.x - tmpinset->Width(font);
1932 if (x > start_x && x < end_x
1933 && y_tmp > cursor.y - tmpinset->Ascent(font)
1934 && y_tmp < cursor.y + tmpinset->Descent(font)) {
1936 // The origin of an inset is on the baseline
1937 y = y_tmp - (cursor.y);
1942 if (cursor.pos - 1 >= 0
1943 && cursor.par->GetChar(cursor.pos - 1) == LyXParagraph::META_INSET
1944 && cursor.par->GetInset(cursor.pos - 1)
1945 && cursor.par->GetInset(cursor.pos - 1)->Editable()) {
1947 Inset * tmpinset = cursor.par->GetInset(cursor.pos);
1948 LyXFont font = text->GetFont(cursor.par, cursor.pos);
1950 if (direction == LYX_DIR_LEFT_TO_RIGHT) {
1952 end_x = cursor.x + tmpinset->Width(font);
1954 start_x = cursor.x - tmpinset->Width(font);
1957 if (x > start_x && x < end_x
1958 && y_tmp > cursor.y - tmpinset->Ascent(font)
1959 && y_tmp < cursor.y + tmpinset->Descent(font)) {
1961 // The origin of an inset is on the baseline
1962 y = y_tmp - (cursor.y);
1965 text->CursorRight();
1974 void BufferView::workAreaExpose()
1976 // this is a hack to ensure that we only call this through
1977 // BufferView::redraw().
1982 static int work_area_width = -1;
1983 static int work_area_height = -1;
1985 bool widthChange = workarea->workWidth() != work_area_width;
1986 bool heightChange = workarea->height() != work_area_height;
1988 // update from work area
1989 work_area_width = workarea->workWidth();
1990 work_area_height = workarea->height();
1993 // All buffers need a resize
1994 bufferlist.resize();
1996 // Remove all texts from the textcache
1997 // This is not _really_ what we want to do. What
1998 // we really want to do is to delete in textcache
1999 // that does not have a BufferView with matching
2000 // width, but as long as we have only one BufferView
2001 // deleting all gives the same result.
2002 if (lyxerr.debugging())
2003 textcache.show(lyxerr, "Expose delete all");
2005 } else if (heightChange) {
2006 // Rebuild image of current screen
2008 // fitCursor() ensures we don't jump back
2009 // to the start of the document on vertical
2013 // The main window size has changed, repaint most stuff
2015 // ...including the minibuffer
2016 owner_->getMiniBuffer()->Init();
2018 } else if (screen) screen->Redraw();
2020 // Grey box when we don't have a buffer
2021 workarea->greyOut();
2024 // always make sure that the scrollbar is sane.
2026 owner_->updateLayoutChoice();
2030 int BufferView::workAreaExpose()
2032 if (!work_area || !work_area->form->visible)
2035 // this is a hack to ensure that we only call this through
2036 // BufferView::redraw().
2041 static int work_area_width = work_area->w;
2042 static int work_area_height = work_area->h;
2044 bool widthChange = work_area->w != work_area_width;
2045 bool heightChange = work_area->h != work_area_height;
2047 // update from work area
2048 work_area_width = work_area->w;
2049 work_area_height = work_area->h;
2052 // All buffers need a resize
2053 bufferlist.resize();
2055 // Remove all texts from the textcache
2056 // This is not _really_ what we want to do. What
2057 // we really want to do is to delete in textcache
2058 // that does not have a BufferView with matching
2059 // width, but as long as we have only one BufferView
2060 // deleting all gives the same result.
2061 if (lyxerr.debugging())
2062 textcache.show(lyxerr, "Expose delete all");
2064 } else if (heightChange) {
2065 // Rebuild image of current screen
2067 // fitCursor() ensures we don't jump back
2068 // to the start of the document on vertical
2072 // The main window size has changed, repaint most stuff
2074 // ...including the minibuffer
2075 owner_->getMiniBuffer()->Init();
2077 } else if (screen) screen->Redraw();
2079 // Grey box when we don't have a buffer
2080 fl_winset(FL_ObjWin(work_area));
2081 fl_rectangle(1, work_area->x, work_area->y,
2082 work_area->w, work_area->h, FL_GRAY63);
2085 // always make sure that the scrollbar is sane.
2087 owner_->updateLayoutChoice();
2093 // Callback for cursor timer
2094 void BufferView::CursorToggleCB(FL_OBJECT * ob, long)
2096 BufferView * view = static_cast<BufferView*>(ob->u_vdata);
2098 // Quite a nice place for asyncron Inset updating, isn't it?
2099 // Actually no! This is run even if no buffer exist... so (Lgb)
2100 if (view && !view->buffer_) {
2101 goto set_timer_and_return;
2105 // On my quest to solve the gs render hangups I am now
2106 // disabling the SIGHUP completely, and will do a wait
2107 // now and then instead. If the guess that xforms somehow
2108 // destroys something is true, this is likely (hopefully)
2109 // to solve the problem...at least I hope so. Lgb
2111 // ...Ok this seems to work...at least it does not make things
2112 // worse so far. However I still see gs processes that hangs.
2113 // I would really like to know _why_ they are hanging. Anyway
2114 // the solution without the SIGCHLD handler seems to be easier
2117 // When attaching gdb to a a running gs that hangs it shows
2118 // that it is waiting for input(?) Is it possible for us to
2119 // provide that input somehow? Or figure what it is expecing
2122 // One solution is to, after some time, look if there are some
2123 // old gs processes still running and if there are: kill them
2126 // Another solution is to provide the user an option to rerender
2127 // a picture. This would, for the picture in question, check if
2128 // there is a gs running for it, if so kill it, and start a new
2129 // rendering process.
2131 // these comments posted to lyx@via
2134 int pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
2135 if (pid == -1) // error find out what is wrong
2136 ; // ignore it for now.
2138 sigchldhandler(pid, &status);
2140 if (InsetUpdateList)
2141 UpdateInsetUpdateList();
2143 if (view && !view->screen){
2144 goto set_timer_and_return;
2147 if (view->lyx_focus && view->work_area_focus) {
2148 if (!view->the_locking_inset) {
2149 view->screen->CursorToggle();
2151 view->the_locking_inset->
2152 ToggleInsetCursor();
2154 goto set_timer_and_return;
2156 // Make sure that the cursor is visible.
2157 if (!view->the_locking_inset) {
2158 view->screen->ShowCursor();
2160 if (!view->the_locking_inset->isCursorVisible())
2161 view->the_locking_inset->
2162 ToggleInsetCursor();
2164 // This is only run when work_area_focus or lyx_focus is false.
2167 XGetInputFocus(fl_display, &tmpwin, &tmp);
2168 // Commenting this out, we have not had problems with this
2169 // for a long time. We will probably work on this code later
2170 // and we can reenable this debug code then. Now it only
2171 // anoying when debugging. (Lgb)
2172 //if (lyxerr.debugging(Debug::INFO)) {
2173 // lyxerr << "tmpwin: " << tmpwin
2174 // << "\nwindow: " << view->owner_->getForm()->window
2175 // << "\nwork_area_focus: " << view->work_area_focus
2176 // << "\nlyx_focus : " << view->lyx_focus
2179 if (tmpwin != view->owner_->getForm()->window) {
2180 view->lyx_focus = false;
2183 view->lyx_focus = true;
2184 if (!view->work_area_focus)
2187 goto set_timer_and_return;
2191 set_timer_and_return:
2192 fl_set_timer(ob, 0.4);
2200 string fromClipboard(Window win, XEvent * event)
2203 if (event->xselection.type == XA_STRING
2204 && event->xselection.property) {
2208 unsigned char * uc = 0;
2210 if (XGetWindowProperty(
2211 event->xselection.display, // display
2213 event->xselection.property, // property
2217 XA_STRING, // req_type
2218 &tmpatom, // actual_type_return
2219 &tmpint, // actual_format_return
2230 if (XGetWindowProperty(
2231 event->xselection.display, // display
2233 event->xselection.property, // property
2235 ul2/4+1, // long_length
2237 XA_STRING, // req_type
2238 &tmpatom, // actual_type_return
2239 &tmpint, // actual_format_return
2240 &ul1, // nitems_return
2241 &ul2, // bytes_after_return
2242 &uc // prop_return */
2247 strret = reinterpret_cast<char*>(uc);
2248 free(uc); // yes free!
2256 void BufferView::WorkAreaSelectionNotify(Window win, XEvent * event)
2258 if (buffer_ == 0) return;
2260 screen->HideCursor();
2262 string clb = fromClipboard(win, event);
2265 text->InsertStringA(clb.c_str());
2267 text->InsertStringB(clb.c_str());
2275 int BufferView::WorkAreaSelectionNotify(FL_OBJECT *, Window win,
2276 int /*w*/, int /*h*/,
2277 XEvent * event, void */*d*/)
2279 if (buffer_ == 0) return 0;
2280 if (event->type != SelectionNotify)
2286 unsigned char * uc = 0;
2288 screen->HideCursor();
2290 if (event->xselection.type == XA_STRING
2291 && event->xselection.property) {
2293 if (XGetWindowProperty(
2294 fl_display /* display */,
2296 event->xselection.property /* property */,
2297 0 /* long_offset */,
2298 0 /* long_length */,
2300 XA_STRING /* req_type */,
2301 &tmpatom /* actual_type_return */,
2302 &tmpint /* actual_format_return */,
2303 &ul1 /* nitems_return */,
2304 &ul2 /* bytes_after_return */,
2305 &uc /* prop_return */
2316 if (XGetWindowProperty(
2317 fl_display /* display */,
2319 event->xselection.property /* property */,
2320 0 /* long_offset */,
2321 ul2/4+1 /* long_length */,
2323 XA_STRING /* req_type */,
2324 &tmpatom /* actual_type_return */,
2325 &tmpint /* actual_format_return */,
2326 &ul1 /* nitems_return */,
2327 &ul2 /* bytes_after_return */,
2328 &uc /* prop_return */
2336 text->InsertStringA(reinterpret_cast<char*>(uc));
2338 text->InsertStringB(reinterpret_cast<char*>(uc));
2352 void BufferView::cursorPrevious()
2354 if (!text->cursor.row->previous) return;
2356 long y = getScreen()->first;
2357 Row * cursorrow = text->cursor.row;
2358 text->SetCursorFromCoordinates(text->cursor.x_fix, y);
2360 // This is to allow jumping over large insets
2361 if ((cursorrow == text->cursor.row))
2364 if (text->cursor.row->height < workarea->height())
2365 getScreen()->Draw(text->cursor.y
2366 - text->cursor.row->baseline
2367 + text->cursor.row->height
2368 - workarea->height() + 1 );
2371 void BufferView::cursorPrevious()
2373 if (!text->cursor.row->previous) return;
2375 long y = getScreen()->first;
2376 Row * cursorrow = text->cursor.row;
2377 text->SetCursorFromCoordinates(text->cursor.x_fix, y);
2379 // This is to allow jumping over large insets
2380 if ((cursorrow == text->cursor.row))
2383 if (text->cursor.row->height < work_area->h)
2384 getScreen()->Draw(text->cursor.y
2385 - text->cursor.row->baseline
2386 + text->cursor.row->height
2387 - work_area->h +1 );
2393 void BufferView::cursorNext()
2395 if (!text->cursor.row->next) return;
2397 long y = getScreen()->first;
2398 text->GetRowNearY(y);
2399 Row * cursorrow = text->cursor.row;
2400 text->SetCursorFromCoordinates(text->cursor.x_fix, y
2401 + workarea->height());
2403 // This is to allow jumping over large insets
2404 if ((cursorrow == text->cursor.row))
2407 if (text->cursor.row->height < workarea->height())
2408 getScreen()->Draw(text->cursor.y
2409 - text->cursor.row->baseline);
2412 void BufferView::cursorNext()
2414 if (!text->cursor.row->next) return;
2416 long y = getScreen()->first;
2417 text->GetRowNearY(y);
2418 Row * cursorrow = text->cursor.row;
2419 text->SetCursorFromCoordinates(text->cursor.x_fix, y + work_area->h);
2421 // This is to allow jumping over large insets
2422 if ((cursorrow == text->cursor.row))
2425 if (text->cursor.row->height < work_area->h)
2426 getScreen()->Draw(text->cursor.y
2427 - text->cursor.row->baseline);
2432 bool BufferView::available() const
2434 if (buffer_ && text) return true;
2439 void BufferView::beforeChange()
2441 getScreen()->ToggleSelection();
2442 text->ClearSelection();
2447 void BufferView::savePosition()
2449 backstack.push(buffer()->fileName(),
2455 void BufferView::restorePosition()
2457 if (backstack.empty()) return;
2460 string fname = backstack.pop(&x, &y);
2463 Buffer * b = bufferlist.exists(fname) ?
2464 bufferlist.getBuffer(fname) :
2465 bufferlist.loadLyXFile(fname); // don't ask, just load it
2467 text->SetCursorFromCoordinates(x, y);
2472 void BufferView::update(signed char f)
2474 owner()->updateLayoutChoice();
2476 if (!text->selection && f > -3)
2477 text->sel_cursor = text->cursor;
2480 text->FullRebreak();
2484 if (f != 3 && f != -3) {
2489 if (f == 1 || f == -1) {
2490 if (buffer()->isLyxClean()) {
2491 buffer()->markDirty();
2492 owner()->getMiniBuffer()->setTimer(4);
2494 buffer()->markDirty();
2500 void BufferView::smallUpdate(signed char f)
2502 getScreen()->SmallUpdate();
2503 if (getScreen()->TopCursorVisible()
2504 != getScreen()->first) {
2512 if (!text->selection)
2513 text->sel_cursor = text->cursor;
2515 if (f == 1 || f == -1) {
2516 if (buffer()->isLyxClean()) {
2517 buffer()->markDirty();
2518 owner()->getMiniBuffer()->setTimer(4);
2520 buffer()->markDirty();
2526 void BufferView::SetState()
2528 if (!lyxrc->rtl_support)
2531 if (text->real_current_font.getFontDirection()
2532 == LYX_DIR_LEFT_TO_RIGHT) {
2533 if (!owner_->getIntl()->primarykeymap)
2534 owner_->getIntl()->KeyMapPrim();
2536 if (owner_->getIntl()->primarykeymap)
2537 owner_->getIntl()->KeyMapSec();
2542 void BufferView::insetSleep()
2544 if (the_locking_inset && !inset_slept) {
2545 the_locking_inset->GetCursorPos(slx, sly);
2546 the_locking_inset->InsetUnlock();
2552 void BufferView::insetWakeup()
2554 if (the_locking_inset && inset_slept) {
2555 the_locking_inset->Edit(slx, sly);
2556 inset_slept = false;
2561 void BufferView::insetUnlock()
2563 if (the_locking_inset) {
2564 if (!inset_slept) the_locking_inset->InsetUnlock();
2565 the_locking_inset = 0;
2567 inset_slept = false;
2572 bool BufferView::focus() const
2574 return workarea->hasFocus();
2578 void BufferView::focus(bool f)
2580 if (f) workarea->setFocus();
2584 bool BufferView::active() const
2586 return workarea->active();