X-Git-Url: https://git.saurik.com/apple/mdnsresponder.git/blobdiff_plain/f5e6e86cb0d7e0c7608c30d93ecb200173f29055..2682e09e0dbe18ba42fd4707b09a89e8c34f697c:/Clients/PrinterSetupWizard/SecondPage.cpp?ds=sidebyside diff --git a/Clients/PrinterSetupWizard/SecondPage.cpp b/Clients/PrinterSetupWizard/SecondPage.cpp index f5647a6..1521d0d 100644 --- a/Clients/PrinterSetupWizard/SecondPage.cpp +++ b/Clients/PrinterSetupWizard/SecondPage.cpp @@ -1,82 +1,19 @@ -/* +/* -*- Mode: C; tab-width: 4 -*- + * * Copyright (c) 1997-2004 Apple Computer, Inc. All rights reserved. * - * @APPLE_LICENSE_HEADER_START@ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * http://www.apache.org/licenses/LICENSE-2.0 * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and * limitations under the License. - * - * @APPLE_LICENSE_HEADER_END@ - - Change History (most recent first): - -$Log: SecondPage.cpp,v $ -Revision 1.15 2005/04/13 17:46:22 shersche - Generic PCL not selected when printers advertise multiple text records - -Revision 1.14 2005/03/20 20:08:37 shersche - Second screen should not select a printer by default - -Revision 1.13 2005/02/15 07:50:10 shersche - Update name - -Revision 1.12 2005/02/10 22:35:11 cheshire - Update name - -Revision 1.11 2005/01/31 23:54:30 shersche - Start browsing when printer wizard starts. Move browsing logic from CSecondPage object to CPrinterSetupWizardSheet object. - -Revision 1.10 2005/01/20 19:54:38 shersche -Fix parse error when text record is NULL - -Revision 1.9 2005/01/06 08:13:50 shersche -Don't use moreComing flag to determine number of text record, disregard queue name if qtotal isn't defined, don't disregard queue name if "rp" is the only key specified - -Revision 1.8 2005/01/04 21:09:14 shersche -Fix problems in parsing text records. Fix problems in remove event handling. Ensure that the same service can't be resolved more than once. - -Revision 1.7 2004/12/31 07:25:27 shersche -Tidy up printer management, and fix memory leaks when hitting 'Cancel' - -Revision 1.6 2004/12/30 01:24:02 shersche - Remove references to description key -Bug #: 3906182 - -Revision 1.5 2004/12/30 01:02:47 shersche - Add Printer information box that displays description and location information when printer name is selected -Bug #: 3734478 - -Revision 1.4 2004/12/29 18:53:38 shersche - - Added support for LPR and IPP protocols as well as support for obtaining multiple text records. Reorganized and simplified codebase. -Bug #: 3725106, 3737413 - -Revision 1.3 2004/09/13 21:26:15 shersche - Use the moreComing flag to determine whether drawing should take place in OnAddPrinter and OnRemovePrinter callbacks -Bug #: 3796483 - -Revision 1.2 2004/06/26 03:19:57 shersche -clean up warning messages - -Submitted by: herscher - -Revision 1.1 2004/06/18 04:36:57 rpantos -First checked in - - -*/ + */ #include "stdafx.h" #include "PrinterSetupWizardApp.h" @@ -121,6 +58,12 @@ CSecondPage::InitBrowseList() psheet = reinterpret_cast(GetParent()); require_quiet( psheet, exit ); + // Initialize so that nothing is selected when we add to the list + + psheet->SetSelectedPrinter( NULL ); + m_gotChoice = false; + m_browseList.Select( NULL, TVGN_FIRSTVISIBLE ); + // // load the no printers message until something shows up in the browse list // @@ -140,11 +83,6 @@ CSecondPage::InitBrowseList() m_descriptionField.SetWindowText( L"" ); m_locationField.SetWindowText( L"" ); - // - // and wait for the user to either hit the mouse or keyboard before selecting an item - // - m_gotChoice = false; - exit: return; @@ -193,6 +131,7 @@ CSecondPage::OnSetActive() { CPrinterSetupWizardSheet * psheet; Printer * printer; + CWnd * pWnd; Printers::iterator it; OSStatus err = kNoErr; BOOL b; @@ -202,23 +141,43 @@ CSecondPage::OnSetActive() psheet = reinterpret_cast(GetParent()); require_action( psheet, exit, err = kUnknownErr ); + // Stash the selected printer if any + + printer = psheet->GetSelectedPrinter(); + // initialize the browse list...this will remove everything currently // in it, and add the no printers item InitBrowseList(); - // And populate the list with any printers that we currently know about + // Populate the list with any printers that we currently know about for ( it = psheet->m_printers.begin(); it != psheet->m_printers.end(); it++ ) { OnAddPrinter( *it, false ); } - printer = psheet->GetSelectedPrinter(); + if ( ( !printer && ( psheet->m_printers.size() > 0 ) ) || ( printer != psheet->GetSelectedPrinter() ) ) + { + if ( !printer ) + { + printer = psheet->m_printers.front(); + } - if ( printer != NULL ) + psheet->SetSelectedPrinter( printer ); + } + + if ( printer ) { - m_browseList.Select( printer->item, TVGN_FIRSTVISIBLE ); + m_browseList.SelectItem( printer->item ); + ::SetFocus( m_browseList ); + } + + // Hide the back button + pWnd = ((CPropertySheet*)GetParent())->GetDlgItem(ID_WIZBACK); + if ( pWnd != NULL ) + { + pWnd->ShowWindow(SW_HIDE); } exit: @@ -230,6 +189,23 @@ exit: BOOL CSecondPage::OnKillActive() { + CPrinterSetupWizardSheet * psheet; + CWnd * pWnd; + + psheet = reinterpret_cast(GetParent()); + require_quiet( psheet, exit ); + + psheet->SetLastPage(this); + + // Show the back button + pWnd = ((CPropertySheet*)GetParent())->GetDlgItem(ID_WIZBACK); + if ( pWnd != NULL ) + { + pWnd->ShowWindow(SW_SHOW); + } + +exit: + return CPropertyPage::OnKillActive(); } @@ -249,6 +225,7 @@ CSecondPage::OnAddPrinter( bool moreComing ) { CPrinterSetupWizardSheet * psheet; + Printer * selectedPrinter; OSStatus err = kNoErr; check( IsWindow( m_hWnd ) ); @@ -258,26 +235,38 @@ CSecondPage::OnAddPrinter( psheet = reinterpret_cast(GetParent()); require_quiet( psheet, exit ); - printer->item = m_browseList.InsertItem(printer->displayName); + if ( printer ) + { + selectedPrinter = psheet->GetSelectedPrinter(); - m_browseList.SetItemData( printer->item, (DWORD_PTR) printer ); + printer->item = m_browseList.InsertItem(printer->displayName); - m_browseList.SortChildren(TVI_ROOT); + m_browseList.SetItemData( printer->item, (DWORD_PTR) printer ); - // - // if the searching item is still in the list - // get rid of it - // - // note that order is important here. Insert the printer - // item before removing the placeholder so we always have - // an item in the list to avoid experiencing the bug - // in Microsoft's implementation of CTreeCtrl - // - if (m_emptyListItem != NULL) - { - m_browseList.DeleteItem(m_emptyListItem); - m_emptyListItem = NULL; - m_browseList.EnableWindow(TRUE); + m_browseList.SortChildren(TVI_ROOT); + + // + // if the searching item is still in the list + // get rid of it + // + // note that order is important here. Insert the printer + // item before removing the placeholder so we always have + // an item in the list to avoid experiencing the bug + // in Microsoft's implementation of CTreeCtrl + // + if (m_emptyListItem != NULL) + { + m_browseList.DeleteItem(m_emptyListItem); + m_emptyListItem = NULL; + m_browseList.EnableWindow(TRUE); + } + + if ( !selectedPrinter ) + { + psheet->SetSelectedPrinter( printer ); + m_browseList.SelectItem( printer->item ); + ::SetFocus( m_browseList ); + } } exit: @@ -308,25 +297,28 @@ CSecondPage::OnRemovePrinter( m_browseList.SetRedraw(FALSE); - // - // check to make sure if we're the only item in the control...i.e. - // the list size is 1. - // - if (m_browseList.GetCount() > 1) - { - // - // if we're not the only thing in the list, then - // simply remove it from the list - // - m_browseList.DeleteItem( printer->item ); - } - else + if ( printer ) { // - // if we're the only thing in the list, then redisplay - // it with the no printers message + // check to make sure if we're the only item in the control...i.e. + // the list size is 1. // - InitBrowseList(); + if (m_browseList.GetCount() > 1) + { + // + // if we're not the only thing in the list, then + // simply remove it from the list + // + m_browseList.DeleteItem( printer->item ); + } + else + { + // + // if we're the only thing in the list, then redisplay + // it with the no printers message + // + InitBrowseList(); + } } exit: