mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-25 11:41:06 +00:00
NSMenuView popup button related fixes and additions
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@16214 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
b19a81ce43
commit
8ba951b342
2 changed files with 98 additions and 98 deletions
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
||||||
|
2003-03-20 Serg Stoyan <stoyan@on.com.ua>
|
||||||
|
|
||||||
|
* Source/NSMenuView.m
|
||||||
|
(sizeToFit): Removed setting _leftBorderOffset to 0 for popup menus.
|
||||||
|
Set menuBarHeight to title view height only if it's not popup menu.
|
||||||
|
Added recalculation of key equivalent offset for popup menu.
|
||||||
|
(setWindowFrameForAttachingToRect:onScreen:preferredEdge:popUpSelectedItem:):
|
||||||
|
Remove title view. Take into account left top border while calculating
|
||||||
|
screenFrame.
|
||||||
|
(drawRect:): Draw left top dark gray border for all types of menus with
|
||||||
|
NSDrawTiledRects().
|
||||||
|
|
||||||
2003-03-19 Fred Kiefer <FredKiefer@gmx.de>
|
2003-03-19 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
* Headers/gnustep/gui/NSMenu.h
|
* Headers/gnustep/gui/NSMenu.h
|
||||||
|
|
|
@ -506,17 +506,14 @@ _addLeftBorderOffsetToRect(NSRect aRect, BOOL isHorizontal)
|
||||||
float neededKeyEquivalentWidth = 0.0;
|
float neededKeyEquivalentWidth = 0.0;
|
||||||
float neededStateImageWidth = 0.0;
|
float neededStateImageWidth = 0.0;
|
||||||
float accumulatedOffset = 0.0;
|
float accumulatedOffset = 0.0;
|
||||||
|
float popupImageWidth = 0.0;
|
||||||
|
float menuBarHeight = 0.0;
|
||||||
|
|
||||||
/* Set the necessary offset for the menuView. That is, how many pixels
|
// Popup menu doesn't need title bar
|
||||||
* do we need for our left side border line. For regular menus this
|
if (![_menu _ownedByPopUp])
|
||||||
* equals 1, for popups it is 0.
|
menuBarHeight = [[self class] menuBarHeight];
|
||||||
*
|
else
|
||||||
* Why here? I could not think of a better place. I figure that everyone
|
menuBarHeight += _leftBorderOffset;
|
||||||
* should sizeToFit their popup/menu before using it so we should get
|
|
||||||
* this set properly fairly early.
|
|
||||||
*/
|
|
||||||
if ([_menu _ownedByPopUp])
|
|
||||||
_leftBorderOffset = 0;
|
|
||||||
|
|
||||||
// TODO: Optimize this loop.
|
// TODO: Optimize this loop.
|
||||||
for (i = 0; i < howMany; i++)
|
for (i = 0; i < howMany; i++)
|
||||||
|
@ -576,6 +573,10 @@ _addLeftBorderOffsetToRect(NSRect aRect, BOOL isHorizontal)
|
||||||
|
|
||||||
if (aKeyEquivalentWidth > neededKeyEquivalentWidth)
|
if (aKeyEquivalentWidth > neededKeyEquivalentWidth)
|
||||||
neededKeyEquivalentWidth = aKeyEquivalentWidth;
|
neededKeyEquivalentWidth = aKeyEquivalentWidth;
|
||||||
|
|
||||||
|
// Popup menu has only one item with nibble image
|
||||||
|
if (anImageWidth)
|
||||||
|
popupImageWidth = anImageWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cache the needed widths.
|
// Cache the needed widths.
|
||||||
|
@ -621,11 +622,13 @@ _addLeftBorderOffsetToRect(NSRect aRect, BOOL isHorizontal)
|
||||||
// Add the border width: 1 for left, 2 for right sides
|
// Add the border width: 1 for left, 2 for right sides
|
||||||
_cellSize.width = accumulatedOffset + 3;
|
_cellSize.width = accumulatedOffset + 3;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_keyEqOffset = _cellSize.width - _keyEqWidth - popupImageWidth;
|
||||||
|
}
|
||||||
|
|
||||||
if (_horizontal == NO)
|
if (_horizontal == NO)
|
||||||
{
|
{
|
||||||
float menuBarHeight = [[self class] menuBarHeight];
|
|
||||||
|
|
||||||
[self setFrameSize: NSMakeSize(_cellSize.width + _leftBorderOffset,
|
[self setFrameSize: NSMakeSize(_cellSize.width + _leftBorderOffset,
|
||||||
(howMany * _cellSize.height) + menuBarHeight)];
|
(howMany * _cellSize.height) + menuBarHeight)];
|
||||||
[_titleView setFrame: NSMakeRect (0, howMany * _cellSize.height,
|
[_titleView setFrame: NSMakeRect (0, howMany * _cellSize.height,
|
||||||
|
@ -842,65 +845,69 @@ _addLeftBorderOffsetToRect(NSRect aRect, BOOL isHorizontal)
|
||||||
preferredEdge: (NSRectEdge)edge
|
preferredEdge: (NSRectEdge)edge
|
||||||
popUpSelectedItem: (int)selectedItemIndex
|
popUpSelectedItem: (int)selectedItemIndex
|
||||||
{
|
{
|
||||||
NSRect r;
|
NSRect r;
|
||||||
NSRect cellFrame;
|
NSRect cellFrame;
|
||||||
NSRect screenFrame;
|
NSRect screenFrame;
|
||||||
int items = [_itemCells count];
|
int items = [_itemCells count];
|
||||||
|
|
||||||
// Convert the screen rect to our view
|
[_titleView removeFromSuperview];
|
||||||
cellFrame.size = screenRect.size;
|
|
||||||
cellFrame.origin = [_window convertScreenToBase: screenRect.origin];
|
|
||||||
cellFrame = [self convertRect: cellFrame fromView: nil];
|
|
||||||
|
|
||||||
_cellSize = cellFrame.size;
|
// Convert the screen rect to our view
|
||||||
[self sizeToFit];
|
cellFrame.size = screenRect.size;
|
||||||
|
cellFrame.origin = [_window convertScreenToBase: screenRect.origin];
|
||||||
|
cellFrame = [self convertRect: cellFrame fromView: nil];
|
||||||
|
|
||||||
/*
|
_cellSize = cellFrame.size;
|
||||||
* Compute the frame
|
[self sizeToFit];
|
||||||
*/
|
|
||||||
screenFrame = screenRect;
|
|
||||||
if (items > 1)
|
|
||||||
{
|
|
||||||
float f;
|
|
||||||
|
|
||||||
if (_horizontal == NO)
|
/*
|
||||||
|
* Compute the frame
|
||||||
|
*/
|
||||||
|
screenFrame = screenRect;
|
||||||
|
if (items > 1)
|
||||||
{
|
{
|
||||||
f = screenRect.size.height * (items - 1);
|
float f;
|
||||||
screenFrame.size.height += f;
|
|
||||||
screenFrame.origin.y -= f;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
f = screenRect.size.width * (items - 1);
|
|
||||||
screenFrame.size.width += f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move the menu window to screen?
|
if (_horizontal == NO)
|
||||||
// TODO
|
{
|
||||||
|
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
|
// Move the menu window to screen?
|
||||||
if (selectedItemIndex != -1)
|
// TODO
|
||||||
{
|
|
||||||
if (_horizontal == NO)
|
// Compute position for popups, if needed
|
||||||
{
|
if (selectedItemIndex != -1)
|
||||||
screenFrame.origin.y += screenRect.size.height * selectedItemIndex;
|
{
|
||||||
|
if (_horizontal == NO)
|
||||||
|
{
|
||||||
|
screenFrame.origin.y += screenRect.size.height * selectedItemIndex;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
screenFrame.origin.x -= screenRect.size.width * selectedItemIndex;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
// Get the frameRect
|
||||||
screenFrame.origin.x -= screenRect.size.width * selectedItemIndex;
|
r = [NSWindow frameRectForContentRect: screenFrame
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the frameRect
|
|
||||||
r = [NSWindow frameRectForContentRect: screenFrame
|
|
||||||
styleMask: [_window styleMask]];
|
styleMask: [_window styleMask]];
|
||||||
|
|
||||||
// Update position,if needed, using the preferredEdge;
|
|
||||||
// TODO
|
|
||||||
|
|
||||||
// Set the window frame
|
// Update position,if needed, using the preferredEdge;
|
||||||
[_window setFrame: r display: NO];
|
// TODO
|
||||||
|
|
||||||
|
// Set the window frame
|
||||||
|
[_window setFrame: r display: NO];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -908,46 +915,27 @@ _addLeftBorderOffsetToRect(NSRect aRect, BOOL isHorizontal)
|
||||||
*/
|
*/
|
||||||
- (void) drawRect: (NSRect)rect
|
- (void) drawRect: (NSRect)rect
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int howMany = [_itemCells count];
|
int howMany = [_itemCells count];
|
||||||
|
NSRectEdge sides[] = {NSMinXEdge, NSMaxYEdge};
|
||||||
|
float grays[] = {NSDarkGray, NSDarkGray};
|
||||||
|
|
||||||
/* For popupButtons we do not want this dark line. */
|
// Draw the dark gray upper left lines.
|
||||||
|
NSDrawTiledRects(rect, rect, sides, grays, 2);
|
||||||
|
|
||||||
if (![_menu _ownedByPopUp])
|
// Draw the menu cells.
|
||||||
{
|
for (i = 0; i < howMany; i++)
|
||||||
NSGraphicsContext *ctxt = GSCurrentContext();
|
{
|
||||||
|
NSRect aRect;
|
||||||
|
NSMenuItemCell *aCell;
|
||||||
|
|
||||||
// Draw a dark gray line at the left of the menu item cells.
|
aRect = [self rectOfItemAtIndex: i];
|
||||||
DPSgsave(ctxt);
|
if (NSIntersectsRect(rect, aRect) == YES)
|
||||||
DPSsetlinewidth(ctxt, 1);
|
{
|
||||||
DPSsetgray(ctxt, NSDarkGray);
|
aCell = [_itemCells objectAtIndex: i];
|
||||||
if (_horizontal == NO)
|
[aCell drawWithFrame: aRect inView: self];
|
||||||
{
|
}
|
||||||
DPSmoveto(ctxt, NSMinX(_bounds), NSMinY(_bounds));
|
}
|
||||||
DPSrlineto(ctxt, 0, _bounds.size.height);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DPSmoveto(ctxt, NSMinX(_bounds), NSMaxY(_bounds));
|
|
||||||
DPSrlineto(ctxt, _bounds.size.width, 0);
|
|
||||||
}
|
|
||||||
DPSstroke(ctxt);
|
|
||||||
DPSgrestore(ctxt);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw the menu cells.
|
|
||||||
for (i = 0; i < howMany; i++)
|
|
||||||
{
|
|
||||||
NSRect aRect;
|
|
||||||
NSMenuItemCell *aCell;
|
|
||||||
|
|
||||||
aRect = [self rectOfItemAtIndex: i];
|
|
||||||
if (NSIntersectsRect(rect, aRect) == YES)
|
|
||||||
{
|
|
||||||
aCell = [_itemCells objectAtIndex: i];
|
|
||||||
[aCell drawWithFrame: aRect inView: self];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue