Programming with XView

 in
This article gives you a high-level introduction to programming with XView, a GUI toolkit that complements the OpenLook interface.
Second Version with Callbacks

Let's extend this sample program by adding two buttons to it. One button will insert a fixed text string into the text sub-window, and the other button will erase the text sub-window. To do this, we will need a place to put them: namely, a control panel which is implemented in the PANEL package. The buttons themselves are panel items called PANEL_BUTTONs. We associate a subroutine, or “callback” routine, with a button, to be called when the user clicks on the button. The callback routines will manipulate the text sub-window. The second version of the sample.c program is shown in Listing 2.

Let's start with the new code inside our main. We created a panel inside the frame, positioned in the upper-left corner (x=0, y=0), extending to the right edge, 30 pixels tall and borderless.

Next, we added two buttons to the panel (not the frame), each with different button labels and different callback routines. For this example, XView handles the chore of positioning the buttons within the panel. If we wanted, we could use the XV_X and XV_Y attributes to position the buttons within the control panel.

Figure 1. Hierarchy in the Window

Note that a hierarchy (see Figure 1) is forming. The frame is a parent of the panel and the text sub-window. The panel is a parent of the two buttons. When we resize the frame, its child components resize with it. The user interface could become quite sophisticated (i.e., complex) but still remain manageable, because of the relations that form among the frames, panels and other components. Our callback routines are invoked by other routines deep within XView and are passed the component and the event that produced this call (in this simple case, the button and the mouse-button-up event).

For the insert string callback routine, we use the global handle to the text sub-window and call an auxiliary routine to insert the literal text into the text pane. For the clear_window callback routine, we use another helper function to reset the text sub-window, which erases all the text from its pane. Although we use xv_set and xv_get to manipulate the attributes of the XView components, some components have a nice set of helper functions to make our job easier. The text sub-window is one such component.

Although this sample program doesn't give you an earth-shattering application, it does show you the core features of XView:

  • attribute,value pairs

  • null-terminated lists

  • xv_init and xv_main_loop for setup and event handling

  • xv_create, xv_set, xv_get for component attributes

  • callback functions for event handling

This article has demonstrated the simplicity, elegance and beauty of XView. Perhaps you will be inspired to look into it further.

XView Components

Resources

Mike Hall is a senior consultant with BALR Corporation, a Chicago-area computer consulting firm. His last assignment used XView and display PostScript on Suns. He can be reached at mghall@balr.com.

______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Re: Programming with XView

Anonymous's picture

Coudl you please tell me from where can I download xview for linux(both for x89 and amd)

Re: Programming with XView

Anonymous's picture

Oh, it's a beautifully simple, beautiful tutorial.

thnx!

Re: Programming with XView

Anonymous's picture

Could you tell me from when can I download xview for linux(both for x86 and amd processors)

Re: Programming with XView

Anonymous's picture

Clear and concise. It is really helpful.

Webcast
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers

Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.

Learn More

Sponsored by AMD

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState