FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

HowTo: tooltip from ListBox entry?

 
Post new topic   Reply to topic     Forum Index -> DFL
View previous topic :: View next topic  
Author Message
Lynn



Joined: 27 Aug 2004
Posts: 89

PostPosted: Fri Dec 24, 2004 7:23 am    Post subject: HowTo: tooltip from ListBox entry? Reply with quote

I'm porting a semi-specialized "reader" from C++ / MFC to D / DFL. I'd like to be able to implement OnHover tooltips when the mouse is over one of the ListBox entries.
Code:

.................
. Search Result .
. ListBox:      .
.................
. Line 1000     .
. Line 1010     .
. Line 2003     .
. Line 2999     .
. etc.          .
.................


When the mouse was "hovered" over one of the SearchResult ListBox entries, I'd like a ToolTip to show up that had that line shown as a tooltip.

With a MFC ListView, the OnNotify message allowed the code to figure out which ListView item was being hovered over. Can the equivalent be done with DFL? If so, sample code would be MUCH appreciated (perhaps an extension of tip.d?)

When filling the ListBox "on the fly" with Search matches, the following indicates that a Search found a match with the 43rd book, 3rd chapter, and 16th verse. The BcvRef::toString causes the string "John 3:16" to show up in the ListBox:
searchResultsListBox.items.add(new BcvRef(43, 3, 16));

Mea culpa ... I'm being lazy/pragmatic by checking if this can be done before putting in the time/effort to give it a try. If it isn't possible at this stage of DFL, I can wait.

I see that control.d provides "ENABLE_NOTIFY_MESSAGE" and onNotifyMessage(Message msg). I didn't see any sample code that used this, however.

Just curious ... why do you hate tooltips?

On this (off?) topic: Perhaps you could provide some advanced example code that illustrates using native Win32 api calls to do things using SendMessage and SetWindowLong, for example.

My impression is that this would allow usage of Win32 api features that DFL doesn't yet implement. It would also facilitate people contributing to DFL by sending you code that accomplishes something that DFL is missing.

Again, thanks VERY much for providing DFL. I can only speculate about the amount of time/effort put into it, as well as the foregone income opportunities. I'm learning quite a bit about D features from looking over your code.
Back to top
View user's profile Send private message
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Fri Dec 24, 2004 8:49 am    Post subject: Reply with quote

For now you can do something like this,
Code:

class ParentForm: Form
{
   protected override void wndProc(inout Message m)
   {
      super.wndProc(m);

      if(m.msg == WM_NOTIFY)
      {
         // Check if the NMHDR.code is TTN_SHOW or something..,
         // Then use ListBox.indexFromPoint (make sure it's not -1 and don't forget about client/screen coords)
         // Set the tool tip's text accordingly...
      }
   }
}


This was just a quick reply, I'll look more into it after the holiday. Have a good one!
- Chris
Back to top
View user's profile Send private message
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Mon Dec 27, 2004 3:00 pm    Post subject: Re: HowTo: tooltip from ListBox entry? Reply with quote

Lynn wrote:
I'd like to be able to implement OnHover tooltips when the mouse is over one of the ListBox entries.
How about this
Code:
class MainForm: Form
{
   ToolTip ttip;
   ListBox myList;
   
   this()
   {
      if(!Control.supportsMouseTracking)
         MessageBox.show("Please install Internet Explorer 5.5 or higher.");
     
      ttip = new ToolTip;
     
      with(myList = new ListBox)
      {
         items.add("Foo");
         items.add("Bar");
         parent = this;
         
         mouseHover ~= &myList_hover;
      }
   }
   
   
   private void myList_hover(Object sender, MouseEventArgs ea)
   {
      int i;
      i = myList.indexFromPoint(ea.x, ea.y);
      if(i != -1)
      {
         ttip.setToolTip(myList, "Item: " ~ myList.items[i].toString());
         ttip.active = true; // Show the tip now.
      }
      else
      {
         ttip.setToolTip(myList, null);
      }
   }
}
You'll need today's snapshot because this code caught a bug.

Windows 95 doesn't support mouse tracking without IE 5.5+ which includes events mouseEnter, mouseLeave and mouseHover. You can use the property Control.supportsMouseTracking to test for its availability.


Quote:
I see that control.d provides "ENABLE_NOTIFY_MESSAGE" and onNotifyMessage(Message msg). I didn't see any sample code that used this, however.
It's just a way to get notified of all WindowProc messages. I'm thinking of removing it because you can just use wndProc().


Quote:
Just curious ... why do you hate tooltips?
They always pop up in the way Razz I don't mind the delayed ones as much. One example of a really crappy tooltip is with XP's auto-hide tray icon feature. Click the arrow to show all the icons and up comes a tooltip covering up all the icons. Move the mouse to remove the tool tip and the icons get hidden again.


Quote:
Again, thanks VERY much for providing DFL. I can only speculate about the amount of time/effort put into it, as well as the foregone income opportunities. I'm learning quite a bit about D features from looking over your code.
Cool Shocked
Back to top
View user's profile Send private message
Lynn



Joined: 27 Aug 2004
Posts: 89

PostPosted: Wed Dec 29, 2004 12:22 pm    Post subject: Reply with quote

> How about this

Almost ... but it has odd/flawed behavior, at least how I tested it. I expanded it into a complete program so as to submit as a tutorial (and then to incorporate into my app).

However, each time when the mouse enters the ListBox, the entries in the ListBox are repeated. At creation, you see three entries in the List Box (First, Second, and Third). When the mouse first enters the ListBox, you see 6 entries ... then 9, then 12, etc.

After changing the original code to just show the i index in the Form Title, the onHover works, in that if you move to the 5th entry, it can detect that you are hovering over the 5th entry.

Am I doing something wrong? If I comment out the following line, the onHover sort of works, in that the Title reflects the index number.
ttip.setToolTip(myList, "Item: " ~ std.string.toString(i));


Also, it only seems to work once. It doesn't seem to "track" as the mouse moves to different ListBox entries. As the mouse hovered over different entries, I would expect the Form title to tooltip to change to correspond.

Here's my test code as tweaked slightly from the code you provided:
Code:

private import std.string;

private import dfl.all;

class MainForm: Form
{
  ToolTip ttip;
  ListBox myList;
   
  this()
  {
    if(!Control.supportsMouseTracking)
      MessageBox.show("Please install Internet Explorer 5.5 or higher.");
   
    ttip = new ToolTip;
   
    with(myList = new ListBox)
    {
      items.add("First: i=0");
      items.add("Second: i=1");
      items.add("Third: i=2");
      parent = this;
       
      mouseHover ~= &myList_hover;
    }
  }
   
   
  private void myList_hover(Object sender, MouseEventArgs ea)
  {
    int i;
    i = myList.indexFromPoint(ea.x, ea.y);
    if(i != -1)
    {
      text = "Hovering over item: " ~ std.string.toString(i);
      ttip.setToolTip(myList, "Item: " ~ std.string.toString(i));
      ttip.active = true; // Show the tip now.
    }
    else
    {
      ttip.setToolTip(myList, null);
    }
  }
}

int main()
{
  Application.run(new MainForm);
 
  return 0;
}
Back to top
View user's profile Send private message
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Thu Dec 30, 2004 2:23 pm    Post subject: Reply with quote

Lynn wrote:
However, each time when the mouse enters the ListBox, the entries in the ListBox are repeated. At creation, you see three entries in the List Box (First, Second, and Third). When the mouse first enters the ListBox, you see 6 entries ... then 9, then 12, etc.
Did you see this part,
Vathix wrote:
You'll need today's snapshot because this code caught a bug.
or is the problem in that one, too?


Lynn wrote:
Also, it only seems to work once. It doesn't seem to "track" as the mouse moves to different ListBox entries.
DFL just fires the hover event when receiving the WM_MOUSEHOVER message. Maybe you have to work around it with a timer or something..
Back to top
View user's profile Send private message
Lynn



Joined: 27 Aug 2004
Posts: 89

PostPosted: Thu Dec 30, 2004 3:21 pm    Post subject: Reply with quote

Hope your holidays are going well ... and I appreciate the timely (and patient) support you provide for DFL.

The problem I describe is from the latest 2004-Dec-27 snapshot ... listbox.d is size 27,073, dated 12/27/2004 3:04pm.
Back to top
View user's profile Send private message
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Thu Dec 30, 2004 6:32 pm    Post subject: Reply with quote

That's the bug I thought I fixed in the snapshot. The code you posted doesn't have that problem for me Shocked
Back to top
View user's profile Send private message
Lynn



Joined: 27 Aug 2004
Posts: 89

PostPosted: Fri Dec 31, 2004 11:42 am    Post subject: Reply with quote

My error ... I had the Dec 27 snapshot, but I didn't replace dfl.lib ... ouch

It works fine now. THANKS!

Quote:
Lynn wrote:
Also, it only seems to work once. It doesn't seem to "track" as the mouse moves to different ListBox entries.
Vathix wrote:
DFL just fires the hover event when receiving the WM_MOUSEHOVER message. Maybe you have to work around it with a timer or something..


Looking at it a bit longer, the ToolTip seems to work this way ... it stays visible until the mouse cursor touches it. If the ToolTip appears below the ListBox entry, it is 'dismissed' when you move the mouse lower. If you move up, the previous ToolTip stays visible.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> DFL All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group