*>>SOURCE FORMAT IS FIXED *> *************************************************************** *> Author: Brian Tiffin *> Date: 03-Dec-2008 *> Purpose: Hello from GTK+ *> Requires: libgtk2.0, libgtk2.0-dev, gtk2.0, pkg-config *> Tectonics: *> cobc -c `pkg-config --cflags gtk+-2.0` ocgtk.c *> cobc -x `pkg-config --libs gtk+-2.0` gtkhello.cob ocgtk.o *> *************************************************************** identification division. program-id. gtkhello. data division. working-storage section. 01 result usage binary-long. 01 gtk-window usage pointer. 01 gtk-box usage pointer. 01 gtk-menubar usage pointer. 01 gtk-filemenu usage pointer. 01 gtk-fileitem usage pointer. 01 gtk-fileopenitem usage pointer. 01 gtk-quititem usage pointer. 01 gtk-helpmenu usage pointer. 01 gtk-helpitem usage pointer. 01 gtk-aboutitem usage pointer. 01 gtk-hello usage pointer. 01 gtk-textentry usage pointer. 01 gtk-filebutton usage pointer. 01 gtk-goodbye usage pointer. 01 callback usage procedure-pointer. 01 params usage pointer. *> ************************************************************** procedure division. *> Initialize GTK CALL "CBL_OC_GTK_INIT_CHECK" returning result END-CALL >>D display "init: " result end-display *> Create a toplevel window CALL "CBL_OC_GTK_WINDOW_NEW" returning gtk-window END-CALL >>D display "win: " gtk-window end-display *> Set the titlebar - using cob_field now **HERE** CALL "CBL_OC_GTK_WINDOW_SET_TITLE" using by value gtk-window by reference "OpenCOBOL GTK+" END-CALL >>D display "title: " gtk-window end-display *> Set the border width CALL "CBL_OC_GTK_CONTAINER_SET_BORDER_WIDTH" using by value gtk-window by value 0 *> 5 END-CALL >>D display "border: " gtk-window end-display *> connect a window destroy, quit main loop handler set callback to entry "CBL_OC_GTK_destroy" CALL "CBL_OC_G_SIGNAL_CONNECT" using by value gtk-window by reference "delete_event" & x"00" by value callback by value params END-CALL *> Create a vertically packed box, CALL "CBL_OC_GTK_VBOX_NEW" using by value 0 by value 0 *> 5 returning gtk-box END-CALL >>D display "box: " gtk-box end-display *> Add the box to the window CALL "CBL_OC_GTK_CONTAINER_ADD" using by value gtk-window by value gtk-box END-CALL *> Create a menu bar CALL "CBL_OC_GTK_MENU_BAR_NEW" returning gtk-menubar END-CALL >>D display "menubar: " gtk-menubar end-display *> Add file menu CALL "CBL_OC_GTK_MENU_NEW" returning gtk-filemenu END-CALL >>D display "filemenu: " gtk-filemenu end-display *> Add help menu CALL "CBL_OC_GTK_MENU_NEW" returning gtk-helpmenu END-CALL >>D display "helpmenu: " gtk-helpmenu end-display *> Attach some menu items CALL "CBL_OC_GTK_MENU_ITEM_NEW_WITH_LABEL" using by reference "File" returning gtk-fileitem END-CALL >>D display "fileitem: " gtk-fileitem end-display CALL "CBL_OC_GTK_MENU_ITEM_NEW_WITH_LABEL" using by reference "Open" returning gtk-fileopenitem END-CALL >>D display "fileopenitem: " gtk-fileopenitem end-display CALL "CBL_OC_GTK_MENU_ITEM_NEW_WITH_LABEL" using by reference "Quit" returning gtk-quititem END-CALL >>D display "quititem: " gtk-quititem end-display *> Attach some help menu items CALL "CBL_OC_GTK_MENU_ITEM_NEW_WITH_LABEL" using by reference "Help" returning gtk-helpitem END-CALL >>D display "helpitem: " gtk-helpitem end-display CALL "CBL_OC_GTK_MENU_ITEM_NEW_WITH_LABEL" using by reference "About" returning gtk-aboutitem END-CALL >>D display "aboutitem: " gtk-aboutitem end-display *> Connect the open menu to the file dialog code set callback to entry "CBL_OC_GTK_filedialog" CALL "CBL_OC_G_SIGNAL_CONNECT" using by value gtk-fileopenitem by reference "activate" & x"00" by value callback by value params END-CALL *> Connect the quit menu to the bye code set callback to entry "CBL_OC_GTK_destroy" CALL "CBL_OC_G_SIGNAL_CONNECT" using by value gtk-quititem by reference "activate" & x"00" by value callback by value params END-CALL *> menu items are ready to show CALL "CBL_OC_GTK_WIDGET_SHOW" using by value gtk-menubar END-CALL CALL "CBL_OC_GTK_WIDGET_SHOW" using by value gtk-fileitem END-CALL CALL "CBL_OC_GTK_WIDGET_SHOW" using by value gtk-fileopenitem END-CALL CALL "CBL_OC_GTK_WIDGET_SHOW" using by value gtk-quititem END-CALL CALL "CBL_OC_GTK_WIDGET_SHOW" using by value gtk-helpitem END-CALL CALL "CBL_OC_GTK_WIDGET_SHOW" using by value gtk-aboutitem END-CALL *> Set the menu hierarchy CALL "CBL_OC_GTK_MENU_ITEM_SET_SUBMENU" using by value gtk-fileitem by value gtk-filemenu END-CALL CALL "CBL_OC_GTK_MENU_ITEM_SET_SUBMENU" using by value gtk-helpitem by value gtk-helpmenu END-CALL CALL "CBL_OC_GTK_MENU_SHELL_APPEND" using by value gtk-filemenu by value gtk-fileopenitem END-CALL CALL "CBL_OC_GTK_MENU_SHELL_APPEND" using by value gtk-filemenu by value gtk-quititem END-CALL CALL "CBL_OC_GTK_MENU_SHELL_APPEND" using by value gtk-helpmenu by value gtk-aboutitem END-CALL CALL "CBL_OC_GTK_MENU_SHELL_APPEND" using by value gtk-menubar by value gtk-fileitem END-CALL CALL "CBL_OC_GTK_MENU_SHELL_APPEND" using by value gtk-menubar by value gtk-helpitem END-CALL *> Pack the menu CALL "CBL_OC_GTK_BOX_PACK_START" using by value gtk-box by value gtk-menubar by value 0 by value 0 by value 3 END-CALL *> Create the hello button CALL "CBL_OC_GTK_BUTTON_NEW_WITH_LABEL" using by reference "Hello from OpenCOBOL and GTK" & x"00" returning gtk-hello END-CALL >>D display "button: " gtk-hello end-display *> Connect the hello button to the hello code set callback to entry "CBL_OC_GTK_hello" CALL "CBL_OC_G_SIGNAL_CONNECT" using by value gtk-hello by reference "clicked" & x"00" by value callback by value params END-CALL *> Pack the button into the box, top to bottom CALL "CBL_OC_GTK_BOX_PACK_START" using by value gtk-box by value gtk-hello by value 1 by value 1 by value 0 END-CALL *> button is ready to show CALL "CBL_OC_GTK_WIDGET_SHOW" using by value gtk-hello END-CALL *> Add a text entry field CALL "CBL_OC_GTK_ENTRY_NEW" returning gtk-textentry END-CALL *> Connect code to the text entry, passing the entry widget set callback to entry "CBL_OC_GTK_activate" CALL "CBL_OC_G_SIGNAL_CONNECT" using by value gtk-textentry by reference "activate" & x"00" by value callback by value gtk-textentry END-CALL *> Pack the text field into the box, top to bottom CALL "CBL_OC_GTK_BOX_PACK_START" using by value gtk-box by value gtk-textentry by value 1 by value 1 by value 0 END-CALL *> text field is ready to show CALL "CBL_OC_GTK_WIDGET_SHOW" using by value gtk-textentry END-CALL *> Create the bye button CALL "CBL_OC_GTK_BUTTON_NEW_WITH_LABEL" using by reference "Goodbye from OpenCOBOL and GTK" & x"00" returning gtk-goodbye END-CALL >>D display "button: " gtk-goodbye end-display *> Connect the bye button to the bye code set callback to entry "CBL_OC_GTK_destroy" CALL "CBL_OC_G_SIGNAL_CONNECT" using by value gtk-goodbye by reference "clicked" & x"00" by value callback by value params END-CALL *> Pack the button into the box, under hello CALL "CBL_OC_GTK_BOX_PACK_START" using by value gtk-box by value gtk-goodbye by value 1 by value 1 by value 0 END-CALL >>D display "pack: " gtk-box end-display *> button is ready to show CALL "CBL_OC_GTK_WIDGET_SHOW" using by value gtk-goodbye END-CALL *> box is ready to show CALL "CBL_OC_GTK_WIDGET_SHOW" using by value gtk-box END-CALL *> window is ready to show CALL "CBL_OC_GTK_WIDGET_SHOW" using by value gtk-window END-CALL *> Start up the event loop, control returned when GTK main exits CALL "CBL_OC_GTK_MAIN" END-CALL *> Something terminated the GTK main loop, sys-close or bye or display "ending..." end-display goback. end program gtkhello. *> ************************************************************** *> **** window shutdown callback ******************************** identification division. program-id. CBL_OC_GTK_destroy. data division. linkage section. 01 gtk-window usage pointer. 01 gtk-data usage pointer. procedure division using by value gtk-window by value gtk-data. CALL "CBL_OC_GTK_MAIN_QUIT" END-CALL goback. end program CBL_OC_GTK_destroy. *> ************************************************************** *> **** hello button click callback ***************************** identification division. program-id. CBL_OC_GTK_hello. data division. linkage section. 01 gtk-window usage pointer. 01 gtk-data usage pointer. procedure division using by value gtk-window by value gtk-data. display "Hello from GTK in OpenCOBOL at " function current-date end-display goback. end program CBL_OC_GTK_hello. *> **** file open menu callback ***************************** identification division. program-id. CBL_OC_GTK_filedialog. data division. working-storage section. 01 gtk-filedialog usage pointer. linkage section. 01 gtk-window usage pointer. 01 gtk-data usage pointer. procedure division using by value gtk-window by value gtk-data. *> Add a file selector CALL "CBL_OC_GTK_FILE_SELECTION_NEW" using by reference "title" & x"00" returning gtk-filedialog END-CALL CALL "CBL_OC_GTK_WIDGET_SHOW" using by value gtk-filedialog END-CALL goback. end program CBL_OC_GTK_filedialog. *> ************************************************************** *> **** text entry activation callback ************************** *> This procedure called from GTK on enter key pressed in entry identification division. program-id. CBL_OC_GTK_activate. data division. working-storage section. 01 textfield pic x(32). 01 textlen usage binary-long. linkage section. 01 gtk-window usage pointer. 01 gtk-data usage pointer. procedure division using by value gtk-window by value gtk-data. CALL "CBL_OC_GTK_ENTRY_GET_TEXT" using by value gtk-data textfield returning textlen END-CALL display "text: " textfield ", " textlen end-display goback. end program CBL_OC_GTK_activate.