• Keine Ergebnisse gefunden

Hello World 'Toolkit) 0

Im Dokument PenPomt GO (Seite 189-196)

*

Set PENPOINT_PATH to your environment variable, if it exists.

*

Otherwise, set it to \penpoint

!ifdef %PENPOINT PATH

PENPOINT_PATH = $(%PENPOINT_PATH)

!else

PENPOINT PATH = \penpoint

!endif

*

The DOS name of your project directory PROJ = emptyapp

*

Standard defines for sample code

!INCLUDE $ (PENPOINT_PATH)\sdk\sample\sdefines.mif

*

The PenPoint name of your application EXE_NAME = Empty Application

*

The linker name for your executable: company-name-V<major> «minor»

EXE_LNAME= GO-EMPTYAPP_EXE-Vl(O)

*

Object files needed to build your app EXE_OBJS = methods.obj emptyapp.obj

*

Libs needed to build your app EXE_LIBS = penpoint app

*

Targets

all: $(APP_DIR)\$(PROJ).exe . SYMBOLIC

*

The clean rule must be :: because it is also defined in srules clean :: .SYMBOLIC

-del methods.h

*

Dependencies

emptyapp.obj: emptyapp.c methods.h

*

Standard rules for sample code

!INCLUDE $(PENPOINT_PATH)\sdk\sample\srules.mif

..

CD

Hello World 'Toolkit)

0

One of the simplest applications in any

programming environment is one that prints the string

"Hello World."

Because Pen Point provides both an API to the ImagePoint imaging model and a rich collection of classes built on top ofImagePoint, there are two different approaches to building a "Hello W orId" application. They are:

Create a window and draw text in it using ImagePoint calls

Use PenPoint's UI Toolkit classes to create a label object.

Each of these approaches is worth demonstrating in a sample application. The first is a good example for programs that need to do a lot of their own drawing, such as freeform graphics editors. The second approach shows how easy it is to use the toolkit classes, and serves as an example for programs that need to draw forms or other structured collections of information.

Therefore, there are two "Hello World" sample applications: Hello World (custom window) and Hello World (toolkit). The rest of this document describes Hello World (toolkit).

Hello World (toolkit) uses dsLabel to display "Hello World" in a window. The simplest way of doing this is to make a single label, which also serves as the window for the application. The code for doing so is inHELLOTK1.C. Since developers will typically want to display more than one toolkit class in a window, we created a second file, HELLOTK2.C. This file shows how to create a layout object (a window with knowledge of how to layout toolkit objects) and a label which is inserted into the layout object.

To change between these two source code files, simply copy the version you want to run to HELLOTKC before compiling the application. (See "Compiling" below for more detailed instructions.)

Obiectives

This sample application shows how to:

• Use clsLabel

• Create a custom layout window.

Class Overview

Hello World (toolkit) defines one class: clsHelloWorld. It makes use of the following classes:

To compile Hello World (toolkit), just

• SAMPLE CODE

cd \penpoint\sdk\sample\hellotk

Next, make the version of the application that you want to test:

copy HELLOTK1.C HELLOTK.C wmake

or

copy HELLOTK2.C HELLOTK.C wmake

This compiles the application and creates HELLOTKEXE in

\PENPOINT\APP\HELLOTK

Running

After compiling Hello World (toolkit), you can run it by 1 Adding \\boot\penpoint\app\Hello World (toolkit) to

\PENPOINT\BOOT\APP .INI 2 Booting PenPoint

3 Creating a new Hello World (toolkit) document, and turning to it.

Alternatively, you can boot PenPoint and then install Hello World (toolkit) through the Connections Notebook.

lesting

Zoom the document, or resize a floating document.

Files Used

The code for Hello World (toolkit) is in

\PENPOINT\SDK\SAMPLE\HELLOTK The files are:

HELLOTK.C source code (actually a copy of either hellotkl.c or hellotk2.c) which is compiled by the makefile

HELLOTKl.C source code for making a single label, which also serves as the window for the application

HELLOTK2.C source code for making a layout object and inserting a label in it

METHODS.TBL the method table for dsHelloWorld.

HELLO WORLD (TOOLKIT) ;

..

METHODS. TBL

1****************************************************************************

File: methods.tbl

Copyright 1990-1992 GO Corporation. All Rights Reserved.

You may use this Sample Code any way you please provided you do not resell the code and that this notice (including the above copyright notice) is reproduced on all copies. THIS SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, AND GO CORPORATION EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES, INCLUDING BUT NOT

LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL GO CORPORATION BE LIABLE TO YOU FOR ANY CONSEQUENTIAL, INCIDENTAL, OR INDIRECT DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THIS SAMPLE CODE.

1. 0 $

$Revision:

$Date: 07 Jan 1992 16:47:30 $

Methods.tbl contains the method table for clsHelloWorld (toolkit version).

*****************************************************************************1

Copyright 1990-1992 GO Corporation. All Rights Reserved.

You may use this Sample Code any way you please provided you do not resell the code and that this notice (including the above copyright notice) is reproduced on all copies. THIS SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, AND GO CORPORATION EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES, INCLUDING BUT NOT

LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL GO CORPORATION BE LIABLE TO YOU FOR ANY CONSEQUENTIAL,INCIDENTAL,OR INDIRECT DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THIS SAMPLE CODE.

$Revision: 1.5 $ (from hello.c 1.1)

$Date: 08 Jan 1992 11:41:14 $

This file contains the application class for a "Hello World" application using toolkit components.

This uses the PenPoint UI Toolkit to draw in its window -- thus it custom layout window.

I f you turp on the "F20" debugging flag (e.g. by putting DEBUGSET=/F0020

in \penpoint\boot\environ.ini), then messages to clsHelloWorld will be traced.

II for debugging statements.

II for O-OP' support.

#include <methods.h> II method function prototypes generated by MT

#define clsHelloWorldwknGDTb II avoids clashing with other HelloWorlds 1* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

MsgHandler(HelloAppInit)

ObjCallWarn(msgNewDefaults, clsLabel, &In);

In.label.style.scaleUnits = bsUnitsFitWindowProper;

In.label.style.xAlignment lsAlignCenter;

In.label.style.yAlignment = lsAlignCenter;

In. label. pSt ring = "Hello World!";

ObjCallRet(msgNew, clsLabel, &In, s);

II Get the app's main window (its frame).

ObjCallJmp(msgAppGetMetrics, self, &am, s, error);

II Insert the label in the frame as its client window.

ObjCallJmp(msgFrameSetClientWin, am.mainWin, \ (P_ARGS)ln.object.uid, s, error);

return stsOK;

MsgHandlerParametersNoWarning;

error:

ObjCallWarn(msgDestroy, In.object.uid, Nil(OBJ_KEY));

return S;

Dbg (Debugf ("HelloTK: msgAppOpen");)

II When the message gets to clsApp the app will go on-screen.

Install the Hello application.

****************************************************************************1 STATUS ClsHelloInit (void)

{

new.appMgr. flags. stationery true;

new.appMgr.flags.accessory true;

new.appMgr.flags.allowEmbedding = false;

new.appMgr.flags.hotMode false;

strcpy (new. appMgr. company, "GO Corporation");

ObjCallRet(msgNew, clsAppMgr, &new, s);

i f (DbgFlagGet('F', Ox20L)) {

Debugf("Turning on message tracing for clsHelloWorld (toolkit)");

(void) ObjCallWarn (msgTrace, clsHelloWorld, (P_ARGS) true);

return stsOK;

} 1* ClsHelloInit *1

1****************************************************************************

main

Main application entry point.

****************************************************************************1 Dbg (Debugf ("main: starting if (processCount == 0) (

II Initialize self.

HelloTK1. exe [%d] ", processCount);)

HELLO WORLD (TOOLKIT)

..

Col

ClsHellolnit () ;

II Suppress compiler warnings

1****************************************************************************

File: hellotk2.c

Copyright 1990-i992 GO Corporation. All Rights Reserved.

You may use this Sample Code any way you please provided you do not resell the code and that this notice (including the above copyright notice) is reproduced on all copies. THIS SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, AND GO CORPORATION EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES; INCLUDING BUT NOT

LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL GO CORPORATION BE LIABLE TO YOU FOR ANY CONSEQUENTIAL,INCIDENTAL,OR INDIRECT DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THIS SAMPLE CODE. using toolkit components.

This uses the PenPoint UI Toolkit to draw in its window -- thus it does not create a window class.

Instead, it creates a custom layout window in its frame and inserts a label within the layout window.

Other versions of hellotk.c don't use custom layout, or create several toolkit windows.

It does not have any state it needs to save.

It does not have any instance data.

I f you turn on the "F20" debugging flag (e.g. by putting DEBUGSET=/F0020

in \penpoint\boot\environ.ini), then messages to clsHelloWorld will be traced.

II for debugging statements.

II for O-OP support.

#ifndef APP_INCLUDED

#include <app.h>

fendif

'ifndef APPMGR INCLUDED finclude <appmgr.h>

II for application messages

II for AppMgr startup stuff

II for strcpy().

II for label.

II for frame metrics. (and clayout.h)

II method function prototypes generated by MT tdefine clsHelloWorldwknGDTc II avoids clashing with other HelloWorlds 1* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Dbg{Debugf("HelloTK: Create the client Win");}

.. •

..

ObjCaIIWarn(msgNewDefaults, clsCustomLayout, &cn);

II ?? Needed?? cn.win.parent = frame;

II If the frame is floating, this will make it wrap neatly

II around the label.

cn.border.style.leftMargin = cn.border.style.rightMargin cn.win.flags.style 1= wsShrinkWrapHeight;

if (DbgFlagGet('F', Ox40L»

cn.border.style.join

ObjCaIIRet(msgNew, clsCustomLayout, &cn, s);

II Create the Hello label window.

ObjCaIIWarn(msgNewDefaults, clsLabel, &In);

In.label.pString = "Hello World!";

ObjCaIIJmp(msgNew, clsLabel, &In, s, errorl);

II Insert the Hello win in the custom layout window.

wm.parent = cn.object.uid;

ObjCaIIJmp(msgWinInsert, In.object.uid, &wm, s, error2);

bsMarginSmall;

II Specify how the custom layout window should position the label.

CstmLayoutSpecInit(&(cs.metrics»;

cs.child = In.object.uid;

cs.metrics.x.constraint CIAlign(cICenterEdge,cISameAs, cICenterEdge);

cs.metrics.y.constraint CIAlign(cICenterEdge, clSameAs, cICenterEdge);

cs.metrics.w.constraint clAsIs;

cs.metrics.h.constraint clAsIs;

ObjCaIIJmp(msgCstmLayoutSetChildSpec, cn.object.uid, &cs, s, error2);

II Get the app's main window (its frame).

ObjCaIIJmp(msgAppGetMetrics, self, &am, s, error2);

II Insert the custom layout window in the frame.

ObjCaIIJmp(msgFrameSetClientWin, am.mainWin, \

(P_ARGS)cn.object.uid, s, error2);

II When the message gets to its ancestor this will all go on-screen.

return stsOK;

MsgHandlerParametersNoWarning;

error2:

ObjCaIIWarn(msgDestroy, In.object.uid, Nil(OBJ_KEY»;

errorl:

ObjCaIIWarn(msgDestroy, cn.object.uid, Nil(OBJ_KEY»;

return S;

ObjCaIIRet(msgAppGetMetrics, self, &am, s);

ObjCaIIRet(msgFrameGetClientWin, am.mainWin, (P_ARGS)&win, s);

II Destroy it.

ObjCaIIRet(msgDestroy, win, &key, s);

Dbg(Debugf ("HelloTK: back from freeing client Win");)

II Tell the app that it no longer has a client window.

ObjCaIIRet(msgFrameSetClientWin, am.mainWin, (P_ARGS)objNull, s);

return stsOK;

MsgHandlerParametersNowarning;

} 1* HelloClose *1

1****************************************************************************

CIsHellolnit

Install the Hello application.

****************************************************************************1 STATUS CIsHelloInit (void)

(

APPJMGR_NEW new;

STATUS S;

II Install the class.

ObjCaIIWarn(msgNewDefaults, clsAppMgr, &new);

new.object.uid clsHelloWorld;

new. object. key (OBJ_KEY)clsHelloTable;

new.cls.pMsg clsHelloTable;

new.appMgr.flags.allowEmbedding = false;

new.appMgr.flags.hotMode false;

strcpy (new. appMgr. company, "GO Corporation");

ObjCaIIRet(msgNew, clsAppMgr, &new, s);

i f (DbgFlagGet('F', Ox20L» {

Debugf("Turning on message tracing for clsHelloWorld (toolkit)");

(void)ObjCaIIWarn(msgTrace, clsHelloWorld, (P_ARGS) true);

HELLO WORLD (TOOLKIT)

..

III

return stsOK;

} 1* ClsHelloInit *1

1****************************************************************************

main

Main application entry point.

****************************************************** **************~*******I

Dbg (Debugf ("main: starting HelloTK2.exe[%d]", processCount);) i f (processCount == 0) (

II Suppress compiler warnings

i.i"i.", •• "." ••• ", •• ,t,." ••• it,.tt.,., •••

I

I WMake Makefilefor HelloTK I I FOR ANY CONSEQUENTIAL,INCIDENTAL,OR INDIRECT DAMAGES ARISING OUT OF I THE USE OR INABILITY TO USE THIS SAMPLE CODE.

I $Revision: 1.6 $

$Date: 07 Jan 1992 16:47:16 $

I

.", •• """"""."".tt.,t., •• "".'"i" •••

I Set PENPOINT_PATH to your environment variable, if it exists.

• Otherwise, set it to \penpoint

!ifdef %PENPOINT_PATH

PENPOINT PATH = $(%PENPOINT_PATH)

!else

PENPOINT_PATH = \penpoint

!endif

• The ,linker name for your executable : company-name-V<major> (<minor»

EXE_LNAME=,GO-HELLOTK-V1(0)

• Object files needed to build your app EXE_OBJS = methods.obj hellotk.obj I Libs needed to build your app EXE_LIBS = penpointapp

I Targets

hellotk.obj: hellotk.c methods.h

• Standard rules for sample code

!INCLUDE $(PENPOINT_PATH)\sdk\sample\srules.mif

. ..

0\ '

Hello World (Custom Window)

Hello World (custom

window) demonstrates how to draw the string "Hello World"

by directly using ImagePoint calls. To do so, it defines a descendant of clsWin.

In its msgWinRepaint handler, the window determines the size of the string

"Hello World" and then calls msgDcDrawText to actually paint the text. It also paints a large exclamation point after it, using ImagePoint's ability to draw bezier curves.

For demonstration purposes, this application's window is compiled as a separate DLL.

I

SAMPLE CODE

Obieclives

This sample application shows how to:

• Create a window, and a drawing context (DC) to draw on

• Draw text and bezier curves

• Separate out part of an application into a reuseable dynamic link libraty

Im Dokument PenPomt GO (Seite 189-196)