Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

CSCombobox Class Reference

#include <CSCombobox.h>

Inheritance diagram for CSCombobox:

CSGrafikElement CSMessageDispatchable CSMessageListener

Public Member Functions

 CSCombobox (int witdh)
virtual ~CSCombobox ()
virtual std::string getType ()
void reactOnMessageCombobox (CSMessage *message)
virtual void reactOnMessage (CSMessage *message)
 to be overloaded

virtual void paint (SDL_Surface *destination, SDL_Rect *parentViewport)
virtual void putString (SDL_Surface *destination, SDL_Rect *parentViewport, int x1, int y1, const std::string &string)
 coordinates relativ to this element

virtual void setItems (const CSStringlist &list)
virtual CSStringlist getItems ()
virtual std::string getSelectedString ()
virtual void setEditable (bool e)
virtual void * getSelectedObject ()
virtual void setSelected (const std::string &text)
virtual void setSelected (int i)
virtual void layoutSetup ()

Static Public Attributes

const char * CLASS = "CSCombobox"
 static element, name of this class (introsepection)


Protected Member Functions

void layoutSetupCombobox ()
void rebuildElement ()

Protected Attributes

GuiMessage MESSAGE_COMBOBOX_ITEM_SELECTED

Constructor & Destructor Documentation

CSCombobox::CSCombobox int  witdh  ) 
 

Definition at line 13 of file CSCombobox.cpp.

References CSGrafikElement::init(), LOG_ENTER, and LOG_EXIT.

00013                                 : CSGrafikElement(0, width)
00014 {
00015     static char *functionName="CSCombobox";
00016     LOG_ENTER 
00017     init("");
00018     LOG_EXIT
00019 }

Here is the call graph for this function:

CSCombobox::~CSCombobox  )  [virtual]
 

Definition at line 21 of file CSCombobox.cpp.

00022 {
00023 }


Member Function Documentation

void CSCombobox::layoutSetupCombobox  )  [protected]
 

Definition at line 353 of file CSCombobox.cpp.

References CSGrafikElement::getBorder(), CSLAF::getCurrentLAF(), CSGrafikElement::getFont(), CSGrafikElement::getHeight(), CSFont::getHeight(), CSBorder::getTotalHeight(), CSInset::getTotalHeight(), CSInset::getTotalWidth(), and CSBorder::getTotalWidth().

Referenced by layoutSetup().

00354 {
00355     static char *functionName="layoutSetupCombobox";
00356     CSLAF *laf = CSLAF::getCurrentLAF();
00357     mComboBoxInset = CSInset(2);
00358 
00359     mTextOffset = 0; 
00360     mHeight = getFont()->getHeight() + mComboBoxInset.getTotalHeight();
00361     if (mHeight < mMore->getHeight())
00362     {
00363         mHeight = mMore->getHeight();
00364         mTextOffset = (mMore->getHeight() - mHeight)/2;
00365     }
00366     mMinHeight = mHeight;
00367     mHeight += getBorder()->getTotalHeight() + mInset.getTotalHeight();
00368     mMinWidth = mWidth - getBorder()->getTotalWidth() + mInset.getTotalWidth();;
00369 }

Here is the call graph for this function:

void CSCombobox::rebuildElement  )  [protected, virtual]
 

Reimplemented from CSGrafikElement.

Definition at line 316 of file CSCombobox.cpp.

References CSGrafikElement::addElement(), CSMessageDispatchable::addMessageListener(), COMBOBOX_BUTTON_MORE_ACTION_ID, CSLAF::getComboboxItemsShown(), CSLAF::getCurrentLAF(), CSLAF::getIcon(), CSGrafikElement::getLayoutData(), GUI_MESSAGE, LAF_ICON_TYPE_DOWN, POSITION_EAST, CSGrafikElement::removeElement(), CSMessageDispatchable::removeMessageListener(), CSGrafikElement::setActionId(), CSLayoutData::setCenteredHorizontal(), CSGrafikElement::setFocusable(), CSListbox::setHoverSelection(), CSListbox::setItemsShown(), CSGrafikElement::setLayoutData(), CSLayoutData::setSpacing(), and CSGrafikElement::setVisible().

00317 {
00318     static char *functionName="rebuildElement";
00319     CSLAF *laf = CSLAF::getCurrentLAF();
00320     if (mMore)
00321     {
00322         mMore->removeMessageListener(this);
00323         removeElement(mMore);
00324         delete (mMore);
00325         mMore = 0;
00326     }
00327 
00328     mMore = new CSButton(laf->getIcon(LAF_ICON_TYPE_DOWN));
00329 
00330     CSLayoutData layoutData = mMore->getLayoutData();
00331     layoutData.setSpacing(0,0);
00332     layoutData.setCenteredHorizontal(false);
00333     mMore->setLayoutData(layoutData);
00334     mMore->setActionId(COMBOBOX_BUTTON_MORE_ACTION_ID);
00335     mMore->addMessageListener(this, GUI_MESSAGE);
00336     addElement(mMore, POSITION_EAST);
00337 
00338     if (mListbox)
00339     {
00340         mListbox->removeMessageListener(this);
00341         removeElement(mListbox);
00342         delete (mListbox);
00343         mListbox = 0;
00344     }
00345     mListbox = new CSListbox(laf->getComboboxItemsShown(), mWidth);
00346     mListbox->setFocusable(false);
00347     mListbox->addMessageListener(this, GUI_MESSAGE);
00348     mListbox->setItemsShown(laf->getComboboxItemsShown());
00349     mListbox->setVisible(false);
00350     mListbox->setHoverSelection(true);
00351 }

Here is the call graph for this function:

virtual std::string CSCombobox::getType  )  [inline, virtual]
 

Reimplemented from CSGrafikElement.

Definition at line 56 of file CSCombobox.h.

References CLASS.

00056 {return (std::string) CLASS;}

void CSCombobox::reactOnMessageCombobox CSMessage message  ) 
 

Definition at line 155 of file CSCombobox.cpp.

References GuiMessage::actionId, BUTTON_PRESSED_MESSAGE, COMBOBOX_BUTTON_MORE_ACTION_ID, FOCUS_GAINED_MESSAGE, FOCUS_LOST_MESSAGE, CSDesktop::focusedNextComponent(), CSGrafikElement::getBorder(), CSGrafikElement::getDesktop(), CSGrafikElement::getEnabled(), CSGrafikElement::getFont(), getSelectedString(), CSBorder::getSizeWest(), CSMessage::getSubtype(), CSMessage::getType(), CSGrafikElement::getWidth(), CSFont::getWidth(), GUI_MESSAGE, KEY_PRESSED_MESSAGE, GuiMessage::keySymbolic, GuiMessage::keyUnicodeChar, LIST_ITEM_SELECTED_MESSAGE, MESSAGE_COMBOBOX_ITEM_SELECTED, CSMessage::mIsHandled, MOUSE_BUTTON_PRESSED_MESSAGE, CSGrafikElement::reactOnMessageGrafikElement(), GuiMessage::receiver, GuiMessage::selected, CSMessageDispatchable::sendMessage(), CSGrafikElement::setEnabled(), and CSDesktop::setFocusedComponent().

Referenced by reactOnMessage().

00156 {
00157     static char *functionName="reactOnMessage";
00158     if (message->mIsHandled)
00159     {
00160         reactOnMessageGrafikElement(message);
00161         return;
00162     }
00163     
00164     if (message->getType() == GUI_MESSAGE)
00165     {
00166         GuiMessage *gm = (GuiMessage *) message;
00167         if (gm->receiver != this)
00168         {
00169             if (gm->getSubtype() == BUTTON_PRESSED_MESSAGE)
00170             {
00171                 if (gm->actionId == COMBOBOX_BUTTON_MORE_ACTION_ID)
00172                 {
00173                     setListActive(!mListboxActive);
00174                 }
00175                 else
00176                 {
00177                     setListActive(false);
00178                 }
00179                 gm->mIsHandled = true;
00180             }
00181 
00182             if (gm->getSubtype() == LIST_ITEM_SELECTED_MESSAGE)
00183             {
00184                 setListActive(true);
00185                 setListActive(false);
00186                 getDesktop()->setFocusedComponent(0);
00187                 mString = getSelectedString();
00188 
00189                 MESSAGE_COMBOBOX_ITEM_SELECTED.selected = gm->selected;
00190                 MESSAGE_COMBOBOX_ITEM_SELECTED.actionId = mActionId;
00191                 MESSAGE_COMBOBOX_ITEM_SELECTED.mIsHandled = false;
00192                 sendMessage(MESSAGE_COMBOBOX_ITEM_SELECTED);
00193                 gm->mIsHandled = true;
00194             }
00195             if (gm->getSubtype() == FOCUS_LOST_MESSAGE)
00196             {
00197                 if (getEnabled())
00198                 {
00199                     mString = mWorkingString;
00200                     setEnabled(false);
00201                 }
00202                 setListActive(false);
00203                 gm->mIsHandled = true;
00204             }
00205         }
00206         else // receiver == this
00207         {
00208             switch (message->getSubtype())
00209             {
00210                 case FOCUS_GAINED_MESSAGE:
00211                 {
00212                     if (mIsEditable)
00213                     {
00214                         mWorkingString = mString;
00215                         setEnabled(true);
00216                         setListActive(!mListboxActive);
00217                     }
00218                     gm->mIsHandled = true;
00219                     break;
00220                 }
00221                 
00222                 case FOCUS_LOST_MESSAGE:
00223                 {
00224                     if (getEnabled())
00225                     {
00226                         mString = mWorkingString;
00227                         setEnabled(false);
00228                     }
00229                     setListActive(false);
00230                     gm->mIsHandled = true;
00231                     break;
00232                 }
00233 
00234                 case MOUSE_BUTTON_PRESSED_MESSAGE:
00235                 {
00236                     setListActive(true);
00237                     gm->mIsHandled = true;
00238                     break;
00239                 }
00240 
00241                 case KEY_PRESSED_MESSAGE:
00242                 {
00243                     if (!getEnabled())
00244                     {
00245                         break;
00246                     }
00247                     int ch=gm->keyUnicodeChar;
00248 
00249                     if ((gm->keySymbolic == SDLK_RETURN) || 
00250                         (gm->keySymbolic == SDLK_KP_ENTER) || 
00251                         (gm->keySymbolic == SDLK_TAB))
00252                     {
00253                         getDesktop()->focusedNextComponent();
00254                         gm->mIsHandled = true;
00255                         break;
00256                     }
00257                     if (((ch>31)||(ch=='\b')) && (ch<128)) 
00258                     {
00259                         int len = mWorkingString.length();
00260                         if (ch=='\b')
00261                         {
00262                             if (len>0)
00263                             {
00264                                 mWorkingString.resize(len-1);
00265                             }
00266                         }
00267                         else
00268                         {
00269                             mWorkingString += (char) ch;
00270                             
00271                             len = mWorkingString.length();
00272                             int witdh = getFont()->getWidth(mWorkingString) + getFont()->getWidth("_");
00273                             if (witdh > getWidth() - (getBorder()->getSizeWest()))
00274                             {
00275                                 mWorkingString.resize(len-1);
00276                             }
00277                         }
00278                         gm->mIsHandled = true;
00279                     }
00280                     break;
00281                 }
00282             }
00283         }
00284     }
00285     reactOnMessageGrafikElement(message);
00286 }

Here is the call graph for this function:

void CSCombobox::reactOnMessage CSMessage message  )  [virtual]
 

to be overloaded

Reimplemented from CSGrafikElement.

Definition at line 150 of file CSCombobox.cpp.

References reactOnMessageCombobox().

00151 {
00152     reactOnMessageCombobox(message);
00153 }

Here is the call graph for this function:

void CSCombobox::paint SDL_Surface *  destination,
SDL_Rect *  parentViewport
[virtual]
 

Todo:
build a combobox from a textfield, a button and a listbos that is, remove custom textfield and reuse the common textfield!

Reimplemented from CSGrafikElement.

Definition at line 64 of file CSCombobox.cpp.

References SDLMain::adjustClipping(), CSGrafikElement::getBorder(), CSGrafikElement::getEnabled(), CSGrafikElement::getFocused(), CSGrafikElement::getFont(), CSGrafikElement::getInset(), CSInset::getSizeNorth(), CSBorder::getSizeNorth(), CSInset::getSizeWest(), CSBorder::getSizeWest(), CSGrafikElement::getViewportArea(), CSFont::getWidth(), CSGrafikElement::getX(), CSGrafikElement::getY(), CSGrafikElement::paintChildren(), and putString().

00065 {
00066     static char *functionName="paint";
00067     SDL_Rect rectSave;
00068     SDL_GetClipRect(destination, &rectSave);
00069 
00070     SDL_Rect rectClip = getViewportArea();
00071     rectClip.x += parentViewport->x + getX();
00072     rectClip.y += parentViewport->y + getY();
00073 
00074     SDLMain::adjustClipping(rectClip, rectSave);
00075     SDL_SetClipRect(destination, &rectClip);
00076 
00077     int xOffset = getBorder()->getSizeWest() + getInset().getSizeWest() + mComboBoxInset.getSizeWest();
00078     int yOffset = getBorder()->getSizeNorth() + getInset().getSizeNorth() + mComboBoxInset.getSizeNorth();
00079 
00080     if ((getFocused()) && (getEnabled()))
00081     {
00082         float currentTick = SDL_GetTicks() + mCursorRate;
00083         if (currentTick > mTickTimeNext)
00084         {
00085             mTickTimeNext = currentTick + mCursorRate;
00086             mCursorShown = !mCursorShown;
00087         }
00088         putString(destination, parentViewport, xOffset, yOffset + mTextOffset, mWorkingString);
00089         if (mCursorShown)
00090         {
00091             int witdh = getFont()->getWidth(mWorkingString);
00092             putString(destination, parentViewport, xOffset + witdh, yOffset + mTextOffset, "_");
00093         }
00094     }
00095     else
00096     {
00097         putString(destination, parentViewport, xOffset, yOffset + mTextOffset, mString);
00098     }
00099     SDL_SetClipRect(destination, &rectSave);
00100     paintChildren(destination, parentViewport);
00101 }

Here is the call graph for this function:

void CSCombobox::putString SDL_Surface *  destination,
SDL_Rect *  parentViewport,
int  x1,
int  y1,
const std::string &  string
[virtual]
 

coordinates relativ to this element

no clipping

Reimplemented from CSGrafikElement.

Definition at line 54 of file CSCombobox.cpp.

References CSGrafikElement::getFont(), CSGrafikElement::getTextColor(), CSGrafikElement::getX(), CSGrafikElement::getY(), and CSFont::putString().

Referenced by paint().

00055 {
00056     static char *functionName="putString";
00057     x1 += parentViewport->x + getX();
00058     y1 += parentViewport->y + getY();
00059     getFont()->putString(destination, x1, y1, getTextColor(), string);
00060 }

Here is the call graph for this function:

void CSCombobox::setItems const CSStringlist list  )  [virtual]
 

Definition at line 112 of file CSCombobox.cpp.

References CSListbox::setItems().

00113 {
00114     if (mListbox)
00115     {
00116         mListbox->setItems(list);
00117     }
00118 }

Here is the call graph for this function:

CSStringlist CSCombobox::getItems  )  [virtual]
 

Definition at line 103 of file CSCombobox.cpp.

References CSListbox::getItems().

00104 {
00105     if (!mListbox)
00106     {
00107         return CSStringlist();
00108     }
00109     return mListbox->getItems();
00110 }

Here is the call graph for this function:

std::string CSCombobox::getSelectedString  )  [virtual]
 

Definition at line 120 of file CSCombobox.cpp.

References CSListbox::getItems(), CSListbox::getSelected(), and CSStringlist::getString().

Referenced by reactOnMessageCombobox().

00121 {
00122     if (!mListbox)
00123     {
00124         return std::string();
00125     }
00126     
00127     return mListbox->getItems().getString(mListbox->getSelected());
00128 }

Here is the call graph for this function:

virtual void CSCombobox::setEditable bool  e  )  [inline, virtual]
 

Definition at line 66 of file CSCombobox.h.

00066 {mIsEditable = e;}

void * CSCombobox::getSelectedObject  )  [virtual]
 

Definition at line 131 of file CSCombobox.cpp.

References CSListbox::getItems(), CSStringlist::getObject(), and CSListbox::getSelected().

00132 {
00133     if (!mListbox)
00134     {
00135         return 0;
00136     }
00137     
00138     return mListbox->getItems().getObject(mListbox->getSelected());
00139 }

Here is the call graph for this function:

virtual void CSCombobox::setSelected const std::string &  text  )  [inline, virtual]
 

Definition at line 68 of file CSCombobox.h.

00068 {mString = text;}

void CSCombobox::setSelected int  i  )  [virtual]
 

Definition at line 141 of file CSCombobox.cpp.

References CSListbox::setSelected().

00142 {
00143     if (!mListbox)
00144     {
00145         return ;
00146     }
00147     mListbox->setSelected(i);
00148 }

Here is the call graph for this function:

virtual void CSCombobox::layoutSetup  )  [inline, virtual]
 

Reimplemented from CSGrafikElement.

Definition at line 70 of file CSCombobox.h.

References layoutSetupCombobox().

Here is the call graph for this function:


Field Documentation

GuiMessage CSCombobox::MESSAGE_COMBOBOX_ITEM_SELECTED [protected]
 

Definition at line 48 of file CSCombobox.h.

Referenced by reactOnMessageCombobox().

const char * CSCombobox::CLASS = "CSCombobox" [static]
 

static element, name of this class (introsepection)

Reimplemented from CSGrafikElement.

Definition at line 11 of file CSCombobox.cpp.

Referenced by CSLAF::getBackgroundColorDisabledInternal(), CSLAF::getBackgroundColorEnabledInternal(), CSLAF::getBorderInternal(), CSLAF::getTextColorDisabledInternal(), and getType().


Generated on Wed Jul 14 00:44:06 2004 for CSLib by doxygen 1.3.6