1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
8 * Olivier Teulière <ipkiss@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #include "ctrl_resize.hpp"
26 #include "../events/evt_generic.hpp"
27 #include "../events/evt_mouse.hpp"
28 #include "../events/evt_motion.hpp"
29 #include "../src/generic_layout.hpp"
30 #include "../src/os_factory.hpp"
31 #include "../utils/position.hpp"
32 #include "../commands/async_queue.hpp"
33 #include "../commands/cmd_resize.hpp"
36 CtrlResize::CtrlResize( intf_thread_t
*pIntf
, WindowManager
&rWindowManager
,
37 CtrlFlat
&rCtrl
, GenericLayout
&rLayout
,
38 const UString
&rHelp
, VarBool
*pVisible
,
39 WindowManager::Direction_t direction
):
40 CtrlFlat( pIntf
, rHelp
, pVisible
), m_fsm( pIntf
),
41 m_rWindowManager( rWindowManager
), m_rCtrl( rCtrl
),
42 m_rLayout( rLayout
), m_direction( direction
), m_cmdOutStill( this ),
43 m_cmdStillOut( this ),
44 m_cmdStillStill( this ),
45 m_cmdStillResize( this ),
46 m_cmdResizeStill( this ),
47 m_cmdResizeResize( this )
54 m_fsm
.addState( "out" );
55 m_fsm
.addState( "still" );
56 m_fsm
.addState( "resize" );
59 m_fsm
.addTransition( "out", "enter", "still", &m_cmdOutStill
);
60 m_fsm
.addTransition( "still", "leave", "out", &m_cmdStillOut
);
61 m_fsm
.addTransition( "still", "motion", "still", &m_cmdStillStill
);
62 m_fsm
.addTransition( "resize", "mouse:left:up:none", "still",
64 m_fsm
.addTransition( "still", "mouse:left:down:none", "resize",
66 m_fsm
.addTransition( "resize", "motion", "resize", &m_cmdResizeResize
);
68 m_fsm
.setState( "still" );
72 bool CtrlResize::mouseOver( int x
, int y
) const
74 return m_rCtrl
.mouseOver( x
, y
);
78 void CtrlResize::draw( OSGraphics
&rImage
, int xDest
, int yDest
, int w
, int h
)
80 m_rCtrl
.draw( rImage
, xDest
, yDest
, w
, h
);
84 void CtrlResize::setLayout( GenericLayout
*pLayout
, const Position
&rPosition
)
86 CtrlGeneric::setLayout( pLayout
, rPosition
);
87 // Set the layout of the decorated control as well
88 m_rCtrl
.setLayout( pLayout
, rPosition
);
92 void CtrlResize::unsetLayout()
94 m_rCtrl
.unsetLayout();
95 CtrlGeneric::unsetLayout();
99 const Position
*CtrlResize::getPosition() const
101 return m_rCtrl
.getPosition();
105 void CtrlResize::onResize()
111 void CtrlResize::handleEvent( EvtGeneric
&rEvent
)
114 m_fsm
.handleTransition( rEvent
.getAsString() );
115 // Transmit the event to the decorated control
116 // XXX: Is it really a good idea?
117 m_rCtrl
.handleEvent( rEvent
);
121 void CtrlResize::changeCursor( WindowManager::Direction_t direction
) const
123 OSFactory::CursorType_t cursor
;
127 case WindowManager::kNone
: cursor
= OSFactory::kDefaultArrow
; break;
128 case WindowManager::kResizeSE
: cursor
= OSFactory::kResizeNWSE
; break;
129 case WindowManager::kResizeS
: cursor
= OSFactory::kResizeNS
; break;
130 case WindowManager::kResizeE
: cursor
= OSFactory::kResizeWE
; break;
132 OSFactory::instance( getIntf() )->changeCursor( cursor
);
136 void CtrlResize::CmdOutStill::execute()
138 m_pParent
->changeCursor( m_pParent
->m_direction
);
142 void CtrlResize::CmdStillOut::execute()
144 m_pParent
->changeCursor( WindowManager::kNone
);
148 void CtrlResize::CmdStillStill::execute()
150 m_pParent
->changeCursor( m_pParent
->m_direction
);
154 void CtrlResize::CmdStillResize::execute()
156 EvtMouse
*pEvtMouse
= static_cast<EvtMouse
*>(m_pParent
->m_pEvt
);
159 m_pParent
->changeCursor( m_pParent
->m_direction
);
161 m_pParent
->m_xPos
= pEvtMouse
->getXPos();
162 m_pParent
->m_yPos
= pEvtMouse
->getYPos();
164 m_pParent
->captureMouse();
166 m_pParent
->m_width
= m_pParent
->m_rLayout
.getWidth();
167 m_pParent
->m_height
= m_pParent
->m_rLayout
.getHeight();
169 m_pParent
->m_rWindowManager
.startResize( m_pParent
->m_rLayout
,
170 m_pParent
->m_direction
);
174 void CtrlResize::CmdResizeStill::execute()
177 m_pParent
->changeCursor( m_pParent
->m_direction
);
179 m_pParent
->releaseMouse();
181 m_pParent
->m_rWindowManager
.stopResize();
185 void CtrlResize::CmdResizeResize::execute()
187 EvtMotion
*pEvtMotion
= static_cast<EvtMotion
*>(m_pParent
->m_pEvt
);
189 m_pParent
->changeCursor( m_pParent
->m_direction
);
191 int newWidth
= m_pParent
->m_width
;
192 newWidth
+= pEvtMotion
->getXPos() - m_pParent
->m_xPos
;
193 int newHeight
= m_pParent
->m_height
;
194 newHeight
+= pEvtMotion
->getYPos() - m_pParent
->m_yPos
;
196 // Create a resize command, instead of calling the window manager directly.
197 // Thanks to this trick, the duplicate resizing commands will be trashed
198 // in the asynchronous queue, thus making resizing faster
199 CmdGeneric
*pCmd
= new CmdResize( m_pParent
->getIntf(),
200 m_pParent
->m_rWindowManager
,
201 m_pParent
->m_rLayout
,
202 newWidth
, newHeight
);
203 // Push the command in the asynchronous command queue
204 AsyncQueue::instance( getIntf() )->push( CmdGenericPtr( pCmd
) );