2 * Application defaults page
4 * Copyright 2003 Mike Hearn
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include <wine/debug.h>
32 WINE_DEFAULT_DEBUG_CHANNEL(winecfg
);
34 int appSettings
= EDITING_GLOBAL
; /* start by editing global */
35 char *currentApp
; /* the app we are currently editing, or NULL if editing global */
37 char *getSectionForApp(char *section
) {
38 static char *lastResult
= NULL
;
39 if (lastResult
) HeapFree(GetProcessHeap(), 0, lastResult
);
40 lastResult
= HeapAlloc(GetProcessHeap(), 0, strlen("AppDefaults\\") + strlen(currentApp
) + 2 /* \\ */ + strlen(section
) + 1 /* terminator */);
41 sprintf(lastResult
, "AppDefaults\\%s\\%s", currentApp
, section
);
45 static void configureFor(HWND dialog
, int mode
) {
46 CheckRadioButton(dialog
, IDC_EDITING_GLOBAL
, IDC_EDITING_APP
, mode
== EDITING_APP
? IDC_EDITING_APP
: IDC_EDITING_GLOBAL
);
47 if (mode
== EDITING_GLOBAL
) {
48 disable(IDC_LIST_APPS
);
49 disable(IDC_ADD_APPDEFAULT
);
50 disable(IDC_REMOVE_APPDEFAULT
);
51 if (currentApp
) HeapFree(GetProcessHeap(), 0, currentApp
);
53 enable(IDC_LIST_APPS
);
54 enable(IDC_ADD_APPDEFAULT
);
55 enable(IDC_REMOVE_APPDEFAULT
);
60 /* fill the dialog with the current appdefault entries */
61 static void refreshDialog(HWND dialog
) {
63 char *subKeyName
= HeapAlloc(GetProcessHeap(), 0, MAX_NAME_LENGTH
);
64 DWORD sizeOfSubKeyName
= MAX_NAME_LENGTH
;
69 /* Clear the listbox */
70 SendMessageA(GetDlgItem(dialog
, IDC_LIST_APPS
), LB_RESETCONTENT
, 0, 0);
73 RegCreateKey(HKEY_LOCAL_MACHINE
, WINE_KEY_ROOT
"\\AppDefaults", &key
) == ERROR_SUCCESS
76 /* Iterate over each subkey in the AppDefaults tree */
78 RegEnumKeyEx(key
, i
, subKeyName
, &sizeOfSubKeyName
, NULL
, NULL
, NULL
, NULL
) != ERROR_NO_MORE_ITEMS
;
79 ++i
, sizeOfSubKeyName
= MAX_NAME_LENGTH
) {
81 WINE_TRACE("appdefault entry=%s\n", subKeyName
);
82 itemIndex
= SendMessageA(GetDlgItem(dialog
, IDC_LIST_APPS
), LB_ADDSTRING
,(WPARAM
) -1, (LPARAM
) subKeyName
);
85 configureFor(dialog
, appSettings
);
89 HeapFree(GetProcessHeap(), 0, subKeyName
);
92 static void onAppsListSelChange(HWND dialog
) {
93 int newPos
= SendDlgItemMessage(dialog
, IDC_LIST_APPS
, LB_GETCURSEL
, 0, 0);
94 int appLen
= SendDlgItemMessage(dialog
, IDC_LIST_APPS
, LB_GETTEXTLEN
, newPos
, 0);
95 if (currentApp
) HeapFree(GetProcessHeap(), 0, currentApp
);
96 currentApp
= HeapAlloc(GetProcessHeap(), 0, appLen
+1);
98 SendDlgItemMessage(dialog
, IDC_LIST_APPS
, LB_GETTEXT
, newPos
, (LPARAM
) currentApp
) != LB_ERR
100 WINE_TRACE("new selection is %s\n", currentApp
);
104 AppDlgProc (HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
108 case WM_COMMAND
: switch (LOWORD(wParam
)) {
109 case IDC_EDITING_APP
:
110 configureFor(hDlg
, EDITING_APP
);
112 case IDC_EDITING_GLOBAL
:
113 configureFor(hDlg
, EDITING_GLOBAL
);
115 case IDC_ADD_APPDEFAULT
:
118 case IDC_REMOVE_APPDEFAULT
:
122 if (HIWORD(wParam
) == LBN_SELCHANGE
) onAppsListSelChange(hDlg
);
127 case WM_NOTIFY
: switch(((LPNMHDR
)lParam
)->code
) {
129 SetWindowLong(hDlg
, DWL_MSGRESULT
, FALSE
);
132 SetWindowLong(hDlg
, DWL_MSGRESULT
, PSNRET_NOERROR
);
142 WINE_TRACE("Init appdefaults\n");