⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scrollbar_event.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
#ifndef lint#ifdef sccsstatic  char sccsid[] = "@(#)scrollbar_event.c 1.1 92/07/30 Copyr 1986 Sun Micro";#endif#endif/*************************************************************************//*                         scrollbar_event.c                             *//*           Copyright (c) 1985 by Sun Microsystems, Inc.                *//*************************************************************************/#include <suntool/scrollbar_impl.h> #define FORWARD_BUTTON		1#define BACKWARD_BUTTON		2#define NO_BUTTON 		3static void		scrollbar_resize();static void		post_scroll();static void		compute_new_view_start();static int		find_region();static void		set_cursor_from_mouse();static Notify_value	scrollbar_timer_proc();static void		scrollbar_timer_start();static void		scrollbar_timer_stop();/**************************************************************************//* cursors to cache cursor images                                         *//**************************************************************************/extern	struct cursor scrollbar_client_saved_cursor;/**************************************************************************//* timer declarations                                                     *//**************************************************************************/struct itimerval scrollbar_timer;int		 scrollbar_t_on;Event            scrollbar_t_event;Scroll_motion    scrollbar_t_motion;/**************************************************************************//* scrollbar_event                                                        *//**************************************************************************/static short button_active_cursor_image[16] = {/* black diamond */        0x0000,0x0000,0x0000,0x0180,0x03C0,0x07E0,0x0FF0,0x1FF8,        0x1FF8,0x0FF0,0x07E0,0x03C0,0x0180,0x0000,0x0000,0x0000};mpr_static(scrollbar_button_active_mpr, 16, 16, 1, button_active_cursor_image);struct cursor scrollbar_button_active_cursor =    {5,7,PIX_SRC|PIX_DST,&scrollbar_button_active_mpr};/*ARGSUSED*/Notify_valuescrollbar_event(sb, event, arg, type)scrollbar_handle   sb;Event             *event;caddr_t		   arg;Notify_event_type  type;{   register Scroll_motion   motion;   struct cursor           *cursor = NULL;   struct cursor           *active_cursor;   int                      undoing = FALSE;      if (find_region(sb, event)==NO_BUTTON)      active_cursor = sb->active_cursor;   else      active_cursor = &scrollbar_button_active_cursor;   switch (event_action(event)) {                case WIN_REPAINT:         (void)scrollbar_paint_clear((Scrollbar)(LINT_CAST(sb)));         return NOTIFY_DONE;                case WIN_RESIZE:         scrollbar_resize((Scrollbar)(LINT_CAST(sb)));         return NOTIFY_DONE;              case LOC_RGNENTER:         /* Always fetch client's cursor */	 (void)win_getcursor(sb->client_windowfd, &scrollbar_client_saved_cursor);         set_cursor_from_mouse(sb, active_cursor);         (void)scrollbar_repaint((Scrollbar)(LINT_CAST(sb)), SCROLLBAR_INSIDE);         scrollbar_active_sb = sb;	 (void)win_post_id_and_arg(sb->notify_client, SCROLL_ENTER, NOTIFY_SAFE, 			     (char *)sb, NOTIFY_COPY_NULL, NOTIFY_RELEASE_NULL);         return NOTIFY_DONE;      case LOC_RGNEXIT:         /* Always restore client's cursor */	 (void)win_setcursor(sb->client_windowfd, &scrollbar_client_saved_cursor);         (void)scrollbar_repaint((Scrollbar)(LINT_CAST(sb)), SCROLLBAR_OUTSIDE);         scrollbar_active_sb = NULL;	 (void)win_post_id_and_arg(sb->notify_client, SCROLL_EXIT, NOTIFY_SAFE,	 		(char *)sb, NOTIFY_COPY_NULL, NOTIFY_RELEASE_NULL);         scrollbar_timer_stop(sb);         return NOTIFY_DONE;             case LOC_MOVE:         if (scrollbar_t_on) {            scrollbar_t_event.ie_locx = event->ie_locx;            scrollbar_t_event.ie_locy = event->ie_locy;         } else            set_cursor_from_mouse(sb, active_cursor);         return NOTIFY_DONE;             case KBD_REQUEST:	 /* Scrollbar always refuses kbd focus request */	 (void)win_refuse_kbd_focus(sb->client_windowfd);         scrollbar_timer_stop(sb);         return NOTIFY_DONE;             case MS_LEFT:         cursor = sb->forward_cursor;         switch (find_region(sb, event)) {            case FORWARD_BUTTON:               motion = SCROLL_LINE_FORWARD;               break;            case BACKWARD_BUTTON:               motion = SCROLL_LINE_FORWARD;               break;            case NO_BUTTON:               motion = event_shift_is_down(event) ?                        SCROLL_MAX_TO_POINT : SCROLL_POINT_TO_MIN;               break;         }         break;               case MS_MIDDLE:         cursor = sb->absolute_cursor;         switch (find_region(sb, event)) {            case FORWARD_BUTTON:               motion = event_shift_is_down(event) ?                        SCROLL_PAGE_BACKWARD : SCROLL_PAGE_FORWARD;               break;            case BACKWARD_BUTTON:               motion = event_shift_is_down(event) ?                        SCROLL_PAGE_BACKWARD : SCROLL_PAGE_FORWARD;               break;            case NO_BUTTON:               motion = SCROLL_ABSOLUTE;               undoing = event_shift_is_down(event);               break;         }         break;               case MS_RIGHT:         cursor = sb->backward_cursor;         switch (find_region(sb, event)) {            case FORWARD_BUTTON:               motion = SCROLL_LINE_BACKWARD;               break;            case BACKWARD_BUTTON:               motion = SCROLL_LINE_BACKWARD;               break;            case NO_BUTTON:               motion = event_shift_is_down(event) ?                        SCROLL_POINT_TO_MAX : SCROLL_MIN_TO_POINT;               break;         }         break;      case ACTION_HELP:	 if (event_is_down(event))	    help_request((caddr_t)(LINT_CAST(sb->notify_client)),			 sb->help_data, event);         return NOTIFY_DONE;#ifdef notdef      case KEY_LEFT(4):	/* UNDO */         if (event_is_up(event))            post_scroll(sb, event, SCROLL_ABSOLUTE, TRUE);         return NOTIFY_DONE;#endif                    default:  {	 Rect	rect;		 /* Translate mouse x and y so that movements inside 	  * the scrollbar are posted with co-ordinates relative	  * to the window that encloses the scrollbar. 	  */	 rect = sb->rect; 	 event->ie_locx += rect.r_left;         event->ie_locy += rect.r_top; 	 (void)win_post_id_and_arg(sb->notify_client, event_id(event), NOTIFY_SAFE, 			     (char *)sb, NOTIFY_COPY_NULL, NOTIFY_RELEASE_NULL);	 return NOTIFY_DONE;	}   }   if (win_inputposevent(event)) {      scrollbar_timer_start(sb, event, motion);   } else {      if (!scrollbar_t_on)         post_scroll(sb, event, motion, undoing);      cursor = active_cursor;      scrollbar_timer_stop(sb);   }   if (cursor)      (void)win_setcursor(sb->client_windowfd, cursor);   return NOTIFY_DONE;}static find_region(sb, event)scrollbar_handle   sb;Event             *event;{   register short loc;   register int   forward_button_limit;   register int   backward_button_limit;   if (!sb->buttons)      return NO_BUTTON;   if (sb->horizontal) {      loc = event_x(event);      forward_button_limit  = sb->button_length;      backward_button_limit = sb->rect.r_width - sb->button_length;   } else {      loc = event_y(event);      forward_button_limit  = sb->button_length;      backward_button_limit = sb->rect.r_height - sb->button_length;   }   if (loc < forward_button_limit)      return FORWARD_BUTTON;    else if (loc > backward_button_limit)      return BACKWARD_BUTTON;    else      return NO_BUTTON;}static voidset_cursor_from_mouse(sb, active_cursor)scrollbar_handle	sb;struct cursor		*active_cursor;{   register int	fd = sb->client_windowfd;   /* figure which cursor to install from mouse state */   if (win_get_vuid_value(fd, MS_LEFT))      active_cursor = sb->forward_cursor;   else if (win_get_vuid_value(fd, MS_MIDDLE))      active_cursor = sb->absolute_cursor;   else if (win_get_vuid_value(fd, MS_RIGHT))      active_cursor = sb->backward_cursor;   /* ..else keep active_cursor unchanged */   /* set cursor if not NULL */   if (active_cursor)      (void)win_setcursor(fd, active_cursor);}/**************************************************************************//* post_scroll                                                            *//* undoing policy: undo to the last position which was departed from      *//* via an "undoable" motion.  Undoable motions are: thumbing, undoing.    *//**************************************************************************/static voidpost_scroll(sb, event, motion, undoing)scrollbar_handle         sb;Event	                *event;Scroll_motion            motion;int                      undoing;{   register int bar_length, request_offset, old_request_offset;   /* compute bar length, offset of request into bar (incl. page buttons) */   old_request_offset = sb->request_offset;   if (sb->horizontal) {      request_offset = event_x(event);      bar_length = sb->rect.r_width;   } else {      request_offset = event_y(event);      bar_length = sb->rect.r_height;   }   /* if thumbing, save request_offset and view_start for future undo */   if (!undoing && motion == SCROLL_ABSOLUTE) {      sb->undo_request_offset = sb->request_offset;      sb->undo_mark           = sb->view_start;      /* don't scroll if double-thumbing in same spot! */      if (sb->request_motion==SCROLL_ABSOLUTE      && request_offset==old_request_offset)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -