MGtk Reference Manual | ||||
---|---|---|---|---|
| Description |
Example 5_bExample 5_b — From Gtk to MGtk |
Example 16. Example b MGtk 0.0.1
#include <gtk/gtk.h> #include <mlib.h> #include <mgtk.h> static gboolean delete_event ( GtkWidget* widget, GdkEvent* event, mpointer data ) { gtk_main_quit (); return FALSE; m_warning_disable_var ( widget ); m_warning_disable_var ( event ); m_warning_disable_var ( data ); } #define SIDE_CELL 6 #define MAX_CELL ( SIDE_CELL * SIDE_CELL) int mgtk_main ( argc, argv ) { mgtk_main_init ( argc, argv ); MId window = MNOID; MId button[MAX_CELL]; MId buttonX = MNOID; MId table = MNOID; MIdArchive* archive = mgtk_idarchive_new (); muint index; mchar str[256] = { '\0' }; mchars pstr = NULL; window = mgtk_window_insert ( GTK_WINDOW_TOPLEVEL, "Table" ); fortooffset ( index, MAX_CELL ) { sprintf ( str, "button[%u]", index ); pstr = g_strdup (str); button[index] = mgtk_button_insert ( str ); MGTK_BUTTON_ARCHIVE_ID ( archive, button[index], pstr ); MGTK_OBJECTDATA_name( MGTK_M_BUTTON_(button[index]) ) = pstr; } buttonX = mgtk_button_insert ( "X" ); table = mgtk_squared_table_insert ( MAX_CELL, HOMOGENEOUS_ON ); MGtkAttachMapTable* map = mgtk_attach_mapping_table_new ( GTK_TABLE (MGTK_TABLE_(table)) ); MGtkAttach4MapTable* cell = mgtk_attach_4map_table_new_from_angle ( MGPID (map,0), MGPID (map,28) ); MGtkAttachMapTable* _cell2 = mgtk_attach_map_table_new ( 4, 6, 3, 6 ); MGtkAttach4MapTable* cell2 = mgtk_attach_map_table_to_four ( _cell2 ); gtk_container_set_border_width ( GTK_CONTAINER ( MGTK_WINDOW_(window) ), 20 ); m_signal_connect ( "delete-event", MGTK_WINDOW_(window), G_CALLBACK (delete_event), NULL ); gtk_container_add ( GTK_CONTAINER ( MGTK_WINDOW_(window) ), MGTK_TABLE_(table) ); fortooffset ( index, (MAX_CELL-1) ) { gtk_table_attach_defaults ( GTK_TABLE ( MGTK_TABLE_(table) ), MGTK_BUTTON_(button[index]), MGTK_ATTACH_MAP_TABLE_EXPAND( map, index ) ); } gtk_table_attach_defaults ( GTK_TABLE ( MGTK_TABLE_(table) ), MGTK_BUTTON_(button[MAX_CELL-1]), MGTK_ATTACH_4MAP_TABLE_EXPAND ( cell2 ) ); gtk_table_attach_defaults ( GTK_TABLE ( MGTK_TABLE_(table) ), MGTK_BUTTON_(buttonX), MGTK_4MAP_GET_LEFT_ATTACH (cell), MGTK_4MAP_GET_RIGHT_ATTACH (cell), MGTK_4MAP_GET_TOP_ATTACH (cell), MGTK_4MAP_GET_BOTTOM_ATTACH (cell) ); fortooffset ( index, SIDE_CELL ) { gtk_widget_show( MGTK_BUTTON_(button[index]) ); gtk_widget_show( MGTK_BUTTON_(button[index+30]) ); } forsettooffset ( index, 30, +6 ) { gtk_widget_show( MGTK_BUTTON_(button[index]) ); gtk_widget_show( MGTK_BUTTON_(button[index+5]) ); } gtk_widget_show( MGTK_BUTTON_(button[15]) ); gtk_widget_show ( MGTK_BUTTON_(buttonX) ); gtk_widget_show ( MGTK_TABLE_(table) ); gtk_widget_show ( MGTK_WINDOW_(window) ); gtk_main (); return 0; }