1*3334a7e6SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*3334a7e6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*3334a7e6SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*3334a7e6SAndrew Rist * distributed with this work for additional information 6*3334a7e6SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*3334a7e6SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*3334a7e6SAndrew Rist * "License"); you may not use this file except in compliance 9*3334a7e6SAndrew Rist * with the License. You may obtain a copy of the License at 10*3334a7e6SAndrew Rist * 11*3334a7e6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*3334a7e6SAndrew Rist * 13*3334a7e6SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*3334a7e6SAndrew Rist * software distributed under the License is distributed on an 15*3334a7e6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*3334a7e6SAndrew Rist * KIND, either express or implied. See the License for the 17*3334a7e6SAndrew Rist * specific language governing permissions and limitations 18*3334a7e6SAndrew Rist * under the License. 19*3334a7e6SAndrew Rist * 20*3334a7e6SAndrew Rist *************************************************************/ 21*3334a7e6SAndrew Rist 22*3334a7e6SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef SVX_FRMSELIMPL_HXX 25cdf0e10cSrcweir #define SVX_FRMSELIMPL_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <vcl/virdev.hxx> 28cdf0e10cSrcweir #include <vcl/image.hxx> 29cdf0e10cSrcweir #include <svx/frmsel.hxx> 30cdf0e10cSrcweir #include <svx/framelinkarray.hxx> 31cdf0e10cSrcweir #include <editeng/borderline.hxx> 32cdf0e10cSrcweir 33cdf0e10cSrcweir namespace svx { 34cdf0e10cSrcweir 35cdf0e10cSrcweir namespace a11y { class AccFrameSelector; } 36cdf0e10cSrcweir 37cdf0e10cSrcweir // ============================================================================ 38cdf0e10cSrcweir 39cdf0e10cSrcweir class FrameBorder 40cdf0e10cSrcweir { 41cdf0e10cSrcweir public: 42cdf0e10cSrcweir explicit FrameBorder( FrameBorderType eType ); 43cdf0e10cSrcweir GetType() const44cdf0e10cSrcweir inline FrameBorderType GetType() const { return meType; } 45cdf0e10cSrcweir IsEnabled() const46cdf0e10cSrcweir inline bool IsEnabled() const { return mbEnabled; } 47cdf0e10cSrcweir void Enable( FrameSelFlags nFlags ); 48cdf0e10cSrcweir GetState() const49cdf0e10cSrcweir inline FrameBorderState GetState() const { return meState; } 50cdf0e10cSrcweir void SetState( FrameBorderState eState ); 51cdf0e10cSrcweir IsSelected() const52cdf0e10cSrcweir inline bool IsSelected() const { return mbSelected; } Select(bool bSelect)53cdf0e10cSrcweir inline void Select( bool bSelect ) { mbSelected = bSelect; } 54cdf0e10cSrcweir GetCoreStyle() const55cdf0e10cSrcweir const SvxBorderLine& GetCoreStyle() const { return maCoreStyle; } 56cdf0e10cSrcweir void SetCoreStyle( const SvxBorderLine* pStyle ); 57cdf0e10cSrcweir SetUIColor(const Color & rColor)58cdf0e10cSrcweir inline void SetUIColor( const Color& rColor ) {maUIStyle.SetColor( rColor ); } GetUIStyle() const59cdf0e10cSrcweir inline const frame::Style& GetUIStyle() const { return maUIStyle; } 60cdf0e10cSrcweir ClearFocusArea()61cdf0e10cSrcweir inline void ClearFocusArea() { maFocusArea.Clear(); } 62cdf0e10cSrcweir void AddFocusPolygon( const Polygon& rFocus ); 63cdf0e10cSrcweir void MergeFocusToPolyPolygon( PolyPolygon& rPPoly ) const; 64cdf0e10cSrcweir ClearClickArea()65cdf0e10cSrcweir inline void ClearClickArea() { maClickArea.Clear(); } 66cdf0e10cSrcweir void AddClickRect( const Rectangle& rRect ); 67cdf0e10cSrcweir bool ContainsClickPoint( const Point& rPos ) const; 68cdf0e10cSrcweir void MergeClickAreaToPolyPolygon( PolyPolygon& rPPoly ) const; 69cdf0e10cSrcweir Rectangle GetClickBoundRect() const; 70cdf0e10cSrcweir 71cdf0e10cSrcweir void SetKeyboardNeighbors( 72cdf0e10cSrcweir FrameBorderType eLeft, FrameBorderType eRight, 73cdf0e10cSrcweir FrameBorderType eTop, FrameBorderType eBottom ); 74cdf0e10cSrcweir FrameBorderType GetKeyboardNeighbor( sal_uInt16 nKeyCode ) const; 75cdf0e10cSrcweir 76cdf0e10cSrcweir private: 77cdf0e10cSrcweir const FrameBorderType meType; /// Frame border type (position in control). 78cdf0e10cSrcweir FrameBorderState meState; /// Frame border state (on/off/don't care). 79cdf0e10cSrcweir SvxBorderLine maCoreStyle; /// Core style from application. 80cdf0e10cSrcweir frame::Style maUIStyle; /// Internal style to draw lines. 81cdf0e10cSrcweir FrameBorderType meKeyLeft; /// Left neighbor for keyboard control. 82cdf0e10cSrcweir FrameBorderType meKeyRight; /// Right neighbor for keyboard control. 83cdf0e10cSrcweir FrameBorderType meKeyTop; /// Upper neighbor for keyboard control. 84cdf0e10cSrcweir FrameBorderType meKeyBottom; /// Lower neighbor for keyboard control. 85cdf0e10cSrcweir PolyPolygon maFocusArea; /// Focus drawing areas. 86cdf0e10cSrcweir PolyPolygon maClickArea; /// Mouse click areas. 87cdf0e10cSrcweir bool mbEnabled; /// true = Border enabled in control. 88cdf0e10cSrcweir bool mbSelected; /// true = Border selected in control. 89cdf0e10cSrcweir }; 90cdf0e10cSrcweir 91cdf0e10cSrcweir // ============================================================================ 92cdf0e10cSrcweir 93cdf0e10cSrcweir typedef std::vector< FrameBorder* > FrameBorderPtrVec; 94cdf0e10cSrcweir 95cdf0e10cSrcweir struct FrameSelectorImpl : public Resource 96cdf0e10cSrcweir { 97cdf0e10cSrcweir typedef ::com::sun::star::uno::Reference< 98cdf0e10cSrcweir ::com::sun::star::accessibility::XAccessible > XAccessibleRef; 99cdf0e10cSrcweir typedef std::vector< a11y::AccFrameSelector* > AccessibleImplVec; 100cdf0e10cSrcweir typedef std::vector< XAccessibleRef > XAccessibleRefVec; 101cdf0e10cSrcweir 102cdf0e10cSrcweir FrameSelector& mrFrameSel; /// The control itself. 103cdf0e10cSrcweir VirtualDevice maVirDev; /// For all buffered drawing operations. 104cdf0e10cSrcweir ImageList maILArrows; /// Arrows in current system colors. 105cdf0e10cSrcweir Color maBackCol; /// Background color. 106cdf0e10cSrcweir Color maArrowCol; /// Selection arrow color. 107cdf0e10cSrcweir Color maMarkCol; /// Selection marker color. 108cdf0e10cSrcweir Color maHCLineCol; /// High contrast line color. 109cdf0e10cSrcweir Point maVirDevPos; /// Position of virtual device in the control. 110cdf0e10cSrcweir Point maMousePos; /// Last mouse pointer position. 111cdf0e10cSrcweir 112cdf0e10cSrcweir FrameBorder maLeft; /// All data of left frame border. 113cdf0e10cSrcweir FrameBorder maRight; /// All data of right frame border. 114cdf0e10cSrcweir FrameBorder maTop; /// All data of top frame border. 115cdf0e10cSrcweir FrameBorder maBottom; /// All data of bottom frame border. 116cdf0e10cSrcweir FrameBorder maHor; /// All data of inner horizontal frame border. 117cdf0e10cSrcweir FrameBorder maVer; /// All data of inner vertical frame border. 118cdf0e10cSrcweir FrameBorder maTLBR; /// All data of top-left to bottom-right frame border. 119cdf0e10cSrcweir FrameBorder maBLTR; /// All data of bottom-left to top-right frame border. 120cdf0e10cSrcweir SvxBorderLine maCurrStyle; /// Current style and color for new borders. 121cdf0e10cSrcweir frame::Array maArray; /// Frame link array to draw an array of frame borders. 122cdf0e10cSrcweir 123cdf0e10cSrcweir FrameSelFlags mnFlags; /// Flags for enabled frame borders. 124cdf0e10cSrcweir FrameBorderPtrVec maAllBorders; /// Pointers to all frame borders. 125cdf0e10cSrcweir FrameBorderPtrVec maEnabBorders; /// Pointers to enables frame borders. 126cdf0e10cSrcweir Link maSelectHdl; /// Selection handler. 127cdf0e10cSrcweir 128cdf0e10cSrcweir long mnCtrlSize; /// Size of the control (always square). 129cdf0e10cSrcweir long mnArrowSize; /// Size of an arrow image. 130cdf0e10cSrcweir long mnLine1; /// Middle of left/top frame borders. 131cdf0e10cSrcweir long mnLine2; /// Middle of inner frame borders. 132cdf0e10cSrcweir long mnLine3; /// Middle of right/bottom frame borders. 133cdf0e10cSrcweir long mnFocusOffs; /// Offset from frame border middle to draw focus. 134cdf0e10cSrcweir 135cdf0e10cSrcweir bool mbHor; /// true = Inner horizontal frame border enabled. 136cdf0e10cSrcweir bool mbVer; /// true = Inner vertical frame border enabled. 137cdf0e10cSrcweir bool mbTLBR; /// true = Top-left to bottom-right frame border enabled. 138cdf0e10cSrcweir bool mbBLTR; /// true = Bottom-left to top-right frame border enabled. 139cdf0e10cSrcweir bool mbFullRepaint; /// Used for repainting (false = only copy virtual device). 140cdf0e10cSrcweir bool mbAutoSelect; /// true = Auto select a frame border, if focus reaches control. 141cdf0e10cSrcweir bool mbClicked; /// true = The control has been clicked at least one time. 142cdf0e10cSrcweir bool mbHCMode; /// true = High contrast mode. 143cdf0e10cSrcweir 144cdf0e10cSrcweir a11y::AccFrameSelector* mpAccess; /// Pointer to accessibility object of the control. 145cdf0e10cSrcweir XAccessibleRef mxAccess; /// Reference to accessibility object of the control. 146cdf0e10cSrcweir AccessibleImplVec maChildVec; /// Pointers to accessibility objects for frame borders. 147cdf0e10cSrcweir XAccessibleRefVec mxChildVec; /// References to accessibility objects for frame borders. 148cdf0e10cSrcweir 149cdf0e10cSrcweir explicit FrameSelectorImpl( FrameSelector& rFrameSel ); 150cdf0e10cSrcweir ~FrameSelectorImpl(); 151cdf0e10cSrcweir 152cdf0e10cSrcweir // initialization --------------------------------------------------------- 153cdf0e10cSrcweir 154cdf0e10cSrcweir /** Initializes the control, enables/disables frame borders according to flags. */ 155cdf0e10cSrcweir void Initialize( FrameSelFlags nFlags ); 156cdf0e10cSrcweir 157cdf0e10cSrcweir /** Fills all color members from current style settings. */ 158cdf0e10cSrcweir void InitColors(); 159cdf0e10cSrcweir /** Creates the image list with selection arrows regarding current style settings. */ 160cdf0e10cSrcweir void InitArrowImageList(); 161cdf0e10cSrcweir /** Initializes global coordinates. */ 162cdf0e10cSrcweir void InitGlobalGeometry(); 163cdf0e10cSrcweir /** Initializes coordinates of all frame borders. */ 164cdf0e10cSrcweir void InitBorderGeometry(); 165cdf0e10cSrcweir /** Initializes click areas of all enabled frame borders. */ 166cdf0e10cSrcweir void InitClickAreas(); 167cdf0e10cSrcweir /** Draws the entire control into the internal virtual device. */ 168cdf0e10cSrcweir void InitVirtualDevice(); 169cdf0e10cSrcweir 170cdf0e10cSrcweir // frame border access ---------------------------------------------------- 171cdf0e10cSrcweir 172cdf0e10cSrcweir /** Returns the object representing the specified frame border. */ 173cdf0e10cSrcweir const FrameBorder& GetBorder( FrameBorderType eBorder ) const; 174cdf0e10cSrcweir /** Returns the object representing the specified frame border (write access). */ 175cdf0e10cSrcweir FrameBorder& GetBorderAccess( FrameBorderType eBorder ); 176cdf0e10cSrcweir 177cdf0e10cSrcweir // drawing ---------------------------------------------------------------- 178cdf0e10cSrcweir 179cdf0e10cSrcweir /** Draws the background of the entire control (the gray areas between borders). */ 180cdf0e10cSrcweir void DrawBackground(); 181cdf0e10cSrcweir 182cdf0e10cSrcweir /** Draws selection arrows for the specified frame border. */ 183cdf0e10cSrcweir void DrawArrows( const FrameBorder& rBorder ); 184cdf0e10cSrcweir /** Draws arrows in current selection state for all enabled frame borders. */ 185cdf0e10cSrcweir void DrawAllArrows(); 186cdf0e10cSrcweir 187cdf0e10cSrcweir /** Returns the color that has to be used to draw a frame border. */ 188cdf0e10cSrcweir Color GetDrawLineColor( const Color& rColor ) const; 189cdf0e10cSrcweir /** Draws all frame borders. */ 190cdf0e10cSrcweir void DrawAllFrameBorders(); 191cdf0e10cSrcweir 192cdf0e10cSrcweir /** Draws all contents of the control. */ 193cdf0e10cSrcweir void DrawVirtualDevice(); 194cdf0e10cSrcweir /** Copies contents of the virtual device to the control. */ 195cdf0e10cSrcweir void CopyVirDevToControl(); 196cdf0e10cSrcweir 197cdf0e10cSrcweir /** Draws tracking rectangles for all selected frame borders. */ 198cdf0e10cSrcweir void DrawAllTrackingRects(); 199cdf0e10cSrcweir 200cdf0e10cSrcweir /** Converts a mouse position to the virtual device position. */ 201cdf0e10cSrcweir Point GetDevPosFromMousePos( const Point& rMousePos ) const; 202cdf0e10cSrcweir 203cdf0e10cSrcweir /** Invalidates the control. 204cdf0e10cSrcweir @param bFullRepaint true = Full repaint; false = update selection only. */ 205cdf0e10cSrcweir void DoInvalidate( bool bFullRepaint ); 206cdf0e10cSrcweir 207cdf0e10cSrcweir // frame border state and style ------------------------------------------- 208cdf0e10cSrcweir 209cdf0e10cSrcweir /** Sets the state of the specified frame border. */ 210cdf0e10cSrcweir void SetBorderState( FrameBorder& rBorder, FrameBorderState eState ); 211cdf0e10cSrcweir /** Sets the core style of the specified frame border, or hides the frame border, if pStyle is 0. */ 212cdf0e10cSrcweir void SetBorderCoreStyle( FrameBorder& rBorder, const SvxBorderLine* pStyle ); 213cdf0e10cSrcweir /** Sets the color of the specified frame border. */ 214cdf0e10cSrcweir void SetBorderColor( FrameBorder& rBorder, const Color& rColor ); 215cdf0e10cSrcweir 216cdf0e10cSrcweir /** Changes the state of a frame border after a control event (mouse/keyboard). */ 217cdf0e10cSrcweir void ToggleBorderState( FrameBorder& rBorder ); 218cdf0e10cSrcweir 219cdf0e10cSrcweir // frame border selection ------------------------------------------------- 220cdf0e10cSrcweir 221cdf0e10cSrcweir /** Selects a frame border and schedules redraw. */ 222cdf0e10cSrcweir void SelectBorder( FrameBorder& rBorder, bool bSelect ); 223cdf0e10cSrcweir /** Grabs focus without auto-selection of a frame border, if no border selected. */ 224cdf0e10cSrcweir void SilentGrabFocus(); 225cdf0e10cSrcweir 226cdf0e10cSrcweir /** Returns true, if all selected frame borders are equal (or if nothing is selected). */ 227cdf0e10cSrcweir bool SelectedBordersEqual() const; 228cdf0e10cSrcweir }; 229cdf0e10cSrcweir 230cdf0e10cSrcweir // ============================================================================ 231cdf0e10cSrcweir 232cdf0e10cSrcweir /** Dummy predicate for frame border iterators to use all borders in a container. */ 233cdf0e10cSrcweir struct FrameBorderDummy_Pred 234cdf0e10cSrcweir { operator ()svx::FrameBorderDummy_Pred235cdf0e10cSrcweir inline bool operator()( const FrameBorder* ) const { return true; } 236cdf0e10cSrcweir }; 237cdf0e10cSrcweir 238cdf0e10cSrcweir /** Predicate for frame border iterators to use only visible borders in a container. */ 239cdf0e10cSrcweir struct FrameBorderVisible_Pred 240cdf0e10cSrcweir { operator ()svx::FrameBorderVisible_Pred241cdf0e10cSrcweir inline bool operator()( const FrameBorder* pBorder ) const { return pBorder->GetState() == FRAMESTATE_SHOW; } 242cdf0e10cSrcweir }; 243cdf0e10cSrcweir 244cdf0e10cSrcweir /** Predicate for frame border iterators to use only selected borders in a container. */ 245cdf0e10cSrcweir struct FrameBorderSelected_Pred 246cdf0e10cSrcweir { operator ()svx::FrameBorderSelected_Pred247cdf0e10cSrcweir inline bool operator()( const FrameBorder* pBorder ) const { return pBorder->IsSelected(); } 248cdf0e10cSrcweir }; 249cdf0e10cSrcweir 250cdf0e10cSrcweir /** Template class for all types of frame border iterators. */ 251cdf0e10cSrcweir template< typename Cont, typename Iter, typename Pred > 252cdf0e10cSrcweir class FrameBorderIterBase 253cdf0e10cSrcweir { 254cdf0e10cSrcweir public: 255cdf0e10cSrcweir typedef Cont container_type; 256cdf0e10cSrcweir typedef Iter iterator_type; 257cdf0e10cSrcweir typedef Pred predicate_type; 258cdf0e10cSrcweir typedef typename Cont::value_type value_type; 259cdf0e10cSrcweir typedef FrameBorderIterBase< Cont, Iter, Pred > this_type; 260cdf0e10cSrcweir 261cdf0e10cSrcweir explicit FrameBorderIterBase( container_type& rCont ); Is() const262cdf0e10cSrcweir inline bool Is() const { return maIt != maEnd; } 263cdf0e10cSrcweir this_type& operator++(); operator *() const264cdf0e10cSrcweir inline value_type operator*() const { return *maIt; } 265cdf0e10cSrcweir 266cdf0e10cSrcweir private: 267cdf0e10cSrcweir iterator_type maIt; 268cdf0e10cSrcweir iterator_type maEnd; 269cdf0e10cSrcweir predicate_type maPred; 270cdf0e10cSrcweir }; 271cdf0e10cSrcweir 272cdf0e10cSrcweir /** Iterator for constant svx::FrameBorder containers, iterates over all borders. */ 273cdf0e10cSrcweir typedef FrameBorderIterBase< const FrameBorderPtrVec, FrameBorderPtrVec::const_iterator, FrameBorderDummy_Pred > 274cdf0e10cSrcweir FrameBorderCIter; 275cdf0e10cSrcweir 276cdf0e10cSrcweir /** Iterator for mutable svx::FrameBorder containers, iterates over all borders. */ 277cdf0e10cSrcweir typedef FrameBorderIterBase< FrameBorderPtrVec, FrameBorderPtrVec::iterator, FrameBorderDummy_Pred > 278cdf0e10cSrcweir FrameBorderIter; 279cdf0e10cSrcweir 280cdf0e10cSrcweir /** Iterator for constant svx::FrameBorder containers, iterates over visible borders. */ 281cdf0e10cSrcweir typedef FrameBorderIterBase< const FrameBorderPtrVec, FrameBorderPtrVec::const_iterator, FrameBorderVisible_Pred > 282cdf0e10cSrcweir VisFrameBorderCIter; 283cdf0e10cSrcweir 284cdf0e10cSrcweir /** Iterator for mutable svx::FrameBorder containers, iterates over visible borders. */ 285cdf0e10cSrcweir typedef FrameBorderIterBase< FrameBorderPtrVec, FrameBorderPtrVec::iterator, FrameBorderVisible_Pred > 286cdf0e10cSrcweir VisFrameBorderIter; 287cdf0e10cSrcweir 288cdf0e10cSrcweir /** Iterator for constant svx::FrameBorder containers, iterates over selected borders. */ 289cdf0e10cSrcweir typedef FrameBorderIterBase< const FrameBorderPtrVec, FrameBorderPtrVec::const_iterator, FrameBorderSelected_Pred > 290cdf0e10cSrcweir SelFrameBorderCIter; 291cdf0e10cSrcweir 292cdf0e10cSrcweir /** Iterator for mutable svx::FrameBorder containers, iterates over selected borders. */ 293cdf0e10cSrcweir typedef FrameBorderIterBase< FrameBorderPtrVec, FrameBorderPtrVec::iterator, FrameBorderSelected_Pred > 294cdf0e10cSrcweir SelFrameBorderIter; 295cdf0e10cSrcweir 296cdf0e10cSrcweir // ============================================================================ 297cdf0e10cSrcweir 298cdf0e10cSrcweir } // namespace svx 299cdf0e10cSrcweir 300cdf0e10cSrcweir #endif 301cdf0e10cSrcweir 302