home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lifeos2.zip / LIFE-1.02 / LIB / EX_TOOLS.LF < prev    next >
Text File  |  1996-06-04  |  6KB  |  227 lines

  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. %    $Id: ex_tools.lf,v 1.2 1994/12/08 23:57:30 duchier Exp $    
  3. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  4. %
  5. % Small example of some the features of the X-toolkit
  6. %
  7. % Author: Bruno Dumant
  8. % (c) Copyright 1993 - Digital Equipment Corporation
  9. % All rights reserved.
  10. %
  11. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  12. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  13.  
  14. %%% load the toolkit, open the xtools module
  15.  
  16.  
  17. module("ex_tools") ?
  18. public(ex_tools) ?
  19.  
  20. import("xtools")?
  21.  
  22.  
  23. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  24. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  25.  
  26. %%% interface design
  27.  
  28. persistent(panels) ?
  29.  
  30. interface :-
  31.  
  32.     %% declaration of the some of the buttons used. Except button1 and
  33.     %% t_box1, all the sorts are predefined by the toolkit.
  34.  
  35.     B1 = text_field_button(height => Hb,
  36.                            text => "100",
  37.                    action => set_slider(B1,Slider), 
  38.                    offset => -5),
  39.     B2 = push_button(text => "Push Button"),
  40.     B3 = on_off_button(text => "On/Off"),
  41.     B4 = button1(text => "Custom Button",        % see def of button1 below
  42.              action => action4),
  43.     B5 = menu_button(menu => Menu,text => "Menu..."),
  44.     B6 = push_button(text => "Quit", action => abort), 
  45.               
  46.         TB1 = t_box1(width => Wt,text => "Text Box"), % see def of t_box1 below
  47.     
  48.  
  49.         %%% B1..B6 must have the same size
  50.  
  51.         same_size([B1,B2,B3,B4,B5,B6]),
  52.  
  53.  
  54.     %% PLACEMENT CONSTRAINTS
  55.  
  56.         %% vl_list: Vertical_Left-aligned_list
  57.         %% hc_list: Horizontal_Centered_list
  58.         %% All these operators are prefix operators
  59.         %% r: right; l: left; t: top; b: bottom; c: center 
  60.  
  61.     Box1 =   vl_list [B1,B2,B3] t_left_of 
  62.              hc_list [h_box(10),TB1,B4] r_above
  63.              B5,
  64.         Box2:@(width => Width,height => Height) = vc_list [Box1,v_box(15),B6],
  65.  
  66.     VSlide = v_slide_bar(height => Height) containing
  67.             Slider:v_slider(min => 0,
  68.                         max => 100,
  69.                     action => set_text(Slider,B1)),
  70.     HSlide = slide_bar(width => Width) containing 
  71.             h_slider(min => 0,
  72.                  max => 100,
  73.                  action => succeed),
  74.  
  75.     Box3 = ht_list [Box2,h_box(5),VSlide],
  76.     Box4 = vl_list [Box3,v_box(5),HSlide],
  77.  
  78.  
  79.     %% definition of the main panel
  80.     
  81.     Panel = panel(title => "XTools Demo") 
  82.                    containing Box4,
  83.     
  84.     %% definition of the menu
  85.     
  86.         FirstCol:@(height => MenuHeight) = 
  87.             menu_list [item_2(text => T1:"Unix"),
  88.                    item_2(text => T2:"VMS"),
  89.                item_2(text => T3:"OSF/1"),
  90.                item_2(text => T4:"Windoze NT")],
  91.  
  92.     I1 = item_1(text => "Tile",           %%% see def of
  93.             action => do_tiles,       %%% item_1 below
  94.             height => MenuHeight/2,
  95.             true_text_color_id => 2),
  96.     I2 = item_1(text => "Refresh",
  97.             action => do_refresh,
  98.             height => MenuHeight/2,
  99.             true_text_color_id => 2),
  100.  
  101.     same_width([I1,I2]),
  102.     
  103.     Menu =  menu_panel containing 
  104.                     FirstCol c_left_of 
  105.                     vl_list [I1,I2],
  106.  
  107.     %% It is possible to add buttons to a panel in any order before
  108.         %% its creation.
  109.             
  110.     Push2:push_button(width => Wt,height => Hb,text =>"Scroll",
  111.                       action => scroll([B1,B2,B3])) 
  112.               lr_aligned B6,
  113.     B6 tb_aligned Push2,
  114.  
  115.     Panel contains Push2,
  116.  
  117.     %% Panel and Menu are now completely specified, they may be saved in a
  118.     %% persistent term.
  119.     
  120.     panels <<- [Panel,Menu].
  121.  
  122.  
  123. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  124. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  125.  
  126. %%% Custom Button Types
  127. %%% These buttons don't have the standard colors & fonts. The ids are used by
  128. %%% the tables defined below (see Tables)
  129.  
  130. %%% There is no predefined color id, and two predefined font ids: medium and
  131. %%% bold. 
  132.  
  133. button1 <| on_off_button.
  134. :: button1(color_id => 1,text_color_id => 4,led_on_color_id => 3,
  135.        font_id => custom,true_text_color_id => 3).
  136.  
  137. t_box1 <| text_box.
  138. :: t_box1(text_color_id => 2,font_id => medium).
  139.  
  140. item_1 <| item_c.
  141. item_1 <| frame.
  142. item_1 <| text_box.
  143. :: I:item_1(on => On,
  144.         depth => 2,
  145.         change_state => change_menu_item(On,I)).
  146.  
  147. item_2 <| menu_item.
  148. :: I:item_2(text => T,action => writeln(T)).
  149.  
  150. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  151. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  152.  
  153. %%% Tables
  154.  
  155. %%% Color Tables 
  156.  
  157. def_color(shade_colors,1,X:new_color(63,106,106)),
  158.   def_color(main_colors,4,X)?
  159. def_color(highlight_colors,1,new_color(118,197,197))?
  160. def_color(main_colors,1,'cadet blue') ?
  161.  
  162. def_color(main_colors,2,red) ?
  163.  
  164. def_color(shade_colors,3,'lime green') ?
  165. def_color(highlight_colors,3,'green yellow') ?
  166. def_color(main_colors,3,green) ?
  167.  
  168.  
  169. %%% font table
  170.  
  171. def_font(custom,new_font("souvenir_demi10")) ?
  172.  
  173. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  174. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  175.  
  176. %%% the interface may be compiled at load time
  177.  
  178. interface ?
  179.  
  180. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  181. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  182.  
  183. %%% Actions
  184.  
  185. set_slider(@(text => T),Slider:@(max => Max,min => Min)) :-
  186.     Y = parse(T),
  187.     cond( Y :< real,
  188.         cond( Y >= Min and Y =< Max,
  189.             move_slider(Slider,Y)
  190.         )
  191.     ).
  192.  
  193. set_text(@(value => V),BT:@(text => T)) :-
  194.         T <<- int2str(floor(V)),
  195.     refresh_look(BT).
  196.  
  197. scroll(L:[B1:@(X1,Y1),B2:@(X2,Y2),B3:@(X3,Y3)]) :-
  198.     X4 = root_sort(X1),
  199.     Y4 = root_sort(Y1),
  200.     move_widget(B1,X2,Y2),
  201.     move_widget(B2,X3,Y3),
  202.     move_widget(B3,X4,Y4),
  203.     L <- [B3,B1,B2].
  204.  
  205. action4 :-
  206.     writeln("Button pressed: ",button_pressed).
  207.  
  208. do_tiles.
  209.  
  210. do_refresh :-
  211.     X = system("xrefresh").
  212.  
  213.  
  214. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  215. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  216.  
  217. %%% utility 
  218.  
  219. C:writeln :- write&strip(C), nl.
  220.  
  221. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  222. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  223.  
  224. %%% main predicate
  225.  
  226. ex_tools :- create_boxes(copy_term(panels)) .
  227.