📄 dw_gtk_scrolled_frame.c
字号:
/* * Standard Gtk+ function */static gint Dw_gtk_scrolled_frame_expose (GtkWidget *widget, GdkEventExpose *event){ gint ret_val; ret_val = GTK_WIDGET_CLASS(parent_class)->expose_event (widget, event); Dw_gtk_scrolled_frame_paint_shadow (widget, &(event->area)); return ret_val;}/* * Standard Gtk+ function */static gint Dw_gtk_scrolled_frame_key_press (GtkWidget *widget, GdkEventKey *event){ GtkContainer *container; GtkDwScrolledFrame *frame; container = GTK_CONTAINER (widget); frame = GTK_DW_SCROLLED_FRAME (widget); switch (event->keyval) { case GDK_Up: case GDK_KP_Up: Dw_gtk_scrolled_frame_move_by (frame, 0, - frame->vadjustment->step_increment); return TRUE; case GDK_Down: case GDK_KP_Down: Dw_gtk_scrolled_frame_move_by (frame, 0, + frame->vadjustment->step_increment); return TRUE; case GDK_Left: case GDK_KP_Left: Dw_gtk_scrolled_frame_move_by (frame, - frame->hadjustment->step_increment, 0); return TRUE; case GDK_Right: case GDK_KP_Right: Dw_gtk_scrolled_frame_move_by (frame, + frame->hadjustment->step_increment, 0); return TRUE; case GDK_Tab: if (event->state & GDK_SHIFT_MASK) return gtk_container_focus (container, GTK_DIR_TAB_BACKWARD); else return gtk_container_focus (container, GTK_DIR_TAB_FORWARD); case GDK_b: case GDK_B: if (event->state & GDK_CONTROL_MASK) return FALSE; /* continues */ case GDK_Page_Up: case GDK_KP_Page_Up: if (event->state & GDK_CONTROL_MASK) Dw_gtk_scrolled_frame_move_by (frame, - frame->hadjustment->page_increment, 0); else Dw_gtk_scrolled_frame_move_by (frame, 0, - frame->vadjustment->page_increment); return TRUE; case GDK_Page_Down: case GDK_KP_Page_Down: case GDK_space: if (event->state & GDK_CONTROL_MASK) Dw_gtk_scrolled_frame_move_by (frame, + frame->hadjustment->page_increment, 0); else Dw_gtk_scrolled_frame_move_by (frame, 0, + frame->vadjustment->page_increment); return TRUE; case GDK_Home: case GDK_KP_Home: if (event->state & GDK_CONTROL_MASK) Dw_gtk_scrolled_frame_move_x_to (frame, 0); else Dw_gtk_scrolled_frame_move_y_to (frame, 0); return TRUE; case GDK_End: case GDK_KP_End: if (event->state & GDK_CONTROL_MASK) Dw_gtk_scrolled_frame_move_x_to (frame, G_MAXFLOAT); else Dw_gtk_scrolled_frame_move_y_to (frame, G_MAXFLOAT); return TRUE; default: return FALSE; }}/* * Standard Gtk+ function */static gint Dw_gtk_scrolled_frame_focus_in (GtkWidget *widget, GdkEventFocus *event){ GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS); gtk_widget_draw_focus (widget); return FALSE;}/* * Standard Gtk+ function */static gint Dw_gtk_scrolled_frame_focus_out (GtkWidget *widget, GdkEventFocus *event){ GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS); gtk_widget_draw_focus (widget); return FALSE;}/* * Standard Gtk+ function */static gint Dw_gtk_scrolled_frame_button_press (GtkWidget *widget, GdkEventButton *event){ GtkDwScrolledFrame *frame; if (!GTK_WIDGET_HAS_FOCUS (widget)) gtk_widget_grab_focus (widget); if (event->button == 2) { frame = GTK_DW_SCROLLED_FRAME (widget); frame->button2_pressed = TRUE; frame->start_lmx = event->x; frame->start_lmy = event->y; gdk_pointer_grab (widget->window, FALSE, GDK_BUTTON_RELEASE_MASK | GDK_BUTTON2_MOTION_MASK, NULL, frame->drag_cursor, event->time); } return TRUE;}/* * Standard Gtk+ function */static gint Dw_gtk_scrolled_frame_button_release (GtkWidget *widget, GdkEventButton *event){ GTK_DW_SCROLLED_FRAME(widget)->button2_pressed = FALSE; gdk_pointer_ungrab (event->time); return TRUE;}/* * Standard Gtk+ function */static gint Dw_gtk_scrolled_frame_motion_notify (GtkWidget *widget, GdkEventMotion *event){ GtkDwScrolledFrame *frame = GTK_DW_SCROLLED_FRAME (widget); /* frame->button2_pressed makes sure that the button was pressed in the GtkDwScrolledFrame */ if ((event->state & GDK_BUTTON2_MASK) && frame->button2_pressed) { Dw_gtk_scrolled_frame_move_by (frame, frame->start_lmx - event->x, frame->start_lmy - event->y); frame->start_lmx = event->x; frame->start_lmy = event->y; } return TRUE;}/************************** * * * GtkContainer methods * * * **************************//* * Standard Gtk+ function */static void Dw_gtk_scrolled_frame_add (GtkContainer *container, GtkWidget *widget){ GtkDwScrolledFrame *frame; GTK_CONTAINER_CLASS(parent_class)->add (container, widget); frame = GTK_DW_SCROLLED_FRAME (container); if ( !gtk_widget_set_scroll_adjustments ( GTK_WIDGET (container), frame->hadjustment, frame->vadjustment) ) g_warning ("Dw_gtk_scrolled_frame_set_scroll_adjustments(): " "child is non scrollable");}/* * Standard Gtk+ function */static gint Dw_gtk_scrolled_frame_focus (GtkContainer *container, GtkDirectionType direction){ /* todo: * This crashed if the child is not a container (what will never happen * in dillo, where GtkDwScrolledFrame always contains a GtkDwViewport). */ GtkDwScrolledFrame *frame; frame = GTK_DW_SCROLLED_FRAME (container); if (!GTK_WIDGET_HAS_FOCUS (container) && container->focus_child == NULL){ // no focus on the GtkDwScrolledFrame or any child widget => grab focus! gtk_widget_grab_focus (GTK_WIDGET (container)); return TRUE; } switch (direction) { case GTK_DIR_TAB_FORWARD: /* deliver to child */ if (!gtk_container_focus (GTK_CONTAINER (GTK_BIN(container)->child), direction)) { /* todo: it would be nice to keep focus on this last child widget, * instead of the container... Anyway this may change with GTK2 */ gtk_widget_grab_focus (GTK_WIDGET (container)); } return TRUE; case GTK_DIR_TAB_BACKWARD: if (GTK_WIDGET_HAS_FOCUS (container)) { /* will focus the widget "before" */ return FALSE; } else { if (!gtk_container_focus (GTK_CONTAINER (GTK_BIN(container)->child), GTK_DIR_TAB_BACKWARD)) /* first child of the child unfocussed */ gtk_widget_grab_focus (GTK_WIDGET (container)); return TRUE; } break; /* case GTK_DIR_LEFT: case GTK_DIR_RIGHT: case GTK_DIR_UP: case GTK_DIR_DOWN: */ default: /* focus the GtkDwScrolledFrame */ gtk_widget_grab_focus (GTK_WIDGET (container)); return TRUE; } /* make compiler happy */ return FALSE;}/******************************** * * * GtkDwScrolledFrame methods * * * ********************************//* * Standard Gtk+ function */static voidDw_gtk_scrolled_frame_set_scroll_adjustments (GtkDwScrolledFrame *frame, GtkAdjustment *hadjustment, GtkAdjustment *vadjustment){ GtkBin *bin; frame->hadjustment = hadjustment; frame->vadjustment = vadjustment; bin = GTK_BIN (frame); if (bin->child) { if (!gtk_widget_set_scroll_adjustments (bin->child, hadjustment, vadjustment)) g_warning ("Dw_gtk_scrolled_frame_set_scroll_adjustments(): " "child is non scrollable"); }}/* * Functions for moving the viewport. This is queued and done in an * idle function, to prevent locks by too frequent keypresses, or too * fast mouse movements. (How to reproduce: start dillo on a slow, * overloaded system with nice priority.) *//* * The idle function. */static gint Dw_gtk_scrolled_frame_move_idle (gpointer data){ GtkDwScrolledFrame *frame; frame = GTK_DW_SCROLLED_FRAME (data); g_return_val_if_fail (frame->hadjustment != NULL, FALSE); g_return_val_if_fail (frame->vadjustment != NULL, FALSE); if (frame->moveto_x != frame->hadjustment->value) { gtk_adjustment_set_value (frame->hadjustment, frame->moveto_x); gtk_signal_emit (GTK_OBJECT (frame), frame_signals[USER_HCHANGED]); } if (frame->moveto_y != frame->vadjustment->value) { gtk_adjustment_set_value (frame->vadjustment, frame->moveto_y); gtk_signal_emit (GTK_OBJECT (frame), frame_signals[USER_VCHANGED]); } frame->move_idle_id = 0; return FALSE;}/* * Change horizontall position to x. */static void Dw_gtk_scrolled_frame_move_x_to (GtkDwScrolledFrame *frame, gfloat x){ frame->moveto_x = Dw_gtk_scrolled_frame_correct_adj (frame->hadjustment, x); if (frame->move_idle_id == 0) frame->move_idle_id = gtk_idle_add (Dw_gtk_scrolled_frame_move_idle, (gpointer) frame);}/* * Change vertical position to y. */static void Dw_gtk_scrolled_frame_move_y_to (GtkDwScrolledFrame *frame, gfloat y){ frame->moveto_y = Dw_gtk_scrolled_frame_correct_adj (frame->vadjustment, y); if (frame->move_idle_id == 0) frame->move_idle_id = gtk_idle_add (Dw_gtk_scrolled_frame_move_idle, (gpointer) frame);}/* * Move viewport by dx and dy. */static void Dw_gtk_scrolled_frame_move_by (GtkDwScrolledFrame *frame, gfloat dx, gfloat dy){ if (frame->move_idle_id == 0) { /* * Initialization: if the idle function is not active, set * moveto_x and moveto_y to adjustments values, which may * already have been changed by the scrollbars. This code does * not work when a user uses scrollbars and keys at the same * time. ;-) */ frame->moveto_x = frame->hadjustment->value; frame->moveto_y = frame->vadjustment->value; } frame->moveto_x = Dw_gtk_scrolled_frame_correct_adj (frame->hadjustment, frame->moveto_x + dx); frame->moveto_y = Dw_gtk_scrolled_frame_correct_adj (frame->vadjustment, frame->moveto_y + dy); if (frame->move_idle_id == 0) frame->move_idle_id = gtk_idle_add (Dw_gtk_scrolled_frame_move_idle, (gpointer) frame);}/* * Helper function: Corrects pos to fit into the boundaries of adj. */static gfloat Dw_gtk_scrolled_frame_correct_adj (GtkAdjustment *adj, gfloat pos){ if (pos < adj->lower) return adj->lower; else if (pos > adj->upper - adj->page_size) return adj->upper - adj->page_size; else return pos;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -