1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
10 #ifndef INCLUDED_TILEBUFFER_HXX
11 #define INCLUDED_TILEBUFFER_HXX
19 #define LOK_TILEBUFFER_ERROR (LOKTileBufferErrorQuark())
21 // Lets use a square of side 256 pixels for each tile.
22 const int nTileSizePixels
= 256;
25 Converts the pixel value to zoom independent twip value.
27 @param fInput value to convert
28 @param zoom the current zoom level
30 @return the pixels value corresponding to given twip value
32 float pixelToTwip(float fInput
, float zoom
);
35 Converts the zoom independent twip value pixel value.
37 @param fInput value to convert
38 @param zoom the current zoom level
40 @return the twip value corresponding to given pixel value
42 float twipToPixel(float fInput
, float zoom
);
45 Gets GQuark identifying this tile buffer errors
47 GQuark
LOKTileBufferErrorQuark(void);
50 This class represents a single tile in the tile buffer.
51 It encloses a reference to GdkPixBuf containing the pixel data of the tile.
64 cairo_surface_destroy(m_pBuffer
);
68 Tells if this tile is valid or not. Initialised to 0 (invalid) during
73 /// Function to get the pointer to enclosing cairo_surface_t
74 cairo_surface_t
* getBuffer();
75 /// Used to set the pixel buffer of this object
76 void setSurface(cairo_surface_t
*);
79 /// Pixel buffer data for this tile
80 cairo_surface_t
* m_pBuffer
;
84 This class represents the tile buffer which is responsible for managing,
85 reusing and caching all the already rendered tiles. If the given tile is not
86 present in the buffer, call to LOK Document's (m_pLOKDocument) paintTile
87 method is made which fetches the rendered tile from LO core and store it in
88 buffer for future reuse.
93 TileBuffer(int columns
= 0, int scale
= 1)
96 cairo_surface_t
* pSurface
= cairo_image_surface_create(
97 CAIRO_FORMAT_ARGB32
, nTileSizePixels
* scale
, nTileSizePixels
* scale
);
98 m_DummyTile
.setSurface(pSurface
);
99 cairo_surface_destroy(pSurface
);
103 Gets the underlying Tile object for given position. The position (0, 0)
104 points to the left top most tile of the buffer.
106 If the tile is not cached by the tile buffer, it makes a paintTile call
107 to LO core asking to render the given tile. It then stores the tile for
110 @param x the tile along the x-axis of the buffer
111 @param y the tile along the y-axis of the buffer
112 @param task GTask object containing the necessary data
113 @param pool GThreadPool managed by the widget instance used for all the
114 LOK calls made by widget. It is needed here because getTile invokes one
115 of the LOK call : paintTile.
117 @return the tile at the mentioned position (x, y)
119 Tile
& getTile(int x
, int y
, GTask
* task
, GThreadPool
* pool
);
122 Takes ownership of the surface and sets it on a tile at a given location
124 void setTile(int x
, int y
, cairo_surface_t
* surface
);
126 /// Returns true if a valid tile exists at this location
127 bool hasValidTile(int x
, int y
);
129 /// Destroys all the tiles in the tile buffer; also frees the memory allocated
130 /// for all the Tile objects.
131 void resetAllTiles();
133 Marks the tile as invalid. The tile (0, 0) is the left topmost tile in
136 @param x the position of tile along x-axis
137 @param y the position of tile along y-axis
138 @param zoom zoom factor of the document
139 @param task GTask object containing the necessary data
140 @param pool GThreadPool managed by the widget instance used for all the
141 LOK calls made by widget. It is needed here because setInvalid() invokes one
142 of the LOK call : paintTile.
144 void setInvalid(int x
, int y
, float zoom
, GTask
* task
, GThreadPool
*);
147 /// Stores all the tiles cached by this tile buffer.
148 std::map
<int, Tile
> m_mTiles
;
149 /// Width of the current tile buffer (number of columns)
164 LOK_POST_MOUSE_EVENT
,
165 LOK_SET_GRAPHIC_SELECTION
,
171 LOK_TILEBUFFER_CHANGED
,
172 LOK_TILEBUFFER_MEMORY
176 A struct that we use to store the data about the LOK call.
178 Object of this type is passed with all the LOK calls,
179 so that they can be identified. Additionally, it also contains
180 the data that LOK call needs.
184 /// To identify the type of LOK call
187 /// @name post_command parameters
189 const gchar
* m_pCommand
;
191 gboolean m_bNotifyWhenFinished
;
194 /// set_edit parameter
197 /// set_partmode parameter
200 /// set_part parameter
203 /// @name postKeyEvent parameters
210 /// @name paintTile parameters
214 float m_fPaintTileZoom
;
215 TileBuffer
* m_pTileBuffer
;
218 /// @name postMouseEvent parameters
220 int m_nPostMouseEventType
;
221 int m_nPostMouseEventX
;
222 int m_nPostMouseEventY
;
223 int m_nPostMouseEventCount
;
224 int m_nPostMouseEventButton
;
225 int m_nPostMouseEventModifier
;
228 /// @name setGraphicSelection parameters
230 int m_nSetGraphicSelectionType
;
231 int m_nSetGraphicSelectionX
;
232 int m_nSetGraphicSelectionY
;
235 /// @name setClientView parameters
237 int m_nTilePixelWidth
;
238 int m_nTilePixelHeight
;
239 int m_nTileTwipWidth
;
240 int m_nTileTwipHeight
;
243 /// Constructor to instantiate an object of type `type`.
244 explicit LOEvent(int type
)
246 , m_pCommand(nullptr)
247 , m_pArguments(nullptr)
248 , m_bNotifyWhenFinished(false)
257 , m_fPaintTileZoom(0)
258 , m_pTileBuffer(nullptr)
259 , m_nPostMouseEventType(0)
260 , m_nPostMouseEventX(0)
261 , m_nPostMouseEventY(0)
262 , m_nPostMouseEventCount(0)
263 , m_nPostMouseEventButton(0)
264 , m_nPostMouseEventModifier(0)
265 , m_nSetGraphicSelectionType(0)
266 , m_nSetGraphicSelectionX(0)
267 , m_nSetGraphicSelectionY(0)
268 , m_nTilePixelWidth(0)
269 , m_nTilePixelHeight(0)
270 , m_nTileTwipWidth(0)
271 , m_nTileTwipHeight(0)
275 /// Wrapper around delete to help GLib.
276 static void destroy(void* pMemory
);
279 #endif // INCLUDED_TILEBUFFER_HXX
281 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */