示例#1
0
/****  Horizontal scrollbar constructor ****/
int
clip_GTK_HSCROLLBARNEW(ClipMachine * ClipMachineMemory)
{
   ClipVar  *cv = _clip_spar(ClipMachineMemory, 1);

   C_widget *cadj = _fetch_cwidget(ClipMachineMemory, _clip_spar(ClipMachineMemory, 2));

   GtkAdjustment *adj;

   GtkWidget *wid = NULL;

   C_widget *cwid;

   CHECKOPT(1, MAP_type_of_ClipVarType);
   CHECKOPT2(2, MAP_type_of_ClipVarType, NUMERIC_type_of_ClipVarType);
   CHECKCWIDOPT(cadj, GTK_IS_ADJUSTMENT);

   adj = cadj ? GTK_ADJUSTMENT(cadj->widget) : NULL;
   wid = gtk_hscrollbar_new(adj);
   if (!wid)
      goto err;
   cwid = _register_widget(ClipMachineMemory, wid, cv);
   _clip_mclone(ClipMachineMemory, RETPTR(ClipMachineMemory), &cwid->obj);
   return 0;
 err:
   return 1;
}
示例#2
0
Scrollbar::Scrollbar(bool horizontal) {
	XOJ_INIT_TYPE(Scrollbar);

#ifdef ENABLE_OS
	if(horizontal) {
		this->scrollbar = os_scrollbar_new(GTK_ORIENTATION_HORIZONTAL, NULL);
	} else {
		this->scrollbar = os_scrollbar_new(GTK_ORIENTATION_VERTICAL, NULL);
	}
#else
	if (horizontal) {
		this->scrollbar = gtk_hscrollbar_new(NULL);
	} else {
		this->scrollbar = gtk_vscrollbar_new(NULL);
	}
#endif

	g_object_ref(this->scrollbar);

	this->listener = NULL;
	this->adj = gtk_range_get_adjustment(GTK_RANGE(this->scrollbar));

	gtk_adjustment_set_step_increment(this->adj, 20);

	this->value = 50;
	this->setMax(100);
	this->setValue(this->value);

	g_signal_connect(this->adj, "value-changed", G_CALLBACK(scrolled), this);
}
示例#3
0
JNIEXPORT jlong JNICALL
Java_org_gnome_gtk_GtkHScrollbar_gtk_1hscrollbar_1new
(
	JNIEnv* env,
	jclass cls,
	jlong _adjustment
)
{
	GtkWidget* result;
	jlong _result;
	GtkAdjustment* adjustment;

	// convert parameter adjustment
	adjustment = (GtkAdjustment*) _adjustment;

	// call function
	result = gtk_hscrollbar_new(adjustment);

	// cleanup parameter adjustment

	// translate return value to JNI type
	_result = (jlong) result;

	// cleanup return value
	if (result != NULL) {
		bindings_java_memory_cleanup((GObject*)result, TRUE);
	}

	// and finally
	return _result;
}
示例#4
0
static void
_ddisplay_setup_scrollbars (DDisplay *ddisp, GtkWidget *table, int width, int height)
{
  /*  The adjustment datums  */
  ddisp->hsbdata = GTK_ADJUSTMENT (gtk_adjustment_new (0, 0, width, 1, (width-1)/4, width-1));
  ddisp->vsbdata = GTK_ADJUSTMENT (gtk_adjustment_new (0, 0, height, 1, (height-1)/4, height-1));

  ddisp->hsb = gtk_hscrollbar_new (ddisp->hsbdata);
#if GTK_CHECK_VERSION(2,18,0)
  gtk_widget_set_can_focus (ddisp->hsb, FALSE);
#else
  GTK_WIDGET_UNSET_FLAGS (ddisp->hsb, GTK_CAN_FOCUS);
#endif
  ddisp->vsb = gtk_vscrollbar_new (ddisp->vsbdata);
#if GTK_CHECK_VERSION(2,18,0)
  gtk_widget_set_can_focus (ddisp->vsb, FALSE);
#else
  GTK_WIDGET_UNSET_FLAGS (ddisp->vsb, GTK_CAN_FOCUS);
#endif

  /*  set up the scrollbar observers  */
  g_signal_connect (G_OBJECT (ddisp->hsbdata), "value_changed",
		    G_CALLBACK(ddisplay_hsb_update), ddisp);
  g_signal_connect (G_OBJECT (ddisp->vsbdata), "value_changed",
		    G_CALLBACK(ddisplay_vsb_update), ddisp);

  /* harder to change position in the table, but we did not do it for years ;) */
  gtk_table_attach (GTK_TABLE (table), ddisp->hsb, 0, 2, 2, 3,
                    GTK_EXPAND | GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
  gtk_table_attach (GTK_TABLE (table), ddisp->vsb, 2, 3, 0, 2,
                    GTK_FILL, GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);

  gtk_widget_show (ddisp->hsb);
  gtk_widget_show (ddisp->vsb);
}
示例#5
0
GtkWidget *
gtk_scrollbar_new( GtkOrientation orientation, GtkAdjustment *adjustment )
{
  return ( orientation == GTK_ORIENTATION_HORIZONTAL )?
          gtk_hscrollbar_new( adjustment ) :
          gtk_vscrollbar_new( adjustment );
}
示例#6
0
GuiScale GuiScale_create (GuiForm parent, int left, int right, int top, int bottom,
	int minimum, int maximum, int value, unsigned long flags)
{
	GuiScale me = Thing_new (GuiScale);
	my d_shell = parent -> d_shell;
	my d_parent = parent;
	#if gtk
		my d_widget = gtk_hscrollbar_new (NULL);
		gtk_range_set_range (GTK_RANGE (my d_widget), 0, 1000);
		GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (my d_widget));
		adj -> page_size = 150;
		gtk_adjustment_changed (adj);
		_GuiObject_setUserData (my d_widget, me);
		my v_positionInForm (my d_widget, left, right, top, bottom, parent);
		g_signal_connect (G_OBJECT (my d_widget), "destroy", G_CALLBACK (_GuiGtkScale_destroyCallback), me);
	#elif cocoa
	#elif motif
		my d_widget = XmCreateScale (parent -> d_widget, "scale", NULL, 0);
		_GuiObject_setUserData (my d_widget, me);
		my v_positionInForm (my d_widget, left, right, top, bottom, parent);
		XtVaSetValues (my d_widget, XmNorientation, XmHORIZONTAL,
			XmNminimum, minimum, XmNmaximum, maximum, XmNvalue, value, //XmNy, 300,
			#ifdef macintosh
				//XmNscaleWidth, 340,
			#endif
			NULL);
	#endif
	return me;
}
示例#7
0
void gScrollBar::resize(int w, int h)
{
	GtkAdjustment* adj;
	GType type;
	
	gControl::resize(w, h);
	
	type = (w < h) ? GTK_TYPE_VSCROLLBAR : GTK_TYPE_HSCROLLBAR;
	
	if (type != G_OBJECT_TYPE(widget))
	{
		adj = gtk_range_get_adjustment(GTK_RANGE(widget));
		g_object_ref(adj);

		g_object_ref(widget);
		gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(widget)), widget);
		gtk_widget_destroy(widget);
		g_object_unref(widget);
		
		if (type == GTK_TYPE_VSCROLLBAR)
			widget = gtk_vscrollbar_new(adj);
		else
			widget = gtk_hscrollbar_new(adj);
		
		gtk_container_add(GTK_CONTAINER(border), widget);
		gtk_widget_show(widget);
		widgetSignals();
		g_signal_connect(G_OBJECT(widget), "value-changed", G_CALLBACK(cb_change), (gpointer)this);
		
		g_object_unref(adj);	
		
		init();
	}
}
示例#8
0
void OnLuminosite(GtkWidget* widget, gpointer data) {
  (void) widget;
  (void) data;

  /* Creation de la boite de dialogue */
  /* 1 bouton Valider */
  /* 1 bouton Annuler */
  GtkWidget* pBoite = gtk_dialog_new_with_buttons("Luminosite", NULL,
      GTK_DIALOG_MODAL,
      GTK_STOCK_OK,GTK_RESPONSE_OK,
      GTK_STOCK_CANCEL,GTK_RESPONSE_CANCEL,
      NULL);

  /* Label d'affichage de valeur */
  GtkWidget *pLabel  = gtk_label_new("100 %");
  gtk_box_pack_start(GTK_BOX(GTK_DIALOG(pBoite)->vbox), pLabel, FALSE, FALSE, 0);
  /* Creation d un GtkAdjustment */
  GtkObject *Adjust = gtk_adjustment_new(0, 0, 201, 1, 10, 1);
  gtk_adjustment_set_value(GTK_ADJUSTMENT(Adjust), 100);
  /* Creation d une scrollbar horizontale*/
  GtkWidget *pScrollbar = gtk_hscrollbar_new(GTK_ADJUSTMENT(Adjust));
  gtk_box_pack_start(GTK_BOX(GTK_DIALOG(pBoite)->vbox), pScrollbar, TRUE, TRUE, 0);
  /* Connexion du signal pour modification de l affichage */
  g_signal_connect(G_OBJECT(pScrollbar), "value-changed", G_CALLBACK(OnScrollbarChange), (GtkWidget*)pLabel);
  /* Affichage des elements de la boite de dialogue */
  gtk_widget_show_all(GTK_DIALOG(pBoite)->vbox);

  if (gtk_dialog_run(GTK_DIALOG(pBoite)) == GTK_RESPONSE_OK) {
    pile_new_image(modifier_lumin(cur_image, gtk_range_get_value(GTK_RANGE(pScrollbar))));
  }

  /* Destruction de la boite de dialogue */
  gtk_widget_destroy(pBoite);
}
示例#9
0
int main(int argc, char *argv[])
{    
    gtk_init(&argc, &argv);
    
    GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL);
    
    GtkWidget *table = gtk_table_new(2, 2, FALSE);
    gtk_container_add(GTK_CONTAINER(window), table);
    
    GtkWidget *layout = gtk_layout_new(NULL, NULL);
    gtk_layout_set_size(GTK_LAYOUT(layout), 2000, 800);
    gtk_table_attach(GTK_TABLE(table), layout, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
    GtkAdjustment *vadjustment = gtk_layout_get_vadjustment(GTK_LAYOUT(layout));
    GtkAdjustment *hadjustment = gtk_layout_get_hadjustment(GTK_LAYOUT(layout));
    
    GtkWidget *vscrollbar = gtk_vscrollbar_new(vadjustment);
    gtk_table_attach(GTK_TABLE(table), vscrollbar, 1, 2, 0, 1, GTK_SHRINK, GTK_FILL | GTK_EXPAND, 0, 0);
    
    GtkWidget *hscrollbar = gtk_hscrollbar_new(hadjustment);
    gtk_table_attach(GTK_TABLE(table), hscrollbar, 0, 1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
    
    gtk_widget_show_all(window);
    
    gtk_main();
    
    return 0;
}
示例#10
0
static void
populate_table (widget_data_t *data)
{
    GtkWidget *table = data->widget;
    GtkWidget *drawing_area, *w;

    drawing_area = gtk_drawing_area_new();

    gtk_widget_show(drawing_area);
    data->drawing_area = drawing_area;

    gtk_table_attach (GTK_TABLE (table), drawing_area,
		      0, 1, 0, 1,
		      GTK_EXPAND | GTK_FILL | GTK_SHRINK,
		      GTK_EXPAND | GTK_FILL | GTK_SHRINK,
		      0, 0);

    data->hadjustment = GTK_ADJUSTMENT(gtk_adjustment_new (0.0, 0.0, 100.0, 10.0, 100.0, 100.0));
    w = gtk_hscrollbar_new (data->hadjustment);
    gtk_table_attach (GTK_TABLE (table), w,
		      0, 1, 1, 2,
		      GTK_EXPAND | GTK_FILL | GTK_SHRINK,
		      GTK_FILL,
		      0, 0);
    gtk_widget_show (w);
    data->hscrollbar = w;

    data->vadjustment = GTK_ADJUSTMENT(gtk_adjustment_new (0.0, 0.0, 100.0, 10.0, 100.0, 100.0));
    w = gtk_vscrollbar_new (data->vadjustment);
    gtk_table_attach (GTK_TABLE (table), w,
		      1, 2, 0, 1,
		      GTK_FILL,
		      GTK_EXPAND | GTK_FILL | GTK_SHRINK,
		      0, 0);
    gtk_widget_show (w);
    data->vscrollbar = w;

    gtk_signal_connect(GTK_OBJECT(drawing_area), "expose_event",
		       (GtkSignalFunc)expose_event, NULL);
    gtk_signal_connect(GTK_OBJECT(drawing_area), "motion_notify_event",
		       (GtkSignalFunc)motion_notify_event, NULL);
    gtk_signal_connect(GTK_OBJECT(drawing_area), "button_press_event",
		       (GtkSignalFunc)button_press_event, NULL);
    gtk_signal_connect(GTK_OBJECT(drawing_area), "button_release_event",
		       (GtkSignalFunc)button_release_event, NULL);
    gtk_widget_set_events(drawing_area, GDK_EXPOSURE_MASK
			  | GDK_LEAVE_NOTIFY_MASK
			  | GDK_BUTTON_PRESS_MASK
			  | GDK_BUTTON_RELEASE_MASK
			  | GDK_POINTER_MOTION_MASK
			  | GDK_POINTER_MOTION_HINT_MASK);

    gtk_signal_connect(GTK_OBJECT(data->hadjustment), "value-changed", (GtkSignalFunc)adjustment_value_changed, data);
    gtk_signal_connect(GTK_OBJECT(data->vadjustment), "value-changed", (GtkSignalFunc)adjustment_value_changed, data);
    gtk_signal_connect(GTK_OBJECT(data->hadjustment), "changed", (GtkSignalFunc)adjustment_changed, data);
    gtk_signal_connect(GTK_OBJECT(data->vadjustment), "changed", (GtkSignalFunc)adjustment_changed, data);

    gtk_signal_connect(GTK_OBJECT(data->drawing_area), "size-allocate", (GtkSignalFunc)size_changed, data);
}
示例#11
0
GtkWidget* RenderThemeGtk::gtkHScrollbar() const
{
    if (m_gtkHScrollbar)
        return m_gtkHScrollbar;
    m_gtkHScrollbar = gtk_hscrollbar_new(0);
    setupWidgetAndAddToContainer(m_gtkHScrollbar, gtkContainer());
    return m_gtkHScrollbar;
}
示例#12
0
/*#
    @class GtkHScrollbar
    @brief A horizontal scrollbar
    @param adjustment the GtkAdjustment to use, or NULL to create a new adjustment

    The GtkHScrollbar widget is a widget arranged horizontally creating a
    scrollbar. See GtkScrollbar for details on scrollbars. GtkAdjustment
    pointers may be added to handle the adjustment of the scrollbar or it
    may be left NULL in which case one will be created for you.
    See GtkScrollbar for a description of what the fields in an adjustment
    represent for a scrollbar.
 */
FALCON_FUNC HScrollbar::init( VMARG )
{
    Item* i_adj = vm->param( 0 );
#ifndef NO_PARAMETER_CHECK
    if ( !i_adj || !( i_adj->isNil() || ( i_adj->isObject()
        && IS_DERIVED( i_adj, GtkAdjustment ) ) ) )
        throw_inv_params( "[GtkAdjustment]" );
#endif
    GtkAdjustment* adj = i_adj->isNil() ? NULL : GET_ADJUSTMENT( *i_adj );
    MYSELF;
    self->setObject( (GObject*) gtk_hscrollbar_new( adj ) );
}
示例#13
0
static VALUE
rg_initialize(int argc, VALUE *argv, VALUE self)
{
    VALUE arg1;
    GtkAdjustment *adj = NULL;

    rb_scan_args(argc, argv, "01", &arg1);
    if (!NIL_P(arg1)) adj = GTK_ADJUSTMENT(RVAL2GOBJ(arg1));

    RBGTK_INITIALIZE(self, gtk_hscrollbar_new(adj));
    return Qnil;
}
示例#14
0
static gint
ensure_scrollbar_widget()
{
    if (!gParts->vertScrollbarWidget) {
        gParts->vertScrollbarWidget = gtk_vscrollbar_new(NULL);
        setup_widget_prototype(gParts->vertScrollbarWidget);
    }
    if (!gParts->horizScrollbarWidget) {
        gParts->horizScrollbarWidget = gtk_hscrollbar_new(NULL);
        setup_widget_prototype(gParts->horizScrollbarWidget);
    }
    return MOZ_GTK_SUCCESS;
}
示例#15
0
GtkWidget *
create_signalwindow(void)
{
GtkWidget *table;
GtkWidget *frame;

table = gtk_table_new(10, 10, FALSE);

signalarea=gtk_drawing_area_new();

gtk_widget_show(signalarea);
MaxSignalLength();

gtk_widget_set_events(signalarea, 
		GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | 
		GDK_BUTTON_RELEASE_MASK | 
		GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK
		);

gtk_signal_connect(GTK_OBJECT(signalarea), "configure_event",
                        GTK_SIGNAL_FUNC(signalarea_configure_event), NULL);
gtk_signal_connect(GTK_OBJECT(signalarea), "expose_event",
                        GTK_SIGNAL_FUNC(expose_event), NULL);
gtk_signal_connect(GTK_OBJECT(signalarea), "button_press_event",
                        GTK_SIGNAL_FUNC(button_press_event), NULL);
gtk_signal_connect(GTK_OBJECT(signalarea), "button_release_event",
                        GTK_SIGNAL_FUNC(button_release_event), NULL);
gtk_signal_connect(GTK_OBJECT(signalarea), "motion_notify_event",
                        GTK_SIGNAL_FUNC(motion_notify_event), NULL);

gtk_table_attach (GTK_TABLE (table), signalarea, 0, 10, 0, 9,
                        GTK_FILL | GTK_EXPAND,
                        GTK_FILL | GTK_EXPAND | GTK_SHRINK, 3, 3);

signal_hslider=gtk_adjustment_new(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
gtk_signal_connect(GTK_OBJECT(signal_hslider), "value_changed",
                        GTK_SIGNAL_FUNC(service_hslider), NULL);
hscroll=gtk_hscrollbar_new(GTK_ADJUSTMENT(signal_hslider));
gtk_widget_show(hscroll);
gtk_table_attach (GTK_TABLE (table), hscroll, 0, 10, 9, 10,
                        GTK_FILL,
                        GTK_FILL | GTK_SHRINK, 3, 3);
gtk_widget_show(table);

frame=gtk_frame_new("Signals");
gtk_container_border_width(GTK_CONTAINER(frame),2);

gtk_container_add(GTK_CONTAINER(frame),table);

return(frame);
}
示例#16
0
gScrollBar::gScrollBar(gContainer *par) : gSlider(par, true)
{
	g_typ = Type_gScrollBar;
	widget = gtk_hscrollbar_new(NULL);
	realize(false);
	
	init();
	onChange = NULL;
	
#ifndef GTK3
	gtk_range_set_update_policy(GTK_RANGE(widget),GTK_UPDATE_CONTINUOUS);
#endif
	g_signal_connect(G_OBJECT(widget), "value-changed", G_CALLBACK(cb_change), (gpointer)this);
}
示例#17
0
bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
           const wxPoint& pos, const wxSize& size,
           long style, const wxValidator& validator, const wxString& name )
{
    m_needParent = true;
    m_acceptsFocus = true;

    if (!PreCreation( parent, pos, size ) ||
        !CreateBase( parent, id, pos, size, style, validator, name ))
    {
        wxFAIL_MSG( wxT("wxScrollBar creation failed") );
        return false;
    }

    const bool isVertical = (style & wxSB_VERTICAL) != 0;
    if (isVertical)
        m_widget = gtk_vscrollbar_new( (GtkAdjustment *) NULL );
    else
        m_widget = gtk_hscrollbar_new( (GtkAdjustment *) NULL );

    m_scrollBar[int(isVertical)] = (GtkRange*)m_widget;

    g_signal_connect(m_widget, "value_changed",
                     G_CALLBACK(gtk_value_changed), this);
    g_signal_connect(m_widget, "button_press_event",
                     G_CALLBACK(gtk_button_press_event), this);
    g_signal_connect(m_widget, "button_release_event",
                     G_CALLBACK(gtk_button_release_event), this);

    gulong handler_id;
    handler_id = g_signal_connect(
        m_widget, "event_after", G_CALLBACK(gtk_event_after), this);
    g_signal_handler_block(m_widget, handler_id);

    m_parent->DoAddChild( this );

    PostCreation(size);

    return true;
}
示例#18
0
/* "message"를 보여주는 스크롤된 텍스트 영역을 만든다. */
GtkWidget *
create_text (void)
{
    GtkWidget *table;
    GtkWidget *text;
    GtkWidget *hscrollbar;
    GtkWidget *vscrollbar;
   
    /* 텍스트 위젯과 스크롤바를 갖는 테이블을 만든다 */
    table = gtk_table_new (2, 2, FALSE);
   
    /* 텍스트 위젯을 왼쪽 위에 놓는다. Y 축 방향으로 GTK_SHRINK가 쓰인 것을
     * 주목할 것. */
    text = gtk_text_new (NULL, NULL);
    gtk_table_attach (GTK_TABLE (table), text, 0, 1, 0, 1,
                      GTK_FILL | GTK_EXPAND,
                      GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 0);
    gtk_widget_show (text);
   
    /* HScrollbar를 왼쪽 아래에 놓는다. */
    hscrollbar = gtk_hscrollbar_new (GTK_TEXT (text)->hadj);
    gtk_table_attach (GTK_TABLE (table), hscrollbar, 0, 1, 1, 2,
                      GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
    gtk_widget_show (hscrollbar);
   
    /* VScrollbar를 오른쪽 위에 놓는다. */
    vscrollbar = gtk_vscrollbar_new (GTK_TEXT (text)->vadj);
    gtk_table_attach (GTK_TABLE (table), vscrollbar, 1, 2, 0, 1,
                      GTK_FILL, GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, 0);
    gtk_widget_show (vscrollbar);
   
    /* 텍스트 widget이 realize되었을 때 그 widget이 갖고 있는 메시지를
     * 출력하여주는 시그널 핸들러를 더한다. */
    gtk_signal_connect (GTK_OBJECT (text), "realize",
                        GTK_SIGNAL_FUNC (realize_text), NULL);
   
    return table;
}
示例#19
0
static void
uni_scroll_win_set_view (UniScrollWin * window, UniImageView * view)
{
    // Setup the scrollbars
    GtkAdjustment *hadj;
    hadj = (GtkAdjustment *) g_object_new (GTK_TYPE_ADJUSTMENT, NULL);

    GtkAdjustment *vadj;
    vadj = (GtkAdjustment *) g_object_new (GTK_TYPE_ADJUSTMENT, NULL);

    window->hscroll = gtk_hscrollbar_new (hadj);
    window->vscroll = gtk_vscrollbar_new (vadj);

    // We want to be notified when the adjustments change.
    g_signal_connect (hadj, "changed",
                      G_CALLBACK (uni_scroll_win_adjustment_changed), window);
    g_signal_connect (vadj, "changed",
                      G_CALLBACK (uni_scroll_win_adjustment_changed), window);

    // Output the adjustments to the widget.
    gtk_widget_set_scroll_adjustments (GTK_WIDGET (view), hadj, vadj);

    // Add the widgets to the table.
    gtk_widget_push_composite_child ();
    gtk_table_attach (GTK_TABLE (window), GTK_WIDGET (view), 0, 1, 0, 1,
                      GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
    gtk_table_attach (GTK_TABLE (window), window->vscroll, 1, 2, 0, 1,
                      GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
    gtk_table_attach (GTK_TABLE (window), window->hscroll, 0, 1, 1, 2,
                      GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
    gtk_table_attach (GTK_TABLE (window), window->nav_box, 1, 2, 1, 2,
                      GTK_SHRINK, GTK_SHRINK, 0, 0);
    gtk_widget_pop_composite_child ();

    // Create the UniNav popup.
    window->nav = uni_nav_new (view);
}
JNIEXPORT void JNICALL 
Java_gnu_java_awt_peer_gtk_GtkScrollbarPeer_create
(JNIEnv *env, jobject obj, jint orientation, jint value, 
 jint min, jint max, jint step_incr, jint page_incr, jint visible_amount)
{
  GtkWidget *sb;
  GtkObject *adj;

  /* Create global reference and save it for future use */
  NSA_SET_GLOBAL_REF (env, obj);

  gdk_threads_enter ();
  
  adj = gtk_adjustment_new (value, min, max, 
			    step_incr, page_incr, 
			    visible_amount);

  sb = (orientation) ? gtk_vscrollbar_new (GTK_ADJUSTMENT (adj)) :
                       gtk_hscrollbar_new (GTK_ADJUSTMENT (adj));

  gdk_threads_leave ();

  NSA_SET_PTR (env, obj, sb);
}
示例#21
0
文件: rangewidgets.c 项目: dimkr/gtk
void create_range_controls( void )
{
    GtkWidget *window;
    GtkWidget *box1, *box2, *box3;
    GtkWidget *button;
    GtkWidget *scrollbar;
    GtkWidget *separator;
    GtkWidget *opt, *menu, *item;
    GtkWidget *label;
    GtkWidget *scale;
    GtkObject *adj1, *adj2;

    /* Standard window-creating stuff */
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_signal_connect (GTK_OBJECT (window), "destroy",
                        GTK_SIGNAL_FUNC(gtk_main_quit),
                        NULL);
    gtk_window_set_title (GTK_WINDOW (window), "range controls");

    box1 = gtk_vbox_new (FALSE, 0);
    gtk_container_add (GTK_CONTAINER (window), box1);
    gtk_widget_show (box1);

    box2 = gtk_hbox_new (FALSE, 10);
    gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
    gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
    gtk_widget_show (box2);

    /* value, lower, upper, step_increment, page_increment, page_size */
    /* Note that the page_size value only makes a difference for
     * scrollbar widgets, and the highest value you'll get is actually
     * (upper - page_size). */
    adj1 = gtk_adjustment_new (0.0, 0.0, 101.0, 0.1, 1.0, 1.0);
  
    vscale = gtk_vscale_new (GTK_ADJUSTMENT (adj1));
    scale_set_default_values (GTK_SCALE (vscale));
    gtk_box_pack_start (GTK_BOX (box2), vscale, TRUE, TRUE, 0);
    gtk_widget_show (vscale);

    box3 = gtk_vbox_new (FALSE, 10);
    gtk_box_pack_start (GTK_BOX (box2), box3, TRUE, TRUE, 0);
    gtk_widget_show (box3);

    /* Reuse the same adjustment */
    hscale = gtk_hscale_new (GTK_ADJUSTMENT (adj1));
    gtk_widget_set_usize (GTK_WIDGET (hscale), 200, 30);
    scale_set_default_values (GTK_SCALE (hscale));
    gtk_box_pack_start (GTK_BOX (box3), hscale, TRUE, TRUE, 0);
    gtk_widget_show (hscale);

    /* Reuse the same adjustment again */
    scrollbar = gtk_hscrollbar_new (GTK_ADJUSTMENT (adj1));
    /* Notice how this causes the scales to always be updated
     * continuously when the scrollbar is moved */
    gtk_range_set_update_policy (GTK_RANGE (scrollbar), 
                                 GTK_UPDATE_CONTINUOUS);
    gtk_box_pack_start (GTK_BOX (box3), scrollbar, TRUE, TRUE, 0);
    gtk_widget_show (scrollbar);

    box2 = gtk_hbox_new (FALSE, 10);
    gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
    gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
    gtk_widget_show (box2);

    /* A checkbutton to control whether the value is displayed or not */
    button = gtk_check_button_new_with_label("Display value on scale widgets");
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
    gtk_signal_connect (GTK_OBJECT (button), "toggled",
                        GTK_SIGNAL_FUNC(cb_draw_value), NULL);
    gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
    gtk_widget_show (button);
  
    box2 = gtk_hbox_new (FALSE, 10);
    gtk_container_set_border_width (GTK_CONTAINER (box2), 10);

    /* An option menu to change the position of the value */
    label = gtk_label_new ("Scale Value Position:");
    gtk_box_pack_start (GTK_BOX (box2), label, FALSE, FALSE, 0);
    gtk_widget_show (label);
  
    opt = gtk_option_menu_new();
    menu = gtk_menu_new();

    item = make_menu_item ("Top",
                           GTK_SIGNAL_FUNC(cb_pos_menu_select),
                           GINT_TO_POINTER (GTK_POS_TOP));
    gtk_menu_append (GTK_MENU (menu), item);
  
    item = make_menu_item ("Bottom", GTK_SIGNAL_FUNC (cb_pos_menu_select), 
                           GINT_TO_POINTER (GTK_POS_BOTTOM));
    gtk_menu_append (GTK_MENU (menu), item);
  
    item = make_menu_item ("Left", GTK_SIGNAL_FUNC (cb_pos_menu_select),
                           GINT_TO_POINTER (GTK_POS_LEFT));
    gtk_menu_append (GTK_MENU (menu), item);
  
    item = make_menu_item ("Right", GTK_SIGNAL_FUNC (cb_pos_menu_select),
                            GINT_TO_POINTER (GTK_POS_RIGHT));
    gtk_menu_append (GTK_MENU (menu), item);
  
    gtk_option_menu_set_menu (GTK_OPTION_MENU (opt), menu);
    gtk_box_pack_start (GTK_BOX (box2), opt, TRUE, TRUE, 0);
    gtk_widget_show (opt);

    gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
    gtk_widget_show (box2);

    box2 = gtk_hbox_new (FALSE, 10);
    gtk_container_set_border_width (GTK_CONTAINER (box2), 10);

    /* Yet another option menu, this time for the update policy of the
     * scale widgets */
    label = gtk_label_new ("Scale Update Policy:");
    gtk_box_pack_start (GTK_BOX (box2), label, FALSE, FALSE, 0);
    gtk_widget_show (label);
  
    opt = gtk_option_menu_new();
    menu = gtk_menu_new();
  
    item = make_menu_item ("Continuous",
                           GTK_SIGNAL_FUNC (cb_update_menu_select),
                           GINT_TO_POINTER (GTK_UPDATE_CONTINUOUS));
    gtk_menu_append (GTK_MENU (menu), item);
  
    item = make_menu_item ("Discontinuous",
                            GTK_SIGNAL_FUNC (cb_update_menu_select),
                            GINT_TO_POINTER (GTK_UPDATE_DISCONTINUOUS));
    gtk_menu_append (GTK_MENU (menu), item);
  
    item = make_menu_item ("Delayed",
                           GTK_SIGNAL_FUNC (cb_update_menu_select),
                           GINT_TO_POINTER (GTK_UPDATE_DELAYED));
    gtk_menu_append (GTK_MENU (menu), item);
  
    gtk_option_menu_set_menu (GTK_OPTION_MENU (opt), menu);
    gtk_box_pack_start (GTK_BOX (box2), opt, TRUE, TRUE, 0);
    gtk_widget_show (opt);
  
    gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
    gtk_widget_show (box2);

    box2 = gtk_hbox_new (FALSE, 10);
    gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
  
    /* An HScale widget for adjusting the number of digits on the
     * sample scales. */
    label = gtk_label_new ("Scale Digits:");
    gtk_box_pack_start (GTK_BOX (box2), label, FALSE, FALSE, 0);
    gtk_widget_show (label);

    adj2 = gtk_adjustment_new (1.0, 0.0, 5.0, 1.0, 1.0, 0.0);
    gtk_signal_connect (GTK_OBJECT (adj2), "value_changed",
                        GTK_SIGNAL_FUNC (cb_digits_scale), NULL);
    scale = gtk_hscale_new (GTK_ADJUSTMENT (adj2));
    gtk_scale_set_digits (GTK_SCALE (scale), 0);
    gtk_box_pack_start (GTK_BOX (box2), scale, TRUE, TRUE, 0);
    gtk_widget_show (scale);

    gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
    gtk_widget_show (box2);
  
    box2 = gtk_hbox_new (FALSE, 10);
    gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
  
    /* And, one last HScale widget for adjusting the page size of the
     * scrollbar. */
    label = gtk_label_new ("Scrollbar Page Size:");
    gtk_box_pack_start (GTK_BOX (box2), label, FALSE, FALSE, 0);
    gtk_widget_show (label);

    adj2 = gtk_adjustment_new (1.0, 1.0, 101.0, 1.0, 1.0, 0.0);
    gtk_signal_connect (GTK_OBJECT (adj2), "value_changed",
                        GTK_SIGNAL_FUNC (cb_page_size), adj1);
    scale = gtk_hscale_new (GTK_ADJUSTMENT (adj2));
    gtk_scale_set_digits (GTK_SCALE (scale), 0);
    gtk_box_pack_start (GTK_BOX (box2), scale, TRUE, TRUE, 0);
    gtk_widget_show (scale);

    gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
    gtk_widget_show (box2);

    separator = gtk_hseparator_new ();
    gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
    gtk_widget_show (separator);

    box2 = gtk_vbox_new (FALSE, 10);
    gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
    gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
    gtk_widget_show (box2);

    button = gtk_button_new_with_label ("Quit");
    gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
                               GTK_SIGNAL_FUNC(gtk_main_quit),
                               NULL);
    gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
    GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
    gtk_widget_grab_default (button);
    gtk_widget_show (button);

    gtk_widget_show (window);
}
示例#22
0
static void midi_section_init(MidiSection* self)
{
    MidiSectionPrivate* p = MIDI_SECTION_GET_PRIVATE(self);
    GtkBox* box = GTK_BOX(self);
    GtkWidget* pad;
    GtkWidget* view;
    GtkWidget* scroll;
    GnomeCanvas* canvas;
    GnomeCanvasPoints* points;
    int x1, x2, y1, y2;

    p->patch = -1;
    p->ignore = FALSE;
    x1 = 0;
    y1 = 0;
    x2 = (PHIN_KEYBOARD_KEY_WIDTH * MIDI_NOTES);
    y2 = HEIGHT;

    /* adjustment */
    p->adj = (GtkAdjustment*) gtk_adjustment_new(0, 0, 0, 0, 0, 0);

    /* viewport */
    view = gtk_viewport_new(p->adj, NULL);
    gtk_box_pack_start(box, view, FALSE, FALSE, 0);
    gtk_viewport_set_shadow_type(GTK_VIEWPORT(view), GTK_SHADOW_NONE);
    gtk_widget_set_size_request(view, 0, y2);
    gtk_widget_show(view);

    /* canvas */
    canvas = (GnomeCanvas*) gnome_canvas_new();
    gtk_widget_set_size_request(GTK_WIDGET(canvas), x2,	y2);
    gnome_canvas_set_scroll_region(canvas, 0, 0, x2 - 1, y2 -1);
    gtk_container_add(GTK_CONTAINER(view), GTK_WIDGET(canvas));
    g_signal_connect(G_OBJECT(canvas), "event",
		     G_CALLBACK(range_cb), (gpointer)p);
    gtk_widget_show(GTK_WIDGET(canvas));

    /* range display backdrop */
    gnome_canvas_item_new(gnome_canvas_root(canvas),
			  gnome_canvas_rect_get_type(),
			  "x1", (gdouble)0,
			  "y1", (gdouble)0,
			  "x2", (gdouble)x2,
			  "y2", (gdouble)y2,
			  "fill-color-rgba", BG_COLOR,
			  NULL);
    /* range */
    p->range = gnome_canvas_item_new(gnome_canvas_root(canvas),
					gnome_canvas_rect_get_type(),
					"x1", (gdouble)x1,
					"y1", (gdouble)y1,
					"x2", (gdouble)PHIN_KEYBOARD_KEY_WIDTH,
					"y2", (gdouble)y2,
					"fill-color-rgba", RANGE_COLOR,
					"outline-color", "black",
					NULL);
    gnome_canvas_item_hide(p->range);
    
    /* range root note */
    p->note = gnome_canvas_item_new(gnome_canvas_root(canvas),
				       gnome_canvas_rect_get_type(),
				       "x1", (gdouble)x1,
				       "y1", (gdouble)y1,
				       "x2", (gdouble)PHIN_KEYBOARD_KEY_WIDTH,
				       "y2", (gdouble)y2,
				       "fill-color-rgba", NOTE_COLOR,
				       "outline-color", "black",
				       NULL);
    gnome_canvas_item_hide(p->note);

    p->canvas = canvas;

    /* range display border */
    points = gnome_canvas_points_new(4);

    points->coords[0] = x1;
    points->coords[1] = y2;
    points->coords[2] = x1;
    points->coords[3] = y1;
    points->coords[4] = x2-1;
    points->coords[5] = y1;
    points->coords[6] = x2-1;
    points->coords[7] = y2;

    gnome_canvas_item_new(gnome_canvas_root(canvas),
			  gnome_canvas_line_get_type(),
			  "points", points,
			  "width-units", (gdouble)1,
			  "fill-color-rgba", 0,
			  NULL);
    gnome_canvas_points_unref(points);


    /* keyboard */
    p->keyboard = phin_hkeyboard_new(p->adj, MIDI_NOTES, TRUE);
    gtk_box_pack_start(box, p->keyboard, FALSE, FALSE, 0);
    gtk_widget_show(p->keyboard);

    /* vpad */
    pad = gui_vpad_new(GUI_SCROLLSPACE);
    gtk_box_pack_start(box, pad, FALSE, FALSE, 0);
    gtk_widget_show(pad);

    /* scrollbar */
    scroll = gtk_hscrollbar_new(p->adj);
    gtk_box_pack_start(box, scroll, FALSE, FALSE, 0);
    gtk_widget_show(scroll);

    /* done */
    connect(p);
}
示例#23
0
    //____________________________________________________
    SliderDemoWidget::SliderDemoWidget( void )
    {

        // main widget
        GtkWidget* mainWidget( gtk_hbox_new( false, 0 ) );
        gtk_box_set_spacing( GTK_BOX( mainWidget ), 5 );
        setWidget( mainWidget );

        // setup
        setName( "Sliders" );
        setComments( "Shows the appearance of sliders, progress bars and scrollbars" );
        setIconName( "measure" );
        realize();

        // horizontal sliders
        {

            // frame
            GtkWidget* frame( gtk_frame_new( "Horizontal" ) );
            gtk_box_pack_start( GTK_BOX( mainWidget ), frame, true, true, 0 );
            gtk_widget_show( frame );

            // container
            GtkWidget* box( gtk_vbox_new( false, 0 ) );
            gtk_container_set_border_width( GTK_CONTAINER( box ), 5 );
            gtk_box_set_spacing( GTK_BOX( box ), 2 );
            gtk_widget_show( box );
            gtk_container_add( GTK_CONTAINER( frame ), box );

            // scale
            _horizontalSliders._scale = gtk_hscale_new_with_range( 0, 100, 1 );
            gtk_scale_set_draw_value( GTK_SCALE( _horizontalSliders._scale ), false );
            gtk_box_pack_start( GTK_BOX( box ), _horizontalSliders._scale, false, true, 0 );
            gtk_widget_show( _horizontalSliders._scale );


            // progress entry
            _horizontalSliders._progressEntry = gtk_entry_new();
            gtk_entry_set_text( GTK_ENTRY( _horizontalSliders._progressEntry ), "Progress Bar Entry" );
            gtk_entry_set_progress_fraction( GTK_ENTRY( _horizontalSliders._progressEntry ), 0.25 );
            gtk_box_pack_start( GTK_BOX( box ), _horizontalSliders._progressEntry, false, true, 0 );
            gtk_widget_show( _horizontalSliders._progressEntry );

            // progress bar
            _horizontalSliders._progressBar = gtk_progress_bar_new();
            #if GTK_CHECK_VERSION(3, 0, 0)
            gtk_orientable_set_orientation( GTK_ORIENTABLE( _horizontalSliders._progressBar ), GTK_ORIENTATION_HORIZONTAL );
            #else
            gtk_progress_bar_set_orientation( GTK_PROGRESS_BAR( _horizontalSliders._progressBar ), GTK_PROGRESS_LEFT_TO_RIGHT );
            #endif

            gtk_progress_set_show_text( GTK_PROGRESS( _horizontalSliders._progressBar ), true );
            gtk_box_pack_start( GTK_BOX( box ), _horizontalSliders._progressBar, false, true, 0 );
            gtk_widget_show( _horizontalSliders._progressBar );

            // pulse progressBar
            _pulseProgressBar = gtk_progress_bar_new();
            #if GTK_CHECK_VERSION(3, 0, 0)
            gtk_orientable_set_orientation( GTK_ORIENTABLE( _pulseProgressBar ), GTK_ORIENTATION_HORIZONTAL );
            #else
            gtk_progress_bar_set_orientation( GTK_PROGRESS_BAR( _pulseProgressBar ), GTK_PROGRESS_LEFT_TO_RIGHT );
            #endif

            gtk_progress_bar_set_pulse_step( GTK_PROGRESS_BAR( _pulseProgressBar ), 0.01 );
            gtk_box_pack_start( GTK_BOX( box ), _pulseProgressBar, false, true, 0 );
            gtk_widget_show( _pulseProgressBar );

            // scrollbar
            GtkAdjustment* adjustment( GTK_ADJUSTMENT( gtk_adjustment_new( 25, 0, 110, 1, 1, 10 ) ) );
            _horizontalSliders._scrollBar = gtk_hscrollbar_new( adjustment );
            gtk_box_pack_start( GTK_BOX( box ), _horizontalSliders._scrollBar, false, true, 0 );
            gtk_widget_show( _horizontalSliders._scrollBar );

        }

        // vertical sliders
        {

            // frame
            GtkWidget* frame( gtk_frame_new( "Vertical" ) );
            gtk_box_pack_start( GTK_BOX( mainWidget ), frame, false, true, 0 );
            gtk_widget_show( frame );

            // container
            GtkWidget* box( gtk_hbox_new( false, 0 ) );
            gtk_container_set_border_width( GTK_CONTAINER( box ), 5 );
            gtk_box_set_spacing( GTK_BOX( box ), 5 );
            gtk_widget_show( box );
            gtk_container_add( GTK_CONTAINER( frame ), box );

            // scale
            _verticalSliders._scale = gtk_vscale_new_with_range( 0, 100, 1 );
            gtk_scale_set_draw_value( GTK_SCALE( _verticalSliders._scale ), false );
            gtk_box_pack_start( GTK_BOX( box ), _verticalSliders._scale, false, true, 0 );
            gtk_widget_show( _verticalSliders._scale );

            // progress bar
            _verticalSliders._progressBar = gtk_progress_bar_new();
            #if GTK_CHECK_VERSION(3, 0, 0)
            gtk_orientable_set_orientation( GTK_ORIENTABLE( _verticalSliders._progressBar ), GTK_ORIENTATION_VERTICAL );
            #else
            gtk_progress_bar_set_orientation( GTK_PROGRESS_BAR( _verticalSliders._progressBar ), GTK_PROGRESS_BOTTOM_TO_TOP );
            #endif

            gtk_progress_set_show_text( GTK_PROGRESS( _verticalSliders._progressBar ), true );
            gtk_box_pack_start( GTK_BOX( box ), _verticalSliders._progressBar, false, true, 0 );
            gtk_widget_show( _verticalSliders._progressBar );

            // scrollbar
            GtkAdjustment* adjustment( GTK_ADJUSTMENT( gtk_adjustment_new( 25, 0, 110, 1, 1, 10 ) ) );
            _verticalSliders._scrollBar = gtk_vscrollbar_new( adjustment );
            gtk_box_pack_start( GTK_BOX( box ), _verticalSliders._scrollBar, false, true, 0 );
            gtk_widget_show( _verticalSliders._scrollBar );

        }

        // connections
        connect( G_OBJECT( _horizontalSliders._scale ), "value-changed", GCallback( valueChanged ), this );
        connect( G_OBJECT( _horizontalSliders._scrollBar ), "value-changed", GCallback( valueChanged ), this );

        connect( G_OBJECT( _verticalSliders._scale ), "value-changed", GCallback( valueChanged ), this );
        connect( G_OBJECT( _verticalSliders._scrollBar ), "value-changed", GCallback( valueChanged ), this );

        // Initialize all
        gtk_range_set_value( GTK_RANGE( _verticalSliders._scale ), 25 );
    }
示例#24
0
int
main (int argc, char *argv[])
{
  GtkWidget *dialog;
  GtkWidget *button;
  GtkWidget *table;
  GtkWidget *label;
  GtkWidget *entry;
  GtkWidget *hscrollbar;
  GtkWidget *vscrollbar;
  GtkWidget *hbox;

  static GtkTargetEntry targetlist[] = {
    { "STRING",        0, STRING },
    { "TEXT",          0, TEXT },
    { "COMPOUND_TEXT", 0, COMPOUND_TEXT }
  };
  static gint ntargets = sizeof(targetlist) / sizeof(targetlist[0]);
  
  gtk_init (&argc, &argv);

  init_atoms();

  selection_widget = gtk_invisible_new ();

  dialog = gtk_dialog_new ();
  gtk_widget_set_name (dialog, "Test Input");
  gtk_container_set_border_width (GTK_CONTAINER(dialog), 0);

  g_signal_connect (dialog, "destroy",
		    G_CALLBACK (quit), NULL);

  table = gtk_table_new (4, 2, FALSE);
  gtk_container_set_border_width (GTK_CONTAINER(table), 10);

  gtk_table_set_row_spacing (GTK_TABLE (table), 0, 5);
  gtk_table_set_row_spacing (GTK_TABLE (table), 1, 2);
  gtk_table_set_row_spacing (GTK_TABLE (table), 2, 2);
  gtk_table_set_col_spacing (GTK_TABLE (table), 0, 2);
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG(dialog)->vbox), 
		      table, TRUE, TRUE, 0);
  gtk_widget_show (table);
  
  selection_button = gtk_toggle_button_new_with_label ("Claim Selection");
  gtk_table_attach (GTK_TABLE (table), selection_button, 0, 2, 0, 1,
		    GTK_EXPAND | GTK_FILL, 0, 0, 0);
  gtk_widget_show (selection_button);

  g_signal_connect (selection_button, "toggled",
		    G_CALLBACK (selection_toggled), NULL);
  g_signal_connect (selection_widget, "selection_clear_event",
		    G_CALLBACK (selection_clear), NULL);
  g_signal_connect (selection_widget, "selection_received",
		    G_CALLBACK (selection_received), NULL);

  gtk_selection_add_targets (selection_widget, GDK_SELECTION_PRIMARY,
			     targetlist, ntargets);

  g_signal_connect (selection_widget, "selection_get",
		    G_CALLBACK (selection_get), NULL);

  selection_text = gtk_text_new (NULL, NULL);
  gtk_table_attach_defaults (GTK_TABLE (table), selection_text, 0, 1, 1, 2);
  gtk_widget_show (selection_text);
  
  hscrollbar = gtk_hscrollbar_new (GTK_TEXT (selection_text)->hadj);
  gtk_table_attach (GTK_TABLE (table), hscrollbar, 0, 1, 2, 3,
		    GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
  gtk_widget_show (hscrollbar);
  
  vscrollbar = gtk_vscrollbar_new (GTK_TEXT (selection_text)->vadj);
  gtk_table_attach (GTK_TABLE (table), vscrollbar, 1, 2, 1, 2,
		    GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
  gtk_widget_show (vscrollbar);

  hbox = gtk_hbox_new (FALSE, 2);
  gtk_table_attach (GTK_TABLE (table), hbox, 0, 2, 3, 4,
		    GTK_EXPAND | GTK_FILL, 0, 0, 0);
  gtk_widget_show (hbox);

  label = gtk_label_new ("Target:");
  gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
  gtk_widget_show (label);

  entry = gtk_entry_new ();
  gtk_box_pack_start (GTK_BOX(hbox), entry, TRUE, TRUE, 0);
  gtk_widget_show (entry);

  /* .. And create some buttons */
  button = gtk_button_new_with_label ("Paste");
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG(dialog)->action_area), 
		      button, TRUE, TRUE, 0);
  g_signal_connect (button, "clicked",
		    G_CALLBACK (paste), entry);
  gtk_widget_show (button);

  button = gtk_button_new_with_label ("Quit");
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG(dialog)->action_area), 
		      button, TRUE, TRUE, 0);

  g_signal_connect_swapped (button, "clicked",
			    G_CALLBACK (gtk_widget_destroy), dialog);
  gtk_widget_show (button);

  gtk_widget_show (dialog);

  gtk_main ();

  return 0;
}
示例#25
0
void timing_dia_window_show(struct vgpu_compute_unit_t *compute_unit)
{
	struct vgpu_t *vgpu = compute_unit->vgpu;
	char text[MAX_STRING_SIZE];

	/* Activate */
	assert(!compute_unit->timing_dia_active);
	compute_unit->timing_dia_active = 1;

	/* Create lists */
	compute_unit->timing_inst_uops = list_create();

	/* Create window */
	GtkWidget *timing_window;
	timing_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	snprintf(text, sizeof text, "Compute Unit %d - Timing Diagram", compute_unit->id);
	gtk_window_set_title(GTK_WINDOW(timing_window), text);
	gtk_window_set_position(GTK_WINDOW(timing_window), GTK_WIN_POS_CENTER);
	gtk_window_set_default_size(GTK_WINDOW(timing_window), 700, 200);
	g_signal_connect(G_OBJECT(timing_window), "delete-event", G_CALLBACK(timing_window_delete_event), compute_unit);

	/* Instruction drawing area */
	GtkWidget *timing_inst_layout = gtk_layout_new(NULL, NULL);
	GtkWidget *timing_inst_title_area = gtk_drawing_area_new();
	GtkWidget *timing_inst_table = gtk_table_new(3, 1, FALSE);
	GtkWidget *timing_inst_frame = gtk_frame_new(NULL);
	gtk_widget_set_size_request(timing_inst_layout, 100, 200);
	gtk_table_attach(GTK_TABLE(timing_inst_table), timing_inst_title_area, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
	gtk_table_attach(GTK_TABLE(timing_inst_table), gtk_hseparator_new(), 0, 1, 1, 2, GTK_FILL, GTK_FILL, 0, 0);
	gtk_table_attach_defaults(GTK_TABLE(timing_inst_table), timing_inst_layout, 0, 1, 2, 3);
	gtk_container_add(GTK_CONTAINER(timing_inst_frame), timing_inst_table);
	g_signal_connect(G_OBJECT(timing_inst_title_area), "draw",
		G_CALLBACK(timing_inst_title_area_draw_event), compute_unit);

	/* White background for instruction layout */
	GdkColor color;
	gdk_color_parse("white", &color);
	gtk_widget_modify_bg(timing_inst_layout, GTK_STATE_NORMAL, &color);

	/* Diagram drawing area */
	GtkWidget *timing_dia_area = gtk_drawing_area_new();
	GtkWidget *timing_dia_title_area = gtk_drawing_area_new();
	GtkWidget *timing_dia_table = gtk_table_new(3, 1, FALSE);
	GtkWidget *timing_dia_frame = gtk_frame_new(NULL);
	gtk_table_attach(GTK_TABLE(timing_dia_table), timing_dia_title_area, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
	gtk_table_attach(GTK_TABLE(timing_dia_table), gtk_hseparator_new(), 0, 1, 1, 2, GTK_FILL, GTK_FILL, 0, 0);
	gtk_table_attach_defaults(GTK_TABLE(timing_dia_table), timing_dia_area, 0, 1, 2, 3);
	gtk_container_add(GTK_CONTAINER(timing_dia_frame), timing_dia_table);
	gtk_widget_set_size_request(timing_dia_area, 200, 200);
	gtk_widget_add_events(timing_dia_area, GDK_BUTTON_PRESS_MASK);
	g_signal_connect(G_OBJECT(timing_dia_title_area), "draw",
		G_CALLBACK(timing_dia_title_area_draw_event), compute_unit);
	g_signal_connect(G_OBJECT(timing_dia_area), "draw",
		G_CALLBACK(timing_dia_area_draw_event), compute_unit);
	g_signal_connect(G_OBJECT(timing_dia_area), "scroll-event",
		G_CALLBACK(timing_dia_area_scroll_event), compute_unit);

	/* Horizontal pane */
	GtkWidget *hpane;
	hpane = gtk_hpaned_new();
	gtk_paned_pack1(GTK_PANED(hpane), timing_inst_frame, TRUE, FALSE);
	gtk_paned_pack2(GTK_PANED(hpane), timing_dia_frame, TRUE, FALSE);

	/* Scrollbars */
	GtkWidget *hscrollbar = gtk_hscrollbar_new(NULL);
	GtkWidget *vscrollbar = gtk_vscrollbar_new(NULL);
	g_signal_connect(G_OBJECT(hscrollbar), "change-value", G_CALLBACK(timing_dia_scroll_event), compute_unit);
	g_signal_connect(G_OBJECT(vscrollbar), "change-value", G_CALLBACK(timing_dia_scroll_event), compute_unit);

	/* Table */
	GtkWidget *table;
	table = gtk_table_new(2, 2, FALSE);
	gtk_table_attach_defaults(GTK_TABLE(table), hpane, 0, 1, 0, 1);
	gtk_table_attach(GTK_TABLE(table), hscrollbar, 0, 1, 1, 2, GTK_EXPAND | GTK_FILL | GTK_SHRINK, GTK_FILL, 0, 0);
	gtk_table_attach(GTK_TABLE(table), vscrollbar, 1, 2, 0, 1, GTK_FILL, GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, 0);

	/* Frame */
	GtkWidget *frame;
	frame = gtk_frame_new(NULL);
	gtk_container_add(GTK_CONTAINER(frame), table);
	gtk_container_add(GTK_CONTAINER(timing_window), frame);

	/* Save widgets and show */
	compute_unit->timing_inst_layout = timing_inst_layout;
	compute_unit->timing_dia_area = timing_dia_area;
	compute_unit->timing_inst_title_area = timing_inst_title_area;
	compute_unit->timing_dia_title_area = timing_dia_title_area;
	compute_unit->timing_dia_hscrollbar = hscrollbar;
	compute_unit->timing_dia_vscrollbar = vscrollbar;
	compute_unit->timing_window = timing_window;
	gtk_widget_show_all(timing_window);

	/* Go to current cycle */
	timing_dia_refresh(compute_unit);
	timing_dia_window_goto(compute_unit, vgpu->cycle);
}
示例#26
0
/*! \todo Finish function documentation!!!
 *  \brief
 *  \par Function Description
 *
 */
void x_window_create_main(GSCHEM_TOPLEVEL *w_current)
{
  TOPLEVEL *toplevel = w_current->toplevel;

  GtkWidget *label=NULL;
  GtkWidget *main_box=NULL;
  GtkWidget *menubar=NULL;
  GtkWidget *drawbox=NULL;
  GtkWidget *bottom_box=NULL;
  GtkWidget *toolbar=NULL;
  GtkWidget *handlebox=NULL;

  /* used to signify that the window isn't mapped yet */
  w_current->window = NULL; 

  w_current->main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

  gtk_widget_set_name (w_current->main_window, "gschem");
  gtk_window_set_policy (GTK_WINDOW (w_current->main_window), TRUE, TRUE, TRUE);

  /* We want the widgets to flow around the drawing area, so we don't
   * set a size of the main window.  The drawing area's size is fixed,
   * see below
   */

   /* 
    * normally we let the window manager handle locating and sizing
    * the window.  However, for some batch processing of schematics
    * (generating a pdf of all schematics for example) we want to
    * override this.  Hence "auto_place_mode".
    */
   if( auto_place_mode )
   	gtk_widget_set_uposition (w_current->main_window, 10, 10);

  /* this should work fine */
  g_signal_connect (G_OBJECT (w_current->main_window), "delete_event",
                    G_CALLBACK (i_callback_close_wm),
                    w_current);

  /* Containers first */
  main_box = gtk_vbox_new(FALSE, 1);
  gtk_container_border_width(GTK_CONTAINER(main_box), 0);
  gtk_container_add(GTK_CONTAINER(w_current->main_window), main_box);

  menubar = get_main_menu (w_current);
  if (w_current->handleboxes) {
  	handlebox = gtk_handle_box_new ();
  	gtk_box_pack_start(GTK_BOX(main_box), handlebox, FALSE, FALSE, 0);
  	gtk_container_add (GTK_CONTAINER (handlebox), menubar);
  } else {
  	gtk_box_pack_start(GTK_BOX(main_box), menubar, FALSE, FALSE, 0);
  }

  w_current->menubar = menubar;
  gtk_widget_realize (w_current->main_window);

  if (w_current->handleboxes && w_current->toolbars) {
  	handlebox = gtk_handle_box_new ();
  	gtk_box_pack_start (GTK_BOX (main_box), handlebox, FALSE, FALSE, 0);
  }
 
  if (w_current->toolbars) {
    toolbar = gtk_toolbar_new();
    gtk_toolbar_set_orientation (GTK_TOOLBAR(toolbar), 
                                 GTK_ORIENTATION_HORIZONTAL);
    gtk_toolbar_set_style (GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS);

    if (w_current->handleboxes) {
      gtk_container_add (GTK_CONTAINER (handlebox), toolbar);
    } else {
      gtk_box_pack_start(GTK_BOX(main_box), toolbar, FALSE, FALSE, 0);
    }

    gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), 
                             _("New"), 
                             _("New file"), 
                             "toolbar/new", 
                             x_window_stock_pixmap("new", w_current),
                             (GtkSignalFunc) i_callback_toolbar_file_new, 
                             w_current);
    gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), 
                             _("Open"), 
                             _("Open file..."), 
                             "toolbar/open",
                             x_window_stock_pixmap("open", w_current),
                             (GtkSignalFunc) i_callback_toolbar_file_open, 
                             w_current);
    gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), 
                             _("Save"), 
                             _("Save file"), 
                             "toolbar/save", 
                             x_window_stock_pixmap("save", w_current),
                             (GtkSignalFunc) i_callback_toolbar_file_save, 
                             w_current);
    gtk_toolbar_append_space (GTK_TOOLBAR(toolbar)); 
    gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), 
                             _("Undo"), 
                             _("Undo last operation"), 
                             "toolbar/undo", 
                             x_window_stock_pixmap("undo", w_current),
                             (GtkSignalFunc) i_callback_toolbar_edit_undo, 
                             w_current);
    gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), 
                             _("Redo"), 
                             _("Redo last undo"), 
                             "toolbar/redo", 
                             x_window_stock_pixmap("redo", w_current),
                             (GtkSignalFunc) i_callback_toolbar_edit_redo, 
                             w_current);
    gtk_toolbar_append_space (GTK_TOOLBAR(toolbar)); 
    /* not part of any radio button group */
    gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), 
                             _("Component"), 
                             _("Add component...\nSelect library and component from list, move the mouse into main window, click to place\nRight mouse button to cancel"), 
                             "toolbar/component", 
                             x_window_stock_pixmap("comp", w_current),
                             (GtkSignalFunc) i_callback_toolbar_add_component, 
                             w_current);
    w_current->toolbar_net = 
      gtk_toolbar_append_element(GTK_TOOLBAR(toolbar),
                                 GTK_TOOLBAR_CHILD_RADIOBUTTON,
                                 NULL,
                                 _("Nets"),
                                 _("Add nets mode\nRight mouse button to cancel"),
                                 "toolbar/nets",
                                 x_window_stock_pixmap("net", w_current),
                                 (GtkSignalFunc) i_callback_toolbar_add_net,
                                 w_current);
    w_current->toolbar_bus = 
      gtk_toolbar_append_element(GTK_TOOLBAR(toolbar),
                                 GTK_TOOLBAR_CHILD_RADIOBUTTON,
                                 w_current->toolbar_net,
                                 _("Bus"),
                                 _("Add buses mode\nRight mouse button to cancel"),
                                 "toolbar/bus",
                                 x_window_stock_pixmap("bus", w_current),
                                 (GtkSignalFunc) i_callback_toolbar_add_bus,
                                 w_current);
    /* not part of any radio button group */
    gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), 
                             _("Text"), 
                             _("Add Text..."), 
                             "toolbar/text", 
                             x_window_stock_pixmap("text", w_current),
                             (GtkSignalFunc) i_callback_toolbar_add_text, 
                             w_current);
    gtk_toolbar_append_space (GTK_TOOLBAR(toolbar)); 
    w_current->toolbar_select = 
      gtk_toolbar_append_element(GTK_TOOLBAR(toolbar),
                                 GTK_TOOLBAR_CHILD_RADIOBUTTON,
                                 w_current->toolbar_bus,
                                 _("Select"),
                                 _("Select mode"),
                                 "toolbar/select",
                                 x_window_stock_pixmap("select", w_current),
                                 (GtkSignalFunc) i_callback_toolbar_edit_select, 
                                 w_current);


    gtk_toolbar_append_space (GTK_TOOLBAR(toolbar)); 
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w_current->toolbar_select),
                                 TRUE);
  } 


  /*  Try to create popup menu (appears in right mouse button  */
  w_current->popup_menu = (GtkWidget *) get_main_popup(w_current);

  drawbox = gtk_hbox_new(FALSE, 0);
  gtk_container_border_width(GTK_CONTAINER(drawbox), 0);
  gtk_container_add(GTK_CONTAINER(main_box), drawbox);

  x_window_create_drawing(drawbox, w_current);
  x_window_setup_draw_events(w_current);

  if (w_current->scrollbars_flag == TRUE) {
    /* setup scroll bars */
    w_current->v_adjustment = GTK_ADJUSTMENT (
      gtk_adjustment_new (toplevel->init_bottom, 0.0, toplevel->init_bottom,
                          100.0, 100.0, 10.0));

    w_current->v_scrollbar = gtk_vscrollbar_new (w_current->v_adjustment);

    gtk_range_set_update_policy (GTK_RANGE (w_current->v_scrollbar),
                                 GTK_UPDATE_CONTINUOUS);

    gtk_box_pack_start (GTK_BOX (drawbox), w_current->v_scrollbar,
                        FALSE, FALSE, 0);

    g_signal_connect (w_current->v_adjustment,
                      "value_changed",
                      G_CALLBACK (x_event_vschanged),
                      w_current);

    w_current->h_adjustment = GTK_ADJUSTMENT (
      gtk_adjustment_new (0.0, 0.0, toplevel->init_right, 100.0, 100.0, 10.0));

    w_current->h_scrollbar = gtk_hscrollbar_new (w_current->h_adjustment);

    gtk_range_set_update_policy (GTK_RANGE (w_current->h_scrollbar),
                                 GTK_UPDATE_CONTINUOUS);

    gtk_box_pack_start (GTK_BOX (main_box), w_current->h_scrollbar,
                        FALSE, FALSE, 0);

    g_signal_connect (w_current->h_adjustment,
                      "value_changed",
                      G_CALLBACK (x_event_hschanged),
                      w_current);
  }

  /* macro box */
  w_current->macro_entry = gtk_entry_new();
  g_signal_connect(w_current->macro_entry, "activate",
		   G_CALLBACK(&x_window_invoke_macro), w_current);

  w_current->macro_box = gtk_hbox_new(FALSE, 0);
  gtk_box_pack_start(GTK_BOX(w_current->macro_box), w_current->macro_entry,
		     TRUE, TRUE, 2);
  gtk_container_border_width(GTK_CONTAINER(w_current->macro_box), 1);
  gtk_box_pack_start (GTK_BOX (main_box), w_current->macro_box,
		      FALSE, FALSE, 0);

  /* bottom box */
  bottom_box = gtk_hbox_new(FALSE, 0);
  gtk_container_border_width(GTK_CONTAINER(bottom_box), 1);
  gtk_box_pack_start (GTK_BOX (main_box), bottom_box, FALSE, FALSE, 0);

  /*	label = gtk_label_new ("Mouse buttons:");
        gtk_box_pack_start (GTK_BOX (bottom_box), label, FALSE, FALSE, 10);
  */

  label = gtk_label_new (" ");
  gtk_box_pack_start (GTK_BOX (bottom_box), label, FALSE, FALSE, 2);

  w_current->left_label = gtk_label_new (_("Pick"));
  gtk_box_pack_start (GTK_BOX (bottom_box), w_current->left_label,
                      FALSE, FALSE, 0);

  label = gtk_label_new ("|");
  gtk_box_pack_start (GTK_BOX (bottom_box), label, FALSE, FALSE, 5);

  if (w_current->middle_button == STROKE) {
#ifdef HAVE_LIBSTROKE
    w_current->middle_label = gtk_label_new (_("Stroke"));
#else
    w_current->middle_label = gtk_label_new (_("none"));
#endif
  } else if (w_current->middle_button == ACTION) {
    w_current->middle_label = gtk_label_new (_("Action"));
  } else {
    w_current->middle_label = gtk_label_new (_("Repeat/none"));
  }

  gtk_box_pack_start (GTK_BOX (bottom_box), w_current->middle_label,
                      FALSE, FALSE, 0);

  label = gtk_label_new ("|");
  gtk_box_pack_start (GTK_BOX (bottom_box), label, FALSE, FALSE, 5);

  if (default_third_button == POPUP_ENABLED) {
    w_current->right_label = gtk_label_new (_("Menu/Cancel"));
  } else {
    w_current->right_label = gtk_label_new (_("Pan/Cancel"));
  }
  gtk_box_pack_start (GTK_BOX (bottom_box), w_current->right_label,
                      FALSE, FALSE, 0);

  label = gtk_label_new (" ");
  gtk_box_pack_start (GTK_BOX (bottom_box), label, FALSE, FALSE, 5);

  w_current->grid_label = gtk_label_new (" ");
  gtk_box_pack_start (GTK_BOX (bottom_box), w_current->grid_label,
                      FALSE, FALSE, 10);

  w_current->status_label = gtk_label_new (_("Select Mode"));
  gtk_box_pack_end (GTK_BOX (bottom_box), w_current->status_label, FALSE,
                    FALSE, 10);

  gtk_widget_show_all (w_current->main_window);
  gtk_widget_hide(w_current->macro_box);

  w_current->window = w_current->drawing_area->window;

  w_current->drawable = w_current->window;

  x_window_setup_gc(w_current);
}
static void
create_basics (void)
{
   GtkWidget *window = NULL;
   GtkWidget *vbox;
   GtkWidget *close_button;
   GtkWidget *box;
   GtkWidget *label;
   GtkWidget *separator;
   GtkWidget *table;
   GtkWidget *scrollbar;
   GtkWidget *ruler;
   GtkDataboxGraph *graph;
   gfloat min_x, max_x;
   gfloat min_y, max_y;
   gfloat *X;
   gfloat *Y;
   gfloat buffer;
   GdkColor color;
   gint i;

   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   gtk_widget_set_size_request (window, 500, 500);

   g_signal_connect (GTK_OBJECT (window), "destroy",
		     G_CALLBACK (gtk_main_quit), NULL);

   gtk_window_set_title (GTK_WINDOW (window), "GtkDatabox: Basics");
   gtk_container_set_border_width (GTK_CONTAINER (window), 0);

   vbox = gtk_vbox_new (FALSE, 0);
   gtk_container_add (GTK_CONTAINER (window), vbox);

   label =
      gtk_label_new
      ("\nThe code for this example demonstrates\n the the basic use of elementary functions\nfor utilizing the GtkDatabox widget.\n\nUsage:\nDraw a selection with the left button pressed,\nThan click into the selection.\nUse the right mouse button to zoom out.\nShift+ right mouse button zooms to default.");
   gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
   separator = gtk_hseparator_new ();
   gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, FALSE, 0);


   /* Instead of the following stuff, you could also call 
    * gtk_databox_create_box_with_scrollbars_and_rulers
    * as it is done in the other examples.
    * Of course, you are more flexible in using scrollbars and rulers 
    * by doing it yourself. */
   table = gtk_table_new (3, 3, FALSE);
   box = gtk_databox_new ();
   gtk_table_attach (GTK_TABLE (table), box, 1, 2, 1, 2,
		     GTK_FILL | GTK_EXPAND | GTK_SHRINK,
		     GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 0);

   /* You can associate a scrollbar with a GtkDatabox widget either 
    * this way ...*/
   scrollbar = gtk_hscrollbar_new (NULL);
   gtk_databox_set_adjustment_x (GTK_DATABOX (box),
				gtk_range_get_adjustment (GTK_RANGE
							  (scrollbar)));
   gtk_table_attach (GTK_TABLE (table), scrollbar, 1, 2, 2, 3,
		     GTK_FILL | GTK_EXPAND | GTK_SHRINK, GTK_FILL, 0, 0);
   /* or this way ... */
   scrollbar = gtk_vscrollbar_new
      (gtk_databox_get_adjustment_y (GTK_DATABOX (box)));
   gtk_table_attach (GTK_TABLE (table), scrollbar, 2, 3, 1, 2,
		     GTK_FILL, GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 0);


   ruler = gtk_databox_ruler_new (GTK_ORIENTATION_HORIZONTAL);
   gtk_widget_set_sensitive (ruler, FALSE);

   gtk_table_attach (GTK_TABLE (table), ruler, 1, 2, 0, 1,
		     GTK_FILL | GTK_EXPAND | GTK_SHRINK, GTK_FILL, 0, 0);
   gtk_databox_set_ruler_x (GTK_DATABOX (box), GTK_DATABOX_RULER (ruler));

   ruler = gtk_databox_ruler_new (GTK_ORIENTATION_VERTICAL);
   gtk_widget_set_sensitive (ruler, FALSE);
   gtk_table_attach (GTK_TABLE (table), ruler, 0, 1, 1, 2,
		     GTK_FILL, GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 0);
   gtk_databox_set_ruler_y (GTK_DATABOX (box), GTK_DATABOX_RULER (ruler));
   /* end of gtk_databox_create_box_with_scrollbars_and_rulers */

   gtk_box_pack_start (GTK_BOX (vbox), table, TRUE, TRUE, 0);

   color.red = 16383;
   color.green = 16383;
   color.blue = 16383;
   gtk_widget_modify_bg (box, GTK_STATE_NORMAL, &color);


   X = g_new0 (gfloat, POINTS);
   Y = g_new0 (gfloat, POINTS);

   for (i = 0; i < POINTS; i++)
   {
      X[i] = i;
      Y[i] = 100. * sin (i * 2 * G_PI / POINTS);
   }
   color.red = 0;
   color.green = 65535;
   color.blue = 0;

   graph = gtk_databox_points_new (POINTS, X, Y, &color, 1);
   gtk_databox_graph_add (GTK_DATABOX (box), graph);

   X = g_new0 (gfloat, STEPS);
   Y = g_new0 (gfloat, STEPS);

   for (i = 0; i < STEPS / 2; i++)
   {
      X[i * 2] = X[i * 2 + 1] = 2 * (i + .5) * POINTS / STEPS;

      if (i > 0)
	 Y[i * 2 - 1] = 100. * sin ((i * 2) * 2 * G_PI / STEPS);
      Y[i * 2] = 100. * sin ((i * 2) * 2 * G_PI / STEPS);
      if (i == STEPS / 2 - 1)
	 Y[i * 2 + 1] = 100. * sin (((i + 1) * 2) * 2 * G_PI / STEPS);
   }
   color.red = 65535;
   color.green = 0;
   color.blue = 0;

   graph = gtk_databox_lines_new (STEPS, X, Y, &color, 1);
   gtk_databox_graph_add (GTK_DATABOX (box), graph);

   X = g_new0 (gfloat, BARS);
   Y = g_new0 (gfloat, BARS);

   for (i = 0; i < BARS; i++)
   {
      X[i] = i * POINTS / BARS;
      Y[i] = 80. * sin (i * 2 * G_PI / BARS);
   }
   color.red = 0;
   color.green = 65535;
   color.blue = 65535;

   graph = gtk_databox_bars_new (BARS, X, Y, &color, 1);
   gtk_databox_graph_add (GTK_DATABOX (box), graph);

   color.red = 32768;
   color.green = 32768;
   color.blue = 32768;

   graph = gtk_databox_cross_simple_new (&color, 0);
   gtk_databox_graph_add (GTK_DATABOX (box), graph);

   /* Instead of doing stuff what you see below, you could call 
    * gtk_databox_auto_rescale (GTK_DATABOX (box), 0.05);
    * as is done in the other examples 
    * Of course, you are more flexible in adjusting the scaling by doing 
    * it yourself, though. */
   if (0 >
       gtk_databox_calculate_extrema (GTK_DATABOX (box), &min_x, &max_x,
				      &min_y, &max_y))
   {
      g_warning ("Calculating extrema failed. Resorting to default values");
      min_x = -100.;
      min_y = -100.;
      max_x = +100.;
      max_y = +100.;
   }
   else
   {
      gfloat width = max_x - min_x;
      gfloat height = max_y - min_y;
      gfloat border = 0.05;

      min_x -= border * width;
      min_y -= border * height;
      max_x += border * width;
      max_y += border * height;
   }

   /* We want larger y values to be higher on the screen */
   buffer = min_y;
   min_y = max_y;
   max_y = buffer;

   gtk_databox_set_total_limits (GTK_DATABOX (box), min_x, max_x, min_y,
				 max_y);
   /* end of gtk_databox_auto_rescale */

   separator = gtk_hseparator_new ();
   gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, TRUE, 0);

   close_button = gtk_button_new_with_label ("close");
   g_signal_connect_swapped (GTK_OBJECT (close_button), "clicked",
			     G_CALLBACK (gtk_main_quit), GTK_OBJECT (box));
   gtk_box_pack_start (GTK_BOX (vbox), close_button, FALSE, FALSE, 0);
   gtk_widget_set_can_default(close_button, GTK_CAN_DEFAULT);
   gtk_widget_grab_default (close_button);
   gtk_widget_grab_focus (close_button);

   gtk_widget_show_all (window);
   gdk_window_set_cursor (box->window, gdk_cursor_new (GDK_CROSS));
}
示例#28
0
static int gtkCanvasMapMethod(Ihandle* ih)
{
  GtkWidget* sb_win;
#if !GTK_CHECK_VERSION(3, 0, 0)
  void* visual;
#endif

  if (!ih->parent)
    return IUP_ERROR;

  ih->data->sb = iupBaseGetScrollbar(ih);

#if !GTK_CHECK_VERSION(3, 0, 0)
  visual = (void*)IupGetAttribute(ih, "VISUAL");   /* defined by the OpenGL Canvas in X11 or NULL */
  if (visual)
    iupgtkPushVisualAndColormap(visual, (void*)iupAttribGet(ih, "COLORMAP"));
#endif

  ih->handle = iupgtkNativeContainerNew();  /* canvas is also a container */

#if !GTK_CHECK_VERSION(3, 0, 0)
  if (visual)
    gtk_widget_pop_colormap();
#endif

  if (!ih->handle)
      return IUP_ERROR;

  /* CD will NOT work properly without this, must use always the CD-GDK driver */
  iupgtkNativeContainerSetHasWindow(ih->handle, TRUE);  

  sb_win = iupgtkNativeContainerNew();
  if (!sb_win)
    return IUP_ERROR;

  iupgtkNativeContainerAdd(sb_win, ih->handle);
  gtk_widget_show(sb_win);

  iupAttribSetStr(ih, "_IUP_EXTRAPARENT", (char*)sb_win);

  /* add to the parent, all GTK controls must call this. */
  iupgtkAddToParent(ih);

  g_signal_connect(G_OBJECT(ih->handle), "focus-in-event",     G_CALLBACK(iupgtkFocusInOutEvent), ih);
  g_signal_connect(G_OBJECT(ih->handle), "focus-out-event",    G_CALLBACK(iupgtkFocusInOutEvent), ih);
  g_signal_connect(G_OBJECT(ih->handle), "key-press-event",    G_CALLBACK(iupgtkKeyPressEvent), ih);
  g_signal_connect(G_OBJECT(ih->handle), "key-release-event",  G_CALLBACK(iupgtkKeyReleaseEvent), ih);
  g_signal_connect(G_OBJECT(ih->handle), "enter-notify-event", G_CALLBACK(iupgtkEnterLeaveEvent), ih);
  g_signal_connect(G_OBJECT(ih->handle), "leave-notify-event", G_CALLBACK(iupgtkEnterLeaveEvent), ih);
  g_signal_connect(G_OBJECT(ih->handle), "show-help",          G_CALLBACK(iupgtkShowHelp), ih);

#if GTK_CHECK_VERSION(3, 0, 0)
  g_signal_connect(G_OBJECT(ih->handle), "draw",               G_CALLBACK(gtkCanvasDraw), ih);
#else
  g_signal_connect(G_OBJECT(ih->handle), "expose-event",       G_CALLBACK(gtkCanvasExposeEvent), ih);
#endif
  g_signal_connect(G_OBJECT(ih->handle), "button-press-event", G_CALLBACK(gtkCanvasButtonEvent), ih);
  g_signal_connect(G_OBJECT(ih->handle), "button-release-event",G_CALLBACK(gtkCanvasButtonEvent), ih);
  g_signal_connect(G_OBJECT(ih->handle), "motion-notify-event",G_CALLBACK(iupgtkMotionNotifyEvent), ih);
  g_signal_connect(G_OBJECT(ih->handle), "scroll-event",G_CALLBACK(gtkCanvasScrollEvent), ih);

  g_signal_connect(G_OBJECT(ih->handle), "size-allocate", G_CALLBACK(gtkCanvasSizeAllocate), ih);

  /* To receive mouse events on a drawing area, you will need to enable them. */
  gtk_widget_add_events(ih->handle, GDK_EXPOSURE_MASK|
    GDK_POINTER_MOTION_MASK|GDK_POINTER_MOTION_HINT_MASK|
    GDK_BUTTON_PRESS_MASK|GDK_BUTTON_RELEASE_MASK|GDK_BUTTON_MOTION_MASK|
    GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK|
    GDK_ENTER_NOTIFY_MASK|GDK_LEAVE_NOTIFY_MASK|
    GDK_FOCUS_CHANGE_MASK|GDK_STRUCTURE_MASK);

  /* To receive keyboard events, you will need to set the GTK_CAN_FOCUS flag on the drawing area. */
  if (ih->iclass->is_interactive)
  {
    if (iupAttribGetBoolean(ih, "CANFOCUS"))
      iupgtkSetCanFocus(ih->handle, 1);
  }

  if (iupAttribGetBoolean(ih, "BORDER"))
  {
    iupAttribSetInt(ih, "BORDERWIDTH", 1);
#if GTK_CHECK_VERSION(3, 0, 0)
    g_signal_connect(G_OBJECT(sb_win), "draw", G_CALLBACK(gtkCanvasBorderDraw), NULL);
#else
    g_signal_connect(G_OBJECT(sb_win), "expose-event", G_CALLBACK(gtkCanvasBorderExposeEvent), NULL);
#endif
  }

  gtk_widget_realize(sb_win);

  if (ih->data->sb & IUP_SB_HORIZ)
  {
#if GTK_CHECK_VERSION(3, 0, 0)
    GtkWidget* sb_horiz = gtk_scrollbar_new(GTK_ORIENTATION_HORIZONTAL, NULL);
#else
    GtkWidget* sb_horiz = gtk_hscrollbar_new(NULL);
#endif
    iupgtkNativeContainerAdd(sb_win, sb_horiz);
    gtk_widget_show(sb_horiz);
    gtk_widget_realize(sb_horiz);

    g_signal_connect(G_OBJECT(sb_horiz), "change-value",G_CALLBACK(gtkCanvasScrollHorizChangeValue), ih);
    g_signal_connect(G_OBJECT(gtk_range_get_adjustment(GTK_RANGE(sb_horiz))), "value-changed",G_CALLBACK(gtkCanvasAdjustHorizValueChanged), ih);

    iupAttribSetStr(ih, "_IUPGTK_SBHORIZ", (char*)sb_horiz);
  }

  if (ih->data->sb & IUP_SB_VERT)
  {
#if GTK_CHECK_VERSION(3, 0, 0)
    GtkWidget* sb_vert = gtk_scrollbar_new(GTK_ORIENTATION_VERTICAL, NULL);
#else
    GtkWidget* sb_vert = gtk_vscrollbar_new(NULL);
#endif
    iupgtkNativeContainerAdd(sb_win, sb_vert);
    gtk_widget_show(sb_vert);
    gtk_widget_realize(sb_vert);

    g_signal_connect(G_OBJECT(sb_vert), "change-value",G_CALLBACK(gtkCanvasScrollVertChangeValue), ih);
    g_signal_connect(G_OBJECT(gtk_range_get_adjustment(GTK_RANGE(sb_vert))), "value-changed",G_CALLBACK(gtkCanvasAdjustVertValueChanged), ih);
    iupAttribSetStr(ih, "_IUPGTK_SBVERT", (char*)sb_vert);
  }

  gtk_widget_realize(ih->handle);

  /* configure for DRAG&DROP */
  if (IupGetCallback(ih, "DROPFILES_CB"))
    iupAttribSetStr(ih, "DROPFILESTARGET", "YES");

  /* update a mnemonic in a label if necessary */
  iupgtkUpdateMnemonic(ih);

  /* force the update of BGCOLOR here, to let derived classes ignore it if ACTION is defined */
  gtkCanvasSetBgColorAttrib(ih, iupAttribGetStr(ih, "BGCOLOR"));
    
  return IUP_NOERROR;
}
示例#29
0
文件: uzbl.c 项目: dusanx/uzbl
int
main (int argc, char* argv[]) {
    gtk_init (&argc, &argv);
    if (!g_thread_supported ())
        g_thread_init (NULL);

    printf("Uzbl start location: %s\n", argv[0]);
    strcpy(executable_path,argv[0]);

    strcat ((char *) XDG_CONFIG_HOME_default, getenv ("HOME"));
    strcat ((char *) XDG_CONFIG_HOME_default, "/.config");

    GError *error = NULL;
    GOptionContext* context = g_option_context_new ("- some stuff here maybe someday");
    g_option_context_add_main_entries (context, entries, NULL);
    g_option_context_add_group (context, gtk_get_option_group (TRUE));
    g_option_context_parse (context, &argc, &argv, &error);
    /* initialize hash table */
    bindings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, free_action);
	
	soup_session = webkit_get_default_session();
    keycmd = g_string_new("");

    settings_init ();
    commands_hash ();

    if (always_insert_mode)
        insert_mode = TRUE;

    GtkWidget* vbox = gtk_vbox_new (FALSE, 0);
    if (status_top)
        gtk_box_pack_start (GTK_BOX (vbox), create_mainbar (), FALSE, TRUE, 0);
    gtk_box_pack_start (GTK_BOX (vbox), create_browser (), TRUE, TRUE, 0);
    if (!status_top)
        gtk_box_pack_start (GTK_BOX (vbox), create_mainbar (), FALSE, TRUE, 0);

    main_window = create_window ();
    gtk_container_add (GTK_CONTAINER (main_window), vbox);

    load_uri (web_view, uri);

    gtk_widget_grab_focus (GTK_WIDGET (web_view));
    gtk_widget_show_all (main_window);
    xwin = GDK_WINDOW_XID (GTK_WIDGET (main_window)->window);
    printf("window_id %i\n",(int) xwin);
    printf("pid %i\n", getpid ());
    printf("name: %s\n", instance_name);

    scbar_v = (GtkScrollbar*) gtk_vscrollbar_new (NULL);
    bar_v = gtk_range_get_adjustment((GtkRange*) scbar_v);
    scbar_h = (GtkScrollbar*) gtk_hscrollbar_new (NULL);
    bar_h = gtk_range_get_adjustment((GtkRange*) scbar_h);
    gtk_widget_set_scroll_adjustments ((GtkWidget*) web_view, bar_h, bar_v);

    if (!show_status)
        gtk_widget_hide(mainbar);

    if (fifo_dir)
        create_fifo ();
    if (socket_dir)
        create_socket();

    gtk_main ();

    g_string_free(keycmd, TRUE);

    if (fifo_dir)
        unlink (fifo_path);
    if (socket_dir)
        unlink (socket_path);

    g_hash_table_destroy(bindings);
    g_hash_table_destroy(commands);
    return 0;
}
示例#30
0
int main(int argc, char **argv)
{
	gtk_init(&argc, &argv);
	printf("%llf\n", exp_fall_function(0.0));

	if(argc != 2) {
		exit(1);
	}
	
	file_info = malloc(sizeof(SF_INFO));
	SNDFILE *sndfile = sf_open (argv[1], SFM_READ, file_info);
	printf("channels: %d, samplerate: %d, samples: %lld\n", file_info->channels, file_info->samplerate, file_info->frames);
	snd_data = malloc(sizeof(short) * file_info->frames);
	p_pos = malloc(sizeof(double) * file_info->frames);
	
	for(int i=0; i<file_info->frames; i++) {
		p_pos[i] = snd_data[i];
	}

	float *snd_dataf = malloc(sizeof(float) * file_info->frames);
	sf_count_t items_read = sf_read_short(sndfile, snd_data, file_info->frames);
	printf("items read: %lld\n", items_read);
	sf_close(sndfile);

	min_fall_lenght = (int) (0.4 * (file_info->samplerate / MAX_FREQ));

	GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	g_signal_connect(window, "destroy",
	                 G_CALLBACK(delete_cb), window);

	GtkWidget *grid = gtk_grid_new();

	drawing_area = gtk_drawing_area_new();
	gtk_widget_set_size_request(drawing_area, 1000, 400);
	g_signal_connect (drawing_area, "draw", G_CALLBACK(draw_callback),
	                  NULL);

	scroll_adj = gtk_adjustment_new(0.0, 0.0, (double) file_info->frames, 1.0, SHOW_FRAMES, SHOW_FRAMES);
	g_signal_connect(G_OBJECT(scroll_adj), "value-changed", 
	                 G_CALLBACK(drawing_area_redraw_cb), NULL);

	GtkWidget *scrollbar = gtk_hscrollbar_new(GTK_ADJUSTMENT(scroll_adj));
	gtk_grid_attach(GTK_GRID(grid), scrollbar, 0, 1, 2, 1);

	spin = gtk_spin_button_new_with_range(0.0, (double) file_info->frames, 1.0);
	gtk_spin_button_set_adjustment(GTK_SPIN_BUTTON(spin), GTK_ADJUSTMENT(scroll_adj));
	gtk_grid_attach(GTK_GRID(grid), spin, 0, 2, 1, 1);
	g_signal_connect(G_OBJECT(spin), "value-changed", 
	                 G_CALLBACK(drawing_area_redraw_cb), NULL);

	window_spin = gtk_spin_button_new_with_range(1.0, (double) file_info->frames, 1.0);
	gtk_spin_button_set_value(GTK_SPIN_BUTTON(window_spin), 1000.0);
	gtk_grid_attach(GTK_GRID(grid), window_spin, 1,2,1,1);
	g_signal_connect(G_OBJECT(window_spin), "value-changed", 
	                 G_CALLBACK(drawing_area_redraw_cb), NULL);
	
	GtkWidget* button = gtk_button_new_with_label("Calculate");
	g_signal_connect(G_OBJECT(button), "clicked",
	                 G_CALLBACK(calculate_click_cb), NULL);
	gtk_grid_attach(GTK_GRID(grid), button, 0, 3, 1, 1);

	gtk_grid_attach(GTK_GRID(grid), drawing_area, 0, 0, 2, 1);

	gtk_container_add(GTK_CONTAINER(window), grid);

	gtk_widget_show (grid);
	gtk_widget_show (drawing_area);
	gtk_widget_show_all (window);
	gtk_main();
	free(snd_data);
	free(p_pos);

	return 0;
}