]> git.lyx.org Git - lyx.git/blob - src/BufferView_pimpl.C
b28da354b1f511140d692034797cd42059799cab
[lyx.git] / src / BufferView_pimpl.C
1 #include <config.h>
2
3 #include <unistd.h>
4 #include <sys/wait.h>
5
6 #ifdef __GNUG__
7 #pragma implementation
8 #endif
9
10 #include "BufferView_pimpl.h"
11 #include "WorkArea.h"
12 #include "lyxscreen.h"
13 #include "lyxtext.h"
14 #include "lyxrow.h"
15 #include "LyXView.h"
16 #include "commandtags.h"
17 #include "lyxfunc.h"
18 #include "minibuffer.h"
19 #include "font.h"
20 #include "bufferview_funcs.h"
21 #include "TextCache.h"
22 #include "bufferlist.h"
23 #include "insets/insetbib.h"
24 #include "menus.h"
25 #include "lyx_gui_misc.h"
26 #include "lyxrc.h"
27 #include "intl.h"
28 #include "support/LAssert.h"
29
30 using std::pair;
31 using std::endl;
32 using std::vector;
33
34 /* the selection possible is needed, that only motion events are 
35  * used, where the bottom press event was on the drawing area too */
36 bool selection_possible = false;
37
38 extern BufferList bufferlist;
39 extern char ascii_type;
40
41 extern void sigchldhandler(pid_t pid, int * status);
42 extern int bibitemMaxWidth(Painter &, LyXFont const &);
43 extern void FreeUpdateTimer();
44
45 extern "C"
46 void C_BufferView_CursorToggleCB(FL_OBJECT * ob, long buf);
47
48
49 static inline
50 void waitForX()
51 {
52         XSync(fl_get_display(), 0);
53 }
54
55
56 static
57 void SetXtermCursor(Window win)
58 {
59         static Cursor cursor;
60         static bool cursor_undefined = true;
61         if (cursor_undefined){
62                 cursor = XCreateFontCursor(fl_display, XC_xterm);
63                 XFlush(fl_display);
64                 cursor_undefined = false;
65         }
66         XDefineCursor(fl_display, win, cursor);
67         XFlush(fl_display);
68 }
69
70
71 BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o,
72              int xpos, int ypos, int width, int height)
73         : bv_(b), owner_(o)
74 {
75         buffer_ = 0;
76         workarea = new WorkArea(bv_, xpos, ypos, width, height);
77         screen = 0;
78         timer_cursor = 0;
79         create_view();
80         current_scrollbar_value = 0;
81         fl_set_timer(timer_cursor, 0.4);
82         workarea->setFocus();
83         work_area_focus = true;
84         lyx_focus = false;
85         using_xterm_cursor = false;
86 }
87
88
89 Painter & BufferView::Pimpl::painter() 
90 {
91         return workarea->getPainter();
92 }
93
94
95 void BufferView::Pimpl::buffer(Buffer * b)
96 {
97         lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
98                             << b << ")" << endl;
99         if (buffer_) {
100                 bv_->insetSleep();
101                 buffer_->delUser(bv_);
102
103                 // Put the old text into the TextCache, but
104                 // only if the buffer is still loaded.
105                 // Also set the owner of the test to 0
106                 bv_->text->owner(0);
107                 textcache.add(bv_->text);
108                 if (lyxerr.debugging())
109                         textcache.show(lyxerr, "BufferView::buffer");
110                 
111                 bv_->text = 0;
112         }
113
114         // Set current buffer
115         buffer_ = b;
116
117         if (bufferlist.getState() == BufferList::CLOSING) return;
118         
119         // Nuke old image
120         // screen is always deleted when the buffer is changed.
121         delete screen;
122         screen = 0;
123
124         // If we are closing the buffer, use the first buffer as current
125         if (!buffer_) {
126                 buffer_ = bufferlist.first();
127         }
128
129         if (buffer_) {
130                 lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
131                 buffer_->addUser(bv_);
132                 owner_->getMenus()->showMenus();
133                 // If we don't have a text object for this, we make one
134                 if (bv_->text == 0)
135                         resizeCurrentBuffer();
136                 else {
137                         updateScreen();
138                         updateScrollbar();
139                 }
140                 screen->first = screen->TopCursorVisible();
141                 redraw();
142                 updateAllVisibleBufferRelatedPopups();
143                 bv_->insetWakeup();
144         } else {
145                 lyxerr[Debug::INFO] << "  No Buffer!" << endl;
146                 owner_->getMenus()->hideMenus();
147                 updateScrollbar();
148                 workarea->redraw();
149
150                 // Also remove all remaining text's from the testcache.
151                 // (there should not be any!) (if there is any it is a
152                 // bug!)
153                 if (lyxerr.debugging())
154                         textcache.show(lyxerr, "buffer delete all");
155                 textcache.clear();
156         }
157         // should update layoutchoice even if we don't have a buffer.
158         owner_->updateLayoutChoice();
159         owner_->getMiniBuffer()->Init();
160         owner_->updateWindowTitle();
161 }
162
163 void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height)
164 {
165         workarea->resize(xpos, ypos, width, height);
166         update(3);
167         redraw();
168 }
169
170
171 void BufferView::Pimpl::resize()
172 {
173         // This will resize the buffer. (Asger)
174         if (buffer_)
175                 resizeCurrentBuffer();
176 }
177
178
179 void BufferView::Pimpl::redraw()
180 {
181         lyxerr[Debug::INFO] << "BufferView::redraw()" << endl;
182         workarea->redraw();
183 }
184
185
186 bool BufferView::Pimpl::fitCursor()
187 {
188         Assert(screen); // it is a programming error to call fitCursor
189         // without a valid screen.
190         bool ret = screen->FitCursor();
191         if (ret) updateScrollbar();
192         return ret;
193 }
194
195
196 void BufferView::Pimpl::redoCurrentBuffer()
197 {
198         lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl;
199         if (buffer_ && bv_->text) {
200                 resize();
201                 owner_->updateLayoutChoice();
202         }
203 }
204
205
206 int BufferView::Pimpl::resizeCurrentBuffer()
207 {
208         lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
209         
210         LyXParagraph * par = 0;
211         LyXParagraph * selstartpar = 0;
212         LyXParagraph * selendpar = 0;
213         int pos = 0;
214         int selstartpos = 0;
215         int selendpos = 0;
216         int selection = 0;
217         int mark_set = 0;
218
219         ProhibitInput(bv_);
220
221         owner_->getMiniBuffer()->Set(_("Formatting document..."));   
222
223         if (bv_->text) {
224                 par = bv_->text->cursor.par;
225                 pos = bv_->text->cursor.pos;
226                 selstartpar = bv_->text->sel_start_cursor.par;
227                 selstartpos = bv_->text->sel_start_cursor.pos;
228                 selendpar = bv_->text->sel_end_cursor.par;
229                 selendpos = bv_->text->sel_end_cursor.pos;
230                 selection = bv_->text->selection;
231                 mark_set = bv_->text->mark_set;
232                 delete bv_->text;
233                 bv_->text = new LyXText(bv_, workarea->workWidth(), buffer_);
234         } else {
235                 // See if we have a text in TextCache that fits
236                 // the new buffer_ with the correct width.
237                 bv_->text = textcache.findFit(buffer_, workarea->workWidth());
238                 if (bv_->text) {
239                         if (lyxerr.debugging()) {
240                                 lyxerr << "Found a LyXText that fits:\n";
241                                 textcache.show(lyxerr, bv_->text);
242                         }
243                         // Set the owner of the newly found text
244                         bv_->text->owner(bv_);
245                         if (lyxerr.debugging())
246                                 textcache.show(lyxerr, "resizeCurrentBuffer");
247                 } else {
248                         bv_->text = new LyXText(bv_, workarea->workWidth(), buffer_);
249                 }
250         }
251         updateScreen();
252
253         if (par) {
254                 bv_->text->selection = true;
255                 /* at this point just to avoid the Delete-Empty-Paragraph
256                  * Mechanism when setting the cursor */
257                 bv_->text->mark_set = mark_set;
258                 if (selection) {
259                         bv_->text->SetCursor(selstartpar, selstartpos);
260                         bv_->text->sel_cursor = bv_->text->cursor;
261                         bv_->text->SetCursor(selendpar, selendpos);
262                         bv_->text->SetSelection();
263                         bv_->text->SetCursor(par, pos);
264                 } else {
265                         bv_->text->SetCursor(par, pos);
266                         bv_->text->sel_cursor = bv_->text->cursor;
267                         bv_->text->selection = false;
268                 }
269         }
270         screen->first = screen->TopCursorVisible(); /* this will scroll the
271                                                      * screen such that the
272                                                      * cursor becomes
273                                                      * visible */ 
274         updateScrollbar();
275         redraw();
276         owner_->getMiniBuffer()->Init();
277         bv_->setState();
278         AllowInput(bv_);
279
280         // Now if the title form still exist kill it
281         TimerCB(0, 0);
282
283         return 0;
284 }
285
286
287 void BufferView::Pimpl::gotoError()
288 {
289         if (!screen)
290                 return;
291    
292         screen->HideCursor();
293         bv_->beforeChange();
294         update(-2);
295         LyXCursor tmp;
296
297         if (!bv_->text->GotoNextError()) {
298                 if (bv_->text->cursor.pos 
299                     || bv_->text->cursor.par != bv_->text->FirstParagraph()) {
300                         tmp = bv_->text->cursor;
301                         bv_->text->cursor.par = bv_->text->FirstParagraph();
302                         bv_->text->cursor.pos = 0;
303                         if (!bv_->text->GotoNextError()) {
304                                 bv_->text->cursor = tmp;
305                                 owner_->getMiniBuffer()
306                                         ->Set(_("No more errors"));
307                                 LyXBell();
308                         }
309                 } else {
310                         owner_->getMiniBuffer()->Set(_("No more errors"));
311                         LyXBell();
312                 }
313         }
314         update(0);
315         bv_->text->sel_cursor = bv_->text->cursor;
316 }
317
318
319 void BufferView::Pimpl::updateScreen()
320 {
321         // Regenerate the screen.
322         delete screen;
323         screen = new LyXScreen(*workarea, bv_->text);
324 }
325
326
327 void BufferView::Pimpl::create_view()
328 {
329         FL_OBJECT * obj;
330
331         //
332         // TIMERS
333         //
334         
335         // timer_cursor
336         timer_cursor = obj = fl_add_timer(FL_HIDDEN_TIMER,
337                                           0, 0, 0, 0, "Timer");
338         fl_set_object_callback(obj, C_BufferView_CursorToggleCB, 0);
339         obj->u_vdata = bv_;
340 }
341
342
343 void BufferView::Pimpl::updateScrollbar()
344 {
345         /* If the text is smaller than the working area, the scrollbar
346          * maximum must be the working area height. No scrolling will 
347          * be possible */
348
349         if (!buffer_) {
350                 workarea->setScrollbar(0, 1.0);
351                 return;
352         }
353         
354         static unsigned long max2 = 0;
355         static unsigned long height2 = 0;
356
357         unsigned long cbth = 0;
358         long cbsf = 0;
359
360         if (bv_->text)
361                 cbth = bv_->text->height;
362         if (screen)
363                 cbsf = screen->first;
364
365         // check if anything has changed.
366         if (max2 == cbth &&
367             height2 == workarea->height() &&
368             current_scrollbar_value == cbsf)
369                 return; // no
370         max2 = cbth;
371         height2 = workarea->height();
372         current_scrollbar_value = cbsf;
373
374         if (cbth <= height2) { // text is smaller than screen
375                 workarea->setScrollbar(0, 1.0); // right?
376                 return;
377         }
378
379         long maximum_height = workarea->height() * 3 / 4 + cbth;
380         long value = cbsf;
381
382         // set the scrollbar
383         double hfloat = workarea->height();
384         double maxfloat = maximum_height;
385
386         float slider_size = 0.0;
387         int slider_value = value;
388
389         workarea->setScrollbarBounds(0, bv_->text->height - workarea->height());
390         double lineh = bv_->text->DefaultHeight();
391         workarea->setScrollbarIncrements(lineh);
392         if (maxfloat > 0.0) {
393                 if ((hfloat / maxfloat) * float(height2) < 3)
394                         slider_size = 3.0/float(height2);
395                 else
396                         slider_size = hfloat / maxfloat;
397         } else
398                 slider_size = hfloat;
399
400         workarea->setScrollbar(slider_value, slider_size / workarea->height());
401 }
402
403
404 // Callback for scrollbar slider
405 void BufferView::Pimpl::scrollCB(double value)
406 {
407         extern bool cursor_follows_scrollbar;
408         
409         if (buffer_ == 0) return;
410
411         current_scrollbar_value = long(value);
412         if (current_scrollbar_value < 0)
413                 current_scrollbar_value = 0;
414    
415         if (!screen)
416                 return;
417
418         screen->Draw(current_scrollbar_value);
419
420         if (cursor_follows_scrollbar) {
421                 LyXText * vbt = bv_->text;
422                 unsigned int height = vbt->DefaultHeight();
423                 
424                 if (vbt->cursor.y < screen->first + height) {
425                         vbt->SetCursorFromCoordinates(0,
426                                                       screen->first +
427                                                       height);
428                 } else if (vbt->cursor.y >
429                            screen->first + workarea->height() - height) {
430                         vbt->SetCursorFromCoordinates(0,
431                                                       screen->first +
432                                                       workarea->height()  -
433                                                       height);
434                 }
435         }
436         waitForX();
437 }
438
439
440 int BufferView::Pimpl::scrollUp(long time)
441 {
442         if (buffer_ == 0) return 0;
443         if (!screen) return 0;
444    
445         double value = workarea->getScrollbarValue();
446    
447         if (value == 0) return 0;
448
449         float add_value =  (bv_->text->DefaultHeight()
450                             + float(time) * float(time) * 0.125);
451    
452         if (add_value > workarea->height())
453                 add_value = float(workarea->height() -
454                                   bv_->text->DefaultHeight());
455    
456         value -= add_value;
457
458         if (value < 0)
459                 value = 0;
460    
461         workarea->setScrollbarValue(value);
462    
463         bv_->scrollCB(value); 
464         return 0;
465 }
466
467
468 int BufferView::Pimpl::scrollDown(long time)
469 {
470         if (buffer_ == 0) return 0;
471         if (!screen) return 0;
472    
473         double value= workarea->getScrollbarValue();
474         pair<float, float> p = workarea->getScrollbarBounds();
475         double max = p.second;
476         
477         if (value == max) return 0;
478
479         float add_value =  (bv_->text->DefaultHeight()
480                             + float(time) * float(time) * 0.125);
481    
482         if (add_value > workarea->height())
483                 add_value = float(workarea->height() -
484                                   bv_->text->DefaultHeight());
485    
486         value += add_value;
487    
488         if (value > max)
489                 value = max;
490
491         workarea->setScrollbarValue(value);
492         
493         bv_->scrollCB(value); 
494         return 0;
495 }
496
497
498 void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
499 {
500         if (buffer_ == 0 || !screen) return;
501
502         // Only use motion with button 1
503         if (!state & Button1MotionMask)
504                 return; 
505
506         // Check for inset locking
507         if (bv_->the_locking_inset) {
508                 LyXCursor cursor = bv_->text->cursor;
509                 bv_->the_locking_inset->
510                         InsetMotionNotify(bv_,
511                                           x - cursor.x,
512                                           y - cursor.y + screen->first,
513                                           state);
514                 return;
515         }
516    
517         /* The selection possible is needed, that only motion events are 
518          * used, where the bottom press event was on the drawing area too */
519         if (selection_possible) {
520                 screen->HideCursor();
521
522                 bv_->text->SetCursorFromCoordinates(x, y + screen->first);
523       
524                 if (!bv_->text->selection)
525                         update(-3); // Maybe an empty line was deleted
526       
527                 bv_->text->SetSelection();
528                 screen->ToggleToggle();
529                 fitCursor();
530                 screen->ShowCursor();
531         }
532         return;
533 }
534
535
536 // Single-click on work area
537 void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
538                                             unsigned int button)
539 {
540         last_click_x = -1;
541         last_click_y = -1;
542
543         if (buffer_ == 0 || !screen) return;
544
545         Inset * inset_hit = checkInsetHit(xpos, ypos, button);
546
547         // ok ok, this is a hack.
548         if (button == 4 || button == 5) {
549                 switch (button) {
550                 case 4:
551                         scrollUp(100); // This number is only temporary
552                         break;
553                 case 5:
554                         scrollDown(100);
555                         break;
556                 }
557         }
558         
559         if (bv_->the_locking_inset) {
560                 // We are in inset locking mode
561                 
562                 /* Check whether the inset was hit. If not reset mode,
563                    otherwise give the event to the inset */
564                 if (inset_hit == bv_->the_locking_inset) {
565                         bv_->the_locking_inset->
566                                 InsetButtonPress(bv_,
567                                                  xpos, ypos,
568                                                  button);
569                         return;
570                 } else {
571                         bv_->unlockInset(bv_->the_locking_inset);
572                 }
573         }
574         
575         if (!inset_hit)
576                 selection_possible = true;
577         screen->HideCursor();
578         
579         // Right button mouse click on a table
580         if (button == 3 &&
581             (bv_->text->cursor.par->table ||
582              bv_->text->MouseHitInTable(xpos, ypos + screen->first))) {
583                 // Set the cursor to the press-position
584                 bv_->text->SetCursorFromCoordinates(xpos, ypos + screen->first);
585                 bool doit = true;
586                 
587                 // Only show the table popup if the hit is in
588                 // the table, too
589                 if (!bv_->text->HitInTable(bv_->text->cursor.row, xpos))
590                         doit = false;
591                 
592                 // Hit above or below the table?
593                 if (doit) {
594                         if (!bv_->text->selection) {
595                                 screen->ToggleSelection();
596                                 bv_->text->ClearSelection();
597                                 bv_->text->FullRebreak();
598                                 screen->Update();
599                                 updateScrollbar();
600                         }
601                         // Popup table popup when on a table.
602                         // This is obviously temporary, since we
603                         // should be able to popup various
604                         // context-sensitive-menus with the
605                         // the right mouse. So this should be done more
606                         // general in the future. Matthias.
607                         selection_possible = false;
608                         owner_->getLyXFunc()
609                                 ->Dispatch(LFUN_LAYOUT_TABLE,
610                                            "true");
611                         return;
612                 }
613         }
614         
615         int screen_first = screen->first;
616         
617         // Middle button press pastes if we have a selection
618         bool paste_internally = false;
619         if (button == 2
620             && bv_->text->selection) {
621                 owner_->getLyXFunc()->Dispatch(LFUN_COPY);
622                 paste_internally = true;
623         }
624         
625         // Clear the selection
626         screen->ToggleSelection();
627         bv_->text->ClearSelection();
628         bv_->text->FullRebreak();
629         screen->Update();
630         updateScrollbar();
631         
632         // Single left click in math inset?
633         if ((inset_hit != 0) &&
634             (inset_hit->Editable()==Inset::HIGHLY_EDITABLE)) {
635                 // Highly editable inset, like math
636                 UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
637                 selection_possible = false;
638                 owner_->updateLayoutChoice();
639                 owner_->getMiniBuffer()->Set(inset->EditMessage());
640                 inset->InsetButtonPress(bv_, xpos, ypos, button);
641                 inset->Edit(bv_, xpos, ypos, button);
642                 return;
643         } 
644         
645         // Right click on a footnote flag opens float menu
646         if (button == 3) { 
647                 selection_possible = false;
648                 return;
649         }
650         
651         if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
652                 bv_->text->SetCursorFromCoordinates(xpos, ypos + screen_first);
653         bv_->text->FinishUndo();
654         bv_->text->sel_cursor = bv_->text->cursor;
655         bv_->text->cursor.x_fix = bv_->text->cursor.x;
656         
657         owner_->updateLayoutChoice();
658         if (fitCursor()) {
659                 selection_possible = false;
660         }
661         
662         // Insert primary selection with middle mouse
663         // if there is a local selection in the current buffer,
664         // insert this
665         if (button == 2) {
666                 if (paste_internally)
667                         owner_->getLyXFunc()->Dispatch(LFUN_PASTE);
668                 else
669                         owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION,
670                                                        "paragraph");
671                 selection_possible = false;
672                 return;
673         }
674 }
675
676
677 void BufferView::Pimpl::doubleClick(int /*x*/, int /*y*/, unsigned int button) 
678 {
679         // select a word
680         if (buffer_ && !bv_->the_locking_inset) {
681                 if (screen && button == 1) {
682                         screen->HideCursor();
683                         screen->ToggleSelection();
684                         bv_->text->SelectWord();
685                         screen->ToggleSelection(false);
686                         /* This will fit the cursor on the screen
687                          * if necessary */
688                         update(0);
689                 }
690         }            
691 }
692
693
694 void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button)
695 {
696         // select a line
697         if (buffer_ && screen && button == 1) {
698                 screen->HideCursor();
699                 screen->ToggleSelection();
700                 bv_->text->CursorHome();
701                 bv_->text->sel_cursor = bv_->text->cursor;
702                 bv_->text->CursorEnd();
703                 bv_->text->SetSelection();
704                 screen->ToggleSelection(false);
705                 /* This will fit the cursor on the screen
706                  * if necessary */
707                 update(0);
708         }
709 }
710
711
712 void BufferView::Pimpl::enterView()
713 {
714         if (active() && available()) {
715                 SetXtermCursor(workarea->getWin());
716                 using_xterm_cursor = true;
717         }
718 }
719
720
721 void BufferView::Pimpl::leaveView()
722 {
723         if (using_xterm_cursor) {
724                 XUndefineCursor(fl_display, workarea->getWin());
725                 using_xterm_cursor = false;
726         }
727 }
728
729
730 void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
731                                               unsigned int button)
732 {
733         if (buffer_ == 0 || screen == 0) return;
734
735         // If we hit an inset, we have the inset coordinates in these
736         // and inset_hit points to the inset.  If we do not hit an
737         // inset, inset_hit is 0, and inset_x == x, inset_y == y.
738         Inset * inset_hit = checkInsetHit(x, y, button);
739
740         if (bv_->the_locking_inset) {
741                 // We are in inset locking mode.
742
743                 /* LyX does a kind of work-area grabbing for insets.
744                    Only a ButtonPress Event outside the inset will 
745                    force a InsetUnlock. */
746                 bv_->the_locking_inset->
747                         InsetButtonRelease(bv_, x, y, button);
748                 return;
749         }
750         
751         selection_possible = false;
752         if (bv_->text->cursor.par->table) {
753                 int cell = bv_->text->
754                         NumberOfCell(bv_->text->cursor.par,
755                                      bv_->text->cursor.pos);
756                 if (bv_->text->cursor.par->table->IsContRow(cell) &&
757                     bv_->text->cursor.par->table->
758                     CellHasContRow(bv_->text->cursor.par->table->
759                                    GetCellAbove(cell))<0) {
760                         bv_->text->CursorUp();
761                 }
762         }
763         
764         if (button >= 2) return;
765
766         bv_->setState();
767         owner_->getMiniBuffer()->Set(CurrentState(bv_));
768
769         // Did we hit an editable inset?
770         if (inset_hit != 0) {
771                 // Inset like error, notes and figures
772                 selection_possible = false;
773
774                 // CHECK fix this proper in 0.13
775
776                 // Following a ref shouldn't issue
777                 // a push on the undo-stack
778                 // anylonger, now that we have
779                 // keybindings for following
780                 // references and returning from
781                 // references.  IMHO though, it
782                 // should be the inset's own business
783                 // to push or not push on the undo
784                 // stack. They don't *have* to
785                 // alter the document...
786                 // (Joacim)
787                 // ...or maybe the SetCursorParUndo()
788                 // below isn't necessary at all anylonger?
789                 if (inset_hit->LyxCode() == Inset::REF_CODE) {
790                         bv_->text->SetCursorParUndo();
791                 }
792
793                 owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
794                 if (inset_hit->Editable()==Inset::HIGHLY_EDITABLE) {
795                         // Highly editable inset, like math
796                         UpdatableInset *inset = (UpdatableInset *)inset_hit;
797                         inset->InsetButtonRelease(bv_, x, y, button);
798                 } else {
799                         inset_hit->InsetButtonRelease(bv_, x, y, button);
800                         inset_hit->Edit(bv_, x, y, button);
801                 }
802                 return;
803         }
804
805         // check whether we want to open a float
806         if (bv_->text) {
807                 bool hit = false;
808                 char c = ' ';
809                 if (bv_->text->cursor.pos <
810                     bv_->text->cursor.par->Last()) {
811                         c = bv_->text->cursor.par->
812                                 GetChar(bv_->text->cursor.pos);
813                 }
814                 if (c == LyXParagraph::META_FOOTNOTE
815                     || c == LyXParagraph::META_MARGIN
816                     || c == LyXParagraph::META_FIG
817                     || c == LyXParagraph::META_TAB
818                     || c == LyXParagraph::META_WIDE_FIG
819                     || c == LyXParagraph::META_WIDE_TAB
820                     || c == LyXParagraph::META_ALGORITHM){
821                         hit = true;
822                 } else if (bv_->text->cursor.pos - 1 >= 0) {
823                         c = bv_->text->cursor.par->
824                                 GetChar(bv_->text->cursor.pos - 1);
825                         if (c == LyXParagraph::META_FOOTNOTE
826                             || c == LyXParagraph::META_MARGIN
827                             || c == LyXParagraph::META_FIG
828                             || c == LyXParagraph::META_TAB
829                             || c == LyXParagraph::META_WIDE_FIG 
830                             || c == LyXParagraph::META_WIDE_TAB
831                             || c == LyXParagraph::META_ALGORITHM){
832                                 // We are one step too far to the right
833                                 bv_->text->CursorLeft();
834                                 hit = true;
835                         }
836                 }
837                 if (hit == true) {
838                         bv_->toggleFloat();
839                         selection_possible = false;
840                         return;
841                 }
842         }
843
844         // Do we want to close a float? (click on the float-label)
845         if (bv_->text->cursor.row->par->footnoteflag == 
846             LyXParagraph::OPEN_FOOTNOTE
847             //&& text->cursor.pos == 0
848             && bv_->text->cursor.row->previous &&
849             bv_->text->cursor.row->previous->par->
850             footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
851                 LyXFont font(LyXFont::ALL_SANE);
852                 font.setSize(LyXFont::SIZE_FOOTNOTE);
853
854                 int box_x = 20; // LYX_PAPER_MARGIN;
855                 box_x += lyxfont::width(" wide-tab ", font);
856
857                 unsigned int screen_first = screen->first;
858
859                 if (x < box_x
860                     && y + screen_first > bv_->text->cursor.y -
861                     bv_->text->cursor.row->baseline
862                     && y + screen_first < bv_->text->cursor.y -
863                     bv_->text->cursor.row->baseline
864                     + lyxfont::maxAscent(font) * 1.2 + lyxfont::maxDescent(font) * 1.2) {
865                         bv_->toggleFloat();
866                         selection_possible = false;
867                         return;
868                 }
869         }
870
871         // Maybe we want to edit a bibitem ale970302
872         if (bv_->text->cursor.par->bibkey && x < 20 + 
873             bibitemMaxWidth(bv_->painter(),
874                             textclasslist
875                             .TextClass(buffer_->
876                                        params.textclass).defaultfont())) {
877                 bv_->text->cursor.par->bibkey->Edit(bv_, 0, 0, 0);
878         }
879
880         return;
881 }
882
883
884 /* 
885  * Returns an inset if inset was hit. 0 otherwise.
886  * If hit, the coordinates are changed relative to the inset. 
887  * Otherwise coordinates are not changed, and false is returned.
888  */
889 Inset * BufferView::Pimpl::checkInsetHit(int & x, int & y,
890                                          unsigned int /* button */)
891 {
892         if (!screen)
893                 return 0;
894   
895         unsigned int y_tmp = y + screen->first;
896   
897         LyXCursor cursor;
898         bv_->text->SetCursorFromCoordinates(cursor, x, y_tmp);
899 #if 0 // Are you planning to use this Jürgen? (Lgb)
900         bool move_cursor = ((cursor.par != bv_->text->cursor.par) ||
901                             (cursor.pos != bv_->text->cursor.pos));
902 #endif
903         if (cursor.pos < cursor.par->Last()
904             && cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET
905             && cursor.par->GetInset(cursor.pos)
906             && cursor.par->GetInset(cursor.pos)->Editable()) {
907
908                 // Check whether the inset really was hit
909                 Inset * tmpinset = cursor.par->GetInset(cursor.pos);
910                 LyXFont font = bv_->text->GetFont(cursor.par, cursor.pos);
911                 bool is_rtl = font.isVisibleRightToLeft();
912                 int start_x, end_x;
913
914                 if (is_rtl) {
915                         start_x = cursor.x - tmpinset->width(bv_->painter(), font);
916                         end_x = cursor.x;
917                 } else {
918                         start_x = cursor.x;
919                         end_x = cursor.x + tmpinset->width(bv_->painter(), font);
920                 }
921
922                 if (x > start_x && x < end_x
923                     && y_tmp > cursor.y - tmpinset->ascent(bv_->painter(), font)
924                     && y_tmp < cursor.y + tmpinset->descent(bv_->painter(), font)) {
925 #if 0
926                         if (move_cursor && (tmpinset != bv_->the_locking_inset))
927 #endif
928                                 bv_->text->SetCursor(cursor.par,cursor.pos,true);
929                         x = x - start_x;
930                         // The origin of an inset is on the baseline
931                         y = y_tmp - (bv_->text->cursor.y); 
932                         return tmpinset;
933                 }
934         }
935
936         if ((cursor.pos - 1 >= 0) &&
937             (cursor.par->GetChar(cursor.pos-1) == LyXParagraph::META_INSET) &&
938             (cursor.par->GetInset(cursor.pos - 1)) &&
939             (cursor.par->GetInset(cursor.pos - 1)->Editable())) {
940                 Inset * tmpinset = cursor.par->GetInset(cursor.pos-1);
941                 LyXFont font = bv_->text->GetFont(cursor.par, cursor.pos-1);
942                 bool is_rtl = font.isVisibleRightToLeft();
943                 int start_x, end_x;
944
945                 if (!is_rtl) {
946                         start_x = cursor.x - tmpinset->width(bv_->painter(), font);
947                         end_x = cursor.x;
948                 } else {
949                         start_x = cursor.x;
950                         end_x = cursor.x + tmpinset->width(bv_->painter(), font);
951                 }
952                 if (x > start_x && x < end_x
953                     && y_tmp > cursor.y - tmpinset->ascent(bv_->painter(), font)
954                     && y_tmp < cursor.y + tmpinset->descent(bv_->painter(), font)) {
955 #if 0
956                         if (move_cursor && (tmpinset != bv_->the_locking_inset))
957 #endif
958                                 bv_->text->SetCursor(cursor.par,cursor.pos-1,true);
959                         x = x - start_x;
960                         // The origin of an inset is on the baseline
961                         y = y_tmp - (bv_->text->cursor.y); 
962                         return tmpinset;
963                 }
964         }
965         return 0;
966 }
967
968
969 void BufferView::Pimpl::workAreaExpose()
970 {
971         // this is a hack to ensure that we only call this through
972         // BufferView::redraw().
973         //if (!lgb_hack) {
974         //      redraw();
975         //}
976         
977         static unsigned int work_area_width = 0;
978         static unsigned int work_area_height = 0;
979
980         bool widthChange = workarea->workWidth() != work_area_width;
981         bool heightChange = workarea->height() != work_area_height;
982
983         // update from work area
984         work_area_width = workarea->workWidth();
985         work_area_height = workarea->height();
986         if (buffer_ != 0) {
987                 if (widthChange) {
988                         // All buffers need a resize
989                         bufferlist.resize();
990
991                         // Remove all texts from the textcache
992                         // This is not _really_ what we want to do. What
993                         // we really want to do is to delete in textcache
994                         // that does not have a BufferView with matching
995                         // width, but as long as we have only one BufferView
996                         // deleting all gives the same result.
997                         if (lyxerr.debugging())
998                                 textcache.show(lyxerr, "Expose delete all");
999                         textcache.clear();
1000                 } else if (heightChange) {
1001                         // Rebuild image of current screen
1002                         updateScreen();
1003                         // fitCursor() ensures we don't jump back
1004                         // to the start of the document on vertical
1005                         // resize
1006                         fitCursor();
1007
1008                         // The main window size has changed, repaint most stuff
1009                         redraw();
1010                         // ...including the minibuffer
1011                         owner_->getMiniBuffer()->Init();
1012
1013                 } else if (screen) screen->Redraw();
1014         } else {
1015                 // Grey box when we don't have a buffer
1016                 workarea->greyOut();
1017         }
1018
1019         // always make sure that the scrollbar is sane.
1020         updateScrollbar();
1021         owner_->updateLayoutChoice();
1022         return;
1023 }
1024
1025
1026 #ifndef XFORMS_CLIPBOARD
1027 static
1028 string fromClipboard(Window win, XEvent * event)
1029 {
1030         string strret;
1031         if (event->xselection.type == XA_STRING
1032             && event->xselection.property) {
1033                 Atom tmpatom;
1034                 unsigned long ul1;
1035                 unsigned long ul2;
1036                 unsigned char * uc = 0;
1037                 int tmpint;
1038                 if (XGetWindowProperty(
1039                         event->xselection.display,  // display
1040                         win,                        // w
1041                         event->xselection.property, // property
1042                         0,                          // long_offset      
1043                         0,                          // logn_length      
1044                         False,                      // delete   
1045                         XA_STRING,                  // req_type 
1046                         &tmpatom,                   // actual_type_return
1047                         &tmpint,                    // actual_format_return
1048                         &ul1,
1049                         &ul2,
1050                         &uc                         // prop_return      
1051                         ) != Success) {
1052                         return strret;
1053                 }
1054                 if (uc) {
1055                         free(uc);
1056                         uc = 0;
1057                 }
1058                 if (XGetWindowProperty(
1059                         event->xselection.display,             // display
1060                         win,                        // w
1061                         event->xselection.property, // property
1062                         0,                          // long_offset
1063                         ul2/4+1,                    // long_length
1064                         True,                       // delete
1065                         XA_STRING,                  // req_type
1066                         &tmpatom,                   // actual_type_return
1067                         &tmpint,                    // actual_format_return
1068                         &ul1,                       // nitems_return
1069                         &ul2,                       // bytes_after_return
1070                         &uc                         // prop_return */
1071                         ) != Success) {
1072                         return strret;
1073                 }
1074                 if (uc) {
1075                         strret = reinterpret_cast<char*>(uc);
1076                         free(uc); // yes free!
1077                         uc = 0;
1078                 }
1079         }
1080         return strret;
1081 }
1082
1083
1084 void BufferView::Pimpl::workAreaSelectionNotify(Window win, XEvent * event)
1085 {
1086         if (buffer_ == 0) return;
1087
1088         screen->HideCursor();
1089         bv_->beforeChange();
1090         string clb = fromClipboard(win, event);
1091         if (!clb.empty()) {
1092                 if (!ascii_type)
1093                         bv_->text->InsertStringA(clb);
1094                 else
1095                         bv_->text->InsertStringB(clb);
1096
1097                 update(1);
1098         }
1099 }
1100 #endif
1101
1102
1103 void BufferView::Pimpl::update()
1104 {
1105         if (screen) screen->Update();
1106 }
1107
1108 // Values used when calling update:
1109 // -3 - update
1110 // -2 - update, move sel_cursor if selection, fitcursor
1111 // -1 - update, move sel_cursor if selection, fitcursor, mark dirty
1112 //  0 - update, move sel_cursor if selection, fitcursor 
1113 //  1 - update, move sel_cursor if selection, fitcursor, mark dirty
1114 //  3 - update, move sel_cursor if selection
1115 //
1116 // update -
1117 // a simple redraw of the parts that need refresh
1118 //
1119 // move sel_cursor if selection -
1120 // the text's sel_cursor is moved if there is selection is progress
1121 //
1122 // fitcursor -
1123 // fitCursor() is called and the scrollbar updated
1124 //
1125 // mark dirty -
1126 // the buffer is marked dirty.
1127 //
1128 // enum {
1129 //       UPDATE = 0,
1130 //       SELECT = 1,
1131 //       FITCUR = 2,
1132 //       CHANGE = 4 
1133 // };
1134 //
1135 // UPDATE_ONLY = UPDATE;
1136 // UPDATE_SELECT = UPDATE | SELECT;
1137 // UPDATE_SELECT_MOVE = UPDATE | SELECT | FITCUR;
1138 // UPDATE_SELECT_MOVE_AFTER_CHANGE = UPDATE | SELECT | FITCUR | CHANGE;
1139 //
1140 // update(-3) -> update(0)         -> update(0) -> update(UPDATE)
1141 // update(-2) -> update(1 + 2)     -> update(3) -> update(SELECT|FITCUR)
1142 // update(-1) -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1143 // update(1)  -> update(1 + 2 + 4) -> update(7) -> update(SELECT|FITCUR|CHANGE)
1144 // update(3)  -> update(1)         -> update(1) -> update(SELECT)
1145 void BufferView::Pimpl::update(signed char f)
1146 {
1147 #if 1
1148         owner_->updateLayoutChoice();
1149
1150         if (!bv_->text->selection && f > -3)
1151                 bv_->text->sel_cursor = bv_->text->cursor;
1152         
1153         FreeUpdateTimer();
1154         bv_->text->FullRebreak();
1155
1156         update();
1157
1158         if (f != 3 && f != -3) {
1159                 fitCursor();
1160                 //updateScrollbar();
1161         }
1162
1163         if (f == 1 || f == -1) {
1164                 if (buffer_->isLyxClean()) {
1165                         buffer_->markDirty();
1166                         owner_->getMiniBuffer()->setTimer(4);
1167                 } else {
1168                         buffer_->markDirty();
1169                 }
1170         }
1171 #else
1172         owner_->updateLayoutChoice();
1173
1174         if (!bv_->text->selection && (f & SELECT))
1175                 bv_->text->sel_cursor = bv_->text->cursor;
1176         
1177         FreeUpdateTimer();
1178         bv_->text->FullRebreak();
1179
1180         update();
1181
1182         if ((f & FITCUR)) {
1183                 fitCursor();
1184                 //updateScrollbar();
1185         }
1186
1187         if ((f & CHANGE)) {
1188                 if (buffer_->isLyxClean()) {
1189                         buffer_->markDirty();
1190                         owner_->getMiniBuffer()->setTimer(4);
1191                 } else {
1192                         buffer_->markDirty();
1193                 }
1194         }
1195 #endif
1196 }
1197
1198
1199 // Callback for cursor timer
1200 void BufferView::Pimpl::cursorToggle()
1201 {
1202         // Quite a nice place for asyncron Inset updating, isn't it?
1203         // Actually no! This is run even if no buffer exist... so (Lgb)
1204         if (!buffer_) {
1205                 goto set_timer_and_return;
1206         }
1207
1208         // NOTE:
1209         // On my quest to solve the gs render hangups I am now
1210         // disabling the SIGHUP completely, and will do a wait
1211         // now and then instead. If the guess that xforms somehow
1212         // destroys something is true, this is likely (hopefully)
1213         // to solve the problem...at least I hope so. Lgb
1214
1215         // ...Ok this seems to work...at least it does not make things
1216         // worse so far. However I still see gs processes that hangs.
1217         // I would really like to know _why_ they are hanging. Anyway
1218         // the solution without the SIGCHLD handler seems to be easier
1219         // to debug.
1220
1221         // When attaching gdb to a a running gs that hangs it shows
1222         // that it is waiting for input(?) Is it possible for us to
1223         // provide that input somehow? Or figure what it is expecing
1224         // to read?
1225
1226         // One solution is to, after some time, look if there are some
1227         // old gs processes still running and if there are: kill them
1228         // and re render.
1229
1230         // Another solution is to provide the user an option to rerender
1231         // a picture. This would, for the picture in question, check if
1232         // there is a gs running for it, if so kill it, and start a new
1233         // rendering process.
1234
1235         // these comments posted to lyx@via
1236         {
1237                 int status = 1;
1238                 int pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
1239                 if (pid == -1) // error find out what is wrong
1240                         ; // ignore it for now.
1241                 else if (pid > 0)
1242                         sigchldhandler(pid, &status);
1243         }
1244
1245         updatelist.update(bv_);
1246         
1247         if (!screen) {
1248                 goto set_timer_and_return;
1249         }
1250
1251         if (lyx_focus && work_area_focus) {
1252                 if (!bv_->the_locking_inset) {
1253                         screen->CursorToggle();
1254                 } else {
1255                         bv_->the_locking_inset->
1256                                 ToggleInsetCursor(bv_);
1257                 }
1258                 goto set_timer_and_return;
1259         } else {
1260                 // Make sure that the cursor is visible.
1261                 if (!bv_->the_locking_inset) {
1262                         screen->ShowCursor();
1263                 } else {
1264                         if (!bv_->the_locking_inset->isCursorVisible())
1265                                 bv_->the_locking_inset->
1266                                         ToggleInsetCursor(bv_);
1267                 }
1268                 // This is only run when work_area_focus or lyx_focus is false.
1269                 Window tmpwin;
1270                 int tmp;
1271                 XGetInputFocus(fl_display, &tmpwin, &tmp);
1272                 // Commenting this out, we have not had problems with this
1273                 // for a long time. We will probably work on this code later
1274                 // and we can reenable this debug code then. Now it only
1275                 // anoying when debugging. (Lgb)
1276                 //if (lyxerr.debugging(Debug::INFO)) {
1277                 //      lyxerr << "tmpwin: " << tmpwin
1278                 //             << "\nwindow: " << view->owner_->getForm()->window
1279                 //             << "\nwork_area_focus: " << view->work_area_focus
1280                 //             << "\nlyx_focus      : " << view->lyx_focus
1281                 //             << endl;
1282                 //}
1283                 if (tmpwin != owner_->getForm()->window) {
1284                         lyx_focus = false;
1285                         goto skip_timer;
1286                 } else {
1287                         lyx_focus = true;
1288                         if (!work_area_focus)
1289                                 goto skip_timer;
1290                         else
1291                                 goto set_timer_and_return;
1292                 }
1293         }
1294
1295   set_timer_and_return:
1296         fl_set_timer(timer_cursor, 0.4);
1297   skip_timer:
1298         return;
1299 }
1300
1301
1302 void BufferView::Pimpl::cursorPrevious()
1303 {
1304         if (!bv_->text->cursor.row->previous) return;
1305         
1306         long y = screen->first;
1307         Row * cursorrow = bv_->text->cursor.row;
1308         bv_->text->SetCursorFromCoordinates(bv_->text->cursor.x_fix, y);
1309         bv_->text->FinishUndo();
1310         // This is to allow jumping over large insets
1311         if ((cursorrow == bv_->text->cursor.row))
1312                 bv_->text->CursorUp();
1313         
1314         if (bv_->text->cursor.row->height < workarea->height())
1315                 screen->Draw(bv_->text->cursor.y
1316                                   - bv_->text->cursor.row->baseline
1317                                   + bv_->text->cursor.row->height
1318                                   - workarea->height() + 1 );
1319         updateScrollbar();
1320 }
1321
1322
1323 void BufferView::Pimpl::cursorNext()
1324 {
1325         if (!bv_->text->cursor.row->next) return;
1326         
1327         long y = screen->first;
1328         bv_->text->GetRowNearY(y);
1329         Row * cursorrow = bv_->text->cursor.row;
1330         bv_->text->SetCursorFromCoordinates(bv_->text->cursor.x_fix, y
1331                                        + workarea->height());
1332         bv_->text->FinishUndo();
1333         // This is to allow jumping over large insets
1334         if ((cursorrow == bv_->text->cursor.row))
1335                 bv_->text->CursorDown();
1336         
1337         if (bv_->text->cursor.row->height < workarea->height())
1338                 screen->Draw(bv_->text->cursor.y
1339                              - bv_->text->cursor.row->baseline);
1340         updateScrollbar();
1341 }
1342
1343
1344 bool BufferView::Pimpl::available() const
1345 {
1346         if (buffer_ && bv_->text) return true;
1347         return false;
1348 }
1349
1350
1351 void BufferView::Pimpl::beforeChange()
1352 {
1353         toggleSelection();
1354         bv_->text->ClearSelection();
1355         FreeUpdateTimer();
1356 }
1357
1358
1359 void BufferView::Pimpl::savePosition()
1360 {
1361         backstack.push(buffer_->fileName(),
1362                        bv_->text->cursor.x,
1363                        bv_->text->cursor.y);
1364 }
1365
1366
1367 void BufferView::Pimpl::restorePosition()
1368 {
1369         if (backstack.empty()) return;
1370         
1371         int  x, y;
1372         string fname = backstack.pop(&x, &y);
1373         
1374         beforeChange();
1375         Buffer * b = bufferlist.exists(fname) ?
1376                 bufferlist.getBuffer(fname) :
1377                 bufferlist.loadLyXFile(fname); // don't ask, just load it
1378         buffer(b);
1379         bv_->text->SetCursorFromCoordinates(x, y);
1380         update(0);
1381
1382
1383
1384 void BufferView::Pimpl::setState()
1385 {
1386         if (!lyxrc.rtl_support)
1387                 return;
1388
1389         if (bv_->text->real_current_font.isRightToLeft() &&
1390             bv_->text->real_current_font.latex() != LyXFont::ON) {
1391                 if (owner_->getIntl()->primarykeymap)
1392                         owner_->getIntl()->KeyMapSec();
1393         } else {
1394                 if (!owner_->getIntl()->primarykeymap)
1395                         owner_->getIntl()->KeyMapPrim();
1396         }
1397 }
1398
1399
1400 void BufferView::Pimpl::insetSleep()
1401 {
1402         if (bv_->the_locking_inset && !bv_->inset_slept) {
1403                 bv_->the_locking_inset->GetCursorPos(bv_->slx, bv_->sly);
1404                 bv_->the_locking_inset->InsetUnlock(bv_);
1405                 bv_->inset_slept = true;
1406         }
1407 }
1408
1409
1410 void BufferView::Pimpl::insetWakeup()
1411 {
1412         if (bv_->the_locking_inset && bv_->inset_slept) {
1413                 bv_->the_locking_inset->Edit(bv_, bv_->slx, bv_->sly, 0);
1414                 bv_->inset_slept = false;
1415         }
1416 }
1417
1418
1419 void BufferView::Pimpl::insetUnlock()
1420 {
1421         if (bv_->the_locking_inset) {
1422                 if (!bv_->inset_slept) bv_->the_locking_inset->InsetUnlock(bv_);
1423                 bv_->the_locking_inset = 0;
1424                 bv_->text->FinishUndo();
1425                 bv_->inset_slept = false;
1426         }
1427 }
1428
1429
1430 bool BufferView::Pimpl::focus() const
1431 {
1432         return workarea->hasFocus();
1433 }
1434
1435
1436 void BufferView::Pimpl::focus(bool f)
1437 {
1438         if (f) workarea->setFocus();
1439 }
1440
1441
1442 bool BufferView::Pimpl::active() const
1443 {
1444         return workarea->active();
1445 }
1446
1447
1448 bool BufferView::Pimpl::belowMouse() const 
1449 {
1450         return workarea->belowMouse();
1451 }
1452
1453
1454 void BufferView::Pimpl::showCursor()
1455 {
1456         if (screen)
1457                 screen->ShowCursor();
1458 }
1459
1460
1461 void BufferView::Pimpl::hideCursor()
1462 {
1463         if (screen)
1464                 screen->HideCursor();
1465 }
1466
1467
1468 void BufferView::Pimpl::toggleSelection(bool b)
1469 {
1470         if (screen)
1471                 screen->ToggleSelection(b);
1472 }
1473
1474
1475 void BufferView::Pimpl::toggleToggle()
1476 {
1477         if (screen)
1478                 screen->ToggleToggle();
1479 }
1480
1481
1482 void BufferView::Pimpl::center() 
1483 {
1484         beforeChange();
1485         if (bv_->text->cursor.y > workarea->height() / 2) {
1486                 screen->Draw(bv_->text->cursor.y - workarea->height() / 2);
1487         } else {
1488                 screen->Draw(0);
1489         }
1490         update(0);
1491         redraw();
1492 }
1493
1494
1495 #ifdef XFORMS_CLIPBOARD
1496 void BufferView::Pimpl::pasteSelection(bool asPara) 
1497 {
1498         if (buffer_ == 0) return;
1499
1500         screen->HideCursor();
1501         bv_->beforeChange();
1502         
1503         string clip(workarea->getClipboard());
1504         
1505         if (clip.empty()) return;
1506
1507         if (asPara) {
1508                 bv_->text->InsertStringB(clip);
1509         } else {
1510                 bv_->text->InsertStringA(clip);
1511         }
1512         update(1);
1513 }
1514 #endif