From: Andrey C. <sku...@us...> - 2006-06-02 14:12:16
|
Update of /cvsroot/eas-dev/clip-ui/example In directory sc8-pr-cvs5.sourceforge.net:/tmp/cvs-serv3248/example Added Files: Makefile form_ui.prg testWindow.xfl test_ui.prg Log Message: Add files --- NEW FILE: Makefile --- # CLIP-UI library examples Makefile # Copyright (C) 2003-2006, E/AS Software Foundation # Web: http://eas.lrn.ru ifndef CLIPROOT CLIPROOT=$(shell cd ../../../../; pwd)/cliproot endif include $(CLIPROOT)/include/Makefile.inc CLIPINCLUDE = -I$(CLIPROOT)/include CLIP = $(CLIPROOT)/bin/clip .SUFFIXES: .prg .o .po .PHONY: all clean # Widget tests PRG1=test_ui PRG2=form_ui LIBS=-lclip-ui -lclip-xml -lexpat EXTRALIBS= all: $(PRG1) $(PRG2) clean: rm -f *.o *.bak core* *core $(PRG1) $(PRG2) *.log *.nm *.ex *.exe $(OUTPUT) $(PRG1): test_ui.prg $(CLIP) -ewslM $(CLIPINCLUDE) test_ui.prg $(LIBS) $(EXTRALIBS) $(PRG2): form_ui.prg $(CLIP) -ewsl $(CLIPINCLUDE) form_ui.prg $(LIBS) $(EXTRALIBS) #.prg.o: # $(CLIP) -l $(CLIPINCLUDE) $< --- NEW FILE: form_ui.prg --- /*-------------------------------------------------------------------------*/ /* This is a part of CLIP-UI library */ /* */ /* Copyright (C) 2003-2005 by E/AS Software Foundation */ /* Author: Andrey Cherepanov <sk...@ea...> */ /* */ /* 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. */ /*-------------------------------------------------------------------------*/ #include <clip-ui.ch> #define PRGVERSION "0.1.2.4" static ws, win function main() local i,form local fileName,driver local params := array(0) driver := "gtk" i := 1 while i <= pcount() if left(param(i),9) == "--driver=" driver := substr(param(i),10) elseif param(i) == "-driver" .and. i+1<=pcount() driver := param(i+1) i += 2 loop else aadd(params, param(i)) endif i++ enddo // Get fileName from parameters if len(params) == 0 ?? "Usage: ./form_ui [--driver=<DRIVER>] <form.xfl>&\n" CANCEL else fileName := params[1] endif /* Use driver for GTK+ 2.x */ ?? "Used driver: "+driver,chr(10) useDriver( driver ) ws := UIWorkSpace( params ) form := UIForm( fileName ) win := form:parseFile() if win == NIL CANCEL endif win:show() ws:run() ws:quit() return 0 --- NEW FILE: testWindow.xfl --- <?xml version="1.0" encoding="koi8-r" ?> <!-- Test interface form --> <!-- Web: http://eas.lrn.ru --> <form> <head> <call widget="mainWindow" method="setCaption"> <param><call method="getClipUIVersion" /></param> </call> </head> <interface> <widget class="mainWindow" name="mainWindow" label="clip-ui test form"> <!-- Menu --> <widget class="menuBar"> <widget class="popupMenu" name="journal_menu" label="&Journal"> <widget class="menuItem" label="&Payment orders" name="Menu.Bank.PaymentOrder.List"> <property name="icon" value="icons/journal_bank_pp.xpm"/> </widget> <widget class="menuItem" label="&Create payment order" name="Menu.Bank.PaymentOrder.Create"> <property name="icon" value="icons/doc_bank_pp.xpm"/> </widget> <widget class="menuSeparator"/> <widget class="menuItem" label="&Exit" name="Menu.Quit"/> </widget> <widget class="popupMenu" name="cfg_menu" label="&Settings"> <widget class="menuCheckedItem" name="showTB" label="Show &toolbar" /> <widget class="menuCheckedItem" name="showSB" label="Show &statusbar" /> <widget class="menuSeparator"/> <widget name="Settings" class="menuItem" label="&Configure..."/> </widget> </widget> <!-- Toolbar --> <widget class="toolBar" name="main_toolBar"> <widget name="TB.Bank.PaymentOrder.List" class="toolButton" label="Payment orders"> <property name="icon" value="icons/journal_bank_pp.xpm"/> </widget> <widget name="TB.Bank.PaymentOrder.Create" class="toolButton" label="Create payment order"> <property name="icon" value="icons/doc_bank_pp.xpm"/> </widget> <widget name="TB.Partner.List" class="toolButton" label="Partners"> <property name="icon" value="icons/reference_partner.xpm"/> </widget> </widget> <widget class="vsplitter"> <widget class="hsplitter"> <widget class="tree" > <column name="n1" title="N1"/> <column name="n2" title="N2"/> <property name="row" element="node1" value="'Node1', 'node1111'" /> <property name="row" element="node11" value="'Node2'" /> <property name="row" element="node2.node1" value="'Leaf1'" /> <property name="row" element="node3.node1" value="'Leaf2'" /> <property name="row" element="node5.node1" value="'Leaf5', 'Leaf5'" /> <property name="row" element="node4.node1.node3" value="'Leaf3'" /> <property name="row" element="node44.node11" value="'Leaf3333'" /> <property name="row" element="node55.node44" value="'Leaf333'" /> <property name="row" element=".node55" value="'Leaf33'" /> </widget> <widget class="table"> <column name="num" title="#"/> <column name="date" title="Date"/> <column name="payee" title="Payee"/> <column name="sum" title="Sum"/> <property name="altColor" value="#cbe8ff" /> <property name="row" element="1" value="'1','20.10.03','JSC "Lighthouse"','20000.00'" /> <property name="row" element="2" value="'2','20.10.03','JSC "Phoenix"','5689.20'" /> <property name="row" element="3" value="'3','21.10.03','JSC "Phoenix"','1500.00'" /> <property name="row" element="4" value="'4','25.10.03','JSC "Phoenix"','99.00'" /> </widget> </widget> <widget class="vbox"> <property name="spacing" value="3" /> <property name="padding" value="3" /> <widget name="tax" class="checkbox" label="Use &tax"> <property name="value" value="false" /> </widget> <widget class="radiogroup"> <widget class="radioButton" name="button1" label="button1" /> <widget class="radioButton" name="button2" label="button2" /> </widget> <widget class="slider" > <property name="value" value="10" /> <property name="range" value="5-60" /> <property name="step" value="5" /> </widget> <widget class="progressbar" label="Progress: " /> <widget class="hbox"> <property name="padding" value="3" /> <widget class="label" label="Payment order N "> <property name="font.style" value="bold" /> <property name="font.size" value="16" /> <property name="color.fg" value="#FF1790" /> </widget> <widget name="number" class="edit" label=""> <property name="geometry.width" value="50" /> <property name="value" value="11" /> </widget> <widget class="label" label=" from " /> <widget name="date" class="editdate" label=""> <property name="geometry.width" value="70" /> <property name="value" value="20.10.03" /> </widget> </widget> <widget name="color" class="editcolor" label=""> <property name="value" value="#91FF40" /> </widget> <widget name="file" class="editfilename" label=""> <property name="value" value="testWindow.xfl" /> </widget> <!-- Payer --> <widget class="frame" label="Payer"> <property name="color.bg" value="darkblue" /> <property name="type" value="raised" /> <widget class="vbox"> <property name="padding" value="3" /> <widget class="combobox" name="payer"> <property name="values" value="'JSC "Brown and son"'" /> </widget> </widget> </widget> <!-- Payee --> <widget class="frame" label="Payee"> <property name="type" value="sunken" /> <widget class="vbox"> <property name="padding" value="3" /> <widget class="combobox" name="payee"> <property name="values" value="'JSC "Lighthouse"','JSC "Ronal"','JSC "Porechnoye"'" /> <property name="selection" value="2" /> </widget> </widget> </widget> <!-- Sum --> <widget class="hbox"> <widget class="label" label="&Sum: " /> <widget class="edit" name="sum"> <property name="value" value="20000.00" /> <property name="color.base" value="#C2D2FF" /> <property name="color.bg" value="red" /> </widget> </widget> <widget class="label" label="Description:" /> <widget class="edittext" name="reason" > <property name="value" value="For delivered goods." /> </widget> <!-- Bottom panel --> <widget class="hbox"> <widget class="layout"> <widget class="button" name="save" label="Save" /> <widget class="button" name="print" label="Print" pos="60,0" /> <widget class="button" name="close" label="Close" pos="120,10" /> </widget> </widget> </widget> </widget> <!-- Statusbar --> <widget class="statusBar" name="main_statusBar" label="Ready." /> </widget> </interface> <!-- Widget properties --> <style> <property widget="mainWindow" name="geometry" value="600,550,35,15" /> <property widget="mainWindow" name="position" value="center" /> <property widget="mainWindow" name="icon" value="icons/eas-logo.xpm" /> </style> <!-- Actions --> <actions> <!-- System actions --> <rule> <event widget="Menu.Quit" signal="activate"/> <event widget="close" signal="activate"/> <action><call widget="mainWindow" method="close"/></action> </rule> <rule> <event widget="showTB" signal="activate"/> <action><call widget="main_toolBar" method="show"> <param><call widget="showTB" method="isChecked" /></param> </call> </action> </rule> <rule> <event widget="showSB" signal="activate"/> <action> <call widget="main_statusBar" method="show"> <param><call widget="showSB" method="isChecked" /></param> </call> </action> </rule> <rule> <event widget="TB.Bank.PaymentOrder.List" signal="clicked"/> <action><call method="qout"> <param value="List of payment orders" /></call> </action> </rule> <rule> <event widget="TB.Bank.PaymentOrder.Create" signal="clicked"/> <action><call method="qout"> <param value="Create payment order" /></call> </action> </rule> <rule> <event widget="Settings" signal="activate"/> <action><call method="Configuration"/></action> </rule> </actions> </form> --- NEW FILE: test_ui.prg --- /*-------------------------------------------------------------------------*/ /* This is a part of CLIP-UI library */ /* */ /* Copyright (C) 2003-2005 by E/AS Software Foundation */ /* Author: Andrey Cherepanov <sk...@ea...> */ /* */ /* 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. */ /*-------------------------------------------------------------------------*/ #include <clip-ui.ch> /* Test of clip-ui library usage */ static ws static wnd := NIL, ww1, ww2 static childToolbar static timer, tbState, iteration /* Declaration */ local menu, i, sp, b, cff local journal_menu, action_menu, doc_menu local ref_menu, cfg_menu, window_menu, help_menu local main_tbar, statusbar local accel_group, driver local win := NIL, params:=array(0) driver := "gtk" for i:=1 to pcount() if left(param(i),9) == "--driver=" driver := substr(param(i),10) elseif param(i) == "-driver" .and. i+1<=pcount() driver := param(i+1) else aadd(params, param(i)) endif next /* Use driver for GTK+ 2.x */ ?? "Used driver: "+driver,chr(10) useDriver( driver ) /* create workspace */ ws := UIWorkSpace( params ) /*--------------------------------------------------------------------*/ /* create main window */ win := UIMainWindow("E/AS " + getClipUIVersion(), NIL, "mainWindow" ) // create menu of main window menu := UIMenu() journal_menu := UIPopupMenu() action_menu := UIPopupMenu() doc_menu := UIPopupMenu() ref_menu := UIPopupMenu() cfg_menu := UIPopupMenu() window_menu := UIPopupMenu() help_menu := UIPopupMenu() menu:add(,"&Journal", journal_menu) i := journal_menu:add( UIImage("icons/journal_bank_pp.xpm"),"&Payment orders", {|| qout("Payment orders") } ) journal_menu:disable(i) i := journal_menu:add( UIImage("icons/doc_bank_pp.xpm"),"&Create payment order", {|| qout("Create payment order") } ) journal_menu:add(,"Submenu",help_menu) help_menu:add(UIImage("icons/journal_bank_pp.xpm"),"Item",{|| qout("Item") }) help_menu:add(,"Item2",{|| qout("Item2") }) journal_menu:setKey(i,"F5") journal_menu:addSeparator() journal_menu:add(,"&Exit", @quit()) menu:add(,"&Settings", cfg_menu) cff := @cfg_menu win:widget["showTB"] := cfg_menu:addChecked(.T., "Show &toolbar", {|w,e| showToolBar(win, "showTB", cfg_menu) } ) win:widget["showSB"] := cfg_menu:addChecked(.T., "Show &statusbar", {|w,e| showStatusBar(win, "showSB", cfg_menu) } ) cfg_menu:addSeparator() cfg_menu:add(,"&Configure...", NIL) //journal_menu:clear() // ToolBars main_tbar := UIToolBar() main_tbar:addButton( UIImage("icons/journal_bank_pp.xpm"), "List of payment orders", {|| qout("List of payment orders") } ) main_tbar:addButton( UIImage("icons/doc_bank_pp.xpm"), "Create payment order", {|| qout("Create payment order") }) main_tbar:addSeparator() main_tbar:addButton( UIImage("icons/reference_partner.xpm"), "Partners", NIL ) //main_tbar:remove(1) statusbar := UIStatusBar() statusbar:setText("Ready.") win:setPanels( menu, main_tbar, statusbar ) win:setMDI() ww1 := UIDocument("Core widgets", win) /* Test widgets */ sp := UISplitter(SPLITTER_VERTICAL) ww1:add(sp, .T., .T.) sp:setPosition( 200 ) BankRefReq( sp ) b := UIVBox(,3,3) sp:addEnd(b) BankDocReq( ww1, b ) ww2 := UIChildWindow("", win) OtherWidget(ww2) ww1:show() ww2:setCaption("Other widgets") ww2:show() ww1:show() // Assign icon to window. win:setIcon( UIImage("icons/eas-logo.xpm") ) // Put window to screen center win:setPlacement( .T. ) // Set size to 600x450 win:setGeometry( { 600, 550, 35, 15 } ) //----------------------------------------------------------------------------- /* show window */ win:show() /* run infinitive application loop */ ws:run() ws:quit() /**================== FUNCTIONS ==================**/ static function quit() ws:quit() return 0 /* Show/hide tool bar */ static function showToolBar(window, id, menu) if window:toolbar != NIL if menu:isChecked(window:widget[id]) window:toolbar:show() else window:toolbar:hide() endif endif return 0 /* Show/hide status bar */ static function showStatusBar(window, id, menu) if window:statusbar != NIL if menu:isChecked(window:widget[id]) window:statusbar:show() else window:statusbar:hide() endif endif return 0 /* Tree and table widgets */ static function BankRefReq( sp ) local splitter, tree, table, vb local node66, node67 splitter := UISplitter(SPLITTER_HORIZONTAL) sp:add(splitter, .T., .T.) tree := UITree(, {"N1","N2"}) tree:setAction("selected",{|w,e| listEventTree(tree, e) }) splitter:add( tree ) table := UITable({"#","Date","Payee","Sum"}) table:setAltRowColor("#cbe8ff") // Fill tree and table updateTable(tree, table) node66 := tree:addNode({"Parent_Last"}) node67 := tree:addNode({"Last Leaf"},, node66) table:addRow({"8","25.10.03",'Last: JSC "Phoenix"',"99.00"}) vb := UIVbox() table:setAction("selected",{|w,e| listEvent(table, e) }) vb:add(table, .T., .T.) vb:addEnd(UIButton("&Update views", {|| updateTable(tree, table) })) splitter:addEnd( vb ) return NIL static function listEventTree(tree, c) ?? "Select in tree:",c,"(id =",tree:getSelectionId(),")",chr(10) return function listEvent(table, c) ?? "Select in table:",c,"(id =",table:getSelectionId(),")",chr(10) return function updateTable(tree, table) local pos local node1,node2,node3,node4,node5 local node11, node44, node55, node66, node67 // Tree data pos := tree:savePosition() ?? "Tree pos:", pos, chr(10) tree:clear() node1 := tree:addNode({"Node1", "node1111"}) node11 := tree:addNode({"Node2"}) node2 := tree:addNode({"Leaf1"},, node1) node3 := tree:addNode({"Leaf2"},, node1) node5 := tree:addNode({"Leaf5", "Leaf5"},, node1) node4 := tree:addNode({"Leaf3"},, node1, node3) node44 := tree:addNode({"Leaf3333"},, node11) node55 := tree:addNode({"Leaf333"},, node44) tree:restorePosition( pos ) // Table data pos := table:savePosition() ?? "Table pos:", pos, chr(10) table:clear() table:addRow({"1","20.10.03",'JSC "Lighthouse"',"20000.00"},"DB0101000588") table:addRow({"2","20.10.03",'JSC "Phoenix"',"5689.20"}) table:addRow({"3","21.10.03",'JSC "Phoenix"',"1500.00"}) table:addRow({"4","25.10.03",'JSC "Phoenix"',"99.00"}) table:addRow({"5","20.10.03",'JSC "Lighthouse"',"20000.00"},"DB0101000589") table:addRow({"6","20.10.03",'JSC "Phoenix"',"5689.20"}) table:addRow({"7","21.10.03",'JSC "Phoenix"',"1500.00"}) table:restorePosition( pos ) return /* Form widgets */ static function BankDocReq(w,grid) local drv, lab, data, top, bottomLine, sd, pol, plat, i, t, f1, f2, t1, t2, b1, b2, b3, e1, e2, cb1, cb2, sum, hbsum, rs, rg drv := getDriver() data := map() data:num := "11" data:date :="20.10" data:client := 'JSC "Brown and son"' data:sum := "20000.00" data:reason := "For delivered goods.&\n" for i:=1 to 10 data:reason += alltrim(str(i))+" line.&\n" next plat := map() plat:name := 'JSC "Brown and son"' plat:bank := 'JSC "MENATEP"' plat:bankCity := "Krasnoyarsk" plat:BIK := "54521724647" plat:korAccount := "86768348914" plat:account := "7683187443445276" plat:INN := "1234567890" pol := map() pol:name := 'JSC "Lighthouse"' pol:bank := 'JSC "MENATEP"' pol:bankCity := "Moscow" pol:BIK := "54521724647" pol:korAccount := "86768348914" pol:account := "7683187443445276" pol:INN := "1212145436" w:setName("usetax",grid:add(UICheckBox(.F.,"Use &tax"))) rg := UIRadioGroup() w:setName("button1", grid:add(rg:addButton("button1"))) w:setName("button2", grid:add(rg:addButton("button2"))) // Slider sd := UISlider(10, 5, 60, 5) w:setName("slider", grid:add(sd)) // Title top := UIHBox(,0,3) lab := UILabel("Payment order N ") drv:setStyle(lab,"font.style","bold") drv:setStyle(lab,"font.size","14") drv:setStyle(lab,"color.bg","red") drv:setStyle(lab,"color.light","white") drv:setStyle(lab,"color.dark","white") drv:setStyle(lab,"color.mid","white") drv:setStyle(lab,"color.text","white") drv:setStyle(lab,"color.base","white") drv:setStyle(lab,"color.white","white") drv:setStyle(lab,"color.fg","#FF1790") // drv:setStyle(lab,"color.text","blue") // drv:setStyle(lab,"color.bg","#ff0000") // drv:setStyle(lab,"color.base","#0000ff") top:add(lab) e1 := UIEdit() e1:setValue(data:num) e1:setGeometry(50) e1:readOnly() w:setName("number", e1) drv:setStyle(top, "background", "icons/tick.xpm") top:add(e1) top:add(UILabel(" from ")) e2 := UIEditDate() e2:setValue(data:date) e2:appendText(".2005") w:setFocus(e2) e2:setGeometry(75) w:setName("date", e2) top:add(e2) grid:add(top) // Payer f1 := UIFrame() grid:add(f1) drv:setStyle(f1,"color.bg","darkblue") f1:setLabel("Payer") f1:setType(FRAME_RAISED) t1 := UIVBox(,,3) f1:add( t1 ) cb1 := UIComboBox({'JSC "Brown and son"'},1) w:setName("payer", cb1) t1:add(cb1) // Payee f2 := UIFrame("Payee",FRAME_SUNKEN) grid:add(f2) t2 := UIVBox(,,3) f2:add( t2 ) cb2 := UIComboBox() cb2:setList({'JSC "Lighthouse"','JSC "Ronal"','JSC "Porechnoye"'}) cb2:setValue(2) cb2:setValueInList(.T.) w:setName("payee", cb2) t2:add(cb2) // Sum hbsum := UIHBox(,3) hbsum:add(UILabel("&Sum: ")) sum := UIEdit(data:sum) drv:setStyle(sum,"color.base","#C2D2FF") drv:setStyle(sum,"color.bg","red") w:setName("sum", sum) hbsum:add(sum) hbsum:add(w:setName("tax", UILabel(""))) grid:add(hbsum) // Fill tax calculation sum:setAction("changed", {|| fieldChanged(w) }) fieldChanged(w) grid:add(UILabel("Description:")) rs := UIEditText(data:reason) rs:appendText("&\nEND.") rs:setGeometry({,30}) w:setName("reason", rs) grid:add(rs, .T., .T.) // Bottom panel bottomLine := w:actions b1 := UIButton( "Save", {|o,e| pp_save(w) } ) b2 := UIButton( "Print", {|| w:dialogBox("Print","Print function isn't implemented yet.","'Ok','Cancel'",NIL,NIL,IMG_OK) } ) b3 := UIButton( "Close", {|o,e| w_close(w) } ) bottomLine:add(b1) bottomLine:add(b2) bottomLine:add(b3) return NIL /* Close specified window */ static function w_close(window) window:close() return 0 /* Show all stored values from document */ static function pp_save(wnd) local val,i val := wnd:getValues() ?? "Form values:"+CHR(10) for i in val ?? CHR(9)+i[1]+" =",i[2],CHR(10) next return 0 static function fieldChanged(win) local s, tax, label, i if valtype(win) != 'O' return endif s := win:val("sum") tax := round(val(s)*0.2,2) label := iif("tax" $ win:value,win:value["tax"],NIL) tax := alltrim(str(tax)) if valtype(label) == 'O' label:setText("Tax: "+tax) endif return static function OtherWidget(w) local hp, pb, bt, percent := 0, lt, g, co, fn, tg, t, tl, tb hp := UIHBox(,3) hp:setPadding(5) hp:add(UILabel("Predefined icons:")) hp:add(UIImage(1)) hp:add(UIImage(2)) hp:add(UIImage(3)) hp:add(UIImage(4)) hp:add(UIImage(5)) // Layout lt := UILayout() hp:add(lt) // Progress Bar pb := UIProgressBar("Progress Bar") lt:add(pb) bt := UIButton( "Change ProgressBar", {|o,e| percent += 0.05, percent := iif(percent > 1, 0, percent),; pb:setPercent(percent, "Progress: "+alltrim(str(percent*100,0))+" %") } ) lt:add(bt, "10,30") w:add( hp ) g := UIHBox(,5) // Get FileName g:add(UILabel("File name: ")) fn := UIEditFileName('') g:add(fn) // Get Color g:add(UILabel("Color: ")) co := UIEditColor('#91FF40') co:setGeometry(60) g:add(co) w:add( g ) // Timer tg := UIHBox(,5) tg:add(UILabel("Timer:")) tl := UILabel("<time>") tbState := 0 timer := NIL tb := UIButton("Start timer", {|| startTimer(tb, tl) }) tg:add(tl) tg:add(tb) w:add( tg ) return /* Start timer */ static function startTimer(tb, tl) if tbState == 0 // start tbState := 1 tb:setText("Stop timer") if empty(timer) timer := UITimer(1, {|| timerEvent(tl) }) else timer:start() endif iteration := 0 else // stop tbState := 0 tb:setText("Start timer") if .not. empty(timer) timer:stop() endif endif return /* Timer event */ static function timerEvent(l) local t, w iteration++ if iteration == 15 w := getMainWindow() if .not. empty(w) w:dialogBox("Timer","Timer works 15 seconds.","'Ok'",NIL,NIL,IMG_OK) else ?? "getMainWindow failed.&\n" endif endif t := time() ?? "Event:", t, chr(10) l:setText(t) return |