#include <gridcombo.h>
Inheritance diagram for wxGridComboPopup:
Public Types | |
enum | EDrawFlags { keSelected = 0x0001, keHighlight = 0x0002, keComboControl = 0x0004, keDisabled = 0x0008 } |
Public Member Functions | |
wxGridComboPopup (wxGridCombo *pCombo) | |
virtual void | Init () |
virtual bool | Create (wxWindow *pwndParent) |
virtual void | OnShow () |
virtual wxSize | GetAdjustedSize (int iMinWidth, int iPrefHeight, int iMaxHeight) |
virtual wxWindow * | GetControl () |
virtual void | DrawItem (wxDC &dc, const wxRect &rect, int iItem, int iFlags)=0 |
virtual void | PaintComboControl (wxDC &dc, const wxRect &rect) |
virtual void | SetSelected (int iItem) |
virtual int | GetSelected () const |
int | GetColumns () const |
int | GetRows () const |
int | GetItemsNum () const |
wxSize | GetItemSize () const |
virtual wxString | GetStringValue () const |
Protected Member Functions | |
virtual void | DrawItem (wxDC &dc, const wxRect &rect, int iCol, int iRow, bool bSelected) |
virtual void | UpdateScrollers () |
virtual void | UpdateColumnsNum () |
virtual void | ChangeSelection (int iOldSelected, int iNewSelected) |
virtual void | SendComboBoxEvent (int iSelection) |
wxRect | GetItemRect (int iItem) |
wxPoint | ItemToGrid (int iItem) |
int | ItemFromPoint (wxPoint ptClient) |
void | InvalidateItem (int iItem) |
void | ClientToScrolledVirtual (int *pX, int *pY) |
void | DismissWithEvent () |
virtual void | OnDraw (wxDC &dc) |
void | OnSize (wxSizeEvent &event) |
void | OnMouseMove (wxMouseEvent &event) |
void | OnKey (wxKeyEvent &event) |
void | OnLeftClick (wxMouseEvent &event) |
void | OnTimer (wxTimerEvent &event) |
Protected Attributes | |
wxGridCombo * | m_pCombo |
int | m_iHighlighed |
wxTimer | m_tmrHighlited |
Friends | |
class | wxGridCombo |
Definition at line 50 of file gridcombo.h.
|
Definition at line 55 of file gridcombo.h. 00056 { 00057 keSelected = 0x0001, // The item is selected. 00058 keHighlight = 0x0002, // The item is hovered. 00059 keComboControl = 0x0004, // The paint the item in the combo control itself. 00060 keDisabled = 0x0008 // The item is disabled. For now can be applied for the combo 00061 // control itself only. 00062 };
|
|
Definition at line 31 of file gridcombo.cpp. 00032 : m_tmrHighlited(this, HIGHLITED_TIMERID) 00033 { 00034 m_pCombo = pCombo; 00035 m_iHighlighed = -1; 00036 00037 }
|
|
Function : wxGridComboPopup::ChangeSelection Author : Mikhail Tatarnikov Purpose : Notification that the selection has been changed. Returns : void Exceptions: Parameters: [in] int iOldSelected - the prevoiusly selected item; [in] int iNewSelected - the newly selected item. Notes : Control has to repqint both items. Definition at line 174 of file gridcombo.cpp. 00175 { 00176 InvalidateItem(iOldSelected); 00177 InvalidateItem(iNewSelected); 00178 }
|
|
Function : wxGridComboPopup::ClientToScrolledVirtual Author : Mikhail Tatarnikov Purpose : Transfers a point from client to virtual (scrolled) coordinates Returns : void Exceptions: Parameters: [in/out] int* pX - the absciss value to convert; [in/out] int* pY - the ordinate value to convert. Notes : Definition at line 283 of file gridcombo.cpp. 00284 { 00285 wxSize szItem = GetItemSize(); 00286 int iXOrigin = 0; 00287 int iYOrigin = 0; 00288 GetViewStart(&iXOrigin, &iYOrigin); 00289 00290 if (pX) 00291 *pX += iXOrigin * szItem.x; 00292 00293 if (pY) 00294 *pY += iYOrigin * szItem.y; 00295 00296 }
|
|
Function : wxGridComboPopup::Create Author : Mikhail Tatarnikov Purpose : Creates the popup window Returns : bool - true if successfull, false otherwise. Exceptions: Parameters: [in] wxWindow* pwndParent - the parent window (combobox control). Notes : Implements wxComboPopup. Definition at line 153 of file gridcombo.cpp. 00154 { 00155 if (!wxScrolledWindow::Create(pwndParent, wxID_ANY, wxDefaultPosition, wxDefaultSize, 00156 wxBORDER_SIMPLE | wxLB_INT_HEIGHT | wxWANTS_CHARS | wxVSCROLL | wxHSCROLL)) 00157 return false; 00158 00159 SetAutoLayout(true); 00160 00161 return true; 00162 }
|
|
Function : wxGridComboPopup::DismissWithEvent Author : Mikhail Tatarnikov Purpose : Helper function to setup a new selection, close the popup and send a notification message. Returns : void Exceptions: Parameters: None Notes : Definition at line 448 of file gridcombo.cpp. 00449 { 00450 Dismiss(); 00451 00452 int iSelected = GetSelected(); 00453 SendComboBoxEvent(iSelected); 00454 }
|
|
Function : wxGridComboPopup::DrawItem Author : Mikhail Tatarnikov Purpose : Draws item based on row and column Returns : void Exceptions: Parameters: [in] wxDC& dc - device context to paint to; [in] wxRect& rcRect - the item position; [in] int iRow - element's row; [in] int iCol - element's column; [in] bool bSelected - indicate whether the item is selected or not. Notes : Calculates the item index and dispatch the call to descendants via DrawItem pure virtual function. Definition at line 641 of file gridcombo.cpp. 00642 { 00643 int iItem = iRow * GetColumns() + iCol; 00644 00645 int iFlags = 0; 00646 if (bSelected) 00647 iFlags |= keSelected; 00648 00649 DrawItem(dc, rcRect, iItem, iFlags); 00650 }
|
|
|
|
Function : wxGridComboPopup::GetAdjustedSize Author : Mikhail Tatarnikov Purpose : Calculates preferable size. Returns : wxSize - the final size requested. Exceptions: Parameters: [in] int iMinWidth - minimum width for the control. In some circumstances can be ignored; [in] int iPrefHeight - preferable height; [in] int iMaxHeight - maximum of height allowed. Notes : Reimplemented from wxComboPopup. Definition at line 496 of file gridcombo.cpp. 00497 { 00498 wxSize szAdjusted(0, 0); 00499 wxSize szItem = GetItemSize(); 00500 int iColumns = GetColumns(); 00501 int iRows = GetRows(); 00502 00503 szAdjusted.x = szItem.x * iColumns; 00504 00505 int iRowsFit = iPrefHeight / szItem.y + 1; 00506 00507 // Check if we fit the maximum height. 00508 int iHeight = iRowsFit * szItem.y; 00509 if (iHeight > iMaxHeight) 00510 iHeight = --iRowsFit * szItem.y; 00511 00512 // We must show at least one row. 00513 iRowsFit = std::max(iRowsFit, 1); 00514 00515 // No point in showing more rows than we have. 00516 iRowsFit = std::min(iRowsFit, iRows); 00517 00518 szAdjusted.y = iRowsFit * szItem.y; 00519 00520 // Check if a slider is required. 00521 if (iRowsFit < iRows) 00522 szAdjusted.x += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); 00523 00524 // Take into account the border. 00525 szAdjusted.x += 2; 00526 szAdjusted.y += 2; 00527 00528 00529 return szAdjusted; 00530 }
|
|
Function : wxGridComboPopup::GetColumns Author : Mikhail Tatarnikov Purpose : A helper function to obtain the number of columns specified by the user Returns : int - the number of columns to display in the popup. Exceptions: Parameters: None Notes : All the information is stored in one place - the combobox control itself. Definition at line 49 of file gridcombo.cpp. 00050 { 00051 return m_pCombo->GetColumns(); 00052 }
|
|
Implements wxComboPopup. Definition at line 73 of file gridcombo.h.
|
|
Function : wxGridComboPopup::GetItemRect Author : Mikhail Tatarnikov Purpose : Calculates the item area (in client virtual coordinates) Returns : wxRect - the area occupied by the item. Exceptions: Parameters: [in] int iItem - item to calculate the area for. Notes : Definition at line 259 of file gridcombo.cpp. 00260 { 00261 wxPoint ptGrid = ItemToGrid(iItem); 00262 wxSize szItem = GetItemSize(); 00263 00264 ptGrid.x *= szItem.x; 00265 ptGrid.y *= szItem.y; 00266 00267 wxRect rcItem(ptGrid, szItem); 00268 00269 return rcItem; 00270 }
|
|
Function : wxGridComboPopup::GetItemSize Author : Mikhail Tatarnikov Purpose : A helper function to obtain the size of items - e.g. the popup cell size. Returns : wxSize - the items size. Exceptions: Parameters: None Notes : All the information is stored in one place - the combobox control itself. All items have the same size. Definition at line 95 of file gridcombo.cpp. 00096 { 00097 return m_pCombo->GetItemSize(); 00098 }
|
|
Function : intwxGridComboPopup::GetItemsNum Author : Mikhail Tatarnikov Purpose : A helper function to obtain the number of items in the combobx. Returns : int - the number of items to display. Exceptions: Parameters: None Notes : All the information is stored in one place - the combobox control itself. Definition at line 79 of file gridcombo.cpp. 00080 { 00081 return m_pCombo->GetItemsNum(); 00082 }
|
|
Function : intwxGridComboPopup::GetRows Author : Mikhail Tatarnikov Purpose : A helper function to obtain the number of rows that should be displayd. Not all rows will be visible at once. Returns : int - the number of all rows (visible and invisible). Exceptions: Parameters: None Notes : All the required to calculate the rows coun is stored in one place - the combobox control itself. Definition at line 65 of file gridcombo.cpp.
|
|
Function : wxGridComboPopup::GetSelected Author : Mikhail Tatarnikov Purpose : Get the currentrly selected element. Returns : int - the index of currently selected element, -1 if none. Exceptions: Parameters: None Notes : Definition at line 109 of file gridcombo.cpp. 00110 { 00111 return m_pCombo->GetSelected(); 00112 }
|
|
Implements wxComboPopup. Definition at line 92 of file gridcombo.h.
|
|
Function : wxGridComboPopup::Init Author : Mikhail Tatarnikov Purpose : Performs any initialization required. Returns : void Exceptions: Parameters: None Notes : Reimplemented from wxComboPopup. Definition at line 139 of file gridcombo.cpp.
|
|
Function : wxGridComboPopup::InvalidateItem Author : Mikhail Tatarnikov Purpose : Requests repaint of an item. Returns : void Exceptions: Parameters: [in] int iItem - an item to repaint. Notes : Definition at line 541 of file gridcombo.cpp. 00542 { 00543 if (iItem == -1) 00544 return; 00545 00546 int iX = 0; 00547 int iY = 0; 00548 00549 wxRect rcItem = GetItemRect(iItem); 00550 00551 ClientToScrolledVirtual(&iX, &iY); 00552 rcItem.x -= iX; 00553 rcItem.y -= iY; 00554 00555 Refresh(false, &rcItem); 00556 }
|
|
Function : wxGridComboPopup::ItemFromPoint Author : Mikhail Tatarnikov Purpose : Finds item based on point (in client virtual coordinates) Returns : int - the item index which the point belong. Exceptions: Parameters: [in] wxPoint ptClient - the point to find item from. Notes : Definition at line 232 of file gridcombo.cpp. 00233 { 00234 // TODO: Optimise - calculate instead of brute force iterate. 00235 00236 int iItemsNum = GetItemsNum(); 00237 for (int i = 0; i < iItemsNum; ++i) 00238 { 00239 // Calculate the area of the current item. 00240 wxRect rcItem = GetItemRect(i); 00241 00242 // Check if the item should be updated. 00243 if (rcItem.Inside(ptClient)) 00244 return i; 00245 } 00246 00247 return -1; 00248 }
|
|
Function : wxGridComboPopup::ItemToGrid Author : Mikhail Tatarnikov Purpose : Calculates position of an item based on its index Returns : wxPoint - the item position (row/column). Exceptions: Parameters: [in] int iItem - item index to calculate positio for. Notes : Definition at line 213 of file gridcombo.cpp. 00214 { 00215 wxPoint ptGrid; 00216 int iCols = GetColumns(); 00217 ptGrid.x = iItem % iCols; 00218 ptGrid.y = iItem / iCols; 00219 00220 return ptGrid; 00221 }
|
|
Function : wxGridComboPopup::OnDraw Author : Mikhail Tatarnikov Purpose : The default implementation of drawing. Returns : void Exceptions: Parameters: [in] wxDC& dc - device context of the control to paint to. Notes : Breaks the control to separate items and sends a request for painting each item via DrawItem pure virtual function. Definition at line 569 of file gridcombo.cpp. 00570 { 00571 wxRect rcInvalid = GetUpdateClientRect(); 00572 ClientToScrolledVirtual(&(rcInvalid.x), &(rcInvalid.y)); 00573 00574 // Iterate over all items, simply figing out whether we 00575 // need to update it or not. 00576 // TODO: optimize - iterate over visible items only. 00577 int iItemsNum = GetColumns() * GetRows(); 00578 for (int i = 0; i < iItemsNum; ++i) 00579 { 00580 // Calculate the area of the current item. 00581 wxRect rcItem = GetItemRect(i); 00582 00583 // Check if the item should be updated. 00584 if (!rcItem.Intersects(rcInvalid)) 00585 continue; 00586 00587 // Check if the item is selected or highlighted. 00588 int iFlags = 0; 00589 if (i == GetSelected()) 00590 iFlags |= keSelected; 00591 00592 if (i == m_iHighlighed) 00593 iFlags |= keHighlight; 00594 00595 DrawItem(dc, rcItem, i, iFlags); 00596 00597 } 00598 }
|
|
Function : wxGridComboPopup::OnKey Author : Mikhail Tatarnikov Purpose : Keyboard notification handler. Returns : void Exceptions: Parameters: [in] wxKeyEvent& event - keyboard event information. Notes : Definition at line 410 of file gridcombo.cpp.
|
|
Function : wxGridComboPopup::OnLeftClick Author : Mikhail Tatarnikov Purpose : Left mouse button click handler Returns : void Exceptions: Parameters: [in] wxMouseEvent& event - mouse event information. Notes : Definition at line 424 of file gridcombo.cpp. 00425 { 00426 // Convert the poin to the logical coordinates. 00427 wxPoint ptMouse(event.GetX(), event.GetY()); 00428 ClientToScrolledVirtual(&ptMouse.x, &ptMouse.y); 00429 00430 // Select a new item, if any was clicked. 00431 int iItem = ItemFromPoint(ptMouse); 00432 if (iItem != -1) 00433 SetSelected(iItem); 00434 00435 DismissWithEvent(); 00436 }
|
|
Function : wxGridComboPopup::OnMouseMove Author : Mikhail Tatarnikov Purpose : mouse movement notification handler Returns : void Exceptions: Parameters: [in] wxMouseEvent& event - mouse event information. Notes : Definition at line 338 of file gridcombo.cpp. 00339 { 00340 // Convert the poin to the logical coordinates. 00341 wxPoint ptMouse(event.GetX(), event.GetY()); 00342 ClientToScrolledVirtual(&ptMouse.x, &ptMouse.y); 00343 00344 // Find out what item the mouse hover over. 00345 int iItem = ItemFromPoint(ptMouse); 00346 00347 // Check if mouse is hovered withing the same item. 00348 if (iItem == m_iHighlighed) 00349 return; 00350 00351 // If an item is hightlighted we need to start "dishighlight" timer 00352 // since this message can be the last one before leaving the control. 00353 if (iItem != -1) 00354 m_tmrHighlited.Start(HIGHLITED_TIMERINTERVAL); 00355 00356 // Repaint the old and new items. 00357 InvalidateItem(m_iHighlighed); 00358 InvalidateItem(iItem); 00359 00360 m_iHighlighed = iItem; 00361 }
|
|
Function : wxGridComboPopup::OnShow Author : Mikhail Tatarnikov Purpose : Notification that the popup is about to be shown Returns : void Exceptions: Parameters: None Notes : Definition at line 308 of file gridcombo.cpp.
|
|
Function : wxGridComboPopup::OnSize Author : Mikhail Tatarnikov Purpose : Resize notification handler. Returns : void Exceptions: Parameters: [in] wxSizeEvent& event - size event information. Notes : We need to update our scroll bars. Definition at line 321 of file gridcombo.cpp. 00322 { 00323 wxScrolledWindow::OnSize(event); 00324 00325 UpdateScrollers(); 00326 }
|
|
Function : wxGridComboPopup::OnTimer Author : Mikhail Tatarnikov Purpose : Timer notification handler Returns : void Exceptions: Parameters: [in] wxTimerEvent& event - time event information. Notes : We need it to trace situations when the mouse highlight an item and then leave the control leaving the item highlighted. Definition at line 374 of file gridcombo.cpp. 00375 { 00376 if (m_iHighlighed == -1) 00377 { 00378 m_tmrHighlited.Stop(); 00379 return; 00380 } 00381 00382 wxMouseState oMouseState = wxGetMouseState(); 00383 wxPoint ptMouse(oMouseState.GetX(), oMouseState.GetY()); 00384 00385 ScreenToClient(&(ptMouse.x), &(ptMouse.y)); 00386 00387 int iItem = ItemFromPoint(ptMouse); 00388 00389 if (iItem == -1) 00390 { 00391 m_tmrHighlited.Stop(); 00392 00393 int iCurHighlighted = m_iHighlighed; 00394 m_iHighlighed = -1; 00395 InvalidateItem(iCurHighlighted); 00396 } 00397 00398 }
|
|
Function : wxGridComboPopup::PaintComboControl Author : Mikhail Tatarnikov Purpose : Paints an item in the combo control itself. Returns : void Exceptions: Parameters: [in] wxDC& dc - dc to paint to; [in] const wxRect& rect - area for painting. Notes : Uses DrawItem pure virtual function. Reimplemented from wxComboPopup. Definition at line 610 of file gridcombo.cpp. 00611 { 00612 int iSelected = GetSelected(); 00613 /* if (iSelected == -1) 00614 { 00615 wxComboPopup::PaintComboControl(dc, rect); 00616 return; 00617 } 00618 */ 00619 int iFlags = keComboControl; 00620 if (!m_pCombo->IsEnabled()) 00621 iFlags |= keDisabled; 00622 00623 DrawItem(dc, rect, iSelected, iFlags); 00624 }
|
|
Function : wxGridComboPopup::SendComboBoxEvent Author : Mikhail Tatarnikov Purpose : Sends a combobox selection event Returns : void Exceptions: Parameters: [in] int iSelection - a new selection to notify clients about. Notes : Definition at line 465 of file gridcombo.cpp. 00466 { 00467 wxCommandEvent evt(wxEVT_COMMAND_COMBOBOX_SELECTED, m_combo->GetId()); 00468 00469 evt.SetEventObject(m_pCombo); 00470 00471 evt.SetInt(iSelection); 00472 00473 // Set client data, if any 00474 if (iSelection >= 0 && GetItemsNum() > iSelection) 00475 { 00476 CGridComboUserData* pClientData = m_pCombo->GetUserData(iSelection); 00477 evt.SetClientData(pClientData); 00478 } 00479 00480 m_combo->GetEventHandler()->AddPendingEvent(evt); 00481 }
|
|
Function : wxGridComboPopup::SetSelected Author : Mikhail Tatarnikov Purpose : Selects an element Returns : void Exceptions: Parameters: [in] int iItem - an element index to select. Notes : Definition at line 124 of file gridcombo.cpp. 00125 { 00126 m_pCombo->SetSelected(iItem); 00127 }
|
|
Function : wxGridComboPopup::UpdateColumnsNum Author : Mikhail Tatarnikov Purpose : Updates the coumn number. Returns : void Exceptions: Parameters: None Notes : Definition at line 662 of file gridcombo.cpp. 00663 { 00664 UpdateScrollers(); 00665 }
|
|
Function : wxGridComboPopup::UpdateScrollers Author : Mikhail Tatarnikov Purpose : Update the scroll bars with the current information (items number, columns, sizes, etc). Returns : void Exceptions: Parameters: None Notes : Definition at line 190 of file gridcombo.cpp. 00191 { 00192 wxSize szItem = GetItemSize(); 00193 00194 wxPoint ptGrid(0, 0); 00195 int iSelected = GetSelected(); 00196 if (iSelected != -1) 00197 ptGrid = ItemToGrid(iSelected); 00198 00199 SetScrollbars(szItem.x, szItem.y, GetColumns(), GetRows(), 00200 ptGrid.x, ptGrid.y); 00201 }
|
|
Definition at line 53 of file gridcombo.h. |
|
Definition at line 120 of file gridcombo.h. |
|
Definition at line 119 of file gridcombo.h. |
|
Definition at line 121 of file gridcombo.h. |