A Simple Motif Widget The basic steps involved in creating and displaying this or any other Motif widget are essentially the same. This is a shell widget.

Slides:



Advertisements
Similar presentations
Chapter 18 Building the user interface. This chapter discusses n Javas graphical user interface. n Swing: an enhancement of a library called the Abstract.
Advertisements

Chapter 16 Graphical User Interfaces
OpenGL Open a Win32 Console Application in Microsoft Visual C++.
OpenGL CMSC340 3D Character Design & Animation. What is OpenGL? A low-level graphics library specification designed for use with the C and C++ provides…
Spring Semester 2013 Lecture 5
Fall 2002CS/PSY User Interface Software Look under the hood Agenda Styles of tools  Design tools  UI toolkits  GUI builder tools.
Chapter 16 Graphical User Interfaces John Keyser’s Modifications of Slides by Bjarne Stroustrup
CS 450 Module R4. R4 Overview Due on March 11 th along with R3. R4 is a small yet critical part of the MPX system. In this module, you will add the functionality.
Project 1 – My Shell Let’s get started… Alex Milenkovich.
1 CS345 Operating Systems Φροντιστήριο Άσκησης 1.
1 Chapter 10 Strings and Pointers. 2 Introduction  String Constant  Example: printf(“Hello”); “Hello” : a string constant oA string constant is a series.
Lecture 20 Arrays and Strings
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
Chapter 7 Process Environment Chien-Chung Shen CIS, UD
Container Widgets Container widgets can be used to combine other widgets into composite panels. Examples: – XmMessageBox – XmForm – XmBulletinBoard – XmRowColumn.
Debugging What can debuggers do? Run programs Make the program stops on specified places or on specified conditions Give information about current variables’
The Environment of a UNIX Process. Introduction How is main() called? How are arguments passed? Memory layout? Memory allocation? Environment variables.
Using Motif with C++ X and Motif are written in C
Chapter 10.
Graphics Programming. In this class, we will cover: The difference between AWT and Swing Creating a frame Frame positioning Displaying information in.
1 Lecture 10: Toolkits: Intrinsics, Callbacks, Resources, Widget hierarchies, Geometry management Brad Myers Advanced User Interface Software.
Functions Definition: Instruction block called by name Good design: Each function should perform one task and do it well Functions are the basic building.
Writing GUI Applications An introduction with Java.
1 Standard Widget Toolkit. 2 SWT l a widget toolkit for Java developers l provides a portable API and tight integration with the underlying native OS.
Using Graphics Libraries Lecture 3 Mon, Sep 1, 2003.
Applets Java API.
Lesson 1 – Microsoft Excel The goal of this lesson is for students to successfully explore and describe the Excel window and to create a new worksheet.
Windows Programming Lecture 05. Preprocessor Preprocessor Directives Preprocessor directives are instructions for compiler.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
By Sidhant Garg.  C was developed between by Dennis Ritchie at Bell Laboratories for use with the Unix Operating System.  Unlike previously.
LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,
Prepared by Fareeha Lecturer DCS IIUI 1 Windows API.
Getting Started The structure of a simple wxWidgets program, Look at where and how a wxWidgets application starts and ends, how to show the main window,
FLTK Tutorial.
By Noorez Kassam Welcome to JNI. Why use JNI ? 1. You already have significantly large and tricky code written in another language and you would rather.
BZUPAGES.COM Visual Programming Lecture – 2 Miss. SADAF MAJEED SIAL Computer Science Department Bahauddin Zakariya University Multan.
Building X Window GUIs with Motif The X Window System: Architecture Applications Sample code Review function (as time permits) … Introduce what it’s like.
Creating Graphical User Interfaces (GUI’s) with MATLAB By Jeffrey A. Webb OSU Gateway Coalition Member.
CNS 1410 Graphical User Interfaces. Obectives Students should understand the difference between a procedural program and an Event Driven Program. Students.
Concurrent Programming and Threads Threads Blocking a User Interface.
Dale Roberts Introduction to Visual Programming Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
Build-A-Button Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, October 8, 2003.
C Functions Three major differences between C and Java functions: –Functions are stand-alone entities, not part of objects they can be defined in a file.
CPS4200 Unix Systems Programming Chapter 2. Programs, Processes and Threads A program is a prepared sequence of instructions to accomplish a defined task.
1 File Handling. 2 Storage seen so far All variables stored in memory Problem: the contents of memory are wiped out when the computer is powered off Example:
Fall 2002 CS 325 Class Notes Page 1 Lecture 25 Today –exec() in Unix –CreateProcess in Windows Announcements.
GUIs Basic Concepts. GUI GUI : Graphical User Interface Window/Frame : a window on the screen Controls/Widgets : GUI components.
CIS Intro to JAVA Lecture Notes Set 8 9-June-05.
Java and C++ Transitioning. A simple example public class HelloWorldApp { public static void main(String[] args) { //Display the string. System.out.println("Hello.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Dialog Widgets Dialog widgets present information and collect input from the user: Dialogs are windows that are often displayed for a relatively short.
Announcements Assignment 1 due Wednesday at 11:59PM Quiz 1 on Thursday 1.
Creating and Using Dialogs ● A dialog is a box that pops up and prompts the user for a value or informs them of something ● One way: directly create objects.
Lesson 28: More on the GUI button, frame and actions.
C Programming Day 2. 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/LA07/003 Version No. 1.0 Union –mechanism to create user defined data types.
Process Related System Calls By Neha Hulkoti & Kavya Bhat.
Chapter 7 Process Environment Chien-Chung Shen CIS/UD
July FLTK The Fast Light Toolkit • A C++ graphical user interface toolkit • Can be used under X, Windows, MacOS • Supports OpenGL • Provides: – Interactive.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Chapter 6 CS 3370 – C++ Functions.
A bit of C programming Lecture 3 Uli Raich.
Windows Programming Lecture 09.
UNIX PROCESSES.
Programmazione I a.a. 2017/2018.
TCL command in C, a simple example Nguyen Truong – GCS VN Aug 5, 2004
User Interface Software Look under the hood
I/O in C Lecture 6 Winter Quarter Engineering H192 Winter 2005
COMMON CONTROLS A control is a child window that an application uses in conjunction with another window to enable user interaction. Controls are most often.
UNIT-5.
Presentation transcript:

A Simple Motif Widget The basic steps involved in creating and displaying this or any other Motif widget are essentially the same. This is a shell widget with a label widget contained in it.

Basic Steps in a Motif Application 1 Initialize Xt. Open a connection to the X server and create a data structure called an application context. 2 Create a shell, to serve as a container for all other widgets in program (can be combined with step 1) 3 Create widgets, using parameterized calls to Xt routines 4 Register callbacks, which are the functions to be called in response to some user input

Basic Steps in a Motif Application (cont'd) 5 Manage all widgets, that is, associate container widgets with their children to keep track of their size and position 6 Realize all widgets, that is, create an X window on the screen and have the widget display itself 7 Handle events. Enter an event loop to receive events from the X server. Events are removed from a queue and dispatched to the appropriate widget for handling (that is, a callback occurs)

The "Hello World" C++/Xt/Motif Program // hello.C, Hello World using C++ and Motif #include void main ( int argc, char **argv ) { Widget label, shell; XtAppContext app; XmString xmstr; Arg args[10]; int n; // Initialize the Intrinsics shell = XtAppInitialize (&app, "Hello", NULL, 0, &argc, argv, NULL, NULL, 0 );...

Notes on the First Part  All include files are relative to /usr/include/  Xm/Xm.h includes X11/Intrinsic.h and X11/Xlib.h  Xm.h defines Motif widgets (names start with `` Xm '')  Intrinsic.h defines X Toolkit widgets (names start with `` Xt '')  Xlib.h defines X basics (names start with `` X '')  The call to XtAppInitialize combines steps 1 and 2

"Hello World" Program (cont'd)... // Create a compound string to display the Hello message xmstr = XmStringCreateLocalized ( "Hello World" ); // Create a label widget to display the string n = 0; XtSetArg ( args[n], XmNlabelString, xmstr ); n++; label = XtCreateManagedWidget ( "label", xmLabelWidgetClass, shell, args, n ); // Free the compound string when it is no longer needed XmStringFree ( xmstr ); XtRealizeWidget ( shell ); XtAppMainLoop ( app ); }

Notes on the Second Part  The call to XtCreateManagedWidget combines steps 3 and 5  There is no step 4 in this example (no ``callbacks'')  The call to XtRealizeWidget is step 6  The call to XtAppMainLoop is step 7

Initialization (Steps 1 and 2) Xt initialization function prototype: Widget XtAppInitialize ( XtAppContext *appContext, //1 const String className, //2 XrmOptionDescList options, //3 Cardinal numOptions, //4 Cardinal *argc, //5 char **argv, //6 const String *fallbackResources, //7 ArgList args, //8 Cardinal numArgs ); //9 XtAppInitialize is a convenience function.

XtAppInitialize Arguments 1 Reference argument to hold application context data structure 2 Application's class name, which is usually the program name upper cased 3 Used if application-specific command line arguments are allowed by the application 4 ditto 5 Used to search for standard command line args 6 ditto

XtAppInitialize Arguments (cont'd) 7 Used if additional customizable widget parameters (resources) are required as fallbacks 8 Allows the program to specify additional arguments (not the user) to be passed to the shell widget 9 ditto

Compound Strings  Motif has defined an abstraction called compound string to allow for international character sets and eliminate dependency on ASCII  The easiest way to create a Motif compound string is with XmStringCreateLocalized : xmstr = XmStringCreateLocalized("Hello World");

Creating Widgets (Step 3) The simplest way to create a widget (prototype): Widget XtCreateWidget (const String name, //1 WidgetClass widgetclass, //2 Widget parent, //3 ArgList args, //4 Cardinal numArgs ); //5

XtCreateWidget Arguments 1 Name of the widget to be created (in our example, "label") 2 Class pointer for the widget ( xmLabelWidgetClass ) 3 Parent of the new widget (in our example, " shell ") 4 To specify additional widget arguments 5 ditto

Managing Widgets (Step 5)  Every widget except the shell must be managed by its parent  After creating a widget with XtCreateWidget, you can manage it with another Xt call ( XtManageChild )  Or, you can do it all at once with XtCreateManagedWidget, which accepts the same arguments as XtCreateWidget.

Giving Widgets Additional Info  The first 3 arguments to XtCreateWidget ( or XtCreateManagedWidget) are required for every widget class  However, different widget classes have different parameters associated with them (called resources).  For example, a label widget cannot be created without a string that it is to display  Specific widget resources are passed to XtCreateWidget through an ArgList.

Giving Widgets Additional Info (cont'd)  An ArgList is an array of type Arg  An Arg is a pair consisting of the name of a widget's customizable parameter and also the value of the parameter  In our example, name: XmNlabelString value: Motif string "Hello World"  It is often convenient to use the macro XtSetArg to add a name/value pair to an ArgList.

Using XtSetArg In our example: Argargs[10]; intn;... n = 0; XtSetArg ( args[n], XmNlabelString, xmstr ); n++; label = XtCreateManagedWidget("label", XmLabelWidgetClass, shell, args, n ); To find widget resource names and widget class pointers, consult the online Motif reference sheet args

Another Example We can also specify the width and height of the label in pixels: Argargs[10]; intn;... n = 0; XtSetArg ( args[n], XmNlabelString, xmstr ); n++; XtSetArg ( args[n], XmNwidth, 400 ); n++; XtSetArg ( args[n], XmNheight, 300 ); n++; label = XtCreateManagedWidget("label", XmLabelWidgetClass, shell, args, n ); args

New Larger Label Widget Note: Font sizes are usually specified using the X Resource Manager and Database, covered later. Also, the look-and-feel of the frame surrounding the widget is different because a different window manager was used.

Creating Widgets Using the vararg Version label = XtVaCreateManagedWidget ( ``label'', xmLabelWidgetClass, shell, XmNlabelString, xmstr, XmNwidth, 200, XmNheight, 300, NULL );

Notes on XtVaCreateManagedWidget  Note the Va in the name  First three arguments the same as before  After that come resource/value pairs  The list of pairs must be terminated with NULL

Using XtVaSetValues To Separate Widget Creation from Setting Widget Resource Values label = XtVaCreateManagedWidget ( ``label'', xmLabelWidgetClass, shell, NULL); XtVaSetValues(label, XmNlabelString, xmstr, XmNwidth, 200, XmNheight, 300, NULL );

Realizing Widgets (Step 6)  Before a widget can be seen, it must create an X window in which to display itself (called realizing the widget)  Use XtRealizeWidget for this: void XtRealizeWidget ( Widget w );  XtRealizeWidget recursively realizes its argument and all children. In the example: XtRealizeWidget ( shell );

Entering the Event Loop (Step 7) Xt implements the event loop like this: void XtAppMainLoop ( XtAppContext app ) { for ( ; ; ) { Xevent event; XtAppNextEvent ( app, &event ); XtDispatchEvent ( &event ); }

Notes On The Event Loop  The event loop has no explicit return  XtAppNextEvent waits until an event is available in the application's event queue When one or more events are available, it removes the first event and returns  XtDispatchEvent finds the window in which the event occurred and sends the event to that window's widget (a callback) Starting the event loop in the example: XtAppMainLoop( app );

Compiling and Running hello.C 12% g++ -o hello hello.C -lXm -lXt -lX11 13% hello The widget will be displayed in the upper left hand corner of the screen. The "hello" program will not terminate until the user clicks the menu bar and quits the widget. Load libraries must be specified using -l option.

Handling Events A widget with a pushbutton instead of a label: Note that the widget is shaded in such as way as to make it appear to protrude from the screen. Suppose we want this application to quit when the "Push Me" button is clicked.

Callback Functions  Each widget supports a specified set of callbacks, which trigger functions to be called when certain events are detected by the widget  There are three types of callbacks for the pushbutton widget: 1 XmNarmCallback: when mouse button is clicked while mouse cursor is on button 2 XmNactivateCallback: when mouse button is released while mouse cursor is on button 3 XmNdisarmCallback: when mouse button is released after mouse cursor moves off button Callbacks for all widgets are in reference sheet.

Associating a Function with a Callback 1 The widget to be associated with the callback 2 Name of the callback 3 The actual callback function 4 Optional application-defined data to be passed to the callback function when called void XtAddCallback ( Widget widget, //1 const String callbackName, //2 XtCallbackProc proc, //3 XtPointer clientData); //4

Prototype of a Callback Function  This is the function called by the X server back to the client application. It passes the following information back to the client: 1 The widget for which the callback was called 2 The clientData specified by the client application in the call to XtAddCallback. 3 Data provided by the widget, usually concerning the nature of the X event that triggered the callback void (Widget w, // 1 XtPointer clientData, // 2 XtPointer callData); // 3

A Simple Callback that Quits  Note that a simple callback like this does not use its parameters  To avoid compiler warnings about unused parameters, leave the parameter type but omit names: void quitCallback (Widget, XtPointer, XtPointer)... void quitCallback (Widget w, XtPointer clientData, XtPointer callData) { exit ( 0 ); }

Pushbutton Example // pushme.C, Using callback functions in C++ #include // Needed for exit prototype #include static void quitCallback ( Widget, XtPointer, XtPointer ); void main ( int argc, char **argv ) { Widget button, shell; XtAppContext app; XmString xmstr; // Initialize the Intrinsics shell = XtAppInitialize ( &app, " Pushme ", NULL, 0, &argc, argv, NULL, NULL, 0 );...

Pushbutton Example (cont'd)... // Create a compound string xmstr = XmStringCreateLocalized ( " Push Me " ); // Create an XmPushButton widget to display the string button = XtVaCreateManagedWidget ( "button", xmPushButtonWidgetClass, shell, XmNlabelString, xmstr, NULL ); // Free the compound string after the XmPushButton // has copied it XmStringFree ( xmstr );...

Pushbutton Example (cont'd)... // Register the quitCallback callback function // to be called when the button is pushed XtAddCallback ( button, XmNactivateCallback, quitCallback, NULL ); // No client data needed // Realize all widgets and enter the main event loop XtRealizeWidget ( shell ); XtAppMainLoop ( app ); } // Callback invoked when button is activated void quitCallback ( Widget, XtPointer, XtPointer ) { exit ( 0 ); }

Notes on the Pushbutton Example  Includes a different widget header file ( Xm/PushB.h )  Incorporates the quitCallback prototype  Has a call to XtAddCallback  Defines the quitCallback function

The Architectural Impact of Event Driven Programming  Applications run asynchronously with respect to the server (and with respect to other applications)  Program cannot suspend while waiting for input (as with scanf), because it cannot receive events  No user-friendly way to interrupt an application (control-C will not work)  A program task should not take longer than the user's perception of a "reasonable" response time  If a task is not done quickly, events will pile up in the queue and the user will encounter windows not redrawn correctly (or worse)