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