]>
Commit | Line | Data |
---|---|---|
23c9e63c DD |
1 | /* |
2 | * Copyright (c) 2000, Red Hat, Inc. | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * A copy of the GNU General Public License can be found at | |
10 | * http://www.gnu.org/ | |
11 | * | |
12 | * Written by DJ Delorie <dj@cygnus.com> | |
13 | * | |
14 | */ | |
15 | ||
16 | /* The purpose of this file is to provide common functionality for | |
17 | all the dialogs in the program. */ | |
18 | ||
b24c88b3 RC |
19 | #if 0 |
20 | static const char *cvsid = | |
21 | "\n%%% $Id$\n"; | |
22 | #endif | |
8507f105 | 23 | |
23c9e63c DD |
24 | #include "win32.h" |
25 | #include <stdio.h> | |
26 | #include <stdlib.h> | |
27 | #include "dialog.h" | |
28 | #include "msg.h" | |
9f4a0c62 | 29 | #include "LogSingleton.h" |
85b43844 | 30 | #include "mount.h" |
23c9e63c DD |
31 | |
32 | char * | |
33 | eget (HWND h, int id, char *var) | |
34 | { | |
35 | char tmp[4000]; | |
3c054baf | 36 | if (var && var != get_root_dir ().cstr_oneuse()) |
23c9e63c | 37 | { |
5e0464a1 | 38 | delete [] var; |
85b43844 | 39 | var = NULL; |
23c9e63c | 40 | } |
42bf5b92 | 41 | if (GetDlgItemText (h, id, tmp, sizeof (tmp)) > 0) |
23c9e63c | 42 | { |
5e0464a1 RC |
43 | var = new char [strlen (tmp) + 1]; |
44 | var [strlen (tmp)] = '\0'; | |
23c9e63c DD |
45 | strcpy (var, tmp); |
46 | } | |
47 | return var; | |
48 | } | |
49 | ||
3c054baf RC |
50 | String |
51 | egetString (HWND h, int id) | |
52 | { | |
53 | String aString; | |
54 | char tmp[4000]; | |
55 | if (GetDlgItemText (h, id, tmp, sizeof (tmp)) > 0) | |
56 | aString = String (tmp); | |
57 | return aString; | |
58 | } | |
59 | ||
23c9e63c DD |
60 | int |
61 | eget (HWND h, int id) | |
62 | { | |
63 | BOOL s; | |
64 | int r = GetDlgItemInt (h, id, &s, TRUE); | |
65 | return r; | |
66 | } | |
67 | ||
68 | void | |
85b43844 | 69 | eset (HWND h, int id, const char *val) |
23c9e63c DD |
70 | { |
71 | SetDlgItemText (h, id, val); | |
72 | } | |
73 | ||
3c054baf RC |
74 | void |
75 | eset (HWND h, int id, String const aString) | |
76 | { | |
77 | SetDlgItemText (h, id, aString.cstr_oneuse()); | |
78 | } | |
79 | ||
23c9e63c DD |
80 | void |
81 | eset (HWND h, int id, int val) | |
82 | { | |
b24c88b3 | 83 | SetDlgItemInt (h, id, (UINT) val, TRUE); |
23c9e63c DD |
84 | } |
85 | ||
86 | int | |
87 | rbget (HWND h, int *ids) | |
88 | { | |
89 | int i; | |
b24c88b3 | 90 | for (i = 0; ids[i]; i++) |
23c9e63c DD |
91 | if (IsDlgButtonChecked (h, ids[i]) == BST_CHECKED) |
92 | return ids[i]; | |
93 | return 0; | |
94 | } | |
95 | ||
96 | void | |
97 | rbset (HWND h, int *ids, int id) | |
98 | { | |
99 | int i; | |
b24c88b3 RC |
100 | for (i = 0; ids[i]; i++) |
101 | CheckDlgButton (h, ids[i], id == ids[i] ? BST_CHECKED : BST_UNCHECKED); | |
23c9e63c DD |
102 | } |
103 | ||
104 | void | |
b24c88b3 | 105 | fatal (const char *msg) |
23c9e63c | 106 | { |
1fd6d0a2 | 107 | DWORD e = GetLastError (); |
23c9e63c DD |
108 | char *buf; |
109 | FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, | |
b24c88b3 | 110 | 0, e, 0, (CHAR *) & buf, 0, 0); |
23c9e63c | 111 | MessageBox (0, buf, msg, 0); |
9f4a0c62 RC |
112 | LogSingleton::GetInstance().exit (1); |
113 | // Keep gcc happy - some sort of bug! | |
114 | exit (1); | |
23c9e63c | 115 | } |