Example B-2. The trigger_notice.c program (continued)
/*
* my_notify_proc() -- called when the user selects the "Move"
* panel button. Put up a notice_prompt 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);
x = event_x(event), y = event_y(event);
printf("original click relative to panel: %d, %d0, x, y);
result = notice_prompt(panel, event,
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);
}
}
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. Note that the window man-
ager adds a title bar and other decorations around the frame; do not expect the upper-left cor-
ner of the frame to move to the new position. The real frame’s origin is moved to the new
position, and the frame’s decorations are moved as well but not aligned to the same values (it
will be somewhat higher).
When notice_prompt() returns, the Event structure that was passed to it contains the
event that triggered the notice to return. 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 when notice_prompt() returns as well as
the current coordinates of the frame (main application).
660 XView Programming Manual
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.
B.2 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 B-3 goes a little fur-
ther 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 button, a notice
pops up asking the user to confirm or cancel the proposed action. If the user confirms quit-
ting the program, the program quits. Otherwise, the result, either Confirmed or Canceled, is
displayed as the text of the message item.
Example B-3. 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
* 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
* items 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();
The notice_prompt
Function
The notice_prompt Function 661
Example B-3. The notice.c program (continued)
/*
* 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
* notice_prompt()
*/
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
*/
xv_set(panel, PANEL_LAYOUT, PANEL_HORIZONTAL, NULL);
(void) xv_create(panel, PANEL_BUTTON,
PANEL_LABEL_STRING, "Commit...",
PANEL_NOTIFY_PROC, my_notify_proc,
XV_KEY_DATA, MSG_ITEM, msg_item,
/*
* attach a prompt specific for this button used by
* notice_prompt()
*/
XV_KEY_DATA, NOTICE_PROMPT, "Update all changes?",
/*
* Note there is no callback func here, but one could be
* written
*/
NULL);
window_fit(panel);
window_fit(frame);
xv_main_loop(frame);
}
/*
* my_notify_proc()
* The notice appears as a result of notice_prompt().
* The "key data" associated with the panel item is extracted via
662 XView Programming Manual
Example B-3. The notice.c program (continued)
* xv_get(). The resulting choice is displayed in the panel
* message item.
*/
Xv_opaque
my_notify_proc(item, event)
Panel_item item;
Event *event;
{
int result;
int (*func)();
char *prompt;
Panel_item msg_item;
Panel panel;
func = (int(*)())xv_get(item, XV_KEY_DATA, CALLBACK_FUNC);
prompt = (char *)xv_get(item, XV_KEY_DATA, NOTICE_PROMPT);
msg_item = (Panel_item)xv_get(item, XV_KEY_DATA, MSG_ITEM);
panel = (Panel)xv_get(item, PANEL_PARENT_PANEL);
/*
* Create the notice and get a response.
*/
result = notice_prompt(panel, NULL,
NOTICE_FOCUS_XY, event_x(event), event_y(event),
NOTICE_MESSAGE_STRINGS,
prompt,
"Press YES to confirm",
"Press NO to cancel",
NULL,
NOTICE_BUTTON_YES, "YES",
NOTICE_BUTTON_NO, "NO",
NULL);
switch(result) {
case NOTICE_YES:
xv_set(msg_item, PANEL_LABEL_STRING, "Confirmed", NULL);
if (func)
(*func)();
break;
case NOTICE_NO:
xv_set(msg_item, PANEL_LABEL_STRING, "Cancelled", NULL);
break;
case NOTICE_FAILED:
xv_set(msg_item, PANEL_LABEL_STRING, "unable to pop-up",
NULL);
break;
default:
xv_set(msg_item, PANEL_LABEL_STRING, "unknown choice",
NULL);
}
}
The notice_prompt
Function
The notice_prompt Function 663
B.3 Notice Package Summary
Table B-1 lists the attributes, procedures and macros for the NOTICE package. This informa-
tion is described fully in the appendices of the XView Reference Manual.
Table B-1. Notice Attributes, Procedures, and Macros
Attributes Procedures and Macros
NOTICE_BUTTON notice_prompt()
NOTICE_BUTTON_NO
NOTICE_BUTTON_YES
NOTICE_FOCUS_XY
NOTICE_FONT
NOTICE_MESSAGE_STRINGS
NOTICE_MESSAGE_STRINGS_ARRAY_PTR
NOTICE_NO_BEEPING
NOTICE_TRIGGER
664 XView Programming Manual

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.