summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authororudge <orudge@openttd.org>2005-06-02 19:55:37 +0000
committerorudge <orudge@openttd.org>2005-06-02 19:55:37 +0000
commite8c6b8feca60797c88467f2b77da26fcf7679a60 (patch)
tree6625c71dd661316ab1258cacbe3076f0c41ed591
parent81ac4ac152b38cb52857d2ce04b8604d9aca8f66 (diff)
downloadopenttd-e8c6b8feca60797c88467f2b77da26fcf7679a60.tar.xz
(svn r2399) - Fix: Update OS/2 project file with filename changes
- Fix: Make clipboard code a bit nicer (thanks Tron)
-rw-r--r--openttd.tgt4
-rw-r--r--os2.c59
2 files changed, 32 insertions, 31 deletions
diff --git a/openttd.tgt b/openttd.tgt
index a4ed0e11c..a3666cf9b 100644
--- a/openttd.tgt
+++ b/openttd.tgt
@@ -2112,8 +2112,8 @@ WVList
0
484
MItem
-5
-ttd.c
+9
+openttd.c
485
WString
4
diff --git a/os2.c b/os2.c
index 76bbb929c..6ceadf62f 100644
--- a/os2.c
+++ b/os2.c
@@ -707,45 +707,46 @@ const HalMusicDriver _os2_music_driver = {
*/
bool InsertTextBufferClipboard(Textbuf *tb)
{
- HAB hab = 0; // anchor-block handle
- PSZ pszClipText, pszClipText2;
- uint16 width = 0;
- uint16 length = 0;
- char clipbuf[300];
-
- pszClipText2 = clipbuf;
+ HAB hab = 0;
if (WinOpenClipbrd(hab))
{
- if (pszClipText = (PSZ) WinQueryClipbrdData(hab, CF_TEXT))
- strncpy(clipbuf, pszClipText, 300);
+ const char* text = (const char*)WinQueryClipbrdData(hab, CF_TEXT);
- WinCloseClipbrd(hab);
- }
+ if (text != NULL)
+ {
+ uint length = 0;
+ uint width = 0;
+ const char* i;
- if (!pszClipText)
- return false;
+ for (i = text; IsValidAsciiChar(*i); i++)
+ {
+ uint w;
- 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 (tb->length + length >= tb->maxlength - 1) break;
- if (length == 0)
- return false;
+ w = GetCharacterWidth((byte)*i);
+ if (tb->maxwidth != 0 && width + tb->width + w > tb->maxwidth) break;
- 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;
+ width += w;
+ length++;
+ }
+
+ memmove(tb->buf + tb->caretpos + length, tb->buf + tb->caretpos, tb->length - tb->caretpos + 1);
+ memcpy(tb->buf + tb->caretpos, text, length);
+ tb->width += width;
+ tb->caretxoffs += width;
+ tb->length += length;
+ tb->caretpos += length;
+
+ WinCloseClipbrd(hab);
+ return true;
+ }
- tb->length += length;
- tb->caretpos += length;
- tb->buf[tb->length + 1] = '\0'; // terminating zero
+ WinCloseClipbrd(hab);
+ }
- return true;
+ return false;
}
static TID thread1 = 0;