00001 /*********************************************************************** 00002 filename: CEGUICombobox.h 00003 created: 13/4/2004 00004 author: Paul D Turner 00005 00006 purpose: Interface to base class for Combobox widget 00007 *************************************************************************/ 00008 /*************************************************************************** 00009 * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team 00010 * 00011 * Permission is hereby granted, free of charge, to any person obtaining 00012 * a copy of this software and associated documentation files (the 00013 * "Software"), to deal in the Software without restriction, including 00014 * without limitation the rights to use, copy, modify, merge, publish, 00015 * distribute, sublicense, and/or sell copies of the Software, and to 00016 * permit persons to whom the Software is furnished to do so, subject to 00017 * the following conditions: 00018 * 00019 * The above copyright notice and this permission notice shall be 00020 * included in all copies or substantial portions of the Software. 00021 * 00022 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00023 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00024 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00025 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 00026 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00027 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00028 * OTHER DEALINGS IN THE SOFTWARE. 00029 ***************************************************************************/ 00030 #ifndef _CEGUICombobox_h_ 00031 #define _CEGUICombobox_h_ 00032 00033 #include "../CEGUIBase.h" 00034 #include "../CEGUIWindow.h" 00035 #include "CEGUIComboboxProperties.h" 00036 00037 00038 #if defined(_MSC_VER) 00039 # pragma warning(push) 00040 # pragma warning(disable : 4251) 00041 #endif 00042 00043 00044 // Start of CEGUI namespace section 00045 namespace CEGUI 00046 { 00047 00052 class CEGUIEXPORT Combobox : public Window 00053 { 00054 public: 00055 static const String EventNamespace; 00056 static const String WidgetTypeName; 00057 00058 /************************************************************************* 00059 Constants 00060 *************************************************************************/ 00061 // event names from edit box 00067 static const String EventReadOnlyModeChanged; 00073 static const String EventValidationStringChanged; 00079 static const String EventMaximumTextLengthChanged; 00086 static const String EventTextInvalidated; 00093 static const String EventInvalidEntryAttempted; 00099 static const String EventCaratMoved; 00105 static const String EventTextSelectionChanged; 00112 static const String EventEditboxFull; 00119 static const String EventTextAccepted; 00120 00121 // event names from list box 00127 static const String EventListContentsChanged; 00134 static const String EventListSelectionChanged; 00140 static const String EventSortModeChanged; 00147 static const String EventVertScrollbarModeChanged; 00154 static const String EventHorzScrollbarModeChanged; 00155 00156 // events we produce / generate ourselves 00162 static const String EventDropListDisplayed; 00168 static const String EventDropListRemoved; 00174 static const String EventListSelectionAccepted; 00175 00176 /************************************************************************* 00177 Child Widget name suffix constants 00178 *************************************************************************/ 00179 static const String EditboxNameSuffix; 00180 static const String DropListNameSuffix; 00181 static const String ButtonNameSuffix; 00182 00183 // override from Window class 00184 bool isHit(const Vector2& position, 00185 const bool allow_disabled = false) const; 00186 00195 bool getSingleClickEnabled(void) const; 00196 00197 00205 bool isDropDownListVisible(void) const; 00206 00207 00218 Editbox* getEditbox() const; 00219 00230 PushButton* getPushButton() const; 00231 00243 ComboDropList* getDropList() const; 00244 00245 00246 /************************************************************************* 00247 Editbox Accessors 00248 *************************************************************************/ 00256 bool hasInputFocus(void) const; 00257 00258 00267 bool isReadOnly(void) const; 00268 00269 00286 bool isTextValid(void) const; 00287 00288 00300 const String& getValidationString(void) const; 00301 00302 00310 size_t getCaratIndex(void) const; 00311 00312 00321 size_t getSelectionStartIndex(void) const; 00322 00323 00332 size_t getSelectionEndIndex(void) const; 00333 00334 00342 size_t getSelectionLength(void) const; 00343 00344 00356 size_t getMaxTextLength(void) const; 00357 00358 00359 /************************************************************************* 00360 List Accessors 00361 *************************************************************************/ 00369 size_t getItemCount(void) const; 00370 00371 00380 ListboxItem* getSelectedItem(void) const; 00381 00382 00395 ListboxItem* getListboxItemFromIndex(size_t index) const; 00396 00397 00410 size_t getItemIndex(const ListboxItem* item) const; 00411 00412 00420 bool isSortEnabled(void) const; 00421 00422 00435 bool isItemSelected(size_t index) const; 00436 00437 00455 ListboxItem* findItemWithText(const String& text, const ListboxItem* start_item); 00456 00457 00465 bool isListboxItemInList(const ListboxItem* item) const; 00466 00467 00476 bool isVertScrollbarAlwaysShown(void) const; 00477 00478 00487 bool isHorzScrollbarAlwaysShown(void) const; 00488 00489 00490 /************************************************************************* 00491 Combobox Manipulators 00492 *************************************************************************/ 00503 virtual void initialiseComponents(void); 00504 00505 00513 void showDropList(void); 00514 00515 00523 void hideDropList(void); 00524 00525 00537 void setSingleClickEnabled(bool setting); 00538 00539 00540 /************************************************************************* 00541 Editbox Manipulators 00542 *************************************************************************/ 00554 void setReadOnly(bool setting); 00555 00556 00571 void setValidationString(const String& validation_string); 00572 00573 00585 void setCaratIndex(size_t carat_pos); 00586 00587 00603 void setSelection(size_t start_pos, size_t end_pos); 00604 00605 00620 void setMaxTextLength(size_t max_len); 00621 00622 00630 void activateEditbox(void); 00631 00632 00633 /************************************************************************* 00634 List Manipulators 00635 *************************************************************************/ 00642 void resetList(void); 00643 00644 00656 void addItem(ListboxItem* item); 00657 00658 00676 void insertItem(ListboxItem* item, const ListboxItem* position); 00677 00678 00690 void removeItem(const ListboxItem* item); 00691 00692 00700 void clearAllSelections(void); 00701 00702 00713 void setSortingEnabled(bool setting); 00714 00715 00727 void setShowVertScrollbar(bool setting); 00728 00729 00741 void setShowHorzScrollbar(bool setting); 00742 00743 00763 void setItemSelectState(ListboxItem* item, bool state); 00764 00765 00785 void setItemSelectState(size_t item_index, bool state); 00786 00787 00800 void handleUpdatedListItemData(void); 00801 00802 00803 /************************************************************************* 00804 Construction and Destruction 00805 *************************************************************************/ 00810 Combobox(const String& type, const String& name); 00811 00812 00817 virtual ~Combobox(void); 00818 00819 00820 protected: 00821 /************************************************************************* 00822 Implementation Methods 00823 *************************************************************************/ 00828 bool button_PressHandler(const EventArgs& e); 00829 00830 00835 bool droplist_SelectionAcceptedHandler(const EventArgs& e); 00836 00837 00842 bool droplist_HiddenHandler(const EventArgs& e); 00843 00844 00849 bool editbox_MouseDownHandler(const EventArgs& e); 00850 00851 00862 virtual bool testClassName_impl(const String& class_name) const 00863 { 00864 if (class_name=="Combobox") return true; 00865 return Window::testClassName_impl(class_name); 00866 } 00867 00873 void itemSelectChangeTextUpdate(const ListboxItem* const item, 00874 bool new_state, bool old_state); 00875 00876 /************************************************************************* 00877 Handlers to relay child widget events so they appear to come from us 00878 *************************************************************************/ 00879 bool editbox_ReadOnlyChangedHandler(const EventArgs& e); 00880 bool editbox_ValidationStringChangedHandler(const EventArgs& e); 00881 bool editbox_MaximumTextLengthChangedHandler(const EventArgs& e); 00882 bool editbox_TextInvalidatedEventHandler(const EventArgs& e); 00883 bool editbox_InvalidEntryAttemptedHandler(const EventArgs& e); 00884 bool editbox_CaratMovedHandler(const EventArgs& e); 00885 bool editbox_TextSelectionChangedHandler(const EventArgs& e); 00886 bool editbox_EditboxFullEventHandler(const EventArgs& e); 00887 bool editbox_TextAcceptedEventHandler(const EventArgs& e); 00888 bool editbox_TextChangedEventHandler(const EventArgs& e); 00889 bool listbox_ListContentsChangedHandler(const EventArgs& e); 00890 bool listbox_ListSelectionChangedHandler(const EventArgs& e); 00891 bool listbox_SortModeChangedHandler(const EventArgs& e); 00892 bool listbox_VertScrollModeChangedHandler(const EventArgs& e); 00893 bool listbox_HorzScrollModeChangedHandler(const EventArgs& e); 00894 00895 00896 /************************************************************************* 00897 New Events for Combobox 00898 *************************************************************************/ 00903 virtual void onReadOnlyChanged(WindowEventArgs& e); 00904 00905 00910 virtual void onValidationStringChanged(WindowEventArgs& e); 00911 00912 00917 virtual void onMaximumTextLengthChanged(WindowEventArgs& e); 00918 00919 00924 virtual void onTextInvalidatedEvent(WindowEventArgs& e); 00925 00926 00931 virtual void onInvalidEntryAttempted(WindowEventArgs& e); 00932 00933 00938 virtual void onCaratMoved(WindowEventArgs& e); 00939 00940 00945 virtual void onTextSelectionChanged(WindowEventArgs& e); 00946 00947 00952 virtual void onEditboxFullEvent(WindowEventArgs& e); 00953 00954 00959 virtual void onTextAcceptedEvent(WindowEventArgs& e); 00960 00961 00966 virtual void onListContentsChanged(WindowEventArgs& e); 00967 00968 00974 virtual void onListSelectionChanged(WindowEventArgs& e); 00975 00976 00981 virtual void onSortModeChanged(WindowEventArgs& e); 00982 00983 00989 virtual void onVertScrollbarModeChanged(WindowEventArgs& e); 00990 00991 00997 virtual void onHorzScrollbarModeChanged(WindowEventArgs& e); 00998 00999 01004 virtual void onDropListDisplayed(WindowEventArgs& e); 01005 01006 01011 virtual void onDroplistRemoved(WindowEventArgs& e); 01012 01013 01018 virtual void onListSelectionAccepted(WindowEventArgs& e); 01019 01020 01021 /************************************************************************* 01022 Overridden Event handlers 01023 *************************************************************************/ 01024 virtual void onFontChanged(WindowEventArgs& e); 01025 virtual void onTextChanged(WindowEventArgs& e); 01026 virtual void onActivated(ActivationEventArgs& e); 01027 01028 01029 /************************************************************************* 01030 Implementation Data 01031 *************************************************************************/ 01032 bool d_singleClickOperation; 01033 01034 01035 private: 01036 /************************************************************************* 01037 Static Properties for this class 01038 *************************************************************************/ 01039 static ComboboxProperties::ReadOnly d_readOnlyProperty; 01040 static ComboboxProperties::ValidationString d_validationStringProperty; 01041 static ComboboxProperties::CaratIndex d_caratIndexProperty; 01042 static ComboboxProperties::EditSelectionStart d_selStartProperty; 01043 static ComboboxProperties::EditSelectionLength d_selLengthProperty; 01044 static ComboboxProperties::MaxEditTextLength d_maxTextLengthProperty; 01045 static ComboboxProperties::SortList d_sortProperty; 01046 static ComboboxProperties::ForceVertScrollbar d_forceVertProperty; 01047 static ComboboxProperties::ForceHorzScrollbar d_forceHorzProperty; 01048 static ComboboxProperties::SingleClickMode d_singleClickOperationProperty; 01049 01050 /************************************************************************* 01051 Private methods 01052 *************************************************************************/ 01053 void addComboboxProperties(void); 01054 }; 01055 01056 } // End of CEGUI namespace section 01057 01058 #if defined(_MSC_VER) 01059 # pragma warning(pop) 01060 #endif 01061 01062 #endif // end of guard _CEGUICombobox_h_