Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

CEGUICombobox.cpp

Go to the documentation of this file.
00001 /************************************************************************
00002         filename:       CEGUICombobox.cpp
00003         created:        13/4/2004
00004         author:         Paul D Turner
00005         
00006         purpose:        Implementation of Combobox 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/CEGUICombobox.h"
00027 #include "elements/CEGUIEditbox.h"
00028 #include "elements/CEGUIPushButton.h"
00029 #include "elements/CEGUIComboDropList.h"
00030 #include "elements/CEGUIListboxItem.h"
00031 
00032 
00033 /*************************************************************************
00034         General information.
00035 
00036         The Combobox class is, for the most part, a huge proxy to the
00037         component Editbox and ComboDropList (Listbox) widgets.  The Combobox
00038         widget itself actually does very little.
00039 *************************************************************************/
00040 
00041 // Start of CEGUI namespace section
00042 namespace CEGUI
00043 {
00044 const String Combobox::EventNamespace("Combobox");
00045 
00046 /*************************************************************************
00047         Definitions for Properties for this class
00048 *************************************************************************/
00049 ComboboxProperties::ReadOnly                                    Combobox::d_readOnlyProperty;
00050 ComboboxProperties::ValidationString                    Combobox::d_validationStringProperty;
00051 ComboboxProperties::CaratIndex                                  Combobox::d_caratIndexProperty;
00052 ComboboxProperties::EditSelectionStart                  Combobox::d_selStartProperty;
00053 ComboboxProperties::EditSelectionLength                 Combobox::d_selLengthProperty;
00054 ComboboxProperties::MaxEditTextLength                   Combobox::d_maxTextLengthProperty;
00055 ComboboxProperties::NormalEditTextColour                Combobox::d_normalTextColourProperty;
00056 ComboboxProperties::SelectedEditTextColour              Combobox::d_selectedTextColourProperty;
00057 ComboboxProperties::ActiveEditSelectionColour   Combobox::d_activeSelectionColourProperty;
00058 ComboboxProperties::InactiveEditSelectionColour Combobox::d_inactiveSelectionColourProperty;
00059 ComboboxProperties::SortList                                    Combobox::d_sortProperty;
00060 ComboboxProperties::ForceVertScrollbar                  Combobox::d_forceVertProperty;
00061 ComboboxProperties::ForceHorzScrollbar                  Combobox::d_forceHorzProperty;
00062 ComboboxProperties::SingleClickMode                             Combobox::d_singleClickOperationProperty;
00063 
00064 
00065 /*************************************************************************
00066         Constants
00067 *************************************************************************/
00068 // event names from edit box
00069 const String Combobox::EventReadOnlyModeChanged( (utf8*)"ReadOnlyChanged" );
00070 const String Combobox::EventValidationStringChanged( (utf8*)"ValidationStringChanged" );
00071 const String Combobox::EventMaximumTextLengthChanged( (utf8*)"MaximumTextLengthChanged" );
00072 const String Combobox::EventTextInvalidated( (utf8*)"TextInvalidatedEvent" );
00073 const String Combobox::EventInvalidEntryAttempted( (utf8*)"InvalidEntryAttempted" );
00074 const String Combobox::EventCaratMoved( (utf8*)"CaratMoved" );
00075 const String Combobox::EventTextSelectionChanged( (utf8*)"TextSelectionChanged" );
00076 const String Combobox::EventEditboxFull( (utf8*)"EditboxFullEvent" );
00077 const String Combobox::EventTextAccepted( (utf8*)"TextAcceptedEvent" );
00078 
00079 // event names from list box
00080 const String Combobox::EventListContentsChanged( (utf8*)"ListContentsChanged" );
00081 const String Combobox::EventListSelectionChanged( (utf8*)"ListSelectionChanged" );
00082 const String Combobox::EventSortModeChanged( (utf8*)"SortModeChanged" );
00083 const String Combobox::EventVertScrollbarModeChanged( (utf8*)"VertScrollbarModeChanged" );
00084 const String Combobox::EventHorzScrollbarModeChanged( (utf8*)"HorzScrollbarModeChanged" );
00085 
00086 // events we produce / generate ourselves
00087 const String Combobox::EventDropListDisplayed( (utf8*)"DropListDisplayed" );
00088 const String Combobox::EventDropListRemoved( (utf8*)"DropListRemoved" );
00089 const String Combobox::EventListSelectionAccepted( (utf8*)"ListSelectionAccepted" );
00090 
00091         
00092 /*************************************************************************
00093         Constructor for Combobox base class
00094 *************************************************************************/
00095 Combobox::Combobox(const String& type, const String& name) :
00096         Window(type, name)
00097 {
00098         d_singleClickOperation = false;
00099 
00100         addComboboxEvents();
00101         addComboboxProperties();
00102 }
00103 
00104 
00105 /*************************************************************************
00106         Destructor for Combobox base class
00107 *************************************************************************/
00108 Combobox::~Combobox(void)
00109 {
00110 }
00111 
00112 
00113 /*************************************************************************
00114         Initialise the Window based object ready for use.
00115 *************************************************************************/
00116 void Combobox::initialise(void)
00117 {
00118         d_editbox       = createEditbox(getName() + "__auto_editbox__");
00119         d_droplist      = createDropList(getName() + "__auto_droplist__");
00120         d_button        = createPushButton(getName() + "__auto_button__");
00121     d_droplist->setFont(getFont());
00122     d_editbox->setFont(getFont());
00123 
00124         addChildWindow(d_editbox);
00125         addChildWindow(d_droplist);
00126         addChildWindow(d_button);
00127 
00128         // internal event wiring
00129         d_button->subscribeEvent(PushButton::EventMouseButtonDown, Event::Subscriber(&CEGUI::Combobox::button_PressHandler, this));
00130         d_droplist->subscribeEvent(ComboDropList::EventListSelectionAccepted, Event::Subscriber(&CEGUI::Combobox::droplist_SelectionAcceptedHandler, this));
00131         d_droplist->subscribeEvent(Window::EventHidden, Event::Subscriber(&CEGUI::Combobox::droplist_HiddenHandler, this));
00132         d_editbox->subscribeEvent(Window::EventMouseButtonDown, Event::Subscriber(&CEGUI::Combobox::editbox_MouseDownHandler, this));
00133 
00134         // event forwarding setup
00135         d_editbox->subscribeEvent(Editbox::EventReadOnlyModeChanged, Event::Subscriber(&CEGUI::Combobox::editbox_ReadOnlyChangedHandler, this));
00136         d_editbox->subscribeEvent(Editbox::EventValidationStringChanged, Event::Subscriber(&CEGUI::Combobox::editbox_ValidationStringChangedHandler, this));
00137         d_editbox->subscribeEvent(Editbox::EventMaximumTextLengthChanged, Event::Subscriber(&CEGUI::Combobox::editbox_MaximumTextLengthChangedHandler, this));
00138         d_editbox->subscribeEvent(Editbox::EventTextInvalidated, Event::Subscriber(&CEGUI::Combobox::editbox_TextInvalidatedEventHandler, this));
00139         d_editbox->subscribeEvent(Editbox::EventInvalidEntryAttempted, Event::Subscriber(&CEGUI::Combobox::editbox_InvalidEntryAttemptedHandler, this));
00140         d_editbox->subscribeEvent(Editbox::EventCaratMoved, Event::Subscriber(&CEGUI::Combobox::editbox_CaratMovedHandler, this));
00141         d_editbox->subscribeEvent(Editbox::EventTextSelectionChanged, Event::Subscriber(&CEGUI::Combobox::editbox_TextSelectionChangedHandler, this));
00142         d_editbox->subscribeEvent(Editbox::EventEditboxFull, Event::Subscriber(&CEGUI::Combobox::editbox_EditboxFullEventHandler, this));
00143         d_editbox->subscribeEvent(Editbox::EventTextAccepted, Event::Subscriber(&CEGUI::Combobox::editbox_TextAcceptedEventHandler, this));
00144         d_editbox->subscribeEvent(Editbox::EventTextChanged, Event::Subscriber(&CEGUI::Combobox::editbox_TextChangedEventHandler, this));
00145         d_droplist->subscribeEvent(Listbox::EventListContentsChanged, Event::Subscriber(&CEGUI::Combobox::listbox_ListContentsChangedHandler, this));
00146         d_droplist->subscribeEvent(Listbox::EventSelectionChanged, Event::Subscriber(&CEGUI::Combobox::listbox_ListSelectionChangedHandler, this));
00147         d_droplist->subscribeEvent(Listbox::EventSortModeChanged, Event::Subscriber(&CEGUI::Combobox::listbox_SortModeChangedHandler, this));
00148         d_droplist->subscribeEvent(Listbox::EventVertScrollbarModeChanged, Event::Subscriber(&CEGUI::Combobox::listbox_VertScrollModeChangedHandler, this));
00149         d_droplist->subscribeEvent(Listbox::EventHorzScrollbarModeChanged, Event::Subscriber(&CEGUI::Combobox::listbox_HorzScrollModeChangedHandler, this));
00150 
00151         // put components in their initial positions
00152         performChildWindowLayout();
00153 }
00154 
00155 
00156 /*************************************************************************
00157         Show the drop-down list
00158 *************************************************************************/
00159 void Combobox::showDropList(void)
00160 {
00161         // Display the box
00162         d_droplist->show();
00163         d_droplist->activate();
00164         d_droplist->captureInput();
00165 
00166         // Fire off event
00167         WindowEventArgs args(this);
00168         onDropListDisplayed(args);
00169 }
00170 
00171 
00172 /*************************************************************************
00173         Hide the drop-down list
00174 *************************************************************************/
00175 void Combobox::hideDropList(void)
00176 {
00177         // the natural order of things when this happens will ensure the list is
00178         // hidden and events are fired.
00179         d_droplist->releaseInput();
00180 }
00181 
00182 
00183 /*************************************************************************
00184         return true if the Editbox has input focus.
00185 *************************************************************************/
00186 bool Combobox::hasInputFocus(void) const
00187 {
00188         return d_editbox->hasInputFocus();
00189 }
00190 
00191 
00192 /*************************************************************************
00193         return true if the Editbox is read-only.
00194 *************************************************************************/
00195 bool Combobox::isReadOnly(void) const
00196 {
00197         return d_editbox->isReadOnly();
00198 }
00199 
00200 
00201 /*************************************************************************
00202         return true if the Editbox text is valid given the currently set
00203         validation string.
00204 *************************************************************************/
00205 bool Combobox::isTextValid(void) const
00206 {
00207         return d_editbox->isTextValid();
00208 }
00209 
00210 
00211 /*************************************************************************
00212         return the currently set validation string
00213 *************************************************************************/
00214 const String& Combobox::getValidationString(void) const
00215 {
00216         return d_editbox->getValidationString();
00217 }
00218 
00219 
00220 /*************************************************************************
00221         return the current position of the carat.
00222 *************************************************************************/
00223 size_t Combobox::getCaratIndex(void) const
00224 {
00225         return d_editbox->getCaratIndex();
00226 }
00227 
00228 
00229 /*************************************************************************
00230         return the current selection start point.
00231 *************************************************************************/
00232 size_t Combobox::getSelectionStartIndex(void) const
00233 {
00234         return d_editbox->getSelectionStartIndex();
00235 }
00236 
00237 
00238 /*************************************************************************
00239         return the current selection end point.
00240 *************************************************************************/
00241 size_t Combobox::getSelectionEndIndex(void) const
00242 {
00243         return d_editbox->getSelectionEndIndex();
00244 }
00245 
00246 
00247 /*************************************************************************
00248         return the length of the current selection (in code points / characters).
00249 *************************************************************************/
00250 size_t Combobox::getSelectionLength(void) const
00251 {
00252         return d_editbox->getSelectionLength();
00253 }
00254 
00255 
00256 /*************************************************************************
00257         return the maximum text length set for this Editbox.
00258 *************************************************************************/
00259 size_t Combobox::getMaxTextLength(void) const
00260 {
00261         return d_editbox->getMaxTextLength();
00262 }
00263 
00264 
00265 /*************************************************************************
00266         return the currently set colour to be used for rendering Editbox text
00267         in the normal, unselected state.
00268 *************************************************************************/
00269 colour Combobox::getNormalTextColour(void) const        
00270 {
00271         return d_editbox->getNormalTextColour();
00272 }
00273 
00274 
00275 /*************************************************************************
00276         return the currently set colour to be used for rendering the Editbox
00277         text when within the selected region.
00278 *************************************************************************/
00279 colour Combobox::getSelectedTextColour(void) const
00280 {
00281         return d_editbox->getSelectedTextColour();
00282 }
00283 
00284 
00285 /*************************************************************************
00286         return the currently set colour to be used for rendering the Editbox
00287         selection highlight when the Editbox is active.
00288 *************************************************************************/
00289 colour Combobox::getNormalSelectBrushColour(void) const
00290 {
00291         return d_editbox->getNormalSelectBrushColour();
00292 }
00293 
00294 
00295 /*************************************************************************
00296         return the currently set colour to be used for rendering the Editbox
00297         selection highlight when the Editbox is inactive.
00298 *************************************************************************/
00299 colour Combobox::getInactiveSelectBrushColour(void) const
00300 {
00301         return d_editbox->getInactiveSelectBrushColour();
00302 }
00303 
00304 
00305 /*************************************************************************
00306         Specify whether the Editbox is read-only.
00307 *************************************************************************/
00308 void Combobox::setReadOnly(bool setting)
00309 {
00310         d_editbox->setReadOnly(setting);
00311 }
00312 
00313 
00314 /*************************************************************************
00315         Set the text validation string.
00316 *************************************************************************/
00317 void Combobox::setValidationString(const String& validation_string)
00318 {
00319         d_editbox->setValidationString(validation_string);
00320 }
00321 
00322 
00323 /*************************************************************************
00324         Set the current position of the carat.
00325 *************************************************************************/
00326 void Combobox::setCaratIndex(size_t carat_pos)
00327 {
00328         d_editbox->setCaratIndex(carat_pos);
00329 }
00330 
00331 
00332 /*************************************************************************
00333         Define the current selection for the Editbox
00334 *************************************************************************/
00335 void Combobox::setSelection(size_t start_pos, size_t end_pos)
00336 {
00337         d_editbox->setSelection(start_pos, end_pos);
00338 }
00339 
00340 
00341 /*************************************************************************
00342         set the maximum text length for this Editbox.
00343 *************************************************************************/
00344 void Combobox::setMaxTextLength(size_t max_len)
00345 {
00346         d_editbox->setMaxTextLength(max_len);
00347 }
00348 
00349 
00350 /*************************************************************************
00351         Set the colour to be used for rendering Editbox text in the normal,
00352         unselected state.
00353 *************************************************************************/
00354 void Combobox::setNormalTextColour(colour col)
00355 {
00356         d_editbox->setNormalTextColour(col);
00357 }
00358 
00359 
00360 /*************************************************************************
00361         Set the colour to be used for rendering the Editbox text when within
00362         the selected region.    
00363 *************************************************************************/
00364 void Combobox::setSelectedTextColour(colour col)
00365 {
00366         d_editbox->setSelectedTextColour(col);
00367 }
00368 
00369 
00370 /*************************************************************************
00371         Set the colour to be used for rendering the Editbox selection
00372         highlight when the Editbox is active.
00373 *************************************************************************/
00374 void Combobox::setNormalSelectBrushColour(colour col)
00375 {
00376         d_editbox->setNormalSelectBrushColour(col);
00377 }
00378 
00379 
00380 /*************************************************************************
00381         Set the colour to be used for rendering the Editbox selection
00382         highlight when the Editbox is inactive.
00383 *************************************************************************/
00384 void Combobox::setInactiveSelectBrushColour(colour col)
00385 {
00386         d_editbox->setInactiveSelectBrushColour(col);
00387 }
00388 
00389 
00390 /*************************************************************************
00391         Return number of items attached to the list box 
00392 *************************************************************************/
00393 size_t Combobox::getItemCount(void) const
00394 {
00395         return d_droplist->getItemCount();
00396 }
00397 
00398 
00399 /*************************************************************************
00400         Return a pointer to the currently selected item.        
00401 *************************************************************************/
00402 ListboxItem* Combobox::getSelectedItem(void) const
00403 {
00404         return d_droplist->getFirstSelectedItem();
00405 }
00406 
00407 
00408 /*************************************************************************
00409         Return the item at index position \a index.
00410 *************************************************************************/
00411 ListboxItem* Combobox::getListboxItemFromIndex(size_t index) const
00412 {
00413         return d_droplist->getListboxItemFromIndex(index);
00414 }
00415 
00416 
00417 /*************************************************************************
00418         Return the index of ListboxItem 'item'
00419 *************************************************************************/
00420 size_t Combobox::getItemIndex(const ListboxItem* item) const
00421 {
00422         return d_droplist->getItemIndex(item);
00423 }
00424 
00425 
00426 /*************************************************************************
00427         return whether list sorting is enabled  
00428 *************************************************************************/
00429 bool Combobox::isSortEnabled(void) const
00430 {
00431         return d_droplist->isSortEnabled();
00432 }
00433 
00434 
00435 /*************************************************************************
00436         return whether the string at index position 'index' is selected 
00437 *************************************************************************/
00438 bool Combobox::isItemSelected(size_t index) const
00439 {
00440         return d_droplist->isItemSelected(index);
00441 }
00442 
00443 
00444 /*************************************************************************
00445         Search the list for an item with the specified text     
00446 *************************************************************************/
00447 ListboxItem* Combobox::findItemWithText(const String& text, const ListboxItem* start_item)
00448 {
00449         return d_droplist->findItemWithText(text, start_item);
00450 }
00451 
00452 
00453 /*************************************************************************
00454         Return whether the specified ListboxItem is in the List 
00455 *************************************************************************/
00456 bool Combobox::isListboxItemInList(const ListboxItem* item) const
00457 {
00458         return d_droplist->isListboxItemInList(item);
00459 }
00460 
00461 
00462 /*************************************************************************
00463         Remove all items from the list. 
00464 *************************************************************************/
00465 void Combobox::resetList(void)
00466 {
00467         d_droplist->resetList();
00468 }
00469 
00470 
00471 /*************************************************************************
00472         Add the given ListboxItem to the list.  
00473 *************************************************************************/
00474 void Combobox::addItem(ListboxItem* item)
00475 {
00476         d_droplist->addItem(item);
00477 }
00478 
00479 
00480 /*************************************************************************
00481         Insert an item into the list box after a specified item already in
00482         the list.       
00483 *************************************************************************/
00484 void Combobox::insertItem(ListboxItem* item, const ListboxItem* position)
00485 {
00486         d_droplist->insertItem(item, position);
00487 }
00488 
00489 
00490 /*************************************************************************
00491         Removes the given item from the list box.       
00492 *************************************************************************/
00493 void Combobox::removeItem(const ListboxItem* item)
00494 {
00495         d_droplist->removeItem(item);
00496 }
00497 
00498 
00499 /*************************************************************************
00500         Clear the selected state for all items. 
00501 *************************************************************************/
00502 void Combobox::clearAllSelections(void)
00503 {
00504         d_droplist->clearAllSelections();
00505 }
00506 
00507 
00508 /*************************************************************************
00509         Set whether the list should be sorted.  
00510 *************************************************************************/
00511 void Combobox::setSortingEnabled(bool setting)
00512 {
00513         d_droplist->setSortingEnabled(setting);
00514 }
00515 
00516 
00517 /*************************************************************************
00518         Set whether the vertical scroll bar should always be shown.     
00519 *************************************************************************/
00520 void Combobox::setShowVertScrollbar(bool setting)
00521 {
00522         d_droplist->setShowVertScrollbar(setting);
00523 }
00524 
00525 
00526 /*************************************************************************
00527         Set whether the horizontal scroll bar should always be shown.   
00528 *************************************************************************/
00529 void Combobox::setShowHorzScrollbar(bool setting)
00530 {
00531         d_droplist->setShowHorzScrollbar(setting);
00532 }
00533 
00534 
00535 /*************************************************************************
00536         Set the select state of an attached ListboxItem.        
00537 *************************************************************************/
00538 void Combobox::setItemSelectState(ListboxItem* item, bool state)
00539 {
00540         d_droplist->setItemSelectState(item, state);
00541 }
00542 
00543 
00544 /*************************************************************************
00545         Set the select state of an attached ListboxItem.        
00546 *************************************************************************/
00547 void Combobox::setItemSelectState(size_t item_index, bool state)
00548 {
00549         d_droplist->setItemSelectState(item_index, state);
00550 }
00551 
00552 
00553 /*************************************************************************
00554         Causes the list box to update it's internal state after changes have
00555         been made to one or more attached ListboxItem objects.
00556 *************************************************************************/
00557 void Combobox::handleUpdatedListItemData(void)
00558 {
00559         d_droplist->handleUpdatedItemData();
00560 }
00561 
00562 
00563 /*************************************************************************
00564         Add combo box specific events
00565 *************************************************************************/
00566 void Combobox::addComboboxEvents(void)
00567 {
00568         addEvent(EventReadOnlyModeChanged);                     addEvent(EventValidationStringChanged);
00569         addEvent(EventMaximumTextLengthChanged);        addEvent(EventTextInvalidated);
00570         addEvent(EventInvalidEntryAttempted);           addEvent(EventCaratMoved);
00571         addEvent(EventTextSelectionChanged);            addEvent(EventEditboxFull);
00572         addEvent(EventTextAccepted);                            addEvent(EventListContentsChanged);
00573         addEvent(EventListSelectionChanged);            addEvent(EventSortModeChanged);
00574         addEvent(EventVertScrollbarModeChanged);        addEvent(EventHorzScrollbarModeChanged);
00575         addEvent(EventDropListDisplayed);                       addEvent(EventDropListRemoved);
00576         addEvent(EventListSelectionAccepted);
00577 }
00578 
00579 
00580 /*************************************************************************
00581         Handler for when 
00582 *************************************************************************/
00583 void Combobox::onReadOnlyChanged(WindowEventArgs& e)
00584 {
00585         fireEvent(EventReadOnlyModeChanged, e, EventNamespace);
00586 }
00587 
00588 
00589 /*************************************************************************
00590         Handler for when 
00591 *************************************************************************/
00592 void Combobox::onValidationStringChanged(WindowEventArgs& e)
00593 {
00594         fireEvent(EventValidationStringChanged, e, EventNamespace);
00595 }
00596 
00597 
00598 /*************************************************************************
00599         Handler for when 
00600 *************************************************************************/
00601 void Combobox::onMaximumTextLengthChanged(WindowEventArgs& e)
00602 {
00603         fireEvent(EventMaximumTextLengthChanged, e, EventNamespace);
00604 }
00605 
00606 
00607 /*************************************************************************
00608         Handler for when 
00609 *************************************************************************/
00610 void Combobox::onTextInvalidatedEvent(WindowEventArgs& e)
00611 {
00612         fireEvent(EventTextInvalidated, e, EventNamespace);
00613 }
00614 
00615 
00616 /*************************************************************************
00617         Handler for when 
00618 *************************************************************************/
00619 void Combobox::onInvalidEntryAttempted(WindowEventArgs& e)
00620 {
00621         fireEvent(EventInvalidEntryAttempted, e, EventNamespace);
00622 }
00623 
00624 
00625 /*************************************************************************
00626         Handler for when 
00627 *************************************************************************/
00628 void Combobox::onCaratMoved(WindowEventArgs& e)
00629 {
00630         fireEvent(EventCaratMoved, e, EventNamespace);
00631 }
00632 
00633 
00634 /*************************************************************************
00635         Handler for when 
00636 *************************************************************************/
00637 void Combobox::onTextSelectionChanged(WindowEventArgs& e)
00638 {
00639         fireEvent(EventTextSelectionChanged, e, EventNamespace);
00640 }
00641 
00642 
00643 /*************************************************************************
00644         Handler for when 
00645 *************************************************************************/
00646 void Combobox::onEditboxFullEvent(WindowEventArgs& e)
00647 {
00648         fireEvent(EventEditboxFull, e, EventNamespace);
00649 }
00650 
00651 
00652 /*************************************************************************
00653         Handler for when 
00654 *************************************************************************/
00655 void Combobox::onTextAcceptedEvent(WindowEventArgs& e)
00656 {
00657         fireEvent(EventTextAccepted, e, EventNamespace);
00658 }
00659 
00660 
00661 /*************************************************************************
00662         Handler for when 
00663 *************************************************************************/
00664 void Combobox::onListContentsChanged(WindowEventArgs& e)
00665 {
00666         fireEvent(EventListContentsChanged, e, EventNamespace);
00667 }
00668 
00669 
00670 /*************************************************************************
00671         Handler for when 
00672 *************************************************************************/
00673 void Combobox::onListSelectionChanged(WindowEventArgs& e)
00674 {
00675         fireEvent(EventListSelectionChanged, e, EventNamespace);
00676 }
00677 
00678 
00679 /*************************************************************************
00680         Handler for when 
00681 *************************************************************************/
00682 void Combobox::onSortModeChanged(WindowEventArgs& e)
00683 {
00684         fireEvent(EventSortModeChanged, e, EventNamespace);
00685 }
00686 
00687 
00688 /*************************************************************************
00689         Handler for when 
00690 *************************************************************************/
00691 void Combobox::onVertScrollbarModeChanged(WindowEventArgs& e)
00692 {
00693         fireEvent(EventVertScrollbarModeChanged, e, EventNamespace);
00694 }
00695 
00696 
00697 /*************************************************************************
00698         Handler for when 
00699 *************************************************************************/
00700 void Combobox::onHorzScrollbarModeChanged(WindowEventArgs& e)
00701 {
00702         fireEvent(EventHorzScrollbarModeChanged, e, EventNamespace);
00703 }
00704 
00705 
00706 /*************************************************************************
00707         Handler for when 
00708 *************************************************************************/
00709 void Combobox::onDropListDisplayed(WindowEventArgs& e)
00710 {
00711         fireEvent(EventDropListDisplayed, e, EventNamespace);
00712 }
00713 
00714 
00715 /*************************************************************************
00716         Handler for when 
00717 *************************************************************************/
00718 void Combobox::onDroplistRemoved(WindowEventArgs& e)
00719 {
00720         fireEvent(EventDropListRemoved, e, EventNamespace);
00721 }
00722 
00723 
00724 /*************************************************************************
00725         Handler for when 
00726 *************************************************************************/
00727 void Combobox::onListSelectionAccepted(WindowEventArgs& e)
00728 {
00729         fireEvent(EventListSelectionAccepted, e, EventNamespace);
00730 }
00731 
00732 
00733 /*************************************************************************
00734         Handler for when widget font is changed
00735 *************************************************************************/
00736 void Combobox::onFontChanged(WindowEventArgs& e)
00737 {
00738     // Propagate to children
00739     d_editbox->setFont(getFont());
00740     d_droplist->setFont(getFont());
00741 
00742     // Call base class handler
00743     Window::onFontChanged(e);
00744 }
00745 
00746 
00747 /*************************************************************************
00748         Handler for when text changes
00749 *************************************************************************/
00750 void Combobox::onTextChanged(WindowEventArgs& e)
00751 {
00752         // update ourselves only if needed (prevents perpetual event loop & stack overflow)
00753         if (d_editbox->getText() != d_text)
00754         {
00755                 // done before doing base class processing so event subscribers see 'updated' version of this.
00756                 d_editbox->setText(d_text);
00757                 e.handled = true;
00758 
00759                 Window::onTextChanged(e);
00760         }
00761 
00762 }
00763 
00764 
00765 
00766 /*************************************************************************
00767         Handler function for button clicks.
00768 *************************************************************************/
00769 bool Combobox::button_PressHandler(const EventArgs& e)
00770 {
00771         showDropList();
00772 
00773         // if there is an item with the same text as the edit box, pre-select it
00774         ListboxItem* item = d_droplist->findItemWithText(d_editbox->getText(), NULL);
00775 
00776         if (item != NULL)
00777         {
00778                 d_droplist->setItemSelectState(item, true);
00779                 d_droplist->ensureItemIsVisible(item);
00780         }
00781         // no matching item, so select nothing
00782         else
00783         {
00784                 d_droplist->clearAllSelections();
00785         }
00786 
00787         return true;
00788 }
00789 
00790 
00791 /*************************************************************************
00792         Handler for selections made in the drop-list
00793 *************************************************************************/
00794 bool Combobox::droplist_SelectionAcceptedHandler(const EventArgs& e)
00795 {
00796         // copy the text from the selected item into the edit box
00797         ListboxItem* item = ((ComboDropList*)((WindowEventArgs&)e).window)->getFirstSelectedItem();
00798 
00799         if (item != NULL)
00800         {
00801                 // Put the text from the list item into the edit box
00802                 d_editbox->setText(item->getText());
00803 
00804                 // select text if it's editable, and move carat to end
00805                 if (!isReadOnly())
00806                 {
00807                         d_editbox->setSelection(0, item->getText().length());
00808                         d_editbox->setCaratIndex(item->getText().length());
00809                 }
00810 
00811                 d_editbox->setCaratIndex(0);
00812 
00813                 // fire off an event of our own
00814                 WindowEventArgs args(this);
00815                 onListSelectionAccepted(args);
00816 
00817                 // finally, activate the edit box
00818                 d_editbox->activate();
00819         }
00820 
00821         return true;
00822 }
00823 
00824 
00825 /*************************************************************************
00826         Handler for when drop-list hides itself
00827 *************************************************************************/
00828 bool Combobox::droplist_HiddenHandler(const EventArgs& e)
00829 {
00830         WindowEventArgs args(this);
00831         onDroplistRemoved(args);
00832 
00833         return true;
00834 }
00835 
00836 
00837 /*************************************************************************
00838         Handler for mouse button down events in editbox 
00839 *************************************************************************/
00840 bool Combobox::editbox_MouseDownHandler(const EventArgs& e)
00841 {
00842         // only interested in left button
00843         if (((const MouseEventArgs&)e).button == LeftButton)
00844         {
00845                 // if edit box is read-only, show list
00846                 if (d_editbox->isReadOnly())
00847                 {
00848                         showDropList();
00849 
00850                         // if there is an item with the same text as the edit box, pre-select it
00851                         ListboxItem* item = d_droplist->findItemWithText(d_editbox->getText(), NULL);
00852 
00853                         if (item != NULL)
00854                         {
00855                                 d_droplist->setItemSelectState(item, true);
00856                                 d_droplist->ensureItemIsVisible(item);
00857                         }
00858                         // no matching item, so select nothing
00859                         else
00860                         {
00861                                 d_droplist->clearAllSelections();
00862                         }
00863 
00864                         return true;
00865                 }
00866         }
00867 
00868         return false;
00869 }
00870 
00871 
00872 /*************************************************************************
00873         Return whether the vertical scroll bar is always shown. 
00874 *************************************************************************/
00875 bool Combobox::isVertScrollbarAlwaysShown(void) const
00876 {
00877         return d_droplist->isVertScrollbarAlwaysShown();
00878 }
00879 
00880 
00881 /*************************************************************************
00882         Return whether the horizontal scroll bar is always shown.       
00883 *************************************************************************/
00884 bool Combobox::isHorzScrollbarAlwaysShown(void) const
00885 {
00886         return d_droplist->isHorzScrollbarAlwaysShown();
00887 }
00888 
00889 
00890 /*************************************************************************
00891         Add properties for this class
00892 *************************************************************************/
00893 void Combobox::addComboboxProperties(void)
00894 {
00895         addProperty(&d_sortProperty);
00896         addProperty(&d_forceHorzProperty);
00897         addProperty(&d_forceVertProperty);
00898         addProperty(&d_readOnlyProperty);
00899         addProperty(&d_validationStringProperty);
00900         addProperty(&d_maxTextLengthProperty);
00901         addProperty(&d_selStartProperty);
00902         addProperty(&d_selLengthProperty);
00903         addProperty(&d_normalTextColourProperty);
00904         addProperty(&d_selectedTextColourProperty);
00905         addProperty(&d_activeSelectionColourProperty);
00906         addProperty(&d_inactiveSelectionColourProperty);
00907         addProperty(&d_caratIndexProperty);
00908         addProperty(&d_singleClickOperationProperty);
00909 }
00910 
00911 
00912 /*************************************************************************
00913         Activate the edit box component of the Combobox.
00914 *************************************************************************/
00915 void Combobox::activateEditbox(void)
00916 {
00917         if (!d_editbox->isActive())
00918         {
00919                 d_editbox->activate();
00920         }
00921 }
00922 
00923 
00924 
00925 /*************************************************************************
00926         Widget activation handler
00927 *************************************************************************/
00928 void Combobox::onActivated(ActivationEventArgs& e)
00929 {
00930         if (!isActive())
00931         {
00932                 Window::onActivated(e);
00933                 activateEditbox();
00934         }
00935 
00936 }
00937 
00938 
00939 /*************************************************************************
00940         Return operation mode for the combo box
00941 *************************************************************************/
00942 bool Combobox::getSingleClickEnabled(void) const
00943 {
00944         return d_singleClickOperation;
00945 }
00946 
00947 
00948 /*************************************************************************
00949         Return whether drop-list is visible.
00950 *************************************************************************/
00951 bool Combobox::isDropDownListVisible(void) const
00952 {
00953         return d_droplist->isVisible();
00954 }
00955 
00956 
00957 /*************************************************************************
00958         Set the operation mode for the combo box.
00959 *************************************************************************/
00960 void Combobox::setSingleClickEnabled(bool setting)
00961 {
00962         d_singleClickOperation = setting;
00963         d_droplist->setAutoArmEnabled(setting);
00964 }
00965 
00966 
00968 /*************************************************************************
00969         Handlers to relay child widget events so they appear to come from us
00970 *************************************************************************/
00972 bool Combobox::editbox_ReadOnlyChangedHandler(const EventArgs& e)
00973 {
00974         WindowEventArgs args(this);
00975         onReadOnlyChanged(args);
00976 
00977         return true;
00978 }
00979 
00980 
00981 bool Combobox::editbox_ValidationStringChangedHandler(const EventArgs& e)
00982 {
00983         WindowEventArgs args(this);
00984         onValidationStringChanged(args);
00985 
00986         return true;
00987 }
00988 
00989 
00990 bool Combobox::editbox_MaximumTextLengthChangedHandler(const EventArgs& e)
00991 {
00992         WindowEventArgs args(this);
00993         onMaximumTextLengthChanged(args);
00994 
00995         return true;
00996 }
00997 
00998 
00999 bool Combobox::editbox_TextInvalidatedEventHandler(const EventArgs& e)
01000 {
01001         WindowEventArgs args(this);
01002         onTextInvalidatedEvent(args);
01003 
01004         return true;
01005 }
01006 
01007 
01008 bool Combobox::editbox_InvalidEntryAttemptedHandler(const EventArgs& e)
01009 {
01010         WindowEventArgs args(this);
01011         onInvalidEntryAttempted(args);
01012 
01013         return true;
01014 }
01015 
01016 
01017 bool Combobox::editbox_CaratMovedHandler(const EventArgs& e)
01018 {
01019         WindowEventArgs args(this);
01020         onCaratMoved(args);
01021 
01022         return true;
01023 }
01024 
01025 
01026 bool Combobox::editbox_TextSelectionChangedHandler(const EventArgs& e)
01027 {
01028         WindowEventArgs args(this);
01029         onTextSelectionChanged(args);
01030 
01031         return true;
01032 }
01033 
01034 
01035 bool Combobox::editbox_EditboxFullEventHandler(const EventArgs& e)
01036 {
01037         WindowEventArgs args(this);
01038         onEditboxFullEvent(args);
01039 
01040         return true;
01041 }
01042 
01043 
01044 bool Combobox::editbox_TextAcceptedEventHandler(const EventArgs& e)
01045 {
01046         WindowEventArgs args(this);
01047         onTextAcceptedEvent(args);
01048 
01049         return true;
01050 }
01051 
01052 
01053 bool Combobox::editbox_TextChangedEventHandler(const EventArgs& e)
01054 {
01055         // set this windows text to match
01056         setText(((const WindowEventArgs&)e).window->getText());
01057 
01058         return true;
01059 }
01060 
01061 
01062 bool Combobox::listbox_ListContentsChangedHandler(const EventArgs& e)
01063 {
01064         WindowEventArgs args(this);
01065         onListContentsChanged(args);
01066 
01067         return true;
01068 }
01069 
01070 
01071 bool Combobox::listbox_ListSelectionChangedHandler(const EventArgs& e)
01072 {
01073         WindowEventArgs args(this);
01074         onListSelectionChanged(args);
01075 
01076         return true;
01077 }
01078 
01079 
01080 bool Combobox::listbox_SortModeChangedHandler(const EventArgs& e)
01081 {
01082         WindowEventArgs args(this);
01083         onSortModeChanged(args);
01084 
01085         return true;
01086 }
01087 
01088 
01089 bool Combobox::listbox_VertScrollModeChangedHandler(const EventArgs& e)
01090 {
01091         WindowEventArgs args(this);
01092         onVertScrollbarModeChanged(args);
01093 
01094         return true;
01095 }
01096 
01097 
01098 bool Combobox::listbox_HorzScrollModeChangedHandler(const EventArgs& e)
01099 {
01100         WindowEventArgs args(this);
01101         onHorzScrollbarModeChanged(args);
01102 
01103         return true;
01104 }
01105 
01106 } // End of  CEGUI namespace section

Generated on Wed Sep 7 09:56:30 2005 for Crazy Eddies GUI System by  doxygen 1.4.3