1. Win32Lib: listbox: select item with RIGHT mouse click?
When you LEFT click on an item in a listbox, it gets selected, and you can
use getIndex to tell you which item was selected, and cause an action
relative to that item with a left double-click (which can be done in one
motion: move cursor to item, then double-click); but I'd also like to make
something happen if an item is RIGHT clicked, but it seems I have to select
the item first with a left click, and then do a right click.
Is there a way to cause a right click alone to select an item in a list and
thence be able to act with regard to that item?
Dan
2. Re: Win32Lib: listbox: select item with RIGHT mouse click?
I don't think there's any automatic way to do this. You'd have to trap the
right click, do a hit test and select the item, if any. There are built in
functions for Listviews and Treeviews, but I think you'd have to do this
manually for a regular list box. You'd want to use a combination of
LB_GETITEMRECT and LB_GETTOPINDEX for the hit testing, to get the
information on what the first visible item is in the list box, and then the
size of the items...
Matt Lewis
> -----Original Message-----
> From: Dan B Moyer
>
> When you LEFT click on an item in a listbox, it gets
> selected, and you can
> use getIndex to tell you which item was selected, and cause an action
> relative to that item with a left double-click (which can be
> done in one
> motion: move cursor to item, then double-click); but I'd also
> like to make
> something happen if an item is RIGHT clicked, but it seems I
> have to select
> the item first with a left click, and then do a right click.
>
> Is there a way to cause a right click alone to select an item
> in a list and
> thence be able to act with regard to that item?
>
> Dan
>
3. Re: Win32Lib: listbox: select item with RIGHT mouse click?
- Posted by Dan B Moyer <DANMOYER at PRODIGY.NET>
Sep 01, 2000
-
Last edited Sep 02, 2000
Matthew,
Could you explain what you mean by a "hit test"(ie, hits what, since no
index is returned), & how to use LB_GETITEMRECT and LB_GETTOPINDEX for the
hit testing? (Are you talking about getting the size( y extent) of the
listbox, the y position of the right-mouse click in the listbox, the number
of items in the listbox, the y size of each item, & then compute which item
was clicked on from all that??)
Dan
Matthew wrote:
> I don't think there's any automatic way to do this. You'd have to trap
the
> right click, do a hit test and select the item, if any. There are built
in
> functions for Listviews and Treeviews, but I think you'd have to do this
> manually for a regular list box. You'd want to use a combination of
> LB_GETITEMRECT and LB_GETTOPINDEX for the hit testing, to get the
> information on what the first visible item is in the list box, and then
the
> size of the items...
>
> Matt Lewis
>
>
>
> > -----Original Message-----
> > From: Dan B Moyer
> >
> > When you LEFT click on an item in a listbox, it gets
> > selected, and you can
> > use getIndex to tell you which item was selected, and cause an action
> > relative to that item with a left double-click (which can be
> > done in one
> > motion: move cursor to item, then double-click); but I'd also
> > like to make
> > something happen if an item is RIGHT clicked, but it seems I
> > have to select
> > the item first with a left click, and then do a right click.
> >
> > Is there a way to cause a right click alone to select an item
> > in a list and
> > thence be able to act with regard to that item?
> >
> > Dan
> >
4. Re: Win32Lib: listbox: select item with RIGHT mouse click?
Here's a solution to right click list box selection:
-----------------------------------------------------------------------
include Win32Lib.ew
constant Desktop=0
constant Window1=
create(Window,"Test LB right clicks",Desktop,10,10,580,460,0)
constant ListBox2=create(List,"2",Window1,40,20,260,200,0)
--test listbox demo items:
for j=1 to 30 do
addItem(ListBox2,"entry"&sprintf("%d",j))
end for
--define constants if not already defined in Win32Lib.ew:
constant LB_GETITEMHEIGHT=#01A1,
LB_GETTOPINDEX=#018E
-- LB_SETCURSEL=#0186
--include an onMouse event in your program code:
procedure onMouse_ListBox2(integer event, integer x, integer y)
--insert event code here:
atom lParam,index,bool,height,topindex,indexoffset
sequence itemtext
if event=RIGHT_DOWN then
height=sendMessage(ListBox2,LB_GETITEMHEIGHT,0,0)
topindex=sendMessage(ListBox2,LB_GETTOPINDEX,0,0)
indexoffset=floor(y/height)
index=indexoffset+topindex
bool=sendMessage(ListBox2,LB_SETCURSEL,index,0)
itemtext=getItem(ListBox2,index+1)
--printf(1,"%s\n",{itemtext}) --unrem to print values
--put any further processing code here:
--
end if
end procedure
onMouse[ListBox2]=routine_id("onMouse_ListBox2")
--may have to modify this last line for your version of Win32Lib:
WinMain(Window1,Normal)
------------------------------------------------------------------
Good luck with it.
Al Getz
5. Re: Win32Lib: listbox: select item with RIGHT mouse click?
That's exactly what I'm talking about. :) A hittest is basically figuring out
which, if any, item is 'hit' by a given point. In this case, we're interested
in finding out which item might be under the mouse pointer. Take a look at
hitTestTV (in Win32Lib) to get an idea (although windows does most of the hard
stuff for that).
I don't have the details of LB_GETITEMRECT and LB_GETTOPINDEX in front of me,
but you can find them in either the Win32 help file (which everyone who codes
in windows should have handy) or online at Microsoft's MSDN library (just do a
search at msdn.microsoft.com).
I think the hit test pseudo code should go something like this:
- get the position of the mouse cursor
- figure out how big each item in the list box is (you could do this ahead of
time)
- get the first item listed
- compute how far down on the list the mouse is, based on the item size
- if there is an item there (ie, if the list is long enough), return the index
Then, in an onMouse routine for your listbox, I'd trap the right click, and do
a hittest. If a positive index is returned, set that as the selection, and
then do whatever else you wanted (like opening a popup menu).
Matt
--- Dan B Moyer <DANMOYER at PRODIGY.NET> wrote:
> Matthew,
>
> Could you explain what you mean by a "hit test"(ie, hits what, since no
> index is returned), & how to use LB_GETITEMRECT and LB_GETTOPINDEX for the
> hit testing? (Are you talking about getting the size( y extent) of the
> listbox, the y position of the right-mouse click in the listbox, the number
> of items in the listbox, the y size of each item, & then compute which item
> was clicked on from all that??)
>
> Dan
>
__________________________________________________
Do You Yahoo!?
Yahoo! Mail - Free email you can access from anywhere!
http://mail.yahoo.com/
6. Re: Win32Lib: listbox: select item with RIGHT mouse click?
Al,
Thanks, I'll try it & see how it works for me.
Dan
----- Original Message -----
From: "Al Getz" <xaxo at AOL.COM>
To: <EUPHORIA at LISTSERV.MUOHIO.EDU>
Sent: Saturday, September 02, 2000 8:20 AM
Subject: Re: Win32Lib: listbox: select item with RIGHT mouse click?
> Here's a solution to right click list box selection:
>
> -----------------------------------------------------------------------
> include Win32Lib.ew
>
> constant Desktop=0
>
> constant Window1=
> create(Window,"Test LB right clicks",Desktop,10,10,580,460,0)
>
> constant ListBox2=create(List,"2",Window1,40,20,260,200,0)
>
>
>
> --test listbox demo items:
>
> for j=1 to 30 do
> addItem(ListBox2,"entry"&sprintf("%d",j))
> end for
>
>
>
>
>
> --define constants if not already defined in Win32Lib.ew:
>
> constant LB_GETITEMHEIGHT=#01A1,
> LB_GETTOPINDEX=#018E
> -- LB_SETCURSEL=#0186
>
> --include an onMouse event in your program code:
>
> procedure onMouse_ListBox2(integer event, integer x, integer y)
> --insert event code here:
> atom lParam,index,bool,height,topindex,indexoffset
> sequence itemtext
>
> if event=RIGHT_DOWN then
> height=sendMessage(ListBox2,LB_GETITEMHEIGHT,0,0)
> topindex=sendMessage(ListBox2,LB_GETTOPINDEX,0,0)
> indexoffset=floor(y/height)
> index=indexoffset+topindex
>
> bool=sendMessage(ListBox2,LB_SETCURSEL,index,0)
> itemtext=getItem(ListBox2,index+1)
>
> --printf(1,"%s\n",{itemtext}) --unrem to print values
>
> --put any further processing code here:
>
>
> --
> end if
> end procedure
> onMouse[ListBox2]=routine_id("onMouse_ListBox2")
>
> --may have to modify this last line for your version of Win32Lib:
> WinMain(Window1,Normal)
>
> ------------------------------------------------------------------
>
> Good luck with it.
> Al Getz
7. Re: Win32Lib: listbox: select item with RIGHT mouse click?
Matt,
<grin!> That's what I was afraid you were talking about! I think I'll give
Al's solution a try first, looks easier! :) Thanks.
Dan
----- Original Message -----
From: "Matt Lewis" <matthewwalkerlewis at YAHOO.COM>
To: <EUPHORIA at LISTSERV.MUOHIO.EDU>
Sent: Saturday, September 02, 2000 10:26 AM
Subject: Re: Win32Lib: listbox: select item with RIGHT mouse click?
> That's exactly what I'm talking about. :) A hittest is basically figuring
out
> which, if any, item is 'hit' by a given point. In this case, we're
interested
> in finding out which item might be under the mouse pointer. Take a look
at
> hitTestTV (in Win32Lib) to get an idea (although windows does most of the
hard
> stuff for that).
>
> I don't have the details of LB_GETITEMRECT and LB_GETTOPINDEX in front of
me,
> but you can find them in either the Win32 help file (which everyone who
codes
> in windows should have handy) or online at Microsoft's MSDN library (just
do a
> search at msdn.microsoft.com).
>
> I think the hit test pseudo code should go something like this:
>
> - get the position of the mouse cursor
> - figure out how big each item in the list box is (you could do this ahead
of
> time)
> - get the first item listed
> - compute how far down on the list the mouse is, based on the item size
> - if there is an item there (ie, if the list is long enough), return the
index
>
> Then, in an onMouse routine for your listbox, I'd trap the right click,
and do
> a hittest. If a positive index is returned, set that as the selection,
and
> then do whatever else you wanted (like opening a popup menu).
>
> Matt
>
> --- Dan B Moyer <DANMOYER at PRODIGY.NET> wrote:
> > Matthew,
> >
> > Could you explain what you mean by a "hit test"(ie, hits what, since no
> > index is returned), & how to use LB_GETITEMRECT and LB_GETTOPINDEX for
the
> > hit testing? (Are you talking about getting the size( y extent) of the
> > listbox, the y position of the right-mouse click in the listbox, the
number
> > of items in the listbox, the y size of each item, & then compute which
item
> > was clicked on from all that??)
> >
> > Dan
> >
>
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Mail - Free email you can access from anywhere!
> http://mail.yahoo.com/
8. Re: Win32Lib: listbox: select item with RIGHT mouse click?
- Posted by Dan B Moyer <DANMOYER at PRODIGY.NET>
Sep 02, 2000
-
Last edited Sep 03, 2000
Al,
Your right click in listbox demo works just fine (once I added integer shift
to the onMouse parameter list); now to put it into my program....
Thanks again!
Dan
----- Original Message -----
From: "Al Getz" <xaxo at AOL.COM>
To: <EUPHORIA at LISTSERV.MUOHIO.EDU>
Sent: Saturday, September 02, 2000 8:20 AM
Subject: Re: Win32Lib: listbox: select item with RIGHT mouse click?
> Here's a solution to right click list box selection:
>
> -----------------------------------------------------------------------
> include Win32Lib.ew
>
> constant Desktop=0
>
> constant Window1=
> create(Window,"Test LB right clicks",Desktop,10,10,580,460,0)
>
> constant ListBox2=create(List,"2",Window1,40,20,260,200,0)
>
>
>
> --test listbox demo items:
>
> for j=1 to 30 do
> addItem(ListBox2,"entry"&sprintf("%d",j))
> end for
>
>
>
>
>
> --define constants if not already defined in Win32Lib.ew:
>
> constant LB_GETITEMHEIGHT=#01A1,
> LB_GETTOPINDEX=#018E
> -- LB_SETCURSEL=#0186
>
> --include an onMouse event in your program code:
>
> procedure onMouse_ListBox2(integer event, integer x, integer y)
> --insert event code here:
> atom lParam,index,bool,height,topindex,indexoffset
> sequence itemtext
>
> if event=RIGHT_DOWN then
> height=sendMessage(ListBox2,LB_GETITEMHEIGHT,0,0)
> topindex=sendMessage(ListBox2,LB_GETTOPINDEX,0,0)
> indexoffset=floor(y/height)
> index=indexoffset+topindex
>
> bool=sendMessage(ListBox2,LB_SETCURSEL,index,0)
> itemtext=getItem(ListBox2,index+1)
>
> --printf(1,"%s\n",{itemtext}) --unrem to print values
>
> --put any further processing code here:
>
>
> --
> end if
> end procedure
> onMouse[ListBox2]=routine_id("onMouse_ListBox2")
>
> --may have to modify this last line for your version of Win32Lib:
> WinMain(Window1,Normal)
>
> ------------------------------------------------------------------
>
> Good luck with it.
> Al Getz
9. Re: Win32Lib: listbox: select item with RIGHT mouse click?
- Posted by Dan B Moyer <DANMOYER at PRODIGY.NET>
Sep 02, 2000
-
Last edited Sep 03, 2000
Al,
Oh, and I also incremented "index" just after "bool", so it could directly
used to reference to a right selected item. Thanks again! I think this
deserves to be an EXAMPLE to be included in Win32Lib.
bool=sendMessage(ListBox2,LB_SETCURSEL,index,0)
index +=1-- changed this
itemtext=getItem(ListBox2,index) -- and this
Dan
----- Original Message -----
From: "Al Getz" <xaxo at AOL.COM>
To: <EUPHORIA at LISTSERV.MUOHIO.EDU>
Sent: Saturday, September 02, 2000 8:20 AM
Subject: Re: Win32Lib: listbox: select item with RIGHT mouse click?
> Here's a solution to right click list box selection:
>
> -----------------------------------------------------------------------
> include Win32Lib.ew
>
> constant Desktop=0
>
> constant Window1=
> create(Window,"Test LB right clicks",Desktop,10,10,580,460,0)
>
> constant ListBox2=create(List,"2",Window1,40,20,260,200,0)
>
>
>
> --test listbox demo items:
>
> for j=1 to 30 do
> addItem(ListBox2,"entry"&sprintf("%d",j))
> end for
>
>
>
>
>
> --define constants if not already defined in Win32Lib.ew:
>
> constant LB_GETITEMHEIGHT=#01A1,
> LB_GETTOPINDEX=#018E
> -- LB_SETCURSEL=#0186
>
> --include an onMouse event in your program code:
>
> procedure onMouse_ListBox2(integer event, integer x, integer y)
> --insert event code here:
> atom lParam,index,bool,height,topindex,indexoffset
> sequence itemtext
>
> if event=RIGHT_DOWN then
> height=sendMessage(ListBox2,LB_GETITEMHEIGHT,0,0)
> topindex=sendMessage(ListBox2,LB_GETTOPINDEX,0,0)
> indexoffset=floor(y/height)
> index=indexoffset+topindex
>
> bool=sendMessage(ListBox2,LB_SETCURSEL,index,0)
> itemtext=getItem(ListBox2,index+1)
>
> --printf(1,"%s\n",{itemtext}) --unrem to print values
>
> --put any further processing code here:
>
>
> --
> end if
> end procedure
> onMouse[ListBox2]=routine_id("onMouse_ListBox2")
>
> --may have to modify this last line for your version of Win32Lib:
> WinMain(Window1,Normal)
>
> ------------------------------------------------------------------
>
> Good luck with it.
> Al Getz
10. Re: Win32Lib: listbox: select item with RIGHT mouse click?
Dan,
Yes i see your parameter addition is needed in the newer version of
Win32Lib. I'm currently using an older version to which i've added
alot of things. Soon i'll have to update to the newer version.
Also, you might have noticed a declared atom "lParam" in the atom
list for that procedure. This was a remnant from experimentation
with the windows listbox message LB_ITEMFROMPOINT and can be removed
also. I've tried on several occasions to get this message to work
but with no success even though it's well documented. If anyone else
is interested in trying, constant LB_ITEMFROMPOINT=#01A9. Please
let me know if you have any success with it.
Glad it helped.
-- Al
original:
>>
Al,
Your right click in listbox demo works just fine (once I added integer shift
to the onMouse parameter list); now to put it into my program....
Thanks again!
Dan
<<