xref: /aoo41x/main/vcl/aqua/source/gdi/aquaprintview.mm (revision 323de322)
1*323de322SAndrew Rist/**************************************************************
2cdf0e10cSrcweir *
3*323de322SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*323de322SAndrew Rist * or more contributor license agreements.  See the NOTICE file
5*323de322SAndrew Rist * distributed with this work for additional information
6*323de322SAndrew Rist * regarding copyright ownership.  The ASF licenses this file
7*323de322SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*323de322SAndrew Rist * "License"); you may not use this file except in compliance
9*323de322SAndrew Rist * with the License.  You may obtain a copy of the License at
10*323de322SAndrew Rist *
11*323de322SAndrew Rist *   http://www.apache.org/licenses/LICENSE-2.0
12*323de322SAndrew Rist *
13*323de322SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*323de322SAndrew Rist * software distributed under the License is distributed on an
15*323de322SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*323de322SAndrew Rist * KIND, either express or implied.  See the License for the
17*323de322SAndrew Rist * specific language governing permissions and limitations
18*323de322SAndrew Rist * under the License.
19*323de322SAndrew Rist *
20*323de322SAndrew Rist *************************************************************/
21*323de322SAndrew Rist
22*323de322SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir// MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir#include "precompiled_vcl.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir#include "vcl/print.hxx"
28cdf0e10cSrcweir
29cdf0e10cSrcweir#include "aqua/aquaprintview.h"
30cdf0e10cSrcweir#include "aqua/salprn.h"
31cdf0e10cSrcweir
32cdf0e10cSrcweir@implementation AquaPrintView
33cdf0e10cSrcweir-(id)initWithController: (vcl::PrinterController*)pController withInfoPrinter: (AquaSalInfoPrinter*)pInfoPrinter
34cdf0e10cSrcweir{
35cdf0e10cSrcweir    NSRect aRect = { { 0, 0 }, [pInfoPrinter->getPrintInfo() paperSize] };
36cdf0e10cSrcweir    if( (self = [super initWithFrame: aRect]) != nil )
37cdf0e10cSrcweir    {
38cdf0e10cSrcweir        mpController = pController;
39cdf0e10cSrcweir        mpInfoPrinter = pInfoPrinter;
40cdf0e10cSrcweir    }
41cdf0e10cSrcweir    return self;
42cdf0e10cSrcweir}
43cdf0e10cSrcweir
44cdf0e10cSrcweir-(BOOL)knowsPageRange: (NSRangePointer)range
45cdf0e10cSrcweir{
46cdf0e10cSrcweir    range->location = 1;
47cdf0e10cSrcweir    range->length = mpInfoPrinter->getCurPageRangeCount();
48cdf0e10cSrcweir    return YES;
49cdf0e10cSrcweir}
50cdf0e10cSrcweir
51cdf0e10cSrcweir-(NSRect)rectForPage: (int)page
52cdf0e10cSrcweir{
53cdf0e10cSrcweir    NSSize aPaperSize =  [mpInfoPrinter->getPrintInfo() paperSize];
54cdf0e10cSrcweir    int nWidth = (int)aPaperSize.width;
55cdf0e10cSrcweir    // #i101108# sanity check
56cdf0e10cSrcweir    if( nWidth < 1 )
57cdf0e10cSrcweir        nWidth = 1;
58cdf0e10cSrcweir    NSRect aRect = { { page % nWidth, page / nWidth }, aPaperSize };
59cdf0e10cSrcweir    return aRect;
60cdf0e10cSrcweir}
61cdf0e10cSrcweir
62cdf0e10cSrcweir-(NSPoint)locationOfPrintRect: (NSRect)aRect
63cdf0e10cSrcweir{
64cdf0e10cSrcweir    (void)aRect;
65cdf0e10cSrcweir    NSPoint aPoint = { 0, 0 };
66cdf0e10cSrcweir    return aPoint;
67cdf0e10cSrcweir}
68cdf0e10cSrcweir
69cdf0e10cSrcweir-(void)drawRect: (NSRect)rect
70cdf0e10cSrcweir{
71cdf0e10cSrcweir    NSPoint aPoint = [self locationOfPrintRect: rect];
72cdf0e10cSrcweir    mpInfoPrinter->setStartPageOffset( static_cast<int>(rect.origin.x), static_cast<int>(rect.origin.y) );
73cdf0e10cSrcweir    NSSize aPaperSize =  [mpInfoPrinter->getPrintInfo() paperSize];
74cdf0e10cSrcweir    int nPage = (int)(aPaperSize.width * rect.origin.y + rect.origin.x);
75cdf0e10cSrcweir
76cdf0e10cSrcweir    // page count is 1 based
77cdf0e10cSrcweir    if( nPage - 1 < (mpInfoPrinter->getCurPageRangeStart() + mpInfoPrinter->getCurPageRangeCount() ) )
78cdf0e10cSrcweir        mpController->printFilteredPage( nPage-1 );
79cdf0e10cSrcweir}
80cdf0e10cSrcweir@end
81