Wnd.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /* GG is a GUI for SDL and OpenGL.
00003    Copyright (C) 2003-2008 T. Zachary Laine
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public License
00007    as published by the Free Software Foundation; either version 2.1
00008    of the License, or (at your option) any later version.
00009    
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014     
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with this library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA
00019 
00020    If you do not wish to comply with the terms of the LGPL please
00021    contact the author as other terms are available for a fee.
00022     
00023    Zach Laine
00024    whatwasthataddress@gmail.com */
00025 
00029 #ifndef _GG_Wnd_h_
00030 #define _GG_Wnd_h_
00031 
00032 #include <GG/Base.h>
00033 #include <GG/Exception.h>
00034 #include <GG/Flags.h>
00035 
00036 #include <list>
00037 #include <set>
00038 
00039 
00040 namespace GG {
00041 
00042 class BrowseInfoWnd;
00043 class Layout;
00044 class StyleFactory;
00045 class Timer;
00046 class WndEditor;
00047 class WndEvent;
00048 
00049 
00051 GG_FLAG_TYPE(WndFlag);
00052 
00055 extern GG_API const WndFlag INTERACTIVE;
00056 
00059 extern GG_API const WndFlag REPEAT_BUTTON_DOWN;
00060 
00062 extern GG_API const WndFlag DRAGABLE;
00063 
00065 extern GG_API const WndFlag RESIZABLE;
00066 
00070 extern GG_API const WndFlag ONTOP;
00071 
00076 extern GG_API const WndFlag MODAL;
00077 
00078 
00227 class GG_API Wnd : public boost::signals::trackable
00228 {
00229 public:
00235     struct GG_API BrowseInfoMode
00236     {
00239         unsigned int time;
00240 
00243         boost::shared_ptr<BrowseInfoWnd> wnd;
00244 
00246         std::string                      text;
00247 
00248         template <class Archive>
00249         void serialize(Archive& ar, const unsigned int version);
00250     };
00251 
00253     typedef std::map<const Wnd*, bool>::iterator DropsAcceptableIter;
00254 
00256     enum ChildClippingMode {
00258         DontClip,
00259 
00262         ClipToClient,
00263 
00266         ClipToWindow,
00267 
00274         ClipToClientAndWindowSeparately
00275     };
00276  
00278     virtual ~Wnd(); 
00279 
00280  
00282 
00285     bool Interactive() const;
00286 
00289     bool RepeatButtonDown() const;
00290 
00292     bool Dragable() const;
00293 
00295     bool Resizable() const;
00296 
00298     bool OnTop() const;
00299 
00301     bool Modal() const;
00302 
00304     ChildClippingMode GetChildClippingMode() const;
00305 
00308     bool NonClientChild() const;
00309 
00311     bool Visible() const;
00312 
00315      const std::string& Name() const;
00316 
00320     const std::string& DragDropDataType() const;
00321 
00325     virtual void DropsAcceptable(DropsAcceptableIter first,
00326                                  DropsAcceptableIter last,
00327                                  const Pt& pt) const;
00328 
00331     Pt UpperLeft() const;
00332 
00336     Pt LowerRight() const;
00337 
00340     Pt RelativeUpperLeft() const;
00341 
00345     Pt RelativeLowerRight() const;
00346 
00347     X Width() const;  
00348     Y Height() const; 
00349 
00352     int ZOrder() const;
00353 
00355     Pt Size() const;
00356 
00357     Pt MinSize() const; 
00358     Pt MaxSize() const; 
00359 
00366     virtual Pt MinUsableSize() const;
00367 
00372     virtual Pt ClientUpperLeft() const;
00373 
00378     virtual Pt ClientLowerRight() const;
00379 
00381     Pt ClientSize() const;
00382 
00383     X ClientWidth() const;  
00384     Y ClientHeight() const; 
00385 
00387     Pt ScreenToWindow(const Pt& pt) const;
00388 
00390     Pt ScreenToClient(const Pt& pt) const;
00391 
00394     virtual bool InWindow(const Pt& pt) const;
00395 
00398     virtual bool InClient(const Pt& pt) const;
00399 
00402     const std::list<Wnd*>& Children() const;
00403 
00405     Wnd* Parent() const;
00406 
00408     Wnd* RootParent() const;
00409 
00411     Layout* GetLayout() const;
00412 
00414     Layout* ContainingLayout() const;
00415 
00423     const std::vector<BrowseInfoMode>&  BrowseModes() const;
00424 
00428     const std::string& BrowseInfoText(std::size_t mode) const;
00429 
00432     const boost::shared_ptr<StyleFactory>& GetStyleFactory() const;
00433 
00435     virtual WndRegion WindowRegion(const Pt& pt) const;
00437  
00439 
00442     void SetDragDropDataType(const std::string& data_type);
00443 
00449     virtual void StartingChildDragDrop(const Wnd* wnd, const Pt& offset);
00450 
00455     virtual void AcceptDrops(const std::vector<Wnd*>& wnds, const Pt& pt);
00456 
00465     virtual void CancellingChildDragDrop(const std::vector<const Wnd*>& wnds);
00466 
00475     virtual void ChildrenDraggedAway(const std::vector<Wnd*>& wnds,
00476                                      const Wnd* destination);
00477 
00480     void SetName(const std::string& name);
00481 
00484     void Hide(bool children = true);
00485 
00488     void Show(bool children = true);
00489 
00493     virtual void ModalInit();
00494 
00496     void SetChildClippingMode(ChildClippingMode mode);
00497 
00500     void NonClientChild(bool b);
00501 
00502     void MoveTo(const Pt& pt);     
00503     void OffsetMove(const Pt& pt); 
00504 
00507     virtual void SizeMove(const Pt& ul, const Pt& lr);
00508 
00510     void Resize(const Pt& sz);
00511 
00513     void SetMinSize(const Pt& sz);
00514 
00516     void SetMaxSize(const Pt& sz);
00517 
00520     void AttachChild(Wnd* wnd);
00521 
00524     void MoveChildUp(Wnd* wnd);
00525 
00528     void MoveChildDown(Wnd* wnd);
00529 
00531     void DetachChild(Wnd* wnd);
00532 
00534     void DetachChildren();
00535 
00538     void DeleteChild(Wnd* wnd);
00539 
00541     void DeleteChildren();
00542 
00544     void InstallEventFilter(Wnd* wnd);
00545 
00547     void RemoveEventFilter(Wnd* wnd);
00548 
00552     void HorizontalLayout();
00553 
00557     void VerticalLayout();
00558 
00562     void GridLayout();
00563 
00566     void SetLayout(Layout* layout);
00567 
00572     void RemoveLayout();
00573 
00577     Layout* DetachLayout();
00578 
00582     void SetLayoutBorderMargin(unsigned int margin);
00583 
00586     void SetLayoutCellMargin(unsigned int margin);
00587 
00588 
00595     virtual void Render();
00596 
00600     virtual int Run();
00601 
00607     void SetBrowseModeTime(unsigned int time, std::size_t mode = 0);
00608 
00612     void SetBrowseInfoWnd(const boost::shared_ptr<BrowseInfoWnd>& wnd, std::size_t mode = 0);
00613 
00618     void ClearBrowseInfoWnd(std::size_t mode = 0);
00619 
00624     void SetBrowseText(const std::string& text, std::size_t mode = 0);
00625 
00633     void SetBrowseModes(const std::vector<BrowseInfoMode>& modes);
00634 
00636     void SetStyleFactory(const boost::shared_ptr<StyleFactory>& factory);
00637 
00640     virtual void DefineAttributes(WndEditor* editor);
00642 
00643 
00646     static unsigned int DefaultBrowseTime();
00647 
00650     static void SetDefaultBrowseTime(unsigned int time);
00651 
00655     static const boost::shared_ptr<BrowseInfoWnd>& DefaultBrowseInfoWnd();
00656 
00659     static void SetDefaultBrowseInfoWnd(const boost::shared_ptr<BrowseInfoWnd>& browse_info_wnd);
00660  
00662 
00663     GG_ABSTRACT_EXCEPTION(Exception);
00664 
00668     GG_CONCRETE_EXCEPTION(BadLayout, GG::Wnd, Exception);
00670 
00671 protected:
00675     enum DragDropRenderingState {
00677         NOT_DRAGGED,
00678 
00681         IN_PLACE_COPY,
00682 
00685         DRAGGED_OVER_UNACCEPTING_DROP_TARGET,
00686 
00689         DRAGGED_OVER_ACCEPTING_DROP_TARGET
00690     };
00691  
00693     Wnd(); 
00694 
00697     Wnd(X x, Y y, X w, Y h, Flags<WndFlag> flags = INTERACTIVE | DRAGABLE);
00699  
00701 
00704     DragDropRenderingState GetDragDropRenderingState() const;
00706  
00708 
00713     virtual void LButtonDown(const Pt& pt, Flags<ModKey> mod_keys);
00714 
00721     virtual void LDrag(const Pt& pt, const Pt& move, Flags<ModKey> mod_keys);
00722 
00727     virtual void LButtonUp(const Pt& pt, Flags<ModKey> mod_keys);
00728 
00733     virtual void LClick(const Pt& pt, Flags<ModKey> mod_keys);
00734 
00742     virtual void LDoubleClick(const Pt& pt, Flags<ModKey> mod_keys);
00743 
00745     virtual void MButtonDown(const Pt& pt, Flags<ModKey> mod_keys);
00746 
00749     virtual void MDrag(const Pt& pt, const Pt& move, Flags<ModKey> mod_keys);
00750 
00753     virtual void MButtonUp(const Pt& pt, Flags<ModKey> mod_keys);
00754 
00757     virtual void MClick(const Pt& pt, Flags<ModKey> mod_keys);
00758 
00761     virtual void MDoubleClick(const Pt& pt, Flags<ModKey> mod_keys);
00762 
00764     virtual void RButtonDown(const Pt& pt, Flags<ModKey> mod_keys);
00765 
00768     virtual void RDrag(const Pt& pt, const Pt& move, Flags<ModKey> mod_keys);
00769 
00772     virtual void RButtonUp(const Pt& pt, Flags<ModKey> mod_keys);
00773 
00776     virtual void RClick(const Pt& pt, Flags<ModKey> mod_keys);
00777 
00780     virtual void RDoubleClick(const Pt& pt, Flags<ModKey> mod_keys);
00781 
00783     virtual void MouseEnter(const Pt& pt, Flags<ModKey> mod_keys);
00784 
00789     virtual void MouseHere(const Pt& pt, Flags<ModKey> mod_keys);
00790 
00792     virtual void MouseLeave();
00793 
00796     virtual void MouseWheel(const Pt& pt, int move, Flags<ModKey> mod_keys);
00797 
00801     virtual void DragDropEnter(const Pt& pt, const std::map<Wnd*, Pt>& drag_drop_wnds,
00802                                Flags<ModKey> mod_keys);
00803 
00810     virtual void DragDropHere(const Pt& pt, const std::map<Wnd*, Pt>& drag_drop_wnds,
00811                               Flags<ModKey> mod_keys);
00812 
00815     virtual void DragDropLeave();
00816 
00825     virtual void KeyPress(Key key, boost::uint32_t key_code_point, Flags<ModKey> mod_keys);
00826 
00832     virtual void KeyRelease(Key key, boost::uint32_t key_code_point, Flags<ModKey> mod_keys);
00833 
00835     virtual void GainingFocus();
00836 
00838     virtual void LosingFocus();
00839 
00841     virtual void TimerFiring(unsigned int ticks, Timer* timer);
00842 
00846     virtual bool EventFilter(Wnd* w, const WndEvent& event);
00847 
00850     void HandleEvent(const WndEvent& event);
00851 
00855     void ForwardEventToParent();
00856 
00858     void BeginClipping();
00859 
00861     void EndClipping();
00862 
00866     void BeginNonclientClipping();
00867 
00871     void EndNonclientClipping();
00873 
00875     bool m_done;
00876 
00877 private:
00878     void ValidateFlags();              
00879     virtual void BeginClippingImpl(ChildClippingMode mode);
00880     virtual void EndClippingImpl(ChildClippingMode mode);
00881     virtual void BeginNonclientClippingImpl();
00882     virtual void EndNonclientClippingImpl();
00883 
00884 
00885     Wnd*              m_parent;        
00886     std::string       m_name;          
00887     std::list<Wnd*>   m_children;      
00888     int               m_zorder;        
00889     bool              m_visible;
00890     std::string       m_drag_drop_data_type; 
00891     ChildClippingMode m_child_clipping_mode;
00892     bool              m_non_client_child;
00893     Pt                m_upperleft;     
00894     Pt                m_lowerright;    
00895     Pt                m_min_size;      
00896     Pt                m_max_size;      
00897 
00900     std::vector<Wnd*> m_filters;
00901 
00902     std::set<Wnd*>    m_filtering;         
00903     Layout*           m_layout;            
00904     Layout*           m_containing_layout; 
00905     std::vector<BrowseInfoMode>
00906                       m_browse_modes;      
00907 
00908     boost::shared_ptr<StyleFactory>
00909                       m_style_factory;     
00910 
00913     Flags<WndFlag> m_flags;
00914 
00917     static unsigned int s_default_browse_time;
00918 
00921     static boost::shared_ptr<BrowseInfoWnd> s_default_browse_info_wnd;
00922 
00923     friend class GUI;   
00924     friend class GUIImpl;
00925     friend class Timer; 
00926     friend class ZList; 
00927 
00928     friend class boost::serialization::access;
00929     template <class Archive>
00930     void serialize(Archive& ar, const unsigned int version);
00931 };
00932 
00933 } // namespace GG
00934 
00935 // template implementations
00936 template <class Archive>
00937 void GG::Wnd::BrowseInfoMode::serialize(Archive& ar, const unsigned int version)
00938 {
00939     ar  & BOOST_SERIALIZATION_NVP(time)
00940         & BOOST_SERIALIZATION_NVP(wnd)
00941         & BOOST_SERIALIZATION_NVP(text);
00942 }
00943 
00944 template <class Archive>
00945 void GG::Wnd::serialize(Archive& ar, const unsigned int version)
00946 {
00947     ar  & BOOST_SERIALIZATION_NVP(m_done)
00948         & BOOST_SERIALIZATION_NVP(m_parent)
00949         & BOOST_SERIALIZATION_NVP(m_name)
00950         & BOOST_SERIALIZATION_NVP(m_children)
00951         & BOOST_SERIALIZATION_NVP(m_zorder)
00952         & BOOST_SERIALIZATION_NVP(m_visible)
00953         & BOOST_SERIALIZATION_NVP(m_drag_drop_data_type)
00954         & BOOST_SERIALIZATION_NVP(m_child_clipping_mode)
00955         & BOOST_SERIALIZATION_NVP(m_non_client_child)
00956         & BOOST_SERIALIZATION_NVP(m_upperleft)
00957         & BOOST_SERIALIZATION_NVP(m_lowerright)
00958         & BOOST_SERIALIZATION_NVP(m_min_size)
00959         & BOOST_SERIALIZATION_NVP(m_max_size)
00960         & BOOST_SERIALIZATION_NVP(m_filters)
00961         & BOOST_SERIALIZATION_NVP(m_filtering)
00962         & BOOST_SERIALIZATION_NVP(m_layout)
00963         & BOOST_SERIALIZATION_NVP(m_containing_layout)
00964         & BOOST_SERIALIZATION_NVP(m_browse_modes)
00965         & BOOST_SERIALIZATION_NVP(m_style_factory)
00966         & BOOST_SERIALIZATION_NVP(m_flags);
00967 
00968     if (Archive::is_loading::value)
00969         ValidateFlags();
00970 }
00971 
00972 #endif // _GG_Wnd_h_

Generated on Sat Mar 26 07:08:37 2011 for GG by  doxygen 1.5.9