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

Diff of /trunk/Src/wptCommonDlg.cpp

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

revision 181 by twoaday, Tue Mar 14 11:01:22 2006 UTC revision 211 by twoaday, Sun May 7 12:36:48 2006 UTC
# Line 20  Line 20 
20  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
21  #include <config.h>  #include <config.h>
22  #endif  #endif
   
 #include <windows.h>  
23  #include <ctype.h>  #include <ctype.h>
24    #include <windows.h>
25    
26  #include "resource.h"  #include "resource.h"
   
27  #include "wptTypes.h"  #include "wptTypes.h"
28  #include "wptW32API.h"  #include "wptW32API.h"
29  #include "wptVersion.h"  #include "wptVersion.h"
30  #include "wptGPG.h"  #include "wptGPG.h"
31  #include "wptCommonCtl.h"  #include "wptCommonCtl.h"
32  #include "wptContext.h"  #include "wptContext.h"
33    #include "wptRegistry.h"
34    
35    
36  /* check if the given buf contains a valid URL. */  /* check if the given buf contains a valid URL. */
# Line 39  static int Line 38  static int
38  check_URL (const char *buf)  check_URL (const char *buf)
39  {  {
40      size_t i;      size_t i;
41      const char *allowed = "-./#_:";      const char *allowed = "-./#_:~&?=";
42    
     if (strncmp (buf, "http://", 7))  
         return -1;  
43      if (!strchr (buf, ':'))      if (!strchr (buf, ':'))
44          return -1;          return -1;
45      if (!strstr (buf, "//"))      if (!strstr (buf, "//"))
# Line 158  get_input_dialog (HWND root, const char Line 155  get_input_dialog (HWND root, const char
155      return m_strdup (ctx.url);      return m_strdup (ctx.url);
156  }  }
157    
 #if 0  
 struct infodlg_s {  
     const char *title;  
     const char *button_1;  
     const char *button_2;  
     const char *text;  
     HICON       ico;  
     int         retval;  
 };  
158    
159  /* Dialog box procedure for the info dialog. */  /* Initialize the language list based on the .mo files
160       found in the dirctory @modpath. */
161    static int
162    nls_load_langlist (HWND dlg, const char *modpath)
163    {
164        WIN32_FIND_DATA fnd;
165        HWND cb;
166        HANDLE hd;
167        char *pattern = NULL;    
168        int i;
169    
170        cb = GetDlgItem (dlg, IDC_LANGUAGE_LIST);
171        combox_add_string (cb, lang_list[0].name);
172        SendMessage (cb, CB_SETCURSEL, 0, 0);
173        
174        memset (&fnd, 0, sizeof (fnd));
175        pattern = make_filename (modpath, "*.mo", NULL);
176        hd = FindFirstFile (pattern, &fnd);
177        if (hd == INVALID_HANDLE_VALUE) {
178            free_if_alloc (pattern);
179            return -1;
180        }
181    
182        do {
183            for (i=0; lang_list[i].id != NULL; i++) {
184                if (!strnicmp (fnd.cFileName, lang_list[i].id, 2))
185                    combox_add_string (cb, lang_list[i].name);
186            }
187            memset (&fnd, 0, sizeof (fnd));
188        } while (FindNextFile (hd, &fnd) != FALSE);
189        FindClose (hd);
190        free_if_alloc (pattern);
191        return 0;
192    }
193    
194    
195    /* Set the default language for the program.
196       The $lang.mo file is copied either to the selected
197       folder or the directory specified by @modpath.
198       The output name of the file is winpt.mo (example: de.mo -> winpt.mo). */
199    static int
200    nls_set_language (HWND dlg, const char *modpath)
201    {
202        HWND cb = GetDlgItem (dlg, IDC_LANGUAGE_LIST);
203        int pos = SendMessage (cb, CB_GETCURSEL, 0, 0);
204        const char *folder;
205        char *src, *dst;
206    
207        /* default langauge is English. */
208        if (pos == 0 || pos == CB_ERR)
209            return 0;
210    
211        folder = get_folder_dlg (dlg, _("Choose Locale Directory"), modpath);
212        if (!folder)
213            return 0;
214    
215        src = make_filename (modpath, lang_list[pos].id, "mo");
216        dst = make_filename (folder, "winpt", "mo");
217    
218        if (!CopyFile (src, dst, FALSE)) {
219            msg_box (dlg, _("Could not create winpt.mo file"),
220                     _("WinPT Error"), MB_ERR);
221            pos = -1;
222        }
223        else
224            set_reg_entry_mo (folder);
225        free_if_alloc (src);
226        free_if_alloc (dst);
227        return pos;
228    }
229    
230    
231  static BOOL CALLBACK  static BOOL CALLBACK
232  infodlg_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  nls_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
233  {  {
234      static struct infodlg_s *ctx;      static char modpath[MAX_PATH+1];
235        int langid = 0, n;
236    
237      switch (msg) {      switch (msg) {
238      case WM_INITDIALOG:      case WM_INITDIALOG:
239          ctx = (struct infodlg_s *)lparam;          if ((n=GetModuleFileName (NULL, modpath, MAX_PATH-1)) > 0) {
240          if (!ctx)              while (n-- > 0) {
241              EndDialog (dlg, FALSE);                  if (modpath[n] == '\\') {
242          if (ctx->title)                      modpath[n] = 0;
243              SetWindowText (dlg, ctx->title);                      break;
244          if (ctx->text)                  }
245              SetDlgItemText (dlg, IDC_INFODLG_TEXT, ctx->text);              }
         if (ctx->button_1)  
             SetDlgItemText (dlg, IDOK, ctx->button_1);  
         if (ctx->button_2)  
             SetDlgItemText (dlg, IDCANCEL, ctx->button_2);  
         if (ctx->ico != NULL) {  
             SendMessage (GetDlgItem (dlg, IDC_INFODLG_ICO), STM_SETICON,  
                          (WPARAM)(HICON)ctx->ico, 0);  
246          }          }
247            n = nls_load_langlist (dlg, modpath);
248            if (n == -1)
249                EndDialog (dlg, -1);
250            SetWindowText (dlg, _("Native Language Support"));
251            SetDlgItemText (dlg, IDC_LANGUAGE_INFO, _("Please select a language"));
252            SetDlgItemText (dlg, IDOK, _("&OK"));
253            SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));
254            center_window (dlg, NULL);
255          SetForegroundWindow (dlg);          SetForegroundWindow (dlg);
256          return TRUE;          break;
257    
258      case WM_COMMAND:      case WM_COMMAND:
259          switch (LOWORD (wparam)) {          switch (LOWORD (wparam)) {
260          case IDOK:          case IDOK:
261              ctx->retval = IDOK;              langid = nls_set_language (dlg, modpath);
262              EndDialog (dlg, TRUE);              EndDialog (dlg, langid);
263              break;              break;
264    
265          case IDCANCEL:          case IDCANCEL:
266              ctx->retval = IDCANCEL;              EndDialog (dlg, -1);
             EndDialog (dlg, FALSE);  
267              break;              break;
268          }          }
269          break;          break;
270      }      }
271    
272      return FALSE;      return FALSE;
273  }  }
274    
275    
276  int  int
277  InfoBox (HWND hwnd, LPCTSTR text, LPCTSTR title, UINT type)  select_language (void)
278  {  {
279      struct infodlg_s inf;      DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_LANGUAGE, GetDesktopWindow (),
280                        nls_dlg_proc, 0);
281      memset (&inf, 0, sizeof (inf));      return 0;
     inf.text = text;  
     inf.title = title;  
     if (type & MB_YESNO) {  
         inf.button_1 = _("Yes");  
         inf.button_2 = _("No");  
     }  
     else {  
         inf.button_1 = _("OK");  
         inf.button_2 = _("Cancel");  
     }  
     if (type & MB_ICONERROR)  
         inf.ico = LoadIcon (NULL, IDI_ERROR);  
     else if (type & MB_ICONWARNING)  
         inf.ico = LoadIcon (NULL,  IDI_EXCLAMATION);  
     else if (type & MB_ICONINFORMATION)  
         inf.ico = LoadIcon (NULL, IDI_INFORMATION);  
     DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_INFODLG, hwnd,  
                     infodlg_dlg_proc, (LPARAM)&inf);  
     return inf.retval;  
 }  
   
   
 int  
 InfoBoxEx (HWND hwnd, LPCTSTR text, LPCTSTR title, UINT type, ...)  
 {        
     va_list arg_ptr;  
     char buf[2048];  
     int id;  
   
     va_start (arg_ptr, type);  
     _vsnprintf (buf, sizeof (buf)-1, text, arg_ptr);      
     id = InfoBox (hwnd, buf, title, type);  
     va_end (arg_ptr);  
     return id;  
282  }  }
 #endif  
283    

Legend:
Removed from v.181  
changed lines
  Added in v.211

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26