Commit 15b2c098 authored by deuce's avatar deuce
Browse files

Two new ciolib functions:

void copytext(const char *text, size_t buflen) which places the buffer in
the clipboard and
char *x_getcliptext(void) which returns a malloc()ed copy of the current
clipboard buffer.
Currently, only implemented in Win32.
parent b1e19714
......@@ -94,6 +94,8 @@ void ciolib_window(int sx, int sy, int ex, int ey);
void ciolib_delline(void);
void ciolib_insline(void);
char *ciolib_getpass(const char *prompt);
void ciolib_copytext(const char *text, size_t buflen);
char *ciolib_getcliptext(void);
#define CIOLIB_INIT() { if(!initialized) initciolib(CIOLIB_MODE_AUTO); }
......@@ -121,6 +123,8 @@ int try_x_init(int mode)
cio_api.showmouse=NULL;
cio_api.hidemouse=NULL;
cio_api.settitle=x_settitle;
cio_api.copytext=x_copytext;
cio_api.getcliptext=x_getcliptext;
return(1);
}
return(0);
......@@ -148,6 +152,8 @@ int try_curses_init(int mode)
cio_api.showmouse=curs_showmouse;
cio_api.hidemouse=curs_hidemouse;
cio_api.settitle=NULL;
cio_api.copytext=NULL;
cio_api.getcliptext=NULL;
return(1);
}
return(0);
......@@ -176,6 +182,8 @@ int try_ansi_init(int mode)
cio_api.showmouse=NULL;
cio_api.hidemouse=NULL;
cio_api.settitle=NULL;
cio_api.copytext=NULL;
cio_api.getcliptext=NULL;
return(1);
}
return(0);
......@@ -207,6 +215,8 @@ int try_conio_init(int mode)
cio_api.showmouse=win32_showmouse;
cio_api.hidemouse=win32_hidemouse;
cio_api.settitle=win32_settitle;
cio_api.copytext=win32_copytext;
cio_api.getcliptext=win32_getcliptext;
return(1);
}
return(0);
......@@ -836,3 +846,21 @@ void ciolib_settitle(const char *title) {
if(cio_api.settitle!=NULL)
cio_api.settitle(title);
}
void ciolib_copytext(const char *text, size_t buflen)
{
CIOLIB_INIT();
if(cio_api.copytext!=NULL)
cio_api.copytext(text,buflen);
}
char *ciolib_getcliptext(void)
{
CIOLIB_INIT();
if(cio_api.getcliptext!=NULL)
return(cio_api.getcliptext());
else
return(NULL);
}
......@@ -193,6 +193,8 @@ typedef struct {
int (*hidemouse) (void);
int (*showmouse) (void);
void (*settitle) (const char *);
void (*copytext) (const char *, size_t);
char *(*getcliptext) (void);
} cioapi_t;
extern cioapi_t cio_api;
......@@ -243,6 +245,8 @@ void settitle(const char *title);
int ciolib_showmouse(void);
int ciolib_hidemouse(void);
void ciolib_settitle(const char *title);
void ciolib_copytext(const char *text, size_t buflen);
char *ciolib_getcliptext(void);
#ifdef __cplusplus
}
#endif
......@@ -286,6 +290,8 @@ void ciolib_settitle(const char *title);
#define hidemouse() ciolib_hidemouse()
#define showmouse() ciolib_showmouse()
#define settitle(a) ciolib_settitle(a)
#define copytext(a,b) ciolib_copytext(a,b)
#define getcliptext() ciolib_getcliptext()
#endif
#endif /* Do not add anything after this line */
......@@ -645,3 +645,47 @@ void win32_settitle(const char *title)
{
SetConsoleTitle(title);
}
void win32_copytext(const char *text, size_t buflen)
{
HGLOBAL clipbuf;
LPTSTR clip;
if(!OpenClipboard(NULL))
return;
EmptyClipboard();
clipbuf=GlobalAlloc(GMEM_MOVEABLE, buflen+1);
if(clipbuf==NULL) {
CloseClipboard();
return;
}
clip=GlobalLock(clipbuf);
memcpy(clip, text, buflen);
clip[buflen]=0;
GlobalUnlock(clipbuf);
SetClipboardData(CF_OEMTEXT, clipbuf);
CloseClipboard();
}
char *win32_getcliptext(void)
{
HGLOBAL clipbuf;
LPTSTR clip;
char *ret;
if(!IsClipboardFormatAvailable(CF_OEMTEXT))
return(NULL);
if(!OpenClipboard(NULL))
return(NULL);
clipbuf=GetClipboardData(CF_OEMTEXT);
if(clipbuf!=NULL) {
clip=GlobalLock(clipbuf);
ret=(char *)malloc(strlen(clip)+1);
if(ret != NULL)
strcpy(ret, clip);
GlobalUnlock(clipbuf);
}
CloseClipboard();
return(ret);
}
......@@ -64,6 +64,8 @@ int win32_wherex(void);
int win32_wherey(void);
void win32_settitle(const char *title);
int win32_initciolib(long inmode);
void win32_copytext(const char *text, size_t buflen);
char *win32_getcliptext(void);
#ifdef __cplusplus
}
......
......@@ -269,3 +269,14 @@ void x_settitle(const char *title)
{
x_win_title(title);
}
void x_copytext(const char *text, size_t buflen)
{
return;
}
char *x_getcliptext(void)
{
return(NULL);
}
......@@ -54,6 +54,8 @@ int x_getche(void);
int x_beep(void);
void x_textmode(int mode);
void x_settitle(const char *title);
void x_copytext(const char *text, size_t buflen);
char *x_getcliptext(void);
#ifdef __cplusplus
}
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment