PFC Resize Service enhancement to remove requirement to use of_SetOrigSize()

More
1 year 1 month ago #455 by Jim Reese
Jim Reese created the code: PFC Resize Service enhancement to remove requirement to use of_SetOrigSize()
While investigating window sizing differences in PB2022, I dug into the PFC code for the window resize service.
We are using the version of PFC that still uses the ClassDefinition to get the original height and width, rather than using WorkspaceHeight() and WorkspaceWidth() in the call to of_SetOrigSize() made from pfc_w_master.of_SetResize(TRUE)

I did numerous comparisons, and found that the window painter values often differed from both the ClassDefinition and the Workspace...() values during window preopen and open events. Workspace...() values were incorrect when opening a sheet as layered!, for example.
Examining the values, I realized that the ClassDefinition height and width values differed from the painter values depending on which window attributes had been set for the particular window.

A window that has none of the attributes set, such as a popup splash with no title or border, has a ClassDefinition width and height that equals the Window Painter width and height values. For each attribute that is enabled, the ClassDefinition width and height values are increased by the following PBU amounts. My screen has a Horizontal Pixel to PBU ratio of 4.5 and a vertical PBU ratio of 4, so the corresponding Pixel values were determined from the PBU values.
			PBUs		Pixels
Attribute		 W	  H	 W	 H
------------		--	---	--	--
titlebar		 0	 72	 0	18
menuname		 0	 64	 0	16
hscrollbar		 0	 76	 0	19
vscrollbar		72	  0	16	 0
resizable		27	 24	 6	 6
border			 9	  8	 2	 2
clientedge		18	 16	 4	 4
palettewindow		 0	-12	 0	-3
By examining the ClassDefinition of the window during of_SetResize(), these values can be subtracted from the reported width and height to determine the original window painter width and height values, removing the need to hard-code the painter values in a call to of_SetOrigSize in the preopen or open event. Those values can be problematic if a developer modifies the size of the window in the painter and neglects to update the values in the script.

Below is my code in w_master.of_SetResize(), overriding the pfc_w_master function it is based on. By coding this, I have been able to remove all of_SetOrigSize() calls in window preopen/open events that are using the resize service.
I have not coded for using a theme, but did a quick test and saw that workspace...() values increased when a theme was used.
//////////////////////////////////////////////////////////////////////////////
//	Public Function:  of_SetResize
//	Arguments:	ab_switch	starts/stops the window resize service
//	Returns:	Integer		1 = success,  0 = no action necessary, -1 error
//	Description:	Starts or stops the window resize service
//////////////////////////////////////////////////////////////////////////////
//	Rev. History:	Version
//			5.0   Initial version
//			8.0   Modified to initially set window dimensions based on the class definition
//			2022  Jim Reese Modified to handle original window sizes based on painter and window properties that affect size
//////////////////////////////////////////////////////////////////////////////
Integer	li_width_offset, li_height_offset, li_found_property //JRR offset values in pixels, convert final sums to PBUs
integer	li_rc, li_v, li_vars
integer li_origwidth, li_origheight

// Check arguments
if IsNull (ab_switch) then
	return -1
end if

if ab_Switch then
	if IsNull(inv_resize) Or not IsValid (inv_resize) then
		inv_resize = create n_cst_resize
		
		/*  Get this window's class definition and extract the width and height  */
		classdefinition lcd_class
		lcd_class = this.ClassDefinition

		li_vars = UpperBound ( lcd_class.VariableList )
		For li_v = 1 to li_vars
			//JRR BEGIN window size varies from painter based on the following attributes. This adjust(s) based on which are set
			CHOOSE CASE lcd_class.VariableList[li_v].Name
				CASE "width"
					li_found_property ++ 
					li_origwidth = Integer ( lcd_class.VariableList[li_v].InitialValue ) 
				CASE "height"
					li_found_property ++
					li_origheight = Integer ( lcd_class.VariableList[li_v].InitialValue ) 
				CASE "titlebar"
					li_found_property ++
					IF lcd_class.VariableList[li_v].InitialValue THEN
						li_height_offset += 18 //72 use pixels for offsets, then convert total number to PBUs at end
					END IF
				CASE "menuname"
					li_found_property ++
					IF len(trim(string(lcd_class.VariableList[li_v].InitialValue))) > 0 THEN
						li_height_offset += 19 //76
					END IF
				CASE "hscrollbar"
					li_found_property ++
					IF lcd_class.VariableList[li_v].InitialValue THEN
						li_height_offset += 19 //76
					END IF
				CASE "vscrollbar"
					li_found_property ++
					IF lcd_class.VariableList[li_v].InitialValue THEN
						li_width_offset += 16 //72
					END IF
				CASE "resizable"
					li_found_property ++
					IF lcd_class.VariableList[li_v].InitialValue THEN
						li_width_offset += 6 //28 
						li_height_offset += 6 //24 
					END IF
				CASE "border"	
					li_found_property ++
					IF lcd_class.VariableList[li_v].InitialValue THEN
						li_width_offset += 2 //9 
						li_height_offset += 2 // 8 
					END IF
				CASE "clientedge"
					li_found_property ++
					IF lcd_class.VariableList[li_v].InitialValue THEN
						li_width_offset += 4 //18
						li_height_offset += 4 //16
					END IF
				CASE "palettewindow"
					li_found_property ++
					IF lcd_class.VariableList[li_v].InitialValue THEN
						li_height_offset -= 3 //12 //reduces height of titlebar
					END IF
			END CHOOSE
			If li_found_property = 10 Then Exit	//exit loop once all 10 values found
			//JRR END
		Next
		li_origwidth -= pixelstounits(li_width_offset,XPixelsToUnits!)   //JRR reduce orig by the offset to get back to painter values
		li_origheight -= pixelstounits(li_height_offset,YPixelsToUnits!) //JRR reduce orig by the offset to get back to painter values
		inv_resize.of_SetOrigSize ( li_origwidth, li_origheight )
	end if
else
	if IsValid (inv_resize) then
		destroy inv_resize
		li_rc = 1
	end if
end If

return li_rc

Please Log in or Create an account to join the conversation.

Moderators: Appeon Administrator