Source file label.icn

#  $Id: label.icn,v 1.1 2003-05-31 06:09:03 jeffery Exp $

##
#  This class implements a Text label.  The default width and
#  height are determined by dimensions of text
#
class Label : Component(
   label,
   internal_alignment,
   tx,
   tw
   )

   ##
   #  The internal alignment of the label, which should be one of
   #  ``l'', ``c'' or ``r'', for left, centre, or right
   #  alignment respectively.   The default is ``l''.
   #  @param x   The alignment.
   #
   method set_internal_alignment(x)
      return self.internal_alignment := x
   end

   ##
   #  Set the label.
   #  @param x   The label.
   #
   method set_label(x)
      self.label := x
      self$redisplay()
      return x
   end

   method resize()
      if /self.label then
         error("no label specified")

      if \self.draw_border_flag then {
         /self.w_spec := TextWidth(self.cwin, label) + 2 * DEFAULT_TEXT_X_SURROUND
         /self.h_spec := WAttrib(self.cwin, "fheight") + 2 * DEFAULT_TEXT_Y_SURROUND
      } else {
         /self.w_spec := TextWidth(self.cwin, label)
         /self.h_spec := WAttrib(self.cwin, "fheight")
      }
      self$Component.resize()

      if \self.draw_border_flag then {
         self.tx := self.x + DEFAULT_TEXT_X_SURROUND
         self.tw := self.w - 2 *  DEFAULT_TEXT_X_SURROUND
      } else {
         self.tx := self.x
         self.tw := self.w
      }
   end

   method display(buffer_flag)
   local yoff
      EraseRectangle(self.cbwin, self.x, self.y, self.w, self.h)

      yoff := self.y + self.h / 2

      if \self.draw_border_flag then
         DrawSunkenRectangle(self.cbwin, self.x, self.y, self.w, self.h,-2)

      Clip(self.cbwin, self.tx, self.y, self.tw, self.h)

      case self.internal_alignment of {
         "c" : center_string(self.cbwin, self.tx + self.tw / 2, yoff, self.label)
         "l" : left_string(self.cbwin, self.tx, yoff, self.label)
         "r" : right_string(self.cbwin, self.tx + self.tw, yoff, self.label)
         default : error("incorrect internal_alignment specifier")
      }

      Clip(self.cbwin)
      self$do_shading(self.cbwin)

      if /buffer_flag then
         CopyArea(self.cbwin, self.cwin, self.x, self.y, self.w, self.h, self.x, self.y)
   end

   method handle_event(e)
      fail
   end

   initially(argv[])
      self$Component.initially()
      self.internal_alignment := "l"
      if *argv > 0 then set_fields(argv)
end

This page produced by UniDoc on 2021/04/15 @ 23:59:44.