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