[Oberon] WMDialogs.Mod

Yaroslav Romanchenko tobject at bk.ru
Sat Mar 17 18:28:59 MET 2007


Folk,

I need to extend base object WMDialogs.Dialog and have to copy into my
module such procedures as InstantiateButton, FindComponent, FindButton
and WireError method because they not exported from module WMDialogs.

And will be useful to have ability to read width an height of dialog
window for more precise positioning (in center of view, for example).
Example of dialog:

    LoginDlg = OBJECT (WMDialogs.Dialog)
    VAR editLogin, editPassword: WMEditors.Editor;
        buttonPanel: WMStandardComponents.Panel;
        server, ok, abort: WMStandardComponents.Button;
        content: WMComponents.VisualComponent;
        width-, height-: LONGINT;
        serverString-: ARRAY 256 OF CHAR;
       
        PROCEDURE &New (serverStr: ARRAY OF CHAR);
        BEGIN
       
            (*serverString := serverStr;*)
            COPY (serverStr, serverString);
           
            errors := FALSE;
            CreateDialog;
            WireDialog;
           
            width := content.bounds.GetWidth ();
            height := content.bounds.GetHeight ();
           
            Init (width, height, FALSE);
            SetContent (content);
           
            IF editLogin # NIL THEN editLogin.SetFocus;
editLogin.SetFocus  END
           
        END New;
       
        PROCEDURE GetServer*(sender, data:PTR);
        VAR
            res: LONGINT;
        BEGIN
            res := QueryString ("Server", serverString);
        END GetServer;

        PROCEDURE CreateDialog;
        VAR
            panel: WMStandardComponents.Panel;
            labelLogin, labelPassword: WMStandardComponents.Label;
            manager: WM.WindowManager;
            windowStyle: WM.WindowStyle;
        CONST
            width = 12 * 18; height = 12 * 9;
            BWidth = 12 * 5; BHeight = 20;
        BEGIN
           
            manager := WM.GetDefaultManager ();
            windowStyle := manager.GetStyle ();           
           
            NEW (panel); panel.bounds.SetExtents (width, height);
            panel.fillColor.Set (windowStyle.bgColor);
            panel.takesFocus.Set (FALSE);
           
            NEW (labelLogin);
            labelLogin.bounds.Set (WMRectangles.MakeRect (12, 12, 12 *
6, 12 + 20));
            labelLogin.SetCaption ("UIN:");
            labelLogin.alignH.Set (WMGraphics.AlignRight);
            panel.AddContent (labelLogin);

            NEW (labelPassword);
            labelPassword.bounds.Set (WMRectangles.MakeRect (12, 12 * 4,
12 * 6, 12 * 4 + 20));
            labelPassword.SetCaption ("Password:");
            labelPassword.alignH.Set (WMGraphics.AlignRight);
            panel.AddContent (labelPassword);
           
            NEW (editLogin); editLogin.uid.SetAOC ("Login");
            editLogin.tv.defaultTextColor.Set (windowStyle.fgColor);
            editLogin.tv.defaultTextBgColor.Set (windowStyle.bgColor);
            editLogin.bounds.Set(WMRectangles.MakeRect (12 * 7, 12,
width - 12, 12 + 20));
            panel.AddContent (editLogin);
            editLogin.multiLine.Set (FALSE); editLogin.tv.borders.Set
(WMRectangles.MakeRect(5, 2, 3, 2));
            editLogin.tv.showBorder.Set (TRUE);
           
            NEW (editPassword); editPassword.uid.SetAOC ("Password");
            editPassword.tv.defaultTextColor.Set (windowStyle.fgColor);
            editPassword.tv.defaultTextBgColor.Set (windowStyle.bgColor);
            editPassword.tv.isPassword.Set (TRUE);
            editPassword.bounds.Set (WMRectangles.MakeRect (12 * 7, 12 *
4, width - 12, 12 * 4 + 20));
            panel.AddContent (editPassword);
            editPassword.multiLine.Set (FALSE);
editPassword.tv.borders.Set (WMRectangles.MakeRect(5, 2, 3, 2));
            editPassword.tv.showBorder.Set (TRUE);
           
            NEW (buttonPanel);
            buttonPanel.bounds.SetHeight (BHeight);
            buttonPanel.alignment.Set (WMComponents.AlignBottom);
            panel.AddContent (buttonPanel);

            abort := InstantiateButton (WMDialogs.AbortBtnId, "Abort");
buttonPanel.AddContent (abort);
            abort.bounds.SetWidth (BWidth); abort.alignment.Set
(WMComponents.AlignRight);
           
            ok := InstantiateButton (WMDialogs.OkBtnId, "Ok");
buttonPanel.AddContent (ok);
            ok.bounds.SetWidth (BWidth); ok.alignment.Set
(WMComponents.AlignRight);
           
            NEW (server); server.caption.SetAOC ("Server...");
            buttonPanel.AddContent (server);
            server.bounds.SetWidth (BWidth);
            server.alignment.Set (WMComponents.AlignRight);

            content := panel
        END CreateDialog;
       
        PROCEDURE WireDialog;
        VAR c: WMComponents.Component;
        BEGIN
            c := FindComponent (content, "Login");
            IF (c # NIL) & (c IS WMEditors.Editor) THEN editLogin := c
(WMEditors.Editor) END;
           
            IF editLogin = NIL THEN
                WireError ("LoginDlg", "Required component 'Login' not
found."); RETURN
            END;
           
            c := FindComponent (content, "Password");
            IF (c # NIL) & (c IS WMEditors.Editor) THEN editPassword :=
c (WMEditors.Editor) END;
           
            IF editPassword = NIL THEN
                WireError ("LoginDlg", "Required component 'Password'
not found."); RETURN
            END;
           
            ok := FindButton (content, WMDialogs.OkBtnId);
            abort := FindButton (content, WMDialogs.AbortBtnId);
            IF ok = NIL THEN WireError ("LoginDlg", "Required component
'Ok' not found."); RETURN END;
            IF abort = NIL THEN WireError ("LoginDlg", "Required
component 'Abort' not found."); RETURN END;
           
            ok.onClick.Add (Ok);
            abort.onClick.Add (Abort);
            editLogin.onEnter.Add (Ok);
            editPassword.onEnter.Add (Ok);
            server.onClick.Add (GetServer);
        END WireDialog;
       
        PROCEDURE WireError(detectedBy, msg: ARRAY OF CHAR);
        BEGIN
            errors := TRUE;
            Out.String ("WMDialogs - Wiring error : ");
            Out.String(detectedBy); Out.String(" - "); Out.String(msg);
Out.Ln;
        END WireError;
   
    END LoginDlg;

PROCEDURE QueryLogin*(caption: ARRAY OF CHAR;
    VAR server, login, password: ARRAY OF CHAR) : LONGINT;
VAR
    ld: LoginDlg;
    vp: WM.ViewPort;
BEGIN
    NEW(ld, server);
    IF ~ld.errors THEN
        ld.SetTitle(Utilities.NewString(caption));
ld.editLogin.SetAsString(login); ld.editLogin.tv.SelectAll();
        vp := WM.GetDefaultView ();
        ld.x := (ENTIER (vp.range.r - vp.range.l) - ld.width) DIV 2;
        ld.y := (ENTIER (vp.range.b - vp.range.t) - ld.height) DIV 2;
ld.Show;
        IF ld.result = WMDialogs.ResOk THEN
            ld.editLogin.GetAsString(login);
            ld.editPassword.GetAsString(password);
            (*server := ld.serverString;*)
            COPY (ld.serverString, server);
        END;
        RETURN ld.result
    ELSE RETURN WMDialogs.ResDialogFailure
    END
END QueryLogin;

-- 
Cheers, SAGE
http://sage.h15.ru/



More information about the Oberon mailing list