几封有趣的邮件

http://mail.gnome.org/archives/gtk-app-devel-list/2003-April/msg00204.html

Page numbers in GtkNotebook


  • From: Manu C S
  • To: gtk-app-devel-list gnome org
  • Subject: Page numbers in GtkNotebook
  • Date: Tue, 15 Apr 2003 12:50:21 -0500 (CDT)

Hi,How does one find out the page numbers of tabs in GtkNotebook?I tried gtk_notebook_get_current_page() in a callback forswitch page signal, but the page number I get from this varies

each time.

I want to be able to do something like this in my code:

-------------------------------------------------------------

#define PAGE_0  0

#define PAGE_1  1

#define PAGE_2  2

...

on_top_switch_page (GtkNotebook* notebook, ....)

{

curr_page = gtk_notebook_get_current_page(notebook);

switch (curr_page) {

case PAGE_0:

break;

case PAGE_1:

break;

....

}

}

-------------------------------------------------------------

I found this question asked in the archives (2000-Jul), but

I couldn't locate any suitable answers.

Can anyone please help? It's rather urgent.

Thanks,

Manu

Re: Page numbers in GtkNotebook


  • From: “Audrey Vernon”
  • To: “Manu C S” ,
  • Subject: Re: Page numbers in GtkNotebook
  • Date: Tue, 15 Apr 2003 23:34:55 -0600

The page number depends on its location in the graph notebook I believe, so if you delete tabs before it the number will change. This works fine for things like removing: gint page; page = gtk\_notebook\_get\_current\_page (myGraphData->notebook); gtk\_notebook\_remove\_page (myGraphData->notebook, page); But what I did when I needed a specific tab was the following: // Get the current notebook tab int currentPageIndex = gtk\_notebook\_get\_current\_page(myData->notebook); GtkFrame *currentPage = GTK\_FRAME(gtk\_notebook\_get\_nth\_page (myData->notebook, currentPageIndex)); Then you can get the notebook label or the widget name or something else to uniquely identify which tab is actually open. I’m not sure if this is ideal, but it worked for me. Audrey —– Original Message —– From: “Manu C S” To: Sent: Tuesday, April 15, 2003 11:50 AM Subject: Page numbers in GtkNotebook

Re: Page numbers in GtkNotebook


  • From: Manu C S
  • To: Audrey Vernon
  • Cc: gtk-app-devel-list gnome org
  • Subject: Re: Page numbers in GtkNotebook
  • Date: Wed, 16 Apr 2003 15:47:20 -0500 (CDT)

Dear Audrey,>Then you can get the notebook label or the widget name or something else to>uniquely identify which tab is actually open.>

>I'm not sure if this is ideal, but it worked for me.

It works for me too!

Also, while working on your solution I found that

if I use

g_signal_connect_after(...switch_page...)

instead of

g_signal_connect(...switch_page...)

then in the callback for switch_page I can do:

on_nb1_main_options_switch_page (GtkNotebook     *notebook,

GtkNotebookPage *page,

guint            page_num,

gpointer         user_data)

{

switch (page_num) {

case 0:

break;

case 1:

break;

...

}

}

where page_num is the correct ascending ordered page

number I want!

For example, if my notebook looks like this:

+---+---+---+---+--------------------------

| A | B | C | D | ....

+---+---+---+---+--------------------------

then page_num will be 0 for A, 1 for B, 2 for C and so on...!

Thank you so much.

Regards,

Manu

destroy 和 delete-event

收到destroy信号后,GtkWidget会被销毁,但是gtk_main()循环还在继续,还需要调用gtk_main_quit()来结束循环。
destroy信号可以连接自定义的回调函数处理别的事情,但是不管怎么样,收到destroy信号以后,widget都会被销毁。
举个例子:
#include

void destroy(GtkObject *window, gpointer user_data)
{
g_print(“OH no no ~\n”);
}

gtk中某个信号对应的回调函数原型

对于gtk中不同信号,对应的回调函数原型是不同的。举例说明如何找到相应信号的回调函数原型:

g_signal_connect_object(buffer, “mark_set”, G_CALLBACK(on_mark_set), statusbar, 0);

首先,mark_set是属于GtkTextBuffer的一个信号(BTW,GtkTextBuffer正是上述函数第一个参数的数据类型);
在GTK+ Reference Manual 中找到GtkTextBuffer这一项,
点击signals,可以看到属于这个类型的所有信号,
点击mark_set,就可以得到这个信号的回调函数原型。

Terrible

i18n
autoconf
apue | linux programming by example | j2se | pointers on c
Unix Network Programing

g_signal_connect() 和 g_signal_connect_swapped()的区别

gtk编程中常用到这两个函数,但是很多人对这两个函数的区别却不太清楚,至少是解释得不够准确。

我在这里找到了确却的解释:
http://gtkforums.com/viewtopic.php?t=1177

简单的说,swapped函数会交换回调函数参数的顺序。

这有什么好处?从例子上看:

<br /> /*这个函数会删除button,尽管用户数据的值是other_widget*/<br /> /* this will delete 'button' on its clicked signal, even though we're passing 'other_widget' as user_data */<br /> g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_widget_destroy), (gpointer)other_widget);<br /> /*这个函数会删除other_widget*/<br /> /* this will delete 'other_widget' on button's clicked signal */<br /> g_signal_connect_swapped(G_OBJECT(button), "clicked", G_CALLBACK(gtk_widget_destroy), (gpointer)other_widget);<br />

char *strcat(char *s, char *t)

char *strcat(char *s, char *t)

把*t连接到*s,并保存在*s中,*s没有足够空间的话,编译器找不到这个小虫子,gdb也没有发现它,一运行它就钻出来…

一个可行的方案:

#include <stdio.h>
#include <string.h>

#define MAX_NUM 100

int main()
{
char fn[MAX_NUM];
char *s = “abc”;
char *t = “def”;

strcpy(fn, s);
strcat(fn, t);

printf(“%s\n”, fn);

return 0;
}

另一个似乎也不错:
#include <stdio.h>

#define MAX_NUM 100

int main()
{
char fn[MAX_NUM];
char *s = “abc”;
char *t = “def”;

sprintf(fn, “%s%s”, s, t);