$include "guiconst.icn" class ProgressBar : Component ( p, bar_x, bar_y, bar_w, bar_h ) method resize() /h_spec := WAttrib(cwin, "fheight") + 2 * DEFAULT_TEXT_Y_SURROUND self$Component.resize() bar_x := x + DEFAULT_TEXT_X_SURROUND bar_y := y + BORDER_WIDTH + 3 bar_w := w - 2 * DEFAULT_TEXT_X_SURROUND bar_h := h - 2 * (BORDER_WIDTH + 3) end method display(buffer_flag) EraseRectangle(cbwni,x,y,w,h) DrawRaisedRectangle(cbwin, x, y, w, h) FillRectangle(cbwin, bar_x, bar_y, bar_w * p / 100.0, bar_h) cw := Clone(cbwin, "drawop=reverse") center_string(cw, x + w/2, y + h/2, p || "%") Uncouple(cw) if /buffer_flag then CopyArea(cbwin, cwin, x, y, w, h, x, y) return end method handle_event(e) if integer(e) = (&lpress|&rpress|&mpress) & in_region() & (&x <= bar_x + bar_w) then { set_percentage((100 * (&x - bar_x)) / bar_w) return _Event(e, self, 0) } end method get_percentage() return p end method set_percentage(pct) p := pct redisplay() end initially(argv[]) self$Component.initially() set_percentage(0) if *argv > 0 then set_fields(argv) end class TestProgressBar : _Dialog(pb, close) method dialog_event(ev) case ev.get_component() of { pb : write("pb produced an event - percentage = ", pb_get_percentage()) close: if ev.get_code() > 0 then dispose() } end initially self$_Dialog.initially() set_attribs("size=400,200", "font=sans", "bg=light gray", "resize=on") pb := ProgressBar("pos=50%,33%", "size=50%", "align=c,c") add(pb) close := TextButton("label=Close", "pos=50%,66%", "align=c,c") add(close) show_modal() end procedure main() TestProgressBar() end