*--------------------------------------------------------------------------------------------------------------------------------------------------------
* (EN) AUTOGENERATED - ATTENTION!! - NOT INTENDED FOR EXECUTION!! USE ONLY FOR MERGING CHANGES AND STORING WITH SCM TOOLS!!
*--------------------------------------------------------------------------------------------------------------------------------------------------------
*< FOXBIN2PRG: Version="1.21" SourceFile="appwiz.vcx" CPID="1252" /> (Solo para binarios VFP 9 / Only for VFP 9 binaries)
*
*
*< LIBCOMMENT: Application Wizard framework class library. />
*
DEFINE CLASS wzapplication AS container 		&& Application class used as a framework for the Application Wizard.
 	*< CLASSDATA: Baseclass="container" Timestamp="" Scale="Pixels" Uniqueid="" />

	*<DefinedPropArrayMethod>
		*m: beforereadevents		&& Method executed before READ EVENTS is executed when ReadEvents is called.
		*m: clearevents		&& Clears any pending read events.
		*m: doform		&& Executes an SCX form.
		*m: dolabel		&& Executes an LBX label
		*m: domenu		&& Executes an MPR menu.
		*m: doprogram		&& Executes a PRG, APP, or EXE program.
		*m: doreport		&& Executes an FRX report.
		*m: filenotfoundmsgbox		&& Displays a File Not Found messagebox.
		*m: getcaption		&& Returns the caption of the application.
		*m: geticon		&& Returns the icon of the application.
		*m: onshutdown		&& Occurs when the user attempts to exit Visual FoxPro.
		*m: readevents		&& Starts read events mode.
		*m: readini
		*m: refreshformscollection		&& Refresh forms collection arrays and counters.
		*m: release		&& Releases the application from memory.
		*m: releaseform		&& Release specifc or active form from memory.
		*m: releaseforms		&& Release all application forms from memory.
		*m: resetformscollection		&& Reset arrays and counters of forms collection.
		*m: restart
		*m: restoreenvironment		&& Restores environment settings.
		*m: saveenvironment		&& Saves environment settings.
		*m: setcaption		&& Sets the caption of the application.
		*m: seticon		&& Sets the icon of the application.
		*m: show		&& Displays the application.
		*m: writeini
		*p: ccaption		&& Caption of the application object.
		*p: cicon		&& Icon of the application object.
		*p: clastcaption		&& Last caption setting of _screen before application object was intantiated.
		*p: clasticon		&& Last icon setting of _screen before application object was intantiated.
		*p: cstartupform		&& Form (SCX) which is executed when the application object is shown.
		*p: cstartupmenu		&& Menu (MPR) which is executed when the application object is shown.
		*p: lcascadeforms		&& Specifies whether forms are cascaded if multiple instances of the same form are opened in the same top and left positions of the desktop.
		*p: lreadevents		&& Enable READ EVENTS within ReadEvents method.
		*p: nformcount		&& Forms collection count for application object.
		*p: npixeloffset		&& Number of pixels which offset multiple instances of the same form.
		*a: aformnames[1,0]		&& Form name collection for application object.
		*a: aforms[1,0]		&& Forms collection for application object.
		*p: _memberdata		&& XML Metadata for customizable properties
	*</DefinedPropArrayMethod>

	PROTECTED ccaption,cicon,clastcaption,clasticon,Destroy,Init
	*<PropValue>
		BackColor = 0,0,255
		ccaption = 
		cicon = 
		clastcaption = 
		clasticon = 
		cstartupform = 
		cstartupmenu = 
		Height = 34
		lcascadeforms = .T.
		lreadevents = .T.
		Name = "wzapplication"
		nformcount = 0
		npixeloffset = 22
		Visible = .F.
		Width = 108
		_memberdata = <VFPData>
			<memberdata name="writeini" display="WriteIni"/>
		</VFPData>
	*</PropValue>
	
	PROTECTED PROCEDURE beforereadevents		&& Method executed before READ EVENTS is executed when ReadEvents is called.
	ENDPROC

	PROCEDURE clearevents		&& Clears any pending read events.
		CLEAR EVENTS
		
	ENDPROC

	PROTECTED PROCEDURE Destroy
		CLEAR EVENTS
		this.RestoreEnvironment
		
	ENDPROC

	PROCEDURE doform		&& Executes an SCX form.
		LPARAMETERS tcFileName,tcClass,tlNoMultipleInstances,tlNoShow
		LOCAL lcFileName,lcClass,oForm,oForm2,lcName,lnCount,lnTop,lnLeft
		LOCAL lcFormName,lnFormCount
		
		_screen.visible=.t.
		
		lcFileName = UPPER(ALLTRIM(tcFileName))
		IF EMPTY(lcFileName)
			RETURN .F.
		ENDIF
		lcClass=IIF(TYPE("tcClass")=="C",LOWER(ALLTRIM(tcClass)),"")
		lcFileName=LOWER(FULLPATH(lcFileName))
		IF NOT "."$lcFileName
			lcFileName=lcFileName+IIF(EMPTY(lcClass),".scx",".vcx")
		ENDIF
		IF NOT FILE(lcFileName)
			this.FileNotFoundMsgBox(lcFileName)
			RETURN .F.
		ENDIF
		lcFormName=IIF(EMPTY(lcClass),lcFileName,lcFileName+","+lcClass)
		IF tlNoMultipleInstances
			FOR lnCount = 1 TO this.nFormCount
				IF this.aFormNames[lnCount]==lcFormName AND ;
						TYPE("this.aForms[lnCount]")=="O" AND ;
						NOT ISNULL(this.aForms[lnCount])
					this.aForms[lnCount].Show
					RETURN .F.
				ENDIF
			ENDFOR
		ENDIF
		this.RefreshFormsCollection
		this.nFormCount=this.nFormCount+1
		DIMENSION this.aForms[this.nFormCount],this.aFormNames[this.nFormCount]
		this.aFormNames[this.nFormCount]=lcFormName
		IF NOT EMPTY(lcClass)
			SET CLASSLIB TO (lcFileName) ADDITIVE
			this.aForms[this.nFormCount]=CREATEOBJECT(lcClass)
			IF NOT tlNoShow AND TYPE("this.aForms[this.nFormCount]")=="O" AND ;
					NOT ISNULL(this.aForms[this.nFormCount])
				this.aForms[this.nFormCount].Show
			ENDIF
		ELSE
			DO FORM (lcFileName) NAME this.aForms[this.nFormCount] LINKED NOSHOW
		ENDIF
		lnFormCount=this.nFormCount
		this.RefreshFormsCollection
		IF this.lCascadeForms AND this.nFormCount>=lnFormCount
			oForm=this.aForms[this.nFormCount]
			lnTop=oForm.Top
			lnLeft=oForm.Left
			lcName=oForm.Name
			IF WEXIST(lcName) AND oForm.WindowState#2
				FOR lnCount = 1 TO (this.nFormCount-1)
					oForm2=this.aForms[lnCount]
					IF TYPE("oForm2")#"O" OR ISNULL(oForm2)
						LOOP
					ENDIF
					IF lcName==oForm2.Name AND WLROW(lcName)=WLROW(oForm2.Name) AND ;
							WLCOL(lcName)=WLCOL(oForm2.Name)
						lnTop=lnTop+this.nPixelOffset
						lnLeft=lnLeft+this.nPixelOffset
					ENDIF
				ENDFOR
				IF oForm.Top#lnTop
					oForm.Top=lnTop
				ENDIF
				IF oForm.Left#lnLeft
					oForm.Left=lnLeft
				ENDIF
			ENDIF
		ENDIF
		
		*!* modificat 18.10.2004
		*!* Marius
		IF !(m.tlNoShow OR (TYPE('glParametri') = 'L' AND 'LOGIN'$UPPER(lcFileName) and m.glParametri))
			this.aForms[this.nFormCount].Show 
		ENDIF
		
	ENDPROC

	PROCEDURE dolabel		&& Executes an LBX label
		LPARAMETERS tcFileName,tlPrint
		LOCAL lcFileName
		
		lcFileName=ALLTRIM(tcFileName)
		IF EMPTY(lcFileName)
			RETURN .F.
		ENDIF
		lcFileName=LOWER(FULLPATH(lcFileName))
		IF NOT "."$lcFileName
			lcFileName=lcFileName+".lbx"
		ENDIF
		IF NOT FILE(lcFileName)
			this.FileNotFoundMsgBox(lcFileName)
			RETURN .F.
		ENDIF
		IF tlPrint
			LABEL FORM (lcFileName) TO PRINTER PROMPT
		ELSE
			LABEL FORM (lcFileName) PREVIEW
		ENDIF
		
	ENDPROC

	PROCEDURE domenu		&& Executes an MPR menu.
		LPARAMETERS tcFileName
		LOCAL lcFileName
		
		lcFileName=ALLTRIM(tcFileName)
		IF EMPTY(lcFileName)
			RETURN .F.
		ENDIF
		lcFileName=LOWER(FULLPATH(lcFileName))
		IF NOT "."$lcFileName
			lcFileName=lcFileName+".mpr"
		ENDIF
		
		IF TYPE('goLocale') = 'O'
			goLocale.SetMenu(m.lcFileName, "menu", null)
		ENDIF 
		
		DO (m.lcFileName)
		
		
		
	ENDPROC

	PROCEDURE doprogram		&& Executes a PRG, APP, or EXE program.
		LPARAMETERS tcFileName
		LOCAL lcFileName
		
		lcFileName=ALLTRIM(tcFileName)
		IF EMPTY(lcFileName)
			RETURN .F.
		ENDIF
		lcFileName=LOWER(FULLPATH(lcFileName))
		IF NOT "."$lcFileName
			lcFileName=lcFileName+".prg"
		ENDIF
		IF NOT FILE(lcFileName)
			this.FileNotFoundMsgBox(lcFileName)
			RETURN .F.
		ENDIF
		DO (lcFileName)
		
	ENDPROC

	PROCEDURE doreport		&& Executes an FRX report.
		LPARAMETERS tcFileName,tlPrint
		LOCAL lcFileName
		
		lcFileName=ALLTRIM(tcFileName)
		IF EMPTY(lcFileName)
			RETURN .F.
		ENDIF
		lcFileName=LOWER(FULLPATH(lcFileName))
		IF NOT "."$lcFileName
			lcFileName=lcFileName+".frx"
		ENDIF
		IF NOT FILE(lcFileName)
			this.FileNotFoundMsgBox(lcFileName)
			RETURN .F.
		ENDIF
		IF tlPrint
			REPORT FORM (lcFileName) TO PRINTER PROMPT
		ELSE
			REPORT FORM (lcFileName) PREVIEW
		ENDIF
		
	ENDPROC

	PROCEDURE filenotfoundmsgbox		&& Displays a File Not Found messagebox.
		LPARAMETERS tcFileName
		
		RETURN AMESSAGEBOX([Fisierul "]+tcFileName+[" nu a fost gasit!],16,gcNumeProgram)
		
	ENDPROC

	PROCEDURE getcaption		&& Returns the caption of the application.
		RETURN this.cCaption
		
	ENDPROC

	PROCEDURE geticon		&& Returns the icon of the application.
		RETURN this.cIcon
		
	ENDPROC

	PROTECTED PROCEDURE Init
		this.SaveEnvironment
		this.ResetFormsCollection
		
	ENDPROC

	PROCEDURE onshutdown		&& Occurs when the user attempts to exit Visual FoxPro.
		If glQuit
			Quit
		Endif
		
		IF TYPE('m.buton') = 'U'
			PRIVATE buton
			buton = 1
		ENDIF 
		
		OA=Createobject('frm_mesaj',gcNumeProgram,'intreb.ico','INTREBARE','Doriți să ieșiți din program?')
		OA.lbl_mesaj1.FontBold=.T.
		OA.lbl_mesaj1.FontSize=12
		OA.lbl_mesaj1.Top=55
		OA.Show(1)
		If buton=1
			ON SHUTDOWN 
			ON ERROR 
			CLEAR EVENTS 
			IF _VFP.StartMode <> 0	 
				QUIT
			ENDIF 	
		Else
			PRIMADATA=.F.
		Endif
		
	ENDPROC

	PROCEDURE readevents		&& Starts read events mode.
		this.BeforeReadEvents
		IF this.lReadEvents
			READ EVENTS
		ENDIF
		
	ENDPROC

	PROCEDURE readini
		LPARAMETERS tcSection, tcVariable
		
		lcSection = IIF(!EMPTY(m.tcSection), ALLTRIM(LOWER(m.tcSection)), '')
		lcVariable = IIF(!EMPTY(m.tcVariable), ALLTRIM(LOWER(m.tcVariable)), '')
		lcValue = ''
		
		IF TYPE('goApi') = 'O' AND !EMPTY(m.lcSection) AND !EMPTY(m.lcVariable)
			 lcValue = goAPI.GetProfileString(m.gcSettingsFile, m.lcSection, m.lcVariable)
		ENDIF 
		
		RETURN NVL(m.lcValue,'')
	ENDPROC

	PROCEDURE refreshformscollection		&& Refresh forms collection arrays and counters.
		LOCAL lnCount,lnCount2
		
		lnCount=1
		DO WHILE lnCount<=this.nFormCount
			IF TYPE("this.aForms[lnCount]")=="O" AND NOT ISNULL(this.aForms[lnCount])
				lnCount=lnCount+1
				LOOP
			ENDIF
			FOR lnCount2 = lnCount TO (this.nFormCount-1)
				this.aForms[lnCount2]=this.aForms[lnCount2+1]
				this.aForms[lnCount2+1]=.NULL.
				this.aFormNames[lnCount2]=this.aFormNames[lnCount2+1]
				this.aFormNames[lnCount2+1]=""
			ENDFOR
			this.nFormCount=this.nFormCount-1
			IF this.nFormCount=0
				EXIT
			ENDIF
			DIMENSION this.aForms[this.nFormCount],this.aFormNames[this.nFormCount]
		ENDDO
		IF this.nFormCount=0
			this.ResetFormsCollection
		ENDIF
		
	ENDPROC

	PROCEDURE release		&& Releases the application from memory.
		IF NOT this.ReleaseForms()
			RETURN .F.
		ENDIF
		this.ClearEvents
		RELEASE this
		
	ENDPROC

	PROCEDURE releaseform		&& Release specifc or active form from memory.
		LPARAMETERS toForm
		
		IF PARAMETERS()=0
			IF TYPE("_screen.ActiveForm")#"O" OR ISNULL(_screen.ActiveForm)
				RETURN .F.
			ENDIF
			_screen.ActiveForm.Release
		ELSE
			IF TYPE("toForm")#"O" OR ISNULL(toForm)
				RETURN .F.
			ENDIF
			toForm.Release
		ENDIF
		this.RefreshFormsCollection
		
	ENDPROC

	PROCEDURE releaseforms		&& Release all application forms from memory.
		LOCAL lnFormCount
		
		this.RefreshFormsCollection
		DO WHILE this.nFormCount>0
			lnFormCount=this.nFormCount
			IF NOT this.ReleaseForm(this.aForms[lnFormCount]) OR this.nFormCount=lnFormCount
				RETURN .F.
			ENDIF
		ENDDO
		
	ENDPROC

	PROTECTED PROCEDURE resetformscollection		&& Reset arrays and counters of forms collection.
		this.nFormCount=0
		DIMENSION this.aForms[1],this.aFormNames[1]
		this.aForms=.NULL.
		this.aFormNames=""
		
	ENDPROC

	PROCEDURE restart
		*!*	e folosita in ROASTART
		This.releaseform()
		This.show()
	ENDPROC

	PROTECTED PROCEDURE restoreenvironment		&& Restores environment settings.
		IF NOT EMPTY(this.cLastCaption) AND NOT _screen.Caption==this.cLastCaption
			_screen.Caption=this.cLastCaption
		ENDIF
		IF NOT EMPTY(this.cLastIcon) AND NOT _screen.Icon==this.cLastIcon
			_screen.Icon=this.cLastIcon
		ENDIF
		
	ENDPROC

	PROTECTED PROCEDURE saveenvironment		&& Saves environment settings.
		this.cLastCaption=_screen.Caption
		this.cLastIcon=_screen.Icon
		
	ENDPROC

	PROCEDURE setcaption		&& Sets the caption of the application.
		LPARAMETERS tcCaption
		
		IF TYPE("tcCaption")#"C"
			RETURN .F.
		ENDIF
		this.cCaption=tcCaption
		_screen.Caption=tcCaption
		
	ENDPROC

	PROCEDURE seticon		&& Sets the icon of the application.
		LPARAMETERS tcIcon
		
		IF TYPE("tcIcon")#"C"
			RETURN .F.
		ENDIF
		this.cIcon=tcIcon
		_screen.Icon=tcIcon
		
	ENDPROC

	PROCEDURE show		&& Displays the application.
		LPARAMETERS nStyle
		
		this.DoMenu(this.cStartupMenu)
		this.DoForm(this.cStartupForm)
		this.ReadEvents
		
	ENDPROC

	PROCEDURE writeini
		LPARAMETERS tcSection, tcVariable, tcValue
		
		lcSection = IIF(!EMPTY(m.tcSection), ALLTRIM(LOWER(m.tcSection)), '')
		lcVariable = IIF(!EMPTY(m.tcVariable), ALLTRIM(LOWER(m.tcVariable)), '')
		lcValue = IIF(!EMPTY(m.tcValue), ALLTRIM(TRANSFORM(m.tcValue)), '')
		
		IF TYPE('goApi') = 'O' AND !EMPTY(m.lcSection) AND !EMPTY(m.lcVariable)
			goAPI.WriteProfileString(m.gcSettingsFile, m.lcSection, m.lcVariable, m.lcValue) 
		ENDIF 
	ENDPROC

ENDDEFINE
