Similarly, the calls below set the type of the notice, error_notice, to make it a screen-
locking notice.
xv_set(error_notice, XV_SHOW, TRUE,
NOTICE_LOCK_SCREEN, TRUE,
NULL);
All screen-locking notices block the thread of execution. Additional attributes apply when
NOTICE_LOCK_SCREEN is TRUE. Table 12-2 lists the attributes that apply when
NOTICE_LOCK_SCREEN is TRUE.
Table 12-2. Screen-Locking Notice Attributes (for NOTICE_LOCK_SCREEN
=
TRUE)
Attribute Procedures
NOTICE_FOCUS_XY create, set
NOTICE_TRIGGER create, set
NOTICE_TRIGGER_EVENT create, set
The position from which the notice shadow emanates is described by the attribute
NOTICE_FOCUS_XY. This value defaults to the current mouse position when the application
maps the notice. Example 12-4 shows code for a screen-locking notice.
Example 12-4. Creating a screen-locking notice
int return_val;
/* Create notice
* Pop up notice with shadow from (100, 200) relative to "parent"
* - this blocks
*/
notice = xv_create(parent, NOTICE,
NOTICE_LOCK_SCREEN, TRUE,
NOTICE_BUTTON, "Save Changes", 100,
NOTICE_BUTTON, "Cancel", 101,
NOTICE_BUTTON, "Quit", 102,
NOTICE_MESSAGE_STRINGS,
"Press Save Changes to save changes to file and quit",
"Press Cancel to continue",
"Press Quit to quit",
NULL,
NOTICE_FOCUS_XY, 100, 200,
NOTICE_STATUS, ¬ice_stat,
XV_SHOW, TRUE,
NULL);
/*
* Notice pops down when a button is pressed.
* notice_stat contains the value of the button that was clicked on.
*/
switch (notice_stat) {
case 100:
/* save changes */
break;
Notices
Notices 317
Example 12-4. Creating a screen-locking notice (continued)
case 101:
/* cancel */
break;
case 102:
/* quit */
break;
}
12.2.2.1 Notice triggers
If you want to assign accelerators to screen-locking notice buttons, or if you find it necessary
to give the user the choice of using mouse buttons or keyboard events to respond to a notice,
you can identify triggers that pop down the notice. The value of NOTICE_STATUS in this
case is NOTICE_TRIGGERED, and the event that caused the trigger will be in the Event
specified by NOTICE_TRIGGER_EVENT. When triggers are not used, the Event pointer can
be NULL. Example 12-5 shows how to use NOTICE_TRIGGER to catch a particular event in a
notice.
Example 12-5. The trigger_notice.c program
/*
* trigger_notice.c -- Demonstrate the use of triggers in notices.
*/
#include <xview/xview.h>
#include <xview/panel.h>
#include <xview/notice.h>
main(argc,argv)
int argc;
char *argv[ ];
{
Frame frame;
Panel panel;
Xv_opaque my_notify_proc();
extern void exit();
/*
* Initialize XView, create a frame, a panel and one panel button.
*/
xv_init(XV_INIT_ARGS, argc, argv, NULL);
frame = (Frame)xv_create(XV_NULL, FRAME, NULL);
panel = (Panel)xv_create(frame, PANEL, NULL);
(void) xv_create(panel, PANEL_BUTTON,
PANEL_LABEL_STRING, "Quit",
PANEL_NOTIFY_PROC, exit,
NULL);
(void) xv_create(panel, PANEL_BUTTON,
PANEL_LABEL_STRING, "Move",
PANEL_NOTIFY_PROC, my_notify_proc,
NULL);
/* make sure everything looks good */
318 XView Programming Manual
Example 12-5. The trigger_notice.c program (continued)
window_fit(panel);
window_fit(frame);
/* start window event processing */
xv_main_loop(frame);
}
/*
* my_notify_proc() -- called when the user selects the "Move"
* panel button. Put up a notice to get new coordinates
* to move the main window.
*/
Xv_opaque
my_notify_proc(item, event)
Panel_item item;
Event *event;
{
int result, x, y;
Panel panel = (Panel)xv_get(item, PANEL_PARENT_PANEL);
Frame frame = (Frame)xv_get(panel, XV_OWNER);
Xv_notice notice;
x = event_x(event), y = event_y(event);
printf("original click relative to panel: %d, %d0, x, y);
notice = xv_create(panel, NOTICE,
NOTICE_LOCK_SCREEN, TRUE,
NOTICE_TRIGGER_EVENT, event,
NOTICE_STATUS, &result,
XV_SHOW, TRUE,
NOTICE_FOCUS_XY, x, y,
NOTICE_MESSAGE_STRINGS,
"You may move the window to a new location specified by",
"clicking the Left Mouse Button somewhere on the screen",
"or cancel this operation by selecting
NULL,
NOTICE_BUTTON_YES, "cancel",
NOTICE_TRIGGER, MS_LEFT,
NOTICE_NO_BEEPING, TRUE,
NULL);
if (result == NOTICE_TRIGGERED) {
x = event_x(event) + (int)xv_get(frame, XV_X);
y = event_y(event) + (int)xv_get(frame, XV_Y);
printf("screen x,y: %d, %d0, x, y);
xv_set(frame, XV_X, x, XV_Y, y, NULL);
}
xv_destroy_safe(notice);
}
Notices
Notices 319
When this program is run and the user selects the Move panel button, a notice is displayed
instructing the user to select a new position for the application window. When the user
selects a new location, the window frame moves to that position.
When the notice pops down, the Event structure that NOTICE_TRIGGER_EVENT points to
contains the event that triggered the notice (popped it down). The x and y coordinates in the
Event structure are relative to the origin of the notice-owner window.
To translate these coordinates to screen-specific coordinates, save the original event location
and add to that the (x, y) coordinates returned in NOTICE_TRIGGER_EVENT when the notice
pops down, as well as the current coordinates of the frame (main application).
Before leaving trigger_notice.c, we should mention the attribute NOTICE_NO_BEEPING that
is used to prevent the notice from beeping when it is displayed. Beeping the screen is usually
done when there is an error condition you wish to alert the user about. In this example, there
is no error condition—it is a simple dialog with the user.
12.3 Destroying a Notice
Notices can be destroyed with xv_destroy(notice). If a notice is destroyed when it is
visible, it will be taken down. Use xv_destroy_safe() if the destruction is done in a
NOTICE_EVENT_PROC.
12.4 Another Example
In the previous example, we used many of the attributes covered in this section in addition to
using some generic and common attributes for the panel items. Example 12-6 goes a little
further to demonstrate how the NOTICE package works in conjunction with the rest of
XView. It creates a frame, a panel with two panel buttons, and a message item. Initially,
only the Quit button and the Commit button are displayed. When the user selects either but-
ton, a notice pops up asking the user to confirm or cancel the proposed action. If the user
confirms quitting the program, the program quits. Otherwise, the result, either Confirmed or
Canceled, is displayed as the text of the message item. In previous examples, the notice is
destroyed immediately after it is unmapped and the status is obtained. In this example, it is
not destroyed, but is reused over and over again.
Example 12-6. The notice.c program
/*
* notice.c --
* This application creates a frame, a panel, and 3 panel buttons.
* A message button, a Quit button (to exit the program) and a
* dummy "commit" button. Extra data is attached to the panel
* items by the use of XV_KEY_DATA. The callback routine for the
* quit and Commit buttons is generalized enough that it can apply
* to either button (or any arbitrary button) because it extracts
* the expected "data" (via XV_KEY_DATA) from whatever panel
320 XView Programming Manual
Example 12-6. The notice.c program (continued)
* button might have called it.
*/
#include <xview/xview.h>
#include <xview/panel.h>
#include <xview/notice.h>
/*
* assign "data" to panel items using XV_KEY_DATA ... attach the
* message panel item, a prompt string specific for the panel
* item’s notice prompt, and a callback function if the user
* chooses "yes".
*/
#define MSG_ITEM 10 /* any arbitrary integer */
#define NOTICE_PROMPT 11
#define CALLBACK_FUNC 12
main(argc,argv)
int argc;
char *argv[ ];
{
Frame frame;
Panel panel;
Panel_item msg_item;
Xv_opaque my_notify_proc();
extern int exit();
/*
* Initialize XView, and create frame, panel and buttons.
*/
xv_init(XV_INIT_ARGS, argc, argv, NULL);
frame = (Frame)xv_create(XV_NULL, FRAME,
FRAME_LABEL, argv[0],
NULL);
panel = (Panel)xv_create(frame, PANEL,
PANEL_LAYOUT, PANEL_VERTICAL,
NULL);
msg_item = (Panel_item)xv_create(panel, PANEL_MESSAGE, NULL);
(void) xv_create(panel, PANEL_BUTTON,
PANEL_LABEL_STRING, "Quit",
PANEL_NOTIFY_PROC, my_notify_proc,
XV_KEY_DATA, MSG_ITEM, msg_item,
/*
* attach a prompt specific for this button used by
* the notice.
*/
XV_KEY_DATA, NOTICE_PROMPT, "Really Quit?",
/*
* a callback function to call if the user answers "yes"
* to prompt
*/
XV_KEY_DATA, CALLBACK_FUNC, exit,
NULL);
/*
* now that the Quit button is under the message item,
* layout horizontally
*/
Notices
Notices 321
Get Volume 7A: XView Programming Manual now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.