calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / vcl / qt5 / QtData.cxx
blobcc2883ae80ca484b5c23f96ce5cfc5c7a744966d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <QtData.hxx>
22 #include <QtGui/QBitmap>
23 #include <QtGui/QCursor>
24 #include <QtWidgets/QApplication>
25 #include <QtWidgets/QStyle>
27 #include <i18nlangtag/languagetag.hxx>
28 #include <sal/log.hxx>
29 #include <tools/stream.hxx>
30 #include <vcl/ImageTree.hxx>
32 #include <bitmaps.hlst>
33 #include <cursor_hotspots.hxx>
34 #include <unx/glyphcache.hxx>
36 QtData::QtData()
37 : GenericUnixSalData()
39 ImplSVData* pSVData = ImplGetSVData();
41 pSVData->maNWFData.mbDockingAreaSeparateTB = true;
42 pSVData->maNWFData.mbFlatMenu = true;
43 pSVData->maNWFData.mbRolloverMenubar = true;
44 pSVData->maNWFData.mbNoFocusRects = true;
45 pSVData->maNWFData.mbNoFocusRectsForFlatButtons = true;
47 QStyle* style = QApplication::style();
48 pSVData->maNWFData.mnMenuFormatBorderX = style->pixelMetric(QStyle::PM_MenuPanelWidth)
49 + style->pixelMetric(QStyle::PM_MenuHMargin);
50 pSVData->maNWFData.mnMenuFormatBorderY = style->pixelMetric(QStyle::PM_MenuPanelWidth)
51 + style->pixelMetric(QStyle::PM_MenuVMargin);
54 // outline dtor b/c of FreetypeManager incomplete type
55 QtData::~QtData() {}
57 static QCursor* getQCursorFromIconTheme(const OUString& rIconName, int nXHot, int nYHot)
59 const OUString sIconTheme = Application::GetSettings().GetStyleSettings().DetermineIconTheme();
60 const OUString sUILang = Application::GetSettings().GetUILanguageTag().getBcp47();
61 auto xMemStream = ImageTree::get().getImageStream(rIconName, sIconTheme, sUILang);
62 if (!xMemStream)
63 return nullptr;
64 auto nLength = xMemStream->TellEnd();
65 if (!nLength)
67 SAL_WARN("vcl.qt", "Cannot load cursor pixmap from empty stream.");
68 return nullptr;
71 const unsigned char* pData = static_cast<const unsigned char*>(xMemStream->GetData());
72 QPixmap aPixmap;
73 aPixmap.loadFromData(pData, nLength);
74 return new QCursor(aPixmap, nXHot, nYHot);
77 #define MAKE_CURSOR(vcl_name, name, icon_name) \
78 case vcl_name: \
79 pCursor = getQCursorFromIconTheme(icon_name, name##curs_x_hot, name##curs_y_hot); \
80 break
82 #define MAP_BUILTIN(vcl_name, qt_enum) \
83 case vcl_name: \
84 pCursor = new QCursor(qt_enum); \
85 break
87 QCursor& QtData::getCursor(PointerStyle ePointerStyle)
89 if (!m_aCursors[ePointerStyle])
91 QCursor* pCursor = nullptr;
93 switch (ePointerStyle)
95 MAP_BUILTIN(PointerStyle::Arrow, Qt::ArrowCursor);
96 MAP_BUILTIN(PointerStyle::Text, Qt::IBeamCursor);
97 MAP_BUILTIN(PointerStyle::Help, Qt::WhatsThisCursor);
98 MAP_BUILTIN(PointerStyle::Cross, Qt::CrossCursor);
99 MAP_BUILTIN(PointerStyle::Wait, Qt::WaitCursor);
100 MAP_BUILTIN(PointerStyle::NSize, Qt::SizeVerCursor);
101 MAP_BUILTIN(PointerStyle::SSize, Qt::SizeVerCursor);
102 MAP_BUILTIN(PointerStyle::WSize, Qt::SizeHorCursor);
103 MAP_BUILTIN(PointerStyle::ESize, Qt::SizeHorCursor);
105 MAP_BUILTIN(PointerStyle::NWSize, Qt::SizeFDiagCursor);
106 MAP_BUILTIN(PointerStyle::NESize, Qt::SizeBDiagCursor);
107 MAP_BUILTIN(PointerStyle::SWSize, Qt::SizeBDiagCursor);
108 MAP_BUILTIN(PointerStyle::SESize, Qt::SizeFDiagCursor);
109 MAP_BUILTIN(PointerStyle::WindowNSize, Qt::SizeVerCursor);
110 MAP_BUILTIN(PointerStyle::WindowSSize, Qt::SizeVerCursor);
111 MAP_BUILTIN(PointerStyle::WindowWSize, Qt::SizeHorCursor);
112 MAP_BUILTIN(PointerStyle::WindowESize, Qt::SizeHorCursor);
113 MAP_BUILTIN(PointerStyle::WindowNWSize, Qt::SizeFDiagCursor);
114 MAP_BUILTIN(PointerStyle::WindowNESize, Qt::SizeBDiagCursor);
115 MAP_BUILTIN(PointerStyle::WindowSWSize, Qt::SizeBDiagCursor);
116 MAP_BUILTIN(PointerStyle::WindowSESize, Qt::SizeFDiagCursor);
118 MAP_BUILTIN(PointerStyle::HSizeBar, Qt::SizeHorCursor);
119 MAP_BUILTIN(PointerStyle::VSizeBar, Qt::SizeVerCursor);
121 MAP_BUILTIN(PointerStyle::RefHand, Qt::PointingHandCursor);
122 MAP_BUILTIN(PointerStyle::Hand, Qt::OpenHandCursor);
123 #if 0
124 MAP_BUILTIN( PointerStyle::Pen, GDK_PENCIL );
125 #endif
126 MAP_BUILTIN(PointerStyle::HSplit, Qt::SizeHorCursor);
127 MAP_BUILTIN(PointerStyle::VSplit, Qt::SizeVerCursor);
129 MAP_BUILTIN(PointerStyle::Move, Qt::SizeAllCursor);
131 MAP_BUILTIN(PointerStyle::Null, Qt::BlankCursor);
132 MAKE_CURSOR(PointerStyle::Magnify, magnify_, RID_CURSOR_MAGNIFY);
133 MAKE_CURSOR(PointerStyle::Fill, fill_, RID_CURSOR_FILL);
134 MAKE_CURSOR(PointerStyle::MoveData, movedata_, RID_CURSOR_MOVE_DATA);
135 MAKE_CURSOR(PointerStyle::CopyData, copydata_, RID_CURSOR_COPY_DATA);
136 MAKE_CURSOR(PointerStyle::MoveFile, movefile_, RID_CURSOR_MOVE_FILE);
137 MAKE_CURSOR(PointerStyle::CopyFile, copyfile_, RID_CURSOR_COPY_FILE);
138 MAKE_CURSOR(PointerStyle::MoveFiles, movefiles_, RID_CURSOR_MOVE_FILES);
139 MAKE_CURSOR(PointerStyle::CopyFiles, copyfiles_, RID_CURSOR_COPY_FILES);
140 MAKE_CURSOR(PointerStyle::NotAllowed, nodrop_, RID_CURSOR_NOT_ALLOWED);
141 MAKE_CURSOR(PointerStyle::Rotate, rotate_, RID_CURSOR_ROTATE);
142 MAKE_CURSOR(PointerStyle::HShear, hshear_, RID_CURSOR_H_SHEAR);
143 MAKE_CURSOR(PointerStyle::VShear, vshear_, RID_CURSOR_V_SHEAR);
144 MAKE_CURSOR(PointerStyle::DrawLine, drawline_, RID_CURSOR_DRAW_LINE);
145 MAKE_CURSOR(PointerStyle::DrawRect, drawrect_, RID_CURSOR_DRAW_RECT);
146 MAKE_CURSOR(PointerStyle::DrawPolygon, drawpolygon_, RID_CURSOR_DRAW_POLYGON);
147 MAKE_CURSOR(PointerStyle::DrawBezier, drawbezier_, RID_CURSOR_DRAW_BEZIER);
148 MAKE_CURSOR(PointerStyle::DrawArc, drawarc_, RID_CURSOR_DRAW_ARC);
149 MAKE_CURSOR(PointerStyle::DrawPie, drawpie_, RID_CURSOR_DRAW_PIE);
150 MAKE_CURSOR(PointerStyle::DrawCircleCut, drawcirclecut_, RID_CURSOR_DRAW_CIRCLE_CUT);
151 MAKE_CURSOR(PointerStyle::DrawEllipse, drawellipse_, RID_CURSOR_DRAW_ELLIPSE);
152 MAKE_CURSOR(PointerStyle::DrawConnect, drawconnect_, RID_CURSOR_DRAW_CONNECT);
153 MAKE_CURSOR(PointerStyle::DrawText, drawtext_, RID_CURSOR_DRAW_TEXT);
154 MAKE_CURSOR(PointerStyle::Mirror, mirror_, RID_CURSOR_MIRROR);
155 MAKE_CURSOR(PointerStyle::Crook, crook_, RID_CURSOR_CROOK);
156 MAKE_CURSOR(PointerStyle::Crop, crop_, RID_CURSOR_CROP);
157 MAKE_CURSOR(PointerStyle::MovePoint, movepoint_, RID_CURSOR_MOVE_POINT);
158 MAKE_CURSOR(PointerStyle::MoveBezierWeight, movebezierweight_,
159 RID_CURSOR_MOVE_BEZIER_WEIGHT);
160 MAKE_CURSOR(PointerStyle::DrawFreehand, drawfreehand_, RID_CURSOR_DRAW_FREEHAND);
161 MAKE_CURSOR(PointerStyle::DrawCaption, drawcaption_, RID_CURSOR_DRAW_CAPTION);
162 MAKE_CURSOR(PointerStyle::LinkData, linkdata_, RID_CURSOR_LINK_DATA);
163 MAKE_CURSOR(PointerStyle::MoveDataLink, movedlnk_, RID_CURSOR_MOVE_DATA_LINK);
164 MAKE_CURSOR(PointerStyle::CopyDataLink, copydlnk_, RID_CURSOR_COPY_DATA_LINK);
165 MAKE_CURSOR(PointerStyle::LinkFile, linkfile_, RID_CURSOR_LINK_FILE);
166 MAKE_CURSOR(PointerStyle::MoveFileLink, moveflnk_, RID_CURSOR_MOVE_FILE_LINK);
167 MAKE_CURSOR(PointerStyle::CopyFileLink, copyflnk_, RID_CURSOR_COPY_FILE_LINK);
168 MAKE_CURSOR(PointerStyle::Chart, chart_, RID_CURSOR_CHART);
169 MAKE_CURSOR(PointerStyle::Detective, detective_, RID_CURSOR_DETECTIVE);
170 MAKE_CURSOR(PointerStyle::PivotCol, pivotcol_, RID_CURSOR_PIVOT_COLUMN);
171 MAKE_CURSOR(PointerStyle::PivotRow, pivotrow_, RID_CURSOR_PIVOT_ROW);
172 MAKE_CURSOR(PointerStyle::PivotField, pivotfld_, RID_CURSOR_PIVOT_FIELD);
173 MAKE_CURSOR(PointerStyle::PivotDelete, pivotdel_, RID_CURSOR_PIVOT_DELETE);
174 MAKE_CURSOR(PointerStyle::Chain, chain_, RID_CURSOR_CHAIN);
175 MAKE_CURSOR(PointerStyle::ChainNotAllowed, chainnot_, RID_CURSOR_CHAIN_NOT_ALLOWED);
176 MAKE_CURSOR(PointerStyle::AutoScrollN, asn_, RID_CURSOR_AUTOSCROLL_N);
177 MAKE_CURSOR(PointerStyle::AutoScrollS, ass_, RID_CURSOR_AUTOSCROLL_S);
178 MAKE_CURSOR(PointerStyle::AutoScrollW, asw_, RID_CURSOR_AUTOSCROLL_W);
179 MAKE_CURSOR(PointerStyle::AutoScrollE, ase_, RID_CURSOR_AUTOSCROLL_E);
180 MAKE_CURSOR(PointerStyle::AutoScrollNW, asnw_, RID_CURSOR_AUTOSCROLL_NW);
181 MAKE_CURSOR(PointerStyle::AutoScrollNE, asne_, RID_CURSOR_AUTOSCROLL_NE);
182 MAKE_CURSOR(PointerStyle::AutoScrollSW, assw_, RID_CURSOR_AUTOSCROLL_SW);
183 MAKE_CURSOR(PointerStyle::AutoScrollSE, asse_, RID_CURSOR_AUTOSCROLL_SE);
184 MAKE_CURSOR(PointerStyle::AutoScrollNS, asns_, RID_CURSOR_AUTOSCROLL_NS);
185 MAKE_CURSOR(PointerStyle::AutoScrollWE, aswe_, RID_CURSOR_AUTOSCROLL_WE);
186 MAKE_CURSOR(PointerStyle::AutoScrollNSWE, asnswe_, RID_CURSOR_AUTOSCROLL_NSWE);
187 MAKE_CURSOR(PointerStyle::TextVertical, vertcurs_, RID_CURSOR_TEXT_VERTICAL);
189 MAKE_CURSOR(PointerStyle::TabSelectS, tblsels_, RID_CURSOR_TAB_SELECT_S);
190 MAKE_CURSOR(PointerStyle::TabSelectE, tblsele_, RID_CURSOR_TAB_SELECT_E);
191 MAKE_CURSOR(PointerStyle::TabSelectSE, tblselse_, RID_CURSOR_TAB_SELECT_SE);
192 MAKE_CURSOR(PointerStyle::TabSelectW, tblselw_, RID_CURSOR_TAB_SELECT_W);
193 MAKE_CURSOR(PointerStyle::TabSelectSW, tblselsw_, RID_CURSOR_TAB_SELECT_SW);
195 MAKE_CURSOR(PointerStyle::HideWhitespace, hidewhitespace_, RID_CURSOR_HIDE_WHITESPACE);
196 MAKE_CURSOR(PointerStyle::ShowWhitespace, showwhitespace_, RID_CURSOR_SHOW_WHITESPACE);
198 MAKE_CURSOR(PointerStyle::FatCross, fatcross_, RID_CURSOR_FATCROSS);
199 default:
200 break;
202 if (!pCursor)
204 pCursor = new QCursor(Qt::ArrowCursor);
205 SAL_WARN("vcl.qt", "pointer " << static_cast<int>(ePointerStyle) << " not implemented");
208 m_aCursors[ePointerStyle].reset(pCursor);
211 return *m_aCursors[ePointerStyle];
214 void QtData::ErrorTrapPush() {}
216 bool QtData::ErrorTrapPop(bool /*bIgnoreError*/) { return false; }
218 bool QtData::noNativeControls()
220 static const bool bNoNative
221 = ((nullptr != getenv("SAL_VCL_QT5_NO_NATIVE")) && (nullptr != ImplGetSVData())
222 && ImplGetSVData()->maAppData.mxToolkitName
223 && ImplGetSVData()->maAppData.mxToolkitName->match("qt5"));
224 return bNoNative;
227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */