1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
///////////////////////////////////////////////////////////////////////////////
// $Id: UIApplication.cxx,v 1.3 1996/01/06 05:10:28 bwmott Exp $
///////////////////////////////////////////////////////////////////////////////
//
// UIApplication.cxx - User Interface application class
//
//
// Bradford W. Mott
// Copyright (C) 1994
// December 12,1994
//
///////////////////////////////////////////////////////////////////////////////
// $Log: UIApplication.cxx,v $
// Revision 1.3 1996/01/06 05:10:28 bwmott
// Changed all NULLs to 0
//
// Revision 1.2 1996/01/03 20:09:46 bwmott
// Changed default font names
//
// Revision 1.1 1995/01/08 06:52:35 bmott
// Initial revision
//
///////////////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <stdlib.h>
#include "UIApplication.hxx"
///////////////////////////////////////////////////////////////////////////////
// Global UIApplication object
///////////////////////////////////////////////////////////////////////////////
UIApplication* application;
///////////////////////////////////////////////////////////////////////////////
// Default fonts to try and load
///////////////////////////////////////////////////////////////////////////////
static char* defaultFontList[] = {
"-adobe-helvetica-medium-r-normal-*-*-140-*",
"-*-lucida-medium-r-normal-*-*-140-*",
"6x13",
"fixed",
(char*)0
};
///////////////////////////////////////////////////////////////////////////////
// Constructor
///////////////////////////////////////////////////////////////////////////////
UIApplication::UIApplication(int* argc, char** argv, char* name, Sound* sound)
: mySoundSystem(sound)
{
myDisplay = XOpenDisplay(0);
if(!myDisplay)
{
fprintf(stderr, "Can't open display.\n");
exit(1);
}
myScreen = DefaultScreen(myDisplay);
myRootWindow = RootWindow(myDisplay, myScreen);
done = 0;
// Load a default font for the application
myDefaultFont = 0;
for(int t = 0; defaultFontList[t] != 0; ++t)
{
myDefaultFont = XLoadQueryFont(myDisplay, defaultFontList[t]);
if(myDefaultFont != 0)
break;
}
// Make sure a font was loaded
if(myDefaultFont == 0)
{
fprintf(stderr, "Couldn't load a usable font!\n");
exit(1);
}
}
///////////////////////////////////////////////////////////////////////////////
// Destructor
///////////////////////////////////////////////////////////////////////////////
UIApplication::~UIApplication()
{
// Destroy any remaining toplevel widgets
for(TopLevel* top = listOfTopLevelWidgets.first();
top != (TopLevel*)0; top = listOfTopLevelWidgets.next())
{
delete top;
}
// If the display connection is open then close it
if(myDisplay)
{
XCloseDisplay(myDisplay);
}
// Tell the X Server that I'm finished with my font
if(myDefaultFont != 0)
{
XUnloadFont(myDisplay, myDefaultFont->fid);
}
}
///////////////////////////////////////////////////////////////////////////////
// Add widget to list of toplevel widgets in the application
///////////////////////////////////////////////////////////////////////////////
void UIApplication::addTopLevel(TopLevel* widget)
{
listOfTopLevelWidgets.append(widget);
}
///////////////////////////////////////////////////////////////////////////////
// Remove widget from list of toplevel widgets in the application
///////////////////////////////////////////////////////////////////////////////
void UIApplication::removeTopLevel(TopLevel* widget)
{
listOfTopLevelWidgets.remove(widget);
}
///////////////////////////////////////////////////////////////////////////////
// Dispatch the event to the correct widget
///////////////////////////////////////////////////////////////////////////////
void UIApplication::dispatchEvent(XEvent* event)
{
BasicWidget* widget;
// Dispatch the event to the correct widget
for(BasicWidget* t = listOfTopLevelWidgets.first();
t != (BasicWidget*) 0; t = listOfTopLevelWidgets.next())
{
widget = t->findWidget(event->xany.window);
if(widget != 0)
break;
}
// Send the event to the widget
if(widget != 0)
widget->handleEvent(event);
}
///////////////////////////////////////////////////////////////////////////////
// Event loop for the application
///////////////////////////////////////////////////////////////////////////////
void UIApplication::eventLoop()
{
while((!done) && (listOfTopLevelWidgets.size() != 0) )
{
XEvent event;
XNextEvent(myDisplay, &event);
dispatchEvent(&event);
}
}
|