calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / vcl / unx / generic / app / salinst.cxx
blob502f4c7f7ec279753098ad3f9a8318aca9695d2d
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 <stdlib.h>
22 #include <config_features.h>
23 #include <vcl/skia/SkiaHelper.hxx>
24 #include <config_skia.h>
25 #if HAVE_FEATURE_SKIA
26 #include <skia/x11/gdiimpl.hxx>
27 #include <skia/salbmp.hxx>
28 #endif
30 #include <unx/saldata.hxx>
31 #include <unx/saldisp.hxx>
32 #include <unx/salinst.h>
33 #include <unx/geninst.h>
34 #include <unx/genpspgraphics.h>
35 #include <unx/salframe.h>
36 #include <unx/sm.hxx>
37 #include <unx/i18n_im.hxx>
38 #include <unx/salbmp.h>
40 #include <vcl/inputtypes.hxx>
42 #include <salwtype.hxx>
44 // plugin factory function
45 extern "C"
47 VCLPLUG_GEN_PUBLIC SalInstance* create_SalInstance()
49 /* #i92121# workaround deadlocks in the X11 implementation
51 static const char* pNoXInitThreads = getenv( "SAL_NO_XINITTHREADS" );
52 /* #i90094#
53 from now on we know that an X connection will be
54 established, so protect X against itself
56 if( ! ( pNoXInitThreads && *pNoXInitThreads ) )
57 XInitThreads();
59 X11SalInstance* pInstance = new X11SalInstance( std::make_unique<SalYieldMutex>() );
61 // initialize SalData
62 X11SalData *pSalData = new X11SalData();
64 pSalData->Init();
65 pInstance->SetLib( pSalData->GetLib() );
67 return pInstance;
71 X11SalInstance::X11SalInstance(std::unique_ptr<SalYieldMutex> pMutex)
72 : SalGenericInstance(std::move(pMutex))
73 , mpXLib(nullptr)
75 ImplSVData* pSVData = ImplGetSVData();
76 pSVData->maAppData.mxToolkitName = OUString("x11");
77 m_bSupportsOpenGL = true;
78 #if HAVE_FEATURE_SKIA
79 X11SkiaSalGraphicsImpl::prepareSkia();
80 #if SKIA_USE_BITMAP32
81 if (SkiaHelper::isVCLSkiaEnabled())
82 m_bSupportsBitmap32 = true;
83 #endif
84 #endif
87 X11SalInstance::~X11SalInstance()
89 // close session management
90 SessionManagerClient::close();
92 // dispose SalDisplay list from SalData
93 // would be done in a static destructor else which is
94 // a little late
95 GetGenericUnixSalData()->Dispose();
97 #if HAVE_FEATURE_SKIA
98 SkiaHelper::cleanup();
99 #endif
102 SalX11Display* X11SalInstance::CreateDisplay() const
104 return new SalX11Display( mpXLib->GetDisplay() );
107 // AnyInput from sv/mow/source/app/svapp.cxx
109 namespace {
111 struct PredicateReturn
113 VclInputFlags nType;
114 bool bRet;
119 extern "C" {
120 static Bool ImplPredicateEvent( Display *, XEvent *pEvent, char *pData )
122 PredicateReturn *pPre = reinterpret_cast<PredicateReturn *>(pData);
124 if ( pPre->bRet )
125 return False;
127 VclInputFlags nType;
129 switch( pEvent->type )
131 case ButtonPress:
132 case ButtonRelease:
133 case MotionNotify:
134 case EnterNotify:
135 case LeaveNotify:
136 nType = VclInputFlags::MOUSE;
137 break;
139 case KeyPress:
140 //case KeyRelease:
141 nType = VclInputFlags::KEYBOARD;
142 break;
143 case Expose:
144 case GraphicsExpose:
145 case NoExpose:
146 nType = VclInputFlags::PAINT;
147 break;
148 default:
149 nType = VclInputFlags::NONE;
152 if ( (nType & pPre->nType) || ( nType == VclInputFlags::NONE && (pPre->nType & VclInputFlags::OTHER) ) )
153 pPre->bRet = true;
155 return False;
159 bool X11SalInstance::AnyInput(VclInputFlags nType)
161 GenericUnixSalData *pData = GetGenericUnixSalData();
162 Display *pDisplay = vcl_sal::getSalDisplay(pData)->GetDisplay();
163 bool bRet = false;
165 if( (nType & VclInputFlags::TIMER) && (mpXLib && mpXLib->CheckTimeout(false)) )
166 bRet = true;
168 if( !bRet && XPending(pDisplay) )
170 PredicateReturn aInput;
171 XEvent aEvent;
173 aInput.bRet = false;
174 aInput.nType = nType;
176 XCheckIfEvent(pDisplay, &aEvent, ImplPredicateEvent,
177 reinterpret_cast<char *>(&aInput) );
179 bRet = aInput.bRet;
181 #if OSL_DEBUG_LEVEL > 1
182 SAL_INFO("vcl.app", "AnyInput "
183 << std::showbase << std::hex
184 << static_cast<unsigned int>(nType)
185 << " = " << (bRet ? "true" : "false"));
186 #endif
187 return bRet;
190 bool X11SalInstance::DoYield(bool bWait, bool bHandleAllCurrentEvents)
192 return mpXLib->Yield( bWait, bHandleAllCurrentEvents );
195 OUString X11SalInstance::GetConnectionIdentifier()
197 static const char* pDisplay = getenv( "DISPLAY" );
198 return pDisplay ? OUString::createFromAscii(pDisplay) : OUString();
201 SalFrame *X11SalInstance::CreateFrame( SalFrame *pParent, SalFrameStyleFlags nSalFrameStyle )
203 SalFrame *pFrame = new X11SalFrame( pParent, nSalFrameStyle );
205 return pFrame;
208 SalFrame* X11SalInstance::CreateChildFrame( SystemParentData* pParentData, SalFrameStyleFlags nStyle )
210 SalFrame* pFrame = new X11SalFrame( nullptr, nStyle, pParentData );
212 return pFrame;
215 void X11SalInstance::DestroyFrame( SalFrame* pFrame )
217 delete pFrame;
220 void X11SalInstance::AfterAppInit()
222 assert( mpXLib->GetDisplay() );
223 assert( mpXLib->GetInputMethod() );
225 SalX11Display *pSalDisplay = CreateDisplay();
226 mpXLib->GetInputMethod()->CreateMethod( mpXLib->GetDisplay() );
227 pSalDisplay->SetupInput();
230 void X11SalInstance::AddToRecentDocumentList(const OUString&, const OUString&, const OUString&) {}
232 void X11SalInstance::PostPrintersChanged()
234 SalDisplay* pDisp = vcl_sal::getSalDisplay(GetGenericUnixSalData());
235 for (auto pSalFrame : pDisp->getFrames() )
236 pDisp->PostEvent( pSalFrame, nullptr, SalEvent::PrinterChanged );
239 std::unique_ptr<GenPspGraphics> X11SalInstance::CreatePrintGraphics()
241 return std::make_unique<GenPspGraphics>();
244 std::shared_ptr<SalBitmap> X11SalInstance::CreateSalBitmap()
246 #if HAVE_FEATURE_SKIA
247 if (SkiaHelper::isVCLSkiaEnabled())
248 return std::make_shared<SkiaSalBitmap>();
249 else
250 #endif
251 return std::make_shared<X11SalBitmap>();
254 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */