Audacity  3.0.3
Printing.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  Printing.cpp
6 
7  Dominic Mazzoni
8 
9 *******************************************************************//*******************************************************************/
15 
16 
17 
18 #include "Printing.h"
19 
20 #include <wx/defs.h>
21 #include <wx/dc.h>
22 #include <wx/intl.h>
23 #include <wx/print.h>
24 #include <wx/printdlg.h>
25 
26 #include "AColor.h"
27 #include "ProjectWindows.h"
28 #include "TrackArtist.h"
29 #include "ViewInfo.h"
30 #include "Track.h"
31 #include "widgets/Ruler.h"
33 
35 
36 #include "tracks/ui/TrackView.h"
37 
38 // Globals, so that we remember settings from session to session
39 wxPrintData &gPrintData()
40 {
41  static wxPrintData theData;
42  return theData;
43 }
44 
45 class AudacityPrintout final : public wxPrintout
46 {
47  public:
49  TrackList *tracks, TrackPanel &panel):
50  wxPrintout(title),
51  mTracks(tracks)
52  , mPanel(panel)
53  {
54  }
55  bool OnPrintPage(int page);
56  bool HasPage(int page);
57  bool OnBeginDocument(int startPage, int endPage);
58  void GetPageInfo(int *minPage, int *maxPage,
59  int *selPageFrom, int *selPageTo);
60 
61  private:
64 };
65 
66 bool AudacityPrintout::OnPrintPage(int WXUNUSED(page))
67 {
68  wxDC *dc = GetDC();
69  if (!dc)
70  return false;
71 
72  int width, height;
73  dc->GetSize(&width, &height);
74 
75  int rulerScreenHeight = 40;
76  int screenTotalHeight =
77  TrackView::GetTotalHeight( *mTracks ) + rulerScreenHeight;
78 
79  double scale = height / (double)screenTotalHeight;
80 
81  int rulerPageHeight = (int)(rulerScreenHeight * scale);
82  Ruler ruler;
83  ruler.SetBounds(0, 0, width, rulerPageHeight);
84  ruler.SetOrientation(wxHORIZONTAL);
87  ruler.SetLabelEdges(true);
88  ruler.Draw(*dc);
89 
90  TrackArtist artist( &mPanel );
91  artist.SetBackgroundBrushes(*wxWHITE_BRUSH, *wxWHITE_BRUSH,
92  *wxWHITE_PEN, *wxWHITE_PEN);
93  const double screenDuration = mTracks->GetEndTime();
94  SelectedRegion region{};
95  artist.pSelectedRegion = &region;
96  ZoomInfo zoomInfo(0.0, width / screenDuration);
97  artist.pZoomInfo = &zoomInfo;
98  int y = rulerPageHeight;
99 
100  for (auto n : mTracks->Any()) {
101  auto &view = TrackView::Get( *n );
102  wxRect r;
103  r.x = 0;
104  r.y = 0;
105  r.width = width;
106  // Note that the views as printed might not have the same proportional
107  // heights as displayed on the screen, because the fixed-sized separators
108  // are counted in those heights but not printed
109  auto trackHeight = (int)(view.GetHeight() * scale);
110  r.height = trackHeight;
111 
112  const auto subViews = view.GetSubViews( r );
113  if (subViews.empty())
114  continue;
115 
116  auto iter = subViews.begin(), end = subViews.end(), next = iter;
117  auto yy = iter->first;
118  for ( ; iter != end; iter = next ) {
119  ++next;
120  auto nextY = ( next == end )
121  ? trackHeight
122  : next->first;
123  r.y = y + yy;
124  r.SetHeight( nextY - yy );
125  yy = nextY;
126 
127  TrackPanelDrawingContext context{
128  *dc, {}, {}, &artist
129  };
130  iter->second->Draw( context, r, TrackArtist::PassTracks );
131  }
132 
133  dc->SetPen(*wxBLACK_PEN);
134  AColor::Line(*dc, 0, y, width, y);
135 
136  y += trackHeight;
137  };
138 
139  return true;
140 }
141 
143 {
144  return (page==1);
145 }
146 
147 bool AudacityPrintout::OnBeginDocument(int startPage, int endPage)
148 {
149  return wxPrintout::OnBeginDocument(startPage, endPage);
150 }
151 
152 void AudacityPrintout::GetPageInfo(int *minPage, int *maxPage,
153  int *selPageFrom, int *selPageTo)
154 {
155  *minPage = 1;
156  *maxPage = 1;
157  *selPageFrom = 1;
158  *selPageTo = 1;
159 }
160 
161 void HandlePageSetup(wxWindow *parent)
162 {
163  wxPageSetupData pageSetupData;
164 
165  wxPageSetupDialog pageSetupDialog(parent, &pageSetupData);
166  pageSetupDialog.ShowModal();
167 
168  gPrintData() = pageSetupDialog.GetPageSetupData().GetPrintData();
169 }
170 
172  wxWindow *parent, const wxString &name, TrackList *tracks,
173  TrackPanel &panel)
174 {
175  wxPrintDialogData printDialogData(gPrintData());
176 
177  wxPrinter printer(&printDialogData);
178  AudacityPrintout printout(name, tracks, panel);
179  if (!printer.Print(parent, &printout, true)) {
180  if (wxPrinter::GetLastError() == wxPRINTER_ERROR) {
182  XO("There was a problem printing."),
183  XO("Print"),
184  wxOK);
185  }
186  else {
187  // Do nothing, the user cancelled...
188  }
189  }
190  else {
191  gPrintData() = printer.GetPrintDialogData().GetPrintData();
192  }
193 }
Ruler::SetLabelEdges
void SetLabelEdges(bool labelEdges)
Definition: Ruler.cpp:226
AudacityMessageBox
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
Definition: AudacityMessageBox.cpp:17
TrackView::Get
static TrackView & Get(Track &)
Definition: TrackView.cpp:63
TrackArtist.h
TrackView.h
AudacityPrintout::OnPrintPage
bool OnPrintPage(int page)
Definition: Printing.cpp:66
ZoomInfo
Definition: ZoomInfo.h:47
TrackPanelDrawingContext
Definition: TrackPanelDrawingContext.h:22
TrackList
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:1280
AColor::Line
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: AColor.cpp:109
AudacityPrintout::GetPageInfo
void GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo)
Definition: Printing.cpp:152
XO
#define XO(s)
Definition: Internat.h:31
Ruler::SetFormat
void SetFormat(RulerFormat format)
Definition: Ruler.cpp:131
Ruler::Draw
void Draw(wxDC &dc) const
Definition: Ruler.cpp:1428
TrackArtist::pZoomInfo
ZoomInfo * pZoomInfo
Definition: TrackArtist.h:153
anonymous_namespace{TimeTrackVRulerControls.cpp}::ruler
Ruler & ruler()
Definition: TimeTrackVRulerControls.cpp:34
TrackArtist
This class handles the actual rendering of WaveTracks (both waveforms and spectra),...
Definition: TrackArtist.h:76
TrackPanel
The TrackPanel class coordinates updates and operations on the main part of the screen which contains...
Definition: TrackPanel.h:66
AudacityPrintout::AudacityPrintout
AudacityPrintout(wxString title, TrackList *tracks, TrackPanel &panel)
Definition: Printing.cpp:48
AudacityPrintout
Derived from wxPrintout, this class helps with printing.
Definition: Printing.cpp:46
Ruler::TimeFormat
@ TimeFormat
Definition: Ruler.h:33
TrackList::GetEndTime
double GetEndTime() const
Definition: Track.cpp:1038
Printing.h
gPrintData
wxPrintData & gPrintData()
Definition: Printing.cpp:39
AudacityPrintout::mTracks
TrackList * mTracks
Definition: Printing.cpp:63
Ruler
Used to display a Ruler.
Definition: Ruler.h:26
name
const TranslatableString name
Definition: Distortion.cpp:98
TrackView::GetTotalHeight
static int GetTotalHeight(const TrackList &list)
Definition: TrackView.cpp:47
HandlePageSetup
void HandlePageSetup(wxWindow *parent)
Definition: Printing.cpp:161
Ruler::SetRange
void SetRange(double min, double max)
Definition: Ruler.cpp:188
Ruler::SetOrientation
void SetOrientation(int orient)
Definition: Ruler.cpp:174
HandlePrint
void HandlePrint(wxWindow *parent, const wxString &name, TrackList *tracks, TrackPanel &panel)
Definition: Printing.cpp:171
ViewInfo.h
Ruler.h
ProjectWindows.h
accessors for certain important windows associated with each project
AudacityPrintout::mPanel
TrackPanel & mPanel
Definition: Printing.cpp:62
TrackArtist::pSelectedRegion
const SelectedRegion * pSelectedRegion
Definition: TrackArtist.h:152
TrackPanelDrawingContext.h
title
static const auto title
Definition: NoUpdatesAvailableDialog.cpp:22
AudacityMessageBox.h
Ruler::SetBounds
void SetBounds(int left, int top, int right, int bottom)
Definition: Ruler.cpp:332
TrackArtist::SetBackgroundBrushes
void SetBackgroundBrushes(wxBrush unselectedBrushIn, wxBrush selectedBrushIn, wxPen unselectedPenIn, wxPen selectedPenIn)
Definition: TrackArtist.h:97
Track.h
declares abstract base class Track, TrackList, and iterators over TrackList
TrackArtist::PassTracks
@ PassTracks
Definition: TrackArtist.h:81
AudacityPrintout::OnBeginDocument
bool OnBeginDocument(int startPage, int endPage)
Definition: Printing.cpp:147
TrackList::Any
auto Any() -> TrackIterRange< TrackType >
Definition: Track.h:1371
AColor.h
AudacityPrintout::HasPage
bool HasPage(int page)
Definition: Printing.cpp:142
SelectedRegion
Defines a selected portion of a project.
Definition: SelectedRegion.h:35