realbasic-nug
[Top] [All Lists]

Re: Popup Menus in Listbox Cells

To: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Subject: Re: Popup Menus in Listbox Cells
From: Robert Steely <robsteely@gmail.com>
Date: Mon, 29 Jun 2009 17:21:57 -0500
Authentication-results: mx.google.com; spf=neutral (google.com: 74.124.194.228 is neither permitted nor denied by best guess record for domain of realbasic-nug-bounces@lists.realsoftware.com) smtp.mail=realbasic-nug-bounces@lists.realsoftware.com; dkim=neutral (body hash did not verify) header.i=@gmail.com
Delivered-to: listarchive@realsoftware.com
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type; bh=GfMD8u0U7xqLrHXNnq141pgJCmnKbhOOzeknZlXUMnI=; b=fNnR63NNDmRR3hvdmH73SthQnkVvqBJ6NyeSebz9KRcMYTYx73lJWRMtMsk+YCxkZx uFSQKIp/AjSSl2g36qD5dkUce4W9EiVQREqc08jEcg9wn6oeMO2j2rhsQDH55Gj/CW/U 4aOQDN5O/ThNkdAXH8IXpmcBl+7nvUY2u69pY=
Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=ZHvYUZ2NdSCuBi/xlGTFiv8zkiQftI1cgVfvP4s01zD/Ndpv4nupIMoT0O5I4XsQTU x1OegnRBqmBQtYeMVh06OpaZ5czQA7RZ0IIX0IS0l/yC5HFEnQarPTTicMUz3tcW56xz zvp+GxQal6GMhOrOHXOUlTsf1Mi9fX1Z8WpO8=
In-reply-to: <4A48D6DA.7020901@inspiringapps.com>
References: <4c8d6c440906290645r4a97bee0y2af0b236c3c5bfd8@mail.gmail.com> <4A48D6DA.7020901@inspiringapps.com>
Reply-to: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Sender: realbasic-nug-bounces@lists.realsoftware.com
Thank you all for the numerous suggestions. The listbox class suggested in
other replies looks promising but, I'd rather stick with pure RB code for
simplicity and cross-platform compatibility. At some point in the future, I
may end up exposing the source code to others in the intended target
community so they can tweak builds for Windows and Linux (which I can't test
on my own.)
I am going to try Karen's and Joe's popup menu suggestion. It looks pretty
straightforward and Joe has already done most of the work for me.  :)

Thanks again!

Bob

On Mon, Jun 29, 2009 at 9:59 AM, Joe Strout <joe@inspiringapps.com> wrote:

> Robert Steely wrote:
>
>  From reading the language reference listbox entry, this doesn't appear
>>>
>> currently possible.
>> I need to add a popup menu temporarily to a listbox cell to ensure the
>> user
>> populates the cell with a valid string value. Once the user selects an
>> item
>> from the popup menu, I would remove the popup and place the corresponding
>> string in the cell as non-editable.
>>
>
> Right.  Just set the cell type to TypeNormal, i.e., don't make it an
> editable cell.  When the user clicks on it, you get a CellClick event. Then
> you should show a popup menu.  I have a little listbox extension method I
> frequently use for this:
>
> Function PopUpCellChoices(extends lb As Listbox, row As Integer, column As
> Integer, choices() As String) As Boolean
>  // Pop up the menu of choices for this cell.  If the user picks one,
>  // store it in that cell and return True.  Otherwise, return False.
>
>  Dim menu As New MenuItem
>  for each choice As String in choices
>    if choice = "-" then
>      menu.Append New MenuItem( MenuItem.TextSeparator )
>    else
>      Dim item As New MenuItem( choice )
>      menu.Append item
>      if choice = lb.Cell( row, column ) then item.Checked = true
>    end if
>  next
>
>  Dim choice As MenuItem = menu.PopUp
>  if choice is nil then return False
>
>  lb.Cell( row, column ) = choice.Text
>  return True
> End Function
>
>
> So, in your CellClick event, you just call me.PopUpCellChoices, passing in
> the row, column, and list of values to choose frome, and it'll return which
> one was chosen.  You can then stuff this into the cell and do whatever else
> you need to do.
>
> In addition, you should probably draw some sort of indicator in the listbox
> that lets the user know they can pop up a menu here.  I do that with this
> other listbox extension:
>
>
> Sub DrawPopupIcon(extends lb As Listbox, g As Graphics)
>  static pic As Picture
>  if pic is nil then
>    pic = NewPicture( cell_popup_icon.width, cell_popup_icon.height, 32 )
>    Dim pg As Graphics = pic.graphics
>    pg.ForeColor = &c000000
>    pg.FillRect 0, 0, pic.width, pic.height
>    pg = pic.Mask.Graphics
>    pg.DrawPicture cell_popup_icon, 0, 0
>  end if
>
>  g.DrawPicture pic, g.width - 10, (g.height - pic.height)\2
> End Sub
>
> ...but it requires a monochrome picture in your project called
> cell_popup_icon.  The shenanigans above with "pic" are just to take the
> popup icon image (which has no transparency) and make it have a transparent
> background.  You could skip all that these days if you use a transparent
> PNG, or set use two images in your project and set one as the mask of the
> other.
>
> HTH,
> - Joe
>
>
> --
> Joe Strout
> Inspiring Applications, Inc.
> http://www.InspiringApps.com
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>


<Prev in Thread] Current Thread [Next in Thread>