Showing Tooltips in XUL Browser.

Keep the following code in the respective files.

.xul File

<browser id = “browser1″

type=”content-primary”

name=”content-primary”

src=”file:///Users/praveen/Desktop/Tooltip.html”

tooltip=”aHTMLTooltip”

flex=”1″ />

<tooltip id=”aHTMLTooltip” onpopupshowing=”return FillInHTMLTooltip(document.tooltipNode);”/>

.js File
function FillInHTMLTooltip(tipElement)
{

var retVal = false;
if (tipElement.namespaceURI == “http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul&#8221;)
return retVal;

const XLinkNS = “http://www.w3.org/1999/xlink&#8221;;

var titleText = null;
var XLinkTitleText = null;

while (!titleText && !XLinkTitleText && tipElement) {
if (tipElement.nodeType == Node.ELEMENT_NODE) {
titleText = tipElement.getAttribute(“title”);
XLinkTitleText = tipElement.getAttributeNS(XLinkNS, “title”);
}
tipElement = tipElement.parentNode;
}

var texts = [titleText, XLinkTitleText];
var tipNode = document.getElementById(“aHTMLTooltip”);

for (var i = 0; i < texts.length; ++i) {
var t = texts[i];
if (t && t.search(/\S/) >= 0) {
tipNode.setAttribute(“label”, t);
retVal = true;
}
}

return retVal;
}

technorati tags:, , , ,

Blogged with Flock

Posted in MOzilla. 1 Comment »

XUL Browser secret features to show up Tooltips

Secret Features

        user_pref(“browser.chrome.tooltips.attrlist.enabled”, true);

        user_pref(“browser.chrome.tooltips.attrlist”,
                “alt|src|data|title|href|cite|action|onclick|onmouseover|onsubmit”);

        By the secret settings above (by the “user.js” or the “about:config” feature), the browser popups all of attributes in the list. If the pointed element doesn’t have the attribute, the browser finds a parental node which has the attribute. And, the following setting shows attributes for all of parental nodes:

        user_pref(“browser.chrome.tooltips.attrlist.recursively”, true);

These features possibly prevents spoofings and phishings.

NOTE: Cited from http://piro.sakura.ne.jp/xul/_popupalt.html.en

technorati tags:, , , ,

Blogged with Flock

Change default printer in Mac

The following statement change default printer to “hp LaserJet 1320 series (FBBF32)”.

What u have to do is replace non-alphanumeric symbols with “_”.

system(“lpoptions -d hp_LaserJet_1320_series__FBBF32_”);

Code to set our printer as default printer and reset to previous one.

=================================================================

=================================================================

// Create Session for Printing Operation.

PMCreateSession(&printSession);

PMPrinter printer;

PMSessionGetCurrentPrinter(printSession, &printer);

CFStringRef availablePrinterID = (CFStringRef) PMPrinterGetID(printer);

CFRetain(availablePrinterID);

char *printerNameToLPOptions = (char *) malloc ( sizeof(char) * ( 14 + strlen(printerName)) );

strcpy(printerNameToLPOptions,”lpoptions -d “);

strcat(printerNameToLPOptions,CFStringGetCStringPtr(getPrinterID(printerName),kCFStringEncodingMacRoman));

printerNameToLPOptions[strlen(printerNameToLPOptions)] =”;

system(printerNameToLPOptions);

}

PMRelease(printSession);

char *aPrinterName = (char*)CFStringGetCStringPtr(availablePrinterID,kCFStringEncodingMacRoman);

char *printerNameToLPOptions = (char *) malloc( sizeof(char) * (14 + strlen(aPrinterName) ) );

strcpy(printerNameToLPOptions,”lpoptions -d “);

strcat(printerNameToLPOptions,aPrinterName);

system(printerNameToLPOptions);

CFRelease(availablePrinterID);

=================================================================

=================================================================

technorati tags:, , , ,

Blogged with Flock

XUL Browser not open popup window

To make the XUL Browser to open popup window you have to set the following priviledge in the prefs.js

( Which is in Corresponding application folder of Application Support folder ).


netscape.security.PrivilegeManager.enablePrivilege(“UniversalXPConnect UniversalBrowserWrite”);

You can program it like the following one.

var prefManager = Components.classes[“@mozilla.org/preferences-service;1”]
.getService(Components.interfaces.nsIPrefBranch);

prefManager.setCharPref(“capability.principal.codebase.p0.granted”,”UniversalXPConnect UniversalBrowserWrite”);

prefManager.setCharPref(“capability.principal.codebase.p0.id”,”http://localhost&#8221;);

technorati tags:, , , , , ,

Blogged with Flock

Limit Preference window size to remove blank space below.

when browser.preferences.animateFadeIn is true the blank space is coming below the xul elements in the Preferences window.

Solution: Set height and width of the preference window.

technorati tags:, , , , , , , ,

Blogged with Flock

read and write to chrome file using XPCOM components.

// To perform local file IO from JavaScript in Mozilla, use the XPCOM
nsIFile file IO library. See the above references for more details.

function xpcomFileWrite(filePath, content) {
if (Components) // XPConnect ‘Components’ object check.
try {

netscape.security.PrivilegeManager.enablePrivilege
(“UniversalXPConnect”);

// Get file component.
var file = Components.classes[“@mozilla.org/file/local;1”]
.createInstance(Components.interfaces.nsILocalFile);

file.initWithPath(filePath);

if (!file.exists()) {
alert(‘Creating new file ‘ + filePath);

/********************************************************************

create(type, permissions)

This function will create a new file or directory in the file system.
Any nodes that have not been created or resolved, will be. If the file
or directory already exists create() will return
NS_ERROR_FILE_ALREADY_EXISTS.

Arguments:

type: This specifies the type of file system object to be made. The
only two types at this time are file and directory/folder which are:

NORMAL_FILE_TYPE = 0x00
DIRECTORY_TYPE = 0x01

If the type is unrecongnized, we will return an error
(NS_ERROR_FILE_UNKNOWN_TYPE).

permissions: The unix style octal permissions. This may be ignored on
systems that do not need to do permissions. In general, permissions are
based on three octal numbers. The first specifies the access for the
user, the second for the group and the last for others.

0 – No permission to read, write or execute.
1 – Execute permission only.
2 – Write permission only.
3 – Execute and write permission.
4 – Read permission only.
5 – Execute and read permission.
6 – Write and read permission.
7 – Execute, write and read permission.

User read/write, group read, others read would be 644

********************************************************************/

file.create(0x00, 0644);
}

// Write with nsIFileOutputStream.

var outputStream = Components.classes
[“@mozilla.org/network/file-output-stream;1”].createInstance
(Components.interfaces.nsIFileOutputStream);

/********************************************************************

init(), opens a file for reading, writing, or both.

INPUTS:

1. The path name of the file to be opened

2. The file status IO flag. It is a bitwise OR of the following
bit flags (only one of the first three flags below may be used):

0x01 – Open for reading only.
0x02 – Open for writing only.
0x04 – Open for reading and writing.
0x08 – If the file does not exist, the file is created.
If the file exists, this flag has no effect.
0x10 – If set, each write will wait for both the file
data and file status to be physically updated.
0x20 – The file pointer is set to the end of the file
prior to each write.
0x40 – If the file exists, its length is truncated to 0.
0x80 – If the file does not exist, the file is created.

If the file already exists, no action and NULL is returned.

3. The access permission bits of the file ‘mode’.
CAVEAT: ‘mode’ is currently only applicable on UNIX platforms.
The ‘mode’ argument may be ignored on other platforms.

00400 – Read by owner.
00200 – Write by owner.
00100 – Execute (search if a directory) by owner.
00040 – Read by group.
00020 – Write by group.
00010 – Execute by group.
00004 – Read by others.
00002 – Write by others
00001 – Execute by others.

4. Behavior flags specifying various behaviors of the class
(currently not supported).

********************************************************************/

outputStream.init(file, 0x20 | 0x02, 00004,
null);
outputStream.write(content, content.length);
outputStream.flush();
outputStream.close();
return true;
}
catch(e) {
alert(e);
return false;
}
return false;
}
if (xpcomFileWrite(‘D:\\My Web
Pages\\test.html’, ‘<html><head><\/head><body><h2>Hello World!
<\/h2><\/body><\/html>’))
window.open(‘file:\/\/\/D:\\My Web
Pages\\test.html’, ‘testWindow’, ‘left=10,top=305,width=500,height=200’)
;

function xpcomFileRead(filePath) {
if (Components)
try {

netscape.security.PrivilegeManager.enablePrivilege(“UniversalXPConnect”);
var file = Components.classes[“@mozilla.org/file/local;1”]
.createInstance(Components.interfaces.nsILocalFile);
file.initWithPath(filePath);
if (!file.exists()) {
alert(‘File does not exist’);
return false;
}
var inputStream = Components.classes[“@mozilla.org/network/file-input-stream;1”]
.createInstance(Components.interfaces.nsIFileInputStream);
inputStream.init(file, 0x01, 00004, null);
var sInputStream = Components.classes
[“@mozilla.org/scriptableinputstream;1”].createInstance
(Components.interfaces.nsIScriptableInputStream);
sInputStream.init(inputStream);
return sInputStream.read(sInputStream.available
());
}
catch(e) {
alert(e);
return false;
}
return false;
}
if ((output = xpcomFileRead(‘D:\\My Web Pages\\test.html’)))
document.aForm.aTextarea.value = output;
</script>
</body>
</html>

technorati tags:, , , , , , ,

Blogged with Flock