VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/UIAbstractDockIconPreview.cpp

Last change on this file was 106061, checked in by vboxsync, 3 weeks ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.1 KB
Line 
1/* $Id: UIAbstractDockIconPreview.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - Realtime Dock Icon Preview
4 */
5
6/*
7 * Copyright (C) 2009-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28/* Qt includes: */
29#include <QStyle>
30
31/* GUI includes: */
32#include "UIAbstractDockIconPreview.h"
33#include "UICommon.h"
34#include "UIConverter.h"
35#include "UIExtraDataManager.h"
36#include "UIFrameBuffer.h"
37#include "UIMachine.h"
38#include "UIMachineLogic.h"
39#include "UIMachineView.h"
40
41/* COM includes: */
42
43
44UIAbstractDockIconPreview::UIAbstractDockIconPreview(UIMachine *, const QPixmap &)
45{
46}
47
48void UIAbstractDockIconPreview::updateDockPreview(UIFrameBuffer *pFrameBuffer)
49{
50 CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
51 Assert(cs);
52 /* Create the image copy of the framebuffer */
53 CGDataProviderRef dp = CGDataProviderCreateWithData(pFrameBuffer, pFrameBuffer->address(), pFrameBuffer->bitsPerPixel() / 8 * pFrameBuffer->width() * pFrameBuffer->height(), NULL);
54 Assert(dp);
55 CGImageRef ir = CGImageCreate(pFrameBuffer->width(), pFrameBuffer->height(), 8, 32, pFrameBuffer->bytesPerLine(), cs,
56 kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host, dp, 0, false,
57 kCGRenderingIntentDefault);
58 Assert(ir);
59
60 /* Update the dock preview icon */
61 updateDockPreview(ir);
62
63 /* Release the temp data and image */
64 CGImageRelease(ir);
65 CGDataProviderRelease(dp);
66 CGColorSpaceRelease(cs);
67}
68
69UIAbstractDockIconPreviewHelper::UIAbstractDockIconPreviewHelper(UIMachine *pMachine, const QPixmap& overlayImage)
70 : m_pMachine(pMachine)
71 , m_dockIconRect(CGRectMake(0, 0, 128, 128))
72 , m_dockMonitor(NULL)
73 , m_dockMonitorGlossy(NULL)
74 , m_updateRect(CGRectMake(0, 0, 0, 0))
75 , m_monitorRect(CGRectMake(0, 0, 0, 0))
76{
77 m_overlayImage = ::darwinToCGImageRef(&overlayImage);
78 Assert(m_overlayImage);
79}
80
81void* UIAbstractDockIconPreviewHelper::currentPreviewWindowId() const
82{
83 /* Get the MachineView which is currently previewed and return the win id
84 of the viewport. */
85 UIMachineView* pView = m_pMachine->machineLogic()->dockPreviewView();
86 if (pView)
87 return (void*)pView->viewport()->winId();
88 return 0;
89}
90
91UIAbstractDockIconPreviewHelper::~UIAbstractDockIconPreviewHelper()
92{
93 CGImageRelease(m_overlayImage);
94 if (m_dockMonitor)
95 CGImageRelease(m_dockMonitor);
96 if (m_dockMonitorGlossy)
97 CGImageRelease(m_dockMonitorGlossy);
98}
99
100void UIAbstractDockIconPreviewHelper::initPreviewImages()
101{
102 if (!m_dockMonitor)
103 {
104 m_dockMonitor = ::darwinToCGImageRef("monitor.png");
105 Assert(m_dockMonitor);
106 /* Center it on the dock icon context */
107 m_monitorRect = centerRect(CGRectMake(0, 0,
108 CGImageGetWidth(m_dockMonitor),
109 CGImageGetWidth(m_dockMonitor)));
110 }
111
112 if (!m_dockMonitorGlossy)
113 {
114 m_dockMonitorGlossy = ::darwinToCGImageRef("monitor_glossy.png");
115 Assert(m_dockMonitorGlossy);
116 /* This depends on the content of monitor.png */
117 m_updateRect = CGRectMake(m_monitorRect.origin.x + 8 /* left-frame */ + 1 /* indent-size */,
118 m_monitorRect.origin.y + 8 /* top-frame */ + 1 /* indent-size */,
119 128 /* .png-width */ - 8 /* left-frame */ - 8 /* right-frame */ - 2 * 1 /* indent-size */,
120 128 /* .png-height */ - 8 /* top-frame */ - 25 /* bottom-frame */ - 2 * 1 /* indent-size */);
121 }
122}
123
124void UIAbstractDockIconPreviewHelper::drawOverlayIcons(CGContextRef context)
125{
126 /* Determine whether dock icon overlay is not disabled: */
127 if (!gEDataManager->dockIconDisableOverlay(uiCommon().managedVMUuid()))
128 {
129 /* Initialize overlay rectangle: */
130 CGRect overlayRect = CGRectMake(0, 0, 0, 0);
131 /* Make sure overlay image is valid: */
132 if (m_overlayImage)
133 {
134 /* Draw overlay image at bottom-right of dock icon: */
135 overlayRect = CGRectMake(m_dockIconRect.size.width - CGImageGetWidth(m_overlayImage),
136 m_dockIconRect.size.height - CGImageGetHeight(m_overlayImage),
137 CGImageGetWidth(m_overlayImage),
138 CGImageGetHeight(m_overlayImage));
139 CGContextDrawImage(context, flipRect(overlayRect), m_overlayImage);
140 }
141 }
142}
143
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette