VBoxConsoleView.h revision 5171615b463e14b73d00e295516beb4c8caf68a4
6ae232055d4d8a97267517c5e50074c2c819941and/** @file
6ae232055d4d8a97267517c5e50074c2c819941and *
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * VBox frontends: Qt GUI ("VirtualBox"):
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * VBoxConsoleView class declaration
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd */
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and/*
6ae232055d4d8a97267517c5e50074c2c819941and * Copyright (C) 2006-2007 innotek GmbH
6ae232055d4d8a97267517c5e50074c2c819941and *
96ad5d81ee4a2cc66a4ae19893efc8aa6d06fae7jailletc * This file is part of VirtualBox Open Source Edition (OSE), as
6ae232055d4d8a97267517c5e50074c2c819941and * available from http://www.virtualbox.org. This file is free software;
6ae232055d4d8a97267517c5e50074c2c819941and * you can redistribute it and/or modify it under the terms of the GNU
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * General Public License (GPL) as published by the Free Software
2e545ce2450a9953665f701bb05350f0d3f26275nd * Foundation, in version 2 as it comes in the "COPYING" file of the
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
6ae232055d4d8a97267517c5e50074c2c819941and */
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and#ifndef __VBoxConsoleView_h__
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen#define __VBoxConsoleView_h__
3f08db06526d6901aa08c110b5bc7dde6bc39905nd
6ae232055d4d8a97267517c5e50074c2c819941and#include "COMDefs.h"
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and#include "VBoxDefs.h"
b43f840409794ed298e8634f6284741f193b6c4ftakashi#include "VBoxGlobalSettings.h"
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and#include <qdatetime.h>
6ae232055d4d8a97267517c5e50074c2c819941and#include <qscrollview.h>
b43f840409794ed298e8634f6284741f193b6c4ftakashi#include <qpixmap.h>
6ae232055d4d8a97267517c5e50074c2c819941and#include <qimage.h>
bc9d4698fce0238d2f6f2682e99423ebb1149976rbowen
6ae232055d4d8a97267517c5e50074c2c819941and#include <qkeysequence.h>
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung
6ae232055d4d8a97267517c5e50074c2c819941and#if defined (Q_WS_PM)
b43f840409794ed298e8634f6284741f193b6c4ftakashi#include "src/os2/VBoxHlp.h"
b43f840409794ed298e8634f6284741f193b6c4ftakashi#endif
b43f840409794ed298e8634f6284741f193b6c4ftakashi
b43f840409794ed298e8634f6284741f193b6c4ftakashi#if defined (Q_WS_MAC)
6ae232055d4d8a97267517c5e50074c2c819941and# include <Carbon/Carbon.h>
6ae232055d4d8a97267517c5e50074c2c819941and# include "DarwinCursor.h"
6ae232055d4d8a97267517c5e50074c2c819941and/** @todo remove this hack when somebody get around fixing the conflicting typedef/enum OSType. */
6ae232055d4d8a97267517c5e50074c2c819941and# define OSType VBoxOSType
6ae232055d4d8a97267517c5e50074c2c819941and#endif
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941andclass VBoxConsoleWnd;
6ae232055d4d8a97267517c5e50074c2c819941andclass MousePointerChangeEvent;
1ac39787115a288f5e848344b1b1e8dccb1c58f1ndclass VBoxFrameBuffer;
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941andclass QPainter;
6ae232055d4d8a97267517c5e50074c2c819941andclass QLabel;
6ae232055d4d8a97267517c5e50074c2c819941andclass QMenuData;
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941andclass VBoxConsoleView : public QScrollView
6ae232055d4d8a97267517c5e50074c2c819941and{
6ae232055d4d8a97267517c5e50074c2c819941and Q_OBJECT
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941andpublic:
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and enum {
6ae232055d4d8a97267517c5e50074c2c819941and MouseCaptured = 0x01,
6ae232055d4d8a97267517c5e50074c2c819941and MouseAbsolute = 0x02,
6ae232055d4d8a97267517c5e50074c2c819941and MouseAbsoluteDisabled = 0x04,
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh MouseNeedsHostCursor = 0x08,
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar KeyboardCaptured = 0x01,
6ae232055d4d8a97267517c5e50074c2c819941and HostKeyPressed = 0x02,
6ae232055d4d8a97267517c5e50074c2c819941and };
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and VBoxConsoleView (VBoxConsoleWnd *mainWnd,
6ae232055d4d8a97267517c5e50074c2c819941and const CConsole &console,
6ae232055d4d8a97267517c5e50074c2c819941and VBoxDefs::RenderMode rm,
6ae232055d4d8a97267517c5e50074c2c819941and QWidget *parent = 0, const char *name = 0, WFlags f = 0);
6ae232055d4d8a97267517c5e50074c2c819941and ~VBoxConsoleView();
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and QSize sizeHint() const;
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and void attach();
6ae232055d4d8a97267517c5e50074c2c819941and void detach();
6ae232055d4d8a97267517c5e50074c2c819941and void refresh() { doRefresh(); }
6ae232055d4d8a97267517c5e50074c2c819941and void normalizeGeometry (bool adjustPosition = false);
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and CConsole &console() { return mConsole; }
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and bool pause (bool on);
6ae232055d4d8a97267517c5e50074c2c819941and
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd void setMouseIntegrationEnabled (bool enabled);
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd
6ae232055d4d8a97267517c5e50074c2c819941and bool isMouseAbsolute() const { return mMouseAbsolute; }
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and void setAutoresizeGuest (bool on);
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and void onFullscreenChange (bool on);
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and void onViewOpened();
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and void fixModifierState (LONG *codes, uint *count);
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and void toggleFSMode();
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and void setIgnoreMainwndResize (bool aYes) { mIgnoreMainwndResize = aYes; }
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941andsignals:
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and void keyboardStateChanged (int state);
6ae232055d4d8a97267517c5e50074c2c819941and void mouseStateChanged (int state);
6ae232055d4d8a97267517c5e50074c2c819941and void machineStateChanged (CEnums::MachineState state);
6ae232055d4d8a97267517c5e50074c2c819941and void additionsStateChanged (const QString &, bool, bool);
6ae232055d4d8a97267517c5e50074c2c819941and void mediaChanged (VBoxDefs::DiskType aType);
6ae232055d4d8a97267517c5e50074c2c819941and void networkStateChange();
6ae232055d4d8a97267517c5e50074c2c819941and void usbStateChange();
6ae232055d4d8a97267517c5e50074c2c819941and void sharedFoldersChanged();
6ae232055d4d8a97267517c5e50074c2c819941and void resizeHintDone();
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941andprotected:
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and // events
6ae232055d4d8a97267517c5e50074c2c819941and bool event (QEvent *e);
6ae232055d4d8a97267517c5e50074c2c819941and bool eventFilter (QObject *watched, QEvent *e);
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and#if defined(Q_WS_WIN32)
6ae232055d4d8a97267517c5e50074c2c819941and bool winLowKeyboardEvent (UINT msg, const KBDLLHOOKSTRUCT &event);
6ae232055d4d8a97267517c5e50074c2c819941and bool winEvent (MSG *msg);
6ae232055d4d8a97267517c5e50074c2c819941and#elif defined(Q_WS_PM)
6ae232055d4d8a97267517c5e50074c2c819941and bool pmEvent (QMSG *aMsg);
6ae232055d4d8a97267517c5e50074c2c819941and#elif defined(Q_WS_X11)
6ae232055d4d8a97267517c5e50074c2c819941and bool x11Event (XEvent *event);
6ae232055d4d8a97267517c5e50074c2c819941and#elif defined(Q_WS_MAC)
6ae232055d4d8a97267517c5e50074c2c819941and bool darwinKeyboardEvent (EventRef inEvent);
6ae232055d4d8a97267517c5e50074c2c819941and void darwinGrabKeyboardEvents (bool fGrab);
6ae232055d4d8a97267517c5e50074c2c819941and#endif
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941andprivate:
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and /** Flags for keyEvent(). */
6ae232055d4d8a97267517c5e50074c2c819941and enum {
6ae232055d4d8a97267517c5e50074c2c819941and KeyExtended = 0x01,
6ae232055d4d8a97267517c5e50074c2c819941and KeyPressed = 0x02,
6ae232055d4d8a97267517c5e50074c2c819941and KeyPause = 0x04,
6ae232055d4d8a97267517c5e50074c2c819941and KeyPrint = 0x08,
6ae232055d4d8a97267517c5e50074c2c819941and };
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and void focusEvent (bool aHasFocus, bool aReleaseHostKey = true);
6ae232055d4d8a97267517c5e50074c2c819941and bool keyEvent (int aKey, uint8_t aScan, int aFlags,
6ae232055d4d8a97267517c5e50074c2c819941and wchar_t *aUniKey = NULL);
6ae232055d4d8a97267517c5e50074c2c819941and bool mouseEvent (int aType, const QPoint &aPos, const QPoint &aGlobalPos,
6ae232055d4d8a97267517c5e50074c2c819941and ButtonState aButton,
6ae232055d4d8a97267517c5e50074c2c819941and ButtonState aState, ButtonState aStateAfter,
6ae232055d4d8a97267517c5e50074c2c819941and int aWheelDelta, Orientation aWheelDir);
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and void emitKeyboardStateChanged()
6ae232055d4d8a97267517c5e50074c2c819941and {
6ae232055d4d8a97267517c5e50074c2c819941and emit keyboardStateChanged (
6ae232055d4d8a97267517c5e50074c2c819941and (mKbdCaptured ? KeyboardCaptured : 0) |
6ae232055d4d8a97267517c5e50074c2c819941and (mIsHostkeyPressed ? HostKeyPressed : 0));
6ae232055d4d8a97267517c5e50074c2c819941and }
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and void emitMouseStateChanged() {
6ae232055d4d8a97267517c5e50074c2c819941and emit mouseStateChanged ((mMouseCaptured ? MouseCaptured : 0) |
6ae232055d4d8a97267517c5e50074c2c819941and (mMouseAbsolute ? MouseAbsolute : 0) |
6ae232055d4d8a97267517c5e50074c2c819941and (!mMouseIntegration ? MouseAbsoluteDisabled : 0));
6ae232055d4d8a97267517c5e50074c2c819941and }
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and // IConsoleCallback event handlers
6ae232055d4d8a97267517c5e50074c2c819941and void onStateChange (CEnums::MachineState state);
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and void doRefresh();
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and void viewportPaintEvent( QPaintEvent * );
6ae232055d4d8a97267517c5e50074c2c819941and#ifdef VBOX_GUI_USE_REFRESH_TIMER
6ae232055d4d8a97267517c5e50074c2c819941and void timerEvent( QTimerEvent * );
6ae232055d4d8a97267517c5e50074c2c819941and#endif
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and void captureKbd (bool aCapture, bool aEmitSignal = true);
6ae232055d4d8a97267517c5e50074c2c819941and void captureMouse (bool aCapture, bool aEmitSignal = true);
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and bool processHotKey (const QKeySequence &key, QMenuData *data);
b43f840409794ed298e8634f6284741f193b6c4ftakashi void updateModifiers (bool fNumLock, bool fCapsLock, bool fScrollLock);
6ae232055d4d8a97267517c5e50074c2c819941and
bc9d4698fce0238d2f6f2682e99423ebb1149976rbowen void releaseAllPressedKeys (bool aReleaseHostKey = true);
6ae232055d4d8a97267517c5e50074c2c819941and void saveKeyStates();
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung void sendChangedKeyStates();
727872d18412fc021f03969b8641810d8896820bhumbedooh void updateMouseClipping();
0d0ba3a410038e179b695446bb149cce6264e0abnd
727872d18412fc021f03969b8641810d8896820bhumbedooh void setPointerShape (MousePointerChangeEvent *me);
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedooh
0d0ba3a410038e179b695446bb149cce6264e0abnd bool isPaused() { return mLastState == CEnums::Paused; }
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedooh bool isRunning() { return mLastState == CEnums::Running; }
727872d18412fc021f03969b8641810d8896820bhumbedooh
0d0ba3a410038e179b695446bb149cce6264e0abnd static void dimImage (QImage &img);
0d0ba3a410038e179b695446bb149cce6264e0abnd
0d0ba3a410038e179b695446bb149cce6264e0abndprivate slots:
ac082aefa89416cbdc9a1836eaf3bed9698201c8humbedooh
0d0ba3a410038e179b695446bb149cce6264e0abnd void doResizeHint (const QSize &aSize = QSize());
0d0ba3a410038e179b695446bb149cce6264e0abnd
0d0ba3a410038e179b695446bb149cce6264e0abndprivate:
727872d18412fc021f03969b8641810d8896820bhumbedooh
0d0ba3a410038e179b695446bb149cce6264e0abnd void maybeRestrictMinimumSize();
0d0ba3a410038e179b695446bb149cce6264e0abnd
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh VBoxConsoleWnd *mMainWnd;
205f749042ed530040a4f0080dbcb47ceae8a374rjung
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen CConsole mConsole;
0d0ba3a410038e179b695446bb149cce6264e0abnd
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd const VBoxGlobalSettings &gs;
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd CEnums::MachineState mLastState;
6ae232055d4d8a97267517c5e50074c2c819941and
bool mAttached : 1;
bool mKbdCaptured : 1;
bool mMouseCaptured : 1;
bool mMouseAbsolute : 1;
bool mMouseIntegration : 1;
QPoint mLastPos;
QPoint mCapturedPos;
bool mDisableAutoCapture : 1;
enum { IsKeyPressed = 0x01, IsExtKeyPressed = 0x02, IsKbdCaptured = 0x80 };
uint8_t mPressedKeys [128];
uint8_t mPressedKeysCopy [128];
bool mIsHostkeyPressed : 1;
bool mIsHostkeyAlone : 1;
/** mKbdCaptured value during the the last host key press or release */
bool hostkey_in_capture : 1;
bool mIgnoreMainwndResize : 1;
bool mAutoresizeGuest : 1;
bool mIsAdditionsActive : 1;
bool mNumLock : 1;
bool mScrollLock : 1;
bool mCapsLock : 1;
long muNumLockAdaptionCnt;
long muCapsLockAdaptionCnt;
QTimer *resize_hint_timer;
QTimer *mToggleFSModeTimer;
VBoxDefs::RenderMode mode;
QRegion mLastVisibleRegion;
QSize mNormalSize;
#if defined(Q_WS_WIN)
HCURSOR mAlphaCursor;
#endif
#if defined(Q_WS_MAC)
# ifndef VBOX_WITH_HACKED_QT
/** Event handler reference. NULL if the handler isn't installed. */
EventHandlerRef mDarwinEventHandlerRef;
# endif
/** The current modifier key mask. Used to figure out which modifier
* key was pressed when we get a kEventRawKeyModifiersChanged event. */
UInt32 mDarwinKeyModifiers;
/** The darwin cursor handle (see DarwinCursor.h/.cpp). */
DARWINCURSOR mDarwinCursor;
#endif
#if defined (VBOX_GUI_USE_REFRESH_TIMER)
QPixmap pm;
int tid; /**< Timer id */
#endif
VBoxFrameBuffer *mFrameBuf;
CConsoleCallback mCallback;
friend class VBoxConsoleCallback;
#if defined (Q_WS_WIN32)
static LRESULT CALLBACK lowLevelKeyboardProc (int nCode,
WPARAM wParam, LPARAM lParam);
#elif defined (Q_WS_MAC)
# ifndef VBOX_WITH_HACKED_QT
static pascal OSStatus darwinEventHandlerProc (EventHandlerCallRef inHandlerCallRef,
EventRef inEvent, void *inUserData);
# else /* VBOX_WITH_HACKED_QT */
static bool macEventFilter (EventRef inEvent, void *inUserData);
# endif /* VBOX_WITH_HACKED_QT */
#endif
QPixmap mPausedShot;
};
#endif // __VBoxConsoleView_h__