2007/1/27

GtkTreeView でツリー構造のリストを作ろう  GTK

ここでは GtkTreeView を使って簡単なツリー上のリストを作るプログラムを紹介します。

できあがりはこんな感じ↓。

クリックすると元のサイズで表示します


#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>

/* Column definition -- # of columns used here is 1 (= COL_NUM) */
enum { COL_NAME, COL_NUM };

/* Callback on "destroy" */
static void
DestroyCB(GtkWidget *widget, gpointer data)
{
gtk_main_quit();
}

/* main */
int
main(int argc, char **argv)
{
GtkWidget *window;
GtkTreeView *tree_view;
GtkTreeStore *store;
GtkCellRenderer *rend;
GtkTreeViewColumn *column;
GtkTreeIter root_iter, child_iter;
GtkTreePath *path;

gtk_init(&argc, &argv);

/* Create the main, top level, window */
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

/* Give it the title */
gtk_window_set_title(GTK_WINDOW(window), "GtkTreeView Test");

/* Open it a bit wider so that both the label and title show up */
//gtk_window_set_default_size(GTK_WINDOW(window), 200, 50);

/* Connect the destroy event of the window with our "quit on destroy"
function */
g_signal_connect(G_OBJECT(window), "destroy",
G_CALLBACK(DestroyCB), NULL);

/* Create a tree store for tree_view */
store = gtk_tree_store_new(COL_NUM, G_TYPE_STRING);

/* Create a tree view */
tree_view =
GTK_TREE_VIEW(gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)));
g_object_unref(store);
gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(tree_view));

/* Don't show the headers this time */
gtk_tree_view_set_headers_visible(tree_view, FALSE);

/* Get a tree store registered in tree_view */
store = GTK_TREE_STORE(gtk_tree_view_get_model(tree_view));

/* Column - name */
column = gtk_tree_view_column_new();
rend = gtk_cell_renderer_text_new();
g_object_set(rend, "ypad", 0, NULL);
//gtk_tree_view_column_set_title(column, "Tree");
gtk_tree_view_column_pack_start(column, rend, FALSE);
gtk_tree_view_column_set_attributes(column, rend, "text", COL_NAME,
NULL);
gtk_tree_view_append_column(tree_view, column);

/* Add root date to tree_view */
gtk_tree_store_append(store, &root_iter, NULL);
gtk_tree_store_set(store, &root_iter, COL_NAME, "Root1", -1);

gtk_tree_store_append(store, &root_iter, NULL);
gtk_tree_store_set(store, &root_iter, COL_NAME, "Root2", -1);

gtk_tree_store_append(store, &root_iter, NULL);
gtk_tree_store_set(store, &root_iter, COL_NAME, "Root3", -1);

/* Add child date to tree_view */
gtk_tree_store_append(store, &child_iter, &root_iter);
gtk_tree_store_set(store, &child_iter, COL_NAME, "Child1", -1);

/* Expand the Root3 row to show the Child1 row */
path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &root_iter);
gtk_tree_view_expand_row(tree_view, path, FALSE);
gtk_tree_path_free(path);

/* Show all widgets */
gtk_widget_show_all(window);

/* Start the main loop */
gtk_main();

return 0;
}
0

2007/1/12

MSN Messenger Protocol - SBP  インスタント・メッセンジャー

<MSN Messenger Protocol Version 11 (MSNP11) で仲間の表示名(ニックネーム)を変更する。>

SBP trid Contact's_CID MFN New_nickname\r\n

trid: メッセージ ID、で通し番号
Contact's_CID: 仲間の CID。LST メッセージと共に送られて来る C=xxx の xxx の部分
New_nickname: 新しい表示名(ニックネーム)。MSN 用に URL エンコードする必要がある

例)
新しい表示名が "Ahoaho Man" の場合は
SBP 34 83137-dc16-473b-aa83-95728db0cc07 MFN Ahoaho%20Man\r\n

>>>
>>>
>>>

<Changing a contact's nickname in MSN Messenger Protocol Version 11 (MSNP11) .>

SBP trid Contact's_CID MFN New_nickname\r\n

trid: A message ID
Contact's_CID: Contact's CID sent with an LST message (C=xxx: xxx is it)
New_nickname: A URL encoded new nickname

Example:
If a new nickname is "Ahoaho Man"
SBP 34 83137-dc16-473b-aa83-95728db0cc07 MFN Ahoaho%20Man\r\n
0



teacup.ブログ “AutoPage”
AutoPage最新お知らせ