Index of Functions ------------------ 1: toggle_FormBrowse Function Name ( 1): toggle_FormBrowse -------------------------------------------------------------------------------- 'Date Created: 05-Apr-2009 01:21:27 AM 'Last Updated: 14-Apr-2009 09:25:46 AM 'Created By : Ira J. Perlow 'Updated By : Ira J. Perlow FUNCTION Toggle_FormBrowse AS C (layoutname="" as c,layouttype="" as c,windowname="" as A,TitlePreserve=.t. as L,NewTitle="" as C,RecordNumber=0 as N) 'DESCRIPTION: Toggles a window between form and browse mode or sets window to an explicit form/browse 'LIMITATIONS:X '========================================================================= ' Created by Computer Systems Design & Associates ' Copyright 2009 Computer Systems Design & Associates, All Rights Reserved ' http://www.csda1.com ' You may use this code at your own risk in whole or as a part. ' Use in full or part in operational code is permitted with proper ' attributions to the source, and preserving the Copyrights and this paragraph ' except it may not be sold as part of any software package that includes a ' library of functions as a primary use of the software package. Use in ' instructional materials is permitted if provided without modification as source '========================================================================= ' Toggle_FormBrowse - Version 1.06 Release Date: 20090412 ' ' Syntax ' C Toggle_FormBrowse([C layoutname[,C layouttype[,* windowname[,L TitlePreserve[,C NewTitle[,N RecordNumber]]]]]]) ' ' Purpose: Toggles a window between form and browse mode or sets window to an explicit form/browse ' ' Input: layoutname - Name of new layout to use (normally a form or browse) ' If null, then use current companion browse/form. ' If blank (1 or more spaces, use companion object with the same name) ' layouttype - normally value of "", "form" or "browse" ' If null or blank, use opposite type to current window class (form or browse) ' windowname - Window name (not the title) to use. ' If null or blank, use current window ' TitlePreserve - If .t. (default), then it preserves title after switch ' NewTitle - if TitlePreserve=.f. and if not blank, then changes to new title after swap ' if TitlePreserve=.f. and is blank, uses current name, or if caption is readable, then the caption ' RecordNumber - Go to record # after swap if greater than 0, otherwise uses original record number ' Default is 0, which uses the original record number ' ' Output: Return's layoutname, or for default layouts, "". On error, returns null string "" ' ' Errors: Return's null "" on error ' ' Examples: ' ?Toggle_FormBrowse() ' Toggle's current window to object's companion (e.g. form's companion browse) ' ?Toggle_FormBrowse("") ' Toggle's current window to object's companion (e.g. form's companion browse) ' ?Toggle_FormBrowse(" ") ' Toggle's current window to companion object with same name ' ?Toggle_FormBrowse("layoutname") ' Change's current window to opposite of current type form or browse called layoutname ' ?Toggle_FormBrowse("layoutname","") ' Change's current window to opposite of current type form or browse called layoutname ' ?Toggle_FormBrowse("formname","form") ' Change's current window to form called formname ' ?Toggle_FormBrowse("browsename","browse") ' Change's current window to browse called browsename ' ?Toggle_FormBrowse("browsename","","Inventory") ' Change's form window named "Inventory" to browse called browsename ' ' Notes: ' Window Title might change during switch. If you wish to keep it unchanged, set it to TitlePreserve to .t. ' If swapped window is based on the same table, it will move to the same record number ' Swapped window must be based on same table, otherwise it fails '====================================================================== ' Set default return value Toggle_FormBrowse="" ' Get current window name DIM winnam as c IF typeof(windowname) $ "CB" IF trim(windowname)=="" ' Use current window name winnam=a5.active() ELSE ' Use supplied window name winnam=alltrim(windowname) END IF ELSE IF typeof(windowname)=="P" ' Get window name of pointer winnam=eval("windowname.name()") ELSE ' Invalid windowname type to derive window name EXIT FUNCTION END IF IF .not.(eval_valid(winnam+".class()")) ' Not a valid window name, so definitely an error EXIT FUNCTION END IF dim winptr as P winptr=eval(winnam+".this") ' Get current windows class DIM wincls as c wincls=winptr.class() IF wordat(wincls,"form,browse",",")<=0 ' This is might not work for other window classes other than form or browse, ' so uncomment next line if desired ' EXIT FUNCTION END IF ' Get layout type to switch to dim laytyp as c IF trim(layouttype)=="" ' If null, then we toggle from the current type IF UT(wincls)=="FORM" ' If form type, then we'll toggle type to browse laytyp="browse" ELSE ' If any other type, then we'll use form laytyp="form" END IF ELSE IF wordat(alltrim(layouttype),"form,browse",",")>0 ' form or browse type, so use that laytyp=alltrim(layouttype) ELSE ' Otherwise we'll use it, but not sure if it is useful laytyp=alltrim(layouttype) ' EXIT FUNCTION ' or treat as error??? END IF END IF ' Get current window title dim wintit as c wintit="" ' The very act of reading the current window title of a browse by any code causes the default caption title ' in a form not to work when switching from the browse to form, so we provide an exception code to try to ' allow it to work IF .not.((ut(laytyp)=="FORM").and.(UT(wincls)=="BROWSE").and.(TitlePreserve=.f.).and.(ut(newtitle)=="")) IF eval_valid("winptr.window_title") ' Not always a valid parameter, so test it wintit=winptr.window_title END IF END IF ' Get new title to set it to, if any dim newtit as c newtit="" IF TitlePreserve ' Preserve Title if specified newtit=wintit ELSE IF .not.(trim(newtitle)=="") ' set to new title newtit=trim(newtitle) END IF ' Get layout name to switch to DIM laynam as c IF trim(layoutname)="" ' If blank and leading character is a space (as opposed to null) if left(layoutname,1)==" " ' Use the same name as the current window (but opposite layout type) laynam=winptr.name(1) ' Returns "" for default browse, but value for form IF ut(wincls)=="FORM" ' Compare name to form's default name IF ut(laynam)==ut("DefaultForm_"+file.filename_parse(winptr.DICTIONARY_GET(1),"N")) ' force to null to select default laynam="" END IF END IF else ' Use the companion object IF ut(wincls)=="FORM" ' This always returns "" for form (at least in A5v8) laynam=winptr.companion_browse IF laynam="" ' Since it came up blank, we'll do it with a form.Toggle_FormBrowse(). ' This is the same as F8 ' Toggle to browse winptr.Toggle_FormBrowse() ' wait for new window to be set up IF version()>=7 ui_yield() ELSE xbasic_wait_for_idle() END IF ' Set the layout window Title if needed IF .not.(newtit=="") IF .not.(newtit=winptr.window_title) winptr.window_title=newtit END IF END IF ' Get the layout name now that we switched to it Toggle_FormBrowse=winptr.name(1) EXIT FUNCTION END IF ELSE IF ut(wincls)=="BROWSE" laynam=winptr.companion_form ELSE ' No companion object, so exit EXIT FUNCTION END IF END IF ELSE laynam=alltrim(layoutname) END IF ' If window is not visible, then activate it IF eval("winptr.IsVisible()")=.f. winptr.activate() END IF ON ERROR GOTO FINISH dim orgtbl as c dim orgrec as n orgtbl=winptr.table_get().Actual_Filename_Get() orgrec=winptr.Table_Get().recno() ' See if we specify the record number dim recnum as n IF recordnumber>0 recnum=recordnumber ELSE recnum=orgrec END IF ' Swap window for new layout IF wordat(laytyp,"form,browse",",")>0 IF (ut(laytyp)=="FORM").and.(UT(wincls)=="BROWSE") winptr.companion_form=laynam winptr.toggle_formbrowse() ELSE IF recnum>0 ' The Record parameter does seem to work, but card swap does not refresh all objects ' Title parameter does not seem to work, but may in older versions of A5 ' we do it here to help eliminate flash in changes. If it doesn't work, it will ' be done later if needed ' card_swap(laytyp+"_viewer","use=~"+laynam+"~"+" Record="+ltrim(str(recnum)),session_get(wintit)) card_swap(laytyp+"_viewer","use=~"+laynam+"~"+" Title=~"+newtit+"~"+" Record="+ltrim(str(recnum)),session_get(wintit)) ELSE card_swap(laytyp+"_viewer","use=~"+laynam+"~",session_get(wintit)) end if END IF ELSE card_swap(laytyp,"use=~"+laynam+"~",session_get(wintit)) END IF ' wait for new window to be set up IF version()>=7 ui_yield() ELSE xbasic_wait_for_idle() END IF ' Set the layout window Title if needed IF newtit=="" ' If blank, then we'll try to use the one that is for the new layout IF eval_valid("winptr.window.window_title") ' caption parameter ' If default caption is exposed, we'll use that, ' but is not available in the form except in design mode ' and not at all in a browse newtit=winptr.window.window_title END IF END IF IF .not.(newtit=="") IF .not.(newtit=winptr.window_title) winptr.window_title=newtit END IF END IF ' Go to record number if not already there IF (winptr.Table_Get().recno()<>recnum).and.(recnum>0) winptr.Table_Get().fetch_goto(recnum) end if winptr.Command("REFRESH") ' Refreshes everything, including embedded browses IF laynam="" ' If default name, return default Toggle_FormBrowse="" ELSE ' Return layout name Toggle_FormBrowse=laynam END IF FINISH: on error goto 0 EXIT FUNCTION END FUNCTION End Function ( 1)---------------------------------------------------------------