Keyboard mnemonics on custom dialogs

Hello All;

Stupid question whose answer has so far alluded me:

This is really neither here nor there, but I am picky to point of annoying some days. :innocent:

For custom dialogs, how the heck do you turn off the keyboard mnemonics so that the ALT/CTRL key underline stops inserting itself into my text and buttons? Or do you? Is it an OS level thing and that is that?

I am using both the Scriptforge library and the standard basic library.

Any hints would be appreciated. At the very least I will twitch less :laughing:

TIA

Ken

Define labels with tilde:
~One
~Two
T~hree
~Four
Fi~ve

After an ā€œinterrogation under duressā€ of the Google search engine the next workaround was found.
We can trick the graphics engine by dynamically attaching the shortcut to a Zero-Width Joiner character (Chr(8205)). The engine draws an underline under it, but since its width is exactly 0 pixels, the line completely disappears, leaving the button text clean and perfectly centered.

Sub Test()
  Dim oDialog as Object, oModel as Object, oControl as Object
  Dim controlName as String
  
  DialogLibraries.LoadLibrary("Standard")   ' ???
  oDialog = CreateUnoDialog(DialogLibraries.getByName("Standard").getByName("Dialog1"))  ' ???
  
  oModel = oDialog.Model
  
  For Each controlName In oModel.getElementNames()
    oControl = oModel.getByName(controlName)
    If oControl.supportsService("com.sun.star.awt.UnoControlButtonModel") Then         
      If oControl.PushButtonType < 2 Then
        oControl.Label = oControl.Label & "~" & Chr(8205) 
      End If
    End if
  Next controlName
  
  oDialog.execute()
End Sub
Version: 26.2.5.2 (X86_64)
Build ID: cd7284b4cbbfeb507e630c1aac019f4157393acb
CPU threads: 6; OS: Windows 10 X86_64 (build 19045); UI render: Skia/Raster; VCL: win
Locale: ru-RU (ru_RU); UI: ru-RU
Calc: CL threaded
1 Like

Okay, considering the crap I was finding myself, that was funny! :joy:

I actually saw a variant of this, but it was another character. I tossed it aside as too ridiculous to believe (and I was getting a lot of ridiculous by then) but if you vouch for it I will give it a try and let you know.

Ken

Don’t you know that worked! And is it ever hacky, but it does the trick! :rofl:

Thank you!

Ken

======

To sum it up for any other newbie who finds this:

Postpending ā€œ~ā€ & Chr(8205) to any custom dialog button/label that mysteriously has erroneous mnemonics will get rid of them by effectively hiding them.

You can also add this to a button defined in the editor (which mine were) by opening a Writer document and typing ~ then inserting the special character after it. Copy that, keeping in mind the inserted character will be invisible, and postpend every button label that has mnemonics on it.

Also keep in mind that 8205 is the decimal value, not the hex value. That confused me at first. :smile:

That’s it. It works like a charm.

1 Like

Before publishing, I tested it on Windows and Linux Ubuntu, and you tested it on Mac OS. It seems to work…

Good call, I did not do windows!