2 * Copyright 2018 Piotr Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(inetcpl
);
33 static BOOL initdialog_done
;
35 static void connections_on_initdialog(HWND hwnd
)
37 INTERNET_PER_CONN_OPTION_LISTW list
;
38 INTERNET_PER_CONN_OPTIONW options
[3];
39 WCHAR
*address
, *port
, *pac_url
;
42 SendMessageW(GetDlgItem(hwnd
, IDC_EDIT_PAC_SCRIPT
),
43 EM_LIMITTEXT
, INTERNET_MAX_URL_LENGTH
, 0);
44 SendMessageW(GetDlgItem(hwnd
, IDC_EDIT_PROXY_SERVER
),
45 EM_LIMITTEXT
, INTERNET_MAX_URL_LENGTH
-10, 0);
46 SendMessageW(GetDlgItem(hwnd
, IDC_EDIT_PROXY_PORT
), EM_LIMITTEXT
, 8, 0);
48 list
.dwSize
= sizeof(list
);
49 list
.pszConnection
= NULL
;
50 list
.dwOptionCount
= ARRAY_SIZE(options
);
51 list
.pOptions
= options
;
53 options
[0].dwOption
= INTERNET_PER_CONN_FLAGS
;
54 options
[1].dwOption
= INTERNET_PER_CONN_PROXY_SERVER
;
55 options
[2].dwOption
= INTERNET_PER_CONN_AUTOCONFIG_URL
;
57 if(!InternetQueryOptionW(NULL
, INTERNET_OPTION_PER_CONNECTION_OPTION
, &list
, &size
))
60 flags
= options
[0].Value
.dwValue
;
61 address
= options
[1].Value
.pszValue
;
62 pac_url
= options
[2].Value
.pszValue
;
64 TRACE("flags = %lx\n", flags
);
65 TRACE("ProxyServer = %s\n", wine_dbgstr_w(address
));
66 TRACE("AutoConfigURL = %s\n", wine_dbgstr_w(pac_url
));
68 if (flags
& PROXY_TYPE_AUTO_DETECT
)
69 CheckDlgButton(hwnd
, IDC_USE_WPAD
, BST_CHECKED
);
71 if(flags
& PROXY_TYPE_PROXY
)
73 CheckDlgButton(hwnd
, IDC_USE_PROXY_SERVER
, BST_CHECKED
);
74 EnableWindow(GetDlgItem(hwnd
, IDC_EDIT_PROXY_SERVER
), TRUE
);
75 EnableWindow(GetDlgItem(hwnd
, IDC_EDIT_PROXY_PORT
), TRUE
);
80 port
= wcschr(address
, ':');
86 SetDlgItemTextW(hwnd
, IDC_EDIT_PROXY_SERVER
, address
);
88 SetDlgItemTextW(hwnd
, IDC_EDIT_PROXY_PORT
, port
);
91 if(flags
& PROXY_TYPE_AUTO_PROXY_URL
)
93 CheckDlgButton(hwnd
, IDC_USE_PAC_SCRIPT
, BST_CHECKED
);
94 EnableWindow(GetDlgItem(hwnd
, IDC_EDIT_PAC_SCRIPT
), TRUE
);
97 SetDlgItemTextW(hwnd
, IDC_EDIT_PAC_SCRIPT
, pac_url
);
104 static INT_PTR
connections_on_command(HWND hwnd
, WPARAM wparam
)
110 case IDC_USE_PAC_SCRIPT
:
111 checked
= IsDlgButtonChecked(hwnd
, IDC_USE_PAC_SCRIPT
);
112 EnableWindow(GetDlgItem(hwnd
, IDC_EDIT_PAC_SCRIPT
), checked
);
114 case IDC_USE_PROXY_SERVER
:
115 checked
= IsDlgButtonChecked(hwnd
, IDC_USE_PROXY_SERVER
);
116 EnableWindow(GetDlgItem(hwnd
, IDC_EDIT_PROXY_SERVER
), checked
);
117 EnableWindow(GetDlgItem(hwnd
, IDC_EDIT_PROXY_PORT
), checked
);
123 case IDC_USE_PAC_SCRIPT
:
124 case IDC_USE_PROXY_SERVER
:
125 case MAKEWPARAM(IDC_EDIT_PAC_SCRIPT
, EN_CHANGE
):
126 case MAKEWPARAM(IDC_EDIT_PROXY_SERVER
, EN_CHANGE
):
127 case MAKEWPARAM(IDC_EDIT_PROXY_PORT
, EN_CHANGE
):
129 SendMessageW(GetParent(hwnd
), PSM_CHANGED
, (WPARAM
)hwnd
, 0);
136 static INT_PTR
connections_on_notify(HWND hwnd
, WPARAM wparam
, LPARAM lparam
)
138 WCHAR proxy
[INTERNET_MAX_URL_LENGTH
];
139 WCHAR pac_script
[INTERNET_MAX_URL_LENGTH
];
140 PSHNOTIFY
*psn
= (PSHNOTIFY
*)lparam
;
141 DWORD proxy_len
, port_len
, pac_script_len
;
142 INTERNET_PER_CONN_OPTION_LISTW list
;
143 INTERNET_PER_CONN_OPTIONW options
[3];
146 if(psn
->hdr
.code
!= PSN_APPLY
)
149 flags
= IsDlgButtonChecked(hwnd
, IDC_USE_PROXY_SERVER
) ? PROXY_TYPE_PROXY
: PROXY_TYPE_DIRECT
;
151 proxy_len
= GetDlgItemTextW(hwnd
, IDC_EDIT_PROXY_SERVER
, proxy
, ARRAY_SIZE(proxy
));
154 proxy
[proxy_len
++] = ':';
155 port_len
= GetDlgItemTextW(hwnd
, IDC_EDIT_PROXY_PORT
, proxy
+proxy_len
,
156 ARRAY_SIZE(proxy
)-proxy_len
);
159 proxy
[proxy_len
++] = '8';
160 proxy
[proxy_len
++] = '0';
161 proxy
[proxy_len
] = 0;
166 flags
= PROXY_TYPE_DIRECT
;
169 pac_script_len
= GetDlgItemTextW(hwnd
, IDC_EDIT_PAC_SCRIPT
,
170 pac_script
, ARRAY_SIZE(pac_script
));
171 if(pac_script_len
&& IsDlgButtonChecked(hwnd
, IDC_USE_PAC_SCRIPT
))
172 flags
|= PROXY_TYPE_AUTO_PROXY_URL
;
174 if(IsDlgButtonChecked(hwnd
, IDC_USE_WPAD
))
175 flags
|= PROXY_TYPE_AUTO_DETECT
;
177 TRACE("flags = %lx\n", flags
);
178 TRACE("ProxyServer = %s\n", wine_dbgstr_w(proxy
));
179 TRACE("AutoConfigURL = %s\n", wine_dbgstr_w(pac_script
));
181 list
.dwSize
= sizeof(list
);
182 list
.pszConnection
= NULL
;
183 list
.dwOptionCount
= ARRAY_SIZE(options
);
184 list
.pOptions
= options
;
186 options
[0].dwOption
= INTERNET_PER_CONN_FLAGS
;
187 options
[0].Value
.dwValue
= flags
;
188 options
[1].dwOption
= INTERNET_PER_CONN_PROXY_SERVER
;
189 options
[1].Value
.pszValue
= proxy
;
190 options
[2].dwOption
= INTERNET_PER_CONN_AUTOCONFIG_URL
;
191 options
[2].Value
.pszValue
= pac_script
;
192 return InternetSetOptionW(NULL
, INTERNET_OPTION_PER_CONNECTION_OPTION
, &list
, sizeof(list
));
195 INT_PTR CALLBACK
connections_dlgproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
200 connections_on_initdialog(hwnd
);
201 initdialog_done
= TRUE
;
204 return connections_on_command(hwnd
, wparam
);
206 return connections_on_notify(hwnd
, wparam
, lparam
);