beos_x11.cpp revision c041511d
1
2/* Copyright (c) Nate Robins, 1997. */
3
4/* This program is freely distributable without licensing fees
5   and is provided without guarantee or warrantee expressed or
6   implied. This program is -not- in the public domain. */
7
8#include <Screen.h>
9#include <stdio.h>
10#include "beos_x11.h"
11
12/* NOTE:  These functions require a BApplication to be instantiated first */
13int DisplayWidth() {
14	BScreen s;
15	return s.Frame().IntegerWidth() + 1;
16}
17
18int DisplayHeight() {
19	BScreen s;
20	return s.Frame().IntegerHeight() + 1;
21}
22
23/* the following function was stolen from the X sources as indicated. */
24
25/* Copyright 	Massachusetts Institute of Technology  1985, 1986, 1987 */
26/* $XConsortium: XParseGeom.c,v 11.18 91/02/21 17:23:05 rws Exp $ */
27
28/*
29Permission to use, copy, modify, distribute, and sell this software and its
30documentation for any purpose is hereby granted without fee, provided that
31the above copyright notice appear in all copies and that both that
32copyright notice and this permission notice appear in supporting
33documentation, and that the name of M.I.T. not be used in advertising or
34publicity pertaining to distribution of the software without specific,
35written prior permission.  M.I.T. makes no representations about the
36suitability of this software for any purpose.  It is provided "as is"
37without express or implied warranty.
38*/
39
40#if 0	// Not used currently...
41
42/*
43 *Returns pointer to first char ins search which is also in what, else NULL.
44 */
45static char *strscan (char *search, char *what)
46{
47	int i, len = strlen (what);
48	char c;
49
50	while ((c = *(search++))) {
51		for (i = 0; i < len; i++)
52			if (c == what [i])
53				return (--search);
54	}
55	return (NULL);
56}
57
58#endif
59
60/*
61 *    XParseGeometry parses strings of the form
62 *   "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
63 *   width, height, xoffset, and yoffset are unsigned integers.
64 *   Example:  "=80x24+300-49"
65 *   The equal sign is optional.
66 *   It returns a bitmask that indicates which of the four values
67 *   were actually found in the string.  For each value found,
68 *   the corresponding argument is updated;  for each value
69 *   not found, the corresponding argument is left unchanged.
70 */
71
72static int
73ReadInteger(char *string, char **NextString)
74{
75    register int Result = 0;
76    int Sign = 1;
77
78    if (*string == '+')
79	string++;
80    else if (*string == '-')
81    {
82	string++;
83	Sign = -1;
84    }
85    for (; (*string >= '0') && (*string <= '9'); string++)
86    {
87	Result = (Result * 10) + (*string - '0');
88    }
89    *NextString = string;
90    if (Sign >= 0)
91	return (Result);
92    else
93	return (-Result);
94}
95
96int XParseGeometry (char *string, int *x, int *y,
97					unsigned int *width, unsigned int *height)
98{
99	int mask = NoValue;
100	register char *strind;
101	unsigned int tempWidth=0, tempHeight=0;
102	int tempX=0, tempY=0;
103	char *nextCharacter;
104
105	if ( (string == NULL) || (*string == '\0')) return(mask);
106	if (*string == '=')
107		string++;  /* ignore possible '=' at beg of geometry spec */
108
109	strind = (char *)string;
110	if (*strind != '+' && *strind != '-' && *strind != 'x') {
111		tempWidth = ReadInteger(strind, &nextCharacter);
112		if (strind == nextCharacter)
113		    return (0);
114		strind = nextCharacter;
115		mask |= WidthValue;
116	}
117
118	if (*strind == 'x' || *strind == 'X') {
119		strind++;
120		tempHeight = ReadInteger(strind, &nextCharacter);
121		if (strind == nextCharacter)
122		    return (0);
123		strind = nextCharacter;
124		mask |= HeightValue;
125	}
126
127	if ((*strind == '+') || (*strind == '-')) {
128		if (*strind == '-') {
129  			strind++;
130			tempX = -ReadInteger(strind, &nextCharacter);
131			if (strind == nextCharacter)
132			    return (0);
133			strind = nextCharacter;
134			mask |= XNegative;
135
136		}
137		else
138		{	strind++;
139			tempX = ReadInteger(strind, &nextCharacter);
140			if (strind == nextCharacter)
141			    return(0);
142			strind = nextCharacter;
143		}
144		mask |= XValue;
145		if ((*strind == '+') || (*strind == '-')) {
146			if (*strind == '-') {
147				strind++;
148				tempY = -ReadInteger(strind, &nextCharacter);
149				if (strind == nextCharacter)
150			    	    return(0);
151				strind = nextCharacter;
152				mask |= YNegative;
153
154			}
155			else
156			{
157				strind++;
158				tempY = ReadInteger(strind, &nextCharacter);
159				if (strind == nextCharacter)
160			    	    return(0);
161				strind = nextCharacter;
162			}
163			mask |= YValue;
164		}
165	}
166
167	/* If strind isn't at the end of the string the it's an invalid
168		geometry specification. */
169
170	if (*strind != '\0') return (0);
171
172	if (mask & XValue)
173	    *x = tempX;
174 	if (mask & YValue)
175	    *y = tempY;
176	if (mask & WidthValue)
177            *width = tempWidth;
178	if (mask & HeightValue)
179            *height = tempHeight;
180	return (mask);
181}
182