xref: /aoo41x/main/vcl/aqua/source/gdi/aquaprintview.mm (revision cdf0e10c)
1/************************************************************************
2 *
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
6 *
7 * OpenOffice.org - a multi-platform office productivity suite
8 *
9 * This file is part of OpenOffice.org.
10 *
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
14 *
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org.  If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
25 *
26 ************************************************************************/
27
28// MARKER(update_precomp.py): autogen include statement, do not remove
29#include "precompiled_vcl.hxx"
30
31#include "vcl/print.hxx"
32
33#include "aqua/aquaprintview.h"
34#include "aqua/salprn.h"
35
36@implementation AquaPrintView
37-(id)initWithController: (vcl::PrinterController*)pController withInfoPrinter: (AquaSalInfoPrinter*)pInfoPrinter
38{
39    NSRect aRect = { { 0, 0 }, [pInfoPrinter->getPrintInfo() paperSize] };
40    if( (self = [super initWithFrame: aRect]) != nil )
41    {
42        mpController = pController;
43        mpInfoPrinter = pInfoPrinter;
44    }
45    return self;
46}
47
48-(BOOL)knowsPageRange: (NSRangePointer)range
49{
50    range->location = 1;
51    range->length = mpInfoPrinter->getCurPageRangeCount();
52    return YES;
53}
54
55-(NSRect)rectForPage: (int)page
56{
57    NSSize aPaperSize =  [mpInfoPrinter->getPrintInfo() paperSize];
58    int nWidth = (int)aPaperSize.width;
59    // #i101108# sanity check
60    if( nWidth < 1 )
61        nWidth = 1;
62    NSRect aRect = { { page % nWidth, page / nWidth }, aPaperSize };
63    return aRect;
64}
65
66-(NSPoint)locationOfPrintRect: (NSRect)aRect
67{
68    (void)aRect;
69    NSPoint aPoint = { 0, 0 };
70    return aPoint;
71}
72
73-(void)drawRect: (NSRect)rect
74{
75    NSPoint aPoint = [self locationOfPrintRect: rect];
76    mpInfoPrinter->setStartPageOffset( static_cast<int>(rect.origin.x), static_cast<int>(rect.origin.y) );
77    NSSize aPaperSize =  [mpInfoPrinter->getPrintInfo() paperSize];
78    int nPage = (int)(aPaperSize.width * rect.origin.y + rect.origin.x);
79
80    // page count is 1 based
81    if( nPage - 1 < (mpInfoPrinter->getCurPageRangeStart() + mpInfoPrinter->getCurPageRangeCount() ) )
82        mpController->printFilteredPage( nPage-1 );
83}
84@end
85