]> git.sesse.net Git - vlc/blob - modules/gui/beos/TransportButton.h
Support for UDP-Lite (with full checksum coverage only atm)
[vlc] / modules / gui / beos / TransportButton.h
1 /*****************************************************************************
2  * TransportButton.h
3  *****************************************************************************
4  * Copyright (C) 2001 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Tony Castley <tcastley@mail.powerup.com.au>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #ifndef __MEDIA_BUTTON__
25 #define __MEDIA_BUTTON__
26
27 #include <Control.h>
28
29 class BMessage;
30 class BBitmap;
31 class PeriodicMessageSender;
32 class BitmapStash;
33
34 // TransportButton must be installed into a window with B_ASYNCHRONOUS_CONTROLS on
35 // currently no button focus drawing
36
37 class TransportButton : public BControl {
38 public:
39
40         TransportButton(BRect frame, const char *name,
41                 const unsigned char *normalBits,
42                 const unsigned char *pressedBits,
43                 const unsigned char *disabledBits,
44                 BMessage *invokeMessage,                        // done pressing over button
45                 BMessage *startPressingMessage = 0, // just clicked button
46                 BMessage *pressingMessage = 0,          // periodical still pressing
47                 BMessage *donePressing = 0,             // tracked out of button/didn't invoke
48                 bigtime_t period = 0,                           // pressing message period
49                 uint32 key = 0,                                         // optional shortcut key
50                 uint32 modifiers = 0,                           // optional shortcut key modifier
51                 uint32 resizeFlags = B_FOLLOW_LEFT | B_FOLLOW_TOP);
52         
53         virtual ~TransportButton();
54
55         void SetStartPressingMessage(BMessage *);
56         void SetPressingMessage(BMessage *);
57         void SetDonePressingMessage(BMessage *);
58         void SetPressingPeriod(bigtime_t);
59
60         virtual void SetEnabled(bool);
61
62 protected:              
63
64         enum {
65                 kDisabledMask = 0x1,
66                 kPressedMask = 0x2
67         };
68         
69         virtual void AttachedToWindow();
70         virtual void DetachedFromWindow();
71         virtual void Draw(BRect);
72         virtual void MouseDown(BPoint);
73         virtual void MouseMoved(BPoint, uint32 code, const BMessage *);
74         virtual void MouseUp(BPoint);
75         virtual void WindowActivated(bool);
76
77         virtual BBitmap *MakeBitmap(uint32);
78                 // lazy bitmap builder
79         
80         virtual uint32 ModeMask() const;
81                 // mode mask corresponding to the current button state
82                 // - determines which bitmap will be used
83         virtual const unsigned char *BitsForMask(uint32) const;
84                 // pick the right bits based on a mode mask
85
86                 // overriding class can add swapping between two pairs of bitmaps, etc.
87         virtual void StartPressing();
88         virtual void MouseCancelPressing();
89         virtual void DonePressing();
90
91 private:
92         void ShortcutKeyDown();
93         void ShortcutKeyUp();
94         
95         void MouseStartPressing();
96         void MouseDonePressing();
97
98         BitmapStash *bitmaps;
99                 // using BitmapStash * here instead of a direct member so that the class can be private in
100                 // the .cpp file
101
102         // bitmap bits used to build bitmaps for the different states
103         const unsigned char *normalBits;
104         const unsigned char *pressedBits;
105         const unsigned char *disabledBits;
106         
107         BMessage *startPressingMessage;
108         BMessage *pressingMessage;
109         BMessage *donePressingMessage;
110         bigtime_t pressingPeriod;
111         
112         bool mouseDown;
113         bool keyDown;
114         PeriodicMessageSender *messageSender;
115         BMessageFilter *keyPressFilter;
116
117         typedef BControl _inherited;
118         
119         friend class SkipButtonKeypressFilter;
120         friend class BitmapStash;
121 };
122
123 class PlayPauseButton : public TransportButton {
124 // Knows about playing and paused states, blinks
125 // the pause LED during paused state
126 public:
127         PlayPauseButton(BRect frame, const char *name,
128                 const unsigned char *normalBits,
129                 const unsigned char *pressedBits,
130                 const unsigned char *disabledBits,
131                 const unsigned char *normalPlayingBits,
132                 const unsigned char *pressedPlayingBits,
133                 const unsigned char *normalPausedBits,
134                 const unsigned char *pressedPausedBits,
135                 BMessage *invokeMessage,                        // done pressing over button
136                 uint32 key = 0,                                         // optional shortcut key
137                 uint32 modifiers = 0,                           // optional shortcut key modifier
138                 uint32 resizeFlags = B_FOLLOW_LEFT | B_FOLLOW_TOP);
139         
140         // These need get called periodically to update the button state
141         // OK to call them over and over - once the state is correct, the call
142         // is very low overhead
143         void SetStopped();
144         void SetPlaying();
145         void SetPaused();
146
147 protected:
148         
149         virtual uint32 ModeMask() const;
150         virtual const unsigned char *BitsForMask(uint32) const;
151
152         virtual void StartPressing();
153         virtual void MouseCancelPressing();
154         virtual void DonePressing();
155
156 private:
157         const unsigned char *normalPlayingBits;
158         const unsigned char *pressedPlayingBits;
159         const unsigned char *normalPausedBits;
160         const unsigned char *pressedPausedBits;
161         
162         enum PlayState {
163                 kStopped,
164                 kAboutToPlay,
165                 kPlaying,
166                 kAboutToPause,
167                 kPausedLedOn,
168                 kPausedLedOff
169         };
170         
171         enum {
172                 kPlayingMask = 0x4,
173                 kPausedMask = 0x8
174         };
175         
176         PlayState state;
177         bigtime_t lastPauseBlinkTime;
178         uint32 lastModeMask;
179         
180         typedef TransportButton _inherited;
181 };
182
183 #endif  // __MEDIA_BUTTON__