File: BasicWidget.hxx

package info (click to toggle)
oonsoo 1.2-8
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,604 kB
  • ctags: 422
  • sloc: cpp: 24,373; makefile: 82
file content (114 lines) | stat: -rw-r--r-- 3,763 bytes parent folder | download | duplicates (2)
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
///////////////////////////////////////////////////////////////////////////////
// $Id: BasicWidget.hxx,v 1.1 1995/01/12 02:09:17 bmott Exp $
///////////////////////////////////////////////////////////////////////////////
//
// BasicWidget.hxx - Abstract base class for all widgets
//
//
// Bradford W. Mott
// Copyright (C) 1994
// December 11,1994
//
///////////////////////////////////////////////////////////////////////////////
// $Log: BasicWidget.hxx,v $
// Revision 1.1  1995/01/12  02:09:17  bmott
// Initial revision
//
///////////////////////////////////////////////////////////////////////////////

#ifndef BASICWIDGET_HXX
#define BASICWIDGET_HXX

#include <X11/Xos.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>

#include "Sprite.hxx"

class ContainerWidget;
class UIApplication;

// Enumerated type for widget's manage state
enum ManageState { Managed, Unmanaged };


class BasicWidget {
  private:
    int myX;                            // My X Coordinate relative to parent
    int myY;                            // My Y Coordinate relative to parent
    int myWidth;                        // My width in pixels
    int myHeight;                       // My height in pixels
    const char *const myName;           // My symbolic name
    ManageState myManageState;          // Indicates what state I'm in

  protected:
    unsigned long myForeground;         // My foreground color
    unsigned long myBackground;         // My background color
    unsigned long myBackgroundHigh;     // My background highlight color 
    unsigned long myBackgroundLow;      // My background lowlight color
    ContainerWidget *const myParent;    // A reference to my parent widget
    Window myWindow;                    // My only visual being

    // Protected constructor to prevent instantiation
    BasicWidget(ContainerWidget *const parent, const char *const name,
        int x, int y, int width, int height);

    // UIApplication needs access to the handleEvent and findWidget methods
    friend class UIApplication;

    // ContainerWidget needs access to the findWidget method
    friend class ContainerWidget;

    // Called whenever an event arrives for me
    virtual void handleEvent(XEvent* event);

    // Find the widget for the given window
    virtual BasicWidget* findWidget(Window window);

  public:
    virtual ~BasicWidget();

    // Manage the entire widget subtree that I represented
    virtual void manage();

    // Unmanage the entire widget subtree that I represented
    virtual void unmanage();

    // Answer my manage state
    const ManageState manageState() { return myManageState; }

    // Answer my name
    const char* name() const { return myName; }

    // Answer my window
    const Window window() const { return myWindow; }

    // Set my background to the named color
    virtual void background(const char* name);

    // Set my background to the given sprite
    virtual void background(const Sprite *const sprite);

    // Set my foreground to the named color
    virtual void foreground(const char* name);

    // Resize myself to the given width and height
    void resize(int width, int height);
 
    // Move myself to the given x and y location
    void move(int x, int y);

    unsigned long background() const { return myBackground; }
    unsigned long backgroundHigh() const { return myBackgroundHigh; }
    unsigned long backgroundLow() const { return myBackgroundLow; }
    unsigned long foreground() const { return myForeground; }
    int x() const { return myX; }
    int y() const { return myY; }
    int width() const { return myWidth; }
    int height() const { return myHeight; }

    // Answer my class
    virtual const char *const className() const { return("BasicWidget"); }
};
#endif