From 4719bb0c6ee0235ba170569c15a0f94a6c2d7968 Mon Sep 17 00:00:00 2001 From: orudge Date: Thu, 2 Jun 2005 10:39:46 +0000 Subject: (svn r2394) - Completed clipboard functions for OS/2 port --- os2.c | 51 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 10 deletions(-) (limited to 'os2.c') diff --git a/os2.c b/os2.c index 19e215265..d61f3ed6d 100644 --- a/os2.c +++ b/os2.c @@ -4,6 +4,8 @@ #include "string.h" #include "table/strings.h" #include "hal.h" +#include "gfx.h" +#include "gui.h" #include #include @@ -11,6 +13,7 @@ #include #include #include +#include #include #include @@ -690,25 +693,54 @@ const HalMusicDriver _os2_music_driver = { OS2MidiSetVolume, }; +/** + * Insert a chunk of text from the clipboard onto the textbuffer. Get TEXT clipboard + * and append this up to the maximum length (either absolute or screenlength). If maxlength + * is zero, we don't care about the screenlength but only about the physical length of the string + * @param tb @Textbuf type to be changed + * @return Return true on successfull change of Textbuf, or false otherwise + */ bool InsertTextBufferClipboard(Textbuf *tb) { -#if 0 HAB hab = 0; // anchor-block handle - PSZ pszClipText, pszLocalText; + PSZ pszClipText, pszClipText2; + uint16 width = 0; + uint16 length = 0; + char clipbuf[300]; + + pszClipText2 = clipbuf; if (WinOpenClipbrd(hab)) { if (pszClipText = (PSZ) WinQueryClipbrdData(hab, CF_TEXT)) - { - while (*pszLocalText++ = *pszClipText++); - } + strncpy(clipbuf, pszClipText, 300); + WinCloseClipbrd(hab); } - // text is now in pszLocalText, do something with it! -#endif - // TODO - return false; + if (!pszClipText) + return false; + + for (; IsValidAsciiChar(*pszClipText2) && (tb->length + length) < tb->maxlength - 1 && + (tb->maxwidth == 0 || width + tb->width + GetCharacterWidth((byte)*pszClipText2) <= tb->maxwidth); pszClipText2++) + { + width += GetCharacterWidth((byte)*pszClipText2); + length++; + } + + if (length == 0) + return false; + + memmove(tb->buf + tb->caretpos + length, tb->buf + tb->caretpos, tb->length - tb->caretpos); + memcpy(tb->buf + tb->caretpos, clipbuf, length); + tb->width += width; + tb->caretxoffs += width; + + tb->length += length; + tb->caretpos += length; + tb->buf[tb->length + 1] = '\0'; // terminating zero + + return true; } static TID thread1 = 0; @@ -719,7 +751,6 @@ static TID thread1 = 0; bool CreateOTTDThread(void *func, void *param) { thread1 = _beginthread(func, NULL, 32768, param); - fprintf(stderr, "beginthread returns: %d\n", thread1); // if (thread1 == -1) return(false); -- cgit v1.2.3-70-g09d2