VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/VBoxCocoaHelper.h

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: 2.2 KB
Line 
1/* $Id: VBoxCocoaHelper.h 106061 2024-09-16 14:03:52Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - VBoxCocoa Helper.
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#ifndef FEQT_INCLUDED_SRC_platform_darwin_VBoxCocoaHelper_h
29#define FEQT_INCLUDED_SRC_platform_darwin_VBoxCocoaHelper_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34/* Global includes */
35#include <VBox/VBoxCocoa.h>
36
37#ifdef __OBJC__
38
39/* System includes */
40#import <AppKit/NSImage.h>
41#import <Foundation/NSAutoreleasePool.h>
42#import <CoreFoundation/CFString.h>
43
44/* Qt includes */
45#include <QString>
46#include <QVarLengthArray>
47
48inline NSString *darwinQStringToNSString(const QString &aString)
49{
50 const UniChar *chars = reinterpret_cast<const UniChar *>(aString.unicode());
51 CFStringRef str = CFStringCreateWithCharacters(0, chars, aString.length());
52 return [(NSString*)CFStringCreateMutableCopy(0, 0, str) autorelease];
53}
54
55inline QString darwinNSStringToQString(const NSString *aString)
56{
57 CFStringRef str = reinterpret_cast<const CFStringRef>(aString);
58 if(!str)
59 return QString();
60 CFIndex length = CFStringGetLength(str);
61 const UniChar *chars = CFStringGetCharactersPtr(str);
62 if (chars)
63 return QString(reinterpret_cast<const QChar *>(chars), length);
64
65 QVarLengthArray<UniChar> buffer(length);
66 CFStringGetCharacters(str, CFRangeMake(0, length), buffer.data());
67 return QString(reinterpret_cast<const QChar *>(buffer.constData()), length);
68}
69
70#endif /* __OBJC__ */
71
72#endif /* !FEQT_INCLUDED_SRC_platform_darwin_VBoxCocoaHelper_h */
73
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