00001 /************************************************************************ 00002 filename: CEGUIComboDropList.cpp 00003 created: 13/6/2004 00004 author: Paul D Turner 00005 00006 purpose: Implements the Combobox Drop-List widget base class 00007 *************************************************************************/ 00008 /************************************************************************* 00009 Crazy Eddie's GUI System (http://www.cegui.org.uk) 00010 Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk) 00011 00012 This library is free software; you can redistribute it and/or 00013 modify it under the terms of the GNU Lesser General Public 00014 License as published by the Free Software Foundation; either 00015 version 2.1 of the License, or (at your option) any later version. 00016 00017 This library is distributed in the hope that it will be useful, 00018 but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00020 Lesser General Public License for more details. 00021 00022 You should have received a copy of the GNU Lesser General Public 00023 License along with this library; if not, write to the Free Software 00024 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00025 *************************************************************************/ 00026 #include "elements/CEGUIComboDropList.h" 00027 #include "elements/CEGUIScrollbar.h" 00028 00029 00030 // Start of CEGUI namespace section 00031 namespace CEGUI 00032 { 00033 const String ComboDropList::EventNamespace("ComboDropList"); 00034 00035 /************************************************************************* 00036 Constants 00037 *************************************************************************/ 00038 // Event names 00039 const String ComboDropList::EventListSelectionAccepted( (utf8*)"ListSelectionAccepted" ); 00040 00041 00042 /************************************************************************* 00043 Constructor for ComboDropList base class 00044 *************************************************************************/ 00045 ComboDropList::ComboDropList(const String& type, const String& name) : 00046 Listbox(type, name) 00047 { 00048 d_autoArm = false; 00049 d_armed = false; 00050 00051 addComboDropListEvents(); 00052 hide(); 00053 } 00054 00055 00056 /************************************************************************* 00057 Destructor for ComboDropList base class 00058 *************************************************************************/ 00059 ComboDropList::~ComboDropList(void) 00060 { 00061 } 00062 00063 00064 /************************************************************************* 00065 Initialise the Window based object ready for use. 00066 *************************************************************************/ 00067 void ComboDropList::initialise(void) 00068 { 00069 Listbox::initialise(); 00070 00071 // set-up scroll bars so they return capture to us. 00072 d_vertScrollbar->setRestoreCapture(true); 00073 d_horzScrollbar->setRestoreCapture(true); 00074 } 00075 00076 00077 /************************************************************************* 00078 Add drop-list specific events 00079 *************************************************************************/ 00080 void ComboDropList::addComboDropListEvents(void) 00081 { 00082 addEvent(EventListSelectionAccepted); 00083 } 00084 00085 00086 /************************************************************************* 00087 Handler for when list selection is confirmed. 00088 *************************************************************************/ 00089 void ComboDropList::onListSelectionAccepted(WindowEventArgs& e) 00090 { 00091 fireEvent(EventListSelectionAccepted, e, EventNamespace); 00092 } 00093 00094 00095 /************************************************************************* 00096 Handler for mouse movement events 00097 *************************************************************************/ 00098 void ComboDropList::onMouseMove(MouseEventArgs& e) 00099 { 00100 Listbox::onMouseMove(e); 00101 00102 // if mouse is within our area (but not our children) 00103 if (isHit(e.position)) 00104 { 00105 if (getChildAtPosition(e.position) == NULL) 00106 { 00107 // handle auto-arm 00108 if (d_autoArm) 00109 { 00110 d_armed = true; 00111 } 00112 00113 if (d_armed) 00114 { 00115 // 00116 // Convert mouse position to absolute window pixels 00117 // 00118 Point localPos(screenToWindow(e.position)); 00119 00120 if (getMetricsMode() == Relative) 00121 { 00122 localPos = relativeToAbsolute(localPos); 00123 } 00124 00125 // check for an item under the mouse 00126 ListboxItem* selItem = getItemAtPoint(localPos); 00127 00128 // if an item is under mouse, select it 00129 if (selItem != NULL) 00130 { 00131 setItemSelectState(selItem, true); 00132 } 00133 else 00134 { 00135 clearAllSelections(); 00136 } 00137 00138 } 00139 } 00140 00141 e.handled = true; 00142 } 00143 // not within the list area 00144 else 00145 { 00146 // if left mouse button is down, clear any selection 00147 if (e.sysKeys & LeftMouse) 00148 { 00149 clearAllSelections(); 00150 } 00151 00152 } 00153 00154 } 00155 00156 00157 /************************************************************************* 00158 Handler for mouse button pressed events 00159 *************************************************************************/ 00160 void ComboDropList::onMouseButtonDown(MouseEventArgs& e) 00161 { 00162 Listbox::onMouseButtonDown(e); 00163 00164 if (e.button == LeftButton) 00165 { 00166 if (!isHit(e.position)) 00167 { 00168 clearAllSelections(); 00169 releaseInput(); 00170 } 00171 else 00172 { 00173 d_armed = true; 00174 } 00175 00176 e.handled = true; 00177 } 00178 00179 } 00180 00181 00182 /************************************************************************* 00183 Handler for mouse button release events 00184 *************************************************************************/ 00185 void ComboDropList::onMouseButtonUp(MouseEventArgs& e) 00186 { 00187 Listbox::onMouseButtonUp(e); 00188 00189 if (e.button == LeftButton) 00190 { 00191 if (d_armed && (getChildAtPosition(e.position) == NULL)) 00192 { 00193 releaseInput(); 00194 00195 // if something was selected, confirm that selection. 00196 if (getSelectedCount() > 0) 00197 { 00198 WindowEventArgs args(this); 00199 onListSelectionAccepted(args); 00200 } 00201 00202 } 00203 // if we are not already armed, in response to a left button up event, we auto-arm. 00204 else 00205 { 00206 d_armed = true; 00207 } 00208 00209 e.handled = true; 00210 } 00211 00212 } 00213 00214 00215 /************************************************************************* 00216 Handler for when input capture is lost 00217 *************************************************************************/ 00218 void ComboDropList::onCaptureLost(WindowEventArgs& e) 00219 { 00220 Listbox::onCaptureLost(e); 00221 d_armed = false; 00222 hide(); 00223 e.handled = true; 00224 } 00225 00226 00227 /************************************************************************* 00228 Handler for when window is activated 00229 *************************************************************************/ 00230 void ComboDropList::onActivated(ActivationEventArgs& e) 00231 { 00232 Listbox::onActivated(e); 00233 } 00234 00235 } // End of CEGUI namespace section