~ubuntu-branches/ubuntu/maverick/vlc/maverick

« back to all changes in this revision

Viewing changes to modules/gui/beos/TransportButton.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2008-09-17 21:56:14 UTC
  • mfrom: (1.1.17 upstream)
  • Revision ID: james.westby@ubuntu.com-20080917215614-tj0vx8xzd57e52t8
Tags: 0.9.2-1ubuntu1
* New Upstream Release, exception granted by
    - dktrkranz, norsetto, Hobbsee (via irc). LP: #270404

Changes done in ubuntu:

* add libxul-dev to build-depends
* make sure that vlc is build against libxul in configure. This doesn't
  change anything in the package, but makes it more robust if building
  in an 'unclean' chroot or when modifying the package.
* debian/control: make Vcs-* fields point to the motumedia branch
* add libx264-dev and libass-dev to build-depends
  LP: #210354, #199870
* actually enable libass support by passing --enable-libass to configure
* enable libdca: add libdca-dev to build depends and --enable-libdca
* install the x264 plugin.

Changes already in the pkg-multimedia branch in debian:

* don't install usr/share/vlc/mozilla in debian/mozilla-plugin-vlc.install  
* new upstream .desktop file now registers flash video mimetype LP: #261567
* add Xb-Npp-Applications to mozilla-plugin-vlc
* remove duplicate entries in debian/vlc-nox.install

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * TransportButton.cpp
3
3
 *****************************************************************************
4
4
 * Copyright (C) 2001 the VideoLAN team
5
 
 * $Id: 5e8a6f6d3d9baf250b9f962b94aba6b5c73dc72e $
 
5
 * $Id$
6
6
 *
7
7
 * Authors: Tony Castley <tcastley@mail.powerup.com.au>
8
8
 *          Stephan Aßmus <stippi@yellowbites.com>
40
40
// flavors of a bitmap. If the stash does not have a particular bitmap,
41
41
// it turns around to ask the button to create one and stores it for next time.
42
42
public:
43
 
        BitmapStash(TransportButton *);
44
 
        ~BitmapStash();
45
 
        BBitmap *GetBitmap(uint32 signature);
46
 
        
 
43
    BitmapStash(TransportButton *);
 
44
    ~BitmapStash();
 
45
    BBitmap *GetBitmap(uint32 signature);
 
46
    
47
47
private:
48
 
        TransportButton *owner;
49
 
        map<uint32, BBitmap *> stash;
 
48
    TransportButton *owner;
 
49
    map<uint32, BBitmap *> stash;
50
50
};
51
51
 
52
52
BitmapStash::BitmapStash(TransportButton *owner)
53
 
        :       owner(owner)
 
53
    :    owner(owner)
54
54
{
55
55
}
56
56
 
57
57
BBitmap *
58
58
BitmapStash::GetBitmap(uint32 signature)
59
59
{
60
 
        if (stash.find(signature) == stash.end()) {
61
 
                BBitmap *newBits = owner->MakeBitmap(signature);
62
 
                ASSERT(newBits);
63
 
                stash[signature] = newBits;
64
 
        }
65
 
        
66
 
        return stash[signature];
 
60
    if (stash.find(signature) == stash.end()) {
 
61
        BBitmap *newBits = owner->MakeBitmap(signature);
 
62
        ASSERT(newBits);
 
63
        stash[signature] = newBits;
 
64
    }
 
65
    
 
66
    return stash[signature];
67
67
}
68
68
 
69
69
BitmapStash::~BitmapStash()
70
70
{
71
 
        // delete all the bitmaps
72
 
        for (map<uint32, BBitmap *>::iterator i = stash.begin(); i != stash.end(); i++) 
73
 
                delete (*i).second;
 
71
    // delete all the bitmaps
 
72
    for (map<uint32, BBitmap *>::iterator i = stash.begin(); i != stash.end(); i++)
 
73
        delete (*i).second;
74
74
}
75
75
 
76
76
 
77
77
class PeriodicMessageSender {
78
 
        // used to send a specified message repeatedly when holding down a button
 
78
    // used to send a specified message repeatedly when holding down a button
79
79
public:
80
 
        static PeriodicMessageSender *Launch(BMessenger target,
81
 
                const BMessage *message, bigtime_t period);
82
 
        void Quit();
 
80
    static PeriodicMessageSender *Launch(BMessenger target,
 
81
        const BMessage *message, bigtime_t period);
 
82
    void Quit();
83
83
 
84
84
private:
85
 
        PeriodicMessageSender(BMessenger target, const BMessage *message,
86
 
                bigtime_t period);
87
 
        ~PeriodicMessageSender() {}
88
 
                // use quit
89
 
 
90
 
        static status_t TrackBinder(void *);
91
 
        void Run();
92
 
        
93
 
        BMessenger target;
94
 
        BMessage message;
95
 
 
96
 
        bigtime_t period;
97
 
        
98
 
        bool requestToQuit;
 
85
    PeriodicMessageSender(BMessenger target, const BMessage *message,
 
86
        bigtime_t period);
 
87
    ~PeriodicMessageSender() {}
 
88
        // use quit
 
89
 
 
90
    static status_t TrackBinder(void *);
 
91
    void Run();
 
92
    
 
93
    BMessenger target;
 
94
    BMessage message;
 
95
 
 
96
    bigtime_t period;
 
97
    
 
98
    bool requestToQuit;
99
99
};
100
100
 
101
101
 
102
102
PeriodicMessageSender::PeriodicMessageSender(BMessenger target,
103
 
        const BMessage *message, bigtime_t period)
104
 
        :       target(target),
105
 
                message(*message),
106
 
                period(period),
107
 
                requestToQuit(false)
 
103
    const BMessage *message, bigtime_t period)
 
104
    :    target(target),
 
105
        message(*message),
 
106
        period(period),
 
107
        requestToQuit(false)
108
108
{
109
109
}
110
110
 
111
111
PeriodicMessageSender *
112
112
PeriodicMessageSender::Launch(BMessenger target, const BMessage *message,
113
 
        bigtime_t period)
 
113
    bigtime_t period)
114
114
{
115
 
        PeriodicMessageSender *result = new PeriodicMessageSender(target, message, period);
116
 
        thread_id thread = spawn_thread(&PeriodicMessageSender::TrackBinder,
117
 
                "ButtonRepeatingThread", B_NORMAL_PRIORITY, result);
118
 
        
119
 
        if (thread <= 0 || resume_thread(thread) != B_OK) {
120
 
                // didn't start, don't leak self
121
 
                delete result;
122
 
                result = 0;
123
 
        }
 
115
    PeriodicMessageSender *result = new PeriodicMessageSender(target, message, period);
 
116
    thread_id thread = spawn_thread(&PeriodicMessageSender::TrackBinder,
 
117
        "ButtonRepeatingThread", B_NORMAL_PRIORITY, result);
 
118
    
 
119
    if (thread <= 0 || resume_thread(thread) != B_OK) {
 
120
        // didn't start, don't leak self
 
121
        delete result;
 
122
        result = 0;
 
123
    }
124
124
 
125
 
        return result;
 
125
    return result;
126
126
}
127
127
 
128
 
void 
 
128
void
129
129
PeriodicMessageSender::Quit()
130
130
{
131
 
        requestToQuit = true;
 
131
    requestToQuit = true;
132
132
}
133
133
 
134
 
status_t 
 
134
status_t
135
135
PeriodicMessageSender::TrackBinder(void *castToThis)
136
136
{
137
 
        ((PeriodicMessageSender *)castToThis)->Run();
138
 
        return 0;
 
137
    ((PeriodicMessageSender *)castToThis)->Run();
 
138
    return 0;
139
139
}
140
140
 
141
 
void 
 
141
void
142
142
PeriodicMessageSender::Run()
143
143
{
144
 
        for (;;) {
145
 
                snooze(period);
146
 
                if (requestToQuit)
147
 
                        break;
148
 
                target.SendMessage(&message);
149
 
        }
150
 
        delete this;
 
144
    for (;;) {
 
145
        snooze(period);
 
146
        if (requestToQuit)
 
147
            break;
 
148
        target.SendMessage(&message);
 
149
    }
 
150
    delete this;
151
151
}
152
152
 
153
153
class SkipButtonKeypressFilter : public BMessageFilter {
154
154
public:
155
 
        SkipButtonKeypressFilter(uint32 shortcutKey, uint32 shortcutModifier,
156
 
                TransportButton *target);
 
155
    SkipButtonKeypressFilter(uint32 shortcutKey, uint32 shortcutModifier,
 
156
        TransportButton *target);
157
157
 
158
158
protected:
159
 
        filter_result Filter(BMessage *message, BHandler **handler);
 
159
    filter_result Filter(BMessage *message, BHandler **handler);
160
160
 
161
161
private:
162
 
        uint32 shortcutKey;
163
 
        uint32 shortcutModifier;
164
 
        TransportButton *target;
 
162
    uint32 shortcutKey;
 
163
    uint32 shortcutModifier;
 
164
    TransportButton *target;
165
165
};
166
166
 
167
167
SkipButtonKeypressFilter::SkipButtonKeypressFilter(uint32 shortcutKey,
168
 
        uint32 shortcutModifier, TransportButton *target)
169
 
        :       BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE),
170
 
                shortcutKey(shortcutKey),
171
 
                shortcutModifier(shortcutModifier),
172
 
                target(target)
 
168
    uint32 shortcutModifier, TransportButton *target)
 
169
    :    BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE),
 
170
        shortcutKey(shortcutKey),
 
171
        shortcutModifier(shortcutModifier),
 
172
        target(target)
173
173
{
174
174
}
175
175
 
176
 
filter_result 
 
176
filter_result
177
177
SkipButtonKeypressFilter::Filter(BMessage *message, BHandler **handler)
178
178
{
179
 
        if (target->IsEnabled()
180
 
                && (message->what == B_KEY_DOWN || message->what == B_KEY_UP)) {
181
 
                uint32 modifiers;
182
 
                uint32 rawKeyChar = 0;
183
 
                uint8 byte = 0;
184
 
                int32 key = 0;
185
 
                
186
 
                if (message->FindInt32("modifiers", (int32 *)&modifiers) != B_OK
187
 
                        || message->FindInt32("raw_char", (int32 *)&rawKeyChar) != B_OK
188
 
                        || message->FindInt8("byte", (int8 *)&byte) != B_OK
189
 
                        || message->FindInt32("key", &key) != B_OK)
190
 
                        return B_DISPATCH_MESSAGE;
191
 
 
192
 
                modifiers &= B_SHIFT_KEY | B_COMMAND_KEY | B_CONTROL_KEY
193
 
                        | B_OPTION_KEY | B_MENU_KEY;
194
 
                        // strip caps lock, etc.
195
 
 
196
 
                if (modifiers == shortcutModifier && rawKeyChar == shortcutKey) {
197
 
                        if (message->what == B_KEY_DOWN)
198
 
                                target->ShortcutKeyDown();
199
 
                        else
200
 
                                target->ShortcutKeyUp();
201
 
                        
202
 
                        return B_SKIP_MESSAGE;
203
 
                }
204
 
        }
205
 
 
206
 
        // let others deal with this
207
 
        return B_DISPATCH_MESSAGE;
 
179
    if (target->IsEnabled()
 
180
        && (message->what == B_KEY_DOWN || message->what == B_KEY_UP)) {
 
181
        uint32 modifiers;
 
182
        uint32 rawKeyChar = 0;
 
183
        uint8 byte = 0;
 
184
        int32 key = 0;
 
185
        
 
186
        if (message->FindInt32("modifiers", (int32 *)&modifiers) != B_OK
 
187
            || message->FindInt32("raw_char", (int32 *)&rawKeyChar) != B_OK
 
188
            || message->FindInt8("byte", (int8 *)&byte) != B_OK
 
189
            || message->FindInt32("key", &key) != B_OK)
 
190
            return B_DISPATCH_MESSAGE;
 
191
 
 
192
        modifiers &= B_SHIFT_KEY | B_COMMAND_KEY | B_CONTROL_KEY
 
193
            | B_OPTION_KEY | B_MENU_KEY;
 
194
            // strip caps lock, etc.
 
195
 
 
196
        if (modifiers == shortcutModifier && rawKeyChar == shortcutKey) {
 
197
            if (message->what == B_KEY_DOWN)
 
198
                target->ShortcutKeyDown();
 
199
            else
 
200
                target->ShortcutKeyUp();
 
201
            
 
202
            return B_SKIP_MESSAGE;
 
203
        }
 
204
    }
 
205
 
 
206
    // let others deal with this
 
207
    return B_DISPATCH_MESSAGE;
208
208
}
209
209
 
210
210
TransportButton::TransportButton(BRect frame, const char *name,
211
 
        const unsigned char *normalBits,
212
 
        const unsigned char *pressedBits,
213
 
        const unsigned char *disabledBits,
214
 
        BMessage *invokeMessage, BMessage *startPressingMessage,
215
 
        BMessage *pressingMessage, BMessage *donePressingMessage, bigtime_t period,
216
 
        uint32 key, uint32 modifiers, uint32 resizeFlags)
217
 
        :       BControl(frame, name, "", invokeMessage, resizeFlags, B_WILL_DRAW | B_NAVIGABLE),
218
 
                bitmaps(new BitmapStash(this)),
219
 
                normalBits(normalBits),
220
 
                pressedBits(pressedBits),
221
 
                disabledBits(disabledBits),
222
 
                startPressingMessage(startPressingMessage),
223
 
                pressingMessage(pressingMessage),
224
 
                donePressingMessage(donePressingMessage),
225
 
                pressingPeriod(period),
226
 
                mouseDown(false),
227
 
                keyDown(false),
228
 
                messageSender(0),
229
 
                keyPressFilter(0)
 
211
    const unsigned char *normalBits,
 
212
    const unsigned char *pressedBits,
 
213
    const unsigned char *disabledBits,
 
214
    BMessage *invokeMessage, BMessage *startPressingMessage,
 
215
    BMessage *pressingMessage, BMessage *donePressingMessage, bigtime_t period,
 
216
    uint32 key, uint32 modifiers, uint32 resizeFlags)
 
217
    :    BControl(frame, name, "", invokeMessage, resizeFlags, B_WILL_DRAW | B_NAVIGABLE),
 
218
        bitmaps(new BitmapStash(this)),
 
219
        normalBits(normalBits),
 
220
        pressedBits(pressedBits),
 
221
        disabledBits(disabledBits),
 
222
        startPressingMessage(startPressingMessage),
 
223
        pressingMessage(pressingMessage),
 
224
        donePressingMessage(donePressingMessage),
 
225
        pressingPeriod(period),
 
226
        mouseDown(false),
 
227
        keyDown(false),
 
228
        messageSender(0),
 
229
        keyPressFilter(0)
230
230
{
231
 
        if (key)
232
 
                keyPressFilter = new SkipButtonKeypressFilter(key, modifiers, this);
 
231
    if (key)
 
232
        keyPressFilter = new SkipButtonKeypressFilter(key, modifiers, this);
233
233
}
234
234
 
235
235
 
236
 
void 
 
236
void
237
237
TransportButton::AttachedToWindow()
238
238
{
239
 
        _inherited::AttachedToWindow();
240
 
        if (keyPressFilter)
241
 
                Window()->AddCommonFilter(keyPressFilter);
242
 
        
243
 
        // transparent to reduce flicker
244
 
        SetViewColor(B_TRANSPARENT_COLOR);
 
239
    _inherited::AttachedToWindow();
 
240
    if (keyPressFilter)
 
241
        Window()->AddCommonFilter(keyPressFilter);
 
242
    
 
243
    // transparent to reduce flicker
 
244
    SetViewColor(B_TRANSPARENT_COLOR);
245
245
}
246
246
 
247
 
void 
 
247
void
248
248
TransportButton::DetachedFromWindow()
249
249
{
250
 
        if (keyPressFilter)
251
 
                Window()->RemoveCommonFilter(keyPressFilter);
252
 
        _inherited::DetachedFromWindow();
 
250
    if (keyPressFilter)
 
251
        Window()->RemoveCommonFilter(keyPressFilter);
 
252
    _inherited::DetachedFromWindow();
253
253
}
254
254
 
255
255
 
256
256
TransportButton::~TransportButton()
257
257
{
258
 
        delete startPressingMessage;
259
 
        delete pressingMessage;
260
 
        delete donePressingMessage;
261
 
        delete bitmaps;
262
 
        delete keyPressFilter;
 
258
    delete startPressingMessage;
 
259
    delete pressingMessage;
 
260
    delete donePressingMessage;
 
261
    delete bitmaps;
 
262
    delete keyPressFilter;
263
263
}
264
264
 
265
 
void 
 
265
void
266
266
TransportButton::WindowActivated(bool state)
267
267
{
268
 
        if (!state)
269
 
                ShortcutKeyUp();
270
 
        
271
 
        _inherited::WindowActivated(state);
 
268
    if (!state)
 
269
        ShortcutKeyUp();
 
270
    
 
271
    _inherited::WindowActivated(state);
272
272
}
273
273
 
274
 
void 
 
274
void
275
275
TransportButton::SetEnabled(bool on)
276
276
{
277
 
        if (on != IsEnabled()) {
278
 
                _inherited::SetEnabled(on);
279
 
                if (!on)
280
 
                        ShortcutKeyUp();
281
 
        }       
 
277
    if (on != IsEnabled()) {
 
278
        _inherited::SetEnabled(on);
 
279
        if (!on)
 
280
            ShortcutKeyUp();
 
281
    }    
282
282
}
283
283
 
284
284
const unsigned char *
285
285
TransportButton::BitsForMask(uint32 mask) const
286
286
{
287
 
        switch (mask) {
288
 
                case 0:
289
 
                        return normalBits;
290
 
                case kDisabledMask:
291
 
                        return disabledBits;
292
 
                case kPressedMask:
293
 
                        return pressedBits;
294
 
                default:
295
 
                        break;
296
 
        }       
297
 
        TRESPASS();
298
 
        return 0;
 
287
    switch (mask) {
 
288
        case 0:
 
289
            return normalBits;
 
290
        case kDisabledMask:
 
291
            return disabledBits;
 
292
        case kPressedMask:
 
293
            return pressedBits;
 
294
        default:
 
295
            break;
 
296
    }    
 
297
    TRESPASS();
 
298
    return 0;
299
299
}
300
300
 
301
301
 
302
302
BBitmap *
303
303
TransportButton::MakeBitmap(uint32 mask)
304
304
{
305
 
        BRect r(Bounds());
306
 
        BBitmap *result = new BBitmap(r, B_CMAP8);
307
 
 
308
 
        uint8* src = (uint8*)BitsForMask(mask);
309
 
 
310
 
        if (src && result && result->IsValid()) {
311
 
                // int32 width = r.IntegerWidth() + 1;
312
 
                int32 height = r.IntegerHeight() + 1;
313
 
                int32 bpr = result->BytesPerRow();
314
 
                uint8* dst = (uint8*)result->Bits();
315
 
                // copy source bits into bitmap line by line,
316
 
                // taking possible alignment into account
317
 
                // since the source data has been generated
318
 
                // by QuickRes, it still contains aligment too
319
 
                // (hence skipping bpr and not width bytes)
320
 
                for (int32 y = 0; y < height; y++) {
321
 
                        memcpy(dst, src, bpr);
322
 
                        src += bpr;
323
 
                        dst += bpr;
324
 
                }
325
 
                ReplaceTransparentColor(result, Parent()->ViewColor());
326
 
        } else {
327
 
                delete result;
328
 
                result = NULL;
329
 
        }
330
 
        
331
 
        return result;
 
305
    BRect r(Bounds());
 
306
    BBitmap *result = new BBitmap(r, B_CMAP8);
 
307
 
 
308
    uint8* src = (uint8*)BitsForMask(mask);
 
309
 
 
310
    if (src && result && result->IsValid()) {
 
311
        // int32 width = r.IntegerWidth() + 1;
 
312
        int32 height = r.IntegerHeight() + 1;
 
313
        int32 bpr = result->BytesPerRow();
 
314
        uint8* dst = (uint8*)result->Bits();
 
315
        // copy source bits into bitmap line by line,
 
316
        // taking possible alignment into account
 
317
        // since the source data has been generated
 
318
        // by QuickRes, it still contains aligment too
 
319
        // (hence skipping bpr and not width bytes)
 
320
        for (int32 y = 0; y < height; y++) {
 
321
            memcpy(dst, src, bpr);
 
322
            src += bpr;
 
323
            dst += bpr;
 
324
        }
 
325
        ReplaceTransparentColor(result, Parent()->ViewColor());
 
326
    } else {
 
327
        delete result;
 
328
        result = NULL;
 
329
    }
 
330
    
 
331
    return result;
332
332
}
333
333
 
334
 
uint32 
 
334
uint32
335
335
TransportButton::ModeMask() const
336
336
{
337
 
        return (IsEnabled() ? 0 : kDisabledMask)
338
 
                | (Value() ? kPressedMask : 0);
 
337
    return (IsEnabled() ? 0 : kDisabledMask)
 
338
        | (Value() ? kPressedMask : 0);
339
339
}
340
340
 
341
 
void 
 
341
void
342
342
TransportButton::Draw(BRect)
343
343
{
344
 
        DrawBitmapAsync(bitmaps->GetBitmap(ModeMask()));
 
344
    DrawBitmapAsync(bitmaps->GetBitmap(ModeMask()));
345
345
}
346
346
 
347
347
 
348
 
void 
 
348
void
349
349
TransportButton::StartPressing()
350
350
{
351
 
        SetValue(1);
352
 
        if (startPressingMessage)
353
 
                Invoke(startPressingMessage);
354
 
        
355
 
        if (pressingMessage) {
356
 
                ASSERT(pressingMessage);
357
 
                messageSender = PeriodicMessageSender::Launch(Messenger(),
358
 
                        pressingMessage, pressingPeriod);
359
 
        }
 
351
    SetValue(1);
 
352
    if (startPressingMessage)
 
353
        Invoke(startPressingMessage);
 
354
    
 
355
    if (pressingMessage) {
 
356
        ASSERT(pressingMessage);
 
357
        messageSender = PeriodicMessageSender::Launch(Messenger(),
 
358
            pressingMessage, pressingPeriod);
 
359
    }
360
360
}
361
361
 
362
 
void 
 
362
void
363
363
TransportButton::MouseCancelPressing()
364
364
{
365
 
        if (!mouseDown || keyDown)
366
 
                return;
367
 
 
368
 
        mouseDown = false;
369
 
 
370
 
        if (pressingMessage) {
371
 
                ASSERT(messageSender);
372
 
                PeriodicMessageSender *sender = messageSender;
373
 
                messageSender = 0;
374
 
                sender->Quit();
375
 
        }
376
 
 
377
 
        if (donePressingMessage)
378
 
                Invoke(donePressingMessage);
379
 
        SetValue(0);
 
365
    if (!mouseDown || keyDown)
 
366
        return;
 
367
 
 
368
    mouseDown = false;
 
369
 
 
370
    if (pressingMessage) {
 
371
        ASSERT(messageSender);
 
372
        PeriodicMessageSender *sender = messageSender;
 
373
        messageSender = 0;
 
374
        sender->Quit();
 
375
    }
 
376
 
 
377
    if (donePressingMessage)
 
378
        Invoke(donePressingMessage);
 
379
    SetValue(0);
380
380
}
381
381
 
382
 
void 
 
382
void
383
383
TransportButton::DonePressing()
384
 
{       
385
 
        if (pressingMessage) {
386
 
                ASSERT(messageSender);
387
 
                PeriodicMessageSender *sender = messageSender;
388
 
                messageSender = 0;
389
 
                sender->Quit();
390
 
        }
 
384
{    
 
385
    if (pressingMessage) {
 
386
        ASSERT(messageSender);
 
387
        PeriodicMessageSender *sender = messageSender;
 
388
        messageSender = 0;
 
389
        sender->Quit();
 
390
    }
391
391
 
392
 
        Invoke();
393
 
        SetValue(0);
 
392
    Invoke();
 
393
    SetValue(0);
394
394
}
395
395
 
396
 
void 
 
396
void
397
397
TransportButton::MouseStartPressing()
398
398
{
399
 
        if (mouseDown)
400
 
                return;
401
 
        
402
 
        mouseDown = true;
403
 
        if (!keyDown)
404
 
                StartPressing();
 
399
    if (mouseDown)
 
400
        return;
 
401
    
 
402
    mouseDown = true;
 
403
    if (!keyDown)
 
404
        StartPressing();
405
405
}
406
406
 
407
 
void 
 
407
void
408
408
TransportButton::MouseDonePressing()
409
409
{
410
 
        if (!mouseDown)
411
 
                return;
412
 
        
413
 
        mouseDown = false;
414
 
        if (!keyDown)
415
 
                DonePressing();
 
410
    if (!mouseDown)
 
411
        return;
 
412
    
 
413
    mouseDown = false;
 
414
    if (!keyDown)
 
415
        DonePressing();
416
416
}
417
417
 
418
 
void 
 
418
void
419
419
TransportButton::ShortcutKeyDown()
420
420
{
421
 
        if (!IsEnabled())
422
 
                return;
 
421
    if (!IsEnabled())
 
422
        return;
423
423
 
424
 
        if (keyDown)
425
 
                return;
426
 
        
427
 
        keyDown = true;
428
 
        if (!mouseDown)
429
 
                StartPressing();
 
424
    if (keyDown)
 
425
        return;
 
426
    
 
427
    keyDown = true;
 
428
    if (!mouseDown)
 
429
        StartPressing();
430
430
}
431
431
 
432
 
void 
 
432
void
433
433
TransportButton::ShortcutKeyUp()
434
434
{
435
 
        if (!keyDown)
436
 
                return;
437
 
        
438
 
        keyDown = false;
439
 
        if (!mouseDown)
440
 
                DonePressing();
 
435
    if (!keyDown)
 
436
        return;
 
437
    
 
438
    keyDown = false;
 
439
    if (!mouseDown)
 
440
        DonePressing();
441
441
}
442
442
 
443
443
 
444
 
void 
 
444
void
445
445
TransportButton::MouseDown(BPoint)
446
446
{
447
 
        if (!IsEnabled())
448
 
                return;
 
447
    if (!IsEnabled())
 
448
        return;
449
449
 
450
 
        ASSERT(Window()->Flags() & B_ASYNCHRONOUS_CONTROLS);
451
 
        SetTracking(true);
452
 
        SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
453
 
        MouseStartPressing();
 
450
    ASSERT(Window()->Flags() & B_ASYNCHRONOUS_CONTROLS);
 
451
    SetTracking(true);
 
452
    SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
 
453
    MouseStartPressing();
454
454
}
455
455
 
456
 
void 
 
456
void
457
457
TransportButton::MouseMoved(BPoint point, uint32 code, const BMessage *)
458
458
{
459
 
        if (IsTracking() && Bounds().Contains(point) != Value()) {
460
 
                if (!Value())
461
 
                        MouseStartPressing();
462
 
                else
463
 
                        MouseCancelPressing();
464
 
        }
 
459
    if (IsTracking() && Bounds().Contains(point) != Value()) {
 
460
        if (!Value())
 
461
            MouseStartPressing();
 
462
        else
 
463
            MouseCancelPressing();
 
464
    }
465
465
}
466
466
 
467
 
void 
 
467
void
468
468
TransportButton::MouseUp(BPoint point)
469
469
{
470
 
        if (IsTracking()) {
471
 
                if (Bounds().Contains(point))
472
 
                        MouseDonePressing();
473
 
                else
474
 
                        MouseCancelPressing();
475
 
                SetTracking(false);
476
 
        }
 
470
    if (IsTracking()) {
 
471
        if (Bounds().Contains(point))
 
472
            MouseDonePressing();
 
473
        else
 
474
            MouseCancelPressing();
 
475
        SetTracking(false);
 
476
    }
477
477
}
478
478
 
479
 
void 
 
479
void
480
480
TransportButton::SetStartPressingMessage(BMessage *message)
481
481
{
482
 
        delete startPressingMessage;
483
 
        startPressingMessage = message;
 
482
    delete startPressingMessage;
 
483
    startPressingMessage = message;
484
484
}
485
485
 
486
 
void 
 
486
void
487
487
TransportButton::SetPressingMessage(BMessage *message)
488
488
{
489
 
        delete pressingMessage;
490
 
        pressingMessage = message;
 
489
    delete pressingMessage;
 
490
    pressingMessage = message;
491
491
}
492
492
 
493
 
void 
 
493
void
494
494
TransportButton::SetDonePressingMessage(BMessage *message)
495
495
{
496
 
        delete donePressingMessage;
497
 
        donePressingMessage = message;
 
496
    delete donePressingMessage;
 
497
    donePressingMessage = message;
498
498
}
499
499
 
500
 
void 
 
500
void
501
501
TransportButton::SetPressingPeriod(bigtime_t newTime)
502
502
{
503
 
        pressingPeriod = newTime;
 
503
    pressingPeriod = newTime;
504
504
}
505
505
 
506
506
 
507
507
PlayPauseButton::PlayPauseButton(BRect frame, const char *name,
508
 
        const unsigned char *normalBits, const unsigned char *pressedBits,
509
 
        const unsigned char *disabledBits, const unsigned char *normalPlayingBits,
510
 
        const unsigned char *pressedPlayingBits, const unsigned char *normalPausedBits,
511
 
        const unsigned char *pressedPausedBits,
512
 
        BMessage *invokeMessage, uint32 key, uint32 modifiers, uint32 resizeFlags)
513
 
        :       TransportButton(frame, name, normalBits, pressedBits,
514
 
                        disabledBits, invokeMessage, 0,
515
 
                        0, 0, 0, key, modifiers, resizeFlags),
516
 
                normalPlayingBits(normalPlayingBits),
517
 
                pressedPlayingBits(pressedPlayingBits),
518
 
                normalPausedBits(normalPausedBits),
519
 
                pressedPausedBits(pressedPausedBits),
520
 
                state(PlayPauseButton::kStopped),
521
 
                lastPauseBlinkTime(0),
522
 
                lastModeMask(0)
 
508
    const unsigned char *normalBits, const unsigned char *pressedBits,
 
509
    const unsigned char *disabledBits, const unsigned char *normalPlayingBits,
 
510
    const unsigned char *pressedPlayingBits, const unsigned char *normalPausedBits,
 
511
    const unsigned char *pressedPausedBits,
 
512
    BMessage *invokeMessage, uint32 key, uint32 modifiers, uint32 resizeFlags)
 
513
    :    TransportButton(frame, name, normalBits, pressedBits,
 
514
            disabledBits, invokeMessage, 0,
 
515
            0, 0, 0, key, modifiers, resizeFlags),
 
516
        normalPlayingBits(normalPlayingBits),
 
517
        pressedPlayingBits(pressedPlayingBits),
 
518
        normalPausedBits(normalPausedBits),
 
519
        pressedPausedBits(pressedPausedBits),
 
520
        state(PlayPauseButton::kStopped),
 
521
        lastPauseBlinkTime(0),
 
522
        lastModeMask(0)
523
523
{
524
524
}
525
525
 
526
 
void 
 
526
void
527
527
PlayPauseButton::SetStopped()
528
528
{
529
 
        if (state == kStopped || state == kAboutToPlay)
530
 
                return;
531
 
        
532
 
        state = kStopped;
533
 
        Invalidate();
 
529
    if (state == kStopped || state == kAboutToPlay)
 
530
        return;
 
531
    
 
532
    state = kStopped;
 
533
    Invalidate();
534
534
}
535
535
 
536
 
void 
 
536
void
537
537
PlayPauseButton::SetPlaying()
538
538
{
539
 
        if (state == kPlaying || state == kAboutToPause)
540
 
                return;
541
 
        
542
 
        state = kPlaying;
543
 
        Invalidate();
 
539
    if (state == kPlaying || state == kAboutToPause)
 
540
        return;
 
541
    
 
542
    state = kPlaying;
 
543
    Invalidate();
544
544
}
545
545
 
546
546
const bigtime_t kPauseBlinkPeriod = 600000;
547
547
 
548
 
void 
 
548
void
549
549
PlayPauseButton::SetPaused()
550
550
{
551
 
        if (state == kAboutToPlay)
552
 
                return;
 
551
    if (state == kAboutToPlay)
 
552
        return;
553
553
 
554
 
        // in paused state blink the LED on and off
555
 
        bigtime_t now = system_time();
556
 
        if (state == kPausedLedOn || state == kPausedLedOff) {
557
 
                if (now - lastPauseBlinkTime < kPauseBlinkPeriod)
558
 
                        return;
559
 
                
560
 
                if (state == kPausedLedOn)
561
 
                        state = kPausedLedOff;
562
 
                else
563
 
                        state = kPausedLedOn;
564
 
        } else
565
 
                state = kPausedLedOn;
566
 
        
567
 
        lastPauseBlinkTime = now;
568
 
        Invalidate();
 
554
    // in paused state blink the LED on and off
 
555
    bigtime_t now = system_time();
 
556
    if (state == kPausedLedOn || state == kPausedLedOff) {
 
557
        if (now - lastPauseBlinkTime < kPauseBlinkPeriod)
 
558
            return;
 
559
        
 
560
        if (state == kPausedLedOn)
 
561
            state = kPausedLedOff;
 
562
        else
 
563
            state = kPausedLedOn;
 
564
    } else
 
565
        state = kPausedLedOn;
 
566
    
 
567
    lastPauseBlinkTime = now;
 
568
    Invalidate();
569
569
}
570
570
 
571
 
uint32 
 
571
uint32
572
572
PlayPauseButton::ModeMask() const
573
573
{
574
 
        if (!IsEnabled())
575
 
                return kDisabledMask;
576
 
        
577
 
        uint32 result = 0;
578
 
 
579
 
        if (Value())
580
 
                result = kPressedMask;
581
 
 
582
 
        if (state == kPlaying || state == kAboutToPlay)
583
 
                result |= kPlayingMask;
584
 
        else if (state == kAboutToPause || state == kPausedLedOn)               
585
 
                result |= kPausedMask;
586
 
        
587
 
        return result;
 
574
    if (!IsEnabled())
 
575
        return kDisabledMask;
 
576
    
 
577
    uint32 result = 0;
 
578
 
 
579
    if (Value())
 
580
        result = kPressedMask;
 
581
 
 
582
    if (state == kPlaying || state == kAboutToPlay)
 
583
        result |= kPlayingMask;
 
584
    else if (state == kAboutToPause || state == kPausedLedOn)        
 
585
        result |= kPausedMask;
 
586
    
 
587
    return result;
588
588
}
589
589
 
590
590
const unsigned char *
591
591
PlayPauseButton::BitsForMask(uint32 mask) const
592
592
{
593
 
        switch (mask) {
594
 
                case kPlayingMask:
595
 
                        return normalPlayingBits;
596
 
                case kPlayingMask | kPressedMask:
597
 
                        return pressedPlayingBits;
598
 
                case kPausedMask:
599
 
                        return normalPausedBits;
600
 
                case kPausedMask | kPressedMask:
601
 
                        return pressedPausedBits;
602
 
                default:
603
 
                        return _inherited::BitsForMask(mask);
604
 
        }       
605
 
        TRESPASS();
606
 
        return 0;
 
593
    switch (mask) {
 
594
        case kPlayingMask:
 
595
            return normalPlayingBits;
 
596
        case kPlayingMask | kPressedMask:
 
597
            return pressedPlayingBits;
 
598
        case kPausedMask:
 
599
            return normalPausedBits;
 
600
        case kPausedMask | kPressedMask:
 
601
            return pressedPausedBits;
 
602
        default:
 
603
            return _inherited::BitsForMask(mask);
 
604
    }    
 
605
    TRESPASS();
 
606
    return 0;
607
607
}
608
608
 
609
609
 
610
 
void 
 
610
void
611
611
PlayPauseButton::StartPressing()
612
612
{
613
 
        if (state == kPlaying)
614
 
                state = kAboutToPause;
615
 
        else
616
 
                state = kAboutToPlay;
617
 
        
618
 
        _inherited::StartPressing();
 
613
    if (state == kPlaying)
 
614
        state = kAboutToPause;
 
615
    else
 
616
         state = kAboutToPlay;
 
617
    
 
618
    _inherited::StartPressing();
619
619
}
620
620
 
621
 
void 
 
621
void
622
622
PlayPauseButton::MouseCancelPressing()
623
623
{
624
 
        if (state == kAboutToPause)
625
 
                state = kPlaying;
626
 
        else
627
 
                state = kStopped;
628
 
        
629
 
        _inherited::MouseCancelPressing();
 
624
    if (state == kAboutToPause)
 
625
         state = kPlaying;
 
626
    else
 
627
        state = kStopped;
 
628
    
 
629
    _inherited::MouseCancelPressing();
630
630
}
631
631
 
632
 
void 
 
632
void
633
633
PlayPauseButton::DonePressing()
634
634
{
635
 
        if (state == kAboutToPause) {
636
 
                state = kPausedLedOn;
637
 
                lastPauseBlinkTime = system_time();
638
 
        } else if (state == kAboutToPlay)
639
 
                state = kPlaying;
640
 
        
641
 
        _inherited::DonePressing();
 
635
    if (state == kAboutToPause) {
 
636
         state = kPausedLedOn;
 
637
        lastPauseBlinkTime = system_time();
 
638
    } else if (state == kAboutToPlay)
 
639
        state = kPlaying;
 
640
    
 
641
    _inherited::DonePressing();
642
642
}
643
643
 
644
644