1 /***********************************************************************
2 	created:	8/8/2004
3 	author:		Steve Streeting
4 
5 	purpose:	Implementation of TabButton widget base class
6 *************************************************************************/
7 /***************************************************************************
8  *   Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
9  *
10  *   Permission is hereby granted, free of charge, to any person obtaining
11  *   a copy of this software and associated documentation files (the
12  *   "Software"), to deal in the Software without restriction, including
13  *   without limitation the rights to use, copy, modify, merge, publish,
14  *   distribute, sublicense, and/or sell copies of the Software, and to
15  *   permit persons to whom the Software is furnished to do so, subject to
16  *   the following conditions:
17  *
18  *   The above copyright notice and this permission notice shall be
19  *   included in all copies or substantial portions of the Software.
20  *
21  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24  *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25  *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27  *   OTHER DEALINGS IN THE SOFTWARE.
28  ***************************************************************************/
29 #include "CEGUI/widgets/TabButton.h"
30 
31 // Start of CEGUI namespace section
32 namespace CEGUI
33 {
34 const String TabButton::EventNamespace("TabButton");
35 const String TabButton::WidgetTypeName("CEGUI/TabButton");
36 
37 
38 /*************************************************************************
39 	Event name constants
40 *************************************************************************/
41 const String TabButton::EventClicked( "Clicked" );
42 const String TabButton::EventDragged( "Dragged" );
43 const String TabButton::EventScrolled( "Scrolled" );
44 
45 
46 /*************************************************************************
47 	Constructor
48 *************************************************************************/
TabButton(const String & type,const String & name)49 TabButton::TabButton(const String& type, const String& name) :
50 	ButtonBase(type, name),
51     d_selected(false),
52     d_dragging(false)
53 {
54 }
55 
56 
57 /*************************************************************************
58 	Destructor
59 *************************************************************************/
~TabButton(void)60 TabButton::~TabButton(void)
61 {
62 }
63 
64 
65 /*************************************************************************
66 Set target window
67 *************************************************************************/
setTargetWindow(Window * wnd)68 void TabButton::setTargetWindow(Window* wnd)
69 {
70     d_targetWindow = wnd;
71     // Copy initial text
72     setText(wnd->getText());
73     // Parent control will keep text up to date, since changes affect layout
74 }
75 
76 
77 /*************************************************************************
78 	handler invoked internally when the button is clicked.
79 *************************************************************************/
onClicked(WindowEventArgs & e)80 void TabButton::onClicked(WindowEventArgs& e)
81 {
82 	fireEvent(EventClicked, e, EventNamespace);
83 }
84 
85 
86 /*************************************************************************
87 	Handler for mouse button release events
88 *************************************************************************/
onMouseButtonDown(MouseEventArgs & e)89 void TabButton::onMouseButtonDown(MouseEventArgs& e)
90 {
91     if (e.button == MiddleButton)
92     {
93         captureInput ();
94         ++e.handled;
95         d_dragging = true;
96 
97         fireEvent(EventDragged, e, EventNamespace);
98     }
99 
100 	// default handling
101 	ButtonBase::onMouseButtonDown(e);
102 }
103 
onMouseButtonUp(MouseEventArgs & e)104 void TabButton::onMouseButtonUp(MouseEventArgs& e)
105 {
106 	if ((e.button == LeftButton) && isPushed())
107 	{
108 		Window* sheet = getGUIContext().getRootWindow();
109 
110 		if (sheet)
111 		{
112 			// if mouse was released over this widget
113             // (use mouse position, as e.position has been unprojected)
114 			if (this == sheet->getTargetChildAtPosition(
115                                     getGUIContext().getMouseCursor().getPosition()))
116 			{
117 				// fire event
118 				WindowEventArgs args(this);
119 				onClicked(args);
120 			}
121 		}
122 
123 		++e.handled;
124     }
125     else if (e.button == MiddleButton)
126     {
127         d_dragging = false;
128         releaseInput ();
129         ++e.handled;
130     }
131 
132 	// default handling
133 	ButtonBase::onMouseButtonUp(e);
134 }
135 
onMouseMove(MouseEventArgs & e)136 void TabButton::onMouseMove(MouseEventArgs& e)
137 {
138     if (d_dragging)
139     {
140         fireEvent(EventDragged, e, EventNamespace);
141         ++e.handled;
142     }
143 
144 	// default handling
145 	ButtonBase::onMouseMove(e);
146 }
147 
onMouseWheel(MouseEventArgs & e)148 void TabButton::onMouseWheel(MouseEventArgs& e)
149 {
150     fireEvent(EventScrolled, e, EventNamespace);
151 
152 	// default handling
153 	ButtonBase::onMouseMove(e);
154 }
155 
156 } // End of  CEGUI namespace section
157