Пример #1
0
nsresult
nsIconChannel::InitWithGIO(nsIMozIconURI* aIconURI)
{
  GIcon *icon = nullptr;
  nsCOMPtr<nsIURL> fileURI;

  // Read icon content
  aIconURI->GetIconURL(getter_AddRefs(fileURI));

  // Get icon for file specified by URI
  if (fileURI) {
    bool isFile;
    nsAutoCString spec;
    fileURI->GetAsciiSpec(spec);
    if (NS_SUCCEEDED(fileURI->SchemeIs("file", &isFile)) && isFile) {
      GFile* file = g_file_new_for_uri(spec.get());
      GFileInfo* fileInfo = g_file_query_info(file,
                                              G_FILE_ATTRIBUTE_STANDARD_ICON,
                                              G_FILE_QUERY_INFO_NONE,
                                              nullptr, nullptr);
      g_object_unref(file);
      if (fileInfo) {
        // icon from g_content_type_get_icon doesn't need unref
        icon = g_file_info_get_icon(fileInfo);
        if (icon) {
          g_object_ref(icon);
        }
        g_object_unref(fileInfo);
      }
    }
  }

  // Try to get icon by using MIME type
  if (!icon) {
    nsAutoCString type;
    aIconURI->GetContentType(type);
    // Try to get MIME type from file extension by using nsIMIMEService
    if (type.IsEmpty()) {
      nsCOMPtr<nsIMIMEService> ms(do_GetService("@mozilla.org/mime;1"));
      if (ms) {
        nsAutoCString fileExt;
        aIconURI->GetFileExtension(fileExt);
        ms->GetTypeFromExtension(fileExt, type);
      }
    }
    char* ctype = nullptr; // character representation of content type
    if (!type.IsEmpty()) {
      ctype = g_content_type_from_mime_type(type.get());
    }
    if (ctype) {
      icon = g_content_type_get_icon(ctype);
      g_free(ctype);
    }
  }

  // Get default icon theme
  GtkIconTheme* iconTheme = gtk_icon_theme_get_default();
  GtkIconInfo* iconInfo = nullptr;
  // Get icon size
  int32_t iconSize = GetIconSize(aIconURI);

  if (icon) {
    // Use icon and theme to get GtkIconInfo
    iconInfo = gtk_icon_theme_lookup_by_gicon(iconTheme,
                                              icon, iconSize,
                                              (GtkIconLookupFlags)0);
    g_object_unref(icon);
  }

  if (!iconInfo) {
    // Mozilla's mimetype lookup failed. Try the "unknown" icon.
    iconInfo = gtk_icon_theme_lookup_icon(iconTheme,
                                          "unknown", iconSize,
                                          (GtkIconLookupFlags)0);
    if (!iconInfo) {
      return NS_ERROR_NOT_AVAILABLE;
    }
  }

  // Create a GdkPixbuf buffer containing icon and scale it
  GdkPixbuf* buf = gtk_icon_info_load_icon(iconInfo, nullptr);
  gtk_icon_info_free(iconInfo);
  if (!buf) {
    return NS_ERROR_UNEXPECTED;
  }

  nsresult rv = ScaleIconBuf(&buf, iconSize);
  NS_ENSURE_SUCCESS(rv, rv);

  rv = moz_gdk_pixbuf_to_channel(buf, aIconURI,
                                 getter_AddRefs(mRealChannel));
  g_object_unref(buf);
  return rv;
}
Пример #2
0
/** \brief DragSelection callback.
 * Handles the results of a drag selection.
 */
void RemoteIconView::DragSelection( Point cStartPoint )
{
	/* Most of this is adapted from IconDirectoryView::DragSelection */
	
	if( m_pcServer == NULL )
	{
		DEBUG( "DragSelection with m_pcServer== NULL\n" );
		return;
	}
	
	String zBase = m_pcServer->GetServerAddress();
	Message cMsg( 1234 );	/* Message code isn't important */
	
	/* Add all selected icons to the message, and find the icon under the mouse. */
	int nCount = 0;
	int nLastSelected = -1;
	Point cIconPos = Point( 0,0 );
	for( uint i = 0; i < GetIconCount(); i++ ) {
		if( GetIconSelected( i ) ) {
			RemoteIconData* pcData = (RemoteIconData*)GetIconData( i );
//			DEBUG( "   %s\n", pcData->m_cNode.m_zPath.c_str() );
			cMsg.AddString( "remote-file/path", pcData->m_cNode.m_zPath );
			cMsg.AddString( "server", zBase );
			cMsg.AddBool( "is_dir", pcData->m_cNode.m_bIsDir );
			
			if( Rect( GetIconPosition( i ), GetIconPosition( i ) + GetIconSize() ).DoIntersect( cStartPoint ) ) {
				cIconPos = GetIconPosition( i );
			}
			
			nLastSelected = i;
			nCount++;
		}
	}
	if( nCount == 0 ) return;
	
	/* Create a drag&drop icon */
	Bitmap cBitmap( (int)GetIconSize().x + 1, (int)GetIconSize().y + 1, CS_RGB32, Bitmap::ACCEPT_VIEWS | Bitmap::SHARE_FRAMEBUFFER );
	View* pcView = new View( Rect( Point(0,0), GetIconSize() ), "temp" );
	cBitmap.AddChild( pcView );
	
	Image* pcIcon = NULL;
	String zLabel;
	if( nCount == 1 ) {
		/* Only one file selected; use its icon */
		zLabel = GetIconString( nLastSelected, 0 );
		pcIcon = GetIconImage( nLastSelected );
	} else {
		/* Multiple files selected; use dir icon */
		zLabel.Format( "%i items", nCount );	/* TODO: localise the string */
		/* TODO: Fall back to resource if file isn't present */
		File* pcFile = new File( "/system/icons/folder.png" );
		BitmapImage* pcBitmapImage = new BitmapImage( pcFile );
		Point cSize = (GetView() == VIEW_LIST || GetView() == VIEW_DETAILS ? Point( 24,24 ) : Point( 48,48 ));
		if( pcBitmapImage->GetSize() != cSize ) pcBitmapImage->SetSize( cSize );
		pcIcon = pcBitmapImage;
	}
	if( pcIcon ) {
		RenderIcon( zLabel, pcIcon, pcView, Point(0,0) );
	}
	cBitmap.Sync();
	if( nCount != 1 ) delete( pcIcon );
	
	BeginDrag( &cMsg, cStartPoint - cIconPos, &cBitmap );
}
Пример #3
0
nsresult
nsIconChannel::InitWithGnome(nsIMozIconURI *aIconURI)
{
  nsresult rv;

  if (NS_FAILED(ensure_libgnomeui()) || NS_FAILED(ensure_libgnome()) || NS_FAILED(ensure_libgnomevfs())) {
    gTriedToLoadGnomeLibs = true;
    return NS_ERROR_NOT_AVAILABLE;
  }

  gTriedToLoadGnomeLibs = true;

  if (!_gnome_program_get()) {
    // Get the brandShortName from the string bundle to pass to GNOME
    // as the application name.  This may be used for things such as
    // the title of grouped windows in the panel.
    nsCOMPtr<nsIStringBundleService> bundleService = 
      do_GetService(NS_STRINGBUNDLE_CONTRACTID);

    NS_ASSERTION(bundleService, "String bundle service must be present!");

    nsCOMPtr<nsIStringBundle> bundle;
    bundleService->CreateBundle("chrome://branding/locale/brand.properties",
                                getter_AddRefs(bundle));
    nsAutoString appName;

    if (bundle) {
      bundle->GetStringFromName(NS_LITERAL_STRING("brandShortName").get(),
                                getter_Copies(appName));
    } else {
      NS_WARNING("brand.properties not present, using default application name");
      appName.Assign(NS_LITERAL_STRING("Gecko"));
    }

    char* empty[] = { "" };
    _gnome_init(NS_ConvertUTF16toUTF8(appName).get(), "1.0", 1, empty, NULL, 0, NULL);
  }

  PRUint32 iconSize = GetIconSize(aIconURI);
  nsCAutoString type;
  aIconURI->GetContentType(type);

  GnomeVFSFileInfo fileInfo = {0};
  fileInfo.refcount = 1; // In case some GnomeVFS function addrefs and releases it

  nsCAutoString spec;
  nsCOMPtr<nsIURL> url;
  rv = aIconURI->GetIconURL(getter_AddRefs(url));
  if (url) {
    url->GetAsciiSpec(spec);
    // Only ask gnome-vfs for a GnomeVFSFileInfo for file: uris, to avoid a
    // network request
    bool isFile;
    if (NS_SUCCEEDED(url->SchemeIs("file", &isFile)) && isFile) {
      _gnome_vfs_get_file_info(spec.get(), &fileInfo, GNOME_VFS_FILE_INFO_DEFAULT);
    }
    else {
      // The filename we get is UTF-8-compatible, which matches gnome expectations.
      // See also: http://lists.gnome.org/archives/gnome-vfs-list/2004-March/msg00049.html
      // "Whenever we can detect the charset used for the URI type we try to
      //  convert it to/from utf8 automatically inside gnome-vfs."
      // I'll interpret that as "otherwise, this field is random junk".
      nsCAutoString name;
      url->GetFileName(name);
      fileInfo.name = g_strdup(name.get());

      if (!type.IsEmpty()) {
        fileInfo.valid_fields = GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE;
        fileInfo.mime_type = g_strdup(type.get());
      }
    }
  }

  if (type.IsEmpty()) {
    nsCOMPtr<nsIMIMEService> ms(do_GetService("@mozilla.org/mime;1"));
    if (ms) {
      nsCAutoString fileExt;
      aIconURI->GetFileExtension(fileExt);
      if (!fileExt.IsEmpty()) {
        ms->GetTypeFromExtension(fileExt, type);
      }
    }
  }
  // Get the icon theme
  if (!gIconTheme) {
    gIconTheme = _gnome_icon_theme_new();

    if (!gIconTheme) {
      _gnome_vfs_file_info_clear(&fileInfo);
      return NS_ERROR_NOT_AVAILABLE;
    }
  }

  char* name = _gnome_icon_lookup(gIconTheme, NULL, spec.get(), NULL, &fileInfo,
                                  type.get(), GNOME_ICON_LOOKUP_FLAGS_NONE,
                                  NULL);

  _gnome_vfs_file_info_clear(&fileInfo);
  if (!name)
    return NS_ERROR_NOT_AVAILABLE;
  
  // Get the default theme associated with the screen
  // Do NOT free.
  GtkIconTheme *theme = gtk_icon_theme_get_default();
  if (!theme) {
    g_free(name);
    return NS_ERROR_UNEXPECTED;
  }

  GError *err = nsnull;
  GdkPixbuf* buf = gtk_icon_theme_load_icon(theme, name, iconSize, (GtkIconLookupFlags)0, &err);
  g_free(name);

  if (!buf) {
    if (err)
      g_error_free(err);
    return NS_ERROR_UNEXPECTED;
  }

  rv = ScaleIconBuf(&buf, iconSize);
  NS_ENSURE_SUCCESS(rv, rv);

  rv = moz_gdk_pixbuf_to_channel(buf, aIconURI,
                                 getter_AddRefs(mRealChannel));
  g_object_unref(buf);
  return rv;
}
Пример #4
0
static void btnPaintContent (PCONTROL pCtrl, HDC hdc, DWORD dwStyle, 
                             RECT* prcText)
{
    switch (dwStyle & BS_CONTENTMASK)
    {
        case BS_TEXT:
        case BS_LEFTTEXT:
        {
            UINT uFormat;
            
            if (dwStyle & BS_MULTLINE)
                uFormat = DT_WORDBREAK;
            else
                uFormat = DT_SINGLELINE;

            if ((dwStyle & BS_TYPEMASK) == BS_PUSHBUTTON
                    || (dwStyle & BS_TYPEMASK) == BS_DEFPUSHBUTTON
                    || (dwStyle & BS_PUSHLIKE))
                uFormat |= DT_CENTER | DT_VCENTER;
            else {
                uFormat = DT_TOP | DT_LEFT;

                if ((dwStyle & BS_ALIGNMASK) == BS_LEFT)
                    uFormat = DT_WORDBREAK | DT_LEFT;
                else if ((dwStyle & BS_ALIGNMASK) == BS_RIGHT)
                    uFormat = DT_WORDBREAK | DT_RIGHT;
                else if ((dwStyle & BS_ALIGNMASK) == BS_CENTER)
                    uFormat = DT_WORDBREAK | DT_CENTER;
            
                if ((dwStyle & BS_ALIGNMASK) == BS_TOP)
                    uFormat = DT_SINGLELINE | DT_TOP;
                else if ((dwStyle & BS_ALIGNMASK) == BS_BOTTOM)
                    uFormat = DT_SINGLELINE | DT_BOTTOM;
                else if ((dwStyle & BS_ALIGNMASK) == BS_VCENTER)
                    uFormat = DT_SINGLELINE | DT_VCENTER;
            }
            
            SetBkColor (hdc, GetWindowBkColor ((HWND)pCtrl));
            if (dwStyle & WS_DISABLED) {
                RECT rc = *prcText;
                
                SetBkMode (hdc, BM_TRANSPARENT);
                SetTextColor (hdc, PIXEL_lightwhite);
                OffsetRect (prcText, 2, 2);
                DrawText (hdc, pCtrl->spCaption, -1, prcText, uFormat);
                
                SetTextColor (hdc, PIXEL_darkgray);
                DrawText (hdc, pCtrl->spCaption, -1, &rc, uFormat);
            }
            else {
                SetBkMode (hdc, BM_TRANSPARENT);
                SetTextColor (hdc, PIXEL_black);
                OffsetRect (prcText, 1, 1);
                DrawText (hdc, pCtrl->spCaption, -1, prcText, uFormat);
            }
        }
        break;
        
        case BS_BITMAP:
            if (BUTTON_DATA(pCtrl)) {
                int x = prcText->left;
                int y = prcText->top;
                int w = RECTWP (prcText);
                int h = RECTHP (prcText);
                PBITMAP bmp = (PBITMAP)(BUTTON_DATA(pCtrl));

                if (dwStyle & BS_REALSIZEIMAGE) {
                    x += (w - bmp->bmWidth) >> 1;
                    y += (h - bmp->bmHeight) >> 1;
                    w = h = 0;
                }
                FillBoxWithBitmap (hdc, x, y, w, h, bmp);
            }
        break;
         
        case BS_ICON:
            if (BUTTON_DATA(pCtrl)) {
                int x = prcText->left;
                int y = prcText->top;
                int w = RECTWP (prcText);
                int h = RECTHP (prcText);
                HICON icon = (HICON)(BUTTON_DATA(pCtrl));

                if (dwStyle & BS_REALSIZEIMAGE) {
                    int iconw, iconh;

                    GetIconSize (icon, &iconw, &iconh);
                    x += (w - iconw) >> 1;
                    y += (h - iconh) >> 1;
                    w = h = 0;
                }

                DrawIcon (hdc, x, y, w, h, icon);
            }