//
//  GlyphsToolEventProtocol.h
//  TestToolPlugin
//
//  Created by Georg Seifert on 4.7.07.
//  Copyright 2007 schriftgestaltung.de. All rights reserved.
//

#import <GlyphsCore/GlyphsCore.h>
#import <GlyphsApp/GlyphsToolAuxiliaryDrawing.h>

extern NSUInteger GSEventModifierFlagSpace;

@class GSLayer;

@protocol GSGlyphViewControllerProtocol;
@class GSEditViewController;

extern CGFloat ClickTolerance;

NS_ASSUME_NONNULL_BEGIN

/** Protocol for the Event handling parts of the tool API.

 All plugins should conform to this protocol. Additionally it could conform the GlyphsToolDraw it it needs to draw.

 The tool can implement all methods that are defined by [NSResponder](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSResponder_Class/)

 @see GlyphsToolDraw
*/
NS_SWIFT_UI_ACTOR
@protocol GlyphsToolEvent <GlyphsToolAuxiliaryDrawing>

/// The interface version.
@property (nonatomic, readonly) NSUInteger interfaceVersion NS_SWIFT_NONISOLATED;

#if !TARGET_OS_IOS
/** The trigger (key mask) to select the tool temporarily

 The select tool is selected with the cmd key. It returns NSEventModifierFlagCommand.
 */
@property (nonatomic, readonly) NSEventModifierFlags tempTrigger;
#endif

/** Set to YES while the mouse is down and dragging.

The setter should initialize the drag action. (set dragStart)
*/
@property (nonatomic) BOOL dragging;

/// The position where the dragging action started.
@property (nonatomic) NSPoint dragStart;

#if !TARGET_OS_IOS // TODO
/** Informs the receiver that the user has pressed or released a modifier key (Shift, Control, and so on).

 @param anEvent An object encapsulating information about the modifier-key event.
 */
- (void)modifierChanged:(NSEvent *)anEvent;
#endif

/** Is called when the tool is activated.

This might happen when the user selects the tool or when the document becomes active
@see willDeactivate
*/
- (void)willActivate;

/** Is called when the tool is deactivated.

 This might happen when the user deselects the tool or when the document becomes inactive
 @see willActivate
 */
- (void)willDeactivate;

/**
 A callback to let the tool know that a temp tool will be selected (by pressing a modifier key). You can return NO to prevent that.

 @param tempTool the temp tool that is about to become active

 @return if you allow it or not
 */
- (BOOL)willSelectTempTool:(id)tempTool;

/** Draws the active selection.
  The default is a colored drag rect.
 */
- (void)drawSelection;

@optional

/** Copy'n'Past Support */
- (void)copy:(nullable id)sender;

/** Copy'n'Past Support */
- (void)paste:(nullable id)sender;

/** Return a NSMenu object that should be displayed if the user presses/holds the mouse on the icon

@return A NSMenu object
*/
- (nullable NSMenu *)toolbarMenu;

- (nullable NSResponder<GlyphsToolEvent> *)eventHandler;

#if !TARGET_OS_IOS
- (void)mouseDoubleDown:(NSEvent *)theEvent;

- (nullable NSMenu *)defaultContextMenu;

/**
 Callback to allow to add something to the context menu

 @param theEvent the current event
 @param theMenu  the context menu to add to
 */
- (void)addMenuItemsForEvent:(NSEvent *)theEvent toMenu:(NSMenu *)theMenu;

- (void)addMenuItemsForEvent:(NSEvent *)theEvent controller:(GSEditViewController *)controller toMenu:(NSMenu *)theMenu;
#endif

/**
 returns all layers that are currently active. That is mostly used for the 'Select All Layers' tool.

 @return an array of layers
 */
- (NSArray<GSLayer *> *)activeLayers;

/// returns the view to place in the inspector
- (nullable NSArray *)inspectorViewControllers;

/// returns the view to place on the left of the normal inspector
- (nullable NSArray *)extraInspectorViewControllers;

- (nullable NSArray *)panelInspectors:(out BOOL *)hasHiddenPanels;

/// return true if the current selection state might show a "Info for Selection" dialog.
- (BOOL)canShowInfoForSelection;
/** actually show the info for Selection dialog

 is only called if canShowInfoForSelection returned YES.

 @see canShowInfoForSelection
 */
- (BOOL)showInfoForSelection;

- (GSWritingDirection)previewOrientation;

- (void)justAddedElement:(NSObject *)newElement;

- (void)justAddedElementsFromArray:(NSArray *)newElements;

- (nullable NSString *)stringForTooltipAtPoint:(NSPoint)point;

@end

@protocol GSInspectorViewControllerDelegate <NSObject>

- (nullable NSArray *)inspectorViewControllersForLayer:(nullable GSLayer *)layer;

/// used form the Edit View
- (nullable NSArray *)panelInspectorsForLayer:(nullable GSLayer *)layer;

/// used form the Font View
- (nullable NSArray *)panelInspectorsForSelectedLayers:(nullable NSArray *)layers;

@end

@protocol GSContextMenuCallbackProtocol <NSObject>
#if !TARGET_OS_IOS
#ifndef GLYPHS_LITE
+ (void)contextMenuCallback:(NSMenu *)menu forSelectedLayers:(nullable NSArray *)layers event:(nullable NSEvent *)event;
#endif
#endif
@end

@protocol GSSelectionChangeCallbackProtocol <NSObject>
#ifndef GLYPHS_LITE
+ (void)selectionDidChangeInLayer:(GSLayer *)layer;
#endif
@end

NS_ASSUME_NONNULL_END
