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;
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 InsetUpdateStruct * InsetUpdateList;
65 extern void UpdateInsetUpdateList();
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(x - cursor.x,
613 // Only use motion with button 1
614 if (!state & Button1MotionMask)
617 /* The selection possible is needed, that only motion events are
618 * used, where the bottom press event was on the drawing area too */
619 if (selection_possible) {
620 screen->HideCursor();
622 text->SetCursorFromCoordinates(x, y + screen->first);
624 if (!text->selection)
625 update(-3); // Maybe an empty line was deleted
627 text->SetSelection();
628 screen->ToggleToggle();
629 if (screen->FitCursor())
631 screen->ShowCursor();
637 extern int bibitemMaxWidth(Painter &, LyXFont const &);
640 // Single-click on work area
641 void BufferView::workAreaButtonPress(int xpos, int ypos, unsigned int button)
646 if (buffer_ == 0 || !screen) return;
648 Inset * inset_hit = checkInsetHit(xpos, ypos);
650 // ok ok, this is a hack.
651 if (button == 4 || button == 5) {
654 scrollUp(100); // This number is only temporary
662 if (the_locking_inset) {
663 // We are in inset locking mode
665 /* Check whether the inset was hit. If not reset mode,
666 otherwise give the event to the inset */
669 InsetButtonPress(xpos, ypos,
673 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 && inset_hit->Editable() == 2) {
735 // Highly editable inset, like math
736 selection_possible = false;
737 owner_->updateLayoutChoice();
738 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
739 inset_hit->Edit(xpos, ypos);
743 // Right click on a footnote flag opens float menu
745 selection_possible = false;
749 text->SetCursorFromCoordinates(xpos, ypos + screen_first);
751 text->sel_cursor = text->cursor;
752 text->cursor.x_fix = text->cursor.x;
754 owner_->updateLayoutChoice();
755 if (screen->FitCursor()){
757 selection_possible = false;
760 // Insert primary selection with middle mouse
761 // if there is a local selection in the current buffer,
764 if (paste_internally)
765 owner_->getLyXFunc()->Dispatch(LFUN_PASTE);
767 owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION,
769 selection_possible = false;
775 void BufferView::workAreaButtonRelease(int x, int y, unsigned int button)
777 if (buffer_ == 0 || screen == 0) return;
779 // If we hit an inset, we have the inset coordinates in these
780 // and inset_hit points to the inset. If we do not hit an
781 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
782 Inset * inset_hit = checkInsetHit(x, y);
784 if (the_locking_inset) {
785 // We are in inset locking mode.
787 /* LyX does a kind of work-area grabbing for insets.
788 Only a ButtonPress Event outside the inset will
789 force a InsetUnlock. */
791 InsetButtonRelease(x, x, button);
795 selection_possible = false;
796 if (text->cursor.par->table) {
798 NumberOfCell(text->cursor.par,
800 if (text->cursor.par->table->IsContRow(cell) &&
801 text->cursor.par->table->
802 CellHasContRow(text->cursor.par->table->
803 GetCellAbove(cell))<0) {
808 if (button >= 2) return;
811 owner_->getMiniBuffer()->Set(CurrentState());
813 // Did we hit an editable inset?
814 if (inset_hit != 0) {
815 // Inset like error, notes and figures
816 selection_possible = false;
818 #warning fix this proper in 0.13
820 // Following a ref shouldn't issue
821 // a push on the undo-stack
822 // anylonger, now that we have
823 // keybindings for following
824 // references and returning from
825 // references. IMHO though, it
826 // should be the inset's own business
827 // to push or not push on the undo
828 // stack. They don't *have* to
829 // alter the document...
831 // ...or maybe the SetCursorParUndo()
832 // below isn't necessary at all anylonger?
833 if (inset_hit->LyxCode() == Inset::REF_CODE) {
834 text->SetCursorParUndo();
837 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
838 inset_hit->Edit(x, y);
842 // check whether we want to open a float
846 if (text->cursor.pos <
847 text->cursor.par->Last()) {
848 c = text->cursor.par->
849 GetChar(text->cursor.pos);
851 if (c == LyXParagraph::META_FOOTNOTE
852 || c == LyXParagraph::META_MARGIN
853 || c == LyXParagraph::META_FIG
854 || c == LyXParagraph::META_TAB
855 || c == LyXParagraph::META_WIDE_FIG
856 || c == LyXParagraph::META_WIDE_TAB
857 || c == LyXParagraph::META_ALGORITHM){
859 } else if (text->cursor.pos - 1 >= 0) {
860 c = text->cursor.par->
861 GetChar(text->cursor.pos - 1);
862 if (c == LyXParagraph::META_FOOTNOTE
863 || c == LyXParagraph::META_MARGIN
864 || c == LyXParagraph::META_FIG
865 || c == LyXParagraph::META_TAB
866 || c == LyXParagraph::META_WIDE_FIG
867 || c == LyXParagraph::META_WIDE_TAB
868 || c == LyXParagraph::META_ALGORITHM){
869 // We are one step too far to the right
876 selection_possible = false;
881 // Do we want to close a float? (click on the float-label)
882 if (text->cursor.row->par->footnoteflag ==
883 LyXParagraph::OPEN_FOOTNOTE
884 //&& text->cursor.pos == 0
885 && text->cursor.row->previous &&
886 text->cursor.row->previous->par->
887 footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
888 LyXFont font(LyXFont::ALL_SANE);
889 font.setSize(LyXFont::SIZE_FOOTNOTE);
891 int box_x = 20; // LYX_PAPER_MARGIN;
892 box_x += font.textWidth(" wide-tab ", 10);
894 int screen_first = screen->first;
897 && y + screen_first > text->cursor.y -
898 text->cursor.row->baseline
899 && y + screen_first < text->cursor.y -
900 text->cursor.row->baseline
901 + font.maxAscent() * 1.2 + font.maxDescent() * 1.2) {
903 selection_possible = false;
908 // Maybe we want to edit a bibitem ale970302
909 if (text->cursor.par->bibkey && x < 20 +
910 bibitemMaxWidth(painter(),
913 params.textclass).defaultfont())) {
914 text->cursor.par->bibkey->Edit(0, 0);
922 * Returns an inset if inset was hit. 0 otherwise.
923 * If hit, the coordinates are changed relative to the inset.
924 * Otherwise coordinates are not changed, and false is returned.
926 Inset * BufferView::checkInsetHit(int & x, int & y)
931 int y_tmp = y + screen->first;
933 LyXCursor & cursor = text->cursor;
934 LyXDirection direction = text->real_current_font.getFontDirection();
936 if (cursor.pos < cursor.par->Last()
937 && cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET
938 && cursor.par->GetInset(cursor.pos)
939 && cursor.par->GetInset(cursor.pos)->Editable()) {
941 // Check whether the inset really was hit
942 Inset * tmpinset = cursor.par->GetInset(cursor.pos);
943 LyXFont font = text->GetFont(cursor.par, cursor.pos);
945 if (direction == LYX_DIR_LEFT_TO_RIGHT) {
947 end_x = cursor.x + tmpinset->width(painter(), font);
949 start_x = cursor.x - tmpinset->width(painter(), font);
953 if (x > start_x && x < end_x
954 && y_tmp > cursor.y - tmpinset->ascent(painter(), font)
955 && y_tmp < cursor.y + tmpinset->descent(painter(), font)) {
957 // The origin of an inset is on the baseline
958 y = y_tmp - (cursor.y);
963 if (cursor.pos - 1 >= 0
964 && cursor.par->GetChar(cursor.pos - 1) == LyXParagraph::META_INSET
965 && cursor.par->GetInset(cursor.pos - 1)
966 && cursor.par->GetInset(cursor.pos - 1)->Editable()) {
968 Inset * tmpinset = cursor.par->GetInset(cursor.pos);
969 LyXFont font = text->GetFont(cursor.par, cursor.pos);
971 if (direction == LYX_DIR_LEFT_TO_RIGHT) {
973 end_x = cursor.x + tmpinset->width(painter(), font);
975 start_x = cursor.x - tmpinset->width(painter(), font);
978 if (x > start_x && x < end_x
979 && y_tmp > cursor.y - tmpinset->ascent(painter(), font)
980 && y_tmp < cursor.y + tmpinset->descent(painter(), font)) {
982 // The origin of an inset is on the baseline
983 y = y_tmp - (cursor.y);
994 void BufferView::workAreaExpose()
996 // this is a hack to ensure that we only call this through
997 // BufferView::redraw().
1002 static int work_area_width = -1;
1003 static int work_area_height = -1;
1005 bool widthChange = workarea->workWidth() != work_area_width;
1006 bool heightChange = workarea->height() != work_area_height;
1008 // update from work area
1009 work_area_width = workarea->workWidth();
1010 work_area_height = workarea->height();
1013 // All buffers need a resize
1014 bufferlist.resize();
1016 // Remove all texts from the textcache
1017 // This is not _really_ what we want to do. What
1018 // we really want to do is to delete in textcache
1019 // that does not have a BufferView with matching
1020 // width, but as long as we have only one BufferView
1021 // deleting all gives the same result.
1022 if (lyxerr.debugging())
1023 textcache.show(lyxerr, "Expose delete all");
1025 } else if (heightChange) {
1026 // Rebuild image of current screen
1028 // fitCursor() ensures we don't jump back
1029 // to the start of the document on vertical
1033 // The main window size has changed, repaint most stuff
1035 // ...including the minibuffer
1036 owner_->getMiniBuffer()->Init();
1038 } else if (screen) screen->Redraw();
1040 // Grey box when we don't have a buffer
1041 workarea->greyOut();
1044 // always make sure that the scrollbar is sane.
1046 owner_->updateLayoutChoice();
1051 // Callback for cursor timer
1052 void BufferView::cursorToggleCB(FL_OBJECT * ob, long)
1054 BufferView * view = static_cast<BufferView*>(ob->u_vdata);
1056 // Quite a nice place for asyncron Inset updating, isn't it?
1057 // Actually no! This is run even if no buffer exist... so (Lgb)
1058 if (view && !view->buffer_) {
1059 goto set_timer_and_return;
1063 // On my quest to solve the gs render hangups I am now
1064 // disabling the SIGHUP completely, and will do a wait
1065 // now and then instead. If the guess that xforms somehow
1066 // destroys something is true, this is likely (hopefully)
1067 // to solve the problem...at least I hope so. Lgb
1069 // ...Ok this seems to work...at least it does not make things
1070 // worse so far. However I still see gs processes that hangs.
1071 // I would really like to know _why_ they are hanging. Anyway
1072 // the solution without the SIGCHLD handler seems to be easier
1075 // When attaching gdb to a a running gs that hangs it shows
1076 // that it is waiting for input(?) Is it possible for us to
1077 // provide that input somehow? Or figure what it is expecing
1080 // One solution is to, after some time, look if there are some
1081 // old gs processes still running and if there are: kill them
1084 // Another solution is to provide the user an option to rerender
1085 // a picture. This would, for the picture in question, check if
1086 // there is a gs running for it, if so kill it, and start a new
1087 // rendering process.
1089 // these comments posted to lyx@via
1092 int pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1093 if (pid == -1) // error find out what is wrong
1094 ; // ignore it for now.
1096 sigchldhandler(pid, &status);
1098 if (InsetUpdateList)
1099 UpdateInsetUpdateList();
1101 if (view && !view->screen){
1102 goto set_timer_and_return;
1105 if (view->lyx_focus && view->work_area_focus) {
1106 if (!view->the_locking_inset) {
1107 view->screen->CursorToggle();
1109 view->the_locking_inset->
1110 ToggleInsetCursor();
1112 goto set_timer_and_return;
1114 // Make sure that the cursor is visible.
1115 if (!view->the_locking_inset) {
1116 view->screen->ShowCursor();
1118 if (!view->the_locking_inset->isCursorVisible())
1119 view->the_locking_inset->
1120 ToggleInsetCursor();
1122 // This is only run when work_area_focus or lyx_focus is false.
1125 XGetInputFocus(fl_display, &tmpwin, &tmp);
1126 // Commenting this out, we have not had problems with this
1127 // for a long time. We will probably work on this code later
1128 // and we can reenable this debug code then. Now it only
1129 // anoying when debugging. (Lgb)
1130 //if (lyxerr.debugging(Debug::INFO)) {
1131 // lyxerr << "tmpwin: " << tmpwin
1132 // << "\nwindow: " << view->owner_->getForm()->window
1133 // << "\nwork_area_focus: " << view->work_area_focus
1134 // << "\nlyx_focus : " << view->lyx_focus
1137 if (tmpwin != view->owner_->getForm()->window) {
1138 view->lyx_focus = false;
1141 view->lyx_focus = true;
1142 if (!view->work_area_focus)
1145 goto set_timer_and_return;
1149 set_timer_and_return:
1150 fl_set_timer(ob, 0.4);
1157 string fromClipboard(Window win, XEvent * event)
1160 if (event->xselection.type == XA_STRING
1161 && event->xselection.property) {
1165 unsigned char * uc = 0;
1167 if (XGetWindowProperty(
1168 event->xselection.display, // display
1170 event->xselection.property, // property
1174 XA_STRING, // req_type
1175 &tmpatom, // actual_type_return
1176 &tmpint, // actual_format_return
1187 if (XGetWindowProperty(
1188 event->xselection.display, // display
1190 event->xselection.property, // property
1192 ul2/4+1, // long_length
1194 XA_STRING, // req_type
1195 &tmpatom, // actual_type_return
1196 &tmpint, // actual_format_return
1197 &ul1, // nitems_return
1198 &ul2, // bytes_after_return
1199 &uc // prop_return */
1204 strret = reinterpret_cast<char*>(uc);
1205 free(uc); // yes free!
1213 void BufferView::workAreaSelectionNotify(Window win, XEvent * event)
1215 if (buffer_ == 0) return;
1217 screen->HideCursor();
1219 string clb = fromClipboard(win, event);
1222 text->InsertStringA(clb.c_str());
1224 text->InsertStringB(clb.c_str());
1232 void BufferView::cursorPrevious()
1234 if (!text->cursor.row->previous) return;
1236 long y = screen->first;
1237 Row * cursorrow = text->cursor.row;
1238 text->SetCursorFromCoordinates(text->cursor.x_fix, y);
1240 // This is to allow jumping over large insets
1241 if ((cursorrow == text->cursor.row))
1244 if (text->cursor.row->height < workarea->height())
1245 screen->Draw(text->cursor.y
1246 - text->cursor.row->baseline
1247 + text->cursor.row->height
1248 - workarea->height() + 1 );
1252 void BufferView::cursorNext()
1254 if (!text->cursor.row->next) return;
1256 long y = screen->first;
1257 text->GetRowNearY(y);
1258 Row * cursorrow = text->cursor.row;
1259 text->SetCursorFromCoordinates(text->cursor.x_fix, y
1260 + workarea->height());
1262 // This is to allow jumping over large insets
1263 if ((cursorrow == text->cursor.row))
1266 if (text->cursor.row->height < workarea->height())
1267 screen->Draw(text->cursor.y
1268 - text->cursor.row->baseline);
1272 bool BufferView::available() const
1274 if (buffer_ && text) return true;
1279 void BufferView::beforeChange()
1282 text->ClearSelection();
1287 void BufferView::savePosition()
1289 backstack.push(buffer()->fileName(),
1295 void BufferView::restorePosition()
1297 if (backstack.empty()) return;
1300 string fname = backstack.pop(&x, &y);
1303 Buffer * b = bufferlist.exists(fname) ?
1304 bufferlist.getBuffer(fname) :
1305 bufferlist.loadLyXFile(fname); // don't ask, just load it
1307 text->SetCursorFromCoordinates(x, y);
1312 void BufferView::update(signed char f)
1314 owner()->updateLayoutChoice();
1316 if (!text->selection && f > -3)
1317 text->sel_cursor = text->cursor;
1320 text->FullRebreak();
1324 if (f != 3 && f != -3) {
1329 if (f == 1 || f == -1) {
1330 if (buffer()->isLyxClean()) {
1331 buffer()->markDirty();
1332 owner()->getMiniBuffer()->setTimer(4);
1334 buffer()->markDirty();
1340 void BufferView::smallUpdate(signed char f)
1342 screen->SmallUpdate();
1343 if (screen->TopCursorVisible()
1352 if (!text->selection)
1353 text->sel_cursor = text->cursor;
1355 if (f == 1 || f == -1) {
1356 if (buffer()->isLyxClean()) {
1357 buffer()->markDirty();
1358 owner()->getMiniBuffer()->setTimer(4);
1360 buffer()->markDirty();
1366 void BufferView::setState()
1368 if (!lyxrc->rtl_support)
1371 if (text->real_current_font.getFontDirection()
1372 == LYX_DIR_LEFT_TO_RIGHT) {
1373 if (!owner_->getIntl()->primarykeymap)
1374 owner_->getIntl()->KeyMapPrim();
1376 if (owner_->getIntl()->primarykeymap)
1377 owner_->getIntl()->KeyMapSec();
1382 void BufferView::insetSleep()
1384 if (the_locking_inset && !inset_slept) {
1385 the_locking_inset->GetCursorPos(slx, sly);
1386 the_locking_inset->InsetUnlock();
1392 void BufferView::insetWakeup()
1394 if (the_locking_inset && inset_slept) {
1395 the_locking_inset->Edit(slx, sly);
1396 inset_slept = false;
1401 void BufferView::insetUnlock()
1403 if (the_locking_inset) {
1404 if (!inset_slept) the_locking_inset->InsetUnlock();
1405 the_locking_inset = 0;
1407 inset_slept = false;
1412 bool BufferView::focus() const
1414 return workarea->hasFocus();
1418 void BufferView::focus(bool f)
1420 if (f) workarea->setFocus();
1424 bool BufferView::active() const
1426 return workarea->active();
1430 void BufferView::showCursor()
1433 screen->ShowCursor();
1437 void BufferView::hideCursor()
1440 screen->HideCursor();
1444 void BufferView::toggleSelection(bool b)
1447 screen->ToggleSelection(b);
1451 void BufferView::toggleToggle()
1454 screen->ToggleToggle();
1458 void BufferView::center()
1461 if (text->cursor.y > workarea->height() / 2) {
1462 screen->Draw(text->cursor.y - workarea->height() / 2);