2014-11-28 16:22:47 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1999-2005 Alfredo K. Kojima, Alban G. Hertroys
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* AUTHOR 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "daargs.h"
|
|
|
|
#include "dautil.h"
|
|
|
|
|
|
|
|
extern struct DAContext *_daContext;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function prototypes
|
|
|
|
*/
|
|
|
|
void _message(const char *label, const char *fmt, va_list args);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Exported functions.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
DASetExpectedVersion(unsigned long expectedVersion)
|
|
|
|
{
|
2014-11-28 16:22:51 +00:00
|
|
|
DAExpectedVersion = expectedVersion;
|
2014-11-28 16:22:47 +00:00
|
|
|
|
2014-11-28 16:22:51 +00:00
|
|
|
if (expectedVersion > DA_VERSION)
|
|
|
|
DAWarning("Version of libdockapp (%u) is older than "
|
|
|
|
"version expected (%u)",
|
|
|
|
DA_VERSION,
|
|
|
|
DAExpectedVersion);
|
2014-11-28 16:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-28 16:22:51 +00:00
|
|
|
Display *
|
2014-11-28 16:22:47 +00:00
|
|
|
DAGetDisplay(char *d, ...)
|
|
|
|
{
|
2014-11-28 16:22:51 +00:00
|
|
|
/* Be backward compatible */
|
|
|
|
if (DAExpectedVersion < 20030126) {
|
|
|
|
va_list ap;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
2014-11-28 16:22:47 +00:00
|
|
|
|
2014-11-28 16:22:51 +00:00
|
|
|
va_start(ap, d);
|
|
|
|
argc = va_arg(ap, int);
|
|
|
|
argv = va_arg(ap, char **);
|
|
|
|
va_end(ap);
|
2014-11-28 16:22:47 +00:00
|
|
|
|
2014-11-28 16:22:51 +00:00
|
|
|
DAOpenDisplay(d, argc, argv);
|
2014-11-28 16:22:47 +00:00
|
|
|
|
2014-11-28 16:22:51 +00:00
|
|
|
DAWarning("Expected version of libdockapp is not set.");
|
|
|
|
DAWarning("Obsolete call to DAGetDisplay().");
|
2014-11-28 16:22:47 +00:00
|
|
|
|
2014-11-28 16:22:51 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2014-11-28 16:22:47 +00:00
|
|
|
|
2014-11-28 16:22:51 +00:00
|
|
|
return DADisplay;
|
2014-11-28 16:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
DASetDisplay(Display *display)
|
|
|
|
{
|
2014-11-28 16:22:51 +00:00
|
|
|
DADisplay = display;
|
2014-11-28 16:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Window
|
|
|
|
DAGetWindow(void)
|
|
|
|
{
|
2014-11-28 16:22:51 +00:00
|
|
|
return DAWindow;
|
2014-11-28 16:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
DASetWindow(Window window)
|
|
|
|
{
|
2014-11-28 16:22:51 +00:00
|
|
|
DAWindow = window;
|
2014-11-28 16:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Window
|
|
|
|
DAGetLeader(void)
|
|
|
|
{
|
2014-11-28 16:22:51 +00:00
|
|
|
return DALeader;
|
2014-11-28 16:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
DASetLeader(Window leader)
|
|
|
|
{
|
2014-11-28 16:22:51 +00:00
|
|
|
DALeader = leader;
|
2014-11-28 16:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Window
|
|
|
|
DAGetIconWindow(void)
|
|
|
|
{
|
2014-11-28 16:22:51 +00:00
|
|
|
return DAIcon;
|
2014-11-28 16:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
DASetIconWindow(Window icon_win)
|
|
|
|
{
|
2014-11-28 16:22:51 +00:00
|
|
|
DAIcon = icon_win;
|
2014-11-28 16:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
DAGetDepth(void)
|
|
|
|
{
|
2014-11-28 16:22:51 +00:00
|
|
|
return DADepth;
|
2014-11-28 16:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
DASetDepth(int depth)
|
|
|
|
{
|
2014-11-28 16:22:51 +00:00
|
|
|
DADepth = depth;
|
2014-11-28 16:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-28 16:22:51 +00:00
|
|
|
Visual *
|
2014-11-28 16:22:47 +00:00
|
|
|
DAGetVisual(void)
|
|
|
|
{
|
2014-11-28 16:22:51 +00:00
|
|
|
return DAVisual;
|
2014-11-28 16:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
DASetVisual(Visual *visual)
|
|
|
|
{
|
2014-11-28 16:22:51 +00:00
|
|
|
DAVisual = visual;
|
2014-11-28 16:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DAWarning(const char *fmt, ...)
|
|
|
|
{
|
2014-11-28 16:22:51 +00:00
|
|
|
va_list args;
|
2014-11-28 16:22:47 +00:00
|
|
|
|
2014-11-28 16:22:51 +00:00
|
|
|
va_start(args, fmt);
|
|
|
|
_message("Warning", fmt, args);
|
|
|
|
va_end(args);
|
2014-11-28 16:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DAError(const char *fmt, ...)
|
|
|
|
{
|
2014-11-28 16:22:51 +00:00
|
|
|
va_list args;
|
2014-11-28 16:22:47 +00:00
|
|
|
|
2014-11-28 16:22:51 +00:00
|
|
|
va_start(args, fmt);
|
|
|
|
_message("Error", fmt, args);
|
|
|
|
exit(1);
|
|
|
|
va_end(args);
|
2014-11-28 16:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
_message(const char *label, const char *fmt, va_list args)
|
|
|
|
{
|
2014-11-28 16:22:51 +00:00
|
|
|
char *w_fmt;
|
2014-11-28 16:22:47 +00:00
|
|
|
|
2014-11-28 16:22:51 +00:00
|
|
|
if (_daContext->programName != NULL) {
|
|
|
|
/* put default string in front of message, add newline */
|
|
|
|
w_fmt = malloc((strlen(_daContext->programName) + strlen(fmt) + 13) * sizeof(char));
|
|
|
|
sprintf(w_fmt, "%s: %s: %s\n", _daContext->programName, label, fmt);
|
|
|
|
} else {
|
|
|
|
w_fmt = malloc((strlen(fmt) + 1) * sizeof(char));
|
|
|
|
sprintf(w_fmt, "%s\n", fmt);
|
|
|
|
}
|
2014-11-28 16:22:47 +00:00
|
|
|
|
2014-11-28 16:22:51 +00:00
|
|
|
/* print the message */
|
|
|
|
vfprintf(stderr, w_fmt, args);
|
2014-11-28 16:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
debug(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2014-11-28 16:22:51 +00:00
|
|
|
va_list args;
|
2014-11-28 16:22:47 +00:00
|
|
|
|
2014-11-28 16:22:51 +00:00
|
|
|
va_start(args, fmt);
|
|
|
|
_message("debug", fmt, args);
|
|
|
|
va_end(args);
|
2014-11-28 16:22:47 +00:00
|
|
|
#endif
|
|
|
|
}
|