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"
56 extern BufferList bufferlist;
59 void sigchldhandler(pid_t pid, int * status);
61 extern void SetXtermCursor(Window win);
62 extern bool input_prohibited;
63 extern bool selection_possible;
64 extern char ascii_type;
65 extern void MenuPasteSelection(char at);
66 extern InsetUpdateStruct * InsetUpdateList;
67 extern void UpdateInsetUpdateList();
68 extern void FreeUpdateTimer();
70 BufferView::BufferView(LyXView * o, int xpos, int ypos,
71 int width, int height)
77 workarea = new WorkArea(this, xpos, ypos, width, height);
80 current_scrollbar_value = 0;
81 // Activate the timer for the cursor
82 fl_set_timer(timer_cursor, 0.4);
84 work_area_focus = true;
86 the_locking_inset = 0;
91 BufferView::~BufferView()
98 Painter & BufferView::painter()
100 return workarea->getPainter();
105 void BufferView::buffer(Buffer * b)
107 lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
111 buffer_->delUser(this);
113 // Put the old text into the TextCache, but
114 // only if the buffer is still loaded.
115 // Also set the owner of the test to 0
118 if (lyxerr.debugging())
119 textcache.show(lyxerr, "BufferView::buffer");
124 // Set current buffer
127 if (bufferlist.getState() == BufferList::CLOSING) return;
130 // screen is always deleted when the buffer is changed.
134 // If we are closing the buffer, use the first buffer as current
136 buffer_ = bufferlist.first();
140 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
141 buffer_->addUser(this);
142 owner_->getMenus()->showMenus();
143 // If we don't have a text object for this, we make one
145 resizeCurrentBuffer();
150 screen->first = screen->TopCursorVisible();
152 updateAllVisibleBufferRelatedPopups();
155 lyxerr[Debug::INFO] << " No Buffer!" << endl;
156 owner_->getMenus()->hideMenus();
160 // Also remove all remaining text's from the testcache.
161 // (there should not be any!) (if there is any it is a
163 if (lyxerr.debugging())
164 textcache.show(lyxerr, "buffer delete all");
167 // should update layoutchoice even if we don't have a buffer.
168 owner_->updateLayoutChoice();
169 owner_->getMiniBuffer()->Init();
170 owner_->updateWindowTitle();
174 void BufferView::updateScreen()
176 // Regenerate the screen.
178 screen = new LyXScreen(this,
180 workarea->getPixmap(),
181 workarea->workWidth(),
189 void BufferView::resize(int xpos, int ypos, int width, int height)
191 workarea->resize(xpos, ypos, width, height);
197 void BufferView::resize()
199 // This will resize the buffer. (Asger)
201 resizeCurrentBuffer();
205 void BufferView::redraw()
207 lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
212 void BufferView::fitCursor()
214 if (screen) screen->FitCursor();
219 void BufferView::update()
221 if (screen) screen->Update();
225 void BufferView::updateScrollbar()
227 /* If the text is smaller than the working area, the scrollbar
228 * maximum must be the working area height. No scrolling will
232 workarea->setScrollbar(0, 1.0);
236 static long max2 = 0;
237 static long height2 = 0;
245 cbsf = screen->first;
247 // check if anything has changed.
249 height2 == workarea->height() &&
250 current_scrollbar_value == cbsf)
253 height2 = workarea->height();
254 current_scrollbar_value = cbsf;
256 if (cbth <= height2) { // text is smaller than screen
257 workarea->setScrollbar(0, 1.0); // right?
261 long maximum_height = workarea->height() * 3 / 4 + cbth;
265 double hfloat = workarea->height();
266 double maxfloat = maximum_height;
268 float slider_size = 0.0;
269 int slider_value = value;
271 workarea->setScrollbarBounds(0, text->height - workarea->height());
272 double lineh = text->DefaultHeight();
273 workarea->setScrollbarIncrements(lineh);
274 if (maxfloat > 0.0) {
275 if ((hfloat / maxfloat) * float(height2) < 3)
276 slider_size = 3.0/float(height2);
278 slider_size = hfloat / maxfloat;
280 slider_size = hfloat;
282 workarea->setScrollbar(slider_value, slider_size / workarea->height());
286 void BufferView::redoCurrentBuffer()
288 lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
289 if (buffer_ && text) {
291 owner_->updateLayoutChoice();
296 int BufferView::resizeCurrentBuffer()
298 lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
300 LyXParagraph * par = 0;
301 LyXParagraph * selstartpar = 0;
302 LyXParagraph * selendpar = 0;
311 owner_->getMiniBuffer()->Set(_("Formatting document..."));
314 par = text->cursor.par;
315 pos = text->cursor.pos;
316 selstartpar = text->sel_start_cursor.par;
317 selstartpos = text->sel_start_cursor.pos;
318 selendpar = text->sel_end_cursor.par;
319 selendpos = text->sel_end_cursor.pos;
320 selection = text->selection;
321 mark_set = text->mark_set;
323 text = new LyXText(this, workarea->workWidth(), buffer_);
325 // See if we have a text in TextCache that fits
326 // the new buffer_ with the correct width.
327 text = textcache.findFit(buffer_, workarea->workWidth());
329 if (lyxerr.debugging()) {
330 lyxerr << "Found a LyXText that fits:\n";
331 textcache.show(lyxerr, text);
333 // Set the owner of the newly found text
335 if (lyxerr.debugging())
336 textcache.show(lyxerr, "resizeCurrentBuffer");
338 text = new LyXText(this, workarea->workWidth(), buffer_);
344 text->selection = true;
345 /* at this point just to avoid the Delete-Empty-Paragraph
346 * Mechanism when setting the cursor */
347 text->mark_set = mark_set;
349 text->SetCursor(selstartpar, selstartpos);
350 text->sel_cursor = text->cursor;
351 text->SetCursor(selendpar, selendpos);
352 text->SetSelection();
353 text->SetCursor(par, pos);
355 text->SetCursor(par, pos);
356 text->sel_cursor = text->cursor;
357 text->selection = false;
360 screen->first = screen->TopCursorVisible(); /* this will scroll the
361 * screen such that the
366 owner_->getMiniBuffer()->Init();
370 // Now if the title form still exist kill it
377 void BufferView::gotoError()
382 screen->HideCursor();
387 if (!text->GotoNextError()) {
389 || text->cursor.par != text->FirstParagraph()) {
391 text->cursor.par = text->FirstParagraph();
392 text->cursor.pos = 0;
393 if (!text->GotoNextError()) {
395 owner_->getMiniBuffer()
396 ->Set(_("No more errors"));
400 owner_->getMiniBuffer()->Set(_("No more errors"));
405 text->sel_cursor = text->cursor;
410 void C_BufferView_CursorToggleCB(FL_OBJECT * ob, long buf)
412 BufferView::CursorToggleCB(ob, buf);
417 void BufferView::create_view()
426 timer_cursor = obj = fl_add_timer(FL_HIDDEN_TIMER,
427 0, 0, 0, 0, "Timer");
428 fl_set_object_callback(obj, C_BufferView_CursorToggleCB, 0);
433 // Callback for scrollbar up button
434 void BufferView::UpCB(long time, int button)
436 if (buffer_ == 0) return;
455 XSync(fl_get_display(), 0);
459 // Callback for scrollbar slider
460 void BufferView::ScrollCB(double value)
462 extern bool cursor_follows_scrollbar;
464 if (buffer_ == 0) return;
466 current_scrollbar_value = long(value);
467 if (current_scrollbar_value < 0)
468 current_scrollbar_value = 0;
473 screen->Draw(current_scrollbar_value);
475 if (cursor_follows_scrollbar) {
476 LyXText * vbt = text;
477 int height = vbt->DefaultHeight();
479 if (vbt->cursor.y < screen->first + height) {
480 vbt->SetCursorFromCoordinates(0,
483 } else if (vbt->cursor.y >
484 screen->first + workarea->height() - height) {
485 vbt->SetCursorFromCoordinates(0,
495 // Callback for scrollbar down button
496 void BufferView::DownCB(long time, int button)
498 if (buffer_ == 0) return;
514 int BufferView::ScrollUp(long time)
516 if (buffer_ == 0) return 0;
517 if (!screen) return 0;
519 double value = workarea->getScrollbarValue();
521 if (value == 0) return 0;
523 float add_value = (text->DefaultHeight()
524 + float(time) * float(time) * 0.125);
526 if (add_value > workarea->height())
527 add_value = float(workarea->height() -
528 text->DefaultHeight());
535 workarea->setScrollbarValue(value);
542 int BufferView::ScrollDown(long time)
544 if (buffer_ == 0) return 0;
545 if (!screen) return 0;
547 double value= workarea->getScrollbarValue();
548 pair<double, double> p = workarea->getScrollbarBounds();
549 double max = p.second;
551 if (value == max) return 0;
553 float add_value = (text->DefaultHeight()
554 + float(time) * float(time) * 0.125);
556 if (add_value > workarea->height())
557 add_value = float(workarea->height() -
558 text->DefaultHeight());
565 workarea->setScrollbarValue(value);
572 void BufferView::ScrollUpOnePage()
574 if (buffer_ == 0) return;
577 long y = screen->first;
581 Row * row = text->GetRowNearY(y);
583 y = y - workarea->height() + row->height;
585 workarea->setScrollbarValue(y);
591 void BufferView::ScrollDownOnePage()
593 if (buffer_ == 0) return;
596 long y = screen->first;
598 if (y > text->height - workarea->height())
601 y += workarea->height();
602 text->GetRowNearY(y);
604 workarea->setScrollbarValue(y);
610 void BufferView::WorkAreaMotionNotify(int x, int y, unsigned int state)
612 if (buffer_ == 0 || !screen) return;
614 // Check for inset locking
615 if (the_locking_inset) {
616 LyXCursor cursor = text->cursor;
618 InsetMotionNotify(x - cursor.x,
624 // Only use motion with button 1
625 if (!state & Button1MotionMask)
628 /* The selection possible is needed, that only motion events are
629 * used, where the bottom press event was on the drawing area too */
630 if (selection_possible) {
631 screen->HideCursor();
633 text->SetCursorFromCoordinates(x, y + screen->first);
635 if (!text->selection)
636 update(-3); // Maybe an empty line was deleted
638 text->SetSelection();
639 screen->ToggleToggle();
640 if (screen->FitCursor())
642 screen->ShowCursor();
649 extern int bibitemMaxWidth(Painter &, LyXFont const &);
651 extern int bibitemMaxWidth(LyXFont const &);
654 // Single-click on work area
655 void BufferView::WorkAreaButtonPress(int xpos, int ypos, unsigned int button)
660 if (buffer_ == 0 || !screen) return;
662 Inset * inset_hit = checkInsetHit(xpos, ypos);
664 // ok ok, this is a hack.
665 if (button == 4 || button == 5) {
668 ScrollUp(100); // This number is only temporary
676 if (the_locking_inset) {
677 // We are in inset locking mode
679 /* Check whether the inset was hit. If not reset mode,
680 otherwise give the event to the inset */
683 InsetButtonPress(xpos, ypos,
687 unlockInset(the_locking_inset);
691 selection_possible = true;
692 screen->HideCursor();
694 // Right button mouse click on a table
696 (text->cursor.par->table ||
697 text->MouseHitInTable(xpos, ypos + screen->first))) {
698 // Set the cursor to the press-position
699 text->SetCursorFromCoordinates(xpos, ypos + screen->first);
702 // Only show the table popup if the hit is in
704 if (!text->HitInTable(text->cursor.row, xpos))
707 // Hit above or below the table?
709 if (!text->selection) {
710 screen->ToggleSelection();
711 text->ClearSelection();
716 // Popup table popup when on a table.
717 // This is obviously temporary, since we
718 // should be able to popup various
719 // context-sensitive-menus with the
720 // the right mouse. So this should be done more
721 // general in the future. Matthias.
722 selection_possible = false;
724 ->Dispatch(LFUN_LAYOUT_TABLE,
730 int screen_first = screen->first;
732 // Middle button press pastes if we have a selection
733 bool paste_internally = false;
735 && text->selection) {
736 owner_->getLyXFunc()->Dispatch(LFUN_COPY);
737 paste_internally = true;
740 // Clear the selection
741 screen->ToggleSelection();
742 text->ClearSelection();
747 // Single left click in math inset?
748 if (inset_hit != 0 && inset_hit->Editable() == 2) {
749 // Highly editable inset, like math
750 selection_possible = false;
751 owner_->updateLayoutChoice();
752 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
753 inset_hit->Edit(xpos, ypos);
757 // Right click on a footnote flag opens float menu
759 selection_possible = false;
763 text->SetCursorFromCoordinates(xpos, ypos + screen_first);
765 text->sel_cursor = text->cursor;
766 text->cursor.x_fix = text->cursor.x;
768 owner_->updateLayoutChoice();
769 if (screen->FitCursor()){
771 selection_possible = false;
774 // Insert primary selection with middle mouse
775 // if there is a local selection in the current buffer,
778 if (paste_internally)
779 owner_->getLyXFunc()->Dispatch(LFUN_PASTE);
781 owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION,
783 selection_possible = false;
789 void BufferView::WorkAreaButtonRelease(int x, int y, unsigned int button)
791 if (buffer_ == 0 || screen == 0) return;
793 // If we hit an inset, we have the inset coordinates in these
794 // and inset_hit points to the inset. If we do not hit an
795 // inset, inset_hit is 0, and inset_x == x, inset_y == y.
796 Inset * inset_hit = checkInsetHit(x, y);
798 if (the_locking_inset) {
799 // We are in inset locking mode.
801 /* LyX does a kind of work-area grabbing for insets.
802 Only a ButtonPress Event outside the inset will
803 force a InsetUnlock. */
805 InsetButtonRelease(x, x, button);
809 selection_possible = false;
810 if (text->cursor.par->table) {
812 NumberOfCell(text->cursor.par,
814 if (text->cursor.par->table->IsContRow(cell) &&
815 text->cursor.par->table->
816 CellHasContRow(text->cursor.par->table->
817 GetCellAbove(cell))<0) {
822 if (button >= 2) return;
825 owner_->getMiniBuffer()->Set(CurrentState());
827 // Did we hit an editable inset?
828 if (inset_hit != 0) {
829 // Inset like error, notes and figures
830 selection_possible = false;
832 #warning fix this proper in 0.13
834 // Following a ref shouldn't issue
835 // a push on the undo-stack
836 // anylonger, now that we have
837 // keybindings for following
838 // references and returning from
839 // references. IMHO though, it
840 // should be the inset's own business
841 // to push or not push on the undo
842 // stack. They don't *have* to
843 // alter the document...
845 // ...or maybe the SetCursorParUndo()
846 // below isn't necessary at all anylonger?
847 if (inset_hit->LyxCode() == Inset::REF_CODE) {
848 text->SetCursorParUndo();
851 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
852 inset_hit->Edit(x, y);
856 // check whether we want to open a float
860 if (text->cursor.pos <
861 text->cursor.par->Last()) {
862 c = text->cursor.par->
863 GetChar(text->cursor.pos);
865 if (c == LyXParagraph::META_FOOTNOTE
866 || c == LyXParagraph::META_MARGIN
867 || c == LyXParagraph::META_FIG
868 || c == LyXParagraph::META_TAB
869 || c == LyXParagraph::META_WIDE_FIG
870 || c == LyXParagraph::META_WIDE_TAB
871 || c == LyXParagraph::META_ALGORITHM){
873 } else if (text->cursor.pos - 1 >= 0) {
874 c = text->cursor.par->
875 GetChar(text->cursor.pos - 1);
876 if (c == LyXParagraph::META_FOOTNOTE
877 || c == LyXParagraph::META_MARGIN
878 || c == LyXParagraph::META_FIG
879 || c == LyXParagraph::META_TAB
880 || c == LyXParagraph::META_WIDE_FIG
881 || c == LyXParagraph::META_WIDE_TAB
882 || c == LyXParagraph::META_ALGORITHM){
883 // We are one step too far to the right
890 selection_possible = false;
895 // Do we want to close a float? (click on the float-label)
896 if (text->cursor.row->par->footnoteflag ==
897 LyXParagraph::OPEN_FOOTNOTE
898 //&& text->cursor.pos == 0
899 && text->cursor.row->previous &&
900 text->cursor.row->previous->par->
901 footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
902 LyXFont font (LyXFont::ALL_SANE);
903 font.setSize(LyXFont::SIZE_FOOTNOTE);
905 int box_x = 20; // LYX_PAPER_MARGIN;
906 box_x += font.textWidth(" wide-tab ", 10);
908 int screen_first = screen->first;
911 && y + screen_first > text->cursor.y -
912 text->cursor.row->baseline
913 && y + screen_first < text->cursor.y -
914 text->cursor.row->baseline
915 + font.maxAscent() * 1.2 + font.maxDescent() * 1.2) {
917 selection_possible = false;
922 // Maybe we want to edit a bibitem ale970302
924 if (text->cursor.par->bibkey && x < 20 +
925 bibitemMaxWidth(painter(),
928 params.textclass).defaultfont())) {
929 text->cursor.par->bibkey->Edit(0, 0);
932 if (text->cursor.par->bibkey && x < 20 +
933 bibitemMaxWidth(textclasslist
935 params.textclass).defaultfont())) {
936 text->cursor.par->bibkey->Edit(0, 0);
945 * Returns an inset if inset was hit. 0 otherwise.
946 * If hit, the coordinates are changed relative to the inset.
947 * Otherwise coordinates are not changed, and false is returned.
950 Inset * BufferView::checkInsetHit(int & x, int & y)
955 int y_tmp = y + getScreen()->first;
957 LyXCursor & cursor = text->cursor;
958 LyXDirection direction = text->real_current_font.getFontDirection();
960 if (cursor.pos < cursor.par->Last()
961 && cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET
962 && cursor.par->GetInset(cursor.pos)
963 && cursor.par->GetInset(cursor.pos)->Editable()) {
965 // Check whether the inset really was hit
966 Inset * tmpinset = cursor.par->GetInset(cursor.pos);
967 LyXFont font = text->GetFont(cursor.par, cursor.pos);
969 if (direction == LYX_DIR_LEFT_TO_RIGHT) {
971 end_x = cursor.x + tmpinset->width(painter(), font);
973 start_x = cursor.x - tmpinset->width(painter(), font);
977 if (x > start_x && x < end_x
978 && y_tmp > cursor.y - tmpinset->ascent(painter(), font)
979 && y_tmp < cursor.y + tmpinset->descent(painter(), font)) {
981 // The origin of an inset is on the baseline
982 y = y_tmp - (cursor.y);
987 if (cursor.pos - 1 >= 0
988 && cursor.par->GetChar(cursor.pos - 1) == LyXParagraph::META_INSET
989 && cursor.par->GetInset(cursor.pos - 1)
990 && cursor.par->GetInset(cursor.pos - 1)->Editable()) {
992 Inset * tmpinset = cursor.par->GetInset(cursor.pos);
993 LyXFont font = text->GetFont(cursor.par, cursor.pos);
995 if (direction == LYX_DIR_LEFT_TO_RIGHT) {
997 end_x = cursor.x + tmpinset->width(painter(), font);
999 start_x = cursor.x - tmpinset->width(painter(), font);
1002 if (x > start_x && x < end_x
1003 && y_tmp > cursor.y - tmpinset->ascent(painter(), font)
1004 && y_tmp < cursor.y + tmpinset->descent(painter(), font)) {
1006 // The origin of an inset is on the baseline
1007 y = y_tmp - (cursor.y);
1010 text->CursorRight();
1017 Inset * BufferView::checkInsetHit(int & x, int & y)
1022 int y_tmp = y + getScreen()->first;
1024 LyXCursor & cursor = text->cursor;
1025 LyXDirection direction = text->real_current_font.getFontDirection();
1027 if (cursor.pos < cursor.par->Last()
1028 && cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET
1029 && cursor.par->GetInset(cursor.pos)
1030 && cursor.par->GetInset(cursor.pos)->Editable()) {
1032 // Check whether the inset really was hit
1033 Inset * tmpinset = cursor.par->GetInset(cursor.pos);
1034 LyXFont font = text->GetFont(cursor.par, cursor.pos);
1036 if (direction == LYX_DIR_LEFT_TO_RIGHT) {
1038 end_x = cursor.x + tmpinset->Width(font);
1040 start_x = cursor.x - tmpinset->Width(font);
1044 if (x > start_x && x < end_x
1045 && y_tmp > cursor.y - tmpinset->Ascent(font)
1046 && y_tmp < cursor.y + tmpinset->Descent(font)) {
1048 // The origin of an inset is on the baseline
1049 y = y_tmp - (cursor.y);
1054 if (cursor.pos - 1 >= 0
1055 && cursor.par->GetChar(cursor.pos - 1) == LyXParagraph::META_INSET
1056 && cursor.par->GetInset(cursor.pos - 1)
1057 && cursor.par->GetInset(cursor.pos - 1)->Editable()) {
1059 Inset * tmpinset = cursor.par->GetInset(cursor.pos);
1060 LyXFont font = text->GetFont(cursor.par, cursor.pos);
1062 if (direction == LYX_DIR_LEFT_TO_RIGHT) {
1064 end_x = cursor.x + tmpinset->Width(font);
1066 start_x = cursor.x - tmpinset->Width(font);
1069 if (x > start_x && x < end_x
1070 && y_tmp > cursor.y - tmpinset->Ascent(font)
1071 && y_tmp < cursor.y + tmpinset->Descent(font)) {
1073 // The origin of an inset is on the baseline
1074 y = y_tmp - (cursor.y);
1077 text->CursorRight();
1086 void BufferView::workAreaExpose()
1088 // this is a hack to ensure that we only call this through
1089 // BufferView::redraw().
1094 static int work_area_width = -1;
1095 static int work_area_height = -1;
1097 bool widthChange = workarea->workWidth() != work_area_width;
1098 bool heightChange = workarea->height() != work_area_height;
1100 // update from work area
1101 work_area_width = workarea->workWidth();
1102 work_area_height = workarea->height();
1105 // All buffers need a resize
1106 bufferlist.resize();
1108 // Remove all texts from the textcache
1109 // This is not _really_ what we want to do. What
1110 // we really want to do is to delete in textcache
1111 // that does not have a BufferView with matching
1112 // width, but as long as we have only one BufferView
1113 // deleting all gives the same result.
1114 if (lyxerr.debugging())
1115 textcache.show(lyxerr, "Expose delete all");
1117 } else if (heightChange) {
1118 // Rebuild image of current screen
1120 // fitCursor() ensures we don't jump back
1121 // to the start of the document on vertical
1125 // The main window size has changed, repaint most stuff
1127 // ...including the minibuffer
1128 owner_->getMiniBuffer()->Init();
1130 } else if (screen) screen->Redraw();
1132 // Grey box when we don't have a buffer
1133 workarea->greyOut();
1136 // always make sure that the scrollbar is sane.
1138 owner_->updateLayoutChoice();
1143 // Callback for cursor timer
1144 void BufferView::CursorToggleCB(FL_OBJECT * ob, long)
1146 BufferView * view = static_cast<BufferView*>(ob->u_vdata);
1148 // Quite a nice place for asyncron Inset updating, isn't it?
1149 // Actually no! This is run even if no buffer exist... so (Lgb)
1150 if (view && !view->buffer_) {
1151 goto set_timer_and_return;
1155 // On my quest to solve the gs render hangups I am now
1156 // disabling the SIGHUP completely, and will do a wait
1157 // now and then instead. If the guess that xforms somehow
1158 // destroys something is true, this is likely (hopefully)
1159 // to solve the problem...at least I hope so. Lgb
1161 // ...Ok this seems to work...at least it does not make things
1162 // worse so far. However I still see gs processes that hangs.
1163 // I would really like to know _why_ they are hanging. Anyway
1164 // the solution without the SIGCHLD handler seems to be easier
1167 // When attaching gdb to a a running gs that hangs it shows
1168 // that it is waiting for input(?) Is it possible for us to
1169 // provide that input somehow? Or figure what it is expecing
1172 // One solution is to, after some time, look if there are some
1173 // old gs processes still running and if there are: kill them
1176 // Another solution is to provide the user an option to rerender
1177 // a picture. This would, for the picture in question, check if
1178 // there is a gs running for it, if so kill it, and start a new
1179 // rendering process.
1181 // these comments posted to lyx@via
1184 int pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1185 if (pid == -1) // error find out what is wrong
1186 ; // ignore it for now.
1188 sigchldhandler(pid, &status);
1190 if (InsetUpdateList)
1191 UpdateInsetUpdateList();
1193 if (view && !view->screen){
1194 goto set_timer_and_return;
1197 if (view->lyx_focus && view->work_area_focus) {
1198 if (!view->the_locking_inset) {
1199 view->screen->CursorToggle();
1201 view->the_locking_inset->
1202 ToggleInsetCursor();
1204 goto set_timer_and_return;
1206 // Make sure that the cursor is visible.
1207 if (!view->the_locking_inset) {
1208 view->screen->ShowCursor();
1210 if (!view->the_locking_inset->isCursorVisible())
1211 view->the_locking_inset->
1212 ToggleInsetCursor();
1214 // This is only run when work_area_focus or lyx_focus is false.
1217 XGetInputFocus(fl_display, &tmpwin, &tmp);
1218 // Commenting this out, we have not had problems with this
1219 // for a long time. We will probably work on this code later
1220 // and we can reenable this debug code then. Now it only
1221 // anoying when debugging. (Lgb)
1222 //if (lyxerr.debugging(Debug::INFO)) {
1223 // lyxerr << "tmpwin: " << tmpwin
1224 // << "\nwindow: " << view->owner_->getForm()->window
1225 // << "\nwork_area_focus: " << view->work_area_focus
1226 // << "\nlyx_focus : " << view->lyx_focus
1229 if (tmpwin != view->owner_->getForm()->window) {
1230 view->lyx_focus = false;
1233 view->lyx_focus = true;
1234 if (!view->work_area_focus)
1237 goto set_timer_and_return;
1241 set_timer_and_return:
1242 fl_set_timer(ob, 0.4);
1249 string fromClipboard(Window win, XEvent * event)
1252 if (event->xselection.type == XA_STRING
1253 && event->xselection.property) {
1257 unsigned char * uc = 0;
1259 if (XGetWindowProperty(
1260 event->xselection.display, // display
1262 event->xselection.property, // property
1266 XA_STRING, // req_type
1267 &tmpatom, // actual_type_return
1268 &tmpint, // actual_format_return
1279 if (XGetWindowProperty(
1280 event->xselection.display, // display
1282 event->xselection.property, // property
1284 ul2/4+1, // long_length
1286 XA_STRING, // req_type
1287 &tmpatom, // actual_type_return
1288 &tmpint, // actual_format_return
1289 &ul1, // nitems_return
1290 &ul2, // bytes_after_return
1291 &uc // prop_return */
1296 strret = reinterpret_cast<char*>(uc);
1297 free(uc); // yes free!
1305 void BufferView::WorkAreaSelectionNotify(Window win, XEvent * event)
1307 if (buffer_ == 0) return;
1309 screen->HideCursor();
1311 string clb = fromClipboard(win, event);
1314 text->InsertStringA(clb.c_str());
1316 text->InsertStringB(clb.c_str());
1324 void BufferView::cursorPrevious()
1326 if (!text->cursor.row->previous) return;
1328 long y = getScreen()->first;
1329 Row * cursorrow = text->cursor.row;
1330 text->SetCursorFromCoordinates(text->cursor.x_fix, y);
1332 // This is to allow jumping over large insets
1333 if ((cursorrow == text->cursor.row))
1336 if (text->cursor.row->height < workarea->height())
1337 getScreen()->Draw(text->cursor.y
1338 - text->cursor.row->baseline
1339 + text->cursor.row->height
1340 - workarea->height() + 1 );
1344 void BufferView::cursorNext()
1346 if (!text->cursor.row->next) return;
1348 long y = getScreen()->first;
1349 text->GetRowNearY(y);
1350 Row * cursorrow = text->cursor.row;
1351 text->SetCursorFromCoordinates(text->cursor.x_fix, y
1352 + workarea->height());
1354 // This is to allow jumping over large insets
1355 if ((cursorrow == text->cursor.row))
1358 if (text->cursor.row->height < workarea->height())
1359 getScreen()->Draw(text->cursor.y
1360 - text->cursor.row->baseline);
1364 bool BufferView::available() const
1366 if (buffer_ && text) return true;
1371 void BufferView::beforeChange()
1373 getScreen()->ToggleSelection();
1374 text->ClearSelection();
1379 void BufferView::savePosition()
1381 backstack.push(buffer()->fileName(),
1387 void BufferView::restorePosition()
1389 if (backstack.empty()) return;
1392 string fname = backstack.pop(&x, &y);
1395 Buffer * b = bufferlist.exists(fname) ?
1396 bufferlist.getBuffer(fname) :
1397 bufferlist.loadLyXFile(fname); // don't ask, just load it
1399 text->SetCursorFromCoordinates(x, y);
1404 void BufferView::update(signed char f)
1406 owner()->updateLayoutChoice();
1408 if (!text->selection && f > -3)
1409 text->sel_cursor = text->cursor;
1412 text->FullRebreak();
1416 if (f != 3 && f != -3) {
1421 if (f == 1 || f == -1) {
1422 if (buffer()->isLyxClean()) {
1423 buffer()->markDirty();
1424 owner()->getMiniBuffer()->setTimer(4);
1426 buffer()->markDirty();
1432 void BufferView::smallUpdate(signed char f)
1434 getScreen()->SmallUpdate();
1435 if (getScreen()->TopCursorVisible()
1436 != getScreen()->first) {
1444 if (!text->selection)
1445 text->sel_cursor = text->cursor;
1447 if (f == 1 || f == -1) {
1448 if (buffer()->isLyxClean()) {
1449 buffer()->markDirty();
1450 owner()->getMiniBuffer()->setTimer(4);
1452 buffer()->markDirty();
1458 void BufferView::SetState()
1460 if (!lyxrc->rtl_support)
1463 if (text->real_current_font.getFontDirection()
1464 == LYX_DIR_LEFT_TO_RIGHT) {
1465 if (!owner_->getIntl()->primarykeymap)
1466 owner_->getIntl()->KeyMapPrim();
1468 if (owner_->getIntl()->primarykeymap)
1469 owner_->getIntl()->KeyMapSec();
1474 void BufferView::insetSleep()
1476 if (the_locking_inset && !inset_slept) {
1477 the_locking_inset->GetCursorPos(slx, sly);
1478 the_locking_inset->InsetUnlock();
1484 void BufferView::insetWakeup()
1486 if (the_locking_inset && inset_slept) {
1487 the_locking_inset->Edit(slx, sly);
1488 inset_slept = false;
1493 void BufferView::insetUnlock()
1495 if (the_locking_inset) {
1496 if (!inset_slept) the_locking_inset->InsetUnlock();
1497 the_locking_inset = 0;
1499 inset_slept = false;
1504 bool BufferView::focus() const
1506 return workarea->hasFocus();
1510 void BufferView::focus(bool f)
1512 if (f) workarea->setFocus();
1516 bool BufferView::active() const
1518 return workarea->active();