Reusable Part VL_SAM068: Dynamic Tool Bars

LANSA

Reusable Part VL_SAM068: Dynamic Tool Bars
Name: VL_SAM068

Description: The following RDMLX reusable component is used to dynamically create a tool bar.

This reusable component is used by forms VL_SAM069 and VL_SAM070.
* ===================================================================
*
* Component : VL_SAM068
* Type : Reusable Component
* Ancestor :
*
* Description : Reusable Component for Dynamic Tool Bars
* This reusable component is used by forms VL_SAM069 and VL_SAM070.
*
* Disclaimer : The following material is supplied as sample material
* only. No warranty concerning this material or its use
* in any way whatsoever is expressed or implied.
*
* ===================================================================
Function Options(*DIRECT)
Begin_Com Role(*EXTENDS #PRIM_PANL) Displayposition(1) Height(40) Left(0) Popupmenu(#MENU1) Tabposition(1) Top(0) Width(256)
Define_Com Class(#PRIM_GPBX) Name(#GROUPBOX) Displayposition(1) Height(42) Hintshow(False) Left(0) Parent(#COM_OWNER) Popupmenu(#MENU1) Tabposition(1) Tabstop(False) Top(0) Width(257)
Define_Com Class(#PRIM_KCOL) Name(#SB) Collects(#PRIM_PHBN) Keyedby(#STD_NUM)
Define_Com Class(#PRIM_LABL) Name(#TEXT) Caption('Tool bar buttons are determined at execution time') Displayposition(1) Height(19) Left(15) Parent(#GROUPBOX) Tabposition(1) Tabstop(False) Top(12) Visible(False) Width(233)

Define_Com Class(#PRIM_PMNU) Name(#MENU1)
Define_Com Class(#PRIM_MITM) Name(#FLOAT) Caption('Float Free ') Displayposition(1) Parent(#MENU1)
Define_Com Class(#PRIM_MITM) Name(#HORIZONTAL) Caption('Horizontal') Displayposition(2) Parent(#MENU1)
Define_Com Class(#PRIM_MITM) Name(#VERTICAL) Caption('Vertical ') Displayposition(3) Parent(#MENU1)

Define_Com Class(#VL_SAM069) Name(#FORM)


Define_Evt Name(TooBarButtonClicked)
Define_Map For(*input) Class(#Std_Obj) Name(#WithName)

Define_Evt Name(SwitchtoAttachMode)
Define_Evt Name(OrientationChanged)

Define_Pty Name(Orientation) Get(GetOrientation) Set(SetOrientation)

Define Field(#VISNAME) Reffld(#STD_OBJ)
Define Field(#WORKNAME) Reffld(#VISNAME)
Define Field(#VISHINT) Reffld(#STD_TEXTL)
Define Field(#VISBITMAP) Reffld(#STD_TEXTS)
Define Field(#VISCOUNT) Reffld(#STD_NUM)
Define Field(#LOOPCOUNT) Length(*REFFLD *PLUS 1) Reffld(#STD_NUM)
Define Field(#INITIALIZ) Type(*CHAR) Length(1) Default(N)

Def_List Name(#VISLIST) Fields(#VISNAME #VISHINT #VISBITMAP) Counter(#VISCOUNT) Type(*WORKING) Entrys(100)

Define Field(#CURCOUNT) Reffld(#STD_NUM)

Define Field(#ORIENT) Reffld(#STD_CODES) Default(H)
Define Field(#CURORIENT) Reffld(#ORIENT)
Def_Cond Name(*ORIENTVER) Cond('#Orient = V')

Define Field(#OPERMODE) Type(*CHAR) Length(1) Default(A)
Def_Cond Name(*ATTACH) Cond('#OperMode = A')
Def_Cond Name(*FLOAT) Cond('#OperMode *ne A')
Define_Pty Name(OperationMode) Set(SetOperMode)

Define_Pty Name(BarHeight) Get(GetBarHeight)
Define_Pty Name(BarWidth) Get(GetBarWidth)

* Show details if not already shown

Evtroutine Handling(#Com_Owner.Initialize)
Change Field(#INITIALIZ) To(Y)
Execute Subroutine(DRAWBAR)
Endroutine

* Return tool bar height

Ptyroutine Name(GetBarHeight)
Define_Map For(*output) Class(#Std_Num) Name(#Property5)
Set Com(#Property5) Value(#Com_Owner.Height)
Endroutine

* Return Tool Bar Width

Ptyroutine Name(GetBarWidth)
Define_Map For(*output) Class(#Std_Num) Name(#Property6)
Set Com(#Property6) Value(#Com_Owner.Width)
Endroutine

* Set Tool Bar Orientation

Ptyroutine Name(SetOrientation)
Define_Map For(*input) Class(#Std_Codes) Name(#Property1)
If Cond(*ATTACH)
Set Com(#FORM) Orientation(#Property1.Value)
Else
Use Builtin(UPPERCASE) With_Args(#PROPERTY1.VALUE) To_Get(#ORIENT)
Execute Subroutine(DRAWBAR)
Signal Event(OrientationChanged)
Endif
Endroutine

* Get Tool Bar Orientation

Ptyroutine Name(GetOrientation)
Define_Map For(*output) Class(#Std_Codes) Name(#Property2)
If Cond(*ATTACH)
Set Com(#Property2) Value(#FORM.Orientation)
Else
Set Com(#Property2) Value(#Orient)
Endif
Endroutine

* Set operational mode to either attached or free floating

Ptyroutine Name(SetOperMode)
Define_Map For(*input) Class(#Std_CodeS) Name(#Property3)
Change Field(#OPERMODE) To('#PROPERTY3.VALUE')
Endroutine

* Add tool bar item to tool bar

Mthroutine Name(AddToolBarItem)
Define_Map For(*input) Class(#Std_CodeL) Name(#UseName)
Define_Map For(*input) Class(#Std_TextL) Name(#UseHint)
Define_Map For(*input) Class(#Std_TextS) Name(#UseBitMap)

If Cond(*ATTACH)
Invoke Method(#FORM.AddToolBarItem) Usename(#UseName.Value) Usehint(#UseHint.Value) Usebitmap(#UseBitMap.value)
Endif

Change Field(#VISNAME) To('#USENAME.VALUE')
Use Builtin(UPPERCASE) With_Args(#VISNAME) To_Get(#VISNAME)
If Cond('#VisName = ALL')
Abort Msgtxt('Property "UseName" value ALL is reserved and cannot be used')
Endif
Change Field(#VISHINT) To('#USEHINT.VALUE')
Change Field(#VISBITMAP) To('#USEBITMAP.VALUE')
Use Builtin(UPPERCASE) With_Args(#VISBITMAP) To_Get(#VISBITMAP)
Add_Entry To_List(#VISLIST)
Endroutine

Mthroutine Name(AlterToolBarItem)
Define_Map For(*input) Class(#Std_CodeL) Name(#Named)
Define_Map For(*input) Class(#Std_CodeL) Name(#SetEnabled)

If Cond(*ATTACH)
Invoke Method(#FORM.AlterToolBarItem) Named(#Named.Value) Setenabled(#SetEnabled.Value)
Endif

Use Builtin(UPPERCASE) With_Args(#NAMED.VALUE) To_Get(#WORKNAME)
Use Builtin(UPPERCASE) With_Args(#SETENABLED.VALUE) To_Get(#STD_CODEL)
Begin_Loop Using(#LOOPCOUNT) To(#VISCOUNT)
Get_Entry Number(#LOOPCOUNT) From_List(#VISLIST)
Case Of_Field(#WORKNAME)
When Value_Is('= #VisName')
Set Com(#SB<#LoopCount>) Enabled(#Std_CodeL)
Return
When Value_Is(' = ALL')
Set Com(#SB<#LoopCount>) Enabled(#Std_CodeL)
Endcase
End_Loop
Endroutine

* Draw / Arrange new or updated tool bar details

Subroutine Name(DRAWBAR)

Define Field(#SBHEIGHT) Reffld(#STD_NUM) Default(28)
Define Field(#SBWIDTH) Reffld(#STD_NUM) Default(28)

Define Field(#SBINTTOP) Reffld(#STD_NUM) Default(9)
Define Field(#SBINTLEFT) Reffld(#STD_NUM) Default(5)

Define Field(#TOP) Reffld(#STD_NUM)
Define Field(#LEFT) Reffld(#STD_NUM)

Define Field(#HEIGHT) Reffld(#STD_NUM)
Define Field(#WIDTH) Reffld(#STD_NUM)

If Cond('#Initializ *ne Y')
Return
Endif

If Cond(*ATTACH)
Set Com(#Float) Caption('Float Free of Form')
Set Com(#Horizontal #Vertical) Enabled(False)
Else
Set Com(#Float) Caption('(Re)Attach to Form')
Set Com(#Horizontal #Vertical) Enabled(True)
Endif

If Cond('(#CurCount < #VisCount) or (#CurOrient *ne #Orient)')
Change Field(#TOP) To(#SBINTTOP)
Change Field(#LEFT) To(#SBINTLEFT)

Begin_Loop Using(#LOOPCOUNT) To(#VISCOUNT)
Get_Entry Number(#LOOPCOUNT) From_List(#VISLIST)
Set Com(#SB<#LoopCount>) Parent(#GroupBox) Top(#Top) Left(#Left) Width(#SBWidth) Height(#SBHeight) Hint(#VisHint) Popupmenu(#Menu1)
Execute Subroutine(SETBITMAP)
If Cond(*ORIENTVER)
Change Field(#TOP) To('#Top + #SBHeight + 2')
Else
Change Field(#LEFT) To('#Left + #SBWidth + 2')
Endif
End_Loop

If Cond(*ORIENTVER)
Change Field(#WIDTH) To('#SBWidth + (2 * #SBIntLeft)')
Change Field(#HEIGHT) To(' (#VisCount * (#SBHeight + 2)) + (1.5 * #SBIntTop)')
Else
Change Field(#WIDTH) To('(#VisCount * (#SBWidth + 2)) + (1.5 * #SBIntLeft)')
Change Field(#HEIGHT) To(' #SBHeight + (1.5 * #SBIntTop)')
Endif

Set Com(#GroupBox) Height(#Height) Width(#Width)

* if the form is floating, the height of the form is greater than the height of the group_box
* because of the forms blue title bar.

If Cond(*FLOAT)
Change Field(#HEIGHT) To('#Height + 22')
Endif

Set Com(#Com_Owner) Height(#Height) Width(#Width)

Begin_Loop Using(#LOOPCOUNT) To(#VISCOUNT)
Invoke Method(#SB<#LoopCount>.Realize)
End_Loop

Change Field(#CURCOUNT) To(#VISCOUNT)
Change Field(#CURORIENT) To(#ORIENT)
Endif

Endroutine

* Handle too bar item clicked

Evtroutine Handling(#SB<>.Click)
Begin_Loop Using(#LOOPCOUNT) To(#VISCOUNT)
If Cond('#SB<#LoopCount>.Focus = True')
Get_Entry Number(#LOOPCOUNT) From_List(#VISLIST)
Signal Event(TooBarButtonClicked) Withname(#VisName)
Return
Endif
End_Loop
Abort Msgtxt('Unable to determine which toolbar button was clicked or no buttons in group')
Endroutine

* Rout incoming click event from floating instance through

Evtroutine Handling(#FORM.TooBarButtonClicked) Withname(#ID1)
Signal Event(TooBarButtonClicked) Withname(#ID1.Value)
Endroutine

* Handle request to swicth to attached mode

Evtroutine Handling(#FORM.SwitchtoAttachMode)
If Cond(*ATTACH)
Set Com(#GroupBox) Visible(True)
Endif
Endroutine

* Handle request to alter orientation to horizontal

Evtroutine Handling(#HORIZONTAL.Click)
Set Com(#Com_Owner) Orientation(H)
Endroutine

* Handle request to alter orientation to vertiacll

Evtroutine Handling(#VERTICAL.Click)
Set Com(#Com_Owner) Orientation(V)
Endroutine

* Handle request to float or attach

Evtroutine Handling(#FLOAT.Click)
If Cond(*ATTACH)
Set Com(#GroupBox) Visible(False)
Invoke Method(#FORM.uShowForm)
Else
Signal Event(SwitchtoAttachMode)
Endif
Endroutine

* --------------------------------------------------------------------------------
* SetBitMap: To use new bitmaps simply add new statement into the CASE statement
* --------------------------------------------------------------------------------

Subroutine Name(SETBITMAP)
Case Of_Field(#VISBITMAP)
When Value_Is('= VB_CLOSE')
Set Com(#SB<#LoopCount>) Image(#VB_CLOSE)
When Value_Is('= VB_COPY')
Set Com(#SB<#LoopCount>) Image(#VB_COPY)
When Value_Is('= VB_CUT')
Set Com(#SB<#LoopCount>) Image(#VB_CUT)
When Value_Is('= VB_DELETE')
Set Com(#SB<#LoopCount>) Image(#VB_DELETE)
When Value_Is('= VB_ARROWB')
Set Com(#SB<#LoopCount>) Image(#VB_ARROWB)
When Value_Is('= VB_ARROWC')
Set Com(#SB<#LoopCount>) Image(#VB_ARROWC)
When Value_Is('= VB_ARROWB')
Set Com(#SB<#LoopCount>) Image(#VB_ARROWB)
When Value_Is('= VB_ARROWF')
Set Com(#SB<#LoopCount>) Image(#VB_ARROWF)
When Value_Is('= VB_ARROWL')
Set Com(#SB<#LoopCount>) Image(#VB_ARROWL)
When Value_Is('= VB_ARROWR')
Set Com(#SB<#LoopCount>) Image(#VB_ARROWR)
When Value_Is('= VB_BIN')
Set Com(#SB<#LoopCount>) Image(#VB_BIN)
When Value_Is('= VB_CD')
Set Com(#SB<#LoopCount>) Image(#VB_CD)
When Value_Is('= VB_COMPUT')
Set Com(#SB<#LoopCount>) Image(#VB_COMPUT)
When Value_Is('= VB_FLOPPY')
Set Com(#SB<#LoopCount>) Image(#VB_FLOPPY)
When Value_Is('= VB_HRDISK')
Set Com(#SB<#LoopCount>) Image(#VB_HRDISK)
When Value_Is('= VB_LOCK')
Set Com(#SB<#LoopCount>) Image(#VB_LOCK)
When Value_Is('= VB_OPEN')
Set Com(#SB<#LoopCount>) Image(#VB_OPEN)
When Value_Is('= VB_PASTE')
Set Com(#SB<#LoopCount>) Image(#VB_PASTE)
Otherwise
Abort Msgtxt('Attempt to set tool bar button to undefined icon value')
Endcase
Endroutine


End_Com