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, button);
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 if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
753 text->SetCursorFromCoordinates(xpos, ypos + screen_first);
755 text->sel_cursor = text->cursor;
756 text->cursor.x_fix = text->cursor.x;
758 owner_->updateLayoutChoice();
759 if (screen->FitCursor()){
761 selection_possible = false;
764 // Insert primary selection with middle mouse
765 // if there is a local selection in the current buffer,
768 if (paste_internally)
769 owner_->getLyXFunc()->Dispatch(LFUN_PASTE);
771 owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION,
773 selection_possible = false;
779 void BufferView::doubleClick(int /*x*/, int /*y*/, unsigned int button)
782 if (buffer_ && !the_locking_inset) {
783 if (screen && button == 1) {
784 screen->HideCursor();
785 screen->ToggleSelection();
787 screen->ToggleSelection(false);
788 /* This will fit the cursor on the screen
796 void BufferView::tripleClick(int /*x*/, int /*y*/, unsigned int button)
799 if (buffer_ && screen && button == 1) {
800 screen->HideCursor();
801 screen->ToggleSelection();
803 text->sel_cursor = text->cursor;
805 text->SetSelection();
806 screen->ToggleSelection(false);
807 /* This will fit the cursor on the screen
814 void BufferView::workAreaButtonRelease(int x, int y, unsigned int button)
816 if (buffer_ == 0 || screen == 0) return;
818 // If we hit an inset, we have the inset coordinates in these
819 // and inset_hit points to the inset. If we do not hit an
820 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
821 Inset * inset_hit = checkInsetHit(x, y, button);
823 if (the_locking_inset) {
824 // We are in inset locking mode.
826 /* LyX does a kind of work-area grabbing for insets.
827 Only a ButtonPress Event outside the inset will
828 force a InsetUnlock. */
830 InsetButtonRelease(this, x, y, button);
834 selection_possible = false;
835 if (text->cursor.par->table) {
837 NumberOfCell(text->cursor.par,
839 if (text->cursor.par->table->IsContRow(cell) &&
840 text->cursor.par->table->
841 CellHasContRow(text->cursor.par->table->
842 GetCellAbove(cell))<0) {
847 if (button >= 2) return;
850 owner_->getMiniBuffer()->Set(CurrentState());
852 // Did we hit an editable inset?
853 if (inset_hit != 0) {
854 // Inset like error, notes and figures
855 selection_possible = false;
857 #warning fix this proper in 0.13
859 // Following a ref shouldn't issue
860 // a push on the undo-stack
861 // anylonger, now that we have
862 // keybindings for following
863 // references and returning from
864 // references. IMHO though, it
865 // should be the inset's own business
866 // to push or not push on the undo
867 // stack. They don't *have* to
868 // alter the document...
870 // ...or maybe the SetCursorParUndo()
871 // below isn't necessary at all anylonger?
872 if (inset_hit->LyxCode() == Inset::REF_CODE) {
873 text->SetCursorParUndo();
876 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
877 if (inset_hit->Editable()==Inset::HIGHLY_EDITABLE) {
878 // Highly editable inset, like math
879 UpdatableInset *inset = (UpdatableInset *)inset_hit;
880 inset->InsetButtonRelease(this, x, y, button);
882 inset_hit->Edit(this, x, y, button);
887 // check whether we want to open a float
891 if (text->cursor.pos <
892 text->cursor.par->Last()) {
893 c = text->cursor.par->
894 GetChar(text->cursor.pos);
896 if (c == LyXParagraph::META_FOOTNOTE
897 || c == LyXParagraph::META_MARGIN
898 || c == LyXParagraph::META_FIG
899 || c == LyXParagraph::META_TAB
900 || c == LyXParagraph::META_WIDE_FIG
901 || c == LyXParagraph::META_WIDE_TAB
902 || c == LyXParagraph::META_ALGORITHM){
904 } else if (text->cursor.pos - 1 >= 0) {
905 c = text->cursor.par->
906 GetChar(text->cursor.pos - 1);
907 if (c == LyXParagraph::META_FOOTNOTE
908 || c == LyXParagraph::META_MARGIN
909 || c == LyXParagraph::META_FIG
910 || c == LyXParagraph::META_TAB
911 || c == LyXParagraph::META_WIDE_FIG
912 || c == LyXParagraph::META_WIDE_TAB
913 || c == LyXParagraph::META_ALGORITHM){
914 // We are one step too far to the right
921 selection_possible = false;
926 // Do we want to close a float? (click on the float-label)
927 if (text->cursor.row->par->footnoteflag ==
928 LyXParagraph::OPEN_FOOTNOTE
929 //&& text->cursor.pos == 0
930 && text->cursor.row->previous &&
931 text->cursor.row->previous->par->
932 footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
933 LyXFont font(LyXFont::ALL_SANE);
934 font.setSize(LyXFont::SIZE_FOOTNOTE);
936 int box_x = 20; // LYX_PAPER_MARGIN;
937 box_x += font.textWidth(" wide-tab ", 10);
939 int screen_first = screen->first;
942 && y + screen_first > text->cursor.y -
943 text->cursor.row->baseline
944 && y + screen_first < text->cursor.y -
945 text->cursor.row->baseline
946 + font.maxAscent() * 1.2 + font.maxDescent() * 1.2) {
948 selection_possible = false;
953 // Maybe we want to edit a bibitem ale970302
954 if (text->cursor.par->bibkey && x < 20 +
955 bibitemMaxWidth(painter(),
958 params.textclass).defaultfont())) {
959 text->cursor.par->bibkey->Edit(this, 0, 0, 0);
967 * Returns an inset if inset was hit. 0 otherwise.
968 * If hit, the coordinates are changed relative to the inset.
969 * Otherwise coordinates are not changed, and false is returned.
971 Inset * BufferView::checkInsetHit(int & x, int & y, unsigned int button)
976 int y_tmp = y + screen->first;
979 text->SetCursorFromCoordinates(cursor, x, y_tmp);
981 bool move_cursor = true;
983 bool move_cursor = ((cursor.par != text->cursor.par) ||
984 (cursor.pos != text->cursor.pos)) && (button < 2);
987 if (cursor.pos < cursor.par->Last()
988 && cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET
989 && cursor.par->GetInset(cursor.pos)
990 && cursor.par->GetInset(cursor.pos)->Editable()) {
992 // Check whether the inset really was hit
993 Inset * tmpinset = cursor.par->GetInset(cursor.pos);
994 LyXFont font = text->GetFont(cursor.par, cursor.pos);
995 bool is_rtl = font.isVisibleRightToLeft();
999 start_x = cursor.x - tmpinset->width(painter(), font);
1003 end_x = cursor.x + tmpinset->width(painter(), font);
1006 if (x > start_x && x < end_x
1007 && y_tmp > cursor.y - tmpinset->ascent(painter(), font)
1008 && y_tmp < cursor.y + tmpinset->descent(painter(), font)) {
1010 text->SetCursorFromCoordinates(x, y_tmp);
1012 // The origin of an inset is on the baseline
1013 y = y_tmp - (text->cursor.y);
1018 if ((cursor.pos - 1 >= 0) &&
1019 (cursor.par->GetChar(cursor.pos-1) == LyXParagraph::META_INSET) &&
1020 (cursor.par->GetInset(cursor.pos - 1)) &&
1021 (cursor.par->GetInset(cursor.pos - 1)->Editable())) {
1022 Inset * tmpinset = cursor.par->GetInset(cursor.pos-1);
1023 LyXFont font = text->GetFont(cursor.par, cursor.pos-1);
1024 bool is_rtl = font.isVisibleRightToLeft();
1028 start_x = cursor.x - tmpinset->width(painter(), font);
1032 end_x = cursor.x + tmpinset->width(painter(), font);
1034 if (x > start_x && x < end_x
1035 && y_tmp > cursor.y - tmpinset->ascent(painter(), font)
1036 && y_tmp < cursor.y + tmpinset->descent(painter(), font)) {
1038 text->SetCursorFromCoordinates(x, y_tmp);
1040 // The origin of an inset is on the baseline
1041 y = y_tmp - (text->cursor.y);
1048 void BufferView::workAreaExpose()
1050 // this is a hack to ensure that we only call this through
1051 // BufferView::redraw().
1056 static int work_area_width = -1;
1057 static int work_area_height = -1;
1059 bool widthChange = workarea->workWidth() != work_area_width;
1060 bool heightChange = workarea->height() != work_area_height;
1062 // update from work area
1063 work_area_width = workarea->workWidth();
1064 work_area_height = workarea->height();
1067 // All buffers need a resize
1068 bufferlist.resize();
1070 // Remove all texts from the textcache
1071 // This is not _really_ what we want to do. What
1072 // we really want to do is to delete in textcache
1073 // that does not have a BufferView with matching
1074 // width, but as long as we have only one BufferView
1075 // deleting all gives the same result.
1076 if (lyxerr.debugging())
1077 textcache.show(lyxerr, "Expose delete all");
1079 } else if (heightChange) {
1080 // Rebuild image of current screen
1082 // fitCursor() ensures we don't jump back
1083 // to the start of the document on vertical
1087 // The main window size has changed, repaint most stuff
1089 // ...including the minibuffer
1090 owner_->getMiniBuffer()->Init();
1092 } else if (screen) screen->Redraw();
1094 // Grey box when we don't have a buffer
1095 workarea->greyOut();
1098 // always make sure that the scrollbar is sane.
1100 owner_->updateLayoutChoice();
1105 // Callback for cursor timer
1106 void BufferView::cursorToggleCB(FL_OBJECT * ob, long)
1108 BufferView * view = static_cast<BufferView*>(ob->u_vdata);
1110 // Quite a nice place for asyncron Inset updating, isn't it?
1111 // Actually no! This is run even if no buffer exist... so (Lgb)
1112 if (view && !view->buffer_) {
1113 goto set_timer_and_return;
1117 // On my quest to solve the gs render hangups I am now
1118 // disabling the SIGHUP completely, and will do a wait
1119 // now and then instead. If the guess that xforms somehow
1120 // destroys something is true, this is likely (hopefully)
1121 // to solve the problem...at least I hope so. Lgb
1123 // ...Ok this seems to work...at least it does not make things
1124 // worse so far. However I still see gs processes that hangs.
1125 // I would really like to know _why_ they are hanging. Anyway
1126 // the solution without the SIGCHLD handler seems to be easier
1129 // When attaching gdb to a a running gs that hangs it shows
1130 // that it is waiting for input(?) Is it possible for us to
1131 // provide that input somehow? Or figure what it is expecing
1134 // One solution is to, after some time, look if there are some
1135 // old gs processes still running and if there are: kill them
1138 // Another solution is to provide the user an option to rerender
1139 // a picture. This would, for the picture in question, check if
1140 // there is a gs running for it, if so kill it, and start a new
1141 // rendering process.
1143 // these comments posted to lyx@via
1146 int pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1147 if (pid == -1) // error find out what is wrong
1148 ; // ignore it for now.
1150 sigchldhandler(pid, &status);
1153 view->updatelist.update(view);
1155 if (view && !view->screen){
1156 goto set_timer_and_return;
1159 if (view->lyx_focus && view->work_area_focus) {
1160 if (!view->the_locking_inset) {
1161 view->screen->CursorToggle();
1163 view->the_locking_inset->
1164 ToggleInsetCursor(view);
1166 goto set_timer_and_return;
1168 // Make sure that the cursor is visible.
1169 if (!view->the_locking_inset) {
1170 view->screen->ShowCursor();
1172 if (!view->the_locking_inset->isCursorVisible())
1173 view->the_locking_inset->
1174 ToggleInsetCursor(view);
1176 // This is only run when work_area_focus or lyx_focus is false.
1179 XGetInputFocus(fl_display, &tmpwin, &tmp);
1180 // Commenting this out, we have not had problems with this
1181 // for a long time. We will probably work on this code later
1182 // and we can reenable this debug code then. Now it only
1183 // anoying when debugging. (Lgb)
1184 //if (lyxerr.debugging(Debug::INFO)) {
1185 // lyxerr << "tmpwin: " << tmpwin
1186 // << "\nwindow: " << view->owner_->getForm()->window
1187 // << "\nwork_area_focus: " << view->work_area_focus
1188 // << "\nlyx_focus : " << view->lyx_focus
1191 if (tmpwin != view->owner_->getForm()->window) {
1192 view->lyx_focus = false;
1195 view->lyx_focus = true;
1196 if (!view->work_area_focus)
1199 goto set_timer_and_return;
1203 set_timer_and_return:
1204 fl_set_timer(ob, 0.4);
1211 string fromClipboard(Window win, XEvent * event)
1214 if (event->xselection.type == XA_STRING
1215 && event->xselection.property) {
1219 unsigned char * uc = 0;
1221 if (XGetWindowProperty(
1222 event->xselection.display, // display
1224 event->xselection.property, // property
1228 XA_STRING, // req_type
1229 &tmpatom, // actual_type_return
1230 &tmpint, // actual_format_return
1241 if (XGetWindowProperty(
1242 event->xselection.display, // display
1244 event->xselection.property, // property
1246 ul2/4+1, // long_length
1248 XA_STRING, // req_type
1249 &tmpatom, // actual_type_return
1250 &tmpint, // actual_format_return
1251 &ul1, // nitems_return
1252 &ul2, // bytes_after_return
1253 &uc // prop_return */
1258 strret = reinterpret_cast<char*>(uc);
1259 free(uc); // yes free!
1267 void BufferView::workAreaSelectionNotify(Window win, XEvent * event)
1269 if (buffer_ == 0) return;
1271 screen->HideCursor();
1273 string clb = fromClipboard(win, event);
1276 text->InsertStringA(clb);
1278 text->InsertStringB(clb);
1286 void BufferView::cursorPrevious()
1288 if (!text->cursor.row->previous) return;
1290 long y = screen->first;
1291 Row * cursorrow = text->cursor.row;
1292 text->SetCursorFromCoordinates(text->cursor.x_fix, y);
1294 // This is to allow jumping over large insets
1295 if ((cursorrow == text->cursor.row))
1298 if (text->cursor.row->height < workarea->height())
1299 screen->Draw(text->cursor.y
1300 - text->cursor.row->baseline
1301 + text->cursor.row->height
1302 - workarea->height() + 1 );
1306 void BufferView::cursorNext()
1308 if (!text->cursor.row->next) return;
1310 long y = screen->first;
1311 text->GetRowNearY(y);
1312 Row * cursorrow = text->cursor.row;
1313 text->SetCursorFromCoordinates(text->cursor.x_fix, y
1314 + workarea->height());
1316 // This is to allow jumping over large insets
1317 if ((cursorrow == text->cursor.row))
1320 if (text->cursor.row->height < workarea->height())
1321 screen->Draw(text->cursor.y
1322 - text->cursor.row->baseline);
1326 bool BufferView::available() const
1328 if (buffer_ && text) return true;
1333 void BufferView::beforeChange()
1336 text->ClearSelection();
1341 void BufferView::savePosition()
1343 backstack.push(buffer()->fileName(),
1349 void BufferView::restorePosition()
1351 if (backstack.empty()) return;
1354 string fname = backstack.pop(&x, &y);
1357 Buffer * b = bufferlist.exists(fname) ?
1358 bufferlist.getBuffer(fname) :
1359 bufferlist.loadLyXFile(fname); // don't ask, just load it
1361 text->SetCursorFromCoordinates(x, y);
1366 void BufferView::update(signed char f)
1368 owner()->updateLayoutChoice();
1370 if (!text->selection && f > -3)
1371 text->sel_cursor = text->cursor;
1374 text->FullRebreak();
1378 if (f != 3 && f != -3) {
1383 if (f == 1 || f == -1) {
1384 if (buffer()->isLyxClean()) {
1385 buffer()->markDirty();
1386 owner()->getMiniBuffer()->setTimer(4);
1388 buffer()->markDirty();
1394 void BufferView::smallUpdate(signed char f)
1396 screen->SmallUpdate();
1397 if (screen->TopCursorVisible()
1406 if (!text->selection)
1407 text->sel_cursor = text->cursor;
1409 if (f == 1 || f == -1) {
1410 if (buffer()->isLyxClean()) {
1411 buffer()->markDirty();
1412 owner()->getMiniBuffer()->setTimer(4);
1414 buffer()->markDirty();
1420 void BufferView::setState()
1422 if (!lyxrc.rtl_support)
1425 if (text->real_current_font.isVisibleRightToLeft()) {
1426 if (owner_->getIntl()->primarykeymap)
1427 owner_->getIntl()->KeyMapSec();
1429 if (!owner_->getIntl()->primarykeymap)
1430 owner_->getIntl()->KeyMapPrim();
1435 void BufferView::insetSleep()
1437 if (the_locking_inset && !inset_slept) {
1438 the_locking_inset->GetCursorPos(slx, sly);
1439 the_locking_inset->InsetUnlock(this);
1445 void BufferView::insetWakeup()
1447 if (the_locking_inset && inset_slept) {
1448 the_locking_inset->Edit(this, slx, sly, 0);
1449 inset_slept = false;
1454 void BufferView::insetUnlock()
1456 if (the_locking_inset) {
1457 if (!inset_slept) the_locking_inset->InsetUnlock(this);
1458 the_locking_inset = 0;
1460 inset_slept = false;
1465 bool BufferView::focus() const
1467 return workarea->hasFocus();
1471 void BufferView::focus(bool f)
1473 if (f) workarea->setFocus();
1477 bool BufferView::active() const
1479 return workarea->active();
1483 Painter & BufferView::getPainter() const
1485 return workarea->getPainter();
1489 unsigned short BufferView::paperWidth() const
1491 return text->paperWidth();
1495 bool BufferView::belowMouse() const
1497 return workarea->belowMouse();
1501 void BufferView::showCursor()
1504 screen->ShowCursor();
1508 void BufferView::hideCursor()
1511 screen->HideCursor();
1515 void BufferView::toggleSelection(bool b)
1518 screen->ToggleSelection(b);
1522 void BufferView::toggleToggle()
1525 screen->ToggleToggle();
1529 void BufferView::center()
1532 if (text->cursor.y > workarea->height() / 2) {
1533 screen->Draw(text->cursor.y - workarea->height() / 2);