C GTK - How to set :display.screen for gtk application window to appear - c

I am using gtk.h for a C application under GNU/Linux and I would like to open my gtk window under a specific display.screen without exporting any environmental variables. The reason I don't want to set the DISPLAY variable and export it is I don't want to lose control of what was the default display in the first place.
I thought about wrapping the application with an X window and mapping it in the display.screen I want but I dont know if thats a good idea. Right now I am trying to set the display via gdk, but unfortunately I can only get x properties like windowid or current display number with my current knowledge. Also, I dont have a problem with the solution being linux specific.
Another crucial detail about why Im not setting the DISPLAY environmental variable is maybe I want to open multiple gtk windows from the application at :2.0 & :2.1.

It was in the gtk documentation after all, I guess I missed it because I was trying to find a native xlib solution. Here is the related documentation page:
For GTK 4:
https://docs.gtk.org/gtk4/method.Window.set_display.html
For GTK 2.2 - 3:
https://docs.gtk.org/gtk3/method.Window.set_screen.html
So in the end, you'll have to set GdkDisplay / GdkScreen somehow and pass it to gtk.

Related

How does XML document work with GTK to create user interface?

I am working on a C/GTK+3 project right now. I have a little experience with front end but mostly only with Android. Even then that was VERY LITTLE experience.
I notice that in the C code I place objects and set properties (like if a textview is editable etc). I also have been able to connect a .ui XML file to my program with the builder functions.
I am wondering how the XML file gets linked to the C code defining the interface. Does it match by structure, by the name or ID properties? Why are properties like "visible" and "editable" present in both the C code and the XML? Do you need the XML file? Do you need to specify the properties in both the XML file and the C code or just one? Will I ever completely understand front end development?
There's two ways of constructing a user interface:
You write the code for it.
You write a file that describes the user interface, and have the user interface built for you at runtime.
If you write the code yourself, everytime you want to move widgets around, you have to modify your code, that you'll need to compile. That is doable for a small UI, and is what is done in most tutorials.
If you use ui files, then you use the Glade application to design your UI graphically, and it will write the UI files for you. This helps in splitting responsabilities too: you may have design people taking care of the UI, and let developpers focus on the behavior. Even without that, you'll be able to design a UI faster with an editor like Glade than by coding it by hand. Think you skip all the compile/debug cycles.
In your ui file, if you name a wigdet "bob", you'll be able to get it in your code by passing its name to gtk_builder_get_object. GtkBuilder takes care of the construction and the memory, so don't destroy the widgets it creates if you need to display them again, and hide them instead.
You have examples of use of UI files in the GTK documentation:
https://developer.gnome.org/gtk3/stable/ch01s04.html#id-1.2.3.12.5

Changing Namespace in a safe manner

This might be a very newbie question (coming from a newbie) but I had some problems regarding the namespace. I've created a User Interface in Visual Studio and gave it a test name to start off and learn how to use the program and the programming language. I kept building and building my UI and now I'm at the point that I'm actually pretty satisfied with my work (and this community's help!). So I decided to change the name of the file from "Test" to something more relevant for my work.
Yet, unfortunately, I ran into some problems regarding the change of the Namespace. I know there are a lot of tabs where it needs to be changed, but I was wondering if there is an easy way to change the file name/namespace of the UI?
Thank you in andvance for replying and taking the time to explain this newbie what to do without breaking his UI ;)
Use tool like Resharper, it will do it for you automatically and safely.
With Keyboard shortcut:
Put the keyboard cursor to the namespace, press Ctrl + R + R and set the new name. It will change the namespace inside XAML as well.
With Mouse:
Right mouse click on the name space, click Refactor > Rename.
When renaming classes and variables there is the lightbulb-menu (Ctrl + .) in witch you can give Visual Studio the instruction to Change it for you. But this will not work with Xaml.
Visual Studio will not change Namespaces as far as I'm concerned. But you can still compile and look at the "Namespace not found"-Errors to change them manually.
As Yohanes Nurcahyo said there is ReSharper but only has a free Trial of 30 days.

Change Textview's Text Upon Change of ComboBoxText Selection - Gtk+ 3.0 in C

I am building a GUI program that allows users to choose between a few software profiles for them to get written to their USB drive. I have chosen GTK+ 3.0 in C, and my supervisor is aware of my chosen method, so I am not changing it.
What I am trying to do is really quite simple but I'm still having trouble finding a comprehensive answer.
I want to be able to allow the user to select a (text) entry in the combo box and have the corresponding description show up in the frame/textview. The description in the textview should change properly to be the description for that combo box entry (the one selected).
My UI is mostly contained within a Glade file. Currently, the UI is functional but changing between combo box entries does nothing to the textview.
EDIT: I removed the posting of my code because it's too long and maybe it was throwing people off. Apologies. I can post things at request. Thanks.

How to put a close button in main window menu?

I'm looking to add a 'close' button to my main window's menu. An example can be found in the picture here: http://ifyoucodeittheywill.com/img/crimson-editor.png
(So, there's the normal close button in the window caption area, but, there's also a close button in the window's menu bar -- on the far right).
I'm using basic win32 API's, though an example using MFC would also be fine.
Does anyone know how to do this?
Thanks,
Andrew
These buttons usually come with MDI windows. However I'm pretty sure the depicted application uses either its own, or more probably some advanced third party toolkit. Because, to be honest, what the Windows API and MFC (which is just a classed wrapper around the windows API) give you for GUI programming is unbareably limited.
If you want to design neat UIs steer clear from MFC and better have a look at something like Qt, wxWidgets or the like.
A really simple way of doing this is to use a regular menu item, using AppendMenu, but use the following flags:
MF_BITMAP with a close button bitmap, or MF_OWNERDRAW or to draw it yourself
MF_HELP (aka WM_RIGHTJUSTIFY), a not-very-well documented flag, which will justify the item to the right.
Here's one reference to MF_HELP that I found on msdn - it's actually about using the Win32 API to right-justify a menu item, but using Visual Basic.
MF_HELP (defined in winuser.h) is something of a holdover from Win16 days, back then, the convention was to right-justify the Help menu item, so it would stand apart. It was 'renamed' - an additional #define added with the same value - to WM_RIGHTJUSTIFY around Win95.
Note that bitmap menu items aren't accessible (eg. to users that are relying on a screenreader to read out where they are on the screen); if taking this approach, then at least add a regular 'Close' menu item elsewhere in the menus (eg. under File), so that a user doesn't have to rely on this item, and can also close it through usual means. Also be sure to implement the Ctrl-F4 shortcut, which is what most applications that support multiple documents or tabs use to close the current item.
By all means do not try to create this behaviour yourself. This is functionality that you get "for free" if you are using the MDI architecture of MFC. The close button "next to the menu" as you call it closes the active MDI child window. If you are not using the MDI architecture then there is no point in trying to add a close button there. Can you explain if you are using the MDI architecture?

Building windows forms in C

So far, I've been able to create a window in C, and add a button and edit box to that window. But, where can I find an exhaustive list of the system classes for all the form controls? I can't remember where I found BUTTON and EDIT--is there a LABEL? LISTBOX? CHECKBOX? COMBOBOX? etc.
Then, how would I use those built in windows functions...I think they're called common controls? Like open a file, save as, print, etc.
You will go insane if you try to write raw Win32 code with C. If you can use C++, I highly suggest using Qt, if not, use Gtk.
Here you are: they are on MSDN.
But I agree with Zifre that you better use a gui-framework for stuff like this.
There are more like these, e.g. MFC or WTL.
Some people like things pure
stromcode zetcode forgers and heck if you're really feeling crazy, win32 in assembly
For the open dialogs and so on you want the Common Dialogs section -- http://msdn.microsoft.com/en-us/library/ms645524(VS.85).aspx.
Whilst on the subject of Win32, if you're using the file dialogs and therefore file names you may also find the shell functions (http://msdn.microsoft.com/en-us/library/bb776426(VS.85).aspx) handy -- in particular, the PathXXX ones. I wish I'd known about these when I was getting started.

Resources