/****************************************************************** * * * Nest version 2 - 3D Wasp Nest Simulator * * Copyright (C) 1997 Sylvain GUERIN * * LIASC, ENST Bretagne & Santa Fe Institute * * * ****************************************************************** E-mail: Sylvain.Guerin@enst-bretagne.fr or: Sylvain Guerin 13 rue des Monts Lorgeaux, 51460 L'EPINE, FRANCE ****************************************************************** This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ****************************************************************** Name : graphical.c Component : graphical interface Fonctionality : contains methods for objects refering to the graphical interface (Xlib) ******************************************************************/ #include "graphical.h" #include "IconBitmap.h" /* ---------------------------------------------------- */ GraphicElement::GraphicElement () { previous = NULL; } GraphicElement::GraphicElement (GraphicElement* aGraphicElement) { display = aGraphicElement->display; color = aGraphicElement->color; gc = aGraphicElement->gc; displayMode = aGraphicElement->displayMode; fontInfo = aGraphicElement->fontInfo; previous = aGraphicElement; } GraphicElement::~GraphicElement () { } void GraphicElement::printLinks () { textInputLinks.print (); } /* ---------------------------------------------------- */ Interface::Interface (int x0, int y0, int aWidth, int aHeight, int constSize, char* windowLabel, char* iconLabel) : GraphicElement () { displayName = new char[32]; displayName = NULL; displayMustBeFreed = 1; if ( (display = XOpenDisplay (displayName)) == NULL ) { printf ("Unable to connect X Server %s\n", XDisplayName (displayName)); exit (-1); } else { /* Connection X autorisee */ initializeInterface (x0, y0, aWidth, aHeight, constSize, windowLabel, iconLabel); } } Interface::Interface (int x0, int y0, int aWidth, int aHeight, int constSize, char* windowLabel, char* iconLabel, Display* aDisplay) : GraphicElement () { /* on pointe sur le display principal */ displayName = new char[32]; displayName = NULL; displayMustBeFreed = 0; display = aDisplay; initializeInterface (x0, y0, aWidth, aHeight, constSize, windowLabel, iconLabel); } void Interface::initializeInterface (int x0, int y0, int aWidth, int aHeight, int constSize, char* windowLabel, char* iconLabel) { int count; windowName = new char[256]; iconName = new char[256]; fontInfo = new XFontStruct; sizeList = new XIconSize; //windowNameX.value = new unsigned char[256]; //iconNameX.value = new unsigned char[256]; screenNum = DefaultScreen (display); getColor (); displayWidth = DisplayWidth (display, screenNum); displayHeight = DisplayHeight (display, screenNum); x = x0; y = y0; borderWidth = 10; width = aWidth; height = aHeight; win = XCreateSimpleWindow (display, RootWindow (display, screenNum), x, y, width, height, borderWidth, color[Black], color[Grey]); /* We don't test this, don't need to know :) */ XGetIconSizes (display, RootWindow (display, screenNum), &(sizeList), &count); iconPixmap = XCreateBitmapFromData (display, win, iconBitmapBits, iconBitmapWidth, iconBitmapHeight); if (constSize == 1) { sizeHints.flags = PPosition | PSize | PMinSize | PMaxSize; sizeHints.min_width = width; sizeHints.min_height = height; sizeHints.max_width = width; sizeHints.max_height = height; } else sizeHints.flags = PPosition | PSize ; strcpy (windowName, windowLabel); strcpy (iconName, iconLabel); if (XStringListToTextProperty (&windowName, 1, &windowNameX) == 0) { printf ("Structure allocation for window name failed\n"); exit (-1); }; if (XStringListToTextProperty (&iconName, 1, &iconNameX) == 0) { printf ("Structure allocation for icon name failed\n"); exit (-1); } wmHints.initial_state = NormalState; wmHints.input = True; wmHints.icon_pixmap = iconPixmap; wmHints.flags = StateHint | IconPixmapHint | InputHint; classHints = XAllocClassHint (); XSetWMProperties (display, win, &windowNameX, &iconNameX, NULL, 0, &sizeHints, &wmHints, classHints); if (constSize == 1) { XSelectInput (display, win, ExposureMask); } else { XSelectInput (display, win, ExposureMask | ResizeRedirectMask); } loadFont (); getGC (); XMapWindow (display, win); backgroundColor = Grey; inputBoxLaunched = 0; } void Interface::resizeWindow () /* used only if constSize = 0 */ { //XWindowChanges values; //values.width = width; //values.height = height; printf ("Resizing not implemented yet\n"); //printf ("resizing %d %d\n", width, height); //XResizeWindow (display, win, width, height); //XMapWindow (display, win); //XConfigureWindow(display, win, CWWidth | CWHeight, &values); //XRaiseWindow (display, win); //XFlush (display); } Interface::~Interface () { XUnmapWindow (display, win); XFreePixmap (display, iconPixmap); XDestroyWindow (display, win); XFreeFont (display, fontInfo); XFreeGC (display, *gc); if (displayMustBeFreed) { XCloseDisplay (display); } delete[] displayName; delete[] windowName; delete[] iconName; delete sizeList; delete[] color; //delete[] windowNameX.value; //delete[] iconNameX.value; } void Interface::getColor () { /* USELESS unsigned long planeMasks[1]; */ unsigned int nColors = 0; int i; /* USELESS char* visualClass[] = {"StaticGray", "GrayScale", "StaticColor", */ /* USELESS "PseudoColor", "TrueColor", "DirectColor"}; */ XVisualInfo visualInfo; XColor exactDef; char* name[] = { "black", // 0 Black "grey", // 1 Grey "light grey", // 2 LightGrey "lightslateblue", // 3 LightBlue "red2", // 4 Red2 "blue", // 5 Blue "red", // 6 Red "red3", // 7 Red3 "gold", // 8 Gold "goldenrod", // 9 GoldenRod "DarkGoldenrod", // 10 DarkGoldenRod "yellow", // 11 Yellow "red4", // 12 Red4 "green", // 13 Green "grey60", // 14 HardGrey "white", // 15 White "DarkSlateBlue", // 16 HardBlue "MediumBlue", // 17 MediumBlue }; color = new unsigned long[COLOR_NUMBER]; defaultDepth = DefaultDepth (display, screenNum); defaultVisual = DefaultVisual (display, screenNum); defaultCmap = DefaultColormap (display, screenNum); i = 5; while (!XMatchVisualInfo (display, screenNum, defaultDepth, i--, &visualInfo)); // printf ("Visual found: %s\n", visualClass[++i]); if ((defaultDepth == 1) || (i < StaticColor)) { /* Ben tant pis, on est en noir et blanc */ color[0] = BlackPixel (display, screenNum); color[1] = WhitePixel (display, screenNum); color[2] = WhitePixel (display, screenNum); color[3] = WhitePixel (display, screenNum); color[4] = WhitePixel (display, screenNum); color[5] = WhitePixel (display, screenNum); color[6] = WhitePixel (display, screenNum); color[7] = WhitePixel (display, screenNum); color[8] = WhitePixel (display, screenNum); color[9] = WhitePixel (display, screenNum); color[10] = WhitePixel (display, screenNum); color[11] = WhitePixel (display, screenNum); color[12] = WhitePixel (display, screenNum); color[13] = WhitePixel (display, screenNum); color[14] = WhitePixel (display, screenNum); color[15] = BlackPixel (display, screenNum); displayMode = blackAndWhiteMode; } else { /* C'est en couleurs, cool */ displayMode = colorMode; if (visualInfo.visual != defaultVisual) { // printf ("Visual %s at default depth\n", visualClass[i]); /* Not default visual, continuing anyway... */ } for (i=0; ifid); XSetForeground (display, mainGC, BlackPixel (display, screenNum)); XSetLineAttributes (display, mainGC, lineWidth, lineStyle, capStyle, joinStyle); XSetDashes (display, mainGC, dashOffset, dashList, listLength); gc = &mainGC; } void Interface::loadFont () { char* fontName = new char[20]; strcpy (fontName, "9x15"); if ((fontInfo = XLoadQueryFont (display, fontName)) == NULL) { printf ("Probleme pour ouvrir la fonte %s\n", fontName); exit (-1); } delete []fontName; } unsigned int Interface::displayDialogBox (Interface* toBeRefreshedInterface, char* DBWLabel, char* DBILabel, char* aText, char* choice1) { int DBWidth; DBWidth = strlen(aText)*9+50; if (DBWidth < 150) { DBWidth = 150; } DialogBox theDialogBox (toBeRefreshedInterface, (int)((displayWidth-DBWidth)/2), (int)((displayHeight-150)/2), DBWidth, 150, DBWLabel, DBILabel, aText, choice1, toBeRefreshedInterface->display); return theDialogBox.manageDialogBox (); } unsigned int Interface::displayDialogBox (Interface* toBeRefreshedInterface, char* DBWLabel, char* DBILabel, char* aText, char* choice1, char* choice2) { int DBWidth; DBWidth = strlen(aText)*9+50; if (DBWidth < 290) { DBWidth = 290; } DialogBox theDialogBox (toBeRefreshedInterface, (int)((displayWidth-DBWidth)/2), (int)((displayHeight-150)/2), DBWidth, 150, DBWLabel, DBILabel, aText, choice1, choice2, toBeRefreshedInterface->display); return theDialogBox.manageDialogBox (); } unsigned int Interface::displayDialogBox (Interface* toBeRefreshedInterface, char* DBWLabel, char* DBILabel, char* aText, char* choice1, char* choice2, char* choice3) { int DBWidth; DBWidth = strlen(aText)*9+50; if (DBWidth < 410) { DBWidth = 410; } DialogBox theDialogBox (toBeRefreshedInterface, (int)((displayWidth-DBWidth)/2), (int)((displayHeight-150)/2), DBWidth, 150, DBWLabel, DBILabel, aText, choice1, choice2, choice3, toBeRefreshedInterface->display); return theDialogBox.manageDialogBox (); } unsigned int Interface::displayDialogBox (Interface* toBeRefreshedInterface, char* DBWLabel, char* DBILabel, char* aText, char* choice1, char* choice2, char* choice3, char* choice4) { int DBWidth; DBWidth = strlen(aText)*9+50; if (DBWidth < 540) { DBWidth = 540; } DialogBox theDialogBox (toBeRefreshedInterface, (int)((displayWidth-DBWidth)/2), (int)((displayHeight-150)/2), DBWidth, 150, DBWLabel, DBILabel, aText, choice1, choice2, choice3, choice4, toBeRefreshedInterface->display); return theDialogBox.manageDialogBox (); } void Interface::displayInfoBox (Interface* toBeRefreshedInterface, int x0, int y0, char* IBWLabel, char* IBILabel, char* aText) { anInfoBox = new InfoBox (toBeRefreshedInterface, x0, y0, strlen(aText)*9+50, 140,IBWLabel, IBILabel, aText, 0); } void Interface::displayInfoBox (Interface* toBeRefreshedInterface, char* IBWLabel, char* IBILabel, char* aText) { anInfoBox = new InfoBox (toBeRefreshedInterface, (int)((displayWidth-strlen(aText)*9-50)/2), (int)((displayHeight-90)/2), strlen(aText)*9+50, 140,IBWLabel, IBILabel, aText, 0); } void Interface::displayAbortableInfoBox (Interface* toBeRefreshedInterface, int x0, int y0, char* IBWLabel, char* IBILabel, char* aText) { anInfoBox = new InfoBox (toBeRefreshedInterface, x0, y0, strlen(aText)*9+50, 165,IBWLabel, IBILabel, aText, 1); } void Interface::displayAbortableInfoBox (Interface* toBeRefreshedInterface, char* IBWLabel, char* IBILabel, char* aText) { anInfoBox = new InfoBox (toBeRefreshedInterface, (int)((displayWidth-strlen(aText)*9-50)/2), (int)((displayHeight-90)/2), strlen(aText)*9+50, 165,IBWLabel, IBILabel, aText, 1); } void Interface::freeInfoBox () { delete anInfoBox; } unsigned int Interface::displayInputBox (Interface* toBeRefreshedInterface, char* IBWLabel, char* IBILabel, int inputNb, int maxCol) /* j'ai oublie ce que ca doit retourner.... a voir... */ { if (inputBoxLaunched) { printf ("Error: input box already launched\n"); return 0; } else { inputBoxLaunched = 1; anInputBox = new InputDialogBox (toBeRefreshedInterface, (int)((displayWidth-maxCol*9-50)/2), (int)((displayHeight-inputNb*20-130)/2), maxCol*9+50, inputNb*20+130, inputNb, IBWLabel, IBILabel); return 1; } } void Interface::addIntInput (char* aLabel, unsigned int aMaxWidth, int* returnedInt) { anInputBox->addIntInput (aLabel, aMaxWidth, returnedInt); } void Interface::addLongInput (char* aLabel, unsigned int aMaxWidth, long* returnedLong) { anInputBox->addLongInput (aLabel, aMaxWidth, returnedLong); } void Interface::addDoubleInput (char* aLabel, unsigned int aMaxWidth, double* returnedDouble) { anInputBox->addDoubleInput (aLabel, aMaxWidth, returnedDouble); } void Interface::addCharInput (char* aLabel, unsigned int aMaxWidth, char* returnedChar) { anInputBox->addCharInput (aLabel, aMaxWidth, returnedChar); } void Interface::addEnumInput (char* aLabel, unsigned int aMaxWidth, Enumeration* anEnumeration) { anInputBox->addEnumInput (aLabel, aMaxWidth, anEnumeration); } void Interface::addIntInput (char* aLabel, unsigned int aMaxWidth, int* returnedInt, fonctionStateType aFonctionState) { anInputBox->addIntInput (aLabel, aMaxWidth, returnedInt, aFonctionState); } void Interface::addLongInput (char* aLabel, unsigned int aMaxWidth, long* returnedLong, fonctionStateType aFonctionState) { anInputBox->addLongInput (aLabel, aMaxWidth, returnedLong, aFonctionState); } void Interface::addDoubleInput (char* aLabel, unsigned int aMaxWidth, double* returnedDouble, fonctionStateType aFonctionState) { anInputBox->addDoubleInput (aLabel, aMaxWidth, returnedDouble, aFonctionState); } void Interface::addCharInput (char* aLabel, unsigned int aMaxWidth, char* returnedChar, fonctionStateType aFonctionState) { anInputBox->addCharInput (aLabel, aMaxWidth, returnedChar, aFonctionState); } void Interface::addEnumInput (char* aLabel, unsigned int aMaxWidth, Enumeration* anEnumeration, fonctionStateType aFonctionState) { anInputBox->addEnumInput (aLabel, aMaxWidth, anEnumeration, aFonctionState); } unsigned int Interface::manageInputBox () { unsigned int returned; returned = anInputBox->manageInputDialogBox (); delete anInputBox; inputBoxLaunched = 0; return returned; } /* ---------------------------------------------------- */ GraphicWidget::GraphicWidget (GraphicElement* anElement, int x0, int y0, unsigned int aWidth, unsigned int aHeight, unsigned int aBorderWidth, colorType aBorderColor, colorType aBackgroundColor, long anEventMask, fonctionStateType aFonctionState) : GraphicElement (anElement) { x = x0; y = y0; width = aWidth; height = aHeight; borderWidth = aBorderWidth; borderColor = aBorderColor; backgroundColor = aBackgroundColor; eventMask = anEventMask; fonctionState = aFonctionState; win = XCreateSimpleWindow(display, anElement->win, x, y, width, height, borderWidth, color[borderColor], color[backgroundColor]); XSelectInput (display, win, eventMask); XMapWindow (display, win); } GraphicWidget::~GraphicWidget () { XUnmapWindow (display, win); XDestroyWindow (display, win); } void GraphicWidget::refresh () { XEvent aReport; if (XCheckWindowEvent (display, win, ExposureMask, &aReport)) manageEvent (aReport); } /* ---------------------------------------------------- */ Button::Button (GraphicElement* anElement, int x0, int y0, unsigned int aWidth, unsigned int aHeight, char* aButtonText, justifType aJustif, fonctionStateType aFonctionState) : GraphicWidget (anElement, x0, y0, aWidth, aHeight, 0, anElement->backgroundColor, anElement->backgroundColor, ExposureMask | ButtonPressMask | ButtonReleaseMask, aFonctionState) { strcpy (buttonText, aButtonText); justif = aJustif; buttonState = notPressed; } Button::~Button () { } actionType Button::manageEvent (XEvent anEvent) { report = anEvent; switch (report.type) { case Expose: manageRefreshEvent (); return noAction; break; case ButtonPress: return manageButtonPressEvent (); break; case ButtonRelease: return manageButtonReleaseEvent (); break; default: return noAction; break; } } void Button::manageRefreshEvent () { if (report.xexpose.window == win) { refreshButton (); } } actionType Button::manageButtonPressEvent () { if ((report.xbutton.window == win) && (fonctionState == enabled)) { buttonState = pressed; refreshButton (); } return noAction; } actionType Button::manageButtonReleaseEvent () { if ((report.xbutton.window == win) && (fonctionState == enabled)) { buttonState = notPressed; refreshButton (); return buttonPressed; } return noAction; } void Button::refreshButton () { if (displayMode == blackAndWhiteMode) { if (fonctionState == disabled) { drawButton (Black, White, White); } else { /* fonctionState = enabled */ if (buttonState == pressed) { drawButton (Black, White, White); } else { /* buttonState = notPressed */ drawButton (White, Black, Black); } } } else { /* colorMode */ if (fonctionState == disabled) { drawButton (Grey, Black, White); } else { /* fonctionState = enabled */ if (buttonState == notPressed) { drawButton (LightGrey, White, Black); } else { /* buttonState = notPressed */ drawButton (HardGrey, Black, White); } } } } void Button::drawButton (colorType colorbg, colorType colorhg, colorType colorbd) { XTextItem textItem; unsigned int colbg, colhg, colbd; unsigned int l, h; l = width-1; h = height-1; colbg = color[colorbg]; colhg = color[colorhg]; colbd = color[colorbd]; XSetLineAttributes (display, *gc, 1, LineSolid, CapRound, JoinRound ); XSetForeground (display, *gc, colbg); XFillArc (display, win, *gc, 0, 0, BRS, BRS, 5760, 5760); XFillArc (display, win, *gc, 0, h-BRS, BRS, BRS, 11520, 5760); XFillArc (display, win, *gc, l-BRS, h-BRS, BRS, BRS, -5760, 5760); XFillArc (display, win, *gc, l-BRS, 0, BRS, BRS, 0, 5760); XFillRectangle (display, win, *gc, BRS/2, 0, l-BRS, BRS/2); XFillRectangle (display, win, *gc, BRS/2, h-BRS/2, l-BRS, BRS/2); XFillRectangle (display, win, *gc, 0, BRS/2, l, h-BRS); XSetForeground (display, *gc, colhg); XDrawArc (display, win, *gc, 0, 0, BRS, BRS, 5760, 5760); XDrawArc (display, win, *gc, 0, h-BRS, BRS, BRS, 11520, 2880); XDrawLine (display, win, *gc, BRS/2, 0, l-BRS/2, 0); XDrawArc (display, win, *gc, l-BRS, 0, BRS, BRS, 2880, 2880); XDrawLine (display, win, *gc, 0, BRS/2, 0, h-BRS/2); XSetForeground (display, *gc, colbd); XDrawLine (display, win, *gc, l, BRS/2, l, h-BRS/2); XDrawArc (display, win, *gc, 0, h-BRS, BRS, BRS, 14400, 2880); XDrawArc (display, win, *gc, l-BRS, h-BRS, BRS, BRS, -5760, 5760); XDrawArc (display, win, *gc, l-BRS, 0, BRS, BRS, 0, 2880); XDrawLine (display, win, *gc, BRS/2, h, l-BRS/2, h); textItem.chars = buttonText; textItem.nchars = strlen (buttonText); textItem.delta = 1; textItem.font = fontInfo->fid; if (justif == centerJustified) { XDrawText (display, win, *gc, (l-9*textItem.nchars)/2, h/2+5, &textItem, 1); } else { /* leftJustified */ XDrawText (display, win, *gc, 10, h/2+5, &textItem, 1); } } void Button::enable () { fonctionState = enabled; refreshButton (); } void Button::disable () { fonctionState = disabled; refreshButton (); } /* ---------------------------------------------------- */ SwapButton::SwapButton (GraphicElement* anElement, int x0, int y0, unsigned int aWidth, unsigned int aHeight, char* aButtonText, char* aSwappedButtonText, justifType aJustif, fonctionStateType aFonctionState) : Button (anElement, x0, y0, aWidth, aHeight, aButtonText, aJustif, aFonctionState) { strcpy (swappedButtonText, aSwappedButtonText); strcpy (notSwappedButtonText, aButtonText); isswapped = 0; } int SwapButton::isSwapped () { return isswapped; } actionType SwapButton::manageButtonReleaseEvent () { if ((report.xbutton.window == win) && (fonctionState == enabled)) { buttonState = notPressed; if (isswapped == 0) { strcpy (buttonText, swappedButtonText); isswapped = 1; } else { strcpy (buttonText, notSwappedButtonText); isswapped = 0; } refreshButton (); return buttonPressed; } return noAction; } /* ---------------------------------------------------- */ GraphButton::GraphButton (GraphicElement* anElement, int x0, int y0, unsigned int aWidth, unsigned int aHeight, fonctionStateType aFonctionState) : GraphicWidget (anElement, x0, y0, aWidth, aHeight, 0, anElement->backgroundColor, anElement->backgroundColor, ExposureMask | ButtonPressMask | ButtonReleaseMask, aFonctionState) { buttonState = notPressed; pressAgain = 1; pressFunction = normal; } GraphButton::GraphButton (GraphicElement* anElement, int x0, int y0, unsigned int aWidth, unsigned int aHeight, fonctionStateType aFonctionState, pressFunctionType aPressFunction) : GraphicWidget (anElement, x0, y0, aWidth, aHeight, 0, anElement->backgroundColor, anElement->backgroundColor, ExposureMask | ButtonPressMask | ButtonReleaseMask, aFonctionState) { buttonState = notPressed; pressFunction = aPressFunction; pressAgain = 1; } GraphButton::~GraphButton () { } actionType GraphButton::manageEvent (XEvent anEvent) { report = anEvent; /* printf ("event occured\n"); */ switch (report.type) { case Expose: manageRefreshEvent (); return noAction; break; case ButtonPress: return manageButtonPressEvent (); break; case ButtonRelease: return manageButtonReleaseEvent (); break; default: return noAction; break; } } void GraphButton::manageRefreshEvent () { if (report.xexpose.window == win) { refreshGraphButton (); } } actionType GraphButton::manageButtonPressEvent () { if ((report.xbutton.window == win) && (fonctionState == enabled)) { if (pressFunction == normal) { buttonState = pressed; refreshGraphButton (); return noAction; } else { XEvent sent_event; sent_event.type = ButtonPress; sent_event.xbutton.window = win; if (pressAgain == 1) { XSendEvent (display, win, 1,ButtonPressMask, &sent_event); buttonState = pressed; refreshGraphButton (); return buttonPressed; } else { pressAgain = 1; buttonState = notPressed; refreshGraphButton (); return endOfPression; } } } return noAction; } actionType GraphButton::manageButtonReleaseEvent () { if ((report.xbutton.window == win) && (fonctionState == enabled)) { pressAgain = 0; buttonState = notPressed; refreshGraphButton (); return buttonPressed; } return noAction; } /* ---------------------------------------------------- */ LeftArrow::LeftArrow (GraphicElement* anElement, int x0, int y0, fonctionStateType aFonctionState) :GraphButton (anElement, x0, y0, 30, 30, aFonctionState) { } LeftArrow::LeftArrow (GraphicElement* anElement, int x0, int y0, fonctionStateType aFonctionState, pressFunctionType aPressFunction) :GraphButton (anElement, x0, y0, 30, 30, aFonctionState, aPressFunction) { } LeftArrow::~LeftArrow () { } void LeftArrow::refreshGraphButton () { XPoint pts[3]; pts[0].x=24; pts[0].y=0; pts[1].x=0; pts[1].y=12; pts[2].x=24; pts[2].y=23; XSetLineAttributes (display, *gc, 1, LineSolid, CapProjecting, JoinMiter ); if (buttonState == notPressed) XSetForeground (display, *gc, color[LightGrey]); else XSetForeground (display, *gc, color[Black]); XFillPolygon (display, win, *gc, pts, 3, Convex, CoordModeOrigin); XSetForeground (display, *gc, color[White]); XDrawLine (display, win, *gc, 24,0,0,12); XSetForeground (display, *gc, color[Black]); XDrawLine (display, win, *gc, 24,0,24,23); } /* ---------------------------------------------------- */ RightArrow::RightArrow (GraphicElement* anElement, int x0, int y0, fonctionStateType aFonctionState) :GraphButton (anElement, x0, y0, 30, 30, aFonctionState) { } RightArrow::RightArrow (GraphicElement* anElement, int x0, int y0, fonctionStateType aFonctionState, pressFunctionType aPressFunction) :GraphButton (anElement, x0, y0, 30, 30, aFonctionState, aPressFunction) { } RightArrow::~RightArrow () { } void RightArrow::refreshGraphButton () { XPoint pts[3]; pts[0].x=0; pts[0].y=0; pts[1].x=24; pts[1].y=12; pts[2].x=0; pts[2].y=23; XSetLineAttributes (display, *gc, 1, LineSolid, CapProjecting, JoinMiter ); if (buttonState == notPressed) XSetForeground (display, *gc, color[LightGrey]); else XSetForeground (display, *gc, color[Black]); XFillPolygon (display, win, *gc, pts, 3, Convex, CoordModeOrigin); XSetForeground (display, *gc, color[White]); XDrawLine (display, win, *gc, 0,0,0,23); XSetForeground (display, *gc, color[Black]); XDrawLine (display, win, *gc, 0,23,24,12); } /* ---------------------------------------------------- */ UpArrow::UpArrow (GraphicElement* anElement, int x0, int y0, fonctionStateType aFonctionState) :GraphButton (anElement, x0, y0, 30, 30, aFonctionState) { } UpArrow::UpArrow (GraphicElement* anElement, int x0, int y0, fonctionStateType aFonctionState, pressFunctionType aPressFunction) :GraphButton (anElement, x0, y0, 30, 30, aFonctionState, aPressFunction) { } UpArrow::~UpArrow () { } void UpArrow::refreshGraphButton () { XPoint pts[3]; pts[0].x=12; pts[0].y=0; pts[1].x=0; pts[1].y=24; pts[2].x=23; pts[2].y=24; XSetLineAttributes (display, *gc, 1, LineSolid, CapProjecting, JoinMiter ); if (buttonState == notPressed) XSetForeground (display, *gc, color[LightGrey]); else XSetForeground (display, *gc, color[Black]); XFillPolygon (display, win, *gc, pts, 3, Convex, CoordModeOrigin); XSetForeground (display, *gc, color[White]); XDrawLine (display, win, *gc, 12,0,0,24); XSetForeground (display, *gc, color[Black]); XDrawLine (display, win, *gc, 0,24,23,24); } /* ---------------------------------------------------- */ DownArrow::DownArrow (GraphicElement* anElement, int x0, int y0, fonctionStateType aFonctionState) :GraphButton (anElement, x0, y0, 30, 30, aFonctionState) { } DownArrow::DownArrow (GraphicElement* anElement, int x0, int y0, fonctionStateType aFonctionState, pressFunctionType aPressFunction) :GraphButton (anElement, x0, y0, 30, 30, aFonctionState, aPressFunction) { } DownArrow::~DownArrow () { } void DownArrow::refreshGraphButton () { XPoint pts[3]; pts[0].x=0; pts[0].y=0; pts[1].x=23; pts[1].y=0; pts[2].x=12; pts[2].y=24; XSetLineAttributes (display, *gc, 1, LineSolid, CapProjecting, JoinMiter ); if (buttonState == notPressed) XSetForeground (display, *gc, color[LightGrey]); else XSetForeground (display, *gc, color[Black]); XFillPolygon (display, win, *gc, pts, 3, Convex, CoordModeOrigin); XSetForeground (display, *gc, color[White]); XDrawLine (display, win, *gc, 0,0,23,0); XSetForeground (display, *gc, color[Black]); XDrawLine (display, win, *gc, 23,0,12,24); } /* ---------------------------------------------------- */ DownSquare::DownSquare (GraphicElement* anElement, int x0, int y0, fonctionStateType aFonctionState) :GraphButton (anElement, x0, y0, 30, 26, aFonctionState) { } DownSquare::DownSquare (GraphicElement* anElement, int x0, int y0, fonctionStateType aFonctionState, pressFunctionType aPressFunction) :GraphButton (anElement, x0, y0, 30, 26, aFonctionState, aPressFunction) { } DownSquare::~DownSquare () { } void DownSquare::refreshGraphButton () { XSetLineAttributes (display, *gc, 1, LineSolid,CapProjecting, JoinMiter ); if (buttonState == notPressed) XSetForeground (display, *gc, color[LightGrey]); else XSetForeground (display, *gc, color[Black]); XFillRectangle (display, win, *gc,0,0,29,25); if (buttonState == notPressed) XSetForeground (display, *gc, color[White]); else XSetForeground (display, *gc, color[Black]); XDrawLine (display, win, *gc, 0,0,28,0); XDrawLine (display, win, *gc, 0,0,0,24); if (buttonState == notPressed) XSetForeground (display, *gc, color[Black]); else XSetForeground (display, *gc, color[White]); XDrawLine (display, win, *gc, 28,24,28,0); XDrawLine (display, win, *gc, 28,24,0,24); if (buttonState == notPressed) XSetForeground (display, *gc,color[Black]); else XSetForeground (display, *gc,color[White]); XSetLineAttributes (display, *gc, 2, LineSolid, CapProjecting, JoinMiter ); XDrawLine (display, win, *gc, 9,12,19,12); XSetLineAttributes (display, *gc, 1, LineSolid, CapProjecting, JoinMiter ); } /* ---------------------------------------------------- */ UpSquare::UpSquare (GraphicElement* anElement, int x0, int y0, fonctionStateType aFonctionState) :GraphButton (anElement, x0, y0, 30, 26, aFonctionState) { } UpSquare::UpSquare (GraphicElement* anElement, int x0, int y0, fonctionStateType aFonctionState, pressFunctionType aPressFunction) :GraphButton (anElement, x0, y0, 30, 26, aFonctionState, aPressFunction) { } UpSquare::~UpSquare () { } void UpSquare::refreshGraphButton () { XSetLineAttributes (display, *gc, 1, LineSolid,CapProjecting, JoinMiter ); if (buttonState == notPressed) XSetForeground (display, *gc, color[LightGrey]); else XSetForeground (display, *gc, color[Black]); XFillRectangle (display, win, *gc,0,0,29,25); if (buttonState == notPressed) XSetForeground (display, *gc, color[White]); else XSetForeground (display, *gc, color[Black]); XDrawLine (display, win, *gc, 0,0,28,0); XDrawLine (display, win, *gc, 0,0,0,24); if (buttonState == notPressed) XSetForeground (display, *gc, color[Black]); else XSetForeground (display, *gc, color[White]); XDrawLine (display, win, *gc, 28,24,28,0); XDrawLine (display, win, *gc, 28,24,0,24); if (buttonState == notPressed) XSetForeground (display, *gc,color[Black]); else XSetForeground (display, *gc,color[White]); XSetLineAttributes (display, *gc, 2, LineSolid, CapProjecting, JoinMiter ); XDrawLine (display, win, *gc, 9,12,19,12); XDrawLine (display, win, *gc, 14,7,14,17); XSetLineAttributes (display, *gc, 1, LineSolid, CapProjecting, JoinMiter ); } /* ---------------------------------------------------- */ PassiveWidget::PassiveWidget (GraphicElement* anElement, int x0, int y0, unsigned int aWidth, unsigned int aHeight) : GraphicWidget (anElement, x0, y0, aWidth, aHeight, 0, anElement->backgroundColor, anElement->backgroundColor, // Red, Red, ExposureMask | ButtonPressMask, enabled) { } PassiveWidget::~PassiveWidget () { } actionType PassiveWidget::manageEvent (XEvent anEvent) { report = anEvent; switch (report.type) { case Expose: manageRefreshEvent (); return noAction; break; default: return noAction; break; } } void PassiveWidget::manageRefreshEvent () { if (report.xexpose.window == win) { refreshWidget (); } } /* ---------------------------------------------------- */ HorizontalBar::HorizontalBar (GraphicElement* anElement, int x0, int y0, unsigned int aWidth) : PassiveWidget (anElement, x0, y0, aWidth, 2) { } HorizontalBar::~HorizontalBar () { } void HorizontalBar::refreshWidget () { XSetForeground (display, *gc, color[White]); XDrawLine (display, win, *gc, 0, 0, width-1, 0); XSetForeground (display, *gc, color[Black]); XDrawLine (display, win, *gc, 0, 1, width-1, 1); } /* ---------------------------------------------------- */ VerticalBar::VerticalBar (GraphicElement* anElement, int x0, int y0, unsigned int aHeight) : PassiveWidget (anElement, x0, y0, 2, aHeight) { } VerticalBar::~VerticalBar () { } void VerticalBar::refreshWidget () { XSetForeground (display, *gc, color[White]); XDrawLine (display, win, *gc, 0, 0, 0, height-1); XSetForeground (display, *gc, color[Black]); XDrawLine (display, win, *gc, 1, 0, 1, height-1); } /* ---------------------------------------------------- */ RoundPanel::RoundPanel (GraphicElement* anElement, int x0, int y0, unsigned int aWidth, unsigned int aHeight) : PassiveWidget (anElement, x0, y0, aWidth, aHeight) { backgroundColor = HardGrey; } RoundPanel::~RoundPanel () { } void RoundPanel::refreshWidget () { unsigned int l; unsigned int h; unsigned long colorbg; unsigned long colorhg; unsigned long colorbd; colorbg = color[HardGrey]; colorhg = color[Black]; colorbd = color[White]; l = width-1; h = height-1; XSetLineAttributes (display, *gc, 1, LineSolid, CapRound, JoinRound ); XSetForeground (display, *gc, colorbg); XFillArc (display, win, *gc, 0, 0, RS, RS, 5760, 5760); XFillArc (display, win, *gc, 0, 0+h-RS, RS, RS, 11520, 5760); XFillArc (display, win, *gc, 0+l-RS, 0+h-RS, RS, RS, -5760, 5760); XFillArc (display, win, *gc, 0+l-RS, 0, RS, RS, 0, 5760); XFillRectangle (display, win, *gc, 0+RS/2, 0, l-RS, RS/2); XFillRectangle (display, win, *gc, 0+RS/2, 0+h-RS/2, l-RS, RS/2); XFillRectangle (display, win, *gc, 0, 0+RS/2, l, h-RS); XSetForeground (display, *gc, colorhg); XDrawArc (display, win, *gc, 0, 0, RS, RS, 5760, 5760); XDrawArc (display, win, *gc, 0, 0+h-RS, RS, RS, 11520, 2880); XDrawLine (display, win, *gc, 0+RS/2, 0, 0+l-RS/2, 0); XDrawArc (display, win, *gc, 0+l-RS, 0, RS, RS, 2880, 2880); XDrawLine (display, win, *gc, 0, 0+RS/2, 0, 0+h-RS/2); XSetForeground (display, *gc, colorbd); XDrawLine (display, win, *gc, 0+l, 0+RS/2, 0+l, 0+h-RS/2); XDrawArc (display, win, *gc, 0, 0+h-RS, RS, RS, 14400, 2880); XDrawArc (display, win, *gc, 0+l-RS, 0+h-RS, RS, RS, -5760, 5760); XDrawArc (display, win, *gc, 0+l-RS, 0, RS, RS, 0, 2880); XDrawLine (display, win, *gc, 0+RS/2, 0+h, 0+l-RS/2, 0+h); } /* ---------------------------------------------------- */ TextWidget::TextWidget (GraphicElement* anElement, int x0, int y0, char* aText) : PassiveWidget (anElement, x0, y0, strlen(aText)*9+2, 18) { strcpy (text, aText); inversedDisplay = 0; boldDisplay = 0; } TextWidget::~TextWidget () { } void TextWidget::refreshWidget () { XTextItem textItem; textItem.chars = text; textItem.nchars = strlen (text); textItem.delta = 1; textItem.font = fontInfo->fid; XClearWindow (display, win); if (inversedDisplay) { XSetBackground (display, *gc, color[HardGrey]); XSetForeground (display, *gc, color[White]); XDrawImageString (display, win, *gc, 0, 12, text, strlen(text)); if (boldDisplay) { XDrawText (display, win, *gc, 0, 12, &textItem, 1); } } else { XSetBackground (display, *gc, color[backgroundColor]); XSetForeground (display, *gc, color[Black]); XDrawImageString (display, win, *gc, 0, 12, text, strlen(text)); if (boldDisplay) { XDrawText (display, win, *gc, 0, 12, &textItem, 1); } } } void TextWidget::change (char* aText) { strcpy (text, aText); refreshWidget (); } void TextWidget::inverseDisplay () { inversedDisplay = 1; } void TextWidget::normalDisplay () { inversedDisplay = 0; boldDisplay = 0; } void TextWidget::setBoldDisplay () { boldDisplay = 1; } /* ---------------------------------------------------- */ SelectableTextWidget::SelectableTextWidget (GraphicElement* anElement, int x0, int y0, char* aText) : TextWidget (anElement, x0, y0, aText) { } SelectableTextWidget::~SelectableTextWidget () { } actionType SelectableTextWidget::manageEvent (XEvent anEvent) { report = anEvent; switch (report.type) { case Expose: manageRefreshEvent (); return noAction; break; case ButtonPress: if (report.xbutton.window == win) return buttonPressed; break; default: break; } return noAction; } /* ---------------------------------------------------- */ GraphicWindow::GraphicWindow (GraphicElement* anElement, int x0, int y0, unsigned int aWidth, unsigned int aHeight, fonctionStateType aFonctionState, long anEventMask, colorType aBackgroundColor) : GraphicWidget (anElement, x0, y0, aWidth, aHeight, 0, aBackgroundColor, aBackgroundColor, anEventMask, aFonctionState) { } GraphicWindow::~GraphicWindow () { } actionType GraphicWindow::manageEvent (XEvent anEvent) { report = anEvent; switch (report.type) { case Expose: return manageRefreshEvent (); break; case ButtonPress: if (report.xbutton.window == win) { if (report.xbutton.button == Button1) { return button1Pressed; } else if (report.xbutton.button == Button2) { return button2Pressed; } else if (report.xbutton.button == Button3) { return button3Pressed; } } return noAction; break; default: return noAction; break; } } int GraphicWindow::shouldBeRefreshed () { XEvent aReport; if (XCheckWindowEvent (display, win, ExposureMask, &aReport)) { return 1; } else { return 0; } } actionType GraphicWindow::manageRefreshEvent () { if (report.xexpose.window == win) { return mustBeRefreshed; } else return noAction; } /* ---------------------------------------------------- */ DialogBox::DialogBox (Interface* toBeRefreshedInterface, int x0, int y0, int aWidth, int aHeight, char* DBWLabel, char* DBILabel, char* aText, char* choice1, Display* aDisplay) : Interface (x0, y0, aWidth, aHeight, 1, DBWLabel, DBILabel, aDisplay) { toBeRefreshed = toBeRefreshedInterface; choiceNumber = 1; theText = new TextWidget (this, (int)((width-strlen (aText)*9)/2), 40, aText); choiceButton1 = new Button (this, (int)((width-110)/2), 90, 110, 25, choice1, centerJustified, enabled); } DialogBox::DialogBox (Interface* toBeRefreshedInterface, int x0, int y0, int aWidth, int aHeight, char* DBWLabel, char* DBILabel, char* aText, char* choice1, char* choice2, Display* aDisplay) : Interface (x0, y0, aWidth, aHeight, 1, DBWLabel, DBILabel, aDisplay) { unsigned int border, space; toBeRefreshed = toBeRefreshedInterface; choiceNumber = 2; space = 20; border = (int)((width-110*choiceNumber-space*(choiceNumber-1))/2); theText = new TextWidget (this, (int)((width-strlen (aText)*9)/2), 40, aText); choiceButton1 = new Button (this, border, 90, 110, 25, choice1, centerJustified, enabled); choiceButton2 = new Button (this, border+110+space, 90, 110, 25, choice2, centerJustified, enabled); } DialogBox::DialogBox (Interface* toBeRefreshedInterface, int x0, int y0, int aWidth, int aHeight, char* DBWLabel, char* DBILabel, char* aText, char* choice1, char* choice2, char* choice3, Display* aDisplay) : Interface (x0, y0, aWidth, aHeight, 1, DBWLabel, DBILabel, aDisplay) { unsigned int border, space; toBeRefreshed = toBeRefreshedInterface; choiceNumber = 3; space = 20; border = (int)((width-110*choiceNumber-space*(choiceNumber-1))/2); theText = new TextWidget (this, (int)((width-strlen (aText)*9)/2), 40, aText); choiceButton1 = new Button (this, border, 90, 110, 25, choice1, centerJustified, enabled); choiceButton2 = new Button (this, border+110+space, 90, 110, 25, choice2, centerJustified, enabled); choiceButton3 = new Button (this, border+2*(110+space), 90, 110, 25, choice3, centerJustified, enabled); } DialogBox::DialogBox (Interface* toBeRefreshedInterface, int x0, int y0, int aWidth, int aHeight, char* DBWLabel, char* DBILabel, char* aText, char* choice1, char* choice2, char* choice3, char* choice4, Display* aDisplay) : Interface (x0, y0, aWidth, aHeight, 1, DBWLabel, DBILabel, aDisplay) { unsigned int border, space; toBeRefreshed = toBeRefreshedInterface; choiceNumber = 4; space = 20; border = (int)((width-110*choiceNumber-space*(choiceNumber-1))/2); theText = new TextWidget (this, (int)((width-strlen (aText)*9)/2), 40, aText); choiceButton1 = new Button (this, border, 90, 110, 25, choice1, centerJustified, enabled); choiceButton2 = new Button (this, border+110+space, 90, 110, 25, choice2, centerJustified, enabled); choiceButton3 = new Button (this, border+2*(110+space), 90, 110, 25, choice3, centerJustified, enabled); choiceButton4 = new Button (this, border+3*(110+space), 90, 110, 25, choice4, centerJustified, enabled); } DialogBox::~DialogBox () { delete theText; if (choiceNumber == 1) { delete choiceButton1; } else if (choiceNumber == 2) { delete choiceButton1; delete choiceButton2; } else if (choiceNumber == 3) { delete choiceButton1; delete choiceButton2; delete choiceButton3; } else if (choiceNumber == 4) { delete choiceButton1; delete choiceButton2; delete choiceButton3; delete choiceButton4; } } unsigned int DialogBox::manageDialogBox () { XEvent aReport; long mask; int end=0; int returnedValue; returnedValue = 0; /* needed by g++ -O2 */ mask = ExposureMask | ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask; while (!end) { XMaskEvent (display, mask, &aReport); theText->manageEvent (aReport); if (choiceNumber == 1) { if (choiceButton1->manageEvent (aReport) == buttonPressed) { returnedValue = 0; end = 1; } } else if (choiceNumber == 2) { if (choiceButton1->manageEvent (aReport) == buttonPressed) { returnedValue = 0; end = 1; } else if (choiceButton2->manageEvent (aReport) == buttonPressed) { returnedValue = 1; end = 1; } } else if (choiceNumber == 3) { if (choiceButton1->manageEvent (aReport) == buttonPressed) { returnedValue = 0; end = 1; } else if (choiceButton2->manageEvent (aReport) == buttonPressed) { returnedValue = 1; end = 1; } else if (choiceButton3->manageEvent (aReport) == buttonPressed) { returnedValue = 2; end = 1; } } else if (choiceNumber == 4) { if (choiceButton1->manageEvent (aReport) == buttonPressed) { returnedValue = 0; end = 1; } else if (choiceButton2->manageEvent (aReport) == buttonPressed) { returnedValue = 1; end = 1; } else if (choiceButton3->manageEvent (aReport) == buttonPressed) { returnedValue = 2; end = 1; } else if (choiceButton4->manageEvent (aReport) == buttonPressed) { returnedValue = 3; end = 1; } } if (aReport.type == Expose) toBeRefreshed->refresh (); } /* while (!end) */ return returnedValue; } void DialogBox::refresh () { } /* ---------------------------------------------------- */ InfoBox::InfoBox (Interface* toBeRefreshedInterface, int x0, int y0, int aWidth, int aHeight, char* IBWLabel, char* IBILabel, char* aText, int isAbortable) : Interface (x0, y0, aWidth, aHeight, 1, IBWLabel, IBILabel) { XEvent aReport; toBeRefreshed = toBeRefreshedInterface; abortable = isAbortable; stat = 0; theText = new TextWidget (this, (int)((width-strlen (aText)*9)/2), 40, aText); statWindow = new GraphicWindow (this, 30, 70, width-60, 25, enabled, ExposureMask, Black); if (abortable) { abortButton = new Button (this, (unsigned int)(width-100)/2, 115, 100, 25, "Abort", centerJustified, enabled); } XWindowEvent (display, win, ExposureMask, &aReport); if (XCheckWindowEvent (display, theText->win, ExposureMask, &aReport)) { theText->manageEvent (aReport); } if (abortable) { if (XCheckWindowEvent (display, abortButton->win, ExposureMask | ButtonPressMask | ButtonReleaseMask, &aReport)) { abortButton->manageEvent (aReport); } } if (XCheckWindowEvent (display, theText->win, ExposureMask, &aReport)) { theText->manageEvent (aReport); } refreshStatWindow (); } InfoBox::~InfoBox () { // XFlush(display); if (abortable) { delete abortButton; } delete theText; delete statWindow; } void InfoBox::setStatWindow (double val) { stat = val; } int InfoBox::refreshStatWindow () { XEvent aReport; int returnedValue; returnedValue = 0; XSetForeground (display, *gc, color[White]); XDrawRectangle (display, statWindow->win, *gc, 0, 0, width-61, 24); XSetForeground (display, *gc, color[Red]); XFillRectangle (display, statWindow->win, *gc, 1, 1, (unsigned int)(stat*(double)(width-62)), 23); // XCheckWindowEvent (display, statWindow->win, ExposureMask, &aReport); if (XCheckWindowEvent (display, theText->win, ExposureMask, &aReport)) { theText->manageEvent (aReport); } if (abortable) { if (XCheckWindowEvent (display, abortButton->win, ExposureMask | ButtonPressMask | ButtonReleaseMask, &aReport)) { if (abortButton->manageEvent (aReport) == buttonPressed) { returnedValue = 1; } } } if (toBeRefreshed != NULL) toBeRefreshed->refresh (); XSync (display, False); return returnedValue; } void InfoBox::refresh () { } /* ---------------------------------------------------- */ MenuEnum::MenuEnum () { number = 0; maxLenght = 0; } MenuEnum::~MenuEnum () { } void MenuEnum::addContent (char* aContent) { strcpy (choice[number], aContent); number++; if (strlen (aContent) > maxLenght) { maxLenght = strlen (aContent); } } unsigned int MenuEnum::getNumber () { return number; } unsigned int MenuEnum::getMaxLenght () { return maxLenght; } char* MenuEnum::getContent(unsigned int index) { if (index 0) { for (i=0; i<(int)columnsNumber; i++) { content[linesNumber][i] = new char[columnSize[i]+1]; if (columnType[i] == CharType) { addData (linesNumber, i, " "); } else if (columnType[i] == DoubleType) { addData (linesNumber, i, 0.0); } else if (columnType[i] == IntType) { addData (linesNumber, i, 0); } } linesNumber++; return (linesNumber-1); } else { printf ("Error: no existing columns\n"); return -1; } } else { printf ("Error: max lines reached\n"); return -1; } } void ArrayContent::removeLine (unsigned int line) { int i,j; for (i=line; i<(int)linesNumber-1; i++) { for (j=1; j<(int)columnsNumber; j++) { strcpy (content[i][j], content[i+1][j]); } } for (j=0; j<(int)columnsNumber; j++) { delete[] content[linesNumber-1][j]; } linesNumber--; } void ArrayContent::print () { int i,j; char temp[80]; printf ("Debugging ArrayContent [maxColumns: %d maxLines: %d]\n", maxColumnsNumber, maxLinesNumber); printf ("current size: [columns: %d lines: %d]\n", columnsNumber, linesNumber); printf ("***************************************************************\n"); for (i=0; i<(int)columnsNumber; i++) { if (columnType[i] == CharType) sprintf (temp, "%s [C/%d] |", columnTitle[i], columnSize[i]); else if (columnType[i] == DoubleType) sprintf (temp, "%s [D/%d] |", columnTitle[i], columnSize[i]); else if (columnType[i] == IntType) sprintf (temp, "%s [I/%d] | ", columnTitle[i], columnSize[i]); printf ("%s", temp); } printf ("\n"); printf ("***************************************************************\n"); for (j=0; j<(int)linesNumber; j++) { for (i=0; i<(int)columnsNumber; i++) { printf ("%s | ", content[j][i]); } printf ("\n"); } } void ArrayContent::addData (unsigned int line, unsigned int column, char* aContent) { if (columnType[column] == CharType) { if ((lineprint (); for (i=0; i<256; i++) { blank[i] = ' '; } bar1 = new HorizontalBar (this, 10, 5, width-20); bar2 = new HorizontalBar (this, 10, 35, width-20); bar3 = new HorizontalBar (this, 10, height-40, width-20); bar4 = new HorizontalBar (this, 10, height-2, width-20); previousPageButton = new Button (this, width-200, height-32, 90, 25, "Previous", centerJustified, enabled); nextPageButton = new Button (this, width-100, height-32, 90, 25, "Next", centerJustified, enabled); upButton = new UpArrow (this, 10, height-32 , enabled); downButton = new DownArrow (this, 40, height-32 , enabled); numberOfLines = (unsigned int)((height-80)/18-1); lenghtOfLine = (unsigned int)((width-40)/9); blank[lenghtOfLine] = '\0'; titleLine = new TextWidget(this, 20, 15, blank); textPanel = new GraphicWindow (this, 10, 45, width-20, height-90, enabled, ExposureMask, LightGrey); textLine = new SelectableTextWidget*[numberOfLines]; for (i=0; igetColumnsNumber (); i++) { strcpy (temp2, arrayContent->getColumnTitle (i)); for (j=0; j<(int)strlen (temp2); j++) { temp[k+j] = temp2[j]; } k = k+arrayContent->getColumnSize (i)+1; } titleLine->change (temp); if (arrayContent->getLinesNumber () == 0) { currentLine = -1; } else { currentLine = 0; } firstLine = 0; setTextLines (); refreshTextLines (); } ArrayWindow::~ArrayWindow () { int i; delete bar1; delete bar2; delete bar3; delete bar4; delete upButton; delete downButton; delete nextPageButton; delete previousPageButton; delete titleLine; for (i=0; i= 0) && (line < (int)arrayContent->getLinesNumber ())) { firstLine = line; setTextLines (); } else { printf ("ERROR: wrong line number\n"); } } void ArrayWindow::setTextLine (unsigned int line) { unsigned int i, j, k; char temp[256]; char temp2[256]; if (line < arrayContent->getLinesNumber ()) { strcpy (temp, blank); k = 0; for (i=0; igetColumnsNumber (); i++) { strcpy (temp2, arrayContent->getCharContent (line, i)); for (j=0; jgetColumnSize (i)+1; } } else { strcpy (temp, blank); } textLine[line-firstLine]->change (temp); } void ArrayWindow::setTextLines () { int i, j, k, line; char temp[256]; char temp2[256]; for (line=firstLine; linegetLinesNumber ()) { strcpy (temp, blank); k = 0; for (i=0; i<(int)arrayContent->getColumnsNumber (); i++) { strcpy (temp2, arrayContent->getCharContent (line, i)); for (j=0; j<(int)strlen (temp2); j++) { temp[k+j] = temp2[j]; } k = k+arrayContent->getColumnSize (i)+1; } } else { strcpy (temp, blank); } textLine[line-firstLine]->change (temp); } if (currentLine >= 0) { textLine[currentLine]->inverseDisplay (); } } void ArrayWindow::refreshTextLines () { int i; for (i=0; irefreshWidget (); } } void ArrayWindow::refreshAll () { // XUnmapWindow (display, textPanel->win); setTextLines (); refreshTextLines (); // XMapWindow (display, textPanel->win); } void ArrayWindow::reset () { if (currentLine != -1) textLine[currentLine]->normalDisplay (); currentLine = -1; firstLine = 0; } void ArrayWindow::refresh () { XEvent aReport; int i; if (XCheckWindowEvent (display, win, ExposureMask, &aReport)) { textPanel->refresh (); bar1->refresh (); bar2->refresh (); bar3->refresh (); bar4->refresh (); upButton->refresh (); downButton->refresh (); nextPageButton->refresh (); previousPageButton->refresh (); for (i=0; irefresh (); } titleLine->refresh (); } } actionType ArrayWindow::manageEvent (XEvent anEvent) { int i; time_t newTime; actionType returnedActionType; /* le type d'evenement qu'on va retourner a la fin */ report = anEvent; returnedActionType = noAction; bar1->manageEvent (report); bar2->manageEvent (report); bar3->manageEvent (report); bar4->manageEvent (report); if (upButton->manageEvent (report) == buttonPressed) { if (firstLine > 0) { firstLine--; setTextLines (); returnedActionType = selectionChanged; } }; if (downButton->manageEvent (report) == buttonPressed) { if (firstLine < (int)arrayContent->getLinesNumber ()-1) { firstLine++; if (currentLine+firstLine >= (int)arrayContent->getLinesNumber ()) { if (currentLine != -1) textLine[currentLine]->normalDisplay (); currentLine = arrayContent->getLinesNumber ()-firstLine-1; if (currentLine > -1) textLine[currentLine]->inverseDisplay (); } setTextLines (); returnedActionType = selectionChanged; } }; if (nextPageButton->manageEvent (report) == buttonPressed) { if (firstLine < ((int)arrayContent->getLinesNumber ()-numberOfLines-1)) { /* on caste avec int sinon la comparaison n'est plus fiable */ firstLine = firstLine + numberOfLines; if (currentLine+firstLine >= (int)arrayContent->getLinesNumber ()) { if (currentLine != -1) textLine[currentLine]->normalDisplay (); currentLine = arrayContent->getLinesNumber ()-firstLine-1; textLine[currentLine]->inverseDisplay (); } setTextLines (); returnedActionType = selectionChanged; } }; if (previousPageButton->manageEvent (report) == buttonPressed) { if (firstLine >= numberOfLines) { firstLine = firstLine - numberOfLines; setTextLines (); returnedActionType = selectionChanged; } }; titleLine->manageEvent (report); for (i=0; imanageEvent (report) == buttonPressed) && (selectionEnabled)) { if (i+firstLine < (int)arrayContent->getLinesNumber ()) { if (currentLine != -1) textLine[currentLine]->normalDisplay (); currentLine = i; textLine[currentLine]->inverseDisplay (); refreshTextLines (); newTime = time (0); if ((newTime-previousTime == 0) && (previousSelected == i)) { returnedActionType = doubleClick; } else { returnedActionType = selectionChanged; } previousTime = newTime; previousSelected = i; } } } return returnedActionType; } void ArrayWindow::manageRefreshEvent () { } int ArrayWindow::addLine () { int returned; returned = arrayContent->addLine (); refreshAll (); return returned; } void ArrayWindow::removeLine (unsigned int line) { arrayContent->removeLine (line); if (arrayContent->getLinesNumber () == 0) { if (currentLine != -1) textLine[currentLine]->normalDisplay (); currentLine = -1; refreshAll (); } else if (currentLine+firstLine >= (int)arrayContent->getLinesNumber ()) { if (currentLine != -1) textLine[currentLine]->normalDisplay (); currentLine = arrayContent->getLinesNumber ()-firstLine-1; if (currentLine > -1) textLine[currentLine]->inverseDisplay (); } refreshAll (); } void ArrayWindow::addData (unsigned int line, unsigned int column, char* aChar) { arrayContent->addData (line, column, aChar); if ((int)line-firstLine < numberOfLines) { textLine[line-firstLine]->refreshWidget (); setTextLine (line); } } void ArrayWindow::addData (unsigned int line, unsigned int column, int aInt) { arrayContent->addData (line, column, aInt); if ((int)line-firstLine < numberOfLines) { textLine[line-firstLine]->refreshWidget (); setTextLine (line); } } void ArrayWindow::addData (unsigned int line, unsigned int column, double aDouble) { arrayContent->addData (line, column, aDouble); if ((int)line-firstLine < numberOfLines) { textLine[line-firstLine]->refreshWidget (); setTextLine (line); } } int ArrayWindow::getSelectedLine () /* -1 when no selected */ { if (currentLine != -1) { return (currentLine+firstLine); } else { return -1; } } int ArrayWindow::setSelectedLine () /* -1 when no selected */ { if (arrayContent->getLinesNumber () == 0) { if (currentLine != -1) textLine[currentLine]->normalDisplay (); currentLine = -1; refreshAll (); } else if (currentLine+firstLine >= (int)arrayContent->getLinesNumber ()) { if (currentLine != -1) textLine[currentLine]->normalDisplay (); currentLine = arrayContent->getLinesNumber ()-firstLine-1; if (currentLine > -1) textLine[currentLine]->inverseDisplay (); } refreshAll (); return getSelectedLine (); } /* ---------------------------------------------------- */ TextInput::TextInput (GraphicElement* anElement, int x0, int y0, unsigned int aWidth, /* max nb of input cars */ char* aLabel, char* initValue, fonctionStateType aFonctionState) : GraphicWidget (anElement, x0+9*(strlen(aLabel)+1), y0-2, 5+9*(aWidth+1), 19, 0, LightGrey, LightGrey, ExposureMask | ButtonPressMask | KeyPressMask| KeyReleaseMask, aFonctionState) { anElement->textInputLinks.addLink (this); enumerationMode = 0; charValue = initValue; varType = CharType; strncpy (label, aLabel, 50); strncpy (value, initValue, 100); labelWidget = new TextWidget (anElement, x0, y0, label); cursorPos = strlen (initValue); editing = 0; insertMode = 1; decal = 0; maxWidth = aWidth; if (cursorPos > (int)maxWidth) { decal = cursorPos-maxWidth; } textCursor = XCreateFontCursor (display, XC_xterm); XDefineCursor (display, win, textCursor); } TextInput::TextInput (GraphicElement* anElement, int x0, int y0, unsigned int aWidth, /* max nb of input cars */ char* aLabel, int* initValue, fonctionStateType aFonctionState) : GraphicWidget (anElement, x0+9*(strlen(aLabel)+1), y0-2, 5+9*(aWidth+1), 19, 0, LightGrey, LightGrey, ExposureMask | ButtonPressMask | KeyPressMask| KeyReleaseMask, aFonctionState) { char temp[30]; anElement->textInputLinks.addLink (this); enumerationMode = 0; intValue = initValue; varType = IntType; sprintf (temp, "%d", *initValue); strncpy (label, aLabel, 50); strncpy (value, temp, 100); labelWidget = new TextWidget (anElement, x0, y0, label); cursorPos = strlen (temp); editing = 0; insertMode = 1; decal = 0; maxWidth = aWidth; if (cursorPos > (int)maxWidth) { decal = cursorPos-maxWidth; } textCursor = XCreateFontCursor (display, XC_xterm); XDefineCursor (display, win, textCursor); } TextInput::TextInput (GraphicElement* anElement, int x0, int y0, unsigned int aWidth, /* max nb of input cars */ char* aLabel, long* initValue, fonctionStateType aFonctionState) : GraphicWidget (anElement, x0+9*(strlen(aLabel)+1), y0-2, 5+9*(aWidth+1), 19, 0, LightGrey, LightGrey, ExposureMask | ButtonPressMask | KeyPressMask| KeyReleaseMask, aFonctionState) { char temp[30]; anElement->textInputLinks.addLink (this); enumerationMode = 0; longValue = initValue; varType = LongType; sprintf (temp, "%ld", *initValue); strncpy (label, aLabel, 50); strncpy (value, temp, 100); labelWidget = new TextWidget (anElement, x0, y0, label); cursorPos = strlen (temp); editing = 0; insertMode = 1; decal = 0; maxWidth = aWidth; if (cursorPos > (int)maxWidth) { decal = cursorPos-maxWidth; } textCursor = XCreateFontCursor (display, XC_xterm); XDefineCursor (display, win, textCursor); } TextInput::TextInput (GraphicElement* anElement, int x0, int y0, unsigned int aWidth, /* max nb of input cars */ char* aLabel, double* initValue, fonctionStateType aFonctionState) : GraphicWidget (anElement, x0+9*(strlen(aLabel)+1), y0-2, 5+9*(aWidth+1), 19, 0, LightGrey, LightGrey, ExposureMask | ButtonPressMask | KeyPressMask| KeyReleaseMask, aFonctionState) { char temp[50]; anElement->textInputLinks.addLink (this); enumerationMode = 0; doubleValue = initValue; varType = DoubleType; sprintf (temp, "%f", *initValue); strncpy (label, aLabel, 50); strncpy (value, temp, 100); labelWidget = new TextWidget (anElement, x0, y0, label); cursorPos = strlen (temp); editing = 0; insertMode = 1; decal = 0; maxWidth = aWidth; if (cursorPos > (int)maxWidth) { decal = cursorPos-maxWidth; } textCursor = XCreateFontCursor (display, XC_xterm); XDefineCursor (display, win, textCursor); } TextInput::TextInput (GraphicElement* anElement, /* enumeration */ int x0, int y0, unsigned int aWidth, /* nb of input cars */ char* aLabel, Enumeration* anEnumeration, fonctionStateType aFonctionState) : GraphicWidget (anElement, x0+9*(strlen(aLabel)+1), y0-2, 5+9*(aWidth+1), 19, 0, LightGrey, LightGrey, ExposureMask | ButtonPressMask | KeyPressMask| KeyReleaseMask, aFonctionState) { char temp[50]; anElement->textInputLinks.addLink (this); enumerationMode = 1; enumeration = anEnumeration; // enumerationValue = &(enumeration->defaultValue ()); varType = EnumType; strcpy (temp, enumeration->getDefault ()); strncpy (label, aLabel, 50); strncpy (value, temp, 100); labelWidget = new TextWidget (anElement, x0, y0, label); cursorPos = strlen (temp); editing = 0; insertMode = 1; decal = 0; maxWidth = aWidth; if (cursorPos > (int)maxWidth) { decal = cursorPos-maxWidth; } textCursor = XCreateFontCursor (display, XC_xterm); XDefineCursor (display, win, textCursor); } TextInput::~TextInput () { delete labelWidget; } char* TextInput::returnLabel () { return label; } void TextInput::refresh () { XEvent aReport; labelWidget->refresh (); if (XCheckWindowEvent (display, win, ExposureMask, &aReport)) { refreshValue (); } } void TextInput::changeIntValue (int* initValue) { char temp[256]; if (varType == IntType) { sprintf (temp, "%d", *initValue); strncpy (value, temp, 100); cursorPos = strlen (temp); editing = 0; insertMode = 1; decal = 0; if (cursorPos > (int)maxWidth) { decal = cursorPos-maxWidth; } refreshValue (); } else { printf ("Error: type mismatch in TextInput\n"); } } void TextInput::changeLongValue (long* initValue) { char temp[256]; if (varType == LongType) { sprintf (temp, "%ld", *initValue); strncpy (value, temp, 100); cursorPos = strlen (temp); editing = 0; insertMode = 1; decal = 0; if (cursorPos > (int)maxWidth) { decal = cursorPos-maxWidth; } refreshValue (); } else { printf ("Error: type mismatch in TextInput\n"); } } void TextInput::changeDoubleValue (double* initValue) { char temp[256]; if (varType == DoubleType) { sprintf (temp, "%f", *initValue); strncpy (value, temp, 100); cursorPos = strlen (temp); editing = 0; insertMode = 1; decal = 0; if (cursorPos > (int)maxWidth) { decal = cursorPos-maxWidth; } refreshValue (); } else { printf ("Error: type mismatch in TextInput\n"); } } void TextInput::changeCharValue (char* initValue) { if (varType == CharType) { strncpy (value, initValue, 100); cursorPos = strlen (initValue); editing = 0; insertMode = 1; decal = 0; if (cursorPos > (int)maxWidth) { decal = cursorPos-maxWidth; } refreshValue (); } else { printf ("Error: type mismatch in TextInput\n"); } } void TextInput::changeEnumValue (int initValue) { /* USELESS char temp[256]; */ if (varType == EnumType) { enumeration->setDefault (initValue); strcpy (value, enumeration->getDefault ()); cursorPos = strlen (value); refreshValue (); } else { printf ("Error: type mismatch in TextInput\n"); } } void TextInput::editText () { editing = 1; refreshValue (); } void TextInput::uneditText () { editing = 0; refreshValue (); } actionType TextInput::manageEvent (XEvent anEvent) { /* USELESS actionType anAction; */ report = anEvent; if (fonctionState == enabled) { switch (report.type) { case Expose: manageRefreshEvent (); break; case ButtonPress: manageButtonPressEvent (); break; case ButtonRelease: manageButtonReleaseEvent (); break; case KeyPress: if (manageKeyPressEvent () == returnPressed) { return returnPressed; } break; case KeyRelease: manageKeyReleaseEvent (); break; default: break; } } else { switch (report.type) { case Expose: manageRefreshEvent (); break; default: break; } } return noAction; } void TextInput::refreshLabel () { labelWidget->manageEvent (report); } void TextInput::refreshValue () { XClearWindow (display, win); XSetBackground (display, *gc, color[backgroundColor]); if (fonctionState == enabled) { XSetForeground (display, *gc, color[Black]); } else { XSetForeground (display, *gc, color[HardGrey]); } XDrawImageString (display, win, *gc, 0, 14, &value[decal], strlen(value)); if (editing) { XSetBackground (display, *gc, color[Black]); XSetForeground (display, *gc, color[White]); if (cursorPos >= (int)strlen(value)) { XDrawImageString (display, win, *gc, (cursorPos-decal)*9, 14, " ", 1); } else if (cursorPos >= 0) { XDrawImageString (display, win, *gc, (cursorPos-decal)*9, 14, &value[cursorPos], 1); } } } void TextInput::manageRefreshEvent () { refreshLabel (); if (report.xexpose.window == win) { refreshValue (); } } void TextInput::manageButtonPressEvent () { int textInputIndex; TextInputLinks* link; int i; if (report.xbutton.window == win) { /* editing = 1; previous->printLinks (); refreshValue (); */ /* il s'agit ici de gerer les dependances entre les differents TextInput de la fenetre */ link = &(previous->textInputLinks); textInputIndex = -1; for (i=0; inumber; i++) { if (link->getLink (i) == this) { textInputIndex = i; } } if (textInputIndex == -1) { printf ("ERROR: problem in link definition\n"); } else { if (link->isEdited == 1) { /* si un TextInput est edite deja... */ (link->getCurrentLink ())->uneditText (); link->current = textInputIndex; (link->getCurrentLink ())->editText (); } else { link->isEdited = 1; link->current = textInputIndex; (link->getCurrentLink ())->editText (); } } } } void TextInput::manageButtonReleaseEvent () { if (report.xbutton.window == win) { } } actionType TextInput::manageKeyPressEvent () { char code[20]; char code2[20]; char c; int i; int len; KeySym aKeySym; XComposeStatus status; if ((report.xkey.window == win) && editing) { /* on appuie sur une touche */ strcpy (code, XKeysymToString(XKeycodeToKeysym (display, report.xkey.keycode, 0))); // printf ("code: %s\n", code); len = XLookupString (&(report.xkey), code2, 20, &aKeySym, &status); if (!enumerationMode) { // printf ("Code [%s] Code2 [%s]\n", code, code2); if (!strcmp (code, "Shift_L")) { } else if (!strcmp (code, "Shift_R")) { } else if (!strcmp (code, "Return")) { editing = 0; refreshValue (); return returnPressed; } else if (!strcmp (code, "Up")) { editing = 0; refreshValue (); return upKeyPressed; } else if (!strcmp (code, "Down")) { editing = 0; refreshValue (); return downKeyPressed; } else if (!strcmp (code, "Left")) { if (cursorPos > 0) { cursorPos--; if (cursorPos > (int)maxWidth) { decal = cursorPos-maxWidth; } refreshValue (); } } else if (!strcmp (code, "Right")) { if (cursorPos < (int)strlen(value)) { cursorPos++; if (cursorPos > (int)maxWidth) { decal = cursorPos-maxWidth; } refreshValue (); } } else if ((!strcmp (code, "KP_Insert")) || (!strcmp (code, "Insert"))){ insertMode = (int)(!insertMode); } else if ((!strcmp (code, "BackSpace")) || (!strcmp (code, "Delete"))) { if (cursorPos == (int)strlen(value)) { if (cursorPos > 0) { value[cursorPos-1] = '\0'; cursorPos--; refreshValue (); } } else { for (i=cursorPos-1; i<(int)strlen(value)-1; i++) { value[i] = value[i+1]; } value[strlen(value)-1] = ' '; refreshValue (); value[strlen(value)-1] = '\0'; cursorPos--; refreshValue (); } } else if ((code2[0] >= 32) && (code2[0]<=126)) { /* insertion of new char */ c = code2[0]; if (cursorPos < 256) { value[cursorPos] = c; cursorPos++; if (cursorPos > (int)maxWidth) { decal = cursorPos-maxWidth; } } } refreshValue (); } else { /* enumeration mode */ if (!strcmp (code, "Return")) { editing = 0; refreshValue (); return returnPressed; } else if (!strcmp (code, "Up")) { editing = 0; refreshValue (); return upKeyPressed; } else if (!strcmp (code, "Down")) { editing = 0; refreshValue (); return downKeyPressed; } else if (!strcmp (code, "Left")) { enumeration->decDefault (); strcpy (value, enumeration->getDefault ()); cursorPos = strlen (value); refreshValue (); } else if (!strcmp (code, "Right")) { enumeration->incDefault (); strcpy (value, enumeration->getDefault ()); cursorPos = strlen (value); refreshValue (); } } } return noAction; } void TextInput::manageKeyReleaseEvent () { // XFlush (display); } int TextInput::returnEnumerateValue () { return enumeration->defaultValue (); } int TextInput::returnIntValue () { return atoi (value); } long TextInput::returnLongValue () { return atol (value); } double TextInput::returnDoubleValue () { return atof (value); } char* TextInput::returnCharValue () { return value; } void TextInput::enable () { fonctionState = enabled; refreshValue (); } void TextInput::disable () { fonctionState = disabled; uneditText (); refreshValue (); } /* ---------------------------------------------------- */ InputDialogBox::InputDialogBox (Interface* toBeRefreshedInterface, int x0, int y0, int aWidth, int aHeight, unsigned inputNb, char* DBWLabel, char* DBILabel) : Interface (x0, y0, aWidth, aHeight, 1, DBWLabel, DBILabel, toBeRefreshedInterface->display) { toBeRefreshed = toBeRefreshedInterface; acceptButton = new Button (this, (int)((width-220)/2), height-50, 90, 25, "Accept", centerJustified, enabled); cancelButton = new Button (this, (int)((width-220)/2+130), height-50, 90, 25, "Cancel", centerJustified, enabled); input = new TextInput*[inputNb]; current = 0; } InputDialogBox::~InputDialogBox () { int i; for (i=current-1; i>=0; i--) { delete input[i]; } delete input; delete acceptButton; delete cancelButton; } void InputDialogBox::addIntInput (char* aLabel, unsigned int aMaxWidth, int* returnedInt) { input[current] = new TextInput (this, 30, 30+current*30, aMaxWidth, aLabel, returnedInt, enabled); current++; } void InputDialogBox::addLongInput (char* aLabel, unsigned int aMaxWidth, long* returnedLong) { input[current] = new TextInput (this, 30, 30+current*30, aMaxWidth, aLabel, returnedLong, enabled); current++; } void InputDialogBox::addDoubleInput (char* aLabel, unsigned int aMaxWidth, double* returnedDouble) { input[current] = new TextInput (this, 30, 30+current*30, aMaxWidth, aLabel, returnedDouble, enabled); current++; } void InputDialogBox::addCharInput (char* aLabel, unsigned int aMaxWidth, char* returnedChar) { input[current] = new TextInput (this, 30, 30+current*30, aMaxWidth, aLabel, returnedChar, enabled); current++; } void InputDialogBox::addEnumInput (char* aLabel, unsigned int aMaxWidth, Enumeration* anEnumeration) { input[current] = new TextInput (this, 30, 30+current*30, aMaxWidth, aLabel, anEnumeration, enabled); current++; } void InputDialogBox::addIntInput (char* aLabel, unsigned int aMaxWidth, int* returnedInt, fonctionStateType aFonctionState) { input[current] = new TextInput (this, 30, 30+current*30, aMaxWidth, aLabel, returnedInt, aFonctionState); current++; } void InputDialogBox::addLongInput (char* aLabel, unsigned int aMaxWidth, long* returnedLong, fonctionStateType aFonctionState) { input[current] = new TextInput (this, 30, 30+current*30, aMaxWidth, aLabel, returnedLong, aFonctionState); current++; } void InputDialogBox::addDoubleInput (char* aLabel, unsigned int aMaxWidth, double* returnedDouble, fonctionStateType aFonctionState) { input[current] = new TextInput (this, 30, 30+current*30, aMaxWidth, aLabel, returnedDouble, aFonctionState); current++; } void InputDialogBox::addCharInput (char* aLabel, unsigned int aMaxWidth, char* returnedChar, fonctionStateType aFonctionState) { input[current] = new TextInput (this, 30, 30+current*30, aMaxWidth, aLabel, returnedChar, aFonctionState); current++; } void InputDialogBox::addEnumInput (char* aLabel, unsigned int aMaxWidth, Enumeration* anEnumeration, fonctionStateType aFonctionState) { input[current] = new TextInput (this, 30, 30+current*30, aMaxWidth, aLabel, anEnumeration, aFonctionState); current++; } unsigned int InputDialogBox::manageInputDialogBox () { XEvent aReport; int i; long mask1; /* pour l'interface InputDialogBox */ int end=0; int returnedValue; returnedValue = 0; /* needed by g++ -O2 */ mask1 = ExposureMask | ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask; while (!end) { XMaskEvent (display, mask1, &aReport); if (acceptButton->manageEvent (aReport) == buttonPressed) { for (i=0; i<(int)current; i++) if (input[i]->varType == CharType) strcpy (input[i]->charValue, input[i]->returnCharValue ()); else if (input[i]->varType == IntType) *(input[i]->intValue) = input[i]->returnIntValue (); else if (input[i]->varType == LongType) *(input[i]->longValue) = input[i]->returnLongValue (); else if (input[i]->varType == DoubleType) *(input[i]->doubleValue) = input[i]->returnDoubleValue (); returnedValue = 0; end = 1; }; if (cancelButton->manageEvent (aReport) == buttonPressed) { returnedValue = 1; end = 1; } for (i=0; i<(int)current; i++) input[i]->manageEvent (aReport); if (aReport.type == Expose) toBeRefreshed->refresh (); } /* while (!end) */ return returnedValue; } void InputDialogBox::refresh () { } /* ---------------------------------------------------- */ FileViewer::FileViewer (GraphicElement* anElement, int x0, int y0, unsigned int aWidth, unsigned int aHeight, fonctionStateType aFonctionState, colorType aBackgroundColor, char* aPathName, char* aFileName, char* title) { char aLine[256]; FILE *aFile; char fname[256]; int end; int nbLines, line; int i; char temp[256]; unsigned int nbCol; nbCol = (unsigned int) ((double)aWidth/9); strcpy (pathName, aPathName); strcpy (fileName, aFileName); strcpy (fname, pathName); strcat (fname, fileName); aFile = fopen(fname,"r"); nbLines = 0; if (aFile == NULL) { printf ("Error: unable to load file %s%s\n", pathName, fileName); } else { // printf ("Loading file %s%s\n", pathName, fileName); end = 0; while (!end) { if (fgets (aLine, 255, aFile) == NULL) { end = 1; } else { nbLines++; } } fclose (aFile); totalLine = nbLines; // printf ("File %s : %d lines\n", fileName, nbLines); } arrayContent = new ArrayContent (1, nbLines+1); arrayContent->addColumn (title, CharType, nbCol); aFile = fopen(fname,"r"); if (aFile == NULL) { printf ("Error: unable to load file %s%s\n", pathName, fileName); } else { for (i=0; iaddLine (); arrayContent->addData (line, 0, aLine); } fclose (aFile); } arrayWindow = new ArrayWindow (anElement, x0, y0, aWidth, aHeight, aFonctionState, aBackgroundColor, arrayContent); arrayWindow->disableSelection (); sprintf (temp, "(%d of %d)", totalLine, totalLine); currentLineText = new TextWidget (arrayWindow, 110, (int)(aHeight-27), temp); } FileViewer::~FileViewer () { delete currentLineText; delete arrayWindow; delete arrayContent; } actionType FileViewer::manageEvent (XEvent report) { char temp[256]; arrayWindow->manageEvent (report); currentLine = arrayWindow->getFirstLine (); sprintf (temp, "(%d of %d) ", currentLine, totalLine); currentLineText->change (temp); currentLineText->manageEvent (report); return noAction; /* a priori, ne retourne pas d'evenement */ } void FileViewer::refresh () { arrayWindow->refresh (); currentLineText->refresh (); } void FileViewer::reload () { printf ("ERROR: reload not implemented\n"); } void FileViewer::goToLine (int line) { arrayWindow->goToLine (line); } /* ---------------------------------------------------- */ Enumeration::Enumeration () { int i; number = 0; defaultIndex = 0; for (i=0; i 0 ) { defaultIndex--; } } void Enumeration::setDefault (int aDefaultValue) { if ((aDefaultValue >= 0) && (aDefaultValue < number)) { defaultIndex = aDefaultValue; } } void Enumeration::clear () { int i; number = 0; defaultIndex = 0; for (i=0; ireturnLabel ()); } } /* ---------------------------------------------------- */