]> git.saurik.com Git - apple/mdnsresponder.git/blob - Clients/PrinterSetupWizard/SecondPage.cpp
mDNSResponder-87.tar.gz
[apple/mdnsresponder.git] / Clients / PrinterSetupWizard / SecondPage.cpp
1 /*
2 * Copyright (c) 1997-2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22
23 Change History (most recent first):
24
25 $Log: SecondPage.cpp,v $
26 Revision 1.3 2004/09/13 21:26:15 shersche
27 <rdar://problem/3796483> Use the moreComing flag to determine whether drawing should take place in OnAddPrinter and OnRemovePrinter callbacks
28 Bug #: 3796483
29
30 Revision 1.2 2004/06/26 03:19:57 shersche
31 clean up warning messages
32
33 Submitted by: herscher
34
35 Revision 1.1 2004/06/18 04:36:57 rpantos
36 First checked in
37
38
39 */
40
41 #include "stdafx.h"
42 #include "PrinterSetupWizardApp.h"
43 #include "PrinterSetupWizardSheet.h"
44 #include "SecondPage.h"
45 #include "DebugServices.h"
46
47 // local variable is initialize but not referenced
48 #pragma warning(disable:4189)
49
50
51 // CSecondPage dialog
52
53 IMPLEMENT_DYNAMIC(CSecondPage, CPropertyPage)
54 CSecondPage::CSecondPage()
55 : CPropertyPage(CSecondPage::IDD)
56 {
57 m_psp.dwFlags &= ~(PSP_HASHELP);
58 m_psp.dwFlags |= PSP_DEFAULT|PSP_USEHEADERTITLE|PSP_USEHEADERSUBTITLE;
59
60 m_psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_BROWSE_TITLE);
61 m_psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_BROWSE_SUBTITLE);
62
63 m_resolver = NULL;
64 m_emptyListItem = NULL;
65 m_initialized = false;
66 m_waiting = false;
67 }
68
69 CSecondPage::~CSecondPage()
70 {
71 }
72
73
74 void
75 CSecondPage::InitBrowseList()
76 {
77 CPrinterSetupWizardSheet * psheet;
78 CString text;
79
80 psheet = reinterpret_cast<CPrinterSetupWizardSheet*>(GetParent());
81 require_quiet( psheet, exit );
82
83 //
84 // load the no rendezvous printers message until something shows up in the browse list
85 //
86 text.LoadString(IDS_NO_RENDEZVOUS_PRINTERS);
87
88 m_emptyListItem = m_browseList.InsertItem( text, 0, 0, NULL, TVI_FIRST );
89
90 //
91 // this will remove everything else in the list...we might be navigating
92 // back to this window, and the browse list might have changed since
93 // we last displayed it.
94 //
95 if ( m_emptyListItem )
96 {
97 HTREEITEM item = m_browseList.GetNextVisibleItem( m_emptyListItem );
98
99 while ( item )
100 {
101 m_browseList.DeleteItem( item );
102 item = m_browseList.GetNextVisibleItem( m_emptyListItem );
103 }
104 }
105
106 //
107 // disable the next button until there's a printer to select
108 //
109 psheet->SetWizardButtons(PSWIZB_BACK);
110
111 //
112 // disable the window until there's a printer to select
113 //
114 m_browseList.EnableWindow( FALSE );
115
116 exit:
117
118 return;
119 }
120
121
122 void CSecondPage::DoDataExchange(CDataExchange* pDX)
123 {
124 CPropertyPage::DoDataExchange(pDX);
125 DDX_Control(pDX, IDC_BROWSE_LIST, m_browseList);
126 }
127
128
129 afx_msg BOOL
130 CSecondPage::OnSetCursor(CWnd * pWnd, UINT nHitTest, UINT message)
131 {
132 DEBUG_UNUSED(pWnd);
133 DEBUG_UNUSED(nHitTest);
134 DEBUG_UNUSED(message);
135
136 CPrinterSetupWizardSheet * psheet;
137
138 psheet = reinterpret_cast<CPrinterSetupWizardSheet*>(GetParent());
139 require_quiet( psheet, exit );
140
141 SetCursor(psheet->GetCursor());
142
143 exit:
144
145 return TRUE;
146 }
147
148
149 BOOL
150 CSecondPage::OnSetActive()
151 {
152 CString noPrinters;
153 CPrinterSetupWizardSheet * psheet;
154
155 psheet = reinterpret_cast<CPrinterSetupWizardSheet*>(GetParent());
156 require_quiet( psheet, exit );
157
158 //
159 // initialize the browse list...this will remove everything currently
160 // in it, and add the no rendezvous printers item
161 //
162 InitBrowseList();
163
164 //
165 // this will invoke OnAddPrinter for all the printers that we have
166 // browsed
167 //
168 psheet->InstallEventHandler(this);
169
170 exit:
171
172 return CPropertyPage::OnSetActive();
173 }
174
175
176 BOOL
177 CSecondPage::OnKillActive()
178 {
179 CPrinterSetupWizardSheet * psheet;
180
181 psheet = reinterpret_cast<CPrinterSetupWizardSheet*>(GetParent());
182 require_quiet( psheet, exit );
183
184 //
185 // we don't want our event handlers called when we don't have
186 // anywhere to put the data
187 //
188 psheet->RemoveEventHandler(this);
189
190 exit:
191
192 return CPropertyPage::OnKillActive();
193 }
194
195
196 BEGIN_MESSAGE_MAP(CSecondPage, CPropertyPage)
197 ON_NOTIFY(TVN_SELCHANGED, IDC_BROWSE_LIST, OnTvnSelchangedBrowseList)
198 ON_WM_SETCURSOR()
199 END_MESSAGE_MAP()
200
201
202 // Printer::EventHandler implementation
203 void
204 CSecondPage::OnAddPrinter(
205 Printer * printer,
206 bool moreComing)
207 {
208 check( IsWindow( m_hWnd ) );
209
210 m_browseList.SetRedraw(FALSE);
211
212 printer->item = m_browseList.InsertItem(printer->displayName);
213
214 m_browseList.SetItemData( printer->item, (DWORD_PTR) printer );
215
216 m_browseList.SortChildren(TVI_ROOT);
217
218 //
219 // if the searching item is still in the list
220 // get rid of it
221 //
222 // note that order is important here. Insert the printer
223 // item before removing the placeholder so we always have
224 // an item in the list to avoid experiencing the bug
225 // in Microsoft's implementation of CTreeCtrl
226 //
227 if (m_emptyListItem != NULL)
228 {
229 m_browseList.DeleteItem(m_emptyListItem);
230 m_emptyListItem = NULL;
231 m_browseList.EnableWindow(TRUE);
232 }
233
234 if (!moreComing)
235 {
236 m_browseList.SetRedraw(TRUE);
237 m_browseList.Invalidate();
238 }
239 }
240
241
242 void
243 CSecondPage::OnRemovePrinter(
244 Printer * printer,
245 bool moreComing)
246 {
247 check( IsWindow( m_hWnd ) );
248
249 m_browseList.SetRedraw(FALSE);
250
251 //
252 // check to make sure if we're the only item in the control...i.e.
253 // the list size is 1.
254 //
255 if (m_browseList.GetCount() > 1)
256 {
257 //
258 // if we're not the only thing in the list, then
259 // simply remove it from the list
260 //
261 m_browseList.DeleteItem( printer->item );
262 }
263 else
264 {
265 //
266 // if we're the only thing in the list, then redisplay
267 // it with the no rendezvous printers message
268 //
269 InitBrowseList();
270 }
271
272 if (!moreComing)
273 {
274 m_browseList.SetRedraw(TRUE);
275 m_browseList.Invalidate();
276 }
277 }
278
279
280 void
281 CSecondPage::OnResolvePrinter(
282 Printer * printer)
283 {
284 DEBUG_UNUSED(printer);
285
286 check( IsWindow( m_hWnd ) );
287
288 CPrinterSetupWizardSheet * psheet = reinterpret_cast<CPrinterSetupWizardSheet*>(GetParent());
289 require_quiet( psheet, exit );
290
291 //
292 // setup the sheet to enable the next button if we've successfully
293 // resolved
294 //
295 psheet->SetWizardButtons( PSWIZB_BACK|PSWIZB_NEXT );
296
297 exit:
298
299 return;
300 }
301
302
303 void CSecondPage::OnTvnSelchangedBrowseList(NMHDR *pNMHDR, LRESULT *pResult)
304 {
305 LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
306 CPrinterSetupWizardSheet * psheet;
307 int err = 0;
308
309 HTREEITEM item = m_browseList.GetSelectedItem();
310 require_quiet( item, exit );
311
312 psheet = reinterpret_cast<CPrinterSetupWizardSheet*>(GetParent());
313 require_action( psheet, exit, err = kUnknownErr );
314
315 Printer * printer;
316
317 printer = reinterpret_cast<Printer*>(m_browseList.GetItemData( item ) );
318 require_quiet( printer, exit );
319
320 //
321 // this call will trigger a resolve. When the resolve is complete,
322 // our OnResolve will be called.
323 //
324 err = psheet->SetSelectedPrinter(printer);
325 require_noerr( err, exit );
326
327 //
328 // setup the sheet to disable the next button until we've successfully
329 // resolved this printer
330 //
331 psheet->SetWizardButtons( PSWIZB_BACK );
332
333 exit:
334
335 if (err != 0)
336 {
337 CString text;
338 CString caption;
339
340 text.LoadString(IDS_ERROR_SELECTING_PRINTER_TEXT);
341 caption.LoadString(IDS_ERROR_SELECTING_PRINTER_CAPTION);
342
343 MessageBox(text, caption, MB_OK|MB_ICONEXCLAMATION);
344 }
345
346 *pResult = 0;
347 }