1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840
|
/*
* File: dw_gtk_scrolled_frame.c
*
* Copyright (C) 2001 Sebastian Geerken <S.Geerken@ping.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
/*
* GtkDwScrolledFrame is a container for the GtkDwViewport, it adds
* a focus around the child and is responsible for focus, keys and the
* button 2 dragging.
*/
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include "dw_gtk_scrolled_frame.h"
static GtkBinClass *parent_class = NULL;
/* object/class initialisation */
static void Dw_gtk_scrolled_frame_init (GtkDwScrolledFrame *frame);
static void Dw_gtk_scrolled_frame_class_init (GtkDwScrolledFrameClass
*klass);
/* GtkObject methods */
static void Dw_gtk_scrolled_frame_destroy (GtkObject *object);
/* GtkWidget methods */
static void Dw_gtk_scrolled_frame_realize (GtkWidget *widget);
static void Dw_gtk_scrolled_frame_unrealize (GtkWidget *widget);
static void Dw_gtk_scrolled_frame_size_request (GtkWidget *widget,
GtkRequisition *requisition);
static void Dw_gtk_scrolled_frame_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static void Dw_gtk_scrolled_frame_draw (GtkWidget *widget,
GdkRectangle *area);
static void Dw_gtk_scrolled_frame_draw_focus (GtkWidget *widget);
static gint Dw_gtk_scrolled_frame_expose (GtkWidget *widget,
GdkEventExpose *event);
static gint Dw_gtk_scrolled_frame_key_press (GtkWidget *widget,
GdkEventKey *event);
static gint Dw_gtk_scrolled_frame_focus_in (GtkWidget *widget,
GdkEventFocus *event);
static gint Dw_gtk_scrolled_frame_focus_out (GtkWidget *widget,
GdkEventFocus *event);
static gint Dw_gtk_scrolled_frame_button_press (GtkWidget *widget,
GdkEventButton *event);
static gint Dw_gtk_scrolled_frame_button_release(GtkWidget *widget,
GdkEventButton *event);
static gint Dw_gtk_scrolled_frame_motion_notify (GtkWidget *widget,
GdkEventMotion *event);
/* GtkContainer methods */
static void Dw_gtk_scrolled_frame_add (GtkContainer *container,
GtkWidget *widget);
static gint Dw_gtk_scrolled_frame_focus (GtkContainer *container,
GtkDirectionType direction);
/* GtkDwScrolledFrame methods */
static void Dw_gtk_scrolled_frame_set_scroll_adjustments (GtkDwScrolledFrame
*frame,
GtkAdjustment
*hadjustment,
GtkAdjustment
*vadjustment);
static void Dw_gtk_scrolled_frame_move_x_to (GtkDwScrolledFrame *frame,
gfloat x);
static void Dw_gtk_scrolled_frame_move_y_to (GtkDwScrolledFrame *frame,
gfloat y);
static void Dw_gtk_scrolled_frame_move_by (GtkDwScrolledFrame *frame,
gfloat dx,
gfloat dy);
static gfloat Dw_gtk_scrolled_frame_correct_adj (GtkAdjustment *adj,
gfloat pos);
enum
{
SET_SCROLL_ADJUSTMENTS,
USER_HCHANGED,
USER_VCHANGED,
LAST_SIGNAL
};
static guint frame_signals[LAST_SIGNAL] = { 0 };
/*
* Standard Gtk+ function
*/
GtkType a_Dw_gtk_scrolled_frame_get_type (void)
{
static GtkType type = 0;
if (!type) {
GtkTypeInfo info = {
"GtkDwScrolledFrame",
sizeof (GtkDwScrolledFrame),
sizeof (GtkDwScrolledFrameClass),
(GtkClassInitFunc) Dw_gtk_scrolled_frame_class_init,
(GtkObjectInitFunc) Dw_gtk_scrolled_frame_init,
(GtkArgSetFunc) NULL,
(GtkArgGetFunc) NULL,
(GtkClassInitFunc) NULL
};
type = gtk_type_unique (GTK_TYPE_BIN, &info);
}
return type;
}
/*
* Standard Gtk+ function
*/
GtkWidget* a_Dw_gtk_scrolled_frame_new (GtkAdjustment *hadjustment,
GtkAdjustment *vadjustment)
{
GtkWidget *widget;
GtkDwScrolledFrame *frame;
widget = gtk_widget_new (GTK_TYPE_DW_SCROLLED_FRAME, NULL);
frame = GTK_DW_SCROLLED_FRAME (widget);
frame->hadjustment = hadjustment;
frame->vadjustment = vadjustment;
return widget;
}
/*********************************
* *
* object/class initialisation *
* *
*********************************/
/*
* Standard Gtk+ function
*/
static void Dw_gtk_scrolled_frame_init (GtkDwScrolledFrame *frame)
{
GTK_WIDGET_SET_FLAGS (frame, GTK_CAN_FOCUS);
GTK_WIDGET_UNSET_FLAGS (frame, GTK_NO_WINDOW);
frame->hadjustment = NULL;
frame->vadjustment = NULL;
frame->button2_pressed = FALSE;
frame->move_idle_id = 0;
}
/*
* Standard Gtk+ function
*/
static void Dw_gtk_scrolled_frame_class_init (GtkDwScrolledFrameClass *klass)
{
GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
GtkContainerClass *container_class;
parent_class = gtk_type_class (gtk_bin_get_type ());
object_class = (GtkObjectClass*) klass;
widget_class = (GtkWidgetClass*) klass;
container_class = (GtkContainerClass*) klass;
frame_signals[SET_SCROLL_ADJUSTMENTS] =
gtk_signal_new ("set_scroll_adjustments",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (GtkDwScrolledFrameClass,
set_scroll_adjustments),
gtk_marshal_NONE__POINTER_POINTER,
GTK_TYPE_NONE, 2, GTK_TYPE_ADJUSTMENT,
GTK_TYPE_ADJUSTMENT);
widget_class->set_scroll_adjustments_signal =
frame_signals[SET_SCROLL_ADJUSTMENTS];
frame_signals[USER_HCHANGED] =
gtk_signal_new ("user_hchanged",
GTK_RUN_LAST | GTK_RUN_ACTION,
object_class->type,
GTK_SIGNAL_OFFSET (GtkDwScrolledFrameClass,
user_hchanged),
gtk_marshal_NONE__NONE,
GTK_TYPE_NONE, 0);
frame_signals[USER_VCHANGED] =
gtk_signal_new ("user_vchanged",
GTK_RUN_LAST | GTK_RUN_ACTION,
object_class->type,
GTK_SIGNAL_OFFSET (GtkDwScrolledFrameClass,
user_vchanged),
gtk_marshal_NONE__NONE,
GTK_TYPE_NONE, 0);
gtk_object_class_add_signals (object_class, frame_signals, LAST_SIGNAL);
object_class->destroy = Dw_gtk_scrolled_frame_destroy;
widget_class->realize = Dw_gtk_scrolled_frame_realize;
widget_class->unrealize = Dw_gtk_scrolled_frame_unrealize;
widget_class->size_request = Dw_gtk_scrolled_frame_size_request;
widget_class->size_allocate = Dw_gtk_scrolled_frame_size_allocate;
widget_class->draw_focus = Dw_gtk_scrolled_frame_draw_focus;
widget_class->draw = Dw_gtk_scrolled_frame_draw;
widget_class->expose_event = Dw_gtk_scrolled_frame_expose;
widget_class->key_press_event = Dw_gtk_scrolled_frame_key_press;
widget_class->focus_in_event = Dw_gtk_scrolled_frame_focus_in;
widget_class->focus_out_event = Dw_gtk_scrolled_frame_focus_out;
widget_class->button_press_event = Dw_gtk_scrolled_frame_button_press;
widget_class->button_release_event = Dw_gtk_scrolled_frame_button_release;
widget_class->motion_notify_event = Dw_gtk_scrolled_frame_motion_notify;
container_class->add = Dw_gtk_scrolled_frame_add;
container_class->focus = Dw_gtk_scrolled_frame_focus;
klass->set_scroll_adjustments =
Dw_gtk_scrolled_frame_set_scroll_adjustments;
klass->user_hchanged = NULL;
klass->user_vchanged = NULL;
}
/***********************
* *
* GtkObject methods *
* *
***********************/
/*
* Standard Gtk+ function
*/
static void Dw_gtk_scrolled_frame_destroy (GtkObject *object)
{
GtkDwScrolledFrame *frame;
frame = GTK_DW_SCROLLED_FRAME (object);
if (frame->move_idle_id != 0)
gtk_idle_remove (frame->move_idle_id);
GTK_OBJECT_CLASS(parent_class)->destroy (object);
}
/***********************
* *
* GtkWidget methods *
* *
***********************/
/*
* Standard Gtk+ function
*/
static void Dw_gtk_scrolled_frame_realize (GtkWidget *widget)
{
GdkWindowAttr attributes;
GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
attributes.window_type = GDK_WINDOW_CHILD;
attributes.x = widget->allocation.x;
attributes.y = widget->allocation.y;
attributes.width = widget->allocation.width;
attributes.height = widget->allocation.height;
attributes.wclass = GDK_INPUT_OUTPUT;
attributes.visual = gtk_widget_get_visual (widget);
attributes.colormap = gtk_widget_get_colormap (widget);
attributes.event_mask = (gtk_widget_get_events (widget)
| GDK_EXPOSURE_MASK
| GDK_KEY_PRESS_MASK
| GDK_BUTTON_PRESS_MASK);
widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
&attributes,
GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL |
GDK_WA_COLORMAP);
gdk_window_set_user_data (widget->window, widget);
widget->style = gtk_style_attach (widget->style, widget->window);
gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
GTK_DW_SCROLLED_FRAME(widget)->drag_cursor = gdk_cursor_new (GDK_FLEUR);
}
/*
* Standard Gtk+ function
*/
static void Dw_gtk_scrolled_frame_unrealize (GtkWidget *widget)
{
gdk_cursor_destroy (GTK_DW_SCROLLED_FRAME(widget)->drag_cursor);
GTK_WIDGET_CLASS(parent_class)->unrealize (widget);
}
/*
* Standard Gtk+ function
*/
static void Dw_gtk_scrolled_frame_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
GtkBin *bin;
gint border_width;
GtkAllocation child_allocation;
widget->allocation = *allocation;
bin = GTK_BIN (widget);
if (GTK_WIDGET_REALIZED (widget))
gdk_window_move_resize (widget->window,
allocation->x, allocation->y,
allocation->width, allocation->height);
if (bin->child) {
border_width = GTK_CONTAINER(widget)->border_width;
child_allocation.width =
MAX (allocation->width - 2 * (widget->style->klass->xthickness +
border_width),
1);
child_allocation.height =
MAX (allocation->height - 2 * (widget->style->klass->ythickness +
border_width),
1);
child_allocation.x = (allocation->width - child_allocation.width) / 2;
child_allocation.y = (allocation->height - child_allocation.height) / 2;
gtk_widget_size_allocate (bin->child, &child_allocation);
}
}
/*
* Standard Gtk+ function
*/
static void Dw_gtk_scrolled_frame_size_request (GtkWidget *widget,
GtkRequisition *requisition)
{
GtkBin *bin;
gint border_width;
GtkRequisition child_requisition;
bin = GTK_BIN (widget);
if (bin->child) {
border_width = GTK_CONTAINER(widget)->border_width;
gtk_widget_size_request (bin->child, &child_requisition);
requisition->width =
child_requisition.width + 2 * (widget->style->klass->xthickness +
border_width);
requisition->height =
child_requisition.height + 2 * (widget->style->klass->ythickness +
border_width);
} else {
requisition->width = 100;
requisition->height = 100;
}
}
/*
* Draw the frame, eventually with a focus border
*/
static void Dw_gtk_scrolled_frame_paint_shadow (GtkWidget *widget,
GdkRectangle *area)
{
gint border_width;
if (GTK_WIDGET_DRAWABLE (widget)) {
border_width = GTK_CONTAINER(widget)->border_width;
if (GTK_WIDGET_HAS_FOCUS (widget)) {
gtk_draw_shadow (widget->style, widget->window,
GTK_STATE_NORMAL, GTK_SHADOW_IN,
border_width + 1, border_width + 1,
widget->allocation.width - 2 * (border_width + 1),
widget->allocation.height - 2 * (border_width + 1));
/* "text" is probably next to what we need */
gtk_paint_focus (widget->style, widget->window,
area, widget, "text",
border_width, border_width,
widget->allocation.width - 2 * border_width - 1,
widget->allocation.height - 2 * border_width - 1);
} else {
gtk_draw_shadow (widget->style, widget->window,
GTK_STATE_NORMAL, GTK_SHADOW_IN,
border_width, border_width,
widget->allocation.width - 2 * border_width,
widget->allocation.height - 2 * border_width);
}
}
}
/*
* Standard Gtk+ function
*/
static void Dw_gtk_scrolled_frame_draw_focus (GtkWidget *widget)
{
Dw_gtk_scrolled_frame_paint_shadow (widget, NULL);
}
/*
* Standard Gtk+ function
*/
static void Dw_gtk_scrolled_frame_draw (GtkWidget *widget,
GdkRectangle *area)
{
GTK_WIDGET_CLASS(parent_class)->draw (widget, area);
Dw_gtk_scrolled_frame_paint_shadow (widget, area);
}
/*
* 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 void
Dw_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;
}
|