Snippets code from my daily experience

October 4, 2008

XPCOM components, extensions and Visual C++ Express

Filed under: extension, gecko, mozilla, vc++, xpcom — dafi @ 3:01 pm

I’ve written a little XPCOM component that worked immediately thanks to the good tutorial written by Mark Finkle.

The extension stopped to work when I’ve installed it on computer different from my development environment, the error in console was

Failed to load XPCOM component: c:\Documents and Settings\…

The solution was to statically link the C/C++ runtime and add msvcrt to nodefaultlib switch.

VC++ Express 2008 (or above??) users must set from Configuration Properties

  • C/C++ -> Code Generation -> Runtime Library = Multi-threaded (/MT)
  • Linker -> Input -> Ignore Specific Library = MSVCRT.LIB

March 11, 2008

XBL, CSS selectors priority and Firefox 3

Filed under: css, firefox, gecko, mozilla, xbl, xul — dafi @ 8:58 pm

I wrote a little XBL component to allow menuitems to have images centered, I added it to Firefox 2 browser context menu and worked fine immediately, after a while I installed component on Firefox 3 beta 4 and surprisingly the menuitem didn’t show the image :(

I’ve asked help on Mozilla IRC and after about an hour the mistery was revealed.

The innocent CSS declaration shown below works fine on Firefox 2

.menuitem-image-center {
-moz-binding: url(‘chrome://morekomodo/content/bindings/menu.xml#menuitemImageCenterBinding’);
}

but requires a little modification on Firefox 3 beta 5pre (at this time the latest available)

.menuitem-image-center {
-moz-binding: url(‘chrome://morekomodo/content/bindings/menu.xml#menuitemImageCenterBinding’)
!important;
}

You must notice the selector without !important attribute works on Firefox 3 when applied on menus different from browser context menu.

I suspect the browser context menu should have some special treatment on new Firefox…

Context menu

December 23, 2007

How to detect the current active theme name on Firefox

Filed under: extension, firefox, gecko, nsIPrefBranch, skin, theme, xpcom — dafi @ 6:42 pm

Sometime obtaining informations about components isn’t so quick, you must iterate over RDF, XML or call many API.

Sometime is very simple like get a pref string… well this time I’m lucky ;-)

The pref general.skins.selectedSkin contains the current active theme name.

var currentThemeName = Components.classes['@mozilla.org/preferences-service;1']
.getService()
.QueryInterface(Components.interfaces.nsIPrefBranch)
.getCharPref("general.skins.selectedSkin");

December 20, 2007

Firefox 3 and broken extensions

When I started Richscrollbar (RSB for friends) development I could not figure out a so difficult programming life cycle.

After all its task is simple, add extra buttons to browser scrollbars to speedup movements inside web page.

Gecko is affect by a bug that reduces RSB productivity dramatically but I’ve created it anyway.

Now I discover RSB totally doesn’t work with Firefox 3 beta 2, Mozilla guys changed API and I suspect introduced some regression.

Obviously it is impossibile to explain the problem to Mozilla, they are so busy to fight against the world.

After some frustrating debug I found the problems and fixed them.

Problem nr 1.

The nsIStyleSheetService.USER_AGENT has changed behaviour without documenting it (at least at this date)

I used USER_SHEET in Firefox 2 but under FF3 the same code simply doesn’t work.

I’ve replaced it with the other flag AGENT_SHEET and magically RSB started to work.

Where can I read the new behaviour? Damned Mozilla :P

Problem nr 2.

An horizontal useless scrollbar is always visible only on tab window open at browser startup, if user opens new tab and/or windows this dumb doesn’t appear, sigh!

I found a reasonable workaround hiding the scrollbar inside the notificationbox component.

I hope to publish the fixed RSB on this weekend.

November 1, 2007

Welcome OpenKomodo

Filed under: gecko, komodo, mozilla, xul — dafi @ 12:15 pm

Finally Komodo is open!

More informations at http://www.openkomodo.com/

Komodo isn’t a promise it is reality.

Open source === Open minds

Why I love it?

I use shanec words

#It allows you to work the way you want to

Sure, you don’t need to fit to your editor but your editor fits to you.

#It’s built for developers by developers

I’ve used ActivePerl for years a step ahead over perl language, a tool designed by programmers with my same needs

Now OpenKomodo is the new frontier, the missing piece: THE EDITOR.

D2D is the right definition: Developer2Developer

# It’s easily extensible using XML, JavaScript, and if you like, Python, and C++

Ok OpenKomodo isn’t perfect for my needs but I can reuse my skills to enhance my programming experience

Use well know technologies to plug new behaviours, I love XUL and you?

The big problems with OpenKomodo are startup-speed and memory usage but these problems are related to Jecko runtime not to ActiveState’s guys implementation.

Do you think I’m a ActiveState employee? No! I’m a programmer that finally founds his programming home.

September 22, 2007

KomodoEdit, the editor I was waiting for…

Filed under: gecko, komodo, xul — dafi @ 10:21 am

When I turn on my computer the first program I run (at least the second ;-) ) is my preferred text editor.

I can open it for development or simply to handle notes, list or any other textual information.

Under Microsoft Windows I can’t live without UltraEdit, sometime I believe UltraEdit’s author entered in my mind to choose what feature add to it because UE has all feature I dream.

UEdit has only a problem… It’s commercial :-( and I’m an open source man…

When I boot up on my Ubuntu box UE equivalent doesn’t exist; gedit, kate are good but not complete like UE.

I love VIM but I’m unable to use it for intensive editing sessions… Emacs the same.

Finally I found my cross-platform full features and free (but not open source) editor and to complete my satisfation it’s built on Mozilla Gecko so I can enhance it with my XUL extensions :-) :-)

KomodoEdit is its name ;-)

Guys at ActiveState made a really great work and the project OpenKomodo is very attractive.

KomodoEdit hasn’t all UE features but adding them it’s easy with XUL, you can create extensions in the same manner you do for Firefox, Thunderbird, SeaMonkey and any other Mozilla Gecko based application.

To fit my needs I’ve developed MoreKomodo, an extension that adds some UE features to KomodoEdit.

I decided to make MoreKomodo public because KomodoEdit is free, I don’t like to support proprietary, commercial and/or closed softwares.

MoreKomodo can be see in action on its screenshoots page locate ad dafizilla.

Blog at WordPress.com.