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