2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2000 The LyX Team.
10 * ====================================================== */
23 #include "support/lstrings.h"
26 #pragma implementation
29 #include "commandtags.h"
30 #include "BufferView.h"
31 #include "bufferlist.h"
34 #include "insets/lyxinset.h"
35 #include "insets/insetbib.h"
36 #include "minibuffer.h"
37 #include "lyxscreen.h"
40 #include "lyx_gui_misc.h"
41 #include "BackStack.h"
46 #include "TextCache.h"
54 extern BufferList bufferlist;
56 void sigchldhandler(pid_t pid, int * status);
58 extern void SetXtermCursor(Window win);
59 extern bool input_prohibited;
60 extern bool selection_possible;
61 extern char ascii_type;
62 extern void MenuPasteSelection(char at);
63 extern void FreeUpdateTimer();
65 BufferView::BufferView(LyXView * o, int xpos, int ypos,
66 int width, int height)
71 workarea = new WorkArea(this, xpos, ypos, width, height);
75 current_scrollbar_value = 0;
76 // Activate the timer for the cursor
77 fl_set_timer(timer_cursor, 0.4);
79 work_area_focus = true;
81 the_locking_inset = 0;
86 BufferView::~BufferView()
92 Painter & BufferView::painter()
94 return workarea->getPainter();
98 void BufferView::buffer(Buffer * b)
100 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
104 buffer_->delUser(this);
106 // Put the old text into the TextCache, but
107 // only if the buffer is still loaded.
108 // Also set the owner of the test to 0
111 if (lyxerr.debugging())
112 textcache.show(lyxerr, "BufferView::buffer");
117 // Set current buffer
120 if (bufferlist.getState() == BufferList::CLOSING) return;
123 // screen is always deleted when the buffer is changed.
127 // If we are closing the buffer, use the first buffer as current
129 buffer_ = bufferlist.first();
133 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
134 buffer_->addUser(this);
135 owner_->getMenus()->showMenus();
136 // If we don't have a text object for this, we make one
138 resizeCurrentBuffer();
143 screen->first = screen->TopCursorVisible();
145 updateAllVisibleBufferRelatedPopups();
148 lyxerr[Debug::INFO] << " No Buffer!" << endl;
149 owner_->getMenus()->hideMenus();
153 // Also remove all remaining text's from the testcache.
154 // (there should not be any!) (if there is any it is a
156 if (lyxerr.debugging())
157 textcache.show(lyxerr, "buffer delete all");
160 // should update layoutchoice even if we don't have a buffer.
161 owner_->updateLayoutChoice();
162 owner_->getMiniBuffer()->Init();
163 owner_->updateWindowTitle();
167 void BufferView::updateScreen()
169 // Regenerate the screen.
171 screen = new LyXScreen(*workarea, text);
175 void BufferView::resize(int xpos, int ypos, int width, int height)
177 workarea->resize(xpos, ypos, width, height);
183 void BufferView::resize()
185 // This will resize the buffer. (Asger)
187 resizeCurrentBuffer();
191 void BufferView::redraw()
193 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
198 void BufferView::fitCursor()
200 if (screen) screen->FitCursor();
205 void BufferView::update()
207 if (screen) screen->Update();
211 void BufferView::updateScrollbar()
213 /* If the text is smaller than the working area, the scrollbar
214 * maximum must be the working area height. No scrolling will
218 workarea->setScrollbar(0, 1.0);
222 static long max2 = 0;
223 static long height2 = 0;
231 cbsf = screen->first;
233 // check if anything has changed.
235 height2 == workarea->height() &&
236 current_scrollbar_value == cbsf)
239 height2 = workarea->height();
240 current_scrollbar_value = cbsf;
242 if (cbth <= height2) { // text is smaller than screen
243 workarea->setScrollbar(0, 1.0); // right?
247 long maximum_height = workarea->height() * 3 / 4 + cbth;
251 double hfloat = workarea->height();
252 double maxfloat = maximum_height;
254 float slider_size = 0.0;
255 int slider_value = value;
257 workarea->setScrollbarBounds(0, text->height - workarea->height());
258 double lineh = text->DefaultHeight();
259 workarea->setScrollbarIncrements(lineh);
260 if (maxfloat > 0.0) {
261 if ((hfloat / maxfloat) * float(height2) < 3)
262 slider_size = 3.0/float(height2);
264 slider_size = hfloat / maxfloat;
266 slider_size = hfloat;
268 workarea->setScrollbar(slider_value, slider_size / workarea->height());
272 void BufferView::redoCurrentBuffer()
274 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
275 if (buffer_ && text) {
277 owner_->updateLayoutChoice();
282 int BufferView::resizeCurrentBuffer()
284 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
286 LyXParagraph * par = 0;
287 LyXParagraph * selstartpar = 0;
288 LyXParagraph * selendpar = 0;
297 owner_->getMiniBuffer()->Set(_("Formatting document..."));
300 par = text->cursor.par;
301 pos = text->cursor.pos;
302 selstartpar = text->sel_start_cursor.par;
303 selstartpos = text->sel_start_cursor.pos;
304 selendpar = text->sel_end_cursor.par;
305 selendpos = text->sel_end_cursor.pos;
306 selection = text->selection;
307 mark_set = text->mark_set;
309 text = new LyXText(this, workarea->workWidth(), buffer_);
311 // See if we have a text in TextCache that fits
312 // the new buffer_ with the correct width.
313 text = textcache.findFit(buffer_, workarea->workWidth());
315 if (lyxerr.debugging()) {
316 lyxerr << "Found a LyXText that fits:\n";
317 textcache.show(lyxerr, text);
319 // Set the owner of the newly found text
321 if (lyxerr.debugging())
322 textcache.show(lyxerr, "resizeCurrentBuffer");
324 text = new LyXText(this, workarea->workWidth(), buffer_);
330 text->selection = true;
331 /* at this point just to avoid the Delete-Empty-Paragraph
332 * Mechanism when setting the cursor */
333 text->mark_set = mark_set;
335 text->SetCursor(selstartpar, selstartpos);
336 text->sel_cursor = text->cursor;
337 text->SetCursor(selendpar, selendpos);
338 text->SetSelection();
339 text->SetCursor(par, pos);
341 text->SetCursor(par, pos);
342 text->sel_cursor = text->cursor;
343 text->selection = false;
346 screen->first = screen->TopCursorVisible(); /* this will scroll the
347 * screen such that the
352 owner_->getMiniBuffer()->Init();
356 // Now if the title form still exist kill it
363 void BufferView::gotoError()
368 screen->HideCursor();
373 if (!text->GotoNextError()) {
375 || text->cursor.par != text->FirstParagraph()) {
377 text->cursor.par = text->FirstParagraph();
378 text->cursor.pos = 0;
379 if (!text->GotoNextError()) {
381 owner_->getMiniBuffer()
382 ->Set(_("No more errors"));
386 owner_->getMiniBuffer()->Set(_("No more errors"));
391 text->sel_cursor = text->cursor;
396 void C_BufferView_CursorToggleCB(FL_OBJECT * ob, long buf)
398 BufferView::cursorToggleCB(ob, buf);
403 void BufferView::create_view()
412 timer_cursor = obj = fl_add_timer(FL_HIDDEN_TIMER,
413 0, 0, 0, 0, "Timer");
414 fl_set_object_callback(obj, C_BufferView_CursorToggleCB, 0);
419 // Callback for scrollbar up button
420 void BufferView::upCB(long time, int button)
422 if (buffer_ == 0) return;
441 XSync(fl_get_display(), 0);
445 // Callback for scrollbar slider
446 void BufferView::scrollCB(double value)
448 extern bool cursor_follows_scrollbar;
450 if (buffer_ == 0) return;
452 current_scrollbar_value = long(value);
453 if (current_scrollbar_value < 0)
454 current_scrollbar_value = 0;
459 screen->Draw(current_scrollbar_value);
461 if (cursor_follows_scrollbar) {
462 LyXText * vbt = text;
463 int height = vbt->DefaultHeight();
465 if (vbt->cursor.y < screen->first + height) {
466 vbt->SetCursorFromCoordinates(0,
469 } else if (vbt->cursor.y >
470 screen->first + workarea->height() - height) {
471 vbt->SetCursorFromCoordinates(0,
481 // Callback for scrollbar down button
482 void BufferView::downCB(long time, int button)
484 if (buffer_ == 0) return;
500 int BufferView::scrollUp(long time)
502 if (buffer_ == 0) return 0;
503 if (!screen) return 0;
505 double value = workarea->getScrollbarValue();
507 if (value == 0) return 0;
509 float add_value = (text->DefaultHeight()
510 + float(time) * float(time) * 0.125);
512 if (add_value > workarea->height())
513 add_value = float(workarea->height() -
514 text->DefaultHeight());
521 workarea->setScrollbarValue(value);
528 int BufferView::scrollDown(long time)
530 if (buffer_ == 0) return 0;
531 if (!screen) return 0;
533 double value= workarea->getScrollbarValue();
534 pair<double, double> p = workarea->getScrollbarBounds();
535 double max = p.second;
537 if (value == max) return 0;
539 float add_value = (text->DefaultHeight()
540 + float(time) * float(time) * 0.125);
542 if (add_value > workarea->height())
543 add_value = float(workarea->height() -
544 text->DefaultHeight());
551 workarea->setScrollbarValue(value);
558 void BufferView::scrollUpOnePage()
560 if (buffer_ == 0) return;
563 long y = screen->first;
567 Row * row = text->GetRowNearY(y);
569 y = y - workarea->height() + row->height;
571 workarea->setScrollbarValue(y);
577 void BufferView::scrollDownOnePage()
579 if (buffer_ == 0) return;
582 long y = screen->first;
584 if (y > text->height - workarea->height())
587 y += workarea->height();
588 text->GetRowNearY(y);
590 workarea->setScrollbarValue(y);
596 void BufferView::workAreaMotionNotify(int x, int y, unsigned int state)
598 if (buffer_ == 0 || !screen) return;
600 // Check for inset locking
601 if (the_locking_inset) {
602 LyXCursor cursor = text->cursor;
604 InsetMotionNotify(this,
611 // Only use motion with button 1
612 if (!state & Button1MotionMask)
615 /* The selection possible is needed, that only motion events are
616 * used, where the bottom press event was on the drawing area too */
617 if (selection_possible) {
618 screen->HideCursor();
620 text->SetCursorFromCoordinates(x, y + screen->first);
622 if (!text->selection)
623 update(-3); // Maybe an empty line was deleted
625 text->SetSelection();
626 screen->ToggleToggle();
627 if (screen->FitCursor())
629 screen->ShowCursor();
635 extern int bibitemMaxWidth(Painter &, LyXFont const &);
638 // Single-click on work area
639 void BufferView::workAreaButtonPress(int xpos, int ypos, unsigned int button)
644 if (buffer_ == 0 || !screen) return;
646 Inset * inset_hit = checkInsetHit(xpos, ypos);
648 // ok ok, this is a hack.
649 if (button == 4 || button == 5) {
652 scrollUp(100); // This number is only temporary
660 if (the_locking_inset) {
661 // We are in inset locking mode
663 /* Check whether the inset was hit. If not reset mode,
664 otherwise give the event to the inset */
667 InsetButtonPress(this,
672 unlockInset(the_locking_inset);
676 selection_possible = true;
677 screen->HideCursor();
679 // Right button mouse click on a table
681 (text->cursor.par->table ||
682 text->MouseHitInTable(xpos, ypos + screen->first))) {
683 // Set the cursor to the press-position
684 text->SetCursorFromCoordinates(xpos, ypos + screen->first);
687 // Only show the table popup if the hit is in
689 if (!text->HitInTable(text->cursor.row, xpos))
692 // Hit above or below the table?
694 if (!text->selection) {
695 screen->ToggleSelection();
696 text->ClearSelection();
701 // Popup table popup when on a table.
702 // This is obviously temporary, since we
703 // should be able to popup various
704 // context-sensitive-menus with the
705 // the right mouse. So this should be done more
706 // general in the future. Matthias.
707 selection_possible = false;
709 ->Dispatch(LFUN_LAYOUT_TABLE,
715 int screen_first = screen->first;
717 // Middle button press pastes if we have a selection
718 bool paste_internally = false;
720 && text->selection) {
721 owner_->getLyXFunc()->Dispatch(LFUN_COPY);
722 paste_internally = true;
725 // Clear the selection
726 screen->ToggleSelection();
727 text->ClearSelection();
732 // Single left click in math inset?
733 if (inset_hit != 0 && inset_hit->Editable()==Inset::HIGHLY_EDITABLE) {
734 // Highly editable inset, like math
735 selection_possible = false;
736 owner_->updateLayoutChoice();
737 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
738 inset_hit->Edit(this, xpos, ypos, button);
742 // Right click on a footnote flag opens float menu
744 selection_possible = false;
748 text->SetCursorFromCoordinates(xpos, ypos + screen_first);
750 text->sel_cursor = text->cursor;
751 text->cursor.x_fix = text->cursor.x;
753 owner_->updateLayoutChoice();
754 if (screen->FitCursor()){
756 selection_possible = false;
759 // Insert primary selection with middle mouse
760 // if there is a local selection in the current buffer,
763 if (paste_internally)
764 owner_->getLyXFunc()->Dispatch(LFUN_PASTE);
766 owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION,
768 selection_possible = false;
774 void BufferView::doubleClick(int /*x*/, int /*y*/, unsigned int button)
777 if (buffer_ && !the_locking_inset) {
778 if (screen && button == 1) {
779 screen->HideCursor();
780 screen->ToggleSelection();
782 screen->ToggleSelection(false);
783 /* This will fit the cursor on the screen
791 void BufferView::tripleClick(int /*x*/, int /*y*/, unsigned int button)
794 if (buffer_ && screen && button == 1) {
795 screen->HideCursor();
796 screen->ToggleSelection();
798 text->sel_cursor = text->cursor;
800 text->SetSelection();
801 screen->ToggleSelection(false);
802 /* This will fit the cursor on the screen
809 void BufferView::workAreaButtonRelease(int x, int y, unsigned int button)
811 if (buffer_ == 0 || screen == 0) return;
813 // If we hit an inset, we have the inset coordinates in these
814 // and inset_hit points to the inset. If we do not hit an
815 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
816 Inset * inset_hit = checkInsetHit(x, y);
818 if (the_locking_inset) {
819 // We are in inset locking mode.
821 /* LyX does a kind of work-area grabbing for insets.
822 Only a ButtonPress Event outside the inset will
823 force a InsetUnlock. */
825 InsetButtonRelease(this, x, y, button);
829 selection_possible = false;
830 if (text->cursor.par->table) {
832 NumberOfCell(text->cursor.par,
834 if (text->cursor.par->table->IsContRow(cell) &&
835 text->cursor.par->table->
836 CellHasContRow(text->cursor.par->table->
837 GetCellAbove(cell))<0) {
842 if (button >= 2) return;
845 owner_->getMiniBuffer()->Set(CurrentState());
847 // Did we hit an editable inset?
848 if (inset_hit != 0) {
849 // Inset like error, notes and figures
850 selection_possible = false;
852 #warning fix this proper in 0.13
854 // Following a ref shouldn't issue
855 // a push on the undo-stack
856 // anylonger, now that we have
857 // keybindings for following
858 // references and returning from
859 // references. IMHO though, it
860 // should be the inset's own business
861 // to push or not push on the undo
862 // stack. They don't *have* to
863 // alter the document...
865 // ...or maybe the SetCursorParUndo()
866 // below isn't necessary at all anylonger?
867 if (inset_hit->LyxCode() == Inset::REF_CODE) {
868 text->SetCursorParUndo();
871 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
872 inset_hit->Edit(this, x, y, button);
876 // check whether we want to open a float
880 if (text->cursor.pos <
881 text->cursor.par->Last()) {
882 c = text->cursor.par->
883 GetChar(text->cursor.pos);
885 if (c == LyXParagraph::META_FOOTNOTE
886 || c == LyXParagraph::META_MARGIN
887 || c == LyXParagraph::META_FIG
888 || c == LyXParagraph::META_TAB
889 || c == LyXParagraph::META_WIDE_FIG
890 || c == LyXParagraph::META_WIDE_TAB
891 || c == LyXParagraph::META_ALGORITHM){
893 } else if (text->cursor.pos - 1 >= 0) {
894 c = text->cursor.par->
895 GetChar(text->cursor.pos - 1);
896 if (c == LyXParagraph::META_FOOTNOTE
897 || c == LyXParagraph::META_MARGIN
898 || c == LyXParagraph::META_FIG
899 || c == LyXParagraph::META_TAB
900 || c == LyXParagraph::META_WIDE_FIG
901 || c == LyXParagraph::META_WIDE_TAB
902 || c == LyXParagraph::META_ALGORITHM){
903 // We are one step too far to the right
910 selection_possible = false;
915 // Do we want to close a float? (click on the float-label)
916 if (text->cursor.row->par->footnoteflag ==
917 LyXParagraph::OPEN_FOOTNOTE
918 //&& text->cursor.pos == 0
919 && text->cursor.row->previous &&
920 text->cursor.row->previous->par->
921 footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
922 LyXFont font(LyXFont::ALL_SANE);
923 font.setSize(LyXFont::SIZE_FOOTNOTE);
925 int box_x = 20; // LYX_PAPER_MARGIN;
926 box_x += font.textWidth(" wide-tab ", 10);
928 int screen_first = screen->first;
931 && y + screen_first > text->cursor.y -
932 text->cursor.row->baseline
933 && y + screen_first < text->cursor.y -
934 text->cursor.row->baseline
935 + font.maxAscent() * 1.2 + font.maxDescent() * 1.2) {
937 selection_possible = false;
942 // Maybe we want to edit a bibitem ale970302
943 if (text->cursor.par->bibkey && x < 20 +
944 bibitemMaxWidth(painter(),
947 params.textclass).defaultfont())) {
948 text->cursor.par->bibkey->Edit(this, 0, 0, 0);
956 * Returns an inset if inset was hit. 0 otherwise.
957 * If hit, the coordinates are changed relative to the inset.
958 * Otherwise coordinates are not changed, and false is returned.
960 Inset * BufferView::checkInsetHit(int & x, int & y)
965 int y_tmp = y + screen->first;
967 LyXCursor & cursor = text->cursor;
968 LyXDirection direction = text->real_current_font.getFontDirection();
970 if (cursor.pos < cursor.par->Last()
971 && cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET
972 && cursor.par->GetInset(cursor.pos)
973 && cursor.par->GetInset(cursor.pos)->Editable()) {
975 // Check whether the inset really was hit
976 Inset * tmpinset = cursor.par->GetInset(cursor.pos);
977 LyXFont font = text->GetFont(cursor.par, cursor.pos);
979 if (direction == LYX_DIR_LEFT_TO_RIGHT) {
981 end_x = cursor.x + tmpinset->width(painter(), font);
983 start_x = cursor.x - tmpinset->width(painter(), font);
987 if (x > start_x && x < end_x
988 && y_tmp > cursor.y - tmpinset->ascent(painter(), font)
989 && y_tmp < cursor.y + tmpinset->descent(painter(), font)) {
991 // The origin of an inset is on the baseline
992 y = y_tmp - (cursor.y);
997 if ((cursor.pos - 1 >= 0) &&
998 (cursor.par->GetChar(cursor.pos-1) == LyXParagraph::META_INSET) &&
999 (cursor.par->GetInset(cursor.pos - 1)) &&
1000 (cursor.par->GetInset(cursor.pos - 1)->Editable())) {
1002 Inset * tmpinset = cursor.par->GetInset(cursor.pos);
1003 LyXFont font = text->GetFont(cursor.par, cursor.pos);
1005 if (direction == LYX_DIR_LEFT_TO_RIGHT) {
1007 end_x = cursor.x + tmpinset->width(painter(), font);
1009 start_x = cursor.x - tmpinset->width(painter(), font);
1012 if (x > start_x && x < end_x
1013 && y_tmp > cursor.y - tmpinset->ascent(painter(), font)
1014 && y_tmp < cursor.y + tmpinset->descent(painter(), font)) {
1016 // The origin of an inset is on the baseline
1017 y = y_tmp - (cursor.y);
1020 text->CursorRight();
1027 void BufferView::workAreaExpose()
1029 // this is a hack to ensure that we only call this through
1030 // BufferView::redraw().
1035 static int work_area_width = -1;
1036 static int work_area_height = -1;
1038 bool widthChange = workarea->workWidth() != work_area_width;
1039 bool heightChange = workarea->height() != work_area_height;
1041 // update from work area
1042 work_area_width = workarea->workWidth();
1043 work_area_height = workarea->height();
1046 // All buffers need a resize
1047 bufferlist.resize();
1049 // Remove all texts from the textcache
1050 // This is not _really_ what we want to do. What
1051 // we really want to do is to delete in textcache
1052 // that does not have a BufferView with matching
1053 // width, but as long as we have only one BufferView
1054 // deleting all gives the same result.
1055 if (lyxerr.debugging())
1056 textcache.show(lyxerr, "Expose delete all");
1058 } else if (heightChange) {
1059 // Rebuild image of current screen
1061 // fitCursor() ensures we don't jump back
1062 // to the start of the document on vertical
1066 // The main window size has changed, repaint most stuff
1068 // ...including the minibuffer
1069 owner_->getMiniBuffer()->Init();
1071 } else if (screen) screen->Redraw();
1073 // Grey box when we don't have a buffer
1074 workarea->greyOut();
1077 // always make sure that the scrollbar is sane.
1079 owner_->updateLayoutChoice();
1084 // Callback for cursor timer
1085 void BufferView::cursorToggleCB(FL_OBJECT * ob, long)
1087 BufferView * view = static_cast<BufferView*>(ob->u_vdata);
1089 // Quite a nice place for asyncron Inset updating, isn't it?
1090 // Actually no! This is run even if no buffer exist... so (Lgb)
1091 if (view && !view->buffer_) {
1092 goto set_timer_and_return;
1096 // On my quest to solve the gs render hangups I am now
1097 // disabling the SIGHUP completely, and will do a wait
1098 // now and then instead. If the guess that xforms somehow
1099 // destroys something is true, this is likely (hopefully)
1100 // to solve the problem...at least I hope so. Lgb
1102 // ...Ok this seems to work...at least it does not make things
1103 // worse so far. However I still see gs processes that hangs.
1104 // I would really like to know _why_ they are hanging. Anyway
1105 // the solution without the SIGCHLD handler seems to be easier
1108 // When attaching gdb to a a running gs that hangs it shows
1109 // that it is waiting for input(?) Is it possible for us to
1110 // provide that input somehow? Or figure what it is expecing
1113 // One solution is to, after some time, look if there are some
1114 // old gs processes still running and if there are: kill them
1117 // Another solution is to provide the user an option to rerender
1118 // a picture. This would, for the picture in question, check if
1119 // there is a gs running for it, if so kill it, and start a new
1120 // rendering process.
1122 // these comments posted to lyx@via
1125 int pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1126 if (pid == -1) // error find out what is wrong
1127 ; // ignore it for now.
1129 sigchldhandler(pid, &status);
1132 view->updatelist.update(view);
1134 if (view && !view->screen){
1135 goto set_timer_and_return;
1138 if (view->lyx_focus && view->work_area_focus) {
1139 if (!view->the_locking_inset) {
1140 view->screen->CursorToggle();
1142 view->the_locking_inset->
1143 ToggleInsetCursor(view);
1145 goto set_timer_and_return;
1147 // Make sure that the cursor is visible.
1148 if (!view->the_locking_inset) {
1149 view->screen->ShowCursor();
1151 if (!view->the_locking_inset->isCursorVisible())
1152 view->the_locking_inset->
1153 ToggleInsetCursor(view);
1155 // This is only run when work_area_focus or lyx_focus is false.
1158 XGetInputFocus(fl_display, &tmpwin, &tmp);
1159 // Commenting this out, we have not had problems with this
1160 // for a long time. We will probably work on this code later
1161 // and we can reenable this debug code then. Now it only
1162 // anoying when debugging. (Lgb)
1163 //if (lyxerr.debugging(Debug::INFO)) {
1164 // lyxerr << "tmpwin: " << tmpwin
1165 // << "\nwindow: " << view->owner_->getForm()->window
1166 // << "\nwork_area_focus: " << view->work_area_focus
1167 // << "\nlyx_focus : " << view->lyx_focus
1170 if (tmpwin != view->owner_->getForm()->window) {
1171 view->lyx_focus = false;
1174 view->lyx_focus = true;
1175 if (!view->work_area_focus)
1178 goto set_timer_and_return;
1182 set_timer_and_return:
1183 fl_set_timer(ob, 0.4);
1190 string fromClipboard(Window win, XEvent * event)
1193 if (event->xselection.type == XA_STRING
1194 && event->xselection.property) {
1198 unsigned char * uc = 0;
1200 if (XGetWindowProperty(
1201 event->xselection.display, // display
1203 event->xselection.property, // property
1207 XA_STRING, // req_type
1208 &tmpatom, // actual_type_return
1209 &tmpint, // actual_format_return
1220 if (XGetWindowProperty(
1221 event->xselection.display, // display
1223 event->xselection.property, // property
1225 ul2/4+1, // long_length
1227 XA_STRING, // req_type
1228 &tmpatom, // actual_type_return
1229 &tmpint, // actual_format_return
1230 &ul1, // nitems_return
1231 &ul2, // bytes_after_return
1232 &uc // prop_return */
1237 strret = reinterpret_cast<char*>(uc);
1238 free(uc); // yes free!
1246 void BufferView::workAreaSelectionNotify(Window win, XEvent * event)
1248 if (buffer_ == 0) return;
1250 screen->HideCursor();
1252 string clb = fromClipboard(win, event);
1255 text->InsertStringA(clb.c_str());
1257 text->InsertStringB(clb.c_str());
1265 void BufferView::cursorPrevious()
1267 if (!text->cursor.row->previous) return;
1269 long y = screen->first;
1270 Row * cursorrow = text->cursor.row;
1271 text->SetCursorFromCoordinates(text->cursor.x_fix, y);
1273 // This is to allow jumping over large insets
1274 if ((cursorrow == text->cursor.row))
1277 if (text->cursor.row->height < workarea->height())
1278 screen->Draw(text->cursor.y
1279 - text->cursor.row->baseline
1280 + text->cursor.row->height
1281 - workarea->height() + 1 );
1285 void BufferView::cursorNext()
1287 if (!text->cursor.row->next) return;
1289 long y = screen->first;
1290 text->GetRowNearY(y);
1291 Row * cursorrow = text->cursor.row;
1292 text->SetCursorFromCoordinates(text->cursor.x_fix, y
1293 + workarea->height());
1295 // This is to allow jumping over large insets
1296 if ((cursorrow == text->cursor.row))
1299 if (text->cursor.row->height < workarea->height())
1300 screen->Draw(text->cursor.y
1301 - text->cursor.row->baseline);
1305 bool BufferView::available() const
1307 if (buffer_ && text) return true;
1312 void BufferView::beforeChange()
1315 text->ClearSelection();
1320 void BufferView::savePosition()
1322 backstack.push(buffer()->fileName(),
1328 void BufferView::restorePosition()
1330 if (backstack.empty()) return;
1333 string fname = backstack.pop(&x, &y);
1336 Buffer * b = bufferlist.exists(fname) ?
1337 bufferlist.getBuffer(fname) :
1338 bufferlist.loadLyXFile(fname); // don't ask, just load it
1340 text->SetCursorFromCoordinates(x, y);
1345 void BufferView::update(signed char f)
1347 owner()->updateLayoutChoice();
1349 if (!text->selection && f > -3)
1350 text->sel_cursor = text->cursor;
1353 text->FullRebreak();
1357 if (f != 3 && f != -3) {
1362 if (f == 1 || f == -1) {
1363 if (buffer()->isLyxClean()) {
1364 buffer()->markDirty();
1365 owner()->getMiniBuffer()->setTimer(4);
1367 buffer()->markDirty();
1373 void BufferView::smallUpdate(signed char f)
1375 screen->SmallUpdate();
1376 if (screen->TopCursorVisible()
1385 if (!text->selection)
1386 text->sel_cursor = text->cursor;
1388 if (f == 1 || f == -1) {
1389 if (buffer()->isLyxClean()) {
1390 buffer()->markDirty();
1391 owner()->getMiniBuffer()->setTimer(4);
1393 buffer()->markDirty();
1399 void BufferView::setState()
1401 if (!lyxrc.rtl_support)
1404 if (text->real_current_font.getFontDirection()
1405 == LYX_DIR_LEFT_TO_RIGHT) {
1406 if (!owner_->getIntl()->primarykeymap)
1407 owner_->getIntl()->KeyMapPrim();
1409 if (owner_->getIntl()->primarykeymap)
1410 owner_->getIntl()->KeyMapSec();
1415 void BufferView::insetSleep()
1417 if (the_locking_inset && !inset_slept) {
1418 the_locking_inset->GetCursorPos(slx, sly);
1419 the_locking_inset->InsetUnlock(this);
1425 void BufferView::insetWakeup()
1427 if (the_locking_inset && inset_slept) {
1428 the_locking_inset->Edit(this, slx, sly, 0);
1429 inset_slept = false;
1434 void BufferView::insetUnlock()
1436 if (the_locking_inset) {
1437 if (!inset_slept) the_locking_inset->InsetUnlock(this);
1438 the_locking_inset = 0;
1440 inset_slept = false;
1445 bool BufferView::focus() const
1447 return workarea->hasFocus();
1451 void BufferView::focus(bool f)
1453 if (f) workarea->setFocus();
1457 bool BufferView::active() const
1459 return workarea->active();
1463 Painter & BufferView::getPainter() const
1465 return workarea->getPainter();
1469 unsigned short BufferView::paperWidth() const
1471 return text->paperWidth();
1475 bool BufferView::belowMouse() const
1477 return workarea->belowMouse();
1481 void BufferView::showCursor()
1484 screen->ShowCursor();
1488 void BufferView::hideCursor()
1491 screen->HideCursor();
1495 void BufferView::toggleSelection(bool b)
1498 screen->ToggleSelection(b);
1502 void BufferView::toggleToggle()
1505 screen->ToggleToggle();
1509 void BufferView::center()
1512 if (text->cursor.y > workarea->height() / 2) {
1513 screen->Draw(text->cursor.y - workarea->height() / 2);