/* * CreateColorfulStyle * * Create a style using the colors passed in. * Set the foreground color, the text color and the * background color. Note that this makes all the * states be the same color. * * fg - foreground color * text - text color * bg - background color */ GtkStyle *CreateColorfulStyle (GdkColor fg, GdkColor text, GdkColor bg) { GtkStyle *defstyle; GtkStyle *style; int i; /* --- Get the default style --- */ defstyle = gtk_widget_get_default_style (); /* --- Make a copy of it. --- */ style = gtk_style_copy (defstyle); /* --- Set the colors for each state --- */ for (i = 0; i < 5; i++) { /* --- Set the colors for the style --- */ style->fg[i] = fg; style->text[i] = text; style->bg[i] = bg; } /* --- All done, here's new style --- */ return (style); }
void draw_init_font (drawctx_t *ctx, GtkStyle *new_font_style) { if (!ctx->pango_ready || (new_font_style && ctx->font_style != new_font_style)) { if (ctx->pangoctx) { g_object_unref (ctx->pangoctx); ctx->pangoctx = NULL; } if (ctx->pangolayout) { g_object_unref (ctx->pangolayout); ctx->pangolayout = NULL; } ctx->font_style = new_font_style ? new_font_style : gtk_widget_get_default_style (); ctx->pangoctx = gdk_pango_context_get (); ctx->pangolayout = pango_layout_new (ctx->pangoctx); pango_layout_set_ellipsize (ctx->pangolayout, PANGO_ELLIPSIZE_END); PangoFontDescription *desc = ctx->font_style->font_desc; ctx->font_weight = pango_font_description_get_weight (desc); pango_layout_set_font_description (ctx->pangolayout, desc); ctx->pango_ready = 1; } else if (new_font_style) { PangoFontDescription *desc = ctx->font_style->font_desc; pango_layout_set_font_description (ctx->pangolayout, desc); } }
/* * frame_update_titlebar_font * * Returns: void * Description: updates the titlebar font from the pango context, should * be called whenever the gtk style or font has changed */ void frame_update_titlebar_font (decor_frame_t *frame) { const PangoFontDescription *font_desc; PangoFontMetrics *metrics; PangoLanguage *lang; frame = gwd_decor_frame_ref (frame); font_desc = get_titlebar_font (frame); if (!font_desc) { GtkStyle *default_style; default_style = gtk_widget_get_default_style (); font_desc = default_style->font_desc; } pango_context_set_font_description (frame->pango_context, font_desc); lang = pango_context_get_language (frame->pango_context); metrics = pango_context_get_metrics (frame->pango_context, font_desc, lang); frame->text_height = PANGO_PIXELS (pango_font_metrics_get_ascent (metrics) + pango_font_metrics_get_descent (metrics)); gwd_decor_frame_unref (frame); pango_font_metrics_unref (metrics); }
wxColour Drawing::getPanelBGColour() { #ifdef __WXGTK__ static bool intitialized(false); static wxColour bgColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); if( !intitialized ) { // try to get the background colour from a menu GtkWidget* menu = gtk_window_new(GTK_WINDOW_TOPLEVEL); GtkStyle* def = gtk_rc_get_style( menu ); if(!def) def = gtk_widget_get_default_style(); if(def) { GdkColor col = def->bg[GTK_STATE_NORMAL]; bgColour = wxColour(col); } gtk_widget_destroy( menu ); intitialized = true; } return bgColour; #else return wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); #endif }
wxColor DrawingUtils::GetMenuBarBgColour() { #ifdef __WXGTK__ static bool intitialized(false); static wxColour textColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR)); if( !intitialized ) { // try to get the background colour from a menu GtkWidget *menuBar = gtk_menu_bar_new(); #ifdef __WXGTK3__ GdkRGBA col; GtkStyleContext* context = gtk_widget_get_style_context( menuBar ); gtk_style_context_get_background_color(context, GTK_STATE_FLAG_NORMAL, &col); textColour = wxColour(col); #else GtkStyle *def = gtk_rc_get_style( menuBar ); if(!def) def = gtk_widget_get_default_style(); if(def) { GdkColor col = def->bg[GTK_STATE_NORMAL]; textColour = wxColour(col); } #endif gtk_widget_destroy( menuBar ); intitialized = true; } return textColour; #else return wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR); #endif }
static GdkPixmap * tile_pixmap (GdkPixmap *pixmap, int width, int height) { GdkPixmap *copy; cairo_t *cr; copy = gdk_pixmap_new (pixmap, width, height, pixmap == NULL? 24 : -1); cr = gdk_cairo_create (copy); if (pixmap != NULL) { cairo_pattern_t *pattern; gdk_cairo_set_source_pixmap (cr, pixmap, 0.0, 0.0); pattern = cairo_get_source (cr); cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT); } else { GtkStyle *style; style = gtk_widget_get_default_style (); gdk_cairo_set_source_color (cr, &style->bg[GTK_STATE_NORMAL]); } cairo_paint (cr); if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) { g_object_unref (copy); copy = NULL; } cairo_destroy (cr); return copy; }
// this is also used from tbargtk.cpp and tooltip.cpp, hence extern extern GdkFont *GtkGetDefaultGuiFont() { if (!g_systemDefaultGuiFont) { GtkWidget *widget = gtk_button_new(); GtkStyle *def = gtk_rc_get_style( widget ); if (def) { g_systemDefaultGuiFont = gdk_font_ref( def->font ); } else { def = gtk_widget_get_default_style(); if (def) g_systemDefaultGuiFont = gdk_font_ref( def->font ); } gtk_widget_destroy( widget ); } else { // already have it, but ref it once more before returning gdk_font_ref(g_systemDefaultGuiFont); } return g_systemDefaultGuiFont; }
// static wxVisualAttributes wxControl::GetDefaultAttributesFromGTKWidget(GtkWidget* widget, bool useBase, int state) { GtkStyle* style; wxVisualAttributes attr; style = gtk_rc_get_style(widget); if (!style) style = gtk_widget_get_default_style(); if (!style) { return wxWindow::GetClassDefaultAttributes(wxWINDOW_VARIANT_NORMAL); } if (state == -1) state = GTK_STATE_NORMAL; // get the style's colours attr.colFg = wxColour(style->fg[state].red >> SHIFT, style->fg[state].green >> SHIFT, style->fg[state].blue >> SHIFT); if (useBase) attr.colBg = wxColour(style->base[state].red >> SHIFT, style->base[state].green >> SHIFT, style->base[state].blue >> SHIFT); else
wxColor DrawingUtils::GetTextCtrlTextColour() { #ifdef __WXGTK__ static bool intitialized(false); static wxColour textColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)); if( !intitialized ) { // try to get the text colour from a textctrl GtkWidget *textCtrl = gtk_text_view_new(); #ifdef __WXGTK3__ GdkRGBA col; GtkStyleContext* context = gtk_widget_get_style_context( textCtrl ); gtk_style_context_get_color(context, GTK_STATE_FLAG_NORMAL, &col); textColour = wxColour(col); #else GtkStyle *def = gtk_rc_get_style( textCtrl ); if(!def) def = gtk_widget_get_default_style(); if(def) { GdkColor col = def->text[GTK_STATE_NORMAL]; textColour = wxColour(col); } #endif gtk_widget_destroy( textCtrl ); intitialized = true; } return textColour; #else return wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); #endif }
/* * CreateFlashyButton * */ void CreateFlashyButton (GtkWidget *vbox, char *label) { GtkStyle *defstyle; GtkStyle *style; defstyle = gtk_widget_get_default_style (); style = gtk_style_copy (defstyle); style->fg[GTK_STATE_NORMAL] = purple; style->text[GTK_STATE_NORMAL] = purple; style->bg[GTK_STATE_NORMAL] = cyan; style->fg[GTK_STATE_PRELIGHT] = green; style->text[GTK_STATE_PRELIGHT] = green; style->bg[GTK_STATE_PRELIGHT] = blue; style->fg[GTK_STATE_ACTIVE] = orange; style->text[GTK_STATE_ACTIVE] = orange; style->bg[GTK_STATE_ACTIVE] = yellow; gtk_widget_push_style (style); /* --- Create a new button --- */ button = gtk_button_new_with_label (label); /* --- The main windows contains the button. --- */ gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); /* --- Make the button visible --- */ gtk_widget_show (button); /* --- Remove the style so it's not the default style --- */ gtk_widget_pop_style (); }
/*-----------------------------------------------------------------------------------------------------------------------*/ void Start(GtkWidget *W,gpointer Data) { gint i; GtkWidget *Win,*VBox,*HBox,*Label,*But,*Entry; static GdkColor Black = {0,0x0000,0x0000,0x0000}; static GdkColor Magenta = {0,0xFFFF,0x0000,0xFFFF}; static GdkColor Gray = {0,0x8888,0x8888,0x8888}; static GdkColor Blue = {0,0x7777,0x7777,0xFFFF}; GtkStyle *Style1,*Style2,*Style3; if (AcqOn) { Attention(100,"Counting is already started"); return; } Style1=gtk_style_copy(gtk_widget_get_default_style()); //Copy default style to this style for (i=0;i<5;i++) { Style1->fg[i]=Style1->text[i]=Magenta; Style1->bg[i]=Black; } //Set colours for all states Style2=gtk_style_copy(gtk_widget_get_default_style()); //Copy default style to this style for (i=0;i<5;i++) { Style2->fg[i]=Style2->text[i]=Black; Style2->bg[i]=Blue; } //Set colours Style3=gtk_style_copy(gtk_widget_get_default_style()); //Copy default style for (i=0;i<5;i++) { Style3->fg[i]=Style3->text[i]=Black; Style3->bg[i]=Gray; } //Set colours Win=gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_grab_add(Win); //Define a new modal window gtk_window_set_title(GTK_WINDOW(Win),"Start Counting"); gtk_widget_set_uposition(GTK_WIDGET(Win),300,300); gtk_widget_set_usize(GTK_WIDGET(Win),245,90); gtk_container_set_border_width(GTK_CONTAINER(Win),10); VBox=gtk_vbox_new(FALSE,0); gtk_container_add(GTK_CONTAINER(Win),VBox); //VBox for the entire window HBox=gtk_hbox_new(FALSE,10); gtk_box_pack_start(GTK_BOX(VBox),HBox,FALSE,FALSE,5); Label=gtk_label_new("Run Name:"); gtk_box_pack_start(GTK_BOX(HBox),Label,FALSE,FALSE,5); Entry=gtk_entry_new_with_max_length(35); gtk_box_pack_start(GTK_BOX(HBox),Entry,FALSE,FALSE,0); SetStyleRecursively(Entry,Style1); strcpy(RunName,"mydata"); gtk_entry_set_text(GTK_ENTRY(Entry),RunName); gtk_widget_set_usize(GTK_WIDGET(Entry),130,25); gtk_signal_connect(GTK_OBJECT(Entry),"changed",GTK_SIGNAL_FUNC(RunNameCallBack),NULL); HBox=gtk_hbox_new(FALSE,10); gtk_box_pack_start(GTK_BOX(VBox),HBox,FALSE,FALSE,5); But=gtk_button_new_with_label("Start"); SetStyleRecursively(But,Style2); gtk_widget_set_usize(GTK_WIDGET(But),100,25); gtk_box_pack_start(GTK_BOX(HBox),But,TRUE,FALSE,5); gtk_signal_connect(GTK_OBJECT(But),"clicked",GTK_SIGNAL_FUNC(StartCallBack),GTK_OBJECT(Win)); But=gtk_button_new_with_label("Cancel"); SetStyleRecursively(But,Style3); gtk_widget_set_usize(GTK_WIDGET(But),100,25); gtk_box_pack_start(GTK_BOX(HBox),But,TRUE,FALSE,5); gtk_signal_connect(GTK_OBJECT(But),"clicked",GTK_SIGNAL_FUNC(CancelCallBack),GTK_OBJECT(Win)); gtk_widget_show_all(Win); gtk_style_unref(Style1); gtk_style_unref(Style2); gtk_style_unref(Style3); }
/*----------------------------------------------------------------------------------------------------------------------*/ void InitializeFileColours(void) //The styles for the file widget open.c are set permanently { static GdkColor Red = {0,0xDDDD,0x0000,0x0000}; static GdkColor Yellow = {0,0xFFFF,0xFFFF,0xBBBB}; static GdkColor GrYellow = {0,0xDDDD,0xDDDD,0x7777}; static GdkColor White = {0,0xFFFF,0xFFFF,0xFFFF}; static GdkColor Black = {0,0x0000,0x0000,0x0000}; static GdkColor Gray = {0,0xDDDD,0xDDDD,0xDDDD}; FolderStyle=gtk_style_copy(gtk_widget_get_default_style()); FolderStyle->fg[0]=FolderStyle->text[0]=Black; FolderStyle->bg[0]=White; //Normal FolderStyle->fg[1]=FolderStyle->text[1]=Black; FolderStyle->bg[1]=Gray; //Button press FolderStyle->fg[2]=FolderStyle->text[2]=Black; FolderStyle->bg[2]=Gray; //Focus FileStyle=gtk_style_copy(gtk_widget_get_default_style()); FileStyle->fg[0]=FileStyle->text[0]=Red; FileStyle->bg[0]=Yellow; //Normal FileStyle->fg[1]=FileStyle->text[1]=Red; FileStyle->bg[1]=GrYellow; //Button press FileStyle->fg[2]=FileStyle->text[2]=Red; FileStyle->bg[2]=GrYellow; //Focus }
static cairo_surface_t * tile_surface (cairo_surface_t *surface, int width, int height) { cairo_surface_t *copy; cairo_t *cr; #if GTK_CHECK_VERSION (3, 0, 0) if (surface == NULL) { copy = gdk_window_create_similar_surface (gdk_get_default_root_window (), CAIRO_CONTENT_COLOR, width, height); } else { copy = cairo_surface_create_similar (surface, cairo_surface_get_content (surface), width, height); } #else copy = gdk_pixmap_new(surface, width, height, surface == NULL? 24 : -1); #endif cr = cairo_create (copy); if (surface != NULL) { cairo_pattern_t *pattern; cairo_set_source_surface (cr, surface, 0.0, 0.0); pattern = cairo_get_source (cr); cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT); } else { GtkStyle *style; style = gtk_widget_get_default_style (); gdk_cairo_set_source_color(cr, &style->bg[GTK_STATE_NORMAL]); } cairo_paint (cr); if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) { cairo_surface_destroy (copy); copy = NULL; } cairo_destroy(cr); return copy; }
wxFont wxSystemSettingsNative::GetFont( wxSystemFont index ) { wxFont font; switch (index) { case wxSYS_OEM_FIXED_FONT: case wxSYS_ANSI_FIXED_FONT: case wxSYS_SYSTEM_FIXED_FONT: font = *wxNORMAL_FONT; break; case wxSYS_ANSI_VAR_FONT: case wxSYS_SYSTEM_FONT: case wxSYS_DEVICE_DEFAULT_FONT: case wxSYS_DEFAULT_GUI_FONT: if (!gs_objects.m_fontSystem.Ok()) { GtkWidget *widget = gtk_button_new(); GtkStyle *def = gtk_rc_get_style( widget ); if ( !def || !def->font_desc ) def = gtk_widget_get_default_style(); if ( def && def->font_desc ) { wxNativeFontInfo info; info.description = pango_font_description_copy(def->font_desc); gs_objects.m_fontSystem = wxFont(info); } else { GtkSettings *settings = gtk_settings_get_default(); gchar *font_name = NULL; g_object_get ( settings, "gtk-font-name", &font_name, NULL); if (!font_name) gs_objects.m_fontSystem = wxFont( 12, wxSWISS, wxNORMAL, wxNORMAL ); else gs_objects.m_fontSystem = wxFont(wxString::FromAscii(font_name)); g_free (font_name); } gtk_object_sink((GtkObject*)widget); } font = gs_objects.m_fontSystem; break; default: break; } return font; }
/* Get default style of a widget */ int clip_GTK_WIDGETGETDEFAULTSTYLE (ClipMachine *cm) { ClipVar *mstyle = RETPTR(cm); GtkStyle *style; style = gtk_widget_get_default_style (); memset(mstyle,0,sizeof(*mstyle)); _clip_map(cm,mstyle); _style_to_map(cm, style, mstyle); return 0; }
static char * mdm_get_font (const char *theme_name) { char *font_name; char *theme_dir; char *file_name; char buf[512]; GtkStyle *style; FILE *fp; style = gtk_widget_get_default_style (); font_name = pango_font_description_to_string (style->font_desc); theme_dir = gtk_rc_get_theme_dir (); file_name = g_build_filename (theme_dir, theme_name, INDEX_FILE1, NULL); if ( ! g_file_test (file_name, G_FILE_TEST_EXISTS)) { g_free (file_name); file_name = g_build_filename (theme_dir, theme_name, INDEX_FILE2, NULL); if ( ! g_file_test (file_name, G_FILE_TEST_EXISTS)) { g_free (theme_dir); g_free (file_name); return font_name; } } g_free (theme_dir); /* * FIXME: this is evil! */ fp = fopen (file_name, "r"); if (fp != NULL) { while (fgets (buf, 512, fp) != NULL) { if (strncmp ("ApplicationFont", buf, 15) == 0) { char *tmp_name; tmp_name = strchr (buf, '='); if (tmp_name != NULL) { g_free (font_name); font_name = strdup (tmp_name + 1); } fclose (fp); g_free (file_name); return font_name; } } fclose (fp); } g_free (file_name); return font_name; }
int main (int argc, char *argv[] ) { /* GtkWidget is the storage type for widgets */ GtkWidget *window, *pixmap, *fixed; GdkPixmap *gdk_pixmap; GdkBitmap *mask; GtkStyle *style; GdkGC *gc; /* Create the main window, and attach delete_event signal to terminate * the application. Note that the main window will not have a titlebar * since we're making it a popup. */ gtk_init (&argc, &argv); window = gtk_window_new( GTK_WINDOW_POPUP ); gtk_signal_connect (GTK_OBJECT (window), "delete_event", GTK_SIGNAL_FUNC (close_application), NULL); gtk_widget_show (window); /* Now for the pixmap and the pixmap widget */ style = gtk_widget_get_default_style(); gc = style->black_gc; gdk_pixmap = gdk_pixmap_create_from_xpm_d( window->window, &mask, &style->bg[GTK_STATE_NORMAL], WheelbarrowFull_xpm ); pixmap = gtk_pixmap_new( gdk_pixmap, mask ); gtk_widget_show( pixmap ); /* To display the pixmap, we use a fixed widget to place the pixmap */ fixed = gtk_fixed_new(); gtk_widget_set_usize( fixed, 200, 200 ); gtk_fixed_put( GTK_FIXED(fixed), pixmap, 0, 0 ); gtk_container_add( GTK_CONTAINER(window), fixed ); gtk_widget_show( fixed ); /* This masks out everything except for the image itself */ gtk_widget_shape_combine_mask( window, mask, 0, 0 ); /* show the window */ gtk_widget_set_uposition( window, 20, 400 ); gtk_widget_show( window ); gtk_main (); return(0); }
/* Set default style of a widget */ int clip_GTK_WIDGETSETDEFAULTSTYLE (ClipMachine *cm) { ClipVar *mstyle = _clip_spar(cm,1); GtkStyle *style; CHECKARG(1,MAP_t); //style = gtk_style_new(); style = gtk_widget_get_default_style(); _map_to_style(cm, mstyle, style); // Apply new style to a widget gtk_widget_set_default_style (style); return 0; err: return 1; }
/* Create a MaskedPixmap from a GTK stock ID. Always returns * a valid image. */ static MaskedPixmap *mp_from_stock(const char *stock_id, int size) { //printf("mp_from_stock()...\n"); GtkIconSet *icon_set; GdkPixbuf *pixbuf; MaskedPixmap *retval; icon_set = gtk_icon_factory_lookup_default(stock_id); if (!icon_set) return get_bad_image(); pixbuf = gtk_icon_set_render_icon(icon_set, gtk_widget_get_default_style(), /* Gtk bug */ GTK_TEXT_DIR_LTR, GTK_STATE_NORMAL, size, NULL, NULL); retval = masked_pixmap_new(pixbuf); g_object_unref(pixbuf); return retval; }
GdkGC * getUIStyle_gc (GtkWidget * win, const gchar * name, const gchar * state) { GtkStyle *style; TRACE ("entering getUIStyle_gc"); g_return_val_if_fail (win != NULL, NULL); g_return_val_if_fail (GTK_IS_WIDGET (win), NULL); g_return_val_if_fail (GTK_WIDGET_REALIZED (win), NULL); style = gtk_rc_get_style (win); if (!style) { style = gtk_widget_get_style (win); } if (!style) { style = gtk_widget_get_default_style (); } return (_getUIStyle_gc (name, state, style)); }
void meta_ui_theme_get_frame_borders (MetaUI *ui, MetaFrameType type, MetaFrameFlags flags, int *top_height, int *bottom_height, int *left_width, int *right_width) { int text_height; PangoContext *context; const PangoFontDescription *font_desc; GtkStyle *default_style; if (meta_ui_have_a_theme ()) { context = gtk_widget_get_pango_context (GTK_WIDGET (ui->frames)); font_desc = meta_prefs_get_titlebar_font (); if (!font_desc) { default_style = gtk_widget_get_default_style (); font_desc = default_style->font_desc; } text_height = meta_pango_font_desc_get_text_height (font_desc, context); meta_theme_get_frame_borders (meta_theme_get_current (), type, text_height, flags, top_height, bottom_height, left_width, right_width); } else { *top_height = *bottom_height = *left_width = *right_width = 0; } }
/*-----------------------------------------------------------------------------------------------------------------------*/ int main(int argc,char *argv[]) { GtkWidget *Win,*VBox,*VBox2,*HBox,*MenuBox,*MenuBar,*But; gint i; static GdkColor White = {0,0xFFFF,0xFFFF,0xFFFF}; static GdkColor Red = {0,0xFFFF,0x0000,0x0000}; static GdkColor Blue = {0,0x0000,0x0000,0xFFFF}; GtkStyle *RedStyle,*BlueStyle; g_thread_init(NULL); gdk_threads_init(); gdk_threads_enter(); gtk_init(&argc,&argv); AcqOn=FALSE; strcpy(SetupFName,""); StnNo=1; NScalers=4; for (i=0;i<4;++i) SubA[i]=i; Interval[0]=1; Interval[1]=5; Interval[2]=60; Duration[0]=10; Duration[1]=60; RedStyle=gtk_style_copy(gtk_widget_get_default_style()); for (i=0;i<5;i++) { RedStyle->fg[i]=RedStyle->text[i]=Red; RedStyle->bg[i]=White; } BlueStyle=gtk_style_copy(gtk_widget_get_default_style()); for (i=0;i<5;i++) { BlueStyle->fg[i]=BlueStyle->text[i]=Blue; BlueStyle->bg[i]=White; } Win=gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_signal_connect(GTK_OBJECT(Win),"delete_event",GTK_SIGNAL_FUNC(DeleteMain),NULL); gtk_signal_connect(GTK_OBJECT(Win),"destroy",GTK_SIGNAL_FUNC(DestroyMain),NULL); gtk_window_set_title(GTK_WINDOW(Win),"SCALER (07 Aug 2009)"); gtk_widget_set_uposition(GTK_WIDGET(Win),100,50); gtk_widget_set_usize(GTK_WIDGET(Win),845,600); VBox=gtk_vbox_new(FALSE,0); gtk_container_add(GTK_CONTAINER(Win),VBox); MenuBox=gtk_vbox_new(FALSE,1); gtk_box_pack_start(GTK_BOX(VBox),MenuBox,FALSE,FALSE,0); GetMainMenu(Win,&MenuBar); gtk_box_pack_start(GTK_BOX(MenuBox),MenuBar,FALSE,TRUE,0); VBox2=gtk_vbox_new(FALSE,0); gtk_box_pack_start(GTK_BOX(VBox),VBox2,FALSE,FALSE,0); gtk_container_set_border_width(GTK_CONTAINER(VBox2),10); HBox=gtk_hbox_new(FALSE,0); gtk_box_pack_start(GTK_BOX(VBox2),HBox,FALSE,FALSE,0); S_Start=gtk_label_new("Start:\n"); gtk_box_pack_start(GTK_BOX(HBox),S_Start,FALSE,FALSE,0); HBox=gtk_hbox_new(FALSE,0); gtk_box_pack_start(GTK_BOX(VBox2),HBox,FALSE,FALSE,0); S_Stop=gtk_label_new("Stop:\n"); gtk_box_pack_start(GTK_BOX(HBox),S_Stop,FALSE,FALSE,0); HBox=gtk_hbox_new(FALSE,0); gtk_box_pack_start(GTK_BOX(VBox),HBox,FALSE,FALSE,0); But=gtk_button_new_with_label("Elapsed"); SetStyleRecursively(But,BlueStyle); gtk_box_pack_start(GTK_BOX(HBox),But,FALSE,FALSE,0); gtk_widget_set_usize(But,56,24); But=gtk_button_new_with_label("Scaler1"); SetStyleRecursively(But,BlueStyle); gtk_box_pack_start(GTK_BOX(HBox),But,FALSE,FALSE,40); gtk_widget_set_usize(But,50,24); But=gtk_button_new_with_label("Rate1"); SetStyleRecursively(But,BlueStyle); gtk_box_pack_start(GTK_BOX(HBox),But,FALSE,FALSE,-20); gtk_widget_set_usize(But,50,24); But=gtk_button_new_with_label("Scaler2"); SetStyleRecursively(But,BlueStyle); gtk_box_pack_start(GTK_BOX(HBox),But,FALSE,FALSE,70); gtk_widget_set_usize(But,50,24); But=gtk_button_new_with_label("Rate2"); SetStyleRecursively(But,BlueStyle); gtk_box_pack_start(GTK_BOX(HBox),But,FALSE,FALSE,-50); gtk_widget_set_usize(But,50,24); But=gtk_button_new_with_label("Scaler3"); SetStyleRecursively(But,BlueStyle); gtk_box_pack_start(GTK_BOX(HBox),But,FALSE,FALSE,100); gtk_widget_set_usize(But,50,24); But=gtk_button_new_with_label("Rate3"); SetStyleRecursively(But,BlueStyle); gtk_box_pack_start(GTK_BOX(HBox),But,FALSE,FALSE,-80); gtk_widget_set_usize(But,50,24); But=gtk_button_new_with_label("Scaler4"); SetStyleRecursively(But,BlueStyle); gtk_box_pack_start(GTK_BOX(HBox),But,FALSE,FALSE,135); gtk_widget_set_usize(But,50,24); But=gtk_button_new_with_label("Rate4"); SetStyleRecursively(But,BlueStyle); gtk_box_pack_start(GTK_BOX(HBox),But,FALSE,FALSE,-120); gtk_widget_set_usize(But,50,24); S_Output=gtk_text_new(NULL,NULL); gtk_widget_set_usize(GTK_WIDGET(S_Output),0,430); SetStyleRecursively(S_Output,RedStyle); gtk_box_pack_start(GTK_BOX(VBox),S_Output,FALSE,FALSE,0); gtk_text_set_word_wrap(GTK_TEXT(S_Output),TRUE); gtk_text_set_editable(GTK_TEXT(S_Output),FALSE); gtk_widget_show_all(Win); //gdk_threads_enter(); gtk_main(); gdk_threads_leave(); gtk_style_unref(RedStyle); gtk_style_unref(BlueStyle); return(0); }
static void xpad_preferences_init (XpadPreferences *pref) { GtkWidget *hbox, *font_hbox, *vbox; const GdkColor *color; const gchar *fontname; GtkStyle *style; GtkWidget *label, *appearance_frame, *alignment, *appearance_vbox; GtkWidget *options_frame, *options_vbox, *global_vbox; gchar *text; GtkSizeGroup *size_group_labels = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); GtkRequisition req; pref->priv = XPAD_PREFERENCES_GET_PRIVATE (pref); text = g_strconcat ("<b>", _("Appearance"), "</b>", NULL); label = GTK_WIDGET (g_object_new (GTK_TYPE_LABEL, "label", text, "use-markup", TRUE, "xalign", 0.0, NULL)); g_free (text); appearance_vbox = GTK_WIDGET (g_object_new (GTK_TYPE_VBOX, "homogeneous", FALSE, "spacing", 18, NULL)); alignment = gtk_alignment_new (1, 1, 1, 1); g_object_set (G_OBJECT (alignment), "left-padding", 12, "top-padding", 12, "child", appearance_vbox, NULL); appearance_frame = GTK_WIDGET (g_object_new (GTK_TYPE_FRAME, "label-widget", label, "shadow-type", GTK_SHADOW_NONE, "child", alignment, NULL)); pref->priv->textbutton = gtk_color_button_new (); pref->priv->backbutton = gtk_color_button_new (); pref->priv->fontbutton = gtk_font_button_new (); pref->priv->antifontcheck = gtk_radio_button_new_with_mnemonic (NULL, _("Use font from theme")); pref->priv->fontcheck = gtk_radio_button_new_with_mnemonic_from_widget (GTK_RADIO_BUTTON (pref->priv->antifontcheck), _("Use this font:")); pref->priv->anticolorcheck = gtk_radio_button_new_with_mnemonic (NULL, _("Use colors from theme")); pref->priv->colorcheck = gtk_radio_button_new_with_mnemonic_from_widget (GTK_RADIO_BUTTON (pref->priv->anticolorcheck), _("Use these colors:")); font_hbox = gtk_hbox_new (FALSE, 6); gtk_box_pack_start (GTK_BOX (font_hbox), pref->priv->fontcheck, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (font_hbox), pref->priv->fontbutton, TRUE, TRUE, 0); pref->priv->colorbox = gtk_vbox_new (FALSE, 6); hbox = gtk_hbox_new (FALSE, 12); label = gtk_label_new_with_mnemonic (_("Background:")); gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); gtk_size_group_add_widget (size_group_labels, label); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (hbox), pref->priv->backbutton, TRUE, TRUE, 0); g_object_set (G_OBJECT (pref->priv->colorbox), "child", hbox, NULL); hbox = gtk_hbox_new (FALSE, 12); label = gtk_label_new_with_mnemonic (_("Foreground:")); gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); gtk_size_group_add_widget (size_group_labels, label); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (hbox), pref->priv->textbutton, TRUE, TRUE, 0); g_object_set (G_OBJECT (pref->priv->colorbox), "child", hbox, NULL); alignment = gtk_alignment_new (1, 1, 1, 1); gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 12, 0); gtk_container_add (GTK_CONTAINER (alignment), pref->priv->colorbox); pref->priv->editcheck = gtk_check_button_new_with_mnemonic (_("_Edit lock")); pref->priv->stickycheck = gtk_check_button_new_with_mnemonic (_("_Pads start on all workspaces")); pref->priv->confirmcheck = gtk_check_button_new_with_mnemonic (_("_Confirm pad deletion")); gtk_dialog_add_button (GTK_DIALOG (pref), "gtk-close", GTK_RESPONSE_CLOSE); gtk_dialog_set_default_response (GTK_DIALOG (pref), GTK_RESPONSE_CLOSE); gtk_dialog_set_has_separator (GTK_DIALOG (pref), FALSE); g_signal_connect (pref, "response", G_CALLBACK (xpad_preferences_response), NULL); gtk_window_set_title (GTK_WINDOW (pref), _("Xpad Preferences")); gtk_color_button_set_use_alpha (GTK_COLOR_BUTTON (pref->priv->textbutton), FALSE); gtk_color_button_set_use_alpha (GTK_COLOR_BUTTON (pref->priv->backbutton), xpad_app_get_translucent ()); gtk_color_button_set_title (GTK_COLOR_BUTTON (pref->priv->textbutton), _("Set Foreground Color")); gtk_color_button_set_title (GTK_COLOR_BUTTON (pref->priv->backbutton), _("Set Background Color")); gtk_font_button_set_title (GTK_FONT_BUTTON (pref->priv->fontbutton), _("Set Font")); /* Set current state */ style = gtk_widget_get_default_style (); color = xpad_settings_get_back_color (xpad_settings ()); if (color) { gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pref->priv->colorcheck), TRUE); gtk_color_button_set_color (GTK_COLOR_BUTTON (pref->priv->backbutton), color); } else { gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pref->priv->anticolorcheck), TRUE); gtk_widget_set_sensitive (pref->priv->colorbox, FALSE); gtk_color_button_set_color (GTK_COLOR_BUTTON (pref->priv->backbutton), &style->base[GTK_STATE_NORMAL]); } color = xpad_settings_get_text_color (xpad_settings ()); if (color) gtk_color_button_set_color (GTK_COLOR_BUTTON (pref->priv->textbutton), color); else gtk_color_button_set_color (GTK_COLOR_BUTTON (pref->priv->textbutton), &style->text[GTK_STATE_NORMAL]); fontname = xpad_settings_get_fontname (xpad_settings ()); if (fontname) { gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pref->priv->fontcheck), TRUE); gtk_font_button_set_font_name (GTK_FONT_BUTTON (pref->priv->fontbutton), fontname); } else { gchar *str; gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pref->priv->antifontcheck), TRUE); gtk_widget_set_sensitive (pref->priv->fontbutton, FALSE); str = pango_font_description_to_string (style->font_desc); gtk_font_button_set_font_name (GTK_FONT_BUTTON (pref->priv->fontbutton), str); g_free (str); } gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pref->priv->editcheck), xpad_settings_get_edit_lock (xpad_settings ())); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pref->priv->stickycheck), xpad_settings_get_sticky (xpad_settings ())); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pref->priv->confirmcheck), xpad_settings_get_confirm_destroy (xpad_settings ())); vbox = gtk_vbox_new (FALSE, 6); gtk_box_pack_start (GTK_BOX (vbox), pref->priv->antifontcheck, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), font_hbox, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (appearance_vbox), vbox, FALSE, FALSE, 0); vbox = gtk_vbox_new (FALSE, 6); gtk_box_pack_start (GTK_BOX (vbox), pref->priv->anticolorcheck, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), pref->priv->colorcheck, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), alignment, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (appearance_vbox), vbox, FALSE, FALSE, 0); text = g_strconcat ("<b>", _("Options"), "</b>", NULL); label = GTK_WIDGET (g_object_new (GTK_TYPE_LABEL, "label", text, "use-markup", TRUE, "xalign", 0.0, NULL)); g_free (text); options_vbox = GTK_WIDGET (g_object_new (GTK_TYPE_VBOX, "homogeneous", FALSE, "spacing", 6, NULL)); alignment = gtk_alignment_new (1, 1, 1, 1); g_object_set (G_OBJECT (alignment), "left-padding", 12, "top-padding", 12, "child", options_vbox, NULL); options_frame = GTK_WIDGET (g_object_new (GTK_TYPE_FRAME, "label-widget", label, "shadow-type", GTK_SHADOW_NONE, "child", alignment, NULL)); gtk_box_pack_start (GTK_BOX (options_vbox), pref->priv->editcheck, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (options_vbox), pref->priv->stickycheck, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (options_vbox), pref->priv->confirmcheck, FALSE, FALSE, 0); global_vbox = g_object_new (GTK_TYPE_VBOX, "border-width", 6, "homogeneous", FALSE, "spacing", 18, "child", appearance_frame, "child", options_frame, NULL); gtk_box_pack_start (GTK_BOX (GTK_DIALOG (pref)->vbox), global_vbox, FALSE, FALSE, 0); pref->priv->editcheck_handler = g_signal_connect (pref->priv->editcheck, "toggled", G_CALLBACK (change_edit_check), pref); pref->priv->stickycheck_handler = g_signal_connect (pref->priv->stickycheck, "toggled", G_CALLBACK (change_sticky_check), pref); pref->priv->confirmcheck_handler = g_signal_connect (pref->priv->confirmcheck, "toggled", G_CALLBACK (change_confirm_check), pref); pref->priv->colorcheck_handler = g_signal_connect (pref->priv->colorcheck, "toggled", G_CALLBACK (change_color_check), pref); pref->priv->fontcheck_handler = g_signal_connect (pref->priv->fontcheck, "toggled", G_CALLBACK (change_font_check), pref); pref->priv->text_handler = g_signal_connect (pref->priv->textbutton, "color-set", G_CALLBACK (change_text_color), pref); pref->priv->back_handler = g_signal_connect (pref->priv->backbutton, "color-set", G_CALLBACK (change_back_color), pref); pref->priv->font_handler = g_signal_connect (pref->priv->fontbutton, "font-set", G_CALLBACK (change_font_face), pref); pref->priv->notify_font_handler = g_signal_connect_swapped (xpad_settings (), "notify::fontname", G_CALLBACK (notify_fontname), pref); pref->priv->notify_text_handler = g_signal_connect_swapped (xpad_settings (), "notify::text-color", G_CALLBACK (notify_text_color), pref); pref->priv->notify_back_handler = g_signal_connect_swapped (xpad_settings (), "notify::back-color", G_CALLBACK (notify_back_color), pref); pref->priv->notify_sticky_handler = g_signal_connect_swapped (xpad_settings (), "notify::sticky", G_CALLBACK (notify_sticky), pref); pref->priv->notify_edit_handler = g_signal_connect_swapped (xpad_settings (), "notify::edit-lock", G_CALLBACK (notify_edit), pref); pref->priv->notify_confirm_handler = g_signal_connect_swapped (xpad_settings (), "notify::confirm-destroy", G_CALLBACK (notify_confirm), pref); g_object_unref (size_group_labels); gtk_widget_show_all (GTK_DIALOG (pref)->vbox); /* Make window not so squished */ gtk_widget_size_request (GTK_WIDGET (pref), &req); g_object_set (G_OBJECT (pref), "default-width", (gint) (req.height * 0.8), NULL); }
// static wxVisualAttributes wxControl::GetDefaultAttributesFromGTKWidget(GtkWidget* widget, bool WXUNUSED_IN_GTK3(useBase), int state) { wxVisualAttributes attr; GtkWidget* tlw = NULL; if (gtk_widget_get_parent(widget) == NULL) { tlw = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_container_add(GTK_CONTAINER(tlw), widget); } #ifdef __WXGTK3__ GtkStateFlags stateFlag = GTK_STATE_FLAG_NORMAL; if (state) { wxASSERT(state == GTK_STATE_ACTIVE); stateFlag = GTK_STATE_FLAG_ACTIVE; } GtkStyleContext* sc = gtk_widget_get_style_context(widget); GdkRGBA c; gtk_style_context_get_color(sc, stateFlag, &c); attr.colFg = wxColour(c); gtk_style_context_get_background_color(sc, stateFlag, &c); attr.colBg = wxColour(c); wxNativeFontInfo info; gtk_style_context_get( sc, stateFlag, GTK_STYLE_PROPERTY_FONT, &info.description, NULL); attr.font = wxFont(info); #else GtkStyle* style; style = gtk_rc_get_style(widget); if (!style) style = gtk_widget_get_default_style(); if (style) { // get the style's colours attr.colFg = wxColour(style->fg[state]); if (useBase) attr.colBg = wxColour(style->base[state]); else attr.colBg = wxColour(style->bg[state]); // get the style's font if (!style->font_desc) style = gtk_widget_get_default_style(); if (style && style->font_desc) { wxNativeFontInfo info; info.description = style->font_desc; attr.font = wxFont(info); info.description = NULL; } } else attr = wxWindow::GetClassDefaultAttributes(wxWINDOW_VARIANT_NORMAL); #endif if (!attr.font.IsOk()) { GtkSettings *settings = gtk_settings_get_default(); gchar *font_name = NULL; g_object_get ( settings, "gtk-font-name", &font_name, NULL); if (!font_name) attr.font = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ); else { attr.font = wxFont(wxString::FromUTF8(font_name)); g_free(font_name); } } if (tlw) gtk_widget_destroy(tlw); return attr; }
// wxSystemSettings::GetColour() helper: get the colours from a GTK+ // widget style, return true if we did get them, false to use defaults static bool GetColourFromGTKWidget(int& red, int& green, int& blue, wxGtkWidgetType type = wxGTK_BUTTON, GtkStateType state = GTK_STATE_NORMAL, wxGtkColourType colour = wxGTK_BG) { GtkWidget *widget; switch ( type ) { default: wxFAIL_MSG( wxT("unexpected GTK widget type") ); // fall through case wxGTK_BUTTON: widget = gtk_button_new(); break; case wxGTK_LIST: widget = gtk_list_new(); break; case wxGTK_MENUITEM: widget = gtk_menu_item_new(); } GtkStyle *def = gtk_rc_get_style( widget ); if ( !def ) def = gtk_widget_get_default_style(); bool ok; if ( def ) { GdkColor *col; switch ( colour ) { default: wxFAIL_MSG( wxT("unexpected GTK colour type") ); // fall through case wxGTK_FG: col = def->fg; break; case wxGTK_BG: col = def->bg; break; case wxGTK_BASE: col = def->base; break; } red = col[state].red; green = col[state].green; blue = col[state].blue; ok = true; } else { ok = false; } gtk_widget_destroy( widget ); return ok; }
void meta_ui_theme_get_frame_borders (MetaUI *ui, MetaFrameType type, MetaFrameFlags flags, int *top_height, int *bottom_height, int *left_width, int *right_width) { int text_height; #if GTK_CHECK_VERSION (3, 0, 0) GtkStyleContext *style = NULL; PangoFontDescription *free_font_desc = NULL; #endif PangoContext *context; const PangoFontDescription *font_desc; if (meta_ui_have_a_theme ()) { context = gtk_widget_get_pango_context (GTK_WIDGET (ui->frames)); font_desc = meta_prefs_get_titlebar_font (); if (!font_desc) { #if GTK_CHECK_VERSION (3, 0, 0) GdkDisplay *display = gdk_x11_lookup_xdisplay (ui->xdisplay); GdkScreen *screen = gdk_display_get_screen (display, XScreenNumberOfScreen (ui->xscreen)); GtkWidgetPath *widget_path; style = gtk_style_context_new (); gtk_style_context_set_screen (style, screen); widget_path = gtk_widget_path_new (); gtk_widget_path_append_type (widget_path, GTK_TYPE_WINDOW); gtk_style_context_set_path (style, widget_path); gtk_widget_path_free (widget_path); gtk_style_context_get (style, GTK_STATE_FLAG_NORMAL, "font", &free_font_desc, NULL); font_desc = (const PangoFontDescription *) free_font_desc; #else GtkStyle *default_style; default_style = gtk_widget_get_default_style (); font_desc = default_style->font_desc; #endif } text_height = meta_pango_font_desc_get_text_height (font_desc, context); meta_theme_get_frame_borders (meta_theme_get_current (), type, text_height, flags, top_height, bottom_height, left_width, right_width); #if GTK_CHECK_VERSION (3, 0, 0) if (free_font_desc) pango_font_description_free (free_font_desc); #endif } else { *top_height = *bottom_height = *left_width = *right_width = 0; } #if GTK_CHECK_VERSION (3, 0, 0) if (style != NULL) g_object_unref (style); #endif }
main(int argc, char *argv[]) { int n; int rows, cols; int drawButtons; char *btn_font, *disp_font; /* GtkWidget *main_w; */ GtkWidget *vbox; GtkWidget *menu; GtkWidget *mdisp; GtkWidget *lcd; GtkWidget *btns; GdkFont *new_font; GtkStyle *default_style, *new_style; GdkBitmap *icon_bitmap; #ifdef USE_GNOME GnomeAppBar *appbar; #endif setlocale(LC_ALL, "C"); #ifdef USE_GNOME gnome_init("grpn", "1.0", argc, argv); gnome_app_new("grpn", "grpn"); #else /* initialize gtk */ gtk_init(&argc, &argv); #endif /* initial values */ drawButtons = 1; rows = 8; cols = 30; btn_font = disp_font = NULL; /* process command line args */ n = 1; while(n < argc){ if(0 == strcmp("-fn", argv[n])){ n++; if(n >= argc){ usage("Missing required argument for -fn."); exit(0); } btn_font = disp_font = argv[n]; } else if(0 == strcmp("-btn-fn", argv[n])){ n++; if(n >= argc){ usage("Missing required argument for -btn-fn."); exit(0); } btn_font = argv[n]; } else if(0 == strcmp("-disp-fn", argv[n])){ n++; if(n >= argc){ usage("Missing required argument for -disp-fn."); exit(0); } disp_font = argv[n]; } else if(0 == strcmp("-rows", argv[n])){ n++; if(n >= argc){ usage("Missing required argument for -rows."); exit(0); } if(1 != sscanf(argv[n], "%d", &rows)){ usage("Unable to read number or rows."); exit(0); } } else if(0 == strcmp("-cols", argv[n])){ n++; if(n >= argc){ usage("Missing required argument for -cols."); exit(0); } if(1 != sscanf(argv[n], "%d", &cols)){ usage("Unable to read number or cols."); exit(0); } } else if(0 == strcmp("-b", argv[n])){ drawButtons = 0; } else if(0 == strcmp("-bm", argv[n])){ n++; if(n >= argc){ usage("Missing required argument for -m."); exit(0); } if (0 == strcmp("dec", argv[n])){ setBaseMode(DECIMAL); } else if (0 == strcmp("eng", argv[n])){ setBaseMode(DECIMAL_ENG); } else if (0 == strcmp("bin", argv[n])){ setBaseMode(BINARY); } else if (0 == strcmp("oct", argv[n])){ setBaseMode(OCTAL); } else if (0 == strcmp("hex", argv[n])){ setBaseMode(HEXADECIMAL); } else { usage("Specify dec, eng, bin, oct or hex for -m."); exit(0); } } else { usage("Unknown Argument."); exit(0); } n++; } /* set up any constants we may use */ setup_constant(); /* initialize the undo system */ initUndoSystem(); /* setup the stack */ if(0 == setup_stack()){ fprintf(stderr, "Error: Could not initalize data structures.\n"); exit(0); } /* set the font if told */ if(btn_font != NULL){ default_style = gtk_widget_get_default_style(); if(NULL == (new_font = gdk_font_load(btn_font))){ fprintf(stderr, "Unable to load font %s.\n", btn_font); exit(0); } new_style = gtk_style_copy(default_style); new_style->font_desc = new_font; /* BDD - No longer in Gtk2.x */ /* gtk_widget_set_default_style(new_style); */ } #ifdef USE_GNOME main_w = gnome_app_new("grpn", "grpn"); setup_menu(main_w); appbar = GNOME_APPBAR(gnome_appbar_new(FALSE, FALSE, FALSE)); gnome_app_set_statusbar(GNOME_APP(main_w), GTK_WIDGET(appbar)); /*create the box that everyone goes in */ vbox = gtk_vbox_new(FALSE, 0); gnome_app_set_contents(GNOME_APP(main_w), vbox); gtk_widget_show(vbox); #else /* the main window contains the work area and the menubar */ main_w = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_widget_set_name(main_w, "grpn"); /*create the box that everyone goes in */ vbox = gtk_vbox_new(FALSE, 0); gtk_container_add(GTK_CONTAINER(main_w), vbox); gtk_widget_show(vbox); /* set up the menu bar */ menu = setup_menu(vbox); #endif /* handle window manager close */ gtk_signal_connect(GTK_OBJECT(main_w), "delete_event", GTK_SIGNAL_FUNC(delete_event), NULL); gtk_signal_connect(GTK_OBJECT(main_w), "destroy", GTK_SIGNAL_FUNC(destroy), NULL); /* create the varrious subsystems */ mdisp = setupModeDisplay(vbox); if(drawButtons) btns = setupButtons(vbox); lcd = setupLCD(vbox, rows, cols, disp_font); /* Create pixmap of depth 1 (bitmap) for icon */ gtk_widget_realize(main_w); icon_bitmap = gdk_bitmap_create_from_data(main_w->window, icon_bitmap_bits, icon_bitmap_width, icon_bitmap_height); gdk_window_set_icon(main_w->window, NULL, icon_bitmap, NULL); gtk_widget_show(main_w); gtk_main(); }
int main (int argc, char *argv[] ) { GtkWidget *window, *pixmap, *fixed; GdkPixmap *gdk_pixmap; GdkBitmap *mask; GtkStyle *style; GdkGC *gc; CursorOffset* icon_pos; //初始化 gtk_set_locale(); gtk_init (&argc, &argv); //根窗口 root_win = gdk_window_foreign_new (GDK_ROOT_WINDOW ()); //建立无边界窗口 window = gtk_window_new( GTK_WINDOW_POPUP ); gtk_widget_set_events (window, gtk_widget_get_events (window) | GDK_BUTTON_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK); gtk_signal_connect (GTK_OBJECT (window), "delete_event", GTK_SIGNAL_FUNC (close_application), NULL); gtk_signal_connect (GTK_OBJECT (window), "button_press_event", GTK_SIGNAL_FUNC (shape_pressed),NULL); gtk_signal_connect (GTK_OBJECT (window), "button_release_event", GTK_SIGNAL_FUNC (shape_released),NULL); gtk_signal_connect (GTK_OBJECT (window), "motion_notify_event", GTK_SIGNAL_FUNC (shape_motion),NULL); gtk_widget_show (window); //建立图像 style = gtk_widget_get_default_style(); gc = style->black_gc; gdk_pixmap = gdk_pixmap_create_from_xpm_d( window->window, &mask, &style->bg[GTK_STATE_NORMAL], xpenguin_color_xpm ); pixmap = gtk_pixmap_new( gdk_pixmap, mask ); gtk_widget_show( pixmap ); //建立一个定点定位容器 fixed = gtk_fixed_new(); //容器的尺寸和图像一样 gtk_widget_set_usize( fixed, 202, 240 ); gtk_fixed_put( GTK_FIXED(fixed), pixmap, 0, 0 ); gtk_container_add( GTK_CONTAINER(window), fixed ); gtk_widget_show( fixed ); //对窗口设置掩码 gtk_widget_shape_combine_mask( window, mask, 0, 0 ); //设置数据 icon_pos = g_new (CursorOffset, 1); gtk_object_set_user_data(GTK_OBJECT(window), icon_pos); //设置窗口的位置 gtk_widget_set_uposition( window, 200, 400 ); gtk_widget_show( window ); gtk_main (); return(0); }
/*----------------------------------------------------------------------------------------------------------------------*/ void FileOpenNew(gchar *Title,GtkWidget *Parent,gint X,gint Y,gboolean OpenToRead,gchar *StartPath,gchar *Mask, gboolean MaskEditable,void (*CallBack)(GtkWidget *,gpointer),gboolean Persist) /* Must have FileX=g_new(struct FileSelectType,1) just before reference to FileOpenNew Title=Window title, Parent=Window wrt to which the file browser will be set_transient (keep NULL if not needed) X,Y=Window position, OpenToRead=TRUE to open file for read or FALSE to open file for write StartPath=initial directory, eg. "." or "/home/lamps/lamps" Mask eg. ".ban" (limited to 3 chars); "" will give all files; "d" will give all files ending in 'd' MaskEditable=TRUE allows the user to change the Mask CallBack=name of callback routine eg. &ReadFile, must g_free(FileX) in this except if Persist=TRUE Persist=TRUE keeps the browser open after selection and the "Cancel" button is replaced by "Dismiss" in this case do not g_free(FileX) in CallBack */ { GtkWidget *VBox,*HBox,*But,*ScrollW,*Label,*Arrow,*PxW; #include "Home.xpm" GdkBitmap *Msk; GdkPixmap *PxMp; GtkStyle *St; gint i,StatOut; struct stat StatBuf; gchar L2Str[LONG_TEXT_FIELD]; static GdkColor Red = {0,0xFFFF,0x0000,0x0000}; static GdkColor Blue = {0,0x0000,0x0000,0xFFFF}; GtkStyle *RedStyle,*BlueStyle; RedStyle=gtk_style_copy(gtk_widget_get_default_style()); RedStyle->fg[0]=RedStyle->text[0]=Red; BlueStyle=gtk_style_copy(gtk_widget_get_default_style()); BlueStyle->fg[0]=BlueStyle->text[0]=Blue; strcpy(FileX->Mask,Mask); FileX->Index=-1; FileX->N=0; for (i=0;i<MAX_DIR_ENTRIES;++i) strcpy(FileX->Names[i],""); FileX->Win=gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_grab_add(FileX->Win); if (Parent) gtk_window_set_transient_for(GTK_WINDOW(FileX->Win),GTK_WINDOW(Parent)); gtk_window_set_title(GTK_WINDOW(FileX->Win),Title); gtk_signal_connect(GTK_OBJECT(FileX->Win),"delete_event",GTK_SIGNAL_FUNC(FileOpenDelete),NULL); gtk_container_set_border_width(GTK_CONTAINER(FileX->Win),10); gtk_widget_set_usize(GTK_WIDGET(FileX->Win),500,466); gtk_widget_set_uposition(GTK_WIDGET(FileX->Win),X,Y); gtk_widget_show(FileX->Win); St=gtk_widget_get_style(FileX->Win); VBox=gtk_vbox_new(FALSE,0); gtk_container_add(GTK_CONTAINER(FileX->Win),VBox); HBox=gtk_hbox_new(FALSE,0); gtk_box_pack_start(GTK_BOX(VBox),HBox,FALSE,FALSE,10); if (OpenToRead) Label=gtk_label_new("Look in:"); else Label=gtk_label_new("Save in:"); gtk_box_pack_start(GTK_BOX(HBox),Label,FALSE,FALSE,10); if (!strcmp(StartPath,".")) getcwd(FileX->Path,LONG_TEXT_FIELD); else strcpy(FileX->Path,StartPath); StatOut=stat(FileX->Path,&StatBuf); //Check if the supplied StartPath is a valid directory if (StatOut==-1) getcwd(FileX->Path,LONG_TEXT_FIELD); //stat in error else if (!S_ISDIR(StatBuf.st_mode)) getcwd(FileX->Path,LONG_TEXT_FIELD); //Not a directory FileX->PEntry=gtk_entry_new_with_max_length(LONG_TEXT_FIELD); gtk_entry_set_text(GTK_ENTRY(FileX->PEntry),FileX->Path); gtk_widget_set_usize(GTK_WIDGET(FileX->PEntry),320,24); gtk_box_pack_start(GTK_BOX(HBox),FileX->PEntry,FALSE,FALSE,0); But=gtk_button_new(); gtk_box_pack_start(GTK_BOX(HBox),But,FALSE,FALSE,0); Arrow=gtk_arrow_new(GTK_ARROW_UP,GTK_SHADOW_IN); gtk_container_add (GTK_CONTAINER(But),Arrow); gtk_signal_connect(GTK_OBJECT(But),"clicked",GTK_SIGNAL_FUNC(FileOpenUp),NULL); But=gtk_button_new(); gtk_box_pack_start(GTK_BOX(HBox),But,FALSE,FALSE,0); gtk_signal_connect(GTK_OBJECT(But),"clicked",GTK_SIGNAL_FUNC(FileOpenHome),NULL); PxMp=gdk_pixmap_create_from_xpm_d((FileX->Win)->window,&Msk,&St->bg[GTK_STATE_NORMAL],(gchar **)Home_xpm); PxW=gtk_pixmap_new(PxMp,Msk); gtk_container_add(GTK_CONTAINER(But),PxW); But=gtk_button_new_with_label("Rescan"); gtk_box_pack_start(GTK_BOX(HBox),But,FALSE,FALSE,0); gtk_signal_connect(GTK_OBJECT(But),"clicked",GTK_SIGNAL_FUNC(FileOpenReScan),NULL); ScrollW=gtk_scrolled_window_new(NULL,NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(ScrollW),GTK_POLICY_NEVER,GTK_POLICY_ALWAYS); gtk_box_pack_start(GTK_BOX(VBox),ScrollW,FALSE,FALSE,0); gtk_widget_set_usize(GTK_WIDGET(ScrollW),0,340); FileX->Table=gtk_table_new(1,3,FALSE); gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(ScrollW),FileX->Table); gtk_table_set_row_spacings(GTK_TABLE(FileX->Table),0); gtk_table_set_col_spacings(GTK_TABLE(FileX->Table),0); DisplayFiles(); HBox=gtk_hbox_new(FALSE,0); gtk_box_pack_start(GTK_BOX(VBox),HBox,FALSE,FALSE,10); Label=gtk_label_new("File Name:"); gtk_box_pack_start(GTK_BOX(HBox),Label,FALSE,FALSE,0); gtk_widget_set_usize(GTK_WIDGET(Label),100,0); FileX->FEntry=gtk_entry_new_with_max_length(LONG_TEXT_FIELD); gtk_box_pack_start(GTK_BOX(HBox),FileX->FEntry,FALSE,FALSE,0); gtk_widget_set_usize(GTK_WIDGET(FileX->FEntry),160,0); gtk_signal_connect(GTK_OBJECT(FileX->FEntry),"changed",GTK_SIGNAL_FUNC(FileChanged),NULL); FileX->Label1=gtk_label_new(""); gtk_box_pack_start(GTK_BOX(HBox),FileX->Label1,FALSE,FALSE,0); SetStyleRecursively(FileX->Label1,RedStyle); gtk_widget_set_usize(GTK_WIDGET(FileX->Label1),170,0); if (OpenToRead) FileX->But=gtk_button_new_with_label("Open"); else FileX->But=gtk_button_new_with_label("Save"); gtk_box_pack_start(GTK_BOX(HBox),FileX->But,FALSE,FALSE,0); gtk_widget_set_usize(GTK_WIDGET(FileX->But),50,0); gtk_widget_set_sensitive(FileX->But,FALSE); gtk_signal_connect(GTK_OBJECT(FileX->But),"clicked",GTK_SIGNAL_FUNC(CallBack),NULL); if (!Persist) gtk_signal_connect_object(GTK_OBJECT(FileX->But),"clicked",GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(FileX->Win)); HBox=gtk_hbox_new(FALSE,0); gtk_box_pack_start(GTK_BOX(VBox),HBox,FALSE,FALSE,0); if (OpenToRead) Label=gtk_label_new("Files of type:"); else Label=gtk_label_new("Save as type:"); gtk_box_pack_start(GTK_BOX(HBox),Label,FALSE,FALSE,0); gtk_widget_set_usize(GTK_WIDGET(Label),100,0); FileX->MEntry=gtk_entry_new_with_max_length(4); gtk_box_pack_start(GTK_BOX(HBox),FileX->MEntry,FALSE,FALSE,0); gtk_entry_set_text(GTK_ENTRY(FileX->MEntry),Mask); gtk_widget_set_usize(GTK_WIDGET(FileX->MEntry),110,0); if (MaskEditable) gtk_entry_set_editable(GTK_ENTRY(FileX->MEntry),TRUE); else gtk_entry_set_editable(GTK_ENTRY(FileX->MEntry),FALSE); gtk_signal_connect(GTK_OBJECT(FileX->MEntry),"changed",GTK_SIGNAL_FUNC(MaskChanged),NULL); But=gtk_button_new_with_label("Rescan"); gtk_box_pack_start(GTK_BOX(HBox),But,FALSE,FALSE,0); sprintf(L2Str,"%d files found",FileX->Files); FileX->Label2=gtk_label_new(L2Str); gtk_box_pack_start(GTK_BOX(HBox),FileX->Label2,FALSE,FALSE,0); gtk_widget_set_usize(GTK_WIDGET(FileX->Label2),170,0); gtk_signal_connect(GTK_OBJECT(But),"clicked",GTK_SIGNAL_FUNC(FileOpenReScan),NULL); SetStyleRecursively(FileX->Label2,BlueStyle); gtk_widget_set_usize(GTK_WIDGET(But),50,0); if (Persist) But=gtk_button_new_with_label("Dismiss"); else But=gtk_button_new_with_label("Cancel"); gtk_box_pack_start(GTK_BOX(HBox),But,FALSE,FALSE,0); gtk_signal_connect(GTK_OBJECT(But),"clicked",GTK_SIGNAL_FUNC(FileOpenCancel),FileX->Win); gtk_widget_set_usize(GTK_WIDGET(But),50,0); gtk_widget_show_all(FileX->Win); gtk_style_unref(RedStyle); gtk_style_unref(BlueStyle); }
static VALUE rg_s_default_style(G_GNUC_UNUSED VALUE self) { return GOBJ2RVAL(gtk_widget_get_default_style()); }