Powerbuilder – PFC Resize Service Extension / Max Height & Width
The PFC window resize service is one of my favorite things in the entire class library as it can easily be implemented and adds a great bit of functionality to an application. One drawback, however, is there is no built in capability to limit the resizing of the objects on a window; either they resize and/or move or they don’t. This simple extension adds the capability to set maximum width and height values to the controls being resized so you don’t end up with an ugly display of a large blank space after the end of the columns inside a datawindow control.
To implement this extension you need to change the code in the n_cst_resizeattrib and n_cst_resize objects. Whether you do this at the PFC layer or some corporate layer is up to you.
In the n_cst_resizeattrib object add the following instance variables:
real r_maxwidth = 0 real r_maxheight = 0
In the n_cst_resize object do the following:
Alter the of_register function to return the array position ‘li_slot_available’.
Add the following functions:
public function integer of_setmaxcontrolwidth (integer ai_arraypos, real ar_width); // 11.5.1 set maximum control width // parms ai_arraypos - array position in the inv_registered control array // ar_width - maximum witdth control can be resized to //set r_maxwidth in n_cst_resizeattrib for specified array position IF Upperbound(inv_registered) >= ai_arraypos THEN inv_registered[ai_arraypos].r_maxwidth = ar_width RETURN Success ELSE RETURN Failure END IF end function public function integer of_setmaxcontrolheight (integer ai_arraypos, real ar_height); // 11.5.1 set maximum control width // parms ai_arraypos - array position in the inv_registered control array // ar_width - maximum height control can be resized to //set r_maxheight in n_cst_resizeattrib for specified array position IF Upperbound(inv_registered) >= ai_arraypos THEN inv_registered[ai_arraypos].r_maxheight = ar_height RETURN Success ELSE RETURN Failure END IF end function
Then in the of_resize method modify as follows:
BEFORE: //Save the 'exact' Width and Height attributes. inv_registered[li_cnt].r_width = inv_registered[li_cnt].r_width + lr_resize_deltawidth inv_registered[li_cnt].r_height = inv_registered[li_cnt].r_height + lr_resize_deltaheight AFTER: // look at maximum values IF (inv_registered[li_cnt].r_maxwidth > 0) AND (inv_registered[li_cnt].r_width + lr_resize_deltawidth > inv_registered[li_cnt].r_maxwidth) THEN // exceeds max width so set to max inv_registered[li_cnt].r_width = inv_registered[li_cnt].r_maxwidth ELSEIF (inv_registered[li_cnt].r_width = inv_registered[li_cnt].r_maxwidth) AND (inv_registered[li_cnt].r_maxwidth > 0) THEN IF inv_registered[li_cnt].b_scalewidth AND (inv_registered[li_cnt].r_width > ai_newwidth) THEN // resize down from max width to fit on window (115 is width of vertical scroll bar) inv_registered[li_cnt].r_width = inv_registered[li_cnt].r_maxwidth + (ai_newwidth - inv_registered[li_cnt].r_width ) - 115 END IF ELSE //Save the 'exact' Width and Height attributes. inv_registered[li_cnt].r_width = inv_registered[li_cnt].r_width + lr_resize_deltawidth END IF IF (inv_registered[li_cnt].r_maxheight > 0) AND (inv_registered[li_cnt].r_height + lr_resize_deltaheight > inv_registered[li_cnt].r_maxheight) THEN // exceeds max so set to max inv_registered[li_cnt].r_height = inv_registered[li_cnt].r_maxheight ELSEIF (inv_registered[li_cnt].r_height = inv_registered[li_cnt].r_maxheight) AND (inv_registered[li_cnt].r_maxheight > 0) THEN // resize down from max IF inv_registered[li_cnt].b_scaleheight AND (inv_registered[li_cnt].r_height > ai_newheight) THEN // resize down from max height to fit on window (115 is width of horizontal scroll bar) inv_registered[li_cnt].r_height = inv_registered[li_cnt].r_maxheight + (ai_newheight - inv_registered[li_cnt].r_height ) - 115 END IF ELSE inv_registered[li_cnt].r_height = inv_registered[li_cnt].r_height + lr_resize_deltaheight END IF
Now in the event you register the controls on the window do the following:
li_arraypos = this.inv_resize.of_Register(dw_1, this.inv_resize.SCALERIGHTBOTTOM) IF li_arraypos > 0 THEN // set max width and height for dw_1 this.inv_resize.of_setmaxcontrolwidth(li_arraypos, 6400) this.inv_resize.of_setmaxcontrolheight(li_arraypos, 3000) END IF
NOTE: as of 10/1/2010 I am unable to get the height maximum piece to properly resize down from a maximum setting. This seems to be a bug but I will work on it some more as time permits. At this time I recommend not setting a maximum height for datawindows.
You might also be interested in
Leave a Reply