18
1 Lecture 10: Toolkits: Intrinsics, Callbacks, Resources, Widget hierarchies, Geometry management Brad Myers 05-830 Advanced User Interface Software

Lecture 10: Toolkits: Intrinsics, Callbacks, Resources, Widget hierarchies, Geometry management

  • Upload
    kaida

  • View
    17

  • Download
    0

Embed Size (px)

DESCRIPTION

Lecture 10: Toolkits: Intrinsics, Callbacks, Resources, Widget hierarchies, Geometry management. Brad Myers 05-830 Advanced User Interface Software. Widgets as objects. Menus, buttons, scrollbars Refresh themselves and handle input, redraw if change - PowerPoint PPT Presentation

Citation preview

Page 1: Lecture 10: Toolkits: Intrinsics, Callbacks, Resources, Widget hierarchies, Geometry management

1

Lecture 10:Toolkits: Intrinsics, Callbacks,

Resources, Widget hierarchies,Geometry management

Brad Myers

05-830Advanced User Interface Software

Page 2: Lecture 10: Toolkits: Intrinsics, Callbacks, Resources, Widget hierarchies, Geometry management

2

Widgets as objects Menus, buttons, scrollbars Refresh themselves and handle input,

redraw if change In Motif and Tk each widget is at least

one window Also Motif has "gadgets" which aren't

windows In Amulet, widgets are not windows

Decorative lines, labels and boxes also are "widgets“

Page 3: Lecture 10: Toolkits: Intrinsics, Callbacks, Resources, Widget hierarchies, Geometry management

3

Intrinsics

How the widgets are implemented Motif --  "fake" object system out of C

(same in Andrew) Tk -- Tcl language Amulet -- Prototype-instance object

system, constraints, Opal graphics model, Interactors input model, command objects

Page 4: Lecture 10: Toolkits: Intrinsics, Callbacks, Resources, Widget hierarchies, Geometry management

4

Resources Every parameter of widgets in Motif

Passed as a parameter to the create routine, set afterwards, or read from a configuration file

Called "options" by Tk Amulet doesn't support having them in a file Each resource has a default value defined by

the class In an X file =

appl.widget1.resource: valueappl.widget1.widget2.resource: value*.resource: value

"sensitive" to grey-out "resizable" for windows

Page 5: Lecture 10: Toolkits: Intrinsics, Callbacks, Resources, Widget hierarchies, Geometry management

5

Callbacks In Motif, associate C procedures with widgets

Many different callbacks for the same widget create, start, abort, finish, destroy, ...

Registered (set) at widget creation time, invoked at run time

Are "resources" There are also "actions" which are internal to the

widget and called by events. Not usually set by programmers Parameters: widget, client data, value

In tk, associate tcl script with "events" in widgets or the widget action if it has one

In Amulet, invoke Command Objects on "interactors" or widget finish, and call-back is the DO method.

Page 6: Lecture 10: Toolkits: Intrinsics, Callbacks, Resources, Widget hierarchies, Geometry management

6

Widget Hierarchies Motif-Primitive adds 3-D shadow

(picture) Label adds string or pixmap display

Push-button adds accepting input Composite is for geometry management

Constraint = how size and position of children managed Manager = 3D shadows

Shell = windows Inheritance down the parent or class hierarchy Current Java object hierarchy contains about 4682

interfacs and classes (1.4.1 had 3300: 2300 classes and 1000 interfaces)

See the list for 1.4.2 How many are for Swing and AWT?

Page 7: Lecture 10: Toolkits: Intrinsics, Callbacks, Resources, Widget hierarchies, Geometry management

7

Geometry Management

Widgets don't set their own location. Widgets put into special group objects

called "geometry managers" that perform the layout by setting the component's positions and size

Used in Motif and tk Each widget negotiates with parent for

more room when resize

Page 8: Lecture 10: Toolkits: Intrinsics, Callbacks, Resources, Widget hierarchies, Geometry management

8

Motif Geometry Management

Motif RowColumn - add widgets and it lays them out Treats all children the same, so not for ScrollBars (picture)

Form - generic constrained layout Put extra resources on the children widgets "For details, see the Motif Reference Manual, because the

complete behavior of Form is quite complicated." Each edge can be constrained

at a position or offset from an edge of the Form at an offset from an edge of another widget percent of the way across the Form (edge, not center) a percent calculated based on the initial position

If wrong, widgets are on top of each other

Page 9: Lecture 10: Toolkits: Intrinsics, Callbacks, Resources, Widget hierarchies, Geometry management

9

Motif Geometry Management

Two phases: bottom up requesting size, then top down setting size. All done before windows are allocated

Unnecessary complexity: "XmCreateMenuBar actually creates a RowColumn widget, but with some special resource settings.... The Motif widget creation routines often have names that are different from the widgets they create."

(picture of code)

Page 10: Lecture 10: Toolkits: Intrinsics, Callbacks, Resources, Widget hierarchies, Geometry management

10

TK Geometry Management All widgets must be in a geometry

manager, or else not displayed Any widget with any geometry manager Layout depends on

widget specified sizes programmer specifications, size of geometry manager itself

Widgets must adjust themselves to the size given

Geometry manager requests size recursively

Page 11: Lecture 10: Toolkits: Intrinsics, Callbacks, Resources, Widget hierarchies, Geometry management

11

TK Geometry, Cont. Placer - specific location for each widget

Each widget treated independently Place "anchor" in absolute coords or as a % of

way across then say which part of object is at the anchor n, ne, e, se, ... center

Packer - "constraint based" specify position of each widget in available space side left, right, top, bottom fill x, -fill y stretch widget to fill available space

Text Canvas - mix graphics and widgets

Page 12: Lecture 10: Toolkits: Intrinsics, Callbacks, Resources, Widget hierarchies, Geometry management

12

Amulet geometry management

Group can have the Am_LAYOUT slot set with a constraint that depends on other slots Sets positions of parts by side effect Default layout routines: Horizontal and

Vertical layout, for lists or tables. Rest done by arbitrary constraints

Page 13: Lecture 10: Toolkits: Intrinsics, Callbacks, Resources, Widget hierarchies, Geometry management

13

Standard Motif Application

1. Include Motif and widget header files 2. Initialize the toolkit: XtAppInitialize

reads resources, creates server connection, returns top-level screen pointer

3. Create the widgets and put them in composites ("parent")

"manage" the widgets (except when pop-ups) 4. Register call-backs with the widgets 5. "Realize" the top level widget

Causes geometry management to be invoked 6. Start the main loop: XtAppMainLoop

Page 14: Lecture 10: Toolkits: Intrinsics, Callbacks, Resources, Widget hierarchies, Geometry management

14

Simple Hello World Program in Amulet

#include <amulet.h>main (void) { Am_Initialize (); Am_Screen .Add_Part (Am_Window.Create ("window") .Set (Am_WIDTH, 200) .Set (Am_HEIGHT, 50) .Add_Part (Am_Text.Create ("string") .Set (Am_TEXT, "Hello World!"))); Am_Main_Event_Loop (); Am_Cleanup ();}

Page 15: Lecture 10: Toolkits: Intrinsics, Callbacks, Resources, Widget hierarchies, Geometry management

15

Goodbye-world Amulet program with button

#include <amulet.h>

main (void) { Am_Initialize (); Am_Screen .Add_Part (Am_Window.Create ("window")

.Set (Am_WIDTH, 200) .Set (Am_HEIGHT, 50) .Set (Am_FILL_STYLE, Am_Amulet_Purple) .Add_Part (Am_Button.Create ("button")

.Set_Part(Am_COMMAND, Am_Quit_No_Ask_Command.Create() .Set (Am_LABEL, "Goodbye, world!"))));

Am_Main_Event_Loop (); Am_Cleanup ();}

Page 16: Lecture 10: Toolkits: Intrinsics, Callbacks, Resources, Widget hierarchies, Geometry management

16

Goodbye-world Amulet program without button

#include <amulet.h>Am_Define_Method (Am_Object_Method, void, quit_method, (Am_Object)) { cerr << "It was nice knowing you.\n" << flush; Am_Exit_Main_Event_Loop();}

main (void) { Am_Object inter; Am_Initialize (); Am_Screen .Add_Part(Am_Window.Create ("window")

.Set (Am_WIDTH, 200) .Set (Am_HEIGHT, 50) .Add_Part(Am_Text.Create ("string")

.Set (Am_TEXT, "Goodbye World!")

.Add_Part(inter = Am_One_Shot_Interactor.Create()))

); inter.Get_Part(Am_COMMAND)

Set (Am_DO_METHOD, quit_method); Am_Main_Event_Loop (); Am_Cleanup ();}

Page 17: Lecture 10: Toolkits: Intrinsics, Callbacks, Resources, Widget hierarchies, Geometry management

17

Minimal Hello-World in Java as Applet using AWT

import java.applet.Applet;import java.awt.Label;public class AWTHelloWorld extends Applet{ public void init () { super.init (); add ( new Label ( "Hello World!" ) ); }}

Page 18: Lecture 10: Toolkits: Intrinsics, Callbacks, Resources, Widget hierarchies, Geometry management

18

Java and Swing Applets

Hello World: AWT HelloWorld Applet (source code) Swing HelloWorld Applet (source code)

Goodbye World: AWT GoodbyeWorld Applet (source code) Swing GoodbyeWorld Applet (source code)