]> git.sesse.net Git - vlc/blob - modules/gui/skins2/win32/win32_popup.cpp
Translate french comment
[vlc] / modules / gui / skins2 / win32 / win32_popup.cpp
1 /*****************************************************************************
2  * win32_popup.cpp
3  *****************************************************************************
4  * Copyright (C) 2003 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 #ifdef WIN32_SKINS
25
26 #include "win32_popup.hpp"
27 #include "win32_factory.hpp"
28
29 #ifndef TPM_NOANIMATION
30 const UINT TPM_NOANIMATION = 0x4000L;
31 #endif
32
33
34 Win32Popup::Win32Popup( intf_thread_t *pIntf, HWND hAssociatedWindow )
35     : OSPopup( pIntf ), m_hWnd( hAssociatedWindow )
36 {
37     // Create the popup menu
38     m_hMenu = CreatePopupMenu();
39
40     if( !m_hMenu )
41     {
42         msg_Err( getIntf(), "CreatePopupMenu failed" );
43         return;
44     }
45 }
46
47
48 Win32Popup::~Win32Popup()
49 {
50     if( m_hMenu )
51         DestroyMenu( m_hMenu );
52 }
53
54
55 void Win32Popup::show( int xPos, int yPos )
56 {
57     TrackPopupMenuEx( m_hMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON
58                                | TPM_HORIZONTAL | TPM_NOANIMATION,
59                       xPos, yPos, m_hWnd, NULL );
60 }
61
62
63 void Win32Popup::hide()
64 {
65     SendMessage( m_hWnd, WM_CANCELMODE, 0, 0 );
66 }
67
68
69 void Win32Popup::addItem( const string &rLabel, int pos )
70 {
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;
76     menuItem.wID = pos;
77     menuItem.dwTypeData = (char*)rLabel.c_str();
78     menuItem.cch = rLabel.size();
79
80     InsertMenuItem( m_hMenu, findInsertionPoint( pos ), TRUE, &menuItem );
81 }
82
83
84 void Win32Popup::addSeparator( int pos )
85 {
86     MENUITEMINFO sepItem;
87     sepItem.cbSize = sizeof( MENUITEMINFO );
88     sepItem.fMask = MIIM_FTYPE;
89     sepItem.fType = MFT_SEPARATOR;
90
91     InsertMenuItem( m_hMenu, findInsertionPoint( pos ), TRUE, &sepItem );
92 }
93
94
95 unsigned int Win32Popup::findInsertionPoint( unsigned int pos ) const
96 {
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
99     int i = 0;
100     while( i < GetMenuItemCount( m_hMenu ) &&
101            GetMenuItemID( m_hMenu, i ) < pos )
102     {
103         i++;
104     }
105     return i;
106 }
107
108
109 #endif
110