diff --git a/ChangeLog b/ChangeLog index 9dedecb127..c97732eead 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2000-05-20 Lars Gullik Bjønnes + + * src/BufferView.C (pasteSelection): new method + + * src/BufferView_pimpl.C (pasteSelection): new method + + * src/lyxfunc.C (Dispatch): use the new clipboard functions. + + * src/WorkArea.C (request_clipboard_cb): new static function + (getClipboard): new method + (putClipboard): new method + 2000-05-19 Lars Gullik Bjønnes * LyX 1.1.5pre2 released diff --git a/src/BufferView.C b/src/BufferView.C index 2425f7ce15..bfe5dc237b 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -193,10 +193,12 @@ void BufferView::cursorToggleCB(FL_OBJECT * ob, long ) } +#ifndef XFORMS_CLIPBOARD void BufferView::workAreaSelectionNotify(Window win, XEvent * event) { pimpl_->workAreaSelectionNotify(win, event); } +#endif void BufferView::cursorPrevious() @@ -323,3 +325,11 @@ void BufferView::center() { pimpl_->center(); } + + +#ifdef XFORMS_CLIPBOARD +void BufferView::pasteSelection(bool asPara) +{ + pimpl_->pasteSelection(asPara); +} +#endif diff --git a/src/BufferView.h b/src/BufferView.h index 1584f02f8e..9c16d916e1 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -24,6 +24,8 @@ class LyXText; class TeXErrors; class Buffer; +#define XFORMS_CLIPBOARD 1 + /// class BufferView { public: @@ -216,10 +218,16 @@ public: void enterView(); /// void leaveView(); +#ifndef XFORMS_CLIPBOARD /// void workAreaSelectionNotify(Window win, XEvent * event); +#endif /// bool ChangeRefs(string const & from, string const & to); +#ifdef XFORMS_CLIPBOARD + /// + void pasteSelection(bool asPara); +#endif private: struct Pimpl; Pimpl * pimpl_; diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 92e5d40fc1..b28da354b1 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -26,8 +26,10 @@ #include "lyxrc.h" #include "intl.h" #include "support/LAssert.h" + using std::pair; using std::endl; +using std::vector; /* the selection possible is needed, that only motion events are * used, where the bottom press event was on the drawing area too */ @@ -1021,6 +1023,7 @@ void BufferView::Pimpl::workAreaExpose() } +#ifndef XFORMS_CLIPBOARD static string fromClipboard(Window win, XEvent * event) { @@ -1094,6 +1097,7 @@ void BufferView::Pimpl::workAreaSelectionNotify(Window win, XEvent * event) update(1); } } +#endif void BufferView::Pimpl::update() @@ -1486,3 +1490,25 @@ void BufferView::Pimpl::center() update(0); redraw(); } + + +#ifdef XFORMS_CLIPBOARD +void BufferView::Pimpl::pasteSelection(bool asPara) +{ + if (buffer_ == 0) return; + + screen->HideCursor(); + bv_->beforeChange(); + + string clip(workarea->getClipboard()); + + if (clip.empty()) return; + + if (asPara) { + bv_->text->InsertStringB(clip); + } else { + bv_->text->InsertStringA(clip); + } + update(1); +} +#endif diff --git a/src/BufferView_pimpl.h b/src/BufferView_pimpl.h index 7dbea91630..5049d0851f 100644 --- a/src/BufferView_pimpl.h +++ b/src/BufferView_pimpl.h @@ -62,8 +62,10 @@ struct BufferView::Pimpl { void workAreaButtonPress(int x, int y, unsigned int button); /// void workAreaButtonRelease(int x, int y, unsigned int button); +#ifndef XFORMS_CLIPBOARD /// void workAreaSelectionNotify(Window win, XEvent * event); +#endif /// void doubleClick(int x, int y, unsigned int button); /// @@ -138,6 +140,10 @@ struct BufferView::Pimpl { WorkArea * workarea; /// UpdateInset updatelist; +#ifdef XFORMS_CLIPBOARD + /// + void pasteSelection(bool asPara); +#endif private: bool using_xterm_cursor; }; diff --git a/src/WorkArea.C b/src/WorkArea.C index 1fd3006829..1e6604ff1a 100644 --- a/src/WorkArea.C +++ b/src/WorkArea.C @@ -344,10 +344,12 @@ int WorkArea::work_area_handler(FL_OBJECT * ob, int event, break; case FL_OTHER: if (!ev) break; +#ifndef XFORMS_CLIPBOARD if (ev->type == SelectionNotify) { lyxerr.debug() << "Workarea event: SELECTION" << endl; area->owner->workAreaSelectionNotify(area->work_area->form->window, ev); } else +#endif lyxerr.debug() << "Workarea event: OTHER" << endl; break; @@ -355,3 +357,52 @@ int WorkArea::work_area_handler(FL_OBJECT * ob, int event, return 1; } + + +#ifdef XFORMS_CLIPBOARD +static string clipboard_selection; +static bool clipboard_read = false; + +static +int request_clipboard_cb(FL_OBJECT * /*ob*/, long /*type*/, + void const * data, long size) +{ + clipboard_selection.erase(); + if (size == 0) return 0; // no selection + + clipboard_selection.reserve(size); + for (int i = 0; i < size; ++i) { + clipboard_selection.push_back(static_cast(data)[i]); + } + clipboard_read = true; + return 0; +} + + +string WorkArea::getClipboard() const +{ + clipboard_read = false; + + if (fl_request_clipboard(work_area, 0, request_clipboard_cb) == -1) + return string(); + + XEvent ev; + + while (!clipboard_read) { + if (fl_check_forms() == FL_EVENT) { + lyxerr << "LyX: This shouldn't happen..." << endl; + fl_XNextEvent(&ev); + } + } + return clipboard_selection; +} + + +void WorkArea::putClipboard(string const & s) const +{ + static string hold; + hold = s; + + fl_stuff_clipboard(work_area, 0, hold.c_str(), hold.size(), 0); +} +#endif diff --git a/src/WorkArea.h b/src/WorkArea.h index 4d9f7a1690..3be02d3625 100644 --- a/src/WorkArea.h +++ b/src/WorkArea.h @@ -23,6 +23,8 @@ class BufferView; +#define XFORMS_CLIPBOARD 1 + class WorkArea { public: /// @@ -90,6 +92,12 @@ public: int /*key*/, void * xev); /// xforms callback static void scroll_cb(FL_OBJECT *, long); +#ifdef XFORMS_CLIPBOARD + /// + string getClipboard() const; + /// + void putClipboard(string const &) const; +#endif private: /// void createPixmap(int, int); diff --git a/src/lyx_cb.C b/src/lyx_cb.C index f51570f0fd..ccc8ce3ca2 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -77,6 +77,8 @@ extern FD_form_ref * fd_form_ref; extern FD_LaTeXOptions * fd_latex_options; extern FD_form_bullet * fd_form_bullet; +#define XFORMS_CLIPBOARD 1 + extern BufferView * current_view; // called too many times in this file... extern void DeleteSimpleCutBuffer(); /* for the cleanup when exiting */ @@ -1222,11 +1224,11 @@ void MenuInsertRef() } +#ifndef XFORMS_CLIPBOARD void MenuPasteSelection(char at) { if (!current_view->available()) return; - ascii_type = at; Atom data_prop = XInternAtom(fl_display, @@ -1238,8 +1240,9 @@ void MenuPasteSelection(char at) XA_PRIMARY, XA_STRING, data_prop, current_view->owner()->getForm()->window, 0); XFlush(fl_display); -} +} +#endif diff --git a/src/lyxfunc.C b/src/lyxfunc.C index ba13ea8b52..cad7b6ac4c 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -107,7 +107,13 @@ extern void MenuSendto(); extern void QuitLyX(); extern void MenuFax(Buffer *); extern void MenuExport(Buffer *, string const &); + +#define XFORMS_CLIPBOARD 1 + +#ifndef XFORMS_CLIPBOARD extern void MenuPasteSelection(char at); +#endif + extern LyXAction lyxaction; // (alkis) extern tex_accent_struct get_accent(kb_action action); @@ -890,8 +896,7 @@ string LyXFunc::Dispatch(int ac, static LyXFindReplace FR_; FR_.StartSearch(owner->view()); } - - break; + break; case LFUN_PASTE: owner->view()->paste(); @@ -902,10 +907,14 @@ string LyXFunc::Dispatch(int ac, { bool asPara = false; if (argument == "paragraph") asPara = true; +#ifdef XFORMS_CLIPBOARD + owner->view()->pasteSelection(asPara); +#else MenuPasteSelection(asPara); - break; +#endif } - + break; + case LFUN_CUT: owner->view()->cut(); break;