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 * ====================================================== */
22 #include "support/lstrings.h"
25 #pragma implementation
28 #include "commandtags.h"
29 #include "BufferView.h"
30 #include "bufferlist.h"
33 #include "insets/lyxinset.h"
34 #include "insets/insetbib.h"
35 #include "minibuffer.h"
36 #include "lyxscreen.h"
39 #include "lyx_gui_misc.h"
40 #include "BackStack.h"
45 #include "TextCache.h"
57 extern BufferList bufferlist;
59 void sigchldhandler(pid_t pid, int * status);
61 extern void SetXtermCursor(Window win);
62 extern bool input_prohibited;
63 extern bool selection_possible;
64 extern char ascii_type;
65 extern void MenuPasteSelection(char at);
66 extern void FreeUpdateTimer();
68 BufferView::BufferView(LyXView * o, int xpos, int ypos,
69 int width, int height)
74 workarea = new WorkArea(this, xpos, ypos, width, height);
78 current_scrollbar_value = 0;
79 // Activate the timer for the cursor
80 fl_set_timer(timer_cursor, 0.4);
82 work_area_focus = true;
84 the_locking_inset = 0;
89 BufferView::~BufferView()
95 Painter & BufferView::painter()
97 return workarea->getPainter();
101 void BufferView::buffer(Buffer * b)
103 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
107 buffer_->delUser(this);
109 // Put the old text into the TextCache, but
110 // only if the buffer is still loaded.
111 // Also set the owner of the test to 0
114 if (lyxerr.debugging())
115 textcache.show(lyxerr, "BufferView::buffer");
120 // Set current buffer
123 if (bufferlist.getState() == BufferList::CLOSING) return;
126 // screen is always deleted when the buffer is changed.
130 // If we are closing the buffer, use the first buffer as current
132 buffer_ = bufferlist.first();
136 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
137 buffer_->addUser(this);
138 owner_->getMenus()->showMenus();
139 // If we don't have a text object for this, we make one
141 resizeCurrentBuffer();
146 screen->first = screen->TopCursorVisible();
148 updateAllVisibleBufferRelatedPopups();
151 lyxerr[Debug::INFO] << " No Buffer!" << endl;
152 owner_->getMenus()->hideMenus();
156 // Also remove all remaining text's from the testcache.
157 // (there should not be any!) (if there is any it is a
159 if (lyxerr.debugging())
160 textcache.show(lyxerr, "buffer delete all");
163 // should update layoutchoice even if we don't have a buffer.
164 owner_->updateLayoutChoice();
165 owner_->getMiniBuffer()->Init();
166 owner_->updateWindowTitle();
170 void BufferView::updateScreen()
172 // Regenerate the screen.
174 screen = new LyXScreen(*workarea, text);
178 void BufferView::resize(int xpos, int ypos, int width, int height)
180 workarea->resize(xpos, ypos, width, height);
186 void BufferView::resize()
188 // This will resize the buffer. (Asger)
190 resizeCurrentBuffer();
194 void BufferView::redraw()
196 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
201 void BufferView::fitCursor()
203 if (screen) screen->FitCursor();
208 void BufferView::update()
210 if (screen) screen->Update();
214 void BufferView::updateScrollbar()
216 /* If the text is smaller than the working area, the scrollbar
217 * maximum must be the working area height. No scrolling will
221 workarea->setScrollbar(0, 1.0);
225 static long max2 = 0;
226 static long height2 = 0;
234 cbsf = screen->first;
236 // check if anything has changed.
238 height2 == workarea->height() &&
239 current_scrollbar_value == cbsf)
242 height2 = workarea->height();
243 current_scrollbar_value = cbsf;
245 if (cbth <= height2) { // text is smaller than screen
246 workarea->setScrollbar(0, 1.0); // right?
250 long maximum_height = workarea->height() * 3 / 4 + cbth;
254 double hfloat = workarea->height();
255 double maxfloat = maximum_height;
257 float slider_size = 0.0;
258 int slider_value = value;
260 workarea->setScrollbarBounds(0, text->height - workarea->height());
261 double lineh = text->DefaultHeight();
262 workarea->setScrollbarIncrements(lineh);
263 if (maxfloat > 0.0) {
264 if ((hfloat / maxfloat) * float(height2) < 3)
265 slider_size = 3.0/float(height2);
267 slider_size = hfloat / maxfloat;
269 slider_size = hfloat;
271 workarea->setScrollbar(slider_value, slider_size / workarea->height());
275 void BufferView::redoCurrentBuffer()
277 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
278 if (buffer_ && text) {
280 owner_->updateLayoutChoice();
285 int BufferView::resizeCurrentBuffer()
287 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
289 LyXParagraph * par = 0;
290 LyXParagraph * selstartpar = 0;
291 LyXParagraph * selendpar = 0;
300 owner_->getMiniBuffer()->Set(_("Formatting document..."));
303 par = text->cursor.par;
304 pos = text->cursor.pos;
305 selstartpar = text->sel_start_cursor.par;
306 selstartpos = text->sel_start_cursor.pos;
307 selendpar = text->sel_end_cursor.par;
308 selendpos = text->sel_end_cursor.pos;
309 selection = text->selection;
310 mark_set = text->mark_set;
312 text = new LyXText(this, workarea->workWidth(), buffer_);
314 // See if we have a text in TextCache that fits
315 // the new buffer_ with the correct width.
316 text = textcache.findFit(buffer_, workarea->workWidth());
318 if (lyxerr.debugging()) {
319 lyxerr << "Found a LyXText that fits:\n";
320 textcache.show(lyxerr, text);
322 // Set the owner of the newly found text
324 if (lyxerr.debugging())
325 textcache.show(lyxerr, "resizeCurrentBuffer");
327 text = new LyXText(this, workarea->workWidth(), buffer_);
333 text->selection = true;
334 /* at this point just to avoid the Delete-Empty-Paragraph
335 * Mechanism when setting the cursor */
336 text->mark_set = mark_set;
338 text->SetCursor(selstartpar, selstartpos);
339 text->sel_cursor = text->cursor;
340 text->SetCursor(selendpar, selendpos);
341 text->SetSelection();
342 text->SetCursor(par, pos);
344 text->SetCursor(par, pos);
345 text->sel_cursor = text->cursor;
346 text->selection = false;
349 screen->first = screen->TopCursorVisible(); /* this will scroll the
350 * screen such that the
355 owner_->getMiniBuffer()->Init();
359 // Now if the title form still exist kill it
366 void BufferView::gotoError()
371 screen->HideCursor();
376 if (!text->GotoNextError()) {
378 || text->cursor.par != text->FirstParagraph()) {
380 text->cursor.par = text->FirstParagraph();
381 text->cursor.pos = 0;
382 if (!text->GotoNextError()) {
384 owner_->getMiniBuffer()
385 ->Set(_("No more errors"));
389 owner_->getMiniBuffer()->Set(_("No more errors"));
394 text->sel_cursor = text->cursor;
399 void C_BufferView_CursorToggleCB(FL_OBJECT * ob, long buf)
401 BufferView::cursorToggleCB(ob, buf);
406 void BufferView::create_view()
415 timer_cursor = obj = fl_add_timer(FL_HIDDEN_TIMER,
416 0, 0, 0, 0, "Timer");
417 fl_set_object_callback(obj, C_BufferView_CursorToggleCB, 0);
422 // Callback for scrollbar up button
423 void BufferView::upCB(long time, int button)
425 if (buffer_ == 0) return;
444 XSync(fl_get_display(), 0);
448 // Callback for scrollbar slider
449 void BufferView::scrollCB(double value)
451 extern bool cursor_follows_scrollbar;
453 if (buffer_ == 0) return;
455 current_scrollbar_value = long(value);
456 if (current_scrollbar_value < 0)
457 current_scrollbar_value = 0;
462 screen->Draw(current_scrollbar_value);
464 if (cursor_follows_scrollbar) {
465 LyXText * vbt = text;
466 int height = vbt->DefaultHeight();
468 if (vbt->cursor.y < screen->first + height) {
469 vbt->SetCursorFromCoordinates(0,
472 } else if (vbt->cursor.y >
473 screen->first + workarea->height() - height) {
474 vbt->SetCursorFromCoordinates(0,
484 // Callback for scrollbar down button
485 void BufferView::downCB(long time, int button)
487 if (buffer_ == 0) return;
503 int BufferView::scrollUp(long time)
505 if (buffer_ == 0) return 0;
506 if (!screen) return 0;
508 double value = workarea->getScrollbarValue();
510 if (value == 0) return 0;
512 float add_value = (text->DefaultHeight()
513 + float(time) * float(time) * 0.125);
515 if (add_value > workarea->height())
516 add_value = float(workarea->height() -
517 text->DefaultHeight());
524 workarea->setScrollbarValue(value);
531 int BufferView::scrollDown(long time)
533 if (buffer_ == 0) return 0;
534 if (!screen) return 0;
536 double value= workarea->getScrollbarValue();
537 pair<double, double> p = workarea->getScrollbarBounds();
538 double max = p.second;
540 if (value == max) return 0;
542 float add_value = (text->DefaultHeight()
543 + float(time) * float(time) * 0.125);
545 if (add_value > workarea->height())
546 add_value = float(workarea->height() -
547 text->DefaultHeight());
554 workarea->setScrollbarValue(value);
561 void BufferView::scrollUpOnePage()
563 if (buffer_ == 0) return;
566 long y = screen->first;
570 Row * row = text->GetRowNearY(y);
572 y = y - workarea->height() + row->height;
574 workarea->setScrollbarValue(y);
580 void BufferView::scrollDownOnePage()
582 if (buffer_ == 0) return;
585 long y = screen->first;
587 if (y > text->height - workarea->height())
590 y += workarea->height();
591 text->GetRowNearY(y);
593 workarea->setScrollbarValue(y);
599 void BufferView::workAreaMotionNotify(int x, int y, unsigned int state)
601 if (buffer_ == 0 || !screen) return;
603 // Check for inset locking
604 if (the_locking_inset) {
605 LyXCursor cursor = text->cursor;
607 InsetMotionNotify(this,
614 // Only use motion with button 1
615 if (!state & Button1MotionMask)
618 /* The selection possible is needed, that only motion events are
619 * used, where the bottom press event was on the drawing area too */
620 if (selection_possible) {
621 screen->HideCursor();
623 text->SetCursorFromCoordinates(x, y + screen->first);
625 if (!text->selection)
626 update(-3); // Maybe an empty line was deleted
628 text->SetSelection();
629 screen->ToggleToggle();
630 if (screen->FitCursor())
632 screen->ShowCursor();
638 extern int bibitemMaxWidth(Painter &, LyXFont const &);
641 // Single-click on work area
642 void BufferView::workAreaButtonPress(int xpos, int ypos, unsigned int button)
647 if (buffer_ == 0 || !screen) return;
649 Inset * inset_hit = checkInsetHit(xpos, ypos, button);
651 // ok ok, this is a hack.
652 if (button == 4 || button == 5) {
655 scrollUp(100); // This number is only temporary
663 if (the_locking_inset) {
664 // We are in inset locking mode
666 /* Check whether the inset was hit. If not reset mode,
667 otherwise give the event to the inset */
668 if (inset_hit == the_locking_inset) {
670 InsetButtonPress(this,
675 unlockInset(the_locking_inset);
680 selection_possible = true;
681 screen->HideCursor();
683 // Right button mouse click on a table
685 (text->cursor.par->table ||
686 text->MouseHitInTable(xpos, ypos + screen->first))) {
687 // Set the cursor to the press-position
688 text->SetCursorFromCoordinates(xpos, ypos + screen->first);
691 // Only show the table popup if the hit is in
693 if (!text->HitInTable(text->cursor.row, xpos))
696 // Hit above or below the table?
698 if (!text->selection) {
699 screen->ToggleSelection();
700 text->ClearSelection();
705 // Popup table popup when on a table.
706 // This is obviously temporary, since we
707 // should be able to popup various
708 // context-sensitive-menus with the
709 // the right mouse. So this should be done more
710 // general in the future. Matthias.
711 selection_possible = false;
713 ->Dispatch(LFUN_LAYOUT_TABLE,
719 int screen_first = screen->first;
721 // Middle button press pastes if we have a selection
722 bool paste_internally = false;
724 && text->selection) {
725 owner_->getLyXFunc()->Dispatch(LFUN_COPY);
726 paste_internally = true;
729 // Clear the selection
730 screen->ToggleSelection();
731 text->ClearSelection();
736 // Single left click in math inset?
737 if ((inset_hit != 0) &&
738 (inset_hit->Editable()==Inset::HIGHLY_EDITABLE)) {
739 // Highly editable inset, like math
740 UpdatableInset *inset = (UpdatableInset *)inset_hit;
741 selection_possible = false;
742 owner_->updateLayoutChoice();
743 owner_->getMiniBuffer()->Set(inset->EditMessage());
744 inset->InsetButtonPress(this, xpos, ypos, button);
745 inset->Edit(this, xpos, ypos, button);
749 // Right click on a footnote flag opens float menu
751 selection_possible = false;
755 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
756 text->SetCursorFromCoordinates(xpos, ypos + screen_first);
758 text->sel_cursor = text->cursor;
759 text->cursor.x_fix = text->cursor.x;
761 owner_->updateLayoutChoice();
762 if (screen->FitCursor()){
764 selection_possible = false;
767 // Insert primary selection with middle mouse
768 // if there is a local selection in the current buffer,
771 if (paste_internally)
772 owner_->getLyXFunc()->Dispatch(LFUN_PASTE);
774 owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION,
776 selection_possible = false;
782 void BufferView::doubleClick(int /*x*/, int /*y*/, unsigned int button)
785 if (buffer_ && !the_locking_inset) {
786 if (screen && button == 1) {
787 screen->HideCursor();
788 screen->ToggleSelection();
790 screen->ToggleSelection(false);
791 /* This will fit the cursor on the screen
799 void BufferView::tripleClick(int /*x*/, int /*y*/, unsigned int button)
802 if (buffer_ && screen && button == 1) {
803 screen->HideCursor();
804 screen->ToggleSelection();
806 text->sel_cursor = text->cursor;
808 text->SetSelection();
809 screen->ToggleSelection(false);
810 /* This will fit the cursor on the screen
817 void BufferView::workAreaButtonRelease(int x, int y, unsigned int button)
819 if (buffer_ == 0 || screen == 0) return;
821 // If we hit an inset, we have the inset coordinates in these
822 // and inset_hit points to the inset. If we do not hit an
823 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
824 Inset * inset_hit = checkInsetHit(x, y, button);
826 if (the_locking_inset) {
827 // We are in inset locking mode.
829 /* LyX does a kind of work-area grabbing for insets.
830 Only a ButtonPress Event outside the inset will
831 force a InsetUnlock. */
833 InsetButtonRelease(this, x, y, button);
837 selection_possible = false;
838 if (text->cursor.par->table) {
840 NumberOfCell(text->cursor.par,
842 if (text->cursor.par->table->IsContRow(cell) &&
843 text->cursor.par->table->
844 CellHasContRow(text->cursor.par->table->
845 GetCellAbove(cell))<0) {
850 if (button >= 2) return;
853 owner_->getMiniBuffer()->Set(CurrentState());
855 // Did we hit an editable inset?
856 if (inset_hit != 0) {
857 // Inset like error, notes and figures
858 selection_possible = false;
860 #warning fix this proper in 0.13
862 // Following a ref shouldn't issue
863 // a push on the undo-stack
864 // anylonger, now that we have
865 // keybindings for following
866 // references and returning from
867 // references. IMHO though, it
868 // should be the inset's own business
869 // to push or not push on the undo
870 // stack. They don't *have* to
871 // alter the document...
873 // ...or maybe the SetCursorParUndo()
874 // below isn't necessary at all anylonger?
875 if (inset_hit->LyxCode() == Inset::REF_CODE) {
876 text->SetCursorParUndo();
879 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
880 if (inset_hit->Editable()==Inset::HIGHLY_EDITABLE) {
881 // Highly editable inset, like math
882 UpdatableInset *inset = (UpdatableInset *)inset_hit;
883 inset->InsetButtonRelease(this, x, y, button);
885 inset_hit->Edit(this, x, y, button);
890 // check whether we want to open a float
894 if (text->cursor.pos <
895 text->cursor.par->Last()) {
896 c = text->cursor.par->
897 GetChar(text->cursor.pos);
899 if (c == LyXParagraph::META_FOOTNOTE
900 || c == LyXParagraph::META_MARGIN
901 || c == LyXParagraph::META_FIG
902 || c == LyXParagraph::META_TAB
903 || c == LyXParagraph::META_WIDE_FIG
904 || c == LyXParagraph::META_WIDE_TAB
905 || c == LyXParagraph::META_ALGORITHM){
907 } else if (text->cursor.pos - 1 >= 0) {
908 c = text->cursor.par->
909 GetChar(text->cursor.pos - 1);
910 if (c == LyXParagraph::META_FOOTNOTE
911 || c == LyXParagraph::META_MARGIN
912 || c == LyXParagraph::META_FIG
913 || c == LyXParagraph::META_TAB
914 || c == LyXParagraph::META_WIDE_FIG
915 || c == LyXParagraph::META_WIDE_TAB
916 || c == LyXParagraph::META_ALGORITHM){
917 // We are one step too far to the right
924 selection_possible = false;
929 // Do we want to close a float? (click on the float-label)
930 if (text->cursor.row->par->footnoteflag ==
931 LyXParagraph::OPEN_FOOTNOTE
932 //&& text->cursor.pos == 0
933 && text->cursor.row->previous &&
934 text->cursor.row->previous->par->
935 footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
936 LyXFont font(LyXFont::ALL_SANE);
937 font.setSize(LyXFont::SIZE_FOOTNOTE);
939 int box_x = 20; // LYX_PAPER_MARGIN;
940 box_x += lyxfont::width(" wide-tab ", font);
942 int screen_first = screen->first;
945 && y + screen_first > text->cursor.y -
946 text->cursor.row->baseline
947 && y + screen_first < text->cursor.y -
948 text->cursor.row->baseline
949 + lyxfont::maxAscent(font) * 1.2 + lyxfont::maxDescent(font) * 1.2) {
951 selection_possible = false;
956 // Maybe we want to edit a bibitem ale970302
957 if (text->cursor.par->bibkey && x < 20 +
958 bibitemMaxWidth(painter(),
961 params.textclass).defaultfont())) {
962 text->cursor.par->bibkey->Edit(this, 0, 0, 0);
970 * Returns an inset if inset was hit. 0 otherwise.
971 * If hit, the coordinates are changed relative to the inset.
972 * Otherwise coordinates are not changed, and false is returned.
974 Inset * BufferView::checkInsetHit(int & x, int & y, unsigned int button)
979 int y_tmp = y + screen->first;
982 text->SetCursorFromCoordinates(cursor, x, y_tmp);
984 bool move_cursor = true;
986 bool move_cursor = ((cursor.par != text->cursor.par) ||
987 (cursor.pos != text->cursor.pos)) && (button < 2);
990 if (cursor.pos < cursor.par->Last()
991 && cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET
992 && cursor.par->GetInset(cursor.pos)
993 && cursor.par->GetInset(cursor.pos)->Editable()) {
995 // Check whether the inset really was hit
996 Inset * tmpinset = cursor.par->GetInset(cursor.pos);
997 LyXFont font = text->GetFont(cursor.par, cursor.pos);
998 bool is_rtl = font.isVisibleRightToLeft();
1002 start_x = cursor.x - tmpinset->width(painter(), font);
1006 end_x = cursor.x + tmpinset->width(painter(), font);
1009 if (x > start_x && x < end_x
1010 && y_tmp > cursor.y - tmpinset->ascent(painter(), font)
1011 && y_tmp < cursor.y + tmpinset->descent(painter(), font)) {
1013 text->SetCursorFromCoordinates(x, y_tmp);
1015 // The origin of an inset is on the baseline
1016 y = y_tmp - (text->cursor.y);
1021 if ((cursor.pos - 1 >= 0) &&
1022 (cursor.par->GetChar(cursor.pos-1) == LyXParagraph::META_INSET) &&
1023 (cursor.par->GetInset(cursor.pos - 1)) &&
1024 (cursor.par->GetInset(cursor.pos - 1)->Editable())) {
1025 Inset * tmpinset = cursor.par->GetInset(cursor.pos-1);
1026 LyXFont font = text->GetFont(cursor.par, cursor.pos-1);
1027 bool is_rtl = font.isVisibleRightToLeft();
1031 start_x = cursor.x - tmpinset->width(painter(), font);
1035 end_x = cursor.x + tmpinset->width(painter(), font);
1037 if (x > start_x && x < end_x
1038 && y_tmp > cursor.y - tmpinset->ascent(painter(), font)
1039 && y_tmp < cursor.y + tmpinset->descent(painter(), font)) {
1041 text->SetCursorFromCoordinates(x, y_tmp);
1043 // The origin of an inset is on the baseline
1044 y = y_tmp - (text->cursor.y);
1051 void BufferView::workAreaExpose()
1053 // this is a hack to ensure that we only call this through
1054 // BufferView::redraw().
1059 static int work_area_width = -1;
1060 static int work_area_height = -1;
1062 bool widthChange = workarea->workWidth() != work_area_width;
1063 bool heightChange = workarea->height() != work_area_height;
1065 // update from work area
1066 work_area_width = workarea->workWidth();
1067 work_area_height = workarea->height();
1070 // All buffers need a resize
1071 bufferlist.resize();
1073 // Remove all texts from the textcache
1074 // This is not _really_ what we want to do. What
1075 // we really want to do is to delete in textcache
1076 // that does not have a BufferView with matching
1077 // width, but as long as we have only one BufferView
1078 // deleting all gives the same result.
1079 if (lyxerr.debugging())
1080 textcache.show(lyxerr, "Expose delete all");
1082 } else if (heightChange) {
1083 // Rebuild image of current screen
1085 // fitCursor() ensures we don't jump back
1086 // to the start of the document on vertical
1090 // The main window size has changed, repaint most stuff
1092 // ...including the minibuffer
1093 owner_->getMiniBuffer()->Init();
1095 } else if (screen) screen->Redraw();
1097 // Grey box when we don't have a buffer
1098 workarea->greyOut();
1101 // always make sure that the scrollbar is sane.
1103 owner_->updateLayoutChoice();
1108 // Callback for cursor timer
1109 void BufferView::cursorToggleCB(FL_OBJECT * ob, long)
1111 BufferView * view = static_cast<BufferView*>(ob->u_vdata);
1113 // Quite a nice place for asyncron Inset updating, isn't it?
1114 // Actually no! This is run even if no buffer exist... so (Lgb)
1115 if (view && !view->buffer_) {
1116 goto set_timer_and_return;
1120 // On my quest to solve the gs render hangups I am now
1121 // disabling the SIGHUP completely, and will do a wait
1122 // now and then instead. If the guess that xforms somehow
1123 // destroys something is true, this is likely (hopefully)
1124 // to solve the problem...at least I hope so. Lgb
1126 // ...Ok this seems to work...at least it does not make things
1127 // worse so far. However I still see gs processes that hangs.
1128 // I would really like to know _why_ they are hanging. Anyway
1129 // the solution without the SIGCHLD handler seems to be easier
1132 // When attaching gdb to a a running gs that hangs it shows
1133 // that it is waiting for input(?) Is it possible for us to
1134 // provide that input somehow? Or figure what it is expecing
1137 // One solution is to, after some time, look if there are some
1138 // old gs processes still running and if there are: kill them
1141 // Another solution is to provide the user an option to rerender
1142 // a picture. This would, for the picture in question, check if
1143 // there is a gs running for it, if so kill it, and start a new
1144 // rendering process.
1146 // these comments posted to lyx@via
1149 int pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1150 if (pid == -1) // error find out what is wrong
1151 ; // ignore it for now.
1153 sigchldhandler(pid, &status);
1156 view->updatelist.update(view);
1158 if (view && !view->screen){
1159 goto set_timer_and_return;
1162 if (view->lyx_focus && view->work_area_focus) {
1163 if (!view->the_locking_inset) {
1164 view->screen->CursorToggle();
1166 view->the_locking_inset->
1167 ToggleInsetCursor(view);
1169 goto set_timer_and_return;
1171 // Make sure that the cursor is visible.
1172 if (!view->the_locking_inset) {
1173 view->screen->ShowCursor();
1175 if (!view->the_locking_inset->isCursorVisible())
1176 view->the_locking_inset->
1177 ToggleInsetCursor(view);
1179 // This is only run when work_area_focus or lyx_focus is false.
1182 XGetInputFocus(fl_display, &tmpwin, &tmp);
1183 // Commenting this out, we have not had problems with this
1184 // for a long time. We will probably work on this code later
1185 // and we can reenable this debug code then. Now it only
1186 // anoying when debugging. (Lgb)
1187 //if (lyxerr.debugging(Debug::INFO)) {
1188 // lyxerr << "tmpwin: " << tmpwin
1189 // << "\nwindow: " << view->owner_->getForm()->window
1190 // << "\nwork_area_focus: " << view->work_area_focus
1191 // << "\nlyx_focus : " << view->lyx_focus
1194 if (tmpwin != view->owner_->getForm()->window) {
1195 view->lyx_focus = false;
1198 view->lyx_focus = true;
1199 if (!view->work_area_focus)
1202 goto set_timer_and_return;
1206 set_timer_and_return:
1207 fl_set_timer(ob, 0.4);
1214 string fromClipboard(Window win, XEvent * event)
1217 if (event->xselection.type == XA_STRING
1218 && event->xselection.property) {
1222 unsigned char * uc = 0;
1224 if (XGetWindowProperty(
1225 event->xselection.display, // display
1227 event->xselection.property, // property
1231 XA_STRING, // req_type
1232 &tmpatom, // actual_type_return
1233 &tmpint, // actual_format_return
1244 if (XGetWindowProperty(
1245 event->xselection.display, // display
1247 event->xselection.property, // property
1249 ul2/4+1, // long_length
1251 XA_STRING, // req_type
1252 &tmpatom, // actual_type_return
1253 &tmpint, // actual_format_return
1254 &ul1, // nitems_return
1255 &ul2, // bytes_after_return
1256 &uc // prop_return */
1261 strret = reinterpret_cast<char*>(uc);
1262 free(uc); // yes free!
1270 void BufferView::workAreaSelectionNotify(Window win, XEvent * event)
1272 if (buffer_ == 0) return;
1274 screen->HideCursor();
1276 string clb = fromClipboard(win, event);
1279 text->InsertStringA(clb);
1281 text->InsertStringB(clb);
1289 void BufferView::cursorPrevious()
1291 if (!text->cursor.row->previous) return;
1293 long y = screen->first;
1294 Row * cursorrow = text->cursor.row;
1295 text->SetCursorFromCoordinates(text->cursor.x_fix, y);
1297 // This is to allow jumping over large insets
1298 if ((cursorrow == text->cursor.row))
1301 if (text->cursor.row->height < workarea->height())
1302 screen->Draw(text->cursor.y
1303 - text->cursor.row->baseline
1304 + text->cursor.row->height
1305 - workarea->height() + 1 );
1309 void BufferView::cursorNext()
1311 if (!text->cursor.row->next) return;
1313 long y = screen->first;
1314 text->GetRowNearY(y);
1315 Row * cursorrow = text->cursor.row;
1316 text->SetCursorFromCoordinates(text->cursor.x_fix, y
1317 + workarea->height());
1319 // This is to allow jumping over large insets
1320 if ((cursorrow == text->cursor.row))
1323 if (text->cursor.row->height < workarea->height())
1324 screen->Draw(text->cursor.y
1325 - text->cursor.row->baseline);
1329 bool BufferView::available() const
1331 if (buffer_ && text) return true;
1336 void BufferView::beforeChange()
1339 text->ClearSelection();
1344 void BufferView::savePosition()
1346 backstack.push(buffer()->fileName(),
1352 void BufferView::restorePosition()
1354 if (backstack.empty()) return;
1357 string fname = backstack.pop(&x, &y);
1360 Buffer * b = bufferlist.exists(fname) ?
1361 bufferlist.getBuffer(fname) :
1362 bufferlist.loadLyXFile(fname); // don't ask, just load it
1364 text->SetCursorFromCoordinates(x, y);
1369 void BufferView::update(signed char f)
1371 owner()->updateLayoutChoice();
1373 if (!text->selection && f > -3)
1374 text->sel_cursor = text->cursor;
1377 text->FullRebreak();
1381 if (f != 3 && f != -3) {
1386 if (f == 1 || f == -1) {
1387 if (buffer()->isLyxClean()) {
1388 buffer()->markDirty();
1389 owner()->getMiniBuffer()->setTimer(4);
1391 buffer()->markDirty();
1397 void BufferView::smallUpdate(signed char f)
1399 screen->SmallUpdate();
1400 if (screen->TopCursorVisible()
1409 if (!text->selection)
1410 text->sel_cursor = text->cursor;
1412 if (f == 1 || f == -1) {
1413 if (buffer()->isLyxClean()) {
1414 buffer()->markDirty();
1415 owner()->getMiniBuffer()->setTimer(4);
1417 buffer()->markDirty();
1423 void BufferView::setState()
1425 if (!lyxrc.rtl_support)
1428 if (text->real_current_font.isVisibleRightToLeft()) {
1429 if (owner_->getIntl()->primarykeymap)
1430 owner_->getIntl()->KeyMapSec();
1432 if (!owner_->getIntl()->primarykeymap)
1433 owner_->getIntl()->KeyMapPrim();
1438 void BufferView::insetSleep()
1440 if (the_locking_inset && !inset_slept) {
1441 the_locking_inset->GetCursorPos(slx, sly);
1442 the_locking_inset->InsetUnlock(this);
1448 void BufferView::insetWakeup()
1450 if (the_locking_inset && inset_slept) {
1451 the_locking_inset->Edit(this, slx, sly, 0);
1452 inset_slept = false;
1457 void BufferView::insetUnlock()
1459 if (the_locking_inset) {
1460 if (!inset_slept) the_locking_inset->InsetUnlock(this);
1461 the_locking_inset = 0;
1463 inset_slept = false;
1468 bool BufferView::focus() const
1470 return workarea->hasFocus();
1474 void BufferView::focus(bool f)
1476 if (f) workarea->setFocus();
1480 bool BufferView::active() const
1482 return workarea->active();
1486 Painter & BufferView::getPainter() const
1488 return workarea->getPainter();
1492 unsigned short BufferView::paperWidth() const
1494 return text->paperWidth();
1498 bool BufferView::belowMouse() const
1500 return workarea->belowMouse();
1504 void BufferView::showCursor()
1507 screen->ShowCursor();
1511 void BufferView::hideCursor()
1514 screen->HideCursor();
1518 void BufferView::toggleSelection(bool b)
1521 screen->ToggleSelection(b);
1525 void BufferView::toggleToggle()
1528 screen->ToggleToggle();
1532 void BufferView::center()
1535 if (text->cursor.y > workarea->height() / 2) {
1536 screen->Draw(text->cursor.y - workarea->height() / 2);