diff options
author | Darkvater <Darkvater@openttd.org> | 2005-02-21 18:59:54 +0000 |
---|---|---|
committer | Darkvater <Darkvater@openttd.org> | 2005-02-21 18:59:54 +0000 |
commit | fb78ca8a62c69a51903416f5a4062a8972c1e98d (patch) | |
tree | ac473756965e88790f53e13ff4589035499ce9c1 /win32.c | |
parent | f13bfccc37237e612d1eb5194d41246072bbc20f (diff) | |
download | openttd-fb78ca8a62c69a51903416f5a4062a8972c1e98d.tar.xz |
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
- Codechange: Introduction of Textbuf struct which not only holds physical data as length but also pixel-constrains (width) and information about the caret
- Codechange: Move Clipboard function to OS specific file. Currently only Windows has clipboard actions
- Feature: Editboxes, console and exit screen also accept the numeric-enter as a yes
- Feature: Navigation through text with cursor keys is possible, as well as arbitrary insertion (also paste) and deletion; both backspace and del keys. Functions DeleteTextBufferChar, InsertTextBufferChar and InsertTextBufferClipboard handle input and deletion. Navigation is done through MoveTextBufferPos.
- Fix: OTTD crash when opening 'add server' editbox
- CodeChange: fix up some stringwidth calculations in gfx.c. You can get the width in pixels of a character by calling GetCharacterWidth().
Diffstat (limited to 'win32.c')
-rw-r--r-- | win32.c | 48 |
1 files changed, 47 insertions, 1 deletions
@@ -6,6 +6,7 @@ #include "gfx.h" #include "sound.h" #include "window.h" +#include "gui.h" #include <windows.h> #include <mmsystem.h> #include "hal.h" @@ -2061,7 +2062,7 @@ int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR lpCmdLin return 0; } -void DeterminePaths() +void DeterminePaths(void) { char *s; char *cfg; @@ -2108,3 +2109,48 @@ int CDECL vsnprintf(char *str, size_t size, const char *format, va_list ap) if (ret < 0) str[size - 1] = '\0'; return ret; } + +/** + * 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 (IsClipboardFormatAvailable(CF_TEXT)) { + HGLOBAL cbuf; + const byte *data, *dataptr; + uint16 width = 0; + uint16 length = 0; + + OpenClipboard(NULL); + cbuf = GetClipboardData(CF_TEXT); + data = GlobalLock(cbuf); // clipboard data + dataptr = data; + + for (; IsValidAsciiChar(*dataptr) && (tb->length + length) < tb->maxlength - 1 && + (tb->maxwidth == 0 || width + tb->width + GetCharacterWidth((byte)*dataptr) <= tb->maxwidth); dataptr++) { + width += GetCharacterWidth((byte)*dataptr); + 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, data, length); + tb->width += width; + tb->caretxoffs += width; + + tb->length += length; + tb->caretpos += length; + tb->buf[tb->length + 1] = '\0'; // terminating zero + + GlobalUnlock(cbuf); + CloseClipboard(); + return true; + } + return false; +} |