├── LICENSE ├── Makefile ├── README.md ├── _examples ├── aboutdialog.c ├── aspectframe.c ├── assistant.c ├── box.c ├── button.c ├── buttonbox.c ├── calendar.c ├── cellrenderercombo.c ├── cellrendererspin.c ├── cellrendererspinner.c ├── cellrenderertext.c ├── cellrenderertoggle.c ├── checkbutton.c ├── clipboard.c ├── colorbutton.c ├── combobox.c ├── comboboxtext.c ├── commonframe.c ├── dialog.c ├── entry.c ├── entrybuffer.c ├── entrycompletion.c ├── expander.c ├── filechooserbutton.c ├── filechooserdialog.c ├── filechooserwidget.c ├── fixed.c ├── flowbox.c ├── fontbutton.c ├── frame.c ├── handlebox.c ├── helloworld.c ├── image.c ├── infobar.c ├── label.c ├── layout.c ├── linkbutton.c ├── liststore.c ├── messagedialog.c ├── notebook.c ├── paned.c ├── plug.c ├── progressbar.c ├── radiobutton.c ├── recentchooserdialog.c ├── recentchoosermenu.c ├── recentchooserwidget.c ├── scale.c ├── scalebutton.c ├── scrollbar.c ├── scrolledwindow.c ├── separator.c ├── sizegroup.c ├── socket.c ├── spinbutton.c ├── spinner.c ├── statusbar.c ├── switch.c ├── textview.c ├── toggleaction.c ├── togglebutton.c ├── toolbar.c ├── toolpalette.c ├── tooltipadvanced.c ├── tooltipbasic.c ├── treestore.c ├── volumebutton.c └── window.c ├── _resources └── gtk.png ├── aboutdialog.rst ├── actionbar.rst ├── aspectframe.rst ├── assistant.rst ├── box.rst ├── button.rst ├── buttonbox.rst ├── calendar.rst ├── checkbutton.rst ├── colorbutton.rst ├── combobox.rst ├── comboboxtext.rst ├── conf.py ├── dialog.rst ├── entry.rst ├── entrybuffer.rst ├── entrycompletion.rst ├── favicon.ico ├── filechooserbutton.rst ├── flowbox.rst ├── fontbutton.rst ├── frame.rst ├── grid.rst ├── headerbar.rst ├── helloworld.rst ├── image.rst ├── index.rst ├── infobar.rst ├── introduction.rst ├── label.rst ├── levelbar.rst ├── linkbutton.rst ├── listbox.rst ├── liststore.rst ├── make.bat ├── menubutton.rst ├── messagedialog.rst ├── paned.rst ├── progressbar.rst ├── revealer.rst ├── scale.rst ├── scalebutton.rst ├── searchentry.rst ├── separator.rst ├── spinbutton.rst ├── spinner.rst ├── stack.rst ├── stacksidebar.rst ├── stackswitcher.rst ├── statusbar.rst ├── switch.rst ├── togglebutton.rst ├── toolbar.rst ├── toolpalette.rst ├── treestore.rst └── window.rst /Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = _build 9 | 10 | # Internal variables. 11 | PAPEROPT_a4 = -D latex_paper_size=a4 12 | PAPEROPT_letter = -D latex_paper_size=letter 13 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 14 | # the i18n builder cannot share the environment and doctrees with the others 15 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 16 | 17 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext 18 | 19 | help: 20 | @echo "Please use \`make ' where is one of" 21 | @echo " html to make standalone HTML files" 22 | @echo " dirhtml to make HTML files named index.html in directories" 23 | @echo " singlehtml to make a single large HTML file" 24 | @echo " pickle to make pickle files" 25 | @echo " json to make JSON files" 26 | @echo " htmlhelp to make HTML files and a HTML help project" 27 | @echo " qthelp to make HTML files and a qthelp project" 28 | @echo " devhelp to make HTML files and a Devhelp project" 29 | @echo " epub to make an epub" 30 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 31 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 32 | @echo " text to make text files" 33 | @echo " man to make manual pages" 34 | @echo " texinfo to make Texinfo files" 35 | @echo " info to make Texinfo files and run them through makeinfo" 36 | @echo " gettext to make PO message catalogs" 37 | @echo " changes to make an overview of all changed/added/deprecated items" 38 | @echo " linkcheck to check all external links for integrity" 39 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 40 | 41 | clean: 42 | -rm -rf $(BUILDDIR)/* 43 | 44 | html: 45 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 46 | @echo 47 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 48 | 49 | dirhtml: 50 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 51 | @echo 52 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 53 | 54 | singlehtml: 55 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 56 | @echo 57 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 58 | 59 | pickle: 60 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 61 | @echo 62 | @echo "Build finished; now you can process the pickle files." 63 | 64 | json: 65 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 66 | @echo 67 | @echo "Build finished; now you can process the JSON files." 68 | 69 | htmlhelp: 70 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 71 | @echo 72 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 73 | ".hhp project file in $(BUILDDIR)/htmlhelp." 74 | 75 | qthelp: 76 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 77 | @echo 78 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 79 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 80 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/GTK3Tutorial.qhcp" 81 | @echo "To view the help file:" 82 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/GTK3Tutorial.qhc" 83 | 84 | devhelp: 85 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 86 | @echo 87 | @echo "Build finished." 88 | @echo "To view the help file:" 89 | @echo "# mkdir -p $$HOME/.local/share/devhelp/GTK3Tutorial" 90 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/GTK3Tutorial" 91 | @echo "# devhelp" 92 | 93 | epub: 94 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 95 | @echo 96 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 97 | 98 | latex: 99 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 100 | @echo 101 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 102 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 103 | "(use \`make latexpdf' here to do that automatically)." 104 | 105 | latexpdf: 106 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 107 | @echo "Running LaTeX files through pdflatex..." 108 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 109 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 110 | 111 | text: 112 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 113 | @echo 114 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 115 | 116 | man: 117 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 118 | @echo 119 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 120 | 121 | texinfo: 122 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 123 | @echo 124 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 125 | @echo "Run \`make' in that directory to run these through makeinfo" \ 126 | "(use \`make info' here to do that automatically)." 127 | 128 | info: 129 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 130 | @echo "Running Texinfo files through makeinfo..." 131 | make -C $(BUILDDIR)/texinfo info 132 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 133 | 134 | gettext: 135 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 136 | @echo 137 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 138 | 139 | changes: 140 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 141 | @echo 142 | @echo "The overview file is in $(BUILDDIR)/changes." 143 | 144 | linkcheck: 145 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 146 | @echo 147 | @echo "Link check complete; look for any errors in the above output " \ 148 | "or in $(BUILDDIR)/linkcheck/output.txt." 149 | 150 | doctest: 151 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 152 | @echo "Testing of doctests in the sources finished, look at the " \ 153 | "results in $(BUILDDIR)/doctest/output.txt." 154 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | The GTK+ 3 Tutorial is an introductory guide through the widgets available in the GTK+ 3 toolkit, combined with the use of the C programming language. 2 | 3 | The tutorial does not guide through the building process of an application from start to finish, but rather provides the common methods and signals used by each widget, and a description of how each works. 4 | 5 | The main GitHub repository for this documentation is https://github.com/Programmica/gtk3-tutorial. 6 | -------------------------------------------------------------------------------- /_examples/aboutdialog.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char *argv[]) 4 | { 5 | gtk_init(&argc, &argv); 6 | 7 | GtkWidget *aboutdialog = gtk_about_dialog_new(); 8 | gtk_about_dialog_set_name(GTK_ABOUT_DIALOG(aboutdialog), "Learn GTK+"); 9 | gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(aboutdialog), "1.0"); 10 | gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(aboutdialog), "An introduction to using GTK+"); 11 | gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(aboutdialog), "http://learngtk.org/"); 12 | gtk_dialog_run(GTK_DIALOG(aboutdialog)); 13 | gtk_widget_destroy(aboutdialog); 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /_examples/aspectframe.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | gtk_init(&argc, &argv); 11 | 12 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 13 | gtk_window_set_default_size(GTK_WINDOW(window), 200, 200); 14 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 15 | 16 | GtkWidget *aspectframe = gtk_aspect_frame_new("Aspect Frame", 0, 0, 1.0, FALSE); 17 | gtk_container_add(GTK_CONTAINER(window), aspectframe); 18 | 19 | gtk_widget_show_all(window); 20 | 21 | gtk_main(); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /_examples/assistant.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | gtk_init(&argc, &argv); 11 | 12 | GtkWidget *assistant = gtk_assistant_new(); 13 | gtk_window_set_default_size(GTK_WINDOW(assistant), 450, -1); 14 | g_signal_connect(assistant, "cancel", G_CALLBACK(destroy), NULL); 15 | g_signal_connect(assistant, "close", G_CALLBACK(destroy), NULL); 16 | g_signal_connect(assistant, "apply", G_CALLBACK(destroy), NULL); 17 | 18 | GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); 19 | GtkWidget *label = gtk_label_new("The first page of an Assistant widget is the intro page, which is used to display information about what the Assistant will do.\n\nThe page contains two buttons, a Forward to continue on to the next page and Cancel close the dialog."); 20 | gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT); 21 | gtk_label_set_line_wrap(GTK_LABEL(label), GTK_WRAP_WORD); 22 | gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 5); 23 | gtk_assistant_append_page(GTK_ASSISTANT(assistant), vbox); 24 | gtk_assistant_set_page_title(GTK_ASSISTANT(assistant), vbox, ("Page 1: Starting Out")); 25 | gtk_assistant_set_page_type(GTK_ASSISTANT(assistant), vbox, GTK_ASSISTANT_PAGE_INTRO); 26 | gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant), vbox, TRUE); 27 | 28 | GtkWidget *vbox1 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); 29 | GtkWidget *label1 = gtk_label_new("After the intro page, the content page is then displayed in the assistant. Usually this consists of labels, entries, buttons, etc. to allow the user to configure the application.\n\nThe assistant can contain as many content pages as necessary.\n\nContent pages have three buttons, a Back button, a Forward button continue on through the Assistant and a Cancel button to exit."); 30 | gtk_label_set_justify(GTK_LABEL(label1), GTK_JUSTIFY_LEFT); 31 | gtk_label_set_line_wrap(GTK_LABEL(label1), GTK_WRAP_WORD); 32 | gtk_box_pack_start(GTK_BOX(vbox1), label1, TRUE, TRUE, 5); 33 | gtk_assistant_append_page(GTK_ASSISTANT(assistant), vbox1); 34 | gtk_assistant_set_page_title(GTK_ASSISTANT(assistant), vbox1, ("Page 2: Moving On...")); 35 | gtk_assistant_set_page_type(GTK_ASSISTANT(assistant), vbox1, GTK_ASSISTANT_PAGE_CONTENT); 36 | gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant), vbox1, TRUE); 37 | 38 | GtkWidget *vbox2 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); 39 | GtkWidget *label2 = gtk_label_new("The Confirm page can be set as the final one in the Assistant and is used to check whether the user really wants to confirm the settings they have specified.\n\nIt also contains a Back and Cancel button, however also includes an Apply button to confirm the changes."); 40 | gtk_label_set_justify(GTK_LABEL(label2), GTK_JUSTIFY_LEFT); 41 | gtk_label_set_line_wrap(GTK_LABEL(label2), GTK_WRAP_WORD); 42 | gtk_box_pack_start(GTK_BOX(vbox2), label2, TRUE, TRUE, 5); 43 | gtk_assistant_append_page(GTK_ASSISTANT(assistant), vbox2); 44 | gtk_assistant_set_page_title(GTK_ASSISTANT(assistant), vbox2, ("Page 3: The Finale")); 45 | gtk_assistant_set_page_type(GTK_ASSISTANT(assistant), vbox2, GTK_ASSISTANT_PAGE_CONFIRM); 46 | gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant), vbox2, TRUE); 47 | 48 | gtk_widget_show_all(assistant); 49 | 50 | gtk_main(); 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /_examples/box.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | gtk_init(&argc, &argv); 11 | 12 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 13 | gtk_window_set_default_size(GTK_WINDOW(window), -1, 200); 14 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 15 | 16 | GtkWidget *label; 17 | 18 | GtkWidget *hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5); 19 | gtk_container_add(GTK_CONTAINER(window), hbox); 20 | label = gtk_label_new("Label 1 packed in HBox"); 21 | gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0); 22 | label = gtk_label_new("Label 2 packed in HBox"); 23 | gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0); 24 | 25 | GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); 26 | gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 0); 27 | label = gtk_label_new("Label 3 packed in VBox"); 28 | gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 0); 29 | label = gtk_label_new("Label 4 packed in VBox"); 30 | gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 0); 31 | 32 | gtk_widget_show_all(window); 33 | 34 | gtk_main(); 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /_examples/button.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | static void button_clicked(GtkWidget *button, gpointer data) 9 | { 10 | g_print("Button clicked\n"); 11 | } 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | GtkWidget *window; 16 | GtkWidget *button; 17 | 18 | gtk_init(&argc, &argv); 19 | 20 | window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 21 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 22 | 23 | button = gtk_button_new_with_label("Button"); 24 | g_signal_connect(GTK_BUTTON(button), "clicked", G_CALLBACK(button_clicked), NULL); 25 | gtk_container_add(GTK_CONTAINER(window), button); 26 | 27 | gtk_widget_show_all(window); 28 | 29 | gtk_main(); 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /_examples/buttonbox.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | gtk_init(&argc, &argv); 11 | 12 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 13 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 14 | 15 | GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5); 16 | gtk_container_add(GTK_CONTAINER(window), box); 17 | 18 | GtkWidget *buttonbox; 19 | GtkWidget *button; 20 | 21 | buttonbox = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL); 22 | gtk_box_set_spacing(GTK_BOX(buttonbox), 5); 23 | gtk_box_pack_start(GTK_BOX(box), buttonbox, TRUE, TRUE, 0); 24 | button = gtk_button_new_with_label("Button 1"); 25 | gtk_container_add(GTK_CONTAINER(buttonbox), button); 26 | button = gtk_button_new_with_label("Button 2"); 27 | gtk_container_add(GTK_CONTAINER(buttonbox), button); 28 | button = gtk_button_new_with_label("Button 3"); 29 | gtk_container_add(GTK_CONTAINER(buttonbox), button); 30 | 31 | buttonbox = gtk_button_box_new(GTK_ORIENTATION_VERTICAL); 32 | gtk_box_set_spacing(GTK_BOX(buttonbox), 10); 33 | gtk_box_pack_start(GTK_BOX(box), buttonbox, TRUE, TRUE, 0); 34 | button = gtk_button_new_with_label("Button 1"); 35 | gtk_container_add(GTK_CONTAINER(buttonbox), button); 36 | button = gtk_button_new_with_label("Button 2"); 37 | gtk_container_add(GTK_CONTAINER(buttonbox), button); 38 | button = gtk_button_new_with_label("Button 3"); 39 | gtk_container_add(GTK_CONTAINER(buttonbox), button); 40 | 41 | gtk_widget_show_all(window); 42 | 43 | gtk_main(); 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /_examples/calendar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | enum 4 | { 5 | calendar_show_header, 6 | calendar_show_days, 7 | calendar_month_change, 8 | calendar_show_week 9 | }; 10 | 11 | GtkWidget *calendar; 12 | 13 | static void destroy(GtkWidget *widget, gpointer data) 14 | { 15 | gtk_main_quit(); 16 | } 17 | 18 | static void calendar_flag_toggle(GtkWidget *checkbutton, GtkWidget *calendar) 19 | { 20 | 21 | } 22 | 23 | int main(int argc, char *argv[]) 24 | { 25 | gtk_init(&argc, &argv); 26 | 27 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 28 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 29 | 30 | GtkWidget *hbox = gtk_hbox_new(FALSE, 5); 31 | gtk_container_add(GTK_CONTAINER(window), hbox); 32 | 33 | calendar = gtk_calendar_new(); 34 | gtk_box_pack_start(GTK_BOX(hbox), calendar, TRUE, TRUE, 0); 35 | 36 | GtkWidget *vbox = gtk_vbox_new(FALSE, 5); 37 | gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, FALSE, 0); 38 | 39 | GtkWidget *checkbutton; 40 | 41 | checkbutton = gtk_check_button_new_with_label("Show Heading"); 42 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton), TRUE); 43 | g_signal_connect(GTK_TOGGLE_BUTTON(checkbutton), "toggled", G_CALLBACK(calendar_flag_toggle), calendar); 44 | gtk_box_pack_start(GTK_BOX(vbox), checkbutton1, FALSE, FALSE, 0); 45 | checkbutton = gtk_check_button_new_with_label("Show Day Names"); 46 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton), TRUE); 47 | gtk_box_pack_start(GTK_BOX(vbox), checkbutton, FALSE, FALSE, 0); 48 | checkbutton = gtk_check_button_new_with_label("Display Week Numbers"); 49 | gtk_box_pack_start(GTK_BOX(vbox), checkbutton, FALSE, FALSE, 0); 50 | checkbutton = gtk_check_button_new_with_label("Prevent Month/Year Change"); 51 | gtk_box_pack_start(GTK_BOX(vbox), checkbutton, FALSE, FALSE, 0); 52 | 53 | gtk_widget_show_all(window); 54 | 55 | gtk_main(); 56 | 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /_examples/cellrenderercombo.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | gtk_init(&argc, &argv); 11 | 12 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 13 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 14 | 15 | GtkListStore *liststore = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING); 16 | GtkTreeIter treeiter; 17 | 18 | gtk_list_store_append(liststore, &treeiter); 19 | gtk_list_store_set(liststore, &treeiter, 0, "Television", 1, "", -1); 20 | gtk_list_store_append(liststore, &treeiter); 21 | gtk_list_store_set(liststore, &treeiter, 0, "Mobile Phone", 1, "", -1); 22 | gtk_list_store_append(liststore, &treeiter); 23 | gtk_list_store_set(liststore, &treeiter, 0, "DVD Player", 1, "", -1); 24 | 25 | GtkListStore *liststoreManufacturer = gtk_list_store_new(1, G_TYPE_STRING); 26 | GtkTreeIter treeiter2; 27 | 28 | gtk_list_store_append(liststoreManufacturer, &treeiter2); 29 | gtk_list_store_set(liststoreManufacturer, &treeiter2, 0, "Sony", -1); 30 | gtk_list_store_append(liststoreManufacturer, &treeiter2); 31 | gtk_list_store_set(liststoreManufacturer, &treeiter2, 0, "Samsung", -1); 32 | gtk_list_store_append(liststoreManufacturer, &treeiter2); 33 | gtk_list_store_set(liststoreManufacturer, &treeiter2, 0, "LG", -1); 34 | 35 | GtkWidget *treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(liststore)); 36 | gtk_container_add(GTK_CONTAINER(window), treeview); 37 | 38 | GtkTreeViewColumn *treeviewcolumn; 39 | GtkCellRenderer *cellrenderertext; 40 | GtkCellRenderer *cellrenderercombo; 41 | 42 | cellrenderertext = gtk_cell_renderer_text_new(); 43 | treeviewcolumn = gtk_tree_view_column_new_with_attributes("Device", 44 | cellrenderertext, 45 | "text", 0, NULL); 46 | gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), treeviewcolumn); 47 | cellrenderercombo = gtk_cell_renderer_combo_new(); 48 | gtk_widget_set_property(GTK_WIDGET(cellrenderercombo), "model", liststoreManufacturer); 49 | treeviewcolumn = gtk_tree_view_column_new_with_attributes("Manufacturer", 50 | cellrenderercombo, 51 | "editable", TRUE, 52 | "model", liststoreManufacturer, 53 | "text-column", 0, NULL); 54 | gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), treeviewcolumn); 55 | 56 | gtk_widget_show_all(window); 57 | 58 | gtk_main(); 59 | 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /_examples/cellrendererspin.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | gtk_init(&argc, &argv); 11 | 12 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 13 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 14 | 15 | GtkListStore *liststore = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT); 16 | GtkTreeIter treeiter; 17 | 18 | gtk_list_store_append(liststore, &treeiter); 19 | gtk_list_store_set(liststore, &treeiter, 0, "Orange", 1, 5, -1); 20 | gtk_list_store_append(liststore, &treeiter); 21 | gtk_list_store_set(liststore, &treeiter, 0, "Apple", 1, 4, -1); 22 | gtk_list_store_append(liststore, &treeiter); 23 | gtk_list_store_set(liststore, &treeiter, 0, "Pineapple", 1, 1, -1); 24 | gtk_list_store_append(liststore, &treeiter); 25 | gtk_list_store_set(liststore, &treeiter, 0, "Melon", 1, 2, -1); 26 | gtk_list_store_append(liststore, &treeiter); 27 | gtk_list_store_set(liststore, &treeiter, 0, "Banana", 1, 6, -1); 28 | 29 | GtkWidget *treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(liststore)); 30 | gtk_container_add(GTK_CONTAINER(window), treeview); 31 | 32 | GtkTreeViewColumn *treeviewcolumn; 33 | 34 | GtkCellRenderer *cellrenderertext = gtk_cell_renderer_text_new(); 35 | treeviewcolumn = gtk_tree_view_column_new_with_attributes("Fruit", 36 | cellrenderertext, 37 | "text", 0, 38 | NULL); 39 | gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), treeviewcolumn); 40 | 41 | GtkCellRenderer *cellrendererspin = gtk_cell_renderer_spin_new(); 42 | g_object_set(G_OBJECT(cellrendererspin), "editable", TRUE, NULL); 43 | GtkObject *adjustment = gtk_adjustment_new(0, 0, 10, 1, 2, 0); 44 | g_object_set(G_OBJECT(cellrendererspin), "adjustment", adjustment, NULL); 45 | treeviewcolumn = gtk_tree_view_column_new_with_attributes("Quantity", 46 | cellrendererspin, 47 | "text", 1, 48 | NULL); 49 | gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), treeviewcolumn); 50 | 51 | gtk_widget_show_all(window); 52 | 53 | gtk_main(); 54 | 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /_examples/cellrendererspinner.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | gtk_init(&argc, &argv); 11 | 12 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 13 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 14 | 15 | GtkListStore *liststore = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_BOOLEAN); 16 | GtkTreeIter treeiter; 17 | 18 | gtk_list_store_append(liststore, &treeiter); 19 | gtk_list_store_set(liststore, &treeiter, 0, "Zenwalk", 1, TRUE, -1); 20 | gtk_list_store_append(liststore, &treeiter); 21 | gtk_list_store_set(liststore, &treeiter, 0, "CentOS", 1, TRUE, -1); 22 | gtk_list_store_append(liststore, &treeiter); 23 | gtk_list_store_set(liststore, &treeiter, 0, "Ubuntu", 1, FALSE, -1); 24 | gtk_list_store_append(liststore, &treeiter); 25 | gtk_list_store_set(liststore, &treeiter, 0, "Puppy", 1, TRUE, -1); 26 | gtk_list_store_append(liststore, &treeiter); 27 | gtk_list_store_set(liststore, &treeiter, 0, "Gentoo", 1, FALSE, -1); 28 | 29 | GtkWidget *treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(liststore)); 30 | gtk_container_add(GTK_CONTAINER(window), treeview); 31 | 32 | GtkTreeViewColumn *treeviewcolumn; 33 | GtkCellRenderer *cellrenderertext; 34 | GtkCellRenderer *cellrendererspinner; 35 | 36 | cellrenderertext = gtk_cell_renderer_text_new(); 37 | treeviewcolumn = gtk_tree_view_column_new_with_attributes("Distribution", 38 | cellrenderertext, 39 | "text", 0, NULL); 40 | gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), treeviewcolumn); 41 | cellrendererspinner = gtk_cell_renderer_spinner_new(); 42 | treeviewcolumn = gtk_tree_view_column_new_with_attributes("Download Progress", 43 | cellrendererspinner, 44 | "active", 1, NULL); 45 | gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), treeviewcolumn); 46 | 47 | gtk_widget_show_all(window); 48 | 49 | gtk_main(); 50 | 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /_examples/cellrenderertext.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | static void on_cell_edited(GtkWidget *cellrenderer, gchar *path, gchar *text, gpointer data) 9 | { 10 | GtkTreeModel *model = (GtkTreeModel *)data; 11 | GtkTreePath *treepath = gtk_tree_path_new_from_string(path); 12 | GtkTreeIter treeiter; 13 | 14 | gtk_tree_model_get_iter(model, &treeiter, treepath); 15 | 16 | gtk_list_store_set(GTK_LIST_STORE(model), &treeiter, 1, text, -1); 17 | } 18 | 19 | int main(int argc, char *argv[]) 20 | { 21 | gtk_init(&argc, &argv); 22 | 23 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 24 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 25 | 26 | GtkListStore *liststore = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING); 27 | GtkTreeIter treeiter; 28 | 29 | gtk_list_store_append(liststore, &treeiter); 30 | gtk_list_store_set(liststore, &treeiter, 0, "Potatoes", 1, "4", -1); 31 | gtk_list_store_append(liststore, &treeiter); 32 | gtk_list_store_set(liststore, &treeiter, 0, "Tissues", 1, "1", -1); 33 | gtk_list_store_append(liststore, &treeiter); 34 | gtk_list_store_set(liststore, &treeiter, 0, "Yoghurts", 1, "3", -1); 35 | gtk_list_store_append(liststore, &treeiter); 36 | gtk_list_store_set(liststore, &treeiter, 0, "Milk", 1, "2", -1); 37 | gtk_list_store_append(liststore, &treeiter); 38 | gtk_list_store_set(liststore, &treeiter, 0, "Soup", 1, "3", -1); 39 | 40 | GtkWidget *treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(liststore)); 41 | gtk_container_add(GTK_CONTAINER(window), treeview); 42 | 43 | GtkTreeViewColumn *treeviewcolumn; 44 | GtkCellRenderer *cellrenderertext; 45 | 46 | cellrenderertext = gtk_cell_renderer_text_new(); 47 | treeviewcolumn = gtk_tree_view_column_new_with_attributes("Grocery", 48 | cellrenderertext, 49 | "text", 0, 50 | NULL); 51 | gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), treeviewcolumn); 52 | treeviewcolumn = gtk_tree_view_column_new_with_attributes("Quantity", 53 | cellrenderertext, 54 | "text", 1, NULL); 55 | g_object_set(cellrenderertext, "editable", TRUE, NULL); 56 | g_signal_connect(cellrenderertext, "edited", G_CALLBACK(on_cell_edited), liststore); 57 | gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), treeviewcolumn); 58 | 59 | gtk_widget_show_all(window); 60 | 61 | gtk_main(); 62 | 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /_examples/cellrenderertoggle.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | gtk_init(&argc, &argv); 11 | 12 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 13 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 14 | 15 | GtkListStore *liststore = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_BOOLEAN); 16 | GtkTreeIter treeiter; 17 | 18 | gtk_list_store_append(liststore, &treeiter); 19 | gtk_list_store_set(liststore, &treeiter, 0, "Michael", 1, FALSE, -1); 20 | gtk_list_store_append(liststore, &treeiter); 21 | gtk_list_store_set(liststore, &treeiter, 0, "Rebecca", 1, TRUE, -1); 22 | gtk_list_store_append(liststore, &treeiter); 23 | gtk_list_store_set(liststore, &treeiter, 0, "Paul", 1, TRUE, -1); 24 | gtk_list_store_append(liststore, &treeiter); 25 | gtk_list_store_set(liststore, &treeiter, 0, "Jessica", 1, FALSE, -1); 26 | gtk_list_store_append(liststore, &treeiter); 27 | gtk_list_store_set(liststore, &treeiter, 0, "Lucy", 1, TRUE, -1); 28 | 29 | GtkWidget *treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(liststore)); 30 | gtk_container_add(GTK_CONTAINER(window), treeview); 31 | 32 | GtkTreeViewColumn *treeviewcolumn; 33 | GtkCellRenderer *cellrenderertext; 34 | 35 | cellrenderertext = gtk_cell_renderer_text_new(); 36 | treeviewcolumn = gtk_tree_view_column_new_with_attributes("Student", 37 | cellrenderertext, 38 | "text", 0, NULL); 39 | gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), treeviewcolumn); 40 | cellrenderertext = gtk_cell_renderer_toggle_new(); 41 | treeviewcolumn = gtk_tree_view_column_new_with_attributes("Present", 42 | cellrenderertext, 43 | "active", 1, NULL); 44 | gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), treeviewcolumn); 45 | 46 | gtk_widget_show_all(window); 47 | 48 | gtk_main(); 49 | 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /_examples/checkbutton.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | static void check_button_toggled(GtkWidget *checkbutton, gpointer data) 9 | { 10 | if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbutton))) 11 | { 12 | g_print("%s toggled on\n", gtk_button_get_label(GTK_BUTTON(checkbutton))); 13 | } 14 | else 15 | { 16 | g_print("%s toggled off\n", gtk_button_get_label(GTK_BUTTON(checkbutton))); 17 | } 18 | } 19 | 20 | int main(int argc, char *argv[]) 21 | { 22 | gtk_init(&argc, &argv); 23 | 24 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 25 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 26 | 27 | GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5); 28 | gtk_container_add(GTK_CONTAINER(window), box); 29 | 30 | GtkWidget *checkbutton; 31 | 32 | checkbutton = gtk_check_button_new_with_label("Check Button 1"); 33 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton), TRUE); 34 | g_signal_connect(checkbutton, "toggled", G_CALLBACK(check_button_toggled), NULL); 35 | gtk_box_pack_start(GTK_BOX(box), GTK_WIDGET(checkbutton), FALSE, FALSE, 0); 36 | 37 | checkbutton = gtk_check_button_new_with_label("Check Button 2"); 38 | g_signal_connect(checkbutton, "toggled", G_CALLBACK(check_button_toggled), NULL); 39 | gtk_box_pack_start(GTK_BOX(box), GTK_WIDGET(checkbutton), FALSE, FALSE, 0); 40 | 41 | checkbutton = gtk_check_button_new_with_label("Check Button 3"); 42 | g_signal_connect(checkbutton, "toggled", G_CALLBACK(check_button_toggled), NULL); 43 | gtk_box_pack_start(GTK_BOX(box), GTK_WIDGET(checkbutton), FALSE, FALSE, 0); 44 | 45 | gtk_widget_show_all(window); 46 | 47 | gtk_main(); 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /_examples/clipboard.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | GtkWidget *entry; 5 | 6 | static void destroy(GtkWidget *widget, gpointer data) 7 | { 8 | gtk_main_quit(); 9 | } 10 | 11 | static void on_cut_text(GtkWidget *button, gpointer data) 12 | { 13 | GtkClipboard *clip = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); 14 | const gchar *text = gtk_entry_get_text(GTK_ENTRY(entry)); 15 | gtk_clipboard_set_text(clip, text, -1); 16 | gtk_entry_set_text(GTK_ENTRY(entry), ""); 17 | } 18 | 19 | static void on_copy_text(GtkWidget *button, gpointer data) 20 | { 21 | GtkClipboard *clip = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); 22 | const gchar *text = gtk_entry_get_text(GTK_ENTRY(entry)); 23 | gtk_clipboard_set_text(clip, text, -1); 24 | } 25 | 26 | static void on_paste_text(GtkWidget *button, gpointer data) 27 | { 28 | gchar *text = gtk_clipboard_wait_for_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD)); 29 | gtk_entry_set_text(GTK_ENTRY(entry), text); 30 | } 31 | 32 | int main(int argc, char *argv[]) 33 | { 34 | gtk_init(&argc, &argv); 35 | 36 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 37 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 38 | 39 | GtkWidget *box1 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); 40 | gtk_container_add(GTK_CONTAINER(window), box1); 41 | entry = gtk_entry_new(); 42 | gtk_box_pack_start(GTK_BOX(box1), entry, FALSE, FALSE, 0); 43 | 44 | GtkWidget *box2 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); 45 | gtk_box_pack_start(GTK_BOX(box1), box2, FALSE, FALSE, 0); 46 | 47 | GtkWidget *button; 48 | 49 | button = gtk_button_new_with_label("_Cut"); 50 | gtk_button_set_use_underline(GTK_BUTTON(button), TRUE); 51 | g_signal_connect(button, "clicked", G_CALLBACK(on_cut_text), NULL); 52 | gtk_box_pack_start(GTK_BOX(box2), button, FALSE, TRUE, 0); 53 | button = gtk_button_new_with_label("_Copy"); 54 | gtk_button_set_use_underline(GTK_BUTTON(button), TRUE); 55 | g_signal_connect(button, "clicked", G_CALLBACK(on_copy_text), NULL); 56 | gtk_box_pack_start(GTK_BOX(box2), button, FALSE, TRUE, 0); 57 | button = gtk_button_new_with_label("_Paste"); 58 | gtk_button_set_use_underline(GTK_BUTTON(button), TRUE); 59 | g_signal_connect(button, "clicked", G_CALLBACK(on_paste_text), NULL); 60 | gtk_box_pack_start(GTK_BOX(box2), button, FALSE, TRUE, 0); 61 | 62 | gtk_widget_show_all(window); 63 | 64 | gtk_main(); 65 | 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /_examples/colorbutton.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static void destroy(GtkWidget *widget, gpointer data) 5 | { 6 | gtk_main_quit(); 7 | } 8 | 9 | static void color_set(GtkWidget *widget, GtkColorButton *colorbutton) 10 | { 11 | GdkColor color; 12 | 13 | gtk_color_button_get_color(colorbutton, &color); 14 | } 15 | 16 | int main(int argc, char *argv[]) 17 | { 18 | gtk_init(&argc, &argv); 19 | 20 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 21 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 22 | 23 | GtkWidget *colorbutton = gtk_color_button_new(); 24 | g_signal_connect(colorbutton, "color-set", G_CALLBACK(color_set), (gpointer) colorbutton); 25 | gtk_container_add(GTK_CONTAINER(window), colorbutton); 26 | 27 | gtk_widget_show_all(window); 28 | 29 | gtk_main(); 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /_examples/combobox.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | gtk_init(&argc, &argv); 11 | 12 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 13 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 14 | 15 | GtkListStore *liststore = gtk_list_store_new(1, G_TYPE_STRING); 16 | GtkTreeIter iter; 17 | 18 | gtk_list_store_append(liststore, &iter); 19 | gtk_list_store_set(liststore, &iter, 0, "Fedora", -1); 20 | gtk_list_store_append(liststore, &iter); 21 | gtk_list_store_set(liststore, &iter, 0, "Debian", -1); 22 | gtk_list_store_append(liststore, &iter); 23 | gtk_list_store_set(liststore, &iter, 0, "OpenSuSE", -1); 24 | gtk_list_store_append(liststore, &iter); 25 | gtk_list_store_set(liststore, &iter, 0, "Sabayon", -1); 26 | gtk_list_store_append(liststore, &iter); 27 | gtk_list_store_set(liststore, &iter, 0, "CentOS", -1); 28 | 29 | GtkWidget *combobox = gtk_combo_box_new_with_model(GTK_TREE_MODEL(liststore)); 30 | gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), 0); 31 | gtk_container_add(GTK_CONTAINER(window), combobox); 32 | 33 | GtkCellRenderer *cellrenderertext = gtk_cell_renderer_text_new(); 34 | gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combobox), cellrenderertext, TRUE); 35 | gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combobox), cellrenderertext, "text", 0, NULL); 36 | 37 | gtk_widget_show_all(window); 38 | 39 | gtk_main(); 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /_examples/comboboxtext.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | static void combobox_changed(GtkWidget *combobox, gpointer data) 9 | { 10 | const char *text = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(combobox)); 11 | printf("%s\n", text); 12 | } 13 | 14 | int main(int argc, char *argv[]) 15 | { 16 | gtk_init(&argc, &argv); 17 | 18 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 19 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 20 | 21 | GtkWidget *combobox = gtk_combo_box_text_new(); 22 | gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combobox), "Oak"); 23 | gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combobox), "Birch"); 24 | gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combobox), "Sycamore"); 25 | gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combobox), "Willow"); 26 | gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), 0); 27 | g_signal_connect(combobox, "changed", G_CALLBACK(combobox_changed), NULL); 28 | gtk_container_add(GTK_CONTAINER(window), combobox); 29 | 30 | gtk_widget_show_all(window); 31 | 32 | gtk_main(); 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /_examples/commonframe.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | gtk_init(&argc, &argv); 11 | 12 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 13 | gtk_window_set_default_size(GTK_WINDOW(window), -1, 200); 14 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 15 | 16 | GtkWidget *frame = gtk_frame_new(NULL); 17 | gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_NONE); 18 | gtk_container_add(GTK_CONTAINER(window), frame); 19 | 20 | GtkWidget *label1 = gtk_label_new("Common Frame"); 21 | gtk_label_set_use_markup(GTK_LABEL(label1), TRUE); 22 | gtk_frame_set_label_widget(GTK_FRAME(frame), label1); 23 | 24 | GtkWidget *alignment = gtk_alignment_new(0.5, 0.5, 1.0, 1.0); 25 | gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), 5, 0, 12, 0); 26 | gtk_container_add(GTK_CONTAINER(frame), alignment); 27 | 28 | GtkWidget *label2 = gtk_label_new("Label inside a Common Frame"); 29 | gtk_container_add(GTK_CONTAINER(alignment), label2); 30 | 31 | gtk_widget_show_all(window); 32 | 33 | gtk_main(); 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /_examples/dialog.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char *argv[]) 4 | { 5 | gtk_init(&argc, &argv); 6 | 7 | int response; 8 | 9 | GtkWidget *dialog = gtk_dialog_new(); 10 | gtk_window_set_title(GTK_WINDOW(dialog), "Dialog Example"); 11 | gtk_window_set_default_size(GTK_WINDOW(dialog), 200, 200); 12 | gtk_dialog_add_button(GTK_DIALOG(dialog), "_Reject", GTK_RESPONSE_REJECT); 13 | gtk_dialog_add_button(GTK_DIALOG(dialog), "_Accept", GTK_RESPONSE_ACCEPT); 14 | response = gtk_dialog_run(GTK_DIALOG(dialog)); 15 | 16 | if (response == -2) 17 | printf("Reject button clicked!\n"); 18 | else if (response == -3) 19 | printf("Accept button clicked!\n"); 20 | 21 | gtk_widget_destroy(dialog); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /_examples/entry.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | static void entry_activated(GtkWidget *entry, gpointer data) 9 | { 10 | g_print("Entry text: '%s'\n", gtk_entry_get_text(GTK_ENTRY(entry))); 11 | } 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | gtk_init(&argc, &argv); 16 | 17 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 18 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 19 | 20 | GtkWidget *entry = gtk_entry_new(); 21 | gtk_entry_set_text(GTK_ENTRY(entry), "A Text Entry Widget"); 22 | gtk_entry_set_placeholder_text(GTK_ENTRY(entry), "Placeholder Text"); 23 | g_signal_connect(GTK_ENTRY(entry), "activate", G_CALLBACK(entry_activated), NULL); 24 | gtk_container_add(GTK_CONTAINER(window), entry); 25 | 26 | gtk_widget_show_all(window); 27 | 28 | gtk_main(); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /_examples/entrybuffer.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | gtk_init(&argc, &argv); 11 | 12 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 13 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 14 | 15 | GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); 16 | gtk_container_add(GTK_CONTAINER(window), vbox); 17 | 18 | GtkWidget *entry; 19 | GtkEntryBuffer *entrybuffer = gtk_entry_buffer_new("EntryBuffer example", -1); 20 | 21 | entry = gtk_entry_new_with_buffer(GTK_ENTRY_BUFFER(entrybuffer)); 22 | gtk_box_pack_start(GTK_BOX(vbox), entry, FALSE, FALSE, 0); 23 | entry = gtk_entry_new_with_buffer(GTK_ENTRY_BUFFER(entrybuffer)); 24 | gtk_box_pack_start(GTK_BOX(vbox), entry, FALSE, FALSE, 0); 25 | entry = gtk_entry_new_with_buffer(GTK_ENTRY_BUFFER(entrybuffer)); 26 | gtk_box_pack_start(GTK_BOX(vbox), entry, FALSE, FALSE, 0); 27 | 28 | gtk_widget_show_all(window); 29 | 30 | gtk_main(); 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /_examples/entrycompletion.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | static void entry_activated(GtkWidget *entry, gpointer data) 9 | { 10 | g_print("Entry text: '%s'\n", gtk_entry_get_text(GTK_ENTRY(entry))); 11 | } 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | gtk_init(&argc, &argv); 16 | 17 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 18 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 19 | 20 | GtkListStore *liststore = gtk_list_store_new(1, G_TYPE_STRING); 21 | GtkTreeIter iter; 22 | 23 | gtk_list_store_append(liststore, &iter); 24 | gtk_list_store_set(liststore, &iter, 0, "Fedora", -1); 25 | gtk_list_store_append(liststore, &iter); 26 | gtk_list_store_set(liststore, &iter, 0, "Sabayon", -1); 27 | gtk_list_store_append(liststore, &iter); 28 | gtk_list_store_set(liststore, &iter, 0, "Arch Linux", -1); 29 | gtk_list_store_append(liststore, &iter); 30 | gtk_list_store_set(liststore, &iter, 0, "SimplyMEPIS", -1); 31 | gtk_list_store_append(liststore, &iter); 32 | gtk_list_store_set(liststore, &iter, 0, "Debian", -1); 33 | 34 | GtkEntryCompletion *entrycompletion = gtk_entry_completion_new(); 35 | gtk_entry_completion_set_model(GTK_ENTRY_COMPLETION(entrycompletion), GTK_TREE_MODEL(liststore)); 36 | gtk_entry_completion_set_text_column(GTK_ENTRY_COMPLETION(entrycompletion), 0); 37 | 38 | GtkWidget *entry = gtk_entry_new(); 39 | gtk_entry_set_completion(GTK_ENTRY(entry), entrycompletion); 40 | g_signal_connect(GTK_ENTRY(entry), "activate", G_CALLBACK(entry_activated), NULL); 41 | gtk_container_add(GTK_CONTAINER(window), entry); 42 | 43 | gtk_widget_show_all(window); 44 | 45 | gtk_main(); 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /_examples/expander.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | gtk_init(&argc, &argv); 11 | 12 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 13 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 14 | 15 | GtkWidget *expander = gtk_expander_new("Expander"); 16 | gtk_container_add(GTK_CONTAINER(window), expander); 17 | 18 | GtkWidget *label = gtk_label_new("Expander with Label"); 19 | gtk_widget_set_size_request(GTK_WIDGET(label), 200, 200); 20 | gtk_container_add(GTK_CONTAINER(expander), label); 21 | 22 | gtk_widget_show_all(window); 23 | 24 | gtk_main(); 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /_examples/filechooserbutton.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | static void file_selected(GtkWidget *filechooserbutton, gpointer data) 9 | { 10 | g_print("Selected file: %s", gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(filechooserbutton))); 11 | } 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | gtk_init(&argc, &argv); 16 | 17 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 18 | gtk_window_set_default_size(GTK_WINDOW(window), 200, -1); 19 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 20 | 21 | GtkWidget *filechooserbutton = gtk_file_chooser_button_new("FileChooserButton", 22 | GTK_FILE_CHOOSER_ACTION_OPEN); 23 | g_signal_connect(filechooserbutton, "file-set", G_CALLBACK(file_selected), NULL); 24 | gtk_container_add(GTK_CONTAINER(window), filechooserbutton); 25 | 26 | gtk_widget_show_all(window); 27 | 28 | gtk_main(); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /_examples/filechooserdialog.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char *argv[]) 4 | { 5 | gtk_init(&argc, &argv); 6 | 7 | GtkWidget *filechooserdialog = gtk_file_chooser_dialog_new("FileChooserDialog", NULL, GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL); 8 | gtk_dialog_run(GTK_DIALOG(filechooserdialog)); 9 | g_print("Selected file: %s", gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(filechooserdialog))); 10 | gtk_widget_destroy(filechooserdialog); 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /_examples/filechooserwidget.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | gtk_init(&argc, &argv); 11 | 12 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 13 | gtk_window_set_default_size(GTK_WINDOW(window), 600, 400); 14 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 15 | 16 | GtkWidget *filechooserwidget = gtk_file_chooser_widget_new(GTK_FILE_CHOOSER_ACTION_OPEN); 17 | gtk_container_add(GTK_CONTAINER(window), filechooserwidget); 18 | 19 | gtk_widget_show_all(window); 20 | 21 | gtk_main(); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /_examples/fixed.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | gtk_init(&argc, &argv); 11 | 12 | GtkWidget *button; 13 | 14 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 15 | gtk_window_set_title(GTK_WINDOW(window), "Window"); 16 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 17 | 18 | GtkWidget *fixed = gtk_fixed_new(); 19 | gtk_container_add(GTK_CONTAINER(window), fixed); 20 | 21 | button = gtk_button_new_with_label("Button 1"); 22 | gtk_fixed_put(GTK_FIXED(fixed), button, 100, 120); 23 | 24 | button = gtk_button_new_with_label("Button 2"); 25 | gtk_fixed_put(GTK_FIXED(fixed), button, 220, 50); 26 | 27 | button = gtk_button_new_with_label("Button 3"); 28 | gtk_fixed_put(GTK_FIXED(fixed), button, 40, 35); 29 | 30 | gtk_widget_show_all(window); 31 | 32 | gtk_main(); 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /_examples/flowbox.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | GtkWidget *window; 11 | GtkWidget *flowbox; 12 | 13 | gtk_init(&argc, &argv); 14 | 15 | window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 16 | gtk_window_set_default_size(GTK_WINDOW(window), 200, 200); 17 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 18 | 19 | flowbox = gtk_flow_box_new(); 20 | gtk_container_add(GTK_CONTAINER(window), flowbox); 21 | 22 | GtkWidget *button = gtk_button_new_with_label("Child 1"); 23 | gtk_flow_box_insert(GTK_FLOW_BOX(flowbox), button, 0); 24 | 25 | GtkWidget *label = gtk_label_new("Child 2"); 26 | gtk_flow_box_insert(GTK_FLOW_BOX(flowbox), label, 1); 27 | 28 | GtkWidget *checkbutton = gtk_check_button_new_with_label("Child 3"); 29 | gtk_flow_box_insert(GTK_FLOW_BOX(flowbox), checkbutton, 2); 30 | 31 | gtk_widget_show_all(window); 32 | 33 | gtk_main(); 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /_examples/fontbutton.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static void destroy(GtkWidget *widget, gpointer data) 5 | { 6 | gtk_main_quit(); 7 | } 8 | 9 | static void font_selected(GtkWidget *fontbutton, gpointer data) 10 | { 11 | g_print("%s\n", gtk_font_button_get_font_name(GTK_FONT_BUTTON(fontbutton))); 12 | } 13 | 14 | int main(int argc, char *argv[]) 15 | { 16 | gtk_init(&argc, &argv); 17 | 18 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 19 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 20 | 21 | GtkWidget *fontbutton = gtk_font_button_new(); 22 | g_signal_connect(fontbutton, "font-set", G_CALLBACK(font_selected), NULL); 23 | gtk_container_add(GTK_CONTAINER(window), fontbutton); 24 | 25 | gtk_widget_show_all(window); 26 | 27 | gtk_main(); 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /_examples/frame.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | gtk_init(&argc, &argv); 11 | 12 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 13 | gtk_window_set_default_size(GTK_WINDOW(window), 200, 200); 14 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 15 | 16 | GtkWidget *frame = gtk_frame_new("Frame"); 17 | gtk_container_add(GTK_CONTAINER(window), frame); 18 | 19 | gtk_widget_show_all(window); 20 | 21 | gtk_main(); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /_examples/handlebox.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | gtk_init(&argc, &argv); 11 | 12 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 13 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 14 | 15 | GtkWidget *handlebox = gtk_handle_box_new(); 16 | gtk_container_add(GTK_CONTAINER(window), handlebox); 17 | 18 | GtkWidget *toolbar = gtk_toolbar_new(); 19 | gtk_widget_set_size_request(toolbar, 200, -1); 20 | gtk_container_add(GTK_CONTAINER(handlebox), toolbar); 21 | 22 | GtkToolItem *toolbuttonNew = gtk_tool_button_new_from_stock(GTK_STOCK_NEW); 23 | gtk_toolbar_insert(GTK_TOOLBAR(toolbar), toolbuttonNew, 0); 24 | GtkToolItem *toolbuttonOpen = gtk_tool_button_new_from_stock(GTK_STOCK_OPEN); 25 | gtk_toolbar_insert(GTK_TOOLBAR(toolbar), toolbuttonOpen, 1); 26 | GtkToolItem *toolbuttonSave = gtk_tool_button_new_from_stock(GTK_STOCK_SAVE); 27 | gtk_toolbar_insert(GTK_TOOLBAR(toolbar), toolbuttonSave, 2); 28 | 29 | gtk_widget_show_all(window); 30 | 31 | gtk_main(); 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /_examples/helloworld.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | gtk_init(&argc, &argv); 11 | 12 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 13 | gtk_window_set_title(GTK_WINDOW(window), "Hello, World!"); 14 | gtk_window_set_default_size(GTK_WINDOW(window), 200, 200); 15 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 16 | 17 | GtkWidget *label = gtk_label_new("Hello, World!"); 18 | gtk_container_add(GTK_CONTAINER(window), label); 19 | 20 | gtk_widget_show_all(window); 21 | 22 | gtk_main(); 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /_examples/image.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | gtk_init(&argc, &argv); 11 | 12 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 13 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 14 | 15 | GtkWidget *image = gtk_image_new_from_file("../resources/gtk.png"); 16 | gtk_container_add(GTK_CONTAINER(window), image); 17 | 18 | gtk_widget_show_all(window); 19 | 20 | gtk_main(); 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /_examples/infobar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | GtkWidget *infobar; 4 | GtkWidget *label; 5 | 6 | static void button_clicked(GtkWidget *button, gchar* message) 7 | { 8 | gchar *text = g_strdup_printf("InfoBar displaying %s message", message); 9 | gtk_label_set_text(GTK_LABEL(label), text); 10 | 11 | if (message == "information") 12 | gtk_info_bar_set_message_type(GTK_INFO_BAR(infobar), GTK_MESSAGE_INFO); 13 | else if (message == "warning") 14 | gtk_info_bar_set_message_type(GTK_INFO_BAR(infobar), GTK_MESSAGE_WARNING); 15 | else if (message == "question") 16 | gtk_info_bar_set_message_type(GTK_INFO_BAR(infobar), GTK_MESSAGE_QUESTION); 17 | else if (message == "error") 18 | gtk_info_bar_set_message_type(GTK_INFO_BAR(infobar), GTK_MESSAGE_ERROR); 19 | 20 | gtk_widget_show(GTK_WIDGET(infobar)); 21 | } 22 | 23 | int main(int argc, char *argv[]) 24 | { 25 | GtkWidget *button; 26 | GtkWidget *content_area; 27 | 28 | gtk_init(&argc, &argv); 29 | 30 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 31 | g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL); 32 | 33 | GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); 34 | gtk_container_add(GTK_CONTAINER(window), vbox); 35 | 36 | infobar = gtk_info_bar_new(); 37 | gtk_info_bar_add_button(GTK_INFO_BAR(infobar), "Close", GTK_RESPONSE_OK); 38 | g_signal_connect(infobar, "response", G_CALLBACK(gtk_widget_hide), NULL); 39 | gtk_box_pack_start(GTK_BOX(vbox), infobar, TRUE, TRUE, 0); 40 | label = gtk_label_new("InfoBar displaying information message"); 41 | content_area = gtk_info_bar_get_content_area(GTK_INFO_BAR(infobar)); 42 | gtk_box_pack_start(GTK_BOX(content_area), label, TRUE, TRUE, 0); 43 | 44 | GtkWidget *hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5); 45 | gtk_box_pack_end(GTK_BOX(vbox), hbox, FALSE, TRUE, 0); 46 | 47 | button = gtk_button_new_with_label("Information"); 48 | g_signal_connect(button, "clicked", G_CALLBACK(button_clicked), "information"); 49 | gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); 50 | button = gtk_button_new_with_label("Warning"); 51 | g_signal_connect(button, "clicked", G_CALLBACK(button_clicked), "warning"); 52 | gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); 53 | button = gtk_button_new_with_label("Question"); 54 | g_signal_connect(button, "clicked", G_CALLBACK(button_clicked), "question"); 55 | gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); 56 | button = gtk_button_new_with_label("Error"); 57 | g_signal_connect(button, "clicked", G_CALLBACK(button_clicked), "error"); 58 | gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); 59 | 60 | gtk_widget_show_all(window); 61 | 62 | gtk_main(); 63 | 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /_examples/label.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | gtk_init(&argc, &argv); 11 | 12 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 13 | gtk_window_set_title(GTK_WINDOW(window), "Window"); 14 | gtk_window_set_default_size(GTK_WINDOW(window), 200, 200); 15 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 16 | 17 | GtkWidget *label = gtk_label_new("This is an example Label"); 18 | gtk_container_add(GTK_CONTAINER(window), label); 19 | 20 | const char *text = gtk_label_get_text(GTK_LABEL(label)); 21 | printf("%s\n", text); 22 | 23 | gtk_widget_show_all(window); 24 | 25 | gtk_main(); 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /_examples/layout.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | gtk_init(&argc, &argv); 11 | 12 | GtkWidget *button; 13 | 14 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 15 | gtk_window_set_title(GTK_WINDOW(window), "Window"); 16 | gtk_window_set_default_size(GTK_WINDOW(window), 300, 200); 17 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 18 | 19 | GtkWidget *layout = gtk_layout_new(NULL, NULL); 20 | gtk_container_add(GTK_CONTAINER(window), layout); 21 | 22 | button = gtk_button_new_with_label("Button 1"); 23 | gtk_layout_put(GTK_LAYOUT(layout), button, 100, 120); 24 | button = gtk_button_new_with_label("Button 2"); 25 | gtk_layout_put(GTK_LAYOUT(layout), button, 220, 50); 26 | button = gtk_button_new_with_label("Button 3"); 27 | gtk_layout_put(GTK_LAYOUT(layout), button, 40, 35); 28 | 29 | gtk_widget_show_all(window); 30 | 31 | gtk_main(); 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /_examples/linkbutton.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | gtk_init(&argc, &argv); 11 | 12 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 13 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 14 | 15 | GtkWidget *linkbutton = gtk_link_button_new_with_label("http://learngtk.org/", "Link Button"); 16 | gtk_container_add(GTK_CONTAINER(window), linkbutton); 17 | 18 | gtk_widget_show_all(window); 19 | 20 | gtk_main(); 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /_examples/liststore.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | gtk_init(&argc, &argv); 11 | 12 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 13 | gtk_window_set_default_size(GTK_WINDOW(window), 200, 200); 14 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 15 | 16 | GtkListStore *liststore = gtk_list_store_new(1, G_TYPE_STRING); 17 | GtkTreeIter treeiter; 18 | 19 | gtk_list_store_append(liststore, &treeiter); 20 | gtk_list_store_set(liststore, &treeiter, 0, "Mandriva", -1); 21 | gtk_list_store_append(liststore, &treeiter); 22 | gtk_list_store_set(liststore, &treeiter, 0, "Aptosid", -1); 23 | gtk_list_store_append(liststore, &treeiter); 24 | gtk_list_store_set(liststore, &treeiter, 0, "OpenSuSE", -1); 25 | gtk_list_store_append(liststore, &treeiter); 26 | gtk_list_store_set(liststore, &treeiter, 0, "Linux Mint", -1); 27 | gtk_list_store_append(liststore, &treeiter); 28 | gtk_list_store_set(liststore, &treeiter, 0, "Arch Linux", -1); 29 | 30 | GtkWidget *treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(liststore)); 31 | gtk_container_add(GTK_CONTAINER(window), treeview); 32 | 33 | GtkCellRenderer *cellrenderertext = gtk_cell_renderer_text_new(); 34 | 35 | GtkTreeViewColumn *treeviewcolumn = gtk_tree_view_column_new_with_attributes("Distributions", 36 | cellrenderertext, 37 | "text", 0, 38 | NULL); 39 | gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), treeviewcolumn); 40 | 41 | gtk_widget_show_all(window); 42 | 43 | gtk_main(); 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /_examples/messagedialog.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | GtkWidget *window; 4 | GtkWidget *button; 5 | GtkWidget *messagedialog; 6 | 7 | static void on_button_clicked(GtkWidget *button, gchar* message) 8 | { 9 | gchar *text = g_strdup_printf("MessageDialog displaying %s message", message); 10 | 11 | messagedialog = gtk_message_dialog_new(GTK_WINDOW(window), 0, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, text); 12 | 13 | gtk_dialog_run(GTK_DIALOG(messagedialog)); 14 | gtk_widget_destroy(messagedialog); 15 | } 16 | 17 | int main(int argc, char *argv[]) 18 | { 19 | gtk_init(&argc, &argv); 20 | 21 | window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 22 | g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL); 23 | 24 | GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5); 25 | gtk_container_add(GTK_CONTAINER(window), box); 26 | 27 | button = gtk_button_new_with_label("Information"); 28 | g_signal_connect(button, "clicked", G_CALLBACK(on_button_clicked), "information"); 29 | gtk_box_pack_start(GTK_BOX(box), GTK_WIDGET(button), TRUE, TRUE, 0); 30 | button = gtk_button_new_with_label("Warning"); 31 | g_signal_connect(button, "clicked", G_CALLBACK(on_button_clicked), "warning"); 32 | gtk_box_pack_start(GTK_BOX(box), GTK_WIDGET(button), TRUE, TRUE, 0); 33 | button = gtk_button_new_with_label("Question"); 34 | g_signal_connect(button, "clicked", G_CALLBACK(on_button_clicked), "question"); 35 | gtk_box_pack_start(GTK_BOX(box), GTK_WIDGET(button), TRUE, TRUE, 0); 36 | button = gtk_button_new_with_label("Error"); 37 | g_signal_connect(button, "clicked", G_CALLBACK(on_button_clicked), "error"); 38 | gtk_box_pack_start(GTK_BOX(box), GTK_WIDGET(button), TRUE, TRUE, 0); 39 | 40 | gtk_widget_show_all(window); 41 | 42 | gtk_main(); 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /_examples/notebook.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | static void destroy(GtkWidget *widget, gpointer data) 6 | { 7 | gtk_main_quit(); 8 | } 9 | 10 | int main(int argc, char *argv[]) 11 | { 12 | gtk_init(&argc, &argv); 13 | 14 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 15 | gtk_window_set_default_size(GTK_WINDOW(window), 200, 200); 16 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 17 | 18 | GtkWidget *notebook = gtk_notebook_new(); 19 | gtk_container_add(GTK_CONTAINER(window), notebook); 20 | 21 | int count; 22 | gchar *text; 23 | 24 | for (count = 1; count <= 5; count++) 25 | { 26 | GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); 27 | text = g_strdup_printf("Page %d", count); 28 | GtkWidget *label = gtk_label_new(text); 29 | 30 | gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox, label); 31 | } 32 | 33 | gtk_widget_show_all(window); 34 | 35 | gtk_main(); 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /_examples/paned.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | gtk_init(&argc, &argv); 11 | 12 | GtkWidget *label; 13 | 14 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 15 | gtk_window_set_default_size(GTK_WINDOW(window), 400, 200); 16 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 17 | 18 | GtkWidget *box = gtk_box_new(TRUE, 5); 19 | gtk_container_add(GTK_CONTAINER(window), box); 20 | 21 | GtkWidget *hpane = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL); 22 | gtk_box_pack_start(GTK_BOX(box), hpane, TRUE, TRUE, 0); 23 | 24 | label = gtk_label_new("Label 1"); 25 | gtk_paned_add1(GTK_PANED(hpane), label); 26 | label = gtk_label_new("Label 2"); 27 | gtk_paned_add2(GTK_PANED(hpane), label); 28 | 29 | GtkWidget *vpane = gtk_paned_new(GTK_ORIENTATION_VERTICAL); 30 | gtk_box_pack_start(GTK_BOX(box), vpane, TRUE, TRUE, 0); 31 | 32 | label = gtk_label_new("Label 1"); 33 | gtk_paned_add1(GTK_PANED(vpane), label); 34 | label = gtk_label_new("Label 2"); 35 | gtk_paned_add2(GTK_PANED(vpane), label); 36 | 37 | gtk_widget_show_all(window); 38 | 39 | gtk_main(); 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /_examples/plug.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | static void embed_event(GtkWidget *widget, gpointer data) 9 | { 10 | g_print("Embed event occurred"); 11 | } 12 | 13 | static void entry_activated(GtkWidget *widget, gpointer data) 14 | { 15 | g_print("Entry activated"); 16 | } 17 | 18 | int main(int argc, char *argv[]) 19 | { 20 | gtk_init(&argc, &argv); 21 | 22 | GtkWidget *plug = gtk_plug_new(NULL); 23 | g_print("%i", gtk_plug_get_id(GTK_PLUG(plug))); 24 | g_signal_connect(plug, "destroy", G_CALLBACK(destroy), NULL); 25 | g_signal_connect(plug, "embed-event", G_CALLBACK(embed_event), NULL); 26 | 27 | GtkWidget *entry = gtk_entry_new(); 28 | gtk_entry_set_text(GTK_ENTRY(entry), "Plug and Socket"); 29 | g_signal_connect(entry, "activate", G_CALLBACK(entry_activated), NULL); 30 | gtk_plug_add(GTK_PLUG(plug), entry); 31 | 32 | gtk_widget_show_all(plug); 33 | 34 | gtk_main(); 35 | 36 | return 0; 37 | } -------------------------------------------------------------------------------- /_examples/progressbar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef struct _ProgressData { 4 | GtkWidget *progressbar; 5 | int timer; 6 | gboolean show_text; 7 | gboolean activity_mode; 8 | } ProgressData; 9 | 10 | static gboolean progress_timeout(gpointer data) 11 | { 12 | ProgressData *progressdata = (ProgressData *)data; 13 | gdouble new_val; 14 | 15 | if (progressdata->activity_mode) 16 | gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progressdata->progressbar)); 17 | else 18 | { 19 | new_val = gtk_progress_bar_get_fraction(GTK_PROGRESS_BAR(progressdata->progressbar)) + 0.1; 20 | 21 | if (new_val > 1.0) 22 | new_val = 0.0; 23 | 24 | gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR (progressdata->progressbar), new_val); 25 | } 26 | 27 | return TRUE; 28 | } 29 | 30 | static void toggle_show_text(GtkWidget *widget, ProgressData *progressdata) 31 | { 32 | if (progressdata->show_text) 33 | { 34 | progressdata->show_text = FALSE; 35 | gtk_progress_bar_set_show_text(GTK_PROGRESS_BAR(progressdata->progressbar), FALSE); 36 | gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progressdata->progressbar), ""); 37 | } 38 | else 39 | { 40 | progressdata->show_text = TRUE; 41 | gtk_progress_bar_set_show_text(GTK_PROGRESS_BAR(progressdata->progressbar), TRUE); 42 | } 43 | } 44 | 45 | static void toggle_activity_mode(GtkWidget *widget, ProgressData *progressdata) 46 | { 47 | progressdata->activity_mode = !progressdata->activity_mode; 48 | 49 | if (progressdata->activity_mode) 50 | gtk_progress_bar_pulse(GTK_PROGRESS_BAR (progressdata->progressbar)); 51 | else 52 | gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR (progressdata->progressbar), 0.0); 53 | } 54 | 55 | static void destroy_progress(GtkWidget *widget, ProgressData *progressdata) 56 | { 57 | g_source_remove(progressdata->timer); 58 | progressdata->timer = 0; 59 | g_free(progressdata); 60 | gtk_main_quit(); 61 | } 62 | 63 | int main(int argc, char *argv[]) 64 | { 65 | gtk_init(&argc, &argv); 66 | 67 | ProgressData *progressdata; 68 | GtkWidget *checkbutton; 69 | 70 | progressdata = g_malloc(sizeof(ProgressData)); 71 | 72 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 73 | gtk_window_set_title(GTK_WINDOW(window), "ProgressBar"); 74 | g_signal_connect(window, "destroy", G_CALLBACK (destroy_progress), (gpointer) progressdata); 75 | gtk_container_set_border_width (GTK_CONTAINER (window), 0); 76 | 77 | GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); 78 | gtk_container_add(GTK_CONTAINER(window), vbox); 79 | 80 | progressdata->activity_mode = FALSE; 81 | 82 | progressdata->progressbar = gtk_progress_bar_new(); 83 | gtk_box_pack_start(GTK_BOX(vbox), progressdata->progressbar, TRUE, FALSE, 0); 84 | 85 | checkbutton = gtk_check_button_new_with_label("Display text"); 86 | g_signal_connect(checkbutton, "clicked", G_CALLBACK(toggle_show_text), progressdata); 87 | gtk_box_pack_start(GTK_BOX(vbox), checkbutton, TRUE, FALSE, 0); 88 | 89 | checkbutton = gtk_check_button_new_with_label("Activity mode"); 90 | g_signal_connect(checkbutton, "clicked", G_CALLBACK(toggle_activity_mode), progressdata); 91 | gtk_box_pack_start(GTK_BOX(vbox), checkbutton, TRUE, FALSE, 0); 92 | 93 | gtk_widget_show_all(window); 94 | 95 | progressdata->timer = g_timeout_add(1000, progress_timeout, progressdata); 96 | 97 | gtk_main(); 98 | 99 | return 0; 100 | } 101 | -------------------------------------------------------------------------------- /_examples/radiobutton.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | static void radio_button_toggled(GtkWidget *radiobutton, gpointer data) 9 | { 10 | if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radiobutton))) 11 | { 12 | g_print("%s active\n", gtk_button_get_label(GTK_BUTTON(radiobutton))); 13 | } 14 | 15 | } 16 | 17 | int main(int argc, char *argv[]) 18 | { 19 | gtk_init(&argc, &argv); 20 | 21 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 22 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 23 | 24 | GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); 25 | gtk_container_add(GTK_CONTAINER(window), box); 26 | 27 | GtkWidget *radiobutton; 28 | 29 | radiobutton = gtk_radio_button_new_with_label(NULL, "Radio Button 1"); 30 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radiobutton), TRUE); 31 | g_signal_connect(radiobutton, "toggled", G_CALLBACK(radio_button_toggled), NULL); 32 | gtk_box_pack_start(GTK_BOX(box), GTK_WIDGET(radiobutton), FALSE, FALSE, 0); 33 | 34 | GSList *group; 35 | group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(radiobutton)); 36 | 37 | radiobutton = gtk_radio_button_new_with_label(gtk_radio_button_get_group(GTK_RADIO_BUTTON(radiobutton)), "Radio Button 2"); 38 | g_signal_connect(radiobutton, "toggled", G_CALLBACK(radio_button_toggled), NULL); 39 | gtk_box_pack_start(GTK_BOX(box), GTK_WIDGET(radiobutton), FALSE, FALSE, 0); 40 | 41 | radiobutton = gtk_radio_button_new_with_label(gtk_radio_button_get_group(GTK_RADIO_BUTTON(radiobutton)), "Radio Button 3"); 42 | g_signal_connect(radiobutton, "toggled", G_CALLBACK(radio_button_toggled), NULL); 43 | gtk_box_pack_start(GTK_BOX(box), GTK_WIDGET(radiobutton), FALSE, FALSE, 0); 44 | 45 | gtk_widget_show_all(window); 46 | 47 | gtk_main(); 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /_examples/recentchooserdialog.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char *argv[]) 4 | { 5 | gtk_init(&argc, &argv); 6 | 7 | GtkWidget *recentchooserdialog = gtk_recent_chooser_dialog_new("RecentChooserDialog", NULL, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL); 8 | gtk_dialog_run(GTK_DIALOG(recentchooserdialog)); 9 | gtk_widget_destroy(recentchooserdialog); 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /_examples/recentchoosermenu.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | gtk_init(&argc, &argv); 11 | 12 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 13 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 14 | 15 | GtkWidget *menubar = gtk_menu_bar_new(); 16 | gtk_container_add(GTK_CONTAINER(window), menubar); 17 | 18 | GtkWidget *menuitem = gtk_menu_item_new_with_label("Recent Documents"); 19 | gtk_menu_bar_append(GTK_MENU_BAR(menubar), menuitem); 20 | 21 | GtkWidget *recentchoosermenu = gtk_recent_chooser_menu_new(); 22 | gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), recentchoosermenu); 23 | 24 | gtk_widget_show_all(window); 25 | 26 | gtk_main(); 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /_examples/recentchooserwidget.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | gtk_init(&argc, &argv); 11 | 12 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 13 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 14 | 15 | GtkWidget *recentchooserwidget = gtk_recent_chooser_widget_new(); 16 | gtk_container_add(GTK_CONTAINER(window), recentchooserwidget); 17 | 18 | gtk_widget_show_all(window); 19 | 20 | gtk_main(); 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /_examples/scale.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | static void scale_adjustment(GtkWidget *widget, gpointer data) 9 | { 10 | double value = gtk_range_get_value(GTK_RANGE(widget)); 11 | printf("Adjustment value: %f\n", value); 12 | } 13 | 14 | int main(int argc, char *argv[]) 15 | { 16 | gtk_init(&argc, &argv); 17 | 18 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 19 | gtk_window_set_default_size(GTK_WINDOW(window), 400, 200); 20 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 21 | 22 | GtkWidget *box = gtk_box_new(TRUE, 5); 23 | gtk_container_add(GTK_CONTAINER(window), box); 24 | 25 | GtkAdjustment *hadjustment = gtk_adjustment_new(50, 0, 100, 1, 10, 0); 26 | GtkWidget *hscale = gtk_scale_new(GTK_ORIENTATION_HORIZONTAL, GTK_ADJUSTMENT(hadjustment)); 27 | g_signal_connect(hscale, "value-changed", G_CALLBACK(scale_adjustment), NULL); 28 | gtk_box_pack_start(GTK_BOX(box), hscale, TRUE, TRUE, 0); 29 | 30 | GtkAdjustment *vadjustment = gtk_adjustment_new(30, 0, 100, 1, 10, 0); 31 | GtkWidget *vscale = gtk_scale_new(GTK_ORIENTATION_VERTICAL, GTK_ADJUSTMENT(vadjustment)); 32 | gtk_scale_set_digits(GTK_SCALE(vscale), 0); 33 | g_signal_connect(vscale, "value-changed", G_CALLBACK(scale_adjustment), NULL); 34 | gtk_box_pack_start(GTK_BOX(box), vscale, TRUE, TRUE, 0); 35 | 36 | gtk_widget_show_all(window); 37 | 38 | gtk_main(); 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /_examples/scalebutton.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | GtkWidget *scalebutton; 4 | 5 | static void destroy(GtkWidget *widget, gpointer data) 6 | { 7 | gtk_main_quit(); 8 | } 9 | 10 | static void value_changed(GtkWidget *scalebutton, gpointer data) 11 | { 12 | int value = gtk_scale_button_get_value(GTK_SCALE_BUTTON(scalebutton)); 13 | g_print("%i\n", value); 14 | } 15 | 16 | int main(int argc, char *argv[]) 17 | { 18 | gtk_init(&argc, &argv); 19 | 20 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 21 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 22 | 23 | scalebutton = gtk_scale_button_new(GTK_ICON_SIZE_BUTTON, 0, 100, 1, NULL); 24 | g_signal_connect(scalebutton, "value-changed", G_CALLBACK(value_changed), NULL); 25 | gtk_container_add(GTK_CONTAINER(window), scalebutton); 26 | 27 | gtk_widget_show_all(window); 28 | 29 | gtk_main(); 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /_examples/scrollbar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | gtk_init(&argc, &argv); 11 | 12 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 13 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 14 | 15 | GtkWidget *table = gtk_table_new(2, 2, FALSE); 16 | gtk_container_add(GTK_CONTAINER(window), table); 17 | 18 | GtkWidget *layout = gtk_layout_new(NULL, NULL); 19 | gtk_layout_set_size(GTK_LAYOUT(layout), 2000, 800); 20 | gtk_table_attach(GTK_TABLE(table), layout, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0); 21 | GtkAdjustment *vadjustment = gtk_layout_get_vadjustment(GTK_LAYOUT(layout)); 22 | GtkAdjustment *hadjustment = gtk_layout_get_hadjustment(GTK_LAYOUT(layout)); 23 | 24 | GtkWidget *vscrollbar = gtk_vscrollbar_new(vadjustment); 25 | gtk_table_attach(GTK_TABLE(table), vscrollbar, 1, 2, 0, 1, GTK_SHRINK, GTK_FILL | GTK_EXPAND, 0, 0); 26 | 27 | GtkWidget *hscrollbar = gtk_hscrollbar_new(hadjustment); 28 | gtk_table_attach(GTK_TABLE(table), hscrollbar, 0, 1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0); 29 | 30 | gtk_widget_show_all(window); 31 | 32 | gtk_main(); 33 | 34 | return 0; 35 | } -------------------------------------------------------------------------------- /_examples/scrolledwindow.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | gtk_init(&argc, &argv); 11 | 12 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 13 | gtk_window_set_default_size(GTK_WINDOW(window), 200, 200); 14 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 15 | 16 | GtkWidget *scrolledwindow = gtk_scrolled_window_new(NULL, NULL); 17 | gtk_container_add(GTK_CONTAINER(window), scrolledwindow); 18 | 19 | GtkWidget *textview = gtk_text_view_new(); 20 | gtk_container_add(GTK_CONTAINER(scrolledwindow), textview); 21 | 22 | gtk_widget_show_all(window); 23 | 24 | gtk_main(); 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /_examples/separator.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | gtk_init(&argc, &argv); 11 | 12 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 13 | gtk_window_set_default_size(GTK_WINDOW(window), 400, 200); 14 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 15 | 16 | GtkWidget *hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5); 17 | gtk_container_add(GTK_CONTAINER(window), hbox); 18 | 19 | GtkWidget *hseparator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL); 20 | gtk_box_pack_start(GTK_BOX(hbox), hseparator, TRUE, TRUE, 0); 21 | GtkWidget *vseparator = gtk_separator_new(GTK_ORIENTATION_VERTICAL); 22 | gtk_box_pack_start(GTK_BOX(hbox), vseparator, TRUE, TRUE, 0); 23 | 24 | gtk_widget_show_all(window); 25 | 26 | gtk_main(); 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /_examples/sizegroup.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | gtk_init(&argc, &argv); 11 | 12 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 13 | gtk_window_set_default_size(GTK_WINDOW(window), 200, 200); 14 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 15 | 16 | GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 2); 17 | gtk_container_add(GTK_CONTAINER(window), vbox); 18 | 19 | GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_BOTH); 20 | 21 | GtkWidget *button1 = gtk_button_new_with_label("Button 1"); 22 | gtk_size_group_add_widget(GTK_SIZE_GROUP(sizegroup), button1); 23 | gtk_box_pack_start(GTK_BOX(vbox), button1, TRUE, TRUE, 0); 24 | GtkWidget *button2 = gtk_button_new_with_label("Button 2"); 25 | gtk_size_group_add_widget(GTK_SIZE_GROUP(sizegroup), button2); 26 | gtk_box_pack_start(GTK_BOX(vbox), button2, TRUE, TRUE, 0); 27 | GtkWidget *button3 = gtk_button_new_with_label("Button 3"); 28 | gtk_size_group_add_widget(GTK_SIZE_GROUP(sizegroup), button3); 29 | gtk_box_pack_start(GTK_BOX(vbox), button3, TRUE, TRUE, 0); 30 | 31 | gtk_widget_show_all(window); 32 | 33 | gtk_main(); 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /_examples/socket.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | static void plug_added(GtkWidget *widget, gpointer data) 9 | { 10 | g_print("A plug has been added"); 11 | } 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | gtk_init(&argc, &argv); 16 | 17 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 18 | gtk_window_set_default_size(GTK_WINDOW(window), 200, 200); 19 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 20 | 21 | GtkWidget *socket = gtk_socket_new(); 22 | g_signal_connect(socket, "plug-added", G_CALLBACK(plug_added), NULL); 23 | gtk_container_add(GTK_CONTAINER(window), socket); 24 | 25 | gtk_widget_show_all(window); 26 | 27 | gtk_main(); 28 | 29 | return 0; 30 | } -------------------------------------------------------------------------------- /_examples/spinbutton.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | gtk_init(&argc, &argv); 11 | 12 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 13 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 14 | 15 | GtkAdjustment *adjustment = gtk_adjustment_new(0, 0, 10, 1, 2, 0); 16 | 17 | GtkWidget *spinbutton = gtk_spin_button_new(GTK_ADJUSTMENT(adjustment), 0, 0); 18 | gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbutton), 5); 19 | gtk_container_add(GTK_CONTAINER(window), spinbutton); 20 | 21 | gtk_widget_show_all(window); 22 | 23 | gtk_main(); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /_examples/spinner.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | static void start_spinner(GtkWidget *button, GtkWidget *spinner) 9 | { 10 | gtk_spinner_start(GTK_SPINNER(spinner)); 11 | } 12 | 13 | static void stop_spinner(GtkWidget *button, GtkWidget *spinner) 14 | { 15 | gtk_spinner_stop(GTK_SPINNER(spinner)); 16 | } 17 | 18 | int main(int argc, char *argv[]) 19 | { 20 | GtkWidget *window; 21 | 22 | gtk_init(&argc, &argv); 23 | 24 | window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 25 | gtk_window_set_default_size(GTK_WINDOW(window), 200, 200); 26 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 27 | 28 | GtkWidget *grid = gtk_grid_new(); 29 | gtk_container_add(GTK_CONTAINER(window), grid); 30 | 31 | GtkWidget *spinner = gtk_spinner_new(); 32 | gtk_widget_set_hexpand(GTK_WIDGET(spinner), TRUE); 33 | gtk_widget_set_vexpand(GTK_WIDGET(spinner), TRUE); 34 | gtk_grid_attach(GTK_GRID(grid), spinner, 0, 0, 2, 1); 35 | 36 | GtkWidget *buttonStart = gtk_button_new_with_label("Start"); 37 | g_signal_connect(buttonStart, "clicked", G_CALLBACK(start_spinner), spinner); 38 | gtk_grid_attach(GTK_GRID(grid), buttonStart, 0, 1, 1, 1); 39 | GtkWidget *buttonStop = gtk_button_new_with_label("Stop"); 40 | g_signal_connect(buttonStop, "clicked", G_CALLBACK(stop_spinner), spinner); 41 | gtk_grid_attach(GTK_GRID(grid), buttonStop, 1, 1, 1, 1); 42 | 43 | gtk_widget_show_all(window); 44 | 45 | gtk_main(); 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /_examples/statusbar.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | GtkWidget *statusbar; 6 | 7 | static void destroy(GtkWidget *widget, gpointer data) 8 | { 9 | gtk_main_quit(); 10 | } 11 | 12 | static void push_button_clicked(GtkWidget *widget, gpointer data) 13 | { 14 | static int count = 1; 15 | gchar *buffer; 16 | 17 | buffer = g_strdup_printf("Item %d", count++); 18 | gtk_statusbar_push(GTK_STATUSBAR(statusbar), GPOINTER_TO_INT(data), buffer); 19 | g_free(buffer); 20 | } 21 | 22 | static void pop_button_clicked(GtkWidget *widget, gpointer data) 23 | { 24 | gtk_statusbar_pop(GTK_STATUSBAR(statusbar), GPOINTER_TO_INT(data)); 25 | } 26 | 27 | int main(int argc, char *argv[]) 28 | { 29 | gtk_init(&argc, &argv); 30 | 31 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 32 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 33 | 34 | GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 2); 35 | gtk_container_add(GTK_CONTAINER(window), vbox); 36 | 37 | statusbar = gtk_statusbar_new(); 38 | gtk_box_pack_end(GTK_BOX(vbox), statusbar, FALSE, TRUE, 0); 39 | gint context_id = gtk_statusbar_get_context_id(GTK_STATUSBAR(statusbar), "Statusbar example"); 40 | 41 | GtkWidget *buttonPush = gtk_button_new_with_label("Push message"); 42 | gtk_box_pack_start(GTK_BOX(vbox), buttonPush, FALSE, TRUE, 0); 43 | g_signal_connect(buttonPush, "clicked", G_CALLBACK(push_button_clicked), GINT_TO_POINTER (context_id)); 44 | GtkWidget *buttonPop = gtk_button_new_with_label("Pop message"); 45 | gtk_box_pack_start(GTK_BOX(vbox), buttonPop, FALSE, TRUE, 0); 46 | g_signal_connect(buttonPop, "clicked", G_CALLBACK(pop_button_clicked), GINT_TO_POINTER (context_id)); 47 | 48 | gtk_widget_show_all(window); 49 | 50 | gtk_main(); 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /_examples/switch.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | GtkWidget *switch1; 4 | 5 | static void destroy(GtkWidget *widget, gpointer data) 6 | { 7 | gtk_main_quit(); 8 | } 9 | 10 | static void switch_toggled(GtkWidget *widget) 11 | { 12 | if (gtk_switch_get_active(GTK_SWITCH(switch1))) 13 | printf("Switch toggled on\n"); 14 | else 15 | printf("Switch toggled off\n"); 16 | } 17 | 18 | int main(int argc, char *argv[]) 19 | { 20 | gtk_init(&argc, &argv); 21 | 22 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 23 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 24 | 25 | switch1 = gtk_switch_new(); 26 | g_signal_connect(switch1, "notify::active", G_CALLBACK(switch_toggled), NULL); 27 | gtk_container_add(GTK_CONTAINER(window), switch1); 28 | 29 | gtk_widget_show_all(window); 30 | 31 | gtk_main(); 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /_examples/textview.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | gtk_init(&argc, &argv); 11 | 12 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 13 | gtk_window_set_default_size(GTK_WINDOW(window), 200, 200); 14 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 15 | 16 | GtkTextBuffer *textbuffer = gtk_text_buffer_new(NULL); 17 | gtk_text_buffer_set_text(textbuffer, "TextView Example", -1); 18 | 19 | GtkWidget *textview = gtk_text_view_new_with_buffer(textbuffer); 20 | gtk_container_add(GTK_CONTAINER(window), textview); 21 | 22 | gtk_widget_show_all(window); 23 | 24 | gtk_main(); 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /_examples/toggleaction.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | gtk_init(&argc, &argv); 11 | 12 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 13 | gtk_window_set_default_size(GTK_WINDOW(window), 200, 200); 14 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 15 | 16 | GtkWidget *menubar = gtk_menu_bar_new(); 17 | gtk_container_add(GTK_CONTAINER(window), menubar); 18 | 19 | GtkActionGroup *actiongroup = gtk_action_group_new("ActionGroup"); 20 | 21 | GtkAction *action = gtk_action_new("actionFile", "_File", NULL, NULL); 22 | gtk_action_group_add_action(GTK_ACTION_GROUP(actiongroup), action); 23 | GtkWidget *menuitemFile = gtk_action_create_menu_item(GTK_ACTION(action)); 24 | gtk_menu_bar_append(GTK_MENU_BAR(menubar), menuitemFile); 25 | 26 | GtkWidget *menu = gtk_menu_new(); 27 | gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitemFile), menu); 28 | 29 | GtkToggleAction *toggleaction; 30 | 31 | toggleaction = gtk_toggle_action_new("actionNew", "_New", "Create a new document", GTK_STOCK_NEW); 32 | gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(toggleaction), TRUE); 33 | gtk_action_group_add_action(GTK_ACTION_GROUP(actiongroup), GTK_ACTION(toggleaction)); 34 | GtkWidget *menuitemNew = gtk_action_create_menu_item(GTK_ACTION(toggleaction)); 35 | gtk_menu_append(GTK_MENU(menu), menuitemNew); 36 | toggleaction = gtk_toggle_action_new("actionOpen", "_Open", "Open a file", GTK_STOCK_OPEN); 37 | gtk_action_group_add_action(GTK_ACTION_GROUP(actiongroup), GTK_ACTION(toggleaction)); 38 | GtkWidget *menuitemOpen = gtk_action_create_menu_item(GTK_ACTION(toggleaction)); 39 | gtk_menu_append(GTK_MENU(menu), menuitemOpen); 40 | toggleaction = gtk_toggle_action_new("actionSave", "_Save", "Save a file", GTK_STOCK_SAVE); 41 | gtk_action_group_add_action(GTK_ACTION_GROUP(actiongroup), GTK_ACTION(toggleaction)); 42 | GtkWidget *menuitemSave = gtk_action_create_menu_item(GTK_ACTION(toggleaction)); 43 | gtk_menu_append(GTK_MENU(menu), menuitemSave); 44 | 45 | gtk_widget_show_all(window); 46 | 47 | gtk_main(); 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /_examples/togglebutton.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | static void toggle_button_toggled(GtkWidget *checkbutton, gpointer data) 9 | { 10 | if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbutton))) 11 | { 12 | g_print("%s toggled on\n", gtk_button_get_label(GTK_BUTTON(checkbutton))); 13 | } 14 | else 15 | { 16 | g_print("%s toggled off\n", gtk_button_get_label(GTK_BUTTON(checkbutton))); 17 | } 18 | } 19 | 20 | int main(int argc, char *argv[]) 21 | { 22 | gtk_init(&argc, &argv); 23 | 24 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 25 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 26 | 27 | GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); 28 | gtk_container_add(GTK_CONTAINER(window), box); 29 | 30 | GtkWidget *togglebutton; 31 | 32 | togglebutton = gtk_toggle_button_new_with_label("Toggle Button 1"); 33 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(togglebutton), TRUE); 34 | g_signal_connect(togglebutton, "toggled", G_CALLBACK(toggle_button_toggled), NULL); 35 | gtk_box_pack_start(GTK_BOX(box), GTK_WIDGET(togglebutton), FALSE, FALSE, 0); 36 | 37 | togglebutton = gtk_toggle_button_new_with_label("Toggle Button 2"); 38 | g_signal_connect(togglebutton, "toggled", G_CALLBACK(toggle_button_toggled), NULL); 39 | gtk_box_pack_start(GTK_BOX(box), GTK_WIDGET(togglebutton), FALSE, FALSE, 0); 40 | 41 | togglebutton = gtk_toggle_button_new_with_label("Toggle Button 3"); 42 | g_signal_connect(togglebutton, "toggled", G_CALLBACK(toggle_button_toggled), NULL); 43 | gtk_box_pack_start(GTK_BOX(box), GTK_WIDGET(togglebutton), FALSE, FALSE, 0); 44 | 45 | gtk_widget_show_all(window); 46 | 47 | gtk_main(); 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /_examples/toolbar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | gtk_init(&argc, &argv); 11 | 12 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 13 | gtk_window_set_default_size(GTK_WINDOW(window), 400, -1); 14 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 15 | 16 | GtkWidget *toolbar = gtk_toolbar_new(); 17 | gtk_container_add(GTK_CONTAINER(window), toolbar); 18 | 19 | GtkToolItem *toolitem; 20 | GtkToolItem *separator; 21 | GSList *group; 22 | 23 | toolitem = gtk_tool_button_new_from_stock(GTK_STOCK_NEW); 24 | gtk_toolbar_insert(GTK_TOOLBAR(toolbar), toolitem, 0); 25 | toolitem = gtk_tool_button_new_from_stock(GTK_STOCK_OPEN); 26 | gtk_toolbar_insert(GTK_TOOLBAR(toolbar), toolitem, 1); 27 | separator = gtk_separator_tool_item_new(); 28 | gtk_toolbar_insert(GTK_TOOLBAR(toolbar), separator, 2); 29 | toolitem = gtk_toggle_tool_button_new_from_stock(GTK_STOCK_MEDIA_PLAY); 30 | gtk_toolbar_insert(GTK_TOOLBAR(toolbar), toolitem, 3); 31 | separator = gtk_separator_tool_item_new(); 32 | gtk_toolbar_insert(GTK_TOOLBAR(toolbar), separator, 4); 33 | toolitem = gtk_menu_tool_button_new_from_stock(GTK_STOCK_GO_BACK); 34 | gtk_toolbar_insert(GTK_TOOLBAR(toolbar), toolitem, 5); 35 | toolitem = gtk_menu_tool_button_new_from_stock(GTK_STOCK_GO_FORWARD); 36 | gtk_toolbar_insert(GTK_TOOLBAR(toolbar), toolitem, 6); 37 | separator = gtk_separator_tool_item_new(); 38 | gtk_toolbar_insert(GTK_TOOLBAR(toolbar), separator, 7); 39 | toolitem = gtk_radio_tool_button_new_from_stock(NULL, GTK_STOCK_ADD); 40 | group = gtk_radio_tool_button_get_group(GTK_RADIO_TOOL_BUTTON(toolitem)); 41 | gtk_toolbar_insert(GTK_TOOLBAR(toolbar), toolitem, 8); 42 | toolitem = gtk_radio_tool_button_new_from_stock(group, GTK_STOCK_REMOVE); 43 | gtk_toolbar_insert(GTK_TOOLBAR(toolbar), toolitem, 9); 44 | 45 | gtk_widget_show_all(window); 46 | 47 | gtk_main(); 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /_examples/toolpalette.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | gtk_init(&argc, &argv); 11 | 12 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 13 | gtk_window_set_default_size(GTK_WINDOW(window), 200, 200); 14 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 15 | 16 | GtkWidget *toolpalette = gtk_tool_palette_new(); 17 | gtk_container_add(GTK_CONTAINER(window), toolpalette); 18 | 19 | GtkWidget *toolitemgroup; 20 | GtkToolItem *toolitem; 21 | 22 | toolitemgroup = gtk_tool_item_group_new("Group 1"); 23 | gtk_container_add(GTK_CONTAINER(toolpalette), toolitemgroup); 24 | 25 | toolitem = gtk_tool_button_new_from_stock(GTK_STOCK_HOME); 26 | gtk_tool_item_group_insert(GTK_TOOL_ITEM_GROUP(toolitemgroup), toolitem, -1); 27 | toolitem = gtk_tool_button_new_from_stock(GTK_STOCK_ABOUT); 28 | gtk_tool_item_group_insert(GTK_TOOL_ITEM_GROUP(toolitemgroup), toolitem, -1); 29 | toolitem = gtk_tool_button_new_from_stock(GTK_STOCK_HELP); 30 | gtk_tool_item_group_insert(GTK_TOOL_ITEM_GROUP(toolitemgroup), toolitem, -1); 31 | 32 | toolitemgroup = gtk_tool_item_group_new("Group 2"); 33 | gtk_container_add(GTK_CONTAINER(toolpalette), toolitemgroup); 34 | 35 | toolitem = gtk_tool_button_new_from_stock(GTK_STOCK_ADD); 36 | gtk_tool_item_group_insert(GTK_TOOL_ITEM_GROUP(toolitemgroup), toolitem, -1); 37 | toolitem = gtk_tool_button_new_from_stock(GTK_STOCK_EDIT); 38 | gtk_tool_item_group_insert(GTK_TOOL_ITEM_GROUP(toolitemgroup), toolitem, -1); 39 | toolitem = gtk_tool_button_new_from_stock(GTK_STOCK_DELETE); 40 | gtk_tool_item_group_insert(GTK_TOOL_ITEM_GROUP(toolitemgroup), toolitem, -1); 41 | 42 | gtk_widget_show_all(window); 43 | 44 | gtk_main(); 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /_examples/tooltipadvanced.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | static gboolean on_query_tooltip(GtkWidget *widget, 9 | gint x, gint y, 10 | gboolean keyboard_tip, 11 | GtkTooltip *tooltip, 12 | gpointer data) 13 | { 14 | gtk_tooltip_set_text(GTK_TOOLTIP(tooltip), data); 15 | 16 | return TRUE; 17 | } 18 | 19 | int main(int argc, char *argv[]) 20 | { 21 | gtk_init(&argc, &argv); 22 | 23 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 24 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 25 | 26 | GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); 27 | gtk_container_add(GTK_CONTAINER(window), vbox); 28 | 29 | GtkWidget *button = gtk_button_new_with_label("Button"); 30 | gtk_widget_set_has_tooltip(GTK_WIDGET(button), TRUE); 31 | g_signal_connect(button, "query-tooltip", G_CALLBACK(on_query_tooltip), "Button with advanced Tooltip"); 32 | gtk_box_pack_start(GTK_BOX(vbox), button, TRUE, TRUE, 0); 33 | 34 | GtkWidget *label = gtk_label_new("Label"); 35 | gtk_widget_set_has_tooltip(GTK_WIDGET(label), TRUE); 36 | g_signal_connect(label, "query-tooltip", G_CALLBACK(on_query_tooltip), "Label with advanced Tooltip"); 37 | gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 0); 38 | 39 | GtkWidget *entry = gtk_entry_new(); 40 | gtk_widget_set_has_tooltip(GTK_WIDGET(entry), TRUE); 41 | g_signal_connect(entry, "query-tooltip", G_CALLBACK(on_query_tooltip), "Entry with advanced Tooltip"); 42 | gtk_box_pack_start(GTK_BOX(vbox), entry, TRUE, TRUE, 0); 43 | 44 | gtk_widget_show_all(window); 45 | 46 | gtk_main(); 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /_examples/tooltipbasic.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | gtk_init(&argc, &argv); 11 | 12 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 13 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 14 | 15 | GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); 16 | gtk_container_add(GTK_CONTAINER(window), vbox); 17 | 18 | GtkWidget *button = gtk_button_new_with_label("Button"); 19 | gtk_widget_set_tooltip_text(GTK_WIDGET(button), "Button with basic Tooltip"); 20 | gtk_box_pack_start(GTK_BOX(vbox), button, TRUE, TRUE, 0); 21 | GtkWidget *label = gtk_label_new("Label"); 22 | gtk_widget_set_tooltip_text(GTK_WIDGET(label), "Label with basic Tooltip"); 23 | gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 0); 24 | GtkWidget *entry = gtk_entry_new(); 25 | gtk_widget_set_tooltip_text(GTK_WIDGET(entry), "Entry with basic Tooltip"); 26 | gtk_box_pack_start(GTK_BOX(vbox), entry, TRUE, TRUE, 0); 27 | 28 | gtk_widget_show_all(window); 29 | 30 | gtk_main(); 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /_examples/treestore.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | gtk_init(&argc, &argv); 11 | 12 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 13 | gtk_window_set_default_size(GTK_WINDOW(window), 300, 200); 14 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 15 | 16 | GtkTreeStore *treestore = gtk_tree_store_new(1, G_TYPE_STRING); 17 | GtkTreeIter treeiter; 18 | 19 | gtk_tree_store_append(treestore, &treeiter, NULL); 20 | gtk_tree_store_set(treestore, &treeiter, 0, "Mageia", -1); 21 | gtk_tree_store_append(treestore, &treeiter, &treeiter); 22 | gtk_tree_store_set(treestore, &treeiter, 0, "http://www.mageia.org/", -1); 23 | gtk_tree_store_append(treestore, &treeiter, NULL); 24 | gtk_tree_store_set(treestore, &treeiter, 0, "Slackware", -1); 25 | gtk_tree_store_append(treestore, &treeiter, &treeiter); 26 | gtk_tree_store_set(treestore, &treeiter, 0, "http://www.slackware.com/", -1); 27 | gtk_tree_store_append(treestore, &treeiter, NULL); 28 | gtk_tree_store_set(treestore, &treeiter, 0, "Chakra", -1); 29 | gtk_tree_store_append(treestore, &treeiter, &treeiter); 30 | gtk_tree_store_set(treestore, &treeiter, 0, "http://chakraos.org/", -1); 31 | 32 | GtkWidget *treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(treestore)); 33 | gtk_container_add(GTK_CONTAINER(window), treeview); 34 | 35 | GtkCellRenderer *cellrenderertext = gtk_cell_renderer_text_new(); 36 | 37 | GtkTreeViewColumn *treeviewcolumn = gtk_tree_view_column_new_with_attributes("Distributions", 38 | cellrenderertext, 39 | "text", 0, 40 | NULL); 41 | gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), treeviewcolumn); 42 | 43 | gtk_widget_show_all(window); 44 | 45 | gtk_main(); 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /_examples/volumebutton.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | GtkWidget *volumebutton; 4 | 5 | static void destroy(GtkWidget *widget, gpointer data) 6 | { 7 | gtk_main_quit(); 8 | } 9 | 10 | static void value_changed(GtkWidget *scalebutton, gpointer data) 11 | { 12 | int value = gtk_scale_button_get_value(GTK_SCALE_BUTTON(volumebutton)); 13 | g_print("%i\n", value); 14 | } 15 | 16 | int main(int argc, char *argv[]) 17 | { 18 | gtk_init(&argc, &argv); 19 | 20 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 21 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 22 | 23 | volumebutton = gtk_volume_button_new(); 24 | g_signal_connect(volumebutton, "value-changed", G_CALLBACK(value_changed), NULL); 25 | gtk_container_add(GTK_CONTAINER(window), volumebutton); 26 | 27 | gtk_widget_show_all(window); 28 | 29 | gtk_main(); 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /_examples/window.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void destroy(GtkWidget *widget, gpointer data) 4 | { 5 | gtk_main_quit(); 6 | } 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | gtk_init(&argc, &argv); 11 | 12 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 13 | gtk_window_set_title(GTK_WINDOW(window), "Window"); 14 | g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); 15 | 16 | gtk_widget_show_all(window); 17 | 18 | gtk_main(); 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /_resources/gtk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RainMark/gtk3-tutorial/a2c0cc82e4e9a090b1617ab43f8256146c7150c2/_resources/gtk.png -------------------------------------------------------------------------------- /aboutdialog.rst: -------------------------------------------------------------------------------- 1 | AboutDialog 2 | =========== 3 | An AboutDialog is used to display information about the application to the end user. Typically, this includes a name, a short description, version number, website, possibly names and contact details of the developers. 4 | 5 | =========== 6 | Constructor 7 | =========== 8 | The construction call for the AboutDialog is:: 9 | 10 | GtkWidget *aboutdialog = gtk_about_dialog_new(); 11 | 12 | ======= 13 | Methods 14 | ======= 15 | The program name can be set via:: 16 | 17 | gtk_about_dialog_set_program_name(GTK_ABOUT_DIALOG(aboutdialog), name); 18 | 19 | Most of the methods are fairly self-explanatory:: 20 | 21 | gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(aboutdialog), version); 22 | gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(aboutdialog), copyright); 23 | gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(aboutdialog), comments); 24 | gtk_about_dialog_set_license(GTK_ABOUT_DIALOG(aboutdialog), license); 25 | gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(aboutdialog), license); 26 | gtk_about_dialog_set_website_label(GTK_ABOUT_DIALOG(aboutdialog), license); 27 | 28 | To configure whether the license text is automatically wrapped, use:: 29 | 30 | gtk_about_dialog_set_wrap_license(GTK_ABOUT_DIALOG(aboutdialog), wrap_license); 31 | 32 | The license type can be defined using constants within GTK+:: 33 | 34 | gtk_about_dialog_set_license_type(GTK_ABOUT_DIALOG(aboutdialog), license_type); 35 | 36 | If the ``set_license_type()`` method is used, it overrides the ``set_license`` method. The *license_type* parameter can be set to one of the following: 37 | 38 | * ``GTK_LICENSE_GPL_2_0`` 39 | * ``GTK_LICENSE_GPL_3_0`` 40 | * ``GTK_LICENSE_LGPL_2_1`` 41 | * ``GTK_LICENSE_LGPL_3_0`` 42 | * ``GTK_LICENSE_BSD`` 43 | * ``GTK_LICENSE_MIT_X11`` 44 | * ``GTK_LICENSE_ARTISTIC`` 45 | * ``GTK_LICENSE_GPL_2_0_ONLY`` 46 | * ``GTK_LICENSE_GPL_3_0_ONLY`` 47 | * ``GTK_LICENSE_LGPL_2_1_ONLY`` 48 | * ``GTK_LICENSE_LGPL_3_0_ONLY`` 49 | 50 | A list of authors (developers), artists, documenters, and translators can be defined for display with the methods:: 51 | 52 | gtk_about_dialog_set_authors(GTK_ABOUT_DIALOG(aboutdialog), authors); 53 | gtk_about_dialog_set_artists(GTK_ABOUT_DIALOG(aboutdialog), artists); 54 | gtk_about_dialog_set_documenters(GTK_ABOUT_DIALOG(aboutdialog), documenters); 55 | gtk_about_dialog_set_translators(GTK_ABOUT_DIALOG(aboutdialog), translators); 56 | 57 | The logo for the program can also be displayed on the AboutDialog with:: 58 | 59 | gtk_about_dialog_set_logo(GTK_ABOUT_DIALOG(aboutdialog), logo); 60 | 61 | The *logo* parameter passed should be a GdkPixbuf object. 62 | 63 | ======= 64 | Example 65 | ======= 66 | Below is an example of an AboutDialog: 67 | 68 | .. literalinclude:: _examples/aboutdialog.c 69 | 70 | Download: :download:`AboutDialog <_examples/aboutdialog.c>` 71 | -------------------------------------------------------------------------------- /actionbar.rst: -------------------------------------------------------------------------------- 1 | ActionBar 2 | ========= 3 | The ActionBar container provides a location on which to add contextual actions. It is commonly placed at the bottom of a window and is expanded to the full width. 4 | 5 | =========== 6 | Constructor 7 | =========== 8 | Construction of the ActionBar is made using the call:: 9 | 10 | GtkWidget *actionbar = gtk_action_bar_new(); 11 | 12 | ======= 13 | Methods 14 | ======= 15 | Items can either be added at the start (left-side) or end (right-side) of the ActionBar via:: 16 | 17 | gtk_action_bar_pack_start(GTK_ACTION_BAR(actionbar), child); 18 | gtk_action_bar_pack_end(GTK_ACTION_BAR(actionbar), child); 19 | 20 | To place items centrally within the ActionBar call:: 21 | 22 | gtk_action_bar_set_center_widget(GTK_ACTION_BAR(actionbar), child); 23 | 24 | ======= 25 | Example 26 | ======= 27 | Below is an example of an ActionBar: 28 | 29 | .. literalinclude:: _examples/actionbar.c 30 | 31 | Download: :download:`ActionBar <_examples/actionbar.c>` 32 | -------------------------------------------------------------------------------- /aspectframe.rst: -------------------------------------------------------------------------------- 1 | AspectFrame 2 | =========== 3 | An AspectFrame is similar to the :doc:`frame` container widget, however it adds the ability to maintain a specific ratio for the child widget. 4 | 5 | =========== 6 | Constructor 7 | =========== 8 | The AspectFrame is constructed using the call:: 9 | 10 | GtkWidget *aspectframe = gtk_aspect_frame_new(label, xalign, yalign, ratio, obey_child); 11 | 12 | The *label* parameter sets the string which will be displayed on the AspectFrame. The *xalign* and *yalign* sets both the horizontal and vertical alignment of the child, with permissable values ranging from ``0.0`` to ``1.0``. The *ratio* determines the aspect ratio to use. Alternatively, if *obey_child* is set to ``TRUE``, the ratio value is ignored and the aspect ratio is instead taken from the child. 13 | 14 | ======= 15 | Methods 16 | ======= 17 | The AspectFrame values can be set after construction using:: 18 | 19 | gtk_aspect_frame_set(GTK_ASPECT_FRAME(aspectframe), label, xalign, yalign, ratio, obey_child); 20 | 21 | ======= 22 | Example 23 | ======= 24 | Below is an example of an AspectFrame: 25 | 26 | .. literalinclude:: _examples/aspectframe.c 27 | 28 | Download: :download:`AspectFrame <_examples/aspectframe.c>` 29 | -------------------------------------------------------------------------------- /assistant.rst: -------------------------------------------------------------------------------- 1 | Assistant 2 | ========= 3 | The Assistant (also referred to as a Wizard in some cases) provides step-by-step iteration through screens displayed to the user. These may be to simply display information, but are more commonly used to retrieve input in a specific order. A common use case includes the initial setup of an email client. 4 | 5 | =========== 6 | Constructor 7 | =========== 8 | The Assistant is constructed via:: 9 | 10 | GtkWidget *assistant = gtk_assistant_new(); 11 | 12 | ======= 13 | Methods 14 | ======= 15 | Pages are inserted into the Assistant by the following:: 16 | 17 | gtk_assistant_append_page(GTK_ASSISTANT(assistant), page); 18 | gtk_assistant_prepend_page(GTK_ASSISTANT(assistant), page); 19 | gtk_assistant_insert_page(GTK_ASSISTANT(assistant), page, position); 20 | 21 | All the methods take a page object, which is typically a container such as a :doc:`grid` or `box` from which additional widgets are added. The ``insert_page()`` method allows pages to be added at a specific point by referencing the position starting at ``0``. 22 | 23 | A page can also be removed by defining the page number to remove:: 24 | 25 | gtk_assistant_remove_page(GTK_ASSISTANT(assistant), position); 26 | 27 | The visible page can be set via:: 28 | 29 | gtk_assistant_set_current_page(GTK_ASSISTANT(assistant), position); 30 | 31 | Alternatively, the currently visible page can be retrieved using:: 32 | 33 | gtk_assistant_get_current_page(GTK_ASSISTANT(assistant)); 34 | 35 | The page widget located at a particular position can be retrieved by calling:: 36 | 37 | gtk_assistant_get_nth_page(GTK_ASSISTANT(assistant), position); 38 | 39 | To retrieve the total number of pages contained within the Assistant use:: 40 | 41 | gtk_assistant_get_n_pages(GTK_ASSISTANT(assistant)); 42 | 43 | Each page within the Assistant can be of a particular type. The type is typically set based on the content of the screen. This is done by the method:: 44 | 45 | gtk_assistant_set_page_type(GTK_ASSISTANT(assistant), page, page_type); 46 | 47 | The *page* parameter should be set to the page object being typed. The *page_type* must be set to one of the following constants: 48 | 49 | * ``GTK_ASSISTANT_PAGE_CONTENT`` - the page has regular content and both Back and Forward buttons will be displayed. 50 | * ``GTK_ASSISTANT_PAGE_INTRO`` - only a Forward button is shown on the page which typically introduces the Assistant purpose. 51 | * ``GTK_ASSISTANT_PAGE_CONFIRM`` - display to allow the user to confirm the changes. A Back and Apply button will be shown. 52 | * ``GTK_ASSISTANT_PAGE_SUMMARY`` - inform user of changes made, and display only a Close button. 53 | * ``GTK_ASSISTANT_PAGE_PROGRESS`` - used for tasks which take a long time to complete, with a Back button displayed. 54 | * ``GTK_ASSISTANT_PAGE_CUSTOM`` - used when none of the other page types are appropriate. The buttons should be added manually. 55 | 56 | A title can be associated with each page via:: 57 | 58 | gtk_assistant_set_page_title(GTK_ASSISTANT(assistant), title); 59 | 60 | In some cases, the Assistant should prevent the user from continuing unless the page has been completed. This can be set programmatically via the use of:: 61 | 62 | gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant), page, complete); 63 | 64 | The *page* parameter should be set to the page widget. The *complete* argument will initially be set to ``FALSE``, and the page buttons will be insensitive. Once complete, the state can be set to ``TRUE`` and the buttons will be updated to allow the user to continue. 65 | 66 | The action area is the location on the Assistant where the buttons are located. Additional widgets can be added and removed from this area via the methods:: 67 | 68 | gtk_assistant_add_action_widget(GTK_ASSISTANT(assistant), widget); 69 | gtk_assistant_remove_action_widget(GTK_ASSISTANT(assistant), widget); 70 | 71 | Additional methods are also available to control the Assistant:: 72 | 73 | gtk_assistant_next_page(GTK_ASSISTANT(assistant)); 74 | gtk_assistant_previous_page(GTK_ASSISTANT(assistant)); 75 | gtk_assistant_commit(GTK_ASSISTANT(assistant)); 76 | 77 | The ``previous_page()`` and ``next_page()`` methods allow the Assistant to programmatically move backwards or forwards. The ``commit()`` method allows changes made up to the current page to be made permanent. This has the effect of clearing page visited history, and removing the Cancel button from subsequent pages. 78 | 79 | ======= 80 | Example 81 | ======= 82 | Below is an example of an Assistant: 83 | 84 | .. literalinclude:: _examples/assistant.c 85 | 86 | Download: :download:`Assistant <_examples/assistant.c>` 87 | -------------------------------------------------------------------------------- /box.rst: -------------------------------------------------------------------------------- 1 | Box 2 | === 3 | A Box widget is a container used to layout child widgets in either a horizontal or vertical direction. 4 | 5 | =========== 6 | Constructor 7 | =========== 8 | The Box widget can be constructed with:: 9 | 10 | GtkBox *box = gtk_box_new(orientation, spacing); 11 | 12 | A *spacing* value indicates the number of pixels in space which will be added between each child widget. The *orientation* parameter determines which way to the child widgets will be laid out. 13 | 14 | * ``GTK_ORIENTATION_HORIZONTAL`` 15 | * ``GTK_ORIENTATION_VERTICAL`` 16 | 17 | ======= 18 | Methods 19 | ======= 20 | Child widgets can be added to the top or left (depending on orientation), and bottom or right of the Box with the methods:: 21 | 22 | gtk_box_pack_start(GTK_BOX(box), child, expand, fill, padding); 23 | gtk_box_pack_end(GTK_BOX(box), child, expand, fill, padding); 24 | 25 | The *child* widget specifies the child to be added into the Box. The *expand* property when set to ``TRUE`` allows the child to be given extra space allocated to the Box, with the extra space being allocated to all widgets with this property set to ``TRUE``. The *fill* property applies when the *expand* property is set to ``TRUE`` only, and allows the widget to fill the entire area. Finally, the *padding* value should be the number of pixels to add for spacing beyond the spacing value specified. 26 | 27 | The child widgets held in the Box can be forced to the same size via:: 28 | 29 | gtk_box_set_homogeneous(GTK_BOX(box), homogeneous); 30 | 31 | Spacing between the child widgets can be defined after construction with:: 32 | 33 | gtk_box_set_spacing(GTK_BOX(box), spacing); 34 | 35 | A child widget can also be moved if necessary with the call:: 36 | 37 | gtk_box_reorder_child(GTK_BOX(box), child, position); 38 | 39 | The *child* parameter is the pointer to the widget to be moved. The *position* value should be set to a number indicating the new position, with ``0`` identifying the top-most or left-most position in the Box. 40 | 41 | A central widget can be defined for the Box with:: 42 | 43 | gtk_box_set_center_widget(GTK_BOX(box), widget); 44 | 45 | ======= 46 | Example 47 | ======= 48 | Below is an example of a Box: 49 | 50 | .. literalinclude:: _examples/box.c 51 | 52 | Download: :download:`Box <_examples/box.c>` 53 | -------------------------------------------------------------------------------- /button.rst: -------------------------------------------------------------------------------- 1 | Button 2 | ====== 3 | The Button widget provides a way for a user to click to begin an operation. Examples of their use include deleting a file or spell checking a file. 4 | 5 | =========== 6 | Constructor 7 | =========== 8 | A Button is constructed with the call:: 9 | 10 | GtkWidget *button = gtk_button_new(); 11 | 12 | Alternatively, if label text is to be set on the Button at construction:: 13 | 14 | GtkWidget *button = gtk_button_new_with_label(text); 15 | 16 | ======= 17 | Methods 18 | ======= 19 | The label text to be displayed on the Button can be set post-construction with:: 20 | 21 | gtk_button_set_label(GTK_BUTTON(button), text); 22 | 23 | Text set on the Button can also be retrieved:: 24 | 25 | gtk_button_get_label(GTK_BUTTON(button)); 26 | 27 | Mnemonic accelerator keys are accessibility features allowing a combination of :kbd:`ALT` and a chosen letter to be used as a shortcut. These shortcuts are identified by an underscore beneath a letter. This feature is enabled or disabled with:: 28 | 29 | gtk_button_set_use_underline(GTK_BUTTON(button), use_underline); 30 | 31 | When *use_underline* is set to ``TRUE``, the underscore in the Label is positioned under the letter it is before. 32 | 33 | By default, Button widgets have a border and appear raised up. This can be adjusted with:: 34 | 35 | gtk_button_set_relief(GTK_BUTTON(button), relief); 36 | 37 | The *relief* parameter should be set to one of the following: 38 | 39 | * ``GTK_RELIEF_NORMAL`` 40 | * ``GTK_RELIEF_NONE`` 41 | 42 | An image can be displayed on the Button via:: 43 | 44 | gtk_button_set_image(GTK_BUTTON(button), image); 45 | 46 | The *image* value should be set to the :doc:`image` to be displayed. 47 | 48 | The position of any image added to the Button is set by:: 49 | 50 | gtk_button_set_image_position(GTK_BUTTON(button), position); 51 | 52 | Set the *position* value to one of the following: 53 | 54 | * ``GTK_POS_LEFT`` 55 | * ``GTK_POS_RIGHT`` 56 | * ``GTK_POS_TOP`` 57 | * ``GTK_POS_BOTTOM`` 58 | 59 | Typically, when a Button is clicked, the Button gains the input focus. In some cases, this may not be desirable and can be configured with:: 60 | 61 | gtk_button_set_focus_on_click(GTK_BUTTON(button), focus_on_click) 62 | 63 | When *focus_on_click* is set to ``FALSE``, the input will remain with the main content rather than on the Button. 64 | 65 | ======= 66 | Example 67 | ======= 68 | Below is an example of a Button: 69 | 70 | .. literalinclude:: _examples/button.c 71 | 72 | Download: :download:`Button <_examples/button.c>` 73 | -------------------------------------------------------------------------------- /buttonbox.rst: -------------------------------------------------------------------------------- 1 | ButtonBox 2 | ========= 3 | A ButtonBox is a container used typically to group :doc:`button` widgets horizontally or vertically, while aiming to give each button an appropriate size. 4 | 5 | =========== 6 | Constructor 7 | =========== 8 | The ButtonBox is constructed using the call:: 9 | 10 | GtkWidget *buttonbox = gtk_button_box_new(orientation); 11 | 12 | The *orientation* should be set to one of the following: 13 | 14 | * ``GTK_ORIENTATION_HORIZONTAL`` 15 | * ``GTK_ORIENTATION_VERTICAL`` 16 | 17 | ======= 18 | Methods 19 | ======= 20 | Child widgets are added to the ButtonBox by calling:: 21 | 22 | gtk_container_add(GTK_CONTAINER(buttonbox), child); 23 | 24 | The ButtonBox layout defaults to centering all of the child widgets in the middle of the container. This can be adjusted by:: 25 | 26 | gtk_button_box_set_layout_style(GTK_BUTTON_BOX(buttonbox), style); 27 | 28 | The *style* parameter should be set to one of the following constants: 29 | 30 | * ``GTK_BUTTONBOX_SPREAD`` - evenly space the child widgets across the container. 31 | * ``GTK_BUTTONBOX_EDGE`` - place widgets at container edges. 32 | * ``GTK_BUTTONBOX_START`` - position buttons at left or top of container. 33 | * ``GTK_BUTTONBOX_END`` - position buttons at right or bottom of container. 34 | * ``GTK_BUTTONBOX_CENTER`` - center the buttons within the container. 35 | * ``GTK_BUTTONBOX_EXPAND`` - expand child buttons to fill all the space available. 36 | 37 | The layout chosen can also be retrieved via:: 38 | 39 | gtk_button_box_get_layout(GTK_BUTTON_BOX(buttonbox)); 40 | 41 | The child widgets by default have no space between themselves. This can be configured after construction with:: 42 | 43 | gtk_box_set_spacing(GTK_BOX(buttonbox), spacing); 44 | 45 | The *spacing* value should be the number of pixels of space to insert between each child. 46 | 47 | In some cases, it may be useful to add a secondary child widget. This can be defined with:: 48 | 49 | gtk_button_box_set_child_secondary(GTK_BUTTON_BOX(buttonbox), child, is_secondary); 50 | 51 | The *child* parameter should be set to the name of the widget which is to be made secondary. The *is_secondary* argument when set to ``TRUE`` enables the secondary functionality. When enabled, the secondary child will appear visibly separate from the other widgets. 52 | 53 | The ButtonBox attempts to make all child widgets to the same size. To configure this for a particular widget call:: 54 | 55 | gtk_button_box_set_child_non_homogeneous(GTK_BUTTON_BOX(buttonbox), child, non_homogeneous); 56 | 57 | The *child* argument should be set to the name of the widget. The *non-homogeneous* parameter when set to ``TRUE`` excludes the child from homogeneous sizing. 58 | 59 | ======= 60 | Example 61 | ======= 62 | Below is an example of a ButtonBox: 63 | 64 | .. literalinclude:: _examples/buttonbox.c 65 | 66 | Download: :download:`ButtonBox <_examples/buttonbox.c>` 67 | -------------------------------------------------------------------------------- /calendar.rst: -------------------------------------------------------------------------------- 1 | Calendar 2 | ======== 3 | The Calendar widget allows for dates to be displayed and selected. It is customisable so that months and years can be viewed, and dates can be marked. 4 | 5 | =========== 6 | Constructor 7 | =========== 8 | The constructor for the Calendar widget is:: 9 | 10 | GtkWidget *calendar = gtk_calendar_new(); 11 | 12 | ======= 13 | Methods 14 | ======= 15 | There are two functions used for setting the date, month, and year:: 16 | 17 | gtk_calendar_select_day(GTK_CALENDAR(calendar), day); 18 | gtk_calendar_select_month(GTK_CALENDAR(calendar), month, year); 19 | 20 | The *day* value should be set to the date of the month. The *month* value is settable to a month number identifying the month, with ``0`` used for January and ``11`` for December. The *year* is set to the appropriate year. 21 | 22 | The date is also retrievable using:: 23 | 24 | gtk_calendar_get_date(GTK_CALENDAR(calendar)); 25 | 26 | The method returns the three values for the year, month, and day. 27 | 28 | Marking of days is useful when an event is associated with a particular day. This places a marker next to the date and is set and unset with:: 29 | 30 | gtk_calendar_mark_day(GTK_CALENDAR(calendar), day); 31 | gtk_calendar_unmark_day(GTK_CALENDAR(calendar), day); 32 | 33 | To retrieve whether a day is marked, call:: 34 | 35 | gtk_calendar_get_day_is_marked(GTK_CALENDAR(calendar), day); 36 | 37 | All the marks set on the Calendar can be cleared via the method:: 38 | 39 | gtk_calendar_clear_marks(GTK_CALENDAR(calendar)); 40 | 41 | The Calendar can be customised by setting a number of displays flags on the method:: 42 | 43 | gtk_calendar_set_display_options(GTK_CALENDAR(calendar), flags); 44 | 45 | The *flags* argument can be set to any of the following values: 46 | 47 | * ``GTK_CALENDAR_SHOW_HEADING`` 48 | * ``GTK_CALENDAR_SHOW_DAY_NAMES`` 49 | * ``GTK_CALENDAR_NO_MONTH_CHANGE`` 50 | * ``GTK_CALENDAR_SHOW_WEEK_NUMBERS`` 51 | * ``GTK_CALENDAR_SHOW_DETAILS`` 52 | 53 | The ``GTK_CALENDAR_SHOW_HEADING`` flag enables the heading which displays the month and year. ``GTK_CALENDAR_SHOW_DAY_NAMES`` sets the three letter day to be displayed. Preventing month and year changes from being made by adding the flag ``GTK_CALENDAR_NO_MONTH_CHANGE``. In some cases, it is useful to display the week numbers via ``GTK_CALENDAR_SHOW_WEEK_NUMBERS``. Each flag should be separated from another by a pipe '|' character. 54 | 55 | ======= 56 | Example 57 | ======= 58 | Below is an example of a Calendar: 59 | 60 | .. literalinclude:: _examples/calendar.c 61 | 62 | Download: :download:`Calendar <_examples/calendar.c>` 63 | -------------------------------------------------------------------------------- /checkbutton.rst: -------------------------------------------------------------------------------- 1 | CheckButton 2 | =========== 3 | A CheckButton is displayed in two parts, a state box and an associated label identifying the purpose of the CheckButton. The CheckButton is often used to identify on/off states such as preference settings. 4 | 5 | ======= 6 | Methods 7 | ======= 8 | The state can be set programatically via:: 9 | 10 | gtk_button_set_active(GTK_TOGGLE_BUTTON(checkbutton), state); 11 | 12 | The *state* argument accepts ``TRUE`` to tick the CheckButton, or ``FALSE`` for the unticked state. 13 | 14 | Retrieving the state of the CheckButton is done via the method:: 15 | 16 | gtk_button_get_active(GTK_TOGGLE_BUTTON(checkbutton)); 17 | 18 | In some cases, it may be useful to display an inconsistent state. This is typically used in conjunction with other CheckButton widgets, where varying states on the others will activate the inconsistent state. This is set with:: 19 | 20 | gtk_button_set_inconsistent(GTK_TOGGLE_BUTTON(checkbutton), inconsistent); 21 | 22 | To retrieve the inconsistent state call:: 23 | 24 | gtk_button_get_inconsistent(GTK_TOGGLE_BUTTON(checkbutton)); 25 | 26 | The label on the CheckButton is customisable post-construction with:: 27 | 28 | gtk_button_set_label(GTK_BUTTON(checkbutton), text); 29 | 30 | ======= 31 | Example 32 | ======= 33 | Below is an example of a CheckButton: 34 | 35 | .. literalinclude:: _examples/checkbutton.c 36 | 37 | Download: :download:`CheckButton <_examples/checkbutton.c>` 38 | -------------------------------------------------------------------------------- /colorbutton.rst: -------------------------------------------------------------------------------- 1 | ColorButton 2 | =========== 3 | The ColorButton allows for the selection of a colour. The Button-like widget displays the chosen colour, and when clicked, a :doc:`colorchooserdialog` is displayed allowing the selection of the colour. 4 | 5 | =========== 6 | Constructor 7 | =========== 8 | Construction of the ColorButton is made with:: 9 | 10 | GtkWidget *colorbutton = gtk_color_button_new(); 11 | 12 | ======= 13 | Methods 14 | ======= 15 | The title of the dialog launched when the ColorButton is clicked can be set via:: 16 | 17 | gtk_color_button_set_title(GTK_COLOR_BUTTON(colorbutton), title); 18 | 19 | ======= 20 | Example 21 | ======= 22 | Below is an example of a ColorButton: 23 | 24 | .. literalinclude:: _examples/colorbutton.c 25 | 26 | Download: :download:`ColorButton <_examples/colorbutton.c>` 27 | -------------------------------------------------------------------------------- /combobox.rst: -------------------------------------------------------------------------------- 1 | ComboBox 2 | ======== 3 | The ComboBox widget provides a dropdown menu for the user to select an item from a defined list. It can also be configured to allow the user to enter a value which is not in the list. 4 | 5 | For simple string listing uses, a :doc:`comboboxtext` widget is simpler to use and quicker to setup. 6 | 7 | =========== 8 | Constructor 9 | =========== 10 | A ComboBox in its most basic form can be constructed with:: 11 | 12 | GtkWidget *combobox = gtk_combo_box_new(); 13 | 14 | Alternatively, a ComboBox can be constructed with either an attached model or entry provided:: 15 | 16 | GtkWidget *combobox = gtk_combo_box_new_with_model(model); 17 | GtkWidget *combobox = gtk_combo_box_new_with_entry(); 18 | 19 | Both a model and entry can be added in a single construction statement via:: 20 | 21 | GtkWidget *combobox = gtk_combo_box_new_with_model_and_entry(model); 22 | 23 | The *model* parameter should be an appropriate :doc:`liststore` which will hold the items for display in the ComboBox. 24 | 25 | ======= 26 | Methods 27 | ======= 28 | A model can be attached to the ComboBox after construction with:: 29 | 30 | gtk_combo_box_set_model(GTK_COMBOBOX(combobox), model); 31 | 32 | The active item can be programatically set in a number of ways:: 33 | 34 | gtk_combo_box_set_active(GTK_COMBOBOX(combobox), index); 35 | gtk_combo_box_set_active_iter(GTK_COMBOBOX(combobox), treeiter); 36 | 37 | The ``set_active()`` method allows the *index* of the item in the model to be displayed, with the first item identified by ``0``. The ``set_active_iter()`` call allows the TreeIter of the item to be passed as *iter*. 38 | 39 | Alternatively, an ID can be passed for display:: 40 | 41 | gtk_combo_box_set_active_id(GTK_COMBOBOX(combobox), id); 42 | 43 | The *id* value should be set to a string which identifies the item to be shown to the user. 44 | 45 | An ID column must be defined to use the ``set_active_id()`` method. The column holding the ID must be a string type:: 46 | 47 | gtk_combo_box_set_id_column(GTK_COMBOBOX(combobox), column); 48 | 49 | By default, all items are placed in a single list. If the list becomes to long, this becomes unmanageable. To mitigate this, the items can be placed into multiple rows and columns with:: 50 | 51 | gtk_combo_box_set_row_span_column(GTK_COMBOBOX(combobox), row_span); 52 | gtk_combo_box_set_column_span_column(GTK_COMBOBOX(combobox), column_span); 53 | 54 | You can check whether the ComboBox has an Entry with:: 55 | 56 | gtk_combo_box_get_has_entry(GTK_COMBOBOX(combobox)); 57 | 58 | The ComboBox can be configured to accept focus or not when clicked via:: 59 | 60 | gtk_combo_box_set_focus_on_click(GTK_COMBOBOX(combobox), focus); 61 | 62 | ======= 63 | Example 64 | ======= 65 | Below is an example of a ComboBox: 66 | 67 | .. literalinclude:: _examples/combobox.c 68 | 69 | Download: :download:`ComboBoxBox <_examples/combobox.c>` 70 | -------------------------------------------------------------------------------- /comboboxtext.rst: -------------------------------------------------------------------------------- 1 | ComboBoxText 2 | ============ 3 | A ComboBoxText provides a quick and easy way to build a drop-down widget without the extra functionality provided by the :doc:`combobox`. The widget does look exactly the same however. 4 | 5 | =========== 6 | Constructor 7 | =========== 8 | A ComboBoxText is constructed with the call:: 9 | 10 | GtkWidget *combobox = gtk_combo_box_text_new(); 11 | 12 | It can also be constructed with a text entry providing a way for the user to enter items now already in the menu:: 13 | 14 | GtkWidget *combobox = gtk_combo_box_text_new_with_entry(); 15 | 16 | ======= 17 | Methods 18 | ======= 19 | Items can be added to the ComboBoxText via the methods:: 20 | 21 | gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combobox), item); 22 | gtk_combo_box_text_prepend_text(GTK_COMBO_BOX_TEXT(combobox), item); 23 | gtk_combo_box_text_insert_text(GTK_COMBO_BOX_TEXT(combobox), position, item); 24 | 25 | The ``append_text()`` and ``prepend_text()`` methods add items to the widget after or before the executed order. The ``insert_text()`` method allows a specific *position* to be defined where the item should be inserted. The *item* value should be the string of text to be added. 26 | 27 | Text can also be added to the ComboBoxText with an associated identifier:: 28 | 29 | gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(combobox), id, item); 30 | gtk_combo_box_text_prepend(GTK_COMBO_BOX_TEXT(combobox), id, item); 31 | gtk_combo_box_text_insert(GTK_COMBO_BOX_TEXT(combobox), position, id, item); 32 | 33 | The *item* and *position* items are the same as above. The extra *id* attribute should be a string of text identifying the text item. 34 | 35 | The selected text can be retrieved from the item via:: 36 | 37 | gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(combobox)); 38 | 39 | Items can be removed from the ComboBoxText with:: 40 | 41 | gtk_combo_box_text_remove(GTK_COMBO_BOX_TEXT(combobox), position); 42 | 43 | The *position* value is the location value of the item in the ComboBoxText, with the first item represented by ``0``. 44 | 45 | All the items can be cleared from the widget using:: 46 | 47 | gtk_combo_box_text_remove_all(GTK_COMBO_BOX_TEXT(combobox)); 48 | 49 | ======= 50 | Example 51 | ======= 52 | Below is an example of a ComboBoxText: 53 | 54 | .. literalinclude:: _examples/comboboxtext.c 55 | 56 | Download: :download:`ComboBoxText <_examples/comboboxtext.c>` 57 | -------------------------------------------------------------------------------- /dialog.rst: -------------------------------------------------------------------------------- 1 | Dialog 2 | ====== 3 | A Dialog is similar to a :doc:`window`, however it provides an integrated content area and action area for buttons to be added. Typically, they are used for sub-windows of an application such as a preferences interface or to request additional information from the user. 4 | 5 | =========== 6 | Constructor 7 | =========== 8 | A Dialog widget is constructed via:: 9 | 10 | GtkWidget *dialog = gtk_dialog_new(); 11 | 12 | .. note:: 13 | 14 | The Dialog widget expects to be the child of another main application Window, and will commonly have a transient parent set. If no parent window is set for the dialog, GTK+ will display a message stating that no parent dialogs are discouraged. 15 | 16 | ======= 17 | Methods 18 | ======= 19 | A title can be set for the Dialog by calling:: 20 | 21 | gtk_window_set_title(GTK_DIALOG(dialog), title); 22 | 23 | An individual button can be added to the Dialog using:: 24 | 25 | gtk_dialog_add_button(GTK_DIALOG(dialog), text, response); 26 | 27 | The *text* value will be set to the text content to be displayed on the button. The response is a GTK+ constant which indicates the response of the button when clicked. The available responses are: 28 | 29 | * ``GTK_RESPONSE_OK`` 30 | * ``GTK_RESPONSE_CANCEL`` 31 | * ``GTK_RESPONSE_APPLY`` 32 | * ``GTK_RESPONSE_CLOSE`` 33 | * ``GTK_RESPONSE_ACCEPT`` 34 | * ``GTK_RESPONSE_REJECT`` 35 | * ``GTK_RESPONSE_YES`` 36 | * ``GTK_RESPONSE_NO`` 37 | * ``GTK_RESPONSE_HELP`` 38 | * ``GTK_RESPONSE_DELETE_EVENT`` 39 | * ``GTK_RESPONSE_NONE 40 | 41 | Alternatively, a positive integer value can be specified in place of the constant. The integer can then be handled to run the appropriate code. 42 | 43 | Multiple buttons can be added in a single statement via:: 44 | 45 | gtk_dialog_add_buttons(GTK_DIALOG(dialog), text, response, text, response, ...); 46 | 47 | The default button which is highlighted when the dialog opens can be set with:: 48 | 49 | gtk_dialog_set_default_response(GTK_DIALOG(dialog), response); 50 | 51 | In some cases, buttons should be made insensitive. For example, you may want to prevent the user clicking OK without choosing an option. This can be done with:: 52 | 53 | gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), response, sensitive); 54 | 55 | The *response* should be set as when creating the button. The *sensitive* when set to ``FALSE`` will grey-out the button. 56 | 57 | A Dialog has two integrated areas which can be obtained:: 58 | 59 | gtk_dialog_get_content_area(GTK_DIALOG(dialog)); 60 | gtk_dialog_get_header_bar(GTK_DIALOG(dialog)); 61 | 62 | Additional widgets can be added to the action area with:: 63 | 64 | gtk_dialog_add_action_widget(GTK_DIALOG(dialog), child, response); 65 | 66 | The *child* value should be set to an appropriate widget to be added alongside the Dialog buttons. 67 | 68 | Running the dialog is done with the method:: 69 | 70 | gtk_dialog_run(GTK_DIALOG(dialog)); 71 | 72 | The Dialog can also be destroyed programmatically via:: 73 | 74 | gtk_widget_destroy(dialog); 75 | 76 | ======= 77 | Example 78 | ======= 79 | Below is an example of a Dialog: 80 | 81 | .. literalinclude:: _examples/dialog.c 82 | 83 | Download: :download:`Dialog <_examples/dialog.c>` 84 | -------------------------------------------------------------------------------- /entry.rst: -------------------------------------------------------------------------------- 1 | Entry 2 | ===== 3 | The Entry widget provides a way to input and display short amounts of text. It is commonly used for text input such as usernames, addresses, websites, etc. 4 | 5 | =========== 6 | Constructor 7 | =========== 8 | The Entry widget can be constructed with:: 9 | 10 | GtkWidget *entry = gtk_entry_new(); 11 | 12 | An Entry can also be constructed with an associated :doc:`entrybuffer` object:: 13 | 14 | GtkWidget *entry = gtk_entry_new_with_buffer(entrybuffer); 15 | 16 | ======= 17 | Methods 18 | ======= 19 | Text is retrieved from the Entry via the method:: 20 | 21 | gtk_entry_get_text(GTK_ENTRY(entry)); 22 | 23 | Programatically setting the text within the widget can also be done with:: 24 | 25 | gtk_entry_set_text(GTK_ENTRY(entry), text); 26 | 27 | In most cases, an :doc:`entrybuffer` is not required, however it can be set using:: 28 | 29 | gtk_entry_set_buffer(GTK_ENTRY(entry), entrybuffer); 30 | 31 | The Entry widget can also be used to enter passwords. It is good practice to mask the input and this can be done via:: 32 | 33 | gtk_entry_set_visibility(GTK_ENTRY(entry), visibility); 34 | 35 | When the *visibility* password is set to ``TRUE``, alternative characters are added in place of the characters. 36 | 37 | The character used to mask the password by default is an asterisk. This can be changed with:: 38 | 39 | gtk_entry_set_invisible_char(GTK_ENTRY(entry), character); 40 | 41 | When the user enters characters into the Entry, it may be desirable to provide a completion function via an :doc:`entrybuffer`. This suggests matching results for the characters entered:: 42 | 43 | gtk_entry_set_completion(GTK_ENTRY(entry), completion); 44 | 45 | The maximum number of characters which can be accepted by the Entry can be limited with:: 46 | 47 | gtk_entry_set_max_length(GTK_ENTRY(entry), maximum); 48 | 49 | If the contents of the Entry are set to longer than the *maximum* length allows, the text will be truncated. 50 | 51 | Placeholder text can be used to signify the purpose of the Entry with:: 52 | 53 | gtk_entry_set_placeholder_text(GTK_ENTRY(entry), text); 54 | 55 | When *text* is entered for display as the placeholder, it is only shown when the Entry is empty. 56 | 57 | By default, text typed in the Entry is inserted alongside any existing text. It can however be made to overwrite existing text with:: 58 | 59 | gtk_entry_set_overwrite_mode(GTK_ENTRY(entry), overwrite); 60 | 61 | An Entry supports placing icons to the left (primary) or right (secondary) of the text content:: 62 | 63 | gtk_entry_set_icon_from_icon_name(GTK_ENTRY(entry), position, icon_name); 64 | gtk_entry_set_icon_from_pixbuf(GTK_ENTRY(entry), position, pixbuf); 65 | gtk_entry_set_icon_from_gicon(GTK_ENTRY(entry), position, gicon); 66 | 67 | The *icon_name* parameter is based on the list of icons supported by GTK+. Alternatively, a *pixbuf* can be defined which would typically be used to load a custom image. Alternatively a GIcon object can be defined which can be created by defining a path to a custom icon. The *position* value should be set to either:: 68 | 69 | * ``GTK_ENTRY_ICON_PRIMARY`` 70 | * ``GTK_ENTRY_ICON_SECONDARY`` 71 | 72 | ======= 73 | Example 74 | ======= 75 | Below is an example of an Entry: 76 | 77 | .. literalinclude:: _examples/entry.c 78 | 79 | Download: :download:`Entry <_examples/entry.c>` 80 | -------------------------------------------------------------------------------- /entrybuffer.rst: -------------------------------------------------------------------------------- 1 | EntryBuffer 2 | =========== 3 | The EntryBuffer object attaches to an :doc:`entry` widget, and provides a store for text entered. It is commonly not explicitly required as an Entry stores its own text in an automatically constructed buffer. 4 | 5 | =========== 6 | Constructor 7 | =========== 8 | Construction of the EntryBuffer is made using:: 9 | 10 | GtkEntryBuffer *entrybuffer = gtk_entry_buffer_new(text, length); 11 | 12 | The *text* parameter allows setting of the text to be stored within the EntryBuffer immediately after construction. A *length* parameter is also required indicating how many characters are to be stored, however this can be set to ``-1`` if no limit is required. 13 | 14 | ======= 15 | Methods 16 | ======= 17 | The text held by the EntryBuffer can be set after construction using:: 18 | 19 | gtk_entry_buffer_set_text(GTK_ENTRY_BUFFER(entrybuffer), text, length); 20 | 21 | Retrieval of the text from the EntryBuffer is done via:: 22 | 23 | gtk_entry_buffer_get_text(GTK_ENTRY_BUFFER(entrybuffer)); 24 | 25 | To obtain the length of the text within the EntryBuffer call:: 26 | 27 | gtk_entry_buffer_get_length(GTK_ENTRY_BUFFER(entrybuffer)); 28 | 29 | Limiting the amount of text which is allowed to be stored in the EntryBuffer is done with the method:: 30 | 31 | gtk_entry_buffer_set_max_length(GTK_ENTRY_BUFFER(entrybuffer), length); 32 | 33 | Text can also be inserted into the EntryBuffer rather than overwriting the existing text:: 34 | 35 | gtk_entry_buffer_insert_text(GTK_ENTRY_BUFFER(entrybuffer), position, chars, length); 36 | 37 | The *position* value indicates the location within the existing buffer where the new text should be inserted. Using ``0`` indicates the start of the string. The *chars* argument specifies the text which will be added. Finally, the length parameter sets how long the string being added is, with ``-1`` defining an unspecified length. 38 | 39 | Text within the buffer can also be deleted with:: 40 | 41 | gtk_entry_buffer_delete_text(GTK_ENTRY_BUFFER(entrybuffer), position, length); 42 | 43 | The *position* value sets where the text should be deleted from with the *length parameter defining the number of characters from position to delete. 44 | 45 | ======= 46 | Example 47 | ======= 48 | Below is an example of an EntryBuffer: 49 | 50 | .. literalinclude:: _examples/entrybuffer.c 51 | 52 | Download: :download:`EntryBuffer <_examples/entrybuffer.c>` 53 | -------------------------------------------------------------------------------- /entrycompletion.rst: -------------------------------------------------------------------------------- 1 | EntryCompletion 2 | =============== 3 | An EntryCompletion provides suggestions on completing text entered into an :doc:`entry`. Completions are either done inline, by completing the letters entered, or displayed in a dropdown menu for selection. 4 | 5 | =========== 6 | Constructor 7 | =========== 8 | The EntryCompletion object is constructed via the call:: 9 | 10 | GtkWidget *entrycompletion = gtk_entry_completion_new(); 11 | 12 | ======= 13 | Methods 14 | ======= 15 | The EntryCompletion uses a model such as a :doc:`liststore` to store items for completion. This is defined with:: 16 | 17 | gtk_entry_completion_set_model(GTK_ENTRY_COMPLETION(entrycompletion), model); 18 | 19 | When the model has been set, the column number where the items for completion are stored must be set:: 20 | 21 | gtk_entry_completion_set_text_column(GTK_ENTRY_COMPLETION(entrycompletion), column); 22 | 23 | The *column* value should be set to an integer which starts with ``0`` to indicate the first column. 24 | 25 | To prevent the completion being called immediately, the minimum key length can be defined with:: 26 | 27 | gtk_entry_completion_set_minimum_key_length(GTK_ENTRY_COMPLETION(entrycompletion), length); 28 | 29 | The *length* parameter should be set to an integer value. 30 | 31 | To enable inline completion where the completion text is inserted into the Entry, use:: 32 | 33 | gtk_entry_completion_set_inline_completion(GTK_ENTRY_COMPLETION(entrycompletion), inline); 34 | 35 | The ability to cycle through completions within the Entry is set with:: 36 | 37 | gtk_entry_completion_set_inline_selection(GTK_ENTRY_COMPLETION(entrycompletion), inline); 38 | 39 | A completion can be programatically forced using the entered text as the key via:: 40 | 41 | gtk_entry_completion_complete(GTK_ENTRY_COMPLETION(entrycompletion)); 42 | 43 | ======= 44 | Example 45 | ======= 46 | Below is an example of an EntryCompletion: 47 | 48 | .. literalinclude:: _examples/entrycompletion.c 49 | 50 | Download: :download:`EntryCompletion <_examples/entrycompletion.c>` 51 | -------------------------------------------------------------------------------- /favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RainMark/gtk3-tutorial/a2c0cc82e4e9a090b1617ab43f8256146c7150c2/favicon.ico -------------------------------------------------------------------------------- /filechooserbutton.rst: -------------------------------------------------------------------------------- 1 | FileChooserButton 2 | ================= 3 | A FileChooserButton provides a Button-style widget which when clicked launches a :doc`filechooserdialog`. 4 | 5 | =========== 6 | Constructor 7 | =========== 8 | The FileChooserButton is constructed using:: 9 | 10 | GtkWidget *filechooserbutton = gtk_file_chooser_button_new(); 11 | 12 | ======= 13 | Methods 14 | ======= 15 | The title displayed on the dialog can be set with:: 16 | 17 | gtk_file_chooser_button_set_title(GTK_FILE_CHOOSER_BUTTON(filechooserbutton), title); 18 | 19 | Customisation of the FileChooserButton width can be made via:: 20 | 21 | gtk_file_chooser_button_set_width_chars(GTK_FILE_CHOOSER_BUTTON(filechooserbutton), width); 22 | 23 | The *width* should be a value set in pixels. 24 | 25 | ======= 26 | Example 27 | ======= 28 | Below is an example of a FileChooserButton: 29 | 30 | .. literalinclude:: _examples/filechooserbutton.c 31 | 32 | Download: :download:`FileChooserButton <_examples/filechooserbutton.c>` 33 | -------------------------------------------------------------------------------- /flowbox.rst: -------------------------------------------------------------------------------- 1 | FlowBox 2 | ======= 3 | The FlowBox allows child widgets to be added to the container, which arranges the added widgets into rows and columns. Depending on the width or height of the child, the amount of space it occupies within the FlowBox is adjusted. In addition, items can be sorted and filtered as required. 4 | 5 | A FlowBox is also similar to a :doc:`listbox`. 6 | 7 | =========== 8 | Constructor 9 | =========== 10 | The FlowBox is constructed by the call:: 11 | 12 | GtkWidget *flowbox = gtk_flow_box_new(); 13 | 14 | ======= 15 | Methods 16 | ======= 17 | Child widgets are added to the FlowBox with the method:: 18 | 19 | gtk_flow_box_insert(GTK_FLOW_BOX(flowbox), child, position); 20 | 21 | The *child* parameter should be set to the child being added. The *position* value specifies the order in which the child should be added. If ``-1`` is used, the child will be appended to the end of the FlowBox. 22 | 23 | The child widget at a particular position can be obtained via the position value with:: 24 | 25 | gtk_flow_box_get_child_at_index(GTK_FLOW_BOX(flowbox), position); 26 | 27 | Spacing between rows and columns can be set via:: 28 | 29 | gtk_flow_box_set_row_spacing(GTK_FLOW_BOX(flowbox), spacing); 30 | gtk_flow_box_set_column_spacing(GTK_FLOW_BOX(flowbox), spacing); 31 | 32 | To ensure that all rows and columns are assigned the same size call:: 33 | 34 | gtk_flow_box_set_homogeneous(GTK_FLOW_BOX(flowbox), homogeneous); 35 | 36 | The child rows contained by the FlowBox are able to be selected or unselected using:: 37 | 38 | gtk_flow_box_select_all(GTK_FLOW_BOX(flowbox)); 39 | gtk_flow_box_unselect_all(GTK_FLOW_BOX(flowbox)); 40 | 41 | The minimum and maximum children per line can be fixed via:: 42 | 43 | gtk_flow_box_set_min_children_per_line(GTK_FLOW_BOX(flowbox), number); 44 | gtk_flow_box_set_max_children_per_line(GTK_FLOW_BOX(flowbox), number); 45 | 46 | Children contained within the FlowBox can be selected by the user. This can be configured via:: 47 | 48 | gtk_flow_box_set_selection_mode(GTK_FLOW_BOX(flowbox), selection); 49 | 50 | The *selection* parameter should be set to one of the following constants:: 51 | 52 | * ``GTK_SELECTION_NONE`` - allow no selections to be made. 53 | * ``GTK_SELECTION_SINGLE`` - allow a single selection. 54 | * ``GTK_SELECTION_MULTIPLE`` - allow multiple selections. 55 | * ``GTK_SELECTION_BROWSE`` - allow a single selection, and only allow the currently selected item to be deselected when another item is selected. 56 | 57 | ======= 58 | Example 59 | ======= 60 | Below is an example of a FlowBox: 61 | 62 | .. literalinclude:: _examples/flowbox.c 63 | 64 | Download: :download:`FlowBox <_examples/flowbox.c>` 65 | -------------------------------------------------------------------------------- /fontbutton.rst: -------------------------------------------------------------------------------- 1 | FontButton 2 | ========== 3 | The FontButton provides a standard Button-like display which launches a :doc:`fontchooserdialog` when clicked allowing the user to select a font, size, and style to be selected. 4 | 5 | =========== 6 | Constructor 7 | =========== 8 | Construction of the FontButton is made using:: 9 | 10 | GtkWidget *fontbutton = gtk_font_button_new(); 11 | 12 | ======= 13 | Methods 14 | ======= 15 | A pre-selected font can be specified via its name by calling:: 16 | 17 | gtk_font_button_set_font_name(GTK_FONT_BUTTON(fontbutton), name); 18 | 19 | The selected font and associated properties can be displayed on the FontButton. These settings can be configured with:: 20 | 21 | gtk_font_button_set_show_style(GTK_FONT_BUTTON(fontbutton), show_style); 22 | gtk_font_button_set_show_size(GTK_FONT_BUTTON(fontbutton), show_size); 23 | 24 | Previews can also be displayed on the FontButton for the selected font using:: 25 | 26 | gtk_font_button_set_use_font(GTK_FONT_BUTTON(fontbutton), use_font); 27 | gtk_font_button_set_use_size(GTK_FONT_BUTTON(fontbutton), use_size); 28 | 29 | The FontButton title to be displayed on the dialog can be set with:: 30 | 31 | gtk_font_button_set_title(GTK_FONT_BUTTON(fontbutton), title); 32 | 33 | ======= 34 | Example 35 | ======= 36 | Below is an example of a FontButton: 37 | 38 | .. literalinclude:: _examples/fontbutton.c 39 | 40 | Download: :download:`FontButton <_examples/fontbutton.c>` 41 | -------------------------------------------------------------------------------- /frame.rst: -------------------------------------------------------------------------------- 1 | Frame 2 | ===== 3 | A Frame provides a container for grouping widgets typically of a similar purpose. By default, a surrounding line indicates the edge of the Frame, and a title is also able to be added indicating the purpose of the contents. 4 | 5 | .. note:: 6 | 7 | The Frame widget border can be considered distracting if overused on a single interface. Typically, a Frame is not used by itself; rather in combination with other widgets and settings. This setup can be viewed on the :doc:`commonframe` page. 8 | 9 | =========== 10 | Constructor 11 | =========== 12 | Construction of the Frame widget is done with:: 13 | 14 | GtkWidget *frame = gtk_frame_new(); 15 | 16 | ======= 17 | Methods 18 | ======= 19 | Title text can be assigned to the Frame post-construction with:: 20 | 21 | gtk_frame_set_label(GTK_FRAME(frame), text); 22 | 23 | Alternatively, a :doc:`label` widget can be added instead:: 24 | 25 | gtk_frame_set_label_widget(GTK_FRAME(frame), label); 26 | 27 | Configuration of the label position can be set via:: 28 | 29 | gtk_frame_set_label_align(GTK_FRAME(frame), xalign, yalign); 30 | 31 | The *xalign* and *yalign* defaults are ``0.0`` and ``0.5`` to position the label on the left. The numbers should be set between ``0.0`` and ``1.0`` for both arguments. 32 | 33 | The line around the Frame is referred to as the shadow and can be set with:: 34 | 35 | gtk_frame_set_shadow_type(GTK_FRAME(frame), shadow); 36 | 37 | The *shadow* value should be set to one of the following: 38 | 39 | * ``GTK_SHADOW_NONE`` - display no frame. 40 | * ``GTK_SHADOW_IN`` - outline is bevelled inwards. 41 | * ``GTK_SHADOW_OUT`` - outline is bevelled outwards. 42 | * ``GTK_SHADOW_ETCHED_IN`` - sunken 3D appearance. 43 | * ``GTK_SHADOW_ETCHED_OUT`` - raised 3D appearance. 44 | 45 | ======= 46 | Example 47 | ======= 48 | Below is an example of a Frame: 49 | 50 | .. literalinclude:: _examples/frame.c 51 | 52 | Download: :download:`Frame <_examples/frame.c>` 53 | -------------------------------------------------------------------------------- /grid.rst: -------------------------------------------------------------------------------- 1 | Grid 2 | ==== 3 | The Grid container provides a dynamically sizing layout on which other widgets can be placed. It allows widgets to be placed in rows and columns with a coordinate-like system. 4 | 5 | =========== 6 | Constructor 7 | =========== 8 | The constructor for the Grid is:: 9 | 10 | GtkWidget *grid = gtk_grid_new(); 11 | 12 | ======= 13 | Methods 14 | ======= 15 | Items are added into the Grid using the method:: 16 | 17 | gtk_grid_attach(GTK_GRID(grid), child, left, top, width, height); 18 | 19 | The *child* parameter is the name of the child widget to be added to the Grid. The *left* and *top* values are integer numbers with ``0`` for both positioning in the top-left corner. The *width* and *height* parameters specify how many rows or columns the widget should span when added. 20 | 21 | Widgets can also be attached next to a sibling widget:: 22 | 23 | gtk_grid_attach_next_to(GTK_GRID(grid), child, sibling, side, width, height); 24 | 25 | The first argument takes the *child* widget to be added, with the *sibling* indicating the widget the child will be added relative to. The *width* and *height* specifies how many rows or columns the child widget will span. Finally, the *side* should be set to one of the following: 26 | 27 | * ``GTK_POS_LEFT`` 28 | * ``GTK_POS_RIGHT`` 29 | * ``GTK_POS_TOP`` 30 | * ``GTK_POS_BOTTOM`` 31 | 32 | When using ``GTK_POS_TOP`` or ``GTK_POS_BOTTOM``, the child is added above or below the sibling. Alternatively, ``GTK_POS_LEFT`` and ``GTK_POS_RIGHT`` allow the child to be added to the left or right side of the sibling. 33 | 34 | By default, the widgets have no space between each other. This can be adjusted using:: 35 | 36 | gtk_grid_set_row_spacing(GTK_GRID(grid), spacing); 37 | gtk_grid_set_column_spacing(GTK_GRID(grid), spacing); 38 | 39 | The *spacing* value should be set to an integer value specifying the number of pixels between each row and column. 40 | 41 | In some cases, it may be useful to ensure that each widget is allocated the same space in the Grid:: 42 | 43 | gtk_grid_set_row_homogeneous(GTK_GRID(grid), homogeneous); 44 | gtk_grid_set_column_homogeneous(GTK_GRID(grid), homogeneous); 45 | 46 | When *homogeneous* is set to ``TRUE``, the Grid will force each widget to be the same size, with the largest widget dictating the overall size. 47 | 48 | The number of rows and columns in the Grid can be increased or decreased by:: 49 | 50 | gtk_grid_insert_row(GTK_GRID(grid), position); 51 | gtk_grid_insert_column(GTK_GRID(grid), position); 52 | gtk_grid_remove_row(GTK_GRID(grid), position); 53 | gtk_grid_remove_column(GTK_GRID(grid), position); 54 | 55 | The *position* value should be an integer value indicating the row or column to remove, with ``0`` referencing the first row or column. Children in the row/column being removed are also removed, while children spanning the row/column will be shrunk. When inserting, rows and columns are moved down/right to make way for the new row or column. 56 | 57 | Additional rows and columns can be inserted relative to a sibling via:: 58 | 59 | gtk_grid_insert_next_to(GTK_GRID(grid), sibling, side); 60 | 61 | The *sibling* argument should be set to the child widget which the row or column is going to be inserted next to. The *side* value should be set to one of the following: 62 | 63 | * ``GTK_POS_LEFT`` 64 | * ``GTK_POS_RIGHT`` 65 | * ``GTK_POS_TOP`` 66 | * ``GTK_POS_BOTTOM`` 67 | 68 | When ``GTK_POS_TOP`` or ``GTK_POS_BOTTOM`` is used, a row is inserted and when ``GTK_POS_LEFT`` and ``GTK_POS_RIGHT`` is used, a column is added. 69 | 70 | The child located in a particular row and column can be retrieved with:: 71 | 72 | gtk_grid_get_child_at(GTK_GRID(grid), left, top); 73 | 74 | ======= 75 | Example 76 | ======= 77 | Below is an example of a Grid: 78 | 79 | .. literalinclude:: _examples/grid.c 80 | 81 | Download: :download:`Grid <_examples/grid.c>` 82 | -------------------------------------------------------------------------------- /headerbar.rst: -------------------------------------------------------------------------------- 1 | HeaderBar 2 | ========= 3 | A HeaderBar is placed at the top of the window which contains it, often replacing the titlebar decoration traditionally drawn by the window manager. Usually included within the HeaderBar is the window title, the close button, the minimise button, and the maximise button. 4 | 5 | =========== 6 | Constructor 7 | =========== 8 | The constructor for the HeaderBar is:: 9 | 10 | GtkWidget *headerbar = gtk_header_bar_new(); 11 | 12 | ======= 13 | Methods 14 | ======= 15 | The title on the HeaderBar is settable with the method:: 16 | 17 | gtk_header_bar_set_title(GTK_HEADER_BAR(headerbar), title); 18 | 19 | A subtitle can also be added which is displayed beneath the title:: 20 | 21 | gtk_header_bar_set_subtitle(GTK_HEADER_BAR(headerbar), subtitle); 22 | 23 | If no subtitle is to be set, but the space for it should be reserved for future use, use:: 24 | 25 | gtk_header_bar_set_has_subtitle(GTK_HEADER_BAR(headerbar), has_subtitle); 26 | 27 | When the *has_subtitle* parameter is set to ``FALSE``, any text set by the ``set_subtitle()`` method will be hidden from view. 28 | 29 | Other widgets can be packed into the HeaderBar by using the methods:: 30 | 31 | gtk_header_bar_pack_start(GTK_HEADER_BAR(headerbar), child); 32 | gtk_header_bar_pack_end(GTK_HEADER_BAR(headerbar), child); 33 | 34 | The close, minimise, and maximise buttons can be hidden from view by using:: 35 | 36 | gtk_header_bar_set_show_close_button(GTK_HEADER_BAR(headerbar), close); 37 | 38 | ======= 39 | Example 40 | ======= 41 | Below is an example of a HeaderBar: 42 | 43 | .. literalinclude:: _examples/headerbar.c 44 | 45 | Download: :download:`HeaderBar <_examples/headerbar.c>` 46 | -------------------------------------------------------------------------------- /helloworld.rst: -------------------------------------------------------------------------------- 1 | Hello, World! 2 | ============= 3 | As is customary with any programming tutorial, a "Hello, World!" example is required. 4 | 5 | .. literalinclude:: _examples/helloworld.c 6 | 7 | Download: :download:`Hello World <_examples/helloworld.c>` 8 | 9 | The example above showcases the simple display of a :doc:`window`, with an embedded :doc:`label` to display the text. It can be compiled using GCC with the following: 10 | 11 | ``gcc helloworld.c `pkg-config --libs --cflags gtk+-3.0` helloworld`` 12 | 13 | Alternatively, if you use the Clang compiler: 14 | 15 | ``clang helloworld.c `pkg-config --libs --cflags gtk+-3.0` helloworld`` 16 | -------------------------------------------------------------------------------- /image.rst: -------------------------------------------------------------------------------- 1 | Image 2 | ===== 3 | The Image widget provides functionality for displaying images within an application. It can be used for small icons up to large photographs, and provides the ability to load from a variety of sources. 4 | 5 | =========== 6 | Constructor 7 | =========== 8 | The constructor for the Image widget is:: 9 | 10 | GtkWidget *image = gtk_image_new(); 11 | 12 | Alternatively, the image to be loaded can be supplied at construction time with:: 13 | 14 | GtkWidget *image = gtk_image_new_from_file(filename); 15 | GtkWidget *image = gtk_image_new_from_pixbuf(pixbuf); 16 | GtkWidget *image = gtk_image_new_from_icon_name(name, size); 17 | 18 | The *filename* parameter of the ``gtk_image_new_from_file`` constructor should be set to the full path of an image (e.g. a JPG, PNG, SVG, GIF, etc). The *pixbuf* argument allows a GTK+ pixbuf object to be loaded and shown with the ``gtk_image_new_from_pixbuf`` method. Icons can also be displayed by supplying the *name* in the ``gtk_image_new_from_icon_name`` method, with a *size* also required which should be set to: 19 | 20 | * ``GTK_ICON_SIZE_MENU`` - 16 pixels 21 | * ``GTK_ICON_SIZE_SMALL_TOOLBAR`` - 16 pixels 22 | * ``GTK_ICON_SIZE_LARGE_TOOLBAR`` - 24 pixels 23 | * ``GTK_ICON_SIZE_BUTTON`` - 16 pixels 24 | * ``GTK_ICON_SIZE_DND`` - 32 pixels 25 | * ``GTK_ICON_SIZE_DIALOG`` - 48 pixels 26 | 27 | ======= 28 | Methods 29 | ======= 30 | The image displayed on the widget can be changed post-construction by calling:: 31 | 32 | gtk_image_set_from_file(GTK_IMAGE(image), filename); 33 | gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf); 34 | gtk_image_set_from_icon_name(GTK_IMAGE(image), name, size); 35 | 36 | Clearing of the Image widget and removing the associated image is done via:: 37 | 38 | gtk_image_clear(GTK_IMAGE(image)); 39 | -------------------------------------------------------------------------------- /index.rst: -------------------------------------------------------------------------------- 1 | Welcome to the GTK+ 3 Tutorial 2 | ============================== 3 | 4 | Contents: 5 | 6 | .. toctree:: 7 | :titlesonly: 8 | 9 | introduction 10 | helloworld 11 | window 12 | box 13 | grid 14 | label 15 | button 16 | togglebutton 17 | checkbutton 18 | spinbutton 19 | linkbutton 20 | menubutton 21 | switch 22 | entry 23 | entrycompletion 24 | entrybuffer 25 | searchentry 26 | buttonbox 27 | separator 28 | spinner 29 | calendar 30 | scale 31 | scalebutton 32 | toolbar 33 | toolpalette 34 | statusbar 35 | frame 36 | aspectframe 37 | expander 38 | revealer 39 | paned 40 | flowbox 41 | listbox 42 | actionbar 43 | headerbar 44 | levelbar 45 | progressbar 46 | stack 47 | stackswitcher 48 | stacksidebar 49 | combobox 50 | comboboxtext 51 | liststore 52 | treestore 53 | filechooserbutton 54 | colorbutton 55 | fontbutton 56 | infobar 57 | textview 58 | dialog 59 | aboutdialog 60 | messagedialog 61 | assistant 62 | 63 | Indices and tables 64 | ================== 65 | 66 | * :ref:`genindex` 67 | * :ref:`modindex` 68 | * :ref:`search` 69 | -------------------------------------------------------------------------------- /infobar.rst: -------------------------------------------------------------------------------- 1 | InfoBar 2 | ======= 3 | The InfoBar widget can be used to display important messages to the end user, which are displayed within the window. Messages can be of a number of types including warnings and errors. 4 | 5 | The widget is similar to a :doc:`messagedialog`, however it is more commonly used when the message should not necessarily interrupt the user. 6 | 7 | =========== 8 | Constructor 9 | =========== 10 | Construction of the InfoBar is made using:: 11 | 12 | GtkWidget *infobar = gtk_info_bar_new(); 13 | 14 | ======= 15 | Methods 16 | ======= 17 | The message type should be set correctly to properly alert the user of the message content. This is set via:: 18 | 19 | gtk_info_bar_set_message_type(GTK_INFO_BAR(infobar), message_type); 20 | 21 | The *message_type* should be set to: 22 | 23 | * ``GTK_MESSAGE_INFO`` 24 | * ``GTK_MESSAGE_WARNING`` 25 | * ``GTK_MESSAGE_ERROR`` 26 | * ``GTK_MESSAGE_QUESTION`` 27 | * ``GTK_MESSAGE_OTHER`` 28 | 29 | An InfoBar can display one or more buttons. These can be added via:: 30 | 31 | gtk_info_bar_add_button(GTK_INFO_BAR(infobar), text, response); 32 | 33 | The *text* value should be the string of text to display on the button. The *response* parameter should be set to a number which is used to handle how the application proceeds. 34 | 35 | Alternatively, multiple buttons can be added at once with:: 36 | 37 | gtk_info_bar_add_buttons(GTK_INFO_BAR(infobar), text, response, text, response, ...); 38 | 39 | In some cases, a button added to the InfoBar will need to be made insensitive. This can be done with:: 40 | 41 | gtk_info_bar_set_response_insensitive(GTK_INFO_BAR(infobar), response, sensitive); 42 | 43 | The *response* value should be set to the response value of the button. The *sensitive* value when set to ``FALSE`` "greys-out" the button. 44 | 45 | A response can also be made default (i.e. it activates when the user pressed :kbd:`Enter` or :kbd:`Return`) via:: 46 | 47 | gtk_info_bar_set_default_response(GTK_INFO_BAR(infobar), response); 48 | 49 | If required, the InfoBar can be dismissed by a close button, which can be shown or hidden via:: 50 | 51 | gtk_info_bar_set_show_close_button(GTK_INFO_BAR(infobar), close_button); 52 | 53 | The content and action areas of the InfoBar can be retrieved using:: 54 | 55 | gtk_info_bar_get_action_area(GTK_INFO_BAR(infobar)); 56 | gtk_info_bar_get_content_area(GTK_INFO_BAR(infobar)); 57 | 58 | ======= 59 | Example 60 | ======= 61 | Below is an example of an InfoBar: 62 | 63 | .. literalinclude:: _examples/infobar.c 64 | 65 | Download: :download:`InfoBar <_examples/infobar.c>` 66 | -------------------------------------------------------------------------------- /introduction.rst: -------------------------------------------------------------------------------- 1 | Introduction 2 | ============ 3 | 4 | ========================== 5 | Before using this tutorial 6 | ========================== 7 | Before working through any of this tutorial, it is advised that you have a good grasp of C programming. Working with graphical interfaces poses new challenges and problems compared to interacting with the Standard Output. 8 | 9 | Prior knowledge of GTK+ is not required, but experience with its use in other languages is beneficial. 10 | 11 | =================== 12 | About this tutorial 13 | =================== 14 | This guide does not walk through creating an application. It merely provides informational on each widget in GTK+, and describes their use. 15 | 16 | It also assumes that you are using up-to-date versions of GCC or Clang, and GTK+. The GTK+ version is recommended to be as new as possible, with the tutorial being written using 3.16. 17 | 18 | =========== 19 | Deprecation 20 | =========== 21 | Deprecation is the process of preparing features within software to be decommisioned or removed. GTK+ deprecates objects by providing warnings both in the GTK+ framework and documentation prior to removal at a later date. This allows developers to change their code before a feature is removed. 22 | 23 | Reasons for deprecation include: 24 | 25 | * A feature has been replaced. 26 | * A feature is no longer seen as widely-used. 27 | * A feature no longer can be used. 28 | 29 | It is highly recommended to not use deprecated features of GTK+ when developing applications, particularly when learning as they can cause problems when understanding other areas of the library. 30 | 31 | This tutorial does not cover widgets which have been marked as deprecated. Any widgets marked as deprecated by GTK+ in the future will also be removed from future versions of the tutorial. 32 | 33 | ======= 34 | Contact 35 | ======= 36 | Please contact me at andrew@andrewsteele.me.uk to report issues, bugs and provide comments. All suggestions are welcome. 37 | 38 | ======= 39 | License 40 | ======= 41 | * The tutorial text and code examples are released under a `CC0 1.0 Universal `_ (CC0 1.0) license (this essentially makes them Public Domain). 42 | * The GTK+ logo used for examples and the site favicon is released under the `Creative Commons Attribution-Share Alike 3.0 Unported `_ license. 43 | -------------------------------------------------------------------------------- /label.rst: -------------------------------------------------------------------------------- 1 | Label 2 | ===== 3 | The Label widget is commonly used for displaying small amounts of text, such as the purpose of another widget. It is however fairly powerful and can also be used to display longer strings of text with various formatting options such as bold or underlined text. 4 | 5 | =========== 6 | Constructor 7 | =========== 8 | The Label can be constructed using the call:: 9 | 10 | GtkWidget *label = gtk_label_new(text); 11 | 12 | The *text* value is used to declare the text to be displayed inside the Label when it is constructed. 13 | 14 | ======= 15 | Methods 16 | ======= 17 | The Label text can be defined after construction with:: 18 | 19 | gtk_label_set_label(GTK_LABEL(label), text); 20 | 21 | Text can also be retrieved from Label via:: 22 | 23 | gtk_label_get_label(GTK_LABEL(label)); 24 | 25 | By default, text aligns centrally on both horizontal and vertical planes. This can be configured using:: 26 | 27 | gtk_label_set_xalign(GTK_LABEL(label), xalign); 28 | gtk_label_set_yalign(GTK_LABEL(label), yalign); 29 | 30 | The *xalign* and *yalign* parameters should be set to a value between ``0.0`` and ``1.0``, with ``0.0`` indicating left or top, and ``1.0`` indicating right or bottom. 31 | 32 | Text within the Label can be made selectable using the method:: 33 | 34 | gtk_label_set_selectable(GTK_LABEL(label), selectable); 35 | 36 | When *selectable* is set to ``TRUE`` the user will be able to highlight the text for copy-and-paste. 37 | 38 | Some widgets cannot directly accept a mnemonic shortcut so an associated Label can be used with the mnemonic, which passes on focus when the shortcut key is used. The mnemonic widget can be set with:: 39 | 40 | gtk_label_set_mnemonic_widget(GTK_LABEL(label), widget); 41 | 42 | The default setting of the text alignment is to align to the left-edge. This can be changed via:: 43 | 44 | gtk_label_set_justify(GTK_LABEL(label), justification); 45 | 46 | The *justification* for the Label can be set to one of the following: 47 | 48 | * ``GTK_JUSTIFY_LEFT`` 49 | * ``GTK_JUSTIFY_RIGHT`` 50 | * ``GTK_JUSTIFY_CENTER`` 51 | * ``GTK_JUSTIFY_FILL`` 52 | 53 | ======= 54 | Example 55 | ======= 56 | Below is an example of a Label: 57 | 58 | .. literalinclude:: _examples/label.c 59 | 60 | Download: :download:`Label <_examples/label.c>` 61 | -------------------------------------------------------------------------------- /levelbar.rst: -------------------------------------------------------------------------------- 1 | LevelBar 2 | ======== 3 | A LevelBar provides a bar on which a level indicator is displayed. It is commonly used to show the strength of a password or the capacity of a battery. 4 | 5 | =========== 6 | Constructor 7 | =========== 8 | The construction of the LevelBar is made by calling:: 9 | 10 | GtkWidget *levelbar = gtk_level_bar_new(); 11 | 12 | The default range of the LevelBar is a value between 0.0 and 1.0. Alternatively, the range can be defined at construction with:: 13 | 14 | GtkWidget *levelbar = gtk_level_bar_new(minimum, maximum); 15 | 16 | ======= 17 | Methods 18 | ======= 19 | The value on the LevelBar can be set using the call:: 20 | 21 | gtk_level_bar_set_value(GTK_LEVEL_BAR(levelbar), value); 22 | 23 | Retrieval of the value from the LevelBar can be done using:: 24 | 25 | gtk_level_bar_get_value(GTK_LEVEL_BAR(levelbar)); 26 | 27 | The range used by the LevelBar can be set post-construction:: 28 | 29 | gtk_level_bar_set_min_value(GTK_LEVEL_BAR(levelbar), minimum); 30 | gtk_level_bar_set_max_value(GTK_LEVEL_BAR(levelbar), maximum); 31 | 32 | By default, the LevelBar (depending on orientation) fills from left-to-right or top-to-bottom. This can be inverted via:: 33 | 34 | gtk_level_bar_set_inverted(GTK_LEVEL_BAR(levelbar), inverted); 35 | 36 | An offset value can be applied to the LevelBar via the method:: 37 | 38 | gtk_level_bar_add_offset_value(GTK_LEVEL_BAR(levelbar), name, value); 39 | 40 | The *name* parameter should be an identifier for the offset value. The *value* should be within the minimum and maximum range. If a name is set on the LevelBar which already exists, the previous value is replaced with the new value. 41 | 42 | The named offset value can be removed with:: 43 | 44 | gtk_level_bar_remove_offset_value(GTK_LEVEL_BAR(levelbar), name); 45 | 46 | ======= 47 | Example 48 | ======= 49 | Below is an example of a LevelBar: 50 | 51 | .. literalinclude:: _examples/levelbar.c 52 | 53 | Download: :download:`LevelBar <_examples/levelbar.c>` 54 | -------------------------------------------------------------------------------- /linkbutton.rst: -------------------------------------------------------------------------------- 1 | LinkButton 2 | ========== 3 | A LinkButton has the appearance of a standard :doc:`button` widget, but is typically used for linking to websites from within the application. The LinkButton provides a text identifier which is underlined and highlighted in blue to signify a link. 4 | 5 | =========== 6 | Constructor 7 | =========== 8 | The LinkButton is constructed using:: 9 | 10 | GtkWidget *linkbutton = gtk_link_button_new(uri); 11 | 12 | The *uri* parameter should be set to the website which the LinkButton links to. Alternatively, a label can also be defined at construction with:: 13 | 14 | GtkWidget *linkbutton = gtk_link_button_new_with_label(uri, label); 15 | 16 | .. note:: 17 | 18 | If no label is specified, the LinkButton will simply use the specified uri as the label. 19 | 20 | ======= 21 | Methods 22 | ======= 23 | The textual label displayed to the user with:: 24 | 25 | gtk_link_button_set_label(GTK_BUTTON(linkbutton), label); 26 | 27 | The link which the LinkButton links to can be set via:: 28 | 29 | gtk_link_button_set_uri(GTK_LINK_BUTTON(linkbutton), uri); 30 | 31 | Checking whether the LinkButton address has been visited is retrievable using:: 32 | 33 | gtk_link_button_get_visited(GTK_LINK_BUTTON(linkbutton)); 34 | 35 | ======= 36 | Example 37 | ======= 38 | Below is an example of a LinkButton: 39 | 40 | .. literalinclude:: _examples/linkbutton.c 41 | 42 | Download: :download:`LinkButton <_examples/linkbutton.c>` 43 | -------------------------------------------------------------------------------- /listbox.rst: -------------------------------------------------------------------------------- 1 | ListBox 2 | ======= 3 | The ListBox is a container which stores children vertically. It allows those widgets to be sorted and filtered dynamically. 4 | 5 | Use of a ListBox is often done as an alternative to a :doc:`treeview` as it allows more complicated layouts than what can be achieved using CellRenderer's. 6 | 7 | =========== 8 | Constructor 9 | =========== 10 | ListBox construction is made using the call:: 11 | 12 | GtkWidget *listbox = gtk_list_box_new(); 13 | 14 | ======= 15 | Methods 16 | ======= 17 | Items can be added to the ListBox with the methods:: 18 | 19 | gtk_list_box_prepend(GTK_WIDGET(child)) 20 | gtk_list_box_insert(GTK_WIDGET(child), position) 21 | 22 | The *child* parameter for both methods takes another widget which is to be added. The *position* value indicates the location at which the child should be added. 23 | 24 | All the rows in the ListBox can be selected and unselected with the use of:: 25 | 26 | gtk_list_box_select_all(GTK_LIST_BOX(listbox)); 27 | gtk_list_box_unselect_all(GTK_LIST_BOX(listbox)); 28 | 29 | An individual item can be selected or unselected with:: 30 | 31 | gtk_list_box_select_row(GTK_LIST_BOX(listbox), row); 32 | gtk_list_box_unselect_row(GTK_LIST_BOX(listbox), row); 33 | 34 | The *row* parameter should be set to an appropriate ListBoxRow object contained within the ListBox. 35 | 36 | By default, rows are selected by double-clicked. Single-click activation can be enabled with:: 37 | 38 | gtk_list_box_set_activate_on_single_click(single); 39 | 40 | A placeholder widget can be added for situations when the ListBox is empty:: 41 | 42 | gtk_list_box_set_placeholder(GTK_LIST_BOX(listbox), widget); 43 | 44 | To configure the row selection functionality call:: 45 | 46 | gtk_list_box_set_selection_mode(GTK_LIST_BOX(listbox), mode); 47 | 48 | The *mode* should be set to one of the following: 49 | 50 | * ``GTK_SELECTION_NONE`` 51 | * ``GTK_SELECTION_SINGLE`` 52 | * ``GTK_SELECTION_BROWSE`` 53 | * ``GTK_SELECTION_MULTIPLE`` 54 | 55 | The selected rows, depending on the selection mode in use, can be obtained via:: 56 | 57 | gtk_list_box_get_selected_row(GTK_LIST_BOX(listbox)); 58 | gtk_list_box_get_selected_rows(GTK_LIST_BOX(listbox)); 59 | 60 | ======= 61 | Example 62 | ======= 63 | Below is an example of a ListBox: 64 | 65 | .. literalinclude:: _examples/listbox.c 66 | 67 | Download: :download:`ListBox <_examples/listbox.c>` 68 | -------------------------------------------------------------------------------- /liststore.rst: -------------------------------------------------------------------------------- 1 | ListStore 2 | ========= 3 | A ListStore is an object used to store data for use in a :doc:`treeview` or :doc:`combobox`. It can be used to store a variety of data types such as text, values, and images. The ListStore itself is not actually visible and it is simply used as the model for other widgets to show the contents it holds. 4 | 5 | =========== 6 | Constructor 7 | =========== 8 | The constructor for the ListStore is:: 9 | 10 | GtkListStore *liststore = gtk_liststore_new(columns, type, type, type...); 11 | 12 | The *columns* parameter indicates the number of columns the ListStore will hold. A matching number of *type* declarations can then be supplied which indicate what type of data will be stored in each column. The types permissible include:: 13 | 14 | * ``G_TYPE_STRING`` 15 | * ``G_TYPE_INT`` 16 | * ``G_TYPE_FLOAT`` 17 | * ``G_TYPE_DOUBLE`` 18 | * ``G_TYPE_BOOLEAN`` 19 | * ``G_TYPE_CHAR`` 20 | * ``G_TYPE_OBJECT`` 21 | 22 | ======= 23 | Methods 24 | ======= 25 | New rows are added to the ListStore with:: 26 | 27 | gtk_liststore_prepend(liststore, treeiter); 28 | gtk_liststore_append(liststore, treeiter); 29 | gtk_liststore_insert(liststore, treeiter, position); 30 | 31 | The *treeiter* parameter should point to an appropriate :doc:`treeiter` object which identifies the particular row being added. The ``insert()`` method also takes the *position* value indicating the location where the row should be added. 32 | 33 | Once the row has been added, the data can then be added:: 34 | 35 | gtk_liststore_set(liststore, treeiter, data, -1); 36 | 37 | Individual items can be removed from the ListStore via:: 38 | 39 | gtk_liststore_remove(liststore, treeiter); 40 | 41 | The *treeiter* parameter points to the TreeIter object of the row to be removed. If the TreeIter is valid and the row is remove, the method returns ``TRUE``, otherwise ``FALSE`` is removed. 42 | 43 | All the items can be cleared from the ListStore using:: 44 | 45 | gtk_liststore_clear(liststore); 46 | 47 | Two rows can be swapped by specifying the TreeIter of both with:: 48 | 49 | gtk_liststore_swap(liststore, treeiter1, treeiter2); 50 | 51 | .. note:: 52 | 53 | The ``swap()`` function only works on ListStore objects which are unsorted. 54 | 55 | Rows can also be moved above or below an existing item by calling:: 56 | 57 | gtk_liststore_move_before(liststore, treeiter, position); 58 | gtk_liststore_move_after(liststore, treeiter, position); 59 | 60 | The *treeiter* call in both methods takes the TreeIter of the item to be moved. The *position* argument is also a TreeIter, but it is that of the existing item to place the moved row above or below. 61 | 62 | .. note:: 63 | 64 | The ``move_before()`` and ``move_after()`` methods only work on ListStore objects which are unsorted. 65 | 66 | ======= 67 | Example 68 | ======= 69 | Below is an example of a ListStore: 70 | 71 | .. literalinclude:: _examples/liststore.c 72 | 73 | Download: :download:`ListStore <_examples/liststore.c>` 74 | -------------------------------------------------------------------------------- /make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Command file for Sphinx documentation 4 | 5 | if "%SPHINXBUILD%" == "" ( 6 | set SPHINXBUILD=sphinx-build 7 | ) 8 | set BUILDDIR=_build 9 | set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . 10 | set I18NSPHINXOPTS=%SPHINXOPTS% . 11 | if NOT "%PAPER%" == "" ( 12 | set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% 13 | set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% 14 | ) 15 | 16 | if "%1" == "" goto help 17 | 18 | if "%1" == "help" ( 19 | :help 20 | echo.Please use `make ^` where ^ is one of 21 | echo. html to make standalone HTML files 22 | echo. dirhtml to make HTML files named index.html in directories 23 | echo. singlehtml to make a single large HTML file 24 | echo. pickle to make pickle files 25 | echo. json to make JSON files 26 | echo. htmlhelp to make HTML files and a HTML help project 27 | echo. qthelp to make HTML files and a qthelp project 28 | echo. devhelp to make HTML files and a Devhelp project 29 | echo. epub to make an epub 30 | echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter 31 | echo. text to make text files 32 | echo. man to make manual pages 33 | echo. texinfo to make Texinfo files 34 | echo. gettext to make PO message catalogs 35 | echo. changes to make an overview over all changed/added/deprecated items 36 | echo. linkcheck to check all external links for integrity 37 | echo. doctest to run all doctests embedded in the documentation if enabled 38 | goto end 39 | ) 40 | 41 | if "%1" == "clean" ( 42 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i 43 | del /q /s %BUILDDIR%\* 44 | goto end 45 | ) 46 | 47 | if "%1" == "html" ( 48 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html 49 | if errorlevel 1 exit /b 1 50 | echo. 51 | echo.Build finished. The HTML pages are in %BUILDDIR%/html. 52 | goto end 53 | ) 54 | 55 | if "%1" == "dirhtml" ( 56 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml 57 | if errorlevel 1 exit /b 1 58 | echo. 59 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. 60 | goto end 61 | ) 62 | 63 | if "%1" == "singlehtml" ( 64 | %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml 65 | if errorlevel 1 exit /b 1 66 | echo. 67 | echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. 68 | goto end 69 | ) 70 | 71 | if "%1" == "pickle" ( 72 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle 73 | if errorlevel 1 exit /b 1 74 | echo. 75 | echo.Build finished; now you can process the pickle files. 76 | goto end 77 | ) 78 | 79 | if "%1" == "json" ( 80 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json 81 | if errorlevel 1 exit /b 1 82 | echo. 83 | echo.Build finished; now you can process the JSON files. 84 | goto end 85 | ) 86 | 87 | if "%1" == "htmlhelp" ( 88 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp 89 | if errorlevel 1 exit /b 1 90 | echo. 91 | echo.Build finished; now you can run HTML Help Workshop with the ^ 92 | .hhp project file in %BUILDDIR%/htmlhelp. 93 | goto end 94 | ) 95 | 96 | if "%1" == "qthelp" ( 97 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp 98 | if errorlevel 1 exit /b 1 99 | echo. 100 | echo.Build finished; now you can run "qcollectiongenerator" with the ^ 101 | .qhcp project file in %BUILDDIR%/qthelp, like this: 102 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\GTK3Tutorial.qhcp 103 | echo.To view the help file: 104 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\GTK3Tutorial.ghc 105 | goto end 106 | ) 107 | 108 | if "%1" == "devhelp" ( 109 | %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp 110 | if errorlevel 1 exit /b 1 111 | echo. 112 | echo.Build finished. 113 | goto end 114 | ) 115 | 116 | if "%1" == "epub" ( 117 | %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub 118 | if errorlevel 1 exit /b 1 119 | echo. 120 | echo.Build finished. The epub file is in %BUILDDIR%/epub. 121 | goto end 122 | ) 123 | 124 | if "%1" == "latex" ( 125 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 126 | if errorlevel 1 exit /b 1 127 | echo. 128 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. 129 | goto end 130 | ) 131 | 132 | if "%1" == "text" ( 133 | %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text 134 | if errorlevel 1 exit /b 1 135 | echo. 136 | echo.Build finished. The text files are in %BUILDDIR%/text. 137 | goto end 138 | ) 139 | 140 | if "%1" == "man" ( 141 | %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man 142 | if errorlevel 1 exit /b 1 143 | echo. 144 | echo.Build finished. The manual pages are in %BUILDDIR%/man. 145 | goto end 146 | ) 147 | 148 | if "%1" == "texinfo" ( 149 | %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo 150 | if errorlevel 1 exit /b 1 151 | echo. 152 | echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. 153 | goto end 154 | ) 155 | 156 | if "%1" == "gettext" ( 157 | %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale 158 | if errorlevel 1 exit /b 1 159 | echo. 160 | echo.Build finished. The message catalogs are in %BUILDDIR%/locale. 161 | goto end 162 | ) 163 | 164 | if "%1" == "changes" ( 165 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes 166 | if errorlevel 1 exit /b 1 167 | echo. 168 | echo.The overview file is in %BUILDDIR%/changes. 169 | goto end 170 | ) 171 | 172 | if "%1" == "linkcheck" ( 173 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck 174 | if errorlevel 1 exit /b 1 175 | echo. 176 | echo.Link check complete; look for any errors in the above output ^ 177 | or in %BUILDDIR%/linkcheck/output.txt. 178 | goto end 179 | ) 180 | 181 | if "%1" == "doctest" ( 182 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest 183 | if errorlevel 1 exit /b 1 184 | echo. 185 | echo.Testing of doctests in the sources finished, look at the ^ 186 | results in %BUILDDIR%/doctest/output.txt. 187 | goto end 188 | ) 189 | 190 | :end 191 | -------------------------------------------------------------------------------- /menubutton.rst: -------------------------------------------------------------------------------- 1 | MenuButton 2 | ========== 3 | The MenuButton provides a widget similar to a :doc:`button`, but with an attached :doc:`menu` which appears when clicked. 4 | 5 | =========== 6 | Constructor 7 | =========== 8 | The MenuButton is constructed using:: 9 | 10 | GtkWidget *menubutton = gtk_menu_button_new(); 11 | 12 | ======= 13 | Methods 14 | ======= 15 | The Menu to popup is set after construction by using:: 16 | 17 | gtk_menu_button_set_popup(GTK_MENU_BUTTON(menubutton), menu); 18 | 19 | Alternatively, if the popup is to contain other widgets, a :doc:`popover` can be defined:: 20 | 21 | gtk_menu_button_set_popover(GTK_MENU_BUTTON(menubutton), popover); 22 | 23 | The direction on which the Menu appears can be configured via:: 24 | 25 | gtk_menu_button_set_direction(GTK_MENU_BUTTON(menubutton), direction); 26 | 27 | Setting of the *direction* parameter should be done to one of the following: 28 | 29 | * ``GTK_ARROW_UP`` 30 | * ``GTK_ARROW_DOWN`` 31 | * ``GTK_ARROW_LEFT`` 32 | * ``GTK_ARROW_RIGHT`` 33 | * ``GTK_ARROW_NONE`` 34 | 35 | ======= 36 | Example 37 | ======= 38 | Below is an example of a MenuButton: 39 | 40 | .. literalinclude:: _examples/menubutton.c 41 | 42 | Download: :download:`MenuButton <_examples/menubutton.c>` 43 | -------------------------------------------------------------------------------- /messagedialog.rst: -------------------------------------------------------------------------------- 1 | MessageDialog 2 | ============= 3 | The MessageDialog is used to convey messages to the user about the state of a process. It is commonly used to ask questions, warn about issues, or display encountered errors. 4 | 5 | =========== 6 | Constructor 7 | =========== 8 | The MessageDialog can be constructed using:: 9 | 10 | messagedialog = gtk_message_dialog_new(parent, flags, type, buttons, text); 11 | 12 | If the MessageDialog is to display formatted text, another constructor can be used:: 13 | 14 | messagedialog = gtk_message_dialog_new_with_markup(parent, flags, type, buttons, text); 15 | 16 | Both calls take on a number of arguments. The first is the *parent* which is set to the parent :doc:`window` or :doc:`dialog` which owns the MessageDialog. The *flags* parameter determines some of the features of the dialog and is able to be set to: 17 | 18 | * ``GTK_DIALOG_MODAL`` 19 | * ``GTK_DIALOG_DESTROY_WITH_PARENT`` - close the dialog when the parent is closed. 20 | * ``GTK_DIALOG_USE_HEADER_BAR`` - create dialog with actions in the header bar rather than the action area. 21 | 22 | The *type* parameter indicates the purpose of the MessageDialog and should be set to one of: 23 | 24 | * ``GTK_MESSAGE_INFO`` 25 | * ``GTK_MESSAGE_WARNING`` 26 | * ``GTK_MESSAGE_QUESTION`` 27 | * ``GTK_MESSAGE_ERROR`` 28 | * ``GTK_MESSAGE_OTHER`` 29 | 30 | Buttons can also be configured at construction time with: 31 | 32 | * ``GTK_BUTTONS_NONE`` 33 | * ``GTK_BUTTONS_OK`` 34 | * ``GTK_BUTTONS_CLOSE`` 35 | * ``GTK_BUTTONS_CANCEL`` 36 | * ``GTK_BUTTONS_YES_NO`` 37 | * ``GTK_BUTTONS_OK_CANCEL`` 38 | 39 | Finally, the text to display can also be set with the *text* argument set to the string to show. 40 | 41 | ======= 42 | Methods 43 | ======= 44 | Text with (and without) markup can be set on the MessageDialog using:: 45 | 46 | gtk_message_dialog_set_markup(GTK_MESSAGE_DIALOG(messagedialog), text); 47 | 48 | If a more detailed explaination of the MessageDialog content is required, use:: 49 | 50 | gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(messagedialog), text); 51 | 52 | The *text* parameter accepts markup if required. When used, the primary message will be made larger and bolder. 53 | 54 | Additional content can be added to the message area of the dialog by retrieving the child :doc:`box` container:: 55 | 56 | gtk_message_dialog_get_message_area(GTK_MESSAGE_DIALOG(messagedialog)); 57 | 58 | ======= 59 | Example 60 | ======= 61 | Below is an example of a MessageDialog: 62 | 63 | .. literalinclude:: _examples/messagedialog.c 64 | 65 | Download: :download:`MessageDialog <_examples/messagedialog.c>` 66 | -------------------------------------------------------------------------------- /paned.rst: -------------------------------------------------------------------------------- 1 | Paned 2 | ===== 3 | The Paned widget is a container which offers two panels from which additional containers or widgets can be inserted. The separator between the panels can be adjusted to increase (and decrease) the size of the panels. 4 | 5 | =========== 6 | Constructor 7 | =========== 8 | The constructor for the Paned widget is:: 9 | 10 | GtkWidget *paned = gtk_paned_new(orientation); 11 | 12 | The *orientation* parameter determines whether the Paned container lays added widgets horizontally or vertically and can be set to either: 13 | 14 | * ``GTK_ORIENTATION_HORIZONTAL`` 15 | * ``GTK_ORIENTATION_VERTICAL`` 16 | 17 | ======= 18 | Methods 19 | ======= 20 | Child widgets can be added to the panels via:: 21 | 22 | gtk_paned_add1(GTK_PANED(paned), widget); 23 | gtk_paned_add2(GTK_PANED(paned), widget); 24 | 25 | The ``add1()`` method adds the child widget to the top or left panel based on orientation. Using ``add2()`` adds the widget to the bottom or right panel. 26 | 27 | Alternatively, widgets can be added with more control over the handling of the sizing:: 28 | 29 | gtk_paned_pack1(GTK_PANED(paned), widget, resize, shrink); 30 | gtk_paned_pack2(GTK_PANED(paned), widget, resize, shrink); 31 | 32 | The *resize* parameter can be set to ``TRUE`` to allow the child to expand when the widget is resized. The *shrink* parameter also when ``TRUE`` permits whether the child can be made smaller than the panel. 33 | 34 | The child widgets attached to the Paned can be obtained via:: 35 | 36 | gtk_paned_get_child1(GTK_PANED(paned)); 37 | gtk_paned_get_child2(GTK_PANED(paned)); 38 | 39 | The position of the handle can be set in pixels with:: 40 | 41 | gtk_paned_set_position(GTK_PANED(paned), position); 42 | 43 | The *position* value should be set to the appropriate number of pixels from the top or left edge depending on the pane orientation. 44 | 45 | To retrieve the current position of the handle call:: 46 | 47 | gtk_paned_get_position(GTK_PANED(paned)); 48 | 49 | In some cases, it may be beneficial to have a wide handle which allows the user to grab the separator more easily. This is set by:: 50 | 51 | gtk_paned_set_wide_handle(GTK_PANED(paned), wide); 52 | 53 | ======= 54 | Example 55 | ======= 56 | Below is an example of a Paned: 57 | 58 | .. literalinclude:: _examples/paned.c 59 | 60 | Download: :download:`Paned <_examples/paned.c>` 61 | -------------------------------------------------------------------------------- /progressbar.rst: -------------------------------------------------------------------------------- 1 | ProgressBar 2 | =========== 3 | A ProgressBar is used to display to the user how long a particular task has remaining to completion. This is often expressed in time or the number of items. 4 | 5 | =========== 6 | Constructor 7 | =========== 8 | The constructor for the ProgressBar widget is:: 9 | 10 | GtkWidget *progressbar = gtk_progress_bar_new(); 11 | 12 | ======= 13 | Methods 14 | ======= 15 | Setting the value completed on the ProgressBar is made via:: 16 | 17 | gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progressbar), fraction); 18 | 19 | The *fraction* parameter should be a number between ``0.0`` and ``1.0``. 20 | 21 | Alternatively, the completion rate can be retrieved by:: 22 | 23 | gtk_progress_bar_get_fraction(GTK_PROGRESS_BAR(progressbar)); 24 | 25 | Text can be displayed within the ProgressBar and set using:: 26 | 27 | gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progressbar), text); 28 | 29 | The text displayed inside the ProgressBar can be made visible or not via:: 30 | 31 | gtk_progress_bar_set_show_text(GTK_PROGRESS_BAR(progressbar), show_text); 32 | 33 | If *show_text* is set to ``TRUE`` but no text string has been defined, the ProgressBar will display the value of the ``set_fraction()`` method. 34 | 35 | If it is unknown how long is left until a task is completed, the ProgressBar can be made to pulse to indicate that the program is still responsive:: 36 | 37 | gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progressbar), pulse); 38 | 39 | The operation of a ProgressBar usually grows from left-to-right if horizontal, or top-to-bottom if vertical. This can be inverted by calling:: 40 | 41 | gtk_progress_bar_set_inverted(GTK_PROGRESS_BAR(progressbar), inverted); 42 | 43 | ======= 44 | Example 45 | ======= 46 | Below is an example of a ProgressBar: 47 | 48 | .. literalinclude:: _examples/progressbar.c 49 | 50 | Download: :download:`ProgressBar <_examples/progressbar.c>` 51 | -------------------------------------------------------------------------------- /revealer.rst: -------------------------------------------------------------------------------- 1 | Revealer 2 | ======== 3 | The Revealer container is similar to a :doc:`expander` in that it provides an expandable/collapsable frame in which to place a child widget. Typically widgets added here are seldom used by the end-user. They are also used for advanced features which shouldn't be shown to users unless they specifically ask for them. 4 | 5 | =========== 6 | Constructor 7 | =========== 8 | The construction of the Revealer widget is made using:: 9 | 10 | GtkWidget *revealer = gtk_revealer_new(); 11 | 12 | ======= 13 | Methods 14 | ======= 15 | The child contained in the Revealer can be programatically shown using:: 16 | 17 | gtk_revealer_set_reveal_child(GTK_REVEALER(revealer), reveal); 18 | 19 | When *reveal* is set to ``TRUE``, the animation runs and the child is displayed. 20 | 21 | The state of the Revealer can also be obtained via:: 22 | 23 | gtk_revealer_get_reveal_child(GTK_REVEALER(revealer)); 24 | 25 | Customisation of the animation transition can be changed with:: 26 | 27 | gtk_revealer_set_transition_duration(GTK_REVEALER(revealer), duration); 28 | 29 | The *duration* value should be specified in milliseconds. 30 | 31 | A transition type can be defined for the Revealer by calling:: 32 | 33 | gtk_revealer_set_transitiion_type(GTK_REVEALER(revealer), transition); 34 | 35 | The *transition* value should be set to one of the following: 36 | 37 | * ``GTK_REVEALER_TRANSITION_TYPE_NONE`` - no transition 38 | * ``GTK_REVEALER_TRANSITION_TYPE_CROSSFADE`` - fade in 39 | * ``GTK_REVEALER_TRANSITION_TYPE_SLIDE_RIGHT`` - slide in from left 40 | * ``GTK_REVEALER_TRANSITION_TYPE_SLIDE_LEFT`` - slide in from right 41 | * ``GTK_REVEALER_TRANSITION_TYPE_SLIDE_UP`` - slide in from bottom 42 | * ``GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN`` - slide in from top 43 | 44 | ======= 45 | Example 46 | ======= 47 | Below is an example of a Revealer: 48 | 49 | .. literalinclude:: _examples/revealer.c 50 | 51 | Download: :download:`Revealer <_examples/revealer.c>` 52 | -------------------------------------------------------------------------------- /scale.rst: -------------------------------------------------------------------------------- 1 | Scale 2 | ===== 3 | The Scale widget provides a way to adjust a slider to output a number between a minimum and maximum range. 4 | 5 | =========== 6 | Constructor 7 | =========== 8 | A Scale widget is constructed by the call:: 9 | 10 | GtkWidget *scale = gtk_scale_new(); 11 | 12 | ======= 13 | Methods 14 | ======= 15 | The value of the Scale is retrievable using:: 16 | 17 | gtk_scale_get_value(GTK_SCALE(scale)); 18 | 19 | Values can also be set onto the Scale with the method:: 20 | 21 | gtk_scale_set_value(GTK_SCALE(scale), value); 22 | 23 | The *value* will need to be a number in between the minimum and maximum range allowance. If the number is outside of this range, the value will be wrapped to the nearest minimum or maximum. 24 | 25 | By default, the current value held by the Scale is drawn on above the marker. This can be configured using:: 26 | 27 | gtk_scale_set_draw_value(GTK_SCALE(scale), draw_value); 28 | 29 | The position of the drawn value is customisable with the method:: 30 | 31 | gtk_scale_set_value_pos(GTK_SCALE(scale), position); 32 | 33 | The *position* argument should be set to one of the following constants: 34 | 35 | * ``GTK_POS_LEFT`` 36 | * ``GTK_POS_RIGHT`` 37 | * ``GTK_POS_TOP`` 38 | * ``GTK_POS_BOTTOM`` 39 | 40 | The number of decimal places displayed on the Scale value is set with:: 41 | 42 | gtk_scale_set_digits(GTK_SCALE(scale), digits); 43 | 44 | The *digits* value can be set to ``0`` to ensure an integer value is displayed on screen. 45 | 46 | An indicator mark can be added to the Scale via:: 47 | 48 | gtk_scale_add_mark(GTK_SCALE(scale), value, position, markup); 49 | 50 | The *value* argument is the value at which the mark should be placed on the Scale. The *markup* parameter can be set to ``NULL`` if not required, or alternatively a string of text to be displayed alongside the mark, typically as an identifier for the purpose of the mark. Finally, the position is settable to one of the constants: 51 | 52 | * ``GTK_POS_LEFT`` 53 | * ``GTK_POS_RIGHT`` 54 | * ``GTK_POS_TOP`` 55 | * ``GTK_POS_BOTTOM`` 56 | 57 | Marks can be cleared from the Scale with the call:: 58 | 59 | gtk_scale_clear_marks(GTK_SCALE(scale)); 60 | 61 | ======= 62 | Example 63 | ======= 64 | Below is an example of a Scale: 65 | 66 | .. literalinclude:: _examples/scale.c 67 | 68 | Download: :download:`Scale <_examples/scale.c>` 69 | -------------------------------------------------------------------------------- /scalebutton.rst: -------------------------------------------------------------------------------- 1 | ScaleButton 2 | =========== 3 | The ScaleButton provides a small button which when clicked, displays a popup containing a slider similar to a :doc:`scale` widget. The widget is commonly used where space in the interface is at a premium and a normal Scale widget would be too large. 4 | 5 | =========== 6 | Constructor 7 | =========== 8 | The ScaleButton is constructable via the call:: 9 | 10 | GtkWidget *scalebutton = gtk_scale_button_new(size, minimum, maximum, step, icons); 11 | 12 | A *minimum* and *maximum* value should be set to provide the range within which the ScaleButton operates. A *step* value indicates the amount of change the slider makes. The *icons* argument shoud be a list of icons which will be displayed as the slider is changed, or alternatively this can be set to ``NULL`` at construction time. The *size* parameter indicates the size allocated to the icon and should be set to one of: 13 | 14 | * ``GTK_ICON_SIZE_MENU`` 15 | * ``GTK_ICON_SIZE_SMALL_TOOLBAR`` 16 | * ``GTK_ICON_SIZE_LARGE_TOOLBAR`` 17 | * ``GTK_ICON_SIZE_BUTTON`` 18 | * ``GTK_ICON_SIZE_DND`` 19 | * ``GTK_ICON_SIZE_DIALOG`` 20 | 21 | ======= 22 | Methods 23 | ======= 24 | The value currently set on the ScaleButton can be retrieved with:: 25 | 26 | gtk_scale_button_get_value(GTK_SCALE_BUTTON(scalebutton)); 27 | 28 | Alternatively, a value is able to be programatically set using:: 29 | 30 | gtk_scale_button_set_value(GTK_SCALE_BUTTON(scalebutton), value); 31 | 32 | The icons used by the ScaleButton are customisable with:: 33 | 34 | gtk_scale_button_set_icons(GTK_SCALE_BUTTON(scalebutton), icons); 35 | 36 | Icons are displayed via the *icons* parameter on the ScaleButton to indicate the current status of the value. This is set with the use of a list. It is recommended that at least three icons are specified, with each icon being used to indicate a different value. For example, it two icons are in use then the bottom 50% of the slider will show the first icon, and the top 50% will show the second. 37 | 38 | The ScaleButton can also be associated with an :doc:`adjustment` object via:: 39 | 40 | gtk_scale_button_set_adjustment(GTK_SCALE_BUTTON(scalebutton), adjustment); 41 | 42 | The Adjustment object can also be fetched with the method:: 43 | 44 | gtk_scale_button_get_adjustment(GTK_SCALE_BUTTON(scalebutton)); 45 | 46 | ======= 47 | Example 48 | ======= 49 | Below is an example of a ScaleButton: 50 | 51 | .. literalinclude:: _examples/scalebutton.c 52 | 53 | Download: :download:`ScaleButton <_examples/scalebutton.c>` 54 | -------------------------------------------------------------------------------- /searchentry.rst: -------------------------------------------------------------------------------- 1 | SearchEntry 2 | =========== 3 | The SearchEntry is a subclass of the :doc:`entry` widget, which is tailored for used to search for data within the application. 4 | 5 | =========== 6 | Constructor 7 | =========== 8 | The constructor for the SearchEntry is:: 9 | 10 | GtkWidget *searchentry = gtk_search_entry_new(); 11 | 12 | ======= 13 | Example 14 | ======= 15 | Below is an example of a SearchEntry: 16 | 17 | .. literalinclude:: _examples/searchentry.c 18 | 19 | Download: :download:`SearchEntry <_examples/searchentry.c>` 20 | -------------------------------------------------------------------------------- /separator.rst: -------------------------------------------------------------------------------- 1 | Separator 2 | ========= 3 | The Separator widget provides a way to add a vertical or horizontal line to the interface, providing a visual divider between content. 4 | 5 | .. note:: 6 | 7 | The use of Separator widgets can be visually distracting if overused, and should only be used when absolutely necessary. In many cases, it may be best to use a :doc:`commonframe`. 8 | 9 | =========== 10 | Constructor 11 | =========== 12 | The Separator is constructed via:: 13 | 14 | GtkWidget *separator = gtk_separator_new(orientation); 15 | 16 | The *orientation* value should be set to one of the following: 17 | 18 | * ``GTK_ORIENTATION_VERTICAL`` 19 | * ``GTK_ORIENTATION_HORIZONTAL`` 20 | 21 | ======= 22 | Methods 23 | ======= 24 | To set the orientation of the Separator after construction use:: 25 | 26 | gtk_widget_set_orientation(GTK_WIDGET(separator), orientation); 27 | 28 | ======= 29 | Example 30 | ======= 31 | Below is an example of a Separator: 32 | 33 | .. literalinclude:: _examples/separator.c 34 | 35 | Download: :download:`Separator <_examples/separator.c>` 36 | -------------------------------------------------------------------------------- /spinbutton.rst: -------------------------------------------------------------------------------- 1 | SpinButton 2 | ========== 3 | A SpinButton allows for adjustments in numerical values either by adjustment buttons or entering text via the keyboard. 4 | 5 | =========== 6 | Constructor 7 | =========== 8 | A ComboBoxText is constructed with the call:: 9 | 10 | gtk_spin_button_new(adjustment, climb_rate, digits); 11 | 12 | The *adjustment* parameter can be set to an :doc:`adjustment` object which handles the currently set value and minimum and maximum values. The *climb_rate* should be set to a value indicating how much the SpinButton changes when adjusted. Finally, the *digits* parameter specifies how many decimal places should be displayed, with setting ``0`` showing only whole numbers. 13 | 14 | An alternative constructor which specifies a range at initialisation is also available:: 15 | 16 | gtk_spin_button_new_with_range(minimum, maximum, step); 17 | 18 | The *minimum* and *maximum* values indicate the lowest and highest accepted values in the SpinButton. The *step* value controls the adjustment amount when the user clicks the adjustment buttons. 19 | 20 | ======= 21 | Methods 22 | ======= 23 | The value set on the SpinButton is set using:: 24 | 25 | gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbutton), value); 26 | 27 | Retrieval of the SpinButton value is retrieved via two functions:: 28 | 29 | gtk_spin_button_get_value(GTK_SPIN_BUTTON(spinbutton)); 30 | gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinbutton)); 31 | 32 | The ``get_value()`` method returns a double type number. Alternatively, an integer value can be returned using ``get_value_as_int()``. 33 | 34 | Limiting the range of numbers which can be entered is done with the call:: 35 | 36 | gtk_spin_button_set_range(GTK_SPIN_BUTTON(spinbutton), minimum, maximum); 37 | 38 | The amount the value in the SpinButton changes which clicking on the adjustment buttons can be changed with:: 39 | 40 | gtk_spin_button_set_increments(GTK_SPIN_BUTTON(spinbutton), step, page); 41 | 42 | The *step* value is the amount to change when left-clicking on the adjustment buttons. The *page* value is used when the adjustment buttons are middle-clicked. 43 | 44 | In some cases, it may be useful to limit the SpinButton value to the nearest step value. This is done with:: 45 | 46 | gtk_spin_button_set_snap_to_ticks(GTK_SPIN_BUTTON(spinbutton), snap_to_ticks); 47 | 48 | When *snap_to_ticks* is set to ``TRUE``, the SpinButton will wrap to the nearest acceptable value. 49 | 50 | ======= 51 | Example 52 | ======= 53 | Below is an example of a SpinButton: 54 | 55 | .. literalinclude:: _examples/spinbutton.c 56 | 57 | Download: :download:`SpinButton <_examples/spinbutton.c>` 58 | -------------------------------------------------------------------------------- /spinner.rst: -------------------------------------------------------------------------------- 1 | Spinner 2 | ======= 3 | A Spinner widget provides an animated spinning ticker which is used to indicate activity within the application. Examples of their usage include the loading of a webpage or waiting for a process to complete. 4 | 5 | Using a Spinner is often preferred when the time taken to complete the job is unknown. If the user should know how long is remaining, it is best to use a :doc:`progressbar`. 6 | 7 | =========== 8 | Constructor 9 | =========== 10 | The construction of the Spinner is done using:: 11 | 12 | GtkWidget *spinner = gtk_spinner_new(); 13 | 14 | ======= 15 | Methods 16 | ======= 17 | The Spinner has two methods to start and stop the animation:: 18 | 19 | gtk_spinner_start(GTK_SPINNER(spinner)); 20 | gtk_spinner_stop(GTK_SPINNER(spinner)); 21 | 22 | ======= 23 | Example 24 | ======= 25 | Below is an example of a Spinner: 26 | 27 | .. literalinclude:: _examples/spinner.c 28 | 29 | Download: :download:`Spinner <_examples/spinner.c>` 30 | -------------------------------------------------------------------------------- /stack.rst: -------------------------------------------------------------------------------- 1 | Stack 2 | ===== 3 | The Stack widget is similar to a :doc:`notebook` by showing only one child at a time. 4 | 5 | The Stack on its own does not provide any way for the user to change which child is visible, so if this functionality is required, the :doc:`stackswitcher` should be also used. 6 | 7 | =========== 8 | Constructor 9 | =========== 10 | The construction for the Stack is made with:: 11 | 12 | GtkWidget *stack = gtk_stack_new(); 13 | 14 | ======= 15 | Methods 16 | ======= 17 | A child can be added to the Stack using:: 18 | 19 | gtk_stack_add_named(GTK_STACK(stack), child, name); 20 | gtk_stack_add_titled(GTK_STACK(stack), child, name, title); 21 | 22 | The *child* parameter should be specified, with a typical child being a container. The *name* parameter is specified to identify the child. The *title* argument is displayed on the StackSwitcher if in use. 23 | 24 | The visible child can be set by declaring the child and name using:: 25 | 26 | gtk_stack_set_visible_child(GTK_STACK(stack), child); 27 | gtk_stack_set_visible_child_name(GTK_STACK(stack), name); 28 | 29 | The currently visible child and name can be retrieved using the methods:: 30 | 31 | gtk_stack_get_visible_child(GTK_STACK(stack)); 32 | gtk_stack_get_visible_child_name(GTK_STACK(stack)); 33 | 34 | The Stack can be made homogeneous, with the same size requested for all children with:: 35 | 36 | gtk_stack_set_homogeneous(GTK_STACK(stack), homogeneous); 37 | 38 | The vertical and horizontal homogeneous setting can be controlled individually via:: 39 | 40 | gtk_stack_set_vhomogeneous(GTK_STACK(stack), homogeneous); 41 | gtk_stack_set_hhomogeneous(GTK_STACK(stack), homogeneous); 42 | 43 | Configuration of the Stack widget transitions can be set by:: 44 | 45 | gtk_stack_set_transition_type(GTK_STACK(stack), transition); 46 | 47 | The *transition* value can be set to any of the following: 48 | 49 | * ``Gtk.StackTransitionType.NONE`` 50 | * ``Gtk.StackTransitionType.CROSSFADE`` 51 | * ``Gtk.StackTransitionType.SLIDE_RIGHT`` 52 | * ``Gtk.StackTransitionType.SLIDE_LEFT`` 53 | * ``Gtk.StackTransitionType.SLIDE_UP`` 54 | * ``Gtk.StackTransitionType.SLIDE_DOWN`` 55 | * ``Gtk.StackTransitionType.SLIDE_LEFT_RIGHT`` 56 | * ``Gtk.StackTransitionType.SLIDE_UP_DOWN`` 57 | * ``Gtk.StackTransitionType.OVER_UP`` 58 | * ``Gtk.StackTransitionType.OVER_DOWN`` 59 | * ``Gtk.StackTransitionType.OVER_LEFT`` 60 | * ``Gtk.StackTransitionType.OVER_RIGHT`` 61 | * ``Gtk.StackTransitionType.UNDER_UP`` 62 | * ``Gtk.StackTransitionType.UNDER_DOWN`` 63 | * ``Gtk.StackTransitionType.UNDER_LEFT`` 64 | * ``Gtk.StackTransitionType.UNDER_RIGHT`` 65 | * ``Gtk.StackTransitionType.OVER_UP_DOWN`` 66 | * ``Gtk.StackTransitionType.OVER_DOWN_UP`` 67 | * ``Gtk.StackTransitionType.OVER_LEFT_RIGHT`` 68 | * ``Gtk.StackTransitionType.OVER_RIGHT_LEFT`` 69 | 70 | Transition animation times can also be set by calling:: 71 | 72 | gtk_stack_set_transition_duration(GTK_STACK(stack), duration); 73 | 74 | The *duration* parameter should be specified in milliseconds. 75 | 76 | ======= 77 | Example 78 | ======= 79 | Below is an example of a Stack: 80 | 81 | .. literalinclude:: _examples/stack.c 82 | 83 | Download: :download:`Stack <_examples/stack.c>` 84 | -------------------------------------------------------------------------------- /stacksidebar.rst: -------------------------------------------------------------------------------- 1 | StackSidebar 2 | ============ 3 | The StackSidebar can be connected to the :doc:`stack` to provide a sidebar for switching between the children contained in the Stack. 4 | 5 | =========== 6 | Constructor 7 | =========== 8 | A StackSidebar is constructed using:: 9 | 10 | stacksidebar = gtk_stack_sidebar_new(); 11 | 12 | ======= 13 | Methods 14 | ======= 15 | To associate the Stack with the StackSidebar call:: 16 | 17 | stacksidebar.set_stack(stack) 18 | 19 | Retrieval of the Stack associated can be made via:: 20 | 21 | stacksidebar.get_stack() 22 | 23 | ======= 24 | Example 25 | ======= 26 | Below is an example of a StackSidebar: 27 | 28 | .. literalinclude:: _examples/stacksidebar.c 29 | 30 | Download: :download:`StackSidebar <_examples/stacksidebar.c>` 31 | -------------------------------------------------------------------------------- /stackswitcher.rst: -------------------------------------------------------------------------------- 1 | StackSwitcher 2 | ============= 3 | A StackSwitcher is an object associated with a :doc:`stack` to provide an interface to switch children in the Stack. The layout provides a horizontal bar with a button for each child in the Stack. 4 | 5 | =========== 6 | Constructor 7 | =========== 8 | The StackSwitcher can be constructed via:: 9 | 10 | stackswitcher = gtk_stack_switcher_new(); 11 | 12 | ======= 13 | Methods 14 | ======= 15 | The StackSwitcher can be attached to the Stack via:: 16 | 17 | stackswitcher.set_stack(stack) 18 | 19 | Retrival of the associated Stack object can be made using:: 20 | 21 | stackswitcher.get_stack() 22 | 23 | ======= 24 | Example 25 | ======= 26 | Below is an example of a StackSwitcher: 27 | 28 | .. literalinclude:: _examples/stackswitcher.c 29 | 30 | Download: :download:`StackSwitcher <_examples/stackswitcher.c>` 31 | -------------------------------------------------------------------------------- /statusbar.rst: -------------------------------------------------------------------------------- 1 | Statusbar 2 | ========= 3 | The Statusbar is seen in a variety of applications such as file managers and text editors. It is commonly used to display status messages such as whether a connection is up or down, or the column and line number. 4 | 5 | Messages are pushed and popped from the Statusbar in a stack-like fashion. This means that the first message on is the last message off. Different message types can also have different contexts, allowing the management of multiple stacks of messages. 6 | 7 | =========== 8 | Constructor 9 | =========== 10 | Construction of the Statusbar object is made using:: 11 | 12 | GtkWidget *statusbar = gtk_statusbar_new(); 13 | 14 | ======= 15 | Methods 16 | ======= 17 | Once the Statusbar has been constructed, the context which identifies a particular group of messages can be retrieved:: 18 | 19 | context_id = gtk_statusbar_get_context_id(GTK_STATUSBAR(statusbar), context); 20 | 21 | The *context* parameter should be a textual description of the Statusbar messages to be displayed. The ``get_context_id()`` method can be called many times with different context descriptions for differing message types. The method returns an integer which is used by a number of other methods to control the display. 22 | 23 | To add a message to the Statusbar, call:: 24 | 25 | message_id = gtk_statusbar_push(GTK_STATUSBAR(statusbar), context_id, message); 26 | 27 | The *context_id* parameter should be set ot the appropriate context in which the *message* parameter text will be added. The method returns a unique *message_id* which identifies the pushed message. 28 | 29 | Messages can be taken of the stack via:: 30 | 31 | gtk_statusbar_pop(GTK_STATUSBAR(statusbar), context_id); 32 | 33 | An individual message can be completely removed with the call:: 34 | 35 | gtk_statusbar_remove(GTK_STATUSBAR(statusbar), context_id, message_id); 36 | 37 | The *context_id* and *message_id* should be set for the correct message to use. Incorrect setting of one may remove an incorrect message. 38 | 39 | All the messages held by the Statusbar can be removed with:: 40 | 41 | gtk_statusbar_remove_all(GTK_STATUSBAR(statusbar), context_id); 42 | 43 | The *context_id* value indicates which context all the messages should be removed from. 44 | 45 | ======= 46 | Signals 47 | ======= 48 | 49 | ======= 50 | Example 51 | ======= 52 | Below is an example of a Statusbar: 53 | 54 | .. literalinclude:: _examples/statusbar.c 55 | 56 | Download: :download:`Statusbar <_examples/statusbar.c>` 57 | -------------------------------------------------------------------------------- /switch.rst: -------------------------------------------------------------------------------- 1 | Switch 2 | ====== 3 | A Switch widget is a simple On/Off state toggle. It is commonly used to represent the state of physical items such as the state of a wireless network connection. 4 | 5 | =========== 6 | Constructor 7 | =========== 8 | The constructor for the Switch is:: 9 | 10 | GtkWidget *switch = gtk_switch_new(); 11 | 12 | ======= 13 | Methods 14 | ======= 15 | To retrieve whether the Switch is active (on) or inactive (off), call:: 16 | 17 | gtk_switch_get_active(GTK_SWITCH(switch)); 18 | 19 | If the Switch is on, ``TRUE`` will be returned, otherwise ``FALSE`` is returned. 20 | 21 | The state of the Switch can be set programatically with:: 22 | 23 | gtk_switch_set_active(GTK_SWITCH(switch), state); 24 | 25 | ======= 26 | Example 27 | ======= 28 | Below is an example of a Switch: 29 | 30 | .. literalinclude:: _examples/switch.c 31 | 32 | Download: :download:`Switch <_examples/switch.c>` 33 | -------------------------------------------------------------------------------- /togglebutton.rst: -------------------------------------------------------------------------------- 1 | ToggleButton 2 | ============ 3 | A ToggleButton has the appearance of a standard :doc:`button` widget however it is able to have an on or off state. Its functionality is similar to a :doc:`checkbutton`. 4 | 5 | =========== 6 | Constructor 7 | =========== 8 | A ToggleButton is constructed with the call:: 9 | 10 | gtk_toggle_button_new(); 11 | 12 | The ToggleButton is also able to be constructed with a label:: 13 | 14 | gtk_toggle_button_new_with_label(label); 15 | 16 | An associated mnemonic accelerator can be added at construction with:: 17 | 18 | gtk_toggle_button_new_with_mnemonic(label); 19 | 20 | ======= 21 | Methods 22 | ======= 23 | The active state can be set on the ToggleButton using the method:: 24 | 25 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(togglebutton), active); 26 | 27 | Retrieving the state from the ToggleButton is done with:: 28 | 29 | gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(togglebutton)); 30 | 31 | The label displayed on the ToggleButton can be changed via:: 32 | 33 | gtk_toggle_button_set_label(GTK_TOGGLE_BUTTON(togglebutton), label); 34 | 35 | ======= 36 | Signals 37 | ======= 38 | 39 | 40 | ======= 41 | Example 42 | ======= 43 | Below is an example of a ToggleButton: 44 | 45 | .. literalinclude:: _examples/togglebutton.c 46 | 47 | Download: :download:`ToggleButton <_examples/togglebutton.c>` 48 | -------------------------------------------------------------------------------- /toolbar.rst: -------------------------------------------------------------------------------- 1 | Toolbar 2 | ======= 3 | A Toolbar is common in applications to provide access to common tasks. It takes the form of a horizontal bar with icons inserted which the user can quickly access. Common uses include opening and saving files, change font sizes, or launching a search function. 4 | 5 | ======= 6 | Methods 7 | ======= 8 | Insertion of items into the Toolbar is made using:: 9 | 10 | gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, position); 11 | 12 | The *item* value should be that of the item to be added. The *position* specifies the location on the Toolbar of the item being inserted, with ``0`` indicating the first item. 13 | 14 | The particular item at a given location can be obtained via:: 15 | 16 | gtk_toolbar_get_nth_item(GTK_TOOLBAR(toolbar), position); 17 | 18 | The position index of a given item can also be retrieved:: 19 | 20 | gtk_toolbar_get_item_index(GTK_TOOLBAR(toolbar), item); 21 | 22 | Retrieval of the number of items held by the Toolbar can be done with:: 23 | 24 | gtk_toolbar_get_n_items(GTK_TOOLBAR(toolbar)); 25 | 26 | Typically, the Toolbar should match the set global settings with regards to displaying text beneath an icon, at the size, or displaying no text at all. The style can be set manually using:: 27 | 28 | gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), style); 29 | 30 | Setting of the *style* parameter should be one of the following: 31 | 32 | * ``GTK_TOOLBAR_ICONS`` - display only icons. 33 | * ``GTK_TOOLBAR_TEXT`` - display only text. 34 | * ``GTK_TOOLBAR_BOTH`` - display icons above text. 35 | * ``GTK_TOOLBAR_BOTH_HORIZ`` - display icons and text alongside each other. 36 | 37 | The style can be unset if required by:: 38 | 39 | gtk_toolbar_unset_style(GTK_TOOLBAR(toolbar)); 40 | 41 | As with style, the size of the icons should in most cases be handled globally. The size can however be configured manually with:: 42 | 43 | gtk_toolbar_set_icon_size(size); 44 | 45 | The *size* parameter should be one of the following:: 46 | 47 | * ``GTK_ICON_SIZE_MENU`` - 16 pixels. 48 | * ``GTK_ICON_SIZE_SMALL_TOOLBAR`` - 16 pixels. 49 | * ``GTK_ICON_SIZE_LARGE_TOOLBAR`` - 24 pixels. 50 | * ``GTK_ICON_SIZE_BUTTON`` - 16 pixels. 51 | * ``GTK_ICON_SIZE_DND`` - 32 pixels. 52 | * ``GTK_ICON_SIZE_DIALOG`` - 48 pixels. 53 | 54 | ======= 55 | Example 56 | ======= 57 | Below is an example of a Toolbar: 58 | 59 | .. literalinclude:: _examples/toolbar.c 60 | 61 | Download: :download:`Toolbar <_examples/toolbar.c>` 62 | -------------------------------------------------------------------------------- /toolpalette.rst: -------------------------------------------------------------------------------- 1 | ToolPalette 2 | =========== 3 | The ToolPalette is commonly used as an alternative to the :doc:`toolbar` in applications which make heavy user of tool items. The ToolPalette displays items in grids, which are grouped into common functionality. 4 | 5 | Common examples include graphics or video editing applications. 6 | 7 | =========== 8 | Constructor 9 | =========== 10 | The ToolPalette widget is constructed using:: 11 | 12 | GtkWidget *toolpalette = gtk_tool_palette_new(); 13 | 14 | ======= 15 | Methods 16 | ======= 17 | The ToolPalette is the container for :doc:`toolitemgroup` sub-containers, which actually hold the items. These are added to the ToolPalette by:: 18 | 19 | gtk_container_add(GTK_CONTAINER(toolpalette), toolitemgroup); 20 | 21 | By default, grouped items can be expanded and collapsed individually. To set a particular group to open exclusively, call:: 22 | 23 | gtk_tool_palette_set_exclusive(toolpalette, group, exclusive); 24 | 25 | The *group* parameter should be set to the :doc:`toolitemgroup` to be made exclusive. When the *exclusive* value is set to ``TRUE``, opening the exclusive group will collapse all other open groups. 26 | 27 | To programatically expand or collapse a ToolItemGroup use:: 28 | 29 | gtk_tool_palette_set_expand(toolpalette, expand); 30 | 31 | The position of a ToolItemGroup within the stack can be set with the positional value via:: 32 | 33 | gtk_tool_palette_set_group_position(toolpalette, group, position); 34 | 35 | The *group* value should be the name of the ToolItemGroup to be positioned, and the *position* value is a numerical value indicating the insert location, starting with ``0``. 36 | 37 | The icon size of items within each ToolItemGroup is configurable with:: 38 | 39 | gtk_tool_palette_set_icon_size(toolpalette, size); 40 | 41 | The *size* value should be set to one of: 42 | 43 | * ``GTK_ICON_SIZE_INVALID`` 44 | * ``GTK_ICON_SIZE_MENU`` (16 pixels) 45 | * ``GTK_ICON_SIZE_SMALL_TOOLBAR`` (16 pixels) 46 | * ``GTK_ICON_SIZE_LARGE_TOOLBAR`` (24 pixels) 47 | * ``GTK_ICON_SIZE_BUTTON`` (16 pixels) 48 | * ``GTK_ICON_SIZE_DND`` (32 pixels) 49 | * ``GTK_ICON_SIZE_DIALOG`` (48 pixels) 50 | 51 | ======= 52 | Example 53 | ======= 54 | Below is an example of a ToolPalette: 55 | 56 | .. literalinclude:: _examples/toolpalette.c 57 | 58 | Download: :download:`ToolPalette <_examples/toolpalette.c>` 59 | -------------------------------------------------------------------------------- /treestore.rst: -------------------------------------------------------------------------------- 1 | TreeStore 2 | ========= 3 | A TreeStore is similar to a :doc:`liststore`, however it allows items to be inserted at sublevels to other items rather than simply as a flat list. It is most commonly used alongside :doc:`treeview` widgets, and is able to store a number of data types including text, values, and images. As with the ListStore, the object is not visible. 4 | 5 | =========== 6 | Constructor 7 | =========== 8 | The constructor for the TreeStore object is:: 9 | 10 | GtkTreeStore *treestore = gtk_treestore_new(columns, type, type, type...); 11 | 12 | The *columns* parameter indicates the number of columns the TreeStore will hold. A matching number of *type* declarations can then be supplied which indicate what type of data will be stored in each column. The types permissible include:: 13 | 14 | * ``G_TYPE_STRING`` 15 | * ``G_TYPE_INT`` 16 | * ``G_TYPE_FLOAT`` 17 | * ``G_TYPE_DOUBLE`` 18 | * ``G_TYPE_BOOLEAN`` 19 | * ``G_TYPE_CHAR`` 20 | * ``G_TYPE_OBJECT`` 21 | 22 | ======= 23 | Example 24 | ======= 25 | Below is an example of a TreeStore: 26 | 27 | .. literalinclude:: _examples/treestore.c 28 | 29 | Download: :download:`TreeStore <_examples/treestore.c>` 30 | -------------------------------------------------------------------------------- /window.rst: -------------------------------------------------------------------------------- 1 | Window 2 | ====== 3 | The Window is the basis of most applications created using GTK+. It is the widget which provides the framework on which other widgets ca be added. Therefore it is known as a container widget. 4 | 5 | By itself, a Window can only pack a single widget within its container. 6 | 7 | =========== 8 | Constructor 9 | =========== 10 | The Window can be constructed using:: 11 | 12 | GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 13 | 14 | ======= 15 | Methods 16 | ======= 17 | The title of the Window can be set using the following method:: 18 | 19 | gtk_window_set_title(GTK_WINDOW(window), "Window"); 20 | 21 | By default, the Window is not shown by GTK+. This needs to be called explicitly with:: 22 | 23 | gtk_widget_show(window); 24 | 25 | Using the ``show()`` call will only display the window, with other widgets subsequently needing their own ``show()`` calls to be displayed. An alternative is to use:: 26 | 27 | gtk_widget_show_all(window); 28 | 29 | .. note:: 30 | 31 | It is recommended to use the ``gtk_widget_show_all(window)`` method once all the widgets have been added to the interface. This ensures that on very slow machines, the window displays all widgets at once rather than a blank window, and all other widgets added as they are processed. 32 | 33 | Window widgets can also be hidden again with:: 34 | 35 | gtk_widget_hide(window); 36 | 37 | ======= 38 | Example 39 | ======= 40 | Below is an example of a Window: 41 | 42 | .. literalinclude:: _examples/window.c 43 | 44 | Download: :download:`Window <_examples/window.c>` 45 | --------------------------------------------------------------------------------