source: golgotha/src/i4/file/win32/win_open.cc @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 14 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 5.6 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#include "file/get_filename.hh"
10#include "window/style.hh"
11#include "window/window.hh"
12#include "string/string.hh"
13#include "device/device.hh"
14#include "device/kernel.hh"
15#include <windows.h>
16#include "string/string.hh"
17#include "main/win_main.hh"
18#include <direct.h>
19
20class open_string : public i4_str
21{
22public:
23  open_string(char *fname)
24    : i4_str(strlen(fname))
25  {
26    len=strlen(fname);
27    memcpy(ptr, fname, len);
28  }
29};
30
31
32long FAR PASCAL WindowProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam );
33
34
35
36UINT APIENTRY win32_dialog_hook( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
37{
38  switch( message )
39  {
40    case WM_LBUTTONUP :
41
42    case WM_RBUTTONUP :
43
44    case WM_MBUTTONUP :
45    case WM_ACTIVATEAPP :
46
47
48    case WM_SYSKEYUP :
49    case WM_KEYUP :
50      WindowProc(hWnd, message, wParam, lParam);
51      break;
52  }
53
54  return FALSE;
55}
56
57
58void i4_create_file_open_dialog(i4_graphical_style_class *style,
59                                const i4_const_str &title_name,
60                                const i4_const_str &start_dir,
61                                const i4_const_str &file_mask,
62                                const i4_const_str &mask_name,
63                                i4_event_handler_class *tell_who,
64                                w32 ok_id, w32 cancel_id)
65{
66  OPENFILENAME ofn;
67
68  char mname[256], m[256], tname[256], idir[256], fname[256], curdir[256];
69
70  ShowCursor(TRUE);
71
72  _getcwd(curdir,256);
73
74  i4_os_string(mask_name, mname, sizeof(mname));
75  i4_os_string(file_mask, m, sizeof(m));
76  i4_os_string(title_name, tname, sizeof(tname));
77  i4_os_string(start_dir, idir, sizeof(idir));
78
79
80  char *af="All files\0*.*\0\0";
81
82  int i=strlen(mname)+1;
83  int l=strlen(m) + 1;
84  memcpy(mname + i, m, l);
85  i+=l;
86  l=15;
87  memcpy(mname + i, m, l);
88
89  fname[0]=0;
90
91  ofn.lStructSize = sizeof(OPENFILENAME);
92  ofn.hwndOwner = i4_win32_window_handle;
93  ofn.hInstance = i4_win32_instance;
94  ofn.lpstrCustomFilter = 0;
95  ofn.nMaxCustFilter = 0;
96  ofn.nFilterIndex = 0;
97  ofn.lpstrFile = fname;
98  ofn.nMaxFile = 256;
99
100  ofn.nMaxFileTitle = 256;
101  ofn.lpstrFileTitle = tname;
102
103  ofn.lpstrInitialDir = idir;
104  ofn.nFileOffset = 0;
105  ofn.nFileExtension = 0;
106  ofn.lCustData = 0L;
107  ofn.lpfnHook = NULL;
108  ofn.lpTemplateName = NULL;
109
110  ofn.lpfnHook = win32_dialog_hook;
111
112
113  ofn.lpstrFilter = mname;
114  ofn.lpstrDefExt = "level";
115  ofn.lpstrTitle = tname;
116  ofn.Flags = OFN_HIDEREADONLY | OFN_ENABLEHOOK | OFN_EXPLORER  ;
117
118  WindowProc(i4_win32_window_handle, WM_LBUTTONUP, 0,0);
119  WindowProc(i4_win32_window_handle, WM_RBUTTONUP, 0,0);
120  WindowProc(i4_win32_window_handle, WM_MBUTTONUP, 0,0);
121
122
123
124  if (GetOpenFileName(&ofn))
125  {     
126    i4_file_open_message_class o(ok_id, new open_string(ofn.lpstrFile));
127    i4_kernel.send_event(tell_who, &o);
128  }
129  else
130  {
131    i4_user_message_event_class o(cancel_id);
132    i4_kernel.send_event(tell_who, &o);
133  }
134
135  _chdir(curdir);
136
137  ShowCursor(FALSE);
138}
139
140
141
142void i4_create_file_save_dialog(i4_graphical_style_class *style,
143                                const i4_const_str &default_name,
144                                const i4_const_str &title_name,
145                                const i4_const_str &start_dir,
146                                const i4_const_str &file_mask,
147                                const i4_const_str &mask_name,
148                                i4_event_handler_class *tell_who,
149                                w32 ok_id, w32 cancel_id)
150{
151  OPENFILENAME ofn;
152
153  char mname[256], m[256], tname[256], idir[256], fname[256], curdir[256];
154
155  _getcwd(curdir,256);
156
157  i4_os_string(mask_name, mname, sizeof(mname));
158  i4_os_string(file_mask, m, sizeof(m));
159  i4_os_string(title_name, tname, sizeof(tname));
160  i4_os_string(start_dir, idir, sizeof(idir));
161
162
163  char *af="All files\0*.*\0\0";
164
165  int i=strlen(mname)+1;
166  int l=strlen(m) + 1;
167  memcpy(mname + i, m, l);
168  i+=l;
169  l=15;
170  memcpy(mname + i, m, l);
171
172  fname[0]=0;
173
174  ofn.lStructSize = sizeof(OPENFILENAME);
175  ofn.hwndOwner = i4_win32_window_handle;
176  ofn.hInstance = i4_win32_instance;
177  ofn.lpstrCustomFilter = 0;
178  ofn.nMaxCustFilter = 0;
179  ofn.nFilterIndex = 0;
180  ofn.lpstrFile = fname;
181  ofn.nMaxFile = 256;
182
183  ofn.nMaxFileTitle = 256;
184  ofn.lpstrFileTitle = tname;
185
186  ofn.lpstrInitialDir = idir;
187  ofn.nFileOffset = 0;
188  ofn.nFileExtension = 0;
189  ofn.lCustData = 0L;
190  ofn.lpfnHook = NULL;
191  ofn.lpTemplateName = NULL;
192
193  ofn.lpfnHook = win32_dialog_hook;
194
195  ofn.lpstrFilter = mname;
196  ofn.lpstrDefExt = m;
197  while (*ofn.lpstrDefExt && *ofn.lpstrDefExt!='.')
198    ofn.lpstrDefExt++;
199
200  ofn.lpstrTitle = tname;
201  ofn.Flags = OFN_HIDEREADONLY | OFN_ENABLEHOOK | OFN_EXPLORER ;
202
203  WindowProc(i4_win32_window_handle, WM_LBUTTONUP, 0,0);
204  WindowProc(i4_win32_window_handle, WM_RBUTTONUP, 0,0);
205  WindowProc(i4_win32_window_handle, WM_MBUTTONUP, 0,0);
206
207
208  if (GetSaveFileName(&ofn))
209  {     
210    i4_file_open_message_class o(ok_id, new open_string(ofn.lpstrFile));
211    i4_kernel.send_event(tell_who, &o);
212  }
213  else
214  {
215    i4_user_message_event_class o(cancel_id);
216    i4_kernel.send_event(tell_who, &o);
217  }
218
219  _chdir(curdir);
220}
Note: See TracBrowser for help on using the repository browser.