2. Re: XControls move splitter programatically
Tony Steward wrote:
>
> Hi Greg or anyone who can help,
> I want to save the splitter position when my app closes and when run
> again to come back the same size. I can do this if I do it at the time
> of creation, but I want to do it after I have created all the other
> screen items so they can automatically resize to suite.
>
> So is it possible to move/resize the windows/panes programatically?
> If so how?
>
Tony,
I do this via a EDB table that I store in the program's directory. Here's
the routine in it's entirety:
-- Open and process the user configuration file
procedure openCfgFile()
db_opened = False
-- Opent the db file
db_result = db_open(FROGCFGFILE, DB_LOCK_EXCLUSIVE)
-- If couldn't open try to create
if db_result != DB_OK then
db_result = db_create(FROGCFGFILE, DB_LOCK_EXCLUSIVE)
-- File opened
if db_result = DB_OK then
db_opened = True
db_result = db_create_table(FROGCFGTABLE)
db_result = db_create_table(FROGSYSCFGTABLE)
end if
-- File opened
else
-- Attempt to select the system config table and if not found create
db_result = db_select_table(FROGSYSCFGTABLE)
if db_result != DB_OK then
db_result = db_create_table(FROGSYSCFGTABLE)
end if
-- Select the config table
db_result = db_select_table(FROGCFGTABLE)
if db_result = DB_OK then
db_opened = True
end if
end if
-- Was the db opened?
if db_opened then
-- Get the current PC user
local_user = GetUserName()
-- Look for a record by user
rec_num = db_find_key(local_user)
-- Record found?
if rec_num > 0 then
-- Get the record data
rec_data = db_record_data(rec_num)
-- Set the main window's size and placment and the
-- size of the main window panes
left_pane_width = rec_data[LEFT_PANE_WIDTH]
right_pane_height = rec_data[RIGHT_PANE_HEIGHT]
window_mode = rec_data[WINDOW_MODE]
window_x = rec_data[WINDOW_X]
window_y = rec_data[WINDOW_Y]
-- If window mode is maximized then calculate the
-- window's normal size
if window_mode = Maximized then
window_width = floor(rec_data[WINDOW_WIDTH] * .5)
window_height = floor(rec_data[WINDOW_HEIGHT] * .5)
-- Else the window is not maximized, accpet size as-is
else
window_width = rec_data[WINDOW_WIDTH]
window_height = rec_data[WINDOW_HEIGHT]
end if
-- If we have user preferences
if length(rec_data) > LOAD_INIT_PAGE then
load_initial = rec_data[LOAD_INIT_PAGE]
font_name = rec_data[MAIN_FONT_NAME]
font_size = rec_data[MAIN_FONT_SIZE]
rec_threshold = rec_data[THRESHOLD]
else
load_initial = True
font_name = {}
font_size = 0
rec_threshold = 5000
end if
-- Check for enter executes sql setting
if length(rec_data) >= ENTER_EXEC_SQL then
enter_exec_sql = rec_data[ENTER_EXEC_SQL]
else
enter_exec_sql = True
end if
-- Check for force signon
if length(rec_data) >= FORCE_SIGNON then
force_signon = rec_data[FORCE_SIGNON]
else
force_signon = True
end if
-- Record not found, flag that the file was not opened
else
db_opened = False
end if
-- Load the system configuration tables
db_result = db_select_table(FROGSYSCFGTABLE)
-- Look for a record by user
rec_num = db_find_key(local_user)
-- Record found?
if rec_num > 0 then
-- Get the record data
rec_data = db_record_data(rec_num)
sys_cfg_names = rec_data[SYSCFG_NAMES]
sys_cfg_data = rec_data[SYSCFG_DATA]
else
sys_cfg_names = {}
sys_cfg_data = {}
end if
-- close the config file
db_close()
end if
-- If the file was not opened then default the screen dimensions
if not db_opened then
left_pane_width = 200
right_pane_height = 300
window_mode = Maximized
window_x = .25
window_y = .25
window_width = .5
window_height = .5
load_initial = True
font_name = {}
font_size = 0
rec_threshold = 5000
enter_exec_sql = True
force_signon = True
end if
end procedure
openCfgFile()
The above routine is called BEFORE any calls to createEx. Then I create
my main window:
-- Window Main
global constant Main = createEx( Window, "F.R.O.G. for IBM iSeries DB2", 0,
window_x, window_y, window_width, window_height, 0, 0 )
Then, in the section of my program where it creates the xControls:
constant MainGMID = xControl( Geometry, "", Main, 0, 0, 0, 0, 0, 0),
MainLS = xControl( LimitSize, "", Main, 400, 400, 0, 0, 0, 0 ),
paneLeft = create(Window, "", Main, 0, 0, 0, 0,
{WS_CHILD,WS_VISIBLE,WS_CLIPSIBLINGS} ),
vsplit = xControl( VSplitter, "", Main, left_pane_width, 0, 0, 0, 0,
MainGMID ),
paneRight = create(Window, "", Main, 0, 0, 0, 0,
{WS_CHILD,WS_VISIBLE,WS_CLIPSIBLINGS} )
manage(MainGMID, paneLeft, {0,5}, {0,5}, {vsplit,0}, {1.0,0})
manage(MainGMID, paneRight, {vsplit,0}, {0,5}, {1.0,-5}, {1.0,0})
manage(MainGMID, MainTB, {0, 0}, {0, 0}, {1, 0}, {0, 34})
constant LeftGMID = xControl( Geometry, "", paneLeft, 0, 0, 0, 0, 0, 0 )
global constant MainTV = createEx( TreeView, "", paneLeft, 0, 0, 0, 0,
or_all({TVS_HASLINES,TVS_LINESATROOT,TVS_HASBUTTONS,TVS_SHOWSELALWAYS,TVS_INFOTIP}),
0 )
removeStyle(MainTV, WS_BORDER)
manage( LeftGMID, MainTV, {0, 0}, {0, 0}, {1.0,0}, {1.0,-5} )
constant RightGMID = xControl( Geometry, "", paneRight, 0, 0, 0, 0, 0, 0),
paneTop = create(Window, "", paneRight, 0, 0, 0, 0,
{WS_CHILD,WS_VISIBLE,WS_CLIPSIBLINGS} ),
hsplit = xControl( HSplitter, "", paneRight, 0, right_pane_height, 0, 0,
0, RightGMID ),
paneBottom = create(Window, "", paneRight, 0, 0, 0, 0,
{WS_CHILD,WS_VISIBLE,WS_CLIPSIBLINGS} )
manage (RightGMID, paneTop, {0,0}, {0,0}, {1.0,0}, {hsplit,0})
manage (RightGMID, paneBottom, {0,0}, {hsplit,0}, {1.0,0}, {1.0,0})
Note that I only track the left pane width and the right pane height.
Then when my program closes, I save the current dimensions with:
-- Open the config database again and save the window size/style
db_result = db_open(FROGCFGFILE, DB_LOCK_EXCLUSIVE)
if db_result = DB_OK then
db_result = db_select_table(FROGCFGTABLE)
if db_result = DB_OK then
rec_num = db_find_key(local_user)
main_rect = getWindowRect(Main)
left_rect = getWindowRect(paneLeft)
top_rect = getWindowRect(paneTop)
if isMaximized(Main) then
maximized = Maximize
else
maximized = Normal
end if
rec_data = {left_rect[3] - left_rect[1],
top_rect[4] - top_rect[2],
maximized, main_rect[1], main_rect[2],
main_rect[3] - main_rect[1],
main_rect[4] - main_rect[2],
load_initial, font_name, font_size, rec_threshold,
enter_exec_sql, force_signon}
if rec_num > 0 then
db_replace_data(rec_num, rec_data)
else
void = db_insert(local_user, rec_data)
end if
end if
Clear as mud?
Jonas Temple
http://www.yhti.net/~jktemple
3. Re: XControls move splitter programatically
> Clear as mud?
Crystal.
I'll look into adding moveSplitter() or something of the
sort to automagically move the splitter at run time, not just set the
size at creation time.
The funny thing is, if you download Don's original splitter control
(vertical only), it allowed for "padding" around the splitter and
adjustable splitter size, neither of which is included in xControls.
The padding can be accomplished with Geometry, and I'll add the
adjustable splitter size later. I should start working on that soon,
but I'm graduating in 6 weeks so all my attention is on my networking
project. All programming is currently on hold until March 9th.
~Greg
4. Re: XControls move splitter programatically
- Posted by Jonas Temple <jtemple at yhti.net>
Jan 29, 2005
-
Last edited Jan 30, 2005
Greg Haberek wrote:
>
> > Clear as mud?
>
> Crystal.
I'll look into adding moveSplitter() or something of the
> sort to automagically move the splitter at run time, not just set the
> size at creation time.
>
> The funny thing is, if you download Don's original splitter control
> (vertical only), it allowed for "padding" around the splitter and
> adjustable splitter size, neither of which is included in xControls.
> The padding can be accomplished with Geometry, and I'll add the
> adjustable splitter size later. I should start working on that soon,
> but I'm graduating in 6 weeks so all my attention is on my networking
> project. All programming is currently on hold until March 9th.
>
> ~Greg
While you're at it, can you improve the library to have a window with
three controls split by two splitters, with each splitter not able to
cross over the other?
:)
Jonas Temple
http://www.yhti.net/~jktemple
5. Re: XControls move splitter programatically
I lookforward to seeing xcontrols only getting better.
I curently have my winow split into three and its awsome.
Jonas thanks for you routine but I had already done that. I was really
after a way to set the splitter positions after creating every thing
because I use autosize.ew to size all my controls.
Maybe geometry would be better, but I just don't get how to use
geometry in split windows to control the size of say an EUGrid.
thanks
Tony
On Sat, 29 Jan 2005 15:07:53 -0800, Jonas Temple
<guest at rapideuphoria.com> wrote:
>
> posted by: Jonas Temple <jtemple at yhti.net>
>
> Greg Haberek wrote:
> >
> > > Clear as mud?
> >
> > Crystal.
I'll look into adding moveSplitter() or something of the
> > sort to automagically move the splitter at run time, not just set the
> > size at creation time.
> >
> > The funny thing is, if you download Don's original splitter control
> > (vertical only), it allowed for "padding" around the splitter and
> > adjustable splitter size, neither of which is included in xControls.
> > The padding can be accomplished with Geometry, and I'll add the
> > adjustable splitter size later. I should start working on that soon,
> > but I'm graduating in 6 weeks so all my attention is on my networking
> > project. All programming is currently on hold until March 9th.
> >
> > ~Greg
> While you're at it, can you improve the library to have a window with
> three controls split by two splitters, with each splitter not able to
> cross over the other?
>
> :)
>
> Jonas Temple
> http://www.yhti.net/~jktemple
>
>
>
>
--
Regards
Tony Steward
www.locksdownunder.com
IF IT IS TO BE IT IS UP TO ME!
6. Re: XControls move splitter programatically
> While you're at it, can you improve the library to have a window with
> three controls split by two splitters, with each splitter not able to
> cross over the other?
Sure, I'll call it XSplitter. It may take some time to develop. I
think I may change the approach to creating panes and splitters, it
does seem a bit convoluted. Until then, here's a little routine I
whipped up to make attaching a pane to a splitter a bit easier.
Remember to call manage_now() after you've attached all panes. This
will be in the next xControls to make it easier to attach panes to an
XSplitter (cross-splitter) by adding values (Top+Left, etc.).
global constant
Left = 1,
Top = 2,
Right = 4,
Bottom = 8
global procedure attachPane( integer pGeom, integer pPane,
integer pSplit, integer pPosition )
sequence pos1, pos2, pos3, pos4
pos1 = {0,0} -- left edge
pos2 = {0,0} -- top edge
pos3 = {1.0,0} -- right edge
pos4 = {1.0,0} -- bottom edge
if and_bits( pPosition, Left ) then
pos3 = {pSplit,0}
elsif and_bits( pPosition, Top ) then
pos4 = {pSplit,0}
elsif and_bits( pPosition, Right ) then
pos1 = {pSplit,0}
elsif and_bits( pPosition, Bottom ) then
pos2 = {pSplit,0}
end if
manage( pGeom, pPane, pos1, pos2, pos3, pos4 )
end procedure