A 'PopupList' control (implemented with OOP).

Share your advanced PureBasic knowledge/code with the community.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

A 'PopupList' control (implemented with OOP).

Post by srod »

Update - Jan 1st 2008.
Bug fixed.

The PopupList control was destroying all other ownerdrawn controls placed on the same window! Doh! :oops:

Download

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

Hi,

I was in need of a simple (and easy to implement! :wink: ) control which combined the functionality of a basic popup menu with a scrollable listbox gadget and one which could be positioned anywhere. By simple I mean that I wanted Windows to do all the hard work of tracking the mouse, dealing with overlap, keyboard control etc. :wink:

Hence, a whopping great cheat was in order!

Still, minimal testing aside, it seems to work okay.

Here's a quick demo Windows exe which you can try :

http://www.purecoder.net/PopupList.exe
(Simply run it and right-click anywhere in the Window etc.)

Methods exposed by the PopupList class :

Code: Select all

AddItem(position, text.s)
ClearItems()
Destroy()
GetColor.l(colorType)
GetFont.l()
GetHeight.l()               
GetItem.s(position)
GetItemCount.l()
GetState.l()
GetWidth.l()
GetX.l()
GetY.l()
RemoveItem(position)
Resize(x, y, width, height)
SetColor(colorType, color)
SetFont(font)
Show.l(state=-1)
NOTES.
  • There is no help manual / user guide. Instead, look at the residents file for a few comments on each method where appropriate. Most methods are completely and utterly self explanatory.
  • This can easily be extended to allow for icons etc.
  • Embedding other controls within this control is quite feasible. It would be quite a bit of work though and it is not something which I require just yet, so I will leave this for another day.
  • I haven't done much testing!
Download the complete source
Last edited by srod on Fri Feb 01, 2008 9:15 pm, edited 1 time in total.
I may look like a mule, but I'm not a complete ass.
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

Too cool. :D

Thanks.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

very nice, Thank You :)
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

You're both welcome.

@SFSxOI : I saw your recent post in which you asked about something like this; however at that time I wasn't in need of this myself! Today, however, I found myself needing exactly this! :)
I may look like a mule, but I'm not a complete ass.
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

I think I can find a good use for this control. :)
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

DoubleDutch wrote:I think I can find a good use for this control. :)
I already have! :wink:
I may look like a mule, but I'm not a complete ass.
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post by Dare »

Very nice.

Small (tiny, miniscule) thing - It is smart enough to know how to position the popup when the window is at the bottom or almost off the bottom of the screen (goes up from pointer rather than down) however on the right edge of the screen it disappears. That is, it always appears to the right of the mouse pointer.

I assume that this means the calling code needs to check X position - although it appears that it doesn't need to check Y position?.

Very nice!
Dare2 cut down to size
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

It's actually an ownerdrawm combobox (rather than a popup menu) and so the automatic repositioning is all down to Windows; nowt to do with me! :)

As for disappearing off the right edge of the screen, yes it's down to the 'dodgy' demo. In a proper application you'd have to take a little care with that simply because, as I say, the control is based upon a combobox and not a popup menu. It would be a simple task to code around this.
I may look like a mule, but I'm not a complete ass.
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post by Dare »

Thanks for confirming.

Weird that windows bothers to check Y and not X in this case.
Dare2 cut down to size
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

It does make sense.

When the listbox which pops up disappears beneath the screen, the actual selection field of the combobox is still fully within the bounds of the main window. All windows does is then move the listbox (not the combo) up the screen.

However, if the listbox disappears off the right of the screen, it means that the selection field of the original combo was positioned in such a way that it did not fit within the bounds of the parent window etc. It then doesn't seem unreasonable that windows should refuse to do anything about it.

You must remember that in my demo, when you right click, an entire combo box is being placed on the screen so that the top left corner of the selection field is positioned exactly where you click. Thus if you click too close to the right edge of the screen... :)

Easy to get around.
I may look like a mule, but I'm not a complete ass.
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post by Dare »

srod wrote:Easy to get around.
Yes. And now my curiosity is satisfied as well. :) Thanks!
Dare2 cut down to size
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

@srod

Yes! I was needing exactly this very thing. Thank You very much...this will really clean up some menu stuff for something I was working on and make it much neater and cleaner, even lend a 'snappy crisp' feel to the project. :)
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

:) Glad it is of use.

There is a little bit of flicker within the client area when scrolling the control. I may address this at some point as it should be easy enough to prevent. Depends on how annoying it gets!
I may look like a mule, but I'm not a complete ass.
Marco2007
Enthusiast
Enthusiast
Posts: 648
Joined: Tue Jun 12, 2007 10:30 am
Location: not there...

Post by Marco2007 »

Excellent!!

Thank you very much! :D

BTW: Why does Srod have only three stripes?
PureBasic for Windows
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

You're welcome.
Marco2007 wrote:BTW: Why does Srod have only three stripes?
hehe, I think I used to have 4... too many off-topic posts! :wink:

It's like my old girlfriend used to say; 'it's not how many you've got or how big they are, it's what you do with 'em that counts!'

Uhm, thinking about it, how the hell did she knew how many stripes I had or indeed how big they were?

Wait, hang on a moment ......

:)
I may look like a mule, but I'm not a complete ass.
Post Reply