]> git.lyx.org Git - features.git/commitdiff
some new clipboard code
authorLars Gullik Bjønnes <larsbj@gullik.org>
Sat, 20 May 2000 01:38:25 +0000 (01:38 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Sat, 20 May 2000 01:38:25 +0000 (01:38 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@752 a592a061-630c-0410-9148-cb99ea01b6c8

ChangeLog
src/BufferView.C
src/BufferView.h
src/BufferView_pimpl.C
src/BufferView_pimpl.h
src/WorkArea.C
src/WorkArea.h
src/lyx_cb.C
src/lyxfunc.C

index 9dedecb12778319c79ba3bd73cb20d4039084daf..c97732eeadd3553cd239a9c186fc2e5a3bf248e2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2000-05-20  Lars Gullik Bjønnes  <larsbj@lyx.org>
+
+       * 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  <larsbj@lyx.org>
 
        * LyX 1.1.5pre2 released
index 2425f7ce1593d5e0f0c65b47095641241cdf482a..bfe5dc237b9f02d9af0200f66733648179031b72 100644 (file)
@@ -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
index 1584f02f8eb777ad65f0b40da6904e7d8693585b..9c16d916e1cd5329a2fa74f6087fa89fcb013574 100644 (file)
@@ -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_;
index 92e5d40fc1da1130971e4232f6352c6a1224d7dd..b28da354b1f511140d692034797cd42059799cab 100644 (file)
 #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
index 7dbea916305364e01dd7a9a339312a2bedd96c5f..5049d0851f46204f62b9b5eaa16c060f8aa20d2e 100644 (file)
@@ -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;
 };
index 1fd3006829c4d4b47ca143769155c0d1029fa56d..1e6604ff1a880905f4ece5f7fdafd8ff37f9a5dd 100644 (file)
@@ -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<char*>(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
index 4d9f7a1690e4d46c814e877b2628be28b0349cb7..3be02d3625d7687c1f6e4db31bdda263e01a16c2 100644 (file)
@@ -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);
index f51570f0fd8dd3e8d21ce1322e718c6159fc69e3..ccc8ce3ca2fd74a7ea1c33a6f010ffda370fb3b7 100644 (file)
@@ -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
 
 
 
index ba13ea8b522f024b0201cdf0e62749546b459cc0..cad7b6ac4cf42c2b8917df24426161db8e26aae0 100644 (file)
@@ -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;