Copyright (1997-2013) EDMGROUP Pty Ltd - EZY Prolog Reference

main page
back to grid object

Grid Object Sample

The goal of the sample:

 

predicates
    % PROGRAM ENTRY POINT FROM EZY PROLOG
    initialize_gui: EZY_INITIALIZE_GUI
    % EVENT HANDLERS CODE - INITIALIZED BY RUNTIME SYSTEM
    handler_ok: EHANDLER
    handler_cancel: EHANDLER
    grid_callbackGRID_CALLBACK
    % SYSTEM CODE
    initialize_grid(WINDOW)
    determ  grid_menu_processor(WINDOW GRID_OBJECTSTRING MENU_TITLE)
    % USER CODE
clauses


% START OF GUI INITIALIZE

initialize_gui(WINDOW):-
    write("GUI initialization started"),nl,
/* GRID INITIALIZE grid CALLBACK grid_callback */

    initialize_grid(WINDOW),
% END OF GUI INITIALIZE

    write("GUI Initialization completed"),nl,
    !.
initialize_gui(_):-!,
    write("GUI initialization failed"),nl.


/* OK HANDLER */

handler_ok(_,e_control(_,_,CTRLWIN,activated),0):-!,
    ezy_object_address(CTRLWINCTRL_ADDRESS),
    write("Button(",CTRL_ADDRESS,") activated"),nl,
    dlg_note("handler_ok Button Pressed","Button:[TOP_FRAME.buttons.Ok]"),
    % Use GUI Designer menu {Control to Clipboard/Reply code} to insert reply code here
    % Change address of top frame if it has different name
    TOP_FRAME_ADDRESS = ["TOP_FRAME"],
    ezy_object_data(CTRLWIN,TOP_FRAME_ADDRESS,VALUE_TOP_FRAME),
    % Destroy dialog and return Values
    ezy_dialog_destroy([VALUE_TOP_FRAME]).
/* CANCEL HANDLER */

handler_cancel(_,e_control(_,_,_,activated),0):-!,
    ezy_dialog_destroy([]).

grid_menu_processor(GRID_OBJECT,MENU_TITLE):-
    searchstring(MENU_TITLE,"copy",_),!,
    ezy_grid_copy(GRID_OBJECT).
grid_menu_processor(GRID_OBJECT,MENU_TITLE):-
    searchstring(MENU_TITLE,"paste",_),!,
    ezy_grid_paste(GRID_OBJECT).
grid_menu_processor(GRID_OBJECT,MENU_TITLE):-
    searchstring(MENU_TITLE,"cut",_),!,
    ezy_grid_cut(GRID_OBJECT).
grid_menu_processor(GRID_OBJECT,MENU_TITLE):-
    searchstring(MENU_TITLE,"delete",_),!,
    ezy_grid_delete(GRID_OBJECT).
grid_menu_processor(GRID_OBJECT,MENU_TITLE):-
    searchstring(MENU_TITLE,"insert",_),!,
    ezy_grid_insert(GRID_OBJECT).
grid_menu_processor(GRID_OBJECT,MENU_TITLE):-
    searchstring(MENU_TITLE,"clear",_),!,
    ezy_grid_clear(GRID_OBJECT).
grid_menu_processor(GRID_OBJECT,MENU_TITLE):-
    searchstring(MENU_TITLE,"sort a-z",_),!,
    ezy_grid_sort(GRID_OBJECT,sort_a_z).
grid_menu_processor(GRID_OBJECT,MENU_TITLE):-
    searchstring(MENU_TITLE,"sort z-a",_),!,
    ezy_grid_sort(GRID_OBJECT,sort_z_a).
grid_menu_processor(GRID_OBJECT,MENU_TITLE):-
    searchstring(MENU_TITLE,"undo",_),!,
    ezy_grid_undo(GRID_OBJECT).

/* GRID MENU HANDLER - ["TOP_FRAME","Grid"] */

/*
grid_callback(WINDOW,user_action(ACTION),_):-
write("grid_callback(",WINDOW,",","user_action","(",ACTION,")",")"),nl,
fail.
grid_callback(WINDOW,event(EVENT_MESSAGE),_):-
write("grid_callback(",WINDOW,",","event","(",EVENT_MESSAGE,")",")"),nl,
fail.
*/

grid_callback
(GRID_OBJECT,event(e_menu(MENU_ID,_)),event_answer(continue)):-!,
    ezy_menu_item(GRID_OBJECT,MENU_ID,MENU_TITLE),
    write("menu item pressed = [",MENU_TITLE,"]"),nl,
    upper_lower(MENU_TITLE,MENU_TITLE_LOW),
    grid_menu_processor(GRID_OBJECT,MENU_TITLE_LOW).

initialize_grid(WINDOW):-
    GRID_ADDR = ["TOP_FRAME","Grid"],
    ezy_object_get(WINDOW,GRID_ADDR,GRID_OBJECT),
    ezy_grid_rows(GRID_OBJECT,MAXROW),
    ezy_grid_columns(GRID_OBJECT,COLUMNNAMES),
    list_length(COLUMNNAMES,MAXCOLUMN),
    for(ROW,1,MAXROW),
        for(COL,1,MAXCOLUMN),
            ezy_grid_cellempty(GRID_OBJECT,ROW,COL),
            format(GRID_CELL_DATA,"empty cell(%,%)",ROW,COL),
            BCOLOR = ROW*255*COL*10,
            ezy_grid_cell(GRID_OBJECT,ROW,COL, textatr(str(GRID_CELL_DATA),0,BCOLOR)),
        COL=MAXCOLUMN,
    ROW=MAXROW,
    write("*** ",GRID_ADDR," Initialized"),nl,
    ezy_form_refresh(GRID_OBJECT),
    !.
goal

    true.

 

Copyright 1997-2013 EDMGROUP (Australia)