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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26