Kaydet (Commit) 0d4f4223 authored tarafından Douglas Mencken's avatar Douglas Mencken Kaydeden (comit) Norbert Thiebaud

vcl.osx.print: convert to use modern API for print dialog

Change-Id: Icc7d7ad95d1ffbf55f1cd704148f3ceb58618e6c
Reviewed-on: https://gerrit.libreoffice.org/19432Reviewed-by: 's avatarNorbert Thiebaud <nthiebaud@gmail.com>
Tested-by: 's avatarNorbert Thiebaud <nthiebaud@gmail.com>
üst caf093e5
...@@ -42,7 +42,8 @@ struct PrintAccessoryViewState ...@@ -42,7 +42,8 @@ struct PrintAccessoryViewState
vcl::PrinterController* mpController; vcl::PrinterController* mpController;
AquaSalInfoPrinter* mpInfoPrinter; AquaSalInfoPrinter* mpInfoPrinter;
} }
-(id)initWithController: (vcl::PrinterController*)pController withInfoPrinter: (AquaSalInfoPrinter*)pInfoPrinter; -(id)initWithController: (vcl::PrinterController*)pController
withInfoPrinter: (AquaSalInfoPrinter*)pInfoPrinter;
-(BOOL)knowsPageRange: (NSRangePointer)range; -(BOOL)knowsPageRange: (NSRangePointer)range;
-(NSRect)rectForPage: (int)page; -(NSRect)rectForPage: (int)page;
-(NSPoint)locationOfPrintRect: (NSRect)aRect; -(NSPoint)locationOfPrintRect: (NSRect)aRect;
...@@ -52,7 +53,9 @@ struct PrintAccessoryViewState ...@@ -52,7 +53,9 @@ struct PrintAccessoryViewState
@interface AquaPrintAccessoryView : NSObject @interface AquaPrintAccessoryView : NSObject
{ {
} }
+(NSObject*)setupPrinterPanel: (NSPrintOperation*)pOp withController: (vcl::PrinterController*)pController withState: (PrintAccessoryViewState*)pState; +(NSObject*)setupPrinterPanel: (NSPrintOperation*)pOp
withController: (vcl::PrinterController*)pController
withState: (PrintAccessoryViewState*)pState;
@end @end
#endif // INCLUDED_VCL_INC_OSX_PRINTVIEW_H #endif // INCLUDED_VCL_INC_OSX_PRINTVIEW_H
......
...@@ -45,11 +45,15 @@ using namespace com::sun::star; ...@@ -45,11 +45,15 @@ using namespace com::sun::star;
using namespace com::sun::star::beans; using namespace com::sun::star::beans;
using namespace com::sun::star::uno; using namespace com::sun::star::uno;
/* Note: the accessory view as implemented here is already deprecated in Leopard. Unfortunately #if MACOSX_SDK_VERSION <= 1040
as long as our baseline is Tiger we cannot gain the advantages over multiple accessory views // as long as you are linking with 10.4 libraries there's no preview
as well havs having accessory views AND a preview (as long as you are linked vs. 10.4 libraries # define VINTAGE_IMPLEMENTATION_OF_PRINT_DIALOG
the preview insists on not being present. This is unfortunate. # undef MODERN_IMPLEMENTATION_OF_PRINT_DIALOG
*/ #else
// since 10.5 you can use multiple accessory views and have accessory views and a preview
# define MODERN_IMPLEMENTATION_OF_PRINT_DIALOG
# undef VINTAGE_IMPLEMENTATION_OF_PRINT_DIALOG
#endif
class ControllerProperties; class ControllerProperties;
...@@ -60,53 +64,163 @@ class ControllerProperties; ...@@ -60,53 +64,163 @@ class ControllerProperties;
-(id)initWithControllerMap: (ControllerProperties*)pController; -(id)initWithControllerMap: (ControllerProperties*)pController;
-(void)triggered:(id)pSender; -(void)triggered:(id)pSender;
-(void)triggeredNumeric:(id)pSender; -(void)triggeredNumeric:(id)pSender;
#ifdef VINTAGE_IMPLEMENTATION_OF_PRINT_DIALOG
-(void)triggeredPreview:(id)pSender; -(void)triggeredPreview:(id)pSender;
#endif
-(void)dealloc; -(void)dealloc;
@end @end
#ifdef MODERN_IMPLEMENTATION_OF_PRINT_DIALOG
@interface AquaPrintPanelAccessoryController : NSViewController< NSPrintPanelAccessorizing >
{
NSPrintOperation *mpPrintOperation;
vcl::PrinterController *mpPrinterController;
PrintAccessoryViewState *mpViewState;
}
-(void)forPrintOperation:(NSPrintOperation*)pPrintOp;
-(void)withPrinterController:(vcl::PrinterController*)pController;
-(void)withViewState:(PrintAccessoryViewState*)pState;
-(NSPrintOperation*)printOperation;
-(vcl::PrinterController*)printerController;
-(PrintAccessoryViewState*)viewState;
-(NSSet*)keyPathsForValuesAffectingPreview;
-(NSArray*)localizedSummaryItems;
-(sal_Int32)updatePrintOperation:(sal_Int32)pLastPageCount;
@end
@implementation AquaPrintPanelAccessoryController
-(void)forPrintOperation:(NSPrintOperation*)pPrintOp
{ mpPrintOperation = pPrintOp; }
-(void)withPrinterController:(vcl::PrinterController*)pController
{ mpPrinterController = pController; }
-(void)withViewState:(PrintAccessoryViewState*)pState
{ mpViewState = pState; }
-(NSPrintOperation*)printOperation
{ return mpPrintOperation; }
-(vcl::PrinterController*)printerController
{ return mpPrinterController; }
-(PrintAccessoryViewState*)viewState
{ return mpViewState; }
-(NSSet*)keyPathsForValuesAffectingPreview
{
return [ NSSet setWithObject:@"updatePrintOperation" ];
}
-(NSArray*)localizedSummaryItems
{
return [ NSArray arrayWithObject:
[ NSDictionary dictionary ] ];
}
-(sal_Int32)updatePrintOperation:(sal_Int32)pLastPageCount
{
// page range may be changed by option choice
sal_Int32 nPages = mpPrinterController->getFilteredPageCount();
mpViewState->bNeedRestart = false;
if( nPages != pLastPageCount )
{
#if OSL_DEBUG_LEVEL > 1
SAL_INFO( "vcl.osx.print", "number of pages changed" <<
" from " << pLastPageCount << " to " << nPages );
#endif
mpViewState->bNeedRestart = true;
}
NSTabView* pTabView = [[[self view] subviews] objectAtIndex:0];
NSTabViewItem* pItem = [pTabView selectedTabViewItem];
if( pItem )
mpViewState->nLastPage = [pTabView indexOfTabViewItem: pItem];
else
mpViewState->nLastPage = 0;
if( mpViewState->bNeedRestart )
{
// AppKit does not give a chance of changing the page count
// and don't let cancel the dialog either
// hack: send a cancel message to the modal window displaying views
NSWindow* pNSWindow = [NSApp modalWindow];
if( pNSWindow )
[pNSWindow cancelOperation: nil];
[[mpPrintOperation printInfo] setJobDisposition: NSPrintCancelJob];
}
return nPages;
}
@end
#endif
class ControllerProperties class ControllerProperties
{ {
vcl::PrinterController* mpController;
std::map< int, rtl::OUString > maTagToPropertyName; std::map< int, rtl::OUString > maTagToPropertyName;
std::map< int, sal_Int32 > maTagToValueInt; std::map< int, sal_Int32 > maTagToValueInt;
std::map< NSView*, NSView* > maViewPairMap; std::map< NSView*, NSView* > maViewPairMap;
std::vector< NSObject* > maViews; std::vector< NSObject* > maViews;
int mnNextTag; int mnNextTag;
sal_Int32 mnLastPageCount; sal_Int32 mnLastPageCount;
PrintAccessoryViewState* mpState; ResStringArray maLocalizedStrings;
#ifdef VINTAGE_IMPLEMENTATION_OF_PRINT_DIALOG
vcl::PrinterController* mpController;
NSPrintOperation* mpOp; NSPrintOperation* mpOp;
PrintAccessoryViewState* mpState;
NSBox* mpPreviewBox;
NSImageView* mpPreview; // print preview is not provided "by default"
NSView* mpAccessoryView; NSView* mpAccessoryView;
NSTabView* mpTabView; NSTabView* mpTabView;
NSBox* mpPreviewBox;
NSImageView* mpPreview;
NSTextField* mpPageEdit; NSTextField* mpPageEdit;
NSStepper* mpStepper; NSStepper* mpStepper;
NSTextView* mpPagesLabel; #else
ResStringArray maLocalizedStrings; AquaPrintPanelAccessoryController* mpAccessoryController;
#endif
public: public:
ControllerProperties( vcl::PrinterController* i_pController, ControllerProperties(
NSPrintOperation* i_pOp, #ifdef VINTAGE_IMPLEMENTATION_OF_PRINT_DIALOG
NSView* i_pAccessoryView, vcl::PrinterController* i_pController
NSTabView* i_pTabView, , NSPrintOperation* i_pOp
PrintAccessoryViewState* i_pState ) , PrintAccessoryViewState* i_pState
: mpController( i_pController ), , NSView* i_pAccessoryView
mnNextTag( 0 ), , NSTabView* i_pTabView
mnLastPageCount( i_pController->getFilteredPageCount() ), #else
mpState( i_pState ), AquaPrintPanelAccessoryController* i_pAccessoryController
mpOp( i_pOp ), #endif
mpAccessoryView( i_pAccessoryView ), )
mpTabView( i_pTabView ), : mnNextTag( 0 )
mpPreviewBox( nil ), #ifdef VINTAGE_IMPLEMENTATION_OF_PRINT_DIALOG
mpPreview( nil ), , mnLastPageCount( i_pController->getFilteredPageCount() )
mpPageEdit( nil ), , mpController( i_pController )
mpStepper( nil ), , mpOp( i_pOp )
mpPagesLabel( nil ), , mpState( i_pState )
maLocalizedStrings( VclResId( SV_PRINT_NATIVE_STRINGS ) ) , mpPreviewBox( nil )
, mpPreview( nil )
, mpAccessoryView( i_pAccessoryView )
, mpTabView( i_pTabView )
, mpPageEdit( nil )
, mpStepper( nil )
#else
, mnLastPageCount( [i_pAccessoryController printerController]->getFilteredPageCount() )
#endif
, maLocalizedStrings( VclResId( SV_PRINT_NATIVE_STRINGS ) )
#ifdef MODERN_IMPLEMENTATION_OF_PRINT_DIALOG
, mpAccessoryController( i_pAccessoryController )
#endif
{ {
mpState->bNeedRestart = false; assert( maLocalizedStrings.Count() >= 5 && "resources not found" );
DBG_ASSERT( maLocalizedStrings.Count() >= 5, "resources not found !" );
} }
rtl::OUString getMoreString() rtl::OUString getMoreString()
...@@ -123,30 +237,34 @@ class ControllerProperties ...@@ -123,30 +237,34 @@ class ControllerProperties
: OUString( "Print selection only" ); : OUString( "Print selection only" );
} }
#ifdef VINTAGE_IMPLEMENTATION_OF_PRINT_DIALOG
void updatePrintJob() void updatePrintJob()
{ {
// TODO: refresh page count etc from mpController // page range may be changed by option choice
// page range may have changed depending on options
sal_Int32 nPages = mpController->getFilteredPageCount(); sal_Int32 nPages = mpController->getFilteredPageCount();
#if OSL_DEBUG_LEVEL > 1
mpState->bNeedRestart = false;
if( nPages != mnLastPageCount ) if( nPages != mnLastPageCount )
fprintf( stderr, "trouble: number of pages changed from %ld to %ld !\n", mnLastPageCount, nPages ); {
#if OSL_DEBUG_LEVEL > 1
SAL_INFO( "vcl.osx.print", "number of pages changed" <<
" from " << mnLastPageCount << " to " << nPages );
#endif #endif
mpState->bNeedRestart = (nPages != mnLastPageCount); mpState->bNeedRestart = true;
}
mnLastPageCount = nPages;
NSTabViewItem* pItem = [mpTabView selectedTabViewItem]; NSTabViewItem* pItem = [mpTabView selectedTabViewItem];
if( pItem ) if( pItem )
mpState->nLastPage = [mpTabView indexOfTabViewItem: pItem]; mpState->nLastPage = [mpTabView indexOfTabViewItem: pItem];
else else
mpState->nLastPage = 0; mpState->nLastPage = 0;
mnLastPageCount = nPages;
if( mpState->bNeedRestart ) if( mpState->bNeedRestart )
{ {
// Warning: bad hack ahead // AppKit does not give a chance of changing the page count
// Apple does not give us a chance of changing the page count, // and don't let cancel the dialog either
// and they don't let us cancel the dialog either // hack: send a cancel message to the modal window displaying views
// hack: send a cancel message to the window displaying our views.
// this is ugly.
NSWindow* pNSWindow = [NSApp modalWindow]; NSWindow* pNSWindow = [NSApp modalWindow];
if( pNSWindow ) if( pNSWindow )
[pNSWindow cancelOperation: nil]; [pNSWindow cancelOperation: nil];
...@@ -158,6 +276,7 @@ class ControllerProperties ...@@ -158,6 +276,7 @@ class ControllerProperties
updatePreviewImage( nPage-1 ); updatePreviewImage( nPage-1 );
} }
} }
#endif
int addNameTag( const rtl::OUString& i_rPropertyName ) int addNameTag( const rtl::OUString& i_rPropertyName )
{ {
...@@ -200,11 +319,18 @@ class ControllerProperties ...@@ -200,11 +319,18 @@ class ControllerProperties
std::map< int, sal_Int32 >::const_iterator value_it = maTagToValueInt.find( i_nTag ); std::map< int, sal_Int32 >::const_iterator value_it = maTagToValueInt.find( i_nTag );
if( name_it != maTagToPropertyName.end() && value_it != maTagToValueInt.end() ) if( name_it != maTagToPropertyName.end() && value_it != maTagToValueInt.end() )
{ {
#ifdef MODERN_IMPLEMENTATION_OF_PRINT_DIALOG
vcl::PrinterController * mpController = [mpAccessoryController printerController];
#endif
PropertyValue* pVal = mpController->getValue( name_it->second ); PropertyValue* pVal = mpController->getValue( name_it->second );
if( pVal ) if( pVal )
{ {
pVal->Value <<= value_it->second; pVal->Value <<= value_it->second;
#ifdef VINTAGE_IMPLEMENTATION_OF_PRINT_DIALOG
updatePrintJob(); updatePrintJob();
#else
mnLastPageCount = [mpAccessoryController updatePrintOperation: mnLastPageCount];
#endif
} }
} }
} }
...@@ -214,11 +340,18 @@ class ControllerProperties ...@@ -214,11 +340,18 @@ class ControllerProperties
std::map< int, rtl::OUString >::const_iterator name_it = maTagToPropertyName.find( i_nTag ); std::map< int, rtl::OUString >::const_iterator name_it = maTagToPropertyName.find( i_nTag );
if( name_it != maTagToPropertyName.end() ) if( name_it != maTagToPropertyName.end() )
{ {
#ifdef MODERN_IMPLEMENTATION_OF_PRINT_DIALOG
vcl::PrinterController * mpController = [mpAccessoryController printerController];
#endif
PropertyValue* pVal = mpController->getValue( name_it->second ); PropertyValue* pVal = mpController->getValue( name_it->second );
if( pVal ) if( pVal )
{ {
pVal->Value <<= i_nValue; pVal->Value <<= i_nValue;
#ifdef VINTAGE_IMPLEMENTATION_OF_PRINT_DIALOG
updatePrintJob(); updatePrintJob();
#else
mnLastPageCount = [mpAccessoryController updatePrintOperation: mnLastPageCount];
#endif
} }
} }
} }
...@@ -228,6 +361,9 @@ class ControllerProperties ...@@ -228,6 +361,9 @@ class ControllerProperties
std::map< int, rtl::OUString >::const_iterator name_it = maTagToPropertyName.find( i_nTag ); std::map< int, rtl::OUString >::const_iterator name_it = maTagToPropertyName.find( i_nTag );
if( name_it != maTagToPropertyName.end() ) if( name_it != maTagToPropertyName.end() )
{ {
#ifdef MODERN_IMPLEMENTATION_OF_PRINT_DIALOG
vcl::PrinterController * mpController = [mpAccessoryController printerController];
#endif
PropertyValue* pVal = mpController->getValue( name_it->second ); PropertyValue* pVal = mpController->getValue( name_it->second );
if( pVal ) if( pVal )
{ {
...@@ -236,7 +372,11 @@ class ControllerProperties ...@@ -236,7 +372,11 @@ class ControllerProperties
pVal->Value <<= i_bValue ? sal_Int32(2) : sal_Int32(0); pVal->Value <<= i_bValue ? sal_Int32(2) : sal_Int32(0);
else else
pVal->Value <<= i_bValue; pVal->Value <<= i_bValue;
#ifdef VINTAGE_IMPLEMENTATION_OF_PRINT_DIALOG
updatePrintJob(); updatePrintJob();
#else
mnLastPageCount = [mpAccessoryController updatePrintOperation: mnLastPageCount];
#endif
} }
} }
} }
...@@ -246,11 +386,18 @@ class ControllerProperties ...@@ -246,11 +386,18 @@ class ControllerProperties
std::map< int, rtl::OUString >::const_iterator name_it = maTagToPropertyName.find( i_nTag ); std::map< int, rtl::OUString >::const_iterator name_it = maTagToPropertyName.find( i_nTag );
if( name_it != maTagToPropertyName.end() ) if( name_it != maTagToPropertyName.end() )
{ {
#ifdef MODERN_IMPLEMENTATION_OF_PRINT_DIALOG
vcl::PrinterController * mpController = [mpAccessoryController printerController];
#endif
PropertyValue* pVal = mpController->getValue( name_it->second ); PropertyValue* pVal = mpController->getValue( name_it->second );
if( pVal ) if( pVal )
{ {
pVal->Value <<= i_rValue; pVal->Value <<= i_rValue;
#ifdef VINTAGE_IMPLEMENTATION_OF_PRINT_DIALOG
updatePrintJob(); updatePrintJob();
#else
mnLastPageCount = [mpAccessoryController updatePrintOperation: mnLastPageCount];
#endif
} }
} }
} }
...@@ -274,6 +421,9 @@ class ControllerProperties ...@@ -274,6 +421,9 @@ class ControllerProperties
std::map< int, rtl::OUString >::const_iterator name_it = maTagToPropertyName.find( nTag ); std::map< int, rtl::OUString >::const_iterator name_it = maTagToPropertyName.find( nTag );
if( name_it != maTagToPropertyName.end() && ! name_it->second.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("PrintContent")) ) if( name_it != maTagToPropertyName.end() && ! name_it->second.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("PrintContent")) )
{ {
#ifdef MODERN_IMPLEMENTATION_OF_PRINT_DIALOG
vcl::PrinterController * mpController = [mpAccessoryController printerController];
#endif
BOOL bEnabled = mpController->isUIOptionEnabled( name_it->second ) ? YES : NO; BOOL bEnabled = mpController->isUIOptionEnabled( name_it->second ) ? YES : NO;
if( pCtrl ) if( pCtrl )
{ {
...@@ -284,11 +434,12 @@ class ControllerProperties ...@@ -284,11 +434,12 @@ class ControllerProperties
} }
else if( pCell ) else if( pCell )
[pCell setEnabled: bEnabled]; [pCell setEnabled: bEnabled];
} }
} }
} }
#ifdef VINTAGE_IMPLEMENTATION_OF_PRINT_DIALOG
void updatePreviewImage( sal_Int32 i_nPage ) void updatePreviewImage( sal_Int32 i_nPage )
{ {
sal_Int32 nPages = mpController->getFilteredPageCount(); sal_Int32 nPages = mpController->getFilteredPageCount();
...@@ -372,14 +523,14 @@ class ControllerProperties ...@@ -372,14 +523,14 @@ class ControllerProperties
NSString* pText = CreateNSString( aBuf.makeStringAndClear() ); NSString* pText = CreateNSString( aBuf.makeStringAndClear() );
NSRect aTextRect = { { 100, 5 }, { 100, 22 } }; NSRect aTextRect = { { 100, 5 }, { 100, 22 } };
mpPagesLabel = [[NSTextView alloc] initWithFrame: aTextRect]; NSTextView* aPagesLabel = [[NSTextView alloc] initWithFrame: aTextRect];
[mpPagesLabel setFont: [NSFont controlContentFontOfSize: 0]]; [aPagesLabel setFont: [NSFont controlContentFontOfSize: 0]];
[mpPagesLabel setEditable: NO]; [aPagesLabel setEditable: NO];
[mpPagesLabel setSelectable: NO]; [aPagesLabel setSelectable: NO];
[mpPagesLabel setDrawsBackground: NO]; [aPagesLabel setDrawsBackground: NO];
[mpPagesLabel setString: [pText autorelease]]; [aPagesLabel setString: [pText autorelease]];
[mpPagesLabel setToolTip: [CreateNSString( maLocalizedStrings.GetString( 2 ) ) autorelease]]; [aPagesLabel setToolTip: [CreateNSString( maLocalizedStrings.GetString( 2 ) ) autorelease]];
[mpPreviewBox addSubview: [mpPagesLabel autorelease]]; [mpPreviewBox addSubview: [aPagesLabel autorelease]];
NSRect aFieldRect = { { 45, 5 }, { 35, 25 } }; NSRect aFieldRect = { { 45, 5 }, { 35, 25 } };
mpPageEdit = [[NSTextField alloc] initWithFrame: aFieldRect]; mpPageEdit = [[NSTextField alloc] initWithFrame: aFieldRect];
...@@ -444,6 +595,9 @@ class ControllerProperties ...@@ -444,6 +595,9 @@ class ControllerProperties
} }
} }
} }
#endif
}; };
static OUString filterAccelerator( rtl::OUString const & rText ) static OUString filterAccelerator( rtl::OUString const & rText )
...@@ -455,6 +609,7 @@ static OUString filterAccelerator( rtl::OUString const & rText ) ...@@ -455,6 +609,7 @@ static OUString filterAccelerator( rtl::OUString const & rText )
} }
@implementation ControlTarget @implementation ControlTarget
-(id)initWithControllerMap: (ControllerProperties*)pController -(id)initWithControllerMap: (ControllerProperties*)pController
{ {
if( (self = [super init]) ) if( (self = [super init]) )
...@@ -463,6 +618,7 @@ static OUString filterAccelerator( rtl::OUString const & rText ) ...@@ -463,6 +618,7 @@ static OUString filterAccelerator( rtl::OUString const & rText )
} }
return self; return self;
} }
-(void)triggered:(id)pSender -(void)triggered:(id)pSender
{ {
if( [pSender isMemberOfClass: [NSPopUpButton class]] ) if( [pSender isMemberOfClass: [NSPopUpButton class]] )
...@@ -500,10 +656,12 @@ static OUString filterAccelerator( rtl::OUString const & rText ) ...@@ -500,10 +656,12 @@ static OUString filterAccelerator( rtl::OUString const & rText )
} }
else else
{ {
SAL_INFO( "vcl.osx.print", "Unsupported class" << ([pSender class] ? [NSStringFromClass([pSender class]) UTF8String] : "nil")); SAL_INFO( "vcl.osx.print", "Unsupported class" <<
( [pSender class] ? [NSStringFromClass([pSender class]) UTF8String] : "nil" ) );
} }
mpController->updateEnableState(); mpController->updateEnableState();
} }
-(void)triggeredNumeric:(id)pSender -(void)triggeredNumeric:(id)pSender
{ {
if( [pSender isMemberOfClass: [NSTextField class]] ) if( [pSender isMemberOfClass: [NSTextField class]] )
...@@ -532,19 +690,25 @@ static OUString filterAccelerator( rtl::OUString const & rText ) ...@@ -532,19 +690,25 @@ static OUString filterAccelerator( rtl::OUString const & rText )
} }
else else
{ {
SAL_INFO( "vcl.osx.print", "Unsupported class" << ([pSender class] ? [NSStringFromClass([pSender class]) UTF8String] : "nil")); SAL_INFO( "vcl.osx.print", "Unsupported class" <<
([pSender class] ? [NSStringFromClass([pSender class]) UTF8String] : "nil") );
} }
mpController->updateEnableState(); mpController->updateEnableState();
} }
#ifdef VINTAGE_IMPLEMENTATION_OF_PRINT_DIALOG
-(void)triggeredPreview:(id)pSender -(void)triggeredPreview:(id)pSender
{ {
mpController->changePreview( pSender ); mpController->changePreview( pSender );
} }
#endif
-(void)dealloc -(void)dealloc
{ {
delete mpController; delete mpController;
[super dealloc]; [super dealloc];
} }
@end @end
struct ColumnItem struct ColumnItem
...@@ -728,10 +892,11 @@ static sal_Int32 findBreak( const rtl::OUString& i_rText, sal_Int32 i_nPos ) ...@@ -728,10 +892,11 @@ static sal_Int32 findBreak( const rtl::OUString& i_rText, sal_Int32 i_nPos )
Reference< i18n::XBreakIterator > xBI( vcl::unohelper::CreateBreakIterator() ); Reference< i18n::XBreakIterator > xBI( vcl::unohelper::CreateBreakIterator() );
if( xBI.is() ) if( xBI.is() )
{ {
i18n::Boundary aBoundary = xBI->getWordBoundary( i_rText, i_nPos, i18n::Boundary aBoundary =
xBI->getWordBoundary( i_rText, i_nPos,
Application::GetSettings().GetLanguageTag().getLocale(), Application::GetSettings().GetLanguageTag().getLocale(),
i18n::WordType::ANYWORD_IGNOREWHITESPACES, i18n::WordType::ANYWORD_IGNOREWHITESPACES,
sal_True ); true );
nRet = aBoundary.endPos; nRet = aBoundary.endPos;
} }
return nRet; return nRet;
...@@ -855,7 +1020,9 @@ static void addRadio( NSView* pCurParent, long& rCurX, long& rCurY, long nAttach ...@@ -855,7 +1020,9 @@ static void addRadio( NSView* pCurParent, long& rCurX, long& rCurY, long nAttach
// setup radio matrix // setup radio matrix
NSButtonCell* pProto = [[NSButtonCell alloc] init]; NSButtonCell* pProto = [[NSButtonCell alloc] init];
NSRect aRadioRect = { { static_cast<CGFloat>(rCurX + nOff), 0 }, { static_cast<CGFloat>(280 - rCurX), static_cast<CGFloat>(5*rChoices.getLength()) } }; NSRect aRadioRect = { { static_cast<CGFloat>(rCurX + nOff), 0 },
{ static_cast<CGFloat>(280 - rCurX),
static_cast<CGFloat>(5*rChoices.getLength()) } };
[pProto setTitle: @"RadioButtonGroup"]; [pProto setTitle: @"RadioButtonGroup"];
[pProto setButtonType: NSRadioButton]; [pProto setButtonType: NSRadioButton];
NSMatrix* pMatrix = [[NSMatrix alloc] initWithFrame: aRadioRect NSMatrix* pMatrix = [[NSMatrix alloc] initWithFrame: aRadioRect
...@@ -1079,36 +1246,48 @@ static void addEdit( NSView* pCurParent, long& rCurX, long& rCurY, long nAttachO ...@@ -1079,36 +1246,48 @@ static void addEdit( NSView* pCurParent, long& rCurX, long& rCurY, long nAttachO
rCurY = aFieldRect.origin.y - 5; rCurY = aFieldRect.origin.y - 5;
} }
// In 10.5 and later:
// 'setAccessoryView:' is deprecated
// Make deprecation warnings just warnings in a -Werror compilation.
#ifdef __GNUC__
// #pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
#endif
@implementation AquaPrintAccessoryView @implementation AquaPrintAccessoryView
+(NSObject*)setupPrinterPanel: (NSPrintOperation*)pOp withController: (vcl::PrinterController*)pController withState: (PrintAccessoryViewState*)pState
+(NSObject*)setupPrinterPanel: (NSPrintOperation*)pOp
withController: (vcl::PrinterController*)pController
withState: (PrintAccessoryViewState*)pState
{ {
const Sequence< PropertyValue >& rOptions( pController->getUIOptions() ); const Sequence< PropertyValue >& rOptions( pController->getUIOptions() );
if( rOptions.getLength() == 0 ) if( rOptions.getLength() == 0 )
return nil; return nil;
NSView* pCurParent = 0; NSRect aViewFrame = { NSZeroPoint, { 600, 400 } };
long nCurY = 0; #ifdef VINTAGE_IMPLEMENTATION_OF_PRINT_DIALOG
long nCurX = 0; NSRect aTabViewFrame = { { 190, 0 }, { 410, 400 } };
NSRect aViewFrame = { NSZeroPoint, {600, 400 } }; #else
NSRect aTabViewFrame = { { 190, 0 }, {410, 400 } }; NSRect aTabViewFrame = aViewFrame;
NSSize aMaxTabSize = NSZeroSize; #endif
NSView* pAccessoryView = [[NSView alloc] initWithFrame: aViewFrame]; NSView* pAccessoryView = [[NSView alloc] initWithFrame: aViewFrame];
NSTabView* pTabView = [[NSTabView alloc] initWithFrame: aTabViewFrame]; NSTabView* pTabView = [[NSTabView alloc] initWithFrame: aTabViewFrame];
[pAccessoryView addSubview: [pTabView autorelease]]; [pAccessoryView addSubview: [pTabView autorelease]];
bool bIgnoreSubgroup = false; #ifdef MODERN_IMPLEMENTATION_OF_PRINT_DIALOG
// create the accessory controller
AquaPrintPanelAccessoryController* pAccessoryController =
[[AquaPrintPanelAccessoryController alloc] initWithNibName: nil bundle: nil];
[pAccessoryController setView: [pAccessoryView autorelease]];
[pAccessoryController forPrintOperation: pOp];
[pAccessoryController withPrinterController: pController];
[pAccessoryController withViewState: pState];
#endif
NSView* pCurParent = 0;
long nCurY = 0;
long nCurX = 0;
NSSize aMaxTabSize = NSZeroSize;
ControllerProperties* pControllerProperties = new ControllerProperties( pController, pOp, pAccessoryView, pTabView, pState ); ControllerProperties* pControllerProperties =
#ifdef VINTAGE_IMPLEMENTATION_OF_PRINT_DIALOG
new ControllerProperties( pController, pOp, pState, pAccessoryView, pTabView );
#else
new ControllerProperties( pAccessoryController );
#endif
ControlTarget* pCtrlTarget = [[ControlTarget alloc] initWithControllerMap: pControllerProperties]; ControlTarget* pCtrlTarget = [[ControlTarget alloc] initWithControllerMap: pControllerProperties];
std::vector< ColumnItem > aLeftColumn, aRightColumn; std::vector< ColumnItem > aLeftColumn, aRightColumn;
...@@ -1116,6 +1295,7 @@ static void addEdit( NSView* pCurParent, long& rCurX, long& rCurY, long nAttachO ...@@ -1116,6 +1295,7 @@ static void addEdit( NSView* pCurParent, long& rCurX, long& rCurY, long nAttachO
// ugly: // ugly:
// prepend a "selection" checkbox if the properties have such a selection in PrintContent // prepend a "selection" checkbox if the properties have such a selection in PrintContent
bool bAddSelectionCheckBox = false, bSelectionBoxEnabled = false, bSelectionBoxChecked = false; bool bAddSelectionCheckBox = false, bSelectionBoxEnabled = false, bSelectionBoxChecked = false;
for( int i = 0; i < rOptions.getLength(); i++ ) for( int i = 0; i < rOptions.getLength(); i++ )
{ {
Sequence< beans::PropertyValue > aOptProp; Sequence< beans::PropertyValue > aOptProp;
...@@ -1167,15 +1347,15 @@ static void addEdit( NSView* pCurParent, long& rCurX, long& rCurY, long nAttachO ...@@ -1167,15 +1347,15 @@ static void addEdit( NSView* pCurParent, long& rCurX, long& rCurY, long nAttachO
rOptions[i].Value >>= aOptProp; rOptions[i].Value >>= aOptProp;
// extract ui element // extract ui element
bool bEnabled = true;
rtl::OUString aCtrlType; rtl::OUString aCtrlType;
rtl::OUString aText; rtl::OUString aText;
rtl::OUString aPropertyName; rtl::OUString aPropertyName;
rtl::OUString aGroupHint; rtl::OUString aGroupHint;
Sequence< rtl::OUString > aChoices; Sequence< rtl::OUString > aChoices;
bool bEnabled = true;
sal_Int64 nMinValue = 0, nMaxValue = 0; sal_Int64 nMinValue = 0, nMaxValue = 0;
long nAttachOffset = 0; long nAttachOffset = 0;
sal_Bool bIgnore = sal_False; bool bIgnore = false;
for( int n = 0; n < aOptProp.getLength(); n++ ) for( int n = 0; n < aOptProp.getLength(); n++ )
{ {
...@@ -1203,7 +1383,7 @@ static void addEdit( NSView* pCurParent, long& rCurX, long& rCurY, long nAttachO ...@@ -1203,7 +1383,7 @@ static void addEdit( NSView* pCurParent, long& rCurX, long& rCurY, long nAttachO
{ {
sal_Bool bValue = sal_True; sal_Bool bValue = sal_True;
rEntry.Value >>= bValue; rEntry.Value >>= bValue;
bEnabled = bValue; bEnabled = bValue ? true : false;
} }
else if( rEntry.Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("MinValue")) ) else if( rEntry.Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("MinValue")) )
{ {
...@@ -1219,7 +1399,9 @@ static void addEdit( NSView* pCurParent, long& rCurX, long& rCurY, long nAttachO ...@@ -1219,7 +1399,9 @@ static void addEdit( NSView* pCurParent, long& rCurX, long& rCurY, long nAttachO
} }
else if( rEntry.Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("InternalUIOnly")) ) else if( rEntry.Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("InternalUIOnly")) )
{ {
rEntry.Value >>= bIgnore; sal_Bool bValue = sal_False;
rEntry.Value >>= bValue;
bIgnore = bValue ? true : false;
} }
else if( rEntry.Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("GroupingHint")) ) else if( rEntry.Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("GroupingHint")) )
{ {
...@@ -1235,8 +1417,10 @@ static void addEdit( NSView* pCurParent, long& rCurX, long& rCurY, long nAttachO ...@@ -1235,8 +1417,10 @@ static void addEdit( NSView* pCurParent, long& rCurX, long& rCurY, long nAttachO
aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Range")) || aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Range")) ||
aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Bool")) ) aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Bool")) )
{ {
// since our build target is MacOSX 10.4 we can have only one accessory view bool bIgnoreSubgroup = false;
// so we have a single accessory view that is tabbed for grouping
// with `setAccessoryView' method only one accessory view can be set
// so create this single accessory view as tabbed for grouping
if( aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Group")) if( aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Group"))
|| ! pCurParent || ! pCurParent
|| ( aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Subgroup")) && nCurY < -250 && ! bIgnore ) || ( aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Subgroup")) && nCurY < -250 && ! bIgnore )
...@@ -1245,6 +1429,7 @@ static void addEdit( NSView* pCurParent, long& rCurX, long& rCurY, long nAttachO ...@@ -1245,6 +1429,7 @@ static void addEdit( NSView* pCurParent, long& rCurX, long& rCurY, long nAttachO
rtl::OUString aGroupTitle( aText ); rtl::OUString aGroupTitle( aText );
if( aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Subgroup")) ) if( aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Subgroup")) )
aGroupTitle = pControllerProperties->getMoreString(); aGroupTitle = pControllerProperties->getMoreString();
// set size of current parent // set size of current parent
if( pCurParent ) if( pCurParent )
adjustViewAndChildren( pCurParent, aMaxTabSize, aLeftColumn, aRightColumn ); adjustViewAndChildren( pCurParent, aMaxTabSize, aLeftColumn, aRightColumn );
...@@ -1260,10 +1445,8 @@ static void addEdit( NSView* pCurParent, long& rCurX, long& rCurY, long nAttachO ...@@ -1260,10 +1445,8 @@ static void addEdit( NSView* pCurParent, long& rCurX, long& rCurY, long nAttachO
[pItem setView: pCurParent]; [pItem setView: pCurParent];
[pLabel release]; [pLabel release];
// reset indent nCurX = 20; // reset indent
nCurX = 20; nCurY = 0; // reset Y
// reset Y
nCurY = 0;
// clear columns // clear columns
aLeftColumn.clear(); aLeftColumn.clear();
aRightColumn.clear(); aRightColumn.clear();
...@@ -1297,7 +1480,7 @@ static void addEdit( NSView* pCurParent, long& rCurX, long& rCurY, long nAttachO ...@@ -1297,7 +1480,7 @@ static void addEdit( NSView* pCurParent, long& rCurX, long& rCurY, long nAttachO
if( pVal ) if( pVal )
pVal->Value >>= bVal; pVal->Value >>= bVal;
addBool( pCurParent, nCurX, nCurY, nAttachOffset, addBool( pCurParent, nCurX, nCurY, nAttachOffset,
aText, true, aPropertyName, bVal, aText, true, aPropertyName, bVal?true:false,
aRightColumn, pControllerProperties, pCtrlTarget ); aRightColumn, pControllerProperties, pCtrlTarget );
} }
else if( aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Radio")) && pCurParent ) else if( aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Radio")) && pCurParent )
...@@ -1325,7 +1508,8 @@ static void addEdit( NSView* pCurParent, long& rCurX, long& rCurY, long nAttachO ...@@ -1325,7 +1508,8 @@ static void addEdit( NSView* pCurParent, long& rCurX, long& rCurY, long nAttachO
aLeftColumn, aRightColumn, aLeftColumn, aRightColumn,
pControllerProperties, pCtrlTarget ); pControllerProperties, pCtrlTarget );
} }
else if( (aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Edit")) || aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Range"))) && pCurParent ) else if( (aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Edit"))
|| aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Range"))) && pCurParent )
{ {
// current value // current value
PropertyValue* pVal = pController->getValue( aPropertyName ); PropertyValue* pVal = pController->getValue( aPropertyName );
...@@ -1345,9 +1529,11 @@ static void addEdit( NSView* pCurParent, long& rCurX, long& rCurY, long nAttachO ...@@ -1345,9 +1529,11 @@ static void addEdit( NSView* pCurParent, long& rCurX, long& rCurY, long nAttachO
pControllerProperties->updateEnableState(); pControllerProperties->updateEnableState();
adjustViewAndChildren( pCurParent, aMaxTabSize, aLeftColumn, aRightColumn ); adjustViewAndChildren( pCurParent, aMaxTabSize, aLeftColumn, aRightColumn );
// leave some space for the preview #ifdef VINTAGE_IMPLEMENTATION_OF_PRINT_DIALOG
// leave some space for preview
if( aMaxTabSize.height < 200 ) if( aMaxTabSize.height < 200 )
aMaxTabSize.height = 200; aMaxTabSize.height = 200;
#endif
// now reposition everything again so it is upper bound // now reposition everything again so it is upper bound
adjustTabViews( pTabView, aMaxTabSize ); adjustTabViews( pTabView, aMaxTabSize );
...@@ -1362,10 +1548,20 @@ static void addEdit( NSView* pCurParent, long& rCurX, long& rCurY, long nAttachO ...@@ -1362,10 +1548,20 @@ static void addEdit( NSView* pCurParent, long& rCurX, long& rCurY, long nAttachO
aViewFrame.size.height = aTabCtrlSize.height + aTabViewFrame.origin.y; aViewFrame.size.height = aTabCtrlSize.height + aTabViewFrame.origin.y;
[pAccessoryView setFrameSize: aViewFrame.size]; [pAccessoryView setFrameSize: aViewFrame.size];
#ifdef VINTAGE_IMPLEMENTATION_OF_PRINT_DIALOG
pControllerProperties->setupPreview( pCtrlTarget ); pControllerProperties->setupPreview( pCtrlTarget );
#endif
#ifdef VINTAGE_IMPLEMENTATION_OF_PRINT_DIALOG
// set the accessory view // set the accessory view
[pOp setAccessoryView: [pAccessoryView autorelease]]; [pOp setAccessoryView: [pAccessoryView autorelease]];
#else // -(void)setAccessoryView:(NSView *)aView of NSPrintOperation is deprecated since 10.5
// get the print panel
NSPrintPanel* pPrintPanel = [pOp printPanel];
[pPrintPanel setOptions: [pPrintPanel options] | NSPrintPanelShowsPreview];
// add the accessory controller to the panel
[pPrintPanel addAccessoryController: [pAccessoryController autorelease]];
#endif
// set the current selecte tab item // set the current selecte tab item
if( pState->nLastPage >= 0 && pState->nLastPage < [pTabView numberOfTabViewItems] ) if( pState->nLastPage >= 0 && pState->nLastPage < [pTabView numberOfTabViewItems] )
...@@ -1374,8 +1570,6 @@ static void addEdit( NSView* pCurParent, long& rCurX, long& rCurY, long nAttachO ...@@ -1374,8 +1570,6 @@ static void addEdit( NSView* pCurParent, long& rCurX, long& rCurY, long nAttachO
return pCtrlTarget; return pCtrlTarget;
} }
// #pragma GCC diagnostic pop
@end @end
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -24,7 +24,9 @@ ...@@ -24,7 +24,9 @@
#include "osx/salprn.h" #include "osx/salprn.h"
@implementation AquaPrintView @implementation AquaPrintView
-(id)initWithController: (vcl::PrinterController*)pController withInfoPrinter: (AquaSalInfoPrinter*)pInfoPrinter
-(id)initWithController: (vcl::PrinterController*)pController
withInfoPrinter: (AquaSalInfoPrinter*)pInfoPrinter
{ {
NSRect aRect = { NSZeroPoint, [pInfoPrinter->getPrintInfo() paperSize] }; NSRect aRect = { NSZeroPoint, [pInfoPrinter->getPrintInfo() paperSize] };
if( (self = [super initWithFrame: aRect]) != nil ) if( (self = [super initWithFrame: aRect]) != nil )
...@@ -49,7 +51,9 @@ ...@@ -49,7 +51,9 @@
// #i101108# sanity check // #i101108# sanity check
if( nWidth < 1 ) if( nWidth < 1 )
nWidth = 1; nWidth = 1;
NSRect aRect = { { static_cast<CGFloat>(page % nWidth), static_cast<CGFloat>(page / nWidth) }, aPaperSize }; NSRect aRect = { { static_cast<CGFloat>(page % nWidth),
static_cast<CGFloat>(page / nWidth) },
aPaperSize };
return aRect; return aRect;
} }
...@@ -61,7 +65,8 @@ ...@@ -61,7 +65,8 @@
-(void)drawRect: (NSRect)rect -(void)drawRect: (NSRect)rect
{ {
mpInfoPrinter->setStartPageOffset( static_cast<int>(rect.origin.x), static_cast<int>(rect.origin.y) ); mpInfoPrinter->setStartPageOffset( static_cast<int>(rect.origin.x),
static_cast<int>(rect.origin.y) );
NSSize aPaperSize = [mpInfoPrinter->getPrintInfo() paperSize]; NSSize aPaperSize = [mpInfoPrinter->getPrintInfo() paperSize];
int nPage = (int)(aPaperSize.width * rect.origin.y + rect.origin.x); int nPage = (int)(aPaperSize.width * rect.origin.y + rect.origin.x);
...@@ -69,6 +74,7 @@ ...@@ -69,6 +74,7 @@
if( nPage - 1 < (mpInfoPrinter->getCurPageRangeStart() + mpInfoPrinter->getCurPageRangeCount() ) ) if( nPage - 1 < (mpInfoPrinter->getCurPageRangeStart() + mpInfoPrinter->getCurPageRangeCount() ) )
mpController->printFilteredPage( nPage-1 ); mpController->printFilteredPage( nPage-1 );
} }
@end @end
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -499,8 +499,9 @@ bool AquaSalInfoPrinter::StartJob( const OUString* i_pFileName, ...@@ -499,8 +499,9 @@ bool AquaSalInfoPrinter::StartJob( const OUString* i_pFileName,
bSuccess = true; bSuccess = true;
mbJob = true; mbJob = true;
pInst->startedPrintJob(); pInst->startedPrintJob();
[pPrintOperation runOperation]; BOOL wasSuccessful = [pPrintOperation runOperation];
pInst->endedPrintJob(); pInst->endedPrintJob();
bSuccess = wasSuccessful ? true : false;
bWasAborted = [[[pPrintOperation printInfo] jobDisposition] compare: NSPrintCancelJob] == NSOrderedSame; bWasAborted = [[[pPrintOperation printInfo] jobDisposition] compare: NSPrintCancelJob] == NSOrderedSame;
mbJob = false; mbJob = false;
if( pReleaseAfterUse ) if( pReleaseAfterUse )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment