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"
55 extern BufferList bufferlist;
57 void sigchldhandler(pid_t pid, int * status);
59 extern void SetXtermCursor(Window win);
60 extern bool input_prohibited;
61 extern bool selection_possible;
62 extern char ascii_type;
63 extern void MenuPasteSelection(char at);
64 extern void FreeUpdateTimer();
66 BufferView::BufferView(LyXView * o, int xpos, int ypos,
67 int width, int height)
72 workarea = new WorkArea(this, xpos, ypos, width, height);
76 current_scrollbar_value = 0;
77 // Activate the timer for the cursor
78 fl_set_timer(timer_cursor, 0.4);
80 work_area_focus = true;
82 the_locking_inset = 0;
87 BufferView::~BufferView()
93 Painter & BufferView::painter()
95 return workarea->getPainter();
99 void BufferView::buffer(Buffer * b)
101 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
105 buffer_->delUser(this);
107 // Put the old text into the TextCache, but
108 // only if the buffer is still loaded.
109 // Also set the owner of the test to 0
112 if (lyxerr.debugging())
113 textcache.show(lyxerr, "BufferView::buffer");
118 // Set current buffer
121 if (bufferlist.getState() == BufferList::CLOSING) return;
124 // screen is always deleted when the buffer is changed.
128 // If we are closing the buffer, use the first buffer as current
130 buffer_ = bufferlist.first();
134 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
135 buffer_->addUser(this);
136 owner_->getMenus()->showMenus();
137 // If we don't have a text object for this, we make one
139 resizeCurrentBuffer();
144 screen->first = screen->TopCursorVisible();
146 updateAllVisibleBufferRelatedPopups();
149 lyxerr[Debug::INFO] << " No Buffer!" << endl;
150 owner_->getMenus()->hideMenus();
154 // Also remove all remaining text's from the testcache.
155 // (there should not be any!) (if there is any it is a
157 if (lyxerr.debugging())
158 textcache.show(lyxerr, "buffer delete all");
161 // should update layoutchoice even if we don't have a buffer.
162 owner_->updateLayoutChoice();
163 owner_->getMiniBuffer()->Init();
164 owner_->updateWindowTitle();
168 void BufferView::updateScreen()
170 // Regenerate the screen.
172 screen = new LyXScreen(*workarea, text);
176 void BufferView::resize(int xpos, int ypos, int width, int height)
178 workarea->resize(xpos, ypos, width, height);
184 void BufferView::resize()
186 // This will resize the buffer. (Asger)
188 resizeCurrentBuffer();
192 void BufferView::redraw()
194 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
199 void BufferView::fitCursor()
201 if (screen) screen->FitCursor();
206 void BufferView::update()
208 if (screen) screen->Update();
212 void BufferView::updateScrollbar()
214 /* If the text is smaller than the working area, the scrollbar
215 * maximum must be the working area height. No scrolling will
219 workarea->setScrollbar(0, 1.0);
223 static long max2 = 0;
224 static long height2 = 0;
232 cbsf = screen->first;
234 // check if anything has changed.
236 height2 == workarea->height() &&
237 current_scrollbar_value == cbsf)
240 height2 = workarea->height();
241 current_scrollbar_value = cbsf;
243 if (cbth <= height2) { // text is smaller than screen
244 workarea->setScrollbar(0, 1.0); // right?
248 long maximum_height = workarea->height() * 3 / 4 + cbth;
252 double hfloat = workarea->height();
253 double maxfloat = maximum_height;
255 float slider_size = 0.0;
256 int slider_value = value;
258 workarea->setScrollbarBounds(0, text->height - workarea->height());
259 double lineh = text->DefaultHeight();
260 workarea->setScrollbarIncrements(lineh);
261 if (maxfloat > 0.0) {
262 if ((hfloat / maxfloat) * float(height2) < 3)
263 slider_size = 3.0/float(height2);
265 slider_size = hfloat / maxfloat;
267 slider_size = hfloat;
269 workarea->setScrollbar(slider_value, slider_size / workarea->height());
273 void BufferView::redoCurrentBuffer()
275 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
276 if (buffer_ && text) {
278 owner_->updateLayoutChoice();
283 int BufferView::resizeCurrentBuffer()
285 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
287 LyXParagraph * par = 0;
288 LyXParagraph * selstartpar = 0;
289 LyXParagraph * selendpar = 0;
298 owner_->getMiniBuffer()->Set(_("Formatting document..."));
301 par = text->cursor.par;
302 pos = text->cursor.pos;
303 selstartpar = text->sel_start_cursor.par;
304 selstartpos = text->sel_start_cursor.pos;
305 selendpar = text->sel_end_cursor.par;
306 selendpos = text->sel_end_cursor.pos;
307 selection = text->selection;
308 mark_set = text->mark_set;
310 text = new LyXText(this, workarea->workWidth(), buffer_);
312 // See if we have a text in TextCache that fits
313 // the new buffer_ with the correct width.
314 text = textcache.findFit(buffer_, workarea->workWidth());
316 if (lyxerr.debugging()) {
317 lyxerr << "Found a LyXText that fits:\n";
318 textcache.show(lyxerr, text);
320 // Set the owner of the newly found text
322 if (lyxerr.debugging())
323 textcache.show(lyxerr, "resizeCurrentBuffer");
325 text = new LyXText(this, workarea->workWidth(), buffer_);
331 text->selection = true;
332 /* at this point just to avoid the Delete-Empty-Paragraph
333 * Mechanism when setting the cursor */
334 text->mark_set = mark_set;
336 text->SetCursor(selstartpar, selstartpos);
337 text->sel_cursor = text->cursor;
338 text->SetCursor(selendpar, selendpos);
339 text->SetSelection();
340 text->SetCursor(par, pos);
342 text->SetCursor(par, pos);
343 text->sel_cursor = text->cursor;
344 text->selection = false;
347 screen->first = screen->TopCursorVisible(); /* this will scroll the
348 * screen such that the
353 owner_->getMiniBuffer()->Init();
357 // Now if the title form still exist kill it
364 void BufferView::gotoError()
369 screen->HideCursor();
374 if (!text->GotoNextError()) {
376 || text->cursor.par != text->FirstParagraph()) {
378 text->cursor.par = text->FirstParagraph();
379 text->cursor.pos = 0;
380 if (!text->GotoNextError()) {
382 owner_->getMiniBuffer()
383 ->Set(_("No more errors"));
387 owner_->getMiniBuffer()->Set(_("No more errors"));
392 text->sel_cursor = text->cursor;
397 void C_BufferView_CursorToggleCB(FL_OBJECT * ob, long buf)
399 BufferView::cursorToggleCB(ob, buf);
404 void BufferView::create_view()
413 timer_cursor = obj = fl_add_timer(FL_HIDDEN_TIMER,
414 0, 0, 0, 0, "Timer");
415 fl_set_object_callback(obj, C_BufferView_CursorToggleCB, 0);
420 // Callback for scrollbar up button
421 void BufferView::upCB(long time, int button)
423 if (buffer_ == 0) return;
442 XSync(fl_get_display(), 0);
446 // Callback for scrollbar slider
447 void BufferView::scrollCB(double value)
449 extern bool cursor_follows_scrollbar;
451 if (buffer_ == 0) return;
453 current_scrollbar_value = long(value);
454 if (current_scrollbar_value < 0)
455 current_scrollbar_value = 0;
460 screen->Draw(current_scrollbar_value);
462 if (cursor_follows_scrollbar) {
463 LyXText * vbt = text;
464 int height = vbt->DefaultHeight();
466 if (vbt->cursor.y < screen->first + height) {
467 vbt->SetCursorFromCoordinates(0,
470 } else if (vbt->cursor.y >
471 screen->first + workarea->height() - height) {
472 vbt->SetCursorFromCoordinates(0,
482 // Callback for scrollbar down button
483 void BufferView::downCB(long time, int button)
485 if (buffer_ == 0) return;
501 int BufferView::scrollUp(long time)
503 if (buffer_ == 0) return 0;
504 if (!screen) return 0;
506 double value = workarea->getScrollbarValue();
508 if (value == 0) return 0;
510 float add_value = (text->DefaultHeight()
511 + float(time) * float(time) * 0.125);
513 if (add_value > workarea->height())
514 add_value = float(workarea->height() -
515 text->DefaultHeight());
522 workarea->setScrollbarValue(value);
529 int BufferView::scrollDown(long time)
531 if (buffer_ == 0) return 0;
532 if (!screen) return 0;
534 double value= workarea->getScrollbarValue();
535 pair<double, double> p = workarea->getScrollbarBounds();
536 double max = p.second;
538 if (value == max) return 0;
540 float add_value = (text->DefaultHeight()
541 + float(time) * float(time) * 0.125);
543 if (add_value > workarea->height())
544 add_value = float(workarea->height() -
545 text->DefaultHeight());
552 workarea->setScrollbarValue(value);
559 void BufferView::scrollUpOnePage()
561 if (buffer_ == 0) return;
564 long y = screen->first;
568 Row * row = text->GetRowNearY(y);
570 y = y - workarea->height() + row->height;
572 workarea->setScrollbarValue(y);
578 void BufferView::scrollDownOnePage()
580 if (buffer_ == 0) return;
583 long y = screen->first;
585 if (y > text->height - workarea->height())
588 y += workarea->height();
589 text->GetRowNearY(y);
591 workarea->setScrollbarValue(y);
597 void BufferView::workAreaMotionNotify(int x, int y, unsigned int state)
599 if (buffer_ == 0 || !screen) return;
601 // Check for inset locking
602 if (the_locking_inset) {
603 LyXCursor cursor = text->cursor;
605 InsetMotionNotify(this,
612 // Only use motion with button 1
613 if (!state & Button1MotionMask)
616 /* The selection possible is needed, that only motion events are
617 * used, where the bottom press event was on the drawing area too */
618 if (selection_possible) {
619 screen->HideCursor();
621 text->SetCursorFromCoordinates(x, y + screen->first);
623 if (!text->selection)
624 update(-3); // Maybe an empty line was deleted
626 text->SetSelection();
627 screen->ToggleToggle();
628 if (screen->FitCursor())
630 screen->ShowCursor();
636 extern int bibitemMaxWidth(Painter &, LyXFont const &);
639 // Single-click on work area
640 void BufferView::workAreaButtonPress(int xpos, int ypos, unsigned int button)
645 if (buffer_ == 0 || !screen) return;
647 Inset * inset_hit = checkInsetHit(xpos, ypos, button);
649 // ok ok, this is a hack.
650 if (button == 4 || button == 5) {
653 scrollUp(100); // This number is only temporary
661 if (the_locking_inset) {
662 // We are in inset locking mode
664 /* Check whether the inset was hit. If not reset mode,
665 otherwise give the event to the inset */
666 if (inset_hit == the_locking_inset) {
668 InsetButtonPress(this,
673 unlockInset(the_locking_inset);
678 selection_possible = true;
679 screen->HideCursor();
681 // Right button mouse click on a table
683 (text->cursor.par->table ||
684 text->MouseHitInTable(xpos, ypos + screen->first))) {
685 // Set the cursor to the press-position
686 text->SetCursorFromCoordinates(xpos, ypos + screen->first);
689 // Only show the table popup if the hit is in
691 if (!text->HitInTable(text->cursor.row, xpos))
694 // Hit above or below the table?
696 if (!text->selection) {
697 screen->ToggleSelection();
698 text->ClearSelection();
703 // Popup table popup when on a table.
704 // This is obviously temporary, since we
705 // should be able to popup various
706 // context-sensitive-menus with the
707 // the right mouse. So this should be done more
708 // general in the future. Matthias.
709 selection_possible = false;
711 ->Dispatch(LFUN_LAYOUT_TABLE,
717 int screen_first = screen->first;
719 // Middle button press pastes if we have a selection
720 bool paste_internally = false;
722 && text->selection) {
723 owner_->getLyXFunc()->Dispatch(LFUN_COPY);
724 paste_internally = true;
727 // Clear the selection
728 screen->ToggleSelection();
729 text->ClearSelection();
734 // Single left click in math inset?
735 if ((inset_hit != 0) &&
736 (inset_hit->Editable()==Inset::HIGHLY_EDITABLE)) {
737 // Highly editable inset, like math
738 UpdatableInset *inset = (UpdatableInset *)inset_hit;
739 selection_possible = false;
740 owner_->updateLayoutChoice();
741 owner_->getMiniBuffer()->Set(inset->EditMessage());
742 inset->InsetButtonPress(this, xpos, ypos, button);
743 inset->Edit(this, xpos, ypos, button);
747 // Right click on a footnote flag opens float menu
749 selection_possible = false;
753 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
754 text->SetCursorFromCoordinates(xpos, ypos + screen_first);
756 text->sel_cursor = text->cursor;
757 text->cursor.x_fix = text->cursor.x;
759 owner_->updateLayoutChoice();
760 if (screen->FitCursor()){
762 selection_possible = false;
765 // Insert primary selection with middle mouse
766 // if there is a local selection in the current buffer,
769 if (paste_internally)
770 owner_->getLyXFunc()->Dispatch(LFUN_PASTE);
772 owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION,
774 selection_possible = false;
780 void BufferView::doubleClick(int /*x*/, int /*y*/, unsigned int button)
783 if (buffer_ && !the_locking_inset) {
784 if (screen && button == 1) {
785 screen->HideCursor();
786 screen->ToggleSelection();
788 screen->ToggleSelection(false);
789 /* This will fit the cursor on the screen
797 void BufferView::tripleClick(int /*x*/, int /*y*/, unsigned int button)
800 if (buffer_ && screen && button == 1) {
801 screen->HideCursor();
802 screen->ToggleSelection();
804 text->sel_cursor = text->cursor;
806 text->SetSelection();
807 screen->ToggleSelection(false);
808 /* This will fit the cursor on the screen
815 void BufferView::workAreaButtonRelease(int x, int y, unsigned int button)
817 if (buffer_ == 0 || screen == 0) return;
819 // If we hit an inset, we have the inset coordinates in these
820 // and inset_hit points to the inset. If we do not hit an
821 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
822 Inset * inset_hit = checkInsetHit(x, y, button);
824 if (the_locking_inset) {
825 // We are in inset locking mode.
827 /* LyX does a kind of work-area grabbing for insets.
828 Only a ButtonPress Event outside the inset will
829 force a InsetUnlock. */
831 InsetButtonRelease(this, x, y, button);
835 selection_possible = false;
836 if (text->cursor.par->table) {
838 NumberOfCell(text->cursor.par,
840 if (text->cursor.par->table->IsContRow(cell) &&
841 text->cursor.par->table->
842 CellHasContRow(text->cursor.par->table->
843 GetCellAbove(cell))<0) {
848 if (button >= 2) return;
851 owner_->getMiniBuffer()->Set(CurrentState());
853 // Did we hit an editable inset?
854 if (inset_hit != 0) {
855 // Inset like error, notes and figures
856 selection_possible = false;
858 #warning fix this proper in 0.13
860 // Following a ref shouldn't issue
861 // a push on the undo-stack
862 // anylonger, now that we have
863 // keybindings for following
864 // references and returning from
865 // references. IMHO though, it
866 // should be the inset's own business
867 // to push or not push on the undo
868 // stack. They don't *have* to
869 // alter the document...
871 // ...or maybe the SetCursorParUndo()
872 // below isn't necessary at all anylonger?
873 if (inset_hit->LyxCode() == Inset::REF_CODE) {
874 text->SetCursorParUndo();
877 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
878 if (inset_hit->Editable()==Inset::HIGHLY_EDITABLE) {
879 // Highly editable inset, like math
880 UpdatableInset *inset = (UpdatableInset *)inset_hit;
881 inset->InsetButtonRelease(this, x, y, button);
883 inset_hit->Edit(this, x, y, button);
888 // check whether we want to open a float
892 if (text->cursor.pos <
893 text->cursor.par->Last()) {
894 c = text->cursor.par->
895 GetChar(text->cursor.pos);
897 if (c == LyXParagraph::META_FOOTNOTE
898 || c == LyXParagraph::META_MARGIN
899 || c == LyXParagraph::META_FIG
900 || c == LyXParagraph::META_TAB
901 || c == LyXParagraph::META_WIDE_FIG
902 || c == LyXParagraph::META_WIDE_TAB
903 || c == LyXParagraph::META_ALGORITHM){
905 } else if (text->cursor.pos - 1 >= 0) {
906 c = text->cursor.par->
907 GetChar(text->cursor.pos - 1);
908 if (c == LyXParagraph::META_FOOTNOTE
909 || c == LyXParagraph::META_MARGIN
910 || c == LyXParagraph::META_FIG
911 || c == LyXParagraph::META_TAB
912 || c == LyXParagraph::META_WIDE_FIG
913 || c == LyXParagraph::META_WIDE_TAB
914 || c == LyXParagraph::META_ALGORITHM){
915 // We are one step too far to the right
922 selection_possible = false;
927 // Do we want to close a float? (click on the float-label)
928 if (text->cursor.row->par->footnoteflag ==
929 LyXParagraph::OPEN_FOOTNOTE
930 //&& text->cursor.pos == 0
931 && text->cursor.row->previous &&
932 text->cursor.row->previous->par->
933 footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
934 LyXFont font(LyXFont::ALL_SANE);
935 font.setSize(LyXFont::SIZE_FOOTNOTE);
937 int box_x = 20; // LYX_PAPER_MARGIN;
938 box_x += font.textWidth(" wide-tab ", 10);
940 int screen_first = screen->first;
943 && y + screen_first > text->cursor.y -
944 text->cursor.row->baseline
945 && y + screen_first < text->cursor.y -
946 text->cursor.row->baseline
947 + font.maxAscent() * 1.2 + font.maxDescent() * 1.2) {
949 selection_possible = false;
954 // Maybe we want to edit a bibitem ale970302
955 if (text->cursor.par->bibkey && x < 20 +
956 bibitemMaxWidth(painter(),
959 params.textclass).defaultfont())) {
960 text->cursor.par->bibkey->Edit(this, 0, 0, 0);
968 * Returns an inset if inset was hit. 0 otherwise.
969 * If hit, the coordinates are changed relative to the inset.
970 * Otherwise coordinates are not changed, and false is returned.
972 Inset * BufferView::checkInsetHit(int & x, int & y, unsigned int button)
977 int y_tmp = y + screen->first;
980 text->SetCursorFromCoordinates(cursor, x, y_tmp);
982 bool move_cursor = true;
984 bool move_cursor = ((cursor.par != text->cursor.par) ||
985 (cursor.pos != text->cursor.pos)) && (button < 2);
988 if (cursor.pos < cursor.par->Last()
989 && cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET
990 && cursor.par->GetInset(cursor.pos)
991 && cursor.par->GetInset(cursor.pos)->Editable()) {
993 // Check whether the inset really was hit
994 Inset * tmpinset = cursor.par->GetInset(cursor.pos);
995 LyXFont font = text->GetFont(cursor.par, cursor.pos);
996 bool is_rtl = font.isVisibleRightToLeft();
1000 start_x = cursor.x - tmpinset->width(painter(), font);
1004 end_x = cursor.x + tmpinset->width(painter(), font);
1007 if (x > start_x && x < end_x
1008 && y_tmp > cursor.y - tmpinset->ascent(painter(), font)
1009 && y_tmp < cursor.y + tmpinset->descent(painter(), font)) {
1011 text->SetCursorFromCoordinates(x, y_tmp);
1013 // The origin of an inset is on the baseline
1014 y = y_tmp - (text->cursor.y);
1019 if ((cursor.pos - 1 >= 0) &&
1020 (cursor.par->GetChar(cursor.pos-1) == LyXParagraph::META_INSET) &&
1021 (cursor.par->GetInset(cursor.pos - 1)) &&
1022 (cursor.par->GetInset(cursor.pos - 1)->Editable())) {
1023 Inset * tmpinset = cursor.par->GetInset(cursor.pos-1);
1024 LyXFont font = text->GetFont(cursor.par, cursor.pos-1);
1025 bool is_rtl = font.isVisibleRightToLeft();
1029 start_x = cursor.x - tmpinset->width(painter(), font);
1033 end_x = cursor.x + tmpinset->width(painter(), font);
1035 if (x > start_x && x < end_x
1036 && y_tmp > cursor.y - tmpinset->ascent(painter(), font)
1037 && y_tmp < cursor.y + tmpinset->descent(painter(), font)) {
1039 text->SetCursorFromCoordinates(x, y_tmp);
1041 // The origin of an inset is on the baseline
1042 y = y_tmp - (text->cursor.y);
1049 void BufferView::workAreaExpose()
1051 // this is a hack to ensure that we only call this through
1052 // BufferView::redraw().
1057 static int work_area_width = -1;
1058 static int work_area_height = -1;
1060 bool widthChange = workarea->workWidth() != work_area_width;
1061 bool heightChange = workarea->height() != work_area_height;
1063 // update from work area
1064 work_area_width = workarea->workWidth();
1065 work_area_height = workarea->height();
1068 // All buffers need a resize
1069 bufferlist.resize();
1071 // Remove all texts from the textcache
1072 // This is not _really_ what we want to do. What
1073 // we really want to do is to delete in textcache
1074 // that does not have a BufferView with matching
1075 // width, but as long as we have only one BufferView
1076 // deleting all gives the same result.
1077 if (lyxerr.debugging())
1078 textcache.show(lyxerr, "Expose delete all");
1080 } else if (heightChange) {
1081 // Rebuild image of current screen
1083 // fitCursor() ensures we don't jump back
1084 // to the start of the document on vertical
1088 // The main window size has changed, repaint most stuff
1090 // ...including the minibuffer
1091 owner_->getMiniBuffer()->Init();
1093 } else if (screen) screen->Redraw();
1095 // Grey box when we don't have a buffer
1096 workarea->greyOut();
1099 // always make sure that the scrollbar is sane.
1101 owner_->updateLayoutChoice();
1106 // Callback for cursor timer
1107 void BufferView::cursorToggleCB(FL_OBJECT * ob, long)
1109 BufferView * view = static_cast<BufferView*>(ob->u_vdata);
1111 // Quite a nice place for asyncron Inset updating, isn't it?
1112 // Actually no! This is run even if no buffer exist... so (Lgb)
1113 if (view && !view->buffer_) {
1114 goto set_timer_and_return;
1118 // On my quest to solve the gs render hangups I am now
1119 // disabling the SIGHUP completely, and will do a wait
1120 // now and then instead. If the guess that xforms somehow
1121 // destroys something is true, this is likely (hopefully)
1122 // to solve the problem...at least I hope so. Lgb
1124 // ...Ok this seems to work...at least it does not make things
1125 // worse so far. However I still see gs processes that hangs.
1126 // I would really like to know _why_ they are hanging. Anyway
1127 // the solution without the SIGCHLD handler seems to be easier
1130 // When attaching gdb to a a running gs that hangs it shows
1131 // that it is waiting for input(?) Is it possible for us to
1132 // provide that input somehow? Or figure what it is expecing
1135 // One solution is to, after some time, look if there are some
1136 // old gs processes still running and if there are: kill them
1139 // Another solution is to provide the user an option to rerender
1140 // a picture. This would, for the picture in question, check if
1141 // there is a gs running for it, if so kill it, and start a new
1142 // rendering process.
1144 // these comments posted to lyx@via
1147 int pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1148 if (pid == -1) // error find out what is wrong
1149 ; // ignore it for now.
1151 sigchldhandler(pid, &status);
1154 view->updatelist.update(view);
1156 if (view && !view->screen){
1157 goto set_timer_and_return;
1160 if (view->lyx_focus && view->work_area_focus) {
1161 if (!view->the_locking_inset) {
1162 view->screen->CursorToggle();
1164 view->the_locking_inset->
1165 ToggleInsetCursor(view);
1167 goto set_timer_and_return;
1169 // Make sure that the cursor is visible.
1170 if (!view->the_locking_inset) {
1171 view->screen->ShowCursor();
1173 if (!view->the_locking_inset->isCursorVisible())
1174 view->the_locking_inset->
1175 ToggleInsetCursor(view);
1177 // This is only run when work_area_focus or lyx_focus is false.
1180 XGetInputFocus(fl_display, &tmpwin, &tmp);
1181 // Commenting this out, we have not had problems with this
1182 // for a long time. We will probably work on this code later
1183 // and we can reenable this debug code then. Now it only
1184 // anoying when debugging. (Lgb)
1185 //if (lyxerr.debugging(Debug::INFO)) {
1186 // lyxerr << "tmpwin: " << tmpwin
1187 // << "\nwindow: " << view->owner_->getForm()->window
1188 // << "\nwork_area_focus: " << view->work_area_focus
1189 // << "\nlyx_focus : " << view->lyx_focus
1192 if (tmpwin != view->owner_->getForm()->window) {
1193 view->lyx_focus = false;
1196 view->lyx_focus = true;
1197 if (!view->work_area_focus)
1200 goto set_timer_and_return;
1204 set_timer_and_return:
1205 fl_set_timer(ob, 0.4);
1212 string fromClipboard(Window win, XEvent * event)
1215 if (event->xselection.type == XA_STRING
1216 && event->xselection.property) {
1220 unsigned char * uc = 0;
1222 if (XGetWindowProperty(
1223 event->xselection.display, // display
1225 event->xselection.property, // property
1229 XA_STRING, // req_type
1230 &tmpatom, // actual_type_return
1231 &tmpint, // actual_format_return
1242 if (XGetWindowProperty(
1243 event->xselection.display, // display
1245 event->xselection.property, // property
1247 ul2/4+1, // long_length
1249 XA_STRING, // req_type
1250 &tmpatom, // actual_type_return
1251 &tmpint, // actual_format_return
1252 &ul1, // nitems_return
1253 &ul2, // bytes_after_return
1254 &uc // prop_return */
1259 strret = reinterpret_cast<char*>(uc);
1260 free(uc); // yes free!
1268 void BufferView::workAreaSelectionNotify(Window win, XEvent * event)
1270 if (buffer_ == 0) return;
1272 screen->HideCursor();
1274 string clb = fromClipboard(win, event);
1277 text->InsertStringA(clb);
1279 text->InsertStringB(clb);
1287 void BufferView::cursorPrevious()
1289 if (!text->cursor.row->previous) return;
1291 long y = screen->first;
1292 Row * cursorrow = text->cursor.row;
1293 text->SetCursorFromCoordinates(text->cursor.x_fix, y);
1295 // This is to allow jumping over large insets
1296 if ((cursorrow == text->cursor.row))
1299 if (text->cursor.row->height < workarea->height())
1300 screen->Draw(text->cursor.y
1301 - text->cursor.row->baseline
1302 + text->cursor.row->height
1303 - workarea->height() + 1 );
1307 void BufferView::cursorNext()
1309 if (!text->cursor.row->next) return;
1311 long y = screen->first;
1312 text->GetRowNearY(y);
1313 Row * cursorrow = text->cursor.row;
1314 text->SetCursorFromCoordinates(text->cursor.x_fix, y
1315 + workarea->height());
1317 // This is to allow jumping over large insets
1318 if ((cursorrow == text->cursor.row))
1321 if (text->cursor.row->height < workarea->height())
1322 screen->Draw(text->cursor.y
1323 - text->cursor.row->baseline);
1327 bool BufferView::available() const
1329 if (buffer_ && text) return true;
1334 void BufferView::beforeChange()
1337 text->ClearSelection();
1342 void BufferView::savePosition()
1344 backstack.push(buffer()->fileName(),
1350 void BufferView::restorePosition()
1352 if (backstack.empty()) return;
1355 string fname = backstack.pop(&x, &y);
1358 Buffer * b = bufferlist.exists(fname) ?
1359 bufferlist.getBuffer(fname) :
1360 bufferlist.loadLyXFile(fname); // don't ask, just load it
1362 text->SetCursorFromCoordinates(x, y);
1367 void BufferView::update(signed char f)
1369 owner()->updateLayoutChoice();
1371 if (!text->selection && f > -3)
1372 text->sel_cursor = text->cursor;
1375 text->FullRebreak();
1379 if (f != 3 && f != -3) {
1384 if (f == 1 || f == -1) {
1385 if (buffer()->isLyxClean()) {
1386 buffer()->markDirty();
1387 owner()->getMiniBuffer()->setTimer(4);
1389 buffer()->markDirty();
1395 void BufferView::smallUpdate(signed char f)
1397 screen->SmallUpdate();
1398 if (screen->TopCursorVisible()
1407 if (!text->selection)
1408 text->sel_cursor = text->cursor;
1410 if (f == 1 || f == -1) {
1411 if (buffer()->isLyxClean()) {
1412 buffer()->markDirty();
1413 owner()->getMiniBuffer()->setTimer(4);
1415 buffer()->markDirty();
1421 void BufferView::setState()
1423 if (!lyxrc.rtl_support)
1426 if (text->real_current_font.isVisibleRightToLeft()) {
1427 if (owner_->getIntl()->primarykeymap)
1428 owner_->getIntl()->KeyMapSec();
1430 if (!owner_->getIntl()->primarykeymap)
1431 owner_->getIntl()->KeyMapPrim();
1436 void BufferView::insetSleep()
1438 if (the_locking_inset && !inset_slept) {
1439 the_locking_inset->GetCursorPos(slx, sly);
1440 the_locking_inset->InsetUnlock(this);
1446 void BufferView::insetWakeup()
1448 if (the_locking_inset && inset_slept) {
1449 the_locking_inset->Edit(this, slx, sly, 0);
1450 inset_slept = false;
1455 void BufferView::insetUnlock()
1457 if (the_locking_inset) {
1458 if (!inset_slept) the_locking_inset->InsetUnlock(this);
1459 the_locking_inset = 0;
1461 inset_slept = false;
1466 bool BufferView::focus() const
1468 return workarea->hasFocus();
1472 void BufferView::focus(bool f)
1474 if (f) workarea->setFocus();
1478 bool BufferView::active() const
1480 return workarea->active();
1484 Painter & BufferView::getPainter() const
1486 return workarea->getPainter();
1490 unsigned short BufferView::paperWidth() const
1492 return text->paperWidth();
1496 bool BufferView::belowMouse() const
1498 return workarea->belowMouse();
1502 void BufferView::showCursor()
1505 screen->ShowCursor();
1509 void BufferView::hideCursor()
1512 screen->HideCursor();
1516 void BufferView::toggleSelection(bool b)
1519 screen->ToggleSelection(b);
1523 void BufferView::toggleToggle()
1526 screen->ToggleToggle();
1530 void BufferView::center()
1533 if (text->cursor.y > workarea->height() / 2) {
1534 screen->Draw(text->cursor.y - workarea->height() / 2);