wxMaxima
OutCommon.h
Go to the documentation of this file.
1 // -*- mode: c++; c-file-style: "linux"; c-basic-offset: 2; indent-tabs-mode: nil -*-
2 //
3 // Copyright (C) 2004-2015 Andrej Vodopivec <andrej.vodopivec@gmail.com>
4 // Copyright (C) 2015 Gunter Königsmann <wxMaxima@physikbuch.de>
5 // Copyright (C) 2020 Kuba Ober <kuba@bertec.com>
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 //
22 // SPDX-License-Identifier: GPL-2.0+
23 
24 #ifndef OUTCOMMON_H
25 #define OUTCOMMON_H
26 
27 #include "Configuration.h"
28 #include "precomp.h"
29 #include <wx/dataobj.h>
30 #include <memory>
31 
37 class Cell;
38 class wxDC;
39 
42 class OutCommon
43 {
44 public:
46  class DataObject final : public wxCustomDataObject
47  {
48  wxMemoryBuffer m_databuf;
49 
50  public:
51  explicit DataObject(const wxDataFormat &format, const wxMemoryBuffer &data);
52  bool GetDataHere(void *buf) const override;
53  size_t GetDataSize() const override;
54  void Free() override;
55  };
56 
59  std::unique_ptr<DataObject> GetDataObject(const wxDataFormat &format);
60 
70  explicit OutCommon(Configuration **configuration, const wxString &filename,
71  int fullWidth, double scale);
72  explicit OutCommon(Configuration **configuration, int fullWidth, double scale);
73  ~OutCommon();
74 
75  OutCommon(const OutCommon&) = delete;
76  void operator=(const OutCommon&) = delete;
77 
78  int Scale_Px(double px) const { return m_thisconfig.Scale_Px(px); }
79  double GetScale() const { return m_scale; }
80  const wxString &GetFilename() const { return m_filename; }
81  const wxString &GetTempFilename() const { return m_tempFilename; }
83  Configuration &GetConfiguration() { return m_thisconfig; }
85  Configuration &GetScreenConfig() { return *(*m_configuration); }
86  wxSize getPPI() const { return m_ppi; }
87 
89  void SetRecalculationContext(wxDC &context) { m_recalculationDc = &context; }
90 
92  bool PrepareLayout(Cell *tree);
93 
95  wxSize GetSize() const { return m_size; }
97  void SetSize(wxSize size) { m_size = size; }
98 
100  wxSize GetScaledSize() const;
102  wxSize GetInvScaledSize() const;
103 
106  bool ToClipboard(const wxDataFormat &format);
107 
109  void Draw(Cell *tree);
110 
111 private:
112  void GetMaxPoint(Cell *tree, int *width, int *height) const;
113  void Recalculate(Cell *tree) const;
114 
115  void BreakLines(Cell *tree) const;
116  void BreakUpCells(Cell *tree);
117 
119  wxString m_tempFilename;
121  wxDC *m_recalculationDc = {};
122 
123  wxString m_filename;
124  Configuration **m_configuration;
125  Configuration *m_oldconfig = *m_configuration;
126  Configuration m_thisconfig{ {}, Configuration::temporary };
128  double m_scale = 1.0;
130  wxSize m_size = wxDefaultSize;
132  int m_fullWidth;
134  wxSize m_ppi;
135 };
136 
137 #endif // OUTCOMMON_H
OutCommon::Draw
void Draw(Cell *tree)
Recursively draws the cells.
Definition: OutCommon.cpp:192
OutCommon::GetScreenConfig
Configuration & GetScreenConfig()
Get the configuration for the screen output.
Definition: OutCommon.h:85
OutCommon::GetInvScaledSize
wxSize GetInvScaledSize() const
Returns the size of the prepared output layout divided by the scale factor.
Definition: OutCommon.cpp:86
Configuration::Scale_Px
long Scale_Px(double px) const
Definition: Configuration.cpp:1272
OutCommon::ToClipboard
bool ToClipboard(const wxDataFormat &format)
Definition: OutCommon.cpp:250
OutCommon::DataObject
An object that can be filled with output data in given format for the clipboard.
Definition: OutCommon.h:46
Configuration::temporary
@ temporary
This configuration is temporary and shouldn't redetect Maxima etc.
Definition: Configuration.h:116
OutCommon::OutCommon
OutCommon(Configuration **configuration, const wxString &filename, int fullWidth, double scale)
Definition: OutCommon.cpp:38
Cell
Definition: Cell.h:139
OutCommon::GetDataObject
std::unique_ptr< DataObject > GetDataObject(const wxDataFormat &format)
Definition: OutCommon.cpp:263
OutCommon::SetSize
void SetSize(wxSize size)
Sets the "default" size of the prepared layout.
Definition: OutCommon.h:97
OutCommon::SetRecalculationContext
void SetRecalculationContext(wxDC &context)
Sets the context for the configuration used in recalculating the cell dimensions.
Definition: OutCommon.h:89
OutCommon::GetScaledSize
wxSize GetScaledSize() const
Returns the size of the prepared output layout multiplied by the scale factor.
Definition: OutCommon.cpp:79
OutCommon
Definition: OutCommon.h:42
Configuration
Definition: Configuration.h:83
OutCommon::GetSize
wxSize GetSize() const
Returns the size of the prepared output layout.
Definition: OutCommon.h:95
OutCommon::PrepareLayout
bool PrepareLayout(Cell *tree)
Prepares to render the tree to the output DC, and computes the size of the output.
Definition: OutCommon.cpp:93
OutCommon::GetConfiguration
Configuration & GetConfiguration()
Get the configuration for the file/bitmap/... output.
Definition: OutCommon.h:83