/[winpt]/trunk/Src/wptClipEditDlg.cpp
ViewVC logotype

Diff of /trunk/Src/wptClipEditDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 36 by werner, Thu Oct 27 15:25:13 2005 UTC revision 229 by twoaday, Mon Jun 19 14:04:31 2006 UTC
# Line 1  Line 1 
1  /* wptClipEditDlg.cpp - Clipboard Editor dialog  /* wptClipEditDlg.cpp - Clipboard Editor dialog
2   *      Copyright (C) 2000-2005 Timo Schulz   *      Copyright (C) 2000-2006 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
# Line 17  Line 17 
17   * along with WinPT; if not, write to the Free Software Foundation,   * along with WinPT; if not, write to the Free Software Foundation,
18   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19   */   */
   
20  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
21  #include <config.h>  #include <config.h>
22  #endif  #endif
23    
24  #include <windows.h>  #include <windows.h>
 #include <windows.h>  
25  #include <stdio.h>  #include <stdio.h>
26    
27  #include "wptTypes.h"  #include "wptTypes.h"
# Line 32  Line 30 
30  #include "wptErrors.h"  #include "wptErrors.h"
31  #include "wptGPG.h"  #include "wptGPG.h"
32  #include "wptNLS.h"  #include "wptNLS.h"
33  #include "../resource.h"  #include "resource.h"
34    #include "wptCommonCtl.h"
35    #include "wptContext.h"
36    #include "wptKeylist.h"
37    
38    #ifdef _MSC_VER
39    #include "winpt_header.h"
40    
41    static DWORD help_arr[] = {
42        IDC_CLIPEDIT_SEND,  WPT_CLIPEDIT_COPY,
43        IDC_CLIPEDIT_CLEAR, WPT_CLIPEDIT_CLEAR,
44        IDC_CLIPEDIT_LOAD,  WPT_CLIPEDIT_LOAD,
45        IDC_CLIPEDIT_SAVE,  WPT_CLIPEDIT_SAVE,
46        IDC_CLIPEDIT_QUOTE, WPT_CLIPEDIT_QUOTE,
47        0, 0};
48    #endif
49    
50    
51  /* Load the clipboard contents into the text field in @dlg.  /* Load the clipboard contents into the text field in @dlg.
52       Optinally @header and @footer can be used to set a header and footer.
53     Return value: 0 on success. */     Return value: 0 on success. */
54  static int  static int
55  load_clipboard (HWND dlg)  load_clipboard (HWND dlg,
56                    const char *header, const char *footer)
57  {  {
58      HANDLE clipmem;      HANDLE clipmem;
59      char *cliptext;      char *cliptext;
60      char *p;      char *p, *pp;
61    
62      CloseClipboard (); /* make sure it is closed. */      CloseClipboard (); /* make sure it is closed. */
63      if (OpenClipboard (NULL) == FALSE) {      if (OpenClipboard (NULL) == FALSE) {
# Line 67  load_clipboard (HWND dlg) Line 82  load_clipboard (HWND dlg)
82      strcpy (p, cliptext);      strcpy (p, cliptext);
83            
84      GlobalUnlock (clipmem);      GlobalUnlock (clipmem);
85      CloseClipboard ();        CloseClipboard ();
86      SetDlgItemText (dlg, IDC_CLIPEDIT_CLIPTEXT2, p);      
87        if (header && footer) {
88            const char *fmt = "%s\r\n%s\r\n%s";
89            int len = strlen (header) + strlen (footer) + strlen (fmt) + strlen (p);
90    
91            pp = new char[len + 1];
92            if (!pp)
93                BUG (0);
94            _snprintf (pp, len, fmt, header, p, footer);
95            SetDlgItemText (dlg, IDC_CLIPEDIT_CLIPTEXT2, pp);
96            free_if_alloc (pp);
97        }
98        else
99            SetDlgItemText (dlg, IDC_CLIPEDIT_CLIPTEXT2, p);
100      free_if_alloc (p);      free_if_alloc (p);
       
101      return 0;      return 0;
102  }  }
103    
# Line 87  load_clipboard_from_file (HWND dlg) Line 114  load_clipboard_from_file (HWND dlg)
114      int id;      int id;
115    
116      memset (&open, 0, sizeof (open));      memset (&open, 0, sizeof (open));
117      open.lStructSize = sizeof (OPENFILENAME);            open.lStructSize = sizeof (OPENFILENAME);
118      open.hInstance = glob_hinst;                  open.hInstance = glob_hinst;
119      open.lpstrTitle = _("File Open");            open.lpstrTitle = _("File Open");
120      open.lpstrFilter = (char *)_("All Files (*.*)\0*.*\0\0");            open.lpstrFilter = "All Files (*.*)\0*.*\0\0";
121      open.hwndOwner = dlg;                open.hwndOwner = dlg;          
122      open.lpstrFile = file;                        open.lpstrFile = file;                  
123      open.nMaxFile = sizeof (file)-1;                      open.nMaxFile = sizeof (file)-1;                
124      open.Flags = OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST;      open.Flags = OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST;
125                            
126      if (GetOpenFileName (&open)) {      if (GetOpenFileName (&open)) {
127          if( (size=get_file_size (file)) > MAX_CLIPTEXT_SIZE) {                if( (size=get_file_size (file)) > MAX_CLIPTEXT_SIZE) {
128              id = msg_box (dlg, _("The file you want to add is very large.\n"              id = msg_box (dlg, _("The file you want to add is very large.\n"
129                                   "Still proceed?"), _("Clipboard"), MB_INFO|MB_YESNO);                                         "Still proceed?"), _("Clipboard"),
130              if (id == IDNO)                                MB_INFO|MB_YESNO);
131                if (id == IDNO)
132                  return -1;                  return -1;
133          }          }
134          fp = fopen (file, "rb");          fp = fopen (file, "rb");
135          if (!fp) {          if (!fp) {
136              msg_box (dlg, winpt_strerror (WPTERR_FILE_OPEN), _("Clipboard"), MB_ERR);              msg_box (dlg, winpt_strerror (WPTERR_FILE_OPEN),
137                         _("Clipboard"), MB_ERR);
138              return FALSE;              return FALSE;
139          }          }
140          p = new char[size+1];          p = new char[size+1];
141          if (!p)          if (!p)
142              BUG (0);              BUG (0);
143          fread (p, 1, size, fp);          memset (p, 0, size+1);
144          p[size] = '\0';          size = fread (p, 1, size, fp);
145          fclose (fp);          fclose (fp);
146          SetDlgItemText (dlg, IDC_CLIPEDIT_CLIPTEXT2, p);                  SetDlgItemText (dlg, IDC_CLIPEDIT_CLIPTEXT2, p);        
147          free_if_alloc (p);          free_if_alloc (p);
# Line 127  save_clipboard_to_file (HWND dlg) Line 156  save_clipboard_to_file (HWND dlg)
156  {  {
157      OPENFILENAME save;      OPENFILENAME save;
158      FILE *fp;      FILE *fp;
159      char *p;      char *p=NULL;
160      char file[300] = "";      char file[300] = "";
161      DWORD nbytes;      DWORD nbytes;
162      int id;      int id;
# Line 136  save_clipboard_to_file (HWND dlg) Line 165  save_clipboard_to_file (HWND dlg)
165      save.lStructSize = sizeof (OPENFILENAME);            save.lStructSize = sizeof (OPENFILENAME);      
166      save.hInstance = glob_hinst;                  save.hInstance = glob_hinst;            
167      save.lpstrTitle = _("File Save");            save.lpstrTitle = _("File Save");      
168      save.lpstrFile = (char *)_("All Files (*.*)\0*.*\0\0");              save.lpstrFile = (char *)"All Files (*.*)\0*.*\0\0";
169      save.hwndOwner = dlg;                        save.hwndOwner = dlg;                  
170      save.lpstrFile = file;                        save.lpstrFile = file;                  
171      save.nMaxFile = sizeof (file) - 1;      save.nMaxFile = sizeof (file) - 1;
172      save.Flags = OFN_OVERWRITEPROMPT;      save.Flags = OFN_OVERWRITEPROMPT;
173                        
174      if( GetSaveFileName( &save ) ) {      if (GetSaveFileName (&save)) {
175          if( file_exist_check( file ) == 0 ) {                if (file_exist_check (file) == 0) {
176              id = log_box (_("Clipboard"), MB_YESNO,              id = log_box (_("Clipboard"), MB_YESNO,
177                            _("\"%s\" already exists.\n"                            _("\"%s\" already exists.\n"
178                              "Replace existing file?"), file);                                    "Replace existing file?"), file);      
# Line 152  save_clipboard_to_file (HWND dlg) Line 181  save_clipboard_to_file (HWND dlg)
181          }          }
182          fp = fopen (file, "wb");          fp = fopen (file, "wb");
183          if (!fp) {          if (!fp) {
184              msg_box (dlg, winpt_strerror (WPTERR_FILE_CREAT), _("Clipboard"), MB_ERR);              msg_box (dlg, winpt_strerror (WPTERR_FILE_CREAT),
185                         _("Clipboard"), MB_ERR);
186              return FALSE;              return FALSE;
187          }          }
188          /* XXX: there is a NUL-byte at the end. */          /* XXX: there is a NUL-byte at the end. */
189          nbytes = SendDlgItemMessage (dlg, IDC_CLIPEDIT_CLIPTEXT2, WM_GETTEXTLENGTH, 0, 0);          nbytes = SendDlgItemMessage (dlg, IDC_CLIPEDIT_CLIPTEXT2,
190                                         WM_GETTEXTLENGTH, 0, 0);
191          if (nbytes > 0) {          if (nbytes > 0) {
192              p = new char[nbytes+1];              p = new char[nbytes+1];
193              if (!p)              if (!p)
194                  BUG (NULL);                  BUG (NULL);
195              GetDlgItemText (dlg, IDC_CLIPEDIT_CLIPTEXT2, p, nbytes);              GetDlgItemText (dlg, IDC_CLIPEDIT_CLIPTEXT2, p, nbytes);
196              fwrite (p, 1, nbytes, fp);              fwrite (p, 1, nbytes, fp);
197                
198          }                    }          
199          fclose (fp);          fclose (fp);
200          free_if_alloc (p);          free_if_alloc (p);
# Line 171  save_clipboard_to_file (HWND dlg) Line 203  save_clipboard_to_file (HWND dlg)
203  }  }
204    
205    
206    void verify_get_clip_info (gpgme_signature_t sig,
207                               char **r_header, char **r_footer);
208    
209  /* Dialog box procedure for the clipboard editor. */  /* Dialog box procedure for the clipboard editor. */
210  BOOL CALLBACK  BOOL CALLBACK
211  clip_edit_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  clip_edit_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
212  {  {
213        char *head=NULL, *foot=NULL;
214    
215      switch (msg)  {      switch (msg)  {
216      case WM_INITDIALOG:      case WM_INITDIALOG:
217          SetWindowText (dlg, _("Clipboard Editor"));          SetWindowText (dlg, _("Clipboard Editor"));
# Line 182  clip_edit_dlg_proc (HWND dlg, UINT msg, Line 219  clip_edit_dlg_proc (HWND dlg, UINT msg,
219          SetDlgItemText (dlg, IDC_CLIPEDIT_CLEAR, _("Clea&r"));          SetDlgItemText (dlg, IDC_CLIPEDIT_CLEAR, _("Clea&r"));
220          SetDlgItemText (dlg, IDC_CLIPEDIT_LOAD, _("&Load"));              SetDlgItemText (dlg, IDC_CLIPEDIT_LOAD, _("&Load"));    
221          SetDlgItemText (dlg, IDC_CLIPEDIT_SAVE, _("&Save"));          SetDlgItemText (dlg, IDC_CLIPEDIT_SAVE, _("&Save"));
222            SetDlgItemText (dlg, IDC_CLIPEDIT_QUOTE, _("Add quotes"));
223          load_clipboard (dlg);          SetDlgItemText (dlg, IDOK, _("&Close"));
224            /* If there is a param, we expect a signature and initialize
225               the header and footer variable accordingly. */
226            if (lparam)
227                verify_get_clip_info ((gpgme_signature_t)lparam, &head, &foot);
228            load_clipboard (dlg, head, foot);
229            free_if_alloc (head);
230            free_if_alloc (foot);
231          center_window (dlg, NULL);          center_window (dlg, NULL);
232          SetForegroundWindow (dlg);          SetForegroundWindow (dlg);
233          return TRUE;          return TRUE;
234            
235      case WM_SYSCOMMAND:      case WM_HELP:
236          if (LOWORD (wparam) == SC_CLOSE)          html_help_dispatch (lparam, "winpt.chm::winpt_texts.txt", help_arr);
237              EndDialog (dlg, TRUE);          break;
         return TRUE;  
238                    
239      case WM_COMMAND:      case WM_COMMAND:
240          switch (LOWORD (wparam)) {          switch (LOWORD (wparam)) {
241            case IDCANCEL:
242                EndDialog (dlg, FALSE);
243                return TRUE;
244    
245          case IDOK:                        case IDOK:              
246              EndDialog (dlg, TRUE);              EndDialog (dlg, TRUE);
247              return TRUE;              return TRUE;
# Line 228  clip_edit_dlg_proc (HWND dlg, UINT msg, Line 275  clip_edit_dlg_proc (HWND dlg, UINT msg,
275                            
276          case IDC_CLIPEDIT_LOAD:          case IDC_CLIPEDIT_LOAD:
277              if (!load_clipboard_from_file (dlg)) {              if (!load_clipboard_from_file (dlg)) {
278                  /* XXX: for some files the code produces a crash! */                  CheckDlgButton (dlg, IDC_CLIPEDIT_QUOTE, BST_UNCHECKED);
279                  PostMessage (dlg, WM_COMMAND, MAKEWPARAM(IDC_CLIPEDIT_SEND, 0), NULL);                  PostMessage (dlg, WM_COMMAND, MAKEWPARAM (IDC_CLIPEDIT_SEND, 0), 0);
280              }              }
281              return TRUE;              return TRUE;
282                            
# Line 242  clip_edit_dlg_proc (HWND dlg, UINT msg, Line 289  clip_edit_dlg_proc (HWND dlg, UINT msg,
289            
290      return FALSE;      return FALSE;
291  }  }
   

Legend:
Removed from v.36  
changed lines
  Added in v.229

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26