comparison gtk/dw.c @ 119:1cad81b7cc4c

Implemented initial splitbar code on Unix. And made some fixes for setting the ID on all platforms, but specifically windows.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 19 Oct 2002 06:36:41 +0000
parents 2d121d4d90c0
children 7d2108cbcd3e
comparison
equal deleted inserted replaced
118:c170181668b7 119:1cad81b7cc4c
5522 if(GTK_IS_LIST(handle2)) 5522 if(GTK_IS_LIST(handle2))
5523 gtk_list_clear_items(GTK_LIST(handle2), index, index); 5523 gtk_list_clear_items(GTK_LIST(handle2), index, index);
5524 DW_MUTEX_UNLOCK; 5524 DW_MUTEX_UNLOCK;
5525 } 5525 }
5526 5526
5527 5527 /* Reposition the bar according to the percentage */
5528 /* 5528 gint _splitbar_size_allocate(GtkWidget *widget, GtkAllocation *event, gpointer data)
5529 * Pack a splitbar (sizer) into the specified box from the start. 5529 {
5530 * Parameters: 5530 int percent = (int)gtk_object_get_data(GTK_OBJECT(widget), "_dw_percent");
5531 * box: Window handle of the box to be packed into. 5531 int lastwidth = (int)gtk_object_get_data(GTK_OBJECT(widget), "_dw_lastwidth");
5532 */ 5532 int lastheight = (int)gtk_object_get_data(GTK_OBJECT(widget), "_dw_lastheight");
5533 void dw_box_pack_splitbar_start(HWND box) 5533 float ratio = ((float)percent/100.0);
5534 { 5534
5535 /* TODO */ 5535 /* Prevent infinite recursion ;) */
5536 } 5536 if(lastwidth == event->width && lastheight == event->height)
5537 5537 return TRUE;
5538 /* 5538
5539 * Pack a splitbar (sizer) into the specified box from the end. 5539 lastwidth = event->width; lastheight = event->height;
5540 * Parameters: 5540
5541 * box: Window handle of the box to be packed into. 5541 gtk_object_set_data(GTK_OBJECT(widget), "_dw_splitbar_sizing", (gpointer)1);
5542 */ 5542 gtk_object_set_data(GTK_OBJECT(widget), "_dw_lastwidth", (gpointer)lastwidth);
5543 void dw_box_pack_splitbar_end(HWND box) 5543 gtk_object_set_data(GTK_OBJECT(widget), "_dw_lastheight", (gpointer)lastheight);
5544 { 5544
5545 /* TODO */ 5545 if(GTK_IS_HPANED(widget))
5546 gtk_paned_set_position(GTK_PANED(widget), (int)(event->width * ratio));
5547 if(GTK_IS_VPANED(widget))
5548 gtk_paned_set_position(GTK_PANED(widget), (int)(event->height * ratio));
5549 return TRUE;
5550 }
5551
5552 /* Figure out the new percentage */
5553 gint _splitbar_child_size_allocate(GtkWidget *widget, GtkAllocation *event, gpointer data)
5554 {
5555 GtkWidget *splitbar = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(widget), "_dw_splitbar");
5556 int percent;
5557
5558 if(!splitbar)
5559 return TRUE;
5560
5561 if(gtk_object_get_data(GTK_OBJECT(splitbar), "_dw_splitbar_sizing"))
5562 {
5563 gtk_object_set_data(GTK_OBJECT(splitbar), "_dw_splitbar_sizing", (gpointer)0);
5564 return TRUE;
5565 }
5566
5567 if(GTK_IS_VPANED(splitbar))
5568 percent = (int)((event->height * 100) / (splitbar->allocation.height - 3));
5569 else if(GTK_IS_HPANED(splitbar))
5570 percent = (int)((event->width * 100) / (splitbar->allocation.width - 3));
5571 else
5572 return TRUE;
5573
5574 gtk_object_set_data(GTK_OBJECT(splitbar), "_dw_percent", (gpointer)percent);
5575
5576 return TRUE;
5577 }
5578
5579 /*
5580 * Creates a splitbar window (widget) with given parameters.
5581 * Parameters:
5582 * type: Value can be BOXVERT or BOXHORZ.
5583 * topleft: Handle to the window to be top or left.
5584 * bottomright: Handle to the window to be bottom or right.
5585 * Returns:
5586 * A handle to a splitbar window or NULL on failure.
5587 */
5588 HWND dw_splitbar_new(int type, HWND topleft, HWND bottomright, unsigned long id)
5589 {
5590 GtkWidget *tmp = NULL;
5591 int _locked_by_me = FALSE;
5592
5593 DW_MUTEX_LOCK;
5594 if(type == BOXHORZ)
5595 tmp = gtk_hpaned_new();
5596 else
5597 tmp = gtk_vpaned_new();
5598 gtk_paned_add1(GTK_PANED(tmp), topleft);
5599 gtk_paned_add2(GTK_PANED(tmp), bottomright);
5600 gtk_object_set_data(GTK_OBJECT(tmp), "id", (gpointer)id);
5601 gtk_object_set_data(GTK_OBJECT(tmp), "_dw_percent", (gpointer)50);
5602 gtk_signal_connect(GTK_OBJECT(tmp), "size-allocate", GTK_SIGNAL_FUNC(_splitbar_size_allocate), NULL);
5603 gtk_object_set_data(GTK_OBJECT(topleft), "_dw_splitbar", (gpointer)tmp);
5604 #if 0
5605 gtk_signal_connect(GTK_OBJECT(topleft), "size-allocate", GTK_SIGNAL_FUNC(_splitbar_child_size_allocate), NULL);
5606 #endif
5607 gtk_paned_set_handle_size(GTK_PANED(tmp), 3);
5608 gtk_widget_show(tmp);
5609 DW_MUTEX_UNLOCK;
5610 return tmp;
5611 }
5612
5613 /*
5614 * Sets the position of a splitbar (pecentage).
5615 * Parameters:
5616 * handle: The handle to the splitbar returned by dw_splitbar_new().
5617 */
5618 void dw_splitbar_set(HWND handle, int percent)
5619 {
5620 /* We probably need to force a redraw here */
5621 dw_window_set_data(handle, "_dw_percent", (void *)percent);
5622 }
5623
5624 /*
5625 * Gets the position of a splitbar (pecentage).
5626 * Parameters:
5627 * handle: The handle to the splitbar returned by dw_splitbar_new().
5628 */
5629 int dw_splitbar_get(HWND handle)
5630 {
5631 return (int)dw_window_get_data(handle, "_dw_percent");
5546 } 5632 }
5547 5633
5548 /* 5634 /*
5549 * Pack windows (widgets) into a box from the start (or top). 5635 * Pack windows (widgets) into a box from the start (or top).
5550 * Parameters: 5636 * Parameters: