Skip to content

Commit

Permalink
Merge pull request #201 from KyleCardoza/add-gstheme-hooks
Browse files Browse the repository at this point in the history
add gstheme hooks
  • Loading branch information
KyleCardoza authored Nov 9, 2023
2 parents 34c5a5e + 7f70818 commit dfa829b
Show file tree
Hide file tree
Showing 12 changed files with 377 additions and 240 deletions.
55 changes: 54 additions & 1 deletion Headers/Additions/GNUstepGUI/GSTheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@
#import <AppKit/NSTabView.h>
#import <AppKit/NSPrintPanel.h>
#import <AppKit/NSPageLayout.h>
// For window decorator protocol
#import <GNUstepGUI/GSWindowDecorationView.h>

#if OS_API_VERSION(GS_API_NONE,GS_API_NONE)
@class NSArray;
Expand Down Expand Up @@ -1244,6 +1246,13 @@ APPKIT_EXPORT_CLASS
state: (int)inputState
andTitle: (NSString*)title;

- (void) setFrameForCloseButton: (NSButton *)closeButton
viewSize: (NSSize)viewSize;

- (NSRect) miniaturizeButtonFrameForBounds: (NSRect)bounds;

- (NSRect) closeButtonFrameForBounds: (NSRect)bounds;

- (NSColor *) browserHeaderTextColor;

- (void) drawBrowserHeaderCell: (NSTableHeaderCell*)cell
Expand Down Expand Up @@ -1501,6 +1510,44 @@ withRepeatedImage: (NSImage*)image
*/
- (void) updateMenu: (NSMenu *)menu forWindow: (NSWindow *)window;
- (void) updateAllWindowsWithMenu: (NSMenu *) menu;

/**
* Modifies the given NSRect for use by NSMenu to position and size
* the displayed menu. The default implementation simply returns
* the original NSRect unmodified.
*/
- (NSRect) modifyRect: (NSRect)aRect
forMenu: (NSMenu *)aMenu
isHorizontal: (BOOL) horizontal;

/**
* Modifies the proposed default width for a menu title in the given NSMenuView.
* The default implementation simply returns the proposed width unmodified.
*/
- (CGFloat) proposedTitleWidth: (CGFloat)proposedWidth
forMenuView: (NSMenuView *)aMenuView;

/**
* Modifies the proposed key equivalent string for the menu item. The default
* implementation simply returns the proposed string unmodified.
*/
- (NSString *) keyForKeyEquivalent: (NSString *)aString;

/**
* Modifies the proposed menu item title. The default implementation simply
* returns the proposed string unmodified.
*/
- (NSString *) proposedTitle: (NSString *)title
forMenuItem: (NSMenuItem *)menuItem;

/**
* Used by the theme to organize the main menu. The default implementation
* organizes the main menu in the same way that NSMenu's old default behaviour
* did, generating an "app name" menu for horizontal display.
*/
- (void) organizeMenu: (NSMenu *)menu
isHorizontal: (BOOL)horizontal;

@end

@interface GSTheme (OpenSavePanels)
Expand Down Expand Up @@ -1541,6 +1588,13 @@ APPKIT_EXPORT_CLASS
@end

@interface GSTheme (NSWindow)

/**
* This method returns the window decorator provided by
* the current theme.
*/
- (id<GSWindowDecorator>) windowDecorator;

/**
* This method returns the standard window button for the
* given mask for the current theme.
Expand Down Expand Up @@ -1594,6 +1648,5 @@ APPKIT_EXPORT_CLASS
- (NSImage *) highlightedBranchImage;
@end


#endif /* OS_API_VERSION */
#endif /* _GNUstep_H_GSTheme */
1 change: 1 addition & 0 deletions Headers/Additions/GNUstepGUI/GSWindowDecorationView.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ APPKIT_EXPORT_CLASS
BOOL hasMenu;
BOOL hasToolbar;
}

+ (id<GSWindowDecorator>) windowDecorator;

- (id) initWithFrame: (NSRect)frame window: (NSWindow *)w;
Expand Down
13 changes: 4 additions & 9 deletions Source/GSStandardWindowDecorationView.m
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,8 @@ - (void) updateRects
}
if (hasCloseButton)
{
closeButtonRect = NSMakeRect([self bounds].size.width - [theme titlebarButtonSize] -
[theme titlebarPaddingRight], [self bounds].size.height -
[theme titlebarButtonSize] - [theme titlebarPaddingTop],
[theme titlebarButtonSize], [theme titlebarButtonSize]);
[closeButton setFrame: closeButtonRect];
NSRect closeButtonFrame = [[GSTheme theme] closeButtonFrameForBounds: [self bounds]];
[closeButton setFrame: closeButtonFrame];
}
else
{
Expand All @@ -121,10 +118,8 @@ - (void) updateRects

if (hasMiniaturizeButton)
{
miniaturizeButtonRect = NSMakeRect([theme titlebarPaddingLeft], [self bounds].size.height -
[theme titlebarButtonSize] - [theme titlebarPaddingTop],
[theme titlebarButtonSize], [theme titlebarButtonSize]);
[miniaturizeButton setFrame: miniaturizeButtonRect];
NSRect miniaturizeButtonFrame = [[GSTheme theme] miniaturizeButtonFrameForBounds: [self bounds]];
[miniaturizeButton setFrame: miniaturizeButtonFrame];
}
else
{
Expand Down
35 changes: 33 additions & 2 deletions Source/GSThemeDrawing.m
Original file line number Diff line number Diff line change
Expand Up @@ -967,13 +967,12 @@ - (void) drawSwitchKnob: (NSRect)frame
// fill oval with background color
[backgroundColor set];
[oval fill];

// and stroke rounded button
[[NSColor shadowColor] set];
[oval stroke];
}


- (void) drawSwitchInRect: (NSRect)rect
forState: (NSControlStateValue)state
enabled: (BOOL)enabled
Expand Down Expand Up @@ -2073,6 +2072,38 @@ - (void) drawWindowBorder: (NSRect)rect
}
}

- (void) setFrameForCloseButton: (NSButton *)closeButton
viewSize: (NSSize)viewSize
{
NSSize buttonSize = [[closeButton image] size];
buttonSize = NSMakeSize(buttonSize.width + 3, buttonSize.height + 3);

[closeButton setFrame: NSMakeRect(viewSize.width - buttonSize.width - 4,
(viewSize.height - buttonSize.height) / 2,
buttonSize.width,
buttonSize.height)];
}

- (NSRect) closeButtonFrameForBounds: (NSRect)bounds
{
GSTheme *theme = [GSTheme theme];

return NSMakeRect(bounds.size.width - [theme titlebarButtonSize] -
[theme titlebarPaddingRight], bounds.size.height -
[theme titlebarButtonSize] - [theme titlebarPaddingTop],
[theme titlebarButtonSize], [theme titlebarButtonSize]);
}

- (NSRect) miniaturizeButtonFrameForBounds: (NSRect)bounds
{
GSTheme *theme = [GSTheme theme];

return NSMakeRect([theme titlebarPaddingLeft],
bounds.size.height - [theme titlebarButtonSize] - [theme titlebarPaddingTop],
[theme titlebarButtonSize],
[theme titlebarButtonSize]);
}

- (NSColor *) browserHeaderTextColor
{
NSColor *color;
Expand Down
Loading

0 comments on commit dfa829b

Please sign in to comment.