Commits (2)
......@@ -44,6 +44,7 @@ Private Sub Image_Write(Value As String)
$sImage = Value
Me.Refresh
If $sImage Then WebForm._AddPreload(Me._GetImageLink($sImage))
End
......@@ -56,6 +57,7 @@ End
Private Sub Shortcut_Write(Value As String)
If $sShortcut = Value Then Return
Me._RegisterShortcut(Value, $sShortcut)
$sShortcut = Value
Me.Refresh
......
......@@ -14,20 +14,34 @@ End
Public Sub SetButton(sButton1 As String, Optional sButton2 As String, sButton3 As String)
Dim hLast As WebButton
If sButton1 Then
btnButton1.Text = sButton1
btnButton1.Default = True
hLast = btnButton1
Endif
If sButton2 Then
btnButton2.Text = sButton2
btnButton2.Show
hLast = btnButton2
Endif
If sButton3 Then
btnButton3.Text = sButton3
btnButton3.Show
hLast = btnButton3
Endif
If Not hLast Then
btnButton1.Text = ("OK")
btnButton1.Default = True
hLast = btnButton1
Endif
If hLast Then hLast.Cancel = True
End
Public Sub _new()
......
......@@ -257,8 +257,8 @@ Public Sub WebSpinBox1_Change()
End
Public Sub WebTree1_Activate()
Public Sub WebMenu17_Click()
Message(WebTree1.Item.Text)
Message(Last.Text)
End
......@@ -224,7 +224,6 @@
}
{ WebTimer1 WebTimer
#MoveScaled(65,75)
Enabled = True
}
{ WebAudio1 WebAudio
#MoveScaled(78,77)
......
......@@ -28,6 +28,7 @@
{ WebButton1 WebButton
#MoveScaled(10,1,16,4)
Text = ("Cancel")
Cancel = True
}
{ WebHBox2 WebHBox
#MoveScaled(26,1,7,4)
......
' Gambas class file
Export
'Export
Static Public Sub _init()
WebForm.Debug = True
'WebForm.Debug = True
End
'
......@@ -26,10 +26,15 @@ Public Sub WebForm_KeyPress()
WebTextArea1.Text &= Last.Name & ": " & JSON.ToString(Key._Event) & " " & Key.Shortcut & " '" & Key.Text & "'\n"
End
'
'
' Public Sub WebTextBox1_KeyPress()
'
' WebTextArea1.Text &= Last.Name & ": " & JSON.ToString(Key._Event) & " " & Key.Shortcut & "\n"
'
' End
Public Sub WebTextBox1_KeyPress()
WebTextArea1.Text &= Last.Name & ": " & JSON.ToString(Key._Event) & " " & Key.Shortcut & "\n"
End
Public Sub WebForm_Open()
WebForm.Debug = True
End
......@@ -1164,9 +1164,10 @@ Private Sub PrintItem(hItem As _WebTreeItem, iLevel As Integer, bVisible As Bool
If $iMode <> Select.Single Then Print ",event";
Print ");\"";
Print Me._GetUpdateJS("ondblclick", "%" & JS(sKeyBase64));
Endif
Print Me._GetUpdateJS("ondblclick", "%" & JS(sKeyBase64));
If Not bVisible Then Print " style=\"display:none;\"";
Print ">";
......@@ -1297,6 +1298,7 @@ Public Sub _UpdateProperty(sProp As String, vValue As Variant)
Dim hItem As _WebTreeItem
Dim sKey As String
Dim sCursor As String
Dim bCancel As Boolean
If sProp Begins "^" Then
......@@ -1335,10 +1337,16 @@ Public Sub _UpdateProperty(sProp As String, vValue As Variant)
Else If sProp Begins "%" Then
sCursor = $sCursor
$sCursor = FromBase64(Mid$(sProp, 2))
Raise Activate
$sCursor = sCursor
If Object.CanRaise(Me, "Activate") Then
sCursor = $sCursor
$sCursor = FromBase64(Mid$(sProp, 2))
bCancel = Raise Activate
$sCursor = sCursor
Endif
If Not bCancel Then
hItem = $cItem[FromBase64(Mid$(sProp, 2))]
If hItem.Children Then hItem.Expanded = Not hItem.Expanded
Endif
Else If sProp = "#scroll" Then
......
......@@ -5,7 +5,7 @@
Export
Inherits WebControl
Public Const _Properties As String = "*,Border=True,Text,Image{WebImage},Immediate,ShowArrow"
Public Const _Properties As String = "*,Border=True,Text,Image{WebImage},Immediate,ShowArrow,Default,Cancel"
'Public Const _DrawWith As String '= "Button"
Public Const _DefaultEvent As String = "Click"
Public Const _DefaultSize As String = "16,4"
......@@ -33,6 +33,9 @@ Property Immediate As Boolean
'' Return or set if the button displays an arrow
Property ShowArrow As Boolean
Property Default As Boolean
Property Cancel As Boolean
Private $sText As String
Private $sImage As String
Private $bImmediate As Boolean
......@@ -83,8 +86,12 @@ End
Public Sub _BeforeRender()
Dim vSave As Variant
Dim sClass As String
sClass = "gw-button"
If Me.Default Then sClass &= " gw-button-default"
Print "<div"; Me._GetClassId();
Print "<div"; Me._GetClassId(sClass);
If Me.Enabled Then
If $bImmediate Then
Print " onclick=\"";
......@@ -169,3 +176,36 @@ Private Sub ShowArrow_Write(Value As Boolean)
Me.Refresh
End
Private Function Default_Read() As Boolean
Return Me._GetTopLevel()._GetDefault() = Me.Id
End
Private Sub Default_Write(Value As Boolean)
If Value Then
Me._GetTopLevel()._SetDefault(Me)
Else If Default_Read() Then
Me._GetTopLevel()._SetDefault(Null)
Endif
End
Private Function Cancel_Read() As Boolean
Return Me._GetTopLevel()._GetCancel() = Me.Id
End
Private Sub Cancel_Write(Value As Boolean)
If Value Then
Me._GetTopLevel()._SetCancel(Me)
Else If Default_Read() Then
Me._GetTopLevel()._SetCancel(Null)
Endif
End
......@@ -87,6 +87,8 @@ Static Private $aStyleSheet As String[]
Static Public _NextName As String
Static Public _Shortcuts As New Collection
Public _Refresh As Boolean
Public _EventName As String
Public _Proxy As String
......@@ -1181,14 +1183,56 @@ Public Sub ToHTML() As String
End
Public Sub _RaiseKeyPress(cEvent As Variant)
Public Sub _RaiseKeyPress(cEvent As Variant) As Boolean
Dim cSave As Collection
Dim bCancel As Boolean
cSave = Key._Event
Key._Event = cEvent
Object.Raise(Me, "KeyPress")
bCancel = Raise KeyPress
Key._Event = cSave
WebForm.Print("_RaiseKeyPress: " & Str(bCancel))
Return bCancel
End
Public Sub _RegisterShortcut(sShortcut As String, sPrevious As String)
Dim aShortcut As Integer[]
Dim iPos As Integer
If sPrevious Then
sPrevious = String.UCase(sPrevious)
aShortcut = _Shortcuts[sPrevious]
If aShortcut Then
iPos = aShortcut.Find($iId)
If iPos Then aShortcut.Remove(iPos)
Endif
Endif
If sShortcut Then
sShortcut = String.UCase(sShortcut)
aShortcut = _Shortcuts[sShortcut]
If Not aShortcut Then
aShortcut = New Integer[]
_Shortcuts[sShortcut] = aShortcut
Endif
aShortcut.Add($iId)
Endif
End
Public Sub _GetTopLevel() As WebForm
Dim hForm As WebForm
Dim hParent As WebContainer
hForm = Me.Form
Do
hParent = hForm.Parent
If Not hParent Or If hForm._Window Then Return hForm
hForm = hForm.Form
Loop
End
......@@ -63,6 +63,7 @@ Static Public _DisableRefresh As Integer
Static Public _HasRefresh As Boolean
Static Public _InMessage As Integer
Static Public _CurrentPopup As WebForm
Static Public _CurrentModal As WebForm
Static Private _Current As WebForm
......@@ -79,6 +80,7 @@ Static Private $iEventLoopLevel As Integer
Static Private $aJavascript As New String[]
Static Private $aJavascriptBefore As New String[]
Static Private $cPreload As New Collection
Public _Loaded As Boolean
Public _Window As Integer
......@@ -103,6 +105,8 @@ Private $aJavascriptExternFiles As String[]
Private $aHeaders As String[]
Private $aShortcuts As String[]
Private $iDefault As Integer
Private $iCancel As Integer
'Private $bOpened As Boolean
......@@ -747,7 +751,8 @@ Public Sub _BeforeRender()
If Me.Class Then Print " "; Me.Class;
Print "\" id=\""; Me.Name; "\"";
Me._RenderStyleSheet()
Print Me._GetKeyPressHandler();
'Print Me._GetKeyPressHandler();
If Object.CanRaise(Me, "KeyPress") Or If $iDefault Or If $iCancel Then Print " onkeydown=\"gw.onkeydown(" & JS(Me.Name) & ", event)\"";
Print ">"
DisableShortcuts()
......@@ -757,6 +762,7 @@ End
Public Sub Render()
Dim sImage As String
Dim aPreload As String[]
Response.Buffered = True
Response.Begin
......@@ -770,11 +776,20 @@ Public Sub Render()
Print "<body"; Me._GetEventJS("onload", "open"); ">"
Print "<div id=\"gw-preload\" style=\"display:none;\">";
For Each sImage In ["error.png", "info.png", "question.png", "warning.png"]
Print "<img src=\""; Application.Root &/ "message" &/ sImage; "\">";
_AddPreload(Application.Root &/ "message" &/ sImage)
Next
Print "</div>"
For Each sImage In ["gw-arrow-down.png", "gw-arrow-left.png", "gw-arrow-right.png", "gw-arrow-up.png", "gw-close.png"]
_AddPreload(Application.Root &/ sImage)
Next
aPreload = New String[]
For Each $cPreload
aPreload.Add($cPreload.Key)
Next
$aJavascript.Add("gw.image.preload(" & JS(aPreload) & ")")
Print "<div id=\"gw-modal\" onclick=\"gw.window.onDownModal();\" onmouseover=\"gw.window.onDownModal(true);\"></div>"
Print "<div id=\"gw-lock\">"
......@@ -887,6 +902,23 @@ Private Sub Resizable_Write(Value As Boolean)
End
Private Sub HandleKeyPress(sName As String, vEvent As Variant)
Dim hCtrl As WebControl
Dim hForm As WebForm
If sName Then
hCtrl = WebControl.FromName(sName)
If hCtrl Then hCtrl._RaiseKeyPress(vEvent)
Else
hForm = _CurrentPopup
If Not hForm Then hForm = _CurrentModal
If Not hForm Then hForm = Me
hForm._RaiseKeyPress(vEvent)
Endif
End
Public Sub _HandleMessage()
Dim hCtrl As WebControl
......@@ -937,11 +969,7 @@ Public Sub _HandleMessage()
Case "keypress"
If aCmd[1] Then
hCtrl = WebControl.FromName(aCmd[1])
If hCtrl Then hCtrl._RaiseKeyPress(aCmd[2])
Endif
Me._RaiseKeyPress(aCmd[2])
HandleKeyPress(aCmd[1], aCmd[2])
Case "finish"
......@@ -1135,7 +1163,7 @@ Private Sub RunEventLoop()
Inc $iEventLoopLevel
iLevel = $iEventLoopLevel
PrintLog("RunEventLoop -> " & $iEventLoopLevel)
Raise Open
If $iEventLoopLevel = iLevel Then
......@@ -1167,6 +1195,7 @@ Public Sub ShowModal(Optional Parent As WebControl) As Variant
Dim hWindow As WebWindow
Dim vReturn As Variant
Dim hPrevious As WebForm
If Me.Parent Then Error.Raise("Form is embedded")
If _Window = 0 Then DoShow()
......@@ -1178,8 +1207,13 @@ Public Sub ShowModal(Optional Parent As WebControl) As Variant
If Parent Then hWindow.ParentControl = Parent.Name
Endif
hPrevious = _CurrentModal
_CurrentModal = Me
RunEventLoop
_CurrentModal = hPRevious
vReturn = $vEventLoopReturn
$vEventLoopReturn = Null
Return vReturn
......@@ -1411,13 +1445,14 @@ End
Private Sub DisableShortcuts()
Dim cShortcut As Collection
Dim cShortcut As New Collection
Dim sShortcut As String
cShortcut = New Collection
FindShortcut($hMenuBar, cShortcut)
For Each WebControl._Shortcuts
sShortcut = WebControl._Shortcuts.Key
cShortcut[sShortcut] = True
Next
If $aShortcuts Then
For Each sShortcut In $aShortcuts
sShortcut = Trim(sShortcut)
......@@ -1432,39 +1467,54 @@ Private Sub DisableShortcuts()
End
Private Sub TriggerShortcut(hParent As WebContainer, sShortcut As String) As Boolean
Dim hChild As WebControl
Dim hMenu As WebMenu
Private Sub TriggerShortcut(sShortcut As String) As Boolean
For Each hChild In hParent.Children
hMenu = hChild
If Not hMenu.Enabled Then Continue
If String.UCase(hMenu.Shortcut) = sShortcut Then
Object.Raise(hChild, "Click")
Return True
Else If hMenu.HasChildren() And If TriggerShortcut(hChild, sShortcut) Then
Return True
Endif
Next
Dim aShortcut As Integer[]
Dim iId As Integer
Dim hCtrl As WebControl
Dim hButton As WebButton
sShortcut = String.UCase(sShortcut)
aShortcut = WebControl._Shortcuts[sShortcut]
If aShortcut Then
For Each iId In aShortcut
hCtrl = WebControl.FromId(iId)
If hCtrl.IsHidden() Then Continue
If Not hCtrl.Enabled Then Continue
If hCtrl Is WebMenu Then
Object.Raise(hCtrl, "Click")
Return True
Endif
Next
Endif
WebForm.Print("TriggerShortcut: " & Me.Name & ": " & sShortcut & " / " & $iDefault & " / " & $iCancel)
If $iDefault And If sShortcut = "ENTER" Then
hButton = WebControl.FromId($iDefault)
hButton.Click()
Return True
Else If $iCancel And If sShortcut = "ESCAPE" Then
hButton = WebControl.FromId($iCancel)
hButton.Click()
Return True
Endif
End
Public Sub _RaiseKeyPress(cEvent As Variant)
Public Sub _RaiseKeyPress(cEvent As Variant) As Boolean
Dim cSave As Collection
Dim sShortcut As String
Super._RaiseKeyPress(cEvent)
If Not $hMenuBar.HasChildren() Then Return
If Super._RaiseKeyPress(cEvent) Then Return True
cSave = Key._Event
Key._Event = cEvent
sShortcut = Key.Shortcut
Key._Event = cSave
TriggerShortcut($hMenuBar, String.UCase(sShortcut))
Return TriggerShortcut(sShortcut)
End
......@@ -1480,3 +1530,41 @@ Private Sub Shortcuts_Write(Value As String[])
$aShortcuts = Value
End
Public Sub _GetDefault() As Integer
Return $iDefault
End
Public Sub _SetDefault(hCtrl As WebControl)
If hCtrl Then
$iDefault = hCtrl.Id
Else
$iDefault = 0
Endif
End
Public Sub _GetCancel() As Integer
Return $iCancel
End
Public Sub _SetCancel(hCtrl As WebControl)
If hCtrl Then
$iCancel = hCtrl.Id
Else
$iCancel = 0
Endif
End
Static Public Sub _AddPreload(sLink As String)
$cPreload[sLink] = True
End
......@@ -776,6 +776,7 @@ gw = {
$(gw.windows[i]).style.zIndex = 11 + i * 2;
gw.window.updateTitleBars();
$(id).focus();
if (send)
gw.update('', '#windows', gw.windows);
......@@ -1581,6 +1582,21 @@ gw = {
}
},
image:
{
preload: function(images)
{
var image;
var i;
for (i = 0; i < images.length; i++)
{
image = new Image();
image.src = images[i];
}
}
},
sound:
{
pause: function(id)
......@@ -1617,23 +1633,8 @@ gw = {
return shortcut;
},
onkeydown: function(event)
sendKeyPress: function(event, id)
{
if (!event.bubbles)
return;
var elt = document.activeElement;
var id = '';
while (elt)
{
id = elt.id;
if (id && id.indexOf(':') < 0)
break;
elt = elt.parentNode;
id = '';
}
gw.send(['keypress', id,
{
'altKey': event.altKey,
......@@ -1643,15 +1644,39 @@ gw = {
'shiftKey': event.shiftKey
}],
null);
},
onkeydown: function(id, event)
{
if (!event.bubbles)
return;
if (gw.shortcuts)
var elt = $(id);
while (elt)
{
id = elt.id;
if (id && id.indexOf(':') < 0)
break;
elt = elt.parentNode;
id = '';
}
gw.sendKeyPress(event, id);
},
onshortcut: function(event)
{
if (event.bubbles && gw.shortcuts)
{
gw.sendKeyPress(event, '');
var shortcut = gw.makeShortcut(event);
gw.log('shortcut -> ' + shortcut);
if (gw.shortcuts[shortcut])
{
gw.log('shortcut -> ' + shortcut);
event.preventDefault();
}
}
}
},
}
document.onkeydown = gw.onkeydown;
document.onkeydown = gw.onshortcut;
......@@ -69,6 +69,10 @@ P:first-child,UL:first-child,OL:first-child {
user-select: none;
}
.gw-button-default {
border-width: 2px;
}
.gw-button:active {
background-color: #E0E0E0;
}
......