~ubuntu-branches/ubuntu/trusty/virtualbox-ose/trusty

« back to all changes in this revision

Viewing changes to src/VBox/Frontends/VirtualBox/src/widgets/VBoxToolBar.h

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2009-12-18 16:44:29 UTC
  • mfrom: (0.3.3 upstream) (0.4.6 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091218164429-jd34ccexpv5na11a
Tags: 3.1.2-dfsg-1ubuntu1
* Merge from Debian unstable (LP: #498219), remaining changes:
  - Disable update action
    - debian/patches/u01-disable-update-action.dpatch
  - VirtualBox should go in Accessories, not in System tools (LP: #288590)
    - debian/virtualbox-ose-qt.files/virtualbox-ose.desktop
  - Add Apport hook
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Add Launchpad integration
    - debian/control
    - debian/lpi-bug.xpm
    - debian/patches/u02-lp-integration.dpatch
* Fixes the following bugs:
  - Kernel module fails to build with Linux >= 2.6.32 (LP: #474625)
  - X.Org drivers need to be rebuilt against X-Server 1.7 (LP: #495935)
  - The *-source packages try to build the kernel modules even though the
    kernel headers aren't available (LP: #473334)
* Replace *-source packages with transitional packages for *-dkms.
* Adapt u01-disable-update-action.dpatch and u02-lp-integration.dpatch for
  new upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** @file
 
2
 *
 
3
 * VBox frontends: Qt GUI ("VirtualBox"):
 
4
 * VBoxToolBar class declaration & implementation
 
5
 */
 
6
 
 
7
/*
 
8
 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
 
9
 *
 
10
 * This file is part of VirtualBox Open Source Edition (OSE), as
 
11
 * available from http://www.virtualbox.org. This file is free software;
 
12
 * you can redistribute it and/or modify it under the terms of the GNU
 
13
 * General Public License (GPL) as published by the Free Software
 
14
 * Foundation, in version 2 as it comes in the "COPYING" file of the
 
15
 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
 
16
 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
 
17
 *
 
18
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
 
19
 * Clara, CA 95054 USA or visit http://www.sun.com if you need
 
20
 * additional information or have any questions.
 
21
 */
 
22
 
 
23
#ifndef ___VBoxToolBar_h___
 
24
#define ___VBoxToolBar_h___
 
25
 
 
26
#include <QGlobalStatic> /* for Q_WS_MAC */
 
27
#ifdef Q_WS_MAC
 
28
#include "VBoxUtils.h"
 
29
#endif
 
30
 
 
31
/* Qt includes */
 
32
#include <QLayout>
 
33
#include <QMainWindow>
 
34
#include <QToolBar>
 
35
 
 
36
/* Note: This styles are available on _all_ platforms. */
 
37
#include <QCleanlooksStyle>
 
38
#include <QWindowsStyle>
 
39
 
 
40
/**
 
41
 *  The VBoxToolBar class is a simple QToolBar reimplementation to disable
 
42
 *  its built-in context menu and add some default behavior we need.
 
43
 */
 
44
class VBoxToolBar : public QToolBar
 
45
{
 
46
 
 
47
public:
 
48
 
 
49
    VBoxToolBar (QWidget *aParent)
 
50
        : QToolBar (aParent)
 
51
        , mMainWindow (qobject_cast <QMainWindow*> (aParent))
 
52
    {
 
53
        setFloatable (false);
 
54
        setMovable (false);
 
55
 
 
56
        /* Remove that ugly frame panel around the toolbar.
 
57
         * Doing that currently for Cleanlooks & Windows styles. */
 
58
        if (qobject_cast <QCleanlooksStyle*> (QToolBar::style()) ||
 
59
            qobject_cast <QWindowsStyle*> (QToolBar::style()))
 
60
            setStyleSheet ("QToolBar { border: 0px none black; }");
 
61
 
 
62
        if (layout())
 
63
            layout()->setContentsMargins (0, 0, 0, 0);;
 
64
 
 
65
        setContextMenuPolicy (Qt::NoContextMenu);
 
66
    }
 
67
 
 
68
#ifdef Q_WS_MAC
 
69
    void setMacToolbar()
 
70
    {
 
71
        if (mMainWindow)
 
72
        {
 
73
            mMainWindow->setUnifiedTitleAndToolBarOnMac (true);
 
74
#ifndef QT_MAC_USE_COCOA
 
75
            WindowRef window = ::darwinToNativeWindow (this);
 
76
            EventHandlerUPP eventHandler = ::NewEventHandlerUPP (VBoxToolBar::macEventFilter);
 
77
            EventTypeSpec eventTypes[2];
 
78
            eventTypes[0].eventClass = kEventClassMouse;
 
79
            eventTypes[0].eventKind  = kEventMouseDown;
 
80
            eventTypes[1].eventClass = kEventClassMouse;
 
81
            eventTypes[1].eventKind  = kEventMouseUp;
 
82
            InstallWindowEventHandler (window, eventHandler,
 
83
                                       RT_ELEMENTS (eventTypes), eventTypes,
 
84
                                       NULL, NULL);
 
85
#endif /* !QT_MAC_USE_COCOA */
 
86
        }
 
87
    }
 
88
 
 
89
#ifndef QT_MAC_USE_COCOA
 
90
    static pascal OSStatus macEventFilter (EventHandlerCallRef aNextHandler,
 
91
                                           EventRef aEvent, void * /* aUserData */)
 
92
    {
 
93
        UInt32 eclass = GetEventClass (aEvent);
 
94
        if (eclass == kEventClassMouse)
 
95
        {
 
96
            WindowPartCode partCode;
 
97
            GetEventParameter (aEvent, kEventParamWindowPartCode, typeWindowPartCode, NULL, sizeof (WindowPartCode), NULL, &partCode);
 
98
            UInt32 ekind = GetEventKind (aEvent);
 
99
            if (partCode == 15 ||
 
100
                partCode == 4)
 
101
                if(ekind == kEventMouseDown || ekind == kEventMouseUp)
 
102
                {
 
103
                    EventMouseButton button = 0;
 
104
                    GetEventParameter (aEvent, kEventParamMouseButton, typeMouseButton, NULL, sizeof (button), NULL, &button);
 
105
                    if (button != kEventMouseButtonPrimary)
 
106
                        return noErr;
 
107
                }
 
108
        }
 
109
        return CallNextEventHandler (aNextHandler, aEvent);
 
110
    }
 
111
#endif /* !QT_MAC_USE_COCOA */
 
112
 
 
113
    void setShowToolBarButton (bool aShow)
 
114
    {
 
115
        ::darwinSetShowsToolbarButton (this, aShow);
 
116
    }
 
117
#endif /* Q_WS_MAC */
 
118
 
 
119
    void setUsesTextLabel (bool aEnable)
 
120
    {
 
121
        Qt::ToolButtonStyle tbs = Qt::ToolButtonTextUnderIcon;
 
122
        if (!aEnable)
 
123
            tbs = Qt::ToolButtonIconOnly;
 
124
 
 
125
        if (mMainWindow)
 
126
            mMainWindow->setToolButtonStyle (tbs);
 
127
        else
 
128
            setToolButtonStyle (tbs);
 
129
    }
 
130
 
 
131
private:
 
132
 
 
133
    QMainWindow *mMainWindow;
 
134
};
 
135
 
 
136
#endif // !___VBoxToolBar_h___
 
137