Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 185 lines (156 sloc) 7.949 kb
c5cfe65 @ttscoff Slightly better way to handle adding scroll reset script.
ttscoff authored
1 //
2 // MAAttachedWindow.h
3 //
4 // Created by Matt Gemmell on 27/09/2007.
5 // Copyright 2007 Magic Aubergine.
6 //
7
8 #import <Cocoa/Cocoa.h>
9
10 /*
11 Below are the positions the attached window can be displayed at.
12
13 Note that these positions are relative to the point passed to the constructor,
14 e.g. MAPositionBottomRight will put the window below the point and towards the right,
15 MAPositionTop will horizontally center the window above the point,
16 MAPositionRightTop will put the window to the right and above the point,
17 and so on.
18
19 You can also pass MAPositionAutomatic (or use an initializer which omits the 'onSide:'
20 argument) and the attached window will try to position itself sensibly, based on
21 available screen-space.
22
23 Notes regarding automatically-positioned attached windows:
24
25 (a) The window prefers to position itself horizontally centered below the specified point.
26 This gives a certain enhanced visual sense of an attachment/relationship.
27
28 (b) The window will try to align itself with its parent window (if any); i.e. it will
29 attempt to stay within its parent window's frame if it can.
30
31 (c) The algorithm isn't perfect. :) If in doubt, do your own calculations and then
32 explicitly request that the window attach itself to a particular side.
33 */
34
35 typedef enum _MAWindowPosition {
36 // The four primary sides are compatible with the preferredEdge of NSDrawer.
37 MAPositionLeft = NSMinXEdge, // 0
38 MAPositionRight = NSMaxXEdge, // 2
39 MAPositionTop = NSMaxYEdge, // 3
40 MAPositionBottom = NSMinYEdge, // 1
41 MAPositionLeftTop = 4,
42 MAPositionLeftBottom = 5,
43 MAPositionRightTop = 6,
44 MAPositionRightBottom = 7,
45 MAPositionTopLeft = 8,
46 MAPositionTopRight = 9,
47 MAPositionBottomLeft = 10,
48 MAPositionBottomRight = 11,
49 MAPositionAutomatic = 12
50 } MAWindowPosition;
51
52 @interface MAAttachedWindow : NSWindow {
53 NSColor *borderColor;
54 float borderWidth;
55 float viewMargin;
56 float arrowBaseWidth;
57 float arrowHeight;
58 BOOL hasArrow;
59 float cornerRadius;
60 BOOL drawsRoundCornerBesideArrow;
61
62 @private
63 NSColor *_MABackgroundColor;
64 __weak NSView *_view;
65 __weak NSWindow *_window;
66 NSPoint _point;
67 MAWindowPosition _side;
68 float _distance;
69 NSRect _viewFrame;
70 BOOL _resizing;
71 }
72
73 /*
74 Initialization methods
75
76 Parameters:
77
78 view The view to display in the attached window. Must not be nil.
79
80 point The point to which the attached window should be attached. If you
81 are also specifying a parent window, the point should be in the
82 coordinate system of that parent window. If you are not specifying
83 a window, the point should be in the screen's coordinate space.
84 This value is required.
85
86 window The parent window to attach this one to. Note that no actual
87 relationship is created (particularly, this window is not made
88 a childWindow of the parent window).
89 Default: nil.
90
91 side The side of the specified point on which to attach this window.
92 Default: MAPositionAutomatic.
93
94 distance How far from the specified point this window should be.
95 Default: 0.
96 */
97
98 - (MAAttachedWindow *)initWithView:(NSView *)view // designated initializer
99 attachedToPoint:(NSPoint)point
100 inWindow:(NSWindow *)window
101 onSide:(MAWindowPosition)side
102 atDistance:(float)distance;
103 - (MAAttachedWindow *)initWithView:(NSView *)view
104 attachedToPoint:(NSPoint)point
105 inWindow:(NSWindow *)window
106 atDistance:(float)distance;
107 - (MAAttachedWindow *)initWithView:(NSView *)view
108 attachedToPoint:(NSPoint)point
109 onSide:(MAWindowPosition)side
110 atDistance:(float)distance;
111 - (MAAttachedWindow *)initWithView:(NSView *)view
112 attachedToPoint:(NSPoint)point
113 atDistance:(float)distance;
114 - (MAAttachedWindow *)initWithView:(NSView *)view
115 attachedToPoint:(NSPoint)point
116 inWindow:(NSWindow *)window;
117 - (MAAttachedWindow *)initWithView:(NSView *)view
118 attachedToPoint:(NSPoint)point
119 onSide:(MAWindowPosition)side;
120 - (MAAttachedWindow *)initWithView:(NSView *)view
121 attachedToPoint:(NSPoint)point;
122
123 // Accessor methods
124 - (void)setPoint:(NSPoint)point side:(MAWindowPosition)side;
125 - (NSColor *)borderColor;
126 - (void)setBorderColor:(NSColor *)value;
127 - (float)borderWidth;
128 - (void)setBorderWidth:(float)value; // See note 1 below.
129 - (float)viewMargin;
130 - (void)setViewMargin:(float)value; // See note 2 below.
131 - (float)arrowBaseWidth;
132 - (void)setArrowBaseWidth:(float)value; // See note 2 below.
133 - (float)arrowHeight;
134 - (void)setArrowHeight:(float)value; // See note 2 below.
135 - (float)hasArrow;
136 - (void)setHasArrow:(float)value;
137 - (float)cornerRadius;
138 - (void)setCornerRadius:(float)value; // See note 2 below.
139 - (float)drawsRoundCornerBesideArrow; // See note 3 below.
140 - (void)setDrawsRoundCornerBesideArrow:(float)value; // See note 2 below.
141 - (void)setBackgroundImage:(NSImage *)value;
142 - (NSColor *)windowBackgroundColor; // See note 4 below.
143 - (void)setBackgroundColor:(NSColor *)value;
144
145 /*
146 Notes regarding accessor methods:
147
148 1. The border is drawn inside the viewMargin area, expanding inwards; it does not
149 increase the width/height of the window. You can use the -setBorderWidth: and
150 -setViewMargin: methods together to achieve the exact look/geometry you want.
151 (viewMargin is the distance between the edge of the view and the window edge.)
152
153 2. The specified setter methods are primarily intended to be used _before_ the window
154 is first shown. If you use them while the window is already visible, be aware
155 that they may cause the window to move and/or resize, in order to stay anchored
156 to the point specified in the initializer. They may also cause the view to move
157 within the window, in order to remain centered there.
158
159 Note that the -setHasArrow: method can safely be used at any time, and will not
160 cause moving/resizing of the window. This is for convenience, in case you want
161 to add or remove the arrow in response to user interaction. For example, you
162 could make the attached window movable by its background, and if the user dragged
163 it away from its initial point, the arrow could be removed. This would duplicate
164 how Aperture's attached windows behave.
165
166 3. drawsRoundCornerBesideArrow takes effect when the arrow is being drawn at a corner,
167 i.e. when it's not at one of the four primary compass directions. In this situation,
168 if drawsRoundCornerBesideArrow is YES (the default), then that corner of the window
169 will be rounded just like the other three corners, thus the arrow will be inset
170 slightly from the edge of the window to allow room for the rounded corner. If this
171 value is NO, the corner beside the arrow will be a square corner, and the other
172 three corners will be rounded.
173
174 This is useful when you want to attach a window very near the edge of another window,
175 and don't want the attached window's edge to be visually outside the frame of the
176 parent window.
177
178 4. Note that to retrieve the background color of the window, you should use the
179 -windowBackgroundColor method, instead of -backgroundColor. This is because we draw
180 the entire background of the window (rounded path, arrow, etc) in an NSColor pattern
181 image, and set it as the backgroundColor of the window.
182 */
183
184 @end
Something went wrong with that request. Please try again.