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 static int needToRefresh
= 1;
39 char *getSectionForApp(char *section
) {
40 static char *lastResult
= NULL
;
41 if (lastResult
) HeapFree(GetProcessHeap(), 0, lastResult
);
42 lastResult
= HeapAlloc(GetProcessHeap(), 0, strlen("AppDefaults\\") + strlen(currentApp
) + 2 /* \\ */ + strlen(section
) + 1 /* terminator */);
43 sprintf(lastResult
, "AppDefaults\\%s\\%s", currentApp
, section
);
47 static void configureFor(HWND dialog
, int mode
) {
48 CheckRadioButton(dialog
, IDC_EDITING_GLOBAL
, IDC_EDITING_APP
, mode
== EDITING_APP
? IDC_EDITING_APP
: IDC_EDITING_GLOBAL
);
49 if (mode
== EDITING_GLOBAL
) {
50 disable(IDC_LIST_APPS
);
51 disable(IDC_ADD_APPDEFAULT
);
52 disable(IDC_REMOVE_APPDEFAULT
);
54 enable(IDC_LIST_APPS
);
55 enable(IDC_ADD_APPDEFAULT
);
56 enable(IDC_REMOVE_APPDEFAULT
);
61 /* fill the dialog with the current appdefault entries */
62 static void refreshDialog(HWND dialog
) {
64 char *subKeyName
= HeapAlloc(GetProcessHeap(), 0, MAX_NAME_LENGTH
);
65 DWORD sizeOfSubKeyName
= MAX_NAME_LENGTH
;
70 /* Clear the listbox */
71 SendMessageA(GetDlgItem(dialog
, IDC_LIST_APPS
), LB_RESETCONTENT
, 0, 0);
74 RegCreateKey(HKEY_LOCAL_MACHINE
, WINE_KEY_ROOT
"\\AppDefaults", &key
) == ERROR_SUCCESS
77 /* Iterate over each subkey in the AppDefaults tree */
79 RegEnumKeyEx(key
, i
, subKeyName
, &sizeOfSubKeyName
, NULL
, NULL
, NULL
, NULL
) != ERROR_NO_MORE_ITEMS
;
80 ++i
, sizeOfSubKeyName
= MAX_NAME_LENGTH
) {
82 WINE_TRACE("appdefault entry=%s\n", subKeyName
);
83 itemIndex
= SendMessageA(GetDlgItem(dialog
, IDC_LIST_APPS
), LB_ADDSTRING
,(WPARAM
) -1, (LPARAM
) subKeyName
);
86 configureFor(dialog
, appSettings
);
90 HeapFree(GetProcessHeap(), 0, subKeyName
);
94 static void onAppsListSelChange(HWND dialog
) {
95 int newPos
= SendDlgItemMessage(dialog
, IDC_LIST_APPS
, LB_GETCURSEL
, 0, 0);
96 int appLen
= SendDlgItemMessage(dialog
, IDC_LIST_APPS
, LB_GETTEXTLEN
, newPos
, 0);
97 if (currentApp
) HeapFree(GetProcessHeap(), 0, currentApp
);
98 currentApp
= HeapAlloc(GetProcessHeap(), 0, appLen
+1);
100 SendDlgItemMessage(dialog
, IDC_LIST_APPS
, LB_GETTEXT
, newPos
, (LPARAM
) currentApp
) != LB_ERR
102 WINE_TRACE("new selection is %s\n", currentApp
);
106 AppDlgProc (HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
110 case WM_COMMAND
: switch (LOWORD(wParam
)) {
111 case IDC_EDITING_APP
:
112 if (SendDlgItemMessage(hDlg
, IDC_LIST_APPS
, LB_GETCURSEL
, 0, 0) == LB_ERR
) {
113 /* no selection, so select the first one */
114 SendDlgItemMessage(hDlg
, IDC_LIST_APPS
, LB_SETCURSEL
, 0, 0);
115 onAppsListSelChange(hDlg
);
117 configureFor(hDlg
, EDITING_APP
);
119 case IDC_EDITING_GLOBAL
:
120 configureFor(hDlg
, EDITING_GLOBAL
);
122 case IDC_ADD_APPDEFAULT
:
126 case IDC_REMOVE_APPDEFAULT
:
131 if (HIWORD(wParam
) == LBN_SELCHANGE
) onAppsListSelChange(hDlg
);
136 case WM_NOTIFY
: switch(((LPNMHDR
)lParam
)->code
) {
138 SetWindowLong(hDlg
, DWL_MSGRESULT
, FALSE
);
141 SetWindowLong(hDlg
, DWL_MSGRESULT
, PSNRET_NOERROR
);
153 WINE_TRACE("Init appdefaults\n");