# ComboBox with pop-up menu above

**URL:** <https://forum.juce.com/t/combobox-with-pop-up-menu-above/973>\
**Category:** General JUCE discussion\
**Created:** [August 3, 2006, 9:07pm UTC](https://forum.juce.com/t/combobox-with-pop-up-menu-above/973 "2006-08-03T21:07:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![matt](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/matt/32/18340_2.png) [@matt](https://forum.juce.com/u/matt)\
**Post date:** [August 3, 2006, 9:07pm UTC](https://forum.juce.com/t/combobox-with-pop-up-menu-above/973/1 "2006-08-03T21:07:22Z")

</div>

I was having a problem with a combo box with a large menu (17 entries). If the window was too close to the bottom of the screen, the pop-up menu does correctly appear above the combo box, but would vanish as soon as I released the mouse.

If the pop-up menu was below the combo box, then it would remain after I did the first mouse-up and would only vanish after clicking an entry in the pop-up menu.

Looking at ComboBox::mouseUp, I found an if statement that decides whether or not to dispatch the mouse-up to the pop-up menu. So I changed this:

```auto
      if (activePopup != 0)
		{
            activePopup->handleMouseUp (e);
		}
```

to this:

```auto
      if ((activePopup != 0) && activePopup->contains (e.getScreenX() - activePopup->getScreenX(),
                                          e.getScreenY() - activePopup->getScreenY()))
		{
            activePopup->handleMouseUp (e);
		}
```

That seems to have done the trick.

There might be a cleaner way to do this, but this is fine for now.

Strangely, this problem doesn’t occur with the combo box in the JUCE demo.

Matt

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [August 4, 2006, 9:49am UTC](https://forum.juce.com/t/combobox-with-pop-up-menu-above/973/2 "2006-08-04T09:49:12Z")

</div>

That’s very odd, and I can’t find a way of making it happen here. But your fix isn’t quite right, as it’ll stop it dismissing the popup correctly - the popup box still needs mouse events that are off its edge. I had a scan through that method and tidied it up, so try these snippets, (though I couldn’t see any bugs in what was there before):

[code] void handleMouseUp (const MouseEvent& e)  
{  
const MouseEvent e2 (e.getEventRelativeTo (list));

```
    if (contains (e2.x, e2.y))
    {
        dismiss();

        const int rowUnderMouse = list->getRowContainingPosition (e2.x, e2.y);

        if (rowUnderMouse >= 0)
        {
            returnKeyPressed (rowUnderMouse);

            // (this component might now have been deleted)
            return;
        }
    }
    else if (e.getDistanceFromDragStart() > 8)
    {
        dismiss();
    }
}[/code]

```

[code]  
void ComboBox::mouseUp (const MouseEvent& e2)  
{  
if (popupDeletionWatcher != 0 && popupDeletionWatcher-\>hasBeenDeleted())  
deletePopup();

```
// need to watch out for repeated mouse-ups arriving in succession because this is a mouselistener -
// so only the fist mouse-up afer a mouse-down will be responded to..
if (isButtonDown)
{
    isButtonDown = false;

    repaint();
    const MouseEvent e (e2.getEventRelativeTo (this));

    if (Component::reallyContains (e.x, e.y, true)
         && (e2.component == this || ! label->isEditable()))
    {
        Component* const lastFocusedComponent = Component::getCurrentlyFocusedComponent();

        if (activePopup == 0)
            createPopup();

        activePopup->grabKeyboardFocus();

        activePopup->runModalLoop();

        if (lastFocusedComponent->isValidComponent())
            lastFocusedComponent->grabKeyboardFocus();
    }
    else if (activePopup != 0)
    {
        activePopup->handleMouseUp (e);
    }
}

```

}[/code]

---

<div class="post-metadata">

**Author:** ![matt](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/matt/32/18340_2.png) [@matt](https://forum.juce.com/u/matt)\
**Post date:** [August 4, 2006, 6:09pm UTC](https://forum.juce.com/t/combobox-with-pop-up-menu-above/973/3 "2006-08-04T18:09:13Z")

</div>

I looked at this some more; it looks like it only happens if you have a native title bar on your window.

It’s easily reproduced with the JUCE demo without any code changes:

-open the demo, select the “misc widgets” tab  
-drag the window down so the combo box is just above the bottom of the screen  
-select “Use native window title bar” from the menu  
-click on the combo box

I’ll try your fix; thanks!

Matt

---

<div class="post-metadata">

**Author:** ![matt](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/matt/32/18340_2.png) [@matt](https://forum.juce.com/u/matt)\
**Post date:** [August 4, 2006, 6:13pm UTC](https://forum.juce.com/t/combobox-with-pop-up-menu-above/973/4 "2006-08-04T18:13:28Z")

</div>

I tried the new code; unfortunately, the problem persists.

Matt

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [August 4, 2006, 8:52pm UTC](https://forum.juce.com/t/combobox-with-pop-up-menu-above/973/5 "2006-08-04T20:52:46Z")

</div>

aha! I didn’t think of trying it with a title bar! It’s a very subtle bug in juce\_win32\_Windowing.cpp - replace this method:

[code] void doCaptureChanged()  
{  
RECT wr;  
GetWindowRect (hwnd, &wr);

```
    currentModifiers &= ~ModifierKeys::allMouseButtonModifiers;
    isDragging = false;

    const DWORD mp = GetMessagePos();

    handleMouseExit (GET_X_LPARAM (mp) - wr.left - windowBorder.getLeft(),
                     GET_Y_LPARAM (mp) - wr.top - windowBorder.getTop(),
                     getMouseEventTime());
}

```

[/code]

---

<div class="post-metadata">

**Author:** ![matt](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/matt/32/18340_2.png) [@matt](https://forum.juce.com/u/matt)\
**Post date:** [August 7, 2006, 6:53pm UTC](https://forum.juce.com/t/combobox-with-pop-up-menu-above/973/6 "2006-08-07T18:53:51Z")

</div>

Thanks! That did it. I don’t think I would have found that one on my own.

Matt

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [May 12, 2017, 10:01am UTC](https://forum.juce.com/t/combobox-with-pop-up-menu-above/973/7 "2017-05-12T10:01:09Z")

</div>

Closed on May 12, 2017, 10:01am UTC


