Images not appearing on buttons when using old GTK 2 versions - gtk

I'm currently testing a GTK 2 version of a program on systems using GTK 2.6, namely Ubuntu 5.04 and Fedora Core 4. I have the issue there that I am unable to create image-only buttons without a label. On later GTK versions (tested with Ubuntu 6.06, Fedora 8 and 10) this works. It looks like this:
Ubuntu 5.04 and Fedora 4 Core:
Ubuntu 6.06 (and similar in Fedora 8 and 10):
I've downloaded GTK 2.6 to find a clue in its documentation, but so far I have not found out why this is happening.
The code I use for image-only buttons is this:
GtkWidget *button = gtk_button_new ();
gtk_button_set_image (GTK_BUTTON (button), gtk_image_new_from_stock (GTK_STOCK_REMOVE, GTK_ICON_SIZE_BUTTON)); // Example
What am I missing here?
(The program is supposed to also run on old and low-end systems, that's why I am bothering with this.)
EDIT
It seems that the behaviour which I had expected was introduced with version 2.8.14, that's why it worked on Ubuntu 6.06 which uses GTK 2.10. This was not obvious to me from reading the documentation.
Packing a stock image into a button by using gtk_container_add() is a way to create labelless image-only buttons when using earlier versions.

Here's the code of gtk_button_set_image as of GTK+ 2.6.9
/**
* gtk_button_set_image:
* #button: a #GtkButton
* #image: a widget to set as the image for the button
*
* Set the image of #button to the given widget. Note that
* it depends on the gtk-button-images setting whether the
* image will be displayed or not.
*
* Since: 2.6
*/
void
gtk_button_set_image (GtkButton *button,
GtkWidget *image)
{
GtkButtonPrivate *priv = GTK_BUTTON_GET_PRIVATE (button);
priv->image = image;
priv->image_is_stock = (image == NULL);
gtk_button_construct_child (button);
g_object_notify (G_OBJECT (button), "image");
}
So first we can see that showing images in the buttons is handled by the gtk-buttons-images setting from your gtkrc, so you may need to force this.
We also see that setting a stock icon can be done differently: you can set as the button label the name of the stock icon, and set the use-stock property of the button to TRUE. So maybe you could try that too.

Related

Intercept X11 KeyPress event in GtkDrawingArea of GTK+3 on Linux

GTK+ version: 3.18.9
I created a drawing area (GtkWidget) with following code
content = gtk_drawing_area_new();
gtk_widget_set_can_focus(content, TRUE);
gtk_widget_add_events(content, GDK_ALL_EVENTS_MASK);
g_signal_connect(content, "draw", G_CALLBACK(&drawCallback), ctx);
gtk_widget_realize(content);
// Add a filter for interception
gdk_window_add_filter(content, gtk_widget_get_window(content),
OnXEvent, NULL);
Problem is that when I clicked the wideget, I got sequence of XEvents as follows:
LeaveNotify
FocusIn
EnterNotify
ButtonPress
FocusOut // Lost focus!
ButtonRelease
Above FocusOut indicated we lost focus right away after clicking.
It implies we can't receive any keyboard events since they are available only within focus.
Is this limitation of GTK? If not, is there any tools/methodlogy to find out which widget/widow trigger the FocusOut?
References:
gdk_window_add_filter
As of GTK+ version 3.18.9, it uses an extra X window for toplevel window and any keyboard events are captured by the window. Thus a filter need to be added as a global one, i.e.
gdk_window_add_filter(NULL, OnXEvent, NULL)
Note that the API was removed in this commit in GTK+ 4.x.

Multidisplay Rendering

I'm trying to build a project on 4 screens (2x projectors and 2x monitors all running at 1024x768). I'm using 2xGTX 295s.
Every time I run the file (using -multidisplay) the main screen hangs black and if I look at the processes I see 3 other screens being created, but nothing ever appears. The log files say "D3D11:failed to create RenderTexture(1024 x 768 fmt 44 aa 8), error 0x8007000e" where each Display.Activate() code should execute.
Relevant code:
if (Display.displays.Length > 1) {
Display.displays [1].SetRenderingResolution (1024, 768);
Display.displays [1].Activate ();
}
if (Display.displays.Length > 2){
Display.displays [2].SetRenderingResolution (1024, 768);
Display.displays [2].Activate ();
}
if (Display.displays.Length > 3) {
Display.displays [3].SetRenderingResolution (1024, 768);
Display.displays [3].Activate ();
}
I've tried searching for a solution, but because multi-display is relatively new I can't seem to find anything on it.
Does anyone have a solution or idea? it would be greatly appreciated. Thanks for your time.
This sounds like a driver issue. Windows update probably updated your video driver. Update your driver from device manager. If that didn't work, use a video driver from the manufacturer of your PC.You can easily download this from their website. Will provide link if you update your question with name of your PC make, the model number and the Operating System.

GTK: Using an Offscreen Window to investigate the rendered dimensions of widgets

I am utilizing a Gtk.Offscreen_Window to investigate the heights of various off-screen widgets in order to figure out where to place them on-screen based on their height. I managed to accomplish this with the following pseudo code.
procedure My_Proc
is
use Gtk.Offscreen_Window;
use Gtk.Box;
Offscreen : Gtk_Offscreen_Window := Gtk_Offscreen_Window_New;
Box : Gtk_Box := Gtk_Box_New ( Orientation_Vertical );
begin
Offscreen.Set_Default_Geometry ( 1000, 1000 );
Offscreen.Add ( Box );
Offscreen.Show_All;
Ada.Text_IO.Put_Line( Glib.Gint'Image ( Box.Get_Allocated_Height ));
end My_Proc;
This code will correctly tell me the height of Box. Note that my original code is a bit more complex than this but I've simplified it for the sake of this posting.
The problem here has to do with Offscreen.Show_All procedure. I know that this is not correct practice with an Offscreen widget since it cannot be shown like a normal Window. This is further emphasized by a warning that shows up on the console when this code is executed:
(main:26724): Gdk-WARNING **: /build/buildd/gtk+3.0-3.10.8/./gdk/x11/gdkwindow-x11.c:5531 drawable is not a native X11 window
Without including the Show_All function the size calculations will be incorrect (returns 1), so the Show_All function seems to be doing something important albeit a little too much. I believe the solution is as simple as finding out what runs the allocation calculations within the Show_All function and running that directly. Unfortunately I don't know what that function is.
So the bottom line is: How do I correctly instruct the Offscreen_Window widget to perform its sizing calculations without using the Show_All function?
Thank you.
I am using Ada 2012, GtkAda (latest since mid 2015), Linux Kubuntu 14.04 but also expect this to run in Windows 7/8.
I've recently learned that using the Gtk.Widget.Size_Request function was more correct for my situation than using Gtk.Widget.Get_Allocated_Height to find out the height of my newly spawned widget. Using this eliminates the erroneous use of Gtk.Widget.Show_All all together.
Thank you again for all your help.

Eclipse setInitialSize doesn't work

I'm trying to set my Eclipse RCP Application's initial size in the suggested way but it doesnt affect the actual size of the window. It doesn't matter what I set the size to the window always appears as fixed with 1020*765 dimensions.
See attached picture (I blanked out some sensitive info). I set the point to 600*400 yet the window appears with the same dimensions. So far no values entered affected the actual size.
I clear the workspace each time and even use -clearPersistedState
Any help would be appreciated
If you are running Eclipse 4.3 or 4.2 this is Eclipse bug 418615 the fix is scheduled for 4.3.2
By Greg's suggestion I looked for a different way and I could manage by using this code. Seems that under 4.3.1 the configurer's initialSize property never gets used but set to 1024*768 by default. This sets the Application window to the display's size:
#Override
public void postWindowOpen() {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().setBounds(getDisplaySize());
}
private Rectangle getDisplaySize() {
try {
Display display = Display.getCurrent();
Monitor monitor = display.getPrimaryMonitor();
Rectangle rect = monitor.getBounds();
return rect;
}
catch ( Throwable ignore ) {
return new Rectangle(0,0,1024,768);
}
}
Also for a maximized state you can use:
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().setMaximized(true);

Formula or API for calulating desktop icon spacing on Windows XP

I've built a simple application that applies grid-lines to an image or just simple colors for use as desktop wallpaper. The idea is that the desktop icons can be arranged within the grid. The problem is that depending on more things than I understand the actual spacing in pixels seems to be different from system to system. I've learned that at least these things play a factor:
Resolution (duh)
Taskbar size and placement
Fonts
There has to be more than this. Maybe there's some api call that I don't know about?
there are a 1001 ways to get/set this (but I only know 2) :-D
Windows Register:
HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics
values are IconSpacing and IconVerticalSpacing
by code:
using System.Management;
public string GetWinIconSpace()
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2","SELECT * FROM Win32_Desktop");
foreach (ManagementObject wmi in searcher.Get())
{
try
{
return "Desktop Icon Spacing: " + wmi.GetPropertyValue("IconSpacing").ToString();
}
catch { }
}
return "Desktop Icon Spacing: Unknown";
}
and the 3rd that I never tried you can find it here
They might also be a size problem due to scaling algorithm if the requested size of the icon is not available.
(since an icon file is actually a collection of icons, as explained in this thread about Icons and cursors know where they came from, from the The Old New Thing)