#
#		Python GUI - Check boxes - Macintosh
#

from Carbon.Ctl import CreateCheckBoxControl
from Properties import overridable_property
from MacDummy import _mac_dummy_window
from StdFonts import system_font
from GCheckBoxes import CheckBox as GCheckBox

class CheckBox(GCheckBox):

    def __init__(self, title = "New Control", font = system_font, **kwds):
        title_width = font.width(title)
        mac_control = CreateCheckBoxControl(_mac_dummy_window,
            (0, 0, 20 + title_width, 18), title, 0, 0)
        GCheckBox.__init__(self, mac_control, font = font, **kwds)
    
    def get_on(self):
        return self._mac_get_control_value()
    
    def set_on(self, v):
        self._mac_set_control_value(not not v)

    def _mac_control_part_hit(self, mac_part_code):
        if mac_part_code:
            if self._auto_toggle:
                ctrl = self._mac_control
                # Already focused at this point
                ctrl.SetControlValue(not ctrl.GetControlValue())
            self.do_action()
