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(this,
614 // Only use motion with button 1
615 if (!state & Button1MotionMask)
618 /* The selection possible is needed, that only motion events are
619 * used, where the bottom press event was on the drawing area too */
620 if (selection_possible) {
621 screen->HideCursor();
623 text->SetCursorFromCoordinates(x, y + screen->first);
625 if (!text->selection)
626 update(-3); // Maybe an empty line was deleted
628 text->SetSelection();
629 screen->ToggleToggle();
630 if (screen->FitCursor())
632 screen->ShowCursor();
638 extern int bibitemMaxWidth(Painter &, LyXFont const &);
641 // Single-click on work area
642 void BufferView::workAreaButtonPress(int xpos, int ypos, unsigned int button)
647 if (buffer_ == 0 || !screen) return;
649 Inset * inset_hit = checkInsetHit(xpos, ypos);
651 // ok ok, this is a hack.
652 if (button == 4 || button == 5) {
655 scrollUp(100); // This number is only temporary
663 if (the_locking_inset) {
664 // We are in inset locking mode
666 /* Check whether the inset was hit. If not reset mode,
667 otherwise give the event to the inset */
670 InsetButtonPress(this,
675 unlockInset(the_locking_inset);
679 selection_possible = true;
680 screen->HideCursor();
682 // Right button mouse click on a table
684 (text->cursor.par->table ||
685 text->MouseHitInTable(xpos, ypos + screen->first))) {
686 // Set the cursor to the press-position
687 text->SetCursorFromCoordinates(xpos, ypos + screen->first);
690 // Only show the table popup if the hit is in
692 if (!text->HitInTable(text->cursor.row, xpos))
695 // Hit above or below the table?
697 if (!text->selection) {
698 screen->ToggleSelection();
699 text->ClearSelection();
704 // Popup table popup when on a table.
705 // This is obviously temporary, since we
706 // should be able to popup various
707 // context-sensitive-menus with the
708 // the right mouse. So this should be done more
709 // general in the future. Matthias.
710 selection_possible = false;
712 ->Dispatch(LFUN_LAYOUT_TABLE,
718 int screen_first = screen->first;
720 // Middle button press pastes if we have a selection
721 bool paste_internally = false;
723 && text->selection) {
724 owner_->getLyXFunc()->Dispatch(LFUN_COPY);
725 paste_internally = true;
728 // Clear the selection
729 screen->ToggleSelection();
730 text->ClearSelection();
735 // Single left click in math inset?
736 if (inset_hit != 0 && inset_hit->Editable() == 2) {
737 // Highly editable inset, like math
738 selection_possible = false;
739 owner_->updateLayoutChoice();
740 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
741 inset_hit->Edit(this, xpos, ypos);
745 // Right click on a footnote flag opens float menu
747 selection_possible = false;
751 text->SetCursorFromCoordinates(xpos, ypos + screen_first);
753 text->sel_cursor = text->cursor;
754 text->cursor.x_fix = text->cursor.x;
756 owner_->updateLayoutChoice();
757 if (screen->FitCursor()){
759 selection_possible = false;
762 // Insert primary selection with middle mouse
763 // if there is a local selection in the current buffer,
766 if (paste_internally)
767 owner_->getLyXFunc()->Dispatch(LFUN_PASTE);
769 owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION,
771 selection_possible = false;
777 void BufferView::workAreaButtonRelease(int x, int y, unsigned int button)
779 if (buffer_ == 0 || screen == 0) return;
781 // If we hit an inset, we have the inset coordinates in these
782 // and inset_hit points to the inset. If we do not hit an
783 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
784 Inset * inset_hit = checkInsetHit(x, y);
786 if (the_locking_inset) {
787 // We are in inset locking mode.
789 /* LyX does a kind of work-area grabbing for insets.
790 Only a ButtonPress Event outside the inset will
791 force a InsetUnlock. */
793 InsetButtonRelease(this, x, y, button);
797 selection_possible = false;
798 if (text->cursor.par->table) {
800 NumberOfCell(text->cursor.par,
802 if (text->cursor.par->table->IsContRow(cell) &&
803 text->cursor.par->table->
804 CellHasContRow(text->cursor.par->table->
805 GetCellAbove(cell))<0) {
810 if (button >= 2) return;
813 owner_->getMiniBuffer()->Set(CurrentState());
815 // Did we hit an editable inset?
816 if (inset_hit != 0) {
817 // Inset like error, notes and figures
818 selection_possible = false;
820 #warning fix this proper in 0.13
822 // Following a ref shouldn't issue
823 // a push on the undo-stack
824 // anylonger, now that we have
825 // keybindings for following
826 // references and returning from
827 // references. IMHO though, it
828 // should be the inset's own business
829 // to push or not push on the undo
830 // stack. They don't *have* to
831 // alter the document...
833 // ...or maybe the SetCursorParUndo()
834 // below isn't necessary at all anylonger?
835 if (inset_hit->LyxCode() == Inset::REF_CODE) {
836 text->SetCursorParUndo();
839 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
840 inset_hit->Edit(this, x, y);
844 // check whether we want to open a float
848 if (text->cursor.pos <
849 text->cursor.par->Last()) {
850 c = text->cursor.par->
851 GetChar(text->cursor.pos);
853 if (c == LyXParagraph::META_FOOTNOTE
854 || c == LyXParagraph::META_MARGIN
855 || c == LyXParagraph::META_FIG
856 || c == LyXParagraph::META_TAB
857 || c == LyXParagraph::META_WIDE_FIG
858 || c == LyXParagraph::META_WIDE_TAB
859 || c == LyXParagraph::META_ALGORITHM){
861 } else if (text->cursor.pos - 1 >= 0) {
862 c = text->cursor.par->
863 GetChar(text->cursor.pos - 1);
864 if (c == LyXParagraph::META_FOOTNOTE
865 || c == LyXParagraph::META_MARGIN
866 || c == LyXParagraph::META_FIG
867 || c == LyXParagraph::META_TAB
868 || c == LyXParagraph::META_WIDE_FIG
869 || c == LyXParagraph::META_WIDE_TAB
870 || c == LyXParagraph::META_ALGORITHM){
871 // We are one step too far to the right
878 selection_possible = false;
883 // Do we want to close a float? (click on the float-label)
884 if (text->cursor.row->par->footnoteflag ==
885 LyXParagraph::OPEN_FOOTNOTE
886 //&& text->cursor.pos == 0
887 && text->cursor.row->previous &&
888 text->cursor.row->previous->par->
889 footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
890 LyXFont font(LyXFont::ALL_SANE);
891 font.setSize(LyXFont::SIZE_FOOTNOTE);
893 int box_x = 20; // LYX_PAPER_MARGIN;
894 box_x += font.textWidth(" wide-tab ", 10);
896 int screen_first = screen->first;
899 && y + screen_first > text->cursor.y -
900 text->cursor.row->baseline
901 && y + screen_first < text->cursor.y -
902 text->cursor.row->baseline
903 + font.maxAscent() * 1.2 + font.maxDescent() * 1.2) {
905 selection_possible = false;
910 // Maybe we want to edit a bibitem ale970302
911 if (text->cursor.par->bibkey && x < 20 +
912 bibitemMaxWidth(painter(),
915 params.textclass).defaultfont())) {
916 text->cursor.par->bibkey->Edit(this, 0, 0);
924 * Returns an inset if inset was hit. 0 otherwise.
925 * If hit, the coordinates are changed relative to the inset.
926 * Otherwise coordinates are not changed, and false is returned.
928 Inset * BufferView::checkInsetHit(int & x, int & y)
933 int y_tmp = y + screen->first;
935 LyXCursor & cursor = text->cursor;
936 LyXDirection direction = text->real_current_font.getFontDirection();
938 if (cursor.pos < cursor.par->Last()
939 && cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET
940 && cursor.par->GetInset(cursor.pos)
941 && cursor.par->GetInset(cursor.pos)->Editable()) {
943 // Check whether the inset really was hit
944 Inset * tmpinset = cursor.par->GetInset(cursor.pos);
945 LyXFont font = text->GetFont(cursor.par, cursor.pos);
947 if (direction == LYX_DIR_LEFT_TO_RIGHT) {
949 end_x = cursor.x + tmpinset->width(painter(), font);
951 start_x = cursor.x - tmpinset->width(painter(), font);
955 if (x > start_x && x < end_x
956 && y_tmp > cursor.y - tmpinset->ascent(painter(), font)
957 && y_tmp < cursor.y + tmpinset->descent(painter(), font)) {
959 // The origin of an inset is on the baseline
960 y = y_tmp - (cursor.y);
965 if (cursor.pos - 1 >= 0
966 && cursor.par->GetChar(cursor.pos - 1) == LyXParagraph::META_INSET
967 && cursor.par->GetInset(cursor.pos - 1)
968 && cursor.par->GetInset(cursor.pos - 1)->Editable()) {
970 Inset * tmpinset = cursor.par->GetInset(cursor.pos);
971 LyXFont font = text->GetFont(cursor.par, cursor.pos);
973 if (direction == LYX_DIR_LEFT_TO_RIGHT) {
975 end_x = cursor.x + tmpinset->width(painter(), font);
977 start_x = cursor.x - tmpinset->width(painter(), font);
980 if (x > start_x && x < end_x
981 && y_tmp > cursor.y - tmpinset->ascent(painter(), font)
982 && y_tmp < cursor.y + tmpinset->descent(painter(), font)) {
984 // The origin of an inset is on the baseline
985 y = y_tmp - (cursor.y);
996 void BufferView::workAreaExpose()
998 // this is a hack to ensure that we only call this through
999 // BufferView::redraw().
1004 static int work_area_width = -1;
1005 static int work_area_height = -1;
1007 bool widthChange = workarea->workWidth() != work_area_width;
1008 bool heightChange = workarea->height() != work_area_height;
1010 // update from work area
1011 work_area_width = workarea->workWidth();
1012 work_area_height = workarea->height();
1015 // All buffers need a resize
1016 bufferlist.resize();
1018 // Remove all texts from the textcache
1019 // This is not _really_ what we want to do. What
1020 // we really want to do is to delete in textcache
1021 // that does not have a BufferView with matching
1022 // width, but as long as we have only one BufferView
1023 // deleting all gives the same result.
1024 if (lyxerr.debugging())
1025 textcache.show(lyxerr, "Expose delete all");
1027 } else if (heightChange) {
1028 // Rebuild image of current screen
1030 // fitCursor() ensures we don't jump back
1031 // to the start of the document on vertical
1035 // The main window size has changed, repaint most stuff
1037 // ...including the minibuffer
1038 owner_->getMiniBuffer()->Init();
1040 } else if (screen) screen->Redraw();
1042 // Grey box when we don't have a buffer
1043 workarea->greyOut();
1046 // always make sure that the scrollbar is sane.
1048 owner_->updateLayoutChoice();
1053 // Callback for cursor timer
1054 void BufferView::cursorToggleCB(FL_OBJECT * ob, long)
1056 BufferView * view = static_cast<BufferView*>(ob->u_vdata);
1058 // Quite a nice place for asyncron Inset updating, isn't it?
1059 // Actually no! This is run even if no buffer exist... so (Lgb)
1060 if (view && !view->buffer_) {
1061 goto set_timer_and_return;
1065 // On my quest to solve the gs render hangups I am now
1066 // disabling the SIGHUP completely, and will do a wait
1067 // now and then instead. If the guess that xforms somehow
1068 // destroys something is true, this is likely (hopefully)
1069 // to solve the problem...at least I hope so. Lgb
1071 // ...Ok this seems to work...at least it does not make things
1072 // worse so far. However I still see gs processes that hangs.
1073 // I would really like to know _why_ they are hanging. Anyway
1074 // the solution without the SIGCHLD handler seems to be easier
1077 // When attaching gdb to a a running gs that hangs it shows
1078 // that it is waiting for input(?) Is it possible for us to
1079 // provide that input somehow? Or figure what it is expecing
1082 // One solution is to, after some time, look if there are some
1083 // old gs processes still running and if there are: kill them
1086 // Another solution is to provide the user an option to rerender
1087 // a picture. This would, for the picture in question, check if
1088 // there is a gs running for it, if so kill it, and start a new
1089 // rendering process.
1091 // these comments posted to lyx@via
1094 int pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1095 if (pid == -1) // error find out what is wrong
1096 ; // ignore it for now.
1098 sigchldhandler(pid, &status);
1100 if (InsetUpdateList)
1101 UpdateInsetUpdateList();
1103 if (view && !view->screen){
1104 goto set_timer_and_return;
1107 if (view->lyx_focus && view->work_area_focus) {
1108 if (!view->the_locking_inset) {
1109 view->screen->CursorToggle();
1111 view->the_locking_inset->
1112 ToggleInsetCursor(view);
1114 goto set_timer_and_return;
1116 // Make sure that the cursor is visible.
1117 if (!view->the_locking_inset) {
1118 view->screen->ShowCursor();
1120 if (!view->the_locking_inset->isCursorVisible())
1121 view->the_locking_inset->
1122 ToggleInsetCursor(view);
1124 // This is only run when work_area_focus or lyx_focus is false.
1127 XGetInputFocus(fl_display, &tmpwin, &tmp);
1128 // Commenting this out, we have not had problems with this
1129 // for a long time. We will probably work on this code later
1130 // and we can reenable this debug code then. Now it only
1131 // anoying when debugging. (Lgb)
1132 //if (lyxerr.debugging(Debug::INFO)) {
1133 // lyxerr << "tmpwin: " << tmpwin
1134 // << "\nwindow: " << view->owner_->getForm()->window
1135 // << "\nwork_area_focus: " << view->work_area_focus
1136 // << "\nlyx_focus : " << view->lyx_focus
1139 if (tmpwin != view->owner_->getForm()->window) {
1140 view->lyx_focus = false;
1143 view->lyx_focus = true;
1144 if (!view->work_area_focus)
1147 goto set_timer_and_return;
1151 set_timer_and_return:
1152 fl_set_timer(ob, 0.4);
1159 string fromClipboard(Window win, XEvent * event)
1162 if (event->xselection.type == XA_STRING
1163 && event->xselection.property) {
1167 unsigned char * uc = 0;
1169 if (XGetWindowProperty(
1170 event->xselection.display, // display
1172 event->xselection.property, // property
1176 XA_STRING, // req_type
1177 &tmpatom, // actual_type_return
1178 &tmpint, // actual_format_return
1189 if (XGetWindowProperty(
1190 event->xselection.display, // display
1192 event->xselection.property, // property
1194 ul2/4+1, // long_length
1196 XA_STRING, // req_type
1197 &tmpatom, // actual_type_return
1198 &tmpint, // actual_format_return
1199 &ul1, // nitems_return
1200 &ul2, // bytes_after_return
1201 &uc // prop_return */
1206 strret = reinterpret_cast<char*>(uc);
1207 free(uc); // yes free!
1215 void BufferView::workAreaSelectionNotify(Window win, XEvent * event)
1217 if (buffer_ == 0) return;
1219 screen->HideCursor();
1221 string clb = fromClipboard(win, event);
1224 text->InsertStringA(clb.c_str());
1226 text->InsertStringB(clb.c_str());
1234 void BufferView::cursorPrevious()
1236 if (!text->cursor.row->previous) return;
1238 long y = screen->first;
1239 Row * cursorrow = text->cursor.row;
1240 text->SetCursorFromCoordinates(text->cursor.x_fix, y);
1242 // This is to allow jumping over large insets
1243 if ((cursorrow == text->cursor.row))
1246 if (text->cursor.row->height < workarea->height())
1247 screen->Draw(text->cursor.y
1248 - text->cursor.row->baseline
1249 + text->cursor.row->height
1250 - workarea->height() + 1 );
1254 void BufferView::cursorNext()
1256 if (!text->cursor.row->next) return;
1258 long y = screen->first;
1259 text->GetRowNearY(y);
1260 Row * cursorrow = text->cursor.row;
1261 text->SetCursorFromCoordinates(text->cursor.x_fix, y
1262 + workarea->height());
1264 // This is to allow jumping over large insets
1265 if ((cursorrow == text->cursor.row))
1268 if (text->cursor.row->height < workarea->height())
1269 screen->Draw(text->cursor.y
1270 - text->cursor.row->baseline);
1274 bool BufferView::available() const
1276 if (buffer_ && text) return true;
1281 void BufferView::beforeChange()
1284 text->ClearSelection();
1289 void BufferView::savePosition()
1291 backstack.push(buffer()->fileName(),
1297 void BufferView::restorePosition()
1299 if (backstack.empty()) return;
1302 string fname = backstack.pop(&x, &y);
1305 Buffer * b = bufferlist.exists(fname) ?
1306 bufferlist.getBuffer(fname) :
1307 bufferlist.loadLyXFile(fname); // don't ask, just load it
1309 text->SetCursorFromCoordinates(x, y);
1314 void BufferView::update(signed char f)
1316 owner()->updateLayoutChoice();
1318 if (!text->selection && f > -3)
1319 text->sel_cursor = text->cursor;
1322 text->FullRebreak();
1326 if (f != 3 && f != -3) {
1331 if (f == 1 || f == -1) {
1332 if (buffer()->isLyxClean()) {
1333 buffer()->markDirty();
1334 owner()->getMiniBuffer()->setTimer(4);
1336 buffer()->markDirty();
1342 void BufferView::smallUpdate(signed char f)
1344 screen->SmallUpdate();
1345 if (screen->TopCursorVisible()
1354 if (!text->selection)
1355 text->sel_cursor = text->cursor;
1357 if (f == 1 || f == -1) {
1358 if (buffer()->isLyxClean()) {
1359 buffer()->markDirty();
1360 owner()->getMiniBuffer()->setTimer(4);
1362 buffer()->markDirty();
1368 void BufferView::setState()
1370 if (!lyxrc->rtl_support)
1373 if (text->real_current_font.getFontDirection()
1374 == LYX_DIR_LEFT_TO_RIGHT) {
1375 if (!owner_->getIntl()->primarykeymap)
1376 owner_->getIntl()->KeyMapPrim();
1378 if (owner_->getIntl()->primarykeymap)
1379 owner_->getIntl()->KeyMapSec();
1384 void BufferView::insetSleep()
1386 if (the_locking_inset && !inset_slept) {
1387 the_locking_inset->GetCursorPos(slx, sly);
1388 the_locking_inset->InsetUnlock(this);
1394 void BufferView::insetWakeup()
1396 if (the_locking_inset && inset_slept) {
1397 the_locking_inset->Edit(this, slx, sly);
1398 inset_slept = false;
1403 void BufferView::insetUnlock()
1405 if (the_locking_inset) {
1406 if (!inset_slept) the_locking_inset->InsetUnlock(this);
1407 the_locking_inset = 0;
1409 inset_slept = false;
1414 bool BufferView::focus() const
1416 return workarea->hasFocus();
1420 void BufferView::focus(bool f)
1422 if (f) workarea->setFocus();
1426 bool BufferView::active() const
1428 return workarea->active();
1432 void BufferView::showCursor()
1435 screen->ShowCursor();
1439 void BufferView::hideCursor()
1442 screen->HideCursor();
1446 void BufferView::toggleSelection(bool b)
1449 screen->ToggleSelection(b);
1453 void BufferView::toggleToggle()
1456 screen->ToggleToggle();
1460 void BufferView::center()
1463 if (text->cursor.y > workarea->height() / 2) {
1464 screen->Draw(text->cursor.y - workarea->height() / 2);