VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/UICocoaSpecialControls.mm@ 74942

Last change on this file since 74942 was 71577, checked in by vboxsync, 6 years ago

FE/Qt: bugref:9049: Full and heavy cleanup for UISpecialControls and UICocoaSpecialControls stuff.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.4 KB
Line 
1/* $Id: UICocoaSpecialControls.mm 71577 2018-03-29 17:13:05Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UICocoaSpecialControls implementation.
4 */
5
6/*
7 * Copyright (C) 2009-2018 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18/* Qt includes: */
19#include <QMacCocoaViewContainer>
20
21/* GUI includes: */
22#include "VBoxUtils-darwin.h"
23#include "UICocoaSpecialControls.h"
24
25/* System includes: */
26#import <AppKit/NSButton.h>
27
28
29/** Private button-target interface. */
30@interface UIButtonTargetPrivate : NSObject
31{
32 UICocoaButton *m_pRealTarget;
33}
34// WORKAROUND:
35// The next method used to be called initWithObject, but Xcode 4.1 preview 5
36// cannot cope with that for some reason. Hope this doesn't break anything.
37-(id)initWithObjectAndLionTrouble:(UICocoaButton*)pObject;
38-(IBAction)clicked:(id)pSender;
39@end
40
41
42/*********************************************************************************************************************************
43* Class UIButtonTargetPrivate implementation. *
44*********************************************************************************************************************************/
45
46@implementation UIButtonTargetPrivate
47-(id)initWithObjectAndLionTrouble:(UICocoaButton*)pObject
48{
49 self = [super init];
50
51 m_pRealTarget = pObject;
52
53 return self;
54}
55
56-(IBAction)clicked:(id)pSender
57{
58 Q_UNUSED(pSender);
59 m_pRealTarget->onClicked();
60}
61@end
62
63
64/*********************************************************************************************************************************
65* Class UICocoaButton implementation. *
66*********************************************************************************************************************************/
67
68UICocoaButton::UICocoaButton(QWidget *pParent, CocoaButtonType enmType)
69 : QMacCocoaViewContainer(0, pParent)
70{
71 /* Prepare auto-release pool: */
72 NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
73
74 /* Prepare native button reference: */
75 NativeNSButtonRef pNativeRef;
76 NSRect initFrame;
77
78 /* Configure button: */
79 switch (enmType)
80 {
81 case HelpButton:
82 {
83 pNativeRef = [[NSButton alloc] init];
84 [pNativeRef setTitle: @""];
85 [pNativeRef setBezelStyle: NSHelpButtonBezelStyle];
86 [pNativeRef setBordered: YES];
87 [pNativeRef setAlignment: NSCenterTextAlignment];
88 [pNativeRef sizeToFit];
89 initFrame = [pNativeRef frame];
90 initFrame.size.width += 12; /* Margin */
91 [pNativeRef setFrame:initFrame];
92 break;
93 };
94 case CancelButton:
95 {
96 pNativeRef = [[NSButton alloc] initWithFrame: NSMakeRect(0, 0, 13, 13)];
97 [pNativeRef setTitle: @""];
98 [pNativeRef setBezelStyle:NSShadowlessSquareBezelStyle];
99 [pNativeRef setButtonType:NSMomentaryChangeButton];
100 [pNativeRef setImage: [NSImage imageNamed: NSImageNameStopProgressFreestandingTemplate]];
101 [pNativeRef setBordered: NO];
102 [[pNativeRef cell] setImageScaling: NSImageScaleProportionallyDown];
103 initFrame = [pNativeRef frame];
104 break;
105 }
106 case ResetButton:
107 {
108 pNativeRef = [[NSButton alloc] initWithFrame: NSMakeRect(0, 0, 13, 13)];
109 [pNativeRef setTitle: @""];
110 [pNativeRef setBezelStyle:NSShadowlessSquareBezelStyle];
111 [pNativeRef setButtonType:NSMomentaryChangeButton];
112 [pNativeRef setImage: [NSImage imageNamed: NSImageNameRefreshFreestandingTemplate]];
113 [pNativeRef setBordered: NO];
114 [[pNativeRef cell] setImageScaling: NSImageScaleProportionallyDown];
115 initFrame = [pNativeRef frame];
116 break;
117 }
118 }
119
120 /* Install click listener: */
121 UIButtonTargetPrivate *bt = [[UIButtonTargetPrivate alloc] initWithObjectAndLionTrouble:this];
122 [pNativeRef setTarget:bt];
123 [pNativeRef setAction:@selector(clicked:)];
124
125 /* Put the button to the QCocoaViewContainer: */
126 setCocoaView(pNativeRef);
127 /* Release our reference, since our super class
128 * takes ownership and we don't need it anymore. */
129 [pNativeRef release];
130
131 /* Finally resize the widget: */
132 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
133 setFixedSize(NSWidth(initFrame), NSHeight(initFrame));
134
135 /* Cleanup auto-release pool: */
136 [pPool release];
137}
138
139UICocoaButton::~UICocoaButton()
140{
141}
142
143QSize UICocoaButton::sizeHint() const
144{
145 NSRect frame = [nativeRef() frame];
146 return QSize(frame.size.width, frame.size.height);
147}
148
149void UICocoaButton::setText(const QString &strText)
150{
151 QString s(strText);
152 /* Set it for accessibility reasons as alternative title: */
153 [nativeRef() setAlternateTitle: ::darwinQStringToNSString(s.remove('&'))];
154}
155
156void UICocoaButton::setToolTip(const QString &strToolTip)
157{
158 [nativeRef() setToolTip: ::darwinQStringToNSString(strToolTip)];
159}
160
161void UICocoaButton::onClicked()
162{
163 emit clicked(false);
164}
165
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use