[haiku-commits] r41248 - in haiku/trunk: headers/private/shared src/kits/shared src/preferences/datatranslations

Author: kirilla
Date: 2011-04-14 00:56:10 +0200 (Thu, 14 Apr 2011)
New Revision: 41248
Changeset: https://dev.haiku-os.org/changeset/41248

Modified:
   haiku/trunk/headers/private/shared/IconView.h
   haiku/trunk/src/kits/shared/IconView.cpp
   haiku/trunk/src/preferences/datatranslations/DataTranslationsWindow.cpp
   haiku/trunk/src/preferences/datatranslations/DataTranslationsWindow.h
Log:
Make IconView icon_size:able. Adapt DataTranslations. Disable DataTranslation's 
info button on list deselection.

Modified: haiku/trunk/headers/private/shared/IconView.h
===================================================================
--- haiku/trunk/headers/private/shared/IconView.h       2011-04-13 18:27:36 UTC 
(rev 41247)
+++ haiku/trunk/headers/private/shared/IconView.h       2011-04-13 22:56:10 UTC 
(rev 41248)
@@ -5,21 +5,28 @@
 
 
 #include <Bitmap.h>
+#include <Mime.h>
 #include <Path.h>
 #include <View.h>
 
 
 class IconView : public BView {
 public:
-                                                       IconView(const BRect& 
frame, const char* name,
-                                                               uint32 resize, 
uint32 flags);
+                                                       IconView(icon_size 
iconSize = B_LARGE_ICON);
+
                                                        ~IconView();
+
+                       status_t                InitCheck() const;
        virtual void                    Draw(BRect area);
-       
-                       bool                    DrawIcon(bool draw);
-                       bool                    SetIcon(const BPath& path);
 
+                       void                    DrawIcon(bool draw);
+                       status_t                SetIcon(const BPath& path,
+                                                               icon_size 
iconSize = B_LARGE_ICON);
+
 private:
+                       void                    _SetSize();
+
+                       icon_size               fIconSize;
                        BBitmap*                fIconBitmap;
                        bool                    fDrawIcon;
 };

Modified: haiku/trunk/src/kits/shared/IconView.cpp
===================================================================
--- haiku/trunk/src/kits/shared/IconView.cpp    2011-04-13 18:27:36 UTC (rev 
41247)
+++ haiku/trunk/src/kits/shared/IconView.cpp    2011-04-13 22:56:10 UTC (rev 
41248)
@@ -4,6 +4,7 @@
 
 #include "IconView.h"
 
+#include <new>
 #include <stdio.h>
 #include <string.h>
 
@@ -12,11 +13,14 @@
 #include <NodeInfo.h>
 
 
-IconView::IconView(const BRect& frame, const char* name, uint32 resize,
-       uint32 flags)
+using std::nothrow;
+
+
+IconView::IconView(icon_size iconSize)
        :
-       BView(frame, name, resize, flags),
-       fIconBitmap(new BBitmap(BRect(B_LARGE_ICON), B_RGBA32)),
+       BView("IconView", B_WILL_DRAW),
+       fIconSize(iconSize),
+       fIconBitmap(new BBitmap(BRect(iconSize), B_RGBA32)),
        fDrawIcon(false)
 {
        SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
@@ -30,45 +34,82 @@
 }
 
 
-bool
-IconView::SetIcon(const BPath& path)
+status_t
+IconView::SetIcon(const BPath& path, icon_size iconSize)
 {
        fDrawIcon = false;
        
+       if (iconSize != fIconSize) {
+               BBitmap* bitmap = new BBitmap(BRect(iconSize), B_RGBA32);
+               if (bitmap == NULL)
+                       return B_NO_MEMORY;
+
+               delete fIconBitmap;
+               fIconBitmap = bitmap;
+               fIconSize = iconSize;
+       }
+
+       status_t status = fIconBitmap->InitCheck();
+       if (status != B_OK)
+               return status;
+
        BEntry entry(path.Path());
        BNode node(&entry);
        BNodeInfo info(&node);
-       
-       if (info.GetTrackerIcon(fIconBitmap) != B_OK)
-               return false;
-       
+
+       status = info.GetTrackerIcon(fIconBitmap, fIconSize);
+       if (status != B_OK)
+               return status;
+
+       if (!fIconBitmap->IsValid())
+               return fIconBitmap->InitCheck();
+
+       _SetSize();
+
        fDrawIcon = true;
        Invalidate();
-       return true;
+       return B_OK;
 }
 
 
-bool
+void
 IconView::DrawIcon(bool draw)
 {
-       bool prev = fDrawIcon;
+       if (draw == fDrawIcon)
+               return;
+
        fDrawIcon = draw;
-       if (prev != fDrawIcon)
-               Invalidate();
-
-       return prev;
+       Invalidate();
 }
 
 
 void
 IconView::Draw(BRect area)
 {
-       SetDrawingMode(B_OP_ALPHA);
-       SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
-
-       if (fDrawIcon)
+       if (fDrawIcon && fIconBitmap != NULL) {
+               SetDrawingMode(B_OP_ALPHA);
+               SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
                DrawBitmap(fIconBitmap);
+               SetDrawingMode(B_OP_COPY);
+       } else
+               BView::Draw(area);
+}
 
-       SetDrawingMode(B_OP_COPY);
+
+status_t
+IconView::InitCheck() const
+{
+       if (fIconBitmap == NULL)
+               return B_NO_MEMORY;
+
+       return fIconBitmap->InitCheck();
 }
 
+
+void
+IconView::_SetSize()
+{
+       SetExplicitMinSize(BSize(fIconSize, fIconSize));
+       SetExplicitMaxSize(BSize(fIconSize, fIconSize));
+       SetExplicitPreferredSize(BSize(fIconSize, fIconSize));
+}

Modified: 
haiku/trunk/src/preferences/datatranslations/DataTranslationsWindow.cpp
===================================================================
--- haiku/trunk/src/preferences/datatranslations/DataTranslationsWindow.cpp     
2011-04-13 18:27:36 UTC (rev 41247)
+++ haiku/trunk/src/preferences/datatranslations/DataTranslationsWindow.cpp     
2011-04-13 22:56:10 UTC (rev 41248)
@@ -19,7 +19,6 @@
 #include <Application.h>
 #include <Bitmap.h>
 #include <Box.h>
-#include <Button.h>
 #include <Catalog.h>
 #include <ControlLook.h>
 #include <Entry.h>
@@ -182,11 +181,10 @@
                        B_ALIGN_USE_FULL_HEIGHT));
 
        // Add the translator icon view
-       fIconView = new IconView(BRect(0, 0, 31, 31), B_TRANSLATE("Icon"),
-               B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, B_WILL_DRAW | B_FRAME_EVENTS);
+       fIconView = new IconView();
 
        // Add the translator info button
-       BButton* button = new BButton("STD", B_TRANSLATE("Info" 
B_UTF8_ELLIPSIS),
+       fButton = new BButton("info", B_TRANSLATE("Info" B_UTF8_ELLIPSIS),
                new BMessage(kMsgTranslatorInfo), B_WILL_DRAW | B_FRAME_EVENTS 
| B_NAVIGABLE);
 
        // Populate the translators list view
@@ -201,7 +199,7 @@
                        .SetInsets(0, 0, 0, 0)
                        .Add(fRightBox, 0, 0, 3, 1)
                        .Add(fIconView, 0, 1)
-                       .Add(button, 2, 1);
+                       .Add(fButton, 2, 1);
 
        fTranslatorListView->MakeFocus();
        fTranslatorListView->Select(0);
@@ -291,6 +289,7 @@
                        if (selected < 0) {
                                // If none selected, clear the old one
                                fIconView->DrawIcon(false);
+                               fButton->SetEnabled(false);
                                fRightBox->RemoveChild(fConfigView);
                                break;
                        }
@@ -307,6 +306,7 @@
                        BPath path;
                        _GetTranslatorInfo(item->ID(), name, info, version, 
path);
                        fIconView->SetIcon(path);
+                       fButton->SetEnabled(true);
                        break;
                }
 

Modified: haiku/trunk/src/preferences/datatranslations/DataTranslationsWindow.h
===================================================================
--- haiku/trunk/src/preferences/datatranslations/DataTranslationsWindow.h       
2011-04-13 18:27:36 UTC (rev 41247)
+++ haiku/trunk/src/preferences/datatranslations/DataTranslationsWindow.h       
2011-04-13 22:56:10 UTC (rev 41248)
@@ -12,6 +12,7 @@
 
 
 #include <Box.h>
+#include <Button.h>
 #include <IconView.h>
 #include <Path.h>
 #include <View.h>
@@ -41,6 +42,7 @@
                        BBox*                   fRightBox;
                        BView*                  fConfigView;
                        IconView*               fIconView;
+                       BButton*                fButton;
 };
 
 


Other related posts:

  • » [haiku-commits] r41248 - in haiku/trunk: headers/private/shared src/kits/shared src/preferences/datatranslations - jonas