Chinaunix首页 | 论坛 | 博客
  • 博客访问: 180679
  • 博文数量: 40
  • 博客积分: 2036
  • 博客等级: 大尉
  • 技术积分: 430
  • 用 户 组: 普通用户
  • 注册时间: 2009-04-12 22:39
文章分类

全部博文(40)

文章存档

2013年(3)

2012年(1)

2011年(18)

2010年(18)

分类: C/C++

2011-02-14 17:16:40

          在Linux下用Gtk开发时,有时会用到构件大小变化size-changed事件,在Gtk中没有。不过,有一个对应的事件是configure-event。
          在Gtk中configure-event只在窗体大小发生变化或移动时发出,而GtkWidget自身的大小变化不能发出configure-event。
由于本人水平有限,自己不能定制一个构件。所以采用了size-allocate事件来模拟size-changed事件。
下面是代码;
  1. gboolean
  2. widget_size_allocate_cb (GtkWidget *widget,
  3.                          GtkAllocation *allocation,
  4.                          gpointer user_data)
  5. {
  6.     static gint width=0, height=0;

  7.     if (width>0 && height>0 && (allocation->width - width || allocation->height - height))
  8.     {
  9.        // g_printf("size changed:width-%d :height- %d: ", width, height);
  10.         width = allocation->width;
  11.         height = allocation->height;

  12.        // 在此,做一些操作...
  13.     }
  14.     if (G_UNLIKELY (width==0 && height==0))
  15.     {
  16.         width = allocation->width;
  17.         height = allocation->height;
  18.     }
  19.     return FALSE;
  20. }


阅读(2077) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~