1 /* classes.cxx
2 $Id: classes.cxx,v 1.16 1998/10/26 18:59:28 elf Exp $
3
4 written by Marc Singer
5 9 May 1997
6
7 This file is part of the project XO. See the file README for
8 more information.
9
10 Copyright (C) 1997 Marc Singer
11
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License as
14 published by the Free Software Foundation; either version 2 of the
15 License, or (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 in a file called COPYING along with this program; if not, write to
24 the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
25 02139, USA.
26
27 -----------
28 DESCRIPTION
29 -----------
30
31 */
32
33 #include "standard.h"
34 #include "ldisplay.h"
35 #include "lwindow.h"
36
37 #include "wbutton.h"
38 #include "wdialog.h"
39 #include "wtext.h"
40
41 extern bool g_fQuit;
42
43 class WTopLevel : public LWindow {
44 public:
WTopLevel(LDisplay * pDisplay)45 WTopLevel (LDisplay* pDisplay) : LWindow (pDisplay) {}
46 void child (XoChildNotifyEvent* pEvent);
47 };
48
49 //void eh_buttondown (LWindow* pWindow, XButtonEvent* pEvent);
50 //void eh_expose (LWindow* pWindow, XExposeEvent* pEvent);
51 //void eh_create (LWindow* pWindow, XoCreateSelfWindowEvent* pEvent);
52 //void eh_child (LWindow* pWindow, XoChildNotifyEvent* pEvent);
53
54 #if 0
55 EventHandlerMap g_rgEventHandlerMap[] = {
56 { ButtonPress, (PFNEvent) &eh_buttondown },
57 { Expose, (PFNEvent) &eh_expose },
58 { CreateSelfNotify, (PFNEvent) &eh_create },
59 { ChildNotify, (PFNEvent) &eh_child },
60 { 0, NULL },
61 };
62 #endif
63
64
child(XoChildNotifyEvent * pEvent)65 void WTopLevel::child (XoChildNotifyEvent* pEvent)
66 {
67 printf ("notify from 0x%lx\n", (long) pEvent->pvParentData);
68 if (pEvent->pvParentData == (void*) 1
69 && pEvent->child_type == ButtonPressNotify) {
70 XUnmapWindow (pEvent->display, pEvent->window);
71 g_fQuit = true;
72 }
73 else if (pEvent->pvParentData == (void*) 0x10001
74 && pEvent->child_type == ButtonPressNotify) {
75 // XUnmapWindow (pEvent->display, pEvent->window);
76 g_fQuit = true;
77 }
78 else if (pEvent->pvParentData == (void*) 0x10002
79 && pEvent->child_type == ButtonPressNotify) {
80 LWindow* pWindow = m_pDisplay->find_child (1);
81 pWindow = pWindow->find_child (3);
82 WTextEdit* pText = (WTextEdit*) pWindow;
83 printf ("Captured '%s'\n", pText->text ());
84 }
85 }
86
87 #if 0
88 void eh_create (LWindow* pWindow, XoCreateSelfWindowEvent* pEvent)
89 {
90 fprintf (stderr, "create self [%ld] window 0x%lx parent 0x%lx\n",
91 pEvent->serial,
92 pEvent->window, pEvent->parent);
93
94 LWindow* pWindowChild = new LWindow (pWindow->display()
95 ->find_template ("button"));
96 pWindowChild->owner (pWindow, (void*) 1);
97 pWindowChild->position (10, 10, 70, 40);
98 if (pWindowChild->create (pWindow))
99 pWindowChild->map ();
100 else
101 delete pWindowChild;
102 }
103
104
105 void eh_buttondown (LWindow* /* pWindow */, XButtonEvent* pEvent)
106 {
107 XUnmapWindow (pEvent->display, pEvent->window);
108 g_fQuit = true;
109 }
110
111
112 void eh_expose (LWindow* pWindow, XExposeEvent* pEvent)
113 {
114 fprintf (stderr, "expose serial %ld count %d [%d %d %d %d]\n",
115 pEvent->serial, pEvent->count,
116 pEvent->x, pEvent->y, pEvent->width, pEvent->height);
117
118 GC gc = pWindow->display ()->gc ();
119
120 // if (!pEvent->count)
121 // XSetState (pEvent->display, gc, 3, 0, GXcopy, AllPlanes);
122
123 XDrawLine (pEvent->display, pEvent->window, gc,
124 pEvent->x, pEvent->y,
125 pEvent->x + pEvent->width, pEvent->y + pEvent->height);
126 XDrawLine (pEvent->display, pEvent->window, gc,
127 pEvent->x + pEvent->width, pEvent->y,
128 pEvent->x, pEvent->y + pEvent->height);
129 }
130 #endif
131
132
register_base_classes(LDisplay * pDisplay)133 void register_base_classes (LDisplay* pDisplay)
134 {
135 LWindow* pWindow = new LWindow (pDisplay);
136 // pWindow->event_handler_map (g_rgEventHandlerMap);
137 // pWindow->select_events (ButtonPressMask | ExposureMask);
138 // pWindow->set_background_pixel (XBlackPixel (pDisplay->display (), 0));
139 // pWindow->set_bit_gravity (SouthEastGravity);
140 pWindow->notify ((PFNEvent) &WTopLevel::child);
141 if (!pDisplay->hash_template ("top-level", pWindow))
142 return;
143
144 WButton::register_template (pDisplay);
145 WTextEdit::register_template (pDisplay);
146 WDialog::register_template (pDisplay);
147 }
148