Mac Control Sizes in REALbasic
October 23rd, 2007 by Jonathan Johnson
For a long time REALbasic I thought REALbasic had the ability to create both regular size controls and small controls. For some controls such as PushButton, you can simply set the height, and the control will automatically resize. However, this may not work in future OS versions, *cough cough*. Even today, many controls have a fixed height that can’t be changed, such as PopupMenus, UpDownArrows, CheckBoxes, RadioButtons, Listbox Headers, and ComboBoxes
There is a trick to making REALbasic use the Small variant for PopupMenus and ListBoxes: set the control font to SmallSystem and it will automatically adjust its size. What I didn’t realize until preparing this post was that this is just a side effect of the controls automatically sizing to fit their fonts, and none of the other above controls behave that way.
So with yet another post failing to be interesting enough to write about, I set out to make it work. The Carbon Control Manager call is SetControlData with the tag of kControlSizeTag. The code is relatively simple:
Module MacControlSizes Private Const kControlSizeTag = 'size' Enum MacControlSize Normal Small Large Mini End Enum Sub MacControlSize(extends c as Control, assigns newSize as MacControlSize) if c.Handle = 0 then return declare function SetControlData lib "Carbon" (ctl as Integer, part as Integer,_ tagName as Integer, size as Integer, byref data as MacControlSize) as Integer dim err as Integer err = SetControlData( c.Handle, 0, kControlSizeTag, 2, newSize ) End Sub End Module
For any controls this extension method doesn’t work on, it will just silently fail. The only built-in control that this method does not work on is the ComboBox, because it is a custom control on Mac OS X.
You can download the project here.
November 7th, 2007 at 1:00 am
Amazing. I’ve been wanting this forever.