12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
* GNU General Public License for more details. |
|
* |
|
|
* You should have received a copy of the GNU Lesser General Public License |
|
|
* along with GPGOE; if not, write to the Free Software Foundation, |
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
15 |
*/ |
*/ |
16 |
|
|
17 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
26 |
#include "GPGOE.h" |
#include "GPGOE.h" |
27 |
|
|
28 |
|
|
29 |
|
/* Convert the string from the native code page to UTF8. */ |
30 |
char* |
char* |
31 |
native_to_utf8 (const char *string) |
native_to_utf8 (const char *string) |
32 |
{ |
{ |
42 |
|
|
43 |
n = MultiByteToWideChar (GetACP (), 0, string, -1, result, n); |
n = MultiByteToWideChar (GetACP (), 0, string, -1, result, n); |
44 |
if (n < 0) { |
if (n < 0) { |
45 |
free (result); |
xfree (result); |
46 |
return NULL; |
return NULL; |
47 |
} |
} |
48 |
|
|
54 |
|
|
55 |
n = WideCharToMultiByte (CP_UTF8, 0, result, -1, native, n, NULL, NULL); |
n = WideCharToMultiByte (CP_UTF8, 0, result, -1, native, n, NULL, NULL); |
56 |
if (n < 0) { |
if (n < 0) { |
57 |
free (result); |
xfree (result); |
58 |
return NULL; |
return NULL; |
59 |
} |
} |
60 |
|
|
61 |
free (result); |
xfree (result); |
62 |
return native; |
return native; |
63 |
} |
} |
64 |
|
|
74 |
n = MultiByteToWideChar (CP_UTF8, 0, string, -1, NULL, 0); |
n = MultiByteToWideChar (CP_UTF8, 0, string, -1, NULL, 0); |
75 |
if (n < 0) |
if (n < 0) |
76 |
return NULL; |
return NULL; |
|
|
|
77 |
result = (wchar_t*)xcalloc (1, (n+1) * sizeof *result); |
result = (wchar_t*)xcalloc (1, (n+1) * sizeof *result); |
|
|
|
78 |
n = MultiByteToWideChar (CP_UTF8, 0, string, -1, result, n); |
n = MultiByteToWideChar (CP_UTF8, 0, string, -1, result, n); |
79 |
if (n < 0) { |
if (n < 0) { |
80 |
free (result); |
xfree (result); |
81 |
return NULL; |
return NULL; |
82 |
} |
} |
83 |
|
|
84 |
n = WideCharToMultiByte (GetACP (), 0, result, -1, NULL, 0, NULL, NULL); |
n = WideCharToMultiByte (GetACP (), 0, result, -1, NULL, 0, NULL, NULL); |
85 |
if (n < 0) |
if (n < 0) |
86 |
return NULL; |
return NULL; |
87 |
|
native = (char*)xcalloc (1, n+1); |
|
native = (char*)malloc (n+1); |
|
|
if (!native) |
|
|
abort (); |
|
|
|
|
88 |
n = WideCharToMultiByte (GetACP (), 0, result, -1, native, n, NULL, NULL); |
n = WideCharToMultiByte (GetACP (), 0, result, -1, native, n, NULL, NULL); |
89 |
if (n < 0) { |
if (n < 0) { |
90 |
free (result); |
xfree (result); |
91 |
return NULL; |
return NULL; |
92 |
} |
} |
93 |
|
|
94 |
free (result); |
xfree (result); |
95 |
return native; |
return native; |
96 |
} |
} |
97 |
|
|
156 |
SetClipboardData (CF_TEXT, clipmem); |
SetClipboardData (CF_TEXT, clipmem); |
157 |
GlobalUnlock (clipmem); |
GlobalUnlock (clipmem); |
158 |
CloseClipboard (); |
CloseClipboard (); |
159 |
GlobalFree (clipmem); |
GlobalFree (clipmem); |
160 |
|
|
161 |
return 0; |
return 0; |
162 |
} |
} |
200 |
va_list ptr; |
va_list ptr; |
201 |
|
|
202 |
va_start (ptr, fmt); |
va_start (ptr, fmt); |
203 |
_vsnprintf (buffer, sizeof (buffer)-1, fmt, ptr); |
_vsnprintf (buffer, DIM (buffer)-1, fmt, ptr); |
204 |
va_end (ptr); |
va_end (ptr); |
205 |
MessageBox (hwnd, buffer, caption, type); |
MessageBox (hwnd, buffer, caption, type); |
206 |
} |
} |
207 |
|
|
208 |
|
|
209 |
|
/* Prepend '> ' to line line in the buffer @inp |
210 |
|
and store the result in @r_outp. */ |
211 |
|
void |
212 |
|
quote_msg_text (const char *inp, char **r_outp) |
213 |
|
{ |
214 |
|
size_t i, n=0; |
215 |
|
char *p; |
216 |
|
char *outp; |
217 |
|
|
218 |
|
for (i=0; i < strlen (inp); i++) { |
219 |
|
if (inp[i] == '\r') |
220 |
|
n += 4; |
221 |
|
} |
222 |
|
outp = xcalloc (1, strlen (inp) + 1 + n + 1); |
223 |
|
p = strtok ((char *)inp, "\r"); |
224 |
|
while (p != NULL) { |
225 |
|
if (*p == '\n') |
226 |
|
p++; |
227 |
|
strcat (outp, "> "); |
228 |
|
strcat (outp, p); |
229 |
|
strcat (outp, "\r\n"); |
230 |
|
p = strtok (NULL, "\r"); |
231 |
|
} |
232 |
|
*r_outp = outp; |
233 |
|
} |
234 |
|
|
235 |
|
|
236 |
|
/* Center the window @hwndChild over the parent window @parent. */ |
237 |
|
void |
238 |
|
center_window (HWND hwndChild, HWND parent) |
239 |
|
{ |
240 |
|
HWND hwndParent; |
241 |
|
RECT rChild, rParent; |
242 |
|
HDC hdc; |
243 |
|
int wChild, hChild, wParent, hParent; |
244 |
|
int wScreen, hScreen, xNew, yNew; |
245 |
|
int flags = SWP_NOSIZE | SWP_NOZORDER; |
246 |
|
|
247 |
|
hwndParent = parent; |
248 |
|
if (hwndParent == NULL) |
249 |
|
hwndParent = GetDesktopWindow (); |
250 |
|
GetWindowRect (hwndChild, &rChild); |
251 |
|
wChild = rChild.right - rChild.left; |
252 |
|
hChild = rChild.bottom - rChild.top; |
253 |
|
|
254 |
|
GetWindowRect (hwndParent, &rParent); |
255 |
|
wParent = rParent.right - rParent.left; |
256 |
|
hParent = rParent.bottom - rParent.top; |
257 |
|
|
258 |
|
hdc = GetDC (hwndChild); |
259 |
|
wScreen = GetDeviceCaps (hdc, HORZRES); |
260 |
|
hScreen = GetDeviceCaps (hdc, VERTRES); |
261 |
|
ReleaseDC (hwndChild, hdc); |
262 |
|
xNew = rParent.left + ((wParent - wChild) /2); |
263 |
|
if (xNew < 0) |
264 |
|
xNew = 0; |
265 |
|
else if ((xNew+wChild) > wScreen) |
266 |
|
xNew = wScreen - wChild; |
267 |
|
yNew = rParent.top + ((hParent - hChild) /2); |
268 |
|
if (yNew < 0) |
269 |
|
yNew = 0; |
270 |
|
else if ((yNew+hChild) > hScreen) |
271 |
|
yNew = hScreen - hChild; |
272 |
|
SetWindowPos (hwndChild, NULL, xNew, yNew, 0, 0, flags); |
273 |
|
} |