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
  
/* XTools.pmod 
 * 
 */ 
 
//! Various tools that are higher level than raw X, but are lower 
//! level than widgets. 
 
/* 
 *    Protocols.X, a Pike interface to the X Window System 
 * 
 *    See COPYRIGHT for copyright information. 
 * 
 *    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 
 */ 
 
#pike __REAL_VERSION__ 
 
class Button 
//! A simple button. Steals and processes mousebutton events 
//! Can be inherited and then expanded the button_pressed function 
{ 
  object window; 
  constant style = 1; 
 
  int pressed; // button is pressed 
  int inside;  // pointer is inside window 
  int button;  // The number of the mouse button used 
  //! 
 
  function(object, int, mapping:void) redraw_callback; 
  function(object:void) clicked_callback; 
 
  //! 
  void button_exposed(mapping event) 
  { 
    redraw_callback(this, pressed && (!style || inside), event); 
  } 
 
  //! 
  mapping button_pressed(mapping event) 
  { 
    werror(sprintf("Button %d pressed.\n", event->detail)); 
    if (event->detail == button) 
      { 
        pressed = 1; 
        inside = 1; 
        redraw_callback(this, 1, 0); 
 
        return 0; 
      } 
    else 
      return event; 
  } 
 
  //! 
  mapping button_released(mapping event) 
  { 
    if (event->detail == button) 
      { 
        pressed = 0; 
        redraw_callback(this, 0, 0); 
        if (inside) 
          clicked_callback(this); 
        return 0; 
      } 
    else 
      return event; 
  } 
 
  //! 
  mapping window_entered(mapping event) 
  { 
    inside = 1; 
    if (pressed && style) 
      redraw_callback(this, 1, 0); 
    return 0; 
  } 
 
  //! 
  mapping window_left(mapping event) 
  { 
    inside = 0; 
    if (pressed && style) 
      redraw_callback(this, 0, 0); 
    return 0; 
  } 
 
  //! 
  void create(object w, int|void b) 
  { 
    window = w; 
    button = b || 1; 
 
    window->SelectInput("Exposure", 
                        "ButtonPress", "ButtonRelease", 
                        "EnterWindow", "LeaveWindow"); 
    // window->GrabButton(button, 0, "EnterWindow", "LeaveWindow"); 
    window->set_event_callback("Expose", button_exposed); 
    window->set_event_callback("ButtonPress", button_pressed); 
    window->set_event_callback("ButtonRelease", button_released); 
    window->set_event_callback("EnterNotify", window_entered); 
    window->set_event_callback("LeaveNotify", window_left); 
  } 
} 
 
class Uglier_button 
{ 
  inherit Button; 
  constant style = 0; 
}