Wnd.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /* GG is a GUI for SDL and OpenGL.
00003    Copyright (C) 2003 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@hotmail.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 
00054 extern GG_API const WndFlag CLICKABLE;
00055 
00057 extern GG_API const WndFlag REPEAT_BUTTON_DOWN;
00058 
00060 extern GG_API const WndFlag DRAGABLE;
00061 
00063 extern GG_API const WndFlag RESIZABLE;
00064 
00066 extern GG_API const WndFlag ONTOP;
00067 
00070 extern GG_API const WndFlag MODAL;
00071 
00072 
00167 class GG_API Wnd : public boost::signals::trackable
00168 {
00169 public:
00173     struct GG_API BrowseInfoMode
00174     {
00175         int                              time; 
00176         boost::shared_ptr<BrowseInfoWnd> wnd;  
00177         std::string                      text; 
00178         template <class Archive>
00179         void serialize(Archive& ar, const unsigned int version);
00180     };
00181  
00183     virtual ~Wnd(); 
00184 
00185  
00187     bool           Clickable() const;    
00188 
00190     bool           RepeatButtonDown() const;
00191 
00192     bool           Dragable() const;     
00193     bool           Resizable() const;    
00194     bool           OnTop() const;        
00195     bool           Modal() const;        
00196     bool           ClipChildren() const; 
00197     bool           Visible() const;      
00198     const std::string&
00199                    WindowText() const;   
00200 
00203     const std::string&
00204                    DragDropDataType() const;
00205 
00208     Pt             UpperLeft() const;
00209 
00212     Pt             LowerRight() const;
00213 
00216     Pt             RelativeUpperLeft() const;
00217 
00220     Pt             RelativeLowerRight() const;
00221 
00222     int            Width() const;        
00223     int            Height() const;       
00224     int            ZOrder() const;       
00225     Pt             Size() const;         
00226     Pt             MinSize() const;      
00227     Pt             MaxSize() const;      
00228 
00233     virtual Pt     MinUsableSize() const;
00234 
00238     virtual Pt     ClientUpperLeft() const;
00239 
00243     virtual Pt     ClientLowerRight() const;
00244 
00246     Pt             ClientSize() const;
00247 
00248     int            ClientWidth() const;                 
00249     int            ClientHeight() const;                
00250 
00251     Pt             ScreenToWindow(const Pt& pt) const;  
00252     Pt             ScreenToClient(const Pt& pt) const;  
00253     virtual bool   InWindow(const Pt& pt) const;        
00254 
00256     virtual bool   InClient(const Pt& pt) const;
00257 
00258     const std::list<Wnd*>&
00259                    Children() const;                    
00260     Wnd*           Parent() const;                      
00261     Wnd*           RootParent() const;                  
00262 
00263     Layout*        GetLayout() const;                   
00264     Layout*        ContainingLayout() const;            
00265 
00270     const std::vector<BrowseInfoMode>&  BrowseModes() const;
00271 
00274     const std::string& BrowseInfoText(int mode) const;
00275 
00276     const boost::shared_ptr<StyleFactory>& GetStyleFactory() const; 
00277 
00278     virtual WndRegion WindowRegion(const Pt& pt) const; 
00279 
00280  
00282 
00284     void           SetDragDropDataType(const std::string& data_type);
00285 
00289     virtual void   StartingChildDragDrop(const Wnd* wnd, const Pt& offset);
00290 
00294     virtual void   AcceptDrops(std::list<Wnd*>& wnds, const Pt& pt);
00295 
00301     virtual void   CancellingChildDragDrop(const std::list<Wnd*>& wnds);
00302 
00308     virtual void   ChildrenDraggedAway(const std::list<Wnd*>& wnds, const Wnd* destination);
00309 
00310     virtual void   SetText(const std::string& str);     
00311 
00313     void           Hide(bool children = true);
00314 
00316     void           Show(bool children = true);
00317 
00320     virtual void   ModalInit();
00321 
00323     void           EnableChildClipping(bool enable = true);
00324 
00325     virtual void   BeginClipping();                     
00326     virtual void   EndClipping();                       
00327     void           MoveTo(const Pt& pt);                
00328     void           OffsetMove(const Pt& pt);            
00329 
00331     virtual void   SizeMove(const Pt& ul, const Pt& lr);
00332 
00333     void           Resize(const Pt& sz);                
00334     void           SetMinSize(const Pt& sz);            
00335     void           SetMaxSize(const Pt& sz);            
00336 
00338     void           AttachChild(Wnd* wnd);
00339 
00341     void           MoveChildUp(Wnd* wnd);
00342 
00344     void           MoveChildDown(Wnd* wnd);
00345 
00346     void           DetachChild(Wnd* wnd);               
00347     void           DetachChildren();                    
00348 
00350     void           DeleteChild(Wnd* wnd);
00351 
00352     void           DeleteChildren();                    
00353     void           InstallEventFilter(Wnd* wnd);        
00354     void           RemoveEventFilter(Wnd* wnd);         
00355 
00358     void           HorizontalLayout();
00359 
00362     void           VerticalLayout();
00363 
00366     void           GridLayout();
00367 
00370     void           SetLayout(Layout* layout);
00371 
00374     void           RemoveLayout();
00375 
00378     Layout*        DetachLayout();
00379 
00382     void           SetLayoutBorderMargin(int margin);
00383 
00386     void           SetLayoutCellMargin(int margin);
00387 
00388 
00393     virtual void   Render();
00394 
00398     virtual void   LButtonDown(const Pt& pt, Flags<ModKey> mod_keys);
00399 
00404     virtual void   LDrag(const Pt& pt, const Pt& move, Flags<ModKey> mod_keys);
00405 
00409     virtual void   LButtonUp(const Pt& pt, Flags<ModKey> mod_keys);
00410 
00413     virtual void   LClick(const Pt& pt, Flags<ModKey> mod_keys);
00414 
00420     virtual void   LDoubleClick(const Pt& pt, Flags<ModKey> mod_keys);
00421 
00423     virtual void   MButtonDown(const Pt& pt, Flags<ModKey> mod_keys);
00424 
00426     virtual void   MDrag(const Pt& pt, const Pt& move, Flags<ModKey> mod_keys);
00427 
00430     virtual void   MButtonUp(const Pt& pt, Flags<ModKey> mod_keys);
00431 
00434     virtual void   MClick(const Pt& pt, Flags<ModKey> mod_keys);
00435 
00437     virtual void   MDoubleClick(const Pt& pt, Flags<ModKey> mod_keys);
00438 
00440     virtual void   RButtonDown(const Pt& pt, Flags<ModKey> mod_keys);
00441 
00443     virtual void   RDrag(const Pt& pt, const Pt& move, Flags<ModKey> mod_keys);
00444 
00447     virtual void   RButtonUp(const Pt& pt, Flags<ModKey> mod_keys);
00448 
00451     virtual void   RClick(const Pt& pt, Flags<ModKey> mod_keys);
00452 
00454     virtual void   RDoubleClick(const Pt& pt, Flags<ModKey> mod_keys);
00455 
00456     virtual void   MouseEnter(const Pt& pt, Flags<ModKey> mod_keys);  
00457 
00461     virtual void   MouseHere(const Pt& pt, Flags<ModKey> mod_keys);
00462 
00463     virtual void   MouseLeave();  
00464 
00466     virtual void   MouseWheel(const Pt& pt, int move, Flags<ModKey> mod_keys);
00467 
00470     virtual void   DragDropEnter(const Pt& pt, const std::map<Wnd*, Pt>& drag_drop_wnds, Flags<ModKey> mod_keys);
00471 
00476     virtual void   DragDropHere(const Pt& pt, const std::map<Wnd*, Pt>& drag_drop_wnds, Flags<ModKey> mod_keys);
00477 
00479     virtual void   DragDropLeave();
00480 
00486     virtual void   KeyPress(Key key, Flags<ModKey> mod_keys);
00487 
00491     virtual void   KeyRelease(Key key, Flags<ModKey> mod_keys);
00492 
00493     virtual void   GainingFocus();                         
00494     virtual void   LosingFocus();                          
00495 
00496     virtual void   TimerFiring(int ticks, Timer* timer);   
00497 
00498 
00501     virtual int    Run();
00502 
00506     void SetBrowseModeTime(int time, int mode = 0);
00507 
00510     void SetBrowseInfoWnd(const boost::shared_ptr<BrowseInfoWnd>& wnd, int mode = 0);
00511 
00515     void SetBrowseText(const std::string& text, int mode = 0);
00516 
00521     void SetBrowseModes(const std::vector<BrowseInfoMode>& modes);
00522 
00523     void SetStyleFactory(const boost::shared_ptr<StyleFactory>& factory); 
00524 
00527     virtual void DefineAttributes(WndEditor* editor);
00529 
00530 
00532     static int DefaultBrowseTime();
00533 
00535     static void SetDefaultBrowseTime(int time);
00536 
00539     static const boost::shared_ptr<BrowseInfoWnd>& DefaultBrowseInfoWnd();
00540 
00542     static void SetDefaultBrowseInfoWnd(const boost::shared_ptr<BrowseInfoWnd>& browse_info_wnd);
00543  
00545 
00546     GG_ABSTRACT_EXCEPTION(Exception);
00547 
00550     GG_CONCRETE_EXCEPTION(BadLayout, GG::Wnd, Exception);
00552 
00553 protected: 
00555     Wnd(); 
00556 
00558     Wnd(int x, int y, int w, int h, Flags<WndFlag> flags = CLICKABLE | DRAGABLE);
00560  
00562 
00564     virtual bool EventFilter(Wnd* w, const WndEvent& event);
00565 
00566     void HandleEvent(const WndEvent& event); 
00567 
00568 
00569     std::string  m_text;               
00570     bool         m_done;               
00571 
00572 private:
00573     void ValidateFlags();              
00574 
00575     Wnd*              m_parent;        
00576     std::list<Wnd*>   m_children;      
00577     int               m_zorder;        
00578     bool              m_visible;       
00579     std::string       m_drag_drop_data_type; 
00580     bool              m_clip_children; 
00581     Pt                m_upperleft;     
00582     Pt                m_lowerright;    
00583     Pt                m_min_size;      
00584     Pt                m_max_size;      
00585 
00587     std::vector<Wnd*> m_filters;
00588 
00589     std::set<Wnd*>    m_filtering;         
00590     Layout*           m_layout;            
00591     Layout*           m_containing_layout; 
00592     std::vector<BrowseInfoMode>
00593                       m_browse_modes;      
00594 
00595     boost::shared_ptr<StyleFactory>
00596                       m_style_factory;     
00597 
00599     Flags<WndFlag>    m_flags;
00600 
00602     static int        s_default_browse_time;
00603 
00605     static boost::shared_ptr<BrowseInfoWnd>
00606                       s_default_browse_info_wnd;
00607 
00608     friend class GUI;   
00609     friend class GUIImpl;
00610     friend class Timer; 
00611     friend class ZList; 
00612 
00613     friend class boost::serialization::access;
00614     template <class Archive>
00615     void serialize(Archive& ar, const unsigned int version);
00616 };
00617 
00618 } // namespace GG
00619 
00620 // template implementations
00621 template <class Archive>
00622 void GG::Wnd::BrowseInfoMode::serialize(Archive& ar, const unsigned int version)
00623 {
00624     ar  & BOOST_SERIALIZATION_NVP(time)
00625         & BOOST_SERIALIZATION_NVP(wnd)
00626         & BOOST_SERIALIZATION_NVP(text);
00627 }
00628 
00629 template <class Archive>
00630 void GG::Wnd::serialize(Archive& ar, const unsigned int version)
00631 {
00632     ar  & BOOST_SERIALIZATION_NVP(m_text)
00633         & BOOST_SERIALIZATION_NVP(m_done)
00634         & BOOST_SERIALIZATION_NVP(m_parent)
00635         & BOOST_SERIALIZATION_NVP(m_children)
00636         & BOOST_SERIALIZATION_NVP(m_zorder)
00637         & BOOST_SERIALIZATION_NVP(m_visible)
00638         & BOOST_SERIALIZATION_NVP(m_drag_drop_data_type)
00639         & BOOST_SERIALIZATION_NVP(m_clip_children)
00640         & BOOST_SERIALIZATION_NVP(m_upperleft)
00641         & BOOST_SERIALIZATION_NVP(m_lowerright)
00642         & BOOST_SERIALIZATION_NVP(m_min_size)
00643         & BOOST_SERIALIZATION_NVP(m_max_size)
00644         & BOOST_SERIALIZATION_NVP(m_filters)
00645         & BOOST_SERIALIZATION_NVP(m_filtering)
00646         & BOOST_SERIALIZATION_NVP(m_layout)
00647         & BOOST_SERIALIZATION_NVP(m_containing_layout)
00648         & BOOST_SERIALIZATION_NVP(m_browse_modes)
00649         & BOOST_SERIALIZATION_NVP(m_style_factory)
00650         & BOOST_SERIALIZATION_NVP(m_flags);
00651 
00652     if (Archive::is_loading::value)
00653         ValidateFlags();
00654 }
00655 
00656 #endif // _GG_Wnd_h_

Generated on Wed Mar 26 14:35:42 2008 for GG by  doxygen 1.5.2