-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathGUIUtil.cpp
More file actions
133 lines (103 loc) · 3.58 KB
/
GUIUtil.cpp
File metadata and controls
133 lines (103 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//////////////////////////////////////////////////////////////////////////////////////////
// File: GUIUtil.h
//////////////////////////////////////////////////////////////////////////////////////////
// Description: GUIUtil class
// Project: GUI Library
// Author(s): Jason Boettcher
// jackal@shplorb.com
// www.shplorb.com/~jackal
//////////////////////////////////////////////////////////////////////////////////////////
// Inclusions of header files
#include "GUI.h"
#include <cstring>
using namespace std;
using namespace RTE;
//////////////////////////////////////////////////////////////////////////////////////////
// Method: TrimString
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Removes the preceeding and ending spaces from a c type string.
char *GUIUtil::TrimString(char *String)
{
char *ptr = String;
// Find the first non-space character
while(*ptr) {
if (*ptr != ' ')
break;
ptr++;
}
// Add a null terminator after the last character
for(int i=strlen(ptr)-1; i>=0; i--) {
if (ptr[i] != ' ') {
ptr[i+1] = '\0';
break;
}
}
return ptr;
}
char* GUIUtil::SafeOverlappingStrCpy(char* dst, char* src)
{
memmove(dst, src, strlen(src) + 1);
return dst;
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: GetClipboardText
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Gets the text from the clipboard.
bool GUIUtil::GetClipboardText(string *Text)
{
/* Platform dependent, moved to WinUtil
HANDLE CBDataHandle; // handle to the clipboard data
LPSTR CBDataPtr; // pointer to data to send
// Check the pointer
assert(Text);
// Does the clipboard contain text?
if (IsClipboardFormatAvailable(CF_TEXT)) {
// Open the clipboard
if (OpenClipboard(m_hWnd)) {
CBDataHandle = GetClipboardData(CF_TEXT);
if (CBDataHandle) {
CBDataPtr = (LPSTR)GlobalLock(CBDataHandle);
int TextSize = strlen(CBDataPtr);
// Insert the text
Text->erase();
Text->insert(0, CBDataPtr);
CloseClipboard();
GlobalUnlock(CBDataHandle);
return true;
}
CloseClipboard();
}
}
*/
return false;
}
//////////////////////////////////////////////////////////////////////////////////////////
// Method: SetClipboardText
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Sets the text in the clipboard.
bool GUIUtil::SetClipboardText(string Text)
{
/* Platform dependent
// Open the clipboard
if (OpenClipboard(m_hWnd)) {
// Allocate global memory for the text
HGLOBAL hMemory = GlobalAlloc(GMEM_MOVEABLE, Text.size()+1);
if (hMemory == 0) {
CloseClipboard();
return false;
}
// Empty the clipboard
EmptyClipboard();
// Copy the text into memory
char *CText = (char *)GlobalLock(hMemory);
memcpy(CText, Text.c_str(), Text.size());
CText[Text.size()] = '\0';
GlobalUnlock(hMemory);
// Set the data
SetClipboardData(CF_TEXT, hMemory);
CloseClipboard();
return true;
}
*/
return false;
}