tu hai idee?
" O San Midi (https://it.wikipedia.org/wiki/Musical_Instrument_Digital_Interface) eremita,
per quali funesti luoghi il dolore me conduce ?
Tetro è il buio opprimente la mia triste vita.
Poi d'un tratto a me doni, benigno, la tua luce. "
sanmidi
Private Menu1 As Menu
Private Menu2 As Menu
Private Menu3 As Menu
Private Menu4 As Menu
Private Label1 As Label
Private tm As Timer
Public Sub Form_Open()
With Menu1 = New Menu(Me) As "Menu1"
.Caption = "Menu1"
End With
With Menu2 = New Menu(Menu1) As "Menu2"
.Caption = "Menu2"
.Tag = "Questo è il Menu2 !"
End With
With Menu3 = New Menu(Menu1) As "Menu3"
.Caption = "Menu3"
.Tag = "Questo è il Menu3 !"
End With
With Menu4 = New Menu(Menu1) As "Menu4"
.Caption = "Menu4"
.Tag = "Questo è il Menu4 !"
End With
With Label1 = New Label(Me)
.W = 200
.H = 30
.X = (Me.W * 0.5) - (.W * 0.5)
.Y = Me.H * 0.6
.Border = Border.Plain
.Alignment = Align.Center
.Foreground = Color.Red
End With
End
Public Sub Menu1_Show()
With tm = New Timer As "Tempus"
.Delay = 30
.Start
End With
End
Public Sub Tempus_Timer()
Dim rt2 As New Rect(Me.ScreenX + 10, Me.ScreenY + 26, Me.Font.TextWidth(Menu2.Caption) + 20, Me.Font.TextHeight(Menu2.Caption))
Dim rt3 As New Rect(Me.ScreenX + 10, Me.ScreenY + 50, Me.Font.TextWidth(Menu3.Caption) + 20, Me.Font.TextHeight(Menu3.Caption))
Dim rt4 As New Rect(Me.ScreenX + 10, Me.ScreenY + 72, Me.Font.TextWidth(Menu4.Caption) + 20, Me.Font.TextHeight(Menu4.Caption))
Label1.Text = Null
If rt2.Contains(Mouse.ScreenX, Mouse.ScreenY) Then Label1.Text = Menu2.Tag
If rt3.Contains(Mouse.ScreenX, Mouse.ScreenY) Then Label1.Text = Menu3.Tag
If rt4.Contains(Mouse.ScreenX, Mouse.ScreenY) Then Label1.Text = Menu4.Tag
End
Public Sub Menu1_Hide()
tm.Stop
End
Ciao, certo chiedere di inserire l'evento sarebbe la cosa più pulita da fare, anche perchè ovviamente un timer è un controllo "dispendioso" (almeno in Windows)
In attesa però ho implementato e modificato il codice di vuott e ho ottenuto il risultato che volevo, sia per il menù (che appare premendo il menù button), sia per l'eventuale sotto menù.
Gianluigi , perchè dici che i menù button non stanno sempre nella stessa posizione?
In ogni caso io non considerato nessuna coordinata fissa. Ogni controllo (tranne i menù) ha la proprietà ScreenX e ScreenY, dunque sappiamo sempre dove sono e il menù parte sempre dalla X del bottone e dalla sua Y + la sua H. Stessa cosa i sotto menù che hanno una X che parte dalla X del bottone + la len della parola più lunga, e una Y che si riferisce al menù selezionato. Non è preciso al millimetro ma per adesso che sono all'inizio dell'applicazione pò bastare.
Qui il codice, magari viene fuori un idea per ottimizzarlo
Public Sub tmrMouse_Timer()
Dim c As Menu
Dim cc As Menu
Dim rects As New Rect[]
Dim rt As Rect
Dim idxs As New Integer[]
Dim idxs2 As New Integer[]
Dim idx As Integer = 0
Dim iRt As Integer
Dim longStr As String
If Not IsNull(selMenu)
If Not selMenu.Closed Then
For Each c In selMenu.Children
rt = New Rect(scrnX, (scrnY + (25 * rects.Count)), rectW, rectH)
rects.Add(rt)
idxs.Add(rects.Count)
idxs2.Add(0)
Next
For Each c In selMenu.Children
If c.Children.Count > 0 Then
If Not c.Closed Then
'prima cercare la stringa piç lunga
For iRt = 0 To (c.Children.count - 1)
If Len(c.Children[iRt].Caption) > Len(longStr) Then
longStr = c.Children[iRt].Caption
Endif
Next
rectW = Me.Font.TextWidth(longStr) + 50
For iRt = 0 To (c.Children.count - 1)
rt = New Rect((scrnX + rectW), (rects[idx].Y + (25 * iRt)), rectW, rectH)
rects.Add(rt)
idxs.Add(idx)
idxs2.Add(iRt)
Next
Endif
Endif
idx = idx + 1
Next
lblMessage.Text = Null
For iRt = 0 To (rects.count - 1)
If rects[iRt].Contains(Mouse.ScreenX, Mouse.ScreenY) Then
If iRt < selMenu.Children.Count Then
lblMessage.text = selMenu.Children[iRt].Tag
Else
lblMessage.text = selMenu.Children[idxs[iRt]].Children[idxs2[iRt]].Tag
Endif
Break
Endif
Next
Endif
Endif
End
Public Sub btnMenu_Enter()
Dim c As Menu
Dim cc As Menu
Dim longStr As String
scrnX = Last.ScreenX + 10
scrnY = (Last.ScreenY + Last.Height + 10)
For Each c In Me.Menus
If c.name = Last.Menu Then
selMenu = c
If c.Children.Count > 0 Then
For Each cc In c.Children
If Len(cc.Caption) > Len(longStr) Then
longStr = cc.Caption
Endif
Next
Endif
Endif
Next
rectH = Last.Font.TextHeight(longStr)
rectW = Last.Font.TextWidth(longStr) + 30
End
Si, corretto, ma pare che nella master (la versione di sviluppo) ci sia un bug, almeno credo.
Se clicchi sul menu Help della IDE (quello col punto interrogativo) > Informazioni di sistema, nella finestra che appare, sotto System c'è il tipo di Gambas che stai usando.
Puoi comunicarmelo?
Ecco, ma non mi fare domande hardware perchè lì sono una vera schiappa. Lavoro su di una macchina virtuale che mi ha preparato il mio collega spagnolo.
[System]
Gambas=3.11.4
OperatingSystem=Linux
Kernel=3.10.0-957.27.2.el7.x86_64
Architecture=x86_64
Distribution=redhat CentOS Linux release 7.6.1810 (Core)
Desktop=MATE
Theme=Windows
Language=es_ES.UTF-8
Memory=7803M
[Libraries]
Cairo=libcairo.so.2.11512.0
DBus=libdbus-1.so.3.14.14
GTK+2=libgtk-x11-2.0.so.0.2400.31
OpenGL=libGL.so.1.7.0
[Environment]
B_LKPATH=<home>/pgr:.
B_MACAD=00:19:5B:6F:59:FE
B_MACLO=15
B_MACNA=1
B_MACNU=8
B_MACPC=118
B_MACPW=DFHLLH
B_MACSN=2130
B_PATH=<home>/files:.
B_TERMTYPE=COHERENT
B_YR2000=50
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-QzvpQP3gX2,guid=d6a35df8f49987b239af415b5e6f1c63
DESKTOP_SESSION=mate
DISPLAY=:0
EDITOR=vi
GB_GUI=gb.qt4
GDMSESSION=mate
GDM_LANG=es_ES.UTF-8
GIO_LAUNCHED_DESKTOP_FILE=<home>/Escritorio/GAMBAS.desktop
GIO_LAUNCHED_DESKTOP_FILE_PID=6965
GTK_IM_MODULE=gtk-im-context-simple
GTK_OVERLAY_SCROLLING=0
HISTCONTROL=ignoredups
HISTSIZE=1000
HOME=<home>
HOSTNAME=<hostname>
IMSETTINGS_INTEGRATE_DESKTOP=yes
IMSETTINGS_MODULE=none
LANG=es_ES.UTF-8
LESSOPEN=||/usr/bin/lesspipe.sh %s
LOGNAME=<user>
MAIL=/var/spool/mail/<user>
MATE_DESKTOP_SESSION_ID=this-is-deprecated
OLDPWD=<home>
PATH=<home>/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:<home>/pgr:<home>/bin
PWD=<home>/files
QT_GRAPHICSSYSTEM_CHECKED=1
QT_IM_MODULE=xim
SESSION_MANAGER=local/unix:@/tmp/.ICE-unix/4808,unix/unix:/tmp/.ICE-unix/4808
SHELL=/bin/bash
SHLVL=1
SSH_AGENT_PID=4971
SSH_AUTH_SOCK=/run/user/1001/keyring/ssh
TERM=dumb
TTY=
TZ=:/etc/localtime
USER=<user>
USERNAME=<user>
WINDOWPATH=1
XAUTHORITY=/run/gdm/auth-for-<user>-UMYZf4/database
XDG_CURRENT_DESKTOP=MATE
XDG_DATA_DIRS=<home>/.local/share/flatpak/exports/share/:/var/lib/flatpak/exports/share/:/usr/local/share/:/usr/share/
XDG_RUNTIME_DIR=/run/user/1001
XDG_SEAT=seat0
XDG_SESSION_DESKTOP=mate
XDG_SESSION_ID=1
XDG_SESSION_TYPE=x11
XDG_VTNR=1
XMODIFIERS=@im=none
_=/usr/bin/mate-session
Grazie dei suggerimenti. Per il bugtraker lo faccio entro oggi
Prego, speriamo che ti risponda positivamente...
Visto che Minisini ha risposto picche riguardo alla richiesta delle nuova proprietà Select per i menu, propongo questo nuovo calcolo della dimensione dei menu che dovrebbe tener conto delle diverse situazioni Desktop.
Private Menu1 As Menu
Private Menu2 As Menu
Private Menu3 As Menu
Private Menu4 As Menu
Private tm As Timer
Private $iOLdText As Integer
Private $iNewText As Integer
Private $iOldShortcut As Integer
Private $iNewShortcut As Integer
Private $iPicture As Integer
Private $iFirstMenuWidth As Integer
Private $hLabel As Label
Public Sub Form_Open()
Dim DS As Integer = Desktop.Scale
Dim hMenu, hMenu2 As Menu
Dim hSpring As Spring
Dim hHBox As HBox
With Menu1 = New Menu(Me) As "Menu1"
.Caption = "Menu1"
End With
With Menu2 = New Menu(Menu1) As "Menu2"
.Caption = "Menu2"
.Shortcut = "ALT+O"
.Picture = Picture["icon:/16/open"]
.Tag = "Questo è il Menu2 !"
End With
With Menu3 = New Menu(Menu1) As "Menu3"
.Caption = "Menu menu menu3"
.Tag = "Questo è il Menu3 !"
End With
With Menu4 = New Menu(Menu1) As "Menu4"
.Caption = "Menu menu 4"
.Shortcut = "CTRL+M"
.Tag = "Questo è il Menu4 !"
End With
Me.Arrangement = Arrange.Vertical
Me.Margin = True
hSpring = New Spring(Me)
hHBox = New HBox(Me)
hHBox.H = 40
$hLabel = New Label(hHBox)
$hLabel.Expand = True
' Calcolo che dovrebbe tenere conto degli spazi basandosi su Desktop.Scale
For Each hMenu In Me.Menus
Print hMenu.Name
If hMenu.Children.Count > 0 Then Print "CHILDREN"
For Each hMenu2 In hMenu.Children
Print hMenu2.Name
If hMenu2.Picture Then $iPicture = 16
If hMenu2.Shortcut Then
$iNewShortcut = Me.Font.TextWidth(hMenu2.Shortcut)
If $iOldShortcut < $iNewShortcut Then $iOldShortcut = $iNewShortcut
Endif
$iNewText = Me.Font.TextWidth(hMenu2.Caption)
If $iOLdText < $iNewText Then $iOLdText = $iNewText
Next
$iFirstMenuWidth = DS + $iPicture + (DS * 3) + $iOLdText + (DS * 6) + $iOldShortcut
Next
End
Public Sub Menu1_Show()
With tm = New Timer As "Tempus"
.Delay = 50
.Start
End With
End
Public Sub Tempus_Timer()
Dim DS As Integer = Desktop.Scale
Dim hRect2 As New Rect(Menu1.Window.X + DS, Menu1.Window.Y + (DS * 3), $iFirstMenuWidth, DS * 3)
Dim hRect3 As New Rect(Menu1.Window.X + DS, Menu1.Window.Y + (DS * 3) * 2, $iFirstMenuWidth, DS * 3)
Dim hRect4 As New Rect(Menu1.Window.X + DS, Menu1.Window.Y + (DS * 3) * 3, $iFirstMenuWidth, DS * 3)
$hLabel.Text = Null
If hRect2.Contains(Mouse.ScreenX, Mouse.ScreenY) Then $hLabel.Text = Menu2.Tag
If hRect3.Contains(Mouse.ScreenX, Mouse.ScreenY) Then $hLabel.Text = Menu3.Tag
If hRect4.Contains(Mouse.ScreenX, Mouse.ScreenY) Then $hLabel.Text = Menu4.Tag
End
Public Sub Menu1_Hide()
tm.Stop
End
:ciao:
Dimenticavo naturalmente usando il componente gb.gui.qt (no gtk)