Basic Univers
; Author   : Progi1984
; Project  : OutlookBarGadget
; History
;   0.1
;     Date    : 13/06/07
;     Comment : Release First Version
;   0.2
;     Date    : 14/06/07
;     Comment : ADDED : GetGadgetItemText
;               ADDED : SetGadgetItemText
;               BUG#1 : String + GetGadgetItemText Delete the string
;   0.3
;     Date    : 19/06/07
;     Comment : ADDED : GetGadgetAttribute
;               ADDED : SetGadgetAttribute
;               ADDED : GetGadgetColor
;               ADDED : SetGadgetColor
;               ADDED : GetGadgetItemColor2
;               ADDED : SetGadgetItemColor2
;               ADDED : GetGadgetItemData
;               ADDED : SetGadgetItemData
;
;{ WIP
;  GetGadgetItemText
;  SetGadgetItemText
;  GetGadgetAttribute       : height button
;  SetGadgetAttribute
;  SetGadgetColor           : listbox (front and back)
;  GetGadgetColor
;  SetGadgetItemColor2      : button
;  GetGadgetItemColor2
;  SetGadgetItemData        : for each button
;  GetGadgetItemData
;}
;{ TODO
;  GetGadgetItemState
;  SetGadgetItemState
;  GetGadgetItemAttribute2
;  SetGadgetItemAttribute2
;}

;- Inc_Main
;{
; Import "C:\Program Files\PureBasic\Compilers\ObjectManager.lib"
; Import "C:\Documents and Settings\Franck\Bureau\PureBasic\Compilers\ObjectManager.lib"
Import #PB_Compiler_Home + "\Compilers\ObjectManager.lib"
  Object_GetOrAllocateID(Objects, Object.l) As "_PB_Object_GetOrAllocateID@8"
  Object_GetObject(Objects, Object.l) As "_PB_Object_GetObject@8"
  Object_IsObject(Objects, Object.l) As "_PB_Object_IsObject@8"
  Object_EnumerateAll(Objects, ObjectEnumerateAllCallback, *VoidData) As "_PB_Object_EnumerateAll@12"
  Object_EnumerateStart(Objects) As "_PB_Object_EnumerateStart@4"
  Object_EnumerateNext(Objects, *object.Long) As "_PB_Object_EnumerateNext@8"
  Object_EnumerateAbort(Objects) As "_PB_Object_EnumerateAbort@4"
  Object_FreeID(Objects, Object.l) As "_PB_Object_FreeID@8"
  Object_Init(StructureSize.l, IncrementStep.l, ObjectFreeFunction) As "_PB_Object_Init@12"
  Object_GetThreadMemory(MemoryID.l) As "_PB_Object_GetThreadMemory@4"
  Object_InitThreadMemory(Size.l, InitFunction, EndFunction) As "_PB_Object_InitThreadMemory@12"
EndImport
Structure S_RoutlookItem
 Text					.s
 ImageID				.l
EndStructure
Structure S_ROutlookHeader
 ID						.l
 PosTop				.l
 NbItem				.l
 Selected      .l
 ButtonID      .S_RoutlookItem[10]
EndStructure
Structure S_ROutlookBar
  Hwnd          .l
  HwndParent		.l
  HwndStaticBg  .l
  HwndListIcon	.l
  PB_Gadget     .l
  X							.l
  Y							.l
  Width         .l
  Height        .l
  State					.l
  NbHeader      .l
  ButtonHeight  .l
  ButtonID      .S_ROutlookHeader[10]
EndStructure
#EOL	= Chr(13) + Chr(10)
; Event
Enumeration
 #OutlookBar_Event_HeaderClicked
 #OutlookBar_Event_ItemClicked
 ;#OutlookBar_Event_
 ;#OutlookBar_Event_
 ;#OutlookBar_Event_
 ;#OutlookBar_Event_
EndEnumeration
Enumeration
  #OutlookBar_HeightHeader
EndEnumeration
Macro HiWord(Long)
  (Long >> 16) & $FFFF)
EndMacro
Macro LoWord(Long)
  Long & $FFFF)
EndMacro
;}
;- Inc_CreateGadget
;{ CreateGadget
Prototype.l ProtoPB_Gadget_RegisterGadget		(ID.l, *Gadget.l, hwnd.l, *GadgetVT.l)
Prototype.l ProtoPB_Gadget_SendGadgetCommand	(hWnd.l, EventType.l)
Enumeration
  #PB_GadgetType_Unknown
  #PB_GadgetType_Button
  #PB_GadgetType_String
  #PB_GadgetType_Text
  #PB_GadgetType_CheckBox
  #PB_GadgetType_Option
  #PB_GadgetType_ListView
  #PB_GadgetType_Frame3D
  #PB_GadgetType_ComboBox
  #PB_GadgetType_Image
  #PB_GadgetType_HyperLink
  #PB_GadgetType_Container
  #PB_GadgetType_ListIcon
  #PB_GadgetType_IPAddress
  #PB_GadgetType_ProgressBar
  #PB_GadgetType_ScrollBar
  #PB_GadgetType_ScrollArea
  #PB_GadgetType_TrackBar
  #PB_GadgetType_Web
  #PB_GadgetType_ButtonImage
  #PB_GadgetType_Calendar
  #PB_GadgetType_Date
  #PB_GadgetType_Editor
  #PB_GadgetType_ExplorerList
  #PB_GadgetType_ExplorerTree
  #PB_GadgetType_ExplorerCombo
  #PB_GadgetType_Spin
  #PB_GadgetType_Tree
  #PB_GadgetType_Panel
  #PB_GadgetType_Splitter
  #PB_GadgetType_MDI
  #PB_GadgetType_Scintilla
  #PB_GadgetType_OutlookBar
  #PB_GadgetType_LastEnum
EndEnumeration

CompilerIf Defined(PB_GadgetVT, #PB_Structure) = #False
Structure PB_GadgetVT
  GadgetType.l
  SizeOf.l
  GadgetCallback.l
  FreeGadget.l
  GetGadgetState.l
  SetGadgetState.l
  GetGadgetText.l
  SetGadgetText.l
  AddGadgetItem2.l
  AddGadgetItem3.l
  RemoveGadgetItem.l
  ClearGadgetItemList.l
  ResizeGadget.l
  CountGadgetItems.l
  GetGadgetItemState.l
  SetGadgetItemState.l
  GetGadgetItemText.l
  SetGadgetItemText.l
  OpenGadgetList2.l
  GadgetX.l
  GadgetY.l
  GadgetWidth.l
  GadgetHeight.l
  HideGadget.l
  AddGadgetColumn.l
  RemoveGadgetColumn.l
  GetGadgetAttribute.l
  SetGadgetAttribute.l
  GetGadgetItemAttribute2.l
  SetGadgetItemAttribute2.l
  SetGadgetColor.l
  GetGadgetColor.l
  SetGadgetItemColor2.l
  GetGadgetItemColor2.l
  SetGadgetItemData.l
  GetGadgetItemData.l
EndStructure
CompilerEndIf
CompilerIf Defined(PB_Gadget, #PB_Structure) = #False
Structure PB_Gadget
  Gadget.l
  *VT.PB_GadgetVT
  UserData.l
  OldCallback.l
  Daten.l[4]
EndStructure
CompilerEndIf
CompilerIf Defined(Gadget_Info, #PB_Structure) = #False
Structure Gadget_Info
  OldCallback.l
  DestroyProc.l
  PBID.l
EndStructure
CompilerEndIf

Procedure Gadget_RegCallback		(hwnd, msg, wParam, lParam)
  Protected *Gadget_Info.Gadget_Info = GetProp_(hwnd, "GadgetInfo")
  Protected OldProc = *Gadget_Info\OldCallback
 
  If msg = #WM_NCDESTROY
    If *Gadget_Info
      If *Gadget_Info\DestroyProc
        CallFunctionFast(*Gadget_Info\DestroyProc, *Gadget_Info\PBID)
      EndIf
    EndIf
    RemoveProp_(hwnd, "GadgetInfo")
    FreeMemory(*Gadget_Info)
  EndIf
 
  ProcedureReturn CallWindowProc_(OldProc, hwnd, msg, wParam, lParam)
EndProcedure
Procedure Gadget_GetParent			()
  !EXTRN _PB_Object_GetThreadMemory@4
  !EXTRN _PB_Gadget_Globals
  !MOV   Eax, [_PB_Gadget_Globals]
  !PUSH  Eax
  !CALL  _PB_Object_GetThreadMemory@4
  !MOV   Eax, [Eax]
  ProcedureReturn
  CreateGadgetList(0)
EndProcedure
Procedure Gadget_Register			(hwnd.l, ID.l, DestroyProc.l = 0, *vttemp.PB_GadgetVT = 0)
;   Protected PB_Object_GetOrAllocateID.ProtoPB_Object_GetOrAllocateID
  Protected PB_Gadget_RegisterGadget.ProtoPB_Gadget_RegisterGadget
  Protected PB_Gadget_Objects.l
  Protected *Gadget.PB_Gadget, *Gadget_Info.Gadget_Info
  Protected OldCallback.l
  Protected *VT.PB_GadgetVT
 
  If((hwnd = 0) Or(ID < #PB_Any))
    ProcedureReturn 0
  EndIf
 
  *VT = AllocateMemory(SizeOf(PB_GadgetVT))
  If *vttemp <> 0
    CopyMemory(*vttemp, *VT, SizeOf(PB_GadgetVT))
  EndIf
 
  CompilerIf #PB_Compiler_Unicode
    !EXTRN  _PB_Gadget_RegisterGadget_UNICODE@16
    !MOV   [p.v_PB_Gadget_RegisterGadget] , dword _PB_Gadget_RegisterGadget_UNICODE@16
  CompilerElse
    !EXTRN _PB_Gadget_RegisterGadget@16
    !MOV   [p.v_PB_Gadget_RegisterGadget] , dword _PB_Gadget_RegisterGadget@16
  CompilerEndIf
 
  ;!EXTRN _PB_Object_GetOrAllocateID@8
  !EXTRN _PB_Gadget_Objects
  ;!MOV   [p.v_PB_Object_GetOrAllocateID],dword _PB_Object_GetOrAllocateID@8
  !MOV   Eax, [_PB_Gadget_Objects]
  !MOV   [p.v_PB_Gadget_Objects], Eax
 
  *Gadget = Object_GetOrAllocateID(PB_Gadget_Objects, ID)
  hwnd    = PB_Gadget_RegisterGadget(ID, *Gadget, hwnd, *VT)

  If DestroyProc
    *Gadget_Info = AllocateMemory(SizeOf(Gadget_Info))
    *Gadget_Info\DestroyProc = DestroyProc
    *Gadget_Info\OldCallback = SetWindowLong_(*Gadget\Gadget, #GWL_WNDPROC, @Gadget_RegCallback())
    If ID = #PB_Any
      *Gadget_Info\PBID = hwnd
    Else
      *Gadget_Info\PBID = ID
    EndIf
    SetProp_(*Gadget\Gadget, "GadgetInfo", *Gadget_Info)
  EndIf
 
  ProcedureReturn hwnd
EndProcedure
Procedure Gadget_Create				(ID.l, ClassName.s, Text.s, Style.l, X.l, Y.l, DX.l, DY.l, ExStyle.l = 0, DestroyProc.l = 0, *VT.PB_GadgetVT = 0, CallBack = 0)
  Protected hwnd.l
  Protected parent.l    = Gadget_GetParent()
  Protected hInstance.l = GetModuleHandle_(0)
  Protected wc.WNDCLASSEX
  wc\cbSize 				= SizeOf(WNDCLASSEX)
  wc\style 					= #CS_DBLCLKS
  wc\lpfnWndProc 		= CallBack
  wc\hInstance 			= hInstance
  wc\lpszClassName 	= @ClassName
  wc\hbrBackground	=	GetStockObject_(#LTGRAY_BRUSH)

  RegisterClassEx_	(@wc)
  hwnd = CreateWindowEx_(0, ClassName, text, style, x, y, DX, DY, parent, 0, hInstance, 0)
  ShowWindow_				(hwnd, #SW_SHOWNORMAL)
  UpdateWindow_			(hwnd)
  ProcedureReturn Gadget_Register(hwnd, ID, DestroyProc, *VT)
EndProcedure
;}

Declare OB_SetGadgetState				(*gadget.PB_Gadget, State.l)
Declare OB_FreeGadget						(*gadget.PB_Gadget)
Declare OB_SetGadgetItemState		(*gadget.PB_Gadget, Position.l, State.l)
Procedure OB_CallbackOB					(WindowID, Message, wParam, lParam)
  Protected *info.S_ROutlookBar = GetProp_(WindowID, "ROutlookBar_Info")
  Select Message
    Case #WM_DESTROY
   With *info
    For Inc_a = 0 To 9
     If \ButtonID[Inc_a]\ID > 0
      FreeGadget(\ButtonID[Inc_a]\ID)
     EndIf
    Next
    FreeGadget(\HwndStaticBg)
   EndWith
      RemoveProp_(WindowID, "ROutlookBar_Info")
  EndSelect
  ProcedureReturn DefWindowProc_(WindowID, Message, wParam, lParam)
EndProcedure
Procedure OB_CallbackButton			(WindowID, Message, wParam, lParam)
 Protected OldProc			.l 							= GetProp_	(WindowID, "Button_Proc")
 Protected MainWindowID	.l							= GetParent_(GetParent_(WindowID))
 Protected *info				.S_ROutlookBar	= GetProp_	(MainWindowID, "ROutlookBar_Info")
 Protected PB_Gadget_SendGadgetCommand.ProtoPB_Gadget_SendGadgetCommand
  !Extrn _PB_Gadget_SendGadgetCommand@8
  !Mov   [p.v_PB_Gadget_SendGadgetCommand], dword _PB_Gadget_SendGadgetCommand@8

 Select Message
  Case #WM_LBUTTONUP
   PB_Gadget_SendGadgetCommand(*info\Hwnd, #OutlookBar_Event_HeaderClicked)
      For Inc_a = 0 To *info\NbHeader - 1
        If GadgetID(*info\ButtonID[Inc_a]\ID) = WindowID
          OB_SetGadgetState(*info\PB_Gadget, Inc_a + 1)
          Break
        EndIf
      Next
 EndSelect
 ProcedureReturn CallWindowProc_(OldProc, WindowID, Message, wParam, lParam)
EndProcedure
Procedure OB_CallbackListIcon		(WindowID, Message, wParam, lParam)
 Protected OldProc			.l 							= GetProp_	(WindowID, "ListIcon_Proc")
 Protected MainWindowID	.l							= GetParent_(GetParent_(WindowID))
 Protected *info				.S_ROutlookBar	= GetProp_	(MainWindowID, "ROutlookBar_Info")
  Select Message
    Case #WM_NCCALCSIZE
      ShowScrollBar_(WindowID, #SB_HORZ, #False)
  EndSelect
  ProcedureReturn CallWindowProc_(OldProc, WindowID, Message, wParam, lParam)
EndProcedure
Procedure OB_CallbackStaticBg		(WindowID, Message, wParam, lParam)
 Protected OldProc			.l 							= GetProp_	(WindowID, "HwndStaticBg_Proc")
 Protected MainWindowID	.l							= GetParent_(WindowID)
 Protected *info				.S_ROutlookBar	= GetProp_	(MainWindowID, "ROutlookBar_Info")
 Protected PB_Gadget_SendGadgetCommand.ProtoPB_Gadget_SendGadgetCommand
 
  ;!Extrn _PB_Gadget_SendGadgetCommand@8
  !Mov   [p.v_PB_Gadget_SendGadgetCommand], dword _PB_Gadget_SendGadgetCommand@8
 Select Message
  Case #WM_NOTIFY
      *pnmhdr.NMHDR = lParam
      Select *pnmhdr\code
      Case #LVN_ITEMCHANGED
       With *info
        PB_Gadget_SendGadgetCommand(\Hwnd, #OutlookBar_Event_ItemClicked)
       EndWith
     EndSelect
  Default
   ; Debug message
 EndSelect
 ProcedureReturn CallWindowProc_(OldProc, WindowID, Message, wParam, lParam)
EndProcedure
Procedure OB_AddGadgetItem3			(*gadget.PB_Gadget, Position, Text.s, ImageID, Options)
 Protected Inc_a.l
 If *gadget
  Protected *info.S_ROutlookBar = GetProp_(*gadget\gadget, "ROutlookBar_Info")
    If ImageID = 0 And Options = 0 And Position <> 0
     With *info
       If \PB_Gadget = 0
         \PB_Gadget = *Gadget
       EndIf
       LockWindowUpdate_(\HwndParent)
        CreateGadgetList(GadgetID(\HwndStaticBg))
         If \NbHeader = 0
          \HwndListIcon = ListIconGadget(#PB_Any, 0, 0, \width, 200, "", \width, 0)
                  ChangeListIconGadgetDisplay(\HwndListIcon, #PB_ListIcon_LargeIcon)
                  SetProp_(GadgetID(\HwndListIcon), "ListIcon_Proc", SetWindowLong_(GadgetID(\HwndListIcon), #GWL_WNDPROC, @OB_CallbackListIcon()))
         EndIf
         If Position = - 1
          Position = \NbHeader
         Else
           Position - 1
          For Inc_a = \NbHeader To Position + 1 Step - 1
           \ButtonID[Inc_a]\ID 				= \ButtonID[Inc_a - 1]\ID
           \ButtonID[Inc_a]\PosTop			=	\ButtonID[Inc_a - 1]\PosTop + 20
          Next
         EndIf
         \ButtonID[Position]\ID = ButtonGadget(#PB_Any, 0, \ButtonID[Position]\PosTop, \width, \ButtonHeight, Text)
         SetProp_(GadgetID(\ButtonID[Position]\ID), "Button_Proc", SetWindowLong_(GadgetID(\ButtonID[Position]\ID), #GWL_WNDPROC, @OB_CallbackButton()))
         \NbHeader + 1
        If Position > - 1
         For Inc_a = 0 To \NbHeader - 1
          ResizeGadget(\ButtonID[Inc_a]\ID, 0, \ButtonID[Inc_a]\PosTop, \width, \ButtonHeight)
          Next
         EndIf
         \State = Position
        OB_SetGadgetState(*gadget, Position)
       UseGadgetList(\HwndParent)
      LockWindowUpdate_(#Null)
     EndWith
  Else
     With *info
       If Position = - 1
        Position = \ButtonID[Options]\NbItem
       Else
        For Inc_a = \ButtonID[Options]\NbItem - 1 To Position + 1 Step - 1
         \ButtonID[Options]\ButtonID[Inc_a]\Text			= \ButtonID[Options]\ButtonID[Inc_a - 1]\Text
         \ButtonID[Options]\ButtonID[Inc_a]\ImageID	= \ButtonID[Options]\ButtonID[Inc_a - 1]\ImageID
        Next
       EndIf
       \ButtonID[Options]\ButtonID[Position]\Text 			= Text
       \ButtonID[Options]\ButtonID[Position]\ImageID 	= ImageID
       \ButtonID[Options]\NbItem + 1
     EndWith
  EndIf
 EndIf
EndProcedure
Procedure OB_GadgetType					(*gadget.PB_Gadget)
 If *gadget
  Protected *info.S_ROutlookBar = GetProp_(*gadget\gadget, "ROutlookBar_Info")
    With *info
     ProcedureReturn #PB_GadgetType_Unknown
    EndWith
  EndIf
EndProcedure
Procedure OB_FreeGadget					(*gadget.PB_Gadget)
; 	Protected Inc_a.l
  If *gadget
  Protected *info.S_ROutlookBar = GetProp_(*gadget\gadget, "ROutlookBar_Info")
;     RemoveProp_(*gadget\gadget,"ROutlookBar_Info")
   EndIf
 EndProcedure
Procedure OB_GetGadgetState			(*gadget.PB_Gadget)
 If *gadget
  Protected *info.S_ROutlookBar = GetProp_(*gadget\gadget, "ROutlookBar_Info")
    With *info
     ProcedureReturn \State
    EndWith
  EndIf
EndProcedure
Procedure OB_SetGadgetState			(*gadget.PB_Gadget, State.l)
 Protected Inc_a.l
 If *gadget
  Protected *info.S_ROutlookBar = GetProp_(*gadget\gadget, "ROutlookBar_Info")
    With *info
     If \State < - 1
      \State = 0
     ElseIf \State > \NbHeader
      \State = \NbHeader
     ElseIf State = 0
       \State = 0
     Else
      \State = State  - 1
     EndIf
     For Inc_a = \NbHeader To 0 Step - 1
      If \ButtonID[Inc_a]\ID > 0
       If Inc_a >= \State + 1
        If Inc_a = \NbHeader - 1
         \ButtonID[Inc_a]\PosTop = \Height - \ButtonHeight
        Else
         \ButtonID[Inc_a]\PosTop = \ButtonID[Inc_a + 1]\PosTop - \ButtonHeight
        EndIf
       Else
        \ButtonID[Inc_a]\PosTop = Inc_a * \ButtonHeight
     EndIf
     ResizeGadget(\ButtonID[Inc_a]\ID, 0, \ButtonID[Inc_a]\PosTop, \width - 1, \ButtonHeight)
      EndIf
     Next
     If \NbHeader = \State + 1
      ResizeGadget(\HwndListIcon, 0,(\State + 1)*20, \width - 2, \height - \ButtonID[\State]\PosTop - 20)
     ElseIf \NbHeader < \State + 1
      ResizeGadget(\HwndListIcon, 0,(\State)*20, 	\width - 2, \height - \ButtonID[\State]\PosTop)
     Else
      ResizeGadget(\HwndListIcon, 0,(\State + 1)*20, \width - 2, \ButtonID[\State + 1]\PosTop - \ButtonID[\State]\PosTop - 20)
     EndIf
     ClearGadgetItemList(\HwndListIcon)
     For Inc_a = 0 To 9
      If \ButtonID[\State]\ButtonID[Inc_a]\Text <> ""
        AddGadgetItem(\HwndListIcon, Inc_a, \ButtonID[\State]\ButtonID[Inc_a]\Text, \ButtonID[\State]\ButtonID[Inc_a]\ImageID)
       EndIf
     Next
     SendMessage_(GadgetID(\HwndListIcon), #LVM_ENSUREVISIBLE, 0, 0)
     InvalidateRect_(*gadget\Gadget, 0, #True)
    EndWith
  EndIf
EndProcedure
Procedure OB_RemoveGadgetItem		(*gadget.PB_Gadget, Position.l)
 Protected Inc_a.l
 If *gadget
  Protected *info.S_ROutlookBar = GetProp_(*gadget\gadget, "ROutlookBar_Info")
    With *info
     If \NbHeader > 0
       ; Libère le bouton
       If Position < 0
        Position = 0
       ElseIf Position > \NbHeader
        Position = \NbHeader - 1
       EndIf
       FreeGadget(\ButtonID[Position]\ID)
       \NbHeader	= \NbHeader - 1
       ; Repositionne les autres boutons
       For Inc_a	= Position To \NbHeader - 1
        \ButtonID[Inc_a]\ID				= \ButtonID[Inc_a + 1]\ID
        \ButtonID[Inc_a]\PosTop	=	\ButtonID[Inc_a + 1]\PosTop - \ButtonHeight
       Next
       If Position > \NbHeader
        Position = \NbHeader - 1
       EndIf
       ; ReDessine le Gadget
       InvalidateRect_(*gadget\Gadget, 0, #True)
       ; SetState le Gadget
       If \NbHeader > 0
         If \NbHeader < \State
          \State = \NbHeader
         EndIf
         OB_SetGadgetState(*gadget, \State)
      Else
       FreeGadget(\HwndListIcon)
       EndIf
     EndIf
    EndWith
  EndIf
EndProcedure
Procedure OB_CountGadgetItems		(*gadget.PB_Gadget)
 If *gadget
  Protected *info.S_ROutlookBar = GetProp_(*gadget\gadget, "ROutlookBar_Info")
    With *info
      ProcedureReturn \NbHeader
    EndWith
  EndIf
EndProcedure
Procedure OB_GadgetX							(*gadget.PB_Gadget)
 If *gadget
  Protected *info.S_ROutlookBar = GetProp_(*gadget\gadget, "ROutlookBar_Info")
    With *info
     ProcedureReturn \X
    EndWith
  EndIf
EndProcedure
Procedure OB_GadgetY							(*gadget.PB_Gadget)
 If *gadget
  Protected *info.S_ROutlookBar = GetProp_(*gadget\gadget, "ROutlookBar_Info")
    With *info
     ProcedureReturn \Y
    EndWith
  EndIf
EndProcedure
Procedure OB_GadgetWidth					(*gadget.PB_Gadget)
 If *gadget
  Protected *info.S_ROutlookBar = GetProp_(*gadget\gadget, "ROutlookBar_Info")
    With *info
     ProcedureReturn \Width
    EndWith
  EndIf
EndProcedure
Procedure OB_GadgetHeight				(*gadget.PB_Gadget)
 If *gadget
  Protected *info.S_ROutlookBar = GetProp_(*gadget\gadget, "ROutlookBar_Info")
    With *info
     ProcedureReturn \Height
    EndWith
  EndIf
EndProcedure
Procedure OB_HideGadget					(*gadget.PB_Gadget, State.l)
 If *gadget
  Protected *info.S_ROutlookBar = GetProp_(*gadget\gadget, "ROutlookBar_Info")
    With *info
     If State = #True
       ShowWindow_(\Hwnd, #SW_HIDE)
     Else
       ShowWindow_(\Hwnd, #SW_SHOW)
     EndIf
    EndWith
  EndIf
EndProcedure
Procedure OB_ResizeGadget				(*gadget.PB_Gadget, x, y, Width, Height)
 If *gadget
  Protected *info.S_ROutlookBar = GetProp_(*gadget\gadget, "ROutlookBar_Info")
    With *info
     If x <> #PB_Ignore
      \x	=	x
     EndIf
     If y <> #PB_Ignore
      \y	=	y
     EndIf
     If Width <> #PB_Ignore
      \Width	=	Width
     EndIf
     If Height <> #PB_Ignore
      \Height	=	Height
     EndIf
     MoveWindow_(\Hwnd, \x, \y, \Width, \Height, #True)
     ResizeGadget(\HwndStaticBg , 0, 0, \Width, \Height)
     OB_SetGadgetState(*gadget, \State)
    EndWith
  EndIf
EndProcedure

;-WIP
Procedure.s OB_GetGadgetItemText	(*gadget.PB_Gadget, Position.l, Column.l, PreviousStringPosition.l)
 If *gadget
  Protected *info.S_ROutlookBar = GetProp_(*gadget\gadget, "ROutlookBar_Info")
    With *info
      If Position = - 1
        Position = \NbHeader
      ElseIf Position > \NbHeader
        Position = \NbHeader
      EndIf
      If Column = - 1
       Column = \ButtonID[Position]\NbItem
      ElseIf Column > \ButtonID[Position]\NbItem
       Column = \ButtonID[Position]\NbItem
      EndIf
     Texte.s = \ButtonID[Position]\ButtonID[Column]\Text
     PreviousStringPosition = @Texte
     ProcedureReturn \ButtonID[Position]\ButtonID[Column]\Text
    EndWith
  EndIf
EndProcedure
Procedure.l OB_SetGadgetItemText	(*gadget.PB_Gadget, Position.l, Text.s, Column.l)
 If *gadget
  Protected *info.S_ROutlookBar = GetProp_(*gadget\gadget, "ROutlookBar_Info")
    With *info
      If Position = - 1
        Position = \NbHeader
      ElseIf Position > \NbHeader
        Position = \NbHeader
      EndIf
      If Column = - 1
       Column = \ButtonID[Position]\NbItem
      ElseIf Column > \ButtonID[Position]\NbItem
       Column = \ButtonID[Position]\NbItem
      EndIf
     \ButtonID[Position]\ButtonID[Column]\Text = Text
     If Position = \State
       OB_SetGadgetState(*gadget, Position)
     EndIf
     ProcedureReturn #True
    EndWith
  EndIf
EndProcedure
Procedure OB_GetGadgetAttribute(*gadget.PB_Gadget, Attribute.l)
 If *gadget
  Protected *info.S_ROutlookBar = GetProp_(*gadget\gadget, "ROutlookBar_Info")
    With *info
      Select Attribute
        Case #OutlookBar_HeightHeader
          ProcedureReturn \ButtonHeight
      EndSelect
    EndWith
  EndIf
EndProcedure
Procedure OB_SetGadgetAttribute(*gadget.PB_Gadget, Attribute.l, Value.l)
 If *gadget
  Protected *info.S_ROutlookBar = GetProp_(*gadget\gadget, "ROutlookBar_Info")
    With *info
      Select Attribute
        Case #OutlookBar_HeightHeader
          \ButtonHeight = Value
          OB_ResizeGadget(*gadget, #PB_Ignore, #PB_Ignore, #PB_Ignore, #PB_Ignore)
      EndSelect
    EndWith
  EndIf
EndProcedure
Procedure OB_GetGadgetColor(*gadget.PB_Gadget, ColorType.l)
 If *gadget
  Protected *info.S_ROutlookBar = GetProp_(*gadget\gadget, "ROutlookBar_Info")
    With *info
      Select  ColorType
        Case #PB_Gadget_FrontColor
          ProcedureReturn GetGadgetColor(\HwndListIcon, #PB_Gadget_FrontColor)
        Case #PB_Gadget_BackColor
          ProcedureReturn GetGadgetColor(\HwndListIcon, #PB_Gadget_BackColor)
      EndSelect
    EndWith
  EndIf
EndProcedure
Procedure OB_SetGadgetColor(*gadget.PB_Gadget, ColorType.l, Color.l)
 If *gadget
  Protected *info.S_ROutlookBar = GetProp_(*gadget\gadget, "ROutlookBar_Info")
    With *info
      Select ColorType
        Case #PB_Gadget_FrontColor
          ProcedureReturn SetGadgetColor(\HwndListIcon, #PB_Gadget_FrontColor, Color)
        Case #PB_Gadget_BackColor
          ProcedureReturn SetGadgetColor(\HwndListIcon, #PB_Gadget_BackColor, Color)
      EndSelect
    EndWith
  EndIf
EndProcedure
Procedure OB_GetGadgetItemColor2(*gadget.PB_Gadget, Item, ColorType.l, Color.l, Column.l)
 If *gadget
  Protected *info.S_ROutlookBar = GetProp_(*gadget\gadget, "ROutlookBar_Info")
    With *info
      If Item <= 0        : Item = 1          : EndIf
      If Item > \NbHeader : Item = \NbHeader  : EndIf
      ProcedureReturn GetGadgetColor(\ButtonID[Item - 1]\ID, ColorType)
    EndWith
  EndIf
EndProcedure
Procedure OB_SetGadgetItemColor2(*gadget.PB_Gadget, Item, ColorType.l, Column.l)
 If *gadget
  Protected *info.S_ROutlookBar = GetProp_(*gadget\gadget, "ROutlookBar_Info")
    With *info
      If Item <= 0        : Item = 1          : EndIf
      If Item > \NbHeader : Item = \NbHeader  : EndIf
      ProcedureReturn SetGadgetColor(\ButtonID[Item - 1]\ID, ColorType, Color)
    EndWith
  EndIf
EndProcedure
Procedure OB_GetGadgetItemData(*gadget.PB_Gadget, Item, Value.l)
 If *gadget
  Protected *info.S_ROutlookBar = GetProp_(*gadget\gadget, "ROutlookBar_Info")
    With *info
      If Item <= 0        : Item = 1          : EndIf
      If Item > \NbHeader : Item = \NbHeader  : EndIf
      ProcedureReturn GetGadgetData(\ButtonID[Item - 1]\ID)
    EndWith
  EndIf
EndProcedure
Procedure OB_SetGadgetItemData(*gadget.PB_Gadget, Item, Value.l)
 If *gadget
  Protected *info.S_ROutlookBar = GetProp_(*gadget\gadget, "ROutlookBar_Info")
    With *info
      If Item <= 0        : Item = 1          : EndIf
      If Item > \NbHeader : Item = \NbHeader  : EndIf
      ProcedureReturn SetGadgetData(\ButtonID[Item - 1]\ID, Value)
    EndWith
  EndIf
EndProcedure


Procedure OB_(*gadget.PB_Gadget)
 If *gadget
  Protected *info.S_ROutlookBar = GetProp_(*gadget\gadget, "ROutlookBar_Info")
    With *info
    EndWith
  EndIf
EndProcedure

Procedure OutlookBarGadget			(ID.l, x, y, width, height, style.l)
  Protected *info.S_ROutlookBar
  Protected Hwnd_Tmp.l, Hwnd.l
  Protected StaticID.l
  Protected vt.PB_GadgetVT
  With vt
   \GadgetType								=	@OB_GadgetType()
; 	  \SizeOf
; 	  \GadgetCallback
   \FreeGadget								=	@OB_FreeGadget()
   \GetGadgetState						=	@OB_GetGadgetState()
   \SetGadgetState						=	@OB_SetGadgetState()
; 	  \GetGadgetText
; 	  \SetGadgetText
;	  \AddGadgetItem2						= @OB_AddGadgetItem2()
   \AddGadgetItem3						= @OB_AddGadgetItem3()
    \RemoveGadgetItem					=	@OB_RemoveGadgetItem()
; 	  \ClearGadgetItemList
    \ResizeGadget							=	@OB_ResizeGadget()
    \CountGadgetItems         = @OB_CountGadgetItems()
; 	  \GetGadgetItemState
; 	  \SetGadgetItemState
    \GetGadgetItemText				=	@OB_GetGadgetItemText()
    \SetGadgetItemText				=	@OB_SetGadgetItemText()
; 	  \OpenGadgetList2
    \GadgetX									=	@OB_GadgetX()
    \GadgetY									=	@OB_GadgetY()
    \GadgetWidth							=	@OB_GadgetWidth()
    \GadgetHeight							=	@OB_GadgetHeight()
    \HideGadget								=	@OB_HideGadget()
; 	  \AddGadgetColumn
; 	  \RemoveGadgetColumn
    \GetGadgetAttribute       = @OB_GetGadgetAttribute()
    \SetGadgetAttribute       = @OB_SetGadgetAttribute()
; 	  \GetGadgetItemAttribute2	=
; 	  \SetGadgetItemAttribute2
    \GetGadgetColor           = @OB_GetGadgetColor()
    \SetGadgetColor           = @OB_SetGadgetColor()
    \SetGadgetItemColor2      = @OB_SetGadgetItemColor2()
    \GetGadgetItemColor2      = @OB_GetGadgetItemColor2()
   \SetGadgetItemData        = @OB_SetGadgetItemData()
   \GetGadgetItemData        = @OB_GetGadgetItemData()
  EndWith

  Hwnd_Tmp = Gadget_Create(ID, "ROutlookBar", "", #WS_BORDER|#WS_CHILD|#WS_VISIBLE, x, y, width, height, 0, 0, @vt, @OB_CallbackOB())
  If ID = #PB_Any
    Hwnd = WindowID(Hwnd_Tmp)
  Else
    Hwnd = Hwnd_Tmp
  EndIf
 *info 						= AllocateMemory(SizeOf(S_ROutlookBar))
 *info\HwndParent	=	Gadget_GetParent()
  CreateGadgetList(Hwnd)
    StaticID = ImageGadget(#PB_Any, 0, 0, width, height, 0)
    With *info
      \Hwnd         = Hwnd
      \HwndStaticBg = StaticID
      SetProp_(GadgetID(\HwndStaticBg), "HwndStaticBg_Proc", SetWindowLong_(GadgetID(\HwndStaticBg), #GWL_WNDPROC, @OB_CallbackStaticBg()))
      \NbHeader     = 0
      \Height       = height
      \Width        = width
      \X						=	x
      \Y						=	y
      \ButtonHeight = 20
    EndWith
    SetProp_(Hwnd, "ROutlookBar_Info", *info)
    ProcedureReturn Hwnd_Tmp
EndProcedure
;- Inc_OutlookBar
Global Quit
Global SystemPath.s
SystemPath  = Space(255)
Result      = GetSystemDirectory_(SystemPath, 255)

OpenWindow(0, 0, 0, 800, 600, "OutlookBar", #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_Invisible)
CreateGadgetList(WindowID(0))
 OutlookBarGadget(10, 10, 10, 100, 250, 0)
   AddGadgetItem(10, - 1, "Truc0")
   AddGadgetItem(10, 01, "Truc1")
   AddGadgetItem(10, 02, "Truc2")
   AddGadgetItem(10, - 1, "Truc3")
   AddGadgetItem(10, - 1, "Truc4")
  AddGadgetItem(10, 03, "Truc5")
  AddGadgetItem(10, 00, "Truc00", ExtractIcon_(0, SystemPath + "\Shell32.dll", 0), 0)
  AddGadgetItem(10, 00, "Truc01", ExtractIcon_(0, SystemPath + "\Shell32.dll", 1), 1)
  AddGadgetItem(10, 01, "Truc02", ExtractIcon_(0, SystemPath + "\Shell32.dll", 2), 1)
  AddGadgetItem(10, - 1, "Truc03", ExtractIcon_(0, SystemPath + "\Shell32.dll", 3), 2)
  AddGadgetItem(10, 00, "Truc04", ExtractIcon_(0, SystemPath + "\Shell32.dll", 4), 3)
  AddGadgetItem(10, 01, "Truc05", ExtractIcon_(0, SystemPath + "\Shell32.dll", 5), 3)
  AddGadgetItem(10, 00, "Truc06", ExtractIcon_(0, SystemPath + "\Shell32.dll", 6), 4)
  AddGadgetItem(10, 00, "Truc07", ExtractIcon_(0, SystemPath + "\Shell32.dll", 7), 5)
  AddGadgetItem(10, - 1, "Truc08", ExtractIcon_(0, SystemPath + "\Shell32.dll", 8), 5)
  AddGadgetItem(10, - 1, "Truc09", ExtractIcon_(0, SystemPath + "\Shell32.dll", 9), 5)
  ; Debug GetGadgetState(10)
  SetGadgetState(10, 1)
  ; Debug GetGadgetState(10)

 ; CloseGadgetList()
 ButtonGadget(00, 700, 000, 100, 030, "RemoveGadgetItem")
 ButtonGadget(01, 700, 030, 100, 030, "CountGadgetItems")
 ButtonGadget(02, 700, 060, 100, 030, "Infos : X - Y - Width - Height", #PB_Button_MultiLine)
 ButtonGadget(03, 700, 090, 100, 030, "Hide : #True", #PB_Button_MultiLine)
 ButtonGadget(04, 700, 120, 100, 030, "Hide : #False", #PB_Button_MultiLine)
 ButtonGadget(05, 700, 150, 100, 030, "Resize", #PB_Button_MultiLine)
 ButtonGadget(06, 700, 180, 100, 030, "(G/S)etItemText", #PB_Button_MultiLine)
 ButtonGadget(07, 700, 210, 100, 030, "(G/S)", #PB_Button_MultiLine)
 ButtonGadget(08, 700, 240, 100, 030, "(G/S)", #PB_Button_MultiLine)
 ButtonGadget(09, 700, 270, 100, 030, "(G/S)", #PB_Button_MultiLine)
 
HideWindow(0, #False)
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0
          RemoveGadgetItem(10, 0)
        Case 1
          MessageRequester("OulookBar ", "Count : " + Str(CountGadgetItems(10)))
        Case 2
          MessageRequester("OulookBar ", "X : " + Str(GadgetX(10))+#EOL+"Y : " + Str(GadgetY(10))+#EOL+"Width : " + Str(GadgetWidth(10))+#EOL+"Height : " + Str(GadgetHeight(10)))
        Case 3
         HideGadget(10, #True)
        Case 4
         HideGadget(10, #False)
        Case 5
         ResizeGadget(10, 50, 50, 150, 300)
        Case 6
          MessageRequester("OulookBar ", "Before : " + GetGadgetItemText(10, 0, 0))
          SetGadgetItemText(10, 0, "NewText", 0)
          MessageRequester("OulookBar ", "After : " + GetGadgetItemText(10, 0, 0))
        Case 10
          Select EventType()
           Case #OutlookBar_Event_HeaderClicked
            Debug "#OutlookBar_Event_HeaderClicked"
      Case #OutlookBar_Event_ItemClicked
       Debug "#OutlookBar_Event_ItemClicked"
          EndSelect
      EndSelect
    Case #PB_Event_CloseWindow
      Quit = 1
  EndSelect
Until Quit = 1
FreeGadget(10)