2 * Copyright (c) 1997-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
23 Change History (most recent first):
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
30 Revision 1.2 2004/06/26 03:19:57 shersche
31 clean up warning messages
33 Submitted by: herscher
35 Revision 1.1 2004/06/18 04:36:57 rpantos
42 #include "PrinterSetupWizardApp.h"
43 #include "PrinterSetupWizardSheet.h"
44 #include "SecondPage.h"
45 #include "DebugServices.h"
47 // local variable is initialize but not referenced
48 #pragma warning(disable:4189)
53 IMPLEMENT_DYNAMIC(CSecondPage
, CPropertyPage
)
54 CSecondPage::CSecondPage()
55 : CPropertyPage(CSecondPage::IDD
)
57 m_psp
.dwFlags
&= ~(PSP_HASHELP
);
58 m_psp
.dwFlags
|= PSP_DEFAULT
|PSP_USEHEADERTITLE
|PSP_USEHEADERSUBTITLE
;
60 m_psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_BROWSE_TITLE
);
61 m_psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_BROWSE_SUBTITLE
);
64 m_emptyListItem
= NULL
;
65 m_initialized
= false;
69 CSecondPage::~CSecondPage()
75 CSecondPage::InitBrowseList()
77 CPrinterSetupWizardSheet
* psheet
;
80 psheet
= reinterpret_cast<CPrinterSetupWizardSheet
*>(GetParent());
81 require_quiet( psheet
, exit
);
84 // load the no rendezvous printers message until something shows up in the browse list
86 text
.LoadString(IDS_NO_RENDEZVOUS_PRINTERS
);
88 m_emptyListItem
= m_browseList
.InsertItem( text
, 0, 0, NULL
, TVI_FIRST
);
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.
95 if ( m_emptyListItem
)
97 HTREEITEM item
= m_browseList
.GetNextVisibleItem( m_emptyListItem
);
101 m_browseList
.DeleteItem( item
);
102 item
= m_browseList
.GetNextVisibleItem( m_emptyListItem
);
107 // disable the next button until there's a printer to select
109 psheet
->SetWizardButtons(PSWIZB_BACK
);
112 // disable the window until there's a printer to select
114 m_browseList
.EnableWindow( FALSE
);
122 void CSecondPage::DoDataExchange(CDataExchange
* pDX
)
124 CPropertyPage::DoDataExchange(pDX
);
125 DDX_Control(pDX
, IDC_BROWSE_LIST
, m_browseList
);
130 CSecondPage::OnSetCursor(CWnd
* pWnd
, UINT nHitTest
, UINT message
)
133 DEBUG_UNUSED(nHitTest
);
134 DEBUG_UNUSED(message
);
136 CPrinterSetupWizardSheet
* psheet
;
138 psheet
= reinterpret_cast<CPrinterSetupWizardSheet
*>(GetParent());
139 require_quiet( psheet
, exit
);
141 SetCursor(psheet
->GetCursor());
150 CSecondPage::OnSetActive()
153 CPrinterSetupWizardSheet
* psheet
;
155 psheet
= reinterpret_cast<CPrinterSetupWizardSheet
*>(GetParent());
156 require_quiet( psheet
, exit
);
159 // initialize the browse list...this will remove everything currently
160 // in it, and add the no rendezvous printers item
165 // this will invoke OnAddPrinter for all the printers that we have
168 psheet
->InstallEventHandler(this);
172 return CPropertyPage::OnSetActive();
177 CSecondPage::OnKillActive()
179 CPrinterSetupWizardSheet
* psheet
;
181 psheet
= reinterpret_cast<CPrinterSetupWizardSheet
*>(GetParent());
182 require_quiet( psheet
, exit
);
185 // we don't want our event handlers called when we don't have
186 // anywhere to put the data
188 psheet
->RemoveEventHandler(this);
192 return CPropertyPage::OnKillActive();
196 BEGIN_MESSAGE_MAP(CSecondPage
, CPropertyPage
)
197 ON_NOTIFY(TVN_SELCHANGED
, IDC_BROWSE_LIST
, OnTvnSelchangedBrowseList
)
202 // Printer::EventHandler implementation
204 CSecondPage::OnAddPrinter(
208 check( IsWindow( m_hWnd
) );
210 m_browseList
.SetRedraw(FALSE
);
212 printer
->item
= m_browseList
.InsertItem(printer
->displayName
);
214 m_browseList
.SetItemData( printer
->item
, (DWORD_PTR
) printer
);
216 m_browseList
.SortChildren(TVI_ROOT
);
219 // if the searching item is still in the list
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
227 if (m_emptyListItem
!= NULL
)
229 m_browseList
.DeleteItem(m_emptyListItem
);
230 m_emptyListItem
= NULL
;
231 m_browseList
.EnableWindow(TRUE
);
236 m_browseList
.SetRedraw(TRUE
);
237 m_browseList
.Invalidate();
243 CSecondPage::OnRemovePrinter(
247 check( IsWindow( m_hWnd
) );
249 m_browseList
.SetRedraw(FALSE
);
252 // check to make sure if we're the only item in the control...i.e.
253 // the list size is 1.
255 if (m_browseList
.GetCount() > 1)
258 // if we're not the only thing in the list, then
259 // simply remove it from the list
261 m_browseList
.DeleteItem( printer
->item
);
266 // if we're the only thing in the list, then redisplay
267 // it with the no rendezvous printers message
274 m_browseList
.SetRedraw(TRUE
);
275 m_browseList
.Invalidate();
281 CSecondPage::OnResolvePrinter(
284 DEBUG_UNUSED(printer
);
286 check( IsWindow( m_hWnd
) );
288 CPrinterSetupWizardSheet
* psheet
= reinterpret_cast<CPrinterSetupWizardSheet
*>(GetParent());
289 require_quiet( psheet
, exit
);
292 // setup the sheet to enable the next button if we've successfully
295 psheet
->SetWizardButtons( PSWIZB_BACK
|PSWIZB_NEXT
);
303 void CSecondPage::OnTvnSelchangedBrowseList(NMHDR
*pNMHDR
, LRESULT
*pResult
)
305 LPNMTREEVIEW pNMTreeView
= reinterpret_cast<LPNMTREEVIEW
>(pNMHDR
);
306 CPrinterSetupWizardSheet
* psheet
;
309 HTREEITEM item
= m_browseList
.GetSelectedItem();
310 require_quiet( item
, exit
);
312 psheet
= reinterpret_cast<CPrinterSetupWizardSheet
*>(GetParent());
313 require_action( psheet
, exit
, err
= kUnknownErr
);
317 printer
= reinterpret_cast<Printer
*>(m_browseList
.GetItemData( item
) );
318 require_quiet( printer
, exit
);
321 // this call will trigger a resolve. When the resolve is complete,
322 // our OnResolve will be called.
324 err
= psheet
->SetSelectedPrinter(printer
);
325 require_noerr( err
, exit
);
328 // setup the sheet to disable the next button until we've successfully
329 // resolved this printer
331 psheet
->SetWizardButtons( PSWIZB_BACK
);
340 text
.LoadString(IDS_ERROR_SELECTING_PRINTER_TEXT
);
341 caption
.LoadString(IDS_ERROR_SELECTING_PRINTER_CAPTION
);
343 MessageBox(text
, caption
, MB_OK
|MB_ICONEXCLAMATION
);