dslinux/user/pixil/libs/pim Fl_Editor.cxx Fl_Tree.cxx Flv_Table_Child.cxx Makefile blkio.c catlist.cxx database.h db.c editengine.cxx flnx_col.cxx index.c misc.c nxapp.cxx nxapp.new nxbox.cxx nxbrowser.cxx nxbutton.cxx nxcalendar.cxx nxcheckbutton.cxx nxdb.cxx nxeditcategory.cxx nxholdbrowser.cxx nximage.cxx nxinput.cxx nxintinput.cxx nxmenu.cxx nxmenu_.cxx nxmenuadd.cxx nxmenubar.cxx nxmenubutton.cxx nxmenuwindow.cxx nxmloutput.cxx nxmultilineinput.cxx nxmultilineoutput.cxx nxoutput.cxx nxradioroundbutton.cxx nxscroll.cxx nxscrollbar.cxx nxsecretinput.cxx nxselectbrowser.cxx nxslider.cxx nxtminput.cxx nxvalueslider.cxx nxweekcalendar.cxx nxwindow.cxx syncengine.new use.c wstring.cxx

amadeus dslinux_amadeus at user.in-berlin.de
Tue Oct 3 13:25:29 CEST 2006


Update of /cvsroot/dslinux/dslinux/user/pixil/libs/pim
In directory antilope:/tmp/cvs-serv11916/libs/pim

Added Files:
	Fl_Editor.cxx Fl_Tree.cxx Flv_Table_Child.cxx Makefile blkio.c 
	catlist.cxx database.h db.c editengine.cxx flnx_col.cxx 
	index.c misc.c nxapp.cxx nxapp.new nxbox.cxx nxbrowser.cxx 
	nxbutton.cxx nxcalendar.cxx nxcheckbutton.cxx nxdb.cxx 
	nxeditcategory.cxx nxholdbrowser.cxx nximage.cxx nxinput.cxx 
	nxintinput.cxx nxmenu.cxx nxmenu_.cxx nxmenuadd.cxx 
	nxmenubar.cxx nxmenubutton.cxx nxmenuwindow.cxx nxmloutput.cxx 
	nxmultilineinput.cxx nxmultilineoutput.cxx nxoutput.cxx 
	nxradioroundbutton.cxx nxscroll.cxx nxscrollbar.cxx 
	nxsecretinput.cxx nxselectbrowser.cxx nxslider.cxx 
	nxtminput.cxx nxvalueslider.cxx nxweekcalendar.cxx 
	nxwindow.cxx syncengine.new use.c wstring.cxx 
Log Message:
adding pristine copy of pixil to HEAD so I can branch from it

--- NEW FILE: use.c ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "file.h"
/*
 * use.c - common database record get/put routines
 *
 * from 8/6/85 mt15b
 */

/* local data*/
static struct usefile usefile[NUSEFILES];
static struct field *p;
static char *cp;

/* local procs*/
static void chguse(int fileno);
static void chkuse(int fileno);
static void setpcp(int var);

int
get16(char *addr)
{
    return ((unsigned char) addr[0]) | (((int) (unsigned char) addr[1]) << 8);
}

void
put16(char *addr, unsigned short val16)
{

    *addr++ = val16;
    *addr = val16 >> 8;
}


long
get32(char *addr)
{

    return ((unsigned char) addr[0]) |
	(((long) (unsigned char) addr[1]) << 8) |
	(((long) (unsigned char) addr[2]) << 16) |
	(((long) (unsigned char) addr[3]) << 24);
}


void
put32(char *addr, long val32)
{

    *addr++ = val32;
    *addr++ = val32 >> 8;
    *addr++ = val32 >> 16;
    *addr = val32 >> 24;
}


void
use(int fileno, struct fildes *fp, struct ndxfile *nfp)
{

    chguse(fileno);
    usefile[fileno].fp = fp;
    if (fp != NULL) {
	fp->ndxfp = nfp;
    }
    usefile[fileno].recno = -1;
}

static void
chguse(int fileno)
{
    if (usefile[fileno].uchanged) {
	putrec(usefile[fileno].recno, usefile[fileno].fp,
	       usefile[fileno].rbuf);
	usefile[fileno].uchanged = 0;
    }
}

static void
chkuse(int fileno)
{
    struct fildes *fp;

    if (fileno < 0 || fileno > NUSEFILES)
	fatal(5);		/* chkuse: bad fileno */
    fp = usefile[fileno].fp;
    if (fp->currec != usefile[fileno].recno) {
	chguse(fileno);
	getrec(fp->currec, fp, usefile[fileno].rbuf);
	usefile[fileno].recno = fp->currec;
    }
}

/*
 * return value of file variable
 * on entry, hi byte of var is fileno, lo byte is fieldno
 */
char *
val(int var)
{
    register int len;
    static char varbuf[65];	/* max var len is 64! */

    setpcp(var);
    if ((len = p->size) > 64)
	len = 64;
    fcopy(cp, varbuf, len);
    return (varbuf);
}

short
ival(int var)
{
    setpcp(var);
    return (get16(cp));
}

long
lval(int var)
{
    setpcp(var);
    return (get32(cp));
}

void
replace(int var, union w newval)
{
    setpcp(var);
    switch (p->type) {
    case 'c':
	memcpy(cp, newval.ptr, p->size);
	break;
    case 'd':
    case 'i':
	put16(cp, newval.word);
	break;
    case 'l':
	put32(cp, newval.lword);
	break;
    }
    usefile[var >> 8].uchanged = 1;
}

int
find(int fileno, char *key)
{
    struct fildes *fp;

    fp = usefile[fileno].fp;
    return (fp->currec = search(key, fp->ndxfp, 0));
}

void
store(void *dst, int var)
{
    setpcp(var);
    switch (p->type) {
    case 'c':
	fcopy(cp, (char *) dst, p->size);
	break;
    case 'd':
    case 'i':
	put16(dst, get16(cp));
	break;
    case 'l':
	put32(dst, get32(cp));
	break;
    }
}

static void
setpcp(int var)
{
    register int fileno, fieldno;

    fileno = var >> 8;
    fieldno = var & 0xff;
    chkuse(fileno);
    p = &usefile[fileno].fp->fieldp[fieldno];
    cp = &usefile[fileno].rbuf[p->offset];
}

/*
 * delete current record in usefile
 */
void
udelrec(int fileno)
{
    chkuse(fileno);
    usefile[fileno].rbuf[0] = '*';
    usefile[fileno].uchanged = 1;
}

/*
 * copy a string field replacing nulls with blanks
 */
char *
fcopy(char *src, char *dst, int len)
{
#if 0
    while (len--)
	if (*src)
	    *dst++ = *src++;
	else {
	    *dst++ = ' ';
	    src++;
	}
    *dst++ = 0;			/* null terminate */
    return (dst);
#else
    while (len--)
	*dst++ = *src++;
    *dst++ = 0;
    return (dst);
#endif
}

--- NEW FILE: wstring.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */



//
//  OKay, I know this is a  pretty wimpy string class, but I was in
//  a hurry, OK?  Nothing fancy, just basic "safe" strings.
//

#include <string.h>
#include <ctype.h>
#include <wstring.h>

RCLDLL char
    wString::dummy[2] =
    "";

RCLDLL wString & wString::Strip()
{
    char *
	temp;

    temp = buffer;
    while (isspace(*temp++));
    if (temp > buffer)
	strcpy(buffer, temp);
    temp = buffer + strlen(buffer);
    while (temp > buffer) {
	if (isspace(*(temp - 1)))
	    break;
	temp--;
    }
    *temp = '\0';
    return (*this);
}

RCLDLL void
wString::Initialize(const char *init, long size)
{
    dummy[0] = '\0';
    if (size < 1)
	if (init)
	    size = strlen(init);
	else
	    size = 1;
    BufferCapacity = 0;
    BufferLength = 0;
    buffer = (char *) calloc(1, size + 4);
    if (buffer) {
	BufferCapacity = size + 3;
	if (init)
	    strcpy(buffer, init);
	else
	    buffer[0] = '\0';
	BufferLength = strlen(buffer);
    }
}

RCLDLL
    wString::wString(const char *what, long where, long howmuch, bool stripit)
{
    buffer = (char *) calloc(1, howmuch + 4);
    if (buffer) {
	BufferCapacity = howmuch + 3;
	memcpy(buffer, &what[where], howmuch);
	buffer[howmuch] = '\0';
	BufferLength = strlen(buffer);
	if (stripit)
	    Strip();
	else {
	    *this += wString(howmuch, ' ');
	    this->ChopAt(howmuch);
	}
    } else
	BufferCapacity = 0;
}

RCLDLL wString::wString(char c, int num)
{
    Initialize("", num + 1);
    if (BufferCapacity > num) {
	memset(buffer, c, num);
	buffer[num + 1] = '\0';
    }
}

RCLDLL wString::~wString()
{
    if (buffer)
	free(buffer);
}

RCLDLL void
wString::Shrink()
{
    if (BufferCapacity > (BufferLength + 4)) {
	char *newbuf = (char *) calloc(1, BufferLength + 4);
	if (newbuf) {
	    if (buffer) {
		strcpy(newbuf, buffer);
		free(buffer);
	    }
	    BufferCapacity = BufferLength + 3;
	    buffer = newbuf;
	}
    }
}

RCLDLL void
wString::SSet(const char *val)
{
    long newsize;

    if (val) {
	newsize = strlen(val) + 4;
	if (BufferCapacity < newsize)
	    Grow(newsize - BufferCapacity + 4);
	if (buffer) {		// this will work whether or not the buffer got resized
	    // since if it did, the '\0' will get copied by the
	    // strncpy, and if it didn't, the next line will get it.
	    strncpy(buffer, val, BufferCapacity);
	    buffer[BufferCapacity] = '\0';
	    BufferLength = strlen(buffer);
	    Shrink();
	}
    } else {
	buffer[0] = '\0';
	BufferLength = 0;
	Shrink();
    }
}

RCLDLL wString &
wString::operator+=(const wString & str)
{
    long newsize = BufferLength + str.BufferLength + 4;
    if (newsize > BufferCapacity)
	Grow(newsize - BufferCapacity + 4);
    strcat(buffer, str.buffer);
    BufferLength = strlen(buffer);
    return (*this);
}

RCLDLL wString &
wString::operator+=(char c)
{
    if (BufferLength > BufferCapacity - 4)
	Grow();
    buffer[BufferLength++] = c;
    buffer[BufferLength] = '\0';
    return (*this);
}

RCLDLL wString
wString::Extract(long position, long length, bool cutit)
{
    long count;

    wString s("", length + 1);
    if (position < BufferLength) {
	if (s.buffer) {
	    for (count = 0; count < length; count++)
		s.buffer[count] = this->buffer[position + count];
	    s.buffer[count] = '\0';
	    s.BufferLength = length;
	    if (cutit)
		DeleteAt(position, length);
	}
    }
    return (s);
}

RCLDLL wString
wString::GetWordAt(long position) const
{
    char *temp;

    wString s("", this->BufferCapacity);
    if (s.buffer) {
	// rewind to start of current word
	while (!isspace(this->buffer[position - 1])
	       && !ispunct(this->buffer[position - 1]))
	    if (position)
		position--;
	    else
		break;
	// skip leading punctuation
	while (ispunct(this->buffer[position]))
	    if (position < BufferLength)
		position++;
	    else
		break;
	temp = s.buffer;
	while (this->buffer[position] && !(isspace(this->buffer[position]))) {
	    if (ispunct(this->buffer[position]))
		if (this->buffer[position] != '\'')
		    break;
	    *temp++ = this->buffer[position++];
	}
	*temp = '\0';
	s.BufferLength = strlen(s.buffer);
	s.Shrink();
    }
    return (s);
}

#include <stdio.h>
RCLDLL wString &
wString::InsertAt(long where, char character)
{
    if (AlmostFull()) {
	Grow();
    }

    if (BufferCapacity > BufferLength) {
	if (where <= (BufferLength + 1))	// insert allowed if before NULL terminator
	{
	    memmove(&buffer[where + 1], &buffer[where],
		    (BufferLength + 1) - where + 1);
	    buffer[where] = character;
	    BufferLength++;
	}
    }

    return (*this);
}

RCLDLL wString &
wString::InsertAt(long where, const char *insertme)
{
    long inslen = strlen(insertme);
    if ((BufferCapacity - BufferLength) < inslen)
	Grow(inslen);
    if (BufferCapacity >= (BufferLength + inslen))
	if (where <= (BufferLength + 1))	// insert allowed if before NULL terminator
	{
	    memmove(&buffer[where + inslen], &buffer[where],
		    BufferLength - where + 1);
	    memcpy(&buffer[where], insertme, inslen);
	    BufferLength += inslen;
	}
    return (*this);
}

RCLDLL wString &
wString::DeleteAt(long where, long howmany)
{
    if ((where >= 0) && (where < BufferLength)) {
	if (howmany < (BufferLength - where)) {
	    strcpy(&buffer[where], &buffer[where + howmany]);
	    BufferLength -= howmany;
	} else {
	    buffer[where] = '\0';
	    BufferLength = where;
	}
	Shrink();
    }
    return (*this);
}


RCLDLL wString &
wString::ChopAt(long limit, wString * remainder, bool special)
{
    if ((BufferLength == limit) && BufferLength && (limit >= 0) && special) {
	if (remainder)
	    remainder->SSet(" ");
	buffer[--limit] = '\0';
	BufferLength = limit;
	Shrink();
    } else if (BufferLength && (limit >= 0) && (limit < BufferLength)) {
	if (remainder)
	    remainder->SSet(&buffer[limit]);
	buffer[limit] = '\0';
	BufferLength = limit;
	Shrink();

    } else if (remainder)
	remainder->SSet("");
    return (*this);
}

RCLDLL wString &
wString::WrapAt(long limit, wString * remainder)
{
    if (remainder)
	remainder->SSet("");
    if (BufferLength && (limit >= 0) && (BufferLength == limit)) {
	if (isspace(buffer[limit - 1]))
	    ChopAt(limit, remainder, true);
    }
    if (BufferLength && (limit >= 0) && (limit < BufferLength)) {
	if (isspace(buffer[limit]) || (buffer[limit] == '\0'))
	    ChopAt(++limit, remainder);
	else {
	    bool have_space = false;
	    for (int idx = limit; idx >= 0; idx--) {
		if (isspace(buffer[idx])) {
		    have_space = true;
		}
	    }
	    if (have_space) {
		while (limit && !isspace(buffer[limit]))
		    limit--;
	    }
	    if (limit)
		ChopAt(++limit, remainder);	// skip past space, clip rest of line
	}
    }
    return (*this);
}

RCLDLL wString &
wString::Grow(long howmuch)
{
    char *newbuf = (char *) calloc(1, BufferCapacity + howmuch + 1);
    if (newbuf) {
	if (buffer) {
	    strcpy(newbuf, buffer);
	    free(buffer);
	} else
	    newbuf[0] = '\0';
	BufferCapacity += howmuch;
	buffer = newbuf;
    }
    return (*this);
}

RCLDLL wString
operator+(const char *str1, const wString & str2)
{
    wString s(str1);
    s += str2;
    return (s);
}

RCLDLL wString
operator+(const wString & str1, const char *str2)
{
    long len = strlen(str2);
    wString s(str1.Get(), str1.Length() + len + 4);
    strcat(s.buffer, str2);
    s.BufferLength += len;
    return (s);
}

RCLDLL void
Pack(wString & string)
{
    long count = 0;

    while (count < string.Length())
	if (ispunct(string[count]) || isspace(string[count]))
	    string.DeleteAt(count, 1);
	else
	    count++;
}

--- NEW FILE: nxdb.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /*  */

#include "nxdb.h"
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#else /*  */
#include <stdlib.h>
#endif /*  */

#include <string.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <assert.h>
#include <locale.h>

#ifdef WIN32
#include <iostream>
#include <direct.h>
#else /*  */
#ifdef __UCLIBC__
#include <iostream>
#endif /*  */
#include <unistd.h>
#endif /*  */

#define OPTIONS "p:k:d:m:"
char *p_arg = 0;
NxDb::NxDb(int argc, char *argv[])
{
    int c;
    path = ".";
    while ((c = getopt(argc, argv, OPTIONS)) != -1) {
	switch (c) {
	case 'p':
	    path = optarg;

	    /*
	       p_arg = optarg;
	       struct stat dir;
	       if ( stat(p_arg, &dir) == 0) {
	       path = p_arg;
	       }
	     */
	    break;
	default:
	    break;
	}			// switch
    }				// while
    dbNum = 0;
    dbinit(0);
}

int
NxDb::Open(string _dbName, fildes * _dbDesc, field * _dbField, int var,
	   int path_flag)
{
    printf("Registering %s\n", _dbName.c_str());

    Register(_dbName, _dbDesc, _dbField, var);

    // Open Database
    string path_dbName;
    if (path_flag)
	path_dbName = _dbName;

    else {
	int len = path.length() - 1;
	if (path[len] != '/' && _dbName[0] != '/')
	    path += '/';
	path_dbName = path + _dbName;
    }
    struct stat dir;
    if (0 != stat(path.c_str(), &dir)) {

#ifndef WIN32
	mkdir(path.c_str(), S_IRWXU);

#else /*  */
	string strDir;
	unsigned int nPos1;
	unsigned int nPos2;

	// Make each level of the directory in turn
	if (path[1] == ':') {

	    // Bypass the drive letter et al
	    nPos1 = (path[2] == '/' || path[2] == '\\') ? 3 : 2;
	}

	else {
	    nPos1 = 0;
	}
	while (nPos1 != string::npos) {

	    // Get the next directory level
	    nPos2 = path.find('/', nPos1);
	    nPos1 = path.find('\\', nPos1);
	    if (nPos1 == string::npos) {
		nPos1 = nPos2;
	    }

	    else if (nPos2 != string::npos) {

		// Where do both Windows and Unix/Linix hide min ?
		nPos1 = (nPos1 <= nPos2 ? nPos1 : nPos2);
	    }
	    // Get the next directory level
	    if (nPos1 != string::npos) {
		strDir = path.substr(0, nPos1);
	    }

	    else {
		strDir = path;
	    }

	    // Make this directory level
	    _mkdir(strDir.c_str());

	    // Set for the next loop
	    if (nPos1 != string::npos) {
		++nPos1;
	    }
	}

#endif /*  */
    }
    if (!dbopen(_dbDesc, (char *) path_dbName.c_str())) {
	fprintf(stderr, "(1) Unable to open:[%s.%s]\n", path_dbName.c_str(),
		_dbDesc->filext);
	return 0;
    } else {

	//fprintf(stderr, "Open DB: [%s] fp: %d\n", path_dbName.c_str(), _dbDesc->fildesc);
    }
    return 1;
}

int
NxDb::Close(string _dbName)
{

#ifdef DEBUG
    assert(db.find(_dbName) != db.end());

#endif /*  */
    int dbNumber = db[_dbName];
    fildes *_dbDesc = dbDesc[dbNumber];
    dbclose(_dbDesc);

#ifdef WIN32
    return (0);

#endif /*  */
}

void
NxDb::Register(string _dbName, fildes * _dbDesc, field * _dbField, int var)
{
    TDatabase::iterator p = db.find(_dbName);
    if (p == db.end()) {
	printf("Inserting %s\n", _dbName.c_str());

	db.insert(TValue(_dbName, dbNum));
	dbNum++;
    }
    TDatabase::iterator result = db.find(_dbName);
    if (result == db.end()) {
	exit(-1);
    } else {

#ifdef DEBUG
	assert(db.find(_dbName) != db.end());

#endif /*  */
	int dbNumber = db[_dbName];
	dbDesc[dbNumber] = _dbDesc;
	dbField[dbNumber] = _dbField;
    }
}
int
NxDb::Create(string _dbName, fildes * _dbDesc, field * _dbField, int var,
	     int path_flag)
{
    string path_dbName;
    if (path_flag)
	path_dbName = _dbName;

    else
	path_dbName = path + _dbName;
    if (!dbcreat(_dbDesc, (char *) path_dbName.c_str())) {
	cerr << "NxDb::Could not create: " << path_dbName << _dbDesc->
	    filext << endl;
	exit(-1);
    }
    Register(_dbName, _dbDesc, _dbField, var);

    //  use(0, NULL, NULL);
    Close(_dbName);
    return 1;
}

int
NxDb::SetFlags(const string _dbName, const int &recno, const int &flags)
{

#ifdef DEBUG
    assert(db.find(_dbName) != db.end());

#endif /*  */
    char buf[MAXRECSIZ];
    int dbNumber = db[_dbName];
    struct fildes *fp = dbDesc[dbNumber];
    int ok = getrec(recno, fp, &buf[0]);
    if (ok)
	fp->flags = flags;

    else
	return -1;
    ok = putrec(recno, fp, &buf[0]);
    dbsave(fp);
    if (ok)
	return 0;

    else
	return -2;
}

int
NxDb::GetFlags(const string _dbName, const int &recno, int &flags)
{

#ifdef DEBUG
    assert(db.find(_dbName) != db.end());

#endif /*  */
    char buf[MAXRECSIZ];
    int dbNumber = db[_dbName];
    struct fildes *fp = dbDesc[dbNumber];
    int ok = getrec(recno, fp, &buf[0]);

    //if (ok)
    flags = fp->flags;

    //cout << "GetFlags(): fp->flags = " << fp->flags << endl;
    //else
    //      return -1;
    return ok;
}

void
NxDb::Insert(string _dbName, char *record)
{

#ifdef DEBUG
    assert(db.find(_dbName) != db.end());

#endif /*  */
    int dbNumber = db[_dbName];
    fildes *fp = dbDesc[dbNumber];
    int recno = APPEND;
    char ret_buf[MAXRECSIZ];

    // look for an empty spot
    for (int i = 1; i <= fp->nrecs; i++) {
	getrec(i, fp, ret_buf);
	if (recerased(fp)) {
	    break;
	}
    }
    fp->flags = NEW;
    putrec(recno, fp, record);

    //cout << "Insert(): recno = " << fp->currec << endl;
    dbsave(fp);
}

void
NxDb::Insert(string _dbName, char *record, int &rec)
{

#ifdef DEBUG
    assert(db.find(_dbName) != db.end());

#endif /*  */
    int dbNumber = db[_dbName];
    fildes *fp = dbDesc[dbNumber];
    int recno = APPEND;
    char ret_buf[MAXRECSIZ];

    // look for an empty spot
    for (int i = 1; i <= fp->nrecs; i++) {
	getrec(i, fp, ret_buf);
	if (recerased(fp)) {
	    break;
	}
    }
    fp->flags = NEW;
    putrec(recno, fp, record);

    //cout << "fp->currec = " << fp->currec << endl;
    rec = fp->currec;
    dbsave(fp);
}

void
NxDb::Edit(string _dbName, int recno, char *record)
{

#ifdef DEBUG
    assert(db.find(_dbName) != db.end());

#endif /*  */
    int dbNumber = db[_dbName];
    fildes *fp = dbDesc[dbNumber];

    // If record has NEW bit set, keep the new bit
    // or else set the bit to changed
    if (!(fp->flags & NEW))
	fp->flags = CHANGED;

    //cout << "Edit() recno = " << recno << endl;
    putrec(recno, fp, record);
    dbsave(fp);
}

void
NxDb::DeleteRec(string _dbName, int recno)
{

#ifdef DEBUG
    assert(db.find(_dbName) != db.end());

#endif /*  */
    int dbNumber = db[_dbName];
    fildes *fp = dbDesc[dbNumber];
    char ret_buf[MAXRECSIZ];
    getrec(recno, fp, ret_buf);

    // If a NEW occurs and then is immediately
    // delete, it would send the deleted record
    // across during a sync, which the other side
    // would not know about. Therefore, ERASE instead
    // of DELETED.
    //////////////////////////////////////////////////
    if (fp->flags & NxDb::NEW)
	fp->flags = NxDb::ERASED;

    else
	fp->flags = NxDb::DELETED;

    //cout << "DeleteRec(): fp->flags = " << fp->flags << endl;
    putrec(recno, fp, ret_buf);

    //fp->flags = 0;
    dbsave(fp);
}

void
NxDb::EraseRec(string _dbName, int recno)
{

#ifdef DEBUG
    assert(db.find(_dbName) != db.end());

#endif /*  */
    int dbNumber = db[_dbName];
    fildes *fp = dbDesc[dbNumber];
    char ret_buf[MAXRECSIZ];
    getrec(recno, fp, ret_buf);
    fp->flags = NxDb::ERASED;
    putrec(recno, fp, ret_buf);
    fp->flags = 0;
    dbsave(fp);
}

int
NxDb::NumRecs(string _dbName)
{

#ifdef DEBUG
    assert(db.find(_dbName) != db.end());

#endif /*  */
    int dbNumber = db[_dbName];
    struct fildes *fp = dbDesc[dbNumber];
    return fp->nrecs;
}

int
NxDb::Select(string _dbName, int ret[], int ret_size, bool bDeleteFlag,
	     int flags)
{

#ifdef DEBUG
    assert(db.find(_dbName) != db.end());

#endif /*  */
    int dbNumber = db[_dbName];
    struct fildes *fp = dbDesc[dbNumber];
    char ret_buf[MAXRECSIZ];

    //  bDeleteFlag = true;
    int idx = 0;
    for (int i = 1; i <= fp->nrecs; i++) {
	getrec(i, fp, ret_buf);
	if (flags != -1) {

	    //cout << "fp->flags = " << fp->flags << endl;
	    //cout << "flags = " << flags << endl;
	    if (!(fp->flags & flags))
		continue;
	} else {
	    if (fp->flags & NxDb::ERASED ||	// Skip erase records
		(fp->flags & NxDb::DELETED && !bDeleteFlag)) {	// Skip logically deleted records if bDeleteFlag not set
		continue;
	    }
	}
	ret[idx] = i;
	idx++;
    }
    return idx;
}

int
NxDb::Select(string _dbName, char *value, int fieldNo, int ret[],
	     int ret_size, bool bDeleteFlag)
{

#ifdef DEBUG
    assert(db.find(_dbName) != db.end());

#endif /*  */
    int dbNumber = db[_dbName];
    struct fildes *fp = dbDesc[dbNumber];
    field *_dbField = dbField[dbNumber];
    char ret_buf[MAXRECSIZ];
    int idx = 0;
    char type;
    type = _dbField[fieldNo].type;

    //cout << "Select()\n";
    for (int i = 1; i <= fp->nrecs; i++) {
	if (idx == ret_size) {
	    return idx;
	}
	memset(ret_buf, 0, MAXRECSIZ);
	getrec(i, fp, ret_buf);

	//cout << "\tSelect(): recno = " << i << endl;
	if (recdeleted(fp) && !bDeleteFlag) {

	    //cout << "recdeleted()\n";
	    continue;
	}
	if (type == 'c') {
	    if (strcmp(value, &ret_buf[_dbField[fieldNo].offset]) == 0) {
		ret[idx] = i;
		idx++;
	    }
	} else if ((type == 'd') || (type == 'i')) {
	    int num = get16(&ret_buf[_dbField[fieldNo].offset]);
	    if (num == atoi(value)) {
		ret[idx] = i;
		idx++;
	    }
	} else if (type == 'l') {
	    long num = get32(&ret_buf[_dbField[fieldNo].offset]);
	    if (num == strtol(value, NULL, 10)) {
		ret[idx] = i;
		idx++;
	    }
	} else {
	    return idx;
	}
    }
    return idx;
}

int
NxDb::Extract(string _dbName, int recno, char *ret_buf)
{

#ifdef DEBUG
    assert(db.find(_dbName) != db.end());

#endif /*  */
    int dbNumber = db[_dbName];
    struct fildes *fp = dbDesc[dbNumber];
    return getrec(recno, fp, ret_buf);
}

int
NxDb::Extract(string _dbName, int recno, int fieldNo, char *ret_buf)
{

#ifdef DEBUG
    assert(db.find(_dbName) != db.end());

#endif /*  */
    int dbNumber = db[_dbName];
    struct fildes *fp = dbDesc[dbNumber];
    field *_dbField = dbField[dbNumber];
    char type;
    char rec_buf[MAXRECSIZ];
    int ival = 0;
    long lval = 0;
    type = _dbField[fieldNo].type;
    if (getrec(recno, fp, rec_buf) == 0)
	return 0;
    switch (type) {
    case 'c':{

	    //cout << "Extract(): c\n";
	    //int size = int(_dbField[fieldNo].size);
	    //size = size - 1;
	    //cerr << "Extract(): size = " << size << endl;
	    //memset(ret_buf, 0, size);
	    strcpy(ret_buf, &rec_buf[_dbField[fieldNo].offset]);

	    //ret_buf[size] = 0;
	    return 1;
	}
    case 'd':
    case 'i':
	ival = get16(&rec_buf[_dbField[fieldNo].offset]);

	//cout << "Extract(): i = " << ival << endl;
	sprintf(ret_buf, "%d", ival);
	return 1;
    case 'l':
	lval = get32(&rec_buf[_dbField[fieldNo].offset]);

	//cout << "Extract(): l\n";
	sprintf(ret_buf, "%ld", lval);
	return 1;
    default:
	break;
    }
    return 0;
}

int
NxDb::ExtractDeleted(string _dbName, int recno, int fieldNo, char *ret_buf)
{

#ifdef DEBUG
    assert(db.find(_dbName) != db.end());

#endif /*  */
    int dbNumber = db[_dbName];
    struct fildes *fp = dbDesc[dbNumber];
    field *_dbField = dbField[dbNumber];
    char type;
    char rec_buf[MAXRECSIZ];
    int ival = 0;
    long lval = 0;
    type = _dbField[fieldNo].type;
    if (getrec(recno, fp, rec_buf) == 1)
	return 0;
    switch (type) {
    case 'c':

	//cout << "Extract(): c\n";
	strcpy(ret_buf, &rec_buf[_dbField[fieldNo].offset]);
	return 1;
    case 'd':
    case 'i':
	ival = get16(&rec_buf[_dbField[fieldNo].offset]);

	//cout << "Extract(): i = " << ival << endl;
	sprintf(ret_buf, "%d", ival);
	return 1;
    case 'l':
	lval = get32(&rec_buf[_dbField[fieldNo].offset]);

	//cout << "Extract(): l\n";
	sprintf(ret_buf, "%ld", lval);
	return 1;
    default:
	break;
    }
    return 0;
}

field *
NxDb::GetField(string _dbName)
{

#ifdef DEBUG
    printf("Looking for database %s\n", _dbName.c_str());

    assert(db.find(_dbName) != db.end());

#endif /*  */
    int dbNumber = db[_dbName];
    struct field *fp = dbField[dbNumber];
    return fp;
}

fildes *
NxDb::GetFilDes(string _dbName)
{

#ifdef DEBUG
    assert(db.find(_dbName) != db.end());

#endif /*  */
    int dbNumber = db[_dbName];
    struct fildes *fp = dbDesc[dbNumber];
    return fp;
}

void
NxDb::Purge(string _dbName, int fieldNo, char *value)
{

#ifdef DEBUG
    assert(db.find(_dbName) != db.end());

#endif /*  */
    int dbNumber = db[_dbName];
    fildes *fp = dbDesc[dbNumber];
    char ret_buf[MAXRECSIZ];
    if (fieldNo != -1) {

	// Purge specific records
	for (int i = 1; i <= fp->nrecs; i++) {
	    Extract(_dbName, i, fieldNo, ret_buf);
	    if (strcmp(ret_buf, value) == 0)
		DeleteRec(_dbName, i);
	}
    } else {

	// Purge all records
	for (int i = 1; i < fp->nrecs; i++)
	    DeleteRec(_dbName, i);
    }
}
void
fatal(int n)
{
    printf("*** Fatal Error #%d\n", n);
}

--- NEW FILE: flnx_col.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Menu_Button.H>

#include <iostream>
#include <unistd.h>

#include "nxapp.h"

#define BY 30

/*
 *
 * Tester Class
 *
 */

class IPCTester:public NxApp
{

  public:

    int fd;
    static int ipc;

      IPCTester()
    {
	fd = Add_Fd("flnx_col", ClientIPCHandler);
    }
     ~IPCTester()
    {
	Remove_Fd(fd);
    }

    // Client IPC Handler
    static void ClientIPCHandler(int fd, void *o);

    // Callbacks
    static void ResetCB(Fl_Widget * fl, void *o);

    // INITIATE
    static void InitiateCB(Fl_Widget * fl, void *o);

    // EXECUTE
    static void ExecuteAllClientsCB(Fl_Widget * fl, void *o);
    static void ExecuteResizeKbdCB(Fl_Widget * fl, void *o);
    static void ExecuteResizeWinCB(Fl_Widget * fl, void *o);
    static void ExecuteNoGuiSearchCB(Fl_Widget * fl, void *o);
    static void ExecuteShowCB(Fl_Widget * fl, void *o);
    static void ExecuteHideCB(Fl_Widget * fl, void *o);
    static void ExecuteSearchCB(Fl_Widget * fl, void *o);
    static void ExecuteExitCB(Fl_Widget * fl, void *o);

    // REQUEST
    static void RequestDefWinXCB(Fl_Widget * fl, void *o);
    static void RequestDefWinYCB(Fl_Widget * fl, void *o);
    static void RequestDefWinWCB(Fl_Widget * fl, void *o);
    static void RequestDefWinHCB(Fl_Widget * fl, void *o);
    static void RequestShowWinXCB(Fl_Widget * fl, void *o);
    static void RequestShowWinYCB(Fl_Widget * fl, void *o);
    static void RequestShowWinWCB(Fl_Widget * fl, void *o);
    static void RequestShowWinHCB(Fl_Widget * fl, void *o);
    static void RequestKbdRunCB(Fl_Widget * fl, void *o);

    // TERMINATE
    static void TerminateCB(Fl_Widget * fl, void *o);

};


// Control Window
Fl_Window *w;
Fl_Window *mw;
Fl_Input *application;
Fl_Menu_Button *result;
Fl_Button *reset;


// Tests Window
// INITIATE
Fl_Button *initiateBut;

// EXECUTE
Fl_Button *executeAllClientsBut;
Fl_Button *executeResizeKbdBut;
Fl_Button *executeResizeWinBut;
Fl_Button *executeNoGuiSearchBut;
Fl_Button *executeShowBut;
Fl_Button *executeHideBut;
Fl_Button *executeSearchBut;
Fl_Button *executeExitBut;

// REQUEST
Fl_Button *requestDefWinXBut;
Fl_Button *requestDefWinYBut;
Fl_Button *requestDefWinWBut;
Fl_Button *requestDefWinHBut;
Fl_Button *requestShowWinXBut;
Fl_Button *requestShowWinYBut;
Fl_Button *requestShowWinWBut;
Fl_Button *requestShowWinHBut;
Fl_Button *requestKbdRunBut;

// TERMINATE
Fl_Button *terminateBut;

int
main(int argc, char *argv[])
{

    IPCTester t;

    mw = new Fl_Window(0, 0, 305, 75, "Control Window");

    application = new Fl_Input(5, 25, 300, 20, "NX Application");
    application->align(FL_ALIGN_LEFT | FL_ALIGN_TOP);

    reset = new Fl_Button(225, 3, 80, 20, "Reset");
    reset->callback(IPCTester::ResetCB);

    result = new Fl_Menu_Button(5, 50, 300, 20, "Results");
    mw->end();

    w = new Fl_Window(0, 0, 350, 350, "Tests Window");

    {
	Fl_Output *o = new Fl_Output(5, 0, 80, 30);
	o->color(FL_GRAY);
	o->box(FL_FLAT_BOX);
	o->textsize(10);
	o->value("I. Start Here.");
    }

    // INITIATE
    initiateBut = new Fl_Button(5, BY, 80, 30, "Inititate");
    initiateBut->color(FL_YELLOW);
    initiateBut->callback(IPCTester::InitiateCB);

    {

	Fl_Output *o = new Fl_Output(90, 0, 80, 30);
	o->color(FL_GRAY);
	o->box(FL_FLAT_BOX);
	o->textsize(10);
	o->value("II. Execute");
    }


    // EXECUTE
    executeAllClientsBut = new Fl_Button(90, BY, 80, 30, "All Clients");
    executeAllClientsBut->color(FL_YELLOW);
    executeAllClientsBut->callback(IPCTester::ExecuteAllClientsCB);

    executeResizeKbdBut =
	new Fl_Button(90, BY + 32, 80, 30, "Move\nKeyboard");
    executeResizeKbdBut->color(FL_YELLOW);
    executeResizeKbdBut->callback(IPCTester::ExecuteResizeKbdCB);

    executeResizeWinBut =
	new Fl_Button(90, BY + 64, 80, 30, "Resize\nWindow");
    executeResizeWinBut->color(FL_YELLOW);
    executeResizeWinBut->callback(IPCTester::ExecuteResizeWinCB);

    executeNoGuiSearchBut =
	new Fl_Button(90, BY + 96, 80, 30, "No Gui\nSearch");
    executeNoGuiSearchBut->callback(IPCTester::ExecuteNoGuiSearchCB);

    executeShowBut = new Fl_Button(90, BY + 128, 80, 30, "Show");
    executeShowBut->color(FL_YELLOW);
    executeShowBut->callback(IPCTester::ExecuteShowCB);

    executeHideBut = new Fl_Button(90, BY + 160, 80, 30, "Hide");
    executeHideBut->color(FL_YELLOW);
    executeHideBut->callback(IPCTester::ExecuteHideCB);

    executeSearchBut = new Fl_Button(90, BY + 192, 80, 30, "Search");
    executeSearchBut->color(FL_YELLOW);
    executeSearchBut->callback(IPCTester::ExecuteSearchCB);

    executeExitBut = new Fl_Button(90, BY + 224, 80, 30, "Exit");
    executeExitBut->color(FL_YELLOW);
    executeExitBut->callback(IPCTester::ExecuteExitCB);


    // REQUEST
    {
	Fl_Output *o = new Fl_Output(175, 0, 80, 30);
	o->color(FL_GRAY);
	o->box(FL_FLAT_BOX);
	o->textsize(10);
	o->value("III. Request");
    }

    requestDefWinXBut = new Fl_Button(175, BY, 80, 30, "Default X");
    requestDefWinXBut->color(FL_YELLOW);
    requestDefWinXBut->callback(IPCTester::RequestDefWinXCB);

    requestDefWinYBut = new Fl_Button(175, BY + 32, 80, 30, "Default Y");
    requestDefWinYBut->color(FL_YELLOW);
    requestDefWinYBut->callback(IPCTester::RequestDefWinYCB);

    requestDefWinWBut = new Fl_Button(175, BY + 64, 80, 30, "Default\nWidth");
    requestDefWinWBut->color(FL_YELLOW);
    requestDefWinWBut->callback(IPCTester::RequestDefWinWCB);

    requestDefWinHBut =
	new Fl_Button(175, BY + 96, 80, 30, "Default\nHeight");
    requestDefWinHBut->color(FL_YELLOW);
    requestDefWinHBut->callback(IPCTester::RequestDefWinHCB);

    requestShowWinXBut = new Fl_Button(175, BY + 128, 80, 30, "Shown X");
    requestShowWinXBut->color(FL_YELLOW);
    requestShowWinXBut->callback(IPCTester::RequestShowWinXCB);

    requestShowWinYBut = new Fl_Button(175, BY + 160, 80, 30, "Show Y");
    requestShowWinYBut->color(FL_YELLOW);
    requestShowWinYBut->callback(IPCTester::RequestShowWinYCB);

    requestShowWinWBut = new Fl_Button(175, BY + 192, 80, 30, "Show\nWidth");
    requestShowWinWBut->color(FL_YELLOW);
    requestShowWinWBut->callback(IPCTester::RequestShowWinWCB);

    requestShowWinHBut = new Fl_Button(175, BY + 224, 80, 30, "Show\nHeight");
    requestShowWinHBut->color(FL_YELLOW);
    requestShowWinHBut->callback(IPCTester::RequestShowWinHCB);

    requestKbdRunBut =
	new Fl_Button(175, BY + 256, 80, 30, "Keboard\nRunning?");
    requestKbdRunBut->color(FL_YELLOW);
    requestKbdRunBut->callback(IPCTester::RequestKbdRunCB);

    // TERMINATE

    {
	Fl_Output *o = new Fl_Output(260, 0, 80, 30);
	o->color(FL_GRAY);
	o->box(FL_FLAT_BOX);
	o->textsize(10);
	o->value("IV. Quit Here");
    }

    terminateBut = new Fl_Button(260, BY, 80, 30, "Terminate");
    terminateBut->color(FL_YELLOW);
    terminateBut->callback(IPCTester::TerminateCB);

    w->end();

    mw->show(argc, argv);
    w->show(argc, argv);

    Fl::run();

}

int
    IPCTester::ipc;

void
IPCTester::ClientIPCHandler(int fd, void *o)
{

    cout << "ClientIPCHandler: file descriptor tripped.\n";

    int ipc_id = -1;

    if (o == NULL) {

	char passMsg[255];
	int length = sizeof(passMsg);
	ipc_id = NxApp::Instance()->Read_Fd(passMsg, &length);

	cout << "Returned... " << passMsg << "." << endl;

	result->add(passMsg);

    } else {

	cout << "Error... void *o not NULL.\n";

    }

}

void
IPCTester::ResetCB(Fl_Widget * fl, void *o)
{

    result->clear();

}

void
IPCTester::InitiateCB(Fl_Widget * fl, void *o)
{

    if (application->value() == NULL)
	return;

    ipc = NxApp::Instance()->Find_Fd((char *) application->value());

    char msg[255];
    int len = sizeof(msg);
    strcpy(msg, "flnx_col^INITIATE^0^");

    NxApp::Instance()->Write_Fd(ipc, msg, len);

}

void
IPCTester::ExecuteAllClientsCB(Fl_Widget * fl, void *o)
{

    if (application->value() == NULL)
	return;

    ipc = NxApp::Instance()->Find_Fd((char *) application->value());

    char msg[255];
    int len = sizeof(msg);
    strcpy(msg, "flnx_col^EXECUTE^all_clients^hide");

    NxApp::Instance()->Write_Fd(ipc, msg, len);


}

void
IPCTester::ExecuteResizeKbdCB(Fl_Widget * fl, void *o)
{

    if (application->value() == NULL)
	return;

    ipc = NxApp::Instance()->Find_Fd((char *) application->value());

    char msg[255];
    int len = sizeof(msg);
    strcpy(msg, "flnx_col^EXECUTE^move_keyboard^0^0^");

    NxApp::Instance()->Write_Fd(ipc, msg, len);


}

void
IPCTester::ExecuteResizeWinCB(Fl_Widget * fl, void *o)
{

    if (application->value() == NULL)
	return;

    ipc = NxApp::Instance()->Find_Fd((char *) application->value());

    char msg[255];
    int len = sizeof(msg);
    strcpy(msg, "flnx_col^EXECUTE^resize_win^0^0^240^200^");

    NxApp::Instance()->Write_Fd(ipc, msg, len);


}

void
IPCTester::ExecuteNoGuiSearchCB(Fl_Widget * fl, void *o)
{

    if (application->value() == NULL)
	return;

    ipc = NxApp::Instance()->Find_Fd((char *) application->value());

    char msg[255];
    int len = sizeof(msg);
    strcpy(msg, "flnx_col^EXECUTE^noguisearch^");

    NxApp::Instance()->Write_Fd(ipc, msg, len);

}

void
IPCTester::ExecuteShowCB(Fl_Widget * fl, void *o)
{

    if (application->value() == NULL)
	return;

    ipc = NxApp::Instance()->Find_Fd((char *) application->value());

    char msg[255];
    int len = sizeof(msg);
    strcpy(msg, "flnx_col^EXECUTE^show^");

    NxApp::Instance()->Write_Fd(ipc, msg, len);


}

void
IPCTester::ExecuteHideCB(Fl_Widget * fl, void *o)
{

    if (application->value() == NULL)
	return;

    ipc = NxApp::Instance()->Find_Fd((char *) application->value());

    char msg[255];
    int len = sizeof(msg);
    strcpy(msg, "flnx_col^EXECUTE^hide^");

    NxApp::Instance()->Write_Fd(ipc, msg, len);


}

void
IPCTester::ExecuteSearchCB(Fl_Widget * fl, void *o)
{

    if (application->value() == NULL)
	return;

    ipc = NxApp::Instance()->Find_Fd((char *) application->value());

    char msg[255];
    int len = sizeof(msg);
    strcpy(msg, "flnx_col^EXECUTE^search^Jeff^240");

    NxApp::Instance()->Write_Fd(ipc, msg, len);


}

void
IPCTester::ExecuteExitCB(Fl_Widget * fl, void *o)
{

    if (application->value() == NULL)
	return;

    ipc = NxApp::Instance()->Find_Fd((char *) application->value());

    char msg[255];
    int len = sizeof(msg);
    strcpy(msg, "flnx_col^EXECUTE^exit^");

    NxApp::Instance()->Write_Fd(ipc, msg, len);


}

void
IPCTester::RequestDefWinXCB(Fl_Widget * fl, void *o)
{

    if (application->value() == NULL)
	return;

    ipc = NxApp::Instance()->Find_Fd((char *) application->value());

    char msg[255];
    int len = sizeof(msg);
    strcpy(msg, "flnx_col^REQUEST^default_win_x^");

    NxApp::Instance()->Write_Fd(ipc, msg, len);


}

void
IPCTester::RequestDefWinYCB(Fl_Widget * fl, void *o)
{

    if (application->value() == NULL)
	return;

    ipc = NxApp::Instance()->Find_Fd((char *) application->value());

    char msg[255];
    int len = sizeof(msg);
    strcpy(msg, "flnx_col^REQUEST^default_win_y^");

    NxApp::Instance()->Write_Fd(ipc, msg, len);


}

void
IPCTester::RequestDefWinWCB(Fl_Widget * fl, void *o)
{

    if (application->value() == NULL)
	return;

    ipc = NxApp::Instance()->Find_Fd((char *) application->value());

    char msg[255];
    int len = sizeof(msg);
    strcpy(msg, "flnx_col^REQUEST^default_win_w");

    NxApp::Instance()->Write_Fd(ipc, msg, len);


}

void
IPCTester::RequestDefWinHCB(Fl_Widget * fl, void *o)
{

    if (application->value() == NULL)
	return;

    ipc = NxApp::Instance()->Find_Fd((char *) application->value());

    char msg[255];
    int len = sizeof(msg);
    strcpy(msg, "flnx_col^REQUEST^default_win_h^");

    NxApp::Instance()->Write_Fd(ipc, msg, len);


}

void
IPCTester::RequestShowWinXCB(Fl_Widget * fl, void *o)
{

    if (application->value() == NULL)
	return;

    ipc = NxApp::Instance()->Find_Fd((char *) application->value());

    char msg[255];
    int len = sizeof(msg);
    strcpy(msg, "flnx_col^REQUEST^show_win_x^");

    NxApp::Instance()->Write_Fd(ipc, msg, len);


}

void
IPCTester::RequestShowWinYCB(Fl_Widget * fl, void *o)
{

    if (application->value() == NULL)
	return;

    ipc = NxApp::Instance()->Find_Fd((char *) application->value());

    char msg[255];
    int len = sizeof(msg);
    strcpy(msg, "flnx_col^REQUEST^show_win_y^");

    NxApp::Instance()->Write_Fd(ipc, msg, len);


}

void
IPCTester::RequestShowWinWCB(Fl_Widget * fl, void *o)
{

    if (application->value() == NULL)
	return;

    ipc = NxApp::Instance()->Find_Fd((char *) application->value());

    char msg[255];
    int len = sizeof(msg);
    strcpy(msg, "flnx_col^REQUEST^show_win_w^");

    NxApp::Instance()->Write_Fd(ipc, msg, len);


}

void
IPCTester::RequestShowWinHCB(Fl_Widget * fl, void *o)
{

    if (application->value() == NULL)
	return;

    ipc = NxApp::Instance()->Find_Fd((char *) application->value());

    char msg[255];
    int len = sizeof(msg);
    strcpy(msg, "flnx_col^REQUEST^show_win_h^");

    NxApp::Instance()->Write_Fd(ipc, msg, len);


}

void
IPCTester::RequestKbdRunCB(Fl_Widget * fl, void *o)
{

    if (application->value() == NULL)
	return;

    ipc = NxApp::Instance()->Find_Fd((char *) application->value());

    char msg[255];
    int len = sizeof(msg);
    strcpy(msg, "flnx_col^REQUEST^keyboard_running^");

    NxApp::Instance()->Write_Fd(ipc, msg, len);


}

void
IPCTester::TerminateCB(Fl_Widget * fl, void *o)
{

    if (application->value() == NULL)
	return;

    ipc = NxApp::Instance()->Find_Fd((char *) application->value());

    char msg[255];
    int len = sizeof(msg);
    strcpy(msg, "flnx_col^TERMINATE^0^");

    NxApp::Instance()->Write_Fd(ipc, msg, len);

}

--- NEW FILE: nxcalendar.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <FL/Fl.H>
#include "nxcalendar.h"

NxCalendar::NxCalendar(NxApp * p, int x, int y, int w, int h, char *s):
Fl_Group(x, y, w, h, s)
{
    p_App = p;
}

void
NxCalendar::update()
{
    m_pDatePickerCalendar->update();
    update_function(this);;
}

time_t NxCalendar::GetPickedDate()
{
    return m_nDatePicked;
}

void
NxCalendar::doneDate_callback(Fl_Widget * o, void *l)
{
    NxCalendar *pThis = (NxCalendar *) l;

    tm d;
    memset(&d, 0, sizeof(d));
    d.tm_year = pThis->m_pDatePickerCalendar->year() - 1900;
    d.tm_mon = pThis->m_pDatePickerCalendar->month() - 1;
    d.tm_mday = pThis->m_pDatePickerCalendar->day();

    pThis->m_nDatePicked = mktime(&d);

    (*pThis->m_pDatePickerCallback) (o, (void *) (pThis->GetApp()));
}

void
NxCalendar::todayDate_callback(Fl_Widget * o, void *l)
{
    NxCalendar *pThis = (NxCalendar *) l;

    pThis->m_nDatePicked = time(0);

    (pThis->GetDatePickerCB())(o, (void *) (pThis->GetApp()));
}

void
NxCalendar::SetPickedDate(time_t t)
{
    tm *tt = localtime(&t);

    m_pDatePickerCalendar->set_date(tt->tm_year + 1900, tt->tm_mon + 1,
				    tt->tm_mday);
    m_pDatePickerCalendar->update();
}

void
NxCalendar::cancelDate_callback(Fl_Widget * o, void *l)
{
    NxCalendar *pThis = (NxCalendar *) l;
    pThis->m_nDatePicked = 0;
    (*pThis->m_pDatePickerCallback) (o, (void *) (pThis->GetApp()));
}


void
NxCalendar::MakeDateWindow()
{

    //  dateWindow = new NxPimPopWindow("Choose Date",NxApp::Instance()->getGlobalColor(APP_FG),5,5,W_W-10,255);
    dateWindow = new NxPimWindow(W_X, W_Y, W_W, W_H);
    {
	Fl_Calendar *o =
	    new Fl_Calendar(3, 5, dateWindow->GetWindowPtr()->w() - 6, 200);
	m_pDatePickerCalendar = o;
	dateWindow->add(o);
    }

    {
	NxButton *o = new NxButton(POP_BUTTON_X, POP_BUTTON_Y(dateWindow),
				   BUTTON_WIDTH, BUTTON_HEIGHT, "Done");
	o->callback(doneDate_callback, this);
	dateWindow->add((Fl_Widget *) o);
    }
    {
	NxButton *o = new NxButton(POP_BUTTON_X + BUTTON_WIDTH + 5,
				   POP_BUTTON_Y(dateWindow),
				   BUTTON_WIDTH, BUTTON_HEIGHT, "Cancel");
	o->callback(cancelDate_callback, this);
	dateWindow->add((Fl_Widget *) o);
    }
    {
	NxButton *o =
	    new NxButton(dateWindow->GetWindowPtr()->w() - BUTTON_WIDTH - 5,
			 POP_BUTTON_Y(dateWindow),
			 BUTTON_WIDTH, BUTTON_HEIGHT, "Today");
	o->callback(todayDate_callback, this);
	dateWindow->add((Fl_Widget *) o);
    }

    dateWindow->GetWindowPtr()->end();
}

void
NxCalendar::DateCallback(void (*cb) (Fl_Widget *, void *))
{
    m_pDatePickerCallback = cb;
}

--- NEW FILE: Makefile ---
# libs/pim/Makefile

LIB_STATIC=libpixil-pim.a
LIB_SHARED=libpixil-pim.so

CSRC=${shell ls *.c} 
CXXSRC=${shell ls *.cxx}

OBJS=${CSRC:.c=.o}
OBJS+=${CXXSRC:.cxx=.o}

CFLAGS ?= 
CFLAGS += -DPIXIL
include $(BASE_DIR)/Rules.make




--- NEW FILE: nxapp.new ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
[...2901 lines suppressed...]
    return db;
}

static db_handle *par_db = openPar();

int
getGblParInt(char *cat, char *pref)
{
    int s;
    par_getGlobalPref(par_db, cat, pref, PAR_INT, &s, sizeof(int));
    return s;
}

void
getGblParStr(char *cat, char *pref, char *text, int len)
{
    par_getGlobalPref(par_db, cat, pref, PAR_TEXT, text, len);
}

#endif

--- NEW FILE: nxbutton.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include <nxapp.h>
#include <FL/Enumerations.H>
#include <nxbutton.h>
#include <stdio.h>

NxButton::NxButton(int x, int y, int w, int h, char *l):
Fl_Button(x, y, w, h, l)
{

    move = true;
    save_y = y;

    // Provide the specific "look-and-feel"
    active = 1;
    color(NxApp::Instance()->getGlobalColor(BUTTON_FACE));
    selection_color(NxApp::Instance()->getGlobalColor(BUTTON_PUSH));
    labelcolor(NxApp::Instance()->getGlobalColor(BUTTON_TEXT));
    NxApp::Instance()->def_font((Fl_Widget *) this);
    align(FL_ALIGN_INSIDE | FL_ALIGN_CENTER | FL_ALIGN_WRAP);
    value(0);
}				// end of NxMenuButton::NxMenuButton()

void
NxButton::activate(void)
{
    if (!active) {
	active = 1;
	this->redraw();
    }				// end of if 
    return;
}				// end of NxButton::activate(void)

void
NxButton::deactivate(void)
{
    if (active) {
	active = 0;
	set_flag(INACTIVE);
	this->redraw();
	clear_flag(INACTIVE);
    }				// end of if
    return;
}				// end of NxButton::activate(void)

void
NxButton::drawButtonCode(int x, int y, int w, int h, Fl_Color c)
{
    // draw main box

    fl_color(c);

    fl_begin_polygon();
    fl_transformed_vertex(x, y + 3);
    fl_transformed_vertex(x + 1, y + 2);
    fl_transformed_vertex(x + 2, y + 1);

    fl_transformed_vertex(x + w - 3, y);
    fl_transformed_vertex(x + w, y + 3);
    fl_transformed_vertex(x + w, y + h - 4);
    fl_transformed_vertex(x + w - 3, y + h);
    fl_transformed_vertex(x + 3, y + h);
    fl_transformed_vertex(x, y + h - 3);
    fl_end_polygon();

}

void
NxButton::draw(void)
{
    if (!active)
	set_flag(INACTIVE);

    // Fl_Button::draw();
    if (type() == FL_HIDDEN_BUTTON)
	return;

    if ((box() == FL_BORDER_BOX) || (box() == FL_FLAT_BOX)) {
	Fl_Button::draw();
	return;
    }

    Fl_Color col = value()? selection_color() : color();

    if (value()) {

	Fl_Color old_label_clr = labelcolor();
	labelcolor(contrast(color(), labelcolor()));

	//draw_box(down(box()),selection_color());

	drawButtonCode(x(), y(), w(), h(),
		       NxApp::Instance()->getGlobalColor(APP_BG));
	drawButtonCode(x() + 2, y() + 2, w(), h(), selection_color());

	draw_label(x() + 2, y() + 2, w(), h());
	labelcolor(old_label_clr);

    } else {

	//draw_box(box(), col);

	drawButtonCode(x() + 2, y() + 2, w(), h(), selection_color());
	drawButtonCode(x(), y(), w(), h(), col);

	draw_label();
    }

    if (!active)
	clear_flag(INACTIVE);

    return;
}				// end of if 

int
NxButton::handle(int event)
{
    return ((active) ? Fl_Button::handle(event) : 0);
}				// end of NxButton::handle(int)

--- NEW FILE: nxmultilineinput.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include <nxapp.h>
#include <FL/Enumerations.H>
#include <nxmultilineinput.h>

NxMultilineInput::NxMultilineInput(int x, int y, int w, int h, const char *l):
Fl_Multiline_Input(x, y, w, h, l)
{

    // Provide the specific "look-and-feel"
    color(NxApp::Instance()->getGlobalColor(APP_BG));
    selection_color(NxApp::Instance()->getGlobalColor(APP_SEL));
    textcolor(NxApp::Instance()->getGlobalColor(APP_FG));
    NxApp::Instance()->def_font(this);
    box(FL_BORDER_BOX);
    align(FL_ALIGN_INSIDE | FL_ALIGN_LEFT);
}				// end of NxMultilineInput::NxMultilineInput()

--- NEW FILE: nxmenu_.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */

#include <FL/Fl.H>
#include <nxmenu_.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

int
NxMenu_::value(const NxMenuItem * m)
{
    clear_changed();
    if (value_ != m) {
	value_ = m;
	return 1;
    }
    return 0;
}

// When user picks a menu item, call this.  It will do the callback.
// Unfortunatly this also casts away const for the checkboxes, but this
// was necessary so non-checkbox menus can really be declared const...
const NxMenuItem *
NxMenu_::picked(const NxMenuItem * v)
{
    if (v) {
	if (v->radio()) {
	    if (!v->value()) {	// they are turning on a radio item
		set_changed();
		((NxMenuItem *) v)->setonly();
	    }
	    redraw();
	} else if (v->flags & FL_MENU_TOGGLE) {
	    set_changed();
	    ((NxMenuItem *) v)->flags ^= FL_MENU_VALUE;
	    redraw();
	} else if (v != value_) {	// normal item
	    set_changed();
	}
	value_ = v;
	if (when() & (FL_WHEN_CHANGED | FL_WHEN_RELEASE)) {
	    if (changed() || when() & FL_WHEN_NOT_CHANGED) {
		clear_changed();
		if (value_ && value_->callback_)
		    value_->do_callback((Fl_Widget *) this);
		else
		    do_callback();
	    }
	}
    }
    return v;
}

// turn on one of a set of radio buttons
void
NxMenuItem::setonly()
{
    flags |= FL_MENU_RADIO | FL_MENU_VALUE;
    NxMenuItem *j;
    for (j = this;;) {		// go down
	if (j->flags & FL_MENU_DIVIDER)
	    break;		// stop on divider lines
	j++;
	if (!j->text || !j->radio())
	    break;		// stop after group
	j->clear();
    }
    for (j = this - 1;; j--) {	// go up
	if (!j->text || (j->flags & FL_MENU_DIVIDER) || !j->radio())
	    break;
	j->clear();
    }
}

NxMenu_::NxMenu_(int X, int Y, int W, int H, const char *l)
    :
Fl_Widget(X, Y, W, H, l)
{
    set_flag(SHORTCUT_LABEL);
    box(FL_UP_BOX);
    when(FL_WHEN_RELEASE_ALWAYS);
    value_ = menu_ = 0;
    alloc = 0;
    selection_color(FL_SELECTION_COLOR);
    textfont(FL_HELVETICA);
    textsize(FL_NORMAL_SIZE);
    textcolor(FL_BLACK);
    down_box(FL_NO_BOX);
}

int
NxMenu_::size() const
{
    if (!menu_)
	return 0;
    return menu_->size();
}

void
NxMenu_::menu(const NxMenuItem * m)
{
    clear();
    value_ = menu_ = (NxMenuItem *) m;
}

void
NxMenu_::menu(const Fl_Menu_Item * m)
{
    clear();
    value_ = menu_ = (NxMenuItem *) m;
}

#if 1
// this version is ok with new NxMenu_add code with fl_menu_array_owner:

void
NxMenu_::copy(const NxMenuItem * m, void *user_data)
{
    int n = m->size();
    NxMenuItem *newMenu = new NxMenuItem[n];
    memcpy(newMenu, m, n * sizeof(NxMenuItem));
    menu(newMenu);
    alloc = 1;			// make destructor free array, but not strings
    // for convienence, provide way to change all the user data pointers:
    if (user_data)
	for (; n--;) {
	    if (newMenu->callback_)
		newMenu->user_data_ = user_data;
	    newMenu++;
	}
}

#else
// This is Guillaume Nodet's fixed version for the older NxMenu_add
// that enlarged the array at powers of 2:

void
NxMenu_::copy(const NxMenuItem * m, void *user_data)
{
    int i, s = m->size(), n = s;
    for (i = 0; n; n >>= 1, i++);
    n = 1 << i;
    NxMenuItem *newMenu = new NxMenuItem[n];
    memcpy(newMenu, m, s * sizeof(NxMenuItem));
    memset(newMenu + s, 0, (n - s) * sizeof(NxMenuItem));
    menu(newMenu);
    alloc = 1;			// make destructor free it
    // for convienence, provide way to change all the user data pointers:
    if (user_data)
	for (; s--;) {
	    if (newMenu->callback_)
		newMenu->user_data_ = user_data;
	    newMenu++;
	}
}
#endif

NxMenu_::~NxMenu_()
{
    clear();
}

// Fl_Menu::add() uses this to indicate the owner of the dynamically-
// expanding array.  We must not free this array:
NxMenu_ *nx_menu_array_owner = 0;

void
NxMenu_::clear()
{
    if (alloc) {
	if (alloc > 1)
	    for (int i = size(); i--;)
		if (menu_[i].text)
		    free((void *) menu_[i].text);
	if (this == nx_menu_array_owner)
	    nx_menu_array_owner = 0;
	else
	    delete[]menu_;
	menu_ = 0;
	value_ = 0;
	alloc = 0;
    }
}

--- NEW FILE: nxscrollbar.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include <nxapp.h>
#include <FL/fl_draw.H>
#include <nxscrollbar.h>
#include <iostream>

NxScrollbar::NxScrollbar(int x, int y, int w, int h, const char *l):
NxSlider(x, y, w, h, l)
{
    box(FL_FLAT_BOX);
    slider(FL_UP_BOX);
    linesize_ = 16;
    pushed_ = 0;
    step(1);
}

#define INITIALREPEAT .5
#define REPEAT .05

void
NxScrollbar::increment_cb()
{
    int i;
    int W = horizontal()? w() : h();
    int S = int (slider_size() * W + .5);

    switch (pushed_) {
    case 1:
	i = -linesize_;
	break;
    default:
	i = linesize_;
	break;
    case 3:
	i = -int (S * (maximum() - minimum()) / W);
	break;
    case 4:
	i = int (S * (maximum() - minimum()) / W);
	break;
    }
    if (maximum() < minimum() && pushed_ < 3)
	i = -i;
    handle_drag(clamp(value() + i));
}

void
NxScrollbar::timeout_cb(void *v)
{
    NxScrollbar *s = (NxScrollbar *) v;
    s->increment_cb();
    //Fl::add_timeout(REPEAT, timeout_cb, s);
}

int
NxScrollbar::handle(int event)
{
    // area of scrollbar:
    int area;
    int X = x();
    int Y = y();
    int W = w();
    int H = h();
    int SX = X;
    int SY = Y;
    int SW = W;
    int SH = H;

    // adjust slider area to be inside the arrow buttons:
    if (horizontal()) {
	if (W >= 3 * H) {
	    X += H;
	    W -= 2 * H;
	}
    } else {
	if (H >= 3 * W) {
	    Y += W;
	    H -= 2 * W;
	}
    }

    // which widget part is highlighted?
    int mx = Fl::event_x();
    int my = Fl::event_y();
    if (!Fl::event_inside(SX, SY, SW, SH))
	area = 0;
    else if (horizontal()) {
	if (mx < X)
	    area = 1;
	else if (mx >= X + W)
	    area = 2;
	else {
	    int sliderx;
	    int S = int (slider_size() * W + .5);
	    double val = (value() - minimum()) / (maximum() - minimum());
	    if (val >= 1.0)
		sliderx = W - S;
	    else if (val <= 0.0)
		sliderx = 0;
	    else
		sliderx = int (val * (W - S) + .5);

	    if (mx < X + sliderx)
		area = 3;
	    else if (mx >= X + sliderx + S)
		area = 4;
	    else
		area = 5;
	}
    } else {
	if (mx < X || mx >= X + W)
	    area = 0;
	else if (my < Y)
	    area = 1;
	else if (my >= Y + H)
	    area = 2;
	else {
	    int slidery;
	    int S = int (slider_size() * H + .5);
	    double val = (value() - minimum()) / (maximum() - minimum());
	    if (val >= 1.0)
		slidery = H - S;
	    else if (val <= 0.0)
		slidery = 0;
	    else
		slidery = int (val * (H - S) + .5);

	    if (my < Y + slidery)
		area = 3;
	    else if (my >= Y + slidery + S)
		area = 4;
	    else
		area = 5;
	}
    }
    switch (event) {
    case FL_ENTER:
    case FL_LEAVE:
	return 1;
    case FL_RELEASE:
	damage(FL_DAMAGE_EXPOSE);
	if (pushed_) {
	    //Fl::remove_timeout(timeout_cb, this);
	    pushed_ = 0;
	}
	handle_release();
	return 1;
    case FL_PUSH:
	if (pushed_)
	    return 1;
	if (area != 5)
	    pushed_ = area;
	if (pushed_) {
	    handle_push();
	    //Fl::add_timeout(INITIALREPEAT, timeout_cb, this);
	    increment_cb();
	    damage(FL_DAMAGE_EXPOSE);
	    return 1;
	}
	return NxSlider::handle(event, X, Y, W, H);
    case FL_DRAG:
	if (pushed_)
	    return 1;
	return NxSlider::handle(event, X, Y, W, H);
    case FL_SHORTCUT:{
	    int v = value();
	    int ls = maximum() >= minimum()? linesize_ : -linesize_;
	    if (horizontal()) {
		switch (Fl::event_key()) {
		case FL_Left:
		    v -= ls;
		    break;
		case FL_Right:
		    v += ls;
		    break;
		default:
		    return 0;
		}
	    } else {		// vertical
		switch (Fl::event_key()) {
		case FL_Up:
		    v -= ls;
		    break;
		case FL_Down:
		    v += ls;
		    break;
		case FL_Page_Up:
		    if (slider_size() >= 1.0)
			return 0;
		    v -= int ((maximum() - minimum()) * slider_size() / (1.0 -
									 slider_size
									 ()));
		    v += ls;
		    break;
		case FL_Page_Down:
		    if (slider_size() >= 1.0)
			return 0;
		    v += int ((maximum() - minimum()) * slider_size() / (1.0 -
									 slider_size
									 ()));
		    v -= ls;
		    break;
		case FL_Home:
		    v = int (minimum());
		    break;
		case FL_End:
		    v = int (maximum());
		    break;
		default:
		    return 0;
		}
	    }
	    v = int (clamp(v));
	    if (v != value()) {
		NxSlider::value(v);
		value_damage();
		do_callback();
	    }
	    return 1;
	}
    }
    return 0;
}

#include <stdio.h>

void
NxScrollbar::draw()
{

    box(FL_BORDER_BOX);
    Fl_Color col = NxApp::Instance()->getGlobalColor(SCROLL_TRAY);
    Fl_Color sel_col = selection_color();

    int X = x() + Fl::box_dx(box());
    int Y = y() + Fl::box_dy(box());
    int W = w() - Fl::box_dw(box());
    int H = h() - Fl::box_dh(box());

    if (damage() & FL_DAMAGE_ALL) {
	Fl_Color clr = fl_color();

	fl_color(NxApp::Instance()->getGlobalColor(SCROLL_TRAY));
	fl_rectf(X, Y, W, H);
	fl_color(NxApp::Instance()->getGlobalColor(SCROLL_FACE));
	fl_rect(X, Y, W, H);

	fl_color(clr);
    }


    if (horizontal()) {

	// the slider button
	if (W < 3 * H) {
	    NxSlider::draw(X - 1, Y, W + 2, H);
	    return;
	}
	NxSlider::draw(X + H - 1, Y, W - 2 * H + 2, H);
	// draw the boxes for the buttons
	if (damage()) {
	    //      draw_box((pushed_ == 1) ? FL_BLACK_BOX : FL_BORDER_BOX,
	    //               X, Y, H, H, col);
	    //      draw_box((pushed_ == 2) ? FL_BLACK_BOX : FL_BORDER_BOX,
	    //               X+W-H, Y, H, H, col);

	    Fl_Color clr = fl_color();

	    // Top Box
	    fl_color((pushed_ == 1) ? col : sel_col);
	    fl_rectf(X, Y, H, H);	// box
	    fl_rect(X + W - H, Y, H, H);	// border

	    // Bottom Box
	    fl_color((pushed_ == 2) ? col : sel_col);
	    fl_rectf(X + W - H, Y, H, H);	// box
	    fl_rect(X, Y, H, H);	// border

	    fl_color(clr);

	    if (active_r())
		fl_color(labelcolor());
	    else
		fl_color(inactive(labelcolor()));
	    int w1 = (H - 1) | 1;	// use odd sizes only
	    int Y1 = Y + w1 / 2;
	    int W1 = w1 / 3;
	    int X1 = X + w1 / 2 + W1 / 2;
	    //or arrows on buttons
	    if (pushed_ == 1)
		fl_color(FL_WHITE);
	    else
		fl_color(FL_BLACK);
	    fl_polygon(X1 - W1, Y1, X1, Y1 - W1, X1, Y1 + W1);
	    X1 = X + W - (X1 - X) - 1;
	    if (pushed_ == 2)
		fl_color(FL_WHITE);
	    else
		fl_color(FL_BLACK);
	    fl_polygon(X1 + W1, Y1, X1, Y1 + W1, X1, Y1 - W1);
	}
    } else {			// vertical
	if (H < 3 * W) {
	    NxSlider::draw(X, Y - 1, W, H + 2);
	    return;
	}
	NxSlider::draw(X, Y + W - 1, W, H - 2 * W + 2);
	if (damage()) {

	    /*
	       draw_box((pushed_ == 1) ? FL_BLACK_BOX : FL_BORDER_BOX,
	       X, Y, W, W, col);
	       draw_box((pushed_ == 2) ? FL_BLACK_BOX : FL_BORDER_BOX,
	       X, Y+H-W, W, W, col);
	     */

	    Fl_Color clr = fl_color();

	    // Top Box
	    fl_color((pushed_ == 1) ? sel_col : col);
	    fl_rectf(X, Y, W, W);	// box
	    fl_color(sel_col);
	    fl_rect(X, Y, W, W);	// border

	    // Bottom Box
	    fl_color((pushed_ == 2) ? sel_col : col);
	    fl_rectf(X, Y + H - W, W, W);	// box
	    fl_color(sel_col);
	    fl_rect(X, Y + H - W, W, W);	// border      

	    fl_color(clr);

	    /*
	       if (active_r())
	       fl_color(labelcolor());
	       else
	       fl_color(labelcolor() | 8);
	       ******* */

	    int w1 = (W - 1) | 1;	// use odd sizes only
	    int X1 = X + w1 / 2 + 1;

	    int W1 = w1 / 3 + 1;
	    int Y1 = Y + w1 / 2 + W1 / 2;

	    // draw the arrow on the buttons

	    if (pushed_ == 1)
		fl_color(col);
	    else
		fl_color(sel_col);


	    fl_polygon(X1, Y1 - W1, X1 + W1, Y1 + 1, X1 - W1, Y1);
	    Y1 = Y + H - (Y1 - Y) - 1;


	    if (pushed_ == 2)
		fl_color(col);
	    else
		fl_color(sel_col);

	    fl_polygon(X1, Y1 + W1, X1 - W1, Y1, X1 + W1, Y1);
	}
    }
}

--- NEW FILE: nxmenu.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
[...1119 lines suppressed...]
    const NxMenuItem *m = this;
    const NxMenuItem *ret = 0;
    if (m)
	for (; m->text; m = m->next()) {
	    if (m->activevisible()) {
		// return immediately any match of an item in top level menu:
		if (Fl::test_shortcut(m->shortcut_))
		    return m;
		// if (Fl_Widget::test_shortcut(m->text)) return m;
		// only return matches from lower menu if nothing found in top menu:
		if (!ret && m->submenu()) {
		    const NxMenuItem *s =
			(m->flags & FL_SUBMENU) ? m +
			1 : (const NxMenuItem *) m->user_data_;
		    ret = s->test_shortcut();
		}
	    }
	}
    return ret;
}

--- NEW FILE: index.c ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "file.h"
/*
 * index.c - B* tree index file access routines
 *
 * from 11/18/85 mt15b by greg haerr
 */

#define RECNOSIZE	sizeof(short)	/* sizeof record number */
/* leaf & ptr block struct*/
#define PAGETYPE(p)	(p->buf[ 0])	/* Leaf or Ptr, != 0 is ptr */
#define NKEYS(p)	(get16(&p->buf[ 1]))	/* # keys this page */
#define setNKEYS(p,v)	(put16(&p->buf[ 1],v))	/* # keys this page */

/* ptr block struct*/
#define BLK0(p)		(get16(&p->buf[ 3]))	/* blk 0 ptr */
#define setBLK0(p,v)	(put16(&p->buf[ 3],v))	/* blk 0 ptr */
#define PKEY1(p)	(&p->buf[ 5])	/* address of first key, pblk */
#define BLKNO(p)	(get16(&p[ gkeylen]))	/* address of next block at p */
#define setBLKNO(p,v)	(put16(&p[ gkeylen],v))	/* address of next block at p */

/* leaf block struct*/
#define FPTR(p)		(get16(&p->buf[ 3]))	/* forward block ptr */
#define setFPTR(p,v)	(put16(&p->buf[ 3],v))	/* forward block ptr */
#define BPTR(p)		(get16(&p->buf[ 5]))	/* backward block ptr */
#define setBPTR(p,v)	(put16(&p->buf[ 5],v))	/* backward block ptr */
#define LKEY1(p)	(&p->buf[ 7])	/* address of first key, lblk */
#define RECNO(p)	(get16(&p[ gkeylen]))	/* address of recno at p */
#define setRECNO(p,v)	(put16(&p[ gkeylen],v))	/* address of recno at p */
#define KEY1OFF		7	/* offset of key #1 in buf */
#define moveleft(s,d,c)	memcpy(d,s,c)

#define F_INT		02	/* char/integer index */
#define F_MULT		04	/* unique/multiple keys */

struct passup
{				/* key pass-up structure */
    char key[11];		/* key, max len = 10 */
    short pblkno;		/* block # */
};

/* local data*/
static int gkeylen;		/* global key length */
static char *gkey;		/* global key ptr */
static char gkeytyp;		/* key type, 0=char, 1=integer */
static struct ndxfile *gfp;	/* global index file */
static int gmode;		/* global mode, 0 = search only */
static int grec;		/* global rec# */

/* local procs*/
static int isrch(int blkno, struct passup *v);
static int dsrch(int blk, struct passup *v);
static void keycopy(char *src, char *dst);
static int keycomp(char *key);
static void moveright(char *asrc, char *adst, int cnt);
static int ierr(int n);

/*
 * search for key in index file fp, if mode != 0, insert as record #mode if
 * not found
 */
int
search(char *key, struct ndxfile *fp, int mode)
{
    register struct buffer *bp;
    register struct buffer *nbp;
    register char *p;
    register int n;
    struct passup v;
    short kbuf;

    gfp = fp;
    gmode = mode;
    gkeylen = gfp->keylen;
    if ((gkeytyp = (gfp->ftype & F_INT)) != 0) {
	gkey = (char *) &kbuf;
	put16((char *) &kbuf, (int) key);
    } else
	gkey = key;
    n = isrch(0, &v);
    if (gmode == 0)		/* search only */
	return (n);
    if (n) {			/* allocate new root node */
	//fprintf(stderr, "search: root passup key=%9s, blkno=%d\n", v.key, v.pblkno);
	if ((nbp = lockb(newblk((struct fildes *) gfp))) == NULL)
	    return (ierr(0));	/* isrch: new root bp fail */
	if ((bp = getblk(0, (struct fildes *) gfp)) == NULL) {
	    unlock(nbp);
	    return (ierr(1));	/* search: bp getblk fail */
	}
	memcpy(nbp->buf, bp->buf, BLKSIZ);	/* copy block 0 */
	PAGETYPE(bp) = 'P';
	setNKEYS(bp, 1);
	setBLK0(bp, nbp->blkno);
	p = PKEY1(bp);
	keycopy(v.key, p);
	setBLKNO(p, v.pblkno);
	bp->changed = 1;
	if (n == FPTR(nbp)) {
	    bp = getblk(n, (struct fildes *) gfp);
	    setBPTR(bp, nbp->blkno);
	    bp->changed = 1;
	}
	if (n == BPTR(nbp)) {
	    bp = getblk(n, (struct fildes *) gfp);
	    setFPTR(bp, nbp->blkno);
	    bp->changed = 1;
	}
	unlock(nbp);
    }
    return (gmode);
}

/*
 * recursive B* tree search (two level only for now)
 */
static int
isrch(int blkno, struct passup *v)
{
    register struct buffer *bp, *nbp;
    char *p, *ap;
    int n, r;
    struct passup u;

  again:
    if ((bp = getblk(blkno, (struct fildes *) gfp)) == NULL)
	return (ierr(2));	/* isrch: bp getblk fail */
    n = NKEYS(bp);
#ifdef UNIV
    if ((gfp == &FAndx2 || gfp == &FAndx3) && n == RECMAX - 5 && gmode) {
	printf("\007***Warning: 5 activities left, space to continue");
	chrin();
    }
    if ((gfp == &FAndx2 || gfp == &FAndx3) && n > RECMAX)
	return (fatal(8));
#endif
    if (PAGETYPE(bp) == 0) {	/* leaf node */
	p = LKEY1(bp);
	while (n > 0 && keycomp(p) < 0) {
	    p += gkeylen + 2;
	    n--;
	}
	if (gmode == 0) {	/* search only */
	    if ((gfp->ftype & F_MULT) && n <= 0)	/* mult keys */
		if ((blkno = FPTR(bp)) != 0) {
		    /*dprintf( "isrch: mult next blk"); */
		    goto again;
		}
	    if (n <= 0 || keycomp(p) != 0)
		return (0);
	    else {
		gfp->curblk = bp->blkno;
		gfp->curoff = NKEYS(bp) - n + 1;
		return (RECNO(p));
	    }
	}
	if (gfp->maxkeys > NKEYS(bp)) {	/* insert, no split needed */
	    while (n > 0 && keycomp(p) == 0) {
		p += gkeylen + 2;
		n--;
	    }
	    if (n != 0)
		moveright(p, p + gkeylen + 2, n * (gkeylen + 2));
	    keycopy(gkey, p);
	    setRECNO(p, gmode);	/* gmode = recno */
	    setNKEYS(bp, NKEYS(bp) + 1);
	    bp->changed = 1;
	    return (0);		/* no passup */
	} else {		/* insert, split leaf */
	    /*dprintf( "isrch: lnode split\n"); */
	    lockb(bp);
	    if ((nbp = lockb(newblk((struct fildes *) gfp))) == NULL) {
		unlock(bp);
		return (ierr(3));	/* isrch: nbp getblk fail */
	    }
	    r = (gfp->maxkeys + 1) / 2;
	    /* copy right page to new block */
	    memcpy(LKEY1(nbp),
		   LKEY1(bp) + (gkeylen + 2) * (gfp->maxkeys / 2),
		   (gkeylen + 2) * (gfp->maxkeys - (gfp->maxkeys / 2)));
	    setNKEYS(nbp, r);
	    setNKEYS(bp, r);
	    bp->changed = 1;
	    if (n >= r) {	/* insert left page */
		n -= r;
		setNKEYS(bp, NKEYS(bp) + 1);
	    } else {		/* insert right page */
		p = LKEY1(nbp) + (p - LKEY1(bp)) -
		    (gkeylen + 2) * (gfp->maxkeys / 2);
		setNKEYS(nbp, NKEYS(nbp) + 1);
	    }
	    if (n != 0)
		moveright(p, p + gkeylen + 2, n * (gkeylen + 2));
	    keycopy(gkey, p);
	    setRECNO(p, gmode);
	    setFPTR(nbp, n = FPTR(bp));
	    setFPTR(bp, nbp->blkno);
	    setBPTR(nbp, bp->blkno);
	    unlock(bp);
	    if (n != 0) {
		if ((bp = getblk(n, (struct fildes *) gfp)) == NULL) {
		    unlock(nbp);
		    return (ierr(4));	/* isrch: bptr getblk fail */
		}
		setBPTR(bp, nbp->blkno);
		bp->changed = 1;
	    }
	    keycopy(LKEY1(nbp), v->key);
	    v->pblkno = nbp->blkno;
	    unlock(nbp);
	    return (1);		/* passup */
	}
    } else {			/* ptr node */
	ap = p = PKEY1(bp);
	if (gfp->ftype & F_MULT)	/* multiple keys */
	    for (r = 0; r < n; r++) {
		if (keycomp(ap) >= 0)
		    break;
		p = ap;
		ap += gkeylen + 2;
	} else			/* unique keys */
	    for (r = 0; r < n; r++) {
		if (keycomp(ap) > 0)
		    break;
		p = ap;
		ap += gkeylen + 2;
	    }
	if (r == 0)
	    n = BLK0(bp);
	else
	    n = BLKNO(p);
	/*dprintf( "psrch %d\n", n); */
	lockb(bp);
	n = isrch(n, &u);
	unlock(bp);
	if (gmode == 0)
	    return (n);
	if (n) {		/* passup */
	    /*dprintf( "isrch: passup key=%9s, blkno=%d\n", u.key, u.pblkno); */
	    n = NKEYS(bp);
	    if (n >= gfp->maxkeys)
		return (ierr(5));	/* isrch: pnode overflow */
	    if (r < n)
		moveright(ap, ap + gkeylen + 2, (n - r) * (gkeylen + 2));
	    keycopy(u.key, ap);
	    setBLKNO(ap, u.pblkno);
	    setNKEYS(bp, NKEYS(bp) + 1);
	    bp->changed = 1;
	}
	return (0);
    }
}

/*
 * delete key with record # rec from index file fp
 */
int
Delete(char *key, int rec, struct ndxfile *fp)
{
    struct passup v;
    short kbuf;

    grec = rec;
    gfp = fp;
    gkeylen = gfp->keylen;
    if ((gkeytyp = (gfp->ftype & F_INT)) != 0) {
	gkey = (char *) &kbuf;
	put16((char *) &kbuf, (int) key);
    } else
	gkey = key;
    gfp->curblk = -1;
    dsrch(0, &v);
    return (grec);
}

/*
 * recursive B* tree delete
 */
static int
dsrch(int blk, struct passup *v)
{
    register struct buffer *bp, *nbp;
    char *p, *ap;
    int n, r;
    struct passup u;

  again:
    if ((bp = getblk(blk, (struct fildes *) gfp)) == NULL)
	return (0);
    n = NKEYS(bp);
    if (PAGETYPE(bp) == 0) {	/* root node is leaf node */
	p = LKEY1(bp);
	while (n > 0 && RECNO(p) != grec) {
	    if (keycomp(p) > 0)
		break;
	    p += gkeylen + 2;
	    n--;
	}
	if ((gfp->ftype & F_MULT) && n <= 0)	/* mult keys */
	    if ((blk = FPTR(bp)) != 0) {
		/*dprintf( "dsrch: mult nxt blk"); */
		goto again;
	    }
	if (n <= 0 || keycomp(p) != 0 || RECNO(p) != grec) {
	    grec = 0;
	    return (ierr(6));	/* dsrch: key not found */
	}
	if (n > 1)
	    moveleft(p + gkeylen + 2, p, (n - 1) * (gkeylen + 2));
	setNKEYS(bp, NKEYS(bp) - 1);
	bp->changed = 1;
	if ((NKEYS(bp) > gfp->maxkeys / 2) || (blk == 0))
	    return (0);		/* aok */
	lockb(bp);
	if ((r = FPTR(bp)) != 0) {	/* fwd blk not empty */
	    if ((nbp = getblk(r, (struct fildes *) gfp)) == NULL) {
		unlock(bp);
		return (ierr(7));	/* dsrch: nbp getblk fail */
	    }
	    p = LKEY1(bp) + (NKEYS(bp) * (gkeylen + 2));
	    ap = LKEY1(nbp);
	    if (NKEYS(nbp) > gfp->maxkeys / 2) {	/* annect 1 */
		/*dprintf( "dsrch: annect 1\n"); */
		memcpy(p, ap, gkeylen + 2);	/* copy key */
		setNKEYS(bp, NKEYS(bp) + 1);
		moveleft(ap + gkeylen + 2, ap,
			 (NKEYS(nbp) - 1) * (gkeylen + 2));
		setNKEYS(nbp, NKEYS(nbp) - 1);
		nbp->changed = 1;
		keycopy(ap, v->key);
		v->pblkno = nbp->blkno;
		unlock(bp);
		return (1);	/* change key in ptr blk */
	    }
	    /*dprintf( "dsrch: annect all\n"); */
	    v->pblkno = nbp->blkno;	/* save blk # to delete */
	    memcpy(p, ap, NKEYS(nbp) * (gkeylen + 2));	/* annect all */
	    setNKEYS(bp, NKEYS(bp) + NKEYS(nbp));
	    setFPTR(bp, r = FPTR(nbp));	/* relink fwd ptr */
	    unlock(bp);
	    if (r != 0) {
		n = bp->blkno;
		if ((bp = getblk(r, (struct fildes *) gfp)) == NULL) {
		    ierr(21);	/* dsrch: nbp fptr fail */
		    return (2);
		}
		setBPTR(bp, n);
		bp->changed = 1;
	    }
	    return (2);		/* delete blk # in ptr blk */
	}
	if (NKEYS(bp) == 0) {	/* fptr null, no keys */
	    /*dprintf( "dsrch: fptr null, no keys\n"); */
	    v->pblkno = bp->blkno;
	    r = BPTR(bp);	/* set bwd ptr to NULL */
	    unlock(bp);
	    if (r != 0) {
		if ((bp = getblk(r, (struct fildes *) gfp)) == NULL) {
		    ierr(22);	/* dsrch: nbp bptr fail */
		    return (2);
		}
		setFPTR(bp, 0);
		bp->changed = 1;
	    }
	    return (2);
	}
	unlock(bp);
	return (0);		/* aok */
    } else {			/* ptr node */
	ap = p = PKEY1(bp);
	if (gfp->ftype & F_MULT)	/* mult keys */
	    for (r = 0; r < n; r++) {
		if (keycomp(ap) >= 0)
		    break;
		p = ap;
		ap += gkeylen + 2;
	} else			/* unique keys */
	    for (r = 0; r < n; r++) {
		if (keycomp(ap) > 0)
		    break;
		p = ap;
		ap += gkeylen + 2;
	    }
	if (r == 0)
	    n = BLK0(bp);
	else
	    n = BLKNO(p);
	lockb(bp);
	/*dprintf( "dsrch %d\n", n); */
	n = dsrch(n, &u);
	switch (n) {
	case 2:		/* delete passup blk # from ptr blk */
	    /*dprintf( "dsrch: delete blk #%d\n", u.pblkno); */
	    if (NKEYS(bp) == 1) {	/* ptr back to leaf node */
		if (u.pblkno == BLK0(bp)) {
		    p = PKEY1(bp);
		    blk = BLKNO(p);
		} else
		    blk = BLK0(bp);
		if ((nbp = getblk(blk, (struct fildes *) gfp)) == NULL) {
		    unlock(bp);
		    return (ierr(8));	/* dsrch: nbp leaf fail */
		}
		memcpy(bp->buf, nbp->buf, BLKSIZ);
		setFPTR(bp, 0);
		setBPTR(bp, 0);
		bp->changed = 1;
		unlock(bp);
		return (0);	// was ;
	    }
	    p = PKEY1(bp);
	    n = NKEYS(bp);
	    if (u.pblkno == BLK0(bp)) {
		setBLK0(bp, BLKNO(p));
		r = 0;
	    } else {
		for (r = 0; r < n; r++) {
		    if (u.pblkno == BLKNO(p))
			break;
		    p += gkeylen + 2;
		}
		if (r >= n) {
		    unlock(bp);
		    return (ierr(9));	/* dsrch: blk find fail */
		}
	    }
	    if (n - r - 1 > 0)
		moveleft(p + gkeylen + 2, p, (n - r - 1) * (gkeylen + 2));
	    setNKEYS(bp, NKEYS(bp) - 1);
	    bp->changed = 1;
	    unlock(bp);
	    return (0);		// was ;
	case 1:		/* change passup blk #'s key */
	    n = NKEYS(bp);
	    p = PKEY1(bp);
	    /*dprintf( "dsrch: change blk #%d key to %9s\n", u.pblkno, u.key); */
	    for (r = 0; r < n; r++) {
		if (u.pblkno == BLKNO(p)) {
		    keycopy(u.key, p);
		    bp->changed = 1;
		    unlock(bp);
		    return (0);	// was ;
		}
		p += gkeylen + 2;
	    }
	    unlock(bp);
	    return (ierr(10));
	}
	unlock(bp);
    }

    return 0;
}

int
next(struct fildes *fp)
{
    register struct ndxfile *nfp;
    register struct buffer *bp;
    register int blk;
    register int n;
    char rbuf[MAXRECSIZ];

    //fprintf(stderr, "next(fp)\n");

    fp->eof = 0;

    if (!fp->ndxfp) {

	//fprintf(stderr, "\t!fp->ndxfp()\n");  
	do {
	    if (++fp->currec > fp->nrecs) {
		fp->currec = fp->nrecs;
		fp->eof = 1;
		return (0);
	    }
	    getrec(fp->currec, fp, rbuf);
	} while (rbuf[0] == '*');
	//fprintf(stderr, "\treturn fp->currec\n");
	return (fp->currec);
    }

    nfp = fp->ndxfp;
    gfp = nfp;

    if ((blk = nfp->curblk) == -1) {
	//fp->eof = 1;
	return (ierr(12));	/* next: no currency */
    }

  nxtblk:
    if ((bp = getblk(blk, (struct fildes *) nfp)) == NULL)
	return (ierr(11));	/* next: bp getblk fail */
#ifdef UNIV
    n = NKEYS(bp);
    if ((gfp == &FAndx2 || gfp == &FAndx3) && n > RECMAX)
	return (fatal(8));
#endif
    if (++(nfp->curoff) > NKEYS(bp)) {
	if ((blk = FPTR(bp)) != 0) {
	    nfp->curblk = blk;
	    nfp->curoff = 0;
	    goto nxtblk;
	}
	nfp->curoff = NKEYS(bp);
	fp->eof = 1;
	return (0);
    }
    n = (nfp->keylen + 2) * (nfp->curoff - 1) + nfp->keylen + KEY1OFF;
    fp->currec = get16(&bp->buf[n]);
    if (fp->currec > fp->nrecs || fp->currec <= 0)
	return (ierr(13));	/* next: invalid currec */
    return (fp->currec);
}

int
prev(struct fildes *fp)
{
    register struct ndxfile *nfp;
    register struct buffer *bp;
    register int blk;
    register int n;
    char rbuf[MAXRECSIZ];

    fp->eof = 0;
    if (!fp->ndxfp) {
	do {
	    if (--fp->currec <= 0) {
		fp->currec = 1;
		fp->eof = 1;
		return (0);
	    }
	    getrec(fp->currec, fp, rbuf);
	} while (rbuf[0] == '*');
	return (fp->currec);
    }
    nfp = fp->ndxfp;
    gfp = nfp;
    if ((blk = nfp->curblk) == -1)
	return (ierr(14));	/* prev: no currency */
    if ((bp = getblk(blk, (struct fildes *) nfp)) == NULL)
	return (ierr(15));	/* prev: bp getblk fail */
    if (--(nfp->curoff) <= 0) {
	if ((blk = BPTR(bp)) != 0) {
	    if ((bp = getblk(blk, (struct fildes *) nfp)) == NULL)
		return (ierr(16));	/* prev: bptr getblk fail */
	    nfp->curblk = blk;
	    nfp->curoff = NKEYS(bp);
	    goto ok;
	}
	nfp->curoff = 1;
	fp->eof = 1;
	return (0);
    }
  ok:
    n = (nfp->keylen + 2) * (nfp->curoff - 1) + nfp->keylen + KEY1OFF;
    fp->currec = get16(&bp->buf[n]);
    return (fp->currec);
}

int
gotop(struct fildes *fp)
{

    register struct ndxfile *nfp;
    register struct buffer *bp;

    fp->eof = 0;
    if (!fp->ndxfp) {
	fp->currec = 0;
	return (next(fp));
    }
    nfp = fp->ndxfp;
    gfp = nfp;
    if ((bp = getblk(0, (struct fildes *) nfp)) == NULL)
	return (ierr(17));	/* gotop: bp getblk fail */
    if (PAGETYPE(bp) != 0)
	if ((bp = getblk(BLK0(bp), (struct fildes *) nfp)) == NULL)
	    return (ierr(18));	/* gotop: blk0 getblk fail */
    nfp->curblk = bp->blkno;
    if (NKEYS(bp) == 0) {
	nfp->curoff = 0;
	fp->eof = 1;
	return (0);
    }
    nfp->curoff = 1;
    return (fp->currec = get16(&bp->buf[nfp->keylen + KEY1OFF]));
}

int
gobot(struct fildes *fp)
{
    register struct ndxfile *nfp;
    register struct buffer *bp;
    register char *p;
    register int n;

    fp->eof = 0;
    if (!fp->ndxfp) {
	fp->currec = fp->nrecs + 1;
	return (prev(fp));
    }
    nfp = fp->ndxfp;
    gfp = nfp;
    if ((bp = getblk(0, (struct fildes *) nfp)) == NULL)
	return (ierr(19));	/* gobot: bp getblk fail */
    gkeylen = nfp->keylen;
    if (PAGETYPE(bp) != 0) {
	p = PKEY1(bp) + ((NKEYS(bp) - 1) * (gkeylen + 2));
	if ((bp = getblk(BLKNO(p), (struct fildes *) nfp)) == NULL)
	    return (ierr(20));	/* gobot: blkno getblk fail */
    }
    nfp->curblk = bp->blkno;
    if (NKEYS(bp) == 0) {
	nfp->curoff = 0;
	fp->eof = 1;
	return (0);
    }
    nfp->curoff = NKEYS(bp);
    n = (nfp->keylen + 2) * (nfp->curoff - 1) + nfp->keylen + KEY1OFF;
    return (fp->currec = get16(&bp->buf[n]));
}

int
gotorec(struct fildes *fp, int rec)
{
    fp->eof = 0;
    if (fp->nrecs == 0 || rec == 0) {
	fp->currec = 0;
	fp->eof = 1;
    } else {
	fp->currec = rec - 1;
	next(fp);
    }
    return (fp->currec);
}

static void
keycopy(char *src, char *dst)
{
    register int n;

    if (gkeytyp)
	put16(dst, (int) get16(src));
    else {
	n = gkeylen;
	while (n--)
	    *dst++ = *src++;
    }
}

static int
keycomp(char *key)
{
    register int n;
    register char *p;

    if (gkeytyp)
	return (get16(key) - get16(gkey));
    n = gkeylen;
    p = gkey;
    while (--n >= 0 && *p++ == *key++)
	continue;
    return (n < 0 ? 0 : *--key - *--p);
}

static void
moveright(char *asrc, char *adst, int cnt)
{
    register char *src, *dst;

    src = asrc + cnt;
    dst = adst + cnt;
    while (cnt--)
	*--dst = *--src;
}

static int
ierr(int n)
{
    printf("\007*** Index Error #%d, file=%s, ", n, gfp->filext);
    if (gkeytyp)
	printf("key=%d", get16(gkey));
    else
	printf("key=%9s", gkey);
    printf("\n");
    return (0);
}

--- NEW FILE: nxscroll.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include <nxapp.h>
#include <FL/Enumerations.H>
#include <nxscroll.h>

#define SLIDER_WIDTH 12

NxScroll::NxScroll(int x, int y, int w, int h, const char *l):
Fl_Group(x, y, w, h, l),
scrollbar(x + w - SLIDER_WIDTH, y, SLIDER_WIDTH, h - SLIDER_WIDTH),
hscrollbar(x, y + h - SLIDER_WIDTH, w - SLIDER_WIDTH, SLIDER_WIDTH)
{
    save_h = h;
    move = true;
    resize_ = true;
    type(BOTH);
    xposition_ = 0;
    yposition_ = 0;

    hscrollbar.type(FL_HORIZONTAL);
    hscrollbar.callback(hscrollbar_cb);
    scrollbar.callback(scrollbar_cb);

    scrollbar.align(FL_ALIGN_RIGHT);
    hscrollbar.align(FL_ALIGN_BOTTOM);

    // Provide the "look-and-feel"
    box(FL_BORDER_BOX);
    type(NxScroll::VERTICAL);
    scrollbar.size(12, scrollbar.h());

    color(NxApp::Instance()->getGlobalColor(APP_BG));
    selection_color(NxApp::Instance()->getGlobalColor(APP_SEL));

}				// end of NxScroll::NxScroll()


// Insure the scrollbars are the last children:
void
NxScroll::fix_scrollbar_order()
{
    Fl_Widget *const *a = array();
    if (a[children() - 1] != &scrollbar) {
	Fl_Widget **a = (Fl_Widget **) array();
	int i, j;
	for (i = j = 0; j < children(); j++)
	    if (a[j] != &hscrollbar && a[j] != &scrollbar)
		a[i++] = a[j];
	a[i++] = &hscrollbar;
	a[i++] = &scrollbar;
    }
}

void
NxScroll::draw_clip(void *v, int X, int Y, int W, int H)
{
    fl_clip(X, Y, W, H);
    NxScroll *s = (NxScroll *) v;
    // erase background if there is a boxtype:
    if (s->box() && !(s->damage() & FL_DAMAGE_ALL)) {
	fl_color(s->color());
	fl_rectf(X, Y, W, H);
    }
    Fl_Widget *const *a = s->array();
    int R = X;
    int B = Y;			// track bottom & right edge of all children
    for (int i = s->children() - 2; i--;) {
	Fl_Widget & o = **a++;
	s->draw_child(o);
	s->draw_outside_label(o);
	if (o.x() + o.w() > R)
	    R = o.x() + o.w();
	if (o.y() + o.h() > B)
	    B = o.y() + o.h();
    }
    // fill any area to right & bottom of widgets:
    if (R < X + W && B > Y) {
	fl_color(s->color());
	fl_rectf(R, Y, X + W - R, B - Y);
    }
    if (B < Y + H) {
	fl_color(s->color());
	fl_rectf(X, B, W, Y + H - B);
    }
    fl_pop_clip();
}

void
NxScroll::bbox(int &X, int &Y, int &W, int &H)
{
    X = x() + Fl::box_dx(box());
    Y = y() + Fl::box_dy(box());
    W = w() - Fl::box_dw(box());
    H = h() - Fl::box_dh(box());
    if (scrollbar.visible()) {
	W -= scrollbar.w();
	if (scrollbar.align() & FL_ALIGN_LEFT)
	    X += scrollbar.w();
    }
    if (hscrollbar.visible()) {
	H -= hscrollbar.h();
	if (scrollbar.align() & FL_ALIGN_TOP)
	    Y += hscrollbar.h();
    }
}

void
NxScroll::draw()
{
    fix_scrollbar_order();
    int X, Y, W, H;
    bbox(X, Y, W, H);

    uchar d = damage();

    X = X + 1;
    W = W - 2;
    H = H - 1;

    if (d & FL_DAMAGE_ALL) {	// full redraw

	draw_box(box(), x(), y() - 1, w(), h() + 1, color());
	draw_clip(this, X, Y, W, H);
    } else {
	if (d & FL_DAMAGE_SCROLL) {	// scroll the contents:
	    fl_scroll(X, Y, W, H, oldx - xposition_, oldy - yposition_,
		      draw_clip, this);
	}
	if (d & FL_DAMAGE_CHILD) {	// draw damaged children
	    fl_clip(X, Y, W, H);
	    Fl_Widget *const *a = array();
	    for (int i = children() - 2; i--;)
		update_child(**a++);
	    fl_pop_clip();
	}
    }

    // accumulate bounding box of children:
    int l = X;
    int r = X;
    int t = Y;
    int b = Y;
    Fl_Widget *const *a = array();
    for (int i = children() - 2; i--;) {
	Fl_Object *o = *a++;
	if (o->x() < l)
	    l = o->x();
	if (o->y() < t)
	    t = o->y();
	if (o->x() + o->w() > r)
	    r = o->x() + o->w();
	if (o->y() + o->h() > b)
	    b = o->y() + o->h();
    }

    // turn the scrollbars on and off as necessary:
    for (int z = 0; z < 2; z++) {
	if ((type() & VERTICAL) && (type() & ALWAYS_ON || t < Y || b > Y + H)) {
	    if (!scrollbar.visible()) {
		scrollbar.set_visible();
		W -= scrollbar.w();
		d = FL_DAMAGE_ALL;
	    }
	} else {
	    if (scrollbar.visible()) {
		scrollbar.clear_visible();
		draw_clip(this,
			  scrollbar.align() & FL_ALIGN_LEFT ? X -
			  scrollbar.w() : X + W, Y, scrollbar.w(), H);
		W += scrollbar.w();
		d = FL_DAMAGE_ALL;
	    }
	}
	if ((type() & HORIZONTAL)
	    && (type() & ALWAYS_ON || l < X || r > X + W)) {
	    if (!hscrollbar.visible()) {
		hscrollbar.set_visible();
		H -= hscrollbar.h();
		d = FL_DAMAGE_ALL;
	    }
	} else {
	    if (hscrollbar.visible()) {
		hscrollbar.clear_visible();
		draw_clip(this, X,
			  scrollbar.align() & FL_ALIGN_TOP ? Y -
			  hscrollbar.h() : Y + H, W, hscrollbar.h());
		H += hscrollbar.h();
		d = FL_DAMAGE_ALL;
	    }
	}
    }


#if 1

#if 1
    int __Y = Y - 1;
    int __H = H + 2;
    int __X = X;
    int __W = W;

    scrollbar.resize(scrollbar.align() & FL_ALIGN_LEFT ? __X -
		     scrollbar.w() : __X + __W, __Y, scrollbar.w(), __H);

    hscrollbar.resize(__X,
		      scrollbar.align() & FL_ALIGN_TOP ? __Y -
		      hscrollbar.h() : __Y + __H, __W, hscrollbar.h());

#else
    scrollbar.resize(scrollbar.align() & FL_ALIGN_LEFT ? X -
		     scrollbar.w() : X + W, Y, scrollbar.w(), H);

    hscrollbar.resize(X,
		      scrollbar.align() & FL_ALIGN_TOP ? Y -
		      hscrollbar.h() : Y + H, W, hscrollbar.h());
#endif
#else
    scrollbar.resize(scrollbar.align() & FL_ALIGN_LEFT ? X -
		     scrollbar.w() : X + W, Y, scrollbar.w(), H);

    hscrollbar.resize(X,
		      scrollbar.align() & FL_ALIGN_TOP ? Y -
		      hscrollbar.h() : Y + H, W, hscrollbar.h());
#endif
    scrollbar.value(oldy = yposition_ = (Y - t), H, 0, b - t);

    hscrollbar.value(oldx = xposition_ = (X - l), W, 0, r - l);

    // draw the scrollbars:
    if (d & FL_DAMAGE_ALL) {
	draw_child(scrollbar);
	draw_child(hscrollbar);
	if (scrollbar.visible() && hscrollbar.visible()) {
	    // fill in the little box in the corner
	    fl_color(color());
	    fl_rectf(scrollbar.x(), hscrollbar.y(), scrollbar.w(),
		     hscrollbar.h());
	}
    } else {
	update_child(scrollbar);
	update_child(hscrollbar);
    }

    if (scrollbar.visible()) {
	Fl_Color old_color = color();
	fl_color(FL_BLACK);
	fl_line(scrollbar.x(), scrollbar.y(), scrollbar.x() + scrollbar.w(),
		scrollbar.y());
	fl_line(scrollbar.x(), scrollbar.y() + scrollbar.h() - 1,
		scrollbar.x() + scrollbar.w(),
		scrollbar.y() + scrollbar.h() - 1);
	fl_color(old_color);
    }

    if (hscrollbar.visible()) {
	Fl_Color old_color = color();
	fl_color(FL_BLACK);
	fl_line(hscrollbar.x(), hscrollbar.y(), hscrollbar.x(),
		hscrollbar.y() + hscrollbar.h() - 1);
	fl_line(hscrollbar.x() + hscrollbar.w(), hscrollbar.y(),
		hscrollbar.x() + hscrollbar.w(),
		hscrollbar.y() + hscrollbar.h() - 1);
	fl_color(old_color);
    }

}

#include <stdio.h>
void
NxScroll::resize(int X, int Y, int W, int H)
{

    if (!resize_)
	return;

    fix_scrollbar_order();

    int new_h;
    if (H == save_h)
	new_h = save_h;
    else
	new_h = H - (this->y() - Y) - 5;

    if (move) {

	// move all the children:
	Fl_Widget *const *a = array();
	for (int i = children() - 2; i--;) {
	    Fl_Object *o = *a++;
	    o->position(o->x() + X - x(), o->y() + Y - y());
	}

	Fl_Widget::resize(X, Y, W, new_h);

    } else {

	// move all the children:
	Fl_Widget *const *a = array();
	for (int i = children() - 2; i--;) {
	    Fl_Object *o = *a++;
	    //o->position(o->x()+X-x(), o->y()+Y-y());
	    o->position(o->x() + X - x(), o->y());
	}

	Fl_Widget::resize(this->x(), this->y(), W, new_h);

    }

}

void
NxScroll::position(int X, int Y)
{
    int dx = xposition_ - X;
    int dy = yposition_ - Y;

    if (!dx && !dy)
	return;
    xposition_ = X;
    yposition_ = Y;
    Fl_Widget *const *a = array();
    for (int i = children(); i--;) {
	Fl_Widget *o = *a++;
	if (o == &hscrollbar || o == &scrollbar)
	    continue;
	o->position(o->x() + dx, o->y() + dy);
    }
    damage(FL_DAMAGE_SCROLL);
}

void
NxScroll::hscrollbar_cb(Fl_Widget * o, void *)
{
    NxScroll *s = (NxScroll *) (o->parent());
    s->position(int (((NxScrollbar *) o)->value()), s->yposition());
}

void
NxScroll::scrollbar_cb(Fl_Widget * o, void *)
{
    NxScroll *s = (NxScroll *) (o->parent());
    s->position(s->xposition(), int (((NxScrollbar *) o)->value()));
}

int
NxScroll::handle(int event)
{
    fix_scrollbar_order();
    return Fl_Group::handle(event);
}

--- NEW FILE: editengine.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
[...1752 lines suppressed...]
	temprow,
	tempcol;

    if (first.Row == last.Row) {
	if (last.Column < first.Column)	// if on same row, just swap columns
	{
	    tempcol = first.Column;
	    first.Column = last.Column;
	    last.Column = tempcol;
	}
    } else if (last.Row < first.Row)	// else must swap both
    {
	temprow = first.Row;
	tempcol = first.Column;
	first.Row = last.Row;
	first.Column = last.Column;
	last.Row = temprow;
	last.Column = tempcol;
    }
}

--- NEW FILE: nxmloutput.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


// DEBUG
#include <stdio.h>
// end of DEBUG

#include <nxapp.h>
#include <FL/Enumerations.H>
#include <nxmloutput.h>

NxMlOutput::NxMlOutput(int x, int y, int w, int h):
Fl_Multiline_Output(x, y, w, h)
{

    // Provide the specific "look-and-feel"
    active = 1;
    color(NxApp::Instance()->getGlobalColor(APP_BG));
    selection_color(NxApp::Instance()->getGlobalColor(APP_SEL));
    box(FL_FLAT_BOX);
    align(FL_ALIGN_INSIDE | FL_ALIGN_LEFT);
}				// end of NxOutput::NxOutput()

void
NxMlOutput::deactivate(void)
{
    if (active) {
	printf("In NxMlOutput::deactivate(), setting active=0\n");
	active = 0;
	set_flag(INACTIVE);
	this->redraw();
	clear_flag(INACTIVE);
    }				// end of if
    return;
}				// end of NxMlOutput::deactivate()

void
NxMlOutput::activate(void)
{
    if (!active) {
	printf("In NxMlOutput::activate(), setting active=1\n");
	active = 1;
	clear_flag(INACTIVE);
	this->redraw();
    }				// end of if
    return;
}				// end of NxMlOutput::activate()

void
NxMlOutput::draw(void)
{
    if (!active)
	set_flag(INACTIVE);

    Fl_Multiline_Output::draw();

    if (!active)
	clear_flag(INACTIVE);

    return;
}				// end of NxMlOutput(void)

int
NxMlOutput::handle(int event)
{
    return ((active) ? Fl_Multiline_Output::handle(event) : 0);
}				// end of NxMlOutput::handle(int)

--- NEW FILE: nxbrowser.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include <nxapp.h>
#include <FL/Enumerations.H>
#include <nxbrowser.h>

NxBrowser::NxBrowser(int x, int y, int w, int h, const char *l):
Fl_Browser(x, y, w, h, l)
{

    save_h = h;
    move = true;
    // Provide the specific "look-and-feel"
    color(NxApp::Instance()->getGlobalColor(APP_BG));
    selection_color(NxApp::Instance()->getGlobalColor(APP_SEL));
    textcolor(NxApp::Instance()->getGlobalColor(APP_FG));
    NxApp::Instance()->def_font(this);
}				// end of NxBrowser::NxHoldBrowser()

--- NEW FILE: db.c ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include <stdio.h>
#ifndef WIN32
#include <unistd.h>
#else /*  */
#include <io.h>
#include <stdlib.h>
#endif
#include <fcntl.h>
#include "file.h"
/*
 * db.c - database & index file open/close/create routines
 *
 * from 9/9/85 mt15b
 */

#ifndef WIN32
#define O_BINARY	0
#endif
static char *str2cat(char *f1, char *ext);

struct buffer *getblk();

extern struct buffer *startbuf, *endbuf;
extern char apflag;

/*
 * create a database or index file
 */
int
dbcreat(struct fildes *fp, char *name)
{
    int fd, ret;

    if ((fd = creat(str2cat(name, fp->filext), 0666)) < 0)
	return (0);
    close(fd);
    apflag = 1;
    ret = dbopen(fp, name);
    apflag = 0;
    return (ret);

}

/*
 * open a database or index file
 */
int
dbopen(struct fildes *fp, char *name)
{
    int fd, off, x;
    struct buffer *bp;

    if ((fd = open(str2cat(name, fp->filext), O_RDWR | O_BINARY)) < 0)
	return (0);
    fp->fildesc = fd;
    fp->fchanged = 0;
    bp = getblk(0, fp);
    if (fp->ftype) {		/* index file */
	((struct ndxfile *) fp)->maxkeys =
	    ((BLKSIZ - 7) / (2 + ((struct ndxfile *) fp)->keylen));
	((struct ndxfile *) fp)->curblk = -1;
	return (1);
    }
    fp->nrecs = get16(&bp->buf[0]);
    fp->currec = 1;

    off = 1;			/* byte 0 is deleted flag */
    for (fd = 0; fp->fieldp[fd].type; fd++) {
	//if( fd >= MAXFIELDS)
	//fatal( x);
	fp->fieldp[fd].offset = off;
	x = fp->fieldp[fd].size;
	switch (fp->fieldp[fd].type) {
	case 'c':
	case 'n':		/* pt only */
	    off += x;
	    break;
	case 'd':
	case 'i':
	    off += x * sizeof(short);
	    break;
	case 'l':
	    off += x * sizeof(long);
	    break;
	}
    }

    x = 1;
    fp->fieldp[fd].offset = off;
    off += x * sizeof(long);

    fp->nfields++;

    fp->nfields = fd;

    fp->recsiz = off;
    if (off > MAXRECSIZ)
	fatal(4);		/* max rec size overflow */
    return (1);
}

/*
 * close and write database or index file
 */
void
dbclose(struct fildes *fp)
{
    struct buffer *bp;

    if (fp->fchanged) {
	bp = getblk(0, fp);
	if (!fp->ftype)
	    put16(&bp->buf[0], fp->nrecs);
	putblk(bp);
    }

    for (bp = startbuf; bp < endbuf; bp++)
	if (bp->fptr == fp) {
	    if (bp->changed)
		putblk(bp);
	    bp->usecnt = 0;
	    bp->fptr = NULL;
	}
    close(fp->fildesc);
}

/*
 * write the database or index file
 */
void
dbsave(struct fildes *fp)
{
    struct buffer *bp;

    if (fp->fchanged) {
	bp = getblk(0, fp);
	if (!fp->ftype)
	    put16(&bp->buf[0], fp->nrecs);
	putblk(bp);
    }

    for (bp = startbuf; bp < endbuf; bp++)
	if (bp->fptr == fp) {
	    if (bp->changed)
		putblk(bp);
	    bp->usecnt = 0;
	    bp->fptr = NULL;
	}
}

static char *
str2cat(char *f1, char *ext)
{
    char *p;

#ifndef WIN32
    static char buf[69];

#else /*  */
    static char buf[_MAX_PATH];

#endif
    p = buf;
    while (*f1)
	*p++ = *f1++;
    *p++ = '.';
    while ((*p++ = *ext++) != 0)
	continue;
    return (buf);
}

--- NEW FILE: nxselectbrowser.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include <nxapp.h>
#include <FL/Enumerations.H>
#include <nxselectbrowser.h>

NxSelectBrowser::NxSelectBrowser(int x, int y, int w, int h, char *l):
Fl_Select_Browser(x, y, w, h, l)
{

    // Provide the "look-and-feel"
    color(NxApp::Instance()->getGlobalColor(APP_BG));
    selection_color(NxApp::Instance()->getGlobalColor(APP_SEL));
    box(FL_SHADOW_BOX);
    align(FL_ALIGN_INSIDE | FL_ALIGN_LEFT);
    value(0);
}				// end of NxSelectBrowswer::NxSelectBrowser()

--- NEW FILE: nxbox.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include <nxapp.h>
#include <FL/Enumerations.H>
#include <nxbox.h>
#include <stdio.h>

NxBox::NxBox(int x, int y, int w, int h, char *l):
Fl_Box(x, y, w, h, l)
{

    move = true;
    resize_ = true;
    default_box_ = true;
    save_h = h;

    // Provide the specific "look-and-feel"
    box_color_ = (NxApp::Instance()->getGlobalColor(APP_FG));
    color(NxApp::Instance()->getGlobalColor(APP_FG));
    selection_color(NxApp::Instance()->getGlobalColor(APP_BG));
    labelcolor(NxApp::Instance()->getGlobalColor(APP_FG));
    NxApp::Instance()->def_font((Fl_Widget *) this);
}				// end of NxBox::NxBox


void
NxBox::draw()
{

    Fl_Color old_color = fl_color();

    draw_box();
    if (!default_box_) {
	fl_color(box_color_);
	fl_rect(x(), y(), w(), h());
	fl_color(old_color);
    }

    draw_label();
}

--- NEW FILE: nxweekcalendar.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <FL/Fl.H>
#include "nxweekcalendar.h"

#ifdef DEBUG
#define DPRINT(str, args...) printf("DEBUG: " str, ## args)
#else
#define DPRINT(args...)
#endif

NxWeekCalendar::NxWeekCalendar(NxApp * p, int x, int y, int w, int h,
			       char *s):
NxCalendar(p, x, y, w, h, s)
{
    p_App = p;
}

void
NxWeekCalendar::MakeDateWindow()
{

    //  dateWindow = new NxPimPopWindow("Choose Date",DEF_FG,5,5,W_W-10,255);
    dateWindow = new NxPimWindow(W_X, W_Y, W_W, W_H);
    {
	Fl_Calendar *o =
	    new Fl_Calendar(3, 5, dateWindow->GetWindowPtr()->w() - 6, 200,
			    "", true, WEEK);
	m_pDatePickerCalendar = o;
	dateWindow->add((Fl_Calendar *) o);
    }

    {
	NxButton *o = new NxButton(POP_BUTTON_X, POP_BUTTON_Y(dateWindow),
				   BUTTON_WIDTH, BUTTON_HEIGHT, "Done");
	o->callback(doneDate_callback, this);
	dateWindow->add((Fl_Widget *) o);
    }
    {
	NxButton *o = new NxButton(POP_BUTTON_X + BUTTON_WIDTH + 5,
				   POP_BUTTON_Y(dateWindow),
				   BUTTON_WIDTH, BUTTON_HEIGHT, "Cancel");
	o->callback(cancelDate_callback, this);
	dateWindow->add((Fl_Widget *) o);
    }
    {
	NxButton *o =
	    new NxButton(dateWindow->GetWindowPtr()->w() - BUTTON_WIDTH - 5,
			 POP_BUTTON_Y(dateWindow),
			 BUTTON_WIDTH, BUTTON_HEIGHT, "This Week");
	o->callback(todayDate_callback, this);
	dateWindow->add((Fl_Widget *) o);
    }

    dateWindow->GetWindowPtr()->end();
}

--- NEW FILE: nxeditcategory.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include <nxwindow.h>
#include <nxapp.h>
#include <icons/folder_small.xpm>
#include <stdio.h>
#include <string.h>

#define CAT_INDEX 0
#define CAT_FIELD 1

void (*update_tree_items_) (const char *);

void
NxEditCategory::list_cb(Fl_Widget * fl, void *o)
{
    NxEditCategory *edit_cat = (NxEditCategory *) o;

    if (edit_cat->get_category_tree()->selection_count() > 1)
	edit_cat->get_category_tree()->unselect();

    if (Fl::event_clicks())
	rename_cb(fl, o);
}

void
NxEditCategory::done_cb(Fl_Widget * fl, void *o)
{
    NxEditCategory *edit_cat = (NxEditCategory *) o;
    edit_cat->get_category_tree()->unselect();
    (*update_tree_items_) (edit_cat->get_menu_list()->label());
    NxApp::Instance()->show_window(edit_cat->get_show_window()->
				   GetWindowPtr());
}

void
NxEditCategory::new_cb(Fl_Widget * fl, void *o)
{
    NxEditCategory *edit_cat = (NxEditCategory *) o;
    edit_cat->get_new_cat_input()->value("");
    NxApp::Instance()->show_window(edit_cat->get_new_cat_window()->
				   GetWindowPtr(), DEACTIVATE,
				   edit_cat->GetWindowPtr());
}

void
NxEditCategory::rename_cb(Fl_Widget * fl, void *o)
{
    NxEditCategory *edit_cat = (NxEditCategory *) o;
    Fl_Toggle_Node *node = edit_cat->get_category_tree()->selected();


    if (node) {
	edit_cat->get_new_cat_input()->value("");
	NxApp::Instance()->show_window(edit_cat->get_rename_cat_window()->
				       GetWindowPtr(), DEACTIVATE,
				       edit_cat->GetWindowPtr());
    }
}

void
NxEditCategory::done_new_cat_cb(Fl_Widget * fl, void *o)
{
    char value[255];
    bool match = false;
    int n_count = 0;
    int len = 0;

    NxEditCategory *edit_cat = (NxEditCategory *) o;

    if (0 == strcasecmp("Edit", edit_cat->get_new_cat_input()->value()))
	return;

    Fl_Toggle_Node *n = edit_cat->get_category_tree()->traverse_start();
    while (n) {
	n = edit_cat->get_category_tree()->traverse_forward();
	n_count++;
    }
    if (0 == strcmp("", edit_cat->get_new_cat_input()->value()))
	return;
	/****
		check input for / or \ and change it to -
		Why? Fltk uses a / as a sub-menu and skips \\
	*****/
    len = strlen(edit_cat->get_new_cat_input()->value());
    char *new_value = (char *) (edit_cat->get_new_cat_input()->value());

    for (int jdx = 0; jdx <= len; jdx++) {
	int c = edit_cat->get_new_cat_input()->value()[jdx];
	if (c == '/' || c == '\\') {
	    new_value[jdx] = '-';
	}
    }
    edit_cat->get_new_cat_input()->value(new_value);

    while (!match) {		// find new key
	for (int idx = 1;
	     idx <=
	     edit_cat->get_cat_db()->NumRecs(edit_cat->get_catdb_name());
	     idx++) {
	    edit_cat->get_cat_db()->Extract(edit_cat->get_catdb_name(), idx,
					    1, value);
	    if (0 == strcmp(value, edit_cat->get_new_cat_input()->value())) {
		match = true;
		edit_cat->get_new_cat_input()->value("");
		return;
	    }
	}
	break;
    }

    // match is false
    edit_cat->get_category_tree()->add_next((char *) edit_cat->
					    get_new_cat_input()->value(), 0,
					    edit_cat->get_folder_pix());
    edit_cat->get_category_tree()->traverse_up();
    NxApp::Instance()->show_window(edit_cat->GetWindowPtr(), ACTIVATE);
    n = edit_cat->get_category_tree()->traverse_start();
    while (n) {
	if (0 == strcmp(edit_cat->get_new_cat_input()->value(), n->label()))
	    edit_cat->get_category_tree()->select_range(n, n, 0);
	n = edit_cat->get_category_tree()->traverse_forward();
    }
    edit_cat->new_cat_update((char *) edit_cat->get_new_cat_input()->value());
}

void
NxEditCategory::cancel_new_cat_cb(Fl_Widget * fl, void *o)
{
    NxEditCategory *edit_cat = (NxEditCategory *) o;
    NxApp::Instance()->show_window(edit_cat->GetWindowPtr(), ACTIVATE);
}

void
NxEditCategory::done_rename_cat_cb(Fl_Widget * fl, void *o)
{
    char old_name[MAX_NAME_SIZE];
    char new_name[MAX_NAME_SIZE];
    bool match = false;
    NxEditCategory *edit_cat = (NxEditCategory *) o;
    Fl_Toggle_Node *node = edit_cat->get_category_tree()->selected();
    int len = 0;

    if (0 == strcmp("", edit_cat->get_rename_cat_input()->value())) {
	return;
    }

    if (0 == strcasecmp("Edit", edit_cat->get_rename_cat_input()->value()))
	return;

	/***
		check input for / or \ and change it to -
		Why? Fltk uses a / as a sub-menu and skips \
	****/
    len = strlen(edit_cat->get_rename_cat_input()->value());
    char *new_value = (char *) (edit_cat->get_rename_cat_input()->value());

    for (int idx = 0; idx <= len; idx++) {
	int c = edit_cat->get_rename_cat_input()->value()[idx];
	if (c == '/' || c == '\\')
	    new_value[idx] = '-';
    }

    if (node) {
	memset(old_name, 0, sizeof(old_name));
	strcpy(old_name, node->label());
	Fl_Toggle_Node *n = edit_cat->get_category_tree()->traverse_start();
	while (n) {
	    if (0 == strcmp(n->label(), new_value)) {
		match = true;
		edit_cat->get_rename_cat_input()->value("");
		return;
	    }
	    n = edit_cat->get_category_tree()->traverse_forward();
	}
	if (false == match)
	    node->label(new_value);
	edit_cat->get_category_tree()->hide();
	edit_cat->get_category_tree()->show();
	memset(new_name, 0, sizeof(new_name));
	strcpy(new_name, new_value);
	edit_cat->rename_cat_update(old_name, new_name);
    }
    node = edit_cat->get_category_tree()->traverse_start();
    while (node) {
	if (0 == strcmp(new_name, node->label()))
	    edit_cat->get_category_tree()->select_range(node, node, 0);
	node = edit_cat->get_category_tree()->traverse_forward();
    }
    NxApp::Instance()->show_window(edit_cat->GetWindowPtr(), ACTIVATE);
}

void
NxEditCategory::cancel_rename_cat_cb(Fl_Widget * fl, void *o)
{
    NxEditCategory *edit_cat = (NxEditCategory *) o;
    NxApp::Instance()->show_window(edit_cat->GetWindowPtr(), ACTIVATE);
}

void
NxEditCategory::delete_cb(Fl_Widget * fl, void *o)
{
    //Delete category
}

void
NxEditCategory::delete_cat_cb(Fl_Widget * fl, void *o)
{
    NxEditCategory *edit_cat = (NxEditCategory *) o;
    Fl_Toggle_Node *node = edit_cat->get_category_tree()->selected();

    if (node) {
	NxApp::Instance()->show_window(edit_cat->get_delete_cat_window()->
				       GetWindowPtr(), DEACTIVATE,
				       edit_cat->GetWindowPtr());
    }
}

void
NxEditCategory::delete_yes_cat_cb(Fl_Widget * fl, void *o)
{
    NxEditCategory *edit_cat = (NxEditCategory *) o;
    Fl_Toggle_Node *node = edit_cat->get_category_tree()->selected();
    int rec_array[255];
    int rec[1];
    int cat_array[1];
    int size;
    int idx = 0;
    char ret_buf[255];
    char field_buf[8];
    char rec_buf[MAXRECSIZ];
    int cat_index = 0;

    for (idx = 0; idx < 255; idx++) {
	rec_array[idx] = -1;
    }
    cat_array[0] = -1;

    size = edit_cat->get_menu_list()->size();
    //fprintf(stderr, "delete_yes_cb: size[%d]\n", size);
    for (int jdx = 0; jdx < size - 2; jdx++) {
	//fprintf(stderr, "delete_yes_cb: doing strcmp jdx[%d]\n", jdx);
	if (0 == strcmp(node->label(), edit_cat->get_menu_list()->text(jdx))) {
	    edit_cat->get_menu_list()->remove(jdx);
	}
    }
    // get cat record that is to be removed
    edit_cat->get_cat_db()->Select(edit_cat->get_catdb_name(), node->label(),
				   1, rec_array, 1);
    cat_index = rec_array[0];
    // get the index value
    edit_cat->get_cat_db()->Extract(edit_cat->get_catdb_name(), rec_array[0],
				    0, ret_buf);
    int remove_num = atoi(ret_buf);

    // get the index num for "Unfiled" from the cataegory database
    edit_cat->get_cat_db()->Select(edit_cat->get_catdb_name(), "Unfiled", 1,
				   cat_array, 1);
    edit_cat->get_cat_db()->Extract(edit_cat->get_catdb_name(), cat_array[0],
				    0, field_buf);
    int num = atoi(field_buf);

    for (idx = 0; idx < 255; idx++) {
	rec_array[idx] = -1;
    }

    // get records that have the cat index that is to be removed
    edit_cat->get_cat_db()->Select(edit_cat->get_notedb_name(), ret_buf,
				   CAT_FIELD, rec_array, 255);
    int rec_count = 0;
    for (idx = 0; idx < 255; idx++) {
	if (-1 != rec_array[idx])
	    rec_count++;
    }

    // go through the records editing the ones with cat index
    for (idx = 0; idx < rec_count; idx++) {
	rec[0] = -1;
	NxDb *db = edit_cat->get_cat_db();
	string notedb_name = edit_cat->get_notedb_name();

	db->Select(notedb_name, ret_buf, CAT_FIELD, rec, 1);

	// get the field that has the cat id
	//fprintf(stderr, "delete_yes_cb: recno[%d]\n", rec[0]);
	if (-1 != rec[0]) {
	    edit_cat->get_cat_db()->Extract(edit_cat->get_notedb_name(),
					    rec[0], CAT_FIELD, rec_buf);
	    int cat_field = atoi(rec_buf);
	    //fprintf(stderr, "delete_yes_cb: cat_field[%d]\n", cat_field);
	    //fprintf(stderr, "delete_yes_cb: num[%d]\n", num);
	    //fprintf(stderr, "delete_yes_cb: remove_num[%d]\n", remove_num);
	    // compare it to the field to remove
	    if (remove_num == cat_field) {
		// edit the record with cat id to to the new cat id
		edit_cat->get_cat_db()->Extract(edit_cat->get_notedb_name(),
						rec[0], rec_buf);
		put16(&rec_buf[edit_cat->get_note_field()[CAT_FIELD].offset],
		      num);
		edit_cat->get_cat_db()->Edit(edit_cat->get_notedb_name(),
					     rec[0], rec_buf);
	    }
	}
    }
    // delete the category from the database
    edit_cat->get_cat_db()->DeleteRec(edit_cat->get_catdb_name(), cat_index);
    edit_cat->get_category_tree()->remove(node);

    edit_cat->get_menu_list()->label("Unfiled");
    (*update_tree_items_) ("Unfiled");
    edit_cat->get_category_tree()->unselect();
    NxApp::Instance()->show_window(edit_cat->GetWindowPtr(), ACTIVATE);
}

void
NxEditCategory::delete_no_cat_cb(Fl_Widget * fl, void *o)
{
    NxEditCategory *edit_cat = (NxEditCategory *) o;
    NxApp::Instance()->show_window(edit_cat->GetWindowPtr(), ACTIVATE);
}

void
NxEditCategory::clear_tree()
{
    Fl_Toggle_Node *n = category_tree_->traverse_start();
    while (n) {
	delete(char *) n->user_data();
	category_tree_->remove(n);
	n = category_tree_->traverse_start();
    }
}

void
NxEditCategory::add_items(Fl_Toggle_Tree * t)
{
    char inbuf[255];
    int idx;
    int rec_count = cat_db_->NumRecs(catdb_name_);
    folderSmall_ = new Fl_Pixmap(folder_small);

    for (idx = 1; idx <= rec_count; idx++) {
	memset(inbuf, 0, sizeof(inbuf));
	if (cat_db_->Extract(catdb_name_, idx, 1, inbuf)) {
	    if (0 == strcmp("Unfiled", inbuf) || 0 == strcmp("All", inbuf))
		continue;
	    t->add_next(inbuf, 0, folderSmall_);
	    t->traverse_up();
	}
    }
}

void
NxEditCategory::new_cat_update(char *new_value)
{
    int size;
    //int index = cat_db_->NumRecs(catdb_name_) + 1;
    int index =
	(NxApp::Instance()->
	 GetKey(cat_db_, (char *) catdb_name_.c_str(), 0)) + 1;
    char rec[MAXRECSIZ];

    size = menu_list_->size();
    menu_list_->add(new_value);

    memset(rec, 0, sizeof(rec));
    put16(&rec[cat_field_[0].offset], index);
    strcpy(&rec[cat_field_[1].offset], new_value);
    cat_db_->Insert(catdb_name_, rec);
    new_cat_input_->value("");
}

void
NxEditCategory::rename_cat_update(char *old_name, char *new_name)
{
    int size;
    int rec_no[1];
    char rec[MAXRECSIZ];

    rec_no[0] = -1;

    size = menu_list_->size();
    for (int jdx = 0; jdx < size - 1; jdx++) {
	if (0 == strcmp(old_name, menu_list_->text(jdx))) {
	    menu_list_->replace(jdx, new_name);
	}
    }
    if (0 == strcmp(old_name, menu_list_->label())) {
	menu_list_->label(new_name);
    }

    rename_cat_input_->value("");
    cat_db_->Select(catdb_name_, old_name, 1, rec_no, 1);
    if (-1 != rec_no[0]) {
	cat_db_->Extract(catdb_name_, rec_no[0], rec);
	strcpy(&rec[cat_field_[CAT_FIELD].offset], new_name);
	cat_db_->Edit(catdb_name_, rec_no[0], rec);
	(*update_tree_items_) (new_name);
    }
}

NxEditCategory::NxEditCategory(NxDb * catDb, string catdb_name,
			       string notedb_name,
			       void (*update_items) (const char *category))
    :
NxPimWindow(W_X, W_Y, W_W, W_H)
{

    int ww[3] = { 150, 200, 0 };

    g_NxEditCatWin = this;
    catdb_name_ = catdb_name;
    notedb_name_ = notedb_name;
    cat_db_ = catDb;
    //fprintf(stderr, "cat_db_ [%p]\n", cat_db_);
    cat_field_ = cat_db_->GetField(catdb_name_);
    cat_des_ = cat_db_->GetFilDes(catdb_name_);
    note_field_ = cat_db_->GetField(notedb_name_);
    note_des_ = cat_db_->GetFilDes(notedb_name_);
    update_tree_items_ = update_items;

    pim_window = get_pim_window();
    {
	NxButton *o = new NxButton(MB_X, MB_Y, MB_W, MB_H, "Edit Category");
	o->movable(false);
	add(o);
    }
    {
	NxScroll *o = category_list_ =
	    new NxScroll(-1, 31, W_W + 2, BUTTON_Y - 38);
	o->align(FL_ALIGN_TOP_LEFT);
	o->movable(false);
	{
	    //category_list_->scrollbar.size(12, category_list_->scrollbar.h());
	    category_tree_ = new Fl_Toggle_Tree(0, 31, W_W, 10);
	    category_tree_->callback(list_cb, this);
	}
	o->end();
    }
    add(category_list_);

    done_button_ =
	new NxButton(1, BUTTON_Y, BUTTON_WIDTH - 4, BUTTON_HEIGHT, "Done");
    done_button_->callback(done_cb, this);
    add(done_button_);

    new_button_ =
	new NxButton(59, BUTTON_Y, BUTTON_WIDTH - 4, BUTTON_HEIGHT, "New");
    new_button_->callback(new_cb, this);
    add(new_button_);

    rename_button_ =
	new NxButton(118, BUTTON_Y, BUTTON_WIDTH - 4, BUTTON_HEIGHT,
		     "Rename");
    rename_button_->callback(rename_cb, this);
    add(rename_button_);

    delete_button_ =
	new NxButton(177, BUTTON_Y, BUTTON_WIDTH - 4, BUTTON_HEIGHT,
		     "Delete");
    delete_button_->callback(delete_cat_cb, this);
    add(delete_button_);

    category_tree_->column_widths(ww);
    add_items(category_tree_);

    new_cat_win_ =
	new NxPimPopWindow("New Category",
			   NxApp::Instance()->getGlobalColor(APP_FG));
    //fprintf(stderr, "NxEditCategory: new_cat_win_->GetWindowPtr[%p]\n",new_cat_win_->GetWindowPtr());
    NxApp::Instance()->add_window((Fl_Window *) new_cat_win_->GetWindowPtr());

    {
	new_cat_input_ =
	    new NxInput(BUTTON_X, 55, 150, 20, "Enter a new category name:");
	new_cat_input_->align(FL_ALIGN_TOP_LEFT);
	new_cat_input_->maximum_size(MAX_NAME_SIZE);
	new_cat_win_->add((Fl_Widget *) new_cat_input_);
    }

    {
	NxButton *o =
	    new NxButton(BUTTON_X, 90, BUTTON_WIDTH, BUTTON_HEIGHT, "Done");
	o->callback(done_new_cat_cb, this);
	new_cat_win_->add((Fl_Widget *) o);
    }
    {
	NxButton *o =
	    new NxButton(BUTTON_X + 61, 90, BUTTON_WIDTH, BUTTON_HEIGHT,
			 "Cancel");
	o->callback(cancel_new_cat_cb, this);
	new_cat_win_->add((Fl_Widget *) o);
    }

    rename_cat_win_ =
	new NxPimPopWindow("Rename Category",
			   NxApp::Instance()->getGlobalColor(APP_FG));
    NxApp::Instance()->add_window((Fl_Window *) rename_cat_win_->
				  GetWindowPtr());
    {
	rename_cat_input_ =
	    new NxInput(BUTTON_X, 55, 150, 20, "Enter a new category name:");
	rename_cat_input_->align(FL_ALIGN_TOP_LEFT);
	rename_cat_input_->maximum_size(MAX_NAME_SIZE);
	rename_cat_win_->add((Fl_Widget *) rename_cat_input_);
    }

    {
	NxButton *o =
	    new NxButton(BUTTON_X, 90, BUTTON_WIDTH, BUTTON_HEIGHT, "Done");
	o->callback(done_rename_cat_cb, this);
	rename_cat_win_->add((Fl_Widget *) o);
    }

    {
	NxButton *o =
	    new NxButton(BUTTON_X + 61, 90, BUTTON_WIDTH, BUTTON_HEIGHT,
			 "Cancel");
	o->callback(cancel_rename_cat_cb, this);
	rename_cat_win_->add((Fl_Widget *) o);
    }

    delete_cat_win_ =
	new NxPimPopWindow("Delete Category",
			   NxApp::Instance()->getGlobalColor(APP_FG));
    NxApp::Instance()->add_window((Fl_Window *) delete_cat_win_->
				  GetWindowPtr());
    {
	Fl_Box *o = new Fl_Box(BUTTON_X, 43, W_W - BUTTON_X - 15, 0,
			       "Are you sure you want to delete this category?");
	o->color(NxApp::Instance()->getGlobalColor(APP_BG));
	o->box(FL_FLAT_BOX);
	o->align(FL_ALIGN_WRAP | FL_ALIGN_LEFT | FL_ALIGN_TOP);
	NxApp::Instance()->def_font((Fl_Widget *) o);
	delete_cat_win_->add((Fl_Widget *) o);
    }
    {
	Fl_Box *o = new Fl_Box(BUTTON_X, 75, W_W - BUTTON_X - 15, 0,
			       "All notes whithin this category become \"Unfiled\".");
	o->color(NxApp::Instance()->getGlobalColor(APP_BG));
	o->box(FL_FLAT_BOX);
	o->align(FL_ALIGN_WRAP | FL_ALIGN_LEFT | FL_ALIGN_TOP);
	NxApp::Instance()->def_font((Fl_Widget *) o);
	delete_cat_win_->add((Fl_Widget *) o);
    }
    {
	NxButton *o =
	    new NxButton(BUTTON_X, 90, BUTTON_WIDTH, BUTTON_HEIGHT, "Yes");
	o->callback(delete_yes_cat_cb, this);
	delete_cat_win_->add((Fl_Widget *) o);
    }
    {
	NxButton *o =
	    new NxButton(BUTTON_X + 61, 90, BUTTON_WIDTH, BUTTON_HEIGHT,
			 "No");
	o->callback(delete_no_cat_cb, this);
	delete_cat_win_->add((Fl_Widget *) o);
    }
    pim_window->end();
    set_pim_window(pim_window);
}

--- NEW FILE: nxmultilineoutput.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include <nxapp.h>
#include <FL/Enumerations.H>
#include <nxmultilineoutput.h>

NxMultilineOutput::NxMultilineOutput(int x, int y, int w, int h,
				     const char *l):
Fl_Multiline_Output(x, y, w, h, l)
{

    // Provide the specific "look-and-feel"
    color(NxApp::Instance()->getGlobalColor(APP_BG));
    selection_color(NxApp::Instance()->getGlobalColor(APP_SEL));
    textcolor(NxApp::Instance()->getGlobalColor(APP_FG));
    NxApp::Instance()->def_font(this);
    box(FL_FLAT_BOX);
    align(FL_ALIGN_INSIDE | FL_ALIGN_LEFT);
}				// end of NxMultilineOutput::NxMultilineOutput()

--- NEW FILE: nxoutput.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include <nxapp.h>
#include <FL/Enumerations.H>
#include <nxoutput.h>

NxOutput::NxOutput(int x, int y, int w, int h, const char *l):
Fl_Output(x, y, w, h, l)
{

    move = true;
    // Provide the specific "look-and-feel"
    color(NxApp::Instance()->getGlobalColor(APP_BG));
    labelcolor(NxApp::Instance()->getGlobalColor(APP_FG));
    textcolor(NxApp::Instance()->getGlobalColor(APP_FG));
    selection_color(NxApp::Instance()->getGlobalColor(APP_SEL));
    NxApp::Instance()->def_font(this);
    box(FL_FLAT_BOX);
    align(FL_ALIGN_INSIDE | FL_ALIGN_LEFT);
}				// end of NxOutput::NxOutput()

--- NEW FILE: blkio.c ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifndef WIN32
#include <unistd.h>
#endif /*  */
#include <malloc.h>
#include "file.h"
/*
 * blkio.c - block i/o routines
 *
 * from 8/25/85 mt15b
 */
#define	MIN(a,b)		((a) < (b) ? (a) : (b))
#define	MAX(a,b) 		((a) > (b) ? (a) : (b))

#define dprintf printf

#define MAXBUFS	20		/* max number of in-core buffers */
#define LOCKVAL	32767		/* value of usecnt to lock buffer incore */
struct buffer *startbuf;	/* ptr to first buffer */
struct buffer *endbuf;		/* ptr past last buffer */
char apflag = 0;		/* append mode flag for getblk() */

/* local data*/
static int lockclock = 0;

/* local procs*/
static int bread(int fd, char *buf, int blk);
static int bwrite(int fd, char *buf, int blk);
static int bfilesize(int fd);
static struct buffer *berr(char *str, int blk, struct fildes *fp);

/*
 * read record recno from file fp into recbuf, return 1 if ok
 */
int
getrec(int recno, struct fildes *fp, char *recbuf)
{
    int off, cnt, n, blk;
    struct buffer *bp;
    long offset;
    char *tmpBuf;
    if ((recno == 0))
	return (0);
    cnt = fp->recsiz;
    offset = (recno - 1) * (long) cnt + RECOFF;
    tmpBuf = recbuf;

    do {
	blk = (int) (offset >> BLKSHFT);	/* logical blk # */
	off = (int) (offset & BLKMSK);	/* offset in blk */
	n = umin(BLKSIZ - off, cnt);	/* calc read cnt */
	if ((bp = getblk(blk, fp)) == NULL)
	    return (0);
	memcpy(recbuf, &bp->buf[off], n);
	recbuf += n;
	cnt -= n;
	offset += n;
    } while (cnt != 0);
    fp->flags = get32(&tmpBuf[fp->recsiz - sizeof(long)]);

#if 0
    if (fp->flags) {
	fprintf(stderr, "getrec: %ld\n", fp->flags);
    }
#endif /*  */
    return (!recdeleted(fp));
}


// returns true if the record can be safely overwritten
int
recerased(struct fildes *fp)
{
    return (fp->flags & 0xF0);
}

int
recdeleted(struct fildes *fp)
{

    /*printf("blkio.c recdeleted may need to check more flags\n"); */
    return ((fp->flags & 0xF0) | (fp->flags & 0x01));
}

int
putrec(int recno, struct fildes *fp, char *recbuf)
{
    int off, cnt, n, blk;
    struct buffer *bp;
    long offset;
    if (recno == 0 || recno > fp->nrecs) {
	fprintf(stderr, "\007*** Putrec: invalid record number %d\n", recno);
	return (0);
    }
    if (recno == APPEND) {	/* check for append mode */
	recno = fp->currec = ++fp->nrecs;
	fp->fchanged = 1;
	apflag = 1;
    }
    cnt = fp->recsiz;
    offset = (recno - 1) * (long) cnt + RECOFF;
    put32(&recbuf[cnt - sizeof(long)], fp->flags);

    do {
	blk = (int) (offset >> BLKSHFT);
	off = (int) (offset & BLKMSK);
	n = umin(BLKSIZ - off, cnt);
	if ((bp = getblk(blk, fp)) == NULL) {
	    return (0);
	}
	memcpy(&bp->buf[off], recbuf, n);
	bp->changed = 1;
	recbuf += n;
	cnt -= n;
	offset += n;
    } while (cnt != 0);
    apflag = 0;
    return (1);
}
struct buffer *
getblk(int blk, struct fildes *fp)
{
    struct buffer *bp, *savbp;
    if (++lockclock >= LOCKVAL)	/* lru timing */
	lockclock = 1;
    savbp = NULL;
    for (bp = startbuf; bp < endbuf; bp++) {
	if (bp->blkno == blk && bp->fptr == fp) {
	    bp->usecnt = lockclock;
	    return (bp);
	}
	if (savbp == NULL || bp->usecnt < savbp->usecnt)
	    savbp = bp;
    }
    if (savbp->usecnt == LOCKVAL)
	return berr("all bufs locked", blk, fp);
    if (savbp->changed) {	/* write buffer if modified */
	putblk(savbp);
    }
    if (!bread(fp->fildesc, savbp->buf, blk)) {
	if (apflag) {
	    memset(savbp->buf, 0, BLKSIZ);
	    savbp->changed = 1;
	} else {
	    return berr("read error", blk, fp);
	}
    }
    savbp->blkno = blk;
    savbp->fptr = fp;
    savbp->usecnt = lockclock;
    return (savbp);
}

void
putblk(struct buffer *bp)
{
    if (bp == NULL)
	return;
    bwrite(bp->fptr->fildesc, bp->buf, bp->blkno);
    bp->changed = 0;
}
struct buffer *
newblk(struct fildes *fp)
{
    struct buffer *bp;
    int blk;
    blk = 0;
    for (bp = startbuf; bp < endbuf; bp++)
	if (bp->fptr == fp)
	    blk = MAX(blk, bp->blkno);
    fprintf(stderr, "newblk: filesize=%d, max incore blk=%d,",
	    bfilesize(fp->fildesc), blk);
    blk = MAX(bfilesize(fp->fildesc), blk + 1);
    fprintf(stderr, "new=%d\n", blk);
    apflag = 1;
    bp = getblk(blk, fp);
    apflag = 0;
    return (bp);
}
struct buffer *
lockb(struct buffer *bp)
{
    if (bp)
	bp->usecnt = LOCKVAL;
    return (bp);
}

void
unlock(struct buffer *bp)
{
    if (++lockclock >= LOCKVAL)	/* lru timing */
	lockclock = 1;
    bp->usecnt = lockclock;
}

void
dbinit(int maxbufs)
{
    register struct buffer *bp;
    if (maxbufs <= 0)
	maxbufs = MAXBUFS;
    while ((startbuf = malloc(sizeof(struct buffer) * maxbufs)) == NULL) {
	if (--maxbufs < 4)
	    fatal(9);		/* no memory */
    }
    endbuf = startbuf + maxbufs;
    for (bp = startbuf; bp < endbuf; bp++) {
	bp->usecnt = 0;
	bp->fptr = NULL;
	bp->changed = 0;
    }
}
static int
bread(int fd, char *buf, int blk)
{
    lseek(fd, (long) blk << 10, 0);
    if (read(fd, buf, 1024) != 1024)
	return (0);
    return (1);
}
static int
bwrite(int fd, char *buf, int blk)
{
    lseek(fd, (long) blk << 10, 0);
    if (write(fd, buf, 1024) != 1024) {
	return (0);
    }
    return (1);
}


/*
 * return file size in 1K blocks
 */
static int
bfilesize(int fd)
{

#if UNIX
    struct stat sbuf;
    if (fstat(fd, &sbuf) < 0)
	return (0);
    return ((int) (sbuf.st_size / (long) BLKSIZ));

#else /*  */
    return ((int) (lseek(fd, 0L, 2) / (long) BLKSIZ));

#endif /*  */
}
unsigned int
umin(unsigned int a, unsigned int b)
{
    if (a < b)
	return (a);
    return (b);
}
static struct buffer *
berr(char *str, int blk, struct fildes *fp)
{
    printf("\007*** getblk: %s, blk=%d, file=%s\n", str, blk, fp->filext);
    return (NULL);
}

--- NEW FILE: database.h ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */

#ifndef _DATABASE_H_
#define _DATABASE_H_

enum
{
    DB_TEXT = 0x001,
    DB_STRING = 0x002,
    DB_INTEGER = 0x004,
    DB_FLOAT = 0x008,
    DB_PLUSINTEGER = 0x010,
    DB_PRIMARY = 0x100
};

enum
{
    DB_OK = 0,
    DB_ERROR = -1,
    DB_TABLE_EXISTS = -2,
    DB_FILE_ERROR = -3,
    DB_NOT_OPENED = -4
};

class db_row
{
  private:
    char **fields_;
    char **data_;

    int cols_;

    int find_col(char *);

  public:
      db_row(void);
      db_row(char **, int, char **);
      db_row(db_row &);
     ~db_row(void);

    char *operator[] (int);
    char *operator[] (char *);

      db_row & operator=(const db_row &);
    int value(int col, void *dest, unsigned int size, int type);
    int value(char *field, void *dest, unsigned int size, int type);
};

class db_query
{
  private:
    db_row ** rows_;
    int count_;
  public:
      db_query(int, char **, int, char **);
     ~db_query();

    int rows(void)
    {
	return (count_);
    }
    db_row *row(int r)
    {
	if (r < count_)
	    return (rows_[r]);
	else
	    return (0);
    }
};


struct db_fields
{
    char field[20];
    int type;
};

struct db_table
{
    char name[20];
    int field_count;
    db_fields *fields;
};


class database
{

  private:
    struct sqlite *dbhandle;

  public:
      database(void)
    {
	dbhandle = 0;
    }
     ~database(void)
    {
	close();
    }

    int open(char *filename);
    void close(void);

    int add_table(db_table * table);

    db_query *get_names(char *);
    db_query *get_record(int);

    int exec(const char *str, ...);
    db_query *do_query(const char *str, ...);

    int insert_record(db_table *, char **, int n = -1);
    int update_record(db_table *, char **);
    void delete_record(int);
};

char *db_qexpand(char *str);

#endif

--- NEW FILE: nxmenuwindow.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */

// This is the window type used by Fl_Menu to make the pop-ups.
// It draws in the overlay planes if possible.

// Also here is the implementation of the mouse & keyboard grab,
// which are used so that clicks outside the program's windows
// can be used to dismiss the menus.

#include <pixil_config.h>

#include <FL/Fl.H>
#include <FL/x.H>
#include <FL/fl_draw.H>
#include <nxmenuwindow.h>

// WIN32 note: HAVE_OVERLAY is false
#if HAVE_OVERLAY
extern XVisualInfo *fl_find_overlay_visual();
extern XVisualInfo *fl_overlay_visual;
extern Colormap fl_overlay_colormap;
extern unsigned long fl_transparent_pixel;
static GC gc;			// the GC used by all X windows
extern uchar fl_overlay;	// changes how fl_color(x) works
#endif

#include <stdio.h>

void
NxMenuWindow::show()
{

#if HAVE_OVERLAY
    if (!shown() && overlay() && fl_find_overlay_visual()) {
	XInstallColormap(fl_display, fl_overlay_colormap);
	fl_background_pixel = int (fl_transparent_pixel);
	Fl_X::make_xid(this, fl_overlay_visual, fl_overlay_colormap);
	fl_background_pixel = -1;
    } else
#endif
#ifdef CONFIG_NANOX
	Fl_X::mw_parent = 0;
#endif
    Fl_Single_Window::show();
}

void
NxMenuWindow::flush()
{
#if HAVE_OVERLAY
    if (!fl_overlay_visual || !overlay()) {
	Fl_Single_Window::flush();
	return;
    }
    Fl_X *i = Fl_X::i(this);
    fl_window = i->xid;
    if (!gc)
	gc = XCreateGC(fl_display, i->xid, 0, 0);
    fl_gc = gc;
    fl_overlay = 1;
    fl_clip_region(i->region);
    i->region = 0;
    draw();
    fl_overlay = 0;
#else
    Fl_Single_Window::flush();
#endif
}

void
NxMenuWindow::erase()
{
#if HAVE_OVERLAY
    if (!gc || !shown())
	return;
//XSetForeground(fl_display, gc, 0);
//XFillRectangle(fl_display, fl_xid(this), gc, 0, 0, w(), h());
    XClearWindow(fl_display, fl_xid(this));
#endif
}

// Fix the colormap flashing on Maximum Impact Graphics by erasing the
// menu before unmapping it:
void
NxMenuWindow::hide()
{
    erase();
    Fl_Single_Window::hide();
}

NxMenuWindow::~NxMenuWindow()
{
    hide();
}

--- NEW FILE: catlist.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include <stdio.h>
#include <string.h>
#include "catlist.h"
#include "nxapp.h"

static void
select_callback(Fl_Widget * fl, long l)
{
    //cerr << "select_callback()\n";
    NxCategoryList *list = (NxCategoryList *) fl;
    memset(list->m_CatBuf, 0, sizeof(list->m_CatBuf));
    strcpy(list->m_CatBuf, list->text());
    if (0 == strcasecmp("Edit", list->m_CatBuf)) {
	NxApp::Instance()->show_window(NxApp::Instance()->
				       get_catlist_window());
	list->label(list->get_category_buf());
    } else {
	strcpy(list->get_category_buf(), list->m_CatBuf);
	list->label(list->m_CatBuf);
	list->hide();
	list->show();
	if (list->m_Cb)
	    (*list->m_Cb) (list, (void *) list->m_CatBuf);

    }

    list->set_value();
}

char *
NxCategoryList::label()
{
    return const_cast < char *>(Fl_Widget::label());
}

void
NxCategoryList::set_value()
{
    for (int idx = 0; idx < size() - 1; idx++) {
	if (0 == strcmp(label(), text(idx))) {
	    value(idx);
	}
    }
}

void
NxCategoryList::label(char *szLabel)
{
    strcpy(m_CatBuf, szLabel);
    Fl_Widget::label(m_CatBuf);

    if (0 != strcasecmp("Edit", m_CatBuf))
	set_value();

}

int
NxCategoryList::add(const char *value)
{
    int ret = 0;

    remove(size() - 2);
    remove(size() - 2);
    ret = NxMenuButton::add(value);

    if (0 > ret)
	return ret;
    ret = NxMenuButton::add("Unfiled");
    if (0 > ret)
	return ret;
    ret = NxMenuButton::add("Edit");
    return ret;
}

void
NxCategoryList::set_category_buf(char *cat_buf)
{
    strcpy(NxCategoryBuf, cat_buf);
}


NxCategoryList::NxCategoryList(int x, int y, int w, int h, NxDb * db,
			       string _dbName):
NxMenuButton(x, y, w, h, "")
{

    add("All");
    box(FL_SHADOW_BOX);

    // Extract records from category database.
    int nLastItem = db->NumRecs(_dbName);
    int key = 0;
    int fieldNo = 1;
    char *new_category = new char[255];

    strcpy(NxCategoryBuf, "All");

    for (int i = 0; i < nLastItem; i++) {

	char find[4];
	sprintf(find, "%d", i);
	int get_recno[1];
	get_recno[0] = -1;

	db->Select(_dbName, find, key, get_recno, 1);
	int recno = get_recno[0];

	if (recno == -1) {
	    break;
	}

	db->Extract(_dbName, recno, fieldNo, new_category);
	add(new_category);

    }

    delete[]new_category;
    new_category = 0;

    callback(select_callback);
    add("Unfiled");
    add("Edit");
    select(0);

}

--- NEW FILE: misc.c ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include <stdio.h>
#include <string.h>

#include "misc.h"

void
remove_end_spaces(char *ret_buf, char *in_buf)
{

    int in_len = 0;
    int idx = 0;
    int end = 0;

    in_len = strlen(in_buf);
    for (idx = in_len; idx >= 0; idx--) {
	if (in_buf[idx] == '\0')
	    continue;
	if (in_buf[idx] != ' ') {
	    ret_buf[idx] = in_buf[idx];
	    if (!end) {
		ret_buf[idx + 1] = '\0';
		end = 1;
	    }
	}
    }
}

--- NEW FILE: nxvalueslider.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include <nxapp.h>
#include <FL/Enumerations.H>
#include <nxvalueslider.h>

NxValueSlider::NxValueSlider(int x, int y, int w, int h, char *l):
Fl_Value_Slider(x, y, w, h, l)
{

    // Provide the "look-and-feel"
    color(NxApp::Instance()->getGlobalColor(SCROLL_TRAY));
    selection_color(NxApp::Instance()->getGlobalColor(SCROLL_FACE));
    box(FL_SHADOW_BOX);
    align(FL_ALIGN_INSIDE | FL_ALIGN_LEFT);
    value(0);
}				// end of NxValueSlider::NxValueSlider()

--- NEW FILE: nxwindow.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include <nxwindow.h>
#include <iostream>
#include <nxapp.h>
#include <nxbox.h>

///////////////////////
// NxPimWindow Methods

//
// Constructors
//

extern void fl_internal_boxtype(Fl_Boxtype t, Fl_Box_Draw_F * f);

void
nx_rectbound(int x, int y, int w, int h, Fl_Color bgcolor)
{
    fl_color(NxApp::Instance()->getGlobalColor(APP_FG));
    fl_rect(x, y, w, h);
    fl_color(bgcolor);
    fl_rectf(x + 1, y + 1, w - 2, h - 2);
}

void
tab_draw(int x, int y, int w, int h, Fl_Color c)
{
    fl_color(c);
    fl_draw_box(FL_ROUNDED_BOX, x, y, w + 5, h, c);
    fl_rectf(x, h - 5, w + 5, 10);
    fl_rectf(w, h + 3, 152, 2);
}

void
nx_bottom_box(int x, int y, int w, int h, Fl_Color c)
{
    y = y + h - 3;
    fl_color(NxApp::Instance()->getGlobalColor(APP_FG));
    fl_rect(x, y, w, 1);
    fl_color(c);
    fl_rectf(x + 1, y + 1, w - 2, h - 2);
}

// Default
NxPimWindow::NxPimWindow(char *_title, Fl_Menu_Item * menu_item, NxDb * catDb,
			 string _catDbName, string _noteDbName,
			 void (*update_items) (const char *category))
{

    //  fl_internal_boxtype(FL_BORDER_BOX, nx_rectbound);
    //  fl_internal_boxtype(_FL_ROUNDED_BOX, nx_rectbound);
    //  fl_internal_boxtype(FL_UP_BOX, nx_rectbound);
#ifdef NANOX
    fl_internal_boxtype(FL_BOTTOM_BOX, nx_bottom_box);
#else
    fl_internal_boxtype(FL_DOWN_BOX, nx_bottom_box);
#endif

    menu = 0;
    grp = 0;

    catDb_ = catDb;
    //fprintf(stderr, "NxPimwWindow:catDb_[%p]\n", catDb_);

    pim_window = new NxDoubleWindow(W_X, W_Y, W_W, W_H);
    pim_window->color(NxApp::Instance()->getGlobalColor(APP_BG));
    pim_window->WinType(PIM_WINDOW);

    menu_bar = new menu_cb_struct;

    grp = new Fl_Group(MENU_X, MENU_Y, MENU_W, MENU_H);

    // Menu Button

#ifndef TABS
    menu_button = new NxButton(MB_X, MB_Y, MB_W, MB_H, _title);
    menu_button->movable(false);	// don't allow this button to do any resize.
#else
    Fl::set_boxtype(FL_PDA_NO_BOX, tab_draw, 1, 1, 2, 2);
    menu_button = new Fl_Button(2, 1, MB_W, MB_H, _title);
    menu_button->box(FL_PDA_NO_BOX);
    menu_button->color(NxApp::Instance()->getGlobalColor(APP_BG));
    menu_button->labelcolor(NxApp::Instance()->getGlobalColor(APP_FG));
#endif

    menu_button->callback((Fl_Callback *) hideButtons_cb, (void *) menu_bar);

    if (catDb_) {

	// Category List
#ifndef TABS
	category_list =
	    new NxCategoryList(CL_X, CL_Y, CL_W, CL_H, catDb, _catDbName);
#else
	category_list =
	    new NxCategoryList(CL_X + 5, 2, CL_W, CL_H - 1, catDb,
			       _catDbName);
#endif
    } else {
	category_list = 0;
    }

    grp->end();

    // Menu
    menu = new NxMenuBar(MENU_X, MENU_Y, MENU_W, MENU_H, grp);
    menu->menu(menu_item);
    menu->callback((Fl_Callback *) hideMenuBar_cb, (void *) menu_bar);
    menu->hide();
    menu_bar->grp = grp;
    menu_bar->menu = menu;

    pim_window->end();

    if (catDb_)
	MakeEditCategoryWindow(catDb, _catDbName, _noteDbName,
			       (void (*)(const char *)) update_items);

}

//  Size All
NxPimWindow::NxPimWindow(Fl_Menu_Item * menu_item, NxDb * catDb,
			 string _catDbName, string _noteDbName,
			 void (*update_items) (const char *category), int x,
			 int y, int w, int h, int menu_x, int menu_y,
			 int menu_w, int menu_h, int cl_x, int cl_y, int cl_w,
			 int cl_h, char *nx_inipath)
{

    menu = 0;
    grp = 0;

    catDb_ = catDb;
    pim_window = new NxDoubleWindow(x, y, w, h);
    pim_window->color(NxApp::Instance()->getGlobalColor(APP_BG));
    pim_window->WinType(PIM_WINDOW);

    // Menu
    menu = new NxMenuBar(menu_x, menu_y, menu_w, menu_h);
    menu->menu(menu_item);
    menu->hide();

    if (catDb_) {
	// Category List
	category_list =
	    new NxCategoryList(cl_x, cl_y, cl_w, cl_h, catDb, _catDbName);
    } else {
	category_list = 0;
    }

    // Menu Button
    menu_button = new NxButton(MB_X, MB_Y, MB_W, MB_H, "Address");

    pim_window->end();

    if (catDb_)
	MakeEditCategoryWindow(catDb, _catDbName, _noteDbName,
			       (void (*)(const char *)) update_items);

}

// Size Window Only or Menu Only
NxPimWindow::NxPimWindow(Fl_Menu_Item * menu_item, NxDb * catDb,
			 string _catDbName, string _noteDbName,
			 void (*update_items) (const char *category), int x,
			 int y, int w, int h, int type)
{

    menu = 0;
    grp = 0;

    catDb_ = catDb;
    // Window
    if (type == WINDOW)
	pim_window = new NxDoubleWindow(x, y, w, h);
    else
	pim_window = new NxDoubleWindow(W_X, W_Y, W_W, W_H);

    pim_window->color(NxApp::Instance()->getGlobalColor(APP_BG));
    pim_window->WinType(PIM_WINDOW);

    // Menu
    if (type == MENU)
	menu = new NxMenuBar(x, y, w, h);
    else
	menu = new NxMenuBar(MENU_X, MENU_Y, MENU_W, MENU_H);

    menu->hide();

    if (catDb_) {
	// Category List
	category_list =
	    new NxCategoryList(CL_X, CL_Y, CL_W, CL_H, catDb, _catDbName);
    } else {
	category_list = 0;
    }

    // Menu Button
    menu_button = new NxButton(MB_X, MB_Y, MB_W, MB_H, "Address");

    pim_window->end();

    if (catDb_)
	MakeEditCategoryWindow(catDb, _catDbName, _noteDbName,
			       (void (*)(const char *)) update_items);

}

// Just a menubar or just a menubutton, but not both.
NxPimWindow::NxPimWindow(char *_title, Fl_Menu_Item * menu_item, int type)
{

#ifdef NANOX
    fl_internal_boxtype(FL_BOTTOM_BOX, nx_bottom_box);
#else
    fl_internal_boxtype(FL_DOWN_BOX, nx_bottom_box);
#endif

    menu = 0;
    grp = 0;

    pim_window = new NxDoubleWindow(W_X, W_Y, W_W, W_H);
    pim_window->color(NxApp::Instance()->getGlobalColor(APP_BG));
    pim_window->WinType(PIM_WINDOW);

    if (type == MENU) {

	// Menu
	_menu = new NxMenuButton(MB_X, MB_Y, MB_W, MB_H, _title);
	_menu->menu(menu_item);

    } else {

	menu_bar = new menu_cb_struct;
	grp = new Fl_Group(MENU_X, MENU_Y, MENU_W, MENU_H);

	// Menu Button
	menu_button = new NxButton(MB_X, MB_Y, MB_W, MB_H, _title);
	menu_button->callback((Fl_Callback *) hideButtons_cb,
			      (void *) menu_bar);

	grp->end();

	// Menu
	menu = new NxMenuBar(MENU_X, MENU_Y, MENU_W, MENU_H, grp);
	menu->menu(menu_item);
	menu->callback((Fl_Callback *) hideMenuBar_cb, (void *) menu_bar);
	menu->hide();
	menu_bar->grp = grp;
	menu_bar->menu = menu;
    }

    pim_window->end();

}

// Size Category List Only
NxPimWindow::NxPimWindow(Fl_Menu_Item * menu_item, NxDb * catDb,
			 string _catDbName, string _noteDbName,
			 void (*update_items) (const char *category),
			 int cl_x, int cl_y, int cl_w, int cl_h,
			 char *nx_inipath)
{

    menu = 0;
    grp = 0;

    catDb_ = catDb;
    pim_window = new NxDoubleWindow(W_X, W_Y, W_W, W_H);
    pim_window->color(NxApp::Instance()->getGlobalColor(APP_BG));
    pim_window->WinType(PIM_WINDOW);

    // Menu
    menu = new NxMenuBar(MENU_X, MENU_Y, MENU_W, MENU_H);
    menu->menu(menu_item);
    menu->box(FL_BORDER_BOX);
    menu->hide();

    if (catDb_) {
	// Category List
	category_list =
	    new NxCategoryList(cl_x, cl_y, cl_w, cl_h, catDb, _catDbName);
    } else {
	category_list = 0;
    }

    // Menu Button
    menu_button = new NxButton(MB_X, MB_Y, MB_W, MB_H, "Address");

    pim_window->end();
    if (catDb_)
	MakeEditCategoryWindow(catDb, _catDbName, _noteDbName,
			       (void (*)(const char *)) update_items);

}

NxPimWindow::NxPimWindow(int x, int y, int w, int h)
{

    menu = 0;
    grp = 0;

    pim_window = new NxDoubleWindow(x, y, w, h);
    pim_window->color(NxApp::Instance()->getGlobalColor(APP_BG));
    pim_window->WinType(PIM_WINDOW);
    pim_window->end();

}

// Callbacks
void
NxPimWindow::hideMenuBar_cb(Fl_Widget * fl, void *o)
{

    menu_cb_struct *s = (menu_cb_struct *) o;
    Fl_Group *grp = s->grp;
    NxMenuBar *menu = s->menu;

    menu->hide();
    grp->show();

}

void
NxPimWindow::hideButtons_cb(Fl_Widget * fl, void *o)
{

    menu_cb_struct *s = (menu_cb_struct *) o;
    Fl_Group *grp = s->grp;
    NxMenuBar *menu = s->menu;

    grp->hide();
    menu->show();

}

// Methods

NxDoubleWindow *
NxPimWindow::GetWindowPtr()
{
    return pim_window;
}

NxDoubleWindow *
NxPimWindow::GetEditCategoryWindowPtr()
{
    return edit_category_window->GetWindowPtr();
}

void
NxPimWindow::add(Fl_Widget * w)
{
    pim_window->add(w);
}

void
NxPimWindow::MakeEditCategoryWindow(NxDb * catDb, string catdb_name,
				    string notedb_name,
				    void (*update_items) (const char
							  *category))
{
    edit_category_window = new NxEditCategory(catDb, catdb_name, notedb_name,
					      (void (*)(const char *))
					      update_items);
    NxApp::Instance()->add_window(edit_category_window->GetWindowPtr());
    edit_category_window->set_show_window(this);
    edit_category_window->set_menu_list(this->category_list);
}

//////////////////////////
// NxPimPopWindow Methods

//
// Constructors
//
#include <nxwindow.h>

NxPimPopWindow::NxPimPopWindow(char *title,
			       Fl_Color title_color,
			       int x, int y, int w, int h)
{


    pimp_window = new NxDoubleWindow(x, y, w, h);
    pimp_window->color(NxApp::Instance()->getGlobalColor(APP_BG));
    pimp_window->WinType(PIMP_WINDOW);

    {
	NxBox *o = new NxBox(0, 0, w - 1, h);
	o->color(NxApp::Instance()->getGlobalColor(APP_BG));
	o->box(FL_BORDER_BOX);
    }

    {
	NxOutput *o = new NxOutput(3, 3, (w - 7), 15, "");
	o->box(FL_BORDER_BOX);
	o->textcolor(NxApp::Instance()->getGlobalColor(TITLE_FG));
	o->color(NxApp::Instance()->getGlobalColor(TITLE_BG));
	o->value(title);
    }

    pimp_window->end();
    pimp_window->resizable(pimp_window);

}

NxPimPopWindow::NxPimPopWindow(int x, int y, int w, int h)
{

    pimp_window = new NxDoubleWindow(x, y, w, h);
    pimp_window->color(NxApp::Instance()->getGlobalColor(APP_BG));
    pimp_window->WinType(PIMP_WINDOW);

    {
	Fl_Box *o = new Fl_Box(0, 0, w, h);
	o->color(NxApp::Instance()->getGlobalColor(APP_BG));
	o->box(FL_BORDER_BOX);
    }

    pimp_window->end();
    pimp_window->resizable(pimp_window);

}

// Methods

NxDoubleWindow *
NxPimPopWindow::GetWindowPtr()
{
    return pimp_window;
}

void
NxPimPopWindow::add(Fl_Widget * w)
{
    pimp_window->add(w);
}

--- NEW FILE: nxintinput.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include <nxapp.h>
#include <FL/Enumerations.H>
#include <nxintinput.h>
#include <stdio.h>

NxIntInput::NxIntInput(int x, int y, int w, int h, const char *l):
Fl_Int_Input(x, y, w, h, l)
{

    move = true;

    // Provide the specific "look-and-feel"
    color(NxApp::Instance()->getGlobalColor(APP_BG));
    labelcolor(NxApp::Instance()->getGlobalColor(APP_FG));
    textcolor(NxApp::Instance()->getGlobalColor(APP_FG));
    selection_color(NxApp::Instance()->getGlobalColor(APP_SEL));
    NxApp::Instance()->def_font(this);
#ifdef NANOX
    box(FL_BOTTOM_BOX);
#else
    box(FL_FLAT_BOX);
#endif
    align(FL_ALIGN_LEFT);
}				// end of NxOutput::NxOutput()

--- NEW FILE: nxcheckbutton.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include <stdio.h>
#include <nxapp.h>
#include <FL/Enumerations.H>
#include <nxcheckbutton.h>

void
nx_cb_draw(int x, int y, int w, int h, Fl_Color c)
{
    Fl_Color lcolor = NxApp::Instance()->getGlobalColor(APP_FG);
    fl_color(lcolor);
    fl_line(x + 1, y + 1, x + w - 2, y + h - 2);
    fl_line(x + w - 2, y + 1, x + 1, y + h - 2);
}

NxCheckButton::NxCheckButton(int x, int y, char *l):
Fl_Check_Button(x, y, CHECK_W, CHECK_H, l)
{

    move = true;

    // Provide the "look-and-feel"
    color(NxApp::Instance()->getGlobalColor(APP_BG));
    selection_color(NxApp::Instance()->getGlobalColor(APP_SEL));
    labelcolor(NxApp::Instance()->getGlobalColor(APP_FG));
    NxApp::Instance()->def_font((Fl_Widget *) this);
    align(FL_ALIGN_INSIDE | FL_ALIGN_LEFT);
    value(0);
}				// end of NxCheckButton::NxCheckButton()

NxCheckButton::NxCheckButton(int x, int y, int w, int h, char *l):
Fl_Check_Button(x, y, w, h, l)
{

    // Provide the "look-and-feel"
    color(NxApp::Instance()->getGlobalColor(APP_BG));
    selection_color(NxApp::Instance()->getGlobalColor(APP_SEL));
    labelcolor(NxApp::Instance()->getGlobalColor(APP_FG));
    NxApp::Instance()->def_font((Fl_Widget *) this);
    align(FL_ALIGN_INSIDE | FL_ALIGN_LEFT);
    value(0);
}				// end of NxCheckButton::NxCheckButton()

void
NxCheckButton::draw(void)
{
    int bh = y() + (h() / 2) / 2;
    int d = h() / 6;
    int W = w() < h()? w() : h();

    draw_box(FL_DOWN_BOX, x(), bh, h() / 2, h() / 2, color());


    if (value()) {
	nx_cb_draw(x(), bh, h() / 2, h() / 2, color());

    }
#ifdef PDA
    labelcolor(labelcolor());
#endif

    draw_label(x() + W - d, y(), w() - W + d, h());

}

--- NEW FILE: nxslider.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include <nxapp.h>
#include <FL/Enumerations.H>
#include <nxslider.h>

void
NxSlider::_NxSlider()
{
    slider_size_ = 0;
    slider_ = 0;		// FL_UP_BOX;
}

NxSlider::NxSlider(int x, int y, int w, int h, const char *l):
Fl_Valuator(x, y, w, h, l)
{

    // Provide the "look-and-feel"
    color(NxApp::Instance()->getGlobalColor(SCROLL_TRAY));
    selection_color(NxApp::Instance()->getGlobalColor(SCROLL_FACE));
    box(FL_SHADOW_BOX);
    align(FL_ALIGN_INSIDE | FL_ALIGN_LEFT);
    value(0);
    movable_ = true;
}				// end of NxSlider::NxSlider()


void
NxSlider::draw()
{
    if (damage() & FL_DAMAGE_ALL)
	draw_box();
    draw(x() + Fl::box_dx(box()),
	 y() + Fl::box_dy(box()),
	 w() - Fl::box_dw(box()), h() - Fl::box_dh(box()));

}

void
NxSlider::slider_size(double v)
{
    if (v < 0)
	v = 0;
    if (v > 1)
	v = 1;
    if (slider_size_ != float (v)) {
	slider_size_ = float (v);
	damage(FL_DAMAGE_EXPOSE);
    }
}

void
NxSlider::bounds(double a, double b)
{
    if (minimum() != a || maximum() != b) {
	Fl_Valuator::bounds(a, b);
	damage(FL_DAMAGE_EXPOSE);
    }
}

int
NxSlider::scrollvalue(int p, int w, int t, int l)
{
//      p = position, first line displayed
//      w = window, number of lines displayed
//      t = top, number of first line
//      l = length, total number of lines
    step(1, 1);
    if (p + w > t + l)
	l = p + w - t;
    slider_size(w >= l ? 1.0 : double (w) / double (l));
#ifdef PDA
    if (slider_size() < slider_size_min_) {
	slider_size(slider_size_min_);
    }
#endif
    bounds(t, l - w + t);
    return value(p);
}

void
NxSlider::draw_bg(int x, int y, int w, int h)
{
    if (!(damage() & FL_DAMAGE_ALL)) {	// not a complete redraw
	if (type() == FL_VERT_NICE_SLIDER || type() == FL_HOR_NICE_SLIDER) {
	    fl_color(color());
	    fl_rectf(x, y, w, h);
	} else {
	    fl_color(color());
	    fl_rectf(x + 1, y, w - 2, h);
	}
    }
    Fl_Color black = active_r()? FL_BLACK : FL_INACTIVE_COLOR;
    if (type() == FL_VERT_NICE_SLIDER) {
	draw_box(FL_THIN_DOWN_BOX, x + w / 2 - 2, y, 4, h, black);
    } else if (type() == FL_HOR_NICE_SLIDER) {
	draw_box(FL_THIN_DOWN_BOX, x, y + h / 2 - 2, w, 4, black);
    }
}

void
NxSlider::draw(int x, int y, int w, int h)
{
    double val;

    if (minimum() == maximum())
	val = 0.5;
    else {
	val = (value() - minimum()) / (maximum() - minimum());
	if (val > 1.0)
	    val = 1.0;
	else if (val < 0.0)
	    val = 0.0;
    }

    int W = (horizontal()? w : h);
    int X, S;

    if (type() == FL_HOR_FILL_SLIDER || type() == FL_VERT_FILL_SLIDER) {
	S = int (val * W + .5);
	if (minimum() > maximum()) {
	    S = W - S;
	    X = W - S;
	} else
	    X = 0;
    } else {
	S = int (slider_size() * W + .5);
	int T = (horizontal()? h : w) / 2 + 1;
	if (type() == FL_VERT_NICE_SLIDER || type() == FL_HOR_NICE_SLIDER)
	    T += 4;
	if (S < T)
	    S = T;
	X = int (val * (W - S) + .5);
    }

    int xsl, ysl, wsl, hsl;
    if (horizontal()) {
	xsl = x + X;
	wsl = S;
	ysl = y;
	hsl = h;
    } else {
	ysl = y + X;
	hsl = S;
	xsl = x;
	wsl = w;
    }

    draw_bg(x, y, w, h);

    /*
       if (damage()&FL_DAMAGE_ALL) { // complete redraw
       draw_bg(x, y, w, h);
       } else { // partial redraw, clip off new position of slider
       // for moving scrollbar down
       if (X > 0) {
       if (horizontal()) 
       fl_clip(x, ysl, X, hsl);
       else {
       fl_clip(xsl, y, wsl, X+3);
       }

       draw_bg(x, y, w, h);
       fl_pop_clip();
       }

       // for moving scrollbar up
       if (X+S < W) {
       if (horizontal()) 
       fl_clip(xsl+wsl, ysl, x+w-xsl-wsl, hsl);
       else {
       fl_clip(xsl, ysl+hsl+10, wsl, y+h-ysl-hsl);
       }

       draw_bg(x, y, w, h);
       fl_pop_clip();
       }
       }
     */

    Fl_Boxtype box1 = slider();
    if (!box1) {
	box1 = (Fl_Boxtype) (box() & -2);
	if (!box1)
	    box1 = FL_UP_BOX;
    }
    if (type() == FL_VERT_NICE_SLIDER) {
	wsl += 2;

	fl_color(selection_color());
	fl_begin_polygon();
	fl_transformed_vertex(xsl, ysl + 3);
	fl_transformed_vertex(xsl + 1, ysl + 2);
	fl_transformed_vertex(xsl + 2, ysl + 1);

	fl_transformed_vertex(xsl + wsl - 3, ysl);
	fl_transformed_vertex(xsl + wsl, ysl + 3);
	fl_transformed_vertex(xsl + wsl, ysl + hsl - 8);
	fl_transformed_vertex(xsl + wsl - 3, ysl + hsl - 4);
	fl_transformed_vertex(xsl + 3, ysl + hsl - 4);
	fl_transformed_vertex(xsl, ysl + hsl - 7);
	fl_end_polygon();

	// draw the lines
	int y_cen = (ysl + hsl) / 2;

	fl_color(NxApp::Instance()->getGlobalColor(SCROLL_TRAY));
	fl_line(xsl + 4, y_cen - 2, xsl + wsl - 8, y_cen - 2);
	fl_line(xsl + 4, y_cen + 2, xsl + wsl - 8, y_cen + 2);
    } else if (type() == FL_HOR_NICE_SLIDER) {

	hsl += 2;
	fl_color(selection_color());
	fl_begin_polygon();
	fl_transformed_vertex(xsl, ysl + 3);
	fl_transformed_vertex(xsl + 1, ysl + 2);
	fl_transformed_vertex(xsl + 2, ysl + 1);

	fl_transformed_vertex(xsl + wsl - 3, ysl);
	fl_transformed_vertex(xsl + wsl, ysl + 3);
	fl_transformed_vertex(xsl + wsl, ysl + hsl - 8);
	fl_transformed_vertex(xsl + wsl - 3, ysl + hsl - 4);
	fl_transformed_vertex(xsl + 3, ysl + hsl - 4);
	fl_transformed_vertex(xsl, ysl + hsl - 7);
	fl_end_polygon();

	// draw the lines
	int x_cen = (xsl + (xsl + wsl)) / 2;

	fl_color(NxApp::Instance()->getGlobalColor(SCROLL_TRAY));
	fl_line(x_cen - 2, ysl + 4, x_cen - 2, ysl + hsl - 8);
	fl_line(x_cen + 2, ysl + 4, x_cen + 2, ysl + hsl - 8);

    } else {			// draw the slider box
	Fl_Color col = selection_color();
	if (horizontal()) {
	    slider_ver_lines(xsl, ysl, wsl, hsl, W, col);
	} else {
	    slider_hor_lines(xsl, ysl, wsl, hsl, W, col);
	}
    }
    draw_label(xsl, ysl, wsl, hsl);
}

void
NxSlider::slider_ver_lines(int x, int y, int w, int h, int W, Fl_Color c)
{
    int cx = x + w / 2;
    int cy = y + h / 2;

    fl_color(FL_BLACK);
    if (type() != FL_HORIZONTAL) {
	draw_box(FL_BORDER_BOX, x, y, w, h, c);
    } else {
	if (w > 0 && h > 0) {
	    if (w < 17) {
		w = 17;
		slider_size(double (w) / double (W));
		slider_size_min_ = slider_size();
	    }
	    draw_box(FL_BORDER_BOX, x, y, w, h, c);
	    fl_color(FL_BLACK);
	    cx = x + w / 2;
	    fl_line(cx, cy - h / 2 + 4, cx, cy + h / 2 - 4);
	    fl_line(cx - 3, cy - h / 2 + 4, cx - 3, cy + h / 2 - 4);
	    fl_line(cx + 3, cy - h / 2 + 4, cx + 3, cy + h / 2 - 4);
	}
    }
}

void
NxSlider::slider_hor_lines(int x, int y, int w, int h, int W, Fl_Color c)
{
    int cx = x + w / 2;
    int cy = y + h / 2;

    fl_color(FL_BLACK);
    if (type() != FL_VERTICAL) {
	draw_box(FL_BORDER_BOX, x, y, w, h, c);
    } else {
	if (w > 0 && h > 0) {
	    if (h < 17) {
		h = 17;
		slider_size(double (h) / double (W));
		slider_size_min_ = slider_size();
	    }

	    fl_color(c);

	    fl_rectf(x + 3, y + 3, w - 6, h - 6);

	    // draw top rounded border
	    fl_line(x + 4, y + 2, x + w - 5, y + 2);

	    // draw bottom rounded border
	    fl_line(x + 4, y + h - 3, x + w - 5, y + h - 3);

	    fl_color(NxApp::Instance()->getGlobalColor(SCROLL_TRAY));

	    cy = y + h / 2;

	    fl_line(cx + w / 2 - 6, cy, cx - w / 2 + 5, cy);
	    fl_line(cx + w / 2 - 6, cy - 3, cx - w / 2 + 5, cy - 3);
	    fl_line(cx + w / 2 - 6, cy + 3, cx - w / 2 + 5, cy + 3);
	}
    }
}

int
NxSlider::handle(int event, int x, int y, int w, int h)
{
    switch (event) {
    case FL_PUSH:
	if (!Fl::event_inside(x, y, w, h))
	    return 0;
	handle_push();
    case FL_DRAG:{
	    int W = (horizontal()? w : h);
	    //int H = (horizontal() ? h : w);
	    int mx = (horizontal()? Fl::event_x() - x : Fl::event_y() - y);
	    int S = int (slider_size_ * W + .5);
	    int X;
	    static int offcenter;
	    if (type() == FL_HOR_FILL_SLIDER || type() == FL_VERT_FILL_SLIDER) {
		double val = (value() - minimum()) / (maximum() - minimum());

		if (val >= 1.0)
		    X = W;
		else if (val <= 0.0)
		    X = 0;
		else
		    X = int (val * W + .5);

		if (event == FL_PUSH) {
		    offcenter = mx - X;
		    if (offcenter < -S / 2)
			offcenter = 0;
		    else if (offcenter > S / 2)
			offcenter = 0;
		    else
			return 1;
		}
		S = 0;
	    } else {
		double val = (value() - minimum()) / (maximum() - minimum());

		if (val >= 1.0)
		    X = W - S;
		else if (val <= 0.0)
		    X = 0;
		else
		    X = int (val * (W - S) + .5);

		if (event == FL_PUSH) {
		    offcenter = mx - X;
		    if (offcenter < 0)
			offcenter = 0;
		    else if (offcenter > S)
			offcenter = S;
		    else
			return 1;
		}
	    }
	    X = mx - offcenter;
	    double v;
	  TRY_AGAIN:
	    if (X < 0) {
		X = 0;
		offcenter = mx;
		if (offcenter < 0)
		    offcenter = 0;
	    } else if (X > (W - S)) {
		X = W - S;
		offcenter = mx - X;
		if (offcenter > S)
		    offcenter = S;
	    }
	    v = round(X * (maximum() - minimum()) / (W - S) + minimum());
	    // make sure a click outside the sliderbar moves it:
	    if (event == FL_PUSH && v == value()) {
		offcenter = S / 2;
		event = FL_DRAG;
		goto TRY_AGAIN;
	    }
	    handle_drag(clamp(v));
	}
	return 1;
    case FL_RELEASE:
	handle_release();
	return 1;
    default:
	return 0;
    }
}

int
NxSlider::handle(int event)
{
    return handle(event,
		  x() + Fl::box_dx(box()),
		  y() + Fl::box_dy(box()),
		  w() - Fl::box_dw(box()), h() - Fl::box_dh(box()));
}

--- NEW FILE: nxradioroundbutton.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include <nxapp.h>
#include <FL/Enumerations.H>
#include <nxradioroundbutton.h>

void
round_draw(int x, int y, int w, int h, Fl_Color c)
{

    Fl_Color bf = NxApp::Instance()->getGlobalColor(APP_SEL);
    fl_color(bf);
    fl_draw_box(FL_ROUNDED_BOX, x + 3, y + 4, w - 10, h - 10, bf);

}

NxRadioRoundButton::NxRadioRoundButton(int x, int y, int w, int h, char *l):
Fl_Radio_Round_Button(x, y, w, h, l)
{

    // Provide the "look-and-feel"
    color(NxApp::Instance()->getGlobalColor(APP_BG));
    selection_color(NxApp::Instance()->getGlobalColor(RADIO_FILL));
    labelcolor(NxApp::Instance()->getGlobalColor(APP_FG));
    NxApp::Instance()->def_font((Fl_Widget *) this);
#ifdef PDA
    Fl::set_boxtype(FL_WHITE_BOX, round_draw, 1, 1, 2, 2);
    box(FL_WHITE_BOX);
#else
    box(FL_NO_BOX);
#endif
    align(FL_ALIGN_INSIDE | FL_ALIGN_LEFT);
    value(0);
}				// end of NxRadioRoundButton::NxRadioRoundButton()

void
NxRadioRoundButton::draw()
{

    if (box())
	draw_box(this == Fl::pushed()? down(box()) : box(), color());

    int d = h() / 6;
    int W = w() < h()? w() : h();

    if (value())
	fl_draw_box(FL_ROUNDED_BOX, x() + d + 2, y() + d + 3, W - 4 * d - 2,
		    W - 4 * d - 2, selection_color());

#ifdef PDA
    labelcolor(labelcolor());
#endif

    draw_label(x() + W - d, y(), w() - W + d, h());
}

--- NEW FILE: nxinput.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include <nxapp.h>
#include <FL/Enumerations.H>
#include <nxinput.h>
#include <stdio.h>

NxInput::NxInput(int x, int y, int w, int h, const char *l):
Fl_Input(x, y, w, h, l)
{

    move = true;

    // Provide the specific "look-and-feel"
    color(NxApp::Instance()->getGlobalColor(APP_BG));
    labelcolor(NxApp::Instance()->getGlobalColor(APP_FG));
    textcolor(NxApp::Instance()->getGlobalColor(APP_FG));
    selection_color(NxApp::Instance()->getGlobalColor(APP_SEL));
    NxApp::Instance()->def_font(this);

#ifdef NANOX
    box(FL_BOTTOM_BOX);
#else
    box(FL_FLAT_BOX);
#endif
    align(FL_ALIGN_LEFT);
    //  when(FL_WHEN_RELEASE_ALWAYS);
    when(FL_WHEN_CHANGED | FL_WHEN_NOT_CHANGED);
    callback(NxApp::Instance()->pasteTarget_callback);
}				// end of NxOutput::NxOutput()

--- NEW FILE: nxmenubar.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include <nxmenubar.h>
#include <nxapp.h>

NxMenuBar::NxMenuBar(int x, int y, int w, int h, Fl_Group * _grp)
    :
Fl_Menu_Bar(x, y, w, h)
{

    color(NxApp::Instance()->getGlobalColor(APP_BG));
    textcolor(NxApp::Instance()->getGlobalColor(APP_FG));
    selection_color(NxApp::Instance()->getGlobalColor(HILIGHT));
    labeltype(FL_NORMAL_LABEL);
    NxApp::Instance()->def_font(this);

    grp = _grp;

}

int
NxMenuBar::handle(int event)
{
    int xoff, yoff;

    const Fl_Menu_Item *v;
    if (menu() && menu()->text)
	switch (event) {
	case FL_ENTER:
	    return 1;
	case FL_LEAVE:
	    this->hide();
	    if (grp)
		grp->show();
	    return 1;
	case FL_PUSH:
	    v = 0;
	  J1:
	    /* JHC - This absolutely does not belong here */
	    /* but I couldn't find any other place to put it */
	    /* Basically - the menu offset needs tobe adjusted */
	    /* to account for the window decorations.  This is */
	    /* the poor man's way of determing the actual position */
	    /* of the window: */

	    xoff = Fl::event_x_root() - Fl::event_x();
	    yoff = Fl::event_y_root() - Fl::event_y();

	    v = menu()->pulldown(x() + xoff, y() + yoff,
				 w(), h(), v, this, 0, 1);
	    picked(v);
	    return 1;
	case FL_SHORTCUT:
	    v = menu()->test_shortcut();
	    if (v) {
		picked(v);
		return 1;
	    }
	    if (visible_r() && (v = menu()->find_shortcut()))
		goto J1;
	    return 0;
	}
    return 0;
}

--- NEW FILE: syncengine.new ---
/* ERROR
   Messages:  ERR
*/

static int state_error(int id, const vector < string > &messages, string &next) {
  ResetSync();  
  return -1;
}

/* OK
   Messages:  RD ET EOT FLIP TS 
*/

static int state_ok(int id, const vector < string > &messages,  string &next) {

  int ret = -1;

  switch(id) {
  case RD:     /* Row Data */
    if (SaveRowData(messages)) {
      next = coder.Ok();
      ret = OK;
    }
    else {
      DoError(SAVE_RD, agent_ipc);
      ResetSync();
    }

    break;

  case ET:
    next = coder.Ok();
    ret = OK;
    break;

  case EOT:
    cur_table = -1;
    next=  coder.Ok();
    ret = OK;
    break;

  case FLIP:
    next = coder.COmmit();
    ret = COMMIT;
    break;
    
  case TS: {
    string t_num = coder.vmessages[cur_table = atoi(t_num.c_str())];
    
    if (CheckTableSchema(coder.vmessages)) {
      next = coder.Info(0);
      ret = INFO;
    } else {
      DoError(BAD_TS, agent_ipc);
      ResetSync();      
    }
  }
    break;
  }

  return ret;
}

/* INFO
   Messages:  RD ET
*/

static int state_info(int id, const vector < string > &messages,  string &next) {
  int ret = -1;

  switch(id) {
  case RD:
    if (SaveRowData(coder.vmessages)) {
      next = coder.Ok();
      ret = OK;
    }
    else {
      DoError(SAVE_RD, agent_ipc);
      ResetSync();
    }
    break;

  case ET:
    next = coder.Ok();
    ret = OK;
    break;

  default:
    DoError(EXP_RD, agent_ipc);
    ResetSync();
  }

  return ret;
}

/* BP
   Messages:  OK
*/

static int state_bp(int id, const vector < string > &messages,  string &next) {

  if (id != OK) {
    DoError(EXP_OK, agent_ipc);
    return -1;
  }

  vector < char >col_type;
  vector < int >col_size;
  
  GetTableSchema(col_type, col_size);
  next = coder.TableSchema(c_db_struct->table_num, col_type, col_size);     
  return TS;
}

/* EP
   Messages:  
*/

static int state_ep(int id, const vector < string > &messages,  string &next) {
  return -1;
}

/* TS
   Messages:  INFO
*/

static int state_ts(int id, const vector < string > &messages,  string &next) {

  int ret = -1;

  if (id != INFO) {
    DoError(EXP_INFO, agent_ipc);
    return ret;
  }

  int flags = -1;
  int i_key = 0;
  vector < string > data;
  string key;
  int sync_type = atoi(coder.vmessages[1].c_str());
  NxDb *db = c_db_struct->db;
  
  switch(sync_type) {
  case MERGE:
    total_rows = db->Select(c_db_struct->str_dbName, rows, 1,
			    false, NxDb::CHANGED | NxDb::DELETED | NxDb::NEW);
    break;
  case PDAOVR:
    total_rows =db->Select(c_db_struct->str_dbName, rows, 1, true);
    break;
    
  case DTOVR:
  default:
    total_rows = 0;
  }
  
  if (!total_rows) {
    ret = ET:
      next = coder.EndTable();
    total_rows = -1;
    cur_row = -1;
  } else {
    ret = RD;
    GetRowData(flags, data, key);
    i_key = atoi(key.c_str());
    next = coder.RowData(flags, i_key, data);
  }

  return ret;
}

/* INFO
   Messages:  OK
*/

static int state_info(int id, const vector < string > &messages,  string &next) {

  int ret = -1;

  if (msg_id != OK) {
    DoError(EXP_OK, agent_ipc);
    ResetSync();
    return -1;
  }

  if (cur_db == (int) v_SyncDB.size()) {	
    next_msg = coder.EndOfTables();
    ret = EOT;
    cur_db = -1;
    total_rows = -1;
  } else {	
    ret = TS;
   
    vector < char >col_type;
    vector < int >col_size;
    
    GetTableSchema(col_type, col_size);
    next = coder.TableSchema(c_db_struct->table_num, col_type, col_size);
  }

  return ret;
}

/* EOT
   Messages:  OK
*/

static int state_eot(int id, const vector < string > &messages,  string &next) {
  if (msg_id != OK) {
    DoError(EXP_OK, agent_ipc);
    ResetSync();
    return -1;
  }
 
  next = coder.Flip();
  return FLIP;
}

/* RD
   Messages:  OK
*/
  
static int state_rd(int id, const vector < string > &messages,  string &next) {

  int ret = -1;
 
  if (msg_id != OK) {
    DoError(EXP_OK, agent_ipc);
    ResetSync();
    return -1;
  }

  if ((cur_row - 1) == total_rows) {
    if (cur_db == (int) v_SyncDB.size()) {
      cur_db = -1;
    }
    
    cur_row = -1;
    total_rows = -1;
    next_msg = coder.EndTable();
    ret = ET;
  } else {	
    int flags = -1;
    int i_key = 0;
    vector < string > data;
    string key;
    
    ret = RD;
    GetRowData(flags, data, key);
    i_key = atoi(key.c_str());
    next_msg = coder.RowData(flags, i_key, data);
  }

  return ret;
}

/* FLIP
   Messages:  TS
*/

static int state_flip(int id, const vector < string > &messages,  string &next) {

  if (id != TS) {
    DoError(EXP_TS, agent_ipc);
    ResetSync();
    return -1;
  }
  
  string t_num = messages[1];
  cur_table = atoi(t_num.c_str());
   
  if (CheckTableSchema(messages)) {
    next = coder.Info(0);
    return INFO;
  }

  DoError(BAD_TS, agent_ipc);
  ResetSync();

  return -1;
}
 
/* COMMIT
   Messages:  OK
*/
     
static int state_commit(int id, const vector < string > &messages,  string &next) {

  if (id == OK) {
    UpdateFlags();
    Refresh();
    
    next = coder.EndPimSync();
    
    /* Inform the sync app that we are done as well */
    Write_Fd(app_ipc, (char *) next.c_str(), next.length());
    Write_Fd(agent_ipc, (char *) next.c_str(), next.length());
  }
  else 
    DoError(EXP_OK, agent_ipc);
    
  ResetSync();
  return -1;
}

static void handle_error(const vector < string > &messages) {
  int code = atoi((char *) messages[1].c_str());
  DoError(code, app_ipc);
  ResetSync();
  return;
}

void NxApp::SendAgentMsg(char *msg) {
  
int NxApp::SetAgents(void) {
  
  if (app_ipc == -1)
    app_ipc = Find_Fd("nxsync");
  
  if (agent_ipc == -1) 
    agent_ipc = Find_Fd("syncagent");
  
  if (agent_ipc < 0) {
    if (app_ipc > 0) 
      DoError(NO_AGENT, app_ipc);      
    else
      printf("ERROR - No application present\n");
    
    ResetSync();
    return -1;
  }

  return 0;
}

void NxApp::SyncEngine(char *message) {

  MsgCoder coder;

  /* Figure out the external applications */

  if (SetAgents() == -1) return;

  /* Decode the incoming message */

  coder.vmessages.clear();
  coder.DecodeMsg(message);

  msg_id = atoi((char *) coder.vmessages[0].c_str());

  if (!ValidMsgId(msg_id)) 
    return;

  /* Step 1 - handle any pending errors */

  if (msg_id == ERR) {
    handle_error(coder.vmessages);
    return;
  }

  /* Step 2 - Get the next database to sync if nessesary */

  if (total_rows == -1) {

    if (!v_syncDb.size()) {
      DoError(NO_DB_REG, app_ipc);
      ResetSync();
      return;
    }
    else {
      cur_db++;
      if (cur_db < (int) v_syncDB.size()) {
	sync_db_struct db_struct = v_SyncDB[cur_db];

	if (!c_db_struct) 
	  c_db_struct = (sync_db_struct *) malloc(sizeof(sync_db_struct));
	
	memcpy(c_db_struct, &db_struct, sizeof(sync_db_struct));
	
	total_rows = 0;
	cur_row = 1;
      }
    }

    /* Step 3 - Handle incoming messages from the sync application */
    
    switch(msg_id) {
    case ABORT:
      ResetSync();
      next = Coder.Err(USER_ABORT);
      break;
      
    case BS:
      if (appSyncState != -1) {
	DoError(UNEXP_ERROR, app_ipc);
	ResetSync();
	return;
      }

      next = coder.BeginPimSync(appName);
      nextSyncState = BP;
      appSyncState = OK;
      break;

    case ES:
    case STATUS:
      return;

    default:
      /* Find the appropriate state handler, and process the incoming message */
      /* The handler will return the new sync state                           */

      for(i = 0; engine[i].state; i++) {
	if (nextSyncState == engine[i].state)
	  nextSyncState = engine[i].handle(msg_id, Coder.vmessages, next);
      }

      if (!engine[i].state) {
	DoError(UNEXP_ERROR, agent_ipc);
	ResetSync();

	return;
      }

      /* Write the message to the sync engine */

      if (appSyncState != -1)
	Write_Fd(agent_ipc, (char *) next.c_str(), next.length());    
      
	
  
  
  

--- NEW FILE: nxapp.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
[...3022 lines suppressed...]
int
getGblParInt(char *cat, char *pref)
{
    int s;
    par_getGlobalPref(par_db, cat, pref, PAR_INT, &s, sizeof(int));
    return s;
}

void
getGblParStr(char *cat, char *pref, char *text, int len)
{
    par_getGlobalPref(par_db, cat, pref, PAR_TEXT, text, len);
}

void 
getDirectory(char *dir, char *text, int size) {
  par_getScreentopDir(par_db, dir, text, size);
}

#endif

--- NEW FILE: nximage.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


/* Derived from FLTK  fltk/src/Fl_Image.cxx */
/* Original copright:  Copyright 1998-1999 by Bill Spitzak and others. */

#include <FL/Fl.H>
#include <FL/fl_draw.H>
#include <FL/x.H>
#include <FL/Fl_Widget.H>
#include <FL/Fl_Menu_Item.H>
#include <nximage.h>

void
NxImage::draw(int XP, int YP, int WP, int HP, int cx, int cy)
{
    // account for current clip region (faster on Irix):
    int X, Y, W, H;
    fl_clip_box(XP, YP, WP, HP, X, Y, W, H);
    cx += X - XP;
    cy += Y - YP;
    // clip the box down to the size of image, quit if empty:
    if (cx < 0) {
	W += cx;
	X -= cx;
	cx = 0;
    }
    if (cx + W > w)
	W = w - cx;
    if (W <= 0)
	return;
    if (cy < 0) {
	H += cy;
	Y -= cy;
	cy = 0;
    }
    if (cy + H > h)
	H = h - cy;
    if (H <= 0)
	return;

    if (!id) {
	id = (ulong) fl_create_offscreen(w, h);
	fl_begin_offscreen((Fl_Offscreen) id);
	fl_draw_image(array, 0, 0, w, h, d, ld);
	fl_end_offscreen();
    }
    fl_copy_offscreen(X, Y, W, H, (Fl_Offscreen) id, cx, cy);
    if (_volatile_data) {
	fl_delete_offscreen((Fl_Offscreen) id);
	id = 0;
    }				// end of if
}

NxImage::~NxImage()
{
    if (id)
	fl_delete_offscreen((Fl_Offscreen) id);
}

static void
image_labeltype(const Fl_Label * o, int x, int y, int w, int h, Fl_Align a)
{
    NxImage *b = (NxImage *) (o->value);
    int cx;

    if (a & FL_ALIGN_LEFT)
	cx = 0;
    else if (a & FL_ALIGN_RIGHT)
	cx = b->w - w;
    else
	cx = (b->w - w) / 2;
    int cy;
    if (a & FL_ALIGN_TOP)
	cy = 0;
    else if (a & FL_ALIGN_BOTTOM)
	cy = b->h - h;
    else
	cy = (b->h - h) / 2;
    b->draw(x, y, w, h, cx, cy);
}

static void
image_measure(const Fl_Label * o, int &w, int &h)
{
    NxImage *b = (NxImage *) (o->value);
    w = b->w;
    h = b->h;
}

void
NxImage::label(Fl_Widget * o)
{
    Fl::set_labeltype(_FL_IMAGE_LABEL, image_labeltype, image_measure);
    o->label(_FL_IMAGE_LABEL, (const char *) this);
}

void
NxImage::label(Fl_Menu_Item * o)
{
    Fl::set_labeltype(_FL_IMAGE_LABEL, image_labeltype, image_measure);
    o->label(_FL_IMAGE_LABEL, (const char *) this);
}

--- NEW FILE: nxmenuadd.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */



// Methods to alter the menu in an NxMenu_ widget.

// These are for Forms emulation and for dynamically changing the
// menus.  They are in this source file so they are not linked in if
// not used, which is what will happen if the the program only uses
// constant menu tables.

// Not at all guaranteed to be Forms compatable, especially with any
// string with a % sign in it!

#include <nxmenu_.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

// If the array is this, we will double-reallocate as necessary:
static NxMenuItem *local_array = 0;
static int local_array_alloc = 0;	// number allocated
static int local_array_size = 0;	// == size(local_array)
extern NxMenu_ *nx_menu_array_owner;	// in NxMenu_.cxx

// For historical reasons there are matching methods that work on a
// user-allocated array of NxMenuItem.  These methods are quite
// depreciated and should not be used.  These old methods use the
// above pointers to detect if the array belongs to an NxMenu_
// widget, and if so it reallocates as necessary.

// Insert a single NxMenuItem into an array of size at offset n,
// if this is local_array it will be reallocated if needed.
static NxMenuItem *
insert(NxMenuItem * array, int size, int n, const char *text, int flags)
{
    if (array == local_array && size >= local_array_alloc) {
	local_array_alloc = 2 * size;
	NxMenuItem *newarray = new NxMenuItem[local_array_alloc];
	memmove(newarray, array, size * sizeof(NxMenuItem));
	delete[]local_array;
	local_array = array = newarray;
    }
    // move all the later items:
    memmove(array + n + 1, array + n, sizeof(NxMenuItem) * (size - n));
    // create the new item:
    NxMenuItem *m = array + n;
    m->text = text ? strdup(text) : 0;
    m->shortcut_ = 0;
    m->callback_ = 0;
    m->user_data_ = 0;
    m->flags = flags;
    m->labeltype_ = m->labelfont_ = m->labelsize_ = m->labelcolor_ = 0;
    return array;
}

// Add an item.  The text is split at '|' characters to automatically
// produce submenus (actually a totally unnecessary feature as you can
// now add submenu titles directly by setting SUBMENU in the flags):
int
NxMenuItem::add(const char *text,
		int shortcut, Fl_Callback * cb, void *data, int flags)
{
    NxMenuItem *array = this;
    NxMenuItem *m = this;
    const char *p;
    char *q;
    char buf[1024];

    int size = array == local_array ? local_array_size : array->size();
    int flags1 = 0;
    char *item;
    for (;;) {			/* do all the supermenus: */

	/* fill in the buf with name, changing \x to x: */
	q = buf;
	for (p = text; *p && *p != '/'; *q++ = *p++)
	    if (*p == '\\')
		p++;
	*q = 0;

	item = buf;
	if (*item == '_') {
	    item++;
	    flags1 = FL_MENU_DIVIDER;
	}
	if (*p != '/')
	    break;		/* not a menu title */
	text = p + 1;		/* point at item title */

	/* find a matching menu title: */
	for (; m->text; m = m->next())
	    if (m->flags & FL_SUBMENU && !strcmp(item, m->text))
		break;

	if (!m->text) {		/* create a new menu */
	    int n = m - array;
	    array = insert(array, size, n, item, FL_SUBMENU | flags1);
	    size++;
	    array = insert(array, size, n + 1, 0, 0);
	    size++;
	    m = array + n;
	}
	m++;			/* go into the submenu */
	flags1 = 0;
    }

    /* find a matching menu item: */
    for (; m->text; m = m->next())
	if (!strcmp(m->text, item))
	    break;

    if (!m->text) {		/* add a new menu item */
	int n = m - array;
	array = insert(array, size, n, item, flags | flags1);
	size++;
	if (flags & FL_SUBMENU) {	// add submenu delimiter
	    array = insert(array, size, n + 1, 0, 0);
	    size++;
	}
	m = array + n;
    }

    /* fill it in */
    m->shortcut_ = shortcut;
    m->callback_ = cb;
    m->user_data_ = data;
    m->flags = flags | flags1;

    if (array == local_array)
	local_array_size = size;
    return m - array;
}

int
NxMenu_::add(const char *t, int s, Fl_Callback * c, void *v, int f)
{
    // make this widget own the local array:
    if (this != nx_menu_array_owner) {
	if (nx_menu_array_owner) {
	    NxMenu_ *o = nx_menu_array_owner;
	    // the previous owner get's its own correctly-sized array:
	    int value_offset = o->value_ - local_array;
	    int n = local_array_size;
	    NxMenuItem *newMenu = o->menu_ = new NxMenuItem[n];
	    memcpy(newMenu, local_array, n * sizeof(NxMenuItem));
	    if (o->value_)
		o->value_ = newMenu + value_offset;
	}
	if (menu_) {
	    // this already has a menu array, use it as the local one:
	    delete[]local_array;
	    if (!alloc)
		copy(menu_);	// duplicate a user-provided static array
	    // add to the menu's current array:
	    local_array_alloc = local_array_size = size();
	    local_array = menu_;
	} else {
	    // start with a blank array:
	    alloc = 2;		// indicates that the strings can be freed
	    if (local_array) {
		menu_ = local_array;
	    } else {
		local_array_alloc = 15;
		local_array = menu_ = new NxMenuItem[local_array_alloc];
	    }
	    menu_[0].text = 0;
	    local_array_size = 1;
	}
	nx_menu_array_owner = this;
    }

    int r = menu_->add(t, s, c, v, f);
    // if it rellocated array we must fix the pointer:
    int value_offset = value_ - menu_;
    menu_ = local_array;	// in case it reallocated it
    if (value_)
	value_ = menu_ + value_offset;
    return r;
}

// This is a Forms (and SGI GL library) compatable add function, it
// adds many menu items, with '|' seperating the menu items, and tab
// seperating the menu item names from an optional shortcut string.
int
NxMenu_::add(const char *str)
{
    char buf[128];
    int r = 0;
    while (*str) {
	int shortcut = 0;
	char *c;
	for (c = buf; *str && *str != '|'; str++) {
	    if (*str == '\t') {
		*c++ = 0;
		shortcut = fl_old_shortcut(str);
	    } else
		*c++ = *str;
	}
	*c = 0;
	r = add(buf, shortcut, 0, 0, 0);
	if (*str)
	    str++;
    }
    return r;
}

void
NxMenu_::replace(int i, const char *str)
{
    if (i < 0 || i >= size())
	return;
    if (!alloc)
	copy(menu_);
    if (alloc > 1) {
	free((void *) menu_[i].text);
	str = strdup(str);
    }
    menu_[i].text = str;
}

void
NxMenu_::remove(int i)
{
    int n = size();
    if (i < 0 || i >= n)
	return;
    if (!alloc)
	copy(menu_);
    if (alloc > 1)
	free((void *) menu_[i].text);
    memmove(&menu_[i], &menu_[i + 1], (n - i) * sizeof(NxMenuItem));
}

--- NEW FILE: Fl_Tree.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include "FL/Fl_Node.H"
#include "FL/Fl_Tree.H"
#include <stdio.h>		// printf
#include <stdlib.h>		// qsort

Fl_Tree::Fl_Tree(int x, int y, int w, int h):
Fl_Widget(x, y, w, h)
{
    first_ = 0;
    top_ = 0;
    top_depth_ = 0;
    damaged_ = 0;
}

void
Fl_Tree::draw_node(int depth, int cy, Fl_Node *)
{
    fl_color(FL_BLACK);
    fl_rectf(x(), cy, depth * 16, 16);
    fl_color(FL_WHITE);
    fl_rectf(x() + depth * 16, cy, w() - depth * 16, 16);
}

Fl_Node *
Fl_Tree::find(int fy, int &depth, int &ry)
{
    int cy = parent()->y() + top_yoffset_;
    int ey = parent()->y() + parent()->h();

    if (fy < cy)
	return 0;

    depth = top_depth_;
    Fl_Node *node = top_;
    traverse_start(top_);

    while (cy < ey && node) {
	ry = cy;
	cy += height(node);
	if (cy > fy)
	    return node;
	node = traverse_forward(1, depth);
    }
    return 0;
}

void
Fl_Tree::update_height(void)
{
    resize(x(), y(), w(), total_height(first_));
}

void
Fl_Tree::draw(void)
{

    update_top();

    int cy = parent()->y() + top_yoffset_;
    int ey = parent()->y() + parent()->h();
    int depth = top_depth_;
    Fl_Node *node = top_;
    int drawing = 0;
    if (damage() == FL_DAMAGE_ALL)
	drawing = 1;
    if (damage() == FL_DAMAGE_CHILD && damaged_ == 0)
	drawing = 1;
    while (cy < ey && node) {
	if (damaged_ == node) {
	    if (damage() == FL_DAMAGE_CHILD) {
		draw_node(depth, cy, node);
		return;
	    }
	    drawing = 1;
	}
	if (drawing)
	    draw_node(depth, cy, node);
	cy += height(node);
	if (node->vsub_) {
	    //printf("has sub\n");
	    node = node->vsub_;
	    depth++;
	} else if (node->next_) {
	    //printf("has no sub\n");
	    node = node->next_;
	} else {
	    while (node && !node->next_) {
		node = node->up_;
		depth--;
	    }
	    if (node)
		node = node->next_;
	}
    }
    fl_color(parent()->color());
    fl_rectf(x(), cy, w(), ey - cy);
}

int (*s_node_compare_) (Fl_Node *, Fl_Node *) = 0;

int
Fl_Tree::s_compare_(void *a, void *b)
{
    Fl_Node *nodeA = *(Fl_Node **) a;
    Fl_Node *nodeB = *(Fl_Node **) b;
    return s_node_compare_(nodeA, nodeB);
}

int
Fl_Tree::s_compare_reverse_(void *a, void *b)
{
    Fl_Node *nodeA = *(Fl_Node **) a;
    Fl_Node *nodeB = *(Fl_Node **) b;
    return -s_node_compare_(nodeA, nodeB);
}

Fl_Node *
Fl_Tree::sort_(Fl_Node * start, int (*compar) (Fl_Node *, Fl_Node *),
	       int down, tree_sort_order order)
{
    int i;
    Fl_Node *node;

    i = 0;
    node = start;

    while (node) {
	node = node->next_;
	i++;
    }
    Fl_Node **array = new Fl_Node *[i];

    i = 0;
    node = start;
    while (node) {
	array[i] = node;
	node = node->next_;
	i++;
    }
    s_node_compare_ = compar;

    if (order == TREE_REVERSE_SORT) {
	qsort(array, i, sizeof(Fl_Node *),
	      (int (*)(const void *, const void *)) s_compare_reverse_);
    } else {
	qsort(array, i, sizeof(Fl_Node *),
	      (int (*)(const void *, const void *)) s_compare_);
    }

    start = array[0];
    int j = 1;
    node = start;
    node->prev_ = 0;		//james
    while (j < i) {
	node->next_ = array[j];
	node->next_->prev_ = node;
	node = node->next_;
	j++;
    }
    node->next_ = 0;

    if (down) {
	node = start;
	while (node) {
	    if (node->sub_)
		node->sub_ = sort_tree(node->sub_, compar, order);
	    if (node->vsub_)
		node->vsub_ = node->sub_;
	    node = node->next_;
	}
    }

    delete[]array;

    return start;
}

Fl_Node *
Fl_Tree::sort(Fl_Node * start, int (*compar) (Fl_Node *, Fl_Node *),
	      tree_sort_order order)
{
    if (first_)
	return sort_(start, compar, 0, order);
    return 0;
}

Fl_Node *
Fl_Tree::sort_tree(Fl_Node * start, int (*compar) (Fl_Node *, Fl_Node *),
		   tree_sort_order order)
{
    if (first_)
	return sort_(start, compar, 1, order);
    return 0;
}

void
Fl_Tree::sort(int (*compar) (Fl_Node *, Fl_Node *), tree_sort_order order)
{
    if (first_)
	first_ = top_ = sort(first_, compar, order);
}

void
Fl_Tree::sort_tree(int (*compar) (Fl_Node *, Fl_Node *),
		   tree_sort_order order)
{
    if (first_)
	first_ = top_ = sort_tree(first_, compar, order);
}

void
Fl_Tree::update_top(void)
{
    Fl_Node *node = first_;
    int py = parent()->y();
    int ly = y();
    int h = 0;
    int depth = 0;

    while (node && ly + (h = height(node)) <= py) {
	ly += h;
	if (node->vsub_) {
	    node = node->vsub_;
	    depth++;
	} else if (node->next_) {
	    node = node->next_;
	} else {
	    while (node && !node->next_) {
		node = node->up_;
		depth--;
	    }
	    if (node)
		node = node->next_;
	}
    }

    top_ = node;
    top_depth_ = depth;
    top_yoffset_ = ly - py;
}

int
Fl_Tree::total_height(Fl_Node * node)
{
    int ret = 0;
    int depth = 1;
    while (node) {
	ret += height(node);
	if (node->vsub_) {
	    node = node->vsub_;
	    depth++;
	} else if (node->next_) {
	    node = node->next_;
	} else {
	    while (node && !node->next_) {
		node = node->up_;
		depth--;
		if (depth <= 0)
		    node = 0;
	    }
	    if (node)
		node = node->next_;
	}
    }
    return ret;
}

int
Fl_Tree::height(Fl_Node *)
{
    return 17;
}

Fl_Node *
Fl_Tree::traverse_start()
{
    t_current_ = first_;
    return t_current_;
}

void
Fl_Tree::traverse_start(Fl_Node * a)
{
    t_current_ = a;
}

void
Fl_Tree::traverse_up(void)
{
    if (t_current_ && t_current_->up_)
	t_current_ = t_current_->up_;
}


Fl_Node *
Fl_Tree::traverse_forward(int visible, int &depth)
{

    if (visible) {
	if (t_current_ && t_current_->vsub_ != 0) {
	    t_current_ = t_current_->vsub_;
	    depth++;
	    return t_current_;
	}
    } else {
	if (t_current_ && t_current_->sub_ != 0) {
	    t_current_ = t_current_->sub_;
	    depth++;
	    return t_current_;
	}
    }

    if (t_current_ && t_current_->next_ != 0) {
	t_current_ = t_current_->next_;
	return t_current_;
    }

    while (t_current_ && !t_current_->next_) {
	t_current_ = t_current_->up_;
	depth--;
    }
    if (t_current_)
	t_current_ = t_current_->next_;

    return t_current_;
}

Fl_Node *
Fl_Tree::traverse_forward()
{
    int d;
    return traverse_forward(0, d);
}

Fl_Node *
Fl_Tree::traverse_backward()
{
    if (t_current_ && t_current_->prev_) {
	t_current_ = t_current_->prev_;
	while (t_current_->sub_) {
	    t_current_ = t_current_->sub_;
	    while (t_current_->next_) {
		t_current_ = t_current_->next_;
		if (t_current_->next_ == 0 && t_current_->sub_) {
		    t_current_ = t_current_->sub_;
		}
	    }
	}
    } else {
	t_current_ = t_current_->up_;
    }
    return t_current_;
}

void
Fl_Tree::add_next(Fl_Node * node)
{
    if (!first_) {
	first_ = node;
	t_current_ = node;
    } else {
	if (t_current_ == 0)
	    t_current_ = first_;
	while (t_current_->next_)
	    t_current_ = t_current_->next_;
	node->next_ = t_current_->next_;
	if (t_current_->next_) {
	    t_current_->next_->prev_ = node;
	}
	t_current_->next_ = node;
	node->prev_ = t_current_;
	node->up_ = t_current_->up_;
	t_current_ = node;
    }

    update_height();
    parent()->damage(FL_DAMAGE_CHILD);
    redraw();
}

void
Fl_Tree::add_sub(Fl_Node * node)
{
    Fl_Node *tmp;

    if (!first_) {
	first_ = node;
	t_current_ = node;
    } else {
	if (t_current_ == 0)
	    t_current_ = first_;
	tmp = t_current_->sub_;
	if (tmp)
	    while (tmp->next_)
		tmp = tmp->next_;
	node->next_ = 0;

	if (tmp)
	    tmp->next_ = node;
	node->prev_ = tmp;
	if (!tmp)
	    t_current_->sub_ = node;

	if (!tmp && (t_current_->opened_))
	    t_current_->vsub_ = node;

	node->up_ = t_current_;
	t_current_ = node;
    }

    update_height();
    parent()->damage(FL_DAMAGE_CHILD);
    redraw();
}

int
Fl_Tree::remove(Fl_Node * a)
{
    Fl_Node *temp = a->sub_;

    while (temp != 0) {		// Remove all children
	remove(temp);
	temp = a->sub_;
    }

    if (a->prev_) {
	a->prev_->next_ = a->next_;
	if (a->next_)
	    a->next_->prev_ = a->prev_;
    } else if (a->up_) {
	Fl_Node *o = a->up_;
	o->sub_ = a->next_;
	if (o->opened_)
	    o->vsub_ = a->next_;
	else
	    o->vsub_ = 0;

	if (a->next_) {
	    a->next_->up_ = o;
	    a->next_->prev_ = a->prev_;
	}
    }

    if (a == first_) {
	if (a->next_) {
	    first_ = a->next_;
	    first_->up_ = 0;
	    first_->prev_ = 0;
	} else {
	    first_ = 0;
	    top_ = 0;
	}
    }

    if (a == current_) {
	if (a->up_)
	    current_ = a->up_;
	else if (a->prev_)
	    current_ = a->prev_;
	else
	    current_ = 0;
    }

    if (a == t_current_) {
	if (a->up_)
	    t_current_ = a->up_;
	else if (a->prev_)
	    t_current_ = a->prev_;
	else
	    t_current_ = 0;
    }

    update_height();
    parent()->damage(FL_DAMAGE_CHILD);
    redraw();

    delete a;
    a = 0;

    return 1;
}

int
Fl_Tree::clear()
{
    return remove(first_);
}

int
Fl_Tree::close(Fl_Node * node)
{
    int th = total_height(node->vsub_);
    node->opened_ = 0;
    node->vsub_ = 0;
    return th;
}

int
Fl_Tree::open(Fl_Node * node)
{
    node->vsub_ = node->sub_;
    int th = total_height(node->vsub_);
    node->opened_ = 1;
    return th;
}

--- NEW FILE: Fl_Editor.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
[...1358 lines suppressed...]
}

FL_API void
Fl_Editor::SyncDisplay()
{
    if (engine->CursorRow() < StartLine)
	StartLine = engine->CursorRow();
    if (engine->CursorRow() >= StartLine + VisibleLines)
	StartLine = engine->CursorRow() - (VisibleLines - 1);
    damage(DAMAGE_EDITOR);
}

FL_API void
Fl_Editor::browse(bool setit)
{
    Browsemode = setit;
    Readonly = setit;
    HideCursor(setit);
    damage(DAMAGE_LINE);
};

--- NEW FILE: Flv_Table_Child.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


/* derived from Flv_List.cxx from the FLEK tookit */
/* Original copyright:  Copyright (C) 1999 Laurence Charlton */
/* Licenced under the LGPL */

#include <FL/Flv_Table_Child.H>

#include "nxapp.h"
#include <iostream>

Flv_Table_Child::Flv_Table_Child(int X, int Y, int W, int H, const char *l,
				 int _col0, int _col1, int _col2, int _col3):
Flv_Table(X, Y, W, H, l)
{
    move = true;
    save_h = H;
    numRows = 0;
    numCols = 0;
    lastNumRecs = 0;
    val = 0;
    col0 = _col0;
    col1 = _col1;
    col2 = _col2;
    col3 = _col3;
    has_scrollbar(FLVS_VERTICAL);
    feature(FLVF_ROW_SELECT);
    global_style.align(FL_ALIGN_LEFT);	//      Left alignment
    global_style.height(15);

    // Global App Colors
    global_style.foreground(NxApp::Instance()->getGlobalColor(APP_FG));
    global_style.background(NxApp::Instance()->getGlobalColor(HILIGHT_LITE));
    hilight_dark = NxApp::Instance()->getGlobalColor(HILIGHT_DARK);
    scrollbar.color(NxApp::Instance()->getGlobalColor(SCROLL_TRAY));
    scrollbar.selection_color(NxApp::Instance()->getGlobalColor(SCROLL_FACE));
    hscrollbar.color(NxApp::Instance()->getGlobalColor(SCROLL_TRAY));
    hscrollbar.selection_color(NxApp::Instance()->
			       getGlobalColor(SCROLL_FACE));
    images = 0;
}

Flv_Table_Child::~Flv_Table_Child()
{
    if (node) {
	delete[]node;
	node = 0;
    }

    if (val) {
	delete[]val;
	val = 0;
    }

    node_image *next_image = images->next;
    node_image *last_image = 0;

    while (next_image) {

	last_image = next_image;
	next_image = next_image->next;
	delete last_image;

    }

    delete images;

}

//
// Image Management
//

void
Flv_Table_Child::_set_image(Fl_Pixmap * image, int R, int C, int id)
{

    if (!images) {

	images = new node_image;
	images->id = id;
	images->R = R;
	images->C = C;
	images->image_data = image;
	images->next = 0;

    } else {

	node_image *next_image = images;

	while (next_image) {
	    next_image = next_image->next;
	}

	next_image = new node_image;
	next_image->id = id;
	next_image->image_data = image;
	next_image->next = 0;

    }

}

void
Flv_Table_Child::set_image(Fl_Pixmap * image, int R, int C, int id)
{
    _set_image(image, R, C, id);
}

Fl_Pixmap *
Flv_Table_Child::get_image(int id)
{

    node_image *next_image = images;

    while (next_image) {

	if (next_image->id == id)
	    return next_image->image_data;

	next_image = next_image->next;

    }

    return 0;

}

int
Flv_Table_Child::find_image(int R, int C)
{

    node_image *next_image = images;

    while (next_image) {

	// Row and Col
	if ((next_image->R == R) && (next_image->C == C))
	    return next_image->id;
	// Col
	if (next_image->C == C)
	    return next_image->id;
	// Row
	if (next_image->R == R)
	    return next_image->id;

	next_image = next_image->next;

    }

    return 0;

}

char *
Flv_Table_Child::get_value(int R, int C, int &image)
{

    image = find_image(R, C);
    return val[R].col[C]._data;
}

void
Flv_Table_Child::set_value(int R, int C, char *data)
{

    strcpy(val[R].col[C]._data, data);

}

void
Flv_Table_Child::Init(int numRecs)
{

    //
    // node_data
    //

    delete[]node;
    node = 0;

    node = new node_data[numRecs];

    //
    // table_row
    //

    if (val) {

	for (int r = 0; r < lastNumRecs; r++)

	    for (int c = 0; c < numCols; c++) {

		delete[]val[r].col[c]._data;
		val[r].col[c]._data = 0;

	    }


	delete[]val;
	val = 0;

    }

    val = new table_row[numRecs];
    lastNumRecs = numRecs;

    for (int r = 0; r < numRecs; r++) {

	val[r].col = new col_data[numCols];

	for (int c = 0; c < numCols; c++) {

	    val[r].col[c]._data = new char[255];

	}

    }

    numRows = numRecs;

}

void
Flv_Table_Child::Add(int row, void *data)
{

    node[row].data = data;

}

void *
Flv_Table_Child::data(int row)
{
    return node[row].data;
}

void *
Flv_Table_Child::selected()
{

    int curRow = row();

    if (rows())
	return node[curRow].data;
    else
	return 0;

}

//      Note: This is so flexible, you don't *have* to use style
//      if you'd rather program the conditions...
void
Flv_Table_Child::get_style(Flv_Style & s, int R, int C)
{
    const char *st;
    int pixmap = 0;

    Flv_Table::get_style(s, R, C);	//       Get standard style

    if (R < 0)			//   Heading/Footing is bold
	s.font((Fl_Font) (s.font() + FL_BOLD));

    if (R == -2)		// Row footer exception
    {
	s.background(FL_BLACK);	//      Black background
	s.foreground(FL_WHITE);	//      White text
	s.frame(FL_FLAT_BOX);	//      No box
	s.align(FL_ALIGN_RIGHT);	//      Right aligned
    }

    if (R > -1 && C > -1 && (R % 2) == 0 && C < 4)	//      Highlight every other row
	s.background(hilight_dark);

    st = get_value(R, C, pixmap);

    if (st)
	if (strstr(st, "-$"))	//     Negative $ are RED
	{
	    s.border(FLVB_OUTER_ALL);	// Nice dark box
	    s.foreground(FL_RED);	// Text in red
	    s.background(Fl_Color(215));	// Pale yellow background
	}

}

#define SZ 5

void
Flv_Table_Child::draw_cell(int Offset, int &X, int &Y, int &W, int &H, int R,
			   int C)
{
    Flv_Style s;

    get_style(s, R, C);
    Flv_Table::draw_cell(Offset, X, Y, W, H, R, C);

    int pixmap = 0;
    char *value = get_value(R, C, pixmap);

    int sX;
    if (pixmap) {
	(get_image(pixmap))->draw(X, Y - 1);
	sX = X + Offset + 25;
    } else {
	sX = X - Offset;
    }

    fl_draw(value, sX, Y, W, H, s.align());

}

int
Flv_Table_Child::text_width()
{
    int scrollbar_width = (scrollbar.visible()? scrollbar.w() : 0);
    int W = w() - scrollbar_width - 1;

    return W;
}

static int cw[10];		//      Column width
//      Another way would be to override handle for FL_SIZE.  We could also
//      spend a lot of time setting styles for the columns and returning
//      that, but since we're calculating it anyway, why bother.
int
Flv_Table_Child::col_width(int C)
{

    static int LW = -1;
    int scrollbar_width = (scrollbar.visible()? scrollbar.w() : 0);
    int W = w() - scrollbar_width - 1;
    int ww, t;

    //    Either always calculate or be sure to check that width
    //    hasn't changed.
    if (W != LW)		//      Width change, recalculate
    {
	cw[0] = (W * col0) / 100;	//      30              Name
	cw[1] = (W * col1) / 100;	//      10              Gender
	cw[2] = (W * col2) / 100;
	cw[3] = (W * col3) / 100;

	for (ww = 0, t = 0; t < 4; t++) {
	    ww += cw[t];
	}
	cw[4] = W - ww - 1;	//        ~30% +/- previous rounding errors
	LW = W;
    }

    return cw[C];

}

--- NEW FILE: nxtminput.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


/* System header files */
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


/* Local header files */
#include "nxtminput.h"
#include <FL/fl_draw.H>
#include <FL/Fl.H>

//-------------------------------------------------------------------------------
//
//      Class NxTmUnit definition (implementation)
//
//-------------------------------------------------------------------------------

/*******************************************************************************\
**
**	Function:	int NxTmUnit::handle()
**	Desc:		Event handler for this class (Overrides the Fl_Input::handle()
**				function.
**	Accepts:	int event = Event to handle
**	Returns:	int; non-zero if event was handled, 0 otherwise.
**
\*******************************************************************************/
int
NxTmUnit::handle(int event)
{
    int c,			// The current character
      mod = 0,			// If the widget was modified
      unit_idx;			// Unit index

    switch (event) {
    case FL_KEYBOARD:
	switch (c = Fl::event_key()) {
	case FL_BackSpace:
	    // handle the backspace
	    for (unit_idx = 0; unit_idx < parent->GetUnits(); unit_idx++) {
		if (this == parent->Units[unit_idx])
		    break;
	    }			// end of for
	    if (unit_idx)
		unit_idx--;
	    if (position() == 0) {
		parent->Units[unit_idx]->take_focus();
		int len = strlen(parent->Units[unit_idx]->value());
		parent->Units[unit_idx]->position(len);
		mod = 1;
	    }			// end of if
	    else
		return (Fl_Input::handle(event));
	    break;
	default:
	    // Get the correct widget
	    for (unit_idx = 0; unit_idx < parent->GetUnits(); unit_idx++)
		if (this == parent->Units[unit_idx])
		    break;

	    if (c >= 0x30 && c <= 0x39) {
		char tmpbuf[3] = { '\0' };
		char buf[3] = { '\0' };

		sprintf(tmpbuf, "%d", max_val[unit_idx]);
		strcpy(buf, value());
		// Determine if we are in selection mode, and if so, overwrite the buffer
//                                              if (mark() != position())
//                                              {
//                                                      // Remove the selection
//                                                      position(mark());
//                                                      buf[0] = buf[1] = '0';  
//                                              } // end of if
//                                              if (position() == 0)
//                                              {
//                                                      // New text.....
//                                                      buf[1] = (char) c;
//                                              } // end of if 
//                                              else if (position() == 2)
//                                              {
		if (buf[1])
		    buf[0] = buf[1];
		else
		    buf[0] = '0';
		buf[1] = (char) c;

		// This can never be a valid 10's digit
		if ((buf[0] > tmpbuf[0]) || atoi(buf) > atoi(tmpbuf))
		    buf[0] = '0';
//                                              } // end of else if 
		value(buf);
		if (when() & FL_WHEN_CHANGED)
		    do_callback();
		else
		    set_changed();
	    }			// end of if
	    else if (c >= FL_Button) {
		return (Fl_Input::handle(event));
	    }			// end of else-if
	    else {
		// Ignore the non-numeric key...
		return (0);
	    }			// end of else
	    break;
	}			// end of switch
	break;
    default:
	// Let the Fl_Input::handle() handler have a go...
	return (Fl_Input::handle(event));
    }				// end of switch

    // Return whether we have taken the character or not....
    return (1);
}				// end of NxTmUnit::handle(int)

//-------------------------------------------------------------------------------
//
//      Class NxTmInput definition (implementation)
//
//-------------------------------------------------------------------------------

/*******************************************************************************\
**
**	Function:	void NxTmInput::draw()
**	Desc:		Handles the drawing for the over all input box
**	Accepts:	Nothing (void)
**	Returns:	Nothing (void)
**	
\*******************************************************************************/
void
NxTmInput::draw(void)
{
    int iwid, owid, x1 = x(), y1 = y(), w1 = w(), h1 = h(), xpos = 0;

    owid = (w1 / MAX_UNITS) / 3;
    iwid = owid * 2;

    if (damage() & (FL_DAMAGE_EXPOSE | FL_DAMAGE_ALL)) {
	Fl_Color c;

	c = NxApp::Instance()->getGlobalColor(APP_BG);
	draw_box(FL_FLAT_BOX, x(), y(), w(), h(), c);
	align(FL_ALIGN_RIGHT);
	for (int idx = 0; idx < _nunits; idx++) {
//                      Units[idx]->resize(x1+xpos+2, y1+2, w1/3-4, h1-4);
	    Units[idx]->box(FL_FLAT_BOX);
	    Units[idx]->align(FL_ALIGN_CENTER);
	    Units[idx]->draw();
	    xpos += w1 / 3;
	}			// end of for
	xpos = x1;


	// Draw the colon
	xpos = x1;
	for (int jdx = 0; jdx < _nunits; jdx++) {
	    if (jdx < 2) {
		xpos = Units[jdx]->x() + Units[jdx]->w();
#ifdef NANOX
		draw_box(FL_BLACK_BOX, xpos, y1 + h1 - 7, 4, 4, FL_BLACK);
		draw_box(FL_BLACK_BOX, xpos, y1 + h1 - 13, 4, 4, FL_BLACK);
#else
		draw_box(FL_FLAT_BOX, xpos, y1 + h1 - 7, 4, 4, FL_BLACK);
		draw_box(FL_FLAT_BOX, xpos, y1 + h1 - 13, 4, 4, FL_BLACK);
#endif
		xpos += owid;
	    }			// end of if
	}			// end of for 
    }				//end of if

    return;
}				// end of NxTmInput::draw(void)

/*******************************************************************************\
**
**	Function:	char *GetTime(void)
**	Desc:		Gets the time as entered in this widget in the format of
**				HH:MM:SS:[AP]M (assuming that all four input widgets are in use)
**	Accepts:	Nothing (void)
**	Returns:	char * (what is contained in _tmstring)
**
\*******************************************************************************/
char *
NxTmInput::GetTime(void)
{
    if (_nunits == 3) {
	// Only hour/minute/second
	sprintf(_tmstring, "%2.2s:%2.2s:%2.2s", Units[0]->value(),
		Units[1]->value(), Units[2]->value());
    }				// end of if
    else {
	// Hour/Minute/second/am or pm
	sprintf(_tmstring, "%2.2s:%2.2s:%2.2s %2.2s", Units[0]->value(),
		Units[1]->value(), Units[2]->value(), Units[3]->value());
    }				// end of else

    return (_tmstring);
}				// end of NxTmInput::GetTime(void)

/*******************************************************************************\
**
**	Function:	void GetTime(struct tm *)
**	Desc:		Gets the time as stored in the widget set, and properly converts it
**				into a struct tm.
**	Accepts:	struct tm *tptr = Ptr to the tm struct
**	Returns:	Nothing (void)
**
\*******************************************************************************/
void
NxTmInput::GetTime(struct tm *tptr)
{
    int idx = 0;		// Index

    if (tptr == NULL)
	return;

    // Get the time
    tptr->tm_hour = atoi(Units[idx++]->value());
    tptr->tm_min = atoi(Units[idx++]->value());
    tptr->tm_sec = atoi(Units[idx++]->value());

    if (_nunits == 4) {
	if (!memcmp(Units[idx]->value(), "PM", 2)) {
	    if (tptr->tm_hour < 12)
		tptr->tm_hour += 12;
	}			// end of if
    }				// end of if

    return;
}				// end of NxTmInput::GetTime(struct tm *)

/*******************************************************************************\
**
**	Function:	void SetUnits()
**	Desc:		Sets the value of _nunits to what is desired (if units are
**				3 then a 24 hour clock is assumed
**	Accepts:	int num = number of units to use
**	Returns:	Nothing (void)
**
\*******************************************************************************/
void
NxTmInput::SetUnits(int num)
{
    // Validate the incoming argument
    if (num <= MAX_UNITS && num > 0)
	_nunits = num;
    else
	_nunits = 4;

    // Activate the used ones and deactivate the unused....
    for (int i = 0; i < MAX_UNITS; i++) {
	if (i < _nunits)
	    Units[i]->activate();
	else
	    Units[i]->deactivate();
    }				// end of for


    return;
}				// end of NxTmInput::SetUnits(int)

/*******************************************************************************\
**
**	Function:	void SetTime(char *)
**	Desc:		Sets the time according to a time string (in format HH:MM:SS AM/PM)
**	Accepts:	char *tmstr = Time string
**	Returns:	Nothing (void)
**
\*******************************************************************************/
void
NxTmInput::SetTime(char *tmstr)
{
    char *cp,			// Character pointer
     *cpdup;
    int nelem;			// Number of time elements

    if (tmstr == NULL || *tmstr == 0)
	return;

    cpdup = strdup(tmstr);

    // Parse the string into a vector-like entity
    for (nelem = 1, cp = cpdup; *cp; cp++) {
	if (*cp == ':' || *cp == ' ') {
	    *cp = '\0';
	    nelem++;
	}			// end of if 
    }				// end of for

    cp = cpdup;
    for (int i = 0; i < nelem; cp += strlen(cp) + 1, i++)
	Units[i]->value(cp);

    free(cpdup);
    // Redraw this widget
    redraw();
    return;
}				// end of NxTmInput::SetTime(char *)

/*******************************************************************************\
**
**	Function:	void SetTime(struct tm *)
**	Desc:		Sets the time (in the widget) according to the tm struct values
**	Accepts:	struct tm *tptr = Ptr to a time value
**	Returns:	Nothing (void)
**
\*******************************************************************************/
void
NxTmInput::SetTime(struct tm *tptr)
{
    char tmbuf[2 + 1] = { '\0' };	// Time buffer
    int hour;			// Potentially modified hour value

    if (tptr == NULL)
	return;

    // Convert the hour
    hour = tptr->tm_hour;
    if (_nunits == 4) {
	// There is an am/pm designation
	if (hour > 12)
	    hour -= 12;
	if (hour == 0)
	    hour = 12;
    }				// end of if
    sprintf(tmbuf, "%2.2d", hour);
    Units[0]->value(tmbuf);
    sprintf(tmbuf, "%2.2d", tptr->tm_min);
    Units[1]->value(tmbuf);
    sprintf(tmbuf, "%2.2d", tptr->tm_sec);
    Units[2]->value(tmbuf);

#if 0
    if (_nunits == 4) {
	Units[3]->value(dayzn[tptr->tm_hour > 12]);
    }				// end of if
#endif

    return;
}				// end of NxTmInput::SetTime(struct tm *)

/*******************************************************************************\
**
**	Function:	void hide()
**	Desc:		Hides this widget (and all children widgets)
**	Accepts:	Nothing (void)
**	Returns:	Nothing (void)
**
\*******************************************************************************/
void
NxTmInput::hide(void)
{
    for (int idx = 0; idx < _nunits; idx++) {
	Units[idx]->hide();
	Units[idx]->redraw();
    }				// end of for

    return;
}				// end of NxTmInput::hide(void)

/*******************************************************************************\
**
**	Function:	void show()
**	Desc:		Shows this widget (and all children widgets)
**	Accepts:	Nothing (void)
**	Returns:	Nothing (void)
**
\*******************************************************************************/
void
NxTmInput::show(void)
{
    for (int idx = 0; idx < _nunits; idx++) {
	Units[idx]->show();
	Units[idx]->redraw();
    }				// end of for

    return;
}				// end of NxTmInput::show(void)

/*******************************************************************************\
**
**	Function:	NxTmInput()
**	Desc:		Default constructor for the NxTmInput() class
**	Accepts:	int x = X component (passed along)
**				int y = Y component (passed along)
**				int w = W component (passed along)
**				int h = H component (passed along)
**				int l = Label (passed along)
**	Returns:	N/A
**
\*******************************************************************************/
NxTmInput::NxTmInput(int x, int y, int w, int h, char *l, int nfld):
Fl_Widget(x, y, w, h, l)
{
    int iwidth, owidth;

    _nunits = nfld;

    owidth = (int) fl_width(":");
    iwidth = (int) fl_width("444") + 5;

    for (int idx = 0; idx < MAX_UNITS; idx++) {
	Units[idx] =
	    new NxTmUnit(x + (idx * (owidth + iwidth)), y, iwidth, h, "");
	Units[idx]->NxTmUnit::SetParent(this);
	Units[idx]->align(FL_ALIGN_RIGHT);
	Units[idx]->maximum_size(2);
	if (idx >= _nunits) {
	    Units[idx]->deactivate();
	    Units[idx]->hide();
	}			// end of if

    }				// end of for

    memset(_tmstring, 0, sizeof(_tmstring));
}				// end of NxTmInput::NxTmInput(int, int, int, int, char *)

--- NEW FILE: nxmenubutton.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include <nxapp.h>
#include <FL/Enumerations.H>
#include <nxmenubutton.h>

#define ARROW_BUTTON_W 13
#define ARROW_BUTTON_H 10

NxMenuButton::NxMenuButton(int x, int y, int w, int h, char *l,
			   int scroll_size):
NxMenu_(x, y, w, h, l)
{

    move = false;
    scrollsize = scroll_size;

    // Provide the "look-and-feel"
    color(NxApp::Instance()->getGlobalColor(BUTTON_FACE));
    selection_color(NxApp::Instance()->getGlobalColor(HILIGHT));
    labelcolor(NxApp::Instance()->getGlobalColor(APP_FG));
    textcolor(NxApp::Instance()->getGlobalColor(APP_FG));
    box(FL_SHADOW_BOX);
    down_box(FL_NO_BOX);
    align(FL_ALIGN_INSIDE | FL_ALIGN_LEFT);
    NxApp::Instance()->def_font(this);

    textfont(DEFAULT_TEXT_FONT);
    textsize(DEFAULT_TEXT_SIZE);

    value(0);
}				// end of NxMenuButton::NxMenuButton()

const NxMenuItem *
NxMenuButton::popup()
{
    const NxMenuItem *m = NULL;

    Fl_Color c = color();
    const NxMenuItem *p = menu();
    int val_ = -1;
    bool text_flag = false;

    if (!text() || 0 > value()) {
	for (int idx = 0; idx < size() - 1; idx++) {
	    if (0 == strcmp(label(), p[idx].label())) {
		text_flag = true;
		value(idx);
		break;
	    }
	}
    } else
	text_flag = true;

    if (text_flag) {
	for (int idx = 0; idx < size() - 1; idx++) {
	    if (p[idx].label()) {
		if (0 == strcmp(p[idx].label(), text())) {
		    val_ = idx;
		    break;
		}
	    }
	}
    }

    if (!box() || type()) {
	color(NxApp::Instance()->getGlobalColor(APP_BG));
	if (-1 == val_)
	    m = menu()->popup(Fl::event_x(), Fl::event_y(), scrollsize,
			      label(), mvalue(), this);
	else
	    m = menu()->popup(Fl::event_x(), Fl::event_y(), scrollsize,
			      label(), &p[val_], this);
    } else {
	color(NxApp::Instance()->getGlobalColor(APP_BG));
	if (-1 == val_)
	    m = menu()->pulldown(x(), y(), w(), h(), scrollsize, 0, this);
	else
	    m = menu()->pulldown(x(), y() + (val_ * h()) + (val_ * 2) + h(),
				 w(), h(), scrollsize, &p[val_], this);
    }

    color(c);

    picked(m);
    return m;
}

// Murphy
const NxMenuItem *
NxMenuButton::popup(int xx, int yy)
{
    const NxMenuItem *m;

    Fl_Color c = color();

    if (!box() || type()) {
	color(NxApp::Instance()->getGlobalColor(APP_BG));
	m = menu()->popup(xx, yy, scrollsize, label(), mvalue(), this);
    } else {
	color(NxApp::Instance()->getGlobalColor(APP_BG));
	m = menu()->pulldown(x(), y(), w(), h(), scrollsize, 0, this);
    }

    color(c);

    picked(m);
    return m;
}

int
NxMenuButton::handle(int e)
{
    if (!menu() || !menu()->text)
	return 0;
    switch (e) {
    case FL_ENTER:
    case FL_LEAVE:
	return (box() && !type())? 1 : 0;
    case FL_PUSH:
	if (!box()) {
	    if (Fl::event_button() != 3)
		return 0;
	} else if (type()) {
	    if (!(type() & (1 << (Fl::event_button() - 1))))
		return 0;
	}
	popup();
	return 1;
    case FL_SHORTCUT:
	if (Fl_Widget::test_shortcut()) {
	    popup();
	    return 1;
	}
	return test_shortcut() != 0;
    default:
	return 0;
    }
}

void
NxMenuButton::draw()
{

    if (!box() || type())
	return;

    int _x = x() + w();
    int _y = y() + h();

    // Added because the labels were getting written on top of each other ---
    // if this is not the correct fix, feel free to implement the correct solution
    fl_color(NxApp::Instance()->getGlobalColor(APP_BG));
    fl_rectf(x(), y(), w(), h());

    Fl_Color c = fl_color();

    fl_color(color());
    fl_line(x(), _y, _x, _y);

    fl_rectf(_x - ARROW_BUTTON_W + 1,
	     _y - ARROW_BUTTON_H + 1, ARROW_BUTTON_W, ARROW_BUTTON_H - 1);

    fl_line(_x - ARROW_BUTTON_W + 2,
	    _y - ARROW_BUTTON_H, _x - 1, _y - ARROW_BUTTON_H);

    fl_color(NxApp::Instance()->getGlobalColor(APP_BG));

    fl_begin_polygon();

    _x = x() + w() - ARROW_BUTTON_W;
    _y = y() + h() - ARROW_BUTTON_H;

    fl_transformed_vertex(_x + 3, _y + 2);

    fl_transformed_vertex(_x + ARROW_BUTTON_W - 2, _y + 2);

    fl_transformed_vertex(_x + (ARROW_BUTTON_W / 2) + 1,
			  _y + ARROW_BUTTON_H - 3);

    fl_transformed_vertex(_x + 3, _y + 2);

    fl_end_polygon();

    fl_line(_x + 3, _y + 2, _x + ARROW_BUTTON_W - 2, _y + 2);

    fl_line(_x + ARROW_BUTTON_W - 2,
	    _y + 2, _x + (ARROW_BUTTON_W / 2) + 1, _y + ARROW_BUTTON_H - 3);

    fl_line(_x + 3,
	    _y + 2, _x + (ARROW_BUTTON_W / 2) + 1, _y + ARROW_BUTTON_H - 3);


    draw_label();

    fl_color(c);

}

--- NEW FILE: nxholdbrowser.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include <nxapp.h>
#include <FL/Enumerations.H>
#include <nxholdbrowser.h>

NxHoldBrowser::NxHoldBrowser(int x, int y, int w, int h, const char *l):
Fl_Hold_Browser(x, y, w, h, l)
{

    // Provide the specific "look-and-feel"
    save_h = 0;
    move = true;
    color(NxApp::Instance()->getGlobalColor(APP_BG));
    selection_color(NxApp::Instance()->getGlobalColor(HILIGHT));
    textcolor(NxApp::Instance()->getGlobalColor(APP_FG));
    NxApp::Instance()->def_font(this);
}				// end of NxHoldBrowser::NxHoldBrowser()

--- NEW FILE: nxsecretinput.cxx ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include <nxapp.h>
#include <FL/Enumerations.H>
#include <nxsecretinput.h>
#include <stdio.h>

NxSecretInput::NxSecretInput(int x, int y, int w, int h, const char *l):
Fl_Secret_Input(x, y, w, h, l)
{

    // Provide the specific "look-and-feel"
    color(NxApp::Instance()->getGlobalColor(APP_BG));
    labelcolor(NxApp::Instance()->getGlobalColor(APP_FG));
    textcolor(NxApp::Instance()->getGlobalColor(APP_FG));
    selection_color(NxApp::Instance()->getGlobalColor(APP_SEL));
    NxApp::Instance()->def_font(this);
#ifdef NANOX
    box(FL_BOTTOM_BOX);
#else
    box(FL_FLAT_BOX);
#endif
    align(FL_ALIGN_LEFT);
}				// end of NxOutput::NxOutput()




More information about the dslinux-commit mailing list