Tipswip   >   Windows   >   Windowsizelocation   >   Window Size & Location (All Contents)
For a better user interface, it is a good idea to store the last used (closed) size and location of each window instance for each user. Then when the user reopens a window instance, you can size and position it to the exact same size and position which they last closed the window.
A simple approach is to update the window's class size and location with the current instance size and location when the window is closed. It is best to put the code for this in the $destruct. This approach has a number or shortfalls. See "Simple Destruct Method" for more details.
A better approach is to store each window instance size and location by user in the data file.
In order to do this, you need to have some type of a 'logon' (Sign-In) method which the user must go through when entering your application. This way your application knows 'who' the user is.
I have a table in my data file called 'usr' which stores the usr_, name, password, direct phone number, email address, security access levels, etc. AND of course the 'usr_WindowsUsedList'
After the user successfully signs in, the 'usr_WindowsUsedList' is loaded into a class variable of the object class 'oWindowSizes'. A class variable is used for the windows used list in oWindowSizes so that the list will persist as the object class instances are opened and closed.
In the $construct of each window (in the base windows superclass) I have a line of code: Do oWindowSizes.$setWindowSize($cinst)
The method checks the WindowsUsed list, if the $cinst.()$name has been opened/closed by the user, then $setWindowSize, sets the size and position to the last used size and position.
In the $destruct of each window (in the base windows superclass) I have a line of code: Do oWindowSizes.$SaveWindowSize($cinst)
The method checks the WindowsUsed list, if the $cinst.()$name has been opened/closed by the user, then $setWindowSize, updates the size and position (and date/time), otherwise it adds it to the list.
Storing the windows opened by each user also gives you a security audit. You can check the user profiles to see all the windows each user has opened, and the date/time they last opened it.
The "oWindowSizes" object class which I use in my application has been copied into this StudioTips library, but since we aren't storing user profiles here, "oWindowSizes" have not been implemented in StudioTips. Feel free to copy "oWindowSizes" to your library and modify it to suit your needs. The methods for "oWindowSizes" are listed in this section with extra comments. "oWindowSizes" has been tested on Mac and Wintel platforms.The simple destruct method approach updates the window's class with the size and location of the current window instance size and location when the window is closed. It is best to put the code for this in the $destruct.
There are a number of shortfalls with the "Simple Destruct Method":
1. New version of software will wipe out the last closed window size and location.
2. It won't help users who use different workstations.
3. It can't save different instances of the same window class.
4. Overriding the inherited size and locations in subclass windows is extra work. (Special notation)
For a simple application with few windows and few updates the simple destruct method is fine. For an application that doesn't have a user sign-in method the simple destruct method is fine. I am using the simple destruct method in StudioTips.
See the sample code for the simple destruct code.
COPY CLASS DATA METHOD
Another possibility is to copy the $cinst properties to the $class. This will save ALL the properties of ALL the objects, methods, etc. of the current instance to its class. (This might be overkill?) You could put the following line in your window's $destruct method.
Do $cclass.$classdata.$assign($cinst.$classdata)WINDOW SIZES OBJECT CLASS
This section lists the methods in the object class "oWindowSizes"
This "oWindowSizes" object class is responsible for keeping track of all the windows the user has closed, and the date/location/size they were last closed. When a window is opened this object is responsible for setting it to the exact same size and location that it was last closed by the user. This object is also responsible for the "open windows toolbar" along the bottom of the screen. The "open windows toolbar" has an icon for each window instance that is currently open. Users can click on the icon to bring the window instance to the front.
When a new user signs in, this object is notified by way of the $signinNewUser() method. This object gets the latest "Windows Used List" from the user's profile. The list is loaded into "cwUsed", a class variable in this object.
When a window is opened, the window's $construct asks this object to $setWindowSize.
$setWindowSize checks "cwUsed" to see if the user has opened the window instance before, if so,
using "pWinRef" the method sets the window size and location to the size and location last closed by the user. If not found,
$setWindowSize opens the window to the default size and location.
$setWindowSize uses "CheckAndSizeToFit" to make sure the window fits within the boundaries of the monitor currently used by the user. If it doesn't, "CheckAndSizeToFit" does its best to move and if necessary adjusts the size of the window so it doesn't exceed the boundaries of the current monitor.
When a window is closed, the window's $destruct informs this object by way of "$SaveWindowSize".
Based on the window instance name "$SaveWindowSize" checked the "cwUsed" list, if found it updates it, if not it adds a new row to the list.
When the user signs off, the signoff method gets the up to date "Windows Used List" from this object using "$retWindowsUsedList". It updates the user profile and saves it to the data file.RETURN WINDOWS USED LIST
This method returns the windows used list to the calling method. The windows used list "cwUsed" is a class variable stored in this object class.
After signing in the windows used list is loaded from the user's profile The list is updated during the session. When the user closes the application
The updated Windows Used list is obtained from this object class, and the user's profile is updated.SAVE WINDOW SIZE
This method is called by the $destruct of every window instance. This method checks to see if the window instance name already exists in the windows used list. If so, the old records is updated with the size and location of that window on closing. If not a new records is added to the list with the size and location on closing the window.
I have a toolbar along the bottom of the window with icons representing each open window. This object class is responsible for the toolbar. This method removes the window's icon from the toolbar.SET MAIN MENU WINDOW SIZE
This method is called by the $construct of the Main Menu window instance. It is only used by the Main Menu. It sets the Main Menu size to cover a good part of the screen so that other windows can be "hidden" behind the Main Menu, keeping the screen uncluttered for the user.SET WINDOW SIZE
When a window is opened, the window's $construct asks this object to $setWindowSize.
$setWindowSize checks "cwUsed" to see if the user has opened the window instance before, if so, using prWin the method sets the window size and location to the size and location last closed by the user. If not found, $setWindowSize opens the window to the default size and location.
$setWindowSize used "CheckAndSizeToFit" to make sure the window fits within the boundaries of the monitor currently used by the user. If it doesn't "CheckAndSizeToFit" does its best to moves and if necessary adjusts the size of the window so it doesn't exceed the boundaries of the current monitor.SIGN IN NEW USER
When a new user signs in, this object is notified by way of the $SignInNewUser() method. This object gets the latest "Windows Used List" from the user's profile. The list is loaded into "cwUsed", a class variable in this object.
If the list is empty, then a windows used list is defined and loaded into "cwUsed"CHECK AND SIZE TO FIT
After $setWindowSize has set the window size and location it calls this method to make sure the proposed size and location fits on the current monitor. If it won't fit within the boundaries this method moves and if necessary resizes the window to fit within the boundaries.The window instance size is set during the $construct of the window. This allows the window to be sized and located before the user sees it. The $contruct calls "oWindowSizes" asking it to set the size and location of the window.
The window instance size is stored during the $destruct of the window. The $destruct calls "oWindowSizes" and asks it to store the size and location of the window instance when it is closed.$construct OF THE BASE WINDOW SUPERCLASS
Set the window size to the last time the user closed it, or the default sizes Do oWindowSizes.$setWindowSize($cinst)
The base window superclass $construct includes the above line of code "oWindowSizes" is a local variable, Type=Object, Subtype pointed to "oWindowSizes". Sending the parameter $cinst of the window instance which is being $constructed allows "oWindowSizes" to get and set the window size and location for this window instance. Since this occurs during the $construct of the window, "oWindowSizes" can change the position and size of the window before the user sees it.
I use the window instance name [$cinst().$name] for my window titles, names, etc.$destruct OF THE BASE WINDOW SUPERCLASS
Save the window size, so it will reopen at this size for this user.
Do oWindowSizes.$saveWindowSize($cinst)
The base window superclass $destruct includes the above line of code. "oWindowSizes" is a local variable, Type=Object, Subtype pointed to "oWindowSizes". Sending the parameter $cinst of the window instance which is being closed allows "oWindowSizes" to get the window size and location for this window, and then store them in the windows used list.
I use the window instance name [$cinst().$name] for my window titles, names, etc.