View Single Post
  #1  
Old 16th September 2010, 23:42
ArokLair's Avatar
ArokLair ArokLair is offline
Junior Member
 
Join Date: Apr 2010
Posts: 3
ArokLair is on a distinguished road
Baan: Baan IVc2 - DB: Informix - OS: AIX 6.1
File Browse Server

This is a library i was developed in Baan IV

Code:
|******************************************************************************
|* tudllfilebrows  0  VRC B40c c2 baan
|* File Browser
|* ArokLair
|* 24/08/10 [16:42]
|******************************************************************************
|* Script Type: Library
|******************************************************************************
#define     COMMAND.ACEPTAR     101
#define     COMMAND.CANCELAR    111
#define		SIZE.STRING			250

long     toplevel, listbox, image,label
string path(SIZE.STRING)
long listitems(200)
string retorno(SIZE.STRING)

function extern select.file(string  ruta_servidor(SIZE.STRING), ref string archivo_seleccionado()){
	
	if not isspace(ruta_servidor) then 
		path=ruta_servidor
	else
		path="/home/"&getenv$("LOGNAME")&"/"
	endif
	main_1()
	archivo_seleccionado=retorno
}

function main_1(){
	image = 0
	show.mwindow()
	fill.work.area()
	update.gwindow()
	handle.event.loop()
}
function write.menu.entry(ref string menudata(), ref long size,
      long level, long id, const string name(), long flags)
{
      store.long(level, menudata(size))
      size = size + 4
      store.long(id, menudata(size))
      size = size + 4
      menudata(size) = name
      size = size + len(name)
      store.byte(0, menudata(size))   | terminate string with 0 char.
      size = size + 1
      store.long(flags, menudata(size))
      size = size + 4
}
function long create.pulldown.menu(long mwin)
{
      long barmenu, size
      string menudata(1) based
      alloc.mem(menudata, 3000)
      size = 1
      | write header info to buffer
      store.long(1, menudata(size))      | version is 1
      size = size + 4
      store.long(8, menudata(size))      | menu contains 8 entries
      size = size + 4
      | create the File submenu
      write.menu.entry(menudata, size, 1, 0, "&Archivo", 0)
		write.menu.entry(menudata, size, 2, -1, "-", 0)      | separator
      write.menu.entry(menudata, size, 2, COMMAND.CANCELAR, "S&alir  Alt+F4", 0)
      barmenu = create.object(DsCbarMenu, mwin,
                  DsNmenuData,   menudata, size-1,
                  DsNsetState,   DSRAISE)
       return(barmenu)
}
function show.mwindow(){
	long barmenu
	|message(str$(get.pgrp(pid)))
	toplevel = create.object(	DsCmwindow, 0,
								DsNtitle,         "File Explorer Baan 1.0 ArokLair ",
								DsNprocessgroup,  get.pgrp(pid),
								|DsNprocessgroup,current.mwindow(),
								DsNmode,         DSPIXELBASED,
								DsNdialog,1,
								DsNmodal,		1,
								DsNminWidth,      400,
								DsNmaxWidth,      800,
								DsNminHeight,     400,
								DsNmaxHeight,     800)
	barmenu = create.pulldown.menu(toplevel)
	change.object(toplevel, DsNbarMenu, barmenu)
	update.object(toplevel)
}
function fill.work.area(){
		long        rowcol,rowcol2
		rowcol = create.object(DsCrowColumn, toplevel,
                DsNvspace,        10,
                DsNhspace,        10,
                DsNnumColumns,     1,
				DsNfixedDimension, DSHORIZONTAL )
		create.object(DsClabel,  rowcol,
							DsNstring, "Seleccione el Archivo a Examinar...")
		label=create.object(DsClabel,  rowcol,
							DsNstring, path)
		listbox=create.object(DsClistBox,rowcol,
							DsNminWidth,350,
							DsNminHeight,15,
							DsNheight,250,
							DsNselectedId,1)
		rowcol2 = create.object(DsCrowColumn, rowcol,
                DsNvspace,        10,
                DsNhspace,        10,
                DsNnumColumns,     2,
                DsNfixedDimension, DSHORIZONTAL )
		create.object(DsCpushButton,  rowcol2,
				DsNstring,        "Aceptar",
				DsNwidth,			100,
				DsNreturnValue,   COMMAND.ACEPTAR)
		create.object(DsCpushButton,  rowcol2,
				DsNstring,        "Cancelar",
				DsNwidth,			100,
				DsNreturnValue,   COMMAND.CANCELAR)
		update.object(toplevel)
		|update.object(gwin)
}
function update.gwindow(){
	| Leer los archivos del directorio
	long fd,rt, size, mode,cont,posno,fc
	string	fname(SIZE.STRING)
	string home(SIZE.STRING)
	cont=1
	
	home = path
	|destroy.sub.object(listbox,)
	|cargar la Raiz
	listitems(1)=create.sub.object(listbox,1,
							DsNitemAttr,1,
							DsNselected,1,
							DsNstring,"..")
	| Recorrer Directorios
	fd=dir.open(home)
	fname = dir.entry(fd, TDIR, rt, size, mode)
	
	while (not isspace(fname))
		posno=pos(fname,".")
		|message(str$(posno))
		if not posno=1 then
			cont=cont+1
			listitems(cont)=create.sub.object(listbox,1,
										DsNitemAttr,cont,
										DsNselected,0,
										DsNstring,fname&"/")
		endif
		fname=dir.entry(fd, TDIR, rt, size, mode)
	endwhile
	fc=dir.close(fd)
	| Recorrer Archivos
	fd=dir.open(home)
	fname = dir.entry(fd, TFILE, rt, size, mode)
	
	while (not isspace(fname))
		posno=pos(fname,".")
		|message(str$(posno))
		if not posno=1 then
			cont=cont+1
			listitems(cont)=create.sub.object(listbox,1,
										DsNitemAttr,cont,
										DsNselected,0,
										DsNstring,fname)
		endif
		fname=dir.entry(fd, TFILE, rt, size, mode)
	endwhile
	
	update.object(toplevel)
}
function doble_clic(string ruta(SIZE.STRING)){
	|Elimar Items 
	long i
	|message("Entro")
	for i = 1 to 200 step 1
		if(listitems(i)<>0) then 
			destroy.sub.object(listbox, listitems(i))
		endif
	endfor
	path=ruta
	|update.object(toplevel)
	update.gwindow()
}
function long isDir(string ruta(SIZE.STRING)){
	long    ret,loc
	long    size, mode, inode, dev, uid, gid, nlink, ctime, atime, mtimel
	string file_name(SIZE.STRING)
	loc=0
	file_name = ruta
	ret = stat.info(file_name,
					size,
					mode,
					inode,
					dev,
					uid,
					gid,
					nlink,
					ctime,
					mtimel,
					atime )
	if ret then
                | stat.info failed, probably file not found
	endif
	if ( S_ISDIR( mode ) ) then
		loc=1
	endif

	return (loc)
}
function string get.parent(string ruta(SIZE.STRING)){
	long rposno
	ruta=ruta(1;len(ruta)-1)
	rposno=rpos(ruta,"/")
	return (ruta(1;rposno))
}
function handle.event.loop(){
 long item,tim.id,click.count,direc

 string fnamel(SIZE.STRING)

 click.count=0
 direc=0
 tim.id = set.timer(1000)
 long event(EVTMAXSIZE)
      while TRUE
            next.event(event)
            on case evt.type(event)
            case EVTMENUSELECT:
					on case evt.menu.return(event)
					
					case COMMAND.CANCELAR:
                        return
					
                  endcase
                  break
            case EVTPUSHBUTTON:
					if (evt.button.return(event) = COMMAND.CANCELAR ) then
                         return
					endif
					if (evt.button.return(event) = COMMAND.ACEPTAR ) then
						get.object(label,DsNstring,fnamel)
						|message(fnamel)
						retorno=fnamel
						return
					endif
					break
			case EVTLISTBOXSELECT:
						if (evt.listbox.item_id(event)=item) then 
							if(click.count=1 ) then 
								get.object(label,DsNstring,fnamel)
								direc=isDir(fnamel)
								if  direc= 1 then
									doble_clic(fnamel)
								endif
								break
							endif
						endif
						if (evt.listbox.item_id(event)=listitems(1)) then
							if(click.count=1 ) then 
								change.object(label,DsNstring,get.parent(path))
								doble_clic(get.parent(path))
							endif
						else
							get.object(listbox,DsNselectedId,item)
							get.sub.object(listbox,item,DsNstring,fnamel)
							change.object(label,DsNstring,path&fnamel)
						endif
						
						update.object(label)					
						click.count=1
						
					break
			case EVTTIMEREVENT:
				click.count=0
                break
			default:
                  break
            endcase
      endwhile
}
Subsession to launch file explorer 3GL

Code:
#pragma used dll otudllfilebrows
string retorno(500)
string tccom9599.path(500)
string tccom9599.field(500)
function main(){
	import("tccom9599.path",tccom9599.path)
	import("tccom9599.field",tccom9599.field)
	|message(tccom9599.field)
	|message(field)
	
	select.file(tccom9599.path,retorno)
	
	export(tccom9599.field,retorno)
	
}
How use in session 4GL
Code:
declaration:
	extern string tccom9599.path(500)
	extern string tccom9599.field(500)
|****************************** form section **********************************
form.1:
	init.form:
		tccom9599.path = "/home/user1/"
		export("tccom9599.path",tccom9599.path)

choice.user.1:
	on.choice:
		tccom9599.field="campo.ruta"
		export("tccom9599.field",tccom9599.field)
		zoom.to$("tccom9599m000", Z.SESSION, "tccur2105m000", "", 0)
		message(campo.ruta)
		display.all()

Last edited by ArokLair : 14th June 2011 at 19:24. Reason: Example to use
Reply With Quote