#! /bin/sh #------------------------------------------------------------------------------ # /var/install/include/ecelib - script interface for edit-conf.cui # # Creation: 2007-11-01 dv # Last update: $Id$ # # Copyright (c) 2004-2008 the eisfair team, team(at)eisfair(dot)org # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------- # ece API codes ECE_API_GETVALUE=1000 value="" #------------------------------------------------------------------------------ # Get variable within current configuration loaded in editor # Expects: $1 <-- MainWin : Window Handle # $2 <-- Variable-Name : String (something like "FOO_2_NAME") # Returns: $p2 --> Value : String #------------------------------------------------------------------------------ function ece_get_value() { cui_send "C" "${ECE_API_GETVALUE}" "$@" cui_wait_ack return $? } #---------------------------------------------------------------------------- # setdata # ece --> preinitialize value before the dialog is opened #---------------------------------------------------------------------------- function setdata() { value="$p2" cui_return "" } #---------------------------------------------------------------------------- # getdata # ece --> request modified value after the dialog has been closed with IDOK #---------------------------------------------------------------------------- function getdata() { cui_return "$value" } #---------------------------------------------------------------------------- # SELECT LIST DIALOG BEGIN #---------------------------------------------------------------------------- ECE_SELECT_LIST_DLG_IDC_COLORS=10 ECE_SELECT_LIST_DLG_IDC_OK=11 ECE_SELECT_LIST_DLG_IDC_CANCEL=12 #---------------------------------------------------------------------------- # ece_select_list_dlg_ok_button # OK button clicked callback #---------------------------------------------------------------------------- function ece_select_list_dlg_ok_button() { local win="$p2" local ctrl local sel if cui_window_getctrl "$win" "${ECE_SELECT_LIST_DLG_IDC_COLORS}" then ctrl="$p2" if cui_listbox_getsel "$ctrl" then sel="$p2" cui_listbox_get "$ctrl" "$sel" value="$p2" fi fi cui_window_close "$win" "${IDOK}" cui_return 1 } #---------------------------------------------------------------------------- # ece_select_list_dlg_cancel_button # Cancel button clicked callback #---------------------------------------------------------------------------- function ece_select_list_dlg_cancel_button() { local win="$p2" cui_window_close "$win" "${IDCANCEL}" cui_return 1 } #---------------------------------------------------------------------------- # ece_select_list_dlg_create_hook (for creation of child windows) # $p2 --> dialog window handle #---------------------------------------------------------------------------- function ece_select_list_create_hook() { local dlg="$p2" local ctrl local count="0" # create listbox if cui_listbox_new "$dlg" "" 2 1 28 7 ${ECE_SELECT_LIST_DLG_IDC_COLORS} $CWS_NONE $CWS_BORDER then ctrl="$p2" cui_window_setcolors "$ctrl" "MENU" cui_window_create "$ctrl" LOCAL_OLD_IFS="$IFS" IFS="," for sel in ${ece_select_list} do cui_listbox_add "$ctrl" "$sel" count=$[$count + 1] done IFS="$LOCAL_OLD_IFS" if [ "$count" -gt 7 ] then count=7 fi cui_window_move "$ctrl" 2 1 28 $count cui_listbox_select "$ctrl" "$value" fi # create buttons if cui_button_new "$dlg" "&OK" 5 "$[$count + 2]" 10 1 ${ECE_SELECT_LIST_DLG_IDC_OK} $CWS_DEFOK $CWS_NONE then ctrl="$p2" cui_button_callback "$ctrl" "$BUTTON_CLICKED" "$dlg" "ece_select_list_dlg_ok_button" cui_window_create "$ctrl" fi if cui_button_new "$dlg" "&Cancel" 17 "$[$count + 2]" 10 1 ${ECE_SELECT_LIST_DLG_IDC_CANCEL} $CWS_DEFCANCEL $CWS_NONE then ctrl="$p2" cui_button_callback "$ctrl" "$BUTTON_CLICKED" "$dlg" "ece_select_list_dlg_cancel_button" cui_window_create "$ctrl" fi # move the window if cui_getwindowrect "$dlg" then local wx="$p2" local wy="$p3" local ww="$p4" local wh="$p5" local delta="$[7 - $count]" cui_window_move "$dlg" "$wx" "$[$wy + $delta / 2]" 34 "$[13 - $delta]" fi cui_return 1 } #---------------------------------------------------------------------------- # ece_select_list_dlg - Select an item from a single list box # Expects: $1 <-- Parent window : Window Handle # $2 <-- Title : String # $3 <-- SelList : String ("Value1,Value2,Value3") # Returns: Nothing #---------------------------------------------------------------------------- function ece_select_list_dlg() { local win="$1" local title="$2" local result="$IDCANCEL" ece_select_list="$3" if cui_window_new "$win" 0 0 34 13 $[$CWS_POPUP + $CWS_BORDER + $CWS_CENTERED] then dlg="$p2" cui_window_setcolors "$dlg" "DIALOG" cui_window_settext "$dlg" "$title" cui_window_sethook "$dlg" "$HOOK_CREATE" ece_select_list_create_hook cui_window_create "$dlg" cui_window_modal "$dlg" && result="$p2" cui_window_destroy "$dlg" fi cui_return $result } #---------------------------------------------------------------------------- # SELECT LIST DIALOG END #----------------------------------------------------------------------------