]> git.saurik.com Git - wxWidgets.git/commitdiff
added wxVListBox::GetItemRect() (#9711)
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 13 Jul 2008 17:28:31 +0000 (17:28 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 13 Jul 2008 17:28:31 +0000 (17:28 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54601 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/vlbox.h
interface/wx/vlbox.h
samples/htlbox/htlbox.cpp
src/generic/vlbox.cpp

index c6235d98b57ece587257822b4e99b2a411266d99..6887686b03f973290782e8c8b2bbf05c8fc8129c 100644 (file)
@@ -127,6 +127,8 @@ public:
     // get the background colour of selected cells
     const wxColour& GetSelectionBackground() const { return m_colBgSel; }
 
+    // get the item rect, returns empty rect if the item is not visible
+    wxRect GetItemRect(size_t n) const;
 
     // operations
     // ----------
index 2f7ae80506d829425421e583ae991d5cd28b24b1..ee09a476dfd18fbc99fa9d82cb42b3382ada6e8e 100644 (file)
@@ -125,6 +125,13 @@ public:
     */
     wxPoint GetMargins() const;
 
+    /**
+        Returns the rectangle occupied by this item in physical coordinates.
+
+        If the item is not currently visible, returns an empty rectangle.
+     */
+    wxRect GetItemRect(size_t item) const;
+
     /**
         Returns the index of the next selected item or @c wxNOT_FOUND if there
         are no more.
index 831dd2c839c888cfd32449290a3211710242cb44..eb4ccdb014b70153eb0f8759f4ee9b923c06b91f 100644 (file)
@@ -116,6 +116,7 @@ public:
     void OnToggleMulti(wxCommandEvent& event);
     void OnSelectAll(wxCommandEvent& event);
     void OnUpdateItem(wxCommandEvent& event);
+    void OnGetItemRect(wxCommandEvent& event);
 
     void OnSetBgCol(wxCommandEvent& event);
     void OnSetSelBgCol(wxCommandEvent& event);
@@ -172,6 +173,7 @@ enum
     HtmlLbox_ToggleMulti,
     HtmlLbox_SelectAll,
     HtmlLbox_UpdateItem,
+    HtmlLbox_GetItemRect,
 
     HtmlLbox_SetBgCol,
     HtmlLbox_SetSelBgCol,
@@ -199,6 +201,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
     EVT_MENU(HtmlLbox_ToggleMulti, MyFrame::OnToggleMulti)
     EVT_MENU(HtmlLbox_SelectAll, MyFrame::OnSelectAll)
     EVT_MENU(HtmlLbox_UpdateItem, MyFrame::OnUpdateItem)
+    EVT_MENU(HtmlLbox_GetItemRect, MyFrame::OnGetItemRect)
 
     EVT_MENU(HtmlLbox_About, MyFrame::OnAbout)
 
@@ -265,6 +268,7 @@ MyFrame::MyFrame()
     menuHLbox->AppendSeparator();
     menuHLbox->Append(HtmlLbox_SelectAll, _T("Select &all items\tCtrl-A"));
     menuHLbox->Append(HtmlLbox_UpdateItem, _T("Update &first item\tCtrl-U"));
+    menuHLbox->Append(HtmlLbox_GetItemRect, _T("Show &rectangle of item #10\tCtrl-R"));
     menuHLbox->AppendSeparator();
     menuHLbox->Append(HtmlLbox_SetBgCol, _T("Set &background...\tCtrl-B"));
     menuHLbox->Append(HtmlLbox_SetSelBgCol,
@@ -434,6 +438,14 @@ void MyFrame::OnUpdateItem(wxCommandEvent& WXUNUSED(event))
         GetMyBox()->UpdateFirstItem();
 }
 
+void MyFrame::OnGetItemRect(wxCommandEvent& WXUNUSED(event))
+{
+    static const int ITEM = 10;
+    const wxRect r = m_hlbox->GetItemRect(ITEM);
+    wxLogMessage("Rect of item %d: (%d, %d)-(%d, %d)",
+                 ITEM, r.x, r.y, r.x + r.width, r.y + r.height);
+}
+
 void MyFrame::OnSetBgCol(wxCommandEvent& WXUNUSED(event))
 {
     wxColour col = wxGetColourFromUser(this, m_hlbox->GetBackgroundColour());
index f94031bca57ebfd874e64defa6c9696efa028f29..df4a9bbfb0c70d4868ab72f39e0a09309a31e232 100644 (file)
@@ -325,6 +325,31 @@ void wxVListBox::RefreshSelected()
     }
 }
 
+wxRect wxVListBox::GetItemRect(size_t n) const
+{
+    wxRect itemrect;
+
+    // check that this item is visible
+    const size_t lineMax = GetVisibleEnd();
+    if ( n >= lineMax )
+        return itemrect;
+    size_t line = GetVisibleBegin();
+    if ( n < line )
+        return itemrect;
+
+    while ( line <= n )
+    {
+        itemrect.y += itemrect.height;
+        itemrect.height = OnGetRowHeight(line);
+
+        line++;
+    }
+
+    itemrect.width = GetClientSize().x;
+
+    return itemrect;
+}
+
 // ----------------------------------------------------------------------------
 // wxVListBox appearance parameters
 // ----------------------------------------------------------------------------