1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
7 * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
26 #include "win32_popup.hpp"
27 #include "win32_factory.hpp"
29 #ifndef TPM_NOANIMATION
30 const UINT TPM_NOANIMATION = 0x4000L;
34 Win32Popup::Win32Popup( intf_thread_t *pIntf, HWND hAssociatedWindow )
35 : OSPopup( pIntf ), m_hWnd( hAssociatedWindow )
37 // Create the popup menu
38 m_hMenu = CreatePopupMenu();
42 msg_Err( getIntf(), "CreatePopupMenu failed" );
48 Win32Popup::~Win32Popup()
51 DestroyMenu( m_hMenu );
55 void Win32Popup::show( int xPos, int yPos )
57 TrackPopupMenuEx( m_hMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON
58 | TPM_HORIZONTAL | TPM_NOANIMATION,
59 xPos, yPos, m_hWnd, NULL );
63 void Win32Popup::hide()
65 SendMessage( m_hWnd, WM_CANCELMODE, 0, 0 );
69 void Win32Popup::addItem( const string &rLabel, int pos )
71 MENUITEMINFO menuItem;
72 menuItem.cbSize = sizeof( MENUITEMINFO );
73 // menuItem.fMask = MIIM_FTYPE | MIIM_ID | MIIM_TYPE | MIIM_STRING;
74 // menuItem.fType = MFT_STRING;
75 menuItem.fMask = MIIM_ID | MIIM_STRING;
77 menuItem.dwTypeData = (char*)rLabel.c_str();
78 menuItem.cch = rLabel.size();
80 InsertMenuItem( m_hMenu, findInsertionPoint( pos ), TRUE, &menuItem );
84 void Win32Popup::addSeparator( int pos )
87 sepItem.cbSize = sizeof( MENUITEMINFO );
88 sepItem.fMask = MIIM_FTYPE;
89 sepItem.fType = MFT_SEPARATOR;
91 InsertMenuItem( m_hMenu, findInsertionPoint( pos ), TRUE, &sepItem );
95 unsigned int Win32Popup::findInsertionPoint( unsigned int pos ) const
97 // For this simple algorithm, we rely on the fact that in the final state
98 // of the menu, the ID of each item is equal to its position in the menu
100 while( i < GetMenuItemCount( m_hMenu ) &&
101 GetMenuItemID( m_hMenu, i ) < pos )