Move Applications tab before Libraries tab.
[wine/wine64.git] / programs / winecfg / appdefaults.c
blobb4e4371c50a223d93ca4e24e66f95dbabea7f73a
1 /*
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
22 #include <stdio.h>
24 #include "winecfg.h"
25 #include <windef.h>
26 #include <winbase.h>
27 #include <winreg.h>
28 #include <wine/debug.h>
30 #include "resource.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);
42 return lastResult;
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);
52 } else {
53 enable(IDC_LIST_APPS);
54 enable(IDC_ADD_APPDEFAULT);
55 enable(IDC_REMOVE_APPDEFAULT);
57 appSettings = mode;
60 /* fill the dialog with the current appdefault entries */
61 static void refreshDialog(HWND dialog) {
62 HKEY key;
63 char *subKeyName = HeapAlloc(GetProcessHeap(), 0, MAX_NAME_LENGTH);
64 DWORD sizeOfSubKeyName = MAX_NAME_LENGTH;
65 int i, itemIndex;
67 WINE_TRACE("\n");
69 /* Clear the listbox */
70 SendMessageA(GetDlgItem(dialog, IDC_LIST_APPS), LB_RESETCONTENT, 0, 0);
72 return_if_fail(
73 RegCreateKey(HKEY_LOCAL_MACHINE, WINE_KEY_ROOT "\\AppDefaults", &key) == ERROR_SUCCESS
76 /* Iterate over each subkey in the AppDefaults tree */
77 for (i = 0;
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);
87 WINE_TRACE("done\n");
88 RegCloseKey(key);
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);
97 return_if_fail(
98 SendDlgItemMessage(dialog, IDC_LIST_APPS, LB_GETTEXT, newPos, (LPARAM) currentApp) != LB_ERR
100 WINE_TRACE("new selection is %s\n", currentApp);
103 INT_PTR CALLBACK
104 AppDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
106 switch (uMsg)
108 case WM_COMMAND: switch (LOWORD(wParam)) {
109 case IDC_EDITING_APP:
110 configureFor(hDlg, EDITING_APP);
111 break;
112 case IDC_EDITING_GLOBAL:
113 configureFor(hDlg, EDITING_GLOBAL);
114 break;
115 case IDC_ADD_APPDEFAULT:
116 WRITEME(hDlg);
117 break;
118 case IDC_REMOVE_APPDEFAULT:
119 WRITEME(hDlg);
120 break;
121 case IDC_LIST_APPS:
122 if (HIWORD(wParam) == LBN_SELCHANGE) onAppsListSelChange(hDlg);
123 break;
125 break;
127 case WM_NOTIFY: switch(((LPNMHDR)lParam)->code) {
128 case PSN_KILLACTIVE:
129 SetWindowLong(hDlg, DWL_MSGRESULT, FALSE);
130 break;
131 case PSN_APPLY:
132 SetWindowLong(hDlg, DWL_MSGRESULT, PSNRET_NOERROR);
133 break;
134 case PSN_SETACTIVE:
135 refreshDialog(hDlg);
136 break;
139 break;
141 case WM_INITDIALOG:
142 WINE_TRACE("Init appdefaults\n");
143 break;
146 return FALSE;