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 void FreeUpdateTimer();
66 BufferView::BufferView(LyXView * o, int xpos, int ypos,
67 int width, int height)
72 workarea = new WorkArea(this, xpos, ypos, width, height);
76 current_scrollbar_value = 0;
77 // Activate the timer for the cursor
78 fl_set_timer(timer_cursor, 0.4);
80 work_area_focus = true;
82 the_locking_inset = 0;
87 BufferView::~BufferView()
93 Painter & BufferView::painter()
95 return workarea->getPainter();
99 void BufferView::buffer(Buffer * b)
101 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
105 buffer_->delUser(this);
107 // Put the old text into the TextCache, but
108 // only if the buffer is still loaded.
109 // Also set the owner of the test to 0
112 if (lyxerr.debugging())
113 textcache.show(lyxerr, "BufferView::buffer");
118 // Set current buffer
121 if (bufferlist.getState() == BufferList::CLOSING) return;
124 // screen is always deleted when the buffer is changed.
128 // If we are closing the buffer, use the first buffer as current
130 buffer_ = bufferlist.first();
134 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
135 buffer_->addUser(this);
136 owner_->getMenus()->showMenus();
137 // If we don't have a text object for this, we make one
139 resizeCurrentBuffer();
144 screen->first = screen->TopCursorVisible();
146 updateAllVisibleBufferRelatedPopups();
149 lyxerr[Debug::INFO] << " No Buffer!" << endl;
150 owner_->getMenus()->hideMenus();
154 // Also remove all remaining text's from the testcache.
155 // (there should not be any!) (if there is any it is a
157 if (lyxerr.debugging())
158 textcache.show(lyxerr, "buffer delete all");
161 // should update layoutchoice even if we don't have a buffer.
162 owner_->updateLayoutChoice();
163 owner_->getMiniBuffer()->Init();
164 owner_->updateWindowTitle();
168 void BufferView::updateScreen()
170 // Regenerate the screen.
172 screen = new LyXScreen(*workarea, text);
176 void BufferView::resize(int xpos, int ypos, int width, int height)
178 workarea->resize(xpos, ypos, width, height);
184 void BufferView::resize()
186 // This will resize the buffer. (Asger)
188 resizeCurrentBuffer();
192 void BufferView::redraw()
194 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
199 void BufferView::fitCursor()
201 if (screen) screen->FitCursor();
206 void BufferView::update()
208 if (screen) screen->Update();
212 void BufferView::updateScrollbar()
214 /* If the text is smaller than the working area, the scrollbar
215 * maximum must be the working area height. No scrolling will
219 workarea->setScrollbar(0, 1.0);
223 static long max2 = 0;
224 static long height2 = 0;
232 cbsf = screen->first;
234 // check if anything has changed.
236 height2 == workarea->height() &&
237 current_scrollbar_value == cbsf)
240 height2 = workarea->height();
241 current_scrollbar_value = cbsf;
243 if (cbth <= height2) { // text is smaller than screen
244 workarea->setScrollbar(0, 1.0); // right?
248 long maximum_height = workarea->height() * 3 / 4 + cbth;
252 double hfloat = workarea->height();
253 double maxfloat = maximum_height;
255 float slider_size = 0.0;
256 int slider_value = value;
258 workarea->setScrollbarBounds(0, text->height - workarea->height());
259 double lineh = text->DefaultHeight();
260 workarea->setScrollbarIncrements(lineh);
261 if (maxfloat > 0.0) {
262 if ((hfloat / maxfloat) * float(height2) < 3)
263 slider_size = 3.0/float(height2);
265 slider_size = hfloat / maxfloat;
267 slider_size = hfloat;
269 workarea->setScrollbar(slider_value, slider_size / workarea->height());
273 void BufferView::redoCurrentBuffer()
275 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
276 if (buffer_ && text) {
278 owner_->updateLayoutChoice();
283 int BufferView::resizeCurrentBuffer()
285 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
287 LyXParagraph * par = 0;
288 LyXParagraph * selstartpar = 0;
289 LyXParagraph * selendpar = 0;
298 owner_->getMiniBuffer()->Set(_("Formatting document..."));
301 par = text->cursor.par;
302 pos = text->cursor.pos;
303 selstartpar = text->sel_start_cursor.par;
304 selstartpos = text->sel_start_cursor.pos;
305 selendpar = text->sel_end_cursor.par;
306 selendpos = text->sel_end_cursor.pos;
307 selection = text->selection;
308 mark_set = text->mark_set;
310 text = new LyXText(this, workarea->workWidth(), buffer_);
312 // See if we have a text in TextCache that fits
313 // the new buffer_ with the correct width.
314 text = textcache.findFit(buffer_, workarea->workWidth());
316 if (lyxerr.debugging()) {
317 lyxerr << "Found a LyXText that fits:\n";
318 textcache.show(lyxerr, text);
320 // Set the owner of the newly found text
322 if (lyxerr.debugging())
323 textcache.show(lyxerr, "resizeCurrentBuffer");
325 text = new LyXText(this, workarea->workWidth(), buffer_);
331 text->selection = true;
332 /* at this point just to avoid the Delete-Empty-Paragraph
333 * Mechanism when setting the cursor */
334 text->mark_set = mark_set;
336 text->SetCursor(selstartpar, selstartpos);
337 text->sel_cursor = text->cursor;
338 text->SetCursor(selendpar, selendpos);
339 text->SetSelection();
340 text->SetCursor(par, pos);
342 text->SetCursor(par, pos);
343 text->sel_cursor = text->cursor;
344 text->selection = false;
347 screen->first = screen->TopCursorVisible(); /* this will scroll the
348 * screen such that the
353 owner_->getMiniBuffer()->Init();
357 // Now if the title form still exist kill it
364 void BufferView::gotoError()
369 screen->HideCursor();
374 if (!text->GotoNextError()) {
376 || text->cursor.par != text->FirstParagraph()) {
378 text->cursor.par = text->FirstParagraph();
379 text->cursor.pos = 0;
380 if (!text->GotoNextError()) {
382 owner_->getMiniBuffer()
383 ->Set(_("No more errors"));
387 owner_->getMiniBuffer()->Set(_("No more errors"));
392 text->sel_cursor = text->cursor;
397 void C_BufferView_CursorToggleCB(FL_OBJECT * ob, long buf)
399 BufferView::cursorToggleCB(ob, buf);
404 void BufferView::create_view()
413 timer_cursor = obj = fl_add_timer(FL_HIDDEN_TIMER,
414 0, 0, 0, 0, "Timer");
415 fl_set_object_callback(obj, C_BufferView_CursorToggleCB, 0);
420 // Callback for scrollbar up button
421 void BufferView::upCB(long time, int button)
423 if (buffer_ == 0) return;
442 XSync(fl_get_display(), 0);
446 // Callback for scrollbar slider
447 void BufferView::scrollCB(double value)
449 extern bool cursor_follows_scrollbar;
451 if (buffer_ == 0) return;
453 current_scrollbar_value = long(value);
454 if (current_scrollbar_value < 0)
455 current_scrollbar_value = 0;
460 screen->Draw(current_scrollbar_value);
462 if (cursor_follows_scrollbar) {
463 LyXText * vbt = text;
464 int height = vbt->DefaultHeight();
466 if (vbt->cursor.y < screen->first + height) {
467 vbt->SetCursorFromCoordinates(0,
470 } else if (vbt->cursor.y >
471 screen->first + workarea->height() - height) {
472 vbt->SetCursorFromCoordinates(0,
482 // Callback for scrollbar down button
483 void BufferView::downCB(long time, int button)
485 if (buffer_ == 0) return;
501 int BufferView::scrollUp(long time)
503 if (buffer_ == 0) return 0;
504 if (!screen) return 0;
506 double value = workarea->getScrollbarValue();
508 if (value == 0) return 0;
510 float add_value = (text->DefaultHeight()
511 + float(time) * float(time) * 0.125);
513 if (add_value > workarea->height())
514 add_value = float(workarea->height() -
515 text->DefaultHeight());
522 workarea->setScrollbarValue(value);
529 int BufferView::scrollDown(long time)
531 if (buffer_ == 0) return 0;
532 if (!screen) return 0;
534 double value= workarea->getScrollbarValue();
535 pair<double, double> p = workarea->getScrollbarBounds();
536 double max = p.second;
538 if (value == max) return 0;
540 float add_value = (text->DefaultHeight()
541 + float(time) * float(time) * 0.125);
543 if (add_value > workarea->height())
544 add_value = float(workarea->height() -
545 text->DefaultHeight());
552 workarea->setScrollbarValue(value);
559 void BufferView::scrollUpOnePage()
561 if (buffer_ == 0) return;
564 long y = screen->first;
568 Row * row = text->GetRowNearY(y);
570 y = y - workarea->height() + row->height;
572 workarea->setScrollbarValue(y);
578 void BufferView::scrollDownOnePage()
580 if (buffer_ == 0) return;
583 long y = screen->first;
585 if (y > text->height - workarea->height())
588 y += workarea->height();
589 text->GetRowNearY(y);
591 workarea->setScrollbarValue(y);
597 void BufferView::workAreaMotionNotify(int x, int y, unsigned int state)
599 if (buffer_ == 0 || !screen) return;
601 // Check for inset locking
602 if (the_locking_inset) {
603 LyXCursor cursor = text->cursor;
605 InsetMotionNotify(this,
612 // Only use motion with button 1
613 if (!state & Button1MotionMask)
616 /* The selection possible is needed, that only motion events are
617 * used, where the bottom press event was on the drawing area too */
618 if (selection_possible) {
619 screen->HideCursor();
621 text->SetCursorFromCoordinates(x, y + screen->first);
623 if (!text->selection)
624 update(-3); // Maybe an empty line was deleted
626 text->SetSelection();
627 screen->ToggleToggle();
628 if (screen->FitCursor())
630 screen->ShowCursor();
636 extern int bibitemMaxWidth(Painter &, LyXFont const &);
639 // Single-click on work area
640 void BufferView::workAreaButtonPress(int xpos, int ypos, unsigned int button)
645 if (buffer_ == 0 || !screen) return;
647 Inset * inset_hit = checkInsetHit(xpos, ypos);
649 // ok ok, this is a hack.
650 if (button == 4 || button == 5) {
653 scrollUp(100); // This number is only temporary
661 if (the_locking_inset) {
662 // We are in inset locking mode
664 /* Check whether the inset was hit. If not reset mode,
665 otherwise give the event to the inset */
668 InsetButtonPress(this,
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()==Inset::HIGHLY_EDITABLE) {
735 // Highly editable inset, like math
736 selection_possible = false;
737 owner_->updateLayoutChoice();
738 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
739 inset_hit->Edit(this, xpos, ypos, button);
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::doubleClick(int /*x*/, int /*y*/, unsigned int button)
778 if (buffer_ && !the_locking_inset) {
779 if (screen && button == 1) {
780 screen->HideCursor();
781 screen->ToggleSelection();
783 screen->ToggleSelection(false);
784 /* This will fit the cursor on the screen
792 void BufferView::tripleClick(int /*x*/, int /*y*/, unsigned int button)
795 if (buffer_ && screen && button == 1) {
796 screen->HideCursor();
797 screen->ToggleSelection();
799 text->sel_cursor = text->cursor;
801 text->SetSelection();
802 screen->ToggleSelection(false);
803 /* This will fit the cursor on the screen
810 void BufferView::workAreaButtonRelease(int x, int y, unsigned int button)
812 if (buffer_ == 0 || screen == 0) return;
814 // If we hit an inset, we have the inset coordinates in these
815 // and inset_hit points to the inset. If we do not hit an
816 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
817 Inset * inset_hit = checkInsetHit(x, y);
819 if (the_locking_inset) {
820 // We are in inset locking mode.
822 /* LyX does a kind of work-area grabbing for insets.
823 Only a ButtonPress Event outside the inset will
824 force a InsetUnlock. */
826 InsetButtonRelease(this, x, y, button);
830 selection_possible = false;
831 if (text->cursor.par->table) {
833 NumberOfCell(text->cursor.par,
835 if (text->cursor.par->table->IsContRow(cell) &&
836 text->cursor.par->table->
837 CellHasContRow(text->cursor.par->table->
838 GetCellAbove(cell))<0) {
843 if (button >= 2) return;
846 owner_->getMiniBuffer()->Set(CurrentState());
848 // Did we hit an editable inset?
849 if (inset_hit != 0) {
850 // Inset like error, notes and figures
851 selection_possible = false;
853 #warning fix this proper in 0.13
855 // Following a ref shouldn't issue
856 // a push on the undo-stack
857 // anylonger, now that we have
858 // keybindings for following
859 // references and returning from
860 // references. IMHO though, it
861 // should be the inset's own business
862 // to push or not push on the undo
863 // stack. They don't *have* to
864 // alter the document...
866 // ...or maybe the SetCursorParUndo()
867 // below isn't necessary at all anylonger?
868 if (inset_hit->LyxCode() == Inset::REF_CODE) {
869 text->SetCursorParUndo();
872 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
873 inset_hit->Edit(this, x, y, button);
877 // check whether we want to open a float
881 if (text->cursor.pos <
882 text->cursor.par->Last()) {
883 c = text->cursor.par->
884 GetChar(text->cursor.pos);
886 if (c == LyXParagraph::META_FOOTNOTE
887 || c == LyXParagraph::META_MARGIN
888 || c == LyXParagraph::META_FIG
889 || c == LyXParagraph::META_TAB
890 || c == LyXParagraph::META_WIDE_FIG
891 || c == LyXParagraph::META_WIDE_TAB
892 || c == LyXParagraph::META_ALGORITHM){
894 } else if (text->cursor.pos - 1 >= 0) {
895 c = text->cursor.par->
896 GetChar(text->cursor.pos - 1);
897 if (c == LyXParagraph::META_FOOTNOTE
898 || c == LyXParagraph::META_MARGIN
899 || c == LyXParagraph::META_FIG
900 || c == LyXParagraph::META_TAB
901 || c == LyXParagraph::META_WIDE_FIG
902 || c == LyXParagraph::META_WIDE_TAB
903 || c == LyXParagraph::META_ALGORITHM){
904 // We are one step too far to the right
911 selection_possible = false;
916 // Do we want to close a float? (click on the float-label)
917 if (text->cursor.row->par->footnoteflag ==
918 LyXParagraph::OPEN_FOOTNOTE
919 //&& text->cursor.pos == 0
920 && text->cursor.row->previous &&
921 text->cursor.row->previous->par->
922 footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
923 LyXFont font(LyXFont::ALL_SANE);
924 font.setSize(LyXFont::SIZE_FOOTNOTE);
926 int box_x = 20; // LYX_PAPER_MARGIN;
927 box_x += font.textWidth(" wide-tab ", 10);
929 int screen_first = screen->first;
932 && y + screen_first > text->cursor.y -
933 text->cursor.row->baseline
934 && y + screen_first < text->cursor.y -
935 text->cursor.row->baseline
936 + font.maxAscent() * 1.2 + font.maxDescent() * 1.2) {
938 selection_possible = false;
943 // Maybe we want to edit a bibitem ale970302
944 if (text->cursor.par->bibkey && x < 20 +
945 bibitemMaxWidth(painter(),
948 params.textclass).defaultfont())) {
949 text->cursor.par->bibkey->Edit(this, 0, 0, 0);
957 * Returns an inset if inset was hit. 0 otherwise.
958 * If hit, the coordinates are changed relative to the inset.
959 * Otherwise coordinates are not changed, and false is returned.
961 Inset * BufferView::checkInsetHit(int & x, int & y)
966 int y_tmp = y + screen->first;
968 LyXCursor & cursor = text->cursor;
969 LyXDirection direction = text->real_current_font.getFontDirection();
971 if (cursor.pos < cursor.par->Last()
972 && cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET
973 && cursor.par->GetInset(cursor.pos)
974 && cursor.par->GetInset(cursor.pos)->Editable()) {
976 // Check whether the inset really was hit
977 Inset * tmpinset = cursor.par->GetInset(cursor.pos);
978 LyXFont font = text->GetFont(cursor.par, cursor.pos);
980 if (direction == LYX_DIR_LEFT_TO_RIGHT) {
982 end_x = cursor.x + tmpinset->width(painter(), font);
984 start_x = cursor.x - tmpinset->width(painter(), font);
988 if (x > start_x && x < end_x
989 && y_tmp > cursor.y - tmpinset->ascent(painter(), font)
990 && y_tmp < cursor.y + tmpinset->descent(painter(), font)) {
992 // The origin of an inset is on the baseline
993 y = y_tmp - (cursor.y);
998 if (cursor.pos - 1 >= 0
999 && cursor.par->GetChar(cursor.pos - 1) == LyXParagraph::META_INSET
1000 && cursor.par->GetInset(cursor.pos - 1)
1001 && cursor.par->GetInset(cursor.pos - 1)->Editable()) {
1003 Inset * tmpinset = cursor.par->GetInset(cursor.pos);
1004 LyXFont font = text->GetFont(cursor.par, cursor.pos);
1006 if (direction == LYX_DIR_LEFT_TO_RIGHT) {
1008 end_x = cursor.x + tmpinset->width(painter(), font);
1010 start_x = cursor.x - tmpinset->width(painter(), font);
1013 if (x > start_x && x < end_x
1014 && y_tmp > cursor.y - tmpinset->ascent(painter(), font)
1015 && y_tmp < cursor.y + tmpinset->descent(painter(), font)) {
1017 // The origin of an inset is on the baseline
1018 y = y_tmp - (cursor.y);
1021 text->CursorRight();
1028 void BufferView::workAreaExpose()
1030 // this is a hack to ensure that we only call this through
1031 // BufferView::redraw().
1036 static int work_area_width = -1;
1037 static int work_area_height = -1;
1039 bool widthChange = workarea->workWidth() != work_area_width;
1040 bool heightChange = workarea->height() != work_area_height;
1042 // update from work area
1043 work_area_width = workarea->workWidth();
1044 work_area_height = workarea->height();
1047 // All buffers need a resize
1048 bufferlist.resize();
1050 // Remove all texts from the textcache
1051 // This is not _really_ what we want to do. What
1052 // we really want to do is to delete in textcache
1053 // that does not have a BufferView with matching
1054 // width, but as long as we have only one BufferView
1055 // deleting all gives the same result.
1056 if (lyxerr.debugging())
1057 textcache.show(lyxerr, "Expose delete all");
1059 } else if (heightChange) {
1060 // Rebuild image of current screen
1062 // fitCursor() ensures we don't jump back
1063 // to the start of the document on vertical
1067 // The main window size has changed, repaint most stuff
1069 // ...including the minibuffer
1070 owner_->getMiniBuffer()->Init();
1072 } else if (screen) screen->Redraw();
1074 // Grey box when we don't have a buffer
1075 workarea->greyOut();
1078 // always make sure that the scrollbar is sane.
1080 owner_->updateLayoutChoice();
1085 // Callback for cursor timer
1086 void BufferView::cursorToggleCB(FL_OBJECT * ob, long)
1088 BufferView * view = static_cast<BufferView*>(ob->u_vdata);
1090 // Quite a nice place for asyncron Inset updating, isn't it?
1091 // Actually no! This is run even if no buffer exist... so (Lgb)
1092 if (view && !view->buffer_) {
1093 goto set_timer_and_return;
1097 // On my quest to solve the gs render hangups I am now
1098 // disabling the SIGHUP completely, and will do a wait
1099 // now and then instead. If the guess that xforms somehow
1100 // destroys something is true, this is likely (hopefully)
1101 // to solve the problem...at least I hope so. Lgb
1103 // ...Ok this seems to work...at least it does not make things
1104 // worse so far. However I still see gs processes that hangs.
1105 // I would really like to know _why_ they are hanging. Anyway
1106 // the solution without the SIGCHLD handler seems to be easier
1109 // When attaching gdb to a a running gs that hangs it shows
1110 // that it is waiting for input(?) Is it possible for us to
1111 // provide that input somehow? Or figure what it is expecing
1114 // One solution is to, after some time, look if there are some
1115 // old gs processes still running and if there are: kill them
1118 // Another solution is to provide the user an option to rerender
1119 // a picture. This would, for the picture in question, check if
1120 // there is a gs running for it, if so kill it, and start a new
1121 // rendering process.
1123 // these comments posted to lyx@via
1126 int pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1127 if (pid == -1) // error find out what is wrong
1128 ; // ignore it for now.
1130 sigchldhandler(pid, &status);
1133 view->updatelist.update(view);
1135 if (view && !view->screen){
1136 goto set_timer_and_return;
1139 if (view->lyx_focus && view->work_area_focus) {
1140 if (!view->the_locking_inset) {
1141 view->screen->CursorToggle();
1143 view->the_locking_inset->
1144 ToggleInsetCursor(view);
1146 goto set_timer_and_return;
1148 // Make sure that the cursor is visible.
1149 if (!view->the_locking_inset) {
1150 view->screen->ShowCursor();
1152 if (!view->the_locking_inset->isCursorVisible())
1153 view->the_locking_inset->
1154 ToggleInsetCursor(view);
1156 // This is only run when work_area_focus or lyx_focus is false.
1159 XGetInputFocus(fl_display, &tmpwin, &tmp);
1160 // Commenting this out, we have not had problems with this
1161 // for a long time. We will probably work on this code later
1162 // and we can reenable this debug code then. Now it only
1163 // anoying when debugging. (Lgb)
1164 //if (lyxerr.debugging(Debug::INFO)) {
1165 // lyxerr << "tmpwin: " << tmpwin
1166 // << "\nwindow: " << view->owner_->getForm()->window
1167 // << "\nwork_area_focus: " << view->work_area_focus
1168 // << "\nlyx_focus : " << view->lyx_focus
1171 if (tmpwin != view->owner_->getForm()->window) {
1172 view->lyx_focus = false;
1175 view->lyx_focus = true;
1176 if (!view->work_area_focus)
1179 goto set_timer_and_return;
1183 set_timer_and_return:
1184 fl_set_timer(ob, 0.4);
1191 string fromClipboard(Window win, XEvent * event)
1194 if (event->xselection.type == XA_STRING
1195 && event->xselection.property) {
1199 unsigned char * uc = 0;
1201 if (XGetWindowProperty(
1202 event->xselection.display, // display
1204 event->xselection.property, // property
1208 XA_STRING, // req_type
1209 &tmpatom, // actual_type_return
1210 &tmpint, // actual_format_return
1221 if (XGetWindowProperty(
1222 event->xselection.display, // display
1224 event->xselection.property, // property
1226 ul2/4+1, // long_length
1228 XA_STRING, // req_type
1229 &tmpatom, // actual_type_return
1230 &tmpint, // actual_format_return
1231 &ul1, // nitems_return
1232 &ul2, // bytes_after_return
1233 &uc // prop_return */
1238 strret = reinterpret_cast<char*>(uc);
1239 free(uc); // yes free!
1247 void BufferView::workAreaSelectionNotify(Window win, XEvent * event)
1249 if (buffer_ == 0) return;
1251 screen->HideCursor();
1253 string clb = fromClipboard(win, event);
1256 text->InsertStringA(clb.c_str());
1258 text->InsertStringB(clb.c_str());
1266 void BufferView::cursorPrevious()
1268 if (!text->cursor.row->previous) return;
1270 long y = screen->first;
1271 Row * cursorrow = text->cursor.row;
1272 text->SetCursorFromCoordinates(text->cursor.x_fix, y);
1274 // This is to allow jumping over large insets
1275 if ((cursorrow == text->cursor.row))
1278 if (text->cursor.row->height < workarea->height())
1279 screen->Draw(text->cursor.y
1280 - text->cursor.row->baseline
1281 + text->cursor.row->height
1282 - workarea->height() + 1 );
1286 void BufferView::cursorNext()
1288 if (!text->cursor.row->next) return;
1290 long y = screen->first;
1291 text->GetRowNearY(y);
1292 Row * cursorrow = text->cursor.row;
1293 text->SetCursorFromCoordinates(text->cursor.x_fix, y
1294 + workarea->height());
1296 // This is to allow jumping over large insets
1297 if ((cursorrow == text->cursor.row))
1300 if (text->cursor.row->height < workarea->height())
1301 screen->Draw(text->cursor.y
1302 - text->cursor.row->baseline);
1306 bool BufferView::available() const
1308 if (buffer_ && text) return true;
1313 void BufferView::beforeChange()
1316 text->ClearSelection();
1321 void BufferView::savePosition()
1323 backstack.push(buffer()->fileName(),
1329 void BufferView::restorePosition()
1331 if (backstack.empty()) return;
1334 string fname = backstack.pop(&x, &y);
1337 Buffer * b = bufferlist.exists(fname) ?
1338 bufferlist.getBuffer(fname) :
1339 bufferlist.loadLyXFile(fname); // don't ask, just load it
1341 text->SetCursorFromCoordinates(x, y);
1346 void BufferView::update(signed char f)
1348 owner()->updateLayoutChoice();
1350 if (!text->selection && f > -3)
1351 text->sel_cursor = text->cursor;
1354 text->FullRebreak();
1358 if (f != 3 && f != -3) {
1363 if (f == 1 || f == -1) {
1364 if (buffer()->isLyxClean()) {
1365 buffer()->markDirty();
1366 owner()->getMiniBuffer()->setTimer(4);
1368 buffer()->markDirty();
1374 void BufferView::smallUpdate(signed char f)
1376 screen->SmallUpdate();
1377 if (screen->TopCursorVisible()
1386 if (!text->selection)
1387 text->sel_cursor = text->cursor;
1389 if (f == 1 || f == -1) {
1390 if (buffer()->isLyxClean()) {
1391 buffer()->markDirty();
1392 owner()->getMiniBuffer()->setTimer(4);
1394 buffer()->markDirty();
1400 void BufferView::setState()
1402 if (!lyxrc->rtl_support)
1405 if (text->real_current_font.getFontDirection()
1406 == LYX_DIR_LEFT_TO_RIGHT) {
1407 if (!owner_->getIntl()->primarykeymap)
1408 owner_->getIntl()->KeyMapPrim();
1410 if (owner_->getIntl()->primarykeymap)
1411 owner_->getIntl()->KeyMapSec();
1416 void BufferView::insetSleep()
1418 if (the_locking_inset && !inset_slept) {
1419 the_locking_inset->GetCursorPos(slx, sly);
1420 the_locking_inset->InsetUnlock(this);
1426 void BufferView::insetWakeup()
1428 if (the_locking_inset && inset_slept) {
1429 the_locking_inset->Edit(this, slx, sly, 0);
1430 inset_slept = false;
1435 void BufferView::insetUnlock()
1437 if (the_locking_inset) {
1438 if (!inset_slept) the_locking_inset->InsetUnlock(this);
1439 the_locking_inset = 0;
1441 inset_slept = false;
1446 bool BufferView::focus() const
1448 return workarea->hasFocus();
1452 void BufferView::focus(bool f)
1454 if (f) workarea->setFocus();
1458 bool BufferView::active() const
1460 return workarea->active();
1464 Painter & BufferView::getPainter() const
1466 return workarea->getPainter();
1470 unsigned short BufferView::paperWidth() const
1472 return text->paperWidth();
1476 bool BufferView::belowMouse() const
1478 return workarea->belowMouse();
1482 void BufferView::showCursor()
1485 screen->ShowCursor();
1489 void BufferView::hideCursor()
1492 screen->HideCursor();
1496 void BufferView::toggleSelection(bool b)
1499 screen->ToggleSelection(b);
1503 void BufferView::toggleToggle()
1506 screen->ToggleToggle();
1510 void BufferView::center()
1513 if (text->cursor.y > workarea->height() / 2) {
1514 screen->Draw(text->cursor.y - workarea->height() / 2);