Home | History | Annotate | Download | only in printing
      1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef PRINTING_PRINTING_CONTEXT_WIN_H_
      6 #define PRINTING_PRINTING_CONTEXT_WIN_H_
      7 
      8 #include <string>
      9 
     10 #include "base/memory/scoped_ptr.h"
     11 #include "printing/printing_context.h"
     12 #include "ui/gfx/native_widget_types.h"
     13 
     14 namespace printing {
     15 
     16 class PrintSettings;
     17 
     18 class PRINTING_EXPORT PrintingContextWin : public PrintingContext {
     19  public:
     20   explicit PrintingContextWin(Delegate* delegate);
     21   virtual ~PrintingContextWin();
     22 
     23   // PrintingContext implementation.
     24   virtual void AskUserForSettings(
     25       int max_pages,
     26       bool has_selection,
     27       const PrintSettingsCallback& callback) OVERRIDE;
     28   virtual Result UseDefaultSettings() OVERRIDE;
     29   virtual gfx::Size GetPdfPaperSizeDeviceUnits() OVERRIDE;
     30   virtual Result UpdatePrinterSettings(bool external_preview,
     31                                        bool show_system_dialog) OVERRIDE;
     32   virtual Result InitWithSettings(const PrintSettings& settings) OVERRIDE;
     33   virtual Result NewDocument(const base::string16& document_name) OVERRIDE;
     34   virtual Result NewPage() OVERRIDE;
     35   virtual Result PageDone() OVERRIDE;
     36   virtual Result DocumentDone() OVERRIDE;
     37   virtual void Cancel() OVERRIDE;
     38   virtual void ReleaseContext() OVERRIDE;
     39   virtual gfx::NativeDrawingContext context() const OVERRIDE;
     40 
     41  protected:
     42   static HWND GetRootWindow(gfx::NativeView view);
     43 
     44   // Reads the settings from the selected device context. Updates settings_ and
     45   // its margins.
     46   virtual Result InitializeSettings(const base::string16& device_name,
     47                                     DEVMODE* dev_mode);
     48 
     49   HDC contest() const { return context_; }
     50 
     51   void set_context(HDC context) { context_ = context; }
     52 
     53  private:
     54   virtual scoped_ptr<DEVMODE, base::FreeDeleter> ShowPrintDialog(
     55       HANDLE printer,
     56       gfx::NativeView parent_view,
     57       DEVMODE* dev_mode);
     58 
     59   // Used in response to the user canceling the printing.
     60   static BOOL CALLBACK AbortProc(HDC hdc, int nCode);
     61 
     62   // The selected printer context.
     63   HDC context_;
     64 
     65   DISALLOW_COPY_AND_ASSIGN(PrintingContextWin);
     66 };
     67 
     68 }  // namespace printing
     69 
     70 #endif  // PRINTING_PRINTING_CONTEXT_WIN_H_
     71