GG: Wnd.h Source File

GG

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

Wnd.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /* GG is a GUI for SDL and OpenGL.
3 Copyright (C) 2003-2008 T. Zachary Laine
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public License
7 as published by the Free Software Foundation; either version 2.1
8 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA
19
20 If you do not wish to comply with the terms of the LGPL please
21 contact the author as other terms are available for a fee.
22
23 Zach Laine
24 whatwasthataddress@gmail.com */
25
29 #ifndef _GG_Wnd_h_
30 #define _GG_Wnd_h_
31
32 #include <GG/Base.h>
33 #include <GG/Exception.h>
34 #include <GG/Flags.h>
35
36 #include <list>
37 #include <set>
38
39
40 namespace GG {
41
42 class BrowseInfoWnd;
43 class Layout;
44 class StyleFactory;
45 class Timer;
46 class WndEvent;
47
48
50 GG_FLAG_TYPE(WndFlag);
51
54 extern GG_API const WndFlag INTERACTIVE;
55
58 extern GG_API const WndFlag REPEAT_BUTTON_DOWN;
59
61 extern GG_API const WndFlag DRAGABLE;
62
64 extern GG_API const WndFlag RESIZABLE;
65
69 extern GG_API const WndFlag ONTOP;
70
75 extern GG_API const WndFlag MODAL;
76
77
220 class GG_API Wnd : public boost::signals::trackable
221 {
222 public:
228 struct GG_API BrowseInfoMode
229 {
232 unsigned int time;
233
236 boost::shared_ptr<BrowseInfoWnd> wnd;
237
239 std::string text;
240 };
241
243 typedef std::map<const Wnd*, bool>::iterator DropsAcceptableIter;
244
246 enum ChildClippingMode {
248 DontClip,
249
252 ClipToClient,
253
256 ClipToWindow,
257
264 ClipToClientAndWindowSeparately
265 };
266
268 virtual ~Wnd();
269
270
272
275 bool Interactive() const;
276
279 bool RepeatButtonDown() const;
280
282 bool Dragable() const;
283
285 bool Resizable() const;
286
288 bool OnTop() const;
289
291 bool Modal() const;
292
294 ChildClippingMode GetChildClippingMode() const;
295
298 bool NonClientChild() const;
299
301 bool Visible() const;
302
305 const std::string& Name() const;
306
310 const std::string& DragDropDataType() const;
311
315 virtual void DropsAcceptable(DropsAcceptableIter first,
316 DropsAcceptableIter last,
317 const Pt& pt) const;
318
321 Pt UpperLeft() const;
322
326 Pt LowerRight() const;
327
330 Pt RelativeUpperLeft() const;
331
335 Pt RelativeLowerRight() const;
336
337 X Width() const;
338 Y Height() const;
339
342 int ZOrder() const;
343
345 Pt Size() const;
346
347 Pt MinSize() const;
348 Pt MaxSize() const;
349
356 virtual Pt MinUsableSize() const;
357
362 virtual Pt ClientUpperLeft() const;
363
368 virtual Pt ClientLowerRight() const;
369
371 Pt ClientSize() const;
372
373 X ClientWidth() const;
374 Y ClientHeight() const;
375
377 Pt ScreenToWindow(const Pt& pt) const;
378
380 Pt ScreenToClient(const Pt& pt) const;
381
384 virtual bool InWindow(const Pt& pt) const;
385
388 virtual bool InClient(const Pt& pt) const;
389
392 const std::list<Wnd*>& Children() const;
393
395 Wnd* Parent() const;
396
398 Wnd* RootParent() const;
399
401 Layout* GetLayout() const;
402
404 Layout* ContainingLayout() const;
405
413 const std::vector<BrowseInfoMode>& BrowseModes() const;
414
418 const std::string& BrowseInfoText(std::size_t mode) const;
419
422 const boost::shared_ptr<StyleFactory>& GetStyleFactory() const;
423
425 virtual WndRegion WindowRegion(const Pt& pt) const;
427
429
432 void SetDragDropDataType(const std::string& data_type);
433
439 virtual void StartingChildDragDrop(const Wnd* wnd, const Pt& offset);
440
445 virtual void AcceptDrops(const std::vector<Wnd*>& wnds, const Pt& pt);
446
455 virtual void CancellingChildDragDrop(const std::vector<const Wnd*>& wnds);
456
465 virtual void ChildrenDraggedAway(const std::vector<Wnd*>& wnds,
466 const Wnd* destination);
467
470 void SetName(const std::string& name);
471
474 void Hide(bool children = true);
475
478 void Show(bool children = true);
479
483 virtual void ModalInit();
484
486 void SetChildClippingMode(ChildClippingMode mode);
487
490 void NonClientChild(bool b);
491
492 void MoveTo(const Pt& pt);
493 void OffsetMove(const Pt& pt);
494
497 virtual void SizeMove(const Pt& ul, const Pt& lr);
498
500 void Resize(const Pt& sz);
501
503 void SetMinSize(const Pt& sz);
504
506 void SetMaxSize(const Pt& sz);
507
510 void AttachChild(Wnd* wnd);
511
514 void MoveChildUp(Wnd* wnd);
515
518 void MoveChildDown(Wnd* wnd);
519
521 void DetachChild(Wnd* wnd);
522
524 void DetachChildren();
525
528 void DeleteChild(Wnd* wnd);
529
531 void DeleteChildren();
532
534 void InstallEventFilter(Wnd* wnd);
535
537 void RemoveEventFilter(Wnd* wnd);
538
542 void HorizontalLayout();
543
547 void VerticalLayout();
548
552 void GridLayout();
553
556 void SetLayout(Layout* layout);
557
562 void RemoveLayout();
563
567 Layout* DetachLayout();
568
572 void SetLayoutBorderMargin(unsigned int margin);
573
576 void SetLayoutCellMargin(unsigned int margin);
577
578
585 virtual void Render();
586
590 virtual bool Run();
591
593 void EndRun();
594
600 void SetBrowseModeTime(unsigned int time, std::size_t mode = 0);
601
605 void SetBrowseInfoWnd(const boost::shared_ptr<BrowseInfoWnd>& wnd, std::size_t mode = 0);
606
611 void ClearBrowseInfoWnd(std::size_t mode = 0);
612
617 void SetBrowseText(const std::string& text, std::size_t mode = 0);
618
626 void SetBrowseModes(const std::vector<BrowseInfoMode>& modes);
627
629 void SetStyleFactory(const boost::shared_ptr<StyleFactory>& factory);
631
632
635 static unsigned int DefaultBrowseTime();
636
639 static void SetDefaultBrowseTime(unsigned int time);
640
644 static const boost::shared_ptr<BrowseInfoWnd>& DefaultBrowseInfoWnd();
645
648 static void SetDefaultBrowseInfoWnd(const boost::shared_ptr<BrowseInfoWnd>& browse_info_wnd);
649
651
652 GG_ABSTRACT_EXCEPTION(Exception);
653
657 GG_CONCRETE_EXCEPTION(BadLayout, GG::Wnd, Exception);
659
660 protected:
664 enum DragDropRenderingState {
666 NOT_DRAGGED,
667
670 IN_PLACE_COPY,
671
674 DRAGGED_OVER_UNACCEPTING_DROP_TARGET,
675
678 DRAGGED_OVER_ACCEPTING_DROP_TARGET
679 };
680
682 Wnd();
683
686 Wnd(X x, Y y, X w, Y h, Flags<WndFlag> flags = INTERACTIVE | DRAGABLE);
688
690
693 DragDropRenderingState GetDragDropRenderingState() const;
695
697
702 virtual void LButtonDown(const Pt& pt, Flags<ModKey> mod_keys);
703
710 virtual void LDrag(const Pt& pt, const Pt& move, Flags<ModKey> mod_keys);
711
716 virtual void LButtonUp(const Pt& pt, Flags<ModKey> mod_keys);
717
722 virtual void LClick(const Pt& pt, Flags<ModKey> mod_keys);
723
731 virtual void LDoubleClick(const Pt& pt, Flags<ModKey> mod_keys);
732
734 virtual void MButtonDown(const Pt& pt, Flags<ModKey> mod_keys);
735
738 virtual void MDrag(const Pt& pt, const Pt& move, Flags<ModKey> mod_keys);
739
742 virtual void MButtonUp(const Pt& pt, Flags<ModKey> mod_keys);
743
746 virtual void MClick(const Pt& pt, Flags<ModKey> mod_keys);
747
750 virtual void MDoubleClick(const Pt& pt, Flags<ModKey> mod_keys);
751
753 virtual void RButtonDown(const Pt& pt, Flags<ModKey> mod_keys);
754
757 virtual void RDrag(const Pt& pt, const Pt& move, Flags<ModKey> mod_keys);
758
761 virtual void RButtonUp(const Pt& pt, Flags<ModKey> mod_keys);
762
765 virtual void RClick(const Pt& pt, Flags<ModKey> mod_keys);
766
769 virtual void RDoubleClick(const Pt& pt, Flags<ModKey> mod_keys);
770
772 virtual void MouseEnter(const Pt& pt, Flags<ModKey> mod_keys);
773
778 virtual void MouseHere(const Pt& pt, Flags<ModKey> mod_keys);
779
781 virtual void MouseLeave();
782
785 virtual void MouseWheel(const Pt& pt, int move, Flags<ModKey> mod_keys);
786
790 virtual void DragDropEnter(const Pt& pt, const std::map<Wnd*, Pt>& drag_drop_wnds,
791 Flags<ModKey> mod_keys);
792
799 virtual void DragDropHere(const Pt& pt, const std::map<Wnd*, Pt>& drag_drop_wnds,
800 Flags<ModKey> mod_keys);
801
804 virtual void DragDropLeave();
805
814 virtual void KeyPress(Key key, boost::uint32_t key_code_point, Flags<ModKey> mod_keys);
815
821 virtual void KeyRelease(Key key, boost::uint32_t key_code_point, Flags<ModKey> mod_keys);
822
824 virtual void GainingFocus();
825
827 virtual void LosingFocus();
828
830 virtual void TimerFiring(unsigned int ticks, Timer* timer);
831
835 virtual bool EventFilter(Wnd* w, const WndEvent& event);
836
839 void HandleEvent(const WndEvent& event);
840
844 void ForwardEventToParent();
845
847 void BeginClipping();
848
850 void EndClipping();
851
855 void BeginNonclientClipping();
856
860 void EndNonclientClipping();
862
864 bool m_done;
865
866 private:
867 void ValidateFlags();
868 virtual void BeginClippingImpl(ChildClippingMode mode);
869 virtual void EndClippingImpl(ChildClippingMode mode);
870 virtual void BeginNonclientClippingImpl();
871 virtual void EndNonclientClippingImpl();
872
873
874 Wnd* m_parent;
875 std::string m_name;
876 std::list<Wnd*> m_children;
877 int m_zorder;
878 bool m_visible;
879 std::string m_drag_drop_data_type;
880 ChildClippingMode m_child_clipping_mode;
881 bool m_non_client_child;
882 Pt m_upperleft;
883 Pt m_lowerright;
884 Pt m_min_size;
885 Pt m_max_size;
886
889 std::vector<Wnd*> m_filters;
890
891 std::set<Wnd*> m_filtering;
892 Layout* m_layout;
893 Layout* m_containing_layout;
894 std::vector<BrowseInfoMode>
895 m_browse_modes;
896
897 boost::shared_ptr<StyleFactory>
898 m_style_factory;
899
902 Flags<WndFlag> m_flags;
903
906 static unsigned int s_default_browse_time;
907
910 static boost::shared_ptr<BrowseInfoWnd> s_default_browse_info_wnd;
911
912 friend class GUI;
913 friend class GUIImpl;
914 friend class Timer;
915 friend class ZList;
916 };
917
918 } // namespace GG
919
920 #endif