Audacity  2.2.2
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 #include "Audacity.h"
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 "TrackArtist.h"
28 #include "ViewInfo.h"
29 #include "WaveTrack.h"
30 #include "widgets/Ruler.h"
31 #include "widgets/ErrorDialog.h"
32 
33 #include "Experimental.h"
34 
36 #include "Internat.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:
48  AudacityPrintout(wxString title,
49  TrackList *tracks):
50  wxPrintout(title),
51  mTracks(tracks)
52  {
53  }
54  bool OnPrintPage(int page);
55  bool HasPage(int page);
56  bool OnBeginDocument(int startPage, int endPage);
57  void GetPageInfo(int *minPage, int *maxPage,
58  int *selPageFrom, int *selPageTo);
59 
60  private:
62 };
63 
64 bool AudacityPrintout::OnPrintPage(int WXUNUSED(page))
65 {
66  wxDC *dc = GetDC();
67  if (!dc)
68  return false;
69 
70  int width, height;
71  dc->GetSize(&width, &height);
72 
73  int rulerScreenHeight = 40;
74  int screenTotalHeight = mTracks->GetHeight() + rulerScreenHeight;
75 
76  double scale = height / (double)screenTotalHeight;
77 
78  int rulerPageHeight = (int)(rulerScreenHeight * scale);
79  Ruler ruler;
80  ruler.SetBounds(0, 0, width, rulerPageHeight);
81  ruler.SetOrientation(wxHORIZONTAL);
82  ruler.SetRange(0.0, mTracks->GetEndTime());
84  ruler.SetLabelEdges(true);
85  ruler.Draw(*dc);
86 
87  TrackArtist artist;
88  artist.SetBackgroundBrushes(*wxWHITE_BRUSH, *wxWHITE_BRUSH,
89  *wxWHITE_PEN, *wxWHITE_PEN);
90  const double screenDuration = mTracks->GetEndTime();
91  ZoomInfo zoomInfo(0.0, width / screenDuration);
92  int y = rulerPageHeight;
93 
95  Track *n = iter.First();
96  while (n) {
97  wxRect r;
98  r.x = 0;
99  r.y = y;
100  r.width = width;
101  r.height = (int)(n->GetHeight() * scale);
102 
103  TrackPanelDrawingContext context{ *dc, {}, {} };
104  artist.DrawTrack(
105  context, n, r, SelectedRegion(), zoomInfo, false, false, false, false);
106 
107  dc->SetPen(*wxBLACK_PEN);
108  AColor::Line(*dc, 0, r.y, width, r.y);
109 
110  n = iter.Next();
111  y += r.height;
112  };
113 
114  return true;
115 }
116 
118 {
119  return (page==1);
120 }
121 
122 bool AudacityPrintout::OnBeginDocument(int startPage, int endPage)
123 {
124  return wxPrintout::OnBeginDocument(startPage, endPage);
125 }
126 
127 void AudacityPrintout::GetPageInfo(int *minPage, int *maxPage,
128  int *selPageFrom, int *selPageTo)
129 {
130  *minPage = 1;
131  *maxPage = 1;
132  *selPageFrom = 1;
133  *selPageTo = 1;
134 }
135 
136 void HandlePageSetup(wxWindow *parent)
137 {
138  wxPageSetupData pageSetupData;
139 
140  wxPageSetupDialog pageSetupDialog(parent, &pageSetupData);
141  pageSetupDialog.ShowModal();
142 
143  gPrintData() = pageSetupDialog.GetPageSetupData().GetPrintData();
144 }
145 
146 void HandlePrint(wxWindow *parent, const wxString &name, TrackList *tracks)
147 {
148  wxPrintDialogData printDialogData(gPrintData());
149 
150  wxPrinter printer(&printDialogData);
151  AudacityPrintout printout(name, tracks);
152  if (!printer.Print(parent, &printout, true)) {
153  if (wxPrinter::GetLastError() == wxPRINTER_ERROR) {
154  AudacityMessageBox(_("There was a problem printing."),
155  _("Print"), wxOK);
156  }
157  else {
158  // Do nothing, the user cancelled...
159  }
160  }
161  else {
162  gPrintData() = printer.GetPrintDialogData().GetPrintData();
163  }
164 }
void SetBackgroundBrushes(wxBrush unselectedBrush, wxBrush selectedBrush, wxPen unselectedPen, wxPen selectedPen)
Definition: TrackArtist.h:80
void Draw(wxDC &dc)
Definition: Ruler.cpp:1323
A list of TrackListNode items.
Definition: Track.h:618
This class handles the actual rendering of WaveTracks (both waveforms and spectra), NoteTracks, LabelTracks and TimeTracks.
Definition: TrackArtist.h:50
int GetHeight() const
Definition: Track.cpp:1372
double GetEndTime() const
Definition: Track.cpp:1418
void SetBounds(int left, int top, int right, int bottom)
Definition: Ruler.cpp:358
TrackList * mTracks
Definition: Printing.cpp:61
int AudacityMessageBox(const wxString &message, const wxString &caption=AudacityMessageBoxCaptionStr(), long style=wxOK|wxCENTRE, wxWindow *parent=NULL, int x=wxDefaultCoord, int y=wxDefaultCoord)
Definition: ErrorDialog.h:92
bool OnBeginDocument(int startPage, int endPage)
Definition: Printing.cpp:122
void GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo)
Definition: Printing.cpp:127
void SetOrientation(int orient)
Definition: Ruler.cpp:222
void DrawTrack(TrackPanelDrawingContext &context, const Track *t, const wxRect &rect, const SelectedRegion &selectedRegion, const ZoomInfo &zoomInfo, bool drawEnvelope, bool bigPoints, bool drawSliders, bool hasSolo)
AudacityPrintout(wxString title, TrackList *tracks)
Definition: Printing.cpp:48
Defines a selected portion of a project.
void SetLabelEdges(bool labelEdges)
Definition: Ruler.cpp:274
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:101
wxPrintData & gPrintData()
Definition: Printing.cpp:39
void HandlePrint(wxWindow *parent, const wxString &name, TrackList *tracks)
Definition: Printing.cpp:146
virtual Track * First(TrackList *val=nullptr)
Definition: Track.cpp:418
bool OnPrintPage(int page)
Definition: Printing.cpp:64
void HandlePageSetup(wxWindow *parent)
Definition: Printing.cpp:136
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: AColor.cpp:122
An iterator for a TrackList.
Definition: Track.h:401
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
void SetFormat(RulerFormat format)
Definition: Ruler.cpp:188
void SetRange(double min, double max)
Definition: Ruler.cpp:236
const wxChar * name
Definition: Distortion.cpp:94
Used to display a Ruler.
Definition: Ruler.h:32
virtual Track * Next(bool skiplinked=false)
Definition: Track.cpp:460
bool HasPage(int page)
Definition: Printing.cpp:117
Derived from wxPrintout, this class helps with printing.
Definition: Printing.cpp:45
int GetHeight() const
Definition: Track.cpp:180