' Gambas module file

' Private $hFadeN As Picture
' ' Private $hFadeW As Picture
' ' Private $hFadeS As Picture
' ' Private $hFadeE As Picture
' 
' Private Sub LoadFades()
'   
'   Dim hImage As Image
'   'Dim Y As Integer
'   Dim iColor As Integer
'   
'   iColor = Color.Desaturate(Color.TextForeground)
'   
'   'If iColor = $iFadeColor Then Return
'   
'   hImage = New Image(32, 8, Color.Transparent)
'   ' For Y = 0 To 7
'   '   hImage.FillRect(0, Y, hImage.W, 1, Color.SetAlpha(iColor, 160 + Y * 12))
'   ' Next
'   
'   $hFadeN = hImage.Picture
'   $hFadeN = hImage.Picture
'   ' hImage.RotateLeft
'   ' $hFadeW = hImage.Picture
'   ' hImage.RotateLeft
'   ' $hFadeS = hImage.Picture
'   ' hImage.RotateLeft
'   ' $hFadeE = hImage.Picture
'   
' End

Public Sub Main()

  Component.Load("gb.form")
  
  Message.Style = "integrated"
  'Message.ColoredButtons = True
  
  Message.Question("Ceci est un très long message qui doit permettre de tester la nouvelle disposition des boutons des boites de dialogues affichant des messages.", "Oui", "Non", "Peut-être")
  'Message.Warning("Ceci est un message.") ', "Oui", "Non")

End

Public Sub GetFileSize(iSize As Long, Optional nDigit As Integer = 1) As String

  Dim sFormat As String
  
  sFormat = "0." & String$(nDigit, "#")
  
  If iSize < 1024 Then
    Return Subst(("&1 B"), CStr(iSize))
  Else If iSize < 1048576 Then
    Return Subst(("&1 KiB"), Format(iSize / 1024, sFormat))
  Else If iSize < 1073741824 Then
    Return Subst(("&1 MiB"), Format(iSize / 1048576, sFormat))
  Else
    Return Subst(("&1 GiB"), Format(iSize / 1073741824, sFormat))
  Endif
  
End

Public Sub SplitHTML(Html As String) As String[]

  Dim P As Integer
  Dim iLen As Integer
  Dim C As String
  Dim sResult As String
  Dim C2 As String
  Dim aResult As String[]
  
  aResult = New String[]
  iLen = String.Len(Html)
  
READ_TEXT:
  
  GoSub LOOK_CHAR
  
  If C = "<" Then Goto READ_MARKUP
  If C = "&" Then Goto READ_ENTITY
  
  GoSub READ_CHAR
  Goto READ_TEXT
  
READ_MARKUP:

  GoSub ADD_RESULT
  GoSub READ_CHAR
  
READ_MARKUP_NAME:

  GoSub READ_CHAR
  
  If C = " " Then Goto READ_MARKUP_REST
  If C = ">" Then Goto READ_MARKUP_END
  
  Goto READ_MARKUP_NAME
  
READ_MARKUP_REST:

  GoSub READ_CHAR
  
  If C = ">" Then Goto READ_MARKUP_END
  
  If C = Chr$(34) Or If C = "'" Then 
    C2 = C
    Goto READ_STRING
  Endif
  
  Goto READ_MARKUP_REST

READ_MARKUP_END:

  GoSub ADD_RESULT
  Goto READ_TEXT

READ_STRING:

  GoSub READ_CHAR
  
  If C = C2 Then Goto READ_MARKUP
  
  Goto READ_STRING

READ_ENTITY:

  GoSub ADD_RESULT
  GoSub READ_CHAR

  Do
    GoSub READ_CHAR
    If Not IsDigit(C) And If Not IsLetter(C) And If C <> "#" Then Break
  Loop
  
  GoSub ADD_RESULT
  Goto READ_TEXT
  
LOOK_CHAR:

  If P >= iLen Then 
    C = ""
  Else
    C = String.Mid$(Html, P + 1, 1)
  Endif
  Return
  
READ_CHAR:

  Inc P
  If P > iLen Then
    GoSub ADD_RESULT
    Return aResult
  Endif
  C = String.Mid$(Html, P, 1)
  sResult &= C
  Return
  
ADD_RESULT:

  If sResult Then
    aResult.Add(sResult)
    sResult = ""
  Endif
  Return
  
End
