1. Trang chủ
  2. » Công Nghệ Thông Tin

Fundamentals of X Programming potx

332 291 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 332
Dung lượng 4,32 MB

Nội dung

TEAMFLY Team-Fly ® Fundamentals of X Programming Graphical User Interfaces and Beyond PLENUM SERIES IN COMPUTER SCIENCE Series Editor: Rami G. Melhem University of Pittsburgh Pittsburgh, Pennsylvania FUNDAMENTALS OF X PROGRAMMING Graphical User Interfaces and Beyond Theo Pavlidis INTRODUCTION TO PARALLEL PROCESSING Algorithms and Architectures Behrooz Parhami Fundamentals of X Programming Graphical User Interfaces and Beyond Theo Pavlidis State University of New York at Stony Brook Stony Brook, New York KLUWER ACADEMIC PUBLISHERS NEW YORK, BOSTON, DORDRECHT, LONDON, MOSCOW eBook ISBN: 0-306-46968-5 Print ISBN: 0-306-46065-3 ©2002 Kluwer Academic Publishers New York, Boston, Dordrecht, London, Moscow All rights reserved No part of this eBook may be reproduced or transmitted in any form or by any means, electronic, mechanical, recording, or otherwise, without written consent from the Publisher Created in the United States of America Visit Kluwer Online at: http://www.kluweronline.com and Kluwer's eBookstore at: http://www.ebooks.kluweronline.com Preface This book provides an overview of the X Window System focusing on characteristics that have significant impact on the development of both application programs and widgets. We pay special attention to applications that go beyond graphical user interfaces (GUIs); therefore we discuss issues affecting video games, visualization and imaging programs, and designing widgets with a complex appearance. While the book does not assume previous knowledge of X, it is intended for experienced programmers, especially those who want to write programs that go beyond simple GUIs. X is the dominant window system under Unix, and X servers are available for Microsoft Windows, thus enabling graphics over a network in the PC world. While Java offers an apparently universal graphics library (the abstract window toolkit), the reality is quite different: For high-quality graphics and image display, we must program on the target platform itself (X or one of Microsoft’s APIs) rather than rely on Java peer objects. X is a vast subject, so it is impossible to provide a complete coverage in a few hundred pages. Thus we selected topics that are fundamental to the system, so that the reader who masters them should be able to read the documentation of the numerous libraries and toolkits. Therefore we provide documentation on the most important Xlib and X toolkit functions only. Most of the existing X literature and X toolkits (such as Motif ) focus on GUI applications. This excludes such applications as visualization, imaging, video games, and drawing programs. Such applications may have few windows and a relatively simple layout but the appearance of each window and the user interaction v vi FUNDAMENTALS OF X PROGRAMMING can be quite complex. Usually the applications programmer is left to struggle with the low-level Xlib library or to use an existing toolkit component (widget) for what it was not designed. If the reader must write an application that cannot be readily assembled from the widgets of an existing toolkit, then it is necessary to understand not only drawing functions, but also such issues as resource definition, selections (for interclient communication), and widget writing. Even if we rely on an existing toolkit, understanding these issues clarifies the functionality of the components and their interactions with each other. Quite often the best solution for a complex application is to write an extension of a toolkit. In discussing toolkits we tried to avoid limiting our description to a single toolkit, such as Motif , to emphasize concepts in contrast to implementation details. A small Starter toolkit is used for rapid prototyping and facilitating drawing operations that normally require low-level Xlib functions. The code of that toolkit as well as code in the examples can be obtained through anonymous ftp as described in Software Installation. Stony Brook, New York Theo Pavlidis Acknowledgments The text was extensively revised on the basis of comments from its early readers. Kevin Hunter (Ft. Myers) provided significant input on both the organization and coverage. C. J. Smith (Palo Alto) and Thomas G. Lane (Pittsburgh) had many useful comments and suggestions. I am also grateful to my students in the graduate window systems course for their feedback. Sections 2.2.2, 2.4.1, 3.1.2, and 8.1.3 and Figures 2.1, 2.2, 3.1, 3.2, 3.3, 8.1, and 8.2 are excerpted from, and some other parts of Chapters 2, 8, and 9 are based on, Interactive Computer Graphics in X by Theo Pavlidis, © 1996, PWS Publishing, a division of International Thomson, Publishing, Inc. Used by permission. vii This page intentionally left blank. Contents Software Installation xvii 1. Introduction 1 1.1. Overview of X 3 1.1.1. 1.1.2. 1.1.3. 1.1.4. Our Goal and Subject Main Features of the X Window System. Programming in X Note for Those Familiar with Microsoft Windows 3 3 6 7 1.2. Highlights of the X Toolkit 8 1.2.1. 1.2.2. 1.2.3. A Simple Program Using the X Toolkit Resources and Translations Widgets. 8 11 12 1.3. Simplifying X. 13 1.3.1. 1.3.2. Challenges Starter Toolkit 13 14 1.4. Odds and Ends 16 1.4.1. 1.4.2. 1.4.3. A Few Words on Display Hardware. A Few Words on Software Special Issues in Debugging X Programs 16 18 20 1.5. Conclusions. 22 1.5.1. Other Systems—Simple and Complex Servers . . . 22 ix [...]... as the Xlib functions Assuming that everything is in the directory /usr/local /X1 1R6, we can use the following makefile: INC_FILE=usr/local /X1 1R6/include LIB_FILE=/usr/local /X1 1R6/lib CFLAGS=-I$(INC_FILE) xt: xt.o $(CC)-L$(LIB_FILE) xt.o -1Xaw -lXmu -1Xext -lXt -lX11 -o xt The flags -lXaw -1Xmu -1Xext are needed to access the Athena toolkit INTRODUCTION 11 1.2.2 Resources and Translations The Xt uses... lines: xt*canvas.translations: Listing 1.2 : Example of Resources xt*button.label: PRESS xt*button.width: 100 xt*button.height: 100 quit() 12 FUNDAMENTALS OF X PROGRAMMING where translations is a keyword that takes the place of a resource name (canvas is the widget name) The second field is the event that causes the invocation of a function referred to in the third field However the syntax... INTRODUCTION Listing 1.1 A Trivial Xt Program /* A Trivial Xt Toolkit Program (using Athena widgets) */ /* The argument structure is explained in Chapter 4 */ #include #include #include int main (int arc, char **arv) { Widget toplevel, button; XtAppContext app; extern exit(); /* Initialize the Application */ toplevel=XtAppInitialize( &app, "Trivial",... terminated list of pairs, each consisting of a symbolic string and a value Symbolic strings are defined in one of the Xt include files, for example: #define XtNlabel "label" #define XtNwidth "width" #define XtNheight "height" This mechanism makes the order of most arguments in a function unimportant at the expense of having to provide twice as many arguments Using symbolic names rather than explicit strings... create in X an entity whose functionality is comparable to that of a single Microsoft window Creating new window classes (widget classes) in X is more complex than in Microsoft Windows, so this process should not be undertaken lightly 8 FUNDAMENTALS OF X PROGRAMMING The X resources (see Sec 1.2.2) serve a similar purpose (selecting run-time parameters from a file) as resources in Microsoft Windows,... functional simple program in Microsoft Windows than in X Roughly speaking the Microsoft Windows API corresponds to Xt functions with only the drawing operations API at the Xlib level 1.2 HIGHLIGHTS OF THE X TOOLKIT 1.2.1 Simple Program Using the X Toolkit The X toolkit, discussed in detail in Chaps 3-7, consists of a library of functions, the intrinsics, and a set of structures (objects), the widgets,... of the Starter toolkit is in starter To compile and run various programs, requires Release 4 or later of X xvii This page is intentionally left blank 1 Introduction Overview of X 1.1.1 Our Goal and Subject 1.1.2 Main Features of the X Window System 1.1.3 Programming in X 1.1.4 Note for Those Familiar with Microsoft... except in two 6 FUNDAMENTALS OF X PROGRAMMING situations The first is debugging (discussed in Sec 1.4.3); the second involves messages from programs that perform lengthy computations or handle large files, such as Please wait while loading the next frame We must flush the buffer explicitly to ensure that the message appears when it is supposed to X Releases There have been seven releases of X The X. .. { put_text ("The end of the world is near", 20, 20); } main() { vis_window(hello); } Listing 1.5 A Window that Iconifies Itself #include #include #include #include void hello(Widget w) { St_put_text("The end of the world is near", 20, 20); St_xflush ( ); /* to actually display the message */ sleep (1); XtVaSetValues(XtParent(w), XtNiconic,... widget structure */ button=XtVaCreateManagedWidget ("button", CommandWidgetClass, toplevel, xtNlabel, "Hello World", XtNwidth, 256, XtNheight, 256, NULL); /* Arrange so that when a mouse button */ /* is pressed the application exits */ XtAddCallback (button, XtNcallback, exit, NULL); /* Request that the windows be displayed */ XtRealizeWidget (toplevel); /* Enter an Infinite Loop */ XtAppMainLoop (app); . to: ftp://ftp.cs.sunysb.edu/pub/TechReports/pavlidis/Xstart and then click on Xfund.tar.Z. To extract the files, execute the two following Unix commands: uncompress Xfund.tar.Z tar -xvf Xfund.tar Then. . 351 353 355 xvi FUNDAMENTALS OF X PROGRAMMING 12.3.4. Resizing and Moving Children of a Composite Widget 357 12.4. 12.5. Conclusions. Projects 357 358 Appendix.

Ngày đăng: 18/03/2014, 00:20

TỪ KHÓA LIÊN QUAN