mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 15:11:37 +00:00
return back horizontal menu code
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@16396 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
58a9585750
commit
223ed7f03f
3 changed files with 203 additions and 94 deletions
17
ChangeLog
17
ChangeLog
|
@ -1,3 +1,20 @@
|
|||
2003-04-09 Serg Stoyan <stoyan@hologr.com>
|
||||
|
||||
* Source/NSMenuView.m: return back horizontal menu code.
|
||||
(sizeToFit): ditto.
|
||||
(innerRect): ditto.
|
||||
(rectOfItemAtIndex:): ditto.
|
||||
(locationForSubmenu:): ditto.
|
||||
(setWindowFrameForAttachingToRect:): ditto.
|
||||
(encodeWithCoder:): ditto.
|
||||
(initWithCoder:): ditto.
|
||||
(setHorizontal:): added.
|
||||
(isHorizontal): added.
|
||||
|
||||
* Headers/NSMenuView.h:
|
||||
(setHorizontal:): added.
|
||||
(isHorizontal): added.
|
||||
|
||||
2003-04-09 00:38 Alexander Malmberg <alexander@malmberg.org>
|
||||
|
||||
* Source/NSView.m (-setNeedsDisplay:, -setNeedsDisplayInRect:):
|
||||
|
|
|
@ -56,23 +56,24 @@
|
|||
|
||||
<br/><br/>
|
||||
<strong>How menus are drawn</strong>
|
||||
<br/><br/>
|
||||
<br/><br/>
|
||||
|
||||
This class implements several menu look and feels at the same time.
|
||||
The looks and feels implemented are:
|
||||
<list>
|
||||
<item>
|
||||
Ordinary vertically stacked menus with the NeXT submenu positioning
|
||||
behavour.
|
||||
</item>
|
||||
Ordinary vertically stacked menus with the NeXT submenu positioning
|
||||
behavour.
|
||||
</item>
|
||||
<item>
|
||||
Vertically stacked menus with the WindowMaker submenu placement. This
|
||||
behaviour is selected by choosing the <strong>GSWindowMakerInterfaceStyle</strong>.
|
||||
</item>
|
||||
Vertically stacked menus with the WindowMaker submenu placement. This
|
||||
behaviour is selected by choosing the
|
||||
<strong>GSWindowMakerInterfaceStyle</strong>.
|
||||
</item>
|
||||
<item>
|
||||
PopupButtons are actually menus. This class implements also the
|
||||
behaviour for the NSPopButtons. See for the the class NSPopButton.
|
||||
</item>
|
||||
PopupButtons are actually menus. This class implements also the
|
||||
behaviour for the NSPopButtons. See for the the class NSPopButton.
|
||||
</item>
|
||||
</list>
|
||||
*/
|
||||
@interface NSMenuView : NSView <NSCoding, NSMenuView>
|
||||
|
@ -86,13 +87,13 @@
|
|||
float _stateImageWidth;
|
||||
float _imageAndTitleOffset;
|
||||
float _imageAndTitleWidth;
|
||||
float _keyEqOffset;
|
||||
float _keyEqWidth;
|
||||
BOOL _needsSizing;
|
||||
float _keyEqOffset;
|
||||
float _keyEqWidth;
|
||||
BOOL _needsSizing;
|
||||
NSSize _cellSize;
|
||||
|
||||
@private
|
||||
id _items_link;
|
||||
id _items_link;
|
||||
int _leftBorderOffset;
|
||||
id _titleView;
|
||||
}
|
||||
|
@ -127,6 +128,19 @@
|
|||
*/
|
||||
- (NSMenu *) menu;
|
||||
|
||||
/**
|
||||
Sets menu orientation. If YES menu items are displayed from left
|
||||
to right, if NO from top to bottom (vertically). By default, menu
|
||||
items are displayed vertically.
|
||||
*/
|
||||
- (void) setHorizontal: (BOOL)flag;
|
||||
|
||||
/**
|
||||
Returns YES if menu items are displayed horizontally, NO if
|
||||
vertically.
|
||||
*/
|
||||
- (BOOL) isHorizontal;
|
||||
|
||||
/**
|
||||
Sets the default font to use when drawing the menu text.
|
||||
*/
|
||||
|
@ -198,29 +212,29 @@
|
|||
/**
|
||||
Marks menu item cell associated with the menu item and menu view as
|
||||
needing to be resized. This method is invoked when
|
||||
NSMenuDidChangeItemNotification received. The notification parameter
|
||||
contains index of changed menu item and can be accessed with
|
||||
NSMenuItemIndex key.
|
||||
NSMenuDidChangeItemNotification received. The notification parameter
|
||||
contains index of changed menu item and can be accessed with
|
||||
NSMenuItemIndex key.
|
||||
*/
|
||||
- (void) itemChanged: (NSNotification *)notification;
|
||||
|
||||
/**
|
||||
Creates new item cell for the newly created menu item, marks cell and
|
||||
menu view as needing to be resized. This method is invoked when
|
||||
NSMenuDidAddItemNotification received. The notification parameter
|
||||
contains index of changed menu item and can be accessed with
|
||||
NSMenuItemIndex key.
|
||||
menu view as needing to be resized. This method is invoked when
|
||||
NSMenuDidAddItemNotification received. The notification parameter
|
||||
contains index of changed menu item and can be accessed with
|
||||
NSMenuItemIndex key.
|
||||
|
||||
*/
|
||||
- (void) itemAdded: (NSNotification *)notification;
|
||||
|
||||
/**
|
||||
Removes cell associated with removed menu item, removes highlighting
|
||||
if removed menu item was highlighted, marks cell and menu view as
|
||||
needing to be resized. This method is invoked when
|
||||
NSMenuDidRemoveItemNotification received. The notification parameter
|
||||
contains index of changed menu item and can be accessed with
|
||||
NSMenuItemIndex key.
|
||||
if removed menu item was highlighted, marks cell and menu view as
|
||||
needing to be resized. This method is invoked when
|
||||
NSMenuDidRemoveItemNotification received. The notification parameter
|
||||
contains index of changed menu item and can be accessed with
|
||||
NSMenuItemIndex key.
|
||||
|
||||
*/
|
||||
- (void) itemRemoved: (NSNotification *)notification;
|
||||
|
@ -235,7 +249,7 @@
|
|||
|
||||
/**
|
||||
Attach submenu if the item at index is a submenu. It will figure out
|
||||
if the new submenu should be transient or not.
|
||||
if the new submenu should be transient or not.
|
||||
*/
|
||||
- (void) attachSubmenuForItemAtIndex: (int)index;
|
||||
|
||||
|
@ -245,14 +259,14 @@
|
|||
/**
|
||||
Adds title view for application menu and submenus, removes title view
|
||||
if menu is owned by NSPopUpButton, adds close button to title view for
|
||||
torn off menus and removes it for other type of menu.
|
||||
torn off menus and removes it for other type of menu.
|
||||
*/
|
||||
- (void) update;
|
||||
|
||||
/**
|
||||
Sets the flag whether layout needs to be resized. Set it to YES if
|
||||
menu contents changed and layout needs to be recalculated. This method
|
||||
is used internally. Yout should not invoke it directly from applications.
|
||||
menu contents changed and layout needs to be recalculated. This method
|
||||
is used internally. Yout should not invoke it directly from applications.
|
||||
*/
|
||||
- (void) setNeedsSizing: (BOOL)flag;
|
||||
|
||||
|
@ -283,37 +297,37 @@
|
|||
|
||||
/**
|
||||
Returns the width of the image and title section. Tis section contains
|
||||
image and text of menu item.
|
||||
image and text of menu item.
|
||||
*/
|
||||
- (float) imageAndTitleWidth;
|
||||
|
||||
/**
|
||||
Returns the starting position for drawing the key equivalent. Key
|
||||
equivalent can be submenu arrow if menu item has submenu.
|
||||
equivalent can be submenu arrow if menu item has submenu.
|
||||
*/
|
||||
- (float) keyEquivalentOffset;
|
||||
|
||||
/**
|
||||
Returns the width of key equivalent text. Key equivalent can be submenu
|
||||
arrow if menu item has submenu
|
||||
arrow if menu item has submenu
|
||||
*/
|
||||
- (float) keyEquivalentWidth;
|
||||
|
||||
/**
|
||||
Returns bounds rectangle of the menu view. It is smaller by 1 pixel
|
||||
in width than menu window (dark gray border at left).
|
||||
in width than menu window (dark gray border at left).
|
||||
*/
|
||||
- (NSRect) innerRect;
|
||||
|
||||
/**
|
||||
Returns frame rectangle of menu item cell. It is smaller by 1 pixel
|
||||
in width than menu window (dark gray border).
|
||||
in width than menu window (dark gray border).
|
||||
*/
|
||||
- (NSRect) rectOfItemAtIndex: (int)index;
|
||||
|
||||
/**
|
||||
Returns the index of the item below point. Returns -1 if mouse is
|
||||
not above a menu item.
|
||||
not above a menu item.
|
||||
*/
|
||||
- (int) indexOfItemAtPoint: (NSPoint)point;
|
||||
|
||||
|
@ -330,11 +344,11 @@
|
|||
|
||||
/**
|
||||
Resize menu view frame to be appropriate in size to attach to screenRect
|
||||
at preferredEdge. For popup's menu, if selectedItemIndex is other than
|
||||
-1, position view so selected item covers the NSPopUpButton.
|
||||
|
||||
<br/><strong>NOTE: preffered edge positioning doesn't implemented
|
||||
yet!</strong>
|
||||
at preferredEdge. For popup's menu, if selectedItemIndex is other than
|
||||
-1, position view so selected item covers the NSPopUpButton.
|
||||
|
||||
<br/><strong>NOTE: preffered edge positioning doesn't implemented
|
||||
yet!</strong>
|
||||
*/
|
||||
- (void) setWindowFrameForAttachingToRect: (NSRect)screenRect
|
||||
onScreen: (NSScreen *)screen
|
||||
|
@ -363,38 +377,38 @@
|
|||
attach / detach submenus.
|
||||
</item>
|
||||
<item> The flag justAttachedNewSubmenu is set to YES when a new
|
||||
submenu is attached. The effect is that the
|
||||
highlighting / attaching / detaching is supressed
|
||||
for this menu. This is done so the user is given
|
||||
a change to move the mouse pointer into the newly
|
||||
attached submenu. Otherwise it would immediately
|
||||
be removed as the mouse pointer move over another
|
||||
item.
|
||||
submenu is attached. The effect is that the
|
||||
highlighting / attaching / detaching is supressed
|
||||
for this menu. This is done so the user is given
|
||||
a change to move the mouse pointer into the newly
|
||||
attached submenu. Otherwise it would immediately
|
||||
be removed as the mouse pointer move over another
|
||||
item.
|
||||
|
||||
The logic for resetting the flag is rather adhoc.
|
||||
The logic for resetting the flag is rather adhoc.
|
||||
</item>
|
||||
|
||||
<item> the flag subMenusNeedRemoving means that we
|
||||
will remove all the submenus after we are done.
|
||||
will remove all the submenus after we are done.
|
||||
|
||||
This flag is used to clean up the submenus
|
||||
when the user has opened a submenu by clicking
|
||||
and wants to close it again by clicking on the
|
||||
hihglighted item.
|
||||
This flag is used to clean up the submenus
|
||||
when the user has opened a submenu by clicking
|
||||
and wants to close it again by clicking on the
|
||||
hihglighted item.
|
||||
</item>
|
||||
<item> When the user released the mouse this method
|
||||
will cleanup all the transient menus.
|
||||
will cleanup all the transient menus.
|
||||
|
||||
Not only its own, but also its attached menu
|
||||
and all its transient super menus.
|
||||
Not only its own, but also its attached menu
|
||||
and all its transient super menus.
|
||||
</item>
|
||||
<item> The clean up is done BEFORE the action is executed.
|
||||
This is needed otherwise `hiding' the application
|
||||
leaves a dangling menu. If this is not acceptable,
|
||||
there should be another mechanism of handling
|
||||
the hiding. BTW besides the `hiding' the application,
|
||||
model panels are also a problem when the menu
|
||||
is not cleared before executing the action.
|
||||
This is needed otherwise `hiding' the application
|
||||
leaves a dangling menu. If this is not acceptable,
|
||||
there should be another mechanism of handling
|
||||
the hiding. BTW besides the `hiding' the application,
|
||||
model panels are also a problem when the menu
|
||||
is not cleared before executing the action.
|
||||
</item>
|
||||
</list>
|
||||
*/
|
||||
|
|
|
@ -216,6 +216,18 @@ _addLeftBorderOffsetToRect(NSRect aRect)
|
|||
return _menu;
|
||||
}
|
||||
|
||||
// FIXME: horizontal orientation related code shoul be removed
|
||||
- (void) setHorizontal: (BOOL)flag
|
||||
{
|
||||
_horizontal = flag;
|
||||
}
|
||||
|
||||
// FIXME: horizontal orientation related code shoul be removed
|
||||
- (BOOL) isHorizontal
|
||||
{
|
||||
return _horizontal;
|
||||
}
|
||||
|
||||
- (void) setFont: (NSFont*)font
|
||||
{
|
||||
ASSIGN(_font, font);
|
||||
|
@ -457,7 +469,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
|
|||
[self addSubview: _titleView];
|
||||
[_titleView release];
|
||||
}
|
||||
else if ([_menu _ownedByPopUp] && _titleView)
|
||||
else if ([_menu _ownedByPopUp] && _titleView)
|
||||
{
|
||||
// Remove title view if this menu owned by popup
|
||||
[_titleView removeFromSuperview];
|
||||
|
@ -494,7 +506,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
|
|||
{
|
||||
unsigned i;
|
||||
unsigned howMany = [_itemCells count];
|
||||
unsigned wideTitleView = 1;
|
||||
unsigned wideTitleView = 1;
|
||||
float neededImageAndTitleWidth = 0.0;
|
||||
float neededKeyEquivalentWidth = 0.0;
|
||||
float neededStateImageWidth = 0.0;
|
||||
|
@ -632,12 +644,23 @@ _addLeftBorderOffsetToRect(NSRect aRect)
|
|||
{
|
||||
_keyEqOffset = _cellSize.width - _keyEqWidth - popupImageWidth;
|
||||
}
|
||||
|
||||
[self setFrameSize: NSMakeSize (_cellSize.width + _leftBorderOffset,
|
||||
(howMany * _cellSize.height)
|
||||
+ menuBarHeight)];
|
||||
[_titleView setFrame: NSMakeRect (0, howMany * _cellSize.height,
|
||||
NSWidth (_bounds), menuBarHeight)];
|
||||
|
||||
// FIXME: horizontal orientation related code shoul be removed
|
||||
if (_horizontal == NO)
|
||||
{
|
||||
[self setFrameSize: NSMakeSize(_cellSize.width + _leftBorderOffset,
|
||||
(howMany * _cellSize.height)
|
||||
+ menuBarHeight)];
|
||||
[_titleView setFrame: NSMakeRect (0, howMany * _cellSize.height,
|
||||
NSWidth (_bounds), menuBarHeight)];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self setFrameSize: NSMakeSize((howMany * _cellSize.width),
|
||||
_cellSize.height + _leftBorderOffset)];
|
||||
[_titleView setFrame: NSMakeRect (0, 0,
|
||||
_cellSize.width, _cellSize.height + 1)];
|
||||
}
|
||||
|
||||
_needsSizing = NO;
|
||||
}
|
||||
|
@ -692,10 +715,21 @@ _addLeftBorderOffsetToRect(NSRect aRect)
|
|||
|
||||
- (NSRect) innerRect
|
||||
{
|
||||
return NSMakeRect(_bounds.origin.x + _leftBorderOffset,
|
||||
_bounds.origin.y,
|
||||
_bounds.size.width - _leftBorderOffset,
|
||||
_bounds.size.height);
|
||||
// FIXME: horizontal orientation related code shoul be removed
|
||||
if (_horizontal == NO)
|
||||
{
|
||||
return NSMakeRect (_bounds.origin.x + _leftBorderOffset,
|
||||
_bounds.origin.y,
|
||||
_bounds.size.width - _leftBorderOffset,
|
||||
_bounds.size.height);
|
||||
}
|
||||
else
|
||||
{
|
||||
return NSMakeRect (_bounds.origin.x,
|
||||
_bounds.origin.y + _leftBorderOffset,
|
||||
_bounds.size.width,
|
||||
_bounds.size.height - _leftBorderOffset);
|
||||
}
|
||||
}
|
||||
|
||||
- (NSRect) rectOfItemAtIndex: (int)index
|
||||
|
@ -710,8 +744,17 @@ _addLeftBorderOffsetToRect(NSRect aRect)
|
|||
/* Fiddle with the origin so that the item rect is shifted 1 pixel over
|
||||
* so we do not draw on the heavy line at origin.x = 0.
|
||||
*/
|
||||
theRect.origin.y = _cellSize.height * ([_itemCells count] - index - 1);
|
||||
theRect.origin.x = _leftBorderOffset;
|
||||
// FIXME: horizontal orientation related code shoul be removed
|
||||
if (_horizontal == NO)
|
||||
{
|
||||
theRect.origin.y = _cellSize.height * ([_itemCells count] - index - 1);
|
||||
theRect.origin.x = _leftBorderOffset;
|
||||
}
|
||||
else
|
||||
{
|
||||
theRect.origin.x = _cellSize.width * index;
|
||||
theRect.origin.y = 0;
|
||||
}
|
||||
theRect.size = _cellSize;
|
||||
|
||||
/* NOTE: This returns the correct NSRect for drawing cells, but nothing
|
||||
|
@ -763,22 +806,36 @@ _addLeftBorderOffsetToRect(NSRect aRect)
|
|||
else
|
||||
submenuFrame = NSZeroRect;
|
||||
|
||||
if (NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", nil)
|
||||
== GSWindowMakerInterfaceStyle)
|
||||
// FIXME: horizontal orientation related code shoul be removed
|
||||
if (_horizontal == NO)
|
||||
{
|
||||
NSRect aRect = [self rectOfItemAtIndex:
|
||||
[_menu indexOfItemWithSubmenu: aSubmenu]];
|
||||
NSPoint subOrigin = [_window convertBaseToScreen:
|
||||
NSMakePoint(aRect.origin.x, aRect.origin.y)];
|
||||
if (NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", nil)
|
||||
== GSWindowMakerInterfaceStyle)
|
||||
{
|
||||
NSRect aRect = [self rectOfItemAtIndex:
|
||||
[_menu indexOfItemWithSubmenu: aSubmenu]];
|
||||
NSPoint subOrigin = [_window convertBaseToScreen:
|
||||
NSMakePoint(aRect.origin.x, aRect.origin.y)];
|
||||
|
||||
return NSMakePoint (NSMaxX(frame),
|
||||
subOrigin.y - NSHeight(submenuFrame) - 3 +
|
||||
2*[NSMenuView menuBarHeight]);
|
||||
return NSMakePoint (NSMaxX(frame),
|
||||
subOrigin.y - NSHeight(submenuFrame) - 3 +
|
||||
2*[NSMenuView menuBarHeight]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return NSMakePoint(NSMaxX(frame),
|
||||
NSMaxY(frame) - NSHeight(submenuFrame));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return NSMakePoint(NSMaxX(frame),
|
||||
NSMaxY(frame) - NSHeight(submenuFrame));
|
||||
NSRect aRect = [self rectOfItemAtIndex:
|
||||
[_menu indexOfItemWithSubmenu: aSubmenu]];
|
||||
NSPoint subOrigin = [_window convertBaseToScreen:
|
||||
NSMakePoint(NSMinX(aRect),
|
||||
NSMinY(aRect))];
|
||||
|
||||
return NSMakePoint(subOrigin.x, subOrigin.y - NSHeight(submenuFrame));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -817,17 +874,34 @@ _addLeftBorderOffsetToRect(NSRect aRect)
|
|||
{
|
||||
float f;
|
||||
|
||||
f = screenRect.size.height * (items - 1);
|
||||
screenFrame.size.height += f + _leftBorderOffset;
|
||||
screenFrame.origin.y -= f;
|
||||
screenFrame.size.width += _leftBorderOffset;
|
||||
screenFrame.origin.x -= _leftBorderOffset;
|
||||
// FIXME: horizontal orientation related code shoul be removed
|
||||
if (_horizontal == NO)
|
||||
{
|
||||
f = screenRect.size.height * (items - 1);
|
||||
screenFrame.size.height += f + _leftBorderOffset;
|
||||
screenFrame.origin.y -= f;
|
||||
screenFrame.size.width += _leftBorderOffset;
|
||||
screenFrame.origin.x -= _leftBorderOffset;
|
||||
}
|
||||
else
|
||||
{
|
||||
f = screenRect.size.width * (items - 1);
|
||||
screenFrame.size.width += f;
|
||||
}
|
||||
}
|
||||
|
||||
// Compute position for popups, if needed
|
||||
if (selectedItemIndex != -1)
|
||||
{
|
||||
screenFrame.origin.y += screenRect.size.height * selectedItemIndex;
|
||||
// FIXME: horizontal orientation related code shoul be removed
|
||||
if (_horizontal == NO)
|
||||
{
|
||||
screenFrame.origin.y += screenRect.size.height * selectedItemIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
screenFrame.origin.x -= screenRect.size.width * selectedItemIndex;
|
||||
}
|
||||
}
|
||||
|
||||
// Get the frameRect
|
||||
|
@ -1276,6 +1350,8 @@ _addLeftBorderOffsetToRect(NSRect aRect)
|
|||
|
||||
[encoder encodeObject: _itemCells];
|
||||
[encoder encodeObject: _font];
|
||||
// FIXME: horizontal orientation related code shoul be removed
|
||||
[encoder encodeValueOfObjCType: @encode(BOOL) at: &_horizontal];
|
||||
[encoder encodeValueOfObjCType: @encode(float) at: &_horizontalEdgePad];
|
||||
[encoder encodeValueOfObjCType: @encode(NSSize) at: &_cellSize];
|
||||
}
|
||||
|
@ -1290,6 +1366,8 @@ _addLeftBorderOffsetToRect(NSRect aRect)
|
|||
withObject: self];
|
||||
|
||||
[decoder decodeValueOfObjCType: @encode(id) at: &_font];
|
||||
// FIXME: horizontal orientation related code shoul be removed
|
||||
[decoder decodeValueOfObjCType: @encode(BOOL) at: &_horizontal];
|
||||
[decoder decodeValueOfObjCType: @encode(float) at: &_horizontalEdgePad];
|
||||
[decoder decodeValueOfObjCType: @encode(NSSize) at: &_cellSize];
|
||||
|
||||
|
|
Loading…
Reference in a new issue