Code examples

This source code generates the following window


(**
  A simple "Hello world!" demo for VisualOberon.
**)

MODULE HelloWorld;

(*
    Demo for VisualOberon. Prints "Hello world" into a window.
    Copyright (C) 1997-2001 Tim Teulings (rael@edge.ping.de)

    This file is part of VisualOberon.

    VisualOberon is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    VisualOberon is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with VisualOberon. If not, write to the Free Software
    Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*)

IMPORT D   := VODisplay,     (* Display stuff *)
       T   := VOText,        (* The textclass *)
              VOUsePrefs,    (* The use the preferences setting *)
       W   := VOWindow,      (* Window class *)
       WG  := VOWindowGroup, (* The window group object *)

              Err;           (* Simple error output *)

VAR
  w          : W.Window;       (* The window *)

  wGroup     : WG.WindowGroup; (* The window group *)

  msg2Exit   : D.Msg2Exit;     (* a simple message converter *)


BEGIN
  (*
    Try to initialize it.
    This call make the connection to the X server and allocates
    fonts, colors and that stuff
  *)
  D.display.SetAppName("HelloWorld");
  IF ~d.Open() THEN
    Err.String("Cannot open to display!"); Err.Ln;
    HALT(1);
  END;

  (* Create an instance of the window class *)
  NEW(w);

  (* Initialize it *)
  w.Init;

  (*
    Allocate an instance of the window group class and initialize it.
    This group handles positioning of menustrip and window contents.
  *)
  wGroup:=WG.CreateWindowGroup();

  (*
    Set the contents of the window group.
    * First parameter is a pointer to a menu strip, here NIL,
      since we don't have one.
    * Second parameter is a pointer to a (group)object, that represents
      the rest of the window contents.
      Here we use a convenience function of the text class, that
      generates a standard text object that is centered. The escape
      sequences tell text object to display the text smart (i.e.
      black on white), italic and with the larges fontsize (0-9)
      available.
    * Third parameter tell the window groub object to put some space
      around the text object.

  *)
  wGroup.Set(NIL,T.MakeCenterText("\es\ei\e9Hello world!"),TRUE);

  (* Set the top object of the window to the window group *)
  w.SetTop(wGroup);

  (* Set the title of the window *)
  w.SetTitle("Hello world");

  (*
    Allocate an instance of this special message handler.
    A handler is a class that can convert any or a special
    input message to an other message and sends the resulting
    message to the given destination. However the baseclas just
    returns the input message.

    Most converters are handwritten, but some special converters are
    given by the corresponding objects.

    This converter converts the close-message generated when clicking
    the closing gadget of the window to an exist-message of the display
    class.
  *)
    NEW(msg2Exit);

  (*
    Send the resulting exit message to the display, which will finish
    the event loop and receiving.
  *)
  msg2Exit.destination:=D.display;

  (*
    Add the handler to window and tell the window that it should call
    this hndler when a close message gets send.
  *)
  w.AddHandler(msg2Exit,W.closeMsg);

  (* Open the main window *)
  w.Open;

  (*
    Start the main event loop. The event loop will get finished when
    the display receives a close message or its exit method gets called.
  *)
  d.EventLoop;


  (*
    Close the window.
  *)
  w.Close;

  (* Free possible ressources of the display. *)
  D.display.Close;
END HelloWorld.