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>
* 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)
{
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

View 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_;

View File

@ -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

View 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;
};

View 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

View 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);

View 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

View 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,7 +896,6 @@ string LyXFunc::Dispatch(int ac,
static LyXFindReplace FR_;
FR_.StartSearch(owner->view());
}
break;
case LFUN_PASTE:
@ -902,9 +907,13 @@ 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();