some new clipboard code

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@752 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2000-05-20 01:38:25 +00:00
parent 63dbdad67e
commit f007271216
9 changed files with 139 additions and 6 deletions

View File

@ -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> 2000-05-19 Lars Gullik Bjønnes <larsbj@lyx.org>
* LyX 1.1.5pre2 released * LyX 1.1.5pre2 released

View File

@ -193,10 +193,12 @@ void BufferView::cursorToggleCB(FL_OBJECT * ob, long )
} }
#ifndef XFORMS_CLIPBOARD
void BufferView::workAreaSelectionNotify(Window win, XEvent * event) void BufferView::workAreaSelectionNotify(Window win, XEvent * event)
{ {
pimpl_->workAreaSelectionNotify(win, event); pimpl_->workAreaSelectionNotify(win, event);
} }
#endif
void BufferView::cursorPrevious() void BufferView::cursorPrevious()
@ -323,3 +325,11 @@ void BufferView::center()
{ {
pimpl_->center(); pimpl_->center();
} }
#ifdef XFORMS_CLIPBOARD
void BufferView::pasteSelection(bool asPara)
{
pimpl_->pasteSelection(asPara);
}
#endif

View File

@ -24,6 +24,8 @@ class LyXText;
class TeXErrors; class TeXErrors;
class Buffer; class Buffer;
#define XFORMS_CLIPBOARD 1
/// ///
class BufferView { class BufferView {
public: public:
@ -216,10 +218,16 @@ public:
void enterView(); void enterView();
/// ///
void leaveView(); void leaveView();
#ifndef XFORMS_CLIPBOARD
/// ///
void workAreaSelectionNotify(Window win, XEvent * event); void workAreaSelectionNotify(Window win, XEvent * event);
#endif
/// ///
bool ChangeRefs(string const & from, string const & to); bool ChangeRefs(string const & from, string const & to);
#ifdef XFORMS_CLIPBOARD
///
void pasteSelection(bool asPara);
#endif
private: private:
struct Pimpl; struct Pimpl;
Pimpl * pimpl_; Pimpl * pimpl_;

View File

@ -26,8 +26,10 @@
#include "lyxrc.h" #include "lyxrc.h"
#include "intl.h" #include "intl.h"
#include "support/LAssert.h" #include "support/LAssert.h"
using std::pair; using std::pair;
using std::endl; using std::endl;
using std::vector;
/* the selection possible is needed, that only motion events are /* the selection possible is needed, that only motion events are
* used, where the bottom press event was on the drawing area too */ * used, where the bottom press event was on the drawing area too */
@ -1021,6 +1023,7 @@ void BufferView::Pimpl::workAreaExpose()
} }
#ifndef XFORMS_CLIPBOARD
static static
string fromClipboard(Window win, XEvent * event) string fromClipboard(Window win, XEvent * event)
{ {
@ -1094,6 +1097,7 @@ void BufferView::Pimpl::workAreaSelectionNotify(Window win, XEvent * event)
update(1); update(1);
} }
} }
#endif
void BufferView::Pimpl::update() void BufferView::Pimpl::update()
@ -1486,3 +1490,25 @@ void BufferView::Pimpl::center()
update(0); update(0);
redraw(); 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

View File

@ -62,8 +62,10 @@ struct BufferView::Pimpl {
void workAreaButtonPress(int x, int y, unsigned int button); void workAreaButtonPress(int x, int y, unsigned int button);
/// ///
void workAreaButtonRelease(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); void workAreaSelectionNotify(Window win, XEvent * event);
#endif
/// ///
void doubleClick(int x, int y, unsigned int button); void doubleClick(int x, int y, unsigned int button);
/// ///
@ -138,6 +140,10 @@ struct BufferView::Pimpl {
WorkArea * workarea; WorkArea * workarea;
/// ///
UpdateInset updatelist; UpdateInset updatelist;
#ifdef XFORMS_CLIPBOARD
///
void pasteSelection(bool asPara);
#endif
private: private:
bool using_xterm_cursor; bool using_xterm_cursor;
}; };

View File

@ -344,10 +344,12 @@ int WorkArea::work_area_handler(FL_OBJECT * ob, int event,
break; break;
case FL_OTHER: case FL_OTHER:
if (!ev) break; if (!ev) break;
#ifndef XFORMS_CLIPBOARD
if (ev->type == SelectionNotify) { if (ev->type == SelectionNotify) {
lyxerr.debug() << "Workarea event: SELECTION" << endl; lyxerr.debug() << "Workarea event: SELECTION" << endl;
area->owner->workAreaSelectionNotify(area->work_area->form->window, ev); area->owner->workAreaSelectionNotify(area->work_area->form->window, ev);
} else } else
#endif
lyxerr.debug() << "Workarea event: OTHER" << endl; lyxerr.debug() << "Workarea event: OTHER" << endl;
break; break;
@ -355,3 +357,52 @@ int WorkArea::work_area_handler(FL_OBJECT * ob, int event,
return 1; 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

View File

@ -23,6 +23,8 @@
class BufferView; class BufferView;
#define XFORMS_CLIPBOARD 1
class WorkArea { class WorkArea {
public: public:
/// ///
@ -90,6 +92,12 @@ public:
int /*key*/, void * xev); int /*key*/, void * xev);
/// xforms callback /// xforms callback
static void scroll_cb(FL_OBJECT *, long); static void scroll_cb(FL_OBJECT *, long);
#ifdef XFORMS_CLIPBOARD
///
string getClipboard() const;
///
void putClipboard(string const &) const;
#endif
private: private:
/// ///
void createPixmap(int, int); void createPixmap(int, int);

View File

@ -77,6 +77,8 @@ extern FD_form_ref * fd_form_ref;
extern FD_LaTeXOptions * fd_latex_options; extern FD_LaTeXOptions * fd_latex_options;
extern FD_form_bullet * fd_form_bullet; extern FD_form_bullet * fd_form_bullet;
#define XFORMS_CLIPBOARD 1
extern BufferView * current_view; // called too many times in this file... extern BufferView * current_view; // called too many times in this file...
extern void DeleteSimpleCutBuffer(); /* for the cleanup when exiting */ extern void DeleteSimpleCutBuffer(); /* for the cleanup when exiting */
@ -1222,11 +1224,11 @@ void MenuInsertRef()
} }
#ifndef XFORMS_CLIPBOARD
void MenuPasteSelection(char at) void MenuPasteSelection(char at)
{ {
if (!current_view->available()) if (!current_view->available())
return; return;
ascii_type = at; ascii_type = at;
Atom data_prop = XInternAtom(fl_display, Atom data_prop = XInternAtom(fl_display,
@ -1238,8 +1240,9 @@ void MenuPasteSelection(char at)
XA_PRIMARY, XA_STRING, data_prop, XA_PRIMARY, XA_STRING, data_prop,
current_view->owner()->getForm()->window, 0); current_view->owner()->getForm()->window, 0);
XFlush(fl_display); XFlush(fl_display);
}
}
#endif

View File

@ -107,7 +107,13 @@ extern void MenuSendto();
extern void QuitLyX(); extern void QuitLyX();
extern void MenuFax(Buffer *); extern void MenuFax(Buffer *);
extern void MenuExport(Buffer *, string const &); extern void MenuExport(Buffer *, string const &);
#define XFORMS_CLIPBOARD 1
#ifndef XFORMS_CLIPBOARD
extern void MenuPasteSelection(char at); extern void MenuPasteSelection(char at);
#endif
extern LyXAction lyxaction; extern LyXAction lyxaction;
// (alkis) // (alkis)
extern tex_accent_struct get_accent(kb_action action); extern tex_accent_struct get_accent(kb_action action);
@ -890,7 +896,6 @@ string LyXFunc::Dispatch(int ac,
static LyXFindReplace FR_; static LyXFindReplace FR_;
FR_.StartSearch(owner->view()); FR_.StartSearch(owner->view());
} }
break; break;
case LFUN_PASTE: case LFUN_PASTE:
@ -902,9 +907,13 @@ string LyXFunc::Dispatch(int ac,
{ {
bool asPara = false; bool asPara = false;
if (argument == "paragraph") asPara = true; if (argument == "paragraph") asPara = true;
#ifdef XFORMS_CLIPBOARD
owner->view()->pasteSelection(asPara);
#else
MenuPasteSelection(asPara); MenuPasteSelection(asPara);
break; #endif
} }
break;
case LFUN_CUT: case LFUN_CUT:
owner->view()->cut(); owner->view()->cut();