]> git.sesse.net Git - vlc/blobdiff - modules/gui/beos/TransportButton.cpp
Make Zorglub less unhappy
[vlc] / modules / gui / beos / TransportButton.cpp
index 0a82bb470ce6245de99762fb9a2c1c539c7d3b90..9fdc24d28b21a77dd8b3090bf8fef968470a85e2 100644 (file)
@@ -1,16 +1,17 @@
 /*****************************************************************************
  * TransportButton.cpp
  *****************************************************************************
- * Copyright (C) 2001 VideoLAN
- * $Id: TransportButton.cpp,v 1.1 2002/08/04 17:23:43 sam Exp $
+ * Copyright (C) 2001 the VideoLAN team
+ * $Id$
  *
  * Authors: Tony Castley <tcastley@mail.powerup.com.au>
+ *          Stephan Aßmus <stippi@yellowbites.com>
  *
  * 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
@@ -246,10 +247,8 @@ TransportButton::AttachedToWindow()
 void 
 TransportButton::DetachedFromWindow()
 {
-       if (keyPressFilter) {
+       if (keyPressFilter)
                Window()->RemoveCommonFilter(keyPressFilter);
-               delete keyPressFilter;
-       }
        _inherited::DetachedFromWindow();
 }
 
@@ -260,6 +259,7 @@ TransportButton::~TransportButton()
        delete pressingMessage;
        delete donePressingMessage;
        delete bitmaps;
+       delete keyPressFilter;
 }
 
 void 
@@ -274,9 +274,11 @@ TransportButton::WindowActivated(bool state)
 void 
 TransportButton::SetEnabled(bool on)
 {
-       _inherited::SetEnabled(on);
-       if (!on)
-               ShortcutKeyUp();        
+       if (on != IsEnabled()) {
+               _inherited::SetEnabled(on);
+               if (!on)
+                       ShortcutKeyUp();
+       }       
 }
 
 const unsigned char *
@@ -300,11 +302,31 @@ TransportButton::BitsForMask(uint32 mask) const
 BBitmap *
 TransportButton::MakeBitmap(uint32 mask)
 {
-       BBitmap *result = new BBitmap(Bounds(), B_COLOR_8_BIT);
-       result->SetBits(BitsForMask(mask), (Bounds().Width() + 1) * (Bounds().Height() + 1),
-               0, B_COLOR_8_BIT);
-
-       ReplaceTransparentColor(result, Parent()->ViewColor());
+       BRect r(Bounds());
+       BBitmap *result = new BBitmap(r, B_CMAP8);
+
+       uint8* src = (uint8*)BitsForMask(mask);
+
+       if (src && result && result->IsValid()) {
+               // int32 width = r.IntegerWidth() + 1;
+               int32 height = r.IntegerHeight() + 1;
+               int32 bpr = result->BytesPerRow();
+               uint8* dst = (uint8*)result->Bits();
+               // copy source bits into bitmap line by line,
+               // taking possible alignment into account
+               // since the source data has been generated
+               // by QuickRes, it still contains aligment too
+               // (hence skipping bpr and not width bytes)
+               for (int32 y = 0; y < height; y++) {
+                       memcpy(dst, src, bpr);
+                       src += bpr;
+                       dst += bpr;
+               }
+               ReplaceTransparentColor(result, Parent()->ViewColor());
+       } else {
+               delete result;
+               result = NULL;
+       }
        
        return result;
 }