Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1769 | yogev_ezra | 1 | #include |
2 | #include |
||
3 | |||
4 | #include |
||
5 | #include |
||
6 | #include "me_cdlg.h" |
||
7 | |||
8 | using namespace Menuet; |
||
9 | |||
10 | extern HINSTANCE hInstance; |
||
11 | |||
12 | struct TThreadDataStruct |
||
13 | { |
||
14 | void *user; |
||
15 | void *stack_begin; |
||
16 | TWindowData *win_data; |
||
17 | HWND hwnd; |
||
18 | int flag; |
||
19 | unsigned int win_time, me_time; |
||
20 | void *picture; |
||
21 | unsigned int picture_width, picture_height; |
||
22 | void *keys; |
||
23 | unsigned int bmp_data_length; |
||
24 | unsigned int *bmp_data; |
||
25 | unsigned int mouse_state; |
||
26 | }; |
||
27 | |||
28 | struct TOpenFileData |
||
29 | { |
||
30 | int state; |
||
31 | char name[1]; |
||
32 | }; |
||
33 | |||
34 | namespace Menuet |
||
35 | { |
||
36 | TOpenFileStruct::TOpenFileStruct() : data(0) {} |
||
37 | |||
38 | TOpenFileStruct::~TOpenFileStruct() |
||
39 | { |
||
40 | if (data) {delete[] (char*)data; data = 0;} |
||
41 | } |
||
42 | |||
43 | void OpenFileInit(TOpenFileStruct &ofs) {ofs.data = 0;} |
||
44 | |||
45 | void OpenFileDelete(TOpenFileStruct &ofs) |
||
46 | { |
||
47 | if (ofs.data) {delete[] (char*)ofs.data; ofs.data = 0;} |
||
48 | } |
||
49 | |||
50 | bool OpenFileDialog(TOpenFileStruct &ofs) |
||
51 | { |
||
52 | char CustomFilter[300], *name; |
||
53 | int size; |
||
54 | CustomFilter[0] = 0; CustomFilter[1] = 0; |
||
55 | if (!OpenFileSetState(ofs, 0)) return false; |
||
56 | OPENFILENAME ofn = {sizeof(OPENFILENAME), ((TThreadDataStruct*)GetThreadData())->hwnd, |
||
57 | hInstance, "All files (*.*)\0*.*\0", |
||
58 | CustomFilter, sizeof(CustomFilter)-1, 1, NULL, 0, NULL, 0, NULL, NULL, |
||
59 | OFN_HIDEREADONLY | OFN_EXPLORER, 0, 0, "", 0, NULL, 0}; |
||
60 | size = 0; |
||
61 | if (ofs.data) size = strlen(((TOpenFileData*)ofs.data)->name) + 1; |
||
62 | if (size < 10000) size = 10000; |
||
63 | name = new char[size + 1]; |
||
64 | if (!name) return false; |
||
65 | if (ofs.data) strcpy(name, ((TOpenFileData*)ofs.data)->name); |
||
66 | else name[0] = 0; |
||
67 | ofn.lpstrFile = &name[0]; ofn.nMaxFile = size; |
||
68 | size = GetOpenFileName(&ofn) == TRUE; |
||
69 | if (OpenFileSetName(ofs, name)) |
||
70 | { |
||
71 | ((TOpenFileData*)ofs.data)->state = (size ? 2 : 1); |
||
72 | } |
||
73 | else size = 0; |
||
74 | delete[] name; |
||
75 | return (bool)size; |
||
76 | } |
||
77 | |||
78 | int OpenFileGetState(const TOpenFileStruct &ofs) |
||
79 | { |
||
80 | return ofs.data ? ((TOpenFileData*)ofs.data)->state : 0; |
||
81 | } |
||
82 | |||
83 | bool OpenFileSetState(TOpenFileStruct &ofs, int state) |
||
84 | { |
||
85 | if (!ofs.data || !((TOpenFileData*)ofs.data)->state) return !state; |
||
86 | if (((TOpenFileData*)ofs.data)->state == state) return true; |
||
87 | if (state < 0) return false; |
||
88 | ((TOpenFileData*)ofs.data)->state = state; |
||
89 | return true; |
||
90 | } |
||
91 | |||
92 | char *OpenFileGetName(const TOpenFileStruct &ofs) |
||
93 | { |
||
94 | if (!ofs.data) return 0; |
||
95 | else return ((TOpenFileData*)ofs.data)->name; |
||
96 | } |
||
97 | |||
98 | bool OpenFileSetName(TOpenFileStruct &ofs, char *name) |
||
99 | { |
||
100 | if (!ofs.data && !name) return true; |
||
101 | int size = (unsigned int)(((TOpenFileData*)0)->name) + 1; |
||
102 | int state = 0; |
||
103 | if (name) size += strlen(name); |
||
104 | if (ofs.data) |
||
105 | { |
||
106 | state = ((TOpenFileData*)ofs.data)->state; |
||
107 | delete[] (char*)ofs.data; |
||
108 | } |
||
109 | ofs.data = (unsigned int)(new char[size]); |
||
110 | if (!ofs.data) return false; |
||
111 | ((TOpenFileData*)ofs.data)->state = state; |
||
112 | if (name) strcpy(((TOpenFileData*)ofs.data)->name, name); |
||
113 | else ((TOpenFileData*)ofs.data)->name[0] = 0; |
||
114 | return true; |
||
115 | } |
||
116 | }>> |