473,574 Members | 2,529 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

stick mouse cursor

Eep²
14 New Member
I'm trying to change the Firefox extension Scrollbar Anywhere so the mouse cursor does not move when scrolling. Here's the code but I don't know what to change:

[PHP]// Constants
const sbawLeftButton = 0;
const sbawMiddleButto n = 1;
const sbawRightButton = 2;
var sbawIsWin, sbawIsMac, sbawIsNix;
var sbawContentArea , sbawRenderingAr ea, sbawContextPopu p;
var sbawFxV1_0;
var sbawEnableConte xtMenu;
var sbawMainWin;
var sbawScrollObj;
var sbawStartY, sbawStartX;
var sbawInitX, sbawInitY;
var sbawHasMoved, sbawSense, sbawButton, sbawMul, sbawGrabNDrag;
var sbawCustomCurso r, sbawEnableLock, sbawCancelIfOut ;
var sbawMouseLocked ;
const sbawPrefListene r = {
domain: "scrollbarAnywh ere.",
observe: function(subjec t, topic, prefName) {
if (topic != "nsPref:changed ") return;
sbawInit();
}
}
var sbawPrefService = Components.clas ses["@mozilla.o rg/preferences-service;1"]
.getService(Com ponents.interfa ces.nsIPrefServ ice);
var sbawPrefRoot = sbawPrefService .getBranch(null );
var sbawPref = sbawPrefService .getBranch("scr ollbarAnywhere. ");
var sbawPbi = sbawPrefRoot.Qu eryInterface(Co mponents.interf aces.nsIPrefBra nchInternal);
sbawPbi.addObse rver(sbawPrefLi stener.domain, sbawPrefListene r, false);

function sbawInit() {
const unixRe = new RegExp("unix|li nux|sun|freebsd ", "i");
try {
sbawSense = sbawPref.getBoo lPref("reverse" );
}
catch(err) {sbawPref.setBo olPref("reverse ", false); return; }
try {
sbawButton = sbawPref.getInt Pref("button");
}
catch(err) {sbawPref.setIn tPref("button", 2); return; }
try {
sbawGrabNDrag = sbawPref.getBoo lPref("grabNDra g");
}
catch(err) {sbawPref.setBo olPref("grabNDr ag", false); return; }
try {
sbawCustomCurso r = sbawPref.getBoo lPref("customCu rsor");
}
catch(err) {sbawPref.setBo olPref("customC ursor", false); return; }
try {
sbawEnableLock = sbawPref.getBoo lPref("enableLo ck");
}
catch(err) {sbawPref.setBo olPref("enableL ock", false); return; }
try {
sbawCancelIfOut = sbawPref.getBoo lPref("cancelIf Out");
}
catch(err) {sbawPref.setBo olPref("cancelI fOut", false); return; }
sbawMul = sbawSense ? -1 : 1;
sbawMouseLocked = false;
sbawIsWin = false; sbawIsMac = false; sbawIsNix = false;
var platform = window.navigato r.platform.toLo werCase();
if (platform.index Of('win') != -1) sbawIsWin = true;
else if (platform.index Of('mac') != -1) sbawIsMac = true;
else sbawIsNix = platform.search (unixRe) != -1;;
var geckoVers = parseFloat(wind ow.navigator.us erAgent.substri ng(window.navig ator.userAgent. lastIndexOf("rv :") + 3));
sbawFxV1_0 = !isNaN(geckoVer s) && geckoVers < 1.8;

sbawMainWin = document.getEle mentById("main-window");
sbawContentArea = document.getEle mentById("conte nt");
sbawRenderingAr ea = sbawContentArea .mPanelContaine r;
sbawContextPopu p = document.getEle mentById("conte ntAreaContextMe nu");
if (sbawButton == sbawRightButton ) sbawContextPopu p.addEventListe ner("popupshowi ng", sbawDisableAllC ontextMenus, false);
else sbawContextPopu p.removeEventLi stener("popupsh owing", sbawDisableAllC ontextMenus, false);
sbawEnableConte xtMenu = false;
sbawRenderingAr ea.addEventList ener("mousedown ", sbawDownHandler , true);
dump("Scrollbar Anywhere started\n");
}

function sbawFindNodeToS croll(initialNo de) {

function scrollCursorTyp e(neededW, availW, neededH, availH, scrollBarSize) {
if (neededW <= availW && neededH <= availH) return 3;
if (neededW > availW && neededH > availH) return 0;
if (neededW > availW) return ((neededH <= (availH - scrollBarSize)) - 0) << 1; // 0 or 2
return (neededW <= (availW - scrollBarSize)) - 0;
}

function getStyle(elem, aProp) {
var p = elem.ownerDocum ent.defaultView .getComputedSty le(elem, "").getProperty Value(aProp);
var val = parseFloat(p);
if (!isNaN(val)) return Math.ceil(val);
if (p == "thin") return 1;
if (p == "medium") return 3;
if (p == "thick") return 5;
return 0;
}

const defaultScrollBa rSize = 16;
const twiceScrollBarS ize = defaultScrollBa rSize * 2;
var retObj = {scrollType: 3, isXML: false, nodeToScroll: null, ratioX: 1,
ratioY: 1, clientFrame: null, isBody: false, isFrame: false,
targetDoc: null, insertionNode: null, cursorChangeabl e: false};
var realWidth, realHeight, nextNode, currNode;
var targetDoc = initialNode.own erDocument;
var docEl = targetDoc.docum entElement;
retObj.insertio nNode = (docEl) ? docEl : targetDoc;
var docBox = targetDoc.getBo xObjectFor(retO bj.insertionNod e);
if (docBox) {
retObj.docBoxX = docBox.screenX; retObj.docBoxY = docBox.screenY;
if (!sbawFxV1_0) {
retObj.docBoxX += targetDoc.defau ltView.pageXOff set;
retObj.docBoxY += targetDoc.defau ltView.pageYOff set;
}
}
var clientFrame = targetDoc.defau ltView;
retObj.targetDo c = targetDoc; retObj.clientFr ame = clientFrame;
if (docEl && docEl.nodeName. toLowerCase() == "html") { // walk the tree up looking for something to scroll
if (clientFrame.fr ameElement) retObj.isFrame = true; else retObj.isFrame = false;
var bodies = docEl.getElemen tsByTagName("bo dy");
if (!bodies || !bodies.length) return retObj;
var bodyEl = bodies[0];
if (initialNode == docEl) nextNode = bodyEl;
else if (initialNode.no deName.toLowerC ase() == "select") nextNode = initialNode.par entNode;
else nextNode = initialNode;
do {
try {
currNode = nextNode;
if (currNode.clien tWidth && currNode.client Height &&
currNode.ownerD ocument.default View.getCompute dStyle(currNode , "").getProperty Value("overflow ") != "hidden") {
realWidth = currNode.client Width + getStyle(currNo de, "border-left-width") + getStyle(currNo de, "border-right-width");
realHeight = currNode.client Height + getStyle(currNo de, "border-top-width") + getStyle(currNo de, "border-bottom-width");
retObj.scrollTy pe = scrollCursorTyp e(currNode.scro llWidth, realWidth, currNode.scroll Height, realHeight, 0);
if (retObj.scrollT ype != 3) {
retObj.nodeToSc roll = currNode;
retObj.isBody = currNode == bodyEl || currNode == docEl;
if (realWidth > twiceScrollBarS ize) realWidth -= twiceScrollBarS ize;
if (realHeight > twiceScrollBarS ize) realHeight -= twiceScrollBarS ize;
retObj.ratioY = (currNode.scrol lHeight / realHeight) * sbawMul;
retObj.ratioX = (currNode.scrol lWidth / realWidth) * sbawMul;
return retObj;
}
}
nextNode = currNode.parent Node;
}
catch(err) {return retObj;}
} while (nextNode && currNode != docEl);
if (retObj.isFrame ) return sbawFindNodeToS croll(clientFra me.frameElement .ownerDocument. documentElement );
}
else { // XML document; do our best
retObj.nodeToSc roll = initialNode;
if (docBox) {
retObj.ratioX = (docBox.width / sbawRenderingAr ea.boxObject.wi dth) * sbawMul;
retObj.ratioY = (docBox.height / sbawRenderingAr ea.boxObject.he ight) * sbawMul;
retObj.scrollTy pe = scrollCursorTyp e(docBox.width, sbawRenderingAr ea.boxObject.wi dth,
docBox.height, sbawRenderingAr ea.boxObject.he ight, defaultScrollBa rSize);
}
retObj.isXML = true;
}
return retObj;
}

function sbawDisableAllC ontextMenus(e) {
if (e.target.nodeN ame != "popup") return; // let sub-menus popup
if (!sbawEnableCon textMenu) e.preventDefaul t();
else sbawEnableConte xtMenu = false;
}

function sbawDisplayCont extMenu(aX, aY) {
sbawContextPopu p.showPopup(sba wMainWin, aX, aY, "context", null, null);
}

function sbawShowContext Menu(e) {
sbawEnableConte xtMenu = true;
if (sbawIsWin) return; // use the default action
var lName = e.target.localN ame.toLowerCase ();
if ((sbawIsNix || sbawIsMac) && (lName == "input" || lName == "textarea") ) document.popupN ode = e.target;
else document.popupN ode = e.originalTarge t;
setTimeout(sbaw DisplayContextM enu, 0, e.clientX + 2, e.clientY + 2);
}

function sbawDownHandler (e) {
if (e.button == sbawButton) {
sbawHasMoved = false;
sbawScrollObj = sbawFindNodeToS croll(e.target) ;
if (sbawGrabNDrag) {sbawScrollObj. ratioX = sbawMul; sbawScrollObj.r atioY = sbawMul;}
// dump("X: " + sbawScrollObj.r atioX + ",Y: " + sbawScrollObj.r atioY + "\n");
window.addEvent Listener("mouse up", sbawUpHandler, true);
if (sbawScrollObj. scrollType == 3) return;
if (!sbawScrollObj .isXML && sbawScrollObj.n odeToScroll.nod eName.toLowerCa se() != "select" && sbawCustomCurso r) {
sbawScrollObj.c ursorChangeable = true;
sbawScrollObj.n odeToScroll.sty le.cursor = "url(chrome ://scrollbaranywhe re/content/grab.png), move";
}
if (sbawButton == sbawRightButton ) {
e.preventDefaul t(); e.stopPropagati on();
}
sbawRenderingAr ea.removeEventL istener("moused own", sbawDownHandler , true);
if (sbawCancelIfOu t) window.addEvent Listener("mouse out", sbawOutHandler, true);
window.addEvent Listener("mouse down", sbawUpHandler, true);
window.addEvent Listener("mouse move", sbawMoveScrollB ar, true);
sbawStartY = e.screenY; sbawStartX = e.screenX;
sbawInitY = e.screenY; sbawInitX = e.screenX;
}
}

function sbawMoveScrollB ar(e) {
if (!sbawHasMoved && Math.abs(e.scre enX - sbawInitX) < 3 && Math.abs(e.scre enY - sbawInitY) < 3) return;
sbawHasMoved = true;
var dX = e.screenX - sbawStartX; var dY = e.screenY - sbawStartY;
sbawStartY = e.screenY; sbawStartX = e.screenX;
if (sbawScrollObj. isXML)
switch (sbawScrollObj. scrollType) {
case 1: sbawScrollObj.c lientFrame.scro llBy(0, Math.ceil((dY) * sbawScrollObj.r atioY));
break;
case 2: sbawScrollObj.c lientFrame.scro llBy(Math.ceil( (dX) * sbawScrollObj.r atioX), 0);
break;
case 0: if (Math.abs(dX) > Math.abs(dY))
sbawScrollObj.c lientFrame.scro llBy(Math.ceil( (dX) * sbawScrollObj.r atioX), 0);
else sbawScrollObj.c lientFrame.scro llBy(0, Math.ceil((dY) * sbawScrollObj.r atioY));
}
else
switch (sbawScrollObj. scrollType) {
case 1: sbawScrollObj.n odeToScroll.scr ollTop += Math.ceil((dY) * sbawScrollObj.r atioY);
break;
case 2: sbawScrollObj.n odeToScroll.scr ollLeft += Math.ceil((dX) * sbawScrollObj.r atioX);
break;
case 0: if (Math.abs(dX) > Math.abs(dY))
sbawScrollObj.n odeToScroll.scr ollLeft += Math.ceil((dX) * sbawScrollObj.r atioX);
else sbawScrollObj.n odeToScroll.scr ollTop += Math.ceil((dY) * sbawScrollObj.r atioY);
}
}

function sbawEndScrollin g() {
sbawMouseLocked = false;
window.removeEv entListener("mo useup", sbawUpHandler, true);
window.removeEv entListener("mo usedown", sbawUpHandler, true);
if (sbawCancelIfOu t) window.removeEv entListener("mo useout", sbawOutHandler, true);
window.removeEv entListener("mo usemove", sbawMoveScrollB ar, true);
sbawRenderingAr ea.addEventList ener("mousedown ", sbawDownHandler , true);
if (sbawScrollObj. cursorChangeabl e)
sbawScrollObj.n odeToScroll.sty le.cursor = "auto";
}

function sbawUpHandler(e ) {
if (!sbawEnableLoc k || sbawMouseLocked || !sbawHasMoved) {
if (e.type == "mousedown" ) {
e.preventDefaul t(); e.stopPropagati on();
window.removeEv entListener("mo usemove", sbawMoveScrollB ar, true);
}
else { // mouseup
if (sbawIsMac && e.button == sbawLeftButton && e.ctrlKey) var button = sbawRightButton ;
else button = e.button;
sbawEndScrollin g();
if (!sbawHasMoved && button == sbawRightButton ) {
e.preventDefaul t(); e.stopPropagati on();
sbawShowContext Menu(e);
}
}
}
else sbawMouseLocked = true;
}

function sbawOutHandler( e) {
if (!e.relatedTarg et) sbawEndScrollin g();
}[/PHP]
Sep 9 '07 #1
4 2062
gits
5,390 Recognized Expert Moderator Expert
hi ...

may be i simply don't get it but ... what do you want to have changed? is the extension not working or should it work another way? ... what is the problem you have?

kind regards

ps: installed it now - and: ahhh ... i see ... you want the mouse pointer to be sticky at the point where you right-clicked ... ok?

pps: interesting thing ;) ... i'll do some investigations :))
Sep 10 '07 #2
Eep²
14 New Member
Yea, the problem is if, say, the right mouse button is held down and moved into another part of the window (like tab bar, toolbar, menu bar, etc), and let go, the context menu will pop up and scrolling will still be active, thus being highly disorienting (not to mention annoying). Plus, since the mouse cursor doesn't have any screenwrapping, scrolling distance is limited based on the cursor's position--if it hits the screen edge, scrolling will stop.

I've tried emailing the author several times over the years but have never received a response... Hopefully you and/or someone else can figure it out. Thanks.
Sep 14 '07 #3
Eep²
14 New Member
Hello? Anyone? <insert more characters here>
Sep 17 '07 #4
gits
5,390 Recognized Expert Moderator Expert
hi ... yesterday i thought it over :) ... may be this week we should start a try to solve this ... at first let me simplify it and we will see what we may do with it ... but i need some time ... i'm really busy here at the office ...
Sep 17 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
6932
by: Robin Shuff | last post by:
Hi, I'm trying to limit the movement of the mouse cursor in using a VB app. The idea is to stop the cursor straying on to the second monitor of a dual screen set-up (i.e. a projector) while this program is running. I've found and have been working with Knowledge Base Article 179192...
1
2183
by: Tee | last post by:
Hi, From my main form, I am executing another application using System.Diagnostics.Process.Start. The application has its own window displaying when the applicaiton is run. I want to change the cursor to a hourglass. But I only can change my own form's cursor using Cursor.Current, whenever I move my mouse cursor into the window, the...
10
18049
by: Danny | last post by:
How can I get the coordinates of the mouse cursor in Mozilla browsers as well as Opera and IE6? I'm struggling to understand how to capture mouse movement events with Mozilla/Netscape/Firefox and I've Googled so much my brain hurts. http://www.ghpkendal.co.uk/TestPages/Test.htm Move your cursor over the yellow area and you should see the...
2
3042
by: Gas | last post by:
Hi, I also want to know how to change the mouse cursor to normal, hourglass.....etc. in runtime thanks Gas
3
3436
by: Tim | last post by:
Hi, How would I go about changing the windows mouse cursor ? (Not the mouse cursor on a form...but the actual mouse cursor in windows..) Any ideas would be greatly appreciated Thanks, Tim
1
3914
by: Tim | last post by:
Hi, I would like to create a custom mouse cursor for my print preview page. I want to use a bitmap of a magnifiying glass with a plus in it. Pretty standard stuff. How do I change the cursor? I found the code below but I just get the default mouse cursor dragging around the bitmap which is actually a little behind. I want to replace the
8
16985
by: Eddie | last post by:
Hi All, I just want to change the mouse cursor during a process. I want a hourglass... How may I do it ? Thx
3
2514
by: =?Utf-8?B?Vk1BTQ==?= | last post by:
Hi, I have a windows form with a ownerdraw combobox. When I draw the combobox items I also change the mouse cursor to something different than Cursors.Default. When the DropDown opens and the cursor moves inside, the cursor changes correctly. However, I would like to change the cursor back to Cursors.Default if the mouse exits the DropDown...
0
2293
by: Studlyami | last post by:
I am trying to find how windows translate the input from a HID device to an actual windows message; specifically, the mouse. I am trying to figure out how when the mouse moves the process windows takes in order to ensure all windows receive the notification that the mouse moved and how windows moves the mouse cursor. What process handles the...
0
7815
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7738
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7828
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8113
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5634
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5316
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2253
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1076
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.