/[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 120 by twoaday, Fri Dec 9 14:27:59 2005 UTC revision 231 by twoaday, Tue Jun 20 09:18:44 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"
40                                                                                    
41  static DWORD help_arr[] = {  static DWORD help_arr[] = {
42          IDC_CLIPEDIT_SEND,  WPT_CLIPEDIT_COPY,      IDC_CLIPEDIT_SEND,  WPT_CLIPEDIT_COPY,
43          IDC_CLIPEDIT_CLEAR, WPT_CLIPEDIT_CLEAR,      IDC_CLIPEDIT_CLEAR, WPT_CLIPEDIT_CLEAR,
44          IDC_CLIPEDIT_LOAD,  WPT_CLIPEDIT_LOAD,      IDC_CLIPEDIT_LOAD,  WPT_CLIPEDIT_LOAD,
45          IDC_CLIPEDIT_SAVE,  WPT_CLIPEDIT_SAVE,      IDC_CLIPEDIT_SAVE,  WPT_CLIPEDIT_SAVE,
46          IDC_CLIPEDIT_QUOTE, WPT_CLIPEDIT_QUOTE,      IDC_CLIPEDIT_QUOTE, WPT_CLIPEDIT_QUOTE,
47          0, 0      0, 0};
 };  
48  #endif  #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 77  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;
90    
91            len = strlen (header) + strlen (footer) + strlen (fmt) + strlen (p);
92            pp = new char[len + 1];
93            if (!pp)
94                BUG (0);
95            _snprintf (pp, len, fmt, header, p, footer);
96            SetDlgItemText (dlg, IDC_CLIPEDIT_CLIPTEXT2, pp);
97            free_if_alloc (pp);
98        }
99        else
100            SetDlgItemText (dlg, IDC_CLIPEDIT_CLIPTEXT2, p);
101      free_if_alloc (p);      free_if_alloc (p);
       
102      return 0;      return 0;
103  }  }
104    
# Line 97  load_clipboard_from_file (HWND dlg) Line 115  load_clipboard_from_file (HWND dlg)
115      int id;      int id;
116    
117      memset (&open, 0, sizeof (open));      memset (&open, 0, sizeof (open));
118      open.lStructSize = sizeof (OPENFILENAME);            open.lStructSize = sizeof (OPENFILENAME);
119      open.hInstance = glob_hinst;                  open.hInstance = glob_hinst;
120      open.lpstrTitle = _("File Open");            open.lpstrTitle = _("File Open");
121      open.lpstrFilter = (char *)_("All Files (*.*)\0*.*\0\0");            open.lpstrFilter = "All Files (*.*)\0*.*\0\0";
122      open.hwndOwner = dlg;                open.hwndOwner = dlg;          
123      open.lpstrFile = file;                        open.lpstrFile = file;                  
124      open.nMaxFile = sizeof (file)-1;                      open.nMaxFile = sizeof (file)-1;                
125      open.Flags = OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST;      open.Flags = OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST;
126                            
127      if (GetOpenFileName (&open)) {      if (GetOpenFileName (&open)) {
128          if( (size=get_file_size (file)) > MAX_CLIPTEXT_SIZE) {                if( (size=get_file_size (file)) > MAX_CLIPTEXT_SIZE) {
129              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"
130                                   "Still proceed?"), _("Clipboard"),                                   "Still proceed?"), _("Clipboard"),
131                            MB_INFO|MB_YESNO);                            MB_INFO|MB_YESNO);
# Line 123  load_clipboard_from_file (HWND dlg) Line 141  load_clipboard_from_file (HWND dlg)
141          p = new char[size+1];          p = new char[size+1];
142          if (!p)          if (!p)
143              BUG (0);              BUG (0);
144          fread (p, 1, size, fp);          memset (p, 0, size+1);
145          p[size] = '\0';          size = fread (p, 1, size, fp);
146          fclose (fp);          fclose (fp);
147          SetDlgItemText (dlg, IDC_CLIPEDIT_CLIPTEXT2, p);                  SetDlgItemText (dlg, IDC_CLIPEDIT_CLIPTEXT2, p);        
148          free_if_alloc (p);          free_if_alloc (p);
# Line 148  save_clipboard_to_file (HWND dlg) Line 166  save_clipboard_to_file (HWND dlg)
166      save.lStructSize = sizeof (OPENFILENAME);            save.lStructSize = sizeof (OPENFILENAME);      
167      save.hInstance = glob_hinst;                  save.hInstance = glob_hinst;            
168      save.lpstrTitle = _("File Save");            save.lpstrTitle = _("File Save");      
169      save.lpstrFile = (char *)_("All Files (*.*)\0*.*\0\0");              save.lpstrFile = (char *)"All Files (*.*)\0*.*\0\0";
170      save.hwndOwner = dlg;                        save.hwndOwner = dlg;                  
171      save.lpstrFile = file;                        save.lpstrFile = file;                  
172      save.nMaxFile = sizeof (file) - 1;      save.nMaxFile = sizeof (file) - 1;
173      save.Flags = OFN_OVERWRITEPROMPT;      save.Flags = OFN_OVERWRITEPROMPT;
174                        
175      if( GetSaveFileName( &save ) ) {      if (GetSaveFileName (&save)) {
176          if( file_exist_check( file ) == 0 ) {                if (file_exist_check (file) == 0) {
177              id = log_box (_("Clipboard"), MB_YESNO,              id = log_box (_("Clipboard"), MB_YESNO,
178                            _("\"%s\" already exists.\n"                            _("\"%s\" already exists.\n"
179                              "Replace existing file?"), file);                                    "Replace existing file?"), file);      
# Line 186  save_clipboard_to_file (HWND dlg) Line 204  save_clipboard_to_file (HWND dlg)
204  }  }
205    
206    
207    void verify_get_clip_info (gpgme_signature_t sig,
208                               char **r_header, char **r_footer);
209    
210  /* Dialog box procedure for the clipboard editor. */  /* Dialog box procedure for the clipboard editor. */
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    
216      switch (msg)  {      switch (msg)  {
217      case WM_INITDIALOG:      case WM_INITDIALOG:
218            /* XXX: it would be really nice to have tempest prevention fonts. */
219          SetWindowText (dlg, _("Clipboard Editor"));          SetWindowText (dlg, _("Clipboard Editor"));
220          SetDlgItemText (dlg, IDC_CLIPEDIT_SEND, _("&Copy"));          SetDlgItemText (dlg, IDC_CLIPEDIT_SEND, _("&Copy"));
221          SetDlgItemText (dlg, IDC_CLIPEDIT_CLEAR, _("Clea&r"));          SetDlgItemText (dlg, IDC_CLIPEDIT_CLEAR, _("Clea&r"));
222          SetDlgItemText (dlg, IDC_CLIPEDIT_LOAD, _("&Load"));              SetDlgItemText (dlg, IDC_CLIPEDIT_LOAD, _("&Load"));    
223          SetDlgItemText (dlg, IDC_CLIPEDIT_SAVE, _("&Save"));          SetDlgItemText (dlg, IDC_CLIPEDIT_SAVE, _("&Save"));
224          SetDlgItemText (dlg, IDC_CLIPEDIT_QUOTE, _("Add quotes"));          SetDlgItemText (dlg, IDC_CLIPEDIT_QUOTE, _("Add quotes"));
225          SetDlgItemText (dlg, IDOK, _("&Exit"));          SetDlgItemText (dlg, IDOK, _("&Close"));
226            /* If there is a param, we expect a signature and initialize
227          load_clipboard (dlg);             the header and footer variable accordingly. */
228            if (lparam)
229                verify_get_clip_info ((gpgme_signature_t)lparam, &head, &foot);
230            load_clipboard (dlg, head, foot);
231            free_if_alloc (head);
232            free_if_alloc (foot);
233          center_window (dlg, NULL);          center_window (dlg, NULL);
234          SetForegroundWindow (dlg);          SetForegroundWindow (dlg);
235          return TRUE;          return TRUE;
236            
237      case WM_SYSCOMMAND:      case WM_HELP:
238          if (LOWORD (wparam) == SC_CLOSE)          html_help_dispatch (lparam, "winpt.chm::winpt_texts.txt", help_arr);
239              EndDialog (dlg, TRUE);          break;
         return TRUE;  
240                    
241      case WM_COMMAND:      case WM_COMMAND:
242          switch (LOWORD (wparam)) {          switch (LOWORD (wparam)) {
243            case IDCANCEL:
244                EndDialog (dlg, FALSE);
245                return TRUE;
246    
247          case IDOK:                        case IDOK:              
248              EndDialog (dlg, TRUE);              EndDialog (dlg, TRUE);
249              return TRUE;              return TRUE;
# Line 245  clip_edit_dlg_proc (HWND dlg, UINT msg, Line 277  clip_edit_dlg_proc (HWND dlg, UINT msg,
277                            
278          case IDC_CLIPEDIT_LOAD:          case IDC_CLIPEDIT_LOAD:
279              if (!load_clipboard_from_file (dlg)) {              if (!load_clipboard_from_file (dlg)) {
280                  /* XXX: for some files the code produces a crash! */                  CheckDlgButton (dlg, IDC_CLIPEDIT_QUOTE, BST_UNCHECKED);
281                  PostMessage (dlg, WM_COMMAND, MAKEWPARAM(IDC_CLIPEDIT_SEND, 0), 0);                  PostMessage (dlg, WM_COMMAND, MAKEWPARAM (IDC_CLIPEDIT_SEND, 0), 0);
282              }              }
283              return TRUE;              return TRUE;
284                            

Legend:
Removed from v.120  
changed lines
  Added in v.231

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26