1 /***************************************************************************** 2 * generic_layout.hpp 3 ***************************************************************************** 4 * Copyright (C) 2003 the VideoLAN team 5 * $Id: 8c4d4652de85a674d4b86346d796765c8a677842 $ 6 * 7 * Authors: Cyril Deguet <asmax@via.ecp.fr> 8 * Olivier Teulière <ipkiss@via.ecp.fr> 9 * 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. 14 * 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. 19 * 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 *****************************************************************************/ 24 25 #ifndef GENERIC_LAYOUT_HPP 26 #define GENERIC_LAYOUT_HPP 27 28 #include "skin_common.hpp" 29 #include "top_window.hpp" 30 #include "../utils/pointer.hpp" 31 #include "../utils/position.hpp" 32 33 #include <list> 34 35 class Anchor; 36 class OSGraphics; 37 class CtrlGeneric; 38 class CtrlVideo; 39 class VarBoolImpl; 40 41 42 /// Control and its associated layer 43 struct LayeredControl 44 { LayeredControlLayeredControl45 LayeredControl( CtrlGeneric *pControl, int layer ): 46 m_pControl( pControl ), m_layer( layer ) { } 47 48 /// Pointer on the control 49 CtrlGeneric *m_pControl; 50 /// Layer number 51 int m_layer; 52 }; 53 54 55 /// Base class for layouts 56 class GenericLayout: public SkinObject 57 { 58 public: 59 GenericLayout( intf_thread_t *pIntf, int width, int height, 60 int minWidth, int maxWidth, int minHeight, int maxHeight ); 61 62 virtual ~GenericLayout(); 63 64 /// Attach the layout to a window 65 virtual void setWindow( TopWindow *pWindow ); 66 67 /// Get the associated window, if any getWindow() const68 virtual TopWindow *getWindow() const { return m_pWindow; } 69 70 /// Called by a control which wants to capture the mouse 71 virtual void onControlCapture( const CtrlGeneric &rCtrl ); 72 73 /// Called by a control which wants to release the mouse 74 virtual void onControlRelease( const CtrlGeneric &rCtrl ); 75 76 /// Refresh the window 77 virtual void refreshAll(); 78 79 /// Refresh a rectangular portion of the window 80 virtual void refreshRect( int x, int y, int width, int height ); 81 82 /// Get the image of the layout getImage() const83 virtual OSGraphics *getImage() const { return m_pImage; } 84 85 /// Get the position of the layout (relative to the screen) 86 /** 87 * Note: These values are different from the m_rect.getLeft() and 88 * m_rect.getTop(), which always return 0. 89 * The latter methods are there as a "root rect" for the panels and 90 * controls, since each control knows its parent rect, but returns 91 * coordinates relative to the root rect. 92 */ getLeft() const93 virtual int getLeft() const { return m_pWindow->getLeft(); } getTop() const94 virtual int getTop() const { return m_pWindow->getTop(); } 95 96 /// Get the size of the layout getWidth() const97 virtual int getWidth() const { return m_rect.getWidth(); } getHeight() const98 virtual int getHeight() const { return m_rect.getHeight(); } getRect() const99 virtual const GenericRect &getRect() const { return m_rect; } 100 101 /// Get the minimum and maximum size of the layout getMinWidth() const102 virtual int getMinWidth() const { return m_minWidth; } getMaxWidth() const103 virtual int getMaxWidth() const { return m_maxWidth; } getMinHeight() const104 virtual int getMinHeight() const { return m_minHeight; } getMaxHeight() const105 virtual int getMaxHeight() const { return m_maxHeight; } 106 107 /// Resize the layout 108 virtual void resize( int width, int height ); 109 110 /// determine whether layouts should be kept the same size 111 virtual bool isTightlyCoupledWith( const GenericLayout& otherLayout ) const; 112 113 // getter for layout visibility isVisible() const114 virtual bool isVisible( ) const { return m_visible; } 115 116 /** 117 * Add a control in the layout at the given position, and 118 * the optional given layer 119 */ 120 virtual void addControl( CtrlGeneric *pControl, 121 const Position &rPosition, 122 int layer ); 123 124 /// Get the list of the controls in this layout, by layer order 125 virtual const std::list<LayeredControl> &getControlList() const; 126 127 /// Called by a control when its image has changed 128 /** 129 * The arguments indicate the size of the rectangle to refresh, 130 * and the offset (from the control position) of this rectangle. 131 * Use a negative width or height to refresh the layout completely 132 */ 133 virtual void onControlUpdate( const CtrlGeneric &rCtrl, 134 int width, int height, 135 int xOffSet, int yOffSet ); 136 137 /// Get the list of the anchors of this layout 138 virtual const std::list<Anchor*>& getAnchorList() const; 139 140 /// Add an anchor to this layout 141 virtual void addAnchor( Anchor *pAnchor ); 142 143 /// Called when the layout is shown 144 virtual void onShow(); 145 146 /// Called when the layout is hidden 147 virtual void onHide(); 148 149 /// Give access to the "active layout" variable 150 // FIXME: we give read/write access getActiveVar()151 VarBoolImpl &getActiveVar() { return *m_pVarActive; } 152 153 private: 154 /// Parent window of the layout 155 TopWindow *m_pWindow; 156 /// Layout original size 157 const int m_original_width; 158 const int m_original_height; 159 /// Layout size 160 SkinsRect m_rect; 161 const int m_minWidth, m_maxWidth; 162 const int m_minHeight, m_maxHeight; 163 /// Image of the layout 164 OSGraphics *m_pImage; 165 /// List of the controls in the layout 166 std::list<LayeredControl> m_controlList; 167 /// Video control(s) 168 std::set<CtrlVideo *> m_pVideoCtrlSet; 169 /// List of the anchors in the layout 170 std::list<Anchor*> m_anchorList; 171 /// Flag to know if the layout is visible 172 bool m_visible; 173 /// Variable for the "active state" of the layout 174 /** 175 * Note: the layout is not an observer on this variable, because it 176 * cannot be changed externally (i.e. without an explicit change of 177 * layout). This way, we avoid using a setActiveLayoutInner method. 178 */ 179 mutable VarBoolImpl *m_pVarActive; 180 }; 181 182 183 typedef CountedPtr<GenericLayout> GenericLayoutPtr; 184 185 186 #endif 187