[haiku-commits] r35139 - haiku/trunk/src/apps/showimage

  • From: host.haiku@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 18 Jan 2010 01:14:40 +0100 (CET)

Author: julun
Date: 2010-01-18 01:14:40 +0100 (Mon, 18 Jan 2010)
New Revision: 35139
Changeset: http://dev.haiku-os.org/changeset/35139/haiku
Ticket: http://dev.haiku-os.org/ticket/4874

Modified:
   haiku/trunk/src/apps/showimage/ShowImageView.cpp
   haiku/trunk/src/apps/showimage/ShowImageView.h
Log:
* Fix can't cut and drag a piece of picture from ShowImage to Desktop, ticket 
#4874.
* Set the current image mime as first in the translators list, thus on 
drag&drop with
  left mouse button the same image type is created as the currently loaded in 
ShowImage.

  Still this does more hide than fix the real problem, beeing ICO translator 
the first in
  the generated translator list due to the high capabilitys values and a 
limited set of
  output sizes it can handle. I attached a further fix to the ticket, still i 
would like
  to get some other opinions on it before commiting.


By default the transla


Modified: haiku/trunk/src/apps/showimage/ShowImageView.cpp
===================================================================
--- haiku/trunk/src/apps/showimage/ShowImageView.cpp    2010-01-17 22:51:24 UTC 
(rev 35138)
+++ haiku/trunk/src/apps/showimage/ShowImageView.cpp    2010-01-18 00:14:40 UTC 
(rev 35139)
@@ -596,6 +596,7 @@
                fDocumentCount = 1;
 
        fImageType = info.name;
+       fImageMime = info.MIME;
 
        GetPath(&fCaption);
        if (fDocumentCount > 1)
@@ -1125,31 +1126,46 @@
        if (roster == NULL)
                return false;
 
+       // add the current image mime first, will make it the preferred format 
on
+       // left mouse drag
+       msg->AddString("be:types", fImageMime);
+       msg->AddString("be:filetypes", fImageMime);
+       msg->AddString("be:type_descriptions", fImageType);
+
+       bool foundOther = false;
+       bool foundCurrent = false;
+
+       int32 infoCount;
+       translator_info* info;
        BBitmapStream stream(bitmap);
-
-       translator_info *outInfo;
-       bool found = false;
-       int32 outNumInfo;
-       if (roster->GetTranslators(&stream, NULL, &outInfo, &outNumInfo) == 
B_OK) {
-               for (int32 i = 0; i < outNumInfo; i++) {
-                       const translation_format *fmts;
-                       int32 num_fmts;
-                       roster->GetOutputFormats(outInfo[i].translator, &fmts, 
&num_fmts);
-                       for (int32 j = 0; j < num_fmts; j++) {
-                               if (strcmp(fmts[j].MIME, "image/x-be-bitmap") 
!= 0) {
+       if (roster->GetTranslators(&stream, NULL, &info, &infoCount) == B_OK) {
+               for (int32 i = 0; i < infoCount; i++) {
+                       const translation_format* formats;
+                       int32 count;
+                       roster->GetOutputFormats(info[i].translator, &formats, 
&count);
+                       for (int32 j = 0; j < count; j++) {
+                               if (fImageMime == formats[j].MIME) {
+                                       foundCurrent = true;
+                               } else if (strcmp(formats[j].MIME, 
"image/x-be-bitmap") != 0) {
+                                       foundOther = true;
                                        // needed to send data in message
-                                       msg->AddString("be:types", 
fmts[j].MIME);
+                                       msg->AddString("be:types", 
formats[j].MIME);
                                        // needed to pass data via file
-                                       msg->AddString("be:filetypes", 
fmts[j].MIME);
-                                       msg->AddString("be:type_descriptions", 
fmts[j].name);
+                                       msg->AddString("be:filetypes", 
formats[j].MIME);
+                                       msg->AddString("be:type_descriptions", 
formats[j].name);
                                }
-                               found = true;
                        }
                }
        }
        stream.DetachBitmap(&bitmap);
 
-       return found;
+       if (!foundCurrent) {
+               msg->RemoveData("be:types", 0);
+               msg->RemoveData("be:filetypes", 0);
+               msg->RemoveData("be:type_descriptions", 0);
+       }
+
+       return foundOther || foundCurrent;
 }
 
 
@@ -1174,8 +1190,10 @@
                drag.AddString("be:types", B_FILE_MIME_TYPE);
                // avoid flickering of dragged bitmap caused by drawing into 
the window
                _AnimateSelection(false);
-               // only use a transparent bitmap on selections less than 
400x400 (taking into account zooming)
-               if ((fSelectionRect.Width() * fZoom) < 400.0 && 
(fSelectionRect.Height() * fZoom) < 400.0) {
+               // only use a transparent bitmap on selections less than 400x400
+               // (taking into account zooming)
+               if ((fSelectionRect.Width() * fZoom) < 400.0
+                       && (fSelectionRect.Height() * fZoom) < 400.0) {
                        sourcePoint -= fSelectionRect.LeftTop();
                        sourcePoint.x *= fZoom;
                        sourcePoint.y *= fZoom;
@@ -1288,20 +1306,16 @@
 void
 ShowImageView::_HandleDrop(BMessage* msg)
 {
-       BMessage data(B_MIME_DATA);
        entry_ref dirRef;
        BString name, type;
-       bool saveToFile;
-       bool sendInMessage;
-       BBitmap *bitmap;
-
-       saveToFile = msg->FindString("be:filetypes", &type) == B_OK
+       bool saveToFile = msg->FindString("be:filetypes", &type) == B_OK
                && msg->FindRef("directory", &dirRef) == B_OK
                && msg->FindString("name", &name) == B_OK;
 
-       sendInMessage = (!saveToFile) && msg->FindString("be:types", &type) == 
B_OK;
+       bool sendInMessage = !saveToFile
+               && msg->FindString("be:types", &type) == B_OK;
 
-       bitmap = _CopySelection();
+       BBitmap* bitmap = _CopySelection();
        if (bitmap == NULL)
                return;
 

Modified: haiku/trunk/src/apps/showimage/ShowImageView.h
===================================================================
--- haiku/trunk/src/apps/showimage/ShowImageView.h      2010-01-17 22:51:24 UTC 
(rev 35138)
+++ haiku/trunk/src/apps/showimage/ShowImageView.h      2010-01-18 00:14:40 UTC 
(rev 35139)
@@ -242,6 +242,7 @@
                BString fCaption;                       // caption text
 
                BString fImageType;             // Type of image, for use in 
status bar and caption
+               BString fImageMime;
 
                bool fInverted;
 


Other related posts:

  • » [haiku-commits] r35139 - haiku/trunk/src/apps/showimage - host . haiku