1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 *   Licensed to the Apache Software Foundation (ASF) under one or more
12 *   contributor license agreements. See the NOTICE file distributed
13 *   with this work for additional information regarding copyright
14 *   ownership. The ASF licenses this file to you under the Apache
15 *   License, Version 2.0 (the "License"); you may not use this file
16 *   except in compliance with the License. You may obtain a copy of
17 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20
21#include <vcl/print.hxx>
22
23#include <osx/printview.h>
24#include <osx/salprn.h>
25
26@implementation AquaPrintView
27
28-(id)initWithController: (vcl::PrinterController*)pController
29        withInfoPrinter: (AquaSalInfoPrinter*)pInfoPrinter
30{
31    NSRect aRect = { NSZeroPoint, [pInfoPrinter->getPrintInfo() paperSize] };
32    if( (self = [super initWithFrame: aRect]) != nil )
33    {
34        mpController = pController;
35        mpInfoPrinter = pInfoPrinter;
36    }
37    return self;
38}
39
40-(BOOL)knowsPageRange: (NSRangePointer)range
41{
42    range->location = 1;
43    range->length = mpInfoPrinter->getCurPageRangeCount();
44    return YES;
45}
46
47-(NSRect)rectForPage: (int)page
48{
49    NSSize aPaperSize =  [mpInfoPrinter->getPrintInfo() paperSize];
50    int nWidth = static_cast<int>(aPaperSize.width);
51    // #i101108# sanity check
52    if( nWidth < 1 )
53        nWidth = 1;
54    NSRect aRect = { { static_cast<CGFloat>(page % nWidth),
55                       static_cast<CGFloat>(page / nWidth) },
56                     aPaperSize };
57    return aRect;
58}
59
60-(NSPoint)locationOfPrintRect: (NSRect)aRect
61{
62    (void)aRect;
63    return NSZeroPoint;
64}
65
66-(void)drawRect: (NSRect)rect
67{
68    mpInfoPrinter->setStartPageOffset( static_cast<int>(rect.origin.x),
69                                       static_cast<int>(rect.origin.y) );
70    NSSize aPaperSize =  [mpInfoPrinter->getPrintInfo() paperSize];
71    int nPage = static_cast<int>(aPaperSize.width * rect.origin.y + rect.origin.x);
72
73    // page count is 1 based
74    if( nPage - 1 < (mpInfoPrinter->getCurPageRangeStart() + mpInfoPrinter->getCurPageRangeCount() ) )
75        mpController->printFilteredPage( nPage-1 );
76}
77
78@end
79
80/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
81