aboutsummaryrefslogtreecommitdiffstats
path: root/lib/gs/doc/src/examples
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gs/doc/src/examples')
-rw-r--r--lib/gs/doc/src/examples/die_icon9
-rw-r--r--lib/gs/doc/src/examples/ex1.erl20
-rw-r--r--lib/gs/doc/src/examples/ex10.erl59
-rw-r--r--lib/gs/doc/src/examples/ex11.erl42
-rw-r--r--lib/gs/doc/src/examples/ex12.erl33
-rw-r--r--lib/gs/doc/src/examples/ex13.erl74
-rw-r--r--lib/gs/doc/src/examples/ex14.erl46
-rw-r--r--lib/gs/doc/src/examples/ex15.erl30
-rw-r--r--lib/gs/doc/src/examples/ex16.erl40
-rw-r--r--lib/gs/doc/src/examples/ex17.erl32
-rw-r--r--lib/gs/doc/src/examples/ex2.erl19
-rw-r--r--lib/gs/doc/src/examples/ex3.erl23
-rw-r--r--lib/gs/doc/src/examples/ex4.erl23
-rw-r--r--lib/gs/doc/src/examples/ex5.erl27
-rw-r--r--lib/gs/doc/src/examples/ex6.erl23
-rw-r--r--lib/gs/doc/src/examples/ex7.erl42
-rw-r--r--lib/gs/doc/src/examples/ex8.erl22
-rw-r--r--lib/gs/doc/src/examples/ex9.erl43
18 files changed, 607 insertions, 0 deletions
diff --git a/lib/gs/doc/src/examples/die_icon b/lib/gs/doc/src/examples/die_icon
new file mode 100644
index 0000000000..52be1869fa
--- /dev/null
+++ b/lib/gs/doc/src/examples/die_icon
@@ -0,0 +1,9 @@
+#define die_icon_width 22
+#define die_icon_height 22
+static char die_icon_bits[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x7f, 0x00, 0x80, 0xff, 0x00,
+ 0xc0, 0xdd, 0x01, 0xc0, 0x88, 0x01, 0xc0, 0xdd, 0x01, 0xc0, 0xff, 0x01,
+ 0xc0, 0xff, 0x01, 0x80, 0xff, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x3e, 0x00,
+ 0x00, 0x3e, 0x00, 0x00, 0x3e, 0x00, 0x08, 0x1c, 0x07, 0xf0, 0xc0, 0x01,
+ 0x00, 0x73, 0x00, 0x00, 0x1c, 0x00, 0x80, 0x77, 0x00, 0x60, 0xc0, 0x03,
+ 0x00, 0x00, 0x06, 0x00, 0x00, 0x00};
diff --git a/lib/gs/doc/src/examples/ex1.erl b/lib/gs/doc/src/examples/ex1.erl
new file mode 100644
index 0000000000..8ba353a1d7
--- /dev/null
+++ b/lib/gs/doc/src/examples/ex1.erl
@@ -0,0 +1,20 @@
+-module(ex1).
+-copyright('Copyright (c) 1991-97 Ericsson Telecom AB').
+-vsn('$Revision: /main/release/2 $ ').
+
+-export([init/0]).
+
+init() ->
+ S = gs:start(),
+ %% the parent of a top-level window is the gs server
+ Win = gs:create(window,S,[{width,200},{height,100}]),
+ Butt = gs:create(button,Win,[{label, {text,"Press Me"}}]),
+ gs:config(Win, {map,true}),
+ loop(Butt).
+
+loop(Butt) ->
+ receive
+ {gs, Butt, click, Data, Args} ->
+ io:format("Hello There~n",[]),
+ loop(Butt)
+ end.
diff --git a/lib/gs/doc/src/examples/ex10.erl b/lib/gs/doc/src/examples/ex10.erl
new file mode 100644
index 0000000000..d414aca940
--- /dev/null
+++ b/lib/gs/doc/src/examples/ex10.erl
@@ -0,0 +1,59 @@
+-module(ex10).
+-copyright('Copyright (c) 1991-97 Ericsson Telecom AB').
+-vsn('$Revision: /main/release/2 $ ').
+
+-export([start/0, init/3]).
+
+start() ->
+ start("Pick a fruit:",
+ [apple, banana, lemon, orange, strawberry,
+ mango, kiwi, pear, cherry,pineapple,peach,apricot]).
+
+start(Text,Items) ->
+ spawn(ex10,init,[self(),Text,Items]),
+ receive
+ {browser,Result} -> Result
+ end.
+
+init(Pid,Text,Items) ->
+ S=gs:start(),
+ Win=gs:window(S,[{width,250},{height,270},
+ {title,"Browser"}]),
+ Lbl=gs:label(Win,[{label,{text,Text}},{width,250}]),
+ Entry=gs:entry(Win,[{y,35},{width,240},{x,5},
+ {keypress,true},
+ {setfocus,true}]),
+ Lb=gs:listbox(Win,[{x,5},{y,65},{width,160},
+ {height,195},{vscroll,right},
+ {click,true},{doubleclick,true}]),
+ Ok=gs:button(Win,[{label,{text,"OK"}},
+ {width,40},{x,185},{y,175}]),
+ Cancel=gs:button(Win,[{label,{text,"Cancel"}},
+ {x,175},{y,225},{width,65}]),
+ gs:config(Lb,[{items,Items}]),
+ gs:config(Win,{map,true}),
+ browser_loop(Pid,Ok,Cancel,Entry,Lb).
+
+browser_loop(Pid,Ok,Cancel,Entry,Lb) ->
+ receive
+ {gs,Ok,click,_,_} ->
+ Txt=gs:read(Entry,text),
+ Pid ! {browser,{ok,Txt}};
+ {gs,Cancel,click,_,_} ->
+ Pid ! {browser,cancel};
+ {gs,Entry,keypress,_,['Return'|_]} ->
+ Txt=gs:read(Entry,text),
+ Pid ! {browser,{ok,Txt}};
+ {gs,Entry,keypress,_,_} ->
+ browser_loop(Pid,Ok,Cancel,Entry,Lb);
+ {gs,Lb,click,_,[Idx, Txt|_]} ->
+ gs:config(Entry,{text,Txt}),
+ browser_loop(Pid,Ok,Cancel,Entry,Lb);
+ {gs,Lb,doubleclick,_,[Idx, Txt|_]} ->
+ Pid ! {browser,{ok,Txt}};
+ {gs,_,destroy,_,_} ->
+ Pid ! {browser,cancel};
+ X ->
+ io:format("Got X=~w~n",[X]),
+ browser_loop(Pid,Ok,Cancel,Entry,Lb)
+ end.
diff --git a/lib/gs/doc/src/examples/ex11.erl b/lib/gs/doc/src/examples/ex11.erl
new file mode 100644
index 0000000000..96343c3c22
--- /dev/null
+++ b/lib/gs/doc/src/examples/ex11.erl
@@ -0,0 +1,42 @@
+-module(ex11).
+-copyright('Copyright (c) 1991-97 Ericsson Telecom AB').
+-vsn('$Revision: /main/release/3 $ ').
+
+-export([start/0,init/0]).
+
+start() ->
+ spawn(ex11,init,[]).
+
+init() ->
+ I= gs:start(),
+ W= gs:window(I,[{title,"Color Demo"},
+ {width,300},{height,195}]),
+ B=gs:button(W,[{label,{image,"die_icon"}},{x,271},{y,166},
+ {width,30}]),
+ gs:config(B,[{bg,yellow},{fg,hotpink1},{data,quit}]),
+ gs:scale(W,[{text,"Red"},{y,0},{range,{0,255}},
+ {orient,horizontal},
+ {height,65},{data,red},{pos,42}]),
+ gs:scale(W,[{text,"Blue"},{y,65},{range,{0,255}},
+ {orient,horizontal},
+ {height,65},{data,blue},{pos,42}]),
+ gs:scale(W,[{text,"Green"},{y,130},{range,{0,255}},
+ {orient,horizontal},
+ {height,65},{data,green},{pos,42}]),
+ gs:config(W,{map,true}),
+ loop(W,0,0,0).
+
+loop(W,R,G,B) ->
+ gs:config(W,{bg,{R,G,B}}),
+ receive
+ {gs,_,click,red,[New_R|_]} ->
+ loop(W,New_R,G,B);
+ {gs,_,click,green,[New_G|_]} ->
+ loop(W,R,New_G,B);
+ {gs,_,click,blue,[New_B|_]} ->
+ loop(W,R,G,New_B);
+ {gs,_,click,quit,_} ->
+ true;
+ {gs,W,destroy,_,_} ->
+ true
+ end.
diff --git a/lib/gs/doc/src/examples/ex12.erl b/lib/gs/doc/src/examples/ex12.erl
new file mode 100644
index 0000000000..4af0205061
--- /dev/null
+++ b/lib/gs/doc/src/examples/ex12.erl
@@ -0,0 +1,33 @@
+-module(ex12).
+-copyright('Copyright (c) 1991-97 Ericsson Telecom AB').
+-vsn('$Revision: /main/release/2 $ ').
+
+-export([start/0,init/0]).
+
+start() -> spawn(ex12, init, []).
+
+init() ->
+ R=[{window,[{width,200},{height,200},{title,"grid"},{map, true}],
+ {grid, [{x,10},{y,10},{height,180},{width,180},{columnwidths,[80,60]},
+ {rows,{1, 20}}],
+ [{gridline,[{text,{1,"NAME"}},{text,{2,"PHONE"}},
+ {font,{screen,bold,12}},{row,1},{click,false}]},
+ {gridline,[{text,{1,"Adam"}},{text,{2,"1234"}},{row,2}]},
+ {gridline,[{text,{1,"Beata"}},{text,{2,"4321"}},{row,3}]},
+ {gridline,[{text,{1,"Thomas"}},{text,{2,"1432"}},{row,4}]},
+ {gridline,[{text,{1,"Bond"}},{text,{2,"007"}},{row,5}]},
+ {gridline,[{text,{1,"King"}},{text,{2,"112"}},{row,6}]},
+ {gridline,[{text,{1,"Eva"}},{text,{2,"4123"}},{row,7}]}]}}],
+ gs:create_tree(gs:start(),R),
+ loop().
+
+loop() ->
+ receive
+ {gs,_Win,destroy,_Data,_Args} -> bye;
+ {gs,_Gridline,click,_Data,[Col,Row,Text|_]} ->
+ io:format("Click at col:~p row:~p text:~p~n",[Col,Row,Text]),
+ loop();
+ Msg ->
+ io:format("Got ~p~n",[Msg]),
+ loop()
+ end.
diff --git a/lib/gs/doc/src/examples/ex13.erl b/lib/gs/doc/src/examples/ex13.erl
new file mode 100644
index 0000000000..f8af1f34c6
--- /dev/null
+++ b/lib/gs/doc/src/examples/ex13.erl
@@ -0,0 +1,74 @@
+-module(ex13).
+-copyright('Copyright (c) 1991-97 Ericsson Telecom AB').
+-vsn('$Revision: /main/release/2 $ ').
+
+-export([start/0,init/0]).
+
+start() -> spawn(ex13, init, []).
+
+init() ->
+ I=gs:start(),
+ Win=gs:window(I, [{width,200},{height,100},
+ {title,"menu"},{map, true}]),
+ Bar = gs:create(menubar, Win, []),
+ Fmb = gs:create(menubutton, Bar,
+ [{label,{text,"File"}}]),
+ Emb = gs:create(menubutton, Bar,
+ [{label,{text,"Edit"}}]),
+ Hmb = gs:create(menubutton, Bar,
+ [{label,{text,"Help"}},{side,right}]),
+ Fmnu = gs:create(menu, Fmb, []),
+ Emnu = gs:create(menu, Emb, []),
+ Hmnu = gs:create(menu, Hmb, []),
+ gs:create(menuitem, load, Fmnu,
+ [{label,{text, "Load"}}]),
+ gs:create(menuitem, save, Fmnu,
+ [{label,{text, "Save"}}]),
+ Exit = gs:create(menuitem, Fmnu,
+ [{label,{text, "Exit"}}]),
+ Color = gs:create(menuitem, Emnu,
+ [{label,{text, "Color"}},
+ {itemtype, cascade}]),
+ Cmnu = gs:create(menu, Color, [{disabledfg,gray}]),
+ gs:create(menuitem, Cmnu, [{label, {text,"Red"}},
+ {data, {new_color, red}},
+ {itemtype,radio},{group,gr1}]),
+ gs:create(menuitem, Cmnu, [{label, {text,"Blue"}},
+ {data, {new_color, blue}},
+ {itemtype,radio},{group,gr1}]),
+ gs:create(menuitem,Cmnu, [{label, {text,"Black"}},
+ {data, {new_color, black}},
+ {itemtype,radio},{group,gr1}]),
+ Y = gs:create(menuitem, Hmnu, [{label, {text,"You"}},
+ {itemtype, check}]),
+ M = gs:create(menuitem, me, Hmnu, [{label, {text, "Me"}},
+ {itemtype, check}]),
+ gs:create(menuitem, Hmnu, [{itemtype, separator}]),
+ gs:create(menuitem, Hmnu, [{label, {text, "Other"}},
+ {itemtype, check},
+ {enable,false}]),
+ gs:create(menuitem, doit, Hmnu, [{label, {text, "Doit!"}},
+ {data, {doit, Y, M}}]),
+ loop(Exit, Win).
+
+loop(Exit, Win) ->
+ receive
+ {gs, save, click, _Data, [Txt, Index | Rest]} ->
+ io:format("Save~n");
+ {gs, load, click, _Data, [Txt, Index | Rest]} ->
+ io:format("Load~n");
+ {gs, Exit, click, _Data, [Txt, Index | Rest]} ->
+ io:format("Exit~n"),
+ exit(normal);
+ {gs, _MnuItem, click, {new_color, Color}, Args} ->
+ io:format("Change color to ~w. Args:~p~n",
+ [Color, Args]),
+ gs:config(Win, [{bg, Color}]);
+ {gs, doit, click, {doit, YouId, MeId}, Args} ->
+ HelpMe = gs:read(MeId, select),
+ HelpYou = gs:read(YouId, select),
+ io:format("Doit. HelpMe:~w, HelpYou:~w, Args:~p~n",
+ [HelpMe, HelpYou, Args]);
+ Other -> io:format("Other:~p~n",[Other])
+ end,
+ loop(Exit, Win).
diff --git a/lib/gs/doc/src/examples/ex14.erl b/lib/gs/doc/src/examples/ex14.erl
new file mode 100644
index 0000000000..b35de6cb1c
--- /dev/null
+++ b/lib/gs/doc/src/examples/ex14.erl
@@ -0,0 +1,46 @@
+-module(ex14).
+-copyright('Copyright (c) 1991-97 Ericsson Telecom AB').
+-vsn('$Revision: /main/release/2 $ ').
+
+-export([start/0,init/0]).
+
+start() -> spawn(ex14, init, []).
+
+init() ->
+ Y = [{y,0},{height, 30},{width, 90}],
+ R=[{window, [{width, 400},{height, 300}, {title,"editor"},{map, true}],
+ [{editor,editor,[{x,0},{y, 35},{width,300},{height,250},
+ {insert,{'end',"Edit this text!"}},{vscroll,right}]},
+ {button, clear, [{label, {text, "Clear"}},{x,0} | Y]},
+ {checkbutton,enable,[{label,{text,"Enable"}},{select,false},{x,100}|Y]},
+ {button, time, [{label, {text, "Insert Time"}},{x,200} | Y]},
+ {button, quit, [{label, {text, "Quit"}},{x,300} | Y]}]}],
+ gs:create_tree(gs:start(),R),
+ gs:config(editor,{enable,false}),
+ loop().
+
+loop() ->
+ receive
+ {gs, clear, _, _, _} ->
+ io:format("clear editor~n"),
+ Enable = gs:read(editor, enable),
+ gs:config(editor,{enable, true}),
+ gs:config(editor,clear),
+ gs:config(editor,{enable, Enable});
+ {gs, enable, _, _, [_Txt, _Grp, Enable|_]} ->
+ io:format("Enable: ~w~n", [Enable]),
+ gs:config(editor,{enable, Enable});
+ {gs, time, _, _, _} ->
+ TimeStr = io_lib:format("Hr:Min:Sec is now ~w:~w:~w~n",
+ tuple_to_list(time())),
+ io:format("Insert Time: ~s~n", [TimeStr]),
+ Enable = gs:read(editor, enable),
+ gs:config(editor,{enable, true}),
+ gs:config(editor,{insert, {insert, TimeStr}}),
+ gs:config(editor,{enable, Enable});
+ {gs, quit, _, _, _} ->
+ exit(normal);
+ Other ->
+ io:format("Other:~w~n",[Other])
+ end,
+ loop().
diff --git a/lib/gs/doc/src/examples/ex15.erl b/lib/gs/doc/src/examples/ex15.erl
new file mode 100644
index 0000000000..864bdd93b2
--- /dev/null
+++ b/lib/gs/doc/src/examples/ex15.erl
@@ -0,0 +1,30 @@
+-module(ex15).
+-copyright('Copyright (c) 1991-97 Ericsson Telecom AB').
+-vsn('$Revision: /main/release/3 $ ').
+
+-export([start/0,init/0]).
+
+start() -> spawn(ex15, init, []).
+
+init() ->
+ I=gs:start(),
+ Win=gs:create(window, I,
+ [{width, 400},{height, 250},
+ {title,"Font Demo"},{map, true}]),
+ E = gs:create(canvas, can1,Win,
+ [{x,0},{y, 0},{width,400},{height,250}]),
+ Fonts = [{times,19},{screen,16},{helvetica,bold,21},
+ {symbol,12},{times,[bold,italic],33},{courier,6}],
+ show_fonts_in_boxes(Fonts,0),
+ receive
+ {gs,_Id,destroy,_Data,_Arg} -> bye
+ end.
+
+show_fonts_in_boxes([],_) -> done;
+show_fonts_in_boxes([Font|Fonts],Y) ->
+ Txt = io_lib:format("Hi! ~p",[Font]),
+ {Width,Height} = gs:read(can1,{font_wh,{Font,Txt}}),
+ Y2=Y+Height+2,
+ gs:create(rectangle,can1,[{coords,[{0,Y},{Width,Y2}]}]),
+ gs:create(text,can1,[{font,Font},{text,Txt},{coords,[{0,Y+1}]}]),
+ show_fonts_in_boxes(Fonts,Y2+1).
diff --git a/lib/gs/doc/src/examples/ex16.erl b/lib/gs/doc/src/examples/ex16.erl
new file mode 100644
index 0000000000..9c995d16bf
--- /dev/null
+++ b/lib/gs/doc/src/examples/ex16.erl
@@ -0,0 +1,40 @@
+-module(ex16).
+-copyright('Copyright (c) 1991-97 Ericsson Telecom AB').
+-vsn('$Revision: /main/release/3 $ ').
+
+-export([start/0,init/0]).
+
+start() -> spawn(ex16, init, []).
+
+init() ->
+ I=gs:start(),
+ Win=gs:create(window, I,
+ [{width, 200},{height, 200},
+ {title,"Default Demo"},{map, true}]),
+ gs:create(canvas, can1,Win,
+ [{x,0},{y, 0},{width,200},{height,200},
+ {default,text,{font,{courier,bold,19}}},
+ {default,text,{fg,blue}},
+ {default,rectangle,{fill,red}},{default,text,{text,"Pow!"}},
+ {default,oval,{fill,green}}]),
+ {A,B,C} = erlang:now(),
+ random:seed(A,B,C),
+ loop().
+
+loop() ->
+ receive
+ {gs,_Id,destroy,_Data,_Arg} -> bye
+ after 500 ->
+ XY = {random:uniform(200),random:uniform(200)},
+ draw(random:uniform(3),XY),
+ loop()
+ end.
+
+draw(1,XY) ->
+ gs:create(text,can1,[{coords,[XY]}]);
+draw(2,XY) ->
+ XY2 = {random:uniform(200),random:uniform(200)},
+ gs:create(rectangle,can1,[{coords,[XY,XY2]}]);
+draw(3,XY) ->
+ XY2 = {random:uniform(200),random:uniform(200)},
+ gs:create(oval,can1,[{coords,[XY,XY2]}]).
diff --git a/lib/gs/doc/src/examples/ex17.erl b/lib/gs/doc/src/examples/ex17.erl
new file mode 100644
index 0000000000..f659b42ae3
--- /dev/null
+++ b/lib/gs/doc/src/examples/ex17.erl
@@ -0,0 +1,32 @@
+-module(ex17).
+-copyright('Copyright (c) 1991-97 Ericsson Telecom AB').
+-vsn('$Revision: /main/release/1 $ ').
+
+-export([start/0,init/0]).
+
+start() -> spawn(ex17, init, []).
+
+init() ->
+ WH = [{width,200},{height,300}],
+ Win = gs:window(gs:start(),[{map,true},{configure,true},
+ {title,"Packer Demo"}|WH]),
+ gs:frame(packer,Win,[{packer_x,[{stretch,1,50},{stretch,2,50},
+ {stretch,1,50}]},
+ {packer_y,[{fixed,30},{stretch,1}]}]),
+ gs:button(packer,[{label,{text,"left"}},{pack_xy,{1,1}}]),
+ gs:button(packer,[{label,{text,"middle"}},{pack_xy,{2,1}}]),
+ gs:button(packer,[{label,{text,"right"}},{pack_xy,{3,1}}]),
+ gs:editor(packer,[{pack_xy,{{1,3},2}},{vscroll,true},{hscroll,true}]),
+ gs:config(packer,WH), % refresh to initial size
+ loop().
+
+loop() ->
+ receive
+ {gs,_Id,destroy,_Data,_Arg} -> bye;
+ {gs,_Id,configure,_Data,[W,H|_]} ->
+ gs:config(packer,[{width,W},{height,H}]), % repack
+ loop();
+ Other ->
+ io:format("loop got: ~p~n",[Other]),
+ loop()
+ end.
diff --git a/lib/gs/doc/src/examples/ex2.erl b/lib/gs/doc/src/examples/ex2.erl
new file mode 100644
index 0000000000..833d189602
--- /dev/null
+++ b/lib/gs/doc/src/examples/ex2.erl
@@ -0,0 +1,19 @@
+-module(ex2).
+-copyright('Copyright (c) 1991-97 Ericsson Telecom AB').
+-vsn('$Revision: /main/release/2 $ ').
+
+-export([init/0]).
+
+init() ->
+ S = gs:start(),
+ gs:create(window,win1,S,[{width,200},{height,100}]),
+ gs:create(button,b1,win1,[{label, {text,"Press Me"}}]),
+ gs:config(win1, {map,true}),
+ loop().
+
+loop() ->
+ receive
+ {gs, b1, click, Data, Args} ->
+ io:format("Hello World!~n",[]),
+ loop()
+ end.
diff --git a/lib/gs/doc/src/examples/ex3.erl b/lib/gs/doc/src/examples/ex3.erl
new file mode 100644
index 0000000000..486cec0e4e
--- /dev/null
+++ b/lib/gs/doc/src/examples/ex3.erl
@@ -0,0 +1,23 @@
+-module(ex3).
+-copyright('Copyright (c) 1991-97 Ericsson Telecom AB').
+-vsn('$Revision: /main/release/2 $ ').
+
+-export([init/0]).
+
+init() ->
+ S = gs:start(),
+ W = gs:create(window,S,[{width,300},{height,200}]),
+ B1 = gs:create(button,W,[{label, {text,"Button1"}},{y,0}]),
+ B2 = gs:create(button,W,[{label, {text,"Button2"}},{y,40}]),
+ gs:config(W, {map,true}),
+ loop(B1,B2).
+
+loop(B1,B2) ->
+ receive
+ {gs,B1,click,_Data,_Arg} -> % button 1 pressed
+ io:format("Button 1 pressed!~n",[]),
+ loop(B1,B2);
+ {gs,B2,click,_Data,_Arg} -> % button 2 pressed
+ io:format("Button 2 pressed!~n",[]),
+ loop(B1,B2)
+ end.
diff --git a/lib/gs/doc/src/examples/ex4.erl b/lib/gs/doc/src/examples/ex4.erl
new file mode 100644
index 0000000000..21a0fe3e96
--- /dev/null
+++ b/lib/gs/doc/src/examples/ex4.erl
@@ -0,0 +1,23 @@
+-module(ex4).
+-copyright('Copyright (c) 1991-97 Ericsson Telecom AB').
+-vsn('$Revision: /main/release/2 $ ').
+
+-export([init/0]).
+
+init() ->
+ S = gs:start(),
+ gs:create(window,win1,S,[{width,300},{height,200}]),
+ gs:create(button,b1,win1,[{label, {text,"Button1"}},{y,0}]),
+ gs:create(button,b2,win1,[{label, {text,"Button2"}},{y,40}]),
+ gs:config(win1, {map,true}),
+ loop(). %% look, no args!
+
+loop() ->
+ receive
+ {gs,b1,click,_,_} -> % button 1 pressed
+ io:format("Button 1 pressed!~n",[]),
+ loop();
+ {gs,b2,click,_,_} -> % button 2 pressed
+ io:format("Button 2 pressed!~n",[]),
+ loop()
+ end.
diff --git a/lib/gs/doc/src/examples/ex5.erl b/lib/gs/doc/src/examples/ex5.erl
new file mode 100644
index 0000000000..e608709991
--- /dev/null
+++ b/lib/gs/doc/src/examples/ex5.erl
@@ -0,0 +1,27 @@
+-module(ex5).
+-copyright('Copyright (c) 1991-97 Ericsson Telecom AB').
+-vsn('$Revision: /main/release/2 $ ').
+
+-export([start/0, init/0, b1/0, b2/0]).
+
+start() ->
+ spawn(ex5, init, []).
+
+init() ->
+ S = gs:start(),
+ W = gs:create(window,S,[{map,true}]),
+ gs:create(button,W,[{label,{text,"Button1"}},{data,{ex5,b1,[]}},{y,0}]),
+ gs:create(button,W,[{label,{text,"Button2"}},{data,{ex5,b2,[]}},{y,40}]),
+ loop().
+
+loop()->
+ receive
+ {gs,_,click,{M,F,A},_} -> % any button pressed
+ apply(M,F,A),
+ loop()
+ end.
+
+b1() ->
+ io:format("Button 1 pressed!~n",[]).
+b2() ->
+ io:format("Button 2 pressed!~n",[]).
diff --git a/lib/gs/doc/src/examples/ex6.erl b/lib/gs/doc/src/examples/ex6.erl
new file mode 100644
index 0000000000..ca73deb78e
--- /dev/null
+++ b/lib/gs/doc/src/examples/ex6.erl
@@ -0,0 +1,23 @@
+-module(ex6).
+-copyright('Copyright (c) 1991-97 Ericsson Telecom AB').
+-vsn('$Revision: /main/release/2 $ ').
+
+-export([start/0,init/0]).
+
+start() ->
+ spawn(ex6,init,[]).
+
+init() ->
+ S = gs:start(),
+ W = gs:create(window,S,[{map,true},{keypress,true},
+ {buttonpress,true},{motion,true}]),
+ gs:create(button,W,[{label,{text,"PressMe"}},{enter,true},
+ {leave,true}]),
+ event_loop().
+
+event_loop() ->
+ receive
+ X ->
+ io:format("Got event: ~w~n",[X]),
+ event_loop()
+ end.
diff --git a/lib/gs/doc/src/examples/ex7.erl b/lib/gs/doc/src/examples/ex7.erl
new file mode 100644
index 0000000000..a80c36fdcb
--- /dev/null
+++ b/lib/gs/doc/src/examples/ex7.erl
@@ -0,0 +1,42 @@
+-module(ex7).
+-copyright('Copyright (c) 1991-97 Ericsson Telecom AB').
+-vsn('$Revision: /main/release/2 $ ').
+
+-export([mk_window/0]).
+
+mk_window() ->
+ S= gs:start(),
+ Win= gs:create(window,S,[{motion,true},{map,true}]),
+ gs:config(Win,[{configure,true},{keypress,true}]),
+ gs:config(Win,[{buttonpress,true}]),
+ gs:config(Win,[{buttonrelease,true}]),
+ event_loop(Win).
+
+event_loop(Win) ->
+ receive
+ {gs,Win,motion,Data,[X,Y | Rest]} ->
+ %% mouse moved to position X Y
+ io:format("mouse moved to X:~w Y:~w~n",[X,Y]);
+ {gs,Win,configure,Data,[W,H | Rest]} ->
+ %% window was resized by user
+ io:format("window resized W:~w H:~w~n",[W,H]);
+ {gs,Win,buttonpress,Data,[1,X,Y | Rest]} ->
+ %% button 1 was pressed at location X Y
+ io:format("button 1 pressed X:~w Y:~w~n",[X,Y]);
+ {gs,Win,buttonrelease,Data,[_,X,Y | Rest]} ->
+ %% Any button (1-3) was released over X Y
+ io:format("Any button released X:~w Y:~w~n",[X,Y]);
+ {gs,Win,keypress,Data,[a | Rest]} ->
+ %% key `a' was pressed in window
+ io:format("key a was pressed in window~n");
+ {gs,Win,keypress,Data,[_,65,1 | Rest]} ->
+ %% Key shift-a
+ io:format("shift-a was pressed in window~n");
+ {gs,Win,keypress,Data,[c,_,_,1 | Rest]} ->
+ %% CTRL_C pressed
+ io:format("CTRL_C was pressed in window~n");
+ {gs,Win,keypress,Data, ['Return' | Rest]} ->
+ %% Return key pressed
+ io:format("Return key was pressed in window~n")
+ end,
+ event_loop(Win).
diff --git a/lib/gs/doc/src/examples/ex8.erl b/lib/gs/doc/src/examples/ex8.erl
new file mode 100644
index 0000000000..3081cb6114
--- /dev/null
+++ b/lib/gs/doc/src/examples/ex8.erl
@@ -0,0 +1,22 @@
+-module(ex8).
+-copyright('Copyright (c) 1991-97 Ericsson Telecom AB').
+-vsn('$Revision: /main/release/2 $ ').
+
+-export([start/0]).
+
+start() ->
+ gs:window(win,gs:start(),{map,true}),
+ gs:radiobutton(rb1,win,[{label,{text,"rb1"}},{value,a},{y,0}]),
+ gs:radiobutton(rb2,win,[{label,{text,"rb2"}},{value,a},{y,30}]),
+ gs:radiobutton(rb3,win,[{label,{text,"rb3"}},{value,b},{y,60}]),
+ rb_loop().
+
+rb_loop() ->
+ receive
+ {gs,Any_Rb,click,Data,[Text, Grp, a | Rest]} ->
+ io:format("either rb1 or rb2 is on.~n",[]),
+ rb_loop();
+ {gs,rb3,click,Data,[Text, Grp, b | Rest]} ->
+ io:format("rb3 is selected.~n",[]),
+ rb_loop()
+ end.
diff --git a/lib/gs/doc/src/examples/ex9.erl b/lib/gs/doc/src/examples/ex9.erl
new file mode 100644
index 0000000000..2034520c6c
--- /dev/null
+++ b/lib/gs/doc/src/examples/ex9.erl
@@ -0,0 +1,43 @@
+-module(ex9).
+-copyright('Copyright (c) 1991-97 Ericsson Telecom AB').
+-vsn('$Revision: /main/release/2 $ ').
+
+-export([start/0,init/1]).
+
+start() ->
+ spawn(ex9, init, [self()]),
+ receive
+ {entry_reply, Reply} -> Reply
+ end.
+
+init(Pid) ->
+ S = gs:start(),
+ Win = gs:create(window,S,[{title,"Entry Demo"},
+ {width,150},{height,100}]),
+ gs:create(label,Win,[{label,{text,"What's your name?"}},
+ {width,150}]),
+ gs:create(entry,entry,Win,[{x,10},{y,30},{width,130},
+ {keypress,true}]),
+ gs:create(button,ok,Win,[{width,45},{y,60},{x,10},
+ {label,{text,"Ok"}}]),
+ gs:create(button,cancel,Win,[{width,60},{y,60},{x,80},
+ {label,{text,"Cancel"}}]),
+ gs:config(Win,{map,true}),
+ loop(Pid).
+
+loop(Pid) ->
+ receive
+ {gs,entry,keypress,_,['Return'|_]} ->
+ Text=gs:read(entry,text),
+ Pid ! {entry_reply,{name,Text}};
+ {gs,entry,keypress,_,_} -> % all other keypresses
+ loop(Pid);
+ {gs,ok,click,_,_} ->
+ Text=gs:read(entry,text),
+ Pid ! {entry_reply,{name,Text}};
+ {gs,cancel,click,_,_} ->
+ Pid ! {entry_reply,cancel};
+ X ->
+ io:format("Got X=~w~n",[X]),
+ loop(Pid)
+ end.