/[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 22 by twoaday, Wed Aug 10 11:33:35 2005 UTC revision 24 by twoaday, Sat Oct 8 10:43:08 2005 UTC
# Line 35  Line 35 
35    
36  extern "C" void _SHFree (void *p);  extern "C" void _SHFree (void *p);
37    
38  /*  /* The the text of a menu item. */
  * The the text of a menu item.  
  */  
39  void  void
40  set_menu_text (HMENU menu, int m_uid, const char *text)  set_menu_text (HMENU menu, int m_uid, const char *text)
41  {  {
# Line 73  set_menu_state (HMENU menu, int m_uid, i Line 71  set_menu_state (HMENU menu, int m_uid, i
71  } /* set_menu_state */  } /* set_menu_state */
72    
73    
74    /* Use the common dialog to request a file from the user.
75       id can be either FILE_OPEN or FILE_SAVE.
76       The return value is the file name or NULL if cancel was chosen. */
77  const char *  const char *
78  get_filename_dlg (HWND hwnd, int id, const char * title,  get_filename_dlg (HWND hwnd, int id, const char * title,
79                    const char * filter, const char * name)                    const char * filter, const char * name)
# Line 86  get_filename_dlg (HWND hwnd, int id, con Line 86  get_filename_dlg (HWND hwnd, int id, con
86      else      else
87          memset (file, 0, sizeof (file));          memset (file, 0, sizeof (file));
88      if (!filter)      if (!filter)
89          filter = _("All Files (*.*)\0*.*");          filter = _("All Files (*.*)\0*.*\0\0");
90      memset (&open, 0, sizeof (open));      memset (&open, 0, sizeof (open));
91      open.lStructSize = sizeof (OPENFILENAME);      open.lStructSize = sizeof (OPENFILENAME);
92      open.hInstance = glob_hinst;      open.hInstance = glob_hinst;
# Line 95  get_filename_dlg (HWND hwnd, int id, con Line 95  get_filename_dlg (HWND hwnd, int id, con
95      open.hwndOwner = hwnd;      open.hwndOwner = hwnd;
96      open.lpstrFile = file;      open.lpstrFile = file;
97      open.nMaxFile = sizeof (file) - 1;      open.nMaxFile = sizeof (file) - 1;
98      open.Flags = 0;      if (id == FILE_OPEN)
99            open.Flags = OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST;
100        else
101            open.Flags = OFN_OVERWRITEPROMPT;
102    
103      if (id == 0 && GetOpenFileName (&open))      if (id == FILE_OPEN && GetOpenFileName (&open))
104          return open.lpstrFile;          return open.lpstrFile;
105      else if (id == 1 && GetSaveFileName (&open))      else if (id == FILE_SAVE && GetSaveFileName (&open))
106          return open.lpstrFile;          return open.lpstrFile;
107            
108      return NULL;      return NULL;
109  } /* get_filename_dlg */  }
   
110    
111  const char *  /* Use the common dialog to allow the user to select a folder.
112       The return value is either the folder path or NULL if cancel was chosen. */
113    const char*
114  get_folder_dlg (HWND hwnd, const char * title, const char * name)  get_folder_dlg (HWND hwnd, const char * title, const char * name)
115  {  {
116      static char folder[MAX_PATH] = "";      static char folder[MAX_PATH+1] = "";
117      BROWSEINFO bi;      BROWSEINFO bi;
118      ITEMIDLIST * il;      ITEMIDLIST * il;
119    
# Line 131  get_folder_dlg (HWND hwnd, const char * Line 135  get_folder_dlg (HWND hwnd, const char *
135  }  }
136    
137    
138    /* Return the clipboard contents as a string or NULL
139       if the clipboard does not contain text. */
140  char*  char*
141  get_clip_text (HWND hwnd)  get_clip_text (HWND hwnd)
142  {  {
# Line 162  get_clip_text (HWND hwnd) Line 168  get_clip_text (HWND hwnd)
168  leave:  leave:
169      CloseClipboard ();      CloseClipboard ();
170      return p;      return p;
171  } /* get_clip_text */  }
172    
173    
174    /* Set the the given text to the clipboard. */
175  int  int
176  set_clip_text (HWND hwnd, const char *text, int nbytes)  set_clip_text (HWND hwnd, const char *text, int nbytes)
177  {      {    
# Line 196  leave: Line 203  leave:
203  } /* set_clip_text */  } /* set_clip_text */
204    
205    
206    /* Append or prepend some text to the clipboard contents.
207       If as_footer = 1, append the text otherwise prepend. */
208  int  int
209  set_clip_text2 (HWND hwnd, const char *text, int nbytes, int head_foot)  set_clip_text2 (HWND hwnd, const char *text, int nbytes, int as_footer)
210  {  {
211      char *p, *new_text;      char *p, *new_text;
212    
# Line 207  set_clip_text2 (HWND hwnd, const char *t Line 216  set_clip_text2 (HWND hwnd, const char *t
216      new_text = new char [strlen (p)+strlen (text)+8];      new_text = new char [strlen (p)+strlen (text)+8];
217      if (!new_text)      if (!new_text)
218          BUG (0);          BUG (0);
219      if (head_foot == 0)      if (as_footer == 0)
220          sprintf (new_text, "%s\r\n%s\r\n\r\n", text, p);          sprintf (new_text, "%s\r\n%s\r\n\r\n", text, p);
221      else      else
222          sprintf (new_text, "%s\n%s\n\n", p, text);          sprintf (new_text, "%s\n%s\n\n", p, text);
# Line 218  set_clip_text2 (HWND hwnd, const char *t Line 227  set_clip_text2 (HWND hwnd, const char *t
227  }  }
228    
229    
230    /* Make a file name out of the path, the file and an extension. */
231  char*  char*
232  make_filename( const char *path, const char *file, const char *ext )  make_filename (const char *path, const char *file, const char *ext)
233  {  {
234      char *p;      char *p;
235      size_t size = 0;      size_t size = 0;
# Line 250  make_filename( const char *path, const c Line 260  make_filename( const char *path, const c
260  /* return 0 if it exists, otherwise >0. */  /* return 0 if it exists, otherwise >0. */
261  int  int
262  file_exist_check (const char * fname)  file_exist_check (const char * fname)
263  {        {
264      HANDLE fh;        struct stat st;
265        if (stat (fname, &st) == -1)
     fh = CreateFile( fname, GENERIC_READ, FILE_SHARE_READ,  
                      NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );  
     if( fh == INVALID_HANDLE_VALUE )  
266          return WPTERR_FILE_EXIST;          return WPTERR_FILE_EXIST;
     CloseHandle( fh );  
267      return 0;      return 0;
268  } /* file_exist_check */  }
269    
270    
271    /* Check if the current folder exists.
272       Return 0 for success. */
273  int  int
274  dir_exist_check( const char *dir )  dir_exist_check (const char *dir)
275  {  {
276      struct stat statbuf;          struct stat statbuf;    
277            
# Line 272  dir_exist_check( const char *dir ) Line 280  dir_exist_check( const char *dir )
280      if( statbuf.st_mode & _S_IFDIR )      if( statbuf.st_mode & _S_IFDIR )
281          return 0;          return 0;
282      return WPTERR_GENERAL;      return WPTERR_GENERAL;
283  } /* dir_exist_check */  }
284    
285    
286    /* Return the file size of the given file. */
287  size_t  size_t
288  get_file_size( const char *fname )  get_file_size (const char *fname)
289  {  {
290      size_t fsize;      size_t fsize;
291      HANDLE fh;      HANDLE fh;
# Line 324  release_file_lock( LOCK *ctx ) Line 333  release_file_lock( LOCK *ctx )
333  } /* release_file_lock */  } /* release_file_lock */
334    
335    
336    /* Start a dialog with the exception that before it is checked that the
337       dialog is not already openened. */
338  int  int
339  dialog_box_param( HINSTANCE hinst, LPCTSTR name, HWND parent, DLGPROC fnc,  dialog_box_param( HINSTANCE hinst, LPCTSTR name, HWND parent, DLGPROC fnc,
340                                    LPARAM param, LPCTSTR title, int title_id )                                    LPARAM param, LPCTSTR title, int title_id )
# Line 342  dialog_box_param( HINSTANCE hinst, LPCTS Line 353  dialog_box_param( HINSTANCE hinst, LPCTS
353  } /* dialog_box_param */  } /* dialog_box_param */
354    
355    
356    /* Wrapper for message box which forces the message box into the
357       foreground and it is displayed always on top. */
358  int  int
359  msg_box( HWND hwnd, const char *text, const char *title, int mode )  msg_box (HWND hwnd, const char *text, const char *title, int mode)
360  {  {
361      mode |= MB_SETFOREGROUND;      mode |= MB_SETFOREGROUND;
362      mode |= MB_TASKMODAL;      mode |= MB_TASKMODAL;
363      mode |= MB_TOPMOST;      mode |= MB_TOPMOST;
364      return MessageBox(hwnd, text, title, mode);      return MessageBox(hwnd, text, title, mode);
365  } /* msg_box */  }
366    
367    
368  void  void
369  set_active_window( HWND dlg )  set_active_window( HWND dlg)
370  {        {      
371      activ_hwnd = dlg;      activ_hwnd = dlg;
372  } /* set_active_window */  } /* set_active_window */
# Line 366  reset_active_window( void ) Line 379  reset_active_window( void )
379    
380    
381  static DWORD CALLBACK  static DWORD CALLBACK
382  reminder_thread( void *ctx )  reminder_thread (void *ctx)
383  {  {
384      reminder_ctx_s *c = (reminder_ctx_s *)ctx;      reminder_ctx_s *c = (reminder_ctx_s *)ctx;
385    
# Line 376  reminder_thread( void *ctx ) Line 389  reminder_thread( void *ctx )
389      return 0;      return 0;
390  } /* reminder_thread */  } /* reminder_thread */
391    
392    
393  HANDLE  HANDLE
394  window_reminder( struct reminder_ctx_s *ctx )  window_reminder( struct reminder_ctx_s *ctx )
395  {  {
# Line 385  window_reminder( struct reminder_ctx_s * Line 399  window_reminder( struct reminder_ctx_s *
399  } /* window_reminder */  } /* window_reminder */
400    
401    
402  char *  char*
403  m_strdup (const char *str)  m_strdup (const char *str)
404  {  {
405      char * p = new char[strlen (str) + 1];      char * p = new char[strlen (str) + 1];
# Line 395  m_strdup (const char *str) Line 409  m_strdup (const char *str)
409  } /* m_strdup */  } /* m_strdup */
410    
411    
412    /* Center the hwndChild relative to parent.
413       The style param allows to specificy additional styles (like topmost). */
414  void  void
415  center_window2 (HWND hwndChild, HWND style)  center_window2 (HWND hwndChild, HWND parent, HWND style)
416  {      {    
417      HWND hwndParent;      HWND hwndParent;
418      RECT rChild, rParent;          RECT rChild, rParent;    
# Line 405  center_window2 (HWND hwndChild, HWND sty Line 421  center_window2 (HWND hwndChild, HWND sty
421      int wScreen, hScreen, xNew, yNew;      int wScreen, hScreen, xNew, yNew;
422      int flags = SWP_NOSIZE | SWP_NOZORDER;      int flags = SWP_NOSIZE | SWP_NOZORDER;
423    
424      hwndParent = GetDesktopWindow ();      hwndParent = parent;
425        if (hwndParent == NULL)
426            hwndParent = GetDesktopWindow ();
427      GetWindowRect (hwndChild, &rChild);          GetWindowRect (hwndChild, &rChild);    
428      wChild = rChild.right - rChild.left;          wChild = rChild.right - rChild.left;    
429      hChild = rChild.bottom - rChild.top;      hChild = rChild.bottom - rChild.top;
# Line 434  center_window2 (HWND hwndChild, HWND sty Line 452  center_window2 (HWND hwndChild, HWND sty
452  }  }
453    
454    
455    /* Center the given hwndChild window with no special style. */
456  void  void
457  center_window (HWND hwndChild)  center_window (HWND hwndChild, HWND hwndParent)
458  {  {
459      center_window2 (hwndChild, NULL);      center_window2 (hwndChild, hwndParent, NULL);
460  }  }

Legend:
Removed from v.22  
changed lines
  Added in v.24

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26