/[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 174 by twoaday, Thu Feb 2 08:20:50 2006 UTC revision 236 by twoaday, Wed Jun 28 06:59:30 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 31  Line 31 
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  #ifdef _MSC_VER
39  #include "winpt_header.h"  #include "winpt_header.h"
# Line 44  static DWORD help_arr[] = { Line 47  static DWORD help_arr[] = {
47      0, 0};      0, 0};
48  #endif  #endif
49    
50    
51    void verify_get_clip_info (gpgme_signature_t sig,
52                               char **r_header, char **r_footer);
53    
54    
55  /* Load the clipboard contents into the text field in @dlg.  /* Load the clipboard contents into the text field in @dlg.
56       Optinally @header and @footer can be used to set a header and footer.
57     Return value: 0 on success. */     Return value: 0 on success. */
58  static int  static int
59  load_clipboard (HWND dlg)  load_clipboard (HWND dlg,
60                    const char *header, const char *footer)
61  {  {
62      HANDLE clipmem;      HANDLE clipmem;
63      char *cliptext;      char *cliptext;
64      char *p;      char *p, *pp;
65    
66      CloseClipboard (); /* make sure it is closed. */      CloseClipboard (); /* make sure it is closed. */
67      if (OpenClipboard (NULL) == FALSE) {      if (OpenClipboard (NULL) == FALSE) {
# Line 76  load_clipboard (HWND dlg) Line 86  load_clipboard (HWND dlg)
86      strcpy (p, cliptext);      strcpy (p, cliptext);
87            
88      GlobalUnlock (clipmem);      GlobalUnlock (clipmem);
89      CloseClipboard ();        CloseClipboard ();
90      SetDlgItemText (dlg, IDC_CLIPEDIT_CLIPTEXT2, p);      
91        if (header && footer) {
92            const char *fmt = "%s\r\n%s\r\n%s";
93            int len;
94    
95            len = strlen (header) + strlen (footer) + strlen (fmt) + strlen (p);
96            pp = new char[len + 1];
97            if (!pp)
98                BUG (0);
99            _snprintf (pp, len, fmt, header, p, footer);
100            SetDlgItemText (dlg, IDC_CLIPEDIT_CLIPTEXT2, pp);
101            free_if_alloc (pp);
102        }
103        else
104            SetDlgItemText (dlg, IDC_CLIPEDIT_CLIPTEXT2, p);
105      free_if_alloc (p);      free_if_alloc (p);
       
106      return 0;      return 0;
107  }  }
108    
# Line 96  load_clipboard_from_file (HWND dlg) Line 119  load_clipboard_from_file (HWND dlg)
119      int id;      int id;
120    
121      memset (&open, 0, sizeof (open));      memset (&open, 0, sizeof (open));
122      open.lStructSize = sizeof (OPENFILENAME);            open.lStructSize = sizeof (OPENFILENAME);
123      open.hInstance = glob_hinst;                  open.hInstance = glob_hinst;
124      open.lpstrTitle = _("File Open");            open.lpstrTitle = _("File Open");
125      open.lpstrFilter = (char *)"All Files (*.*)\0*.*\0\0";      open.lpstrFilter = "All Files (*.*)\0*.*\0\0";
126      open.hwndOwner = dlg;                open.hwndOwner = dlg;          
127      open.lpstrFile = file;                        open.lpstrFile = file;                  
128      open.nMaxFile = sizeof (file)-1;                      open.nMaxFile = sizeof (file)-1;                
129      open.Flags = OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST;      open.Flags = OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST;
130                            
131      if (GetOpenFileName (&open)) {      if (GetOpenFileName (&open)) {
132          if( (size=get_file_size (file)) > MAX_CLIPTEXT_SIZE) {                if( (size=get_file_size (file)) > MAX_CLIPTEXT_SIZE) {
133              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"
134                                   "Still proceed?"), _("Clipboard"),                                   "Still proceed?"), _("Clipboard"),
135                            MB_INFO|MB_YESNO);                            MB_INFO|MB_YESNO);
# Line 117  load_clipboard_from_file (HWND dlg) Line 140  load_clipboard_from_file (HWND dlg)
140          if (!fp) {          if (!fp) {
141              msg_box (dlg, winpt_strerror (WPTERR_FILE_OPEN),              msg_box (dlg, winpt_strerror (WPTERR_FILE_OPEN),
142                       _("Clipboard"), MB_ERR);                       _("Clipboard"), MB_ERR);
143              return FALSE;              return -1;
144          }          }
145          p = new char[size+1];          p = new char[size+1];
146          if (!p)          if (!p)
147              BUG (0);              BUG (0);
148          fread (p, 1, size, fp);          memset (p, 0, size+1);
149          p[size] = '\0';          size = fread (p, 1, size, fp);
150          fclose (fp);          fclose (fp);
151          SetDlgItemText (dlg, IDC_CLIPEDIT_CLIPTEXT2, p);                  SetDlgItemText (dlg, IDC_CLIPEDIT_CLIPTEXT2, p);        
152          free_if_alloc (p);          free_if_alloc (p);
# Line 147  save_clipboard_to_file (HWND dlg) Line 170  save_clipboard_to_file (HWND dlg)
170      save.lStructSize = sizeof (OPENFILENAME);            save.lStructSize = sizeof (OPENFILENAME);      
171      save.hInstance = glob_hinst;                  save.hInstance = glob_hinst;            
172      save.lpstrTitle = _("File Save");            save.lpstrTitle = _("File Save");      
173      save.lpstrFile = (char *)"All Files (*.*)\0*.*\0\0";      save.lpstrFile = "All Files (*.*)\0*.*\0\0";
174      save.hwndOwner = dlg;                        save.hwndOwner = dlg;
175      save.lpstrFile = file;                        save.lpstrFile = file;
176      save.nMaxFile = sizeof (file) - 1;      save.nMaxFile = sizeof (file) - 1;
177      save.Flags = OFN_OVERWRITEPROMPT;      save.Flags = OFN_OVERWRITEPROMPT;
178                        
179      if( GetSaveFileName( &save ) ) {      if (GetSaveFileName (&save)) {
180          if( file_exist_check( file ) == 0 ) {                if (file_exist_check (file) == 0) {
181              id = log_box (_("Clipboard"), MB_YESNO,              id = log_box (_("Clipboard"), MB_YESNO,
182                            _("\"%s\" already exists.\n"                            _("\"%s\" already exists.\n"
183                              "Replace existing file?"), file);                                    "Replace existing file?"), file);      
184              if( id == IDNO )                  if (id == IDNO)    
185                  return FALSE;                  return -1;
186          }          }
187          fp = fopen (file, "wb");          fp = fopen (file, "wb");
188          if (!fp) {          if (!fp) {
189              msg_box (dlg, winpt_strerror (WPTERR_FILE_CREAT),              msg_box (dlg, winpt_strerror (WPTERR_FILE_CREAT),
190                       _("Clipboard"), MB_ERR);                       _("Clipboard"), MB_ERR);
191              return FALSE;              return -1;
192          }          }
         /* XXX: there is a NUL-byte at the end. */  
193          nbytes = SendDlgItemMessage (dlg, IDC_CLIPEDIT_CLIPTEXT2,          nbytes = SendDlgItemMessage (dlg, IDC_CLIPEDIT_CLIPTEXT2,
194                                       WM_GETTEXTLENGTH, 0, 0);                                       WM_GETTEXTLENGTH, 0, 0);
195          if (nbytes > 0) {          if (nbytes > 0) {
# Line 189  save_clipboard_to_file (HWND dlg) Line 211  save_clipboard_to_file (HWND dlg)
211  BOOL CALLBACK  BOOL CALLBACK
212  clip_edit_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  clip_edit_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
213  {  {
214        char *head=NULL, *foot=NULL;
215        gpgme_data_t txt;
216    
217      switch (msg)  {      switch (msg)  {
218      case WM_INITDIALOG:      case WM_INITDIALOG:
219            /* XXX: it would be really nice to have tempest prevention fonts. */
220          SetWindowText (dlg, _("Clipboard Editor"));          SetWindowText (dlg, _("Clipboard Editor"));
221          SetDlgItemText (dlg, IDC_CLIPEDIT_SEND, _("&Copy"));          SetDlgItemText (dlg, IDC_CLIPEDIT_SEND, _("&Copy"));
222          SetDlgItemText (dlg, IDC_CLIPEDIT_CLEAR, _("Clea&r"));          SetDlgItemText (dlg, IDC_CLIPEDIT_CLEAR, _("Clea&r"));
223          SetDlgItemText (dlg, IDC_CLIPEDIT_LOAD, _("&Load"));              SetDlgItemText (dlg, IDC_CLIPEDIT_LOAD, _("&Load"));    
224          SetDlgItemText (dlg, IDC_CLIPEDIT_SAVE, _("&Save"));          SetDlgItemText (dlg, IDC_CLIPEDIT_SAVE, _("&Save"));
225          SetDlgItemText (dlg, IDC_CLIPEDIT_QUOTE, _("Add quotes"));          SetDlgItemText (dlg, IDC_CLIPEDIT_QUOTE, _("&Quote"));
226          SetDlgItemText (dlg, IDOK, _("&Close"));          SetDlgItemText (dlg, IDOK, _("&Close"));
227    
228          load_clipboard (dlg);          /* If there is a param, we expect a signature and initialize
229               the header and footer variable accordingly. */
230            if (lparam)
231                verify_get_clip_info ((gpgme_signature_t)lparam, &head, &foot);
232            load_clipboard (dlg, head, foot);
233            free_if_alloc (head);
234            free_if_alloc (foot);
235          center_window (dlg, NULL);          center_window (dlg, NULL);
236          SetForegroundWindow (dlg);          SetForegroundWindow (dlg);
237          return TRUE;          return TRUE;
238            
239      case WM_HELP:      case WM_HELP:
240          html_help_dispatch (lparam, "winpt.chm::winpt_texts.txt", help_arr);          html_help_dispatch (lparam, "winpt.chm::winpt_texts.txt", help_arr);
241          break;          break;
   
     case WM_SYSCOMMAND:  
         if (LOWORD (wparam) == SC_CLOSE)  
             EndDialog (dlg, TRUE);  
         return TRUE;  
242                    
243      case WM_COMMAND:      case WM_COMMAND:
244          switch (LOWORD (wparam)) {          switch (LOWORD (wparam)) {
245            case IDCANCEL:
246                EndDialog (dlg, FALSE);
247                return TRUE;
248    
249          case IDOK:                        case IDOK:              
250              EndDialog (dlg, TRUE);              EndDialog (dlg, TRUE);
251              return TRUE;              return TRUE;
252                            
253          case IDC_CLIPEDIT_SEND:          case IDC_CLIPEDIT_QUOTE:
254              if (IsDlgButtonChecked (dlg, IDC_CLIPEDIT_QUOTE)) {              if (gpg_data_new_from_clipboard (&txt, 0))
                 gpgme_data_t txt;  
                 gpg_data_new_from_clipboard (&txt, 0);  
                 gpg_data_mail_quote (&txt);  
                 gpg_data_release_and_set_clipboard (txt, 0);  
                 SendMessage (dlg, WM_INITDIALOG, 0, 0);  
255                  return TRUE;                  return TRUE;
256              }              gpg_data_mail_quote (&txt);
257                gpg_data_release_and_set_clipboard (txt, 0);
258                load_clipboard (dlg, head, foot);
259                return TRUE;
260    
261            case IDC_CLIPEDIT_SEND:
262              SendDlgItemMessage (dlg, IDC_CLIPEDIT_CLIPTEXT2, EM_SETSEL, 0, -1);              SendDlgItemMessage (dlg, IDC_CLIPEDIT_CLIPTEXT2, EM_SETSEL, 0, -1);
263              SendDlgItemMessage (dlg, IDC_CLIPEDIT_CLIPTEXT2, WM_COPY, 0, 0);              SendDlgItemMessage (dlg, IDC_CLIPEDIT_CLIPTEXT2, WM_COPY, 0, 0);
264              return TRUE;              return TRUE;
# Line 247  clip_edit_dlg_proc (HWND dlg, UINT msg, Line 278  clip_edit_dlg_proc (HWND dlg, UINT msg,
278              return TRUE;              return TRUE;
279                            
280          case IDC_CLIPEDIT_LOAD:          case IDC_CLIPEDIT_LOAD:
281              if (!load_clipboard_from_file (dlg)) {              if (!load_clipboard_from_file (dlg))
282                  /* XXX: for some files the code produces a crash! */                  PostMessage (dlg, WM_COMMAND, MAKEWPARAM (IDC_CLIPEDIT_SEND, 0), 0);
                 PostMessage (dlg, WM_COMMAND, MAKEWPARAM(IDC_CLIPEDIT_SEND, 0), 0);  
             }  
283              return TRUE;              return TRUE;
284                            
285          case IDC_CLIPEDIT_SAVE:          case IDC_CLIPEDIT_SAVE:

Legend:
Removed from v.174  
changed lines
  Added in v.236

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26