/*
Copyright (C) 2015 Runtime Revolution Ltd.

This file is part of LiveCode.

LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.

LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with LiveCode.  If not see <http://www.gnu.org/licenses/>.  */

/* A segmented control. A segmented control is a horizontal control that is made up of multiple segments, where each segment functions as a discrete button.

Name: segmentStyle
Type: property
Syntax: set the segmentStyle of <widget> to <pStyle>
Syntax: get the segmentStyle of <widget>

Summary: The style of the control.

Parameters:
pStyle(enum): The style of the control.
-"segment": The widget displays as a segmented control
-"bar": The widget displays as a button bar

Description:
The style property of the control (segmented control or bar button).

Name: multiSelect
Type: property
Syntax: set the multiSelect of <widget> to <pCanMultiSelect>
Syntax: get the multiSelect of <widget>

Summary: Whether the control can have multiple segments selected

Parameters:
pCanMultiSelect(boolean):

Description:
The multiSelect property of the control.

Name: segmentNames
Type: property
Syntax: set the segmentNames of <widget> to <pNames>
Syntax: get the segmentNames of <widget>
Summary: Sets the names of the segments.

Parameters:
pNames(string): A comma-delimited list of names for the segments.

Description:
Sets the names of each segment in the control.

Name: segmentLabels
Type: property
Syntax: set the segmentLabels of <widget> to <pLabels>
Syntax: get the segmentLabels of <widget>

Summary: Sets the labels of the segments.

Parameters:
pLabels: A comma-delimited list of labels for the segments.

Description:
Sets the labels of each segment in the control.

Name: segmentIcons
Type: property
Syntax: set the segmentIcons of <widget> to <pIcons>
Syntax: get the segmentIcons of <widget>

Summary: Sets the icons of the segments.

Parameters:
pIcons: A comma-delimited list of codepoints, which display as fontawesome icons for the segments

Description:
Sets the icons of each segment in the control.

Name: selectedIcons
Type: property
Syntax: set the selectedIcons of <widget> to <pSelectedIcons>
Syntax: get the selectedIcons of <widget>

Summary: Sets the selected icons of the segments.

Parameters:
pSelectedIcons: A comma-delimited list of codepoints, which display as fontawesome icons for the selected segments.

Description:
Sets the selected icons of each segment in the control.

Name: segmentDisplay
Type: property
Syntax: set the segmentDisplay of <widget> to <pSegmentDisplay>
Syntax: get the segmentDisplay of <widget>

Summary: Sets the segment display style.

Parameters:
pSegmentDisplay(enum): The style of the segment display.
-"icon": Show the chosen fontawesome icons
-"label": Show the chosen labels

Description:
Sets the segment display style of the control to either icon or label.

Name: segmentMinWidth
Type: property
Syntax: set the segmentMinWidth of <widget> to <pMinWidths>
Syntax: get the segmentMinWidth of <widget>

Summary: Sets the minimum widths of the segments.

Parameters:
pMinWidths: A comma-delimited list of numbers.

Description:
Sets the minimum width of each segment in the control.

Name: selectedSegment
Type: property
Syntax: set the selectedSegment of <widget> to <pSelectedSegments>
Syntax: get the selectedSegment of <widget>

Summary: Sets the selected segment.

Parameters:
pSelectedSegments: A comma-delimited list of the numbers of the selected segment.

Description:
Sets the selected segments of the control.
*/


-- declaring extension as widget, followed by identifier
widget com.livecode.widget.segmented
--

-- dependency declarations
use com.livecode.canvas
use com.livecode.widget
use com.livecode.engine
use com.livecode.library.iconSVG

-- metadata
metadata title is "Segmented"
metadata author is "LiveCode"
metadata version is "1.0.0"
metadata svgicon is "M72.6,0H7.7C3.4,0,0,3.4,0,7.7v14c0,4.2,3.4,7.7,7.7,7.7h64.9c4.2,0,7.7-3.4,7.7-7.7v-14C80.2,3.4,76.8,0,72.6,0z M7.8,13.5h8v2.3h-8V13.5z M19.7,20.6h-12v-2.3h12V20.6z M19.7,11h-12V8.8h12V11z M27.8,25.5h-1V3.8h1V25.5z M46.1,20.6h-12v-2.3h12V20.6zM36.1,15.7v-2.3h8v2.3H36.1z M46.1,11h-12V8.8h12V11z M54.4,25.5h-1V3.8h1V25.5z M72.7,20.6h-12v-2.3h12V20.6z M72.7,15.7h-8v-2.3h8V15.7z M72.7,11h-12V8.8h12V11z"

-- property declarations
property segmentStyle 		get mStyle				set setStyle
property multiSelect		get mMultiSelect		set setMultiSelect		

property segmentNames		get getSegmentNames		set setSegmentNames
property segmentLabels		get getSegmentLabels	set setSegmentLabels
property segmentIcons		get getSegmentIcons		set setSegmentIcons	
property selectedIcons		get getSelectedIcons	set setSelectedIcons

property segmentDisplay		get mSegmentDisplay		set setSegmentDisplay
property segmentMinWidth	get getSegmentMinWidth	set setSegmentMinWidth
property selectedSegment	get getSelectedSegment	set setSelectedSegment	

property showFrameBorder	get mShowFrameBorder	set setShowFrameBorder
--

-- property metadata
metadata segmentStyle.editor 		is "com.livecode.pi.enum"
metadata segmentStyle.options 		is "segment,bar"
metadata segmentStyle.default		is "segment"
metadata multiSelect.editor			is "com.livecode.pi.boolean"
metadata multiSelect.default		is "false"

metadata segmentNames.editor		is "com.livecode.pi.string"
metadata segmentNames.default		is "segment1,segment2,segment3"
metadata segmentLabels.editor 		is "com.livecode.pi.string"
metadata segmentLabels.default		is "Title,Title,Title"
metadata segmentIcons.editor		is "com.livecode.pi.string"
metadata segmentIcons.default		is "f036,f037,f038"
metadata selectedIcons.editor		is "com.livecode.pi.string"
metadata selectedIcons.default		is "f036,f037,f038"

metadata segmentDisplay.editor		is "com.livecode.pi.enum"
metadata segmentDisplay.options		is "text,icon"
metadata segmentDisplay.default		is "text"
metadata segmentMinWidth.editor		is "com.livecode.pi.string"
metadata segmentMinWidth.default 	is "30,30,30"
metadata selectedSegment.editor		is "com.livecode.pi.string"
metadata selectedSegment.default	is "1"
--

-- private instance variables
--properties
private variable mStyle				as String
private variable mMultiSelect		as Boolean

private variable mSegmentNames		as List
private variable mSegmentLabels		as List
private variable mSegmentIcons		as List
private variable mSelectedIcons		as List

private variable mSegmentDisplay	as String
private variable mSegmentMinWidth	as List
private variable mSelectedSegments	as List

--variables
private variable mGeometryIsChanged	as Boolean
private variable mNumSegments		as Integer
private variable mLeft				as Real

private variable mPerimeter			as Path
private variable mLines				as List			-- list of line paths
private variable mRadius			as Real

private variable mShowFrameBorder	as Boolean
--

-- constants
constant kIconSize is 16
constant kTextSize is 13
constant kIconPaddingRatio is 0.2
--

public handler OnSave(out rProperties as Array)
	put the empty array into rProperties
	
	put mStyle				into rProperties["style"]
	put mMultiSelect		into rProperties["multiSelect"]
	put mSegmentNames		into rProperties["segmentNames"]
	put mSegmentLabels		into rProperties["segmentLabels"]
	put mSegmentIcons		into rProperties["segmentIcons"]
	put mSelectedIcons		into rProperties["selectedIcons"]
	put mSegmentDisplay		into rProperties["segmentDisplay"]
	put mSegmentMinWidth	into rProperties["segmentMinWidth"]	
	put mSelectedSegments	into rProperties["selectedSegment"]
	put mShowFrameBorder	into rProperties["showFrameBorder"]
	
	return rProperties
end handler

public handler OnLoad(in pProperties as Array)
	
	put pProperties["style"]			into mStyle
	put pProperties["multiSelect"]		into mMultiSelect
	put pProperties["segmentNames"]		into mSegmentNames
	put pProperties["segmentLabels"]	into mSegmentLabels
	put pProperties["segmentIcons"]		into mSegmentIcons
	put pProperties["selectedIcons"]	into mSelectedIcons
	put pProperties["segmentDisplay"]	into mSegmentDisplay
	put pProperties["segmentMinWidth"]	into mSegmentMinWidth
	put pProperties["selectedSegment"]	into mSelectedSegments
	put pProperties["showFrameBorder"]	into mShowFrameBorder
	
end handler

public handler OnCreate()
	
	-- properties
	put "segment" into mStyle
	put false into mMultiSelect
	
	put ["segment1","segment2","segment3"] into mSegmentNames
	put ["Title","Title","Title"] into mSegmentLabels
	put ["align left","align center","align right"] into mSegmentIcons
	put ["align left","align center","align right"] into mSelectedIcons
	
	put "icon" into mSegmentDisplay
	put [30,30,30] into mSegmentMinWidth
	put [1] into mSelectedSegments
	--
	
	-- variables
	put true into mGeometryIsChanged
	put (the number of elements in mSegmentNames) into mNumSegments
	put 0 into mLeft
	put the empty path into mPerimeter
	put the empty list into mLines
	put 0 into mRadius
	--
	put false into mShowFrameBorder
	
end handler

public handler OnPaint()

	put (the number of elements in mSegmentNames) into mNumSegments
	
	if mGeometryIsChanged then
		updateProperties()	
		-- update mPerimeter and mLines variables if the geometry has changed
		put (the trunc of my height)/5 into mRadius
		updatePerimeter()
		updateLines()
	end if
	
	drawSegments()
	
	-- draw the lines to separate the segments
	set the antialias of this canvas to false
	set the stroke width of this canvas to 1
	set the paint of this canvas to fetchPaint("lines", "yosemite")
	
	variable tLine
	repeat for each element tLine in mLines
		stroke tLine on this canvas
	end repeat
	
	set the antialias of this canvas to true
	--
	
	-- draw the perimeter of the control
	if mShowFrameBorder then
		set the paint of this canvas to fetchPaint("border", "yosemite")
		set the stroke width of this canvas to 1
		stroke mPerimeter on this canvas
	end if
	--
	
	put false into mGeometryIsChanged
end handler

public handler OnGeometryChanged()
	put true into mGeometryIsChanged
end handler

public handler OnClick()
	
	variable tX as Integer
	variable tLabel as String
	variable tSegment
	variable tCount as Integer
	 
	if mMultiSelect is false then
		-- if cannot multiselect, then need to select the clicked-on segment and deselect the currently selected segment
		-- if the clicked-on segment is already selected, then do nothing
	
		if the click position is not within fetchBounds(element 1 of mSelectedSegments) then
			repeat with tX from 1 up to mNumSegments
			
				if the click position is within fetchBounds(tX) then
					
					put the empty list into mSelectedSegments
					push tX onto back of mSelectedSegments
					
					put element tX of mSegmentNames into tLabel
					post "segmentSelected" with [tLabel]
				end if
				
			end repeat	
		end if
		
	else
		-- if can multiselect, then select the clicked-on segment if it is unselected or unselect if its selected
		repeat with tX from 1 up to mNumSegments
			if the click position is within fetchBounds(tX) then
		
				variable tIsIn
				put tX is in mSelectedSegments into tIsIn
		
				if tIsIn then
					put 1 into tCount
					variable tElement
					repeat for each element tElement in mSelectedSegments
						if tElement = tX then
							exit repeat
						end if
						add 1 to tCount
					end repeat
					
					delete element tCount of mSelectedSegments
					put element tX of mSegmentNames into tLabel
					post "segmentUnselected" with [tLabel]
				else
					put element tX of mSegmentNames into tLabel
					post "segmentSelected" with [tLabel]
					push tX onto back of mSelectedSegments
						
				end if
			end if
		end repeat
	end if
	
	redraw all
end handler

private handler drawSegments() returns nothing

	variable tX as Integer
	variable tLabel as String
	variable tWidth as Real
	variable tIsIn as Boolean
	
	put 0 into mLeft
	set the font of this canvas to fetchFont()
	
	repeat with tX from 1 up to mNumSegments
		put fetchWidth(tX) into tWidth
		put tX is in mSelectedSegments into tIsIn
		
		if tIsIn then
			-- set the paint of the background of the selected segment(s)
			set the paint of this canvas to fetchPaint("selected background", "yosemite")
		else
			set the paint of this canvas to fetchPaint("background", "yosemite")
		end if	
		
		variable tSegmentRect as Rectangle
		put rectangle [mLeft, 0, mLeft+tWidth, my height] into tSegmentRect
		if tX = 1 then
			-- rounded rectangle segment
			fill rounded rectangle path of tSegmentRect with radius mRadius on this canvas
			fill rectangle path of rectangle [mLeft+tWidth, 0, mLeft+tWidth*0.5, my height] on this canvas
				
		else if tX = mNumSegments then
			-- rounded rectangle segment
			fill rounded rectangle path of tSegmentRect with radius mRadius on this canvas
			fill rectangle path of rectangle [mLeft, 0, mLeft+tWidth*0.5, my height] on this canvas
				
		else
			fill rectangle path of tSegmentRect on this canvas
		end if

		if tIsIn then
			-- set the paint of the label(s) in the selected segment(s)
			set the paint of this canvas to fetchPaint("selected label", "yosemite")
		else
			set the paint of this canvas to fetchPaint("label", "yosemite")
		end if	
			

		variable tIconPath as Path
		variable tIconRect as Rectangle
		put rectangle [mLeft + tWidth * kIconPaddingRatio, tWidth * kIconPaddingRatio, mLeft + tWidth * (1 - kIconPaddingRatio), my height - (tWidth * kIconPaddingRatio)] into tIconRect
		if mSegmentDisplay is "icon" then
			if tIsIn then
				put path iconSVGPathFromName(element tX of mSelectedIcons) into tIconPath
			else
				put path iconSVGPathFromName(element tX of mSegmentIcons) into tIconPath
			end if
			setIconPath(tIconRect, tIconPath)
			fill tIconPath on this canvas
		else
			put (element tX of mSegmentLabels) into tLabel
			fill text tLabel at center of fetchLabelRect(tWidth) on this canvas
		end if

		add tWidth to mLeft
	end repeat
	
end handler

private handler setIconPath(in pTargetRect as Rectangle, inout xPath as Path)

	// Scale the icon
	variable tBounds
	put the bounding box of xPath into tBounds
	
	// Scale appropriately
	variable tXScale as Real
	variable tYScale as Real
		
	put the width of pTargetRect / the width of tBounds into tXScale
	put the height of pTargetRect / the height of tBounds into tYScale
		
	if tXScale > tYScale then
		put tYScale into tXScale
	else
		put tXScale into tYScale
	end if

    scale xPath by [tXScale, tYScale]

	variable tXTranslate as Real
	variable tYTranslate as Real

    put the bounding box of xPath into tBounds

	put the left of pTargetRect - the left of tBounds into tXTranslate
	put the top of pTargetRect - the top of tBounds into tYTranslate

    variable tXDiff as Real
    variable tYDiff as Real

    put the width of pTargetRect - the width of tBounds into tXDiff
    put the height of pTargetRect - the height of tBounds into tYDiff

	// align center
	divide tXDiff by 2
	divide tYDiff by 2

	translate xPath by [tXTranslate + tXDiff, tYTranslate + tYDiff]
end handler

private handler updateLines() returns nothing
	
	variable tX as Integer
	variable tWidth as Real
	variable tLeft as Real
	
	put the empty list into mLines
	
	put 0 into tLeft
	
	repeat with tX from 1 up to mNumSegments
	
		put fetchWidth(tX) into tWidth
		add tWidth to tLeft
		if tX < mNumSegments then
			push line path from point [tLeft, 0] to point [tLeft, my height] onto back of mLines
		end if
		
	end repeat
end handler

private handler updatePerimeter() returns nothing
	variable tRight as Real
	variable tX as Integer
	
	put 0 into tRight
	repeat with tX from 1 up to mNumSegments
	 	add fetchWidth(tX) to tRight
	end repeat
	
	put rounded rectangle path of rectangle [0.5, 0.5, (the trunc of tRight) + 0.5, (the trunc of my height) - 0.5] with radius mRadius into mPerimeter
end handler

private handler updateProperties() returns nothing
	variable tX as Integer
	
	if (the number of elements in mSegmentLabels) < mNumSegments then
		repeat with tX from 1 up to (mNumSegments-(the number of elements in mSegmentLabels))
			push "Title" onto back of mSegmentLabels
		end repeat
	else if (the number of elements in mSegmentLabels) > mNumSegments then
		repeat with tX from 1 up to (the number of elements in mSegmentLabels)-mNumSegments
			delete element (tX + mNumSegments) of mSegmentLabels
		end repeat
	end if
		
	if (the number of elements in mSegmentIcons) < mNumSegments then
		repeat with tX from 1 up to (mNumSegments-(the number of elements in mSegmentIcons))
			push "f10c" onto back of mSegmentIcons
		end repeat
	else if (the number of elements in mSegmentIcons) > mNumSegments then
		repeat with tX from 1 up to (the number of elements in mSegmentIcons)-mNumSegments
			delete element (tX + mNumSegments) of mSegmentIcons
		end repeat
	end if
	
	if (the number of elements in mSelectedIcons) < mNumSegments then
		repeat with tX from 1 up to (mNumSegments-(the number of elements in mSelectedIcons))
			push "f111" onto back of mSelectedIcons
		end repeat
	else if (the number of elements in mSelectedIcons) > mNumSegments then
		repeat with tX from 1 up to (the number of elements in mSelectedIcons)-mNumSegments
			delete element (tX + mNumSegments) of mSelectedIcons
		end repeat
	end if
	
	if (the number of elements in mSegmentMinWidth) < mNumSegments then
		repeat with tX from 1 up to (mNumSegments-(the number of elements in mSegmentMinWidth))
			push 30 onto back of mSegmentMinWidth
		end repeat
	else if (the number of elements in mSegmentMinWidth) > mNumSegments then
		repeat with tX from 1 up to (the number of elements in mSegmentMinWidth)-mNumSegments
			delete element (tX + mNumSegments) of mSegmentMinWidth
		end repeat
	end if
	
end handler

private handler fetchPath(in pObject as String, in pInt as Integer) returns Path
	
	if pObject is "border" then
		return rounded rectangle path of rectangle [0.5, 0.5, (the trunc of my width)-0.5, (the trunc of my height)-0.5] with radius 2
	end if
	
end handler

private handler fetchPaint(in pObject as String, in pPlatform as String) returns Paint
	
	if pObject is "lines" then
		if pPlatform is "yosemite" then
			return solid paint with color [240/255, 240/255, 240/255]	
		else
			return solid paint with color [51/255, 153/255, 1]
		end if
		
	else if pObject is "border" then
		if pPlatform is "yosemite" then
			return solid paint with color [240/255, 240/255, 240/255]	
		else
			return solid paint with color [51/255, 153/255, 1]
		end if
		
	else if pObject is "selected background" then
		if pPlatform is "yosemite" then
			return solid paint with color [110/255, 110/255, 110/255]
		else
			return solid paint with color [51/255, 153/255, 1]
		end if
		
	else if pObject is "background" then
		if pPlatform is "yosemite" then
			return solid paint with color [1, 1, 1]
		else
			return solid paint with color [0, 0, 0, 0]
		end if
		
	else if pObject is "label" then
		if pPlatform is "yosemite" then
			return solid paint with color [110/255, 110/255, 110/255]
		else
			return solid paint with color [51/255, 153/255, 1]
		end if
		
	else if pObject is "selected label" then
		if pPlatform is "yosemite" then
			return solid paint with color [1, 1, 1]
		else
			return solid paint with color [1, 1 ,1]
		end if
	
	end if
	return solid paint with color [1,0,0]
end handler

private handler fetchFont() returns Font
	variable tFont as Font
	put the font of this canvas into tFont
	set the size of tFont to kTextSize
	return tFont
end handler

private handler fetchLabelRect(in pWidth as Real) returns Rectangle
	return rectangle [mLeft, 0, mLeft + pWidth, my height]
	
end handler

private handler fetchWidth(in pSegment as Integer) returns Real
	if pSegment is 0 then
		return 0
	end if
	
	variable tWidth as Real
	put my width / mNumSegments into tWidth
	if tWidth < (element pSegment of mSegmentMinWidth) then
		put (element pSegment of mSegmentMinWidth) into tWidth
	end if
	
	return tWidth
end handler

private handler fetchBounds(in pSegment as Integer) returns Rectangle
	
	variable tLeft as Real
	put 0 into tLeft
	
	variable tX as Integer
	repeat with tX from 1 up to pSegment-1
	 	add fetchWidth(tX) to tLeft
	end repeat
		
	variable tWidth
	put fetchWidth(pSegment) into tWidth
	
	return rectangle [tLeft, 0, tLeft + tWidth, my height]
end handler

private handler getSegmentNames() returns String

	variable tSegmentNames as String
	combine mSegmentNames with "," into tSegmentNames
	return tSegmentNames
	
end handler

private handler getSegmentLabels() returns String
	
	variable tSegmentLabels as String
	combine mSegmentLabels with "," into tSegmentLabels
	return tSegmentLabels

end handler

private handler getSegmentIcons() returns String
	
	variable tSegmentIcons as String
	combine mSegmentIcons with "," into tSegmentIcons
	return tSegmentIcons
	
end handler

private handler getSelectedIcons() returns String

	variable tSelectedIcons as String
	combine mSelectedIcons with "," into tSelectedIcons
	return tSelectedIcons
	
end handler

private handler getSelectedSegment() returns String
	
	variable tSelected
	variable tSelectedString as String
	variable tStringList as List
	
	put the empty list into tStringList
	
	repeat for each element tSelected in mSelectedSegments
		put tSelected formatted as string into tSelectedString
		push tSelectedString onto back of tStringList
	end repeat
	
	variable tFinalString as String
	combine tStringList with "," into tFinalString
	return tFinalString
	
end handler

private handler getSegmentMinWidth() returns String
		
	variable tMinWidth
	variable tMinWidthString as String
	variable tStringList as List
	
	put the empty list into tStringList
	
	repeat for each element tMinWidth in mSegmentMinWidth
		put tMinWidth formatted as string into tMinWidthString
		push tMinWidthString onto back of tStringList
	end repeat
	
	variable tFinalString as String
	combine tStringList with "," into tFinalString
	return tFinalString
	
end handler

private handler setStyle(in pStyle as String)
	put pStyle into mStyle
	put true into mGeometryIsChanged
	redraw all
end handler

private handler setMultiSelect(in pCanMultiSelect as Boolean)
	put pCanMultiSelect into mMultiSelect
end handler

private handler setSegmentNames(in pNames as String)
	split pNames by "," into mSegmentNames
	put true into mGeometryIsChanged
	redraw all
end handler

private handler setSegmentLabels(in pLabels as String)
	split pLabels by "," into mSegmentLabels
	put true into mGeometryIsChanged
	redraw all
end handler

private handler setSegmentIcons(in pIcons as String)
	split pIcons by "," into mSegmentIcons
	put true into mGeometryIsChanged
	redraw all
end handler

private handler setSelectedIcons(in pSelectedIcons as String)
	split pSelectedIcons by "," into mSelectedIcons
	put true into mGeometryIsChanged
	redraw all
end handler


private handler setSegmentDisplay(in pSegmentDisplay as String)
	put pSegmentDisplay into mSegmentDisplay
	put true into mGeometryIsChanged
	redraw all
end handler

private handler setSegmentMinWidth(in pMinWidths as String)
	put the empty list into mSegmentMinWidth
	
	variable tStringList as List
	split pMinWidths by "," into tStringList
	
	variable tStringMinWidth as String
	variable tMinWidth as Real
	repeat for each element tStringMinWidth in tStringList
		put tStringMinWidth parsed as number into tMinWidth
		push tMinWidth onto back of mSegmentMinWidth
	end repeat
		
	put true into mGeometryIsChanged
	redraw all
end handler

private handler setSelectedSegment(in pSelectedSegment as String) 
	put the empty list into mSelectedSegments
	
	variable tStringList as List
	split pSelectedSegment by "," into tStringList
	
	variable tSelectedString as String
	variable tSelected as Real
	repeat for each element tSelectedString in tStringList
		put tSelectedString parsed as number into tSelected
		push tSelected onto back of mSelectedSegments
	end repeat
	redraw all
end handler

private handler setShowFrameBorder(in pShow as Boolean)
	put pShow into mShowFrameBorder
	redraw all
end handler

end widget
