mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-20 22:37:21 +00:00
Added the possibility to rearrange toolbar items
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@19976 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
19e45d5c7b
commit
ef1010acc4
5 changed files with 387 additions and 39 deletions
|
@ -29,19 +29,24 @@
|
|||
#include <Foundation/NSObject.h>
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSDictionary.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSNotification.h>
|
||||
#include <Foundation/NSUserDefaults.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include "AppKit/NSToolbarItem.h"
|
||||
#include "AppKit/NSBezierPath.h"
|
||||
#include "AppKit/NSButton.h"
|
||||
#include "AppKit/NSClipView.h"
|
||||
#include "AppKit/NSColor.h"
|
||||
#include "AppKit/NSColorList.h"
|
||||
#include "AppKit/NSDragging.h"
|
||||
#include "AppKit/NSEvent.h"
|
||||
#include "AppKit/NSImage.h"
|
||||
#include "AppKit/NSMenu.h"
|
||||
#include "AppKit/NSPasteboard.h"
|
||||
#include "AppKit/NSToolbarItem.h" // It contains GSMovableToolbarItemPboardType declaration
|
||||
#include "AppKit/NSView.h"
|
||||
#include "AppKit/NSWindow.h"
|
||||
#include "GNUstepGUI/GSToolbar.h"
|
||||
#include "GNUstepGUI/GSToolbarView.h"
|
||||
|
||||
typedef enum {
|
||||
|
@ -138,6 +143,12 @@ static void initSystemExtensionsColors(void)
|
|||
*/
|
||||
@interface GSToolbar (GNUstepPrivate)
|
||||
- (void) _build;
|
||||
|
||||
- (void) _concludeRemoveItem: (NSToolbarItem *)item atIndex: (int)index broadcast: (BOOL)broadcast;
|
||||
- (int) _indexOfItem: (NSToolbarItem *)item;
|
||||
- (void) _insertPassivelyItem: (NSToolbarItem *)item atIndex: (int)newIndex;
|
||||
- (void) _moveItemFromIndex: (int)index toIndex: (int)newIndex broadcast: (BOOL)broacast;
|
||||
|
||||
- (void) _toolbarViewWillMoveToSuperview: (NSView *)newSuperview;
|
||||
|
||||
// Accessors
|
||||
|
@ -155,12 +166,21 @@ static void initSystemExtensionsColors(void)
|
|||
- (BOOL) _isFlexibleSpace;
|
||||
@end
|
||||
|
||||
@interface GSToolbarButton
|
||||
- (NSToolbarItem *) toolbarItem;
|
||||
@end
|
||||
|
||||
@interface GSToolbarBackView
|
||||
- (NSToolbarItem *) toolbarItem;
|
||||
@end
|
||||
|
||||
@interface GSToolbarView (GNUstepPrivate)
|
||||
- (void) _handleBackViewsFrame;
|
||||
- (void) _handleViewsVisibility;
|
||||
- (void) _reload;
|
||||
- (void) _setToolbar: (GSToolbar *)toolbar;
|
||||
- (void) _takeInAccountFlexibleSpaces;
|
||||
- (int) _insertionIndexAtPoint: (NSPoint)location;
|
||||
|
||||
// Accessors
|
||||
- (float) _heightFromLayout;
|
||||
|
@ -190,6 +210,13 @@ static void initSystemExtensionsColors(void)
|
|||
- (void) setToolbar: (GSToolbar *)toolbar;
|
||||
@end
|
||||
|
||||
@interface GSToolbarClipView : NSClipView
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation GSToolbarClippedItemsButton
|
||||
- (id) init
|
||||
{
|
||||
|
@ -279,6 +306,14 @@ static void initSystemExtensionsColors(void)
|
|||
}
|
||||
@end
|
||||
|
||||
// ---
|
||||
|
||||
@implementation GSToolbarClipView
|
||||
|
||||
// Nothing here
|
||||
|
||||
@end
|
||||
|
||||
// Implementation GSToolbarView
|
||||
|
||||
@implementation GSToolbarView
|
||||
|
@ -314,19 +349,19 @@ static void initSystemExtensionsColors(void)
|
|||
|
||||
switch (_sizeMode)
|
||||
{
|
||||
case NSToolbarSizeModeDefault:
|
||||
toolbarViewHeight = ToolbarViewDefaultHeight;
|
||||
break;
|
||||
case NSToolbarSizeModeRegular:
|
||||
toolbarViewHeight = ToolbarViewRegularHeight;
|
||||
break;
|
||||
case NSToolbarSizeModeSmall:
|
||||
toolbarViewHeight = ToolbarViewSmallHeight;
|
||||
break;
|
||||
default:
|
||||
// Raise exception
|
||||
toolbarViewHeight = 0;
|
||||
}
|
||||
case NSToolbarSizeModeDefault:
|
||||
toolbarViewHeight = ToolbarViewDefaultHeight;
|
||||
break;
|
||||
case NSToolbarSizeModeRegular:
|
||||
toolbarViewHeight = ToolbarViewRegularHeight;
|
||||
break;
|
||||
case NSToolbarSizeModeSmall:
|
||||
toolbarViewHeight = ToolbarViewSmallHeight;
|
||||
break;
|
||||
default:
|
||||
// Raise exception
|
||||
toolbarViewHeight = 0;
|
||||
}
|
||||
|
||||
[self setFrame: NSMakeRect(frame.origin.x,
|
||||
frame.origin.y,
|
||||
|
@ -335,7 +370,7 @@ static void initSystemExtensionsColors(void)
|
|||
|
||||
// ---
|
||||
|
||||
_clipView = [[NSClipView alloc] initWithFrame: NSMakeRect(0, 0, 100, 100)];
|
||||
_clipView = [[GSToolbarClipView alloc] initWithFrame: NSMakeRect(0, 0, 100, 100)];
|
||||
|
||||
[_clipView setAutoresizingMask: (NSViewWidthSizable |
|
||||
NSViewHeightSizable)];
|
||||
|
@ -355,6 +390,8 @@ static void initSystemExtensionsColors(void)
|
|||
// deallocated with the class when the application quits.
|
||||
|
||||
// ---
|
||||
|
||||
[self registerForDraggedTypes: [NSArray arrayWithObject: GSMovableToolbarItemPboardType]];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
@ -380,6 +417,68 @@ static void initSystemExtensionsColors(void)
|
|||
[super dealloc];
|
||||
}
|
||||
|
||||
// Dragging related methods
|
||||
|
||||
- (NSDragOperation) draggingEntered: (id <NSDraggingInfo>)info
|
||||
{
|
||||
if ([self _insertionIndexAtPoint: [info draggingLocation]] != NSNotFound);
|
||||
{
|
||||
return NSDragOperationGeneric;
|
||||
}
|
||||
|
||||
return NSDragOperationNone;
|
||||
}
|
||||
|
||||
- (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>)info
|
||||
{
|
||||
if ([self _insertionIndexAtPoint: [info draggingLocation]] != NSNotFound);
|
||||
{
|
||||
return NSDragOperationGeneric;
|
||||
}
|
||||
|
||||
return NSDragOperationNone;
|
||||
}
|
||||
|
||||
- (void) draggingEnded: (id <NSDraggingInfo>)info
|
||||
{
|
||||
NSPasteboard *pboard = [info draggingPasteboard];
|
||||
NSString *str = [pboard stringForType: [[pboard types] objectAtIndex: 0]];
|
||||
int index = [str intValue];
|
||||
GSToolbar *toolbar = [self toolbar];
|
||||
|
||||
[toolbar _concludeRemoveItem: [[info draggingSource] toolbarItem] atIndex: index broadcast: YES];
|
||||
}
|
||||
|
||||
- (void) draggingExited: (id <NSDraggingInfo>)info
|
||||
{
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
- (BOOL) prepareForDragOperation: (id <NSDraggingInfo>)info
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL) performDragOperation: (id <NSDraggingInfo>)info
|
||||
{
|
||||
NSPasteboard *pboard = [info draggingPasteboard];
|
||||
NSString *str = [pboard stringForType: [[pboard types] objectAtIndex: 0]];
|
||||
int index = [str intValue];
|
||||
GSToolbar *toolbar = [self toolbar];
|
||||
NSToolbarItem *item = [[info draggingSource] toolbarItem];
|
||||
int newIndex = [self _insertionIndexAtPoint: [info draggingLocation]]; // Calculate the index
|
||||
|
||||
[toolbar _insertPassivelyItem:item atIndex: index];
|
||||
RELEASE(item);
|
||||
[toolbar _moveItemFromIndex: index toIndex: newIndex broadcast: YES];
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void) concludeDragOperation: (id <NSDraggingInfo>)info
|
||||
{
|
||||
// Nothing to do currently
|
||||
}
|
||||
|
||||
// More overrided methods
|
||||
|
||||
- (void) drawRect: (NSRect)aRect
|
||||
|
@ -756,6 +855,25 @@ static void initSystemExtensionsColors(void)
|
|||
|
||||
}
|
||||
|
||||
- (int) _insertionIndexAtPoint: (NSPoint)location
|
||||
{
|
||||
id hitView = [self hitTest: location];
|
||||
NSRect hitViewFrame = [hitView frame];;
|
||||
int index;
|
||||
|
||||
if ((hitView != nil)
|
||||
& ([hitView isKindOfClass: [GSToolbarButton class]]
|
||||
|| [hitView isKindOfClass: [GSToolbarBackView class]]))
|
||||
{
|
||||
index = [_toolbar _indexOfItem: [hitView toolbarItem]];
|
||||
if (location.x - hitViewFrame.origin.x > hitViewFrame.size.width / 2)
|
||||
index++;
|
||||
|
||||
return index;
|
||||
}
|
||||
return NSNotFound;
|
||||
}
|
||||
|
||||
// Accessors private methods
|
||||
|
||||
- (float) _heightFromLayout
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue