Code: Select all
;===============================================
;
; file name : clsButtonBar.pbi
; description : ButtonBar Class
; author : Rod Gobby (BorisTheOld)
; copyright : you have my permission to use this code as you wish
; date generated : 2013-10-23 21:00
; configuration : PureBasic 5.20 LTS, x86, Linux & Windows
; notes : no API used
;
;===============================================
;
BeginClass(ButtonBar)
;
;===============================================
;
; Properties
;
BeginClassData
;
; primary properties
;
FieldPointer(prpVirtualTable) ; 16393 : pointer to the class virtual table
Field(exiClassReferenceNumber, typInt32) ; 16447 : the entity number for the class (module, program, package, etc)
Field(exoParent, objGeneric) ; 16086 : reference to an object`s parent
Field(exiChildEntryNumber, typInt32) ; 16484 : entry number of the object in the parent child array (1 based)
;
; private properties
;
FieldDynamicArray(proChild, objGeneric) ; 16448 : reference to a child object
Field(priChildCount, typInt32) ; 16451 : number of child objects attached to a parent object
;
; external properties: read/write
;
Field(exlBorder, typBoolean) ; 16390 : true = show a border around a panel
Field(exiPadding, typInt32) ; 16412 : width of the empty border inside a gui object (pixels)
;
; external properties: read only
;
Field(exiGadgetNumber, typInt32) ; 16402 : assigned by pb using #pb_any
Field(exiActualLeft, typInt32) ; 16417 : actual left position of the gui object (pixels)
Field(exiActualTop, typInt32) ; 16418 : actual top position of the gui object (pixels)
Field(exiActualWidth, typInt32) ; 16419 : actual width of the gui object (pixels)
Field(exiActualHeight, typInt32) ; 16420 : actual height of the gui object (pixels)
;
; external properties: write only
;
Field(exnFirstButton, typDword) ; 11670 : first button to receive focus
Field(exiBackgroundColour, typInt32) ; 14751 : background colour
FieldCallBack(expCBDesign) ; 16080 : callback ptr: design an object
Field(exiMarginTop, typInt32) ; 16128 : top margin outside the gadget (pixels)
Field(exiMarginBottom, typInt32) ; 16129 : bottom margin outside the gadget (pixels)
Field(exiMarginLeft, typInt32) ; 16130 : left margin outside the gadget (pixels)
Field(exiMarginRight, typInt32) ; 16131 : right margin outside the gadget (pixels)
Field(exlResizeAllowed, typBoolean) ; 16405 : true = gui object can be resized
Field(exlShrinkAllowed, typBoolean) ; 16406 : true = gui object can shrink below the base size
Field(exiHorizontalAlignmentMode, typInt32) ; 16408 : fill, start, end, centre
Field(exlHorizontalAlignment, typBoolean) ; 16409 : true = horizontal gui object alignment is allowed
Field(exiVerticalAlignmentMode, typInt32) ; 16410 : fill, start, end, centre
Field(exlVerticalAlignment, typBoolean) ; 16411 : true = vertical gui object alignment is allowed
Field(exiBaseLeft, typInt32) ; 16413 : nominal left position of the gui object (pixels)
Field(exiBaseTop, typInt32) ; 16414 : nominal top position of the gui object (pixels)
Field(exiBaseWidth, typInt32) ; 16415 : nominal width of the gui object (pixels)
Field(exiBaseHeight, typInt32) ; 16416 : nominal height of the gui object (pixels)
Field(exsToolTip, typString) ; 16421 : tooltip text: blank = no tooltip
Field(exiBaseButtonSpacing, typInt32) ; 16678 : nominal spacing between and around each button (pixels)
Field(exiBaseButtonWidth, typInt32) ; 16679 : nominal width to be applied to each button (pixels)
Field(exiBaseButtonHeight, typInt32) ; 16680 : nominal height to be applied to each button (pixels)
Field(exiButtonLayoutMode, typInt32) ; 16685 : Layout mode: edge, start, end, centre, expand, fill, stretch
;
EndClassData
;
;===============================================
;
; Private Declares
;
DeclarePrivateSubroutine(Constructor) (ByVal(Me, strButtonBar))
DeclarePrivateSubroutine(Destructor) (ByVal(Me, strButtonBar))
DeclarePrivateSubroutine(ApplyExternalResizeRules) (ByVal(Me, strButtonBar))
DeclarePrivateSubroutine(setexiButtonLayoutMode) (ByVal(Me, strButtonBar))
DeclarePrivateSubroutine(ApplyInternalResizeRules) (ByVal(Me, strButtonBar))
DeclarePrivateSubroutine(BuildStartLayout) (ByVal(Me, strButtonBar))
DeclarePrivateSubroutine(BuildEndLayout) (ByVal(Me, strButtonBar))
DeclarePrivateSubroutine(BuildCentreLayout) (ByVal(Me, strButtonBar))
DeclarePrivateSubroutine(BuildEdgeLayout) (ByVal(Me, strButtonBar))
DeclarePrivateSubroutine(BuildExpandLayout) (ByVal(Me, strButtonBar))
DeclarePrivateSubroutine(BuildStretchLayout) (ByVal(Me, strButtonBar))
DeclarePrivateSubroutine(BuildFillLayout) (ByVal(Me, strButtonBar))
;
;===============================================
;
; Primary Methods
;
;-----------------------------------------------
;
ExternalFunction(Create, typObject) ()
;
; Create create a class instance
;
Local(Me, strButtonBar)
Me = AllocateMemory(SizeOf(strButtonBar))
If IsObject(Me)
InitializeStructure(Me, strButtonBar)
Me\prpVirtualTable = LabelPtr(VirtualTable)
ClassCall(Constructor) (Me)
EndIf
ProcedureReturn Me
EndFunction
;
;-----------------------------------------------
;
ExternalFunction(Destroy, typObject) (ByVal(Me, strButtonBar))
;
; Destroy destroy a class instance
;
If IsObject(Me)
ClassCall(Destructor) (Me)
ClearStructure(Me, strButtonBar)
FreeMemory(Me)
EndIf
ProcedureReturn Nothing
EndFunction
;
;-----------------------------------------------
;
; exiClassReferenceNumber 16447 : the entity number for the class (module, program, package, etc)
;
ExternalGet(exiClassReferenceNumber, typInt32) (ByVal(Me, strButtonBar))
ProcedureReturn Me\exiClassReferenceNumber
EndGet
;
;-----------------------------------------------
;
; exoParent 16086 : reference to an object`s parent
;
ExternalSet(exoParent) (ByVal(Me, strButtonBar), ByVal(bvoParent, typObject))
Me\exoParent = bvoParent
EndSet
;
;-----------------------------------------------
;
; exiChildEntryNumber 16484 : entry number of the object in the parent child array (1 based)
;
ExternalGet(exiChildEntryNumber, typInt32) (ByVal(Me, strButtonBar))
ProcedureReturn Me\exiChildEntryNumber
EndGet
;
ExternalSet(exiChildEntryNumber) (ByVal(Me, strButtonBar), ByVal(bviChildEntryNumber, typInt32))
Me\exiChildEntryNumber = bviChildEntryNumber
EndSet
;
;===============================================
;
; External Methods
;
;-----------------------------------------------
;
ExternalSubroutine(Events) (ByVal(Me, strButtonBar))
;
; Events process gadget events
;
; not used -- placeholder only
;
EndSubroutine
;
;-----------------------------------------------
;
ExternalSubroutine(Resize) (ByVal(Me, strButtonBar))
;
; Resize process a window resize event
;
;
Local(iLoop, typInt32) ; 15051 : generic loop counter
If IsTrue(Me\exlResizeAllowed)
ClassCall(ApplyExternalResizeRules) (Me) ; resize the buttonbar
ResizeGadget(Me\exiGadgetNumber, Me\exiActualLeft, Me\exiActualTop, Me\exiActualWidth, Me\exiActualHeight)
ClassCall(ApplyInternalResizeRules) (Me) ; resize the buttons
EndIf
EndSubroutine
;
;-----------------------------------------------
;
ExternalSubroutine(Build) (ByVal(Me, strButtonBar))
;
; Build build this object
;
;
Local(oGenericButton, objButton) ; 16116 : generic reference to a button object
Local(iGadgetFlags, typInt32) ; 16403 : composite option flags used when creating a pb gadget
AttachMeToParent
Me\exiActualLeft = Me\exiBaseLeft ; set the initial size values
Me\exiActualTop = Me\exiBaseTop
Me\exiActualWidth = Me\exiBaseWidth
Me\exiActualHeight = Me\exiPadding + Me\exiBaseButtonSpacing + Me\exiBaseButtonHeight + Me\exiBaseButtonSpacing + Me\exiPadding
ClassCall(ApplyExternalResizeRules) (Me)
If IsTrue(Me\exlBorder)
iGadgetFlags = #PB_Container_Flat
Else
iGadgetFlags = 0
EndIf
Me\exiGadgetNumber = ContainerGadget(#PB_Any, Me\exiActualLeft, Me\exiActualTop, Me\exiActualWidth, Me\exiActualHeight, iGadgetFlags)
SetGadgetData(Me\exiGadgetNumber, Me) ; link this buttonbar object to the gadget
GadgetToolTip(Me\exiGadgetNumber, Me\exsToolTip)
SetGadgetColor(Me\exiGadgetNumber, #PB_Gadget_BackColor, Me\exiBackgroundColour)
CallBack(Me\expCBDesign) ; design the buttonbar
CloseGadgetList() ; finish building the buttonbar contents
ClassCall(ApplyInternalResizeRules) (Me) ; position the buttons
oGenericButton = Me\proChild(Me\exnFirstButton) ; create a reference to the primary button
SetObjectFocus(oGenericButton) ; activate the primary button
EndSubroutine
;
;-----------------------------------------------
;
ExternalSubroutine(AttachChild) (ByVal(Me, strButtonBar), ByRef(broChild, objGeneric))
;
; AttachChild attach a child object
;
; broChild 16448 : reference to a child object
;
Increment(Me\priChildCount)
ResizeDynamicArray(Me\proChild, Me\priChildCount) ; add an entry to the child array
Me\proChild(Me\priChildCount) = Ref(broChild) ; store the child object reference
Set(Ref(broChild), exiChildEntryNumber, Me\priChildCount) ; update the child`s entry number
EndSubroutine
;
;-----------------------------------------------
;
ExternalSubroutine(DetachChild) (ByVal(Me, strButtonBar), ByRef(broChild, objGeneric))
;
; DetachChild detach a child object
;
; broChild 16448 : reference to a child object
;
Local(iLoop, typInt32) ; 15051 : generic loop counter
Local(iChildEntryNumber, typInt32) ; 16484 : entry number of the object in the parent child array (1 based)
iChildEntryNumber = Get(Ref(broChild), exiChildEntryNumber) ; extract the child entry number
If (iChildEntryNumber > 0) And (iChildEntryNumber <= Me\priChildCount)
Decrement(Me\priChildCount)
For iLoop = iChildEntryNumber To Me\priChildCount ; adjust the array entries
Me\proChild(iLoop) = Me\proChild(iLoop + 1) ; shift left into the vacated spot
Set(Me\proChild(iLoop), exiChildEntryNumber, iLoop) ; adjust the child`s entry number
Next
ResizeDynamicArray(Me\proChild, Me\priChildCount) ; trim the last entry off the array
EndIf
Set(Ref(broChild), exoParent, Nothing) ; detach the child from this parent object
Set(Ref(broChild), exiChildEntryNumber, 0) ; clear the child`s entry number
EndSubroutine
;
;-----------------------------------------------
;
ExternalSubroutine(ProcessEsc) (ByVal(Me, strButtonBar))
;
; ProcessEsc process a button escape key
;
;
Local(iLoop, typInt32) ; 15051 : generic loop counter
Local(oGenericButton, objButton) ; 16116 : generic reference to a button object
For iLoop = 1 To Me\priChildCount
oGenericButton = Me\proChild(iLoop)
If Get(oGenericButton, exlTrapEscKey) = True
SetObjectFocus(oGenericButton)
PostCustomEvent(oGenericButton, #iEVENT_LEFT_CLICK)
ExitFor
EndIf
Next
EndSubroutine
;
;-----------------------------------------------
;
ExternalSubroutine(ProcessLeft) (ByVal(Me, strButtonBar), ByRef(broGenericButton, objButton))
;
; ProcessLeft process a button left key
;
; broGenericButton 16116 : generic reference to a button object
;
Local(oGenericButton, objButton) ; 16116 : generic reference to a button object
Local(iChildEntryNumber, typInt32) ; 16484 : entry number of the object in the parent child array (1 based)
iChildEntryNumber = Get(Ref(broGenericButton), exiChildEntryNumber) ; extract the button entry number
If iChildEntryNumber > 1
Decrement(iChildEntryNumber) ; shift left to the previous button
Else
iChildEntryNumber = Me\priChildCount ; loop to the last button
EndIf
oGenericButton = Me\proChild(iChildEntryNumber) ; create a reference to the new button
SetObjectFocus(oGenericButton)
EndSubroutine
;
;-----------------------------------------------
;
ExternalSubroutine(ProcessRight) (ByVal(Me, strButtonBar), ByRef(broGenericButton, objButton))
;
; ProcessRight process a button right key
;
; broGenericButton 16116 : generic reference to a button object
;
Local(oGenericButton, objButton) ; 16116 : generic reference to a button object
Local(iChildEntryNumber, typInt32) ; 16484 : entry number of the object in the parent child array (1 based)
iChildEntryNumber = Get(Ref(broGenericButton), exiChildEntryNumber) ; extract the button entry number
If iChildEntryNumber < Me\priChildCount
Increment(iChildEntryNumber) ; shift right to the next button
Else
iChildEntryNumber = 1 ; loop to the first button
EndIf
oGenericButton = Me\proChild(iChildEntryNumber) ; create a reference to the new button
SetObjectFocus(oGenericButton)
EndSubroutine
;
;-----------------------------------------------
;
ExternalSubroutine(ProcessHotkey) (ByVal(Me, strButtonBar), ByVal(bvcHotkeyChar, typChar))
;
; ProcessHotkey process a button hotkey
;
; bvcHotkeyChar 11683 : hot key character: alphanumeric
;
Local(iLoop, typInt32) ; 15051 : generic loop counter
Local(oGenericButton, objButton) ; 16116 : generic reference to a button object
For iLoop = 1 To Me\priChildCount
oGenericButton = Me\proChild(iLoop)
If Get(oGenericButton, excHotkeyChar) = bvcHotkeyChar
SetObjectFocus(oGenericButton)
PostCustomEvent(oGenericButton, #iEVENT_LEFT_CLICK)
ExitFor
EndIf
Next
EndSubroutine
;
;===============================================
;
; Property Methods
;
;-----------------------------------------------
;
; external properties: read/write
;
;--------
;
ExternalGet(exlBorder, typBoolean) (ByVal(Me, strButtonBar))
ProcedureReturn Me\exlBorder
EndGet
;
ExternalSet(exlBorder) (ByVal(Me, strButtonBar), ByVal(bvlBorder, typBoolean))
Me\exlBorder = bvlBorder
EndSet
;
;--------
;
ExternalGet(exiPadding, typInt32) (ByVal(Me, strButtonBar))
ProcedureReturn Me\exiPadding
EndGet
;
ExternalSet(exiPadding) (ByVal(Me, strButtonBar), ByVal(bviPadding, typInt32))
Me\exiPadding = bviPadding
EndSet
;
;-----------------------------------------------
;
; external properties: read only
;
;--------
;
ExternalGet(exiGadgetNumber, typInt32) (ByVal(Me, strButtonBar))
ProcedureReturn Me\exiGadgetNumber
EndGet
;
;--------
;
ExternalGet(exiActualLeft, typInt32) (ByVal(Me, strButtonBar))
ProcedureReturn Me\exiActualLeft
EndGet
;
;--------
;
ExternalGet(exiActualTop, typInt32) (ByVal(Me, strButtonBar))
ProcedureReturn Me\exiActualTop
EndGet
;
;--------
;
ExternalGet(exiActualWidth, typInt32) (ByVal(Me, strButtonBar))
ProcedureReturn Me\exiActualWidth
EndGet
;
;--------
;
ExternalGet(exiActualHeight, typInt32) (ByVal(Me, strButtonBar))
ProcedureReturn Me\exiActualHeight
EndGet
;
;-----------------------------------------------
;
; external properties: write only
;
;--------
;
ExternalSet(exnFirstButton) (ByVal(Me, strButtonBar), ByVal(bvnFirstButton, typDword))
Me\exnFirstButton = bvnFirstButton
EndSet
;
;--------
;
ExternalSet(exiBackgroundColour) (ByVal(Me, strButtonBar), ByVal(bviBackgroundColour, typInt32))
Me\exiBackgroundColour = bviBackgroundColour
EndSet
;
;--------
;
ExternalSet(expCBDesign) (ByVal(Me, strButtonBar), ByVal(bviIndex, typInt32), ByVal(bvpCBDesign, typPointer))
Me\expCBDesign(bviIndex) = bvpCBDesign
EndSet
;
;--------
;
ExternalSet(exiMarginTop) (ByVal(Me, strButtonBar), ByVal(bviMarginTop, typInt32))
Me\exiMarginTop = bviMarginTop
EndSet
;
;--------
;
ExternalSet(exiMarginBottom) (ByVal(Me, strButtonBar), ByVal(bviMarginBottom, typInt32))
Me\exiMarginBottom = bviMarginBottom
EndSet
;
;--------
;
ExternalSet(exiMarginLeft) (ByVal(Me, strButtonBar), ByVal(bviMarginLeft, typInt32))
Me\exiMarginLeft = bviMarginLeft
EndSet
;
;--------
;
ExternalSet(exiMarginRight) (ByVal(Me, strButtonBar), ByVal(bviMarginRight, typInt32))
Me\exiMarginRight = bviMarginRight
EndSet
;
;--------
;
ExternalSet(exlResizeAllowed) (ByVal(Me, strButtonBar), ByVal(bvlResizeAllowed, typBoolean))
Me\exlResizeAllowed = bvlResizeAllowed
EndSet
;
;--------
;
ExternalSet(exlShrinkAllowed) (ByVal(Me, strButtonBar), ByVal(bvlShrinkAllowed, typBoolean))
Me\exlShrinkAllowed = bvlShrinkAllowed
EndSet
;
;--------
;
ExternalSet(exiHorizontalAlignmentMode) (ByVal(Me, strButtonBar), ByVal(bviHorizontalAlignmentMode, typInt32))
Me\exiHorizontalAlignmentMode = bviHorizontalAlignmentMode
EndSet
;
;--------
;
ExternalSet(exlHorizontalAlignment) (ByVal(Me, strButtonBar), ByVal(bvlHorizontalAlignment, typBoolean))
Me\exlHorizontalAlignment = bvlHorizontalAlignment
EndSet
;
;--------
;
ExternalSet(exiVerticalAlignmentMode) (ByVal(Me, strButtonBar), ByVal(bviVerticalAlignmentMode, typInt32))
Me\exiVerticalAlignmentMode = bviVerticalAlignmentMode
EndSet
;
;--------
;
ExternalSet(exlVerticalAlignment) (ByVal(Me, strButtonBar), ByVal(bvlVerticalAlignment, typBoolean))
Me\exlVerticalAlignment = bvlVerticalAlignment
EndSet
;
;--------
;
ExternalSet(exiBaseLeft) (ByVal(Me, strButtonBar), ByVal(bviBaseLeft, typInt32))
Me\exiBaseLeft = bviBaseLeft
EndSet
;
;--------
;
ExternalSet(exiBaseTop) (ByVal(Me, strButtonBar), ByVal(bviBaseTop, typInt32))
Me\exiBaseTop = bviBaseTop
EndSet
;
;--------
;
ExternalSet(exiBaseWidth) (ByVal(Me, strButtonBar), ByVal(bviBaseWidth, typInt32))
Me\exiBaseWidth = bviBaseWidth
EndSet
;
;--------
;
ExternalSet(exiBaseHeight) (ByVal(Me, strButtonBar), ByVal(bviBaseHeight, typInt32))
Me\exiBaseHeight = bviBaseHeight
EndSet
;
;--------
;
ExternalSet(exsToolTip) (ByVal(Me, strButtonBar), ByVal(bvsToolTip, typString))
Me\exsToolTip = bvsToolTip
EndSet
;
;--------
;
ExternalSet(exiBaseButtonSpacing) (ByVal(Me, strButtonBar), ByVal(bviBaseButtonSpacing, typInt32))
Me\exiBaseButtonSpacing = bviBaseButtonSpacing
EndSet
;
;--------
;
ExternalSet(exiBaseButtonWidth) (ByVal(Me, strButtonBar), ByVal(bviBaseButtonWidth, typInt32))
Me\exiBaseButtonWidth = bviBaseButtonWidth
EndSet
;
;--------
;
ExternalSet(exiBaseButtonHeight) (ByVal(Me, strButtonBar), ByVal(bviBaseButtonHeight, typInt32))
Me\exiBaseButtonHeight = bviBaseButtonHeight
EndSet
;
;--------
;
ExternalSet(exiButtonLayoutMode) (ByVal(Me, strButtonBar), ByVal(bviButtonLayoutMode, typInt32))
Me\exiButtonLayoutMode = bviButtonLayoutMode
ClassCall(setexiButtonLayoutMode) (Me)
EndSet
;
;===============================================
;
; Private Methods
;
;-----------------------------------------------
;
PrivateSubroutine(Constructor) (ByVal(Me, strButtonBar))
;
; Constructor class constructor
;
Me\exiClassReferenceNumber = #iCLASS_REF_BUTTONBAR
Me\exiBackgroundColour = #iBUTTONBAR_COLOUR
Me\exlResizeAllowed = True
Me\exlHorizontalAlignment = True
Me\exiHorizontalAlignmentMode = #iGUI_ALIGN_FILL
Me\exlVerticalAlignment = True
Me\exiVerticalAlignmentMode = #iGUI_ALIGN_END
Me\exiBaseButtonSpacing = #iBUTTON_SPACING
Me\exiBaseButtonWidth = #iBUTTON_WIDTH
Me\exiBaseButtonHeight = #iBUTTON_HEIGHT
Me\exiButtonLayoutMode = #iGUI_LAYOUT_START
Me\exnFirstButton = 1
EndSubroutine
;
;-----------------------------------------------
;
PrivateSubroutine(Destructor) (ByVal(Me, strButtonBar))
;
; Destructor class destructor
;
DestroyMyGadget
DetachMeFromParent
DetachMyChildren
EndSubroutine
;
;-----------------------------------------------
;
PrivateSubroutine(ApplyExternalResizeRules) (ByVal(Me, strButtonBar))
;
; ApplyExternalResizeRules apply the external resize rules
;
;
Local(oGenericContainer, objContainer) ; 16077 : generic reference to a container object
Local(iParentWidth, typInt32) ; 16458 : parent container width (pixels)
Local(iParentHeight, typInt32) ; 16459 : parent container height (pixels)
Local(iParentPadding, typInt32) ; 16460 : parent container padding (pixels)
;
; Note:
;
; 1) If no horizontal alignment, then Me\exiActualLeft and Me\exiActualWidth remain unchanged
;
; 2) If no vertical alignment, then Me\exiActualTop and Me\exiActualHeight remain unchanged
;
oGenericContainer = Me\exoParent ; reference the parent container
iParentWidth = Get(oGenericContainer, exiActualWidth)
iParentHeight = Get(oGenericContainer, exiActualHeight)
iParentPadding = Get(oGenericContainer, exiPadding)
If IsTrue(Me\exlHorizontalAlignment)
Select Me\exiHorizontalAlignmentMode
Case #iGUI_ALIGN_FILL
Me\exiActualLeft = iParentPadding + Me\exiMarginLeft
Me\exiActualWidth = iParentWidth - iParentPadding - Me\exiMarginLeft - Me\exiMarginRight - iParentPadding
Case #iGUI_ALIGN_START
Me\exiActualLeft = iParentPadding + Me\exiMarginLeft
Case #iGUI_ALIGN_END
Me\exiActualLeft = iParentWidth - iParentPadding - Me\exiMarginRight - Me\exiActualWidth
Case #iGUI_ALIGN_CENTRE
Me\exiActualLeft = (iParentWidth - Me\exiActualWidth) / 2
EndSelect
EndIf
If IsTrue(Me\exlVerticalAlignment)
Select Me\exiVerticalAlignmentMode
Case #iGUI_ALIGN_FILL
Me\exiActualTop = iParentPadding + Me\exiMarginTop
Me\exiActualHeight = iParentHeight - iParentPadding - Me\exiMarginTop - Me\exiMarginBottom - iParentPadding
Case #iGUI_ALIGN_START
Me\exiActualTop = iParentPadding + Me\exiMarginTop
Case #iGUI_ALIGN_END
Me\exiActualTop = iParentHeight - iParentPadding - Me\exiMarginBottom - Me\exiActualHeight
Case #iGUI_ALIGN_CENTRE
Me\exiActualTop = (iParentHeight - Me\exiActualHeight) / 2
EndSelect
EndIf
EndSubroutine
;
;-----------------------------------------------
;
PrivateSubroutine(setexiButtonLayoutMode) (ByVal(Me, strButtonBar))
;
; update the buttonbar to match the new layout mode
;
ClassCall(ApplyInternalResizeRules) (Me)
EndSubroutine
;
;-----------------------------------------------
;
PrivateSubroutine(ApplyInternalResizeRules) (ByVal(Me, strButtonBar))
;
; ApplyInternalResizeRules apply the internal resize rules
;
;
Select Me\exiButtonLayoutMode
Case #iGUI_LAYOUT_START
ClassCall(BuildStartLayout) (Me)
Case #iGUI_LAYOUT_END
ClassCall(BuildEndLayout) (Me)
Case #iGUI_LAYOUT_CENTRE
ClassCall(BuildCentreLayout) (Me)
Case #iGUI_LAYOUT_EDGE
ClassCall(BuildEdgeLayout) (Me)
Case #iGUI_LAYOUT_EXPAND
ClassCall(BuildExpandLayout) (Me)
Case #iGUI_LAYOUT_STRETCH
ClassCall(BuildStretchLayout) (Me)
Case #iGUI_LAYOUT_FILL
ClassCall(BuildFillLayout) (Me)
CaseElse
ClassCall(BuildStartLayout) (Me)
EndSelect
EndSubroutine
;
;-----------------------------------------------
;
PrivateSubroutine(BuildStartLayout) (ByVal(Me, strButtonBar))
;
; BuildStartLayout build buttons: layout mode = start
;
;
Local(iLoop, typInt32) ; 15051 : generic loop counter
Local(oGenericButton, objButton) ; 16116 : generic reference to a button object
Local(iBaseLeft, typInt32) ; 16413 : nominal left position of the gui object (pixels)
Local(iBaseTop, typInt32) ; 16414 : nominal top position of the gui object (pixels)
Local(iBaseWidth, typInt32) ; 16415 : nominal width of the gui object (pixels)
Local(iBaseHeight, typInt32) ; 16416 : nominal height of the gui object (pixels)
iBaseLeft = 0
iBaseTop = Me\exiBaseButtonSpacing
iBaseWidth = Me\exiBaseButtonWidth
iBaseHeight = Me\exiBaseButtonHeight
For iLoop = 1 To Me\priChildCount ; resize all child objects
oGenericButton = Me\proChild(iLoop)
Set(oGenericButton, exiBaseLeft, iBaseLeft)
Set(oGenericButton, exiBaseTop, iBaseTop)
Set(oGenericButton, exiBaseWidth, iBaseWidth)
Set(oGenericButton, exiBaseHeight, iBaseHeight)
ObjectCall(oGenericButton, Resize) ()
iBaseLeft = iBaseLeft + iBaseWidth + Me\exiBaseButtonSpacing ; set location of the next button
Next
EndSubroutine
;
;-----------------------------------------------
;
PrivateSubroutine(BuildEndLayout) (ByVal(Me, strButtonBar))
;
; BuildEndLayout build buttons: layout mode = end
;
;
Local(iLoop, typInt32) ; 15051 : generic loop counter
Local(oGenericButton, objButton) ; 16116 : generic reference to a button object
Local(iBaseLeft, typInt32) ; 16413 : nominal left position of the gui object (pixels)
Local(iBaseTop, typInt32) ; 16414 : nominal top position of the gui object (pixels)
Local(iBaseWidth, typInt32) ; 16415 : nominal width of the gui object (pixels)
Local(iBaseHeight, typInt32) ; 16416 : nominal height of the gui object (pixels)
iBaseLeft = Me\exiActualWidth - Me\exiBaseButtonWidth
iBaseTop = Me\exiBaseButtonSpacing
iBaseWidth = Me\exiBaseButtonWidth
iBaseHeight = Me\exiBaseButtonHeight
For iLoop = Me\priChildCount To 1 Step -1 ; resize all child objects
oGenericButton = Me\proChild(iLoop)
Set(oGenericButton, exiBaseLeft, iBaseLeft)
Set(oGenericButton, exiBaseTop, iBaseTop)
Set(oGenericButton, exiBaseWidth, iBaseWidth)
Set(oGenericButton, exiBaseHeight, iBaseHeight)
ObjectCall(oGenericButton, Resize) ()
iBaseLeft = iBaseLeft - iBaseWidth - Me\exiBaseButtonSpacing ; set location of the previous button
Next
EndSubroutine
;
;-----------------------------------------------
;
PrivateSubroutine(BuildCentreLayout) (ByVal(Me, strButtonBar))
;
; BuildCentreLayout build buttons: layout mode = centre
;
;
Local(iLoop, typInt32) ; 15051 : generic loop counter
Local(oGenericButton, objButton) ; 16116 : generic reference to a button object
Local(iBaseLeft, typInt32) ; 16413 : nominal left position of the gui object (pixels)
Local(iBaseTop, typInt32) ; 16414 : nominal top position of the gui object (pixels)
Local(iBaseWidth, typInt32) ; 16415 : nominal width of the gui object (pixels)
Local(iBaseHeight, typInt32) ; 16416 : nominal height of the gui object (pixels)
iBaseLeft = (Me\exiActualWidth - (Me\exiBaseButtonWidth + Me\exiBaseButtonSpacing) * Me\priChildCount - Me\exiBaseButtonSpacing) / 2
iBaseTop = Me\exiBaseButtonSpacing
iBaseWidth = Me\exiBaseButtonWidth
iBaseHeight = Me\exiBaseButtonHeight
For iLoop = 1 To Me\priChildCount ; resize all child objects
oGenericButton = Me\proChild(iLoop)
Set(oGenericButton, exiBaseLeft, iBaseLeft)
Set(oGenericButton, exiBaseTop, iBaseTop)
Set(oGenericButton, exiBaseWidth, iBaseWidth)
Set(oGenericButton, exiBaseHeight, iBaseHeight)
ObjectCall(oGenericButton, Resize) ()
iBaseLeft = iBaseLeft + iBaseWidth + Me\exiBaseButtonSpacing ; set location of the next button
Next
EndSubroutine
;
;-----------------------------------------------
;
PrivateSubroutine(BuildEdgeLayout) (ByVal(Me, strButtonBar))
;
; BuildEdgeLayout build buttons: layout mode = edge
;
;
Local(iLoop, typInt32) ; 15051 : generic loop counter
Local(oGenericButton, objButton) ; 16116 : generic reference to a button object
Local(iBaseLeft, typInt32) ; 16413 : nominal left position of the gui object (pixels)
Local(iBaseTop, typInt32) ; 16414 : nominal top position of the gui object (pixels)
Local(iBaseWidth, typInt32) ; 16415 : nominal width of the gui object (pixels)
Local(iBaseHeight, typInt32) ; 16416 : nominal height of the gui object (pixels)
Local(iBaseButtonSpacing, typInt32) ; 16678 : nominal spacing between and around each button (pixels)
Local(iUnusedWidth, typInt32) ; 16694 : unused width in resizing operations (pixels)
iUnusedWidth = Me\exiActualWidth - (Me\exiBaseButtonWidth * Me\priChildCount) ; total amount of available spacing
iBaseButtonSpacing = iUnusedWidth / (Me\priChildCount - 1) ; nominal spacing between buttons
iUnusedWidth = iUnusedWidth % (Me\priChildCount - 1) ; unused width to be allocated to spaces
iBaseLeft = 0
iBaseTop = Me\exiBaseButtonSpacing
iBaseWidth = Me\exiBaseButtonWidth
iBaseHeight = Me\exiBaseButtonHeight
For iLoop = 1 To Me\priChildCount ; resize all child objects
oGenericButton = Me\proChild(iLoop)
Set(oGenericButton, exiBaseLeft, iBaseLeft)
Set(oGenericButton, exiBaseTop, iBaseTop)
Set(oGenericButton, exiBaseWidth, iBaseWidth)
Set(oGenericButton, exiBaseHeight, iBaseHeight)
ObjectCall(oGenericButton, Resize) ()
iBaseLeft = iBaseLeft + iBaseWidth + iBaseButtonSpacing ; set the nominal location of the next button
If iUnusedWidth > 0
Increment(iBaseLeft) ; assign an extra pixel to the spacing
Decrement(iUnusedWidth) ; reduce the number of available spacing pixels
EndIf
Next
EndSubroutine
;
;-----------------------------------------------
;
PrivateSubroutine(BuildExpandLayout) (ByVal(Me, strButtonBar))
;
; BuildExpandLayout build buttons: layout mode = expand
;
;
Local(iLoop, typInt32) ; 15051 : generic loop counter
Local(oGenericButton, objButton) ; 16116 : generic reference to a button object
Local(iBaseLeft, typInt32) ; 16413 : nominal left position of the gui object (pixels)
Local(iBaseTop, typInt32) ; 16414 : nominal top position of the gui object (pixels)
Local(iBaseWidth, typInt32) ; 16415 : nominal width of the gui object (pixels)
Local(iBaseHeight, typInt32) ; 16416 : nominal height of the gui object (pixels)
Local(iBaseButtonSpacing, typInt32) ; 16678 : nominal spacing between and around each button (pixels)
Local(iUnusedWidth, typInt32) ; 16694 : unused width in resizing operations (pixels)
iUnusedWidth = Me\exiActualWidth - (Me\exiBaseButtonWidth * Me\priChildCount) ; total amount of available spacing
iBaseButtonSpacing = iUnusedWidth / (Me\priChildCount + 1) ; nominal spacing between buttons
iUnusedWidth = iUnusedWidth % (Me\priChildCount + 1) ; unused width to be allocated to spaces
iBaseLeft = iBaseButtonSpacing
iBaseTop = Me\exiBaseButtonSpacing
iBaseWidth = Me\exiBaseButtonWidth
iBaseHeight = Me\exiBaseButtonHeight
For iLoop = 1 To Me\priChildCount ; resize all child objects
oGenericButton = Me\proChild(iLoop)
Set(oGenericButton, exiBaseLeft, iBaseLeft)
Set(oGenericButton, exiBaseTop, iBaseTop)
Set(oGenericButton, exiBaseWidth, iBaseWidth)
Set(oGenericButton, exiBaseHeight, iBaseHeight)
ObjectCall(oGenericButton, Resize) ()
iBaseLeft = iBaseLeft + iBaseWidth + iBaseButtonSpacing ; set the nominal location of the next button
If iUnusedWidth > 0
Increment(iBaseLeft) ; assign an extra pixel to the spacing
Decrement(iUnusedWidth) ; reduce the number of available spacing pixels
EndIf
Next
EndSubroutine
;
;-----------------------------------------------
;
PrivateSubroutine(BuildStretchLayout) (ByVal(Me, strButtonBar))
;
; BuildStretchLayout build buttons: layout mode = stretch
;
;
Local(iLoop, typInt32) ; 15051 : generic loop counter
Local(oGenericButton, objButton) ; 16116 : generic reference to a button object
Local(iBaseLeft, typInt32) ; 16413 : nominal left position of the gui object (pixels)
Local(iBaseTop, typInt32) ; 16414 : nominal top position of the gui object (pixels)
Local(iBaseWidth, typInt32) ; 16415 : nominal width of the gui object (pixels)
Local(iBaseHeight, typInt32) ; 16416 : nominal height of the gui object (pixels)
Local(iBaseButtonWidth, typInt32) ; 16679 : nominal width to be applied to each button (pixels)
Local(iUnusedWidth, typInt32) ; 16694 : unused width in resizing operations (pixels)
iUnusedWidth = Me\exiActualWidth - (Me\exiBaseButtonSpacing * (Me\priChildCount + 1)) ; total amount of available button width
iBaseButtonWidth = iUnusedWidth / Me\priChildCount ; nominal button width
iUnusedWidth = iUnusedWidth % Me\priChildCount ; unused width to be allocated to buttons
iBaseLeft = Me\exiBaseButtonSpacing
iBaseTop = Me\exiBaseButtonSpacing
iBaseWidth = iBaseButtonWidth
iBaseHeight = Me\exiBaseButtonHeight
For iLoop = 1 To Me\priChildCount ; resize all child objects
oGenericButton = Me\proChild(iLoop)
Set(oGenericButton, exiBaseLeft, iBaseLeft)
Set(oGenericButton, exiBaseTop, iBaseTop)
Set(oGenericButton, exiBaseWidth, iBaseWidth)
Set(oGenericButton, exiBaseHeight, iBaseHeight)
ObjectCall(oGenericButton, Resize) ()
iBaseLeft = iBaseLeft + iBaseWidth + Me\exiBaseButtonSpacing ; set the location of the next button
iBaseWidth = iBaseButtonWidth ; set the nominal width of the next button
If iUnusedWidth > 0
Increment(iBaseWidth) ; assign an extra pixel to the button width
Decrement(iUnusedWidth) ; reduce the number of available spacing pixels
EndIf
Next
EndSubroutine
;
;-----------------------------------------------
;
PrivateSubroutine(BuildFillLayout) (ByVal(Me, strButtonBar))
;
; BuildFillLayout build buttons: layout mode = fill
;
;
Local(iLoop, typInt32) ; 15051 : generic loop counter
Local(oGenericButton, objButton) ; 16116 : generic reference to a button object
Local(iBaseLeft, typInt32) ; 16413 : nominal left position of the gui object (pixels)
Local(iBaseTop, typInt32) ; 16414 : nominal top position of the gui object (pixels)
Local(iBaseWidth, typInt32) ; 16415 : nominal width of the gui object (pixels)
Local(iBaseHeight, typInt32) ; 16416 : nominal height of the gui object (pixels)
Local(iBaseButtonWidth, typInt32) ; 16679 : nominal width to be applied to each button (pixels)
Local(iUnusedWidth, typInt32) ; 16694 : unused width in resizing operations (pixels)
iUnusedWidth = Me\exiActualWidth ; total amount of available button width
iBaseButtonWidth = iUnusedWidth / Me\priChildCount ; nominal button width
iUnusedWidth = iUnusedWidth % Me\priChildCount ; unused width to be allocated to buttons
iBaseLeft = 0
iBaseTop = Me\exiBaseButtonSpacing
iBaseWidth = iBaseButtonWidth
iBaseHeight = Me\exiBaseButtonHeight
For iLoop = 1 To Me\priChildCount ; resize all child objects
oGenericButton = Me\proChild(iLoop)
Set(oGenericButton, exiBaseLeft, iBaseLeft)
Set(oGenericButton, exiBaseTop, iBaseTop)
Set(oGenericButton, exiBaseWidth, iBaseWidth)
Set(oGenericButton, exiBaseHeight, iBaseHeight)
ObjectCall(oGenericButton, Resize) ()
iBaseLeft = iBaseLeft + iBaseWidth ; set the location of the next button
iBaseWidth = iBaseButtonWidth ; set the nominal width of the next button
If iUnusedWidth > 0
Increment(iBaseWidth) ; assign an extra pixel to the button width
Decrement(iUnusedWidth) ; reduce the number of available spacing pixels
EndIf
Next
EndSubroutine
;
;===============================================
;
; Virtual Table
;
BeginVirtualTable
;
; primary methods
;
VirtualFunc(Destroy)
VirtualGetx(exiClassReferenceNumber)
VirtualSetx(exoParent)
VirtualGetx(exiChildEntryNumber)
VirtualSetx(exiChildEntryNumber)
;
; external methods
;
VirtualSubr(Events)
VirtualSubr(Resize)
VirtualSubr(Build)
VirtualSubr(AttachChild)
VirtualSubr(DetachChild)
VirtualSubr(ProcessEsc)
VirtualSubr(ProcessLeft)
VirtualSubr(ProcessRight)
VirtualSubr(ProcessHotkey)
;
; external properties: read/write
;
VirtualGetx(exlBorder)
VirtualSetx(exlBorder)
VirtualGetx(exiPadding)
VirtualSetx(exiPadding)
;
; external properties: read only
;
VirtualGetx(exiGadgetNumber)
VirtualGetx(exiActualLeft)
VirtualGetx(exiActualTop)
VirtualGetx(exiActualWidth)
VirtualGetx(exiActualHeight)
;
; external properties: write only
;
VirtualSetx(exnFirstButton)
VirtualSetx(exiBackgroundColour)
VirtualSetx(expCBDesign)
VirtualSetx(exiMarginTop)
VirtualSetx(exiMarginBottom)
VirtualSetx(exiMarginLeft)
VirtualSetx(exiMarginRight)
VirtualSetx(exlResizeAllowed)
VirtualSetx(exlShrinkAllowed)
VirtualSetx(exiHorizontalAlignmentMode)
VirtualSetx(exlHorizontalAlignment)
VirtualSetx(exiVerticalAlignmentMode)
VirtualSetx(exlVerticalAlignment)
VirtualSetx(exiBaseLeft)
VirtualSetx(exiBaseTop)
VirtualSetx(exiBaseWidth)
VirtualSetx(exiBaseHeight)
VirtualSetx(exsToolTip)
VirtualSetx(exiBaseButtonSpacing)
VirtualSetx(exiBaseButtonWidth)
VirtualSetx(exiBaseButtonHeight)
VirtualSetx(exiButtonLayoutMode)
;
EndVirtualTable
;
;===============================================
;
EndClass
;
;===============================================
; end of : clsButtonBar.bi
;===============================================