1 | /*-------------------------------------------------------------------------------------------------------*\ |
---|
2 | | Adium, Copyright (C) 2001-2005, Adam Iser (adamiser@mac.com | http://www.adiumx.com) | |
---|
3 | \---------------------------------------------------------------------------------------------------------/ |
---|
4 | | This program is free software; you can redistribute it and/or modify it under the terms of the GNU |
---|
5 | | General Public License as published by the Free Software Foundation; either version 2 of the License, |
---|
6 | | or (at your option) any later version. |
---|
7 | | |
---|
8 | | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even |
---|
9 | | the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
---|
10 | | Public License for more details. |
---|
11 | | |
---|
12 | | You should have received a copy of the GNU General Public License along with this program; if not, |
---|
13 | | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
14 | \------------------------------------------------------------------------------------------------------ */ |
---|
15 | |
---|
16 | /*! @brief Obtains the high and low surrogate for a Unicode code-point. |
---|
17 | * |
---|
18 | * If \a in is lower than U+10FFF (which means it would not require surrogates to construct), \c *outHigh will be 0, and \c *outLow will be \a in. |
---|
19 | * |
---|
20 | * @return The high and low surrogate (if applicable), or 0 and the input character. |
---|
21 | */ |
---|
22 | BOOL AIGetSurrogates(UTF32Char in, UTF16Char *outHigh, UTF16Char *outLow); |
---|
23 | |
---|
24 | #pragma mark Wired memory |
---|
25 | /*! @defgroup AIWiredMemory Wired memory |
---|
26 | * |
---|
27 | * Functions for allocating and handling wired memory. |
---|
28 | */ |
---|
29 | /*@{*/ |
---|
30 | |
---|
31 | /*! @brief Clobbers a region of memory with gibberish. |
---|
32 | * |
---|
33 | * Use this to sanitize memory that you don't want to be viewed in the future. For example, if you had a password in this memory, you would clobber it using this function so that the password cannot be peeked later. |
---|
34 | */ |
---|
35 | void AIWipeMemory(void *buf, size_t len); |
---|
36 | /*! @brief Allocate or resize a region of wired memory. |
---|
37 | * |
---|
38 | * AIReallocWired is for use with wired memory. It returns a block that is already wired in core memory. |
---|
39 | * Before freeing the old block, it wipes (see AIWipeMemory) and unlocks it. |
---|
40 | * |
---|
41 | * If the new block could not be allocated or wired, the old block is still valid, wired, and unchanged. |
---|
42 | * All other aspects of its behaviour are the same as \c realloc(3) (for example, \c realloc(NULL, x) == \c malloc(x)). |
---|
43 | * When you are done with the memory, call \c munlock on it, followed by \c free. |
---|
44 | * |
---|
45 | * @return The new region of memory, or \c NULL if one could not be created and wired. |
---|
46 | */ |
---|
47 | void *AIReallocWired(void *oldBuf, size_t newLen); |
---|
48 | |
---|
49 | /*! @brief Sets every byte in \a buf within \a range to \a ch. |
---|
50 | * Qux. |
---|
51 | */ |
---|
52 | void AISetRangeInMemory(void *buf, NSRange range, int ch); |
---|
53 | |
---|
54 | /*@}*/ |
---|
55 | |
---|
56 | #pragma mark Rect utilities |
---|
57 | /*! @defgroup AIRectUtilities Rectangle utilities |
---|
58 | * |
---|
59 | * Functions for managing the placement and alignment of rectangles relative to other rectangles. |
---|
60 | */ |
---|
61 | /*@{*/ |
---|
62 | |
---|
63 | /*! @enum AIRectEdgeMask |
---|
64 | * A bit mask of zero or more edges of a rectangle. |
---|
65 | */ |
---|
66 | typedef enum AIRectEdgeMask { |
---|
67 | //!No edges. |
---|
68 | AINoEdges = 0, |
---|
69 | //!Far right. |
---|
70 | AIMaxXEdgeMask = (1 << NSMaxXEdge), |
---|
71 | //!Top. |
---|
72 | AIMaxYEdgeMask = (1 << NSMaxYEdge), |
---|
73 | //!Far left. |
---|
74 | AIMinXEdgeMask = (1 << NSMinXEdge), |
---|
75 | //!Bottom. |
---|
76 | AIMinYEdgeMask = (1 << NSMinYEdge) |
---|
77 | } AIRectEdgeMask; |
---|
78 | |
---|
79 | enum { |
---|
80 | //!This value in an NSRectEdge variable indicates no edge. |
---|
81 | AINotARectEdge = -1 |
---|
82 | }; |
---|
83 | |
---|
84 | /*! @brief Returns the coordinate for an edge of a rectangle. |
---|
85 | * |
---|
86 | * For example, AICoordinateForRect_edge_(rect, NSMaxXEdge) is the same as NSMaxX(rect). |
---|
87 | * |
---|
88 | * @return An X or Y coordinate. |
---|
89 | */ |
---|
90 | float AICoordinateForRect_edge_(NSRect rect, NSRectEdge edge); |
---|
91 | |
---|
92 | /*! @brief Measures a line from \a edge to \a point. |
---|
93 | * |
---|
94 | * Returns the distance that \a point lies outside of \a rect on a particular side (\a edge). |
---|
95 | * If the point lies on the interior side of that edge, the number returned will be negative, even if the point is outside the rectangle itself. |
---|
96 | * For example, if \c rect.origin.x is 50, and \c rect.size.width is 50, and \c point.x is 25, and \a edge is \c NSMaxXEdge, the result will be -75.0f. |
---|
97 | * |
---|
98 | * @return The distance between the edge and the point. It is positive if the point is outside the edge, negative if it is inside the edge (even it is outside the rectangle). |
---|
99 | */ |
---|
100 | float AISignedExteriorDistanceRect_edge_toPoint_(NSRect rect, NSRectEdge edge, NSPoint point); |
---|
101 | |
---|
102 | /*! @brief Returns the edge that would be across a rectangle from \a edge. |
---|
103 | * |
---|
104 | * For example, AIOppositeRectEdge_(NSMaxXEdge) is NSMinXEdge. |
---|
105 | * |
---|
106 | * @return An edge. |
---|
107 | */ |
---|
108 | NSRectEdge AIOppositeRectEdge_(NSRectEdge edge); |
---|
109 | |
---|
110 | // translate mobileRect so that it aligns with stationaryRect |
---|
111 | // undefined if aligning left to top or something else that does not make sense |
---|
112 | NSRect AIRectByAligningRect_edge_toRect_edge_(NSRect mobileRect, |
---|
113 | NSRectEdge mobileRectEdge, |
---|
114 | NSRect stationaryRect, |
---|
115 | NSRectEdge stationaryRectEdge); |
---|
116 | |
---|
117 | /*! @brief Returns whether \a edge1 of \a rect1 is within \a tolerance units of \a edge2 of \a rect2. |
---|
118 | * @return \c YES if the distance between the two edges is less than \a tolerance; \c NO if not. |
---|
119 | */ |
---|
120 | BOOL AIRectIsAligned_edge_toRect_edge_tolerance_(NSRect rect1, |
---|
121 | NSRectEdge edge1, |
---|
122 | NSRect rect2, |
---|
123 | NSRectEdge edge2, |
---|
124 | float tolerance); |
---|
125 | |
---|
126 | // minimally translate mobileRect so that it lies within stationaryRect |
---|
127 | NSRect AIRectByMovingRect_intoRect_(NSRect mobileRect, NSRect stationaryRect); |
---|
128 | |
---|
129 | /*@}*/ |
---|