# # Include some standard constants # $include "guiconst.icn" # # Selection from a list # class Circulate : Component(selection, selection_list, b, l ) # # Some methods to set/get the selection data. # method set_selection_list(x) selection_list := x set_selection(1) return x end method set_selection(x) selection := x l.set_label(selection_list[selection]) redisplay() return x end method get_selection() return selection end # # This method is called after resize, but before # the object has been displayed. # method firstly() self$Component.firstly() b.firstly() l.firstly() end # # Called after the dialog is closed. # method finally() self.Component.finally() b.finally() l.finally() end # # Called once at startup, and whenever the window is resized. # method resize() /h_spec := WAttrib(cwin, "fheight") + 16 self$Component.resize() # # Set button position and size # b.set_pos(BORDER_WIDTH, BORDER_WIDTH) b.set_size(h - 2 * BORDER_WIDTH, h - 2 * BORDER_WIDTH) b.resize() l.set_pos(h-BORDER_WIDTH + DEFAULT_TEXT_X_SURROUND, h / 2) l.set_align("l", "c") l.set_size(w - h - 2 * DEFAULT_TEXT_X_SURROUND, h - 2 * BORDER_WIDTH) l.resize() return end # # Display the object. In this case, double buffering # is not necessary. # method display(buffer_flag) W := if /buffer_flag then cwin else cbwin EraseRectangle(W, x, y, w, h) DrawSunkenRectangle(W, x, y, w, h) l.display(buffer_flag) b.display(buffer_flag) do_shading(W) end # # Event handler - if the button is clicked move the selection # on one and produce and Event, which is the received by the # dialog's dialog_event method. # method handle_event(e) if b.handle_event(e).get_code() > 0 then { set_selection(1 + selection % *selection_list) return _Event(e, self, 0) } end # # This method has to be extended to initialize the label and # the button. # method final_setup(x, y) self$Component.final_setup(x, y) b.final_setup(x, self) l.final_setup(x, self) end initially(argv[]) self$Component.initially() if *argv > 0 then set_fields(argv) l := Label("pos=10,10") l.clear_draw_border() b := IconButton() b.set_draw_border() b.set_img("13,c1,_ ~~~~0000~~~~~_ ~~~000000~~~~_ ~~00~~~~00~~~_ ~00~~~~~~00~~_ ~00~~~~~~00~~_ ~00~~~~~~~~~~_ ~00~~~~~~~~~~_ ~00~~~~~~0~~~_ ~00~~~~~000~~_ ~00~~~~00000~_ ~00~~~0000000_ ~00~~~~~~00~~_ ~00~~~~~~00~~_ ~00~~~~~~00~~_ ~~00~~~~00~~~_ ~~~000000~~~~_ ~~~~0000~~~~~_ ") end class TestCirculate : _Dialog(c, clos) method dialog_event(ev) if \ev.get_component() then case ev.get_component() of { c : write("c produced an event - selection = ", c.get_selection()) clos : if ev.get_code() > 0 then dispose() } end initially self$_Dialog.initially() c := Circulate("pos=50%,33%", "size=150,20", "align=c,c") c.set_selection_list(["one", "two", "three", "four", "five"]) add(c) # # Add a close button. # clos := TextButton("label=Close", "pos=50%,66%", "align=c,c") add(clos) show_modal() end procedure main() TestCirculate() end