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

9. ÄÁÅ×ÀÌ³Ê widget

9.1 ³ëÆ®ºÏ

³ëÆ®ºÏ widgetÀº ¼­·Î ¿À¹ö·¦µÇ¸ç ´Ù¸¥ Á¤º¸¸¦ °¡Áö°í ÀÖ´Â 'ÆäÀÌÁöµé'ÀÇ ¸ðÀÓÀÌ´Ù. ÀÌ·± widgetÀº ÃÖ±Ù GUI ÇÁ·Î±×·¡¹Ö¿¡¼­ ´õ ÀϹÝÈ­µÇ¾ú°í, È­¸é¿¡¼­ ºñ½ÁÇÏÁö¸¸ ±¸º°µÇ¾î¾ß ÇÒ Á¤º¸ ºí·°À» º¸ÀÌ´Â µ¥ ÁÁÀº ¹æ¹ýÀÌ´Ù.

¿ì¸®°¡ ¾Ë¾Æ¾ß ÇÒ Ã¹¹ø° ÇÔ¼ö´Â ¿¹»óÇÑ´ë·Î »õ·Î¿î ³ëÆ®ºÏ widgetÀ» ¸¸µå´Â °ÍÀÌ´Ù.

GtkWidget* gtk_notebook_new (void);

ÀÏ´Ü ³ëÆ®ºÏÀÌ ¸¸µé¾îÁö¸é, ±× ³ëÆ®ºÏ widgetÀ» ´Ù·ê 12°³ÀÇ ÇÔ¼ö°¡ ÀÖ´Ù. ±×µé ÇϳªÇϳª¸¦ »ìÆ캸ÀÚ.

¿ì¸®°¡ ¸ÕÀú ÇÒ ÀÏÀº ÆäÀÌÁö Ç¥½ÃÀÚÀÇ À§Ä¡¸¦ ¾î¶»°Ô Àâ´ÂÁö ¾Ë¾Æº¸´Â °ÍÀÌ´Ù. ÀÌ·± ÆäÀÌÁö Ç¥½ÃÀÚ È¤Àº 'tab'Àº, ³× °¡Áö ¹æ¹ýÀ¸·Î Àâ¾ÆÁÙ ¼ö ÀÖ´Ù. Áï top, bottom, left, ¶Ç´Â rightÀÌ´Ù.

void gtk_notebook_set_tab_pos (GtkNotebook *notebook, GtkPositionType pos);

GtkPositionTypeÀº ´ÙÀ½ Áß ÇϳªÀ̸ç, »ó´çÈ÷ Á÷°üÀûÀÌ´Ù.

GTK_POS_TOPÀÌ µðÆúÆ®´Ù.

´ÙÀ½À¸·Î ³ëÆ®ºÏ¿¡ ¾î¶»°Ô ÆäÀÌÁö¸¦ ³Ö´ÂÁö ¾Ë¾Æº¸ÀÚ. ÀÌ·¸°Ô ÇÏ´Â °Í¿¡´Â ¼¼°¡Áö ¹æ¹ýÀÌ ÀÖ´Ù. ¿ì¼± ¼­·Î À¯»çÇÑ µÎ°¡Áö¸¦ ¸ÕÀú »ìÆ캸ÀÚ.

void gtk_notebook_append_page (GtkNotebook *notebook, GtkWidget *child, GtkWidget *tab_label);

void gtk_notebook_prepend_page (GtkNotebook *notebook, GtkWidget *child, GtkWidget *tab_label);

ÀÌ·± ÇÔ¼öµéÀº ³ëÆ®ºÏÀÇ µÚ¿¡ »ðÀԵǴøÁö(append), ¶Ç´Â ³ëÆ®ºÏÀÇ ¾Õ¿¡¼­ »ðÀԵǴøÁö(prepend) Çؼ­ ÆäÀÌÁö¸¦ ´õÇØÁØ´Ù. *child´Â ³ëÆ®ºÏ ÆäÀÌÁö¿¡ À§Ä¡ÇÏ´Â widgetÀÌ°í, *tab_labelÀº ´õÇØÁú ÆäÀÌÁö¸¦ À§ÇÑ ¶óº§ÀÌ´Ù.

ÆäÀÌÁö¸¦ ´õÇØÁÖ´Â ¸¶Áö¸· ÇÔ¼ö´Â ¾ÕÀÇ µÎ°¡Áö°¡ °¡Áø Ư¼ºÀ» ¸ðµÎ °¡Áö°í ÀÖ´Ù. ÇÏÁö¸¸ ÀÌ°ÍÀº ¿ì¸®°¡ ³ëÆ®ºÏÀÇ ¾î´À À§Ä¡¿¡ ÆäÀÌÁö¸¦ ¼³Á¤ÇÒ Áö¸¦ Á¤Çϵµ·Ï ÇØÁØ´Ù.

void gtk_notebook_insert_page (GtkNotebook *notebook, GtkWidget *child, GtkWidget *tab_label, gint position);

positionÀ̶ó´Â ¶Ç ÇϳªÀÇ ÀÎÀÚ¸¦ Æ÷ÇÔÇÑ´Ù´Â °Í¸¸ »©°í´Â, gtk_notebook_append_page ±×¸®°í gtk_notebook_prepend_page¿Í ÀÎÀÚ°¡ °°´Ù. position ÀÎÀÚ´Â ÀÌ ÆäÀÌÁö°¡ ¾î´À À§Ä¡¿¡ »ðÀ﵃ °ÍÀÎÁö ÁöÁ¤ÇØ ÁØ´Ù.

ÀÌÁ¦ ¾î¶»°Ô ÆäÀÌÁö¸¦ ´õÇÏ´ÂÁö ¾Ë¾ÒÀ¸¹Ç·Î, ³ëÆ®ºÏ¿¡¼­ ÆäÀÌÁö¸¦ ¾î¶»°Ô Á¦°ÅÇÏ´ÂÁö¸¦ ¾Ë¾Æº¸µµ·Ï ÇÏÀÚ.

void gtk_notebook_remove_page (GtkNotebook *notebook, gint page_num);

ÀÌ ÇÔ¼ö´Â page_num ÀÎÀÚ·Î ÁÖ¾îÁø ÆäÀÌÁö¸¦ ÃëÇؼ­, ±×°ÍÀ» *notebookÀ̶ó´Â widget¿¡¼­ Á¦°ÅÇØÁØ´Ù.

ÇöÀçÀÇ ÆäÀÌÁö¸¦ ¾Ë¾Æ³»±â À§Çؼ­´Â ÀÌ ÇÔ¼ö¸¦ ÀÌ¿ëÇÑ´Ù.

gint gtk_notebook_current_page (GtkNotebook *notebook);

¿©±â ¼Ò°³ÇÏ´Â µÎ ÇÔ¼ö´Â ³ëÆ®ºÏÀÇ ÆäÀÌÁö¸¦ ¾ÕµÚ·Î À̵¿ÇÒ ¶§ ¾²´Â °£´ÜÇÑ ÇÔ¼öµéÀÌ´Ù. ¿ì¸®°¡ ´Ù·ê ³ëÆ®ºÏ widgetÀ» ´Ù·ç±â À§Çؼ­ Àú¸¶´ÙÀÇ ÇÔ¼ö¸¦ Áֱ⸸ ÇÏ¸é µÈ´Ù. ÁÖÀÇÇÒ °ÍÀº, ¸¶Áö¸· ÆäÀÌÁö¿¡¼­ gtk_notebook_next_page°¡ È£ÃâµÇ¸é ³ëÆ®ºÏÀÌ Ã¹¹ø° ÆäÀÌÁö·Î µ¹¾Æ°¡ ¹ö¸°´Ù´Â »ç½ÇÀÌ´Ù. ¸¶Âù°¡Áö·Î ù¹ø° ÆäÀÌÁö¿¡¼­ gtk_notebook_prev_page°¡ È£ÃâµÇ¸é ³ëÆ®ºÏÀÇ ¸¶Áö¸· ÆäÀÌÁö ·Î °¡¹ö¸°´Ù.

void gtk_notebook_next_page (GtkNoteBook *notebook);
void gtk_notebook_prev_page (GtkNoteBook *notebook);

À̹ø ÇÔ¼ö´Â 'active', Áï È°¼ºÈ­µÈ ÆäÀÌÁö¸¦ ¼¼ÆÃÇÑ´Ù. ¿¹¸¦µé¾î óÀ½ºÎÅÍ 5¹ø ÆäÀÌÁö·Î ³ëÆ®ºÏÀ» ¿­·Á¸é ÀÌ ÇÔ¼ö¸¦ ÀÌ¿ëÇÏ¸é µÉ °ÍÀÌ´Ù. ÀÌ°ÍÀ» ¾²Áö ¾ÊÀ¸¸é, µðÆúÆ®·Î ³ëÆ®ºÏÀº ù¹ø° ÆäÀÌÁö¿¡¼­ ¿­¸®°Ô µÈ´Ù.

void gtk_notebook_set_page (GtkNotebook *notebook, gint page_num);

ÀÌ µÎ ÇÔ¼ö´Â °¢°¢ ³ëÆ®ºÏÀÇ ÆäÀÌÁö tab°ú °æ°è¸¦ ´õÇϰųª Á¦°ÅÇØÁØ´Ù.

void gtk_notebook_set_show_tabs (GtkNotebook *notebook, gint show_tabs);
void gtk_notebook_set_show_border (GtkNotebook *notebook, gint show_border);

ÀÎÀÚ show_tabs¿Í show_border´Â TRUE/FALSE Áß Çϳª°¡ µÉ ¼ö ÀÖ´Ù.

ÀÌÁ¦ ¿¹Á¦¸¦ Çϳª º¸ÀÚ. ÀÌ°ÍÀº GTK ¹èÆ÷º»°ú ÇÔ²² ÀÖ´Â testgtk.c ÇÁ·Î±×·¥ À¸·Î, 13°³ÀÇ ÇÔ¼ö¸¦ ¸ðµÎ º¸¿©ÁØ´Ù. ÀÌ ÀÛÀº ÇÁ·Î±×·¥Àº ³ëÆ®ºÏ°ú ¿©¼¸ °³ÀÇ ¹öÆ°À» °¡Áö°í ÀÖ´Â À©µµ¸¦ ¸¸µç´Ù. ³ëÆ®ºÏÀº ¼¼°¡Áö ´Ù¸¥ ¹æ¹ý, Áï append/ insert/prepend¸¦ ÅëÇØ ´õÇØÁø 11°³ ÆäÀÌÁö¸¦ °¡Áö°í ÀÖ´Ù. ¹öÆ°µéÀº tabÀÇ À§Ä¡¸¦ ¼øȯ½Ãų ¼ö ÀÖ°í, tab°ú border¸¦ ´õÇØÁְųª Áö¿ï¼ö ÀÖÀ¸¸ç, ÇÑ ÆäÀÌÁö ¸¦ Áö¿ï ¼öµµ ÀÖ´Ù. ±×¸®°í ¾ÕµÚ ¾ç¹æÇâÀ¸·Î ÆäÀÌÁö¸¦ ¹Ù²ãÁÖ¸ç, ÇÁ·Î±×·¥À» ³¡³¾ ¼öµµ ÀÖ´Ù.

/* notebook.c */

#include <gtk/gtk.h>

/* ÀÌ ÇÔ¼ö´Â tabÀÇ À§Ä¡¸¦ ·ÎÅ×ÀÌ¼Ç ½ÃŲ´Ù. */
void rotate_book (GtkButton *button, GtkNotebook *notebook)
{
                gtk_notebook_set_tab_pos (notebook, (notebook->tab_pos +1) %4);
}

/* page tab°ú border¸¦ ´õÇϰųª »èÁ¦ÇÑ´Ù. */
void tabsborder_book (GtkButton *button, GtkNotebook *notebook)
{
                gint tval = FALSE;
                gint bval = FALSE;
                if (notebook->show_tabs == 0)
                                                tval = TRUE;
                if (notebook->show_border == 0)
                                                bval = TRUE;

                gtk_notebook_set_show_tabs (notebook, tval);
                gtk_notebook_set_show_border (notebook, bval);
}

/* ³ëÆ®ºÏ¿¡¼­ ÇÑ ÆäÀÌÁö¸¦ Á¦°ÅÇÑ´Ù. */
void remove_book (GtkButton *button, GtkNotebook *notebook)
{
                gint page;

                page = gtk_notebook_current_page(notebook);
                gtk_notebook_remove_page (notebook, page);
                /* Need to refresh the widget -
                 This forces the widget to redraw itself. */
                gtk_widget_draw(GTK_WIDGET(notebook), NULL);
}

void delete (GtkWidget *widget, GdkEvent *event, gpointer data)
{
                gtk_main_quit ();
}

int main (int argc, char *argv[])
{
                GtkWidget *window;
                GtkWidget *button;
                GtkWidget *table;
                GtkWidget *notebook;
                GtkWidget *frame;
                GtkWidget *label;
                GtkWidget *checkbutton;
                int i;
                char bufferf[32];
                char bufferl[32];

                gtk_init (&argc, &argv);

                window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

                gtk_signal_connect (GTK_OBJECT (window), "delete_event",
                                                        GTK_SIGNAL_FUNC (delete), NULL);

                gtk_container_border_width (GTK_CONTAINER (window), 10);

                table = gtk_table_new(2,6,TRUE);
                gtk_container_add (GTK_CONTAINER (window), table);

                /* »õ ³ëÆ®ºÏÀ» ¸¸µé°í, tabµéÀÇ À§Ä¡¸¦ ¼³Á¤ÇÑ´Ù. */
                notebook = gtk_notebook_new ();
                gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), GTK_POS_TOP);
                gtk_table_attach_defaults(GTK_TABLE(table), notebook, 0,6,0,1);
                gtk_widget_show(notebook);

                /* ³ëÆ®ºÏ¿¡ ÆäÀÌÁöµéÀÇ ¹­À½À» Ãß°¡ÇÑ´Ù. */
                for (i=0; i < 5; i++) {
                                sprintf(bufferf, "Append Frame %d", i+1);
                                sprintf(bufferl, "Page %d", i+1);

                                frame = gtk_frame_new (bufferf);
                                gtk_container_border_width (GTK_CONTAINER (frame), 10);
                                gtk_widget_set_usize (frame, 100, 75);
                                gtk_widget_show (frame);

                                label = gtk_label_new (bufferf);
                                gtk_container_add (GTK_CONTAINER (frame), label);
                                gtk_widget_show (label);

                                label = gtk_label_new (bufferl);
                                gtk_notebook_append_page (GTK_NOTEBOOK (notebook), frame, label);
                }

                /* ÁöÁ¤ÇÑ °÷À¸·Î ÇÑ ÆäÀÌÁö¸¦ ´õÇÑ´Ù. */
                checkbutton = gtk_check_button_new_with_label ("Check me please!");
                gtk_widget_set_usize(checkbutton, 100, 75);
                gtk_widget_show (checkbutton);

                label = gtk_label_new ("Add spot");
                gtk_container_add (GTK_CONTAINER (checkbutton), label);
                gtk_widget_show (label);
                label = gtk_label_new ("Add page");
                gtk_notebook_insert_page (GTK_NOTEBOOK (notebook), checkbutton, label, 2);

                /* ÀÌÁ¦ ³ëÆ®ºÏÀÇ ¼±µÎ¿¡ ÆäÀÌÁö¸¦ prependÇÑ´Ù. */
                for (i=0; i < 5; i++) {
                                sprintf(bufferf, "Prepend Frame %d", i+1);
                                sprintf(bufferl, "PPage %d", i+1);

                                frame = gtk_frame_new (bufferf);
                                gtk_container_border_width (GTK_CONTAINER (frame), 10);
                                gtk_widget_set_usize (frame, 100, 75);
                                gtk_widget_show (frame);

                                label = gtk_label_new (bufferf);
                                gtk_container_add (GTK_CONTAINER (frame), label);
                                gtk_widget_show (label);

                                label = gtk_label_new (bufferl);
                                gtk_notebook_prepend_page (GTK_NOTEBOOK(notebook), frame, label);
                }

                /* ½ÃÀÛÇÒ ÆäÀÌÁö¸¦ ¼¼ÆÃÇÑ´Ù(¿©±â¼­´Â page 4). */
                gtk_notebook_set_page (GTK_NOTEBOOK(notebook), 3);

                /* ¹öÆ°ÀÇ ´Ù¹ß(bunch)À» Çϳª ¸¸µç´Ù. */
                button = gtk_button_new_with_label ("close");
                gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
                                   GTK_SIGNAL_FUNC (destroy), NULL);
                gtk_table_attach_defaults(GTK_TABLE(table), button, 0,1,1,2);
                gtk_widget_show(button);

                button = gtk_button_new_with_label ("next page");
                gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
                                   (GtkSignalFunc) gtk_notebook_next_page,
                                   GTK_OBJECT (notebook));
                gtk_table_attach_defaults(GTK_TABLE(table), button, 1,2,1,2);
                gtk_widget_show(button);

                button = gtk_button_new_with_label ("prev page");
                gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
                                   (GtkSignalFunc) gtk_notebook_prev_page,
                                   GTK_OBJECT (notebook));
                gtk_table_attach_defaults(GTK_TABLE(table), button, 2,3,1,2);
                gtk_widget_show(button);

                button = gtk_button_new_with_label ("tab position");
                gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
                                   (GtkSignalFunc) rotate_book, GTK_OBJECT(notebook));
                gtk_table_attach_defaults(GTK_TABLE(table), button, 3,4,1,2);
                gtk_widget_show(button);

                button = gtk_button_new_with_label ("tabs/border on/off");
                gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
                                   (GtkSignalFunc) tabsborder_book,
                                   GTK_OBJECT (notebook));
                gtk_table_attach_defaults(GTK_TABLE(table), button, 4,5,1,2);
                gtk_widget_show(button);

                button = gtk_button_new_with_label ("remove page");
                gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
                                   (GtkSignalFunc) remove_book,
                                   GTK_OBJECT(notebook));
                gtk_table_attach_defaults(GTK_TABLE(table), button, 5,6,1,2);
                gtk_widget_show(button);

                gtk_widget_show(table);
                gtk_widget_show(window);

                gtk_main ();

                return 0;
}

ÀÌ°ÍÀ¸·Î ¿©·¯ºÐÀÇ GTK ¾îÇÃÀ» ¸¸µé ¶§ ³ëÆ®ºÏÀ» ´Ù·ç´Â ¹æ¹ý¿¡ ´ëÇÑ µµ¿òÀÌ µÇ±â¸¦ ¹Ù¶õ´Ù.

9.2 ½ºÅ©·ÑµÈ À©µµ

ÀÌ°ÍÀº ½ÇÁ¦ À©µµ ³»ºÎ¿¡¼­ ½ºÅ©·ÑµÈ ¿µ¿ªÀ» ¸¸µé ¶§ ¾²ÀÌ´Â °ÍÀÌ´Ù. ¿ì¸®´Â ÀÌ·± ½ºÅ©·ÑµÈ ¿µ¿ª¿¡ ¾î¶² Á¾·ùÀÇ widgetÀÌ¶óµµ »ðÀÔÇÒ ¼ö ÀÖ°í, ½ºÅ©·Ñ¹Ù¸¦ ÀÌ¿ëÇÏ¿© Å©±â¿¡ °ü°è¾øÀÌ Á¢±ÙÇÒ ¼ö ÀÖÀ» °ÍÀÌ´Ù.

ÀÌ ÇÔ¼ö´Â »õ·Î¿î ½ºÅ©·Ñ À©µµ¸¦ ¸¸µå´Â °ÍÀÌ´Ù.

GtkWidget* gtk_scrolled_window_new (GtkAdjustment *hadjustment,
                                    GtkAdjustment *vadjustment);

ù¹ø° ÀÎÀÚ´Â ¼öÆò¹æÇâÀ», ±×¸®°í µÎ¹ø° ÀÎÀÚ´Â ¼öÁ÷¹æÇâÀ» Á¶ÀýÇØ ÁØ´Ù. À̰͵éÀº ´ë°³ NULL·Î ¼¼ÆõȴÙ.

void gtk_scrolled_window_set_policy (GtkScrolledWindow *scrolled_window,
                                     GtkPolicyType hscrollbar_policy,
                                     GtkPolicyType vscrollbar_policy);

ÀÌ°ÍÀº ½ºÅ©·Ñ¹ÙµéÀ» ¾²´Â ¹æ½ÄÀ» ¼³Á¤ÇÑ´Ù. ù¹ø° ÀÎÀÚ´Â ¿ì¸®°¡ º¯È­ ½ÃÅ°°íÀÚ ÇÏ´Â ½ºÅ©·Ñ À©µµ´Ù. µÎ¹ø°¿Í ¼¼¹ø° ÀÎÀÚµéÀº °¢°¢ ¼öÆò ½ºÅ©·Ñ¹Ù¿Í ¼öÁ÷ ½ºÅ©·Ñ¹ÙÀÇ ¹æ½ÄÀ» ¼¼ÆÃÇÑ´Ù.

ÀÌ ¹æ½ÄÀ̶õ °ÍÀº GTK_POLICY_AUTOMATIC ȤÀº GTK_POLICY_ALWAYS °¡ µÈ´Ù. GTK_POLICY_AUTOMATICÀº ½ºÅ©·Ñ¹Ù°¡ ÇÊ¿äÇÒ ¶§¸¦ ÀÚµ¿ÀûÀ¸·Î °áÁ¤ÇÏ°í, ¹Ý¸é GTK_POLICY_ALWAYS´Â ¾ðÁ¦³ª ½ºÅ©·Ñ¹Ù¸¦ ¸¸µé¾î µÐ´Ù.

ÀÌ °£´ÜÇÑ ¿¹Á¦´Â ½ºÅ©·ÑµÈ À©µµ¿¡ 100°³ÀÇ Åä±Û ¹öÆ°À» ÆÐÅ·ÇÑ´Ù. ¿©±â¼­ÀÇ ÁÖ¼®Àº ¿©·¯ºÐ¿¡°Ô »ý¼ÒÇÒ ºÎºÐ¿¡¸¸ ºÙ¿©Áú °ÍÀÌ´Ù.

/* scrolledwin.c */

#include <gtk/gtk.h>

void destroy(GtkWidget *widget, gpointer data)
{
                gtk_main_quit();
}

int main (int argc, char *argv[])
{
                static GtkWidget *window;
                GtkWidget *scrolled_window;
                GtkWidget *table;
                GtkWidget *button;
                char buffer[32];
                int i, j;

                gtk_init (&argc, &argv);

                /* ½ºÅ©·ÑµÈ À©µµ°¡ ÆÐÅ·µÇ¾î µé¾î°¥ dialog À©µµ¸¦ ¸¸µç´Ù. 
                 * Dialog À©µµ¶õ vbox¿Í ±×°Í¿¡ ÆÐÅ·µÇ¾î µé¾î°¥ ¼öÆò seperator¸¦ °¡Áö°í
                 * ÀÖ´Ù´Â °Í¸¸ »©°í´Â º¸ÅëÀÇ À©µµ¿Í µ¿ÀÏÇÑ °ÍÀÌ´Ù.  ÀÌ°ÍÀº dialog¸¦
                 * ¸¸µé°Ô µÇ´Â ÀÏÁ¾ÀÇ shortcutÀÌ´Ù. */
                window = gtk_dialog_new ();
                gtk_signal_connect (GTK_OBJECT (window), "destroy",
                                                        (GtkSignalFunc) destroy, NULL);
                gtk_window_set_title (GTK_WINDOW (window), "dialog");
                gtk_container_border_width (GTK_CONTAINER (window), 0);

                /* ½ºÅ©·ÑµÈ(scrolled) À©µµ¸¦ Çϳª ¸¸µç´Ù. */
                scrolled_window = gtk_scrolled_window_new (NULL, NULL);

                gtk_container_border_width (GTK_CONTAINER (scrolled_window), 10);

                /* ¿©±â¼­ÀÇ ¹æ½ÄÀº GTK_POLICY_AUTOMATIC ¶Ç´Â GTK_POLICY_ALWAYS Áß
                 * ÇϳªÀÌ´Ù.  GTK_POLICY_AUTOMATICÀº ½ºÅ©·Ñ¹Ù°¡ ÇÊ¿äÇÑÁö¸¦ ÀÚµ¿ÀûÀ¸·Î
                 * °áÁ¤ÇÏ°í, ¹Ý¸é GTK_POLICY_ALWAYS´Â ¾ðÁ¦³ª ½ºÅ©·Ñ¹Ù¸¦ °¡Áö°Ô ÇÑ´Ù.
                 * ù¹ø°´Â ¼öÆò¹æÇâÀÇ ½ºÅ©·Ñ¹Ù, ±×¸®°í µÎ¹ø°´Â ¼öÁ÷¹æÇâÀÇ °ÍÀÌ´Ù. */

                gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
                                       GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
                /* vbox°¡ ÆÐÅ·µÇ¾î µé¾î°£ dialog À©µµ¸¦ Çϳª ¸¸µç´Ù. */
                gtk_box_pack_start (GTK_BOX (GTK_DIALOG(window)->vbox), scrolled_window,
                                                                                                TRUE, TRUE, 0);
                gtk_widget_show (scrolled_window);

                /* 10Çà 10¿­ÀÇ Å×À̺íÀ» ¸¸µç´Ù. */
                table = gtk_table_new (10, 10, FALSE);

                /* x¿Í y¿¡ ´ëÇØ 10 ¸¸Å­ÀÇ spacingÀ» ¼¼ÆÃÇÑ´Ù. */
                gtk_table_set_row_spacings (GTK_TABLE (table), 10);
                gtk_table_set_col_spacings (GTK_TABLE (table), 10);

                /* ½ºÅ©·ÑµÈ À©µµ¿¡ Å×À̺íÀ» ÆÐÅ·ÇÑ´Ù. */
                gtk_container_add (GTK_CONTAINER (scrolled_window), table);
                gtk_widget_show (table);

                /* ÀÌ°ÍÀº ´Ü¼øÈ÷ ½ºÅ©·ÑµÈ À©µµ¸¦ º¸¿©ÁÖ±â À§ÇØ Å×À̺í À§¿¡
                 * Åä±Û¹öÆ°µéÀÇ °ÝÀÚ(grid)¸¦ Çϳª ¸¸µç´Ù. */
                for (i = 0; i < 10; i++)
                                                for (j = 0; j < 10; j++) {
                                                                sprintf (buffer, "button (%d,%d)\n", i, j);
                                                                button = gtk_toggle_button_new_with_label (buffer);
                                                                gtk_table_attach_defaults (GTK_TABLE (table), button,
                                                                                                         i, i+1, j, j+1);
                                                                gtk_widget_show (button);
                                                }
                /* DialogÀÇ ¸Ç ¾Æ·¡ÂÊ¿¡ "close" ¹öÆ°À» Ãß°¡ÇÑ´Ù. */
                button = gtk_button_new_with_label ("close");
                gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
                                                                 (GtkSignalFunc) gtk_widget_destroy,
                                                                 GTK_OBJECT (window));

                /* ÀÌ°ÍÀ» µðÆúÆ® ¹öÆ°À¸·Î ÇÑ´Ù. */

                GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
                gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), button, TRUE, TRUE, 0);

                /* ÀÌ ¹öÆ°ÀÌ µðÆúÆ® ¹öÆ°À¸·Î µÇµµ·Ï Àâ¾Ææ´Ù.  °£´ÜÈ÷ "Enter"¸¦ Ä¡¸é
                 * ÀÌ ¹öÆ°À» È°¼ºÈ­ ½Ãų °ÍÀÌ´Ù. */
                gtk_widget_grab_default (button);
                gtk_widget_show (button);

                gtk_widget_show (window);

                gtk_main();

                return(0);
}

À©µµÀÇ Å©±â¸¦ º¯ÇÏ°Ô Çغ¸¶ó. ½ºÅ©·Ñ¹Ù°¡ ¾î¶»°Ô ¹ÝÀÀÇÏ´ÂÁö ¾Ë ¼ö ÀÖÀ» °ÍÀÌ´Ù. ¿ì¸®´Â ¶ÇÇÑ À©µµ³ª ´Ù¸¥ widgetÀÇ µðÆúÆ® Å©±â¸¦ ¼¼ÆÃÇϱâ À§ÇØ gtk_widget_set_usize() ÇÔ¼ö¸¦ ÀÌ¿ëÇÒ ¼öµµ ÀÖÀ» °ÍÀÌ´Ù.

9.3 Paned À©µµ widget

ÀÌ paned À©µµ widgetÀº ÇÑ ¿µ¿ªÀ» »ç¿ëÀÚ¿¡ ÀÇÇؼ­ ±× »ó´ëÀûÀÎ Å©±â¸¦ ¸¶À½´ë·Î Á¶ÀýÇÒ ¼ö ÀÖ´Â µÎ ¿µ¿ªÀ¸·Î ³ª´©¾î ¾²°í ½ÍÀ» ¶§ »ç¿ëÇÑ´Ù. µÎ ¿µ¿ª »çÀÌ¿¡´Â handleÀÌ ´Þ¸° ȨÀÌ ÀÖ°í À̸¦ ¸¶¿ì½º·Î µå·¡±×Çؼ­ »ç¿ëÀÚ´Â ¿øÇÏ´Â ´ë·Î µÎ ¿µ¿ªÀÇ ºñÀ²À» ¹Ù²Ü ¼ö ÀÖ´Ù. ÀÌ·¯ÇÑ ºÐÇÒÀº ¼öÆò(HPaned)ÀûÀ̰ųª ¼öÁ÷(VPaned)ÀûÀÌ µÈ´Ù.

»õ paned À©µµ¸¦ ¸¸µé·Á¸é ´ÙÀ½Áß Çϳª¸¦ ºÎ¸¥´Ù.

GtkWidget* gtk_hpaned_new (void)
GtkWidget* gtk_vpaned_new (void)

Paned À©µµ widgetÀ» ¸¸µç ´ÙÀ½¿¡´Â ³ª´©¾îÁø ¾çÂÊ¿¡ ÀÚ½Ä widgetÀ» ÁÖ¾î¾ß ÇÑ´Ù. ÀÌ´Â ´ÙÀ½ ÇÔ¼öµéÀ» ÀÌ¿ëÇؼ­ ÀÌ·ç¾îÁø´Ù.

void gtk_paned_add1 (GtkPaned *paned, GtkWidget *child)
void gtk_paned_add2 (GtkPaned *paned, GtkWidget *child)

gtk_paned_add1()´Â paned À©µµ widgetÀÇ ¿ÞÂÊ È¤Àº À­ÂÊ¿¡ ÀÚ½Ä widgetÀ» ´õÇÑ´Ù. gtk_paned_add2()´Â ¹Ý´ë·Î ¿À¸¥ÂÊ È¤Àº ¾Æ·§ÂÊ¿¡ ´õÇÑ´Ù.

ÇÑ ¿¡·Î °¡»óÀûÀÎ email ÇÁ·Î±×·¥ÀÇ »ç¿ëÀÚ ÀÎÅÍÆäÀ̽º ÀϺθ¦ ¸¸µé¾î º¸±â·Î ÇÑ´Ù. À©µµ´Â email ¸Þ¼¼ÁöµéÀÇ ¸®½ºÆ®¸¦ Ç¥½ÃÇÏ´Â À­ ºÎºÐ°ú ¸Þ¼¼Áö ÀÚü¸¦ Ç¥½ÃÇÏ´Â ¾Æ·§ ºÎºÐÀ¸·Î ³ª´©¾îÁø´Ù. ÇÁ·Î±×·¡ÀÇ ´ëºÎºÐÀº ¹«Ã´ °£´ÜÇÏ´Ù. µÎ°¡Áö ÁÖÀÇÇØ¾ß ÇÒ Á¡ÀÌ ÀÖ´Ù. ÅؽºÆ®´Â ÅؽºÆ® widget¿¡ ÀÌ°ÍÀÌ realizeµÇ±â Àü¿¡´Â ´õÇØÁú ¼ö ¾ø´Ù. ÀÌ´Â gtk_widget_realize()¸¦ È£ÃâÇؼ­ ÀÌ·ç¾îÁöÁö¸¸ ¶Ç ´Ù¸¥ ¹æ¹ýÀ¸·Î text¸¦ ´õÇϱâ À§ÇØ "realize" ½Ã±×³ÎÀ» ¿¬°áÇÒ ¼öµµ ÀÖ´Ù. ¶ÇÇÑ, GTK_SHRINK ¿É¼ÇÀ» text À©µµ¿Í ½ºÅ©·Ñ¹Ù¸¦ Æ÷ÇÔÇÏ°í ÀÖ´Â Å×ÀÌºí ³»¿ë ÀϺο¡ ´õÇØÁÖ´Â °ÍÀÌ ÇÊ¿äÇÏ´Ù. ±×·¡¾ß¸¸ ¾Æ·§ ºÎºÐÀ» ÀÛ°Ô ¸¸µé¶§ À©µµÀÇ ¹Ù´ÚÀÌ ¹Ð·Á³ª´Â ´ë½Å ¿øÇÏ´ø ºÎºÐÀÌ ÁÙ¾îµé°Ô µÈ´Ù.

/* paned.c */

#include <gtk/gtk.h>
   
/* "messages"ÀÇ ¸®½ºÆ®¸¦ ¸¸µç´Ù */
GtkWidget *
create_list (void)
{

    GtkWidget *scrolled_window;
    GtkWidget *list;
    GtkWidget *list_item;
   
    int i;
    char buffer[16];
   
    /* ½ºÅ©·Ñ¹Ù(ÇÊ¿äÇÒ ¶§¸¸)°¡ µþ¸° ½ºÅ©·ÑµÈ À©µµ¸¦ ¸¸µç´Ù. */
    scrolled_window = gtk_scrolled_window_new (NULL, NULL);
    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
                                    GTK_POLICY_AUTOMATIC, 
                                    GTK_POLICY_AUTOMATIC);
   
    /* »õ·Î¿î ¸®½ºÆ®¸¦ ¸¸µé¾î À̸¦ ½ºÅ©·ÑµÈ À©µµ¿¡ Áý¾î³Ö´Â´Ù. */
    list = gtk_list_new ();
    gtk_container_add (GTK_CONTAINER(scrolled_window), list);
    gtk_widget_show (list);
   
    /* À©µµ¿¡ ¸Þ½ÃÁö ¸î°³¸¦ ´õÇÑ´Ù */
    for (i=0; i<10; i++) {

        sprintf(buffer,"Message #%d",i);
        list_item = gtk_list_item_new_with_label (buffer);
        gtk_container_add (GTK_CONTAINER(list), list_item);
        gtk_widget_show (list_item);

    }
   
    return scrolled_window;
}
   
/* ÅؽºÆ® ¸î°³¸¦ ÅؽºÆ® widget¿¡ ´õÇÑ´Ù. - ¾Æ·¡ ÇÔ¼ö´Â ¿ì¸®ÀÇ À©µµ°¡ realize µÉ
¶§ ºÒ¸®´Â callbackÀÌ´Ù. gtk_widget_realize·Î realizeµÇµµ·Ï °­Á¦ÇÒ ¼öµµ ÀÖÁö¸¸
±×°Ç ¸ÕÀú °èÃþ±¸Á¶ÀÇ ÇÑ ºÎºÐÀÌ µÇ¾î¾ß ÇÒ °ÍÀÌ´Ù.
*/
void
realize_text (GtkWidget *text, gpointer data)
{
    gtk_text_freeze (GTK_TEXT (text));
    gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL,
    "From: pathfinder@nasa.gov\n"
    "To: mom@nasa.gov\n"
    "Subject: Made it!\n"
    "\n"
    "We just got in this morning. The weather has been\n"
    "great - clear but cold, and there are lots of fun sights.\n"
    "Sojourner says hi. See you soon.\n"
    " -Path\n", -1);
   
    gtk_text_thaw (GTK_TEXT (text));
}
   
/* "message"¸¦ º¸¿©ÁÖ´Â ½ºÅ©·ÑµÈ ÅؽºÆ® ¿µ¿ªÀ» ¸¸µç´Ù. */
GtkWidget *
create_text (void)
{
    GtkWidget *table;
    GtkWidget *text;
    GtkWidget *hscrollbar;
    GtkWidget *vscrollbar;
   
    /* ÅؽºÆ® À§Á¬°ú ½ºÅ©·Ñ¹Ù¸¦ °®´Â Å×À̺íÀ» ¸¸µç´Ù */
    table = gtk_table_new (2, 2, FALSE);
   
    /* ÅؽºÆ® À§Á¬À» ¿ÞÂÊ À§¿¡ ³õ´Â´Ù. Y Ãà ¹æÇâÀ¸·Î GTK_SHRINK°¡ ¾²ÀÎ °ÍÀ»
     * ÁÖ¸ñÇÒ °Í. */
    text = gtk_text_new (NULL, NULL);
    gtk_table_attach (GTK_TABLE (table), text, 0, 1, 0, 1,
                      GTK_FILL | GTK_EXPAND,
                      GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 0);
    gtk_widget_show (text);
   
    /* HScrollbar¸¦ ¿ÞÂÊ ¾Æ·¡¿¡ ³õ´Â´Ù. */
    hscrollbar = gtk_hscrollbar_new (GTK_TEXT (text)->hadj);
    gtk_table_attach (GTK_TABLE (table), hscrollbar, 0, 1, 1, 2,
                      GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
    gtk_widget_show (hscrollbar);
   
    /* VScrollbar¸¦ ¿À¸¥ÂÊ À§¿¡ ³õ´Â´Ù. */
    vscrollbar = gtk_vscrollbar_new (GTK_TEXT (text)->vadj);
    gtk_table_attach (GTK_TABLE (table), vscrollbar, 1, 2, 0, 1,
                      GTK_FILL, GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, 0);
    gtk_widget_show (vscrollbar);
   
    /* ÅؽºÆ® widgetÀÌ realizeµÇ¾úÀ» ¶§ ±× widgetÀÌ °®°í ÀÖ´Â ¸Þ½ÃÁö¸¦
     * Ãâ·ÂÇÏ¿©ÁÖ´Â ½Ã±×³Î Çڵ鷯¸¦ ´õÇÑ´Ù. */
    gtk_signal_connect (GTK_OBJECT (text), "realize",
                        GTK_SIGNAL_FUNC (realize_text), NULL);
   
    return table;
}
   
int
main (int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *vpaned;
    GtkWidget *list;
    GtkWidget *text;

    gtk_init (&argc, &argv);
   
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title (GTK_WINDOW (window), "Paned Windows");
    gtk_signal_connect (GTK_OBJECT (window), "destroy",
                        GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
    gtk_container_border_width (GTK_CONTAINER (window), 10);
   
    /* vpaned widgetÀ» ¸¸µé¾î¼­ toplevel À©µµ¿¡ ´õÇÑ´Ù. */
   
    vpaned = gtk_vpaned_new ();
    gtk_container_add (GTK_CONTAINER(window), vpaned);
    gtk_widget_show (vpaned);
   
    /* ÀÌÁ¦ À©µµ µÎ ºÎºÐÀÇ ³»¿ëÀ» ¸¸µç´Ù. */
   
    list = create_list ();
    gtk_paned_add1 (GTK_PANED(vpaned), list);
    gtk_widget_show (list);
   
    text = create_text ();
    gtk_paned_add2 (GTK_PANED(vpaned), text);
    gtk_widget_show (text);
    gtk_widget_show (window);
    gtk_main ();
    return 0;
}

9.4 Aspect ÇÁ·¹ÀÓ

Aspect ÇÁ·¹ÀÓÀº ¸î°¡Áö Ư¡À» »©¸é ÇÁ·¹ÀÓ widget°ú ºñ½ÁÇÏ´Ù. ÀÌ widgetÀº ÀÚ½Ä widgetÀÇ aspect ºñÀ²(°¡·Î¿Í ¼¼·Î ºñÀ²)ÀÌ ¹Ýµå½Ã ¾î¶² ƯÁ¤ÇÑ °ªÀÌ µÇµµ·Ï ¶§¿¡ µû¶ó ¿©ºÐÀÇ °ø°£À» ´õÇؼ­¶óµµ °­Á¦ÇÑ´Ù. ÀÌ°ÍÀº ¿¹¸¦ µé¸é »ó´çÈ÷ Å« À̹ÌÁöÀÇ ¹Ì¸®º¸±â¸¦ º¸´Â ¶§ °°Àº °æ¿ì À¯¿ëÇÏ´Ù. ÀÌ ¹Ì¸®º¸±âÀÇ Å©±â´Â »ç¿ëÀÚ°¡ À©µµÀÇ Å©±â¸¦ ¹Ù²Ü ¶§¸¶´Ù ´Þ¶óÁöÁö¸¸ °¡·Î¼¼·Î ºñÀ²Àº ¾ðÁ¦³ª ¿ø·¡ À̹ÌÁö¿Í °°¾Æ¾ß¸¸ ÇÑ´Ù.

»õ·Î¿î aspect ÇÁ·¹ÀÓÀ» ¸¸µå·Á¸é,

GtkWidget* gtk_aspect_frame_new  (const gchar *label,
                                        gfloat xalign,
                                        gfloat yalign,
                                        gfloat ratio,
                                        gint obey_child)

xalign¿Í yalignÀº Alignment widget¿¡¼­Ã³·³ widgetÀÇ alignment °ªÀ» Á¤ÇÑ´Ù. ¸¸ÀÏ obey_child °ªÀÌ true¸é, ÀÚ½Ä widgetÀÇ °¡·Î¼¼·Î ºñÀ²Àº ¿ø·¡ ¸¸µé¾îÁ³À» ¶§ÀÇ ÀÌ»óÀûÀÎ ºñÀ²°ú °°°Ô µÈ´Ù. ¹Ý´ë·Î falseÀÌ¸é ±× ºñÀ²Àº ratio·Î Á÷Á¢ ÁÖ¾îÁø´Ù.

ÀÌ¹Ì Á¸ÀçÇÏ°í ÀÖ´Â aspect ÇÁ·¹ÀÓÀÇ ¿É¼ÇÀ» ¹Ù²Ù·Á¸é ´ÙÀ½ ÇÔ¼ö¸¦ ÀÌ¿ëÇÑ´Ù.

void gtk_aspect_frame_set (GtkAspectFrame *aspect_frame,
                           gfloat xalign,
                           gfloat yalign,
                           gfloat ratio,
                           gint obey_child)

¿¹Á¦ÀÎ ´ÙÀ½ ÇÁ·Î±×·¥Àº »ç¿ëÀÚ°¡ toplevel À©µµÀÇ Å©±â¸¦ ¾î¶»°Ô ¹Ù²Ùµç ¾ðÁ¦³ª °¡·Î¼¼·Î ºñÀ²ÀÌ 2:1ÀÎ drawing area¸¦ Ç¥ÇöÇϴµ¥ AspectFrameÀ» ¾²°í ÀÖ´Ù.

/* aspectframe.c */

#include <gtk/gtk.h>
   
int
main (int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *aspect_frame;
    GtkWidget *drawing_area;
    gtk_init (&argc, &argv);
   
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title (GTK_WINDOW (window), "Aspect Frame");
    gtk_signal_connect (GTK_OBJECT (window), "destroy",
    GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
    gtk_container_border_width (GTK_CONTAINER (window), 10);
   
    /* aspect_frameÀ» ¸¸µé¾î toplevel À©µµ¿¡ ´õÇÑ´Ù */
   
    aspect_frame = gtk_aspect_frame_new ("2x1", /* ·¹À̺í */
                                         0.5, /* center x */
                                         0.5, /* center y */
                                         2, /* xsize/ysize = 2 */
                                         FALSE /* ÀÚ½ÄÀÇ °¡·Î¼¼·Î ºñÀ² ¹«½Ã*/);
   
    gtk_container_add (GTK_CONTAINER(window), aspect_frame);
    gtk_widget_show (aspect_frame);
   
    /* aspect frame¿¡ ´õÇÒ ÀÚ½Ä widgetÀ» ¸¸µç´Ù*/
   
    drawing_area = gtk_drawing_area_new ();
   
    /* 200x200 À©µµ¸¦ ¿äûÇßÁö¸¸ AspectFrameÀº 2:1 ºñÀ²À» °­Á¦Çϱ⠶§¹®¿¡
     * 200x100 À©µµ¸¦ ÁØ´Ù. */
    gtk_widget_set_usize (drawing_area, 200, 200);
    gtk_container_add (GTK_CONTAINER(aspect_frame), drawing_area);
    gtk_widget_show (drawing_area);
   
    gtk_widget_show (window);
    gtk_main ();
    return 0;
}  


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