of_restore


pfcwnsrv.pbl   >   pfc_n_cst_winsrv_preference   >   of_restore   

Full name pfc_n_cst_winsrv_preference.of_restore
Access protected
Extend of integer
Return value integer
Prototype protected function integer of_restore(boolean,string,string)

Name Datatype
No Data

Name Datatype
lb_sectionfound boolean
lb_toolbarposition boolean
lb_visible boolean
li_barindexarray integer[]
li_cnt integer
li_height integer
li_rc integer
li_tbindex integer
li_upperbound integer
li_width integer
li_x integer
li_y integer
lnv_conversion n_cst_conversion
lnv_ini n_cst_inifile
lnv_menu n_cst_menu
ls_alignment string
ls_height string
ls_regvalues string[]
ls_sections string[]
ls_tbindex string
ls_title string
ls_visible string
ls_width string
ls_windowstate string
ls_x string
ls_y string
ltb_alignment toolbaralignment

protected function integer of_restore (boolean ab_useregistry, string as_keyorini, string as_inisection);//////////////////////////////////////////////////////////////////////////////
//
//	Function:  		of_Restore
//
//	Access:  		protected
//
//	Arguments:	
//	ab_UseRegistry	Function behavior. - use the registry or an .ini file.
//	as_KeyOrIni		The KeyName for use with the Registry or the IniFile name
//						for use with an .Ini file.
//	as_IniSection	The name of the .Ini section. 
//
//	Returns:  		Integer
//						1 if it succeeds and -1 if an error occurs.
//
//	Description:  	Restores the preference information from either the Registry
//						or from an .INI file.
//
//////////////////////////////////////////////////////////////////////////////
//
//	Revision History
//
//	Version
//	5.0    Initial version
//	5.0.02 Check for an associated menu prior to restoring menu preferences.
// 5.0.03 Check for the existance of the section.
// 7.0	 Add logic to restore the window state to maximized or normal
//
//////////////////////////////////////////////////////////////////////////////
//
//	Copyright © 1996-1997 Sybase, Inc. and its subsidiaries.  All rights reserved.
//	Any distribution of the PowerBuilder Foundation Classes (PFC)
//	source code by other than Sybase, Inc. and its subsidiaries is prohibited.
//
//////////////////////////////////////////////////////////////////////////////

string				ls_title
string				ls_tbindex 
string				ls_visible
string				ls_alignment
string				ls_x, ls_y, ls_width, ls_height
string				ls_sections[], ls_regvalues[]
string				ls_windowstate
integer				li_tbindex 
integer				li_x, li_y, li_width, li_height
integer				li_rc = 1
integer				li_cnt
integer				li_upperbound
integer				li_barindexarray[]
boolean				lb_visible
boolean				lb_toolbarposition
boolean				lb_sectionfound=False
toolbaralignment	ltb_alignment
n_cst_menu			lnv_menu
n_cst_conversion	lnv_conversion
n_cst_inifile		lnv_ini

//Check for a window association with this object.
If IsNull(iw_requestor) Or Not IsValid (iw_requestor) Then 
	Return -1
End If

//Check arguments
If IsNull(ab_UseRegistry) or IsNull(as_KeyOrIni) Then
	Return -1
End If

//Validate specifics for either Registry or .Ini functionality.
If ab_UseRegistry Then
	//Check for the existance of the section.	
	RegistryValues(as_KeyOrIni, ls_regvalues)
	If UpperBound(ls_regvalues) <= 0 Then
		Return -1
	End If
Else
	//Check for the existance of the file.
	If Not FileExists(as_KeyOrIni) Then
		Return -1
	End If
	//Check the section parameter
	If IsNull(as_IniSection) or Len(Trim(as_IniSection))=0 Then
		Return -1
	End If
	//Check for the existance of the section.
	lnv_ini.of_GetSections(as_KeyOrIni, ls_sections)
	li_upperbound = UpperBound(ls_sections)
	For li_cnt = 1 to li_upperbound
		If Lower(Trim(as_IniSection)) = Lower(Trim(ls_sections[li_cnt])) Then
			lb_sectionfound = True
		End If
	Next
	If Not lb_sectionfound Then 
		Return -1
	End If
End If

If ib_window Then
	// Restore the window state
   li_rc = of_Restore (ab_UseRegistry, as_KeyOrIni, as_IniSection, &
           'window.windowstate', ls_windowstate, 'normal')
   Choose Case ls_windowstate 
		Case 'maximized' 
			iw_requestor.windowstate = Maximized!
		Case Else
			iw_requestor.windowstate = Normal!
	End Choose
		
	If iw_requestor.WindowState = Normal! Then
		//Restore Normal State window position and size.
		li_rc = of_Restore (ab_UseRegistry, as_KeyOrIni, as_IniSection, &
			'window.x', ls_x, '')
		li_rc = of_Restore (ab_UseRegistry, as_KeyOrIni, as_IniSection, &
			'window.y', ls_y, '')
		li_rc = of_Restore (ab_UseRegistry, as_KeyOrIni, as_IniSection, &
				'window.width', ls_width, '')
		li_rc = of_Restore (ab_UseRegistry, as_KeyOrIni, as_IniSection, &
				'window.height', ls_height, '')		
		If IsNumber(ls_x) and IsNumber(ls_y) Then
			iw_requestor.Move(Integer(ls_x), Integer(ls_y))
		ElseIf IsNumber(ls_x) Then
			iw_requestor.x = Integer (ls_x)
		ElseIf IsNumber(ls_y) Then
			iw_requestor.y = Integer (ls_y)
		End If
		If iw_requestor.Resizable Then
			If IsNumber(ls_width) and IsNumber(ls_height) Then
				iw_requestor.Resize(Integer(ls_width), Integer(ls_height))
			ElseIf IsNumber(ls_width) Then
				iw_requestor.width = Integer (ls_width)	
			ElseIf IsNumber(ls_height) Then
				iw_requestor.height = Integer (ls_height)	
			End If
		End If
	End If
End If

If ib_menuitems Then
	//Restore menu items
	li_rc = of_RestoreMenu(ab_UseRegistry, as_KeyOrIni, as_IniSection, iw_requestor.MenuId)
End If

//Check if the last functionality in this script is requested.
If ib_toolbars=False Then
	//Finished restore process.		
	Return 1
End If

//Check for a Menu on the window
If Not IsValid(iw_requestor.MenuId) or IsNull(iw_requestor.MenuId) Then
	//There is no menu associated on this window.  Processing
	//can end.
	Return 1
End If

//Get handles to all the Toolbars.
If lnv_menu.of_GetAllToolbarIndex (iw_requestor.MenuId, li_barindexarray) < 0 Then
	Return -1  //Fatal error
End If

//Loop through all toolbars.
li_upperbound = UpperBound(li_barindexarray)
For li_cnt = 1 to li_upperbound
	//Get the Toolbar for this iteration
	li_tbindex = li_barindexarray[li_cnt]
	ls_tbindex = 'toolbarindex'+string(li_barindexarray[li_cnt])

	//Restore all SetToolbar information.
	li_rc = of_Restore (ab_UseRegistry, as_KeyOrIni, as_IniSection, &
		ls_tbindex+'.title', ls_title, '')
	li_rc = of_Restore (ab_UseRegistry, as_KeyOrIni, as_IniSection, &
		ls_tbindex+'.visible', ls_visible, 'true')
	li_rc = of_Restore (ab_UseRegistry, as_KeyOrIni, as_IniSection, &
		ls_tbindex+'.alignment', ls_alignment, '')
	
	//Restore all SetToolbarPos information.
	//Only valid values for the toolbar position are numerical,
	//and greater than zero.
	lb_toolbarposition = True //Initialize to true.
	If Not of_RestorePositiveNumber (ab_UseRegistry, as_KeyOrIni, as_IniSection, &
		ls_tbindex+'.x', li_x) Then lb_toolbarposition=False	
	If Not of_RestorePositiveNumber (ab_UseRegistry, as_KeyOrIni, as_IniSection, &
		ls_tbindex+'.y', li_y) Then lb_toolbarposition=False
	If Lower(ls_alignment) = 'floating' Then
		If Not of_RestorePositiveNumber (ab_UseRegistry, as_KeyOrIni, as_IniSection, &
			ls_tbindex+'.width', li_width) Then lb_toolbarposition=False
		If Not of_RestorePositiveNumber (ab_UseRegistry, as_KeyOrIni, as_IniSection, &
			ls_tbindex+'.height', li_height) Then lb_toolbarposition=False
	End If

	//Convert to the appropriate data types. (no validation at this time)
	lb_visible = lnv_conversion.of_boolean(ls_visible)
	li_rc = lnv_conversion.of_ToolbarAlignment(ls_alignment, ltb_alignment)
	
	//Validate Toolbars values. 
	If IsNull(lb_visible) Then lb_visible=True	
	If IsNull(ls_title) Then ls_title=''	
	If IsNull(ltb_alignment) or lb_toolbarposition=False Then 
		//There was a problem with one value; Force Toolbar to appear TopLeft!
		ltb_alignment = AlignAtLeft!
		li_x = 1
		li_y = 1
	End If
	
	//Restore Toolbar values
	If ib_toolbartitles Then
		li_rc = iw_requestor.SetToolbar(li_tbindex, lb_visible, ltb_alignment, ls_title)
	Else
		li_rc = iw_requestor.SetToolbar(li_tbindex, lb_visible, ltb_alignment)		
	End If
		
	//Call the appropriate function for a Floating or NonFloating Toolbar.
	If ltb_alignment = Floating! Then	
		li_rc = iw_requestor.SetToolbarPos(li_tbindex, li_x, li_y, li_width, li_height)
	Else
		li_rc = iw_requestor.SetToolbarPos (li_tbindex, li_x, li_y, False)
	End If
Next

Return 1
end function

     
Name Owner
pfc_n_cst_winsrv_preference.of_restore pfc_n_cst_winsrv_preference
pfc_n_cst_winsrv_preference.of_restore pfc_n_cst_winsrv_preference

     
Name Owner
window.move window
window.resize window
window.settoolbar window
window.settoolbar window
window.settoolbarpos window
window.settoolbarpos window
systemfunctions.fileexists systemfunctions
systemfunctions.integer systemfunctions
systemfunctions.isnull systemfunctions
systemfunctions.isnumber systemfunctions
systemfunctions.isvalid systemfunctions
systemfunctions.len systemfunctions
systemfunctions.lower systemfunctions
systemfunctions.registryvalues systemfunctions
systemfunctions.string systemfunctions
systemfunctions.trim systemfunctions
systemfunctions.upperbound systemfunctions
pfc_n_cst_inifile.of_getsections pfc_n_cst_inifile
pfc_n_cst_conversion.of_boolean pfc_n_cst_conversion
pfc_n_cst_conversion.of_toolbaralignment pfc_n_cst_conversion
pfc_n_cst_winsrv_preference.of_restorepositivenumber pfc_n_cst_winsrv_preference
pfc_n_cst_winsrv_preference.of_restoremenu pfc_n_cst_winsrv_preference
pfc_n_cst_winsrv_preference.of_restore pfc_n_cst_winsrv_preference
pfc_n_cst_menu.of_getalltoolbarindex pfc_n_cst_menu

     
Full name
pfc_w_master

     
Name Scope
No Data