xenocara/app/editres/geometry.c

435 lines
12 KiB
C
Raw Normal View History

2006-11-25 13:07:29 -07:00
/*
*
Copyright 1989, 1998 The Open Group
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.
*
* Author: Chris D. Peterson, MIT X Consortium
*/
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>
#include <stdio.h>
2018-05-21 09:15:36 -06:00
#include <X11/Xaw/Cardinals.h>
2006-11-25 13:07:29 -07:00
#include "editresP.h"
/*
2018-05-21 09:15:36 -06:00
* Local function definitions
2006-11-25 13:07:29 -07:00
*/
2018-05-21 09:15:36 -06:00
static void AddToFlashList ( TreeInfo * tree_info, GetGeomInfo * geom_info,
2006-11-25 13:07:29 -07:00
char ** errors );
2018-05-21 09:15:36 -06:00
static void _AddToFlashList ( TreeInfo * tree_info, char ** errors,
WNode * node, int x, int y, unsigned int width,
2006-11-25 13:07:29 -07:00
unsigned int height );
2018-05-21 09:15:36 -06:00
static void CreateFlashWidget ( TreeInfo * tree_info, int x, int y,
2006-11-25 13:07:29 -07:00
unsigned int width, unsigned int height );
static void FlashWidgets ( TreeInfo * tree_info );
static void FlashWidgetsOn ( XtPointer info_ptr, XtIntervalId * id );
static void FlashWidgetsOff ( XtPointer info_ptr, XtIntervalId * id );
static void FlashWidgetsCleanup ( XtPointer info_ptr, XtIntervalId * id );
/* Function Name: _FindWidget
* Description: Finds a widget in the tree and shows it to the user.
* Arguments: w - any widget in the application.
* Returns: none.
*/
2018-05-21 09:15:36 -06:00
void
2010-05-31 13:33:38 -06:00
_FindWidget(Widget w)
2006-11-25 13:07:29 -07:00
{
char msg[BUFSIZ];
WNode * node;
Window win;
int x, y; /* location of event in root coordinates. */
2018-05-21 09:15:36 -06:00
snprintf(msg, sizeof(msg), res_labels[14]);
2006-11-25 13:07:29 -07:00
SetMessage(global_screen_data.info_label, msg);
if ( (win = GetClientWindow(w, &x, &y)) != None) {
node = FindWidgetFromWindow(global_tree_info, win);
if (node != NULL) {
2018-05-21 09:15:36 -06:00
ProtocolStream * stream = &(global_client.stream);
2006-11-25 13:07:29 -07:00
_XEditResResetStream(stream);
InsertWidgetFromNode(stream, node);
_XEditResPut16(stream, (short) x);
_XEditResPut16(stream, (short) y);
SetCommand(w, LocalFindChild, NULL);
return;
}
}
2018-05-21 09:15:36 -06:00
SetMessage(global_screen_data.info_label,
2006-11-25 13:07:29 -07:00
res_labels[15]);
}
/* Function Name: DisplayChild
* Description: Displays the child node returned by the client
* Arguments: event - the event from the client.
* Returns: none.
*/
void
2010-05-31 13:33:38 -06:00
DisplayChild(Event *event)
2006-11-25 13:07:29 -07:00
{
FindChildEvent * find_event = (FindChildEvent *) event;
WNode * node;
char msg[BUFSIZ];
node = FindNode(global_tree_info->top_node, find_event->widgets.ids,
find_event->widgets.num_widgets);
if (node == NULL) {
2018-05-21 09:15:36 -06:00
snprintf(msg, sizeof(msg), res_labels[13]);
2006-11-25 13:07:29 -07:00
SetMessage(global_screen_data.info_label, msg);
2018-05-21 09:15:36 -06:00
return;
2006-11-25 13:07:29 -07:00
}
SetAndCenterTreeNode(node);
node = node->tree_info->top_node;
2018-05-21 09:15:36 -06:00
snprintf(msg, sizeof(msg), res_labels[12], node->name, node->class);
2006-11-25 13:07:29 -07:00
SetMessage(global_screen_data.info_label, msg);
_FlashActiveWidgets(global_tree_info);
}
/* Function Name: _FlashActiveWidgets
* Description: Highlights all active widgets in the tree.
* Arguments: tree_info - information about the current tree.
* Returns: none.
*/
void
2010-05-31 13:33:38 -06:00
_FlashActiveWidgets(TreeInfo *tree_info)
2006-11-25 13:07:29 -07:00
{
2018-05-21 09:15:36 -06:00
Cardinal i;
2006-11-25 13:07:29 -07:00
ProtocolStream * stream = &(global_client.stream);
if (tree_info == NULL) {
SetMessage(global_screen_data.info_label,
res_labels[17]);
return;
}
if (tree_info->num_nodes == 0) {
SetMessage(global_screen_data.info_label,res_labels[18]);
return;
}
2018-05-21 09:15:36 -06:00
_XEditResResetStream(stream);
2006-11-25 13:07:29 -07:00
/*
2018-05-21 09:15:36 -06:00
* Insert the number of widgets.
2006-11-25 13:07:29 -07:00
*/
_XEditResPut16(stream, (unsigned short) tree_info->num_nodes);
2018-05-21 09:15:36 -06:00
for (i = 0; i < tree_info->num_nodes; i++)
2006-11-25 13:07:29 -07:00
InsertWidgetFromNode(stream, global_tree_info->active_nodes[i]);
SetCommand(tree_info->tree_widget, LocalFlashWidget, NULL);
}
/* Function Name: HandleFlashWidget
* Description: Is called when client has returned geometry of all widget
* to flash.
* Arguments: event - the event containing the client info.
* Returns: none.
*/
char *
2010-05-31 13:33:38 -06:00
HandleFlashWidget(Event *event)
2006-11-25 13:07:29 -07:00
{
GetGeomEvent * geom_event = (GetGeomEvent *) event;
char * errors = NULL;
int i;
2018-05-21 09:15:36 -06:00
for (i = 0; i < (int)geom_event->num_entries; i++)
2006-11-25 13:07:29 -07:00
AddToFlashList(global_tree_info, geom_event->info + i, &errors);
FlashWidgets(global_tree_info);
return(errors);
}
/* Function Name: AddWidgetToFlashList
* Description: Adds a widget to the list of widget to flash.
* Arguments: tree_info - info about this tree.
* geom_info - the info from the client about this widget.
* errors - a string containing the errors.
* Returns: none
*/
static void
2010-05-31 13:33:38 -06:00
AddToFlashList(TreeInfo *tree_info, GetGeomInfo *geom_info, char **errors)
2006-11-25 13:07:29 -07:00
{
WNode * node;
char buf[BUFSIZ];
2018-05-21 09:15:36 -06:00
node = FindNode(tree_info->top_node,
2006-11-25 13:07:29 -07:00
geom_info->widgets.ids, geom_info->widgets.num_widgets);
if (node == NULL) {
2018-05-21 09:15:36 -06:00
snprintf(buf, sizeof(buf),
"Editres Internal Error: Unable to FindNode.\n");
AddString(errors, buf);
return;
2006-11-25 13:07:29 -07:00
}
if (geom_info->error) {
2018-05-21 09:15:36 -06:00
AddString(errors, geom_info->message);
return;
2006-11-25 13:07:29 -07:00
}
if (!geom_info->visable) {
2018-05-21 09:15:36 -06:00
snprintf(buf, sizeof(buf), "%s(0x%lx) - This widget is not mapped\n",
2006-11-25 13:07:29 -07:00
node->name, node->id);
2018-05-21 09:15:36 -06:00
AddString(errors, buf);
2006-11-25 13:07:29 -07:00
return;
}
2018-05-21 09:15:36 -06:00
_AddToFlashList(tree_info, errors, node,
geom_info->x, geom_info->y,
geom_info->width + geom_info->border_width,
2006-11-25 13:07:29 -07:00
geom_info->height + geom_info->border_width);
}
/* Function Name: _AddToFlashList
* Description: adds the window to the current client's flash list.
* Arguments: errors - a string to stuff any errors encountered.
* node - the node associated with this object.
* x, y - location of the flash widget in root coords.
* width, height - size of the flash widget.
* Returns: none.
*/
static void
2010-05-31 13:33:38 -06:00
_AddToFlashList(TreeInfo *tree_info, char **errors, WNode *node,
int x, int y, unsigned int width, unsigned int height)
2006-11-25 13:07:29 -07:00
{
Display * dpy = XtDisplay(tree_info->tree_widget);
Window window = (Window) node->window;
XWindowAttributes attrs;
if (window == EDITRES_IS_OBJECT)
window = node->parent->window;
if (window == EDITRES_IS_UNREALIZED) {
char buf[BUFSIZ];
2018-05-21 09:15:36 -06:00
if (node->window == EDITRES_IS_OBJECT)
snprintf(buf, sizeof(buf),
"%s(0x%lx) - This object's parent is unrealized\n",
node->name, node->id);
2006-11-25 13:07:29 -07:00
else
2018-05-21 09:15:36 -06:00
snprintf(buf, sizeof(buf),
"%s(0x%lx) - This widget is unrealized\n",
node->name, node->id);
2006-11-25 13:07:29 -07:00
2018-05-21 09:15:36 -06:00
AddString(errors, buf);
2006-11-25 13:07:29 -07:00
return;
}
global_error_code = NO_ERROR; /* Reset Error code. */
global_old_error_handler = XSetErrorHandler(HandleXErrors);
global_serial_num = NextRequest(dpy);
XGetWindowAttributes(dpy, window, &attrs);
XSync(dpy, FALSE);
XSetErrorHandler(global_old_error_handler);
if (global_error_code == NO_WINDOW) {
char buf[BUFSIZ];
2018-05-21 09:15:36 -06:00
snprintf(buf, sizeof(buf),
"%s(0x%lx) - This widget's window no longer exists.\n",
node->name, node->id);
AddString(errors, buf);
2006-11-25 13:07:29 -07:00
return;
2018-05-21 09:15:36 -06:00
}
2006-11-25 13:07:29 -07:00
if (attrs.map_state != IsViewable) {
char buf[BUFSIZ];
2018-05-21 09:15:36 -06:00
snprintf(buf, sizeof(buf), "%s(0x%lx) - This widget is not mapped.\n",
node->name, node->id);
AddString(errors, buf);
2006-11-25 13:07:29 -07:00
return;
2018-05-21 09:15:36 -06:00
}
2006-11-25 13:07:29 -07:00
CreateFlashWidget(tree_info, x, y, width, height);
}
/* Function Name: CreateFlashWidget
* Description: Creates a widget of the size specified that
* will flash on the display, and adds it to the list
* of widgets to flash.
* Arguments: tree_info - the tree information structure.
* x,y,width, height - size and location of the flash widget.
* Returns: none.
*/
2018-05-21 09:15:36 -06:00
2006-11-25 13:07:29 -07:00
#define MORE_FLASH_WIDGETS 5
static void
2010-05-31 13:33:38 -06:00
CreateFlashWidget(TreeInfo *tree_info, int x, int y,
unsigned int width, unsigned int height)
2006-11-25 13:07:29 -07:00
{
Widget shell;
Arg args[3];
Cardinal num = 0;
Dimension bw;
XtSetArg(args[num], XtNx, x); num++;
XtSetArg(args[num], XtNy, y); num++;
XtSetArg(args[num], XtNbackground, global_resources.flash_color); num++;
2018-05-21 09:15:36 -06:00
shell = XtCreatePopupShell("flash", overrideShellWidgetClass,
2006-11-25 13:07:29 -07:00
tree_info->tree_widget, args, num);
num = 0;
XtSetArg(args[num], XtNborderWidth, &bw); num++;
XtGetValues(shell, args, num);
2018-05-21 09:15:36 -06:00
2006-11-25 13:07:29 -07:00
bw *= 2;
num = 0;
XtSetArg(args[num], XtNwidth, (width - bw)); num++;
XtSetArg(args[num], XtNheight, (height - bw)); num++;
2018-05-21 09:15:36 -06:00
XtSetValues(shell, args, num);
2006-11-25 13:07:29 -07:00
if (tree_info->num_flash_widgets + 1 > tree_info->alloc_flash_widgets) {
tree_info->alloc_flash_widgets += MORE_FLASH_WIDGETS;
tree_info->flash_widgets =
(Widget *) XtRealloc((char *)tree_info->flash_widgets,
sizeof(Widget) * tree_info->alloc_flash_widgets);
}
tree_info->flash_widgets[tree_info->num_flash_widgets] = shell;
tree_info->num_flash_widgets++;
}
/* Function Name: FlashWidgets
* Description: Starts the widgets flashing.
* Arguments: tree_info - the info about the tree (contains flash list)
* Returns: none
*/
static void
2010-05-31 13:33:38 -06:00
FlashWidgets(TreeInfo *tree_info)
2006-11-25 13:07:29 -07:00
{
int i;
unsigned long wait, half_flash;
XtAppContext ac = XtWidgetToApplicationContext(tree_info->tree_widget);
if (tree_info->flash_widgets == NULL) /* no widgets to flash. */
return;
wait = half_flash = global_resources.flash_time/2;
for (i = 1; i < global_resources.num_flashes; i++) {
XtAppAddTimeOut(ac, wait, FlashWidgetsOff,(XtPointer)tree_info);
wait += half_flash;
XtAppAddTimeOut(ac, wait, FlashWidgetsOn,(XtPointer)tree_info);
wait += half_flash;
}
wait += half_flash;
XtAppAddTimeOut(ac, wait, FlashWidgetsCleanup, (XtPointer)tree_info);
FlashWidgetsOn((XtPointer) tree_info, (XtIntervalId *) NULL);
}
2018-05-21 09:15:36 -06:00
2006-11-25 13:07:29 -07:00
/* Function Name: FlashWidgetsOn
* Description: Turns on all the Flash Widgets.
* Arguments: info_ptr - pointer to the tree info.
* id - *** UNUSED ***.
* Returns: none
*/
/* ARGSUSED */
static void
2010-05-31 13:33:38 -06:00
FlashWidgetsOn(XtPointer info_ptr, XtIntervalId *id)
2006-11-25 13:07:29 -07:00
{
2018-05-21 09:15:36 -06:00
Cardinal i;
2006-11-25 13:07:29 -07:00
TreeInfo * tree_info = (TreeInfo *) info_ptr;
2018-05-21 09:15:36 -06:00
2006-11-25 13:07:29 -07:00
for (i = 0; i < tree_info->num_flash_widgets; i++) {
XtRealizeWidget(tree_info->flash_widgets[i]);
XMapRaised(XtDisplay(tree_info->flash_widgets[i]),
XtWindow(tree_info->flash_widgets[i]));
}
}
/* Function Name: FlashWidgetsOff
* Description: Turns off all the Flash Widgets.
* Arguments: info_ptr - pointer to the tree info.
* id - *** UNUSED ***.
* Returns: none
*/
/* ARGSUSED */
static void
2010-05-31 13:33:38 -06:00
FlashWidgetsOff(XtPointer info_ptr, XtIntervalId *id)
2006-11-25 13:07:29 -07:00
{
2018-05-21 09:15:36 -06:00
Cardinal i;
2006-11-25 13:07:29 -07:00
TreeInfo * tree_info = (TreeInfo *) info_ptr;
2018-05-21 09:15:36 -06:00
2006-11-25 13:07:29 -07:00
for (i = 0; i < tree_info->num_flash_widgets; i++)
XtUnmapWidget(tree_info->flash_widgets[i]);
}
/* Function Name: FlashWidgetsCleanup
* Description: Destroys all the Flash Widgets.
* Arguments: info_ptr - pointer to the tree info.
* id - *** UNUSED ***.
* Returns: none
*/
/* ARGSUSED */
static void
2010-05-31 13:33:38 -06:00
FlashWidgetsCleanup(XtPointer info_ptr, XtIntervalId *id)
2006-11-25 13:07:29 -07:00
{
2018-05-21 09:15:36 -06:00
Cardinal i;
2006-11-25 13:07:29 -07:00
TreeInfo * tree_info = (TreeInfo *) info_ptr;
/*
* Unmap 'em first for consistency.
*/
2018-05-21 09:15:36 -06:00
2006-11-25 13:07:29 -07:00
for (i = 0; i < tree_info->num_flash_widgets; i++)
XtUnmapWidget(tree_info->flash_widgets[i]);
XFlush(XtDisplay(tree_info->tree_widget));
2018-05-21 09:15:36 -06:00
for (i = 0; i < tree_info->num_flash_widgets; i++)
2006-11-25 13:07:29 -07:00
XtDestroyWidget(tree_info->flash_widgets[i]);
XtFree((char *)tree_info->flash_widgets);
tree_info->flash_widgets = NULL;
tree_info->num_flash_widgets = tree_info->alloc_flash_widgets = 0;
}