diff options
| author | YAMAMOTO Mitsuharu | 2007-06-14 08:39:29 +0000 |
|---|---|---|
| committer | YAMAMOTO Mitsuharu | 2007-06-14 08:39:29 +0000 |
| commit | c6829f81ad9bca81d6b688c01783e96447bbcd4e (patch) | |
| tree | 4db0325fb4f78227d3b5754e72b867a0d1328578 /src | |
| parent | 1bd0c76127b3b35a356237c8e7cc3064a0ff2392 (diff) | |
| download | emacs-c6829f81ad9bca81d6b688c01783e96447bbcd4e.tar.gz emacs-c6829f81ad9bca81d6b688c01783e96447bbcd4e.zip | |
(x_draw_fringe_bitmap) [MAC_OSX]: Extend fringe
background to scroll bar gap.
(x_scroll_bar_create) [MAC_OSX]: Set bar->fringe_extended_p.
(XTset_vertical_scroll_bar) [MAC_OSX]: Put leftmost/rightmost
scroll bars on frame edge. Check fringe background extension.
Don't clear extended fringe background area.
(TOOLBAR_IDENTIFIER, TOOLBAR_ICON_ITEM_IDENTIFIER)
(TOOLBAR_ITEM_COMMAND_ID_OFFSET, TOOLBAR_ITEM_COMMAND_ID_P)
(TOOLBAR_ITEM_COMMAND_ID_VALUE, TOOLBAR_ITEM_MAKE_COMMAND_ID):
[USE_MAC_TOOLBAR]: New macros.
(mac_move_window_with_gravity, mac_get_window_origin_with_gravity)
(mac_handle_toolbar_event, mac_image_spec_to_cg_image)
(mac_create_frame_tool_bar, update_frame_tool_bar, free_frame_tool_bar)
(mac_tool_bar_note_mouse_movement, mac_handle_toolbar_command_event)
[USE_MAC_TOOLBAR]: New functions.
(mac_handle_window_event) [USE_MAC_TOOLBAR]: Reposition window
manually if previous repositioning has failed.
(mac_handle_keyboard_event): Use precomputed event kind.
(XTread_socket) [USE_MAC_TOOLBAR]: Handle click in structure region
as tool bar item click. Handle mouse movement over tool bar items.
Diffstat (limited to 'src')
| -rw-r--r-- | src/macterm.c | 662 |
1 files changed, 655 insertions, 7 deletions
diff --git a/src/macterm.c b/src/macterm.c index bdeedfb9ab6..85799cddc23 100644 --- a/src/macterm.c +++ b/src/macterm.c | |||
| @@ -2195,6 +2195,57 @@ x_draw_fringe_bitmap (w, row, p) | |||
| 2195 | struct face *face = p->face; | 2195 | struct face *face = p->face; |
| 2196 | int rowY; | 2196 | int rowY; |
| 2197 | 2197 | ||
| 2198 | #ifdef MAC_OSX | ||
| 2199 | if (p->bx >= 0 && !p->overlay_p) | ||
| 2200 | { | ||
| 2201 | int bx = p->bx, nx = p->nx; | ||
| 2202 | |||
| 2203 | #if 0 /* MAC_TODO: stipple */ | ||
| 2204 | /* In case the same realized face is used for fringes and | ||
| 2205 | for something displayed in the text (e.g. face `region' on | ||
| 2206 | mono-displays, the fill style may have been changed to | ||
| 2207 | FillSolid in x_draw_glyph_string_background. */ | ||
| 2208 | if (face->stipple) | ||
| 2209 | XSetFillStyle (FRAME_X_DISPLAY (f), face->gc, FillOpaqueStippled); | ||
| 2210 | else | ||
| 2211 | XSetForeground (FRAME_X_DISPLAY (f), face->gc, face->background); | ||
| 2212 | #endif | ||
| 2213 | |||
| 2214 | /* If the fringe is adjacent to the left (right) scroll bar of a | ||
| 2215 | leftmost (rightmost, respectively) window, then extend its | ||
| 2216 | background to the gap between the fringe and the bar. */ | ||
| 2217 | if ((WINDOW_LEFTMOST_P (w) | ||
| 2218 | && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w)) | ||
| 2219 | || (WINDOW_RIGHTMOST_P (w) | ||
| 2220 | && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w))) | ||
| 2221 | { | ||
| 2222 | int sb_width = WINDOW_CONFIG_SCROLL_BAR_WIDTH (w); | ||
| 2223 | |||
| 2224 | if (sb_width > 0) | ||
| 2225 | { | ||
| 2226 | int left = WINDOW_SCROLL_BAR_AREA_X (w); | ||
| 2227 | int width = (WINDOW_CONFIG_SCROLL_BAR_COLS (w) | ||
| 2228 | * FRAME_COLUMN_WIDTH (f)); | ||
| 2229 | |||
| 2230 | if (left + width == bx) | ||
| 2231 | { | ||
| 2232 | bx = left + sb_width; | ||
| 2233 | nx += width - sb_width; | ||
| 2234 | } | ||
| 2235 | else if (bx + nx == left) | ||
| 2236 | nx += width - sb_width; | ||
| 2237 | } | ||
| 2238 | } | ||
| 2239 | |||
| 2240 | mac_erase_rectangle (f, face->gc, bx, p->by, nx, p->ny); | ||
| 2241 | |||
| 2242 | #if 0 /* MAC_TODO: stipple */ | ||
| 2243 | if (!face->stipple) | ||
| 2244 | XSetForeground (FRAME_X_DISPLAY (f), face->gc, face->foreground); | ||
| 2245 | #endif | ||
| 2246 | } | ||
| 2247 | #endif /* MAC_OSX */ | ||
| 2248 | |||
| 2198 | /* Must clip because of partially visible lines. */ | 2249 | /* Must clip because of partially visible lines. */ |
| 2199 | rowY = WINDOW_TO_FRAME_PIXEL_Y (w, row->y); | 2250 | rowY = WINDOW_TO_FRAME_PIXEL_Y (w, row->y); |
| 2200 | if (p->y < rowY) | 2251 | if (p->y < rowY) |
| @@ -2212,6 +2263,7 @@ x_draw_fringe_bitmap (w, row, p) | |||
| 2212 | else | 2263 | else |
| 2213 | x_clip_to_row (w, row, -1, face->gc); | 2264 | x_clip_to_row (w, row, -1, face->gc); |
| 2214 | 2265 | ||
| 2266 | #ifndef MAC_OSX | ||
| 2215 | if (p->bx >= 0 && !p->overlay_p) | 2267 | if (p->bx >= 0 && !p->overlay_p) |
| 2216 | { | 2268 | { |
| 2217 | #if 0 /* MAC_TODO: stipple */ | 2269 | #if 0 /* MAC_TODO: stipple */ |
| @@ -2232,6 +2284,7 @@ x_draw_fringe_bitmap (w, row, p) | |||
| 2232 | XSetForeground (FRAME_X_DISPLAY (f), face->gc, face->foreground); | 2284 | XSetForeground (FRAME_X_DISPLAY (f), face->gc, face->foreground); |
| 2233 | #endif | 2285 | #endif |
| 2234 | } | 2286 | } |
| 2287 | #endif /* !MAC_OSX */ | ||
| 2235 | 2288 | ||
| 2236 | if (p->which | 2289 | if (p->which |
| 2237 | #if USE_CG_DRAWING | 2290 | #if USE_CG_DRAWING |
| @@ -4995,6 +5048,9 @@ x_scroll_bar_create (w, top, left, width, height, disp_top, disp_height) | |||
| 4995 | XSETINT (bar->start, 0); | 5048 | XSETINT (bar->start, 0); |
| 4996 | XSETINT (bar->end, 0); | 5049 | XSETINT (bar->end, 0); |
| 4997 | bar->dragging = Qnil; | 5050 | bar->dragging = Qnil; |
| 5051 | #ifdef MAC_OSX | ||
| 5052 | bar->fringe_extended_p = Qnil; | ||
| 5053 | #endif | ||
| 4998 | #ifdef USE_TOOLKIT_SCROLL_BARS | 5054 | #ifdef USE_TOOLKIT_SCROLL_BARS |
| 4999 | bar->track_top = Qnil; | 5055 | bar->track_top = Qnil; |
| 5000 | bar->track_height = Qnil; | 5056 | bar->track_height = Qnil; |
| @@ -5127,6 +5183,9 @@ XTset_vertical_scroll_bar (w, portion, whole, position) | |||
| 5127 | struct scroll_bar *bar; | 5183 | struct scroll_bar *bar; |
| 5128 | int top, height, left, sb_left, width, sb_width, disp_top, disp_height; | 5184 | int top, height, left, sb_left, width, sb_width, disp_top, disp_height; |
| 5129 | int window_y, window_height; | 5185 | int window_y, window_height; |
| 5186 | #ifdef MAC_OSX | ||
| 5187 | int fringe_extended_p; | ||
| 5188 | #endif | ||
| 5130 | 5189 | ||
| 5131 | /* Get window dimensions. */ | 5190 | /* Get window dimensions. */ |
| 5132 | window_box (w, -1, 0, &window_y, 0, &window_height); | 5191 | window_box (w, -1, 0, &window_y, 0, &window_height); |
| @@ -5146,9 +5205,9 @@ XTset_vertical_scroll_bar (w, portion, whole, position) | |||
| 5146 | 5205 | ||
| 5147 | /* Compute the left edge of the scroll bar. */ | 5206 | /* Compute the left edge of the scroll bar. */ |
| 5148 | if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w)) | 5207 | if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w)) |
| 5149 | sb_left = left; | 5208 | sb_left = left + (WINDOW_RIGHTMOST_P (w) ? width - sb_width : 0); |
| 5150 | else | 5209 | else |
| 5151 | sb_left = left + width - sb_width; | 5210 | sb_left = left + (WINDOW_LEFTMOST_P (w) ? 0 : width - sb_width); |
| 5152 | 5211 | ||
| 5153 | /* Adjustments according to Inside Macintosh to make it look nice */ | 5212 | /* Adjustments according to Inside Macintosh to make it look nice */ |
| 5154 | disp_top = top; | 5213 | disp_top = top; |
| @@ -5169,11 +5228,29 @@ XTset_vertical_scroll_bar (w, portion, whole, position) | |||
| 5169 | sb_left++; | 5228 | sb_left++; |
| 5170 | #endif | 5229 | #endif |
| 5171 | 5230 | ||
| 5231 | #ifdef MAC_OSX | ||
| 5232 | if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w)) | ||
| 5233 | fringe_extended_p = (WINDOW_LEFTMOST_P (w) | ||
| 5234 | && WINDOW_LEFT_FRINGE_WIDTH (w) | ||
| 5235 | && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w) | ||
| 5236 | || WINDOW_LEFT_MARGIN_COLS (w) == 0)); | ||
| 5237 | else | ||
| 5238 | fringe_extended_p = (WINDOW_RIGHTMOST_P (w) | ||
| 5239 | && WINDOW_RIGHT_FRINGE_WIDTH (w) | ||
| 5240 | && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w) | ||
| 5241 | || WINDOW_RIGHT_MARGIN_COLS (w) == 0)); | ||
| 5242 | #endif | ||
| 5243 | |||
| 5172 | /* Does the scroll bar exist yet? */ | 5244 | /* Does the scroll bar exist yet? */ |
| 5173 | if (NILP (w->vertical_scroll_bar)) | 5245 | if (NILP (w->vertical_scroll_bar)) |
| 5174 | { | 5246 | { |
| 5175 | BLOCK_INPUT; | 5247 | BLOCK_INPUT; |
| 5176 | mac_clear_area (f, left, top, width, height); | 5248 | #ifdef MAC_OSX |
| 5249 | if (fringe_extended_p) | ||
| 5250 | mac_clear_area (f, sb_left, top, sb_width, height); | ||
| 5251 | else | ||
| 5252 | #endif | ||
| 5253 | mac_clear_area (f, left, top, width, height); | ||
| 5177 | UNBLOCK_INPUT; | 5254 | UNBLOCK_INPUT; |
| 5178 | bar = x_scroll_bar_create (w, top, sb_left, sb_width, height, disp_top, | 5255 | bar = x_scroll_bar_create (w, top, sb_left, sb_width, height, disp_top, |
| 5179 | disp_height); | 5256 | disp_height); |
| @@ -5193,11 +5270,20 @@ XTset_vertical_scroll_bar (w, portion, whole, position) | |||
| 5193 | if (!(XINT (bar->left) == sb_left | 5270 | if (!(XINT (bar->left) == sb_left |
| 5194 | && XINT (bar->top) == top | 5271 | && XINT (bar->top) == top |
| 5195 | && XINT (bar->width) == sb_width | 5272 | && XINT (bar->width) == sb_width |
| 5196 | && XINT (bar->height) == height)) | 5273 | && XINT (bar->height) == height |
| 5274 | #ifdef MAC_OSX | ||
| 5275 | && !NILP (bar->fringe_extended_p) == fringe_extended_p | ||
| 5276 | #endif | ||
| 5277 | )) | ||
| 5197 | { | 5278 | { |
| 5198 | /* Since toolkit scroll bars are smaller than the space reserved | 5279 | /* Since toolkit scroll bars are smaller than the space reserved |
| 5199 | for them on the frame, we have to clear "under" them. */ | 5280 | for them on the frame, we have to clear "under" them. */ |
| 5200 | mac_clear_area (f, left, top, width, height); | 5281 | #ifdef MAC_OSX |
| 5282 | if (fringe_extended_p) | ||
| 5283 | mac_clear_area (f, sb_left, top, sb_width, height); | ||
| 5284 | else | ||
| 5285 | #endif | ||
| 5286 | mac_clear_area (f, left, top, width, height); | ||
| 5201 | 5287 | ||
| 5202 | #if USE_CG_DRAWING | 5288 | #if USE_CG_DRAWING |
| 5203 | mac_prepare_for_quickdraw (f); | 5289 | mac_prepare_for_quickdraw (f); |
| @@ -5226,6 +5312,10 @@ XTset_vertical_scroll_bar (w, portion, whole, position) | |||
| 5226 | UNBLOCK_INPUT; | 5312 | UNBLOCK_INPUT; |
| 5227 | } | 5313 | } |
| 5228 | 5314 | ||
| 5315 | #ifdef MAC_OSX | ||
| 5316 | bar->fringe_extended_p = fringe_extended_p ? Qt : Qnil; | ||
| 5317 | #endif | ||
| 5318 | |||
| 5229 | #ifdef USE_TOOLKIT_SCROLL_BARS | 5319 | #ifdef USE_TOOLKIT_SCROLL_BARS |
| 5230 | if (NILP (bar->track_top)) | 5320 | if (NILP (bar->track_top)) |
| 5231 | { | 5321 | { |
| @@ -5589,6 +5679,539 @@ x_scroll_bar_clear (f) | |||
| 5589 | 5679 | ||
| 5590 | 5680 | ||
| 5591 | /*********************************************************************** | 5681 | /*********************************************************************** |
| 5682 | Tool-bars | ||
| 5683 | ***********************************************************************/ | ||
| 5684 | #if USE_MAC_TOOLBAR | ||
| 5685 | |||
| 5686 | /* In identifiers such as function/variable names, Emacs tool bar is | ||
| 5687 | referred to as `tool_bar', and Carbon HIToolbar as `toolbar'. */ | ||
| 5688 | |||
| 5689 | #define TOOLBAR_IDENTIFIER (CFSTR ("org.gnu.Emacs.toolbar")) | ||
| 5690 | #define TOOLBAR_ICON_ITEM_IDENTIFIER (CFSTR ("org.gnu.Emacs.toolbar.icon")) | ||
| 5691 | |||
| 5692 | #define TOOLBAR_ITEM_COMMAND_ID_OFFSET 'Tb\0\0' | ||
| 5693 | #define TOOLBAR_ITEM_COMMAND_ID_P(id) \ | ||
| 5694 | (((id) & ~0xffff) == TOOLBAR_ITEM_COMMAND_ID_OFFSET) | ||
| 5695 | #define TOOLBAR_ITEM_COMMAND_ID_VALUE(id) \ | ||
| 5696 | ((id) - TOOLBAR_ITEM_COMMAND_ID_OFFSET) | ||
| 5697 | #define TOOLBAR_ITEM_MAKE_COMMAND_ID(value) \ | ||
| 5698 | ((value) + TOOLBAR_ITEM_COMMAND_ID_OFFSET) | ||
| 5699 | |||
| 5700 | static int mac_event_to_emacs_modifiers P_ ((EventRef)); | ||
| 5701 | static void mac_handle_origin_change P_ ((struct frame *)); | ||
| 5702 | static OSStatus mac_handle_toolbar_command_event P_ ((EventHandlerCallRef, | ||
| 5703 | EventRef, void *)); | ||
| 5704 | |||
| 5705 | static void | ||
| 5706 | mac_move_window_with_gravity (f, win_gravity, left, top) | ||
| 5707 | struct frame *f; | ||
| 5708 | int win_gravity; | ||
| 5709 | short left, top; | ||
| 5710 | { | ||
| 5711 | Rect inner, outer; | ||
| 5712 | |||
| 5713 | mac_get_window_bounds (f, &inner, &outer); | ||
| 5714 | |||
| 5715 | switch (win_gravity) | ||
| 5716 | { | ||
| 5717 | case NorthWestGravity: | ||
| 5718 | case WestGravity: | ||
| 5719 | case SouthWestGravity: | ||
| 5720 | left += inner.left - outer.left; | ||
| 5721 | break; | ||
| 5722 | |||
| 5723 | case NorthGravity: | ||
| 5724 | case CenterGravity: | ||
| 5725 | case SouthGravity: | ||
| 5726 | left += ((inner.left - outer.left) + (inner.right - outer.right)) / 2; | ||
| 5727 | break; | ||
| 5728 | |||
| 5729 | case NorthEastGravity: | ||
| 5730 | case EastGravity: | ||
| 5731 | case SouthEastGravity: | ||
| 5732 | left += inner.right - outer.right; | ||
| 5733 | break; | ||
| 5734 | } | ||
| 5735 | |||
| 5736 | switch (win_gravity) | ||
| 5737 | { | ||
| 5738 | case NorthWestGravity: | ||
| 5739 | case NorthGravity: | ||
| 5740 | case NorthEastGravity: | ||
| 5741 | top += inner.top - outer.top; | ||
| 5742 | break; | ||
| 5743 | |||
| 5744 | case WestGravity: | ||
| 5745 | case CenterGravity: | ||
| 5746 | case EastGravity: | ||
| 5747 | top += ((inner.top - outer.top) + (inner.bottom - outer.bottom)) / 2; | ||
| 5748 | break; | ||
| 5749 | |||
| 5750 | case SouthWestGravity: | ||
| 5751 | case SouthGravity: | ||
| 5752 | case SouthEastGravity: | ||
| 5753 | top += inner.bottom - outer.bottom; | ||
| 5754 | break; | ||
| 5755 | } | ||
| 5756 | |||
| 5757 | MoveWindow (FRAME_MAC_WINDOW (f), left, top, false); | ||
| 5758 | } | ||
| 5759 | |||
| 5760 | static void | ||
| 5761 | mac_get_window_origin_with_gravity (f, win_gravity, left, top) | ||
| 5762 | struct frame *f; | ||
| 5763 | int win_gravity; | ||
| 5764 | short *left, *top; | ||
| 5765 | { | ||
| 5766 | Rect inner, outer; | ||
| 5767 | |||
| 5768 | mac_get_window_bounds (f, &inner, &outer); | ||
| 5769 | |||
| 5770 | switch (win_gravity) | ||
| 5771 | { | ||
| 5772 | case NorthWestGravity: | ||
| 5773 | case WestGravity: | ||
| 5774 | case SouthWestGravity: | ||
| 5775 | *left = outer.left; | ||
| 5776 | break; | ||
| 5777 | |||
| 5778 | case NorthGravity: | ||
| 5779 | case CenterGravity: | ||
| 5780 | case SouthGravity: | ||
| 5781 | *left = outer.left + ((outer.right - outer.left) | ||
| 5782 | - (inner.right - inner.left)) / 2; | ||
| 5783 | break; | ||
| 5784 | |||
| 5785 | case NorthEastGravity: | ||
| 5786 | case EastGravity: | ||
| 5787 | case SouthEastGravity: | ||
| 5788 | *left = outer.right - (inner.right - inner.left); | ||
| 5789 | break; | ||
| 5790 | } | ||
| 5791 | |||
| 5792 | switch (win_gravity) | ||
| 5793 | { | ||
| 5794 | case NorthWestGravity: | ||
| 5795 | case NorthGravity: | ||
| 5796 | case NorthEastGravity: | ||
| 5797 | *top = outer.top; | ||
| 5798 | break; | ||
| 5799 | |||
| 5800 | case WestGravity: | ||
| 5801 | case CenterGravity: | ||
| 5802 | case EastGravity: | ||
| 5803 | *top = outer.top + ((outer.bottom - outer.top) | ||
| 5804 | - (inner.bottom - inner.top)) / 2; | ||
| 5805 | break; | ||
| 5806 | |||
| 5807 | case SouthWestGravity: | ||
| 5808 | case SouthGravity: | ||
| 5809 | case SouthEastGravity: | ||
| 5810 | *top = outer.bottom - (inner.bottom - inner.top); | ||
| 5811 | break; | ||
| 5812 | } | ||
| 5813 | } | ||
| 5814 | |||
| 5815 | static OSStatus | ||
| 5816 | mac_handle_toolbar_event (next_handler, event, data) | ||
| 5817 | EventHandlerCallRef next_handler; | ||
| 5818 | EventRef event; | ||
| 5819 | void *data; | ||
| 5820 | { | ||
| 5821 | OSStatus err, result = eventNotHandledErr; | ||
| 5822 | |||
| 5823 | switch (GetEventKind (event)) | ||
| 5824 | { | ||
| 5825 | case kEventToolbarGetDefaultIdentifiers: | ||
| 5826 | result = noErr; | ||
| 5827 | break; | ||
| 5828 | |||
| 5829 | case kEventToolbarGetAllowedIdentifiers: | ||
| 5830 | { | ||
| 5831 | CFMutableArrayRef array; | ||
| 5832 | |||
| 5833 | GetEventParameter (event, kEventParamMutableArray, | ||
| 5834 | typeCFMutableArrayRef, NULL, | ||
| 5835 | sizeof (CFMutableArrayRef), NULL, &array); | ||
| 5836 | CFArrayAppendValue (array, TOOLBAR_ICON_ITEM_IDENTIFIER); | ||
| 5837 | result = noErr; | ||
| 5838 | } | ||
| 5839 | break; | ||
| 5840 | |||
| 5841 | case kEventToolbarCreateItemWithIdentifier: | ||
| 5842 | { | ||
| 5843 | CFStringRef identifier; | ||
| 5844 | HIToolbarItemRef item = NULL; | ||
| 5845 | |||
| 5846 | GetEventParameter (event, kEventParamToolbarItemIdentifier, | ||
| 5847 | typeCFStringRef, NULL, | ||
| 5848 | sizeof (CFStringRef), NULL, &identifier); | ||
| 5849 | |||
| 5850 | if (CFStringCompare (identifier, TOOLBAR_ICON_ITEM_IDENTIFIER, 0) | ||
| 5851 | == kCFCompareEqualTo) | ||
| 5852 | HIToolbarItemCreate (identifier, | ||
| 5853 | kHIToolbarItemAllowDuplicates | ||
| 5854 | | kHIToolbarItemCantBeRemoved, &item); | ||
| 5855 | |||
| 5856 | if (item) | ||
| 5857 | { | ||
| 5858 | SetEventParameter (event, kEventParamToolbarItem, | ||
| 5859 | typeHIToolbarItemRef, | ||
| 5860 | sizeof (HIToolbarItemRef), &item); | ||
| 5861 | result = noErr; | ||
| 5862 | } | ||
| 5863 | } | ||
| 5864 | break; | ||
| 5865 | |||
| 5866 | default: | ||
| 5867 | abort (); | ||
| 5868 | } | ||
| 5869 | |||
| 5870 | return result; | ||
| 5871 | } | ||
| 5872 | |||
| 5873 | static CGImageRef | ||
| 5874 | mac_image_spec_to_cg_image (f, image) | ||
| 5875 | struct frame *f; | ||
| 5876 | Lisp_Object image; | ||
| 5877 | { | ||
| 5878 | if (!valid_image_p (image)) | ||
| 5879 | return NULL; | ||
| 5880 | else | ||
| 5881 | { | ||
| 5882 | int img_id = lookup_image (f, image); | ||
| 5883 | struct image *img = IMAGE_FROM_ID (f, img_id); | ||
| 5884 | |||
| 5885 | prepare_image_for_display (f, img); | ||
| 5886 | |||
| 5887 | return img->data.ptr_val; | ||
| 5888 | } | ||
| 5889 | } | ||
| 5890 | |||
| 5891 | /* Create a tool bar for frame F. */ | ||
| 5892 | |||
| 5893 | static OSStatus | ||
| 5894 | mac_create_frame_tool_bar (f) | ||
| 5895 | FRAME_PTR f; | ||
| 5896 | { | ||
| 5897 | OSStatus err; | ||
| 5898 | HIToolbarRef toolbar; | ||
| 5899 | |||
| 5900 | err = HIToolbarCreate (TOOLBAR_IDENTIFIER, kHIToolbarNoAttributes, | ||
| 5901 | &toolbar); | ||
| 5902 | if (err == noErr) | ||
| 5903 | { | ||
| 5904 | static const EventTypeSpec specs[] = | ||
| 5905 | {{kEventClassToolbar, kEventToolbarGetDefaultIdentifiers}, | ||
| 5906 | {kEventClassToolbar, kEventToolbarGetAllowedIdentifiers}, | ||
| 5907 | {kEventClassToolbar, kEventToolbarCreateItemWithIdentifier}}; | ||
| 5908 | |||
| 5909 | err = InstallEventHandler (HIObjectGetEventTarget (toolbar), | ||
| 5910 | mac_handle_toolbar_event, | ||
| 5911 | GetEventTypeCount (specs), specs, | ||
| 5912 | f, NULL); | ||
| 5913 | } | ||
| 5914 | |||
| 5915 | if (err == noErr) | ||
| 5916 | err = HIToolbarSetDisplayMode (toolbar, kHIToolbarDisplayModeIconOnly); | ||
| 5917 | if (err == noErr) | ||
| 5918 | { | ||
| 5919 | static const EventTypeSpec specs[] = | ||
| 5920 | {{kEventClassCommand, kEventCommandProcess}}; | ||
| 5921 | |||
| 5922 | err = InstallWindowEventHandler (FRAME_MAC_WINDOW (f), | ||
| 5923 | mac_handle_toolbar_command_event, | ||
| 5924 | GetEventTypeCount (specs), | ||
| 5925 | specs, f, NULL); | ||
| 5926 | } | ||
| 5927 | if (err == noErr) | ||
| 5928 | err = SetWindowToolbar (FRAME_MAC_WINDOW (f), toolbar); | ||
| 5929 | |||
| 5930 | if (toolbar) | ||
| 5931 | CFRelease (toolbar); | ||
| 5932 | |||
| 5933 | return err; | ||
| 5934 | } | ||
| 5935 | |||
| 5936 | /* Update the tool bar for frame F. Add new buttons and remove old. */ | ||
| 5937 | |||
| 5938 | void | ||
| 5939 | update_frame_tool_bar (f) | ||
| 5940 | FRAME_PTR f; | ||
| 5941 | { | ||
| 5942 | HIToolbarRef toolbar = NULL; | ||
| 5943 | short left, top; | ||
| 5944 | CFArrayRef old_items = NULL; | ||
| 5945 | CFIndex old_count; | ||
| 5946 | int i, pos, win_gravity = f->output_data.mac->toolbar_win_gravity; | ||
| 5947 | struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f); | ||
| 5948 | |||
| 5949 | BLOCK_INPUT; | ||
| 5950 | |||
| 5951 | GetWindowToolbar (FRAME_MAC_WINDOW (f), &toolbar); | ||
| 5952 | if (toolbar == NULL) | ||
| 5953 | { | ||
| 5954 | mac_create_frame_tool_bar (f); | ||
| 5955 | GetWindowToolbar (FRAME_MAC_WINDOW (f), &toolbar); | ||
| 5956 | if (toolbar == NULL) | ||
| 5957 | goto out; | ||
| 5958 | if (win_gravity >= NorthWestGravity && win_gravity <= SouthEastGravity) | ||
| 5959 | mac_get_window_origin_with_gravity (f, win_gravity, &left, &top); | ||
| 5960 | } | ||
| 5961 | |||
| 5962 | HIToolbarCopyItems (toolbar, &old_items); | ||
| 5963 | if (old_items == NULL) | ||
| 5964 | goto out; | ||
| 5965 | |||
| 5966 | old_count = CFArrayGetCount (old_items); | ||
| 5967 | pos = 0; | ||
| 5968 | for (i = 0; i < f->n_tool_bar_items; ++i) | ||
| 5969 | { | ||
| 5970 | #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX)) | ||
| 5971 | |||
| 5972 | int enabled_p = !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P)); | ||
| 5973 | int selected_p = !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P)); | ||
| 5974 | int idx; | ||
| 5975 | Lisp_Object image; | ||
| 5976 | CGImageRef cg_image; | ||
| 5977 | CFStringRef label; | ||
| 5978 | HIToolbarItemRef item; | ||
| 5979 | |||
| 5980 | /* If image is a vector, choose the image according to the | ||
| 5981 | button state. */ | ||
| 5982 | image = PROP (TOOL_BAR_ITEM_IMAGES); | ||
| 5983 | if (VECTORP (image)) | ||
| 5984 | { | ||
| 5985 | if (enabled_p) | ||
| 5986 | idx = (selected_p | ||
| 5987 | ? TOOL_BAR_IMAGE_ENABLED_SELECTED | ||
| 5988 | : TOOL_BAR_IMAGE_ENABLED_DESELECTED); | ||
| 5989 | else | ||
| 5990 | idx = (selected_p | ||
| 5991 | ? TOOL_BAR_IMAGE_DISABLED_SELECTED | ||
| 5992 | : TOOL_BAR_IMAGE_DISABLED_DESELECTED); | ||
| 5993 | |||
| 5994 | xassert (ASIZE (image) >= idx); | ||
| 5995 | image = AREF (image, idx); | ||
| 5996 | } | ||
| 5997 | else | ||
| 5998 | idx = -1; | ||
| 5999 | |||
| 6000 | cg_image = mac_image_spec_to_cg_image (f, image); | ||
| 6001 | /* Ignore invalid image specifications. */ | ||
| 6002 | if (cg_image == NULL) | ||
| 6003 | continue; | ||
| 6004 | |||
| 6005 | label = cfstring_create_with_string (PROP (TOOL_BAR_ITEM_CAPTION)); | ||
| 6006 | if (label == NULL) | ||
| 6007 | label = CFSTR (""); | ||
| 6008 | |||
| 6009 | if (pos < old_count) | ||
| 6010 | { | ||
| 6011 | CGImageRef old_cg_image = NULL; | ||
| 6012 | CFStringRef old_label = NULL; | ||
| 6013 | Boolean old_enabled_p; | ||
| 6014 | |||
| 6015 | item = (HIToolbarItemRef) CFArrayGetValueAtIndex (old_items, pos); | ||
| 6016 | |||
| 6017 | HIToolbarItemCopyImage (item, &old_cg_image); | ||
| 6018 | if (cg_image != old_cg_image) | ||
| 6019 | HIToolbarItemSetImage (item, cg_image); | ||
| 6020 | CGImageRelease (old_cg_image); | ||
| 6021 | |||
| 6022 | HIToolbarItemCopyLabel (item, &old_label); | ||
| 6023 | if (CFStringCompare (label, old_label, 0) != kCFCompareEqualTo) | ||
| 6024 | HIToolbarItemSetLabel (item, label); | ||
| 6025 | CFRelease (old_label); | ||
| 6026 | |||
| 6027 | old_enabled_p = HIToolbarItemIsEnabled (item); | ||
| 6028 | if ((enabled_p || idx >= 0) != old_enabled_p) | ||
| 6029 | HIToolbarItemSetEnabled (item, (enabled_p || idx >= 0)); | ||
| 6030 | } | ||
| 6031 | else | ||
| 6032 | { | ||
| 6033 | item = NULL; | ||
| 6034 | HIToolbarCreateItemWithIdentifier (toolbar, | ||
| 6035 | TOOLBAR_ICON_ITEM_IDENTIFIER, | ||
| 6036 | NULL, &item); | ||
| 6037 | if (item) | ||
| 6038 | { | ||
| 6039 | HIToolbarItemSetImage (item, cg_image); | ||
| 6040 | HIToolbarItemSetLabel (item, label); | ||
| 6041 | HIToolbarItemSetEnabled (item, (enabled_p || idx >= 0)); | ||
| 6042 | HIToolbarAppendItem (toolbar, item); | ||
| 6043 | CFRelease (item); | ||
| 6044 | } | ||
| 6045 | } | ||
| 6046 | |||
| 6047 | CFRelease (label); | ||
| 6048 | if (item) | ||
| 6049 | { | ||
| 6050 | HIToolbarItemSetCommandID (item, TOOLBAR_ITEM_MAKE_COMMAND_ID (i)); | ||
| 6051 | pos++; | ||
| 6052 | } | ||
| 6053 | } | ||
| 6054 | |||
| 6055 | CFRelease (old_items); | ||
| 6056 | |||
| 6057 | while (pos < old_count) | ||
| 6058 | HIToolbarRemoveItemAtIndex (toolbar, --old_count); | ||
| 6059 | |||
| 6060 | ShowHideWindowToolbar (FRAME_MAC_WINDOW (f), true, | ||
| 6061 | !win_gravity && f == mac_focus_frame (dpyinfo)); | ||
| 6062 | /* Mac OS X 10.3 does not issue kEventWindowBoundsChanged events on | ||
| 6063 | toolbar visibility change. */ | ||
| 6064 | mac_handle_origin_change (f); | ||
| 6065 | if (win_gravity >= NorthWestGravity && win_gravity <= SouthEastGravity) | ||
| 6066 | { | ||
| 6067 | mac_move_window_with_gravity (f, win_gravity, left, top); | ||
| 6068 | /* If the title bar is completely outside the screen, adjust the | ||
| 6069 | position. */ | ||
| 6070 | ConstrainWindowToScreen (FRAME_MAC_WINDOW (f), kWindowTitleBarRgn, | ||
| 6071 | kWindowConstrainMoveRegardlessOfFit | ||
| 6072 | | kWindowConstrainAllowPartial, NULL, NULL); | ||
| 6073 | f->output_data.mac->toolbar_win_gravity = 0; | ||
| 6074 | } | ||
| 6075 | |||
| 6076 | out: | ||
| 6077 | UNBLOCK_INPUT; | ||
| 6078 | } | ||
| 6079 | |||
| 6080 | /* Hide the tool bar on frame F. Unlike the counterpart on GTK+, it | ||
| 6081 | doesn't deallocate the resources. */ | ||
| 6082 | |||
| 6083 | void | ||
| 6084 | free_frame_tool_bar (f) | ||
| 6085 | FRAME_PTR f; | ||
| 6086 | { | ||
| 6087 | if (IsWindowToolbarVisible (FRAME_MAC_WINDOW (f))) | ||
| 6088 | { | ||
| 6089 | struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f); | ||
| 6090 | |||
| 6091 | BLOCK_INPUT; | ||
| 6092 | ShowHideWindowToolbar (FRAME_MAC_WINDOW (f), false, | ||
| 6093 | f == mac_focus_frame (dpyinfo)); | ||
| 6094 | /* Mac OS X 10.3 does not issue kEventWindowBoundsChanged events | ||
| 6095 | on toolbar visibility change. */ | ||
| 6096 | mac_handle_origin_change (f); | ||
| 6097 | UNBLOCK_INPUT; | ||
| 6098 | } | ||
| 6099 | } | ||
| 6100 | |||
| 6101 | static void | ||
| 6102 | mac_tool_bar_note_mouse_movement (f, event) | ||
| 6103 | struct frame *f; | ||
| 6104 | EventRef event; | ||
| 6105 | { | ||
| 6106 | OSStatus err; | ||
| 6107 | struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f); | ||
| 6108 | int mouse_down_p; | ||
| 6109 | HIViewRef item_view; | ||
| 6110 | UInt32 command_id; | ||
| 6111 | |||
| 6112 | mouse_down_p = (dpyinfo->grabbed | ||
| 6113 | && f == last_mouse_frame | ||
| 6114 | && FRAME_LIVE_P (f)); | ||
| 6115 | if (mouse_down_p) | ||
| 6116 | return; | ||
| 6117 | |||
| 6118 | err = HIViewGetViewForMouseEvent (HIViewGetRoot (FRAME_MAC_WINDOW (f)), | ||
| 6119 | event, &item_view); | ||
| 6120 | /* This doesn't work on Mac OS X 10.2. On Mac OS X 10.3 and 10.4, a | ||
| 6121 | toolbar item view seems to have the same command ID with that of | ||
| 6122 | the toolbar item. */ | ||
| 6123 | if (err == noErr) | ||
| 6124 | err = GetControlCommandID (item_view, &command_id); | ||
| 6125 | if (err == noErr && TOOLBAR_ITEM_COMMAND_ID_P (command_id)) | ||
| 6126 | { | ||
| 6127 | int i = TOOLBAR_ITEM_COMMAND_ID_VALUE (command_id); | ||
| 6128 | |||
| 6129 | if (i < f->n_tool_bar_items) | ||
| 6130 | { | ||
| 6131 | HIRect bounds; | ||
| 6132 | HIViewRef content_view; | ||
| 6133 | |||
| 6134 | err = HIViewGetBounds (item_view, &bounds); | ||
| 6135 | if (err == noErr) | ||
| 6136 | err = HIViewFindByID (HIViewGetRoot (FRAME_MAC_WINDOW (f)), | ||
| 6137 | kHIViewWindowContentID, &content_view); | ||
| 6138 | if (err == noErr) | ||
| 6139 | err = HIViewConvertRect (&bounds, item_view, content_view); | ||
| 6140 | if (err == noErr) | ||
| 6141 | SetRect (&last_mouse_glyph, | ||
| 6142 | CGRectGetMinX (bounds), CGRectGetMinY (bounds), | ||
| 6143 | CGRectGetMaxX (bounds), CGRectGetMaxY (bounds)); | ||
| 6144 | |||
| 6145 | help_echo_object = help_echo_window = Qnil; | ||
| 6146 | help_echo_pos = -1; | ||
| 6147 | help_echo_string = PROP (TOOL_BAR_ITEM_HELP); | ||
| 6148 | if (NILP (help_echo_string)) | ||
| 6149 | help_echo_string = PROP (TOOL_BAR_ITEM_CAPTION); | ||
| 6150 | } | ||
| 6151 | } | ||
| 6152 | } | ||
| 6153 | |||
| 6154 | static OSStatus | ||
| 6155 | mac_handle_toolbar_command_event (next_handler, event, data) | ||
| 6156 | EventHandlerCallRef next_handler; | ||
| 6157 | EventRef event; | ||
| 6158 | void *data; | ||
| 6159 | { | ||
| 6160 | OSStatus err, result = eventNotHandledErr; | ||
| 6161 | struct frame *f = (struct frame *) data; | ||
| 6162 | HICommand command; | ||
| 6163 | |||
| 6164 | err = GetEventParameter (event, kEventParamDirectObject, | ||
| 6165 | typeHICommand, NULL, | ||
| 6166 | sizeof (HICommand), NULL, &command); | ||
| 6167 | if (err != noErr) | ||
| 6168 | return result; | ||
| 6169 | |||
| 6170 | switch (GetEventKind (event)) | ||
| 6171 | { | ||
| 6172 | case kEventCommandProcess: | ||
| 6173 | if (!TOOLBAR_ITEM_COMMAND_ID_P (command.commandID)) | ||
| 6174 | result = CallNextEventHandler (next_handler, event); | ||
| 6175 | else | ||
| 6176 | { | ||
| 6177 | int i = TOOLBAR_ITEM_COMMAND_ID_VALUE (command.commandID); | ||
| 6178 | |||
| 6179 | if (i < f->n_tool_bar_items | ||
| 6180 | && !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P))) | ||
| 6181 | { | ||
| 6182 | Lisp_Object frame; | ||
| 6183 | struct input_event buf; | ||
| 6184 | |||
| 6185 | EVENT_INIT (buf); | ||
| 6186 | |||
| 6187 | XSETFRAME (frame, f); | ||
| 6188 | buf.kind = TOOL_BAR_EVENT; | ||
| 6189 | buf.frame_or_window = frame; | ||
| 6190 | buf.arg = frame; | ||
| 6191 | kbd_buffer_store_event (&buf); | ||
| 6192 | |||
| 6193 | buf.kind = TOOL_BAR_EVENT; | ||
| 6194 | buf.frame_or_window = frame; | ||
| 6195 | buf.arg = PROP (TOOL_BAR_ITEM_KEY); | ||
| 6196 | buf.modifiers = mac_event_to_emacs_modifiers (event); | ||
| 6197 | kbd_buffer_store_event (&buf); | ||
| 6198 | |||
| 6199 | result = noErr; | ||
| 6200 | } | ||
| 6201 | } | ||
| 6202 | break; | ||
| 6203 | |||
| 6204 | default: | ||
| 6205 | abort (); | ||
| 6206 | } | ||
| 6207 | #undef PROP | ||
| 6208 | |||
| 6209 | return result; | ||
| 6210 | } | ||
| 6211 | #endif /* USE_MAC_TOOLBAR */ | ||
| 6212 | |||
| 6213 | |||
| 6214 | /*********************************************************************** | ||
| 5592 | Text Cursor | 6215 | Text Cursor |
| 5593 | ***********************************************************************/ | 6216 | ***********************************************************************/ |
| 5594 | 6217 | ||
| @@ -10080,6 +10703,13 @@ mac_handle_window_event (next_handler, event, data) | |||
| 10080 | kWindowCascadeOnParentWindowScreen | 10703 | kWindowCascadeOnParentWindowScreen |
| 10081 | #endif | 10704 | #endif |
| 10082 | ); | 10705 | ); |
| 10706 | #if USE_MAC_TOOLBAR | ||
| 10707 | /* This is a workaround. RepositionWindow fails to put | ||
| 10708 | a window at the cascading position when its parent | ||
| 10709 | window has a Carbon HIToolbar. */ | ||
| 10710 | if (f->top_pos == sf->top_pos && f->left_pos == sf->left_pos) | ||
| 10711 | MoveWindowStructure (wp, f->left_pos + 10, f->top_pos + 32); | ||
| 10712 | #endif | ||
| 10083 | } | 10713 | } |
| 10084 | result = noErr; | 10714 | result = noErr; |
| 10085 | } | 10715 | } |
| @@ -10362,8 +10992,7 @@ mac_handle_keyboard_event (next_handler, event, data) | |||
| 10362 | if (err != noErr) | 10992 | if (err != noErr) |
| 10363 | break; | 10993 | break; |
| 10364 | 10994 | ||
| 10365 | do_keystroke ((GetEventKind (event) == kEventRawKeyDown | 10995 | do_keystroke ((event_kind == kEventRawKeyDown ? keyDown : autoKey), |
| 10366 | ? keyDown : autoKey), | ||
| 10367 | char_code, key_code, modifiers, | 10996 | char_code, key_code, modifiers, |
| 10368 | ((unsigned long) | 10997 | ((unsigned long) |
| 10369 | (GetEventTime (event) / kEventDurationMillisecond)), | 10998 | (GetEventTime (event) / kEventDurationMillisecond)), |
| @@ -11417,6 +12046,21 @@ XTread_socket (sd, expected, hold_quit) | |||
| 11417 | do_zoom_window (window_ptr, part_code); | 12046 | do_zoom_window (window_ptr, part_code); |
| 11418 | break; | 12047 | break; |
| 11419 | 12048 | ||
| 12049 | #if USE_MAC_TOOLBAR | ||
| 12050 | case inStructure: | ||
| 12051 | { | ||
| 12052 | OSStatus err; | ||
| 12053 | HIViewRef ch; | ||
| 12054 | |||
| 12055 | err = HIViewGetViewForMouseEvent (HIViewGetRoot (window_ptr), | ||
| 12056 | eventRef, &ch); | ||
| 12057 | /* This doesn't work on Mac OS X 10.2. */ | ||
| 12058 | if (err == noErr) | ||
| 12059 | HIViewClick (ch, eventRef); | ||
| 12060 | } | ||
| 12061 | break; | ||
| 12062 | #endif /* USE_MAC_TOOLBAR */ | ||
| 12063 | |||
| 11420 | default: | 12064 | default: |
| 11421 | break; | 12065 | break; |
| 11422 | } | 12066 | } |
| @@ -11501,6 +12145,10 @@ XTread_socket (sd, expected, hold_quit) | |||
| 11501 | } | 12145 | } |
| 11502 | if (!note_mouse_movement (f, &mouse_pos)) | 12146 | if (!note_mouse_movement (f, &mouse_pos)) |
| 11503 | help_echo_string = previous_help_echo_string; | 12147 | help_echo_string = previous_help_echo_string; |
| 12148 | #if USE_MAC_TOOLBAR | ||
| 12149 | else | ||
| 12150 | mac_tool_bar_note_mouse_movement (f, eventRef); | ||
| 12151 | #endif | ||
| 11504 | } | 12152 | } |
| 11505 | } | 12153 | } |
| 11506 | 12154 | ||