#Region - TimeStamp
; 2011-11-23 23:29:09
#EndRegion - TimeStamp

#include <OwnTab.au3>
Opt('GUIOnEventMode', 1)

Local $hGui = GUICreate("Funkey's OwnTab-UDF Example", 500, 350)
GUISetOnEvent(-3, '_Exit')
GUISetBkColor(0xbbbbbb)

$OwnTab_Style = Random(0, 1, 1)	;random style (only 2 styles available!!)

Local $aTabText[5] = ["Settings", "Register without icon", "Pic", "Status", "Tab in Tab"] ;Declare the regions for the OwnTab-control
Local $aTabIcons[5][2] = [["shell32.dll", 130],[""],["shell32.dll", 139],["shell32.dll", 90], ["shell32.dll", 43]]
;~ Global $aCtrlTab = _OwnTab_Create($hGui, $aTabText, 10, 10, 480, 300, 30, 0xD5D5D5, 0xCFE0E7, 0xCFE0E7, $aTabIcons)
Global $aCtrlTab = _OwnTab_Create($hGui, $aTabText, 10, 10, 480, 300, '_OnClick', 30, 0xD5D5D5, 0xCFE0E7, 0xCFE0E7, $aTabIcons)

Local $aTabTip[5] = ["Tip Item 1", "Tip Item 2", "Tip Item 3", "Alarm-Register"]
_OwnTab_SetTip($aCtrlTab, $aTabTip) ;set the tooltips for the OwnTab-control

#Region Tab1
_OwnTab_Add($aCtrlTab) ;Start controls tab1
Global $Edit1 = GUICtrlCreateEdit("Edit in Tab1", 20, 55, 300, 50, 0)
Global $Button1 = GUICtrlCreateButton("Simulate an alarm", 20, 120, 300, 20)
GUICtrlSetOnEvent(-1, '_OnClick')
Global $Box1 = GUICtrlCreateCheckbox("Switch on hover  -  set time -->", 20, 180)
GUICtrlSetBkColor(-1, 0xCFE0E7)
Global $Input1 = GUICtrlCreateInput("1", 200, 180, 50, 20)
GUICtrlCreateUpdown($Input1)
GUICtrlSetLimit(-1, 15, 1)
#EndRegion Tab1

#Region Tab2
_OwnTab_Add($aCtrlTab) ;Start controls tab2
Global $Edit2 = GUICtrlCreateEdit("Edit in Tab2", 20, 150, 300, 50, 0)
Global $Label2 = GUICtrlCreateLabel("Label in Tab2", 20, 220, 300, 20, 0x201)
GUICtrlSetBkColor(-1, -2) ;$GUI_BKCOLOR_TRANSPARENT
#EndRegion Tab2

#Region Tab3
_OwnTab_Add($aCtrlTab) ;Start controls tab3
Global $Labe3 = GUICtrlCreateLabel("If you see this label, you can change the picture-path in scriptline " &@ScriptLineNumber + 1 &  "!!", 40, 150, 400, 30, 0x201)
Global $Edit3 = GUICtrlCreatePic(@DocumentsCommonDir & '\Eigene Bilder\Beispielbilder\Winter.jpg', 20, 55, 460, 280)
#EndRegion Tab3

#Region Tab4
_OwnTab_Add($aCtrlTab) ;Start controls tab4
Global $Button4 = GUICtrlCreateButton("Acknowledge the alarm", 20, 120, 300, 20)
GUICtrlSetOnEvent(-1, '_OnClick')
Global $Button5 = GUICtrlCreateButton("Enable tab 3", 20, 150, 300, 20)
GUICtrlSetOnEvent(-1, '_OnClick')
Global $Button6 = GUICtrlCreateButton("Disable tab 3", 20, 180, 300, 20)
GUICtrlSetOnEvent(-1, '_OnClick')
Global $Button7 = GUICtrlCreateButton("Hide tab 2", 20, 240, 300, 20)
GUICtrlSetOnEvent(-1, '_OnClick')
Global $Button8 = GUICtrlCreateButton("Show tab 2", 20, 210, 300, 20)
GUICtrlSetOnEvent(-1, '_OnClick')
#EndRegion Tab4

#Region Tab5 and "Tab in Tab"
_OwnTab_Add($aCtrlTab) ;Start controls tab5

GUICtrlCreateLabel("Style Black", 30, 50, 200, 20, 0x201)
$OwnTab_Style = 0
Local $aTabText[2] = ["Tab1", "New Info"] ;Declare the regions for the OwnTab-control
Local $aTabIcons[2][2] = [["shell32.dll", 20],["shell32.dll", 40]]
Global $aCtrlTab2 = _OwnTab_Create($hGui, $aTabText, 30, 80, 200, 200, '_OnClick', 30, 0xD5D5D5, 0x00ff00, 0x00ff00, $aTabIcons)
_OwnTab_Add($aCtrlTab2) ;Start controls tab1
Global $BtnSet = GUICtrlCreateButton("Simulate", 80, 150, 100, 20)
GUICtrlSetOnEvent(-1, '_OnClick')
_OwnTab_Add($aCtrlTab2) ;Start controls tab2
Global $BtnReset = GUICtrlCreateButton("Acknowledge", 80, 170, 100, 20)
GUICtrlSetOnEvent(-1, '_OnClick')
_OwnTab_End($aCtrlTab2)

GUICtrlCreateLabel("Style White", 270, 50, 200, 20, 0x201)
$OwnTab_Style = 1
Local $aTabText[2] = ["Tab1", "Tab2"] ;Declare the regions for the OwnTab-control
Local $aTabIcons[2][2] = [["shell32.dll", 10],["shell32.dll", 60]]
Global $aCtrlTab3 = _OwnTab_Create($hGui, $aTabText, 270, 80, 200, 200, '_OnClick', 30, 0xD5D5D5, 0x00ff00, 0x00ff00, $aTabIcons)
_OwnTab_Add($aCtrlTab3) ;Start controls tab1
GUICtrlCreateLabel("Just testing...", 280, 150, 100, 20)
GUICtrlSetBkColor(-1, -2)
_OwnTab_Add($aCtrlTab3) ;Start controls tab2
GUICtrlCreateLabel("Hello from tab2", 280, 150, 100, 20)
GUICtrlSetBkColor(-1, -2)
_OwnTab_End($aCtrlTab3)
#EndRegion Tab5

_OwnTab_End($aCtrlTab) ;new: end control-definition AND inizialize the OwnTab

_OwnTab_Disable($aCtrlTab, 3) ;new: disable tabitems
_OwnTab_SetFontCol($aCtrlTab, 0xFF) ;new: set font-color

GUISetState()
_OwnTab_Hover($aCtrlTab, 0xFFFF88) ;start hover-function if you want
_OwnTab_AlarmInit()

While 1
	Sleep(100)
WEnd

Func _OnClick()
	For $a = 1 To UBound($aCtrlTab, 1) - 1
		If @GUI_CtrlId = $aCtrlTab[$a][0] Then
			_OwnTab_Switch($aCtrlTab, $a)
			If $a = 5 Then
				_OwnTab_Switch($aCtrlTab2, $aCtrlTab2[0][0], 1)
				_OwnTab_Switch($aCtrlTab3, $aCtrlTab3[0][0], 1)
			EndIf
		EndIf
	Next
	For $a = 1 To UBound($aCtrlTab2, 1) - 1
		If @GUI_CtrlId = $aCtrlTab2[$a][0] Then
			_OwnTab_Switch($aCtrlTab2, $a)
		EndIf
	Next
	For $a = 1 To UBound($aCtrlTab3, 1) - 1
		If @GUI_CtrlId = $aCtrlTab3[$a][0] Then
			_OwnTab_Switch($aCtrlTab3, $a)
		EndIf
	Next
	Switch @GUI_CtrlId
		Case $Button1
			_OwnTab_SetAlarm($aCtrlTab, 4, 0xFF0000)
		Case $Button4
			_OwnTab_ResetAlarm($aCtrlTab, 4)
		Case $BtnSet
			_OwnTab_SetAlarm($aCtrlTab2, 2, 0x5050FF)
		Case $BtnReset
			_OwnTab_ResetAlarm($aCtrlTab2, 2)
		Case $Button5
			_OwnTab_Enable($aCtrlTab, 3)
		Case $Button6
			_OwnTab_Disable($aCtrlTab, 3)
		Case $Button7
			_OwnTab_Hide($aCtrlTab, 2)
		Case $Button8
			_OwnTab_Show($aCtrlTab, 2)
		Case $Box1
			If GUICtrlRead($Box1) = 1 Then
				_OwnTab_Hover($aCtrlTab, 0xFFFF88, GUICtrlRead($Input1))
			Else
				_OwnTab_Hover($aCtrlTab, 0xFFFF88, 0)
			EndIf
		Case $Input1
			If GUICtrlRead($Box1) = 1 Then _OwnTab_Hover($aCtrlTab, 0xFFFF88, GUICtrlRead($Input1))
	EndSwitch
EndFunc

;~ Local $msg

;~ While 1
;~ 	$msg = GUIGetMsg()
;~ 	For $a = 1 To UBound($aCtrlTab, 1) - 1
;~ 		If $msg = $aCtrlTab[$a][0] Then
;~ 			_OwnTab_Switch($aCtrlTab, $a)
;~ 			If $a = 5 Then
;~ 				_OwnTab_Switch($aCtrlTab2, $aCtrlTab2[0][0], 1)
;~ 				_OwnTab_Switch($aCtrlTab3, $aCtrlTab3[0][0], 1)
;~ 			EndIf
;~ 		EndIf
;~ 	Next
;~ 	For $a = 1 To UBound($aCtrlTab2, 1) - 1
;~ 		If $msg = $aCtrlTab2[$a][0] Then
;~ 			_OwnTab_Switch($aCtrlTab2, $a)
;~ 		EndIf
;~ 	Next
;~ 	For $a = 1 To UBound($aCtrlTab3, 1) - 1
;~ 		If $msg = $aCtrlTab3[$a][0] Then
;~ 			_OwnTab_Switch($aCtrlTab3, $a)
;~ 		EndIf
;~ 	Next
;~ 	Switch $msg
;~ 		Case $Button1
;~ 			_OwnTab_SetAlarm($aCtrlTab, 4, 0xFF0000)
;~ 		Case $Button4
;~ 			_OwnTab_ResetAlarm($aCtrlTab, 4)
;~ 		Case $BtnSet
;~ 			_OwnTab_SetAlarm($aCtrlTab2, 2, 0x5050FF)
;~ 		Case $BtnReset
;~ 			_OwnTab_ResetAlarm($aCtrlTab2, 2)
;~ 		Case $Button5
;~ 			_OwnTab_Enable($aCtrlTab, 3)
;~ 		Case $Button6
;~ 			_OwnTab_Disable($aCtrlTab, 3)
;~ 		Case $Button7
;~ 			_OwnTab_Hide($aCtrlTab, 2)
;~ 		Case $Button8
;~ 			_OwnTab_Show($aCtrlTab, 2)
;~ 		Case $Box1
;~ 			If GUICtrlRead($Box1) = 1 Then
;~ 				_OwnTab_Hover($aCtrlTab, 0xFFFF88, GUICtrlRead($Input1))
;~ 			Else
;~ 				_OwnTab_Hover($aCtrlTab, 0xFFFF88, 0)
;~ 			EndIf
;~ 		Case $Input1
;~ 			If GUICtrlRead($Box1) = 1 Then _OwnTab_Hover($aCtrlTab, 0xFFFF88, GUICtrlRead($Input1))
;~ 		Case -3
;~ 			Exit
;~ 	EndSwitch
;~ 	Sleep(10)
;~ WEnd

Func _Exit()
	Exit
EndFunc