[windows] Fix radio group menu items

This commit is contained in:
Lea Anthony 2024-12-06 22:00:43 +11:00
commit 7cbde83f38
No known key found for this signature in database
GPG key ID: 33DAF7BB90A58405
6 changed files with 37 additions and 18 deletions

View file

@ -57,6 +57,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed `AlwaysOnTop` not working on Mac by [leaanthony](https://github.com/leaanthony) in [#3841](https://github.com/wailsapp/wails/pull/3841)
- [darwin] Fixed `application.NewEditMenu` including a duplicate `PasteAndMatchStyle` role in the edit menu on Darwin by [johnmccabe](https://github.com/johnmccabe) in [#3839](https://github.com/wailsapp/wails/pull/3839)
- [linux] Fixed aarch64 compilation [#3840](https://github.com/wailsapp/wails/issues/3840) in [#3854](https://github.com/wailsapp/wails/pull/3854) by [kodflow](https://github.com/kodflow)
- [windows] Fixed radio group menu items by [@leaanthony](https://github.com/leaanthony)
## v3.0.0-alpha.7 - 2024-09-18

View file

@ -62,27 +62,29 @@ func (m *Menu) AddRole(role Role) *Menu {
func (m *Menu) processRadioGroups() {
var radioGroup []*MenuItem
closeOutRadioGroups := func() {
if len(radioGroup) > 0 {
for _, item := range radioGroup {
item.radioGroupMembers = radioGroup
}
radioGroup = []*MenuItem{}
}
}
for _, item := range m.items {
if item.itemType != radio {
closeOutRadioGroups()
}
if item.itemType == submenu {
item.submenu.processRadioGroups()
continue
}
if item.itemType == radio {
radioGroup = append(radioGroup, item)
} else {
if len(radioGroup) > 0 {
for _, item := range radioGroup {
item.radioGroupMembers = radioGroup
}
radioGroup = nil
}
}
}
if len(radioGroup) > 0 {
for _, item := range radioGroup {
item.radioGroupMembers = radioGroup
}
}
closeOutRadioGroups()
}
func (m *Menu) SetLabel(label string) {

View file

@ -60,6 +60,9 @@ func (w *windowsMenu) processMenu(parentMenu w32.HMENU, inputMenu *Menu) {
if item.IsSeparator() {
flags = flags | w32.MF_SEPARATOR
}
if item.itemType == radio {
flags = flags | w32.MFT_RADIOCHECK
}
if item.submenu != nil {
flags = flags | w32.MF_POPUP

View file

@ -69,6 +69,10 @@ func (m *windowsMenuItem) IsCheckbox() bool {
return m.itemType == checkbox
}
func (m *windowsMenuItem) IsRadio() bool {
return m.itemType == radio
}
func (m *windowsMenuItem) Enabled() bool {
return !m.disabled
}
@ -146,6 +150,9 @@ func (m *windowsMenuItem) getMenuInfo() *w32.MENUITEMINFO {
mii.FType = w32.MFT_SEPARATOR
} else {
mii.FType = w32.MFT_STRING
if m.IsRadio() {
mii.FType |= w32.MFT_RADIOCHECK
}
thisText := m.label
if m.menuItem.accelerator != nil {
thisText += "\t" + m.menuItem.accelerator.String()
@ -160,7 +167,7 @@ func (m *windowsMenuItem) getMenuInfo() *w32.MENUITEMINFO {
mii.FState |= w32.MFS_DISABLED
}
if m.IsCheckbox() {
if m.IsCheckbox() || m.IsRadio() {
mii.FMask |= w32.MIIM_CHECKMARKS
}
if m.Checked() {

View file

@ -59,7 +59,7 @@ func (p *Win32Menu) newMenu() w32.HMENU {
}
func (p *Win32Menu) buildMenu(parentMenu w32.HMENU, inputMenu *Menu) {
var currentRadioGroup RadioGroup
currentRadioGroup := RadioGroup{}
for _, item := range inputMenu.items {
if item.Hidden() {
if item.accelerator != nil {
@ -84,20 +84,22 @@ func (p *Win32Menu) buildMenu(parentMenu w32.HMENU, inputMenu *Menu) {
if item.disabled {
flags = flags | w32.MF_GRAYED
}
if item.checked && item.IsCheckbox() {
if item.checked {
flags = flags | w32.MF_CHECKED
}
if item.IsSeparator() {
flags = flags | w32.MF_SEPARATOR
}
if item.checked && item.IsRadio() {
flags = flags | w32.MFT_RADIOCHECK
}
if item.IsCheckbox() {
p.checkboxItems[item] = append(p.checkboxItems[item], itemID)
}
if item.IsRadio() {
if currentRadioGroup != nil {
currentRadioGroup.Add(itemID, item)
}
currentRadioGroup.Add(itemID, item)
} else {
if len(currentRadioGroup) > 0 {
for _, radioMember := range currentRadioGroup {
@ -219,6 +221,9 @@ func (p *Win32Menu) ProcessCommand(cmdMsgID int) bool {
return false
}
if item.IsRadio() {
if item.checked {
return true
}
item.checked = true
p.updateRadioGroup(item)
}

View file

@ -241,6 +241,7 @@ func (w *windowsWebviewWindow) run() {
theMenu = w.parent.options.Windows.Menu
}
if theMenu != nil {
theMenu.Update()
w.menu = NewApplicationMenu(w, theMenu)
w.menu.parentWindow = w
appMenu = w.menu.menu