# # $Id: checkboxmenuitem.icn,v 1.3 2004/11/11 15:16:35 rparlett Exp $ # # This file is in the public domain. # # Author: Robert Parlett (parlett@dial.pipex.com) # package gui link graphics $include "guih.icn" # # This class encapsulates a check box in a menu. # # Several {CheckBoxMenuItems} may be added to a {CheckBoxGroup} # structure to give "radio buttons" within menus. # class CheckBoxMenuItem : Toggle : MenuComponent( img_up, # img_down # ) # # Set the up and down images to x and y respectively. The # default is boxes, unless the component is added to a # {CheckBoxGroup} in which case the default is diamonds. # method set_imgs(x, y) self.img_up := x self.img_down := y img_width(x) = img_width(y) | fatal("Image widths differ") img_height(x) = img_height(y) | fatal("Image heights differ") return end method size_label() # # Set the icons if necessary # if /self.img_up then { if /self.parent_check_box_group then self.set_imgs(img_style("box_up"), img_style("box_down")) else self.set_imgs(img_style("diamond_up"), img_style("diamond_down")) } synch_left_img() self.MenuComponent.size_label() end method display_label(lw, mw, rw) synch_left_img() self.MenuComponent.display_label(lw, mw, rw) end # # Set the left image to the correct up/down icon. # method synch_left_img() if \self.is_checked_flag then set_img_left(self.img_down) else set_img_left(self.img_up) end method succeed(e) if \self.parent_check_box_group then self.parent_check_box_group.set_which_one(self) else self.toggle_is_checked() self.MenuComponent.succeed(e) end method set_one(attr, val) case attr of { "is_checked" : if test_flag(attr, val) then set_is_checked() else clear_is_checked() default: self.MenuComponent.set_one(attr, val) } end initially(a[]) self.MenuComponent.initially() set_fields(a) end