mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r2399) - Fix: Update OS/2 project file with filename changes
- Fix: Make clipboard code a bit nicer (thanks Tron)
This commit is contained in:
parent
81ac4ac152
commit
e8c6b8feca
|
@ -2112,8 +2112,8 @@ WVList
|
||||||
0
|
0
|
||||||
484
|
484
|
||||||
MItem
|
MItem
|
||||||
5
|
9
|
||||||
ttd.c
|
openttd.c
|
||||||
485
|
485
|
||||||
WString
|
WString
|
||||||
4
|
4
|
||||||
|
|
65
os2.c
65
os2.c
|
@ -707,45 +707,46 @@ const HalMusicDriver _os2_music_driver = {
|
||||||
*/
|
*/
|
||||||
bool InsertTextBufferClipboard(Textbuf *tb)
|
bool InsertTextBufferClipboard(Textbuf *tb)
|
||||||
{
|
{
|
||||||
HAB hab = 0; // anchor-block handle
|
HAB hab = 0;
|
||||||
PSZ pszClipText, pszClipText2;
|
|
||||||
uint16 width = 0;
|
|
||||||
uint16 length = 0;
|
|
||||||
char clipbuf[300];
|
|
||||||
|
|
||||||
pszClipText2 = clipbuf;
|
|
||||||
|
|
||||||
if (WinOpenClipbrd(hab))
|
if (WinOpenClipbrd(hab))
|
||||||
{
|
{
|
||||||
if (pszClipText = (PSZ) WinQueryClipbrdData(hab, CF_TEXT))
|
const char* text = (const char*)WinQueryClipbrdData(hab, CF_TEXT);
|
||||||
strncpy(clipbuf, pszClipText, 300);
|
|
||||||
|
if (text != NULL)
|
||||||
|
{
|
||||||
|
uint length = 0;
|
||||||
|
uint width = 0;
|
||||||
|
const char* i;
|
||||||
|
|
||||||
|
for (i = text; IsValidAsciiChar(*i); i++)
|
||||||
|
{
|
||||||
|
uint w;
|
||||||
|
|
||||||
|
if (tb->length + length >= tb->maxlength - 1) break;
|
||||||
|
|
||||||
|
w = GetCharacterWidth((byte)*i);
|
||||||
|
if (tb->maxwidth != 0 && width + tb->width + w > tb->maxwidth) break;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
WinCloseClipbrd(hab);
|
WinCloseClipbrd(hab);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pszClipText)
|
return false;
|
||||||
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;
|
static TID thread1 = 0;
|
||||||
|
|
Loading…
Reference in New Issue