/[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 32 by twoaday, Mon Oct 24 08:03:48 2005 UTC revision 48 by werner, Mon Oct 31 21:14:11 2005 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-2005 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
6   * WinPT is free software; you can redistribute it and/or modify   * WinPT is free software; you can redistribute it and/or modify
7   * it under the terms of the GNU General Public License as published by   * it under the terms of the GNU General Public License as published by
8   * the Free Software Foundation; either version 2 of the License, or   * the Free Software Foundation; either version 2 of the License, or
9   * (at your option) any later version.   * (at your option) any later version.
10   *   *
11   * WinPT is distributed in the hope that it will be useful,   * WinPT is distributed in the hope that it will be useful,
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.
15   *   *
16   * You should have received a copy of the GNU General Public License   * You should have received a copy of the GNU General Public License
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    
21  #include <windows.h>  #ifdef HAVE_CONFIG_H
22  #include <stdio.h>  #include <config.h>
23    #endif
24  #include "wptTypes.h"  
25  #include "wptW32API.h"  #include <windows.h>
26  #include "wptVersion.h"  #include <stdio.h>
27  #include "wptErrors.h"  
28  #include "wptGPG.h"  #include "wptTypes.h"
29  #include "wptNLS.h"  #include "wptW32API.h"
30  #include "../resource.h"  #include "wptVersion.h"
31    #include "wptErrors.h"
32    #include "wptGPG.h"
33  /* Load the clipboard contents into the text field in @dlg.  #include "wptNLS.h"
34     Return value: 0 on success. */  #include "resource.h"
35  static int  
36  load_clipboard (HWND dlg)  
37  {  /* Load the clipboard contents into the text field in @dlg.
38      HANDLE clipmem;     Return value: 0 on success. */
39      char *cliptext;  static int
40      char *p;  load_clipboard (HWND dlg)
41    {
42      CloseClipboard (); /* make sure it is closed. */      HANDLE clipmem;
43      if (OpenClipboard (NULL) == FALSE) {      char *cliptext;
44          msg_box (dlg, winpt_strerror (WPTERR_CLIP_OPEN), _("Clipboard"), MB_ERR);      char *p;
45          return -1;  
46      }      CloseClipboard (); /* make sure it is closed. */
47      clipmem = GetClipboardData (CF_TEXT);      if (OpenClipboard (NULL) == FALSE) {
48      if (clipmem == NULL) {          msg_box (dlg, winpt_strerror (WPTERR_CLIP_OPEN), _("Clipboard"), MB_ERR);
49          CloseClipboard ();          return -1;
50          return -1;      }
51      }      clipmem = GetClipboardData (CF_TEXT);
52            if (clipmem == NULL) {
53      cliptext = (char *) GlobalLock (clipmem);          CloseClipboard ();
54      if (cliptext == NULL || !strlen (cliptext)) {              return -1;
55          CloseClipboard ();      }
56          return -1;      
57      }      cliptext = (char *) GlobalLock (clipmem);
58        if (cliptext == NULL || !strlen (cliptext)) {    
59      p = new char [strlen (cliptext)+2];          CloseClipboard ();
60      if (!p)              return -1;
61          BUG (0);              }
62      strcpy (p, cliptext);  
63            p = new char [strlen (cliptext)+2];
64      GlobalUnlock (clipmem);      if (!p)    
65      CloseClipboard ();            BUG (0);        
66      SetDlgItemText (dlg, IDC_CLIPEDIT_CLIPTEXT2, p);          strcpy (p, cliptext);
67      free_if_alloc (p);      
68            GlobalUnlock (clipmem);
69      return 0;      CloseClipboard ();  
70  }      SetDlgItemText (dlg, IDC_CLIPEDIT_CLIPTEXT2, p);    
71        free_if_alloc (p);
72        
73  /* Load the clipboard from the selected file. */      return 0;
74  static int  }
75  load_clipboard_from_file (HWND dlg)  
76  {  
77      OPENFILENAME open;  /* Load the clipboard from the selected file. */
78      FILE *fp;  static int
79      char *p;  load_clipboard_from_file (HWND dlg)
80      char file[300] = "";  {
81      DWORD size;      OPENFILENAME open;
82      int id;      FILE *fp;
83        char *p;
84      memset (&open, 0, sizeof (open));      char file[300] = "";
85      open.lStructSize = sizeof (OPENFILENAME);            DWORD size;
86      open.hInstance = glob_hinst;                  int id;
87      open.lpstrTitle = _("File Open");        
88      open.lpstrFilter = (char *)_("All Files (*.*)\0*.*\0\0");            memset (&open, 0, sizeof (open));
89      open.hwndOwner = dlg;                open.lStructSize = sizeof (OPENFILENAME);      
90      open.lpstrFile = file;                        open.hInstance = glob_hinst;            
91      open.nMaxFile = sizeof (file)-1;                      open.lpstrTitle = _("File Open");      
92      open.Flags = OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST;      open.lpstrFilter = (char *)_("All Files (*.*)\0*.*\0\0");      
93                    open.hwndOwner = dlg;          
94      if (GetOpenFileName (&open)) {      open.lpstrFile = file;                  
95          if( (size=get_file_size (file)) > MAX_CLIPTEXT_SIZE) {            open.nMaxFile = sizeof (file)-1;                
96              id = msg_box (dlg, _("The file you want to add is very large.\n"      open.Flags = OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST;
97                                   "Still proceed?"), _("Clipboard"), MB_INFO|MB_YESNO);                    
98              if (id == IDNO)          if (GetOpenFileName (&open)) {
99                  return -1;          if( (size=get_file_size (file)) > MAX_CLIPTEXT_SIZE) {      
100          }              id = msg_box (dlg, _("The file you want to add is very large.\n"
101          fp = fopen (file, "rb");                                   "Still proceed?"), _("Clipboard"), MB_INFO|MB_YESNO);      
102          if (!fp) {              if (id == IDNO)    
103              msg_box (dlg, winpt_strerror (WPTERR_FILE_OPEN), _("Clipboard"), MB_ERR);                  return -1;
104              return FALSE;          }
105          }          fp = fopen (file, "rb");
106          p = new char[size+1];          if (!fp) {
107          if (!p)              msg_box (dlg, winpt_strerror (WPTERR_FILE_OPEN), _("Clipboard"), MB_ERR);
108              BUG (0);              return FALSE;
109          fread (p, 1, size, fp);          }
110          p[size] = '\0';          p = new char[size+1];
111          fclose (fp);          if (!p)
112          SetDlgItemText (dlg, IDC_CLIPEDIT_CLIPTEXT2, p);                      BUG (0);
113          free_if_alloc (p);          fread (p, 1, size, fp);
114      }          p[size] = '\0';
115      return 0;          fclose (fp);
116  }          SetDlgItemText (dlg, IDC_CLIPEDIT_CLIPTEXT2, p);        
117            free_if_alloc (p);
118        }
119  /* Save the contents of the clipboard to the selected file. */      return 0;
120  static int  }
121  save_clipboard_to_file (HWND dlg)  
122  {  
123      OPENFILENAME save;  /* Save the contents of the clipboard to the selected file. */
124      FILE *fp;  static int
125      char *p;  save_clipboard_to_file (HWND dlg)
126      char file[300] = "";  {
127      DWORD nbytes;      OPENFILENAME save;
128      int id;      FILE *fp;
129        char *p;
130      memset (&save, 0, sizeof (save));            char file[300] = "";
131      save.lStructSize = sizeof (OPENFILENAME);            DWORD nbytes;
132      save.hInstance = glob_hinst;                  int id;
133      save.lpstrTitle = _("File Save");        
134      save.lpstrFile = (char *)_("All Files (*.*)\0*.*\0\0");              memset (&save, 0, sizeof (save));      
135      save.hwndOwner = dlg;                        save.lStructSize = sizeof (OPENFILENAME);      
136      save.lpstrFile = file;                        save.hInstance = glob_hinst;            
137      save.nMaxFile = sizeof (file) - 1;      save.lpstrTitle = _("File Save");      
138      save.Flags = OFN_OVERWRITEPROMPT;      save.lpstrFile = (char *)_("All Files (*.*)\0*.*\0\0");        
139                            save.hwndOwner = dlg;                  
140      if( GetSaveFileName( &save ) ) {      save.lpstrFile = file;                  
141          if( file_exist_check( file ) == 0 ) {            save.nMaxFile = sizeof (file) - 1;
142              id = log_box (_("Clipboard"), MB_YESNO,      save.Flags = OFN_OVERWRITEPROMPT;
143                            _("\"%s\" already exists.\n"                      
144                              "Replace existing file?"), file);            if( GetSaveFileName( &save ) ) {
145              if( id == IDNO )              if( file_exist_check( file ) == 0 ) {      
146                  return FALSE;              id = log_box (_("Clipboard"), MB_YESNO,
147          }                            _("\"%s\" already exists.\n"
148          fp = fopen (file, "wb");                              "Replace existing file?"), file);      
149          if (!fp) {              if( id == IDNO )    
150              msg_box (dlg, winpt_strerror (WPTERR_FILE_CREAT), _("Clipboard"), MB_ERR);                  return FALSE;
151              return FALSE;          }
152          }          fp = fopen (file, "wb");
153          /* XXX: there is a NUL-byte at the end. */          if (!fp) {
154          nbytes = SendDlgItemMessage (dlg, IDC_CLIPEDIT_CLIPTEXT2, WM_GETTEXTLENGTH, 0, 0);              msg_box (dlg, winpt_strerror (WPTERR_FILE_CREAT), _("Clipboard"), MB_ERR);
155          if (nbytes > 0) {              return FALSE;
156              p = new char[nbytes+1];          }
157              if (!p)          /* XXX: there is a NUL-byte at the end. */
158                  BUG (NULL);          nbytes = SendDlgItemMessage (dlg, IDC_CLIPEDIT_CLIPTEXT2, WM_GETTEXTLENGTH, 0, 0);
159              GetDlgItemText (dlg, IDC_CLIPEDIT_CLIPTEXT2, p, nbytes);          if (nbytes > 0) {
160              fwrite (p, 1, nbytes, fp);              p = new char[nbytes+1];
161          }                        if (!p)
162          fclose (fp);                  BUG (NULL);
163          free_if_alloc (p);              GetDlgItemText (dlg, IDC_CLIPEDIT_CLIPTEXT2, p, nbytes);
164      }              fwrite (p, 1, nbytes, fp);
165      return 0;          }          
166  }          fclose (fp);
167            free_if_alloc (p);
168        }
169  /* Dialog box procedure for the clipboard editor. */      return 0;
170  BOOL CALLBACK  }
171  clip_edit_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  
172  {  
173      switch (msg)  {  /* Dialog box procedure for the clipboard editor. */
174      case WM_INITDIALOG:  BOOL CALLBACK
175          #ifndef LANG_DE  clip_edit_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
176          SetWindowText (dlg, _("Clipboard Editor"));  {
177          SetDlgItemText (dlg, IDC_CLIPEDIT_SEND, _("&Copy"));      switch (msg)  {
178          SetDlgItemText (dlg, IDC_CLIPEDIT_CLEAR, _("Clea&r"));      case WM_INITDIALOG:
179          SetDlgItemText (dlg, IDC_CLIPEDIT_LOAD, _("&Load"));              SetWindowText (dlg, _("Clipboard Editor"));
180          SetDlgItemText (dlg, IDC_CLIPEDIT_SAVE, _("&Save"));          SetDlgItemText (dlg, IDC_CLIPEDIT_SEND, _("&Copy"));
181          #endif          SetDlgItemText (dlg, IDC_CLIPEDIT_CLEAR, _("Clea&r"));
182          load_clipboard (dlg);          SetDlgItemText (dlg, IDC_CLIPEDIT_LOAD, _("&Load"));    
183          center_window (dlg, NULL);          SetDlgItemText (dlg, IDC_CLIPEDIT_SAVE, _("&Save"));
184          SetForegroundWindow (dlg);  
185          return TRUE;          load_clipboard (dlg);
186                    center_window (dlg, NULL);
187      case WM_SYSCOMMAND:          SetForegroundWindow (dlg);
188          if (LOWORD (wparam) == SC_CLOSE)          return TRUE;
189              EndDialog (dlg, TRUE);          
190          return TRUE;      case WM_SYSCOMMAND:
191                    if (LOWORD (wparam) == SC_CLOSE)
192      case WM_COMMAND:              EndDialog (dlg, TRUE);
193          switch (LOWORD (wparam)) {          return TRUE;
194          case IDOK:                        
195              EndDialog (dlg, TRUE);      case WM_COMMAND:
196              return TRUE;          switch (LOWORD (wparam)) {
197                        case IDOK:              
198          case IDC_CLIPEDIT_SEND:              EndDialog (dlg, TRUE);
199              if (IsDlgButtonChecked (dlg, IDC_CLIPEDIT_QUOTE)) {              return TRUE;
200                  gpgme_data_t txt;              
201                  gpg_data_new_from_clipboard (&txt, 0);          case IDC_CLIPEDIT_SEND:
202                  gpg_data_mail_quote (&txt);              if (IsDlgButtonChecked (dlg, IDC_CLIPEDIT_QUOTE)) {
203                  gpg_data_release_and_set_clipboard (txt, 0);                  gpgme_data_t txt;
204                  SendMessage (dlg, WM_INITDIALOG, 0, 0);                  gpg_data_new_from_clipboard (&txt, 0);
205                  return TRUE;                  gpg_data_mail_quote (&txt);
206              }                  gpg_data_release_and_set_clipboard (txt, 0);
207              SendDlgItemMessage (dlg, IDC_CLIPEDIT_CLIPTEXT2, EM_SETSEL, 0, -1);                  SendMessage (dlg, WM_INITDIALOG, 0, 0);
208              SendDlgItemMessage (dlg, IDC_CLIPEDIT_CLIPTEXT2, WM_COPY, 0, 0);                  return TRUE;
209              return TRUE;              }
210                            SendDlgItemMessage (dlg, IDC_CLIPEDIT_CLIPTEXT2, EM_SETSEL, 0, -1);
211          case IDC_CLIPEDIT_CLEAR:              SendDlgItemMessage (dlg, IDC_CLIPEDIT_CLIPTEXT2, WM_COPY, 0, 0);
212              if (OpenClipboard (NULL) == FALSE) {              return TRUE;
213                  msg_box (dlg,  winpt_strerror (WPTERR_CLIP_OPEN),              
214                           _("Clipboard"), MB_ERR);          case IDC_CLIPEDIT_CLEAR:
215                  return TRUE;              if (OpenClipboard (NULL) == FALSE) {
216              }                                    msg_box (dlg,  winpt_strerror (WPTERR_CLIP_OPEN),
217              if (EmptyClipboard () == FALSE)                                       _("Clipboard"), MB_ERR);
218                  msg_box (dlg, winpt_strerror (WPTERR_CLIP_EMPTY),                  return TRUE;
219                           _("Clipboard"), MB_ERR);              }                  
220              else              if (EmptyClipboard () == FALSE)            
221                  SetDlgItemText (dlg, IDC_CLIPEDIT_CLIPTEXT2, "");                  msg_box (dlg, winpt_strerror (WPTERR_CLIP_EMPTY),
222              CloseClipboard ();                           _("Clipboard"), MB_ERR);
223              return TRUE;              else
224                                SetDlgItemText (dlg, IDC_CLIPEDIT_CLIPTEXT2, "");
225          case IDC_CLIPEDIT_LOAD:              CloseClipboard ();
226              if (!load_clipboard_from_file (dlg)) {              return TRUE;
227                  /* XXX: for some files the code produces a crash! */              
228                  PostMessage (dlg, WM_COMMAND, MAKEWPARAM(IDC_CLIPEDIT_SEND, 0), NULL);          case IDC_CLIPEDIT_LOAD:
229              }              if (!load_clipboard_from_file (dlg)) {
230              return TRUE;                  /* XXX: for some files the code produces a crash! */
231                                PostMessage (dlg, WM_COMMAND, MAKEWPARAM(IDC_CLIPEDIT_SEND, 0), NULL);
232          case IDC_CLIPEDIT_SAVE:              }
233              save_clipboard_to_file (dlg);                        return TRUE;
234              return TRUE;              
235          }          case IDC_CLIPEDIT_SAVE:
236          break;              save_clipboard_to_file (dlg);          
237      }              return TRUE;
238                }
239      return FALSE;          break;
240  }      }
241        
242        return FALSE;
243    }
244    

Legend:
Removed from v.32  
changed lines
  Added in v.48

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26