´ÙÀ½ ÀÌÀü Â÷·Ê

14. À̺¥Æ®¹Ú½º widget

¾î¶² GTK widgetµéÀº ±×µé¸¸ÀÇ XÀ©µµ¸¦ °¡ÁöÁö ¾Ê°í ´ÜÁö ±×µéÀÇ parentÀ©µµ¿¡ ±×·ÁÁú »ÓÀÌ´Ù. ÀÌ·Î ÀÎÇØ ±×µéÀº À̺¥Æ®¸¦ ¹ÞÀ» ¼ö ¾ø°í ¶Ç ºÎÁ¤È®ÇÑ Å©±â·Î º¯ÇßÀ» ¶§ Ŭ¸³µÇÁö ¾Ê±â ¶§¹®¿¡ ¾îÁö·´°Ô µ¡Ä¥µÇ¾î ¹ö¸± ¼öµµ ÀÖ´Ù. ÀÌ·± widget¿¡ ´ëÇØ Á»´õ ¸¹Àº °ÍÀ» ±â´ëÇÏ·Á¸é ¹Ù·Î ÀÌ EventBox¸¦ ÀÌ¿ëÇÒ ¼ö ÀÖ´Ù.

¾óÇÍ º¸±â¿¡, EventBox widgetÀº ÀüÇô ¾µ¸ð¾øÀ» ¼öµµ ÀÖ´Ù. ÀÌ°ÍÀº ½ºÅ©¸°¿¡ ¾Æ¹«°Íµµ ±×¸®Áö ¾ÊÀ¸¸ç À̺¥Æ®¿¡µµ ÀÀ´äÇÏÁö ¾Ê´Â´Ù. ÇÏÁö¸¸ ÀÌ°ÍÀº ÀÚ½ÅÀÇ child widgetÀ¸·Î XÀ©µµ¸¦ Á¦°øÇÏ´Â ÇÑ ÇÔ¼ö¸¦ Áö¿øÇÑ´Ù. ÀÌ°ÍÀº ¸¹Àº GTK widgetµéÀÌ °ü·ÃµÈ XÀ©µµ¸¦ °¡ÁöÁö ¾Ê´Â´Ù´Â Á¡¿¡¼­ Áß¿äÇÏ´Ù. XÀ©µµ¸¦ °¡ÁöÁö ¾Ê´Â °ÍÀº ¸Þ¸ð¸®¸¦ Àý¾àÇÏ°í ÆÛÆ÷¸Õ½º¸¦ Áõ´ëÇÏÁö¸¸, ¶ÇÇÑ ¸î°¡Áö ¾àÁ¡µµ ÀÖ´Ù. XÀ©µµ°¡ ¾ø´Â widgetÀº À̺¥Æ®¸¦ ¹ÞÀ» ¼ö ¾ø°í, ±×¸®°í ±×ÀÇ Ç׸ñµé¿¡ ´ëÇÑ Å¬¸®Çεµ ÇÏÁö ¾Ê´Â´Ù. EventBox¶ó´Â À̸§Àº À̺¥Æ®¸¦ ´Ù·ç´Â ÇÔ¼ö¶ó´Â Àǹ̵µ ÀÖÁö¸¸, widgetµéÀÌ Å¬¸®Ç뵃 ¼öµµ ÀÖ´Ù´Â °ÍÀ» ÀǹÌÇϱ⵵ ÇÑ´Ù. (±×¸®°í ´õ ÀÖ´Ù.. ¾Æ·¡ÀÇ ¿¹Á¦¸¦ º¸ÀÚ.)

»õ·Î¿î EventBox widgetÀ» ¸¸µé±â À§Çؼ­ ÀÌ°ÍÀ» ÀÌ¿ëÇÑ´Ù.

GtkWidget* gtk_event_box_new (void);

ÀÌ EventBox¿¡´Â child widgetÀÌ ´õÇØÁú ¼ö ÀÖ´Ù.

gtk_container_add (GTK_CONTAINER(event_box), widget);

À̹øÀÇ ¿¹Á¦´Â ÇÑ EventBoxÀÇ µÎ°¡Áö ¾²ÀÓ»õ¸¦ ´Ù º¸¿©ÁØ´Ù. Áï ÀÛÀº ¹Ú½º·Î Ŭ¸®ÇÎµÈ ¶óº§ÀÌ ÀÖ°í, ÀÌ°Í¿¡ ´ë°í ¸¶¿ì½º¸¦ Ŭ¸¯Çϸé ÇÁ·Î±×·¥ÀÌ ³¡³ª°Ô µÈ´Ù.

#include <gtk/gtk.h>

int
main (int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *event_box;
    GtkWidget *label;

    gtk_init (&argc, &argv);

    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

    gtk_window_set_title (GTK_WINDOW (window), "Event Box");

    gtk_signal_connect (GTK_OBJECT (window), "destroy",
              GTK_SIGNAL_FUNC (gtk_exit), NULL);

    gtk_container_border_width (GTK_CONTAINER (window), 10);

    /* EventBox¸¦ Çϳª ¸¸µé°í ±×°ÍÀ» toplevel À©µµ¿¡ ´õÇØÁØ´Ù. */

    event_box = gtk_event_box_new ();
    gtk_container_add (GTK_CONTAINER(window), event_box);
    gtk_widget_show (event_box);

    /* ±ä ¶óº§À» ¸¸µç´Ù. */

    label = gtk_label_new ("Click here to quit, quit, quit, quit, quit");
    gtk_container_add (GTK_CONTAINER (event_box), label);
    gtk_widget_show (label);

    /* ÀÌ°ÍÀ» ÀÛ°Ô Å¬¸®ÇÎÇÑ´Ù. */
    gtk_widget_set_usize (label, 110, 20);

    /* ÀÌ°Í¿¡ µ¿ÀÛ(action)À» ¿¬°á½ÃÄÑ ÁØ´Ù. */
    gtk_widget_set_events (event_box, GDK_BUTTON_PRESS_MASK);
    gtk_signal_connect (GTK_OBJECT(event_box), "button_press_event",
              GTK_SIGNAL_FUNC (gtk_exit), NULL);

    /* ¾î¶² X À©µµ¸¦ À§ÇØ ÇÑ °¡Áö ´õ ÇÊ¿äÇÑ °Ô ÀÖ´Ù... */

    gtk_widget_realize (event_box);
    gdk_window_set_cursor (event_box->window, gdk_cursor_new (GDK_HAND1));

    gtk_widget_show (window);

    gtk_main ();

    return 0;
}


´ÙÀ½ ÀÌÀü Â÷·Ê