Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIKeyboardHandlerScale.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIKeyboardHandlerScale.cpp	(revision 30848)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIKeyboardHandlerScale.cpp	(revision 30848)
@@ -0,0 +1,78 @@
+/* $Id$ */
+/** @file
+ *
+ * VBox frontends: Qt GUI ("VirtualBox"):
+ * UIKeyboardHandlerScale class implementation
+ */
+
+/*
+ * Copyright (C) 2010 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ */
+
+/* Global includes */
+#include <QKeyEvent>
+#include <QTimer>
+#include <QWidget>
+
+/* Local includes */
+#include "UIKeyboardHandlerScale.h"
+#include "UIMachineWindow.h"
+
+/* Fullscreen keyboard-handler constructor: */
+UIKeyboardHandlerScale::UIKeyboardHandlerScale(UIMachineLogic* pMachineLogic)
+    : UIKeyboardHandler(pMachineLogic)
+{
+}
+
+/* Fullscreen keyboard-handler destructor: */
+UIKeyboardHandlerScale::~UIKeyboardHandlerScale()
+{
+}
+
+/* Event handler for prepared listener(s): */
+bool UIKeyboardHandlerScale::eventFilter(QObject *pWatchedObject, QEvent *pEvent)
+{
+    /* Check if pWatchedObject object is view: */
+    if (UIMachineView *pWatchedView = isItListenedView(pWatchedObject))
+    {
+        /* Get corresponding screen index: */
+        ulong uScreenId = m_views.key(pWatchedView);
+        NOREF(uScreenId);
+        /* Handle view events: */
+        switch (pEvent->type())
+        {
+#ifndef Q_WS_MAC
+            /* We don't want this on the Mac, cause there the menu bar isn't within the window
+             * and popping up a menu there looks really ugly. */
+            case QEvent::KeyPress:
+            {
+                /* Get key-event: */
+                QKeyEvent *pKeyEvent = static_cast<QKeyEvent*>(pEvent);
+                /* Process Host+Home for menu popup: */
+                if (isHostKeyPressed() && pKeyEvent->key() == Qt::Key_Home)
+                {
+                    /* Post request to show popup-menu: */
+                    QTimer::singleShot(0, m_windows[uScreenId]->machineWindow(), SLOT(sltPopupMainMenu()));
+                    /* Filter-out this event: */
+                    return true;
+                }
+                break;
+            }
+#endif /* !Q_WS_MAC */
+            default:
+                break;
+        }
+    }
+
+    /* Else just propagate to base-class: */
+    return UIKeyboardHandler::eventFilter(pWatchedObject, pEvent);
+}
+
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIKeyboardHandlerScale.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIKeyboardHandlerScale.h	(revision 30848)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIKeyboardHandlerScale.h	(revision 30848)
@@ -0,0 +1,45 @@
+/** @file
+ *
+ * VBox frontends: Qt GUI ("VirtualBox"):
+ * UIKeyboardHandlerScale class declaration
+ */
+
+/*
+ * Copyright (C) 2010 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ */
+
+#ifndef ___UIKeyboardHandlerScale_h___
+#define ___UIKeyboardHandlerScale_h___
+
+/* Local includes */
+#include "UIKeyboardHandler.h"
+
+class UIKeyboardHandlerScale : public UIKeyboardHandler
+{
+    Q_OBJECT;
+
+protected:
+
+    /* Fullscreen keyboard-handler constructor/destructor: */
+    UIKeyboardHandlerScale(UIMachineLogic *pMachineLogic);
+    virtual ~UIKeyboardHandlerScale();
+
+private:
+
+    /* Event handlers: */
+    bool eventFilter(QObject *pWatched, QEvent *pEvent);
+
+    /* Friend classes: */
+    friend class UIKeyboardHandler;
+};
+
+#endif // !___UIKeyboardHandlerScale_h___
+
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineLogicScale.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineLogicScale.cpp	(revision 30848)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineLogicScale.cpp	(revision 30848)
@@ -0,0 +1,154 @@
+/* $Id$ */
+/** @file
+ *
+ * VBox frontends: Qt GUI ("VirtualBox"):
+ * UIMachineLogicScale class implementation
+ */
+
+/*
+ * Copyright (C) 2010 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ */
+
+/* Local includes */
+#include "COMDefs.h"
+#include "VBoxGlobal.h"
+#include "VBoxProblemReporter.h"
+
+#include "UISession.h"
+#include "UIActionsPool.h"
+#include "UIMachineLogicScale.h"
+#include "UIMachineWindow.h"
+#include "UIDownloaderAdditions.h"
+
+#ifdef Q_WS_MAC
+#include "VBoxUtils.h"
+#endif /* Q_WS_MAC */
+
+UIMachineLogicScale::UIMachineLogicScale(QObject *pParent, UISession *pSession, UIActionsPool *pActionsPool)
+    : UIMachineLogic(pParent, pSession, pActionsPool, UIVisualStateType_Scale)
+{
+}
+
+UIMachineLogicScale::~UIMachineLogicScale()
+{
+#ifdef Q_WS_MAC
+    /* Cleanup the dock stuff before the machine window(s): */
+    cleanupDock();
+#endif /* Q_WS_MAC */
+
+    /* Cleanup machine window(s): */
+    cleanupMachineWindow();
+
+    /* Cleanup handlers: */
+    cleanupHandlers();
+}
+
+void UIMachineLogicScale::initialize()
+{
+    /* Prepare required features: */
+    prepareRequiredFeatures();
+
+    /* Prepare session connections: */
+    prepareSessionConnections();
+
+    /* Prepare action groups:
+     * Note: This has to be done before prepareActionConnections
+     * cause here actions/menus are recreated. */
+    prepareActionGroups();
+
+    /* Prepare action connections: */
+    prepareActionConnections();
+
+    /* Prepare handlers: */
+    prepareHandlers();
+
+    /* Prepare scale machine window: */
+    prepareMachineWindows();
+
+    /* If there is an Additions download running, update the parent window
+     * information. */
+    if (UIDownloaderAdditions *pDl = UIDownloaderAdditions::current())
+        pDl->setParentWidget(mainMachineWindow()->machineWindow());
+
+#ifdef Q_WS_MAC
+    /* Prepare dock: */
+    prepareDock();
+#endif /* Q_WS_MAC */
+
+    /* Power up machine: */
+    uisession()->powerUp();
+
+    /* Initialization: */
+    sltMachineStateChanged();
+    sltAdditionsStateChanged();
+    sltMouseCapabilityChanged();
+
+    /* Retranslate logic part: */
+    retranslateUi();
+}
+
+void UIMachineLogicScale::prepareActionGroups()
+{
+    /* Base class action groups: */
+    UIMachineLogic::prepareActionGroups();
+
+    /* Guest auto-resize isn't allowed in scale-mode: */
+    actionsPool()->action(UIActionIndex_Toggle_GuestAutoresize)->setVisible(false);
+
+    /* Adjust-window isn't allowed in scale-mode: */
+    actionsPool()->action(UIActionIndex_Simple_AdjustWindow)->setVisible(false);
+}
+
+void UIMachineLogicScale::prepareMachineWindows()
+{
+    /* Do not create window(s) if they created already: */
+    if (isMachineWindowsCreated())
+        return;
+
+#ifdef Q_WS_MAC // TODO: Is that really need here?
+    /* We have to make sure that we are getting the front most process.
+     * This is necessary for Qt versions > 4.3.3: */
+    ::darwinSetFrontMostProcess();
+#endif /* Q_WS_MAC */
+
+    /* Get monitors count: */
+    ulong uMonitorCount = session().GetMachine().GetMonitorCount();
+    /* Create machine window(s): */
+    for (ulong uScreenId = 0; uScreenId < uMonitorCount; ++ uScreenId)
+        addMachineWindow(UIMachineWindow::create(this, visualStateType(), uScreenId));
+    /* Order machine window(s): */
+    for (ulong uScreenId = uMonitorCount; uScreenId > 0; -- uScreenId)
+        machineWindows()[uScreenId - 1]->machineWindow()->raise();
+
+    /* Remember what machine window(s) created: */
+    setMachineWindowsCreated(true);
+}
+
+void UIMachineLogicScale::cleanupMachineWindow()
+{
+    /* Do not cleanup machine window(s) if not present: */
+    if (!isMachineWindowsCreated())
+        return;
+
+    /* Cleanup machine window(s): */
+    foreach (UIMachineWindow *pMachineWindow, machineWindows())
+        UIMachineWindow::destroy(pMachineWindow);
+}
+
+void UIMachineLogicScale::cleanupActionGroups()
+{
+    /* Reenable guest-autoresize action: */
+    actionsPool()->action(UIActionIndex_Toggle_GuestAutoresize)->setVisible(true);
+
+    /* Reenable adjust-window action: */
+    actionsPool()->action(UIActionIndex_Simple_AdjustWindow)->setVisible(true);
+}
+
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineLogicScale.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineLogicScale.h	(revision 30848)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineLogicScale.h	(revision 30848)
@@ -0,0 +1,57 @@
+/** @file
+ *
+ * VBox frontends: Qt GUI ("VirtualBox"):
+ * UIMachineLogicScale class declaration
+ */
+
+/*
+ * Copyright (C) 2010 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ */
+
+#ifndef __UIMachineLogicScale_h__
+#define __UIMachineLogicScale_h__
+
+/* Local includes */
+#include "UIMachineLogic.h"
+
+/* Local forwards */
+class UIActionsPool;
+
+class UIMachineLogicScale : public UIMachineLogic
+{
+    Q_OBJECT;
+
+protected:
+
+    /* Scale machine logic constructor/destructor: */
+    UIMachineLogicScale(QObject *pParent,
+                        UISession *pSession,
+                        UIActionsPool *pActionsPool);
+    virtual ~UIMachineLogicScale();
+
+    void initialize();
+
+private:
+
+    /* Prepare helpers: */
+    void prepareActionGroups();
+    void prepareMachineWindows();
+
+    /* Cleanup helpers: */
+    void cleanupMachineWindow();
+    void cleanupActionGroups();
+
+    /* Friend classes: */
+    friend class UIMachineLogic;
+};
+
+#endif // __UIMachineLogicScale_h__
+
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineViewScale.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineViewScale.cpp	(revision 30848)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineViewScale.cpp	(revision 30848)
@@ -0,0 +1,331 @@
+/* $Id$ */
+/** @file
+ *
+ * VBox frontends: Qt GUI ("VirtualBox"):
+ * UIMachineViewScale class implementation
+ */
+
+/*
+ * Copyright (C) 2010 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ */
+
+/* Global includes */
+#include <QDesktopWidget>
+#include <QMainWindow>
+#include <QTimer>
+
+/* Local includes */
+#include "VBoxGlobal.h"
+#include "UISession.h"
+#include "UIMachineLogic.h"
+#include "UIMachineWindow.h"
+#include "UIMachineViewScale.h"
+#include "UIFrameBuffer.h"
+#include "UIFrameBufferQImage.h"
+
+UIMachineViewScale::UIMachineViewScale(  UIMachineWindow *pMachineWindow
+                                       , ulong uScreenId
+#ifdef VBOX_WITH_VIDEOHWACCEL
+                                       , bool bAccelerate2DVideo
+#endif
+                                       )
+    : UIMachineView(  pMachineWindow
+                    , uScreenId
+#ifdef VBOX_WITH_VIDEOHWACCEL
+                    , bAccelerate2DVideo
+#endif
+                    )
+    , m_fShouldWeDoScale(false)
+{
+    /* Load machine view settings: */
+    loadMachineViewSettings();
+
+    /* Prepare viewport: */
+    prepareViewport();
+
+    /* Prepare frame buffer: */
+    prepareFrameBuffer();
+
+    /* Prepare common things: */
+    prepareCommon();
+
+    /* Prepare event-filters: */
+    prepareFilters();
+
+    /* Prepare connections: */
+    prepareConnections();
+
+    /* Prepare console connections: */
+    prepareConsoleConnections();
+
+    /* Initialization: */
+    sltMachineStateChanged();
+}
+
+UIMachineViewScale::~UIMachineViewScale()
+{
+    /* Save machine view settings: */
+    saveMachineViewSettings();
+
+    /* Cleanup frame buffer: */
+    cleanupFrameBuffer();
+}
+
+void UIMachineViewScale::sltMachineStateChanged()
+{
+    /* Base-class processing: */
+    UIMachineView::sltMachineStateChanged();
+
+    /* Get machine state: */
+    KMachineState state = uisession()->machineState();
+    switch (state)
+    {
+        case KMachineState_Paused:
+        case KMachineState_TeleportingPausedVM:
+        {
+            /* Scale stored pause-shot, it will be repainted on the next event-processing step: */
+            m_pauseShot = m_pauseShot.scaled(frameBuffer()->scaledSize(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
+            break;
+        }
+        default:
+            break;
+    }
+}
+
+void UIMachineViewScale::sltPerformGuestScale()
+{
+    /* Check if scale is requested: */
+    if (!m_fShouldWeDoScale)
+        return;
+
+    /* Set new frame-buffer scale-factor: */
+    frameBuffer()->setScaledSize(viewport()->size());
+
+    /* Update viewport: */
+    viewport()->repaint();
+
+    /* Update machine-view sliders: */
+    updateSliders();
+
+    /* Set request reflector to 'false' after scaling is done: */
+    m_fShouldWeDoScale = false;
+}
+
+void UIMachineViewScale::sltDesktopResized()
+{
+    /* If the desktop geometry is set automatically, this will update it: */
+    calculateDesktopGeometry();
+}
+
+bool UIMachineViewScale::event(QEvent *pEvent)
+{
+    switch (pEvent->type())
+    {
+        case VBoxDefs::ResizeEventType:
+        {
+            /* Some situations require framebuffer resize events to be ignored at all,
+             * leaving machine-window, machine-view and framebuffer sizes preserved: */
+            if (uisession()->isGuestResizeIgnored())
+                return true;
+
+            /* We are starting to perform machine-view resize: */
+            bool oldIgnoreMainwndResize = isMachineWindowResizeIgnored();
+            setMachineWindowResizeIgnored(true);
+
+            /* Get guest resize-event: */
+            UIResizeEvent *pResizeEvent = static_cast<UIResizeEvent*>(pEvent);
+
+            /* Perform framebuffer resize: */
+            frameBuffer()->setScaledSize(size());
+            frameBuffer()->resizeEvent(pResizeEvent);
+
+            /* Store the new size to prevent unwanted resize hints being sent back: */
+            storeConsoleSize(pResizeEvent->width(), pResizeEvent->height());
+
+            /* Let our toplevel widget calculate its sizeHint properly. */
+#ifdef Q_WS_X11
+            /* We use processEvents rather than sendPostedEvents & set the time out value to max cause on X11 otherwise
+             * the layout isn't calculated correctly. Dosn't find the bug in Qt, but this could be triggered through
+             * the async nature of the X11 window event system. */
+            QCoreApplication::processEvents(QEventLoop::AllEvents, INT_MAX);
+#else /* Q_WS_X11 */
+            QCoreApplication::sendPostedEvents(0, QEvent::LayoutRequest);
+#endif /* Q_WS_X11 */
+
+#ifdef Q_WS_MAC
+            machineLogic()->updateDockIconSize(screenId(), pResizeEvent->width(), pResizeEvent->height());
+#endif /* Q_WS_MAC */
+
+            /* Report to the VM thread that we finished resizing */
+            session().GetConsole().GetDisplay().ResizeCompleted(screenId());
+
+            /* We are finishing to perform machine-view resize: */
+            setMachineWindowResizeIgnored(oldIgnoreMainwndResize);
+
+            /* Make sure that all posted signals are processed: */
+            qApp->processEvents();
+
+            /* We also recalculate the desktop geometry if this is determined
+             * automatically.  In fact, we only need this on the first resize,
+             * but it is done every time to keep the code simpler. */
+            calculateDesktopGeometry();
+
+            /* Emit a signal about guest was resized: */
+            emit resizeHintDone();
+
+            return true;
+        }
+
+        case VBoxDefs::RepaintEventType:
+        {
+            UIRepaintEvent *pPaintEvent = static_cast<UIRepaintEvent*>(pEvent);
+            QSize scaledSize = frameBuffer()->scaledSize();
+            double xRatio = (double)scaledSize.width() / frameBuffer()->width();
+            double yRatio = (double)scaledSize.height() / frameBuffer()->height();
+            AssertMsg(contentsX() == 0, ("Thats can't be, else notify Dsen!\n"));
+            AssertMsg(contentsY() == 0, ("Thats can't be, else notify Dsen!\n"));
+            viewport()->repaint((pPaintEvent->x() - 10 /* 10 pixels left to cover xRatio*10 */) * xRatio,
+                                (pPaintEvent->y() - 10 /* 10 pixels left to cover yRatio*10 */) * yRatio,
+                                (pPaintEvent->width() + 10 /* 10 pixels right to cover x shift */ + 10 /* 10 pixels right to cover xRatio*10 */) * xRatio,
+                                (pPaintEvent->height() + 10 /* 10 pixels right to cover y shift */ + 10 /* 10 pixels right to cover yRatio*10 */) * yRatio);
+
+            return true;
+        }
+
+        default:
+            break;
+    }
+    return UIMachineView::event(pEvent);
+}
+
+bool UIMachineViewScale::eventFilter(QObject *pWatched, QEvent *pEvent)
+{
+    /* Who are we watching? */
+    QMainWindow *pMainDialog = machineWindowWrapper() && machineWindowWrapper()->machineWindow() ?
+                               qobject_cast<QMainWindow*>(machineWindowWrapper()->machineWindow()) : 0;
+
+    if (pWatched != 0 && pWatched == pMainDialog)
+    {
+        switch (pEvent->type())
+        {
+            case QEvent::Resize:
+            {
+                /* Set the "guest needs to resize" hint.
+                 * This hint is acted upon when (and only when) the autoresize property is "true": */
+                m_fShouldWeDoScale = true;
+                QTimer::singleShot(300, this, SLOT(sltPerformGuestScale()));
+                break;
+            }
+#if defined (Q_WS_WIN32)
+# if defined (VBOX_GUI_USE_DDRAW)
+            case QEvent::Move:
+            {
+                /* Notification from our parent that it has moved. We need this in order
+                 * to possibly adjust the direct screen blitting: */
+                if (frameBuffer())
+                    frameBuffer()->moveEvent(static_cast<QMoveEvent*>(pEvent));
+                break;
+            }
+# endif /* defined (VBOX_GUI_USE_DDRAW) */
+#endif /* defined (Q_WS_WIN32) */
+            default:
+                break;
+        }
+    }
+
+    return UIMachineView::eventFilter(pWatched, pEvent);
+}
+
+void UIMachineViewScale::prepareFrameBuffer()
+{
+    /* That method is partial copy-paste of UIMachineView::prepareFrameBuffer()
+     * and its temporary here just because not all of our frame-buffers are currently supports scale-mode;
+     * When all of our frame-buffers will be supporting scale-mode, method will be removed!
+     * Here we are processing only these frame-buffer types, which knows scale-mode! */
+
+    /* Prepare frame-buffer depending on render-mode: */
+    switch (vboxGlobal().vmRenderMode())
+    {
+        default:
+#ifdef VBOX_GUI_USE_QIMAGE
+        case VBoxDefs::QImageMode:
+            m_pFrameBuffer = new UIFrameBufferQImage(this);
+            break;
+#endif /* VBOX_GUI_USE_QIMAGE */
+            AssertReleaseMsgFailed(("Scale-mode is currently NOT supporting that render-mode: %d\n", vboxGlobal().vmRenderMode()));
+            LogRel(("Scale-mode is currently NOT supporting that render-mode: %d\n", vboxGlobal().vmRenderMode()));
+            qApp->exit(1);
+            break;
+    }
+
+    /* If frame-buffer was prepared: */
+    if (m_pFrameBuffer)
+    {
+        /* Prepare display: */
+        CDisplay display = session().GetConsole().GetDisplay();
+        Assert(!display.isNull());
+        m_pFrameBuffer->AddRef();
+        display.SetFramebuffer(m_uScreenId, CFramebuffer(m_pFrameBuffer));
+    }
+}
+
+void UIMachineViewScale::prepareConnections()
+{
+    connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(sltDesktopResized()));
+}
+
+void UIMachineViewScale::saveMachineViewSettings()
+{
+    /* Store guest size hint: */
+    storeGuestSizeHint(QSize(frameBuffer()->width(), frameBuffer()->height()));
+}
+
+QSize UIMachineViewScale::sizeHint() const
+{
+    /* Base-class have its own thoughts about size-hint
+     * but scale-mode needs no size-hint to be set: */
+    return QSize();
+}
+
+QRect UIMachineViewScale::workingArea()
+{
+    return QApplication::desktop()->availableGeometry(this);
+}
+
+void UIMachineViewScale::calculateDesktopGeometry()
+{
+    /* This method should not get called until we have initially set up the desktop geometry type: */
+    Assert((desktopGeometryType() != DesktopGeo_Invalid));
+    /* If we are not doing automatic geometry calculation then there is nothing to do: */
+    if (desktopGeometryType() == DesktopGeo_Automatic)
+    {
+        /* The area taken up by the machine window on the desktop,
+         * including window frame, title, menu bar and status bar: */
+        QRect windowGeo = machineWindowWrapper()->machineWindow()->frameGeometry();
+        /* The area taken up by the machine central widget, so excluding all decorations: */
+        QRect centralWidgetGeo = static_cast<QMainWindow*>(machineWindowWrapper()->machineWindow())->centralWidget()->geometry();
+        /* To work out how big we can make the console window while still fitting on the desktop,
+         * we calculate workingArea() - (windowGeo - centralWidgetGeo).
+         * This works because the difference between machine window and machine central widget
+         * (or at least its width and height) is a constant. */
+        m_desktopGeometry = QSize(workingArea().width() - (windowGeo.width() - centralWidgetGeo.width()),
+                                  workingArea().height() - (windowGeo.height() - centralWidgetGeo.height()));
+    }
+}
+
+void UIMachineViewScale::updateSliders()
+{
+    if (horizontalScrollBarPolicy() != Qt::ScrollBarAlwaysOff)
+        setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+    if (verticalScrollBarPolicy() != Qt::ScrollBarAlwaysOff)
+        setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+}
+
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineViewScale.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineViewScale.h	(revision 30848)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineViewScale.h	(revision 30848)
@@ -0,0 +1,84 @@
+/** @file
+ *
+ * VBox frontends: Qt GUI ("VirtualBox"):
+ * UIMachineViewScale class declaration
+ */
+
+/*
+ * Copyright (C) 2010 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ */
+
+#ifndef ___UIMachineViewScale_h___
+#define ___UIMachineViewScale_h___
+
+/* Local includes */
+#include "UIMachineView.h"
+
+class UIMachineViewScale : public UIMachineView
+{
+    Q_OBJECT;
+
+protected:
+
+    /* Scale machine-view constructor: */
+    UIMachineViewScale(  UIMachineWindow *pMachineWindow
+                       , ulong uScreenId
+#ifdef VBOX_WITH_VIDEOHWACCEL
+                       , bool bAccelerate2DVideo
+#endif
+    );
+    /* Scale machine-view destructor: */
+    virtual ~UIMachineViewScale();
+
+private slots:
+
+    /* Console callback handlers: */
+    void sltMachineStateChanged();
+
+    /* Slot to perform guest resize: */
+    void sltPerformGuestScale();
+
+    /* Watch dog for desktop resizes: */
+    void sltDesktopResized();
+
+private:
+
+    /* Event handlers: */
+    bool event(QEvent *pEvent);
+    bool eventFilter(QObject *pWatched, QEvent *pEvent);
+
+    /* Prepare helpers: */
+    void prepareFrameBuffer();
+    void prepareConnections();
+    //void loadMachineViewSettings();
+
+    /* Cleanup helpers: */
+    void saveMachineViewSettings();
+    //void cleanupConnections() {}
+    //void cleanupFrameBuffer() {}
+
+    /* Private helpers: */
+    QSize sizeHint() const;
+    void normalizeGeometry(bool /* fAdjustPosition */) {}
+    QRect workingArea();
+    void calculateDesktopGeometry();
+    void maybeRestrictMinimumSize() {}
+    void updateSliders();
+
+    /* Private members: */
+    bool m_fShouldWeDoScale : 1;
+
+    /* Friend classes: */
+    friend class UIMachineView;
+};
+
+#endif // !___UIMachineViewScale_h___
+
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineWindowScale.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineWindowScale.cpp	(revision 30848)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineWindowScale.cpp	(revision 30848)
@@ -0,0 +1,307 @@
+/* $Id$ */
+/** @file
+ *
+ * VBox frontends: Qt GUI ("VirtualBox"):
+ * UIMachineWindowScale class implementation
+ */
+
+/*
+ * Copyright (C) 2010 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ */
+
+/* Global includes */
+#include <QDesktopWidget>
+#include <QMenuBar>
+#include <QTimer>
+#include <QContextMenuEvent>
+
+/* Local includes */
+#include "VBoxGlobal.h"
+#include "VBoxProblemReporter.h"
+#include "VBoxUtils.h"
+
+#include "UISession.h"
+#include "UIActionsPool.h"
+#include "UIMachineLogic.h"
+#include "UIMachineView.h"
+#include "UIMachineWindowScale.h"
+
+UIMachineWindowScale::UIMachineWindowScale(UIMachineLogic *pMachineLogic, ulong uScreenId)
+    : QIWithRetranslateUI2<QMainWindow>(0, Qt::Window)
+    , UIMachineWindow(pMachineLogic, uScreenId)
+    , m_pMainMenu(0)
+{
+    /* "This" is machine window: */
+    m_pMachineWindow = this;
+
+    /* Set the main window in VBoxGlobal */
+    if (uScreenId == 0)
+        vboxGlobal().setMainWindow(this);
+
+    /* Prepare window icon: */
+    prepareWindowIcon();
+
+    /* Prepare console connections: */
+    prepareConsoleConnections();
+
+    /* Prepare menu: */
+    prepareMenu();
+
+    /* Retranslate normal window finally: */
+    retranslateUi();
+
+    /* Prepare normal machine view container: */
+    prepareMachineViewContainer();
+
+    /* Prepare normal machine view: */
+    prepareMachineView();
+
+    /* Prepare handlers: */
+    prepareHandlers();
+
+    /* Load normal window settings: */
+    loadWindowSettings();
+
+    /* Update all the elements: */
+    updateAppearanceOf(UIVisualElement_AllStuff);
+
+    /* Show window: */
+    showSimple();
+}
+
+UIMachineWindowScale::~UIMachineWindowScale()
+{
+    /* Save normal window settings: */
+    saveWindowSettings();
+
+    /* Prepare handlers: */
+    cleanupHandlers();
+
+    /* Cleanup normal machine view: */
+    cleanupMachineView();
+}
+
+void UIMachineWindowScale::sltMachineStateChanged()
+{
+    UIMachineWindow::sltMachineStateChanged();
+}
+
+void UIMachineWindowScale::sltPopupMainMenu()
+{
+    /* Popup main menu if present: */
+    if (m_pMainMenu && !m_pMainMenu->isEmpty())
+    {
+        m_pMainMenu->popup(machineWindow()->geometry().center());
+        QTimer::singleShot(0, m_pMainMenu, SLOT(sltSelectFirstAction()));
+    }
+}
+
+void UIMachineWindowScale::sltTryClose()
+{
+    UIMachineWindow::sltTryClose();
+}
+
+void UIMachineWindowScale::retranslateUi()
+{
+    /* Translate parent class: */
+    UIMachineWindow::retranslateUi();
+}
+
+bool UIMachineWindowScale::event(QEvent *pEvent)
+{
+    switch (pEvent->type())
+    {
+        case QEvent::Resize:
+        {
+            QResizeEvent *pResizeEvent = static_cast<QResizeEvent*>(pEvent);
+            if (!isMaximizedChecked())
+            {
+                m_normalGeometry.setSize(pResizeEvent->size());
+#ifdef VBOX_WITH_DEBUGGER_GUI
+                /* Update debugger window position */
+                updateDbgWindows();
+#endif
+            }
+            break;
+        }
+        case QEvent::Move:
+        {
+            if (!isMaximizedChecked())
+            {
+                m_normalGeometry.moveTo(geometry().x(), geometry().y());
+#ifdef VBOX_WITH_DEBUGGER_GUI
+                /* Update debugger window position */
+                updateDbgWindows();
+#endif
+            }
+            break;
+        }
+        default:
+            break;
+    }
+    return QIWithRetranslateUI2<QMainWindow>::event(pEvent);
+}
+
+#ifdef Q_WS_X11
+bool UIMachineWindowScale::x11Event(XEvent *pEvent)
+{
+    return UIMachineWindow::x11Event(pEvent);
+}
+#endif
+
+void UIMachineWindowScale::closeEvent(QCloseEvent *pEvent)
+{
+    return UIMachineWindow::closeEvent(pEvent);
+}
+
+void UIMachineWindowScale::prepareMenu()
+{
+    /* No view menu in normal mode: */
+    m_pMainMenu = uisession()->newMenu(UIMainMenuType(UIMainMenuType_All ^ UIMainMenuType_View));
+}
+
+void UIMachineWindowScale::prepareMachineViewContainer()
+{
+    /* Call to base-class: */
+    UIMachineWindow::prepareMachineViewContainer();
+
+    /* Strict spacers to hide them, they are not necessary for scale-mode: */
+    m_pTopSpacer->changeSize(0, 0, QSizePolicy::Fixed, QSizePolicy::Fixed);
+    m_pBottomSpacer->changeSize(0, 0, QSizePolicy::Fixed, QSizePolicy::Fixed);
+    m_pLeftSpacer->changeSize(0, 0, QSizePolicy::Fixed, QSizePolicy::Fixed);
+    m_pRightSpacer->changeSize(0, 0, QSizePolicy::Fixed, QSizePolicy::Fixed);
+}
+
+void UIMachineWindowScale::prepareMachineView()
+{
+#ifdef VBOX_WITH_VIDEOHWACCEL
+    /* Need to force the QGL framebuffer in case 2D Video Acceleration is supported & enabled: */
+    bool bAccelerate2DVideo = session().GetMachine().GetAccelerate2DVideoEnabled() && VBoxGlobal::isAcceleration2DVideoAvailable();
+#endif
+
+    /* Set central widget: */
+    setCentralWidget(new QWidget);
+
+    /* Set central widget layout: */
+    centralWidget()->setLayout(m_pMachineViewContainer);
+
+    m_pMachineView = UIMachineView::create(  this
+                                           , m_uScreenId
+                                           , machineLogic()->visualStateType()
+#ifdef VBOX_WITH_VIDEOHWACCEL
+                                           , bAccelerate2DVideo
+#endif
+                                           );
+
+    /* Add machine view into layout: */
+    m_pMachineViewContainer->addWidget(m_pMachineView, 1, 1);
+}
+
+void UIMachineWindowScale::loadWindowSettings()
+{
+    /* Load scale window settings: */
+    CMachine machine = session().GetMachine();
+
+    /* Load extra-data settings: */
+    {
+        QString strPositionAddress = m_uScreenId == 0 ? QString("%1").arg(VBoxDefs::GUI_LastScaleWindowPosition) :
+                                     QString("%1%2").arg(VBoxDefs::GUI_LastScaleWindowPosition).arg(m_uScreenId);
+        QStringList strPositionSettings = machine.GetExtraDataStringList(strPositionAddress);
+
+        bool ok = true, max = false;
+        int x = 0, y = 0, w = 0, h = 0;
+        if (ok && strPositionSettings.size() > 0)
+            x = strPositionSettings[0].toInt(&ok);
+        if (ok && strPositionSettings.size() > 1)
+            y = strPositionSettings[1].toInt(&ok);
+        if (ok && strPositionSettings.size() > 2)
+            w = strPositionSettings[2].toInt(&ok);
+        if (ok && strPositionSettings.size() > 3)
+            h = strPositionSettings[3].toInt(&ok);
+        if (ok && strPositionSettings.size() > 4)
+            max = strPositionSettings[4] == VBoxDefs::GUI_LastWindowState_Max;
+
+        QRect ar = ok ? QApplication::desktop()->availableGeometry(QPoint(x, y)) :
+                        QApplication::desktop()->availableGeometry(machineWindow());
+
+        /* If previous parameters were read correctly: */
+        if (ok)
+        {
+            /* Restore window size and position: */
+            m_normalGeometry = QRect(x, y, w, h);
+            setGeometry(m_normalGeometry);
+            /* Maximize if needed: */
+            if (max)
+                setWindowState(windowState() | Qt::WindowMaximized);
+        }
+        else
+        {
+            /* Resize to default size: */
+            resize(640, 480);
+            qApp->processEvents();
+            /* Move newly created window to the screen center: */
+            m_normalGeometry = geometry();
+            m_normalGeometry.moveCenter(ar.center());
+            setGeometry(m_normalGeometry);
+        }
+    }
+}
+
+void UIMachineWindowScale::saveWindowSettings()
+{
+    CMachine machine = session().GetMachine();
+
+    /* Save extra-data settings: */
+    {
+        QString strWindowPosition = QString("%1,%2,%3,%4")
+                                    .arg(m_normalGeometry.x()).arg(m_normalGeometry.y())
+                                    .arg(m_normalGeometry.width()).arg(m_normalGeometry.height());
+        if (isMaximizedChecked())
+            strWindowPosition += QString(",%1").arg(VBoxDefs::GUI_LastWindowState_Max);
+        QString strPositionAddress = m_uScreenId == 0 ? QString("%1").arg(VBoxDefs::GUI_LastScaleWindowPosition) :
+                                     QString("%1%2").arg(VBoxDefs::GUI_LastScaleWindowPosition).arg(m_uScreenId);
+        machine.SetExtraData(strPositionAddress, strWindowPosition);
+    }
+}
+
+void UIMachineWindowScale::cleanupMachineView()
+{
+    /* Do not cleanup machine view if it is not present: */
+    if (!machineView())
+        return;
+
+    UIMachineView::destroy(m_pMachineView);
+    m_pMachineView = 0;
+}
+
+void UIMachineWindowScale::cleanupMenu()
+{
+    delete m_pMainMenu;
+    m_pMainMenu = 0;
+}
+
+void UIMachineWindowScale::showSimple()
+{
+    /* Just show window: */
+    show();
+}
+
+bool UIMachineWindowScale::isMaximizedChecked()
+{
+#ifdef Q_WS_MAC
+    /* On the Mac the WindowStateChange signal doesn't seems to be delivered
+     * when the user get out of the maximized state. So check this ourself. */
+    return ::darwinIsWindowMaximized(this);
+#else /* Q_WS_MAC */
+    return isMaximized();
+#endif /* !Q_WS_MAC */
+}
+
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineWindowScale.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineWindowScale.h	(revision 30848)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineWindowScale.h	(revision 30848)
@@ -0,0 +1,87 @@
+/** @file
+ *
+ * VBox frontends: Qt GUI ("VirtualBox"):
+ * UIMachineWindowScale class declaration
+ */
+
+/*
+ * Copyright (C) 2010 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ */
+
+#ifndef __UIMachineWindowScale_h__
+#define __UIMachineWindowScale_h__
+
+/* Global includes */
+#include <QMainWindow>
+
+/* Local includes */
+#include "QIWithRetranslateUI.h"
+#include "UIMachineWindow.h"
+
+class UIMachineWindowScale : public QIWithRetranslateUI2<QMainWindow>, public UIMachineWindow
+{
+    Q_OBJECT;
+
+protected:
+
+    /* Scale machine window constructor/destructor: */
+    UIMachineWindowScale(UIMachineLogic *pMachineLogic, ulong uScreenId);
+    virtual ~UIMachineWindowScale();
+
+private slots:
+
+    /* Console callback handlers: */
+    void sltMachineStateChanged();
+
+    /* Popup main menu: */
+    void sltPopupMainMenu();
+
+    /* Close window reimplementation: */
+    void sltTryClose();
+
+private:
+
+    /* Translate routine: */
+    void retranslateUi();
+
+    /* Event handlers: */
+    bool event(QEvent *pEvent);
+#ifdef Q_WS_X11
+    bool x11Event(XEvent *pEvent);
+#endif
+    void closeEvent(QCloseEvent *pEvent);
+
+    /* Prepare helpers: */
+    void prepareMenu();
+    void prepareMachineViewContainer();
+    void prepareMachineView();
+    void loadWindowSettings();
+
+    /* Cleanup helpers: */
+    void saveWindowSettings();
+    void cleanupMachineView();
+    //void cleanupMachineViewContainer() {}
+    void cleanupMenu();
+
+    /* Other members: */
+    void showSimple();
+    bool isMaximizedChecked();
+
+    /* Other members: */
+    QMenu *m_pMainMenu;
+    QRect m_normalGeometry;
+
+    /* Factory support: */
+    friend class UIMachineWindow;
+};
+
+#endif // __UIMachineWindowScale_h__
+
