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

Diff of /trunk/Src/wptW32API.cpp

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

revision 167 by twoaday, Thu Jan 26 10:17:17 2006 UTC revision 205 by twoaday, Thu Apr 27 12:46:03 2006 UTC
# Line 35  Line 35 
35  #include "wptW32API.h"  #include "wptW32API.h"
36  #include "wptErrors.h"  #include "wptErrors.h"
37  #include "wptVersion.h"  #include "wptVersion.h"
38    #include "wptUTF8.h"
39  #include "wptTypes.h"  #include "wptTypes.h"
40    
41    
42  extern "C" void _SHFree (void *p);  extern "C" void _SHFree (void *p);
43    
44    
45    
46    /* Insert a new item into the menu @hm at position @pos. */
47    void
48    insert_menu_item (HMENU hm, int pos, UINT m_id, const char *text)
49    {
50        MENUITEMINFO mi;
51    
52        memset (&mi, 0, sizeof mi);
53        mi.cbSize = sizeof mi;
54        mi.fType = MF_STRING;
55        mi.dwTypeData = (char *)text;
56        mi.cch = strlen (text);
57        mi.wID = m_id;
58        mi.fMask = MIIM_ID|MIIM_DATA| MIIM_TYPE;
59        InsertMenuItem (hm, pos, FALSE, &mi);
60    }
61    
62    
63  static void  static void
64  set_menu_text_ext (HMENU menu, int by_pos, int m_uid, const char *text)  set_menu_text_ext (HMENU menu, int by_pos, int m_uid, const char *text)
65  {  {
# Line 108  enum { Line 127  enum {
127     id can be either FILE_OPEN or FILE_SAVE.     id can be either FILE_OPEN or FILE_SAVE.
128     The return value is the file name or NULL if cancel was chosen. */     The return value is the file name or NULL if cancel was chosen. */
129  const char *  const char *
130  get_filename_dlg (HWND hwnd, int id, const char * title,  get_filename_dlg (HWND hwnd, int id, const char *title,
131                    const char * filter, const char * name)                    const char *filter, const char *name)
132  {  {
133      static char file[512] = "";      static char file[512] = "";
134      OPENFILENAME open;      OPENFILENAME open;
# Line 238  set_clip_text (HWND hwnd, const char *te Line 257  set_clip_text (HWND hwnd, const char *te
257          BUG (NULL);          BUG (NULL);
258      p = (char *) GlobalLock (clipmem);      p = (char *) GlobalLock (clipmem);
259      if (p == NULL) {      if (p == NULL) {
260          rc = WPTERR_GENERAL;;          CloseClipboard ();
261          goto leave;              GlobalFree (clipmem);
262            return WPTERR_GENERAL;
263      }      }
264      memcpy (p, text, nbytes);      memcpy (p, text, nbytes);
265      p[nbytes] = '\0';      p[nbytes] = '\0';
266            
     GlobalUnlock (clipmem);  
267      SetClipboardData (CF_TEXT, clipmem);      SetClipboardData (CF_TEXT, clipmem);
268            GlobalUnlock (clipmem);
 leave:  
269      CloseClipboard ();      CloseClipboard ();
270        GlobalFree (clipmem);
271        
272      return rc;      return rc;
273  } /* set_clip_text */  }
274    
275    
276  /* Append or prepend some text to the clipboard contents.  /* Append or prepend some text to the clipboard contents.
# Line 542  get_locale_date (long tm_t, char *buf, D Line 562  get_locale_date (long tm_t, char *buf, D
562  }  }
563    
564    
565    /* Generate a temporary file name by using the users
566       temp path and optionally a name @name provided by the caller.
567       Return value: 0 on success. */
568    int
569    get_temp_name (char *buf, DWORD buflen, const char *name)
570    {
571        char tmp[32];
572    
573        if (!name) {
574            sprintf (tmp, "%08lX", GetTickCount ());
575            name = tmp;
576        }
577    
578        /* in the mobile mode we use a local temp folder
579           with the fixed name 'temp'. */
580        if (mobile_mode_active) {
581            _snprintf (buf, buflen-1, "temp\\%s", name);
582            return 0;
583        }
584    
585        if (!GetTempPath (buflen - strlen (name) -2, buf)) {
586            log_debug ("GetTempPath() failed ec=%d\n", (int)GetLastError ());
587            return -1;
588        }
589        strcat (buf, name);
590        return 0;
591    }
592    
593    
594    void
595    ListBox_AddString_utf8 (HWND lb, const char *txt)
596    {
597        char *utf8_txt;
598    
599        utf8_txt = utf8_to_native (txt);
600        SendMessage (lb, LB_ADDSTRING, 0, (LPARAM)(LPCSTR)(utf8_txt));
601        safe_free (utf8_txt);
602    }
603    
604    
605    void
606    ComboBox_AddString_utf8 (HWND cb, const char *txt)
607    {
608    
609        char *utf8_txt;
610    
611        utf8_txt = utf8_to_native (txt);
612        SendMessage ((cb), CB_ADDSTRING, 0, (LPARAM)(LPCSTR)(utf8_txt));
613        safe_free (utf8_txt);
614    }
615    
616    
617    /* GetDlgItemText replacement with UTF8 support. */
618    int
619    GetDlgItemText_utf8 (HWND dlg, int id, char **r_txt)
620    {
621        int len = GetWindowTextLength (GetDlgItem (dlg, id));
622        char *txt;
623    
624        *r_txt = NULL;
625        if (len < 1)
626            return 0;
627        txt = new char[len+2];
628        if (!txt)
629            BUG (NULL);
630        GetDlgItemText (dlg, id, txt, len+1);
631        *r_txt = native_to_utf8 (txt);
632        free_if_alloc (txt);
633        return len;
634    }
635    
636    
637  struct reminder_hd_s {  struct reminder_hd_s {
638      int msecs;      int msecs;
639      HWND dlg;      HWND dlg;

Legend:
Removed from v.167  
changed lines
  Added in v.205

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26