Add gtk51

This commit is contained in:
daleclack 2021-03-20 13:02:37 +08:00
parent fd2750a7c9
commit 6c4ca77cec
5 changed files with 274 additions and 0 deletions

View File

@ -0,0 +1,59 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
//For linux amd64 and linux on arm64,some include path may different
//Commet and uncomment these lines to compile on a specificed archtiecture
//Arm64 linux libs
/*
"/usr/lib/aarch64-linux-gnu/dbus-1.0/include/**",
"/usr/lib/aarch64-linux-gnu/glib-2.0/include",
*/
//amd64 linux libs(For ubuntu)
/*
"/usr/lib/x86_64-linux-gnu/dbus-1.0/include",
"/usr/lib/x86_64-linux-gnu/glib-2.0/include",
*/
//For debian and ubuntu,kali
/*
"/usr/include/gtk-3.0/gtk/**",
"/usr/include/uuid/**",
*/
//For manjaro(Arch linux)
"/usr/lib/dbus-1.0/include/**",
"/usr/lib/glib-2.0/include/**",
"/usr/include/lzo/**",
"/usr/include/cloudproviders/**",
"${workspaceFolder}/**",
"/usr/include/gtk-3.0/**",
"/usr/include/at-spi2-atk/2.0/**",
"/usr/include/at-spi-2.0/**",
"/usr/include/dbus-1.0/**",
"/usr/include/gio-unix-2.0/**",
"/usr/include/cairo/**",
"/usr/include/pango-1.0/**",
"/usr/include/fribidi/**",
"/usr/include/harfbuzz/**",
"/usr/include/atk-1.0/**",
"/usr/include/pixman-1/**",
"/usr/include/freetype2/**",
"/usr/include/libpng16/**",
"/usr/include/gdk-pixbuf-2.0/**",
"/usr/include/libmount/**",
"/usr/include/blkid/**",
"/usr/include/glib-2.0/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "gcc-arm64",
"compilerArgs": [
"`pkg-config --cflags --libs gtk+-3.0`"
],
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}

29
Gtk3/gtk51_treeview/.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,29 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++ - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/bin/gtk51",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++ build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}

View File

@ -0,0 +1,4 @@
{
"C_Cpp.errorSquiggles": "Disabled",
"cmake.configureOnOpen": false
}

82
Gtk3/gtk51_treeview/.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,82 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"src/*.cpp",
"-o",
"${workspaceFolder}/bin/gtk51",
"-pthread",
//For Arm64 linux
/*
"-I/usr/lib/aarch64-linux-gnu/dbus-1.0/include",
"-I/usr/lib/aarch64-linux-gnu/glib-2.0/include",
*/
//For amd64 linux
/*
"-I/usr/lib/x86_64-linux-gnu/dbus-1.0/include",
"-I/usr/lib/x86_64-linux-gnu/glib-2.0/include",
*/
//Ubuntu and kali include paths
/*
"-I/usr/include/uuid",
*/
//Manjaro linux and Arch linux include args
"-I${workspaceFolder}",
"-I/usr/lib/glib-2.0/include",
"-I/usr/lib/dbus-1.0/include",
"-I/usr/include/lzo",
"-I/usr/include/cloudproviders",
"-I/usr/include/gtk-3.0",
"-I/usr/include/at-spi2-atk/2.0",
"-I/usr/include/at-spi-2.0",
"-I/usr/include/dbus-1.0",
"-I/usr/include/gio-unix-2.0",
"-I/usr/include/cairo",
"-I/usr/include/pango-1.0",
"-I/usr/include/fribidi",
"-I/usr/include/harfbuzz",
"-I/usr/include/atk-1.0",
"-I/usr/include/pixman-1",
"-I/usr/include/freetype2",
"-I/usr/include/libpng16",
"-I/usr/include/gdk-pixbuf-2.0",
"-I/usr/include/libmount",
"-I/usr/include/blkid",
"-I/usr/include/glib-2.0",
//Manjaro linux lib args
"-lz",
"-lgtk-3",
"-lgdk-3",
"-lpangocairo-1.0",
"-lpango-1.0",
"-lharfbuzz",
"-latk-1.0",
"-lcairo-gobject",
"-lcairo",
"-lgdk_pixbuf-2.0",
"-lgio-2.0",
"-lgobject-2.0",
"-lglib-2.0",
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}

View File

@ -0,0 +1,100 @@
#include <gtk/gtk.h>
enum{
COLUMN = 0,
NUM_COLS
};
void on_changed(GtkTreeSelection *select,GtkStatusbar *status){
GtkTreeIter iter;
GtkTreeModel *model;
char *str;
if(gtk_tree_selection_get_selected(select,&model,&iter)){
gtk_tree_model_get(model,&iter,COLUMN,&str,-1);
gtk_statusbar_push(status,gtk_statusbar_get_context_id(status,str),str);
g_free(str);
}
}
static GtkTreeModel *create_model(void){
//Create a treestore and fill the store
GtkTreeStore *treestore;
GtkTreeIter toplevel,child;
treestore=gtk_tree_store_new(NUM_COLS,G_TYPE_STRING);
gtk_tree_store_append(treestore,&toplevel,NULL);
gtk_tree_store_set(treestore,&toplevel,COLUMN,"List 1",-1);
gtk_tree_store_append(treestore,&child,&toplevel);
gtk_tree_store_set(treestore,&child,COLUMN,"Item 1",-1);
gtk_tree_store_append(treestore,&child,&toplevel);
gtk_tree_store_set(treestore,&child,COLUMN,"Item 2",-1);
gtk_tree_store_append(treestore,&child,&toplevel);
gtk_tree_store_set(treestore,&child,COLUMN,"Item 3",-1);
gtk_tree_store_append(treestore,&child,&toplevel);
gtk_tree_store_set(treestore,&child,COLUMN,"Item 4",-1);
gtk_tree_store_append(treestore,&toplevel,NULL);
gtk_tree_store_set(treestore,&toplevel,COLUMN,"List 2",-1);
gtk_tree_store_append(treestore,&child,&toplevel);
gtk_tree_store_set(treestore,&child,COLUMN,"Item 5",-1);
gtk_tree_store_append(treestore,&child,&toplevel);
gtk_tree_store_set(treestore,&child,COLUMN,"Item 6",-1);
gtk_tree_store_append(treestore,&child,&toplevel);
gtk_tree_store_set(treestore,&child,COLUMN,"Item 7",-1);
return GTK_TREE_MODEL(treestore);
}
static GtkWidget *create_view_and_model(void){
GtkTreeViewColumn *col;
GtkCellRenderer *render;
GtkTreeModel *model;
GtkWidget *view;
//Create a treeview widget
view=gtk_tree_view_new();
//Append column to show selection
col=gtk_tree_view_column_new();
gtk_tree_view_column_set_title(col,"Tree List");
gtk_tree_view_append_column(GTK_TREE_VIEW(view),col);
//renderer to shoe the text
render=gtk_cell_renderer_text_new();
gtk_tree_view_column_pack_start(col,render,TRUE);
gtk_tree_view_column_add_attribute(col,render,"text",COLUMN);
//model as a store
model=create_model();
gtk_tree_view_set_model(GTK_TREE_VIEW(view),model);
g_object_unref(model);
return view;
}
static void gtkmain(GtkApplication *app,gpointer user_data){
GtkWidget *window,*treeview,*vbox,*statusbar,*sw;
GtkTreeSelection *select;
//Main window
window=gtk_application_window_new(app);
gtk_window_set_icon_name(GTK_WINDOW(window),"org.gtk.daleclack");
gtk_window_set_default_size(GTK_WINDOW(window),350,300);
//Veritcal box
vbox=gtk_box_new(GTK_ORIENTATION_VERTICAL,0);
//GtkTreeView
treeview=create_view_and_model();
//Scrolled window
sw=gtk_scrolled_window_new(NULL,NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC);
gtk_container_add(GTK_CONTAINER(sw),treeview);
gtk_box_pack_start(GTK_BOX(vbox),sw,TRUE,TRUE,0);
//Statusbar
statusbar=gtk_statusbar_new();
gtk_box_pack_end(GTK_BOX(vbox),statusbar,FALSE,TRUE,1);
//Selection
select=gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
g_signal_connect(select,"changed",G_CALLBACK(on_changed),statusbar);
gtk_container_add(GTK_CONTAINER(window),vbox);
gtk_widget_show_all(window);
}
int main(int argc,char **argv){
GtkApplication *app;
app=gtk_application_new("org.gtk.daleclack",G_APPLICATION_NON_UNIQUE);
g_signal_connect(app,"activate",G_CALLBACK(gtkmain),NULL);
return g_application_run(G_APPLICATION(app),argc,argv);
}