VirtualBox

Ignore:
Timestamp:
Nov 19, 2010 12:27:13 PM (14 years ago)
Author:
vboxsync
Message:

FE/Qt4-OSX: some experiments

Location:
trunk/src/VBox/Frontends/VirtualBox/src/darwin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/darwin/VBoxUtils-darwin-cocoa.mm

    r30155 r34192  
    8484   CGImageRelease(pCGImage);
    8585   return pNSImage;
     86}
     87
     88NativeNSStringRef darwinToNativeString(const char* pcszString)
     89{
     90    return [NSString stringWithUTF8String: pcszString];
    8691}
    8792
     
    138143}
    139144
     145void darwinMinaturizeWindow(NativeNSWindowRef pWindow)
     146{
     147//    [[NSApplication sharedApplication] miniaturizeAll];
     148//    printf("bla\n");
     149//    [pWindow miniaturize:pWindow];
     150//    [[NSApplication sharedApplication] deactivate];
     151//    [pWindow performMiniaturize:nil];
     152}
     153
    140154void darwinSetDockIconMenu(QMenu* pMenu)
    141155{
     
    169183    windowFrame.origin.y -= h1;
    170184
    171     [pWindow setFrame:windowFrame display:YES animate:YES];
     185    [pWindow setFrame:windowFrame display:YES animate: YES];
     186}
     187
     188void darwinWindowAnimateResizeNewImpl(NativeNSWindowRef pWindow, int height, bool fAnimate)
     189{
     190    /* It seems that Qt doesn't return the height of the window with the
     191     * toolbar height included. So add this size manually. Could easily be that
     192     * the Trolls fix this in the final release. */
     193    NSToolbar *toolbar = [pWindow toolbar];
     194    NSRect windowFrame = [pWindow frame];
     195    int toolbarHeight = 0;
     196    if(toolbar && [toolbar isVisible])
     197        toolbarHeight = NSHeight(windowFrame) - NSHeight([[pWindow contentView] frame]);
     198    int h = height + toolbarHeight;
     199    int h1 = h - NSHeight(windowFrame);
     200    windowFrame.size.height = h;
     201    windowFrame.origin.y -= h1;
     202
     203    [pWindow setFrame:windowFrame display:YES animate: fAnimate ? YES : NO];
     204}
     205
     206void darwinTest(NativeNSViewRef pViewOld, NativeNSViewRef pViewNew, int h)
     207{
     208    NSMutableDictionary *pDicts[3] = { nil, nil, nil };
     209    int c = 0;
     210
     211    /* Scaling necessary? */
     212    if (h != -1)
     213    {
     214        NSWindow *pWindow  = [(pViewOld ? pViewOld : pViewNew) window];
     215        NSToolbar *toolbar = [pWindow toolbar];
     216        NSRect windowFrame = [pWindow frame];
     217        /* Dictionary containing all animation parameters. */
     218        pDicts[c] = [NSMutableDictionary dictionaryWithCapacity:2];
     219        /* Specify the animation target. */
     220        [pDicts[c] setObject:pWindow forKey:NSViewAnimationTargetKey];
     221        /* Scaling effect. */
     222        [pDicts[c] setObject:[NSValue valueWithRect:windowFrame] forKey:NSViewAnimationStartFrameKey];
     223        int toolbarHeight = 0;
     224        if(toolbar && [toolbar isVisible])
     225            toolbarHeight = NSHeight(windowFrame) - NSHeight([[pWindow contentView] frame]);
     226        int h1 = h + toolbarHeight;
     227        int h2 = h1 - NSHeight(windowFrame);
     228        windowFrame.size.height = h1;
     229        windowFrame.origin.y -= h2;
     230        [pDicts[c] setObject:[NSValue valueWithRect:windowFrame] forKey:NSViewAnimationEndFrameKey];
     231        ++c;
     232    }
     233    /* Fade out effect. */
     234    if (pViewOld)
     235    {
     236        /* Dictionary containing all animation parameters. */
     237        pDicts[c] = [NSMutableDictionary dictionaryWithCapacity:2];
     238        /* Specify the animation target. */
     239        [pDicts[c] setObject:pViewOld forKey:NSViewAnimationTargetKey];
     240        /* Fade out effect. */
     241        [pDicts[c] setObject:NSViewAnimationFadeOutEffect forKey:NSViewAnimationEffectKey];
     242        ++c;
     243    }
     244    /* Fade in effect. */
     245    if (pViewNew)
     246    {
     247        /* Dictionary containing all animation parameters. */
     248        pDicts[c] = [NSMutableDictionary dictionaryWithCapacity:2];
     249        /* Specify the animation target. */
     250        [pDicts[c] setObject:pViewNew forKey:NSViewAnimationTargetKey];
     251        /* Fade in effect. */
     252        [pDicts[c] setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
     253        ++c;
     254    }
     255    /* Create our animation object. */
     256    NSViewAnimation *pAni = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:pDicts count:c]];
     257    [pAni setDuration:.15];
     258    [pAni setAnimationCurve:NSAnimationEaseIn];
     259    [pAni setAnimationBlockingMode:NSAnimationBlocking];
     260//    [pAni setAnimationBlockingMode:NSAnimationNonblockingThreaded];
     261
     262    /* Run the animation. */
     263    [pAni startAnimation];
     264    /* Cleanup */
     265    [pAni release];
    172266}
    173267
     
    203297
    204298    return fResult;
     299}
     300
     301bool darwinShowFileInFinder(NativeNSStringRef pstrFile)
     302{
     303    return [[NSWorkspace sharedWorkspace] selectFile:pstrFile inFileViewerRootedAtPath:@""];
     304}
     305
     306bool darwinOpenFile(NativeNSStringRef pstrFile)
     307{
     308    return [[NSWorkspace sharedWorkspace] openFile:pstrFile];
    205309}
    206310
     
    252356    NSEventType  eEvtType = [pEvent type];
    253357    bool         fGlobalHotkey = false;
     358//
     359//    if (   (eEvtType == NSKeyDown || eEvtType == NSKeyUp)
     360//        && [[NSApp mainMenu] performKeyEquivalent:pEvent])
     361//        return true;
     362//    return false;
     363//        && [[[NSApp mainMenu] delegate] menuHasKeyEquivalent:[NSApp mainMenu] forEvent:pEvent target:b action:a])
    254364
    255365    switch (eEvtType)
     
    266376                    || KeyCode == 0x04) /* CMD+H (Hide) */
    267377                    fGlobalHotkey = true;
    268             } 
     378            }
    269379            else if (   ((fEvtMask & (NX_NONCOALSESCEDMASK | NX_ALTERNATEMASK | NX_DEVICELALTKEYMASK | NX_COMMANDMASK | NX_DEVICELCMDKEYMASK)) == (NX_NONCOALSESCEDMASK | NX_ALTERNATEMASK | NX_DEVICELALTKEYMASK | NX_COMMANDMASK | NX_DEVICELCMDKEYMASK)) /* L+ALT+CMD */
    270380                     || ((fEvtMask & (NX_NONCOALSESCEDMASK | NX_ALTERNATEMASK | NX_DEVICERCMDKEYMASK | NX_COMMANDMASK | NX_DEVICERCMDKEYMASK)) == (NX_NONCOALSESCEDMASK | NX_ALTERNATEMASK | NX_DEVICERCMDKEYMASK | NX_COMMANDMASK | NX_DEVICERCMDKEYMASK))) /* R+ALT+CMD */
     
    280390}
    281391
     392void darwinRetranslateAppMenu()
     393{
     394    /* This is purely Qt internal. If the Trolls change something here, it will
     395       not work anymore, but at least it will not be a burning man. */
     396    if ([NSApp respondsToSelector:@selector(qt_qcocoamenuLoader)])
     397    {
     398        id loader = [NSApp performSelector:@selector(qt_qcocoamenuLoader)];
     399        if ([loader respondsToSelector:@selector(qtTranslateApplicationMenu)])
     400            [loader performSelector:@selector(qtTranslateApplicationMenu)];
     401    }
     402}
     403
  • trunk/src/VBox/Frontends/VirtualBox/src/darwin/VBoxUtils-darwin.cpp

    r30151 r34192  
    3838NativeNSViewRef darwinToNativeView(QWidget *pWidget)
    3939{
    40     return reinterpret_cast<NativeNSViewRef>(pWidget->winId());
     40    if (pWidget)
     41        return reinterpret_cast<NativeNSViewRef>(pWidget->winId());
     42    return nil;
    4143}
    4244
    4345NativeNSWindowRef darwinToNativeWindow(QWidget *pWidget)
    4446{
    45     return ::darwinToNativeWindowImpl(::darwinToNativeView(pWidget));
     47    if (pWidget)
     48        return ::darwinToNativeWindowImpl(::darwinToNativeView(pWidget));
     49    return nil;
    4650}
    4751
     
    8185{
    8286    ::darwinWindowAnimateResizeImpl(::darwinToNativeWindow(pWidget), aTarget.x(), aTarget.y(), aTarget.width(), aTarget.height());
     87}
     88
     89void darwinWindowAnimateResizeNew(QWidget *pWidget, int h, bool fAnimate)
     90{
     91    ::darwinWindowAnimateResizeNewImpl(::darwinToNativeWindow(pWidget), h, fAnimate);
     92}
     93
     94void darwinTest(QWidget *pWidget1, QWidget *pWidget2, int h)
     95{
     96    ::darwinTest(::darwinToNativeView(pWidget1), ::darwinToNativeView(pWidget2), h);
    8397}
    8498
     
    116130    return false;
    117131#endif /* !QT_MAC_USE_COCOA */
     132}
     133
     134void darwinMinaturizeWindow(QWidget *pWidget)
     135{
     136    return ::darwinMinaturizeWindow(::darwinToNativeWindow(pWidget));
     137}
     138
     139bool darwinShowFileInFinder(const QString& strFile)
     140{
     141    return ::darwinShowFileInFinder(darwinToNativeString(strFile.toUtf8().constData()));
     142}
     143
     144bool darwinOpenFile(const QString& strFile)
     145{
     146    return ::darwinOpenFile(darwinToNativeString(strFile.toUtf8().constData()));
    118147}
    119148
  • trunk/src/VBox/Frontends/VirtualBox/src/darwin/VBoxUtils-darwin.h

    r31235 r34192  
    3131ADD_COCOA_NATIVE_REF(NSView);
    3232ADD_COCOA_NATIVE_REF(NSWindow);
     33ADD_COCOA_NATIVE_REF(NSString);
    3334
    3435class QImage;
     
    4849NativeNSWindowRef darwinToNativeWindowImpl(NativeNSViewRef pView);
    4950NativeNSViewRef darwinToNativeViewImpl(NativeNSWindowRef pWindow);
     51NativeNSStringRef darwinToNativeString(const char* pcszString);
    5052
    5153/********************************************************************************
     
    6062void darwinSetMouseCoalescingEnabled(bool fEnabled);
    6163
     64void darwintest(NativeNSWindowRef pWindow);
    6265/********************************************************************************
    6366 *
     
    6669 ********************************************************************************/
    6770void darwinWindowAnimateResizeImpl(NativeNSWindowRef pWindow, int x, int y, int width, int height);
     71void darwinWindowAnimateResizeNewImpl(NativeNSWindowRef pWindow, int height, bool fAnimate);
     72void darwinTest(NativeNSViewRef pView, NativeNSViewRef pView1, int h);
    6873void darwinWindowInvalidateShapeImpl(NativeNSWindowRef pWindow);
    6974void darwinWindowInvalidateShadowImpl(NativeNSWindowRef pWindow);
     
    7176bool darwinIsToolbarVisible(NativeNSWindowRef pWindow);
    7277bool darwinIsWindowMaximized(NativeNSWindowRef pWindow);
     78void darwinMinaturizeWindow(NativeNSWindowRef pWindow);
     79
     80bool darwinShowFileInFinder(NativeNSStringRef pstrFile);
     81bool darwinOpenFile(NativeNSStringRef pstrFile);
    7382
    7483float darwinSmallFontSize();
     
    8089
    8190bool darwinIsApplicationCommand(ConstNativeNSEventRef pEvent);
     91
     92void darwinRetranslateAppMenu();
    8293
    8394RT_C_DECLS_END
     
    168179void darwinDisableIconsInMenus(void);
    169180
     181void darwinTest(QWidget *pWidget1, QWidget *pWidget2, int h);
     182
    170183/********************************************************************************
    171184 *
     
    174187 ********************************************************************************/
    175188void darwinWindowAnimateResize(QWidget *pWidget, const QRect &aTarget);
     189void darwinWindowAnimateResizeNew(QWidget *pWidget, int h, bool fAnimate);
    176190void darwinWindowInvalidateShape(QWidget *pWidget);
    177191void darwinWindowInvalidateShadow(QWidget *pWidget);
     
    179193bool darwinIsToolbarVisible(QToolBar *pToolBar);
    180194bool darwinIsWindowMaximized(QWidget *pWidget);
     195void darwinMinaturizeWindow(QWidget *pWidget);
     196
     197bool darwinShowFileInFinder(const QString &strFile);
     198bool darwinOpenFile(const QString &strFile);
     199
    181200QString darwinSystemLanguage(void);
    182201QPixmap darwinCreateDragPixmap(const QPixmap& aPixmap, const QString &aText);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette