build fix: no comphelper/profilezone.hxx in this branch
[LibreOffice.git] / vcl / source / window / openglwin.cxx
blob7d20fd777ad4a787202d61b7859bb7248e3641c2
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/.
8 */
10 #include <vcl/openglwin.hxx>
11 #include <vcl/opengl/OpenGLContext.hxx>
12 #include <vcl/event.hxx>
13 #include <vcl/sysdata.hxx>
15 class OpenGLWindowImpl
17 public:
18 explicit OpenGLWindowImpl(vcl::Window* pWindow, bool bInit);
19 ~OpenGLWindowImpl();
20 OpenGLContext& getContext() { return *mxContext.get(); }
22 bool IsInitialized() const;
24 void Initialize();
26 private:
28 rtl::Reference<OpenGLContext> mxContext;
29 VclPtr<SystemChildWindow> mxChildWindow;
31 bool mbInitialized;
34 OpenGLWindowImpl::OpenGLWindowImpl(vcl::Window* pWindow, bool bInit)
35 : mxContext(OpenGLContext::Create()),
36 mbInitialized(bInit)
38 SystemWindowData aData = mxContext->generateWinData(pWindow, false);
39 mxChildWindow.reset(VclPtr<SystemChildWindow>::Create(pWindow, 0, &aData));
40 mxChildWindow->Show();
42 if (bInit)
43 mxContext->init(mxChildWindow.get());
45 pWindow->SetMouseTransparent(false);
48 OpenGLWindowImpl::~OpenGLWindowImpl()
50 mxContext->dispose();
51 mxChildWindow.disposeAndClear();
54 bool OpenGLWindowImpl::IsInitialized() const
56 return mbInitialized;
59 void OpenGLWindowImpl::Initialize()
61 mxContext->init(mxChildWindow.get());
62 mbInitialized = true;
65 OpenGLWindow::OpenGLWindow(vcl::Window* pParent, bool bInit):
66 Window(pParent, 0),
67 mxImpl(new OpenGLWindowImpl(this, bInit)),
68 mpRenderer(nullptr)
72 OpenGLWindow::~OpenGLWindow()
74 disposeOnce();
77 void OpenGLWindow::dispose()
79 if(mpRenderer)
80 mpRenderer->contextDestroyed();
81 mpRenderer = nullptr;
82 mxImpl.reset();
83 Window::dispose();
86 OpenGLContext& OpenGLWindow::getContext()
88 return mxImpl->getContext();
91 void OpenGLWindow::Paint(vcl::RenderContext& /*rRenderContext*/, const Rectangle&)
93 if(mpRenderer)
94 mpRenderer->update();
97 void OpenGLWindow::MouseButtonDown( const MouseEvent& rMEvt )
99 maStartPoint = rMEvt.GetPosPixel();
102 void OpenGLWindow::MouseButtonUp( const MouseEvent& rMEvt )
104 if(!mpRenderer)
105 return;
107 Point aPoint = rMEvt.GetPosPixel();
108 if(aPoint == maStartPoint)
110 mpRenderer->clickedAt(aPoint, rMEvt.GetButtons());
112 else
114 mpRenderer->mouseDragMove(maStartPoint, aPoint,
115 rMEvt.GetButtons());
119 void OpenGLWindow::Command( const CommandEvent& rCEvt )
121 if(!mpRenderer)
122 return;
124 if(rCEvt.GetCommand() == CommandEventId::Wheel)
126 const CommandWheelData* pData = rCEvt.GetWheelData();
127 if(pData->GetMode() == CommandWheelMode::SCROLL)
129 long nDelta = pData->GetDelta();
130 mpRenderer->scroll(nDelta);
135 void OpenGLWindow::MouseMove( const MouseEvent& /*rMEvt*/ )
139 void OpenGLWindow::setRenderer(IRenderer* pRenderer)
141 mpRenderer = pRenderer;
144 void OpenGLWindow::Initialize()
146 if (!mxImpl->IsInitialized())
147 mxImpl->Initialize();
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */