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 "minibuffer.h"
36 #include "lyxscreen.h"
39 #include "lyx_gui_misc.h"
40 #include "BackStack.h"
45 #include "TextCache.h"
53 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 InsetUpdateStruct * InsetUpdateList;
64 extern void UpdateInsetUpdateList();
65 extern void FreeUpdateTimer();
67 BufferView::BufferView(LyXView * o, int xpos, int ypos,
68 int width, int height)
74 workarea = new WorkArea(this, xpos, ypos, width, height);
77 current_scrollbar_value = 0;
78 // Activate the timer for the cursor
79 fl_set_timer(timer_cursor, 0.4);
81 work_area_focus = true;
83 the_locking_inset = 0;
88 BufferView::~BufferView()
94 Painter & BufferView::painter()
96 return workarea->getPainter();
100 void BufferView::buffer(Buffer * b)
102 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
106 buffer_->delUser(this);
108 // Put the old text into the TextCache, but
109 // only if the buffer is still loaded.
110 // Also set the owner of the test to 0
113 if (lyxerr.debugging())
114 textcache.show(lyxerr, "BufferView::buffer");
119 // Set current buffer
122 if (bufferlist.getState() == BufferList::CLOSING) return;
125 // screen is always deleted when the buffer is changed.
129 // If we are closing the buffer, use the first buffer as current
131 buffer_ = bufferlist.first();
135 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
136 buffer_->addUser(this);
137 owner_->getMenus()->showMenus();
138 // If we don't have a text object for this, we make one
140 resizeCurrentBuffer();
145 screen->first = screen->TopCursorVisible();
147 updateAllVisibleBufferRelatedPopups();
150 lyxerr[Debug::INFO] << " No Buffer!" << endl;
151 owner_->getMenus()->hideMenus();
155 // Also remove all remaining text's from the testcache.
156 // (there should not be any!) (if there is any it is a
158 if (lyxerr.debugging())
159 textcache.show(lyxerr, "buffer delete all");
162 // should update layoutchoice even if we don't have a buffer.
163 owner_->updateLayoutChoice();
164 owner_->getMiniBuffer()->Init();
165 owner_->updateWindowTitle();
169 void BufferView::updateScreen()
171 // Regenerate the screen.
173 screen = new LyXScreen(this,
175 workarea->getPixmap(),
176 workarea->workWidth(),
184 void BufferView::resize(int xpos, int ypos, int width, int height)
186 workarea->resize(xpos, ypos, width, height);
192 void BufferView::resize()
194 // This will resize the buffer. (Asger)
196 resizeCurrentBuffer();
200 void BufferView::redraw()
202 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
207 void BufferView::fitCursor()
209 if (screen) screen->FitCursor();
214 void BufferView::update()
216 if (screen) screen->Update();
220 void BufferView::updateScrollbar()
222 /* If the text is smaller than the working area, the scrollbar
223 * maximum must be the working area height. No scrolling will
227 workarea->setScrollbar(0, 1.0);
231 static long max2 = 0;
232 static long height2 = 0;
240 cbsf = screen->first;
242 // check if anything has changed.
244 height2 == workarea->height() &&
245 current_scrollbar_value == cbsf)
248 height2 = workarea->height();
249 current_scrollbar_value = cbsf;
251 if (cbth <= height2) { // text is smaller than screen
252 workarea->setScrollbar(0, 1.0); // right?
256 long maximum_height = workarea->height() * 3 / 4 + cbth;
260 double hfloat = workarea->height();
261 double maxfloat = maximum_height;
263 float slider_size = 0.0;
264 int slider_value = value;
266 workarea->setScrollbarBounds(0, text->height - workarea->height());
267 double lineh = text->DefaultHeight();
268 workarea->setScrollbarIncrements(lineh);
269 if (maxfloat > 0.0) {
270 if ((hfloat / maxfloat) * float(height2) < 3)
271 slider_size = 3.0/float(height2);
273 slider_size = hfloat / maxfloat;
275 slider_size = hfloat;
277 workarea->setScrollbar(slider_value, slider_size / workarea->height());
281 void BufferView::redoCurrentBuffer()
283 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
284 if (buffer_ && text) {
286 owner_->updateLayoutChoice();
291 int BufferView::resizeCurrentBuffer()
293 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
295 LyXParagraph * par = 0;
296 LyXParagraph * selstartpar = 0;
297 LyXParagraph * selendpar = 0;
306 owner_->getMiniBuffer()->Set(_("Formatting document..."));
309 par = text->cursor.par;
310 pos = text->cursor.pos;
311 selstartpar = text->sel_start_cursor.par;
312 selstartpos = text->sel_start_cursor.pos;
313 selendpar = text->sel_end_cursor.par;
314 selendpos = text->sel_end_cursor.pos;
315 selection = text->selection;
316 mark_set = text->mark_set;
318 text = new LyXText(this, workarea->workWidth(), buffer_);
320 // See if we have a text in TextCache that fits
321 // the new buffer_ with the correct width.
322 text = textcache.findFit(buffer_, workarea->workWidth());
324 if (lyxerr.debugging()) {
325 lyxerr << "Found a LyXText that fits:\n";
326 textcache.show(lyxerr, text);
328 // Set the owner of the newly found text
330 if (lyxerr.debugging())
331 textcache.show(lyxerr, "resizeCurrentBuffer");
333 text = new LyXText(this, workarea->workWidth(), buffer_);
339 text->selection = true;
340 /* at this point just to avoid the Delete-Empty-Paragraph
341 * Mechanism when setting the cursor */
342 text->mark_set = mark_set;
344 text->SetCursor(selstartpar, selstartpos);
345 text->sel_cursor = text->cursor;
346 text->SetCursor(selendpar, selendpos);
347 text->SetSelection();
348 text->SetCursor(par, pos);
350 text->SetCursor(par, pos);
351 text->sel_cursor = text->cursor;
352 text->selection = false;
355 screen->first = screen->TopCursorVisible(); /* this will scroll the
356 * screen such that the
361 owner_->getMiniBuffer()->Init();
365 // Now if the title form still exist kill it
372 void BufferView::gotoError()
377 screen->HideCursor();
382 if (!text->GotoNextError()) {
384 || text->cursor.par != text->FirstParagraph()) {
386 text->cursor.par = text->FirstParagraph();
387 text->cursor.pos = 0;
388 if (!text->GotoNextError()) {
390 owner_->getMiniBuffer()
391 ->Set(_("No more errors"));
395 owner_->getMiniBuffer()->Set(_("No more errors"));
400 text->sel_cursor = text->cursor;
405 void C_BufferView_CursorToggleCB(FL_OBJECT * ob, long buf)
407 BufferView::cursorToggleCB(ob, buf);
412 void BufferView::create_view()
421 timer_cursor = obj = fl_add_timer(FL_HIDDEN_TIMER,
422 0, 0, 0, 0, "Timer");
423 fl_set_object_callback(obj, C_BufferView_CursorToggleCB, 0);
428 // Callback for scrollbar up button
429 void BufferView::upCB(long time, int button)
431 if (buffer_ == 0) return;
450 XSync(fl_get_display(), 0);
454 // Callback for scrollbar slider
455 void BufferView::scrollCB(double value)
457 extern bool cursor_follows_scrollbar;
459 if (buffer_ == 0) return;
461 current_scrollbar_value = long(value);
462 if (current_scrollbar_value < 0)
463 current_scrollbar_value = 0;
468 screen->Draw(current_scrollbar_value);
470 if (cursor_follows_scrollbar) {
471 LyXText * vbt = text;
472 int height = vbt->DefaultHeight();
474 if (vbt->cursor.y < screen->first + height) {
475 vbt->SetCursorFromCoordinates(0,
478 } else if (vbt->cursor.y >
479 screen->first + workarea->height() - height) {
480 vbt->SetCursorFromCoordinates(0,
490 // Callback for scrollbar down button
491 void BufferView::downCB(long time, int button)
493 if (buffer_ == 0) return;
509 int BufferView::scrollUp(long time)
511 if (buffer_ == 0) return 0;
512 if (!screen) return 0;
514 double value = workarea->getScrollbarValue();
516 if (value == 0) return 0;
518 float add_value = (text->DefaultHeight()
519 + float(time) * float(time) * 0.125);
521 if (add_value > workarea->height())
522 add_value = float(workarea->height() -
523 text->DefaultHeight());
530 workarea->setScrollbarValue(value);
537 int BufferView::scrollDown(long time)
539 if (buffer_ == 0) return 0;
540 if (!screen) return 0;
542 double value= workarea->getScrollbarValue();
543 pair<double, double> p = workarea->getScrollbarBounds();
544 double max = p.second;
546 if (value == max) return 0;
548 float add_value = (text->DefaultHeight()
549 + float(time) * float(time) * 0.125);
551 if (add_value > workarea->height())
552 add_value = float(workarea->height() -
553 text->DefaultHeight());
560 workarea->setScrollbarValue(value);
567 void BufferView::scrollUpOnePage()
569 if (buffer_ == 0) return;
572 long y = screen->first;
576 Row * row = text->GetRowNearY(y);
578 y = y - workarea->height() + row->height;
580 workarea->setScrollbarValue(y);
586 void BufferView::scrollDownOnePage()
588 if (buffer_ == 0) return;
591 long y = screen->first;
593 if (y > text->height - workarea->height())
596 y += workarea->height();
597 text->GetRowNearY(y);
599 workarea->setScrollbarValue(y);
605 void BufferView::workAreaMotionNotify(int x, int y, unsigned int state)
607 if (buffer_ == 0 || !screen) return;
609 // Check for inset locking
610 if (the_locking_inset) {
611 LyXCursor cursor = text->cursor;
613 InsetMotionNotify(x - cursor.x,
619 // Only use motion with button 1
620 if (!state & Button1MotionMask)
623 /* The selection possible is needed, that only motion events are
624 * used, where the bottom press event was on the drawing area too */
625 if (selection_possible) {
626 screen->HideCursor();
628 text->SetCursorFromCoordinates(x, y + screen->first);
630 if (!text->selection)
631 update(-3); // Maybe an empty line was deleted
633 text->SetSelection();
634 screen->ToggleToggle();
635 if (screen->FitCursor())
637 screen->ShowCursor();
643 extern int bibitemMaxWidth(Painter &, LyXFont const &);
646 // Single-click on work area
647 void BufferView::workAreaButtonPress(int xpos, int ypos, unsigned int button)
652 if (buffer_ == 0 || !screen) return;
654 Inset * inset_hit = checkInsetHit(xpos, ypos);
656 // ok ok, this is a hack.
657 if (button == 4 || button == 5) {
660 scrollUp(100); // This number is only temporary
668 if (the_locking_inset) {
669 // We are in inset locking mode
671 /* Check whether the inset was hit. If not reset mode,
672 otherwise give the event to the inset */
675 InsetButtonPress(xpos, ypos,
679 unlockInset(the_locking_inset);
683 selection_possible = true;
684 screen->HideCursor();
686 // Right button mouse click on a table
688 (text->cursor.par->table ||
689 text->MouseHitInTable(xpos, ypos + screen->first))) {
690 // Set the cursor to the press-position
691 text->SetCursorFromCoordinates(xpos, ypos + screen->first);
694 // Only show the table popup if the hit is in
696 if (!text->HitInTable(text->cursor.row, xpos))
699 // Hit above or below the table?
701 if (!text->selection) {
702 screen->ToggleSelection();
703 text->ClearSelection();
708 // Popup table popup when on a table.
709 // This is obviously temporary, since we
710 // should be able to popup various
711 // context-sensitive-menus with the
712 // the right mouse. So this should be done more
713 // general in the future. Matthias.
714 selection_possible = false;
716 ->Dispatch(LFUN_LAYOUT_TABLE,
722 int screen_first = screen->first;
724 // Middle button press pastes if we have a selection
725 bool paste_internally = false;
727 && text->selection) {
728 owner_->getLyXFunc()->Dispatch(LFUN_COPY);
729 paste_internally = true;
732 // Clear the selection
733 screen->ToggleSelection();
734 text->ClearSelection();
739 // Single left click in math inset?
740 if (inset_hit != 0 && inset_hit->Editable() == 2) {
741 // Highly editable inset, like math
742 selection_possible = false;
743 owner_->updateLayoutChoice();
744 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
745 inset_hit->Edit(xpos, ypos);
749 // Right click on a footnote flag opens float menu
751 selection_possible = false;
755 text->SetCursorFromCoordinates(xpos, ypos + screen_first);
757 text->sel_cursor = text->cursor;
758 text->cursor.x_fix = text->cursor.x;
760 owner_->updateLayoutChoice();
761 if (screen->FitCursor()){
763 selection_possible = false;
766 // Insert primary selection with middle mouse
767 // if there is a local selection in the current buffer,
770 if (paste_internally)
771 owner_->getLyXFunc()->Dispatch(LFUN_PASTE);
773 owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION,
775 selection_possible = false;
781 void BufferView::workAreaButtonRelease(int x, int y, unsigned int button)
783 if (buffer_ == 0 || screen == 0) return;
785 // If we hit an inset, we have the inset coordinates in these
786 // and inset_hit points to the inset. If we do not hit an
787 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
788 Inset * inset_hit = checkInsetHit(x, y);
790 if (the_locking_inset) {
791 // We are in inset locking mode.
793 /* LyX does a kind of work-area grabbing for insets.
794 Only a ButtonPress Event outside the inset will
795 force a InsetUnlock. */
797 InsetButtonRelease(x, x, button);
801 selection_possible = false;
802 if (text->cursor.par->table) {
804 NumberOfCell(text->cursor.par,
806 if (text->cursor.par->table->IsContRow(cell) &&
807 text->cursor.par->table->
808 CellHasContRow(text->cursor.par->table->
809 GetCellAbove(cell))<0) {
814 if (button >= 2) return;
817 owner_->getMiniBuffer()->Set(CurrentState());
819 // Did we hit an editable inset?
820 if (inset_hit != 0) {
821 // Inset like error, notes and figures
822 selection_possible = false;
824 #warning fix this proper in 0.13
826 // Following a ref shouldn't issue
827 // a push on the undo-stack
828 // anylonger, now that we have
829 // keybindings for following
830 // references and returning from
831 // references. IMHO though, it
832 // should be the inset's own business
833 // to push or not push on the undo
834 // stack. They don't *have* to
835 // alter the document...
837 // ...or maybe the SetCursorParUndo()
838 // below isn't necessary at all anylonger?
839 if (inset_hit->LyxCode() == Inset::REF_CODE) {
840 text->SetCursorParUndo();
843 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
844 inset_hit->Edit(x, y);
848 // check whether we want to open a float
852 if (text->cursor.pos <
853 text->cursor.par->Last()) {
854 c = text->cursor.par->
855 GetChar(text->cursor.pos);
857 if (c == LyXParagraph::META_FOOTNOTE
858 || c == LyXParagraph::META_MARGIN
859 || c == LyXParagraph::META_FIG
860 || c == LyXParagraph::META_TAB
861 || c == LyXParagraph::META_WIDE_FIG
862 || c == LyXParagraph::META_WIDE_TAB
863 || c == LyXParagraph::META_ALGORITHM){
865 } else if (text->cursor.pos - 1 >= 0) {
866 c = text->cursor.par->
867 GetChar(text->cursor.pos - 1);
868 if (c == LyXParagraph::META_FOOTNOTE
869 || c == LyXParagraph::META_MARGIN
870 || c == LyXParagraph::META_FIG
871 || c == LyXParagraph::META_TAB
872 || c == LyXParagraph::META_WIDE_FIG
873 || c == LyXParagraph::META_WIDE_TAB
874 || c == LyXParagraph::META_ALGORITHM){
875 // We are one step too far to the right
882 selection_possible = false;
887 // Do we want to close a float? (click on the float-label)
888 if (text->cursor.row->par->footnoteflag ==
889 LyXParagraph::OPEN_FOOTNOTE
890 //&& text->cursor.pos == 0
891 && text->cursor.row->previous &&
892 text->cursor.row->previous->par->
893 footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
894 LyXFont font(LyXFont::ALL_SANE);
895 font.setSize(LyXFont::SIZE_FOOTNOTE);
897 int box_x = 20; // LYX_PAPER_MARGIN;
898 box_x += font.textWidth(" wide-tab ", 10);
900 int screen_first = screen->first;
903 && y + screen_first > text->cursor.y -
904 text->cursor.row->baseline
905 && y + screen_first < text->cursor.y -
906 text->cursor.row->baseline
907 + font.maxAscent() * 1.2 + font.maxDescent() * 1.2) {
909 selection_possible = false;
914 // Maybe we want to edit a bibitem ale970302
915 if (text->cursor.par->bibkey && x < 20 +
916 bibitemMaxWidth(painter(),
919 params.textclass).defaultfont())) {
920 text->cursor.par->bibkey->Edit(0, 0);
928 * Returns an inset if inset was hit. 0 otherwise.
929 * If hit, the coordinates are changed relative to the inset.
930 * Otherwise coordinates are not changed, and false is returned.
932 Inset * BufferView::checkInsetHit(int & x, int & y)
937 int y_tmp = y + screen->first;
939 LyXCursor & cursor = text->cursor;
940 LyXDirection direction = text->real_current_font.getFontDirection();
942 if (cursor.pos < cursor.par->Last()
943 && cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET
944 && cursor.par->GetInset(cursor.pos)
945 && cursor.par->GetInset(cursor.pos)->Editable()) {
947 // Check whether the inset really was hit
948 Inset * tmpinset = cursor.par->GetInset(cursor.pos);
949 LyXFont font = text->GetFont(cursor.par, cursor.pos);
951 if (direction == LYX_DIR_LEFT_TO_RIGHT) {
953 end_x = cursor.x + tmpinset->width(painter(), font);
955 start_x = cursor.x - tmpinset->width(painter(), font);
959 if (x > start_x && x < end_x
960 && y_tmp > cursor.y - tmpinset->ascent(painter(), font)
961 && y_tmp < cursor.y + tmpinset->descent(painter(), font)) {
963 // The origin of an inset is on the baseline
964 y = y_tmp - (cursor.y);
969 if (cursor.pos - 1 >= 0
970 && cursor.par->GetChar(cursor.pos - 1) == LyXParagraph::META_INSET
971 && cursor.par->GetInset(cursor.pos - 1)
972 && cursor.par->GetInset(cursor.pos - 1)->Editable()) {
974 Inset * tmpinset = cursor.par->GetInset(cursor.pos);
975 LyXFont font = text->GetFont(cursor.par, cursor.pos);
977 if (direction == LYX_DIR_LEFT_TO_RIGHT) {
979 end_x = cursor.x + tmpinset->width(painter(), font);
981 start_x = cursor.x - tmpinset->width(painter(), font);
984 if (x > start_x && x < end_x
985 && y_tmp > cursor.y - tmpinset->ascent(painter(), font)
986 && y_tmp < cursor.y + tmpinset->descent(painter(), font)) {
988 // The origin of an inset is on the baseline
989 y = y_tmp - (cursor.y);
1000 void BufferView::workAreaExpose()
1002 // this is a hack to ensure that we only call this through
1003 // BufferView::redraw().
1008 static int work_area_width = -1;
1009 static int work_area_height = -1;
1011 bool widthChange = workarea->workWidth() != work_area_width;
1012 bool heightChange = workarea->height() != work_area_height;
1014 // update from work area
1015 work_area_width = workarea->workWidth();
1016 work_area_height = workarea->height();
1019 // All buffers need a resize
1020 bufferlist.resize();
1022 // Remove all texts from the textcache
1023 // This is not _really_ what we want to do. What
1024 // we really want to do is to delete in textcache
1025 // that does not have a BufferView with matching
1026 // width, but as long as we have only one BufferView
1027 // deleting all gives the same result.
1028 if (lyxerr.debugging())
1029 textcache.show(lyxerr, "Expose delete all");
1031 } else if (heightChange) {
1032 // Rebuild image of current screen
1034 // fitCursor() ensures we don't jump back
1035 // to the start of the document on vertical
1039 // The main window size has changed, repaint most stuff
1041 // ...including the minibuffer
1042 owner_->getMiniBuffer()->Init();
1044 } else if (screen) screen->Redraw();
1046 // Grey box when we don't have a buffer
1047 workarea->greyOut();
1050 // always make sure that the scrollbar is sane.
1052 owner_->updateLayoutChoice();
1057 // Callback for cursor timer
1058 void BufferView::cursorToggleCB(FL_OBJECT * ob, long)
1060 BufferView * view = static_cast<BufferView*>(ob->u_vdata);
1062 // Quite a nice place for asyncron Inset updating, isn't it?
1063 // Actually no! This is run even if no buffer exist... so (Lgb)
1064 if (view && !view->buffer_) {
1065 goto set_timer_and_return;
1069 // On my quest to solve the gs render hangups I am now
1070 // disabling the SIGHUP completely, and will do a wait
1071 // now and then instead. If the guess that xforms somehow
1072 // destroys something is true, this is likely (hopefully)
1073 // to solve the problem...at least I hope so. Lgb
1075 // ...Ok this seems to work...at least it does not make things
1076 // worse so far. However I still see gs processes that hangs.
1077 // I would really like to know _why_ they are hanging. Anyway
1078 // the solution without the SIGCHLD handler seems to be easier
1081 // When attaching gdb to a a running gs that hangs it shows
1082 // that it is waiting for input(?) Is it possible for us to
1083 // provide that input somehow? Or figure what it is expecing
1086 // One solution is to, after some time, look if there are some
1087 // old gs processes still running and if there are: kill them
1090 // Another solution is to provide the user an option to rerender
1091 // a picture. This would, for the picture in question, check if
1092 // there is a gs running for it, if so kill it, and start a new
1093 // rendering process.
1095 // these comments posted to lyx@via
1098 int pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1099 if (pid == -1) // error find out what is wrong
1100 ; // ignore it for now.
1102 sigchldhandler(pid, &status);
1104 if (InsetUpdateList)
1105 UpdateInsetUpdateList();
1107 if (view && !view->screen){
1108 goto set_timer_and_return;
1111 if (view->lyx_focus && view->work_area_focus) {
1112 if (!view->the_locking_inset) {
1113 view->screen->CursorToggle();
1115 view->the_locking_inset->
1116 ToggleInsetCursor();
1118 goto set_timer_and_return;
1120 // Make sure that the cursor is visible.
1121 if (!view->the_locking_inset) {
1122 view->screen->ShowCursor();
1124 if (!view->the_locking_inset->isCursorVisible())
1125 view->the_locking_inset->
1126 ToggleInsetCursor();
1128 // This is only run when work_area_focus or lyx_focus is false.
1131 XGetInputFocus(fl_display, &tmpwin, &tmp);
1132 // Commenting this out, we have not had problems with this
1133 // for a long time. We will probably work on this code later
1134 // and we can reenable this debug code then. Now it only
1135 // anoying when debugging. (Lgb)
1136 //if (lyxerr.debugging(Debug::INFO)) {
1137 // lyxerr << "tmpwin: " << tmpwin
1138 // << "\nwindow: " << view->owner_->getForm()->window
1139 // << "\nwork_area_focus: " << view->work_area_focus
1140 // << "\nlyx_focus : " << view->lyx_focus
1143 if (tmpwin != view->owner_->getForm()->window) {
1144 view->lyx_focus = false;
1147 view->lyx_focus = true;
1148 if (!view->work_area_focus)
1151 goto set_timer_and_return;
1155 set_timer_and_return:
1156 fl_set_timer(ob, 0.4);
1163 string fromClipboard(Window win, XEvent * event)
1166 if (event->xselection.type == XA_STRING
1167 && event->xselection.property) {
1171 unsigned char * uc = 0;
1173 if (XGetWindowProperty(
1174 event->xselection.display, // display
1176 event->xselection.property, // property
1180 XA_STRING, // req_type
1181 &tmpatom, // actual_type_return
1182 &tmpint, // actual_format_return
1193 if (XGetWindowProperty(
1194 event->xselection.display, // display
1196 event->xselection.property, // property
1198 ul2/4+1, // long_length
1200 XA_STRING, // req_type
1201 &tmpatom, // actual_type_return
1202 &tmpint, // actual_format_return
1203 &ul1, // nitems_return
1204 &ul2, // bytes_after_return
1205 &uc // prop_return */
1210 strret = reinterpret_cast<char*>(uc);
1211 free(uc); // yes free!
1219 void BufferView::workAreaSelectionNotify(Window win, XEvent * event)
1221 if (buffer_ == 0) return;
1223 screen->HideCursor();
1225 string clb = fromClipboard(win, event);
1228 text->InsertStringA(clb.c_str());
1230 text->InsertStringB(clb.c_str());
1238 void BufferView::cursorPrevious()
1240 if (!text->cursor.row->previous) return;
1242 long y = screen->first;
1243 Row * cursorrow = text->cursor.row;
1244 text->SetCursorFromCoordinates(text->cursor.x_fix, y);
1246 // This is to allow jumping over large insets
1247 if ((cursorrow == text->cursor.row))
1250 if (text->cursor.row->height < workarea->height())
1251 screen->Draw(text->cursor.y
1252 - text->cursor.row->baseline
1253 + text->cursor.row->height
1254 - workarea->height() + 1 );
1258 void BufferView::cursorNext()
1260 if (!text->cursor.row->next) return;
1262 long y = screen->first;
1263 text->GetRowNearY(y);
1264 Row * cursorrow = text->cursor.row;
1265 text->SetCursorFromCoordinates(text->cursor.x_fix, y
1266 + workarea->height());
1268 // This is to allow jumping over large insets
1269 if ((cursorrow == text->cursor.row))
1272 if (text->cursor.row->height < workarea->height())
1273 screen->Draw(text->cursor.y
1274 - text->cursor.row->baseline);
1278 bool BufferView::available() const
1280 if (buffer_ && text) return true;
1285 void BufferView::beforeChange()
1288 text->ClearSelection();
1293 void BufferView::savePosition()
1295 backstack.push(buffer()->fileName(),
1301 void BufferView::restorePosition()
1303 if (backstack.empty()) return;
1306 string fname = backstack.pop(&x, &y);
1309 Buffer * b = bufferlist.exists(fname) ?
1310 bufferlist.getBuffer(fname) :
1311 bufferlist.loadLyXFile(fname); // don't ask, just load it
1313 text->SetCursorFromCoordinates(x, y);
1318 void BufferView::update(signed char f)
1320 owner()->updateLayoutChoice();
1322 if (!text->selection && f > -3)
1323 text->sel_cursor = text->cursor;
1326 text->FullRebreak();
1330 if (f != 3 && f != -3) {
1335 if (f == 1 || f == -1) {
1336 if (buffer()->isLyxClean()) {
1337 buffer()->markDirty();
1338 owner()->getMiniBuffer()->setTimer(4);
1340 buffer()->markDirty();
1346 void BufferView::smallUpdate(signed char f)
1348 screen->SmallUpdate();
1349 if (screen->TopCursorVisible()
1358 if (!text->selection)
1359 text->sel_cursor = text->cursor;
1361 if (f == 1 || f == -1) {
1362 if (buffer()->isLyxClean()) {
1363 buffer()->markDirty();
1364 owner()->getMiniBuffer()->setTimer(4);
1366 buffer()->markDirty();
1372 void BufferView::setState()
1374 if (!lyxrc->rtl_support)
1377 if (text->real_current_font.getFontDirection()
1378 == LYX_DIR_LEFT_TO_RIGHT) {
1379 if (!owner_->getIntl()->primarykeymap)
1380 owner_->getIntl()->KeyMapPrim();
1382 if (owner_->getIntl()->primarykeymap)
1383 owner_->getIntl()->KeyMapSec();
1388 void BufferView::insetSleep()
1390 if (the_locking_inset && !inset_slept) {
1391 the_locking_inset->GetCursorPos(slx, sly);
1392 the_locking_inset->InsetUnlock();
1398 void BufferView::insetWakeup()
1400 if (the_locking_inset && inset_slept) {
1401 the_locking_inset->Edit(slx, sly);
1402 inset_slept = false;
1407 void BufferView::insetUnlock()
1409 if (the_locking_inset) {
1410 if (!inset_slept) the_locking_inset->InsetUnlock();
1411 the_locking_inset = 0;
1413 inset_slept = false;
1418 bool BufferView::focus() const
1420 return workarea->hasFocus();
1424 void BufferView::focus(bool f)
1426 if (f) workarea->setFocus();
1430 bool BufferView::active() const
1432 return workarea->active();
1436 void BufferView::showCursor()
1439 screen->ShowCursor();
1443 void BufferView::hideCursor()
1446 screen->HideCursor();
1450 void BufferView::toggleSelection(bool b)
1453 screen->ToggleSelection(b);
1457 void BufferView::toggleToggle()
1460 screen->ToggleToggle();
1464 void BufferView::center()
1467 if (text->cursor.y > workarea->height() / 2) {
1468 screen->Draw(text->cursor.y - workarea->height() / 2);