Set the basics of the copy/cut/paste on X11 ==> not ended
This commit is contained in:
parent
ce89a71068
commit
ee1e9a5834
108
Sources/libewol/ewol/ClipBoard.cpp
Normal file
108
Sources/libewol/ewol/ClipBoard.cpp
Normal file
@ -0,0 +1,108 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file ClipBoard.cpp
|
||||
* @brief ewol : copy / past main system (sources)
|
||||
* @author Edouard DUPIN
|
||||
* @date 04/04/2012
|
||||
* @par Project
|
||||
* ewol
|
||||
*
|
||||
* @par Copyright
|
||||
* Copyright 2011 Edouard DUPIN, all right reserved
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY.
|
||||
*
|
||||
* Licence summary :
|
||||
* You can modify and redistribute the sources code and binaries.
|
||||
* You can send me the bug-fix
|
||||
*
|
||||
* Term of the licence in in the file licence.txt.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#include <ewol/Debug.h>
|
||||
#include <ewol/ClipBoard.h>
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "ClipBoard"
|
||||
|
||||
|
||||
/*
|
||||
note: la copy dans le :
|
||||
0 : copy standard
|
||||
[1..9] : copy interne
|
||||
10 : bouton du milieux
|
||||
*/
|
||||
static etk::UString mesCopy[ewol::clipBoard::TOTAL_OF_CLICKBOARD];
|
||||
|
||||
|
||||
void ewol::clipBoard::Init(void)
|
||||
{
|
||||
EWOL_INFO("Initialyse ClipBoards");
|
||||
for(int32_t i=0; i<ewol::clipBoard::TOTAL_OF_CLICKBOARD; i++) {
|
||||
mesCopy[i].Clear();
|
||||
}
|
||||
}
|
||||
|
||||
void ewol::clipBoard::UnInit(void)
|
||||
{
|
||||
EWOL_INFO("Initialyse ClipBoards");
|
||||
for(int32_t i=0; i<ewol::clipBoard::TOTAL_OF_CLICKBOARD; i++) {
|
||||
mesCopy[i].Clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ewol::clipBoard::Set(uint8_t clipboardID, etk::UString &data)
|
||||
{
|
||||
// check if ID is correct
|
||||
if(clipboardID >= ewol::clipBoard::TOTAL_OF_CLICKBOARD) {
|
||||
EWOL_WARNING("request ClickBoard id error");
|
||||
} else if(0 == data.Size()) {
|
||||
EWOL_INFO("request a copy of nothing");
|
||||
} else if (ewol::clipBoard::CLIPBOARD_STD == clipboardID) {
|
||||
//GtkClipboard * clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
|
||||
//gtk_clipboard_set_text(clipboard, (const gchar*)&data[0], data.Size() );
|
||||
} else if (ewol::clipBoard::CLIPBOARD_SELECTION == clipboardID) {
|
||||
//GtkClipboard * clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
|
||||
//gtk_clipboard_set_text(clipboard, (const gchar*)&data[0], data.Size() );
|
||||
}
|
||||
// Copy datas ...
|
||||
mesCopy[clipboardID] = data;
|
||||
}
|
||||
|
||||
|
||||
void ewol::clipBoard::Get(uint8_t clipboardID, etk::UString &data)
|
||||
{
|
||||
if(clipboardID >= ewol::clipBoard::TOTAL_OF_CLICKBOARD) {
|
||||
EWOL_WARNING("request ClickBoard id error");
|
||||
} else if (ewol::clipBoard::CLIPBOARD_STD == clipboardID) {
|
||||
/*
|
||||
GtkClipboard * clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD );
|
||||
gchar *text = gtk_clipboard_wait_for_text(clipboard);
|
||||
if (text != NULL) {
|
||||
mesCopy[COPY_STD].Clear();
|
||||
mesCopy[COPY_STD].PushBack((int8_t*)text, strlen(text) );
|
||||
}
|
||||
*/
|
||||
} else if (ewol::clipBoard::CLIPBOARD_SELECTION == clipboardID) {
|
||||
/*
|
||||
GtkClipboard * clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY );
|
||||
gchar *text = gtk_clipboard_wait_for_text(clipboard);
|
||||
if (text != NULL) {
|
||||
mesCopy[COPY_MIDDLE_BUTTON].Clear();
|
||||
mesCopy[COPY_MIDDLE_BUTTON].PushBack((int8_t*)text, strlen(text) );
|
||||
}
|
||||
*/
|
||||
}
|
||||
// Copy datas ...
|
||||
data = mesCopy[clipboardID];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
58
Sources/libewol/ewol/ClipBoard.h
Normal file
58
Sources/libewol/ewol/ClipBoard.h
Normal file
@ -0,0 +1,58 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file ClipBoard.h
|
||||
* @brief ewol : copy / past main system (header)
|
||||
* @author Edouard DUPIN
|
||||
* @date 04/04/2012
|
||||
* @par Project
|
||||
* ewol
|
||||
*
|
||||
* @par Copyright
|
||||
* Copyright 2011 Edouard DUPIN, all right reserved
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY.
|
||||
*
|
||||
* Licence summary :
|
||||
* You can modify and redistribute the sources code and binaries.
|
||||
* You can send me the bug-fix
|
||||
*
|
||||
* Term of the licence in in the file licence.txt.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __EWOL_CLIPBOARD_H__
|
||||
#define __EWOL_CLIPBOARD_H__
|
||||
|
||||
#include <ewol/Debug.h>
|
||||
#include <etk/UString.h>
|
||||
|
||||
|
||||
namespace ewol {
|
||||
namespace clipBoard
|
||||
{
|
||||
enum {
|
||||
CLIPBOARD_STD,
|
||||
CLIPBOARD_1,
|
||||
CLIPBOARD_2,
|
||||
CLIPBOARD_3,
|
||||
CLIPBOARD_4,
|
||||
CLIPBOARD_5,
|
||||
CLIPBOARD_6,
|
||||
CLIPBOARD_7,
|
||||
CLIPBOARD_8,
|
||||
CLIPBOARD_9,
|
||||
CLIPBOARD_SELECTION,
|
||||
TOTAL_OF_CLICKBOARD,
|
||||
};
|
||||
void Init(void);
|
||||
void UnInit(void);
|
||||
void Set(uint8_t clipboardID, etk::UString &data);
|
||||
void Get(uint8_t clipboardID, etk::UString &data);
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -26,7 +26,7 @@
|
||||
#include <ewol/widget/Joystick.h>
|
||||
#include <ewol/widget/Button.h>
|
||||
#include <ewol/widget/ButtonColor.h>
|
||||
#include <ewol/widget/Scene.h>
|
||||
//#include <ewol/widget/Scene.h>
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "WidgetManager"
|
||||
@ -51,7 +51,7 @@ void ewol::widgetManager::Init(void)
|
||||
ewol::WIDGET_JoystickInit();
|
||||
ewol::WIDGET_ButtonInit();
|
||||
ewol::WIDGET_ButtonColorInit();
|
||||
ewol::WIDGET_SceneInit();
|
||||
//ewol::WIDGET_SceneInit();
|
||||
IsInit = true;
|
||||
}
|
||||
|
||||
|
@ -47,6 +47,14 @@ namespace guiAbstraction
|
||||
void ForceRedrawAll(void);
|
||||
void SendKeyboardEvent(bool isDown, uniChar_t keyInput);
|
||||
void SendKeyboardEventMove(bool isDown, ewol::eventKbMoveType_te &keyInput);
|
||||
|
||||
// copy and cut generic properties :
|
||||
typedef enum {
|
||||
CLIPBOARD_MODE_PRIMARY,
|
||||
CLIPBOARD_MODE_STD,
|
||||
} clipBoardMode_te;
|
||||
void ClipBoardGet(etk::UString& newData, clipBoardMode_te mode);
|
||||
void ClipBoardSet(etk::UString& newData, clipBoardMode_te mode);
|
||||
};
|
||||
|
||||
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include <sys/times.h>
|
||||
|
||||
|
||||
|
||||
int64_t GetCurrentTime(void)
|
||||
{
|
||||
struct timespec now;
|
||||
@ -124,6 +125,17 @@ int32_t offsetMoveClickedDouble = 20;
|
||||
|
||||
bool inputIsPressed[20];
|
||||
|
||||
// internal copy of the clipBoard ...
|
||||
static etk::UString l_clipBoardPrimary("");
|
||||
static etk::UString l_clipBoardStd("");
|
||||
// Atom access...
|
||||
static Atom XAtomeSelection = 0;
|
||||
static Atom XAtomeClipBoard = 0;
|
||||
static Atom XAtomeTargetString = 0;
|
||||
static Atom XAtomeTargetStringUTF8 = 0;
|
||||
static Atom XAtomeTargetTarget = 0;
|
||||
static Atom XAtomeEWOL = 0;
|
||||
|
||||
|
||||
static void X11_ChangeSize(int32_t w, int32_t h);
|
||||
static void X11_ChangePos(int32_t x, int32_t y);
|
||||
@ -421,6 +433,17 @@ void X11_Init(void)
|
||||
}
|
||||
CreateX11Context();
|
||||
CreateOGlContext();
|
||||
// reset clipBoard
|
||||
l_clipBoardPrimary = "";
|
||||
l_clipBoardStd = "";
|
||||
// reset the Atom properties ...
|
||||
XAtomeSelection = XInternAtom(m_display, "PRIMARY", 0);
|
||||
XAtomeClipBoard = XInternAtom(m_display, "CLIPBOARD", 0);
|
||||
XAtomeTargetString = XInternAtom(m_display, "STRING", 0);
|
||||
XAtomeTargetStringUTF8 = XInternAtom(m_display, "UTF8_STRING", 0);
|
||||
XAtomeTargetTarget = XInternAtom(m_display, "TARGETS", 0);
|
||||
XAtomeEWOL = XInternAtom(m_display, "EWOL", 0);
|
||||
|
||||
m_run = true;
|
||||
}
|
||||
|
||||
@ -431,6 +454,7 @@ void X11_Run(void)
|
||||
while(true == m_run) {
|
||||
//EWOL_ERROR("plop1");
|
||||
XEvent event;
|
||||
XEvent respond;
|
||||
// main X boucle :
|
||||
while (XPending(m_display)) {
|
||||
//EWOL_ERROR("plop 22222");
|
||||
@ -449,6 +473,114 @@ void X11_Run(void)
|
||||
}
|
||||
}
|
||||
break;
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Selection AREA //
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
case SelectionClear:
|
||||
// Selection has been done on an other program ==> clear ours ...
|
||||
EWOL_DEBUG("X11 event SelectionClear");
|
||||
{
|
||||
XSelectionRequestEvent *req=&(event.xselectionrequest);
|
||||
EWOL_DEBUG(" property: \"" << XGetAtomName(m_display, req->property) << "\"");
|
||||
EWOL_DEBUG(" target: \"" << XGetAtomName(m_display, req->target) << "\"");
|
||||
}
|
||||
break;
|
||||
case SelectionNotify:
|
||||
EWOL_DEBUG("X11 event SelectionNotify");
|
||||
if (event.xselection.property == None) {
|
||||
EWOL_DEBUG(" ==> no data ...");
|
||||
} else {
|
||||
unsigned char *buf = 0;
|
||||
Atom type;
|
||||
int format;
|
||||
unsigned long nitems, bytes;
|
||||
XGetWindowProperty(m_display,
|
||||
WindowHandle,
|
||||
event.xselection.property,
|
||||
0, // offset
|
||||
(~0L), // length
|
||||
False, // delete
|
||||
AnyPropertyType, // reg_type
|
||||
&type,// *actual_type_return,
|
||||
&format,// *actual_format_return
|
||||
&nitems,// *nitems_return
|
||||
&bytes, // *bytes_after_return
|
||||
&buf// **prop_return);
|
||||
);
|
||||
EWOL_DEBUG(" ==> data : " << buf);
|
||||
}
|
||||
break;
|
||||
case SelectionRequest:
|
||||
EWOL_DEBUG("X11 event SelectionRequest");
|
||||
{
|
||||
XSelectionRequestEvent *req=&(event.xselectionrequest);
|
||||
EWOL_DEBUG(" from: " << XGetAtomName(m_display, req->property) << " request=" << XGetAtomName(m_display, req->selection) << " in " << XGetAtomName(m_display, req->target));
|
||||
const char * magatTextToSend = NULL;
|
||||
|
||||
if (req->selection == XAtomeSelection) {
|
||||
magatTextToSend = l_clipBoardPrimary.Utf8Data();
|
||||
} else if (req->selection == XAtomeClipBoard) {
|
||||
magatTextToSend = l_clipBoardStd.Utf8Data();
|
||||
} else {
|
||||
magatTextToSend = "";
|
||||
}
|
||||
|
||||
Atom listOfAtom[4];
|
||||
if(strlen(magatTextToSend) == 0 ) {
|
||||
respond.xselection.property= None;
|
||||
} else if(XAtomeTargetTarget == req->target) {
|
||||
// We need to generate the list of the possibles target element of atom
|
||||
int32_t nbAtomSupported = 0;
|
||||
listOfAtom[nbAtomSupported++] = XAtomeTargetTarget;
|
||||
listOfAtom[nbAtomSupported++] = XAtomeTargetString;
|
||||
listOfAtom[nbAtomSupported++] = XAtomeTargetStringUTF8;
|
||||
listOfAtom[nbAtomSupported++] = None;
|
||||
XChangeProperty( m_display,
|
||||
req->requestor,
|
||||
req->property,
|
||||
XA_ATOM,
|
||||
32,
|
||||
PropModeReplace,
|
||||
(unsigned char*)listOfAtom,
|
||||
nbAtomSupported );
|
||||
respond.xselection.property=req->property;
|
||||
EWOL_VERBOSE(" ==> Respond ... (test)");
|
||||
} else if(XAtomeTargetString == req->target) {
|
||||
XChangeProperty( m_display,
|
||||
req->requestor,
|
||||
req->property,
|
||||
req->target,
|
||||
8,
|
||||
PropModeReplace,
|
||||
(unsigned char*)magatTextToSend,
|
||||
strlen(magatTextToSend));
|
||||
respond.xselection.property=req->property;
|
||||
EWOL_VERBOSE(" ==> Respond ...");
|
||||
} else if (XAtomeTargetStringUTF8 == req->target) {
|
||||
XChangeProperty( m_display,
|
||||
req->requestor,
|
||||
req->property,
|
||||
req->target,
|
||||
8,
|
||||
PropModeReplace,
|
||||
(unsigned char*)magatTextToSend,
|
||||
strlen(magatTextToSend));
|
||||
respond.xselection.property=req->property;
|
||||
EWOL_VERBOSE(" ==> Respond ...");
|
||||
} else {
|
||||
respond.xselection.property= None;
|
||||
}
|
||||
respond.xselection.type= SelectionNotify;
|
||||
respond.xselection.display= req->display;
|
||||
respond.xselection.requestor= req->requestor;
|
||||
respond.xselection.selection=req->selection;
|
||||
respond.xselection.target= req->target;
|
||||
respond.xselection.time = req->time;
|
||||
XSendEvent (m_display, req->requestor,0,0,&respond);
|
||||
XFlush (m_display);
|
||||
}
|
||||
break;
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
case Expose:
|
||||
EWOL_DEBUG("X11 event Expose");
|
||||
break;
|
||||
@ -746,6 +878,73 @@ void X11_GetAbsPos(int32_t & x, int32_t & y)
|
||||
|
||||
|
||||
|
||||
// ClipBoard AREA :
|
||||
|
||||
void guiAbstraction::ClipBoardGet(etk::UString &newData, clipBoardMode_te mode)
|
||||
{
|
||||
newData = "";
|
||||
switch (mode)
|
||||
{
|
||||
case CLIPBOARD_MODE_PRIMARY:
|
||||
break;
|
||||
case CLIPBOARD_MODE_STD:
|
||||
|
||||
break;
|
||||
default:
|
||||
EWOL_ERROR("Request an unknow ClipBoard ...");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void guiAbstraction::ClipBoardSet(etk::UString &newData, clipBoardMode_te mode)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
case CLIPBOARD_MODE_PRIMARY:
|
||||
if (newData.Size() > 0) {
|
||||
// copy it ...
|
||||
l_clipBoardPrimary = newData;
|
||||
// Request the selection :
|
||||
XSetSelectionOwner(m_display, XAtomeSelection, WindowHandle, CurrentTime);
|
||||
}
|
||||
break;
|
||||
case CLIPBOARD_MODE_STD:
|
||||
if (newData.Size() > 0) {
|
||||
// copy it ...
|
||||
l_clipBoardStd = newData;
|
||||
// Request the clipBoard :
|
||||
XSetSelectionOwner(m_display, XAtomeClipBoard, WindowHandle, CurrentTime);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
EWOL_ERROR("Request an unknow ClipBoard ...");
|
||||
break;
|
||||
}
|
||||
}
|
||||
/*
|
||||
void ewol::clipboard::Copy(etk::UString newData, int32_t bufferId)
|
||||
{
|
||||
char * tmpPointer = newData.Utf8Data();
|
||||
|
||||
Atom selection = XA_PRIMARY;
|
||||
//All your selection are belong to us...
|
||||
XSetSelectionOwner(m_display, selection, WindowHandle, CurrentTime);
|
||||
|
||||
EWOL_DEBUG("--------------------------------------------------------------");
|
||||
if (BadAlloc == XStoreBuffer(m_display, tmpPointer, strlen(tmpPointer), bufferId)) {
|
||||
EWOL_ERROR("Copy error");
|
||||
} else {
|
||||
EWOL_DEBUG("Copy well done : \"" << tmpPointer << "\"=" << strlen(tmpPointer));
|
||||
}
|
||||
if (BadAlloc == XStoreBytes(m_display, tmpPointer, strlen(tmpPointer))) {
|
||||
EWOL_ERROR("Copy error");
|
||||
} else {
|
||||
EWOL_DEBUG("Copy well done");
|
||||
}
|
||||
EWOL_DEBUG("--------------------------------------------------------------");
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#undef __class__
|
||||
|
@ -5,6 +5,7 @@ FILE_LIST = ewol/ewol.cpp \
|
||||
ewol/base/MainThread.cpp \
|
||||
ewol/base/gui.cpp \
|
||||
ewol/base/eventInputManagement.cpp \
|
||||
ewol/ClipBoard.cpp \
|
||||
ewol/Debug.cpp \
|
||||
ewol/EObject.cpp \
|
||||
ewol/EObjectManager.cpp \
|
||||
@ -35,7 +36,6 @@ FILE_LIST = ewol/ewol.cpp \
|
||||
ewol/widget/List.cpp \
|
||||
ewol/widget/Menu.cpp \
|
||||
ewol/widget/PopUp.cpp \
|
||||
ewol/widget/Scene.cpp \
|
||||
ewol/widget/SizerHori.cpp \
|
||||
ewol/widget/SizerVert.cpp \
|
||||
ewol/widget/Slider.cpp \
|
||||
|
Loading…
x
Reference in New Issue
Block a user