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 "insets/insetbib.h"
36 #include "minibuffer.h"
37 #include "lyxscreen.h"
40 #include "lyx_gui_misc.h"
41 #include "BackStack.h"
46 #include "TextCache.h"
54 extern BufferList bufferlist;
56 void sigchldhandler(pid_t pid, int * status);
58 extern void SetXtermCursor(Window win);
59 extern bool input_prohibited;
60 extern bool selection_possible;
61 extern char ascii_type;
62 extern void MenuPasteSelection(char at);
63 extern void FreeUpdateTimer();
65 BufferView::BufferView(LyXView * o, int xpos, int ypos,
66 int width, int height)
71 workarea = new WorkArea(this, xpos, ypos, width, height);
75 current_scrollbar_value = 0;
76 // Activate the timer for the cursor
77 fl_set_timer(timer_cursor, 0.4);
79 work_area_focus = true;
81 the_locking_inset = 0;
86 BufferView::~BufferView()
92 Painter & BufferView::painter()
94 return workarea->getPainter();
98 void BufferView::buffer(Buffer * b)
100 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
104 buffer_->delUser(this);
106 // Put the old text into the TextCache, but
107 // only if the buffer is still loaded.
108 // Also set the owner of the test to 0
111 if (lyxerr.debugging())
112 textcache.show(lyxerr, "BufferView::buffer");
117 // Set current buffer
120 if (bufferlist.getState() == BufferList::CLOSING) return;
123 // screen is always deleted when the buffer is changed.
127 // If we are closing the buffer, use the first buffer as current
129 buffer_ = bufferlist.first();
133 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
134 buffer_->addUser(this);
135 owner_->getMenus()->showMenus();
136 // If we don't have a text object for this, we make one
138 resizeCurrentBuffer();
143 screen->first = screen->TopCursorVisible();
145 updateAllVisibleBufferRelatedPopups();
148 lyxerr[Debug::INFO] << " No Buffer!" << endl;
149 owner_->getMenus()->hideMenus();
153 // Also remove all remaining text's from the testcache.
154 // (there should not be any!) (if there is any it is a
156 if (lyxerr.debugging())
157 textcache.show(lyxerr, "buffer delete all");
160 // should update layoutchoice even if we don't have a buffer.
161 owner_->updateLayoutChoice();
162 owner_->getMiniBuffer()->Init();
163 owner_->updateWindowTitle();
167 void BufferView::updateScreen()
169 // Regenerate the screen.
171 screen = new LyXScreen(*workarea, text);
175 void BufferView::resize(int xpos, int ypos, int width, int height)
177 workarea->resize(xpos, ypos, width, height);
183 void BufferView::resize()
185 // This will resize the buffer. (Asger)
187 resizeCurrentBuffer();
191 void BufferView::redraw()
193 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
198 void BufferView::fitCursor()
200 if (screen) screen->FitCursor();
205 void BufferView::update()
207 if (screen) screen->Update();
211 void BufferView::updateScrollbar()
213 /* If the text is smaller than the working area, the scrollbar
214 * maximum must be the working area height. No scrolling will
218 workarea->setScrollbar(0, 1.0);
222 static long max2 = 0;
223 static long height2 = 0;
231 cbsf = screen->first;
233 // check if anything has changed.
235 height2 == workarea->height() &&
236 current_scrollbar_value == cbsf)
239 height2 = workarea->height();
240 current_scrollbar_value = cbsf;
242 if (cbth <= height2) { // text is smaller than screen
243 workarea->setScrollbar(0, 1.0); // right?
247 long maximum_height = workarea->height() * 3 / 4 + cbth;
251 double hfloat = workarea->height();
252 double maxfloat = maximum_height;
254 float slider_size = 0.0;
255 int slider_value = value;
257 workarea->setScrollbarBounds(0, text->height - workarea->height());
258 double lineh = text->DefaultHeight();
259 workarea->setScrollbarIncrements(lineh);
260 if (maxfloat > 0.0) {
261 if ((hfloat / maxfloat) * float(height2) < 3)
262 slider_size = 3.0/float(height2);
264 slider_size = hfloat / maxfloat;
266 slider_size = hfloat;
268 workarea->setScrollbar(slider_value, slider_size / workarea->height());
272 void BufferView::redoCurrentBuffer()
274 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
275 if (buffer_ && text) {
277 owner_->updateLayoutChoice();
282 int BufferView::resizeCurrentBuffer()
284 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
286 LyXParagraph * par = 0;
287 LyXParagraph * selstartpar = 0;
288 LyXParagraph * selendpar = 0;
297 owner_->getMiniBuffer()->Set(_("Formatting document..."));
300 par = text->cursor.par;
301 pos = text->cursor.pos;
302 selstartpar = text->sel_start_cursor.par;
303 selstartpos = text->sel_start_cursor.pos;
304 selendpar = text->sel_end_cursor.par;
305 selendpos = text->sel_end_cursor.pos;
306 selection = text->selection;
307 mark_set = text->mark_set;
309 text = new LyXText(this, workarea->workWidth(), buffer_);
311 // See if we have a text in TextCache that fits
312 // the new buffer_ with the correct width.
313 text = textcache.findFit(buffer_, workarea->workWidth());
315 if (lyxerr.debugging()) {
316 lyxerr << "Found a LyXText that fits:\n";
317 textcache.show(lyxerr, text);
319 // Set the owner of the newly found text
321 if (lyxerr.debugging())
322 textcache.show(lyxerr, "resizeCurrentBuffer");
324 text = new LyXText(this, workarea->workWidth(), buffer_);
330 text->selection = true;
331 /* at this point just to avoid the Delete-Empty-Paragraph
332 * Mechanism when setting the cursor */
333 text->mark_set = mark_set;
335 text->SetCursor(selstartpar, selstartpos);
336 text->sel_cursor = text->cursor;
337 text->SetCursor(selendpar, selendpos);
338 text->SetSelection();
339 text->SetCursor(par, pos);
341 text->SetCursor(par, pos);
342 text->sel_cursor = text->cursor;
343 text->selection = false;
346 screen->first = screen->TopCursorVisible(); /* this will scroll the
347 * screen such that the
352 owner_->getMiniBuffer()->Init();
356 // Now if the title form still exist kill it
363 void BufferView::gotoError()
368 screen->HideCursor();
373 if (!text->GotoNextError()) {
375 || text->cursor.par != text->FirstParagraph()) {
377 text->cursor.par = text->FirstParagraph();
378 text->cursor.pos = 0;
379 if (!text->GotoNextError()) {
381 owner_->getMiniBuffer()
382 ->Set(_("No more errors"));
386 owner_->getMiniBuffer()->Set(_("No more errors"));
391 text->sel_cursor = text->cursor;
396 void C_BufferView_CursorToggleCB(FL_OBJECT * ob, long buf)
398 BufferView::cursorToggleCB(ob, buf);
403 void BufferView::create_view()
412 timer_cursor = obj = fl_add_timer(FL_HIDDEN_TIMER,
413 0, 0, 0, 0, "Timer");
414 fl_set_object_callback(obj, C_BufferView_CursorToggleCB, 0);
419 // Callback for scrollbar up button
420 void BufferView::upCB(long time, int button)
422 if (buffer_ == 0) return;
441 XSync(fl_get_display(), 0);
445 // Callback for scrollbar slider
446 void BufferView::scrollCB(double value)
448 extern bool cursor_follows_scrollbar;
450 if (buffer_ == 0) return;
452 current_scrollbar_value = long(value);
453 if (current_scrollbar_value < 0)
454 current_scrollbar_value = 0;
459 screen->Draw(current_scrollbar_value);
461 if (cursor_follows_scrollbar) {
462 LyXText * vbt = text;
463 int height = vbt->DefaultHeight();
465 if (vbt->cursor.y < screen->first + height) {
466 vbt->SetCursorFromCoordinates(0,
469 } else if (vbt->cursor.y >
470 screen->first + workarea->height() - height) {
471 vbt->SetCursorFromCoordinates(0,
481 // Callback for scrollbar down button
482 void BufferView::downCB(long time, int button)
484 if (buffer_ == 0) return;
500 int BufferView::scrollUp(long time)
502 if (buffer_ == 0) return 0;
503 if (!screen) return 0;
505 double value = workarea->getScrollbarValue();
507 if (value == 0) return 0;
509 float add_value = (text->DefaultHeight()
510 + float(time) * float(time) * 0.125);
512 if (add_value > workarea->height())
513 add_value = float(workarea->height() -
514 text->DefaultHeight());
521 workarea->setScrollbarValue(value);
528 int BufferView::scrollDown(long time)
530 if (buffer_ == 0) return 0;
531 if (!screen) return 0;
533 double value= workarea->getScrollbarValue();
534 pair<double, double> p = workarea->getScrollbarBounds();
535 double max = p.second;
537 if (value == max) return 0;
539 float add_value = (text->DefaultHeight()
540 + float(time) * float(time) * 0.125);
542 if (add_value > workarea->height())
543 add_value = float(workarea->height() -
544 text->DefaultHeight());
551 workarea->setScrollbarValue(value);
558 void BufferView::scrollUpOnePage()
560 if (buffer_ == 0) return;
563 long y = screen->first;
567 Row * row = text->GetRowNearY(y);
569 y = y - workarea->height() + row->height;
571 workarea->setScrollbarValue(y);
577 void BufferView::scrollDownOnePage()
579 if (buffer_ == 0) return;
582 long y = screen->first;
584 if (y > text->height - workarea->height())
587 y += workarea->height();
588 text->GetRowNearY(y);
590 workarea->setScrollbarValue(y);
596 void BufferView::workAreaMotionNotify(int x, int y, unsigned int state)
598 if (buffer_ == 0 || !screen) return;
600 // Check for inset locking
601 if (the_locking_inset) {
602 LyXCursor cursor = text->cursor;
604 InsetMotionNotify(this,
611 // Only use motion with button 1
612 if (!state & Button1MotionMask)
615 /* The selection possible is needed, that only motion events are
616 * used, where the bottom press event was on the drawing area too */
617 if (selection_possible) {
618 screen->HideCursor();
620 text->SetCursorFromCoordinates(x, y + screen->first);
622 if (!text->selection)
623 update(-3); // Maybe an empty line was deleted
625 text->SetSelection();
626 screen->ToggleToggle();
627 if (screen->FitCursor())
629 screen->ShowCursor();
635 extern int bibitemMaxWidth(Painter &, LyXFont const &);
638 // Single-click on work area
639 void BufferView::workAreaButtonPress(int xpos, int ypos, unsigned int button)
644 if (buffer_ == 0 || !screen) return;
646 Inset * inset_hit = checkInsetHit(xpos, ypos);
648 // ok ok, this is a hack.
649 if (button == 4 || button == 5) {
652 scrollUp(100); // This number is only temporary
660 if (the_locking_inset) {
661 // We are in inset locking mode
663 /* Check whether the inset was hit. If not reset mode,
664 otherwise give the event to the inset */
665 if (inset_hit == the_locking_inset) {
667 InsetButtonPress(this,
672 unlockInset(the_locking_inset);
677 selection_possible = true;
678 screen->HideCursor();
680 // Right button mouse click on a table
682 (text->cursor.par->table ||
683 text->MouseHitInTable(xpos, ypos + screen->first))) {
684 // Set the cursor to the press-position
685 text->SetCursorFromCoordinates(xpos, ypos + screen->first);
688 // Only show the table popup if the hit is in
690 if (!text->HitInTable(text->cursor.row, xpos))
693 // Hit above or below the table?
695 if (!text->selection) {
696 screen->ToggleSelection();
697 text->ClearSelection();
702 // Popup table popup when on a table.
703 // This is obviously temporary, since we
704 // should be able to popup various
705 // context-sensitive-menus with the
706 // the right mouse. So this should be done more
707 // general in the future. Matthias.
708 selection_possible = false;
710 ->Dispatch(LFUN_LAYOUT_TABLE,
716 int screen_first = screen->first;
718 // Middle button press pastes if we have a selection
719 bool paste_internally = false;
721 && text->selection) {
722 owner_->getLyXFunc()->Dispatch(LFUN_COPY);
723 paste_internally = true;
726 // Clear the selection
727 screen->ToggleSelection();
728 text->ClearSelection();
733 // Single left click in math inset?
734 if ((inset_hit != 0) &&
735 (inset_hit->Editable()==Inset::HIGHLY_EDITABLE)) {
736 // Highly editable inset, like math
737 UpdatableInset *inset = (UpdatableInset *)inset_hit;
738 selection_possible = false;
739 owner_->updateLayoutChoice();
740 owner_->getMiniBuffer()->Set(inset->EditMessage());
741 inset->InsetButtonPress(this, xpos, ypos, button);
742 inset->Edit(this, xpos, ypos, button);
746 // Right click on a footnote flag opens float menu
748 selection_possible = false;
752 text->SetCursorFromCoordinates(xpos, ypos + screen_first);
754 text->sel_cursor = text->cursor;
755 text->cursor.x_fix = text->cursor.x;
757 owner_->updateLayoutChoice();
758 if (screen->FitCursor()){
760 selection_possible = false;
763 // Insert primary selection with middle mouse
764 // if there is a local selection in the current buffer,
767 if (paste_internally)
768 owner_->getLyXFunc()->Dispatch(LFUN_PASTE);
770 owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION,
772 selection_possible = false;
778 void BufferView::doubleClick(int /*x*/, int /*y*/, unsigned int button)
781 if (buffer_ && !the_locking_inset) {
782 if (screen && button == 1) {
783 screen->HideCursor();
784 screen->ToggleSelection();
786 screen->ToggleSelection(false);
787 /* This will fit the cursor on the screen
795 void BufferView::tripleClick(int /*x*/, int /*y*/, unsigned int button)
798 if (buffer_ && screen && button == 1) {
799 screen->HideCursor();
800 screen->ToggleSelection();
802 text->sel_cursor = text->cursor;
804 text->SetSelection();
805 screen->ToggleSelection(false);
806 /* This will fit the cursor on the screen
813 void BufferView::workAreaButtonRelease(int x, int y, unsigned int button)
815 if (buffer_ == 0 || screen == 0) return;
817 // If we hit an inset, we have the inset coordinates in these
818 // and inset_hit points to the inset. If we do not hit an
819 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
820 Inset * inset_hit = checkInsetHit(x, y);
822 if (the_locking_inset) {
823 // We are in inset locking mode.
825 /* LyX does a kind of work-area grabbing for insets.
826 Only a ButtonPress Event outside the inset will
827 force a InsetUnlock. */
829 InsetButtonRelease(this, x, y, button);
833 selection_possible = false;
834 if (text->cursor.par->table) {
836 NumberOfCell(text->cursor.par,
838 if (text->cursor.par->table->IsContRow(cell) &&
839 text->cursor.par->table->
840 CellHasContRow(text->cursor.par->table->
841 GetCellAbove(cell))<0) {
846 if (button >= 2) return;
849 owner_->getMiniBuffer()->Set(CurrentState());
851 // Did we hit an editable inset?
852 if (inset_hit != 0) {
853 // Inset like error, notes and figures
854 selection_possible = false;
856 #warning fix this proper in 0.13
858 // Following a ref shouldn't issue
859 // a push on the undo-stack
860 // anylonger, now that we have
861 // keybindings for following
862 // references and returning from
863 // references. IMHO though, it
864 // should be the inset's own business
865 // to push or not push on the undo
866 // stack. They don't *have* to
867 // alter the document...
869 // ...or maybe the SetCursorParUndo()
870 // below isn't necessary at all anylonger?
871 if (inset_hit->LyxCode() == Inset::REF_CODE) {
872 text->SetCursorParUndo();
875 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
876 if (inset_hit->Editable()==Inset::HIGHLY_EDITABLE) {
877 // Highly editable inset, like math
878 UpdatableInset *inset = (UpdatableInset *)inset_hit;
879 inset->InsetButtonRelease(this, x, y, button);
881 inset_hit->Edit(this, x, y, button);
886 // check whether we want to open a float
890 if (text->cursor.pos <
891 text->cursor.par->Last()) {
892 c = text->cursor.par->
893 GetChar(text->cursor.pos);
895 if (c == LyXParagraph::META_FOOTNOTE
896 || c == LyXParagraph::META_MARGIN
897 || c == LyXParagraph::META_FIG
898 || c == LyXParagraph::META_TAB
899 || c == LyXParagraph::META_WIDE_FIG
900 || c == LyXParagraph::META_WIDE_TAB
901 || c == LyXParagraph::META_ALGORITHM){
903 } else if (text->cursor.pos - 1 >= 0) {
904 c = text->cursor.par->
905 GetChar(text->cursor.pos - 1);
906 if (c == LyXParagraph::META_FOOTNOTE
907 || c == LyXParagraph::META_MARGIN
908 || c == LyXParagraph::META_FIG
909 || c == LyXParagraph::META_TAB
910 || c == LyXParagraph::META_WIDE_FIG
911 || c == LyXParagraph::META_WIDE_TAB
912 || c == LyXParagraph::META_ALGORITHM){
913 // We are one step too far to the right
920 selection_possible = false;
925 // Do we want to close a float? (click on the float-label)
926 if (text->cursor.row->par->footnoteflag ==
927 LyXParagraph::OPEN_FOOTNOTE
928 //&& text->cursor.pos == 0
929 && text->cursor.row->previous &&
930 text->cursor.row->previous->par->
931 footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
932 LyXFont font(LyXFont::ALL_SANE);
933 font.setSize(LyXFont::SIZE_FOOTNOTE);
935 int box_x = 20; // LYX_PAPER_MARGIN;
936 box_x += font.textWidth(" wide-tab ", 10);
938 int screen_first = screen->first;
941 && y + screen_first > text->cursor.y -
942 text->cursor.row->baseline
943 && y + screen_first < text->cursor.y -
944 text->cursor.row->baseline
945 + font.maxAscent() * 1.2 + font.maxDescent() * 1.2) {
947 selection_possible = false;
952 // Maybe we want to edit a bibitem ale970302
953 if (text->cursor.par->bibkey && x < 20 +
954 bibitemMaxWidth(painter(),
957 params.textclass).defaultfont())) {
958 text->cursor.par->bibkey->Edit(this, 0, 0, 0);
966 * Returns an inset if inset was hit. 0 otherwise.
967 * If hit, the coordinates are changed relative to the inset.
968 * Otherwise coordinates are not changed, and false is returned.
970 Inset * BufferView::checkInsetHit(int & x, int & y)
975 int y_tmp = y + screen->first;
977 LyXCursor & old_cursor = text->cursor;
978 text->SetCursorFromCoordinates(x,y);
979 LyXCursor & cursor = text->cursor;
981 bool is_rtl = text->real_current_font.isVisibleRightToLeft();
983 if (cursor.pos < cursor.par->Last()
984 && cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET
985 && cursor.par->GetInset(cursor.pos)
986 && cursor.par->GetInset(cursor.pos)->Editable()) {
988 // Check whether the inset really was hit
989 Inset * tmpinset = cursor.par->GetInset(cursor.pos);
990 LyXFont font = text->GetFont(cursor.par, cursor.pos);
993 start_x = cursor.x - tmpinset->width(painter(), font);
997 end_x = cursor.x + tmpinset->width(painter(), font);
1000 if (x > start_x && x < end_x
1001 && y_tmp > cursor.y - tmpinset->ascent(painter(), font)
1002 && y_tmp < cursor.y + tmpinset->descent(painter(), font)) {
1004 // The origin of an inset is on the baseline
1005 y = y_tmp - (cursor.y);
1010 if ((cursor.pos - 1 >= 0) &&
1011 (cursor.par->GetChar(cursor.pos-1) == LyXParagraph::META_INSET) &&
1012 (cursor.par->GetInset(cursor.pos - 1)) &&
1013 (cursor.par->GetInset(cursor.pos - 1)->Editable())) {
1015 Inset * tmpinset = cursor.par->GetInset(cursor.pos);
1016 LyXFont font = text->GetFont(cursor.par, cursor.pos);
1019 start_x = cursor.x - tmpinset->width(painter(), font);
1023 end_x = cursor.x + tmpinset->width(painter(), font);
1025 if (x > start_x && x < end_x
1026 && y_tmp > cursor.y - tmpinset->ascent(painter(), font)
1027 && y_tmp < cursor.y + tmpinset->descent(painter(), font)) {
1029 // The origin of an inset is on the baseline
1030 y = y_tmp - (cursor.y);
1033 text->CursorRight();
1036 text->SetCursor(old_cursor.par, old_cursor.pos);
1040 void BufferView::workAreaExpose()
1042 // this is a hack to ensure that we only call this through
1043 // BufferView::redraw().
1048 static int work_area_width = -1;
1049 static int work_area_height = -1;
1051 bool widthChange = workarea->workWidth() != work_area_width;
1052 bool heightChange = workarea->height() != work_area_height;
1054 // update from work area
1055 work_area_width = workarea->workWidth();
1056 work_area_height = workarea->height();
1059 // All buffers need a resize
1060 bufferlist.resize();
1062 // Remove all texts from the textcache
1063 // This is not _really_ what we want to do. What
1064 // we really want to do is to delete in textcache
1065 // that does not have a BufferView with matching
1066 // width, but as long as we have only one BufferView
1067 // deleting all gives the same result.
1068 if (lyxerr.debugging())
1069 textcache.show(lyxerr, "Expose delete all");
1071 } else if (heightChange) {
1072 // Rebuild image of current screen
1074 // fitCursor() ensures we don't jump back
1075 // to the start of the document on vertical
1079 // The main window size has changed, repaint most stuff
1081 // ...including the minibuffer
1082 owner_->getMiniBuffer()->Init();
1084 } else if (screen) screen->Redraw();
1086 // Grey box when we don't have a buffer
1087 workarea->greyOut();
1090 // always make sure that the scrollbar is sane.
1092 owner_->updateLayoutChoice();
1097 // Callback for cursor timer
1098 void BufferView::cursorToggleCB(FL_OBJECT * ob, long)
1100 BufferView * view = static_cast<BufferView*>(ob->u_vdata);
1102 // Quite a nice place for asyncron Inset updating, isn't it?
1103 // Actually no! This is run even if no buffer exist... so (Lgb)
1104 if (view && !view->buffer_) {
1105 goto set_timer_and_return;
1109 // On my quest to solve the gs render hangups I am now
1110 // disabling the SIGHUP completely, and will do a wait
1111 // now and then instead. If the guess that xforms somehow
1112 // destroys something is true, this is likely (hopefully)
1113 // to solve the problem...at least I hope so. Lgb
1115 // ...Ok this seems to work...at least it does not make things
1116 // worse so far. However I still see gs processes that hangs.
1117 // I would really like to know _why_ they are hanging. Anyway
1118 // the solution without the SIGCHLD handler seems to be easier
1121 // When attaching gdb to a a running gs that hangs it shows
1122 // that it is waiting for input(?) Is it possible for us to
1123 // provide that input somehow? Or figure what it is expecing
1126 // One solution is to, after some time, look if there are some
1127 // old gs processes still running and if there are: kill them
1130 // Another solution is to provide the user an option to rerender
1131 // a picture. This would, for the picture in question, check if
1132 // there is a gs running for it, if so kill it, and start a new
1133 // rendering process.
1135 // these comments posted to lyx@via
1138 int pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1139 if (pid == -1) // error find out what is wrong
1140 ; // ignore it for now.
1142 sigchldhandler(pid, &status);
1145 view->updatelist.update(view);
1147 if (view && !view->screen){
1148 goto set_timer_and_return;
1151 if (view->lyx_focus && view->work_area_focus) {
1152 if (!view->the_locking_inset) {
1153 view->screen->CursorToggle();
1155 view->the_locking_inset->
1156 ToggleInsetCursor(view);
1158 goto set_timer_and_return;
1160 // Make sure that the cursor is visible.
1161 if (!view->the_locking_inset) {
1162 view->screen->ShowCursor();
1164 if (!view->the_locking_inset->isCursorVisible())
1165 view->the_locking_inset->
1166 ToggleInsetCursor(view);
1168 // This is only run when work_area_focus or lyx_focus is false.
1171 XGetInputFocus(fl_display, &tmpwin, &tmp);
1172 // Commenting this out, we have not had problems with this
1173 // for a long time. We will probably work on this code later
1174 // and we can reenable this debug code then. Now it only
1175 // anoying when debugging. (Lgb)
1176 //if (lyxerr.debugging(Debug::INFO)) {
1177 // lyxerr << "tmpwin: " << tmpwin
1178 // << "\nwindow: " << view->owner_->getForm()->window
1179 // << "\nwork_area_focus: " << view->work_area_focus
1180 // << "\nlyx_focus : " << view->lyx_focus
1183 if (tmpwin != view->owner_->getForm()->window) {
1184 view->lyx_focus = false;
1187 view->lyx_focus = true;
1188 if (!view->work_area_focus)
1191 goto set_timer_and_return;
1195 set_timer_and_return:
1196 fl_set_timer(ob, 0.4);
1203 string fromClipboard(Window win, XEvent * event)
1206 if (event->xselection.type == XA_STRING
1207 && event->xselection.property) {
1211 unsigned char * uc = 0;
1213 if (XGetWindowProperty(
1214 event->xselection.display, // display
1216 event->xselection.property, // property
1220 XA_STRING, // req_type
1221 &tmpatom, // actual_type_return
1222 &tmpint, // actual_format_return
1233 if (XGetWindowProperty(
1234 event->xselection.display, // display
1236 event->xselection.property, // property
1238 ul2/4+1, // long_length
1240 XA_STRING, // req_type
1241 &tmpatom, // actual_type_return
1242 &tmpint, // actual_format_return
1243 &ul1, // nitems_return
1244 &ul2, // bytes_after_return
1245 &uc // prop_return */
1250 strret = reinterpret_cast<char*>(uc);
1251 free(uc); // yes free!
1259 void BufferView::workAreaSelectionNotify(Window win, XEvent * event)
1261 if (buffer_ == 0) return;
1263 screen->HideCursor();
1265 string clb = fromClipboard(win, event);
1268 text->InsertStringA(clb);
1270 text->InsertStringB(clb);
1278 void BufferView::cursorPrevious()
1280 if (!text->cursor.row->previous) return;
1282 long y = screen->first;
1283 Row * cursorrow = text->cursor.row;
1284 text->SetCursorFromCoordinates(text->cursor.x_fix, y);
1286 // This is to allow jumping over large insets
1287 if ((cursorrow == text->cursor.row))
1290 if (text->cursor.row->height < workarea->height())
1291 screen->Draw(text->cursor.y
1292 - text->cursor.row->baseline
1293 + text->cursor.row->height
1294 - workarea->height() + 1 );
1298 void BufferView::cursorNext()
1300 if (!text->cursor.row->next) return;
1302 long y = screen->first;
1303 text->GetRowNearY(y);
1304 Row * cursorrow = text->cursor.row;
1305 text->SetCursorFromCoordinates(text->cursor.x_fix, y
1306 + workarea->height());
1308 // This is to allow jumping over large insets
1309 if ((cursorrow == text->cursor.row))
1312 if (text->cursor.row->height < workarea->height())
1313 screen->Draw(text->cursor.y
1314 - text->cursor.row->baseline);
1318 bool BufferView::available() const
1320 if (buffer_ && text) return true;
1325 void BufferView::beforeChange()
1328 text->ClearSelection();
1333 void BufferView::savePosition()
1335 backstack.push(buffer()->fileName(),
1341 void BufferView::restorePosition()
1343 if (backstack.empty()) return;
1346 string fname = backstack.pop(&x, &y);
1349 Buffer * b = bufferlist.exists(fname) ?
1350 bufferlist.getBuffer(fname) :
1351 bufferlist.loadLyXFile(fname); // don't ask, just load it
1353 text->SetCursorFromCoordinates(x, y);
1358 void BufferView::update(signed char f)
1360 owner()->updateLayoutChoice();
1362 if (!text->selection && f > -3)
1363 text->sel_cursor = text->cursor;
1366 text->FullRebreak();
1370 if (f != 3 && f != -3) {
1375 if (f == 1 || f == -1) {
1376 if (buffer()->isLyxClean()) {
1377 buffer()->markDirty();
1378 owner()->getMiniBuffer()->setTimer(4);
1380 buffer()->markDirty();
1386 void BufferView::smallUpdate(signed char f)
1388 screen->SmallUpdate();
1389 if (screen->TopCursorVisible()
1398 if (!text->selection)
1399 text->sel_cursor = text->cursor;
1401 if (f == 1 || f == -1) {
1402 if (buffer()->isLyxClean()) {
1403 buffer()->markDirty();
1404 owner()->getMiniBuffer()->setTimer(4);
1406 buffer()->markDirty();
1412 void BufferView::setState()
1414 if (!lyxrc.rtl_support)
1417 if (text->real_current_font.isVisibleRightToLeft()) {
1418 if (owner_->getIntl()->primarykeymap)
1419 owner_->getIntl()->KeyMapSec();
1421 if (!owner_->getIntl()->primarykeymap)
1422 owner_->getIntl()->KeyMapPrim();
1427 void BufferView::insetSleep()
1429 if (the_locking_inset && !inset_slept) {
1430 the_locking_inset->GetCursorPos(slx, sly);
1431 the_locking_inset->InsetUnlock(this);
1437 void BufferView::insetWakeup()
1439 if (the_locking_inset && inset_slept) {
1440 the_locking_inset->Edit(this, slx, sly, 0);
1441 inset_slept = false;
1446 void BufferView::insetUnlock()
1448 if (the_locking_inset) {
1449 if (!inset_slept) the_locking_inset->InsetUnlock(this);
1450 the_locking_inset = 0;
1452 inset_slept = false;
1457 bool BufferView::focus() const
1459 return workarea->hasFocus();
1463 void BufferView::focus(bool f)
1465 if (f) workarea->setFocus();
1469 bool BufferView::active() const
1471 return workarea->active();
1475 Painter & BufferView::getPainter() const
1477 return workarea->getPainter();
1481 unsigned short BufferView::paperWidth() const
1483 return text->paperWidth();
1487 bool BufferView::belowMouse() const
1489 return workarea->belowMouse();
1493 void BufferView::showCursor()
1496 screen->ShowCursor();
1500 void BufferView::hideCursor()
1503 screen->HideCursor();
1507 void BufferView::toggleSelection(bool b)
1510 screen->ToggleSelection(b);
1514 void BufferView::toggleToggle()
1517 screen->ToggleToggle();
1521 void BufferView::center()
1524 if (text->cursor.y > workarea->height() / 2) {
1525 screen->Draw(text->cursor.y - workarea->height() / 2);