The PFC resize service provides functionality to automatically move and resize controls when the window or tab are resized. A minimum size can be specified, beyond which the control is no longer resized. Options provided to select how each individual control is resized are listed in a table below.
| FixedToRight | Control is moved keeping the original distance to the right edge. |
| FixedToBottom | Control is moved keeping the original distance to the bottom edge. |
| FixedToRight&Bottom | Control is moved keeping the original distance to the right and bottom edge. |
| Scale | Control is resized proportionally to the window. |
| ScaleToRight | Control is resized keeping the original distance to the right edge. |
| ScaleToBottom | Control is resized keeping the original distance to the bottom edge. |
| ScaleToRight&Bottom | Control is resized keeping the original distance to the right and bottom edge. |
| FixedToRight&ScaleToBottom | Control is moved keeping the original distance to the right
edge. Control is resized keeping the original distance to the bottom edge. |
| FixedToBottom&ScaleToRight | Control is moved keeping the original distance to the
bottom edge. Control is resized keeping the original distance to the right edge. |
In order to properly resize controls the resize service needs to know:
The original window size is registered by placing a call to of_SetOrigSize() when the service is created. The original control size and position are registered when each control resize style is specified.
In some cases, such as when opened in Layered! mode, the window may be resized before the open event or even pfc_preopen event. In that case a call to inv_resize.of_SetOrigSize (this.WorkSpaceWidth(), this.WorkSpaceHeight()) will register the new and not the original window size. This will result in the wrong resize behavior, typically a large gap between the controls and the window edge. The problem is that there is no way to dynamically calculate the original window size once it is opened in Layered! mode.
When a window is opened in any style other than Original! prior to registering any controls you need to add a call to of_SetOrigSize() with the static original window values.
In your Window's pfc_PreOpen event: this.of_SetResize(TRUE) // To obtain the accurate size, you must open window in its ORIGINAL size
// and add the following MessageBox to find out the Window's Width & Height
// (It is not necessarily the same as the "Windows Position Tab" Width & Height)
//MessageBox("Window Size","Width: " + string(this.WorkSpaceWidth())+&
// "~r~nHeight: "+ string(this.WorkSpaceHeight()))
IF IsValid(this.inv_resize) THEN this.inv_resize.of_SetOrigSize(2478,1273) //Then Plug in the width & height here
//and comment out temporary MessageBox
//Then continue with registering objects this.inv_resize.of_Register(<control>,"ScaleToRight&Bottom") END IF |
If you don't like to hardcode the window size you can use another approach. In most cases you can avoid hardcoding the window size by using the of_getminmaxpoints() function. The idea is to calculate the original window size by adding a constant gap value to the square area occupied by all the controls on the window. This method will work when the controls occupy most of the area of the window.
int ix, iy, imaxx, imaxy of_setResize(TRUE) IF IsValid(inv_resize) THEN inv_resize.of_getminmaxpoints(control, ix, iy, imaxx, imaxy) inv_resize.of_setorigsize(imaxx + CON.II_RESIZE_GAP, & imaxy + CON.II_RESIZE_GAP) END IF |
When the Preference service is enabled it will resize the window in pfc_w_master's open event.
Therefore, be sure to turn on both the Resize service and the Preference service in the window's pfc_PreOpen event. Also make sure to register all controls in the either the pfc_PreOpen event or an event that executes before it. For example, to register your tab page DWs, use the constructor event of the tabpage. (Please see example below for details.)
Contributed by Sharon Buntz
In your Window's pfc_PreOpen event: // Turn on the Window Resize Service this.of_SetResize (TRUE) IF IsValid(this.inv_resize) THEN this.inv_resize.of_Register (<tab control on window>, "ScaleToRight&Bottom") END IF // Turn on the Window Preference Service (if desired) this.of_SetPreference (TRUE) IF IsValid(this.inv_preference) THEN this.inv_preference.of_SetWindow (TRUE) this.inv_preference.of_SetToolBars (TRUE) this.inv_preference.of_SetMenuItems (FALSE) this.inv_preference.of_SetToolbarItemOrder (FALSE) this.inv_preference.of_SetToolbarItemSpace (FALSE) this.inv_preference.of_SetToolbarItemVisible (FALSE) this.inv_preference.of_SetToolbarTitles (FALSE) END IF |
In your Tab's Constructor event: // Nothing is needed here... // Because the tab pages are automatically resized when the tab control resizes // Do not register the tabpages themselves or you will notice slight resize problems // with your tabpages, since they are then being resized twice. // If you choose to do so, you may register the tab pages' controls from here, // but it is OO-preferable to let each tab page register their controls... // Some older PFC applications register from here because Pre-PFC 5.0.02, // PFC forgot to add the Resize service for the tab page. |
In your Tabpage's Constructor event: // Note: Pre-PFC 5.0.02, PFC forgot to add the Resize service for pfc_u_tabpg // Turn on the Resize Service this.of_SetResize (TRUE) IF IsValid(this.inv_resize) THEN this.inv_resize.of_Register (<control on tab page>, "ScaleToRight&Bottom") END IF |
In u_tabpg and u_tab's Destructor event: // Note: There is a bug where PFC forgot to turn off the Resize service. // As of PFC 5.0.03, it is still missing. // So add this line of code in order to properly destroy the resize // service when the tabpage/tab is destroyed. // This is important in order to plug memory leaks. this.of_SetResize (FALSE) //Add this to u_tabpg and u_tab's destructor event |
Contributed by Sharon Buntz
At top, triggers PFC_PREOPEN events (ancestor/descendants...) first
(Turn on Resize service and Register tab in descendant -
- Also call of_SetOrigSize(w,h) here, if not Original!)
(Turn on Preference service in descendant - if desired)
Then pfc_w_master's OPEN event continues and
it does the "Preference service Restore"(which causes window's RESIZE event to fire,
and, in turn, the window's controls will be moved/resized accordingly
via the Resize service)
Contributed by Sharon Buntz
The Resize service problem with Tabs using CreateOnDemand is very similar to the Resize problem with opening your windows in a style other than Original. Here is an explanation from Claudio Quant for this CreateOnDemand tabpage problem...
Background:
The resize service works by taking a snapshot of the container object (in this case the
TabPage) when the service is instantiated. The function of_SetOrigSize( ) is internally
used to do such. (This works as expected for all TabPages created without CreateOnDemand.)
The user is then expected to call the of_Register function once for each control that is to be resized automatically whenever the container resizes.
Problem:
At the time the objects are being registered, the resize service also takes a snap picture
of the TabPage size. The issue surfaces when CreateOnDemand has been used and prior to the
TabPage being created the TabControl has already been resized. By the time the TabPage
constructor event fires the object has already been resized and the service is out of
sync.
Solution:
Tell the service what the Original Size should be.
In the Constructor event for your CreateOnDemand TabPage: this.of_SetResize(TRUE) IF IsValid(this.inv_resize) THEN this.inv_resize.of_SetOrigSize(ii_originalWidth, ii_originalHeight) // Where ii_originalWidth and ii_originalHeight have values // that width/height would have been had the TabPage been created // in the original size //Then continue with registering objects this.inv_resize.of_Register(<control>,"ScaleToRight&Bottom") //Trigger the resize event to be sure that the tab is sized appropriately event resize(1, this.width, this.height) END IF |
The datawindow resize service is avalable in PFC 6.0. But if you can't wait,
Lijun Yang was kind enough to reverse engineer
it to PFC 5.0 and has made it available through the download
section of the PFCGuide site.
Contributed by PFCGuide staff, except
where noted otherwise.
PFCGuide is sponsored by Dynamic Technology Group.
The information provided is for advice only and not to be considered a contract or a
liability against Dynamic Technology Group.
Last revised: February 15, 2004 03:58 AM.