Пример #1
0
std::string CClipboard::GetContents() const
{
	std::string contents;
#if defined(__APPLE__) || defined(HEADLESS)
	// Nothing for now
#elif defined(WIN32)
	OpenClipboard(NULL);
	const void* p = GetClipboardData(CF_TEXT);
	if (p != NULL) {
		contents = (char*)p;
	}
	CloseClipboard();
#else
	// only works with the cut-buffer method (xterm)
	// (and not with the more recent selections method)
	SDL_SysWMinfo sdlinfo;
	SDL_VERSION(&sdlinfo.version);
	if (SDL_GetWMInfo(&sdlinfo)) {
		sdlinfo.info.x11.lock_func();
		Display* display = sdlinfo.info.x11.display;
		int count = 0;
		char* msg = XFetchBytes(display, &count);
		if ((msg != NULL) && (count > 0)) {
			contents.append((char*)msg, count);
		}
		XFree(msg);
		sdlinfo.info.x11.unlock_func();
	}
#endif
	return contents;
};
Пример #2
0
const char *Sys_Video_GetClipboardText(void *display)
{
	struct display *d;
	char *xbuf;
	char *buf;
	int len;

	d = display;
	buf = 0;

	xbuf = XFetchBytes(d->x_disp, &len);
	if (xbuf)
	{
		buf = malloc(len+1);
		if (buf)
		{
			memcpy(buf, xbuf, len);
			buf[len] = 0;
		}

		XFree(xbuf);
	}

	return buf;
}
Пример #3
0
static int motTextSetClipboardAttrib(Ihandle *ih, const char *value)
{
  if (iupStrEqualNoCase(value, "COPY"))
  {
    char *str = XmTextGetSelection(ih->handle);
    if (!str) return 0;

    XmTextCopy(ih->handle, CurrentTime);

    /* do it also for the X clipboard */
    XStoreBytes(iupmot_display, str, strlen(str)+1);
    XtFree(str);
  }
  else if (iupStrEqualNoCase(value, "CUT"))
  {
    char *str = XmTextGetSelection(ih->handle);
    if (!str) return 0;

    /* disable callbacks */
    iupAttribSetStr(ih, "_IUPMOT_DISABLE_TEXT_CB", "1");

    XmTextCut(ih->handle, CurrentTime);

    /* do it also for the X clipboard */
    XStoreBytes(iupmot_display, str, strlen(str)+1);
    XtFree(str);
    XmTextRemove(ih->handle);

    iupAttribSetStr(ih, "_IUPMOT_DISABLE_TEXT_CB", NULL);
  }
  else if (iupStrEqualNoCase(value, "PASTE"))
  {
    int size;
    char* str = XFetchBytes(iupmot_display, &size);
    if (!str) return 0;

    /* disable callbacks */
    iupAttribSetStr(ih, "_IUPMOT_DISABLE_TEXT_CB", "1");

    XmTextPaste(ih->handle); /* TODO: this could force 2 pastes, check in CDE */

    /* do it also for the X clipboard */
    XmTextRemove(ih->handle);
    XmTextInsert(ih->handle, XmTextGetInsertionPosition(ih->handle), str);
    XFree(str);

    iupAttribSetStr(ih, "_IUPMOT_DISABLE_TEXT_CB", NULL);
  }
  else if (iupStrEqualNoCase(value, "CLEAR"))
  {
    /* disable callbacks */
    iupAttribSetStr(ih, "_IUPMOT_DISABLE_TEXT_CB", "1");
    XmTextRemove(ih->handle);
    iupAttribSetStr(ih, "_IUPMOT_DISABLE_TEXT_CB", NULL);
  }
  return 0;
}
Пример #4
0
char *TCOD_sys_clipboard_get()
{
	int len;
	if (!dpy ) dpy = XOpenDisplay(NULL);
	char *xbuf = XFetchBytes(dpy,&len);
	if (! xbuf ) return NULL;
	char *ret=strdup(xbuf);
	XFree(xbuf);
	return ret;
}
Пример #5
0
void TCOD_sys_clipboard_set(const char *value)
{
	if ( ! value ) return;
	if (!dpy ) dpy = XOpenDisplay(NULL);
	XStoreBytes(dpy,value,strlen(value)+1);
	/* doesn't seem to work without this... */
	int len;
	char *xbuf = XFetchBytes(dpy,&len);
	XFree(xbuf);
}
Пример #6
0
static void
SendCutBuffer()
{
  char *str;
  int len;

  str = XFetchBytes(dpy, &len);
  if (!str) return;

  SendClientCutText(str, len);
  XFree(str);
}
Пример #7
0
void MSWidget::convertSelection(void)
{
#ifndef MS_WINDOWS
  XConvertSelection(display(),XA_PRIMARY,XA_STRING,
		    _server->atom(MSAtomTable::MStk),_window,CurrentTime);  
#else
  int n;
  char *buffer=XFetchBytes(display(),&n);
  if(n!=0)
    {
      _server->pasteBuffer(buffer);
      XFree(buffer);
    }
  selectionNotify(0);
#endif
}
Пример #8
0
sChar *sGetClipboard()
{
  sChar *result = 0;
  int nbytes;
  
  char *buffer = XFetchBytes(sXDisplay(),&nbytes);
  if(buffer)
  {
    char *tempBuf = sALLOCSTACK(char,nbytes+1);
    sCopyMem(tempBuf,buffer,nbytes);
    tempBuf[nbytes] = 0;
    XFree(buffer);
    
    result = new sChar[nbytes+1];
    sLinuxToWide(result,tempBuf,nbytes+1);
  }
  
  return result;
}
Пример #9
0
static char *
get_cut_buffer (void)
{
  int nbytes;
  char *data;

  PRINT_DEBUG (("trying the cut buffer\n"));

  data = XFetchBytes (dpy, &nbytes);

  if (data)
    {
      struct sbuf *s = sbuf_new (0);
      sbuf_nconcat (s, data, nbytes);
      XFree (data);
      return sbuf_free_struct (s);
    }
  else
    return NULL;
}
Пример #10
0
/**
 * Filters through SDL_Events searching for clipboard requests from the X
 * server.
 *
 * @param evt   The event to filter.
 */
static int widgetClipboardFilterX11(const SDL_Event *evt)
{
	// We are only interested in window manager events
	if (evt->type == SDL_SYSWMEVENT)
	{
		XEvent xevent = evt->syswm.msg->event.xevent;

		// See if the event is a selection/clipboard request
		if (xevent.type == SelectionRequest)
		{
			// Get the request in question
			XSelectionRequestEvent *request = &xevent.xselectionrequest;

			// Generate a reply to the selection request
			XSelectionEvent reply;

			reply.type = SelectionNotify;
			reply.serial = xevent.xany.send_event;
			reply.send_event = True;
			reply.display = info.info.x11.display;
			reply.requestor = request->requestor;
			reply.selection = request->selection;
			reply.property = request->property;
			reply.target = None;
			reply.time = request->time;

			// They want to know what we can provide/offer
			if (request->target == XA_TARGETS)
			{
				Atom possibleTargets[] =
				{
					XA_STRING,
					XA_UTF8_STRING,
					XA_COMPOUND_TEXT
				};

				XChangeProperty(info.info.x11.display, request->requestor,
				                request->property, XA_ATOM, 32, PropModeReplace,
				                (unsigned char *) possibleTargets, 3);
			}
			// They want a string (all we can provide)
			else if (request->target == XA_STRING
			      || request->target == XA_UTF8_STRING
			      || request->target == XA_COMPOUND_TEXT)
			{
				int len;
				char *xdata = XFetchBytes(info.info.x11.display, &len);

				XChangeProperty(info.info.x11.display, request->requestor,
				                request->property, request->target, 8,
				                PropModeReplace, (unsigned char *) xdata,
				                len);
				XFree(xdata);
			}
			else
			{
				// Did not have what they wanted, so no property set
				reply.property = None;
			}

			// Dispatch the event
			XSendEvent(request->display, request->requestor, 0, NoEventMask,
			           (XEvent *) &reply);
			XSync(info.info.x11.display, False);
		}
	}

	return 1;
}
Пример #11
0
const char* Clipboard_GetText() {
	int size;
	const char* str = XFetchBytes(xconn,&size);
	return str;
}
Пример #12
0
std::string Get_Clipboard_Content( void )
{
	std::string content;
#ifdef _WIN32
	if( OpenClipboard( NULL ) )
	{
		bool ucs2 = 0;
		if( IsClipboardFormatAvailable( CF_UNICODETEXT ) )
		{
			ucs2 = 1;
		}

		HANDLE h;

		// Both have line ends as CR-LF and a null character at the end of the data.
		if( ucs2 )
		{
			// CF_UNICODETEXT is UCS-2
			h = GetClipboardData( CF_UNICODETEXT );
		}
		else
		{
			// CF_TEXT is Windows-1252
			h = GetClipboardData( CF_TEXT ); 
		}

		// no handle
		if( !h )
		{
			printf( "Could not get clipboard data\n" );
			CloseClipboard();
			return content;
		}

		// get content
		if( ucs2 )
		{
			content = ucs2_to_utf8(static_cast<wchar_t *>(GlobalLock( h )));
		}
		else
		{
			content = static_cast<char *>(GlobalLock( h ));
		}

		// clean up
		GlobalUnlock( h );
		CloseClipboard();
	}
#elif __APPLE__
	// not tested
	ScrapRef scrap;
	if( ::GetCurrentScrap( &scrap ) != noErr )
	{
		return false;
	}

	Size bytecount = 0;
	OSStatus status = ::GetScrapFlavorSize( scrap, kScrapFlavorTypeText, &bytecount );
	if( status != noErr )
	{
		return false;
	}

	char *buffer = new char[bytecount];
	if( ::GetScrapFlavorData( scrap, kScrapFlavorTypeText, &bytecount, buffer ) == noErr )
	{
		content = static_cast<char *>(buffer);
	}

	delete[] buffer;
#elif __unix__
	// only works with the cut-buffer method (xterm) and not with the more recent selections method
	SDL_SysWMinfo sdlinfo;
	SDL_VERSION( &sdlinfo.version );
	if( SDL_GetWMInfo( &sdlinfo ) )
	{
		sdlinfo.info.x11.lock_func();
		Display *display = sdlinfo.info.x11.display;
		int count = 0;
		char *msg = XFetchBytes( display, &count );
		if( msg )
		{
			if( count > 0 )
			{
				content.append( msg, count );
			}

			XFree( msg );
		}

		sdlinfo.info.x11.unlock_func();
	}
#endif
	return content;
}