1 /*****************************************************************************
2 * popup.cpp
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
5 * $Id: 1001f3f36b489edaaba340168705311ff46d8b39 $
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 #include "popup.hpp"
25 #include "os_factory.hpp"
26 #include "os_popup.hpp"
27 #include "window_manager.hpp"
28 #include "../commands/cmd_generic.hpp"
29 #include "../events/evt_menu.hpp"
30
31
Popup(intf_thread_t * pIntf,WindowManager & rWindowManager)32 Popup::Popup( intf_thread_t *pIntf, WindowManager &rWindowManager )
33 : SkinObject( pIntf ), m_rWindowManager( rWindowManager )
34 {
35 // Get the OSFactory
36 OSFactory *pOsFactory = OSFactory::instance( getIntf() );
37
38 // Create an OSPopup to handle OS specific processing
39 m_pOsPopup = pOsFactory->createOSPopup();
40 }
41
42
show(int xPos,int yPos)43 void Popup::show( int xPos, int yPos )
44 {
45 // Notify that we are the active popup menu, so that the window which
46 // receives our menu events knows whom to forward them
47 m_rWindowManager.setActivePopup( *this );
48
49 m_pOsPopup->show( xPos, yPos );
50 }
51
52
hide()53 void Popup::hide()
54 {
55 m_pOsPopup->hide();
56 }
57
58
addItem(const std::string & rLabel,CmdGeneric & rCmd,int pos)59 void Popup::addItem( const std::string &rLabel, CmdGeneric &rCmd, int pos )
60 {
61 m_pOsPopup->addItem( rLabel, pos );
62 m_actions[pos] = &rCmd;
63 }
64
65
addSeparator(int pos)66 void Popup::addSeparator( int pos )
67 {
68 m_pOsPopup->addSeparator( pos );
69 m_actions[pos] = NULL;
70 }
71
72
handleEvent(const EvtMenu & rEvent)73 void Popup::handleEvent( const EvtMenu &rEvent )
74 {
75 unsigned int n = m_pOsPopup->getPosFromId( rEvent.getItemId() );
76 if( (n < m_actions.size()) && m_actions[n] )
77 {
78 m_actions[n]->execute();
79 }
80 else
81 {
82 // Should never happen
83 msg_Warn( getIntf(), "problem in the popup implementation" );
84 }
85 }
86
87