Refactor common code into reusable MacGetPrinterName() function

No real changes, just add a simple helper function instead of
duplicating it in 2 different places.

This also provides a unique place to write the comment explaining why
PMPrinterGetID() is being used instead of PMPrinterGetName().

See #16774.
This commit is contained in:
Vadim Zeitlin
2019-10-22 02:55:49 +02:00
parent 7fa0074e1d
commit 5d8fdcb874

View File

@@ -37,6 +37,15 @@
#include <stdlib.h>
// Helper function to get the printer "name": actually we use its unique ID
// instead of the human-readable name which is not guaranteed to be unique.
static wxString MacGetPrinterName(PMPrinter printer)
{
CFStringRef printerId = PMPrinterGetID(printer);
CFRetain(printerId);
return wxCFStringRef(printerId).AsString();
}
//
// move to print_osx.cpp
//
@@ -124,13 +133,9 @@ void wxOSXPrintData::TransferPrinterNameFrom( const wxPrintData &data )
printer = (PMPrinter)CFArrayGetValueAtIndex(printerList, index);
if ((data.GetPrinterName().empty()) && (PMPrinterIsDefault(printer)))
break;
else
{
CFStringRef printerId = PMPrinterGetID(printer);
CFRetain(printerId);
if (data.GetPrinterName() == wxCFStringRef(printerId).AsString())
break;
}
if (data.GetPrinterName() == MacGetPrinterName(printer))
break;
}
if (index < count)
PMSessionSetCurrentPMPrinter(m_macPrintSession, printer);
@@ -305,11 +310,7 @@ void wxOSXPrintData::TransferPrinterNameTo( wxPrintData &data )
if (PMPrinterIsDefault(printer))
data.SetPrinterName(wxEmptyString);
else
{
CFStringRef printerId = PMPrinterGetID(printer);
CFRetain(printerId);
data.SetPrinterName(wxCFStringRef(printerId).AsString());
}
data.SetPrinterName(MacGetPrinterName(printer));
}
void wxOSXPrintData::TransferPaperInfoTo( wxPrintData &data )