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