Пример #1
0
void _HYPlatformGraphicPane::_SetDialogBG (void)
{
	if (aquaInterfaceOn)
		SetThemeBackground (kThemeBrushDialogBackgroundActive, 32, true);
	else
		((_HYGraphicPane*)this)->SetBColor		   (GetDialogBackgroundColor());
}
Пример #2
0
// --------------------------------------------------------------------------------------
void HandleContentClick(WindowRef window, Point mouseLocation, EventModifiers modifiers)
{
    ListHandle iconList;
    Rect iconListRect;
    Boolean isDoubleClick;
    Cell theCell;

    GetWindowProperty(window, kAppSignature, kIconListTag, sizeof(ListHandle), NULL,
                      &iconList);

    GetListViewBounds(iconList, &iconListRect);

    iconListRect.right += kScrollBarWidth;

    SetPortWindowPort(window);
    GlobalToLocal(&mouseLocation);

    if (PtInRect(mouseLocation, &iconListRect))
    {
        SInt16 pixelDepth;
        Boolean isColorDevice;

        GetWindowDeviceDepthAndColor(window, &pixelDepth, &isColorDevice);
        SetThemeBackground(kThemeBrushWhite, pixelDepth, isColorDevice);
        // if LClick causes the list selection to change, or the
        isDoubleClick = LClick(mouseLocation, modifiers, iconList);		// scroll bar
        SetPt(&theCell, 0, 0);					// to change, the affected cells are
        LGetSelect(true, &theCell, iconList);	// immediately drawn (no update event)

        if ((theCell.v + 1) != gPanelNumber)
            changePanel(window, theCell.v + 1);
    }
}
Пример #3
0
// --------------------------------------------------------------------------------------
void HandleDrawContent(WindowRef prefsWindow)
{
    RgnHandle visibleRegion;
    ListHandle iconList;

    GetWindowProperty(prefsWindow, kAppSignature, kIconListTag, sizeof(ListHandle), NULL,
                      &iconList);

    visibleRegion = NewRgn();
    GetPortVisibleRegion(GetWindowPort(prefsWindow), visibleRegion);

    if (visibleRegion != NULL)
    {
        Boolean active = IsWindowHilited(prefsWindow);
        SInt16 pixelDepth;
        Boolean isColorDevice;

        if (active)
            SetThemeWindowBackground(prefsWindow, kThemeBrushModelessDialogBackgroundActive,
                                     false);
        else
            SetThemeWindowBackground(prefsWindow,
                                     kThemeBrushModelessDialogBackgroundInactive, false);

        EraseRgn(visibleRegion);
        UpdateControls(prefsWindow, visibleRegion);

        GetWindowDeviceDepthAndColor(prefsWindow, &pixelDepth, &isColorDevice);
        SetThemeBackground(kThemeBrushWhite, pixelDepth, isColorDevice);
        LUpdate(visibleRegion, iconList);
        drawFrameAndFocus(iconList, active, prefsWindow);
        DisposeRgn(visibleRegion);
    }
}
Пример #4
0
// --------------------------------------------------------------------------------------
void  HandleActivate(WindowRef window, Boolean activate)
{
    ControlRef rootControl;
    ListHandle iconList;
    SInt16 pixelDepth;
    Boolean isColorDevice;

    GetRootControl(window, &rootControl);
    GetWindowProperty(window, kAppSignature, kIconListTag, sizeof(ListHandle), NULL, &iconList);

    SetPortWindowPort(window);
    GetWindowDeviceDepthAndColor(window, &pixelDepth, &isColorDevice);

    if (activate)
    {
        SetThemeTextColor(kThemeTextColorModelessDialogActive, pixelDepth, isColorDevice);
        ActivateControl(rootControl);

        SetThemeBackground(kThemeBrushWhite, pixelDepth, isColorDevice);
        LActivate(true, iconList);
        RedrawPrefsWindowList(window);	// redraw the list with the active appearance
        drawFrameAndFocus(iconList, true, window);

        EnableMenuItem(GetMenuRef(mFile), iClose);
    }
    else	// deactivate
    {
        SetThemeTextColor(kThemeTextColorModelessDialogInactive, pixelDepth, isColorDevice);
        DeactivateControl(rootControl);

        SetThemeBackground(kThemeBrushWhite, pixelDepth, isColorDevice);
        LActivate(false, iconList);
        RedrawPrefsWindowList(window);	// redraw the  list with the inactive appearance
        drawFrameAndFocus(iconList, false, window);

        DisableMenuItem(GetMenuRef(mFile), iClose);
    }
}
Пример #5
0
// --------------------------------------------------------------------------------------
void RedrawPrefsWindowList(WindowRef prefsWindow)
{
    ListHandle iconList;
    ListBounds visibleCells;
    SInt16 pixelDepth;
    Boolean isColorDevice;
    short row;
    Cell theCell;

    GetWindowProperty(prefsWindow, kAppSignature, kIconListTag, sizeof(ListHandle), NULL,
                      &iconList);
    GetListVisibleCells(iconList, &visibleCells);

    GetWindowDeviceDepthAndColor(prefsWindow, &pixelDepth, &isColorDevice);
    SetThemeBackground(kThemeBrushWhite, pixelDepth, isColorDevice);

    for (row = visibleCells.top; row < visibleCells.bottom; row++)	// redraw just the
    {   // visible cells
        SetPt(&theCell, 0, row);
        LDraw(theCell, iconList);
    }
}
Пример #6
0
// --------------------------------------------------------------------------------------
void HandleKeyDown(char keyCode, WindowRef prefsWindow)
{
    /* Why use the virtual key code instead of the character code?  When the control
       key is held down it often masks out bit 7 of the character code, thus making
       it impossible to distinguish between some key presses such as page down
       (0x0C) and control-L (0x4C & ~bit7 = 0x0C).  The virtual key codes, on the
       other hand, are unaffected by modifier keys. */
    if ( (keyCode == kUpArrowKeyCode) || (keyCode == kDownArrowKeyCode) )
    {
        ListHandle iconList;
        ListBounds bounds;
        short lastRow;
        Cell selectedCell;

        GetWindowProperty(prefsWindow, kAppSignature, kIconListTag, sizeof(ListHandle), NULL,
                          &iconList);
        GetListDataBounds(iconList, &bounds);
        lastRow = bounds.bottom - bounds.top - 1;

        SetPt(&selectedCell, 0, 0);
        LGetSelect(true, &selectedCell, iconList);

        if ( (keyCode == kUpArrowKeyCode) && (selectedCell.v > 0) )
        {
            SInt16 pixelDepth;
            Boolean isColorDevice;

            GetWindowDeviceDepthAndColor(prefsWindow, &pixelDepth, &isColorDevice);
            SetThemeBackground(kThemeBrushWhite, pixelDepth, isColorDevice);

            LSetSelect(false, selectedCell, iconList);	// LSetSelect causes the indicated
            selectedCell.v--;	// cell to be highlighted immediately (no update event)
            LSetSelect(true, selectedCell, iconList);

            LAutoScroll(iconList);	// scroll the list in case the selected cell isn't in view
            changePanel(prefsWindow, selectedCell.v + 1);
        }
        else if ( (keyCode == kDownArrowKeyCode) && (selectedCell.v < lastRow) )
        {
            SInt16 pixelDepth;
            Boolean isColorDevice;

            GetWindowDeviceDepthAndColor(prefsWindow, &pixelDepth, &isColorDevice);
            SetThemeBackground(kThemeBrushWhite, pixelDepth, isColorDevice);

            LSetSelect(false, selectedCell, iconList);
            selectedCell.v++;
            LSetSelect(true, selectedCell, iconList);

            LAutoScroll(iconList);	// scroll the list in case the selected cell isn't in view
            changePanel(prefsWindow, selectedCell.v + 1);
        }
    }
    else if ( (keyCode == kPageUpKeyCode) || (keyCode == kPageDownKeyCode) )
    {
        ListHandle iconList;
        ListBounds visibleCells;
        SInt16 pixelDepth;
        Boolean isColorDevice;

        GetWindowProperty(prefsWindow, kAppSignature, kIconListTag, sizeof(ListHandle), NULL,
                          &iconList);
        GetListVisibleCells(iconList, &visibleCells);

        GetWindowDeviceDepthAndColor(prefsWindow, &pixelDepth, &isColorDevice);
        SetThemeBackground(kThemeBrushWhite, pixelDepth, isColorDevice);
        // LScroll causes the affected cells to be drawn immediately
        if (keyCode == kPageUpKeyCode)								// (no update event)
            LScroll(0, -(visibleCells.bottom - 1 - visibleCells.top), iconList);
        else	// keyCode == kPageDownKeyCode
            LScroll(0, (visibleCells.bottom - 1 - visibleCells.top), iconList);
    }
} // HandleKeyDown
Пример #7
0
// --------------------------------------------------------------------------------------
static pascal OSStatus windowEventHandler(EventHandlerCallRef nextHandler, EventRef event,
        void *junk)
{
#pragma unused (nextHandler, junk)

    OSStatus result = eventNotHandledErr;
    UInt32 eventClass, eventKind;
    WindowRef prefsWindow;
    Point mouseLocation, minWindowBounds;
    UInt32 modifiers;
    ControlRef listScrollBar;
    ListHandle iconList;
    Rect iconListRect;

    eventClass = GetEventClass(event);
    eventKind = GetEventKind(event);

    switch (eventClass)
    {
    case kEventClassWindow:
        GetEventParameter(event, kEventParamDirectObject, typeWindowRef, NULL,
                          sizeof(WindowRef), NULL, &prefsWindow);

        switch (eventKind)
        {
        case kEventWindowActivated:
            HandleActivate(prefsWindow, true);
            result = noErr;
            break;

        case kEventWindowDeactivated:
            HandleActivate(prefsWindow, false);
            result = noErr;
            break;

        case kEventWindowHandleContentClick:
            GetEventParameter(event, kEventParamMouseLocation, typeQDPoint, NULL,
                              sizeof(Point), NULL, &mouseLocation);
            GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL,
                              sizeof(UInt32), NULL, &modifiers);

            HandleContentClick(prefsWindow, mouseLocation, (EventModifiers)modifiers);
            result = noErr;
            break;

        case kEventWindowGetMinimumSize:
            SetPt(&minWindowBounds, gPrefsWindowWidth, gPrefsWindowHeight);
            SetEventParameter(event, kEventParamDimensions, typeQDPoint, sizeof(Point),
                              &minWindowBounds);
            result = noErr;
            break;

        case kEventWindowResizeCompleted:
            AdjustControls(prefsWindow);
            result = noErr;
            break;

        case kEventWindowClose:
            ClosePrefsWindow(prefsWindow);
            result = noErr;
            break;

        case kEventWindowDrawContent:
            HandleDrawContent(prefsWindow);
            result = noErr;
            break;

        case kEventWindowContextualMenuSelect:
            result = noErr;		// eat contextual menu clicks
            break;
        }
        break;

    case kEventClassControl:	// we need to respond to clicks in the list's scroll bar
        switch (eventKind)				// kEventControlClick instead of kEventControlHit
        {   // because the control click must be tracked
        case kEventControlClick:	// with LClick instead of the default handler
            GetEventParameter(event, kEventParamDirectObject, typeControlRef,
                              NULL, sizeof(ControlRef), NULL, &listScrollBar);

            prefsWindow = GetControlOwner(listScrollBar);
            GetWindowProperty(prefsWindow, kAppSignature, kIconListTag,
                              sizeof(ListHandle), NULL, &iconList);
            if (listScrollBar == GetListVerticalScrollBar(iconList))
            {
                GetEventParameter(event, kEventParamMouseLocation, typeQDPoint, NULL,
                                  sizeof(Point), NULL, &mouseLocation);
                GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL,
                                  sizeof(UInt32), NULL, &modifiers);

                HandleContentClick(prefsWindow, mouseLocation,
                                   (EventModifiers)modifiers);
                result = noErr;
            }
            break;
        }
        break;

    case kEventClassMouse:
        switch (eventKind)
        {
        case kEventMouseWheelMoved:
            GetEventParameter(event, kEventParamMouseLocation, typeQDPoint, NULL,
                              sizeof(Point), NULL, &mouseLocation);
            GlobalToLocal(&mouseLocation);

            GetEventParameter(event, kEventParamWindowRef, typeWindowRef, NULL,
                              sizeof(WindowRef), NULL, &prefsWindow);
            GetWindowProperty(prefsWindow, kAppSignature, kIconListTag,
                              sizeof(ListHandle), NULL, &iconList);
            GetListViewBounds(iconList, &iconListRect);
            iconListRect.right += kScrollBarWidth;

            if (PtInRect(mouseLocation, &iconListRect))
            {
                EventMouseWheelAxis axis;
                long mouseWheelDelta;
                SInt16 pixelDepth;
                Boolean isColorDevice;

                GetEventParameter(event, kEventParamMouseWheelAxis, typeMouseWheelAxis,
                                  NULL, sizeof(EventMouseWheelAxis), NULL, &axis);
                GetEventParameter(event, kEventParamMouseWheelDelta, typeLongInteger,
                                  NULL, sizeof(long), NULL, &mouseWheelDelta);

                GetWindowDeviceDepthAndColor(prefsWindow, &pixelDepth, &isColorDevice);
                SetThemeBackground(kThemeBrushWhite, pixelDepth, isColorDevice);
                // LScroll draws the newly visible cells immediately
                if (axis == kEventMouseWheelAxisX)			// (no update event)
                    LScroll(-mouseWheelDelta, 0, iconList);
                else	// axis == kEventMouseWheelAxisY
                    LScroll(0, -mouseWheelDelta, iconList);

                result = noErr;
            }
            break;
        }
        break;

    case kEventClassTextInput:
        switch (eventKind)
        {
        case kEventTextInputUnicodeForKeyEvent:
            prefsWindow = FrontNonFloatingWindow();

            if (prefsWindow != NULL)
            {
                EventRef keyboardEvent;
                UInt32 keyCode;

                GetEventParameter(event, kEventParamTextInputSendKeyboardEvent,
                                  typeEventRef, NULL, sizeof(EventRef), NULL,
                                  &keyboardEvent);
                GetEventParameter(keyboardEvent, kEventParamKeyCode, typeUInt32, NULL,
                                  sizeof(UInt32), NULL, &keyCode);

                HandleKeyDown((char)keyCode, prefsWindow);
                result = noErr;
            }
            break;
        }
        break;
    }

    return result;
} // windowEventHandler
Пример #8
0
// --------------------------------------------------------------------------------------
void OpenPrefsWindow(void)
{
    OSStatus error;
    SInt16 windowResourceID, visibleUserPaneResourceID, invisibleUserPaneResourceID, pixelDepth;
    WindowRef window;
    ControlRef containerControl, embeddedControl;
    short iconListBottom;
    Rect iconListRect;
    Boolean isColorDevice;
    ListHandle iconList;
    EventTypeSpec windowEvents[] = {
        {kEventClassWindow, kEventWindowActivated},
        {kEventClassWindow, kEventWindowDeactivated},
        {kEventClassWindow, kEventWindowHandleContentClick},
        {kEventClassWindow, kEventWindowGetMinimumSize},
        {kEventClassWindow, kEventWindowResizeCompleted},
        {kEventClassWindow, kEventWindowClose},
        {kEventClassWindow, kEventWindowDrawContent},
        {kEventClassWindow, kEventWindowContextualMenuSelect},
        {kEventClassControl, kEventControlClick},
        {kEventClassMouse, kEventMouseWheelMoved},
        {kEventClassTextInput, kEventTextInputUnicodeForKeyEvent}
    };

    if (!RunningInMacOSX())
    {
        windowResourceID = rPrefsWindowPlatinum;
        visibleUserPaneResourceID = cPlatinumWindowUserPaneVisible;
        invisibleUserPaneResourceID = cPlatinumWindowUserPaneInvisible;

        gPrefsWindowHeight = kPrefsWindowPlatinumHeight;
        gPrefsWindowWidth = kPrefsWindowPlatinumWidth;
        gMinimumSpacing = kPlatinumMinimumSpacing;
        gWindowEdgeSpacing = kPlatinumWindowEdgeSpacing;
    }
    else
    {
        windowResourceID = rPrefsWindowAqua;
        visibleUserPaneResourceID = cAquaWindowUserPaneVisible;
        invisibleUserPaneResourceID = cAquaWindowUserPaneInvisible;

        gPrefsWindowHeight = kPrefsWindowAquaHeight;
        gPrefsWindowWidth = kPrefsWindowAquaWidth;
        gMinimumSpacing = kAquaMinimumSpacing;
        gWindowEdgeSpacing = kAquaWindowEdgeSpacing;
    }

    error = CreateWindowFromResource(windowResourceID, &window);
    if (error != noErr)
        ExitToShell();
    RepositionWindow(window, NULL, kWindowCascadeOnMainScreen);		// CreateWindowFromResource
    // doesn't call this for you like GetNewCWindow does
#if TARGET_API_MAC_CARBON	// we would just set the standard handler attribute in the Carbon 
    // Platinum 'wind' resource but that makes it not work under CarbonLib for some reason
    ChangeWindowAttributes(window, kWindowStandardHandlerAttribute, kWindowNoAttributes);
#endif

    SetPortWindowPort(window);

    SetThemeWindowBackground(window, kThemeBrushModelessDialogBackgroundActive, true);

    CreateRootControl(window, &containerControl);

    /* Get each user pane and embed each preference panel's controls (for the
       demonstration there is only some static text identifying each panel number).
       We could just as easily have used AutoEmbedControl but why make the system
       figure out which control to use as the embedder when we already know? */
    containerControl = GetNewControl(visibleUserPaneResourceID, window);
    embeddedControl = GetNewControl(cStaticText, window);
    EmbedControl(embeddedControl, containerControl);
    SetControlData(embeddedControl, kControlEntireControl, kControlStaticTextTextTag, 7,
                   "Panel 1");

    containerControl = GetNewControl(invisibleUserPaneResourceID, window);
    embeddedControl = GetNewControl(cStaticText, window);
    EmbedControl(embeddedControl, containerControl);
    SetControlData(embeddedControl, kControlEntireControl, kControlStaticTextTextTag, 7,
                   "Panel 2");

    containerControl = GetNewControl(invisibleUserPaneResourceID, window);
    embeddedControl = GetNewControl(cStaticText, window);
    EmbedControl(embeddedControl, containerControl);
    SetControlData(embeddedControl, kControlEntireControl, kControlStaticTextTextTag, 7,
                   "Panel 3");

    containerControl = GetNewControl(invisibleUserPaneResourceID, window);
    embeddedControl = GetNewControl(cStaticText, window);
    EmbedControl(embeddedControl, containerControl);
    SetControlData(embeddedControl, kControlEntireControl, kControlStaticTextTextTag, 7,
                   "Panel 4");

    containerControl = GetNewControl(invisibleUserPaneResourceID, window);
    embeddedControl = GetNewControl(cStaticText, window);
    EmbedControl(embeddedControl, containerControl);
    SetControlData(embeddedControl, kControlEntireControl, kControlStaticTextTextTag, 7,
                   "Panel 5");

    containerControl = GetNewControl(invisibleUserPaneResourceID, window);
    embeddedControl = GetNewControl(cStaticText, window);
    EmbedControl(embeddedControl, containerControl);
    SetControlData(embeddedControl, kControlEntireControl, kControlStaticTextTextTag, 7,
                   "Panel 6");

    containerControl = GetNewControl(invisibleUserPaneResourceID, window);
    embeddedControl = GetNewControl(cStaticText, window);
    EmbedControl(embeddedControl, containerControl);
    SetControlData(embeddedControl, kControlEntireControl, kControlStaticTextTextTag, 7,
                   "Panel 7");

    containerControl = GetNewControl(invisibleUserPaneResourceID, window);
    embeddedControl = GetNewControl(cStaticText, window);
    EmbedControl(embeddedControl, containerControl);
    SetControlData(embeddedControl, kControlEntireControl, kControlStaticTextTextTag, 7,
                   "Panel 8");

    containerControl = GetNewControl(invisibleUserPaneResourceID, window);
    embeddedControl = GetNewControl(cStaticText, window);
    EmbedControl(embeddedControl, containerControl);
    SetControlData(embeddedControl, kControlEntireControl, kControlStaticTextTextTag, 7,
                   "Panel 9");

    containerControl = GetNewControl(invisibleUserPaneResourceID, window);
    embeddedControl = GetNewControl(cStaticText, window);
    EmbedControl(embeddedControl, containerControl);
    SetControlData(embeddedControl, kControlEntireControl, kControlStaticTextTextTag, 8,
                   "Panel 10");

    gPanelNumber = 1;

    GetWindowDeviceDepthAndColor(window, &pixelDepth, &isColorDevice);	// draw the list with a
    SetThemeBackground(kThemeBrushWhite, pixelDepth, isColorDevice);	// white background
    // get the bottom-most
    iconListBottom = gPrefsWindowHeight - gWindowEdgeSpacing;	// coordinate we can use
    iconListBottom -= (gPrefsWindowHeight - gWindowEdgeSpacing - gWindowEdgeSpacing) %
                      kCellHeight;	// then subtract out the partial cell height that would
    // be drawn on the bottom so that it's not actually drawn
    SetRect(&iconListRect, gWindowEdgeSpacing, gWindowEdgeSpacing,
            gWindowEdgeSpacing + kListWidth, iconListBottom);
    iconList = createIconList(window, iconListRect);
    SetWindowProperty(window, kAppSignature, kIconListTag, sizeof(ListHandle), &iconList);

#if TARGET_API_MAC_OS8
    CalculateBalloonHelpRects(window);
#else
    gWindowEventHandler = NewEventHandlerUPP(windowEventHandler);
    InstallWindowEventHandler(window, gWindowEventHandler, GetEventTypeCount(windowEvents),
                              windowEvents, NULL, NULL);
    InstallPrefsWindowHelpTags(window);
#endif

    DisableMenuItem(GetMenuRef(mDemonstration), iPrefsWindow);
    EnableMenuItem(GetMenuRef(mFile), iClose);

    ShowWindow(window);
} // OpenPrefsWindow