1 |
twoaday |
1 |
/* OEDlgViewer.c - OE text viewer |
2 |
|
|
* Copyright (C) 2001, 2002, 2003, 2006 Timo Schulz |
3 |
|
|
* |
4 |
|
|
* This file is part of GPGOE. |
5 |
|
|
* |
6 |
|
|
* GPGOE is free software; you can redistribute it and/or modify |
7 |
|
|
* it under the terms of the GNU Lesser General Public License as published by |
8 |
|
|
* the Free Software Foundation; either version 2.1 of the License, or |
9 |
|
|
* (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* GPGOE is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU Lesser General Public License |
17 |
|
|
* along with GPGOE; if not, write to the Free Software Foundation, |
18 |
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
19 |
|
|
*/ |
20 |
|
|
|
21 |
|
|
#ifdef HAVE_CONFIG_H |
22 |
|
|
#include <config.h> |
23 |
|
|
#endif |
24 |
|
|
#include <windows.h> |
25 |
|
|
#include <assert.h> |
26 |
|
|
#include "resource.h" |
27 |
|
|
#include "gpgme.h" |
28 |
|
|
#include "GPGOE.h" |
29 |
|
|
|
30 |
|
|
|
31 |
|
|
/* Read all text from the dialog item @id and |
32 |
|
|
return it as a string. */ |
33 |
|
|
char* |
34 |
|
|
get_item_text (HWND dlg, int id) |
35 |
|
|
{ |
36 |
|
|
char *p; |
37 |
|
|
int n; |
38 |
|
|
|
39 |
|
|
n = SendDlgItemMessage (dlg, id, WM_GETTEXTLENGTH, 0, 0); |
40 |
|
|
if (n < 1) |
41 |
|
|
return NULL; |
42 |
|
|
p = xcalloc (1, n+1); |
43 |
twoaday |
11 |
n = GetDlgItemText (dlg, IDC_VIEWER_TEXT2, p, n); |
44 |
twoaday |
1 |
return p; |
45 |
|
|
} |
46 |
|
|
|
47 |
|
|
|
48 |
twoaday |
12 |
/* Prepend '> ' to line line in the buffer @inp |
49 |
|
|
and store the result in @r_outp. */ |
50 |
|
|
static void |
51 |
|
|
quote_msg_text (const char *inp, char **r_outp) |
52 |
|
|
{ |
53 |
|
|
size_t i, n=0; |
54 |
|
|
char *p; |
55 |
|
|
char *outp; |
56 |
|
|
|
57 |
|
|
for (i=0; i < strlen (inp); i++) { |
58 |
|
|
if (inp[i] == '\r') |
59 |
|
|
n += 4; |
60 |
|
|
} |
61 |
|
|
outp = xcalloc (1, strlen (inp) + 1 + n + 1); |
62 |
|
|
p = strtok ((char *)inp, "\r"); |
63 |
|
|
while (p != NULL) { |
64 |
|
|
if (*p == '\n') |
65 |
|
|
p++; |
66 |
|
|
strcat (outp, "> "); |
67 |
|
|
strcat (outp, p); |
68 |
|
|
strcat (outp, "\r\n"); |
69 |
|
|
p = strtok (NULL, "\r"); |
70 |
|
|
} |
71 |
|
|
*r_outp = outp; |
72 |
|
|
} |
73 |
|
|
|
74 |
|
|
|
75 |
twoaday |
1 |
/* Text viewer dialog box procedure. */ |
76 |
|
|
BOOL CALLBACK |
77 |
|
|
viewer_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
78 |
|
|
{ |
79 |
|
|
static viewer_ctx_t viewer; |
80 |
twoaday |
12 |
char *p, *out; |
81 |
twoaday |
1 |
|
82 |
|
|
switch (msg) { |
83 |
|
|
case WM_INITDIALOG: |
84 |
|
|
viewer = (viewer_ctx_t)lparam; |
85 |
|
|
assert (viewer); |
86 |
twoaday |
12 |
SetDlgItemText (dlg, IDC_VIEWER_COPY, _("&Copy")); |
87 |
|
|
SetDlgItemText (dlg, IDC_VIEWER_QUOTE, _("&Quote")); |
88 |
|
|
SetDlgItemText (dlg, IDOK, _("&OK")); |
89 |
twoaday |
1 |
SetWindowText (dlg, _("Message Viewer")); |
90 |
twoaday |
11 |
SetDlgItemText (dlg, IDC_VIEWER_TEXT2, viewer->msg); |
91 |
twoaday |
1 |
SetForegroundWindow (dlg); |
92 |
|
|
SetFocus (GetDlgItem (dlg, IDOK)); |
93 |
|
|
return FALSE; |
94 |
|
|
|
95 |
|
|
case WM_SYSCOMMAND: |
96 |
|
|
if (LOWORD (wparam) == SC_CLOSE) |
97 |
|
|
EndDialog (dlg, 0); |
98 |
|
|
return FALSE; |
99 |
|
|
|
100 |
|
|
case WM_COMMAND: |
101 |
|
|
switch (LOWORD (wparam)) { |
102 |
|
|
case IDOK: |
103 |
|
|
EndDialog (dlg, 0); |
104 |
|
|
return TRUE; |
105 |
|
|
|
106 |
|
|
case IDC_VIEWER_QUOTE: |
107 |
twoaday |
11 |
p = get_item_text (dlg, IDC_VIEWER_TEXT2); |
108 |
twoaday |
12 |
if (!p) |
109 |
|
|
return TRUE; |
110 |
|
|
quote_msg_text (p, &out); |
111 |
|
|
SetDlgItemText (dlg, IDC_VIEWER_TEXT2, out); |
112 |
twoaday |
1 |
free_if_alloc (p); |
113 |
twoaday |
12 |
free_if_alloc (out); |
114 |
twoaday |
1 |
return TRUE; |
115 |
|
|
|
116 |
|
|
case IDC_VIEWER_COPY: |
117 |
twoaday |
11 |
p = get_item_text (dlg, IDC_VIEWER_TEXT2); |
118 |
twoaday |
1 |
if (p != NULL) |
119 |
|
|
set_clip_text (NULL, p, strlen (p)); |
120 |
|
|
free_if_alloc (p); |
121 |
|
|
return TRUE; |
122 |
|
|
} |
123 |
|
|
break; |
124 |
|
|
} |
125 |
|
|
return FALSE; |
126 |
|
|
} |