#include "wx/hashmap.h"
-#if wxUSE_EXTENDED_RTTI
-WX_DEFINE_FLAGS( wxListCtrlStyle )
-
-wxBEGIN_FLAGS( wxListCtrlStyle )
- // new style border flags, we put them first to
- // use them for streaming out
- wxFLAGS_MEMBER(wxBORDER_SIMPLE)
- wxFLAGS_MEMBER(wxBORDER_SUNKEN)
- wxFLAGS_MEMBER(wxBORDER_DOUBLE)
- wxFLAGS_MEMBER(wxBORDER_RAISED)
- wxFLAGS_MEMBER(wxBORDER_STATIC)
- wxFLAGS_MEMBER(wxBORDER_NONE)
-
- // old style border flags
- wxFLAGS_MEMBER(wxSIMPLE_BORDER)
- wxFLAGS_MEMBER(wxSUNKEN_BORDER)
- wxFLAGS_MEMBER(wxDOUBLE_BORDER)
- wxFLAGS_MEMBER(wxRAISED_BORDER)
- wxFLAGS_MEMBER(wxSTATIC_BORDER)
- wxFLAGS_MEMBER(wxBORDER)
-
- // standard window styles
- wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
- wxFLAGS_MEMBER(wxCLIP_CHILDREN)
- wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
- wxFLAGS_MEMBER(wxWANTS_CHARS)
- wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
- wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
- wxFLAGS_MEMBER(wxVSCROLL)
- wxFLAGS_MEMBER(wxHSCROLL)
-
- wxFLAGS_MEMBER(wxLC_LIST)
- wxFLAGS_MEMBER(wxLC_REPORT)
- wxFLAGS_MEMBER(wxLC_ICON)
- wxFLAGS_MEMBER(wxLC_SMALL_ICON)
- wxFLAGS_MEMBER(wxLC_ALIGN_TOP)
- wxFLAGS_MEMBER(wxLC_ALIGN_LEFT)
- wxFLAGS_MEMBER(wxLC_AUTOARRANGE)
- wxFLAGS_MEMBER(wxLC_USER_TEXT)
- wxFLAGS_MEMBER(wxLC_EDIT_LABELS)
- wxFLAGS_MEMBER(wxLC_NO_HEADER)
- wxFLAGS_MEMBER(wxLC_SINGLE_SEL)
- wxFLAGS_MEMBER(wxLC_SORT_ASCENDING)
- wxFLAGS_MEMBER(wxLC_SORT_DESCENDING)
- wxFLAGS_MEMBER(wxLC_VIRTUAL)
-
-wxEND_FLAGS( wxListCtrlStyle )
-
-IMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl, wxControl,"wx/listctrl.h")
-
-wxBEGIN_PROPERTIES_TABLE(wxListCtrl)
- wxEVENT_PROPERTY( TextUpdated , wxEVT_COMMAND_TEXT_UPDATED , wxCommandEvent )
-
- wxPROPERTY_FLAGS( WindowStyle , wxListCtrlStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
-wxEND_PROPERTIES_TABLE()
-
-wxBEGIN_HANDLERS_TABLE(wxListCtrl)
-wxEND_HANDLERS_TABLE()
-
-wxCONSTRUCTOR_5( wxListCtrl , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle )
-
-/*
- TODO : Expose more information of a list's layout etc. via appropriate objects (¢ la NotebookPageInfo)
-*/
-#else
-IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl)
-#endif
-
-IMPLEMENT_DYNAMIC_CLASS(wxListView, wxListCtrl)
-IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject)
-
-IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent)
-
WX_DECLARE_HASH_MAP( int, wxListItem*, wxIntegerHash, wxIntegerEqual, wxListItemList );
#include "wx/listimpl.cpp"
if (result == kControlButtonPart){
DataBrowserPropertyID col;
GetDataBrowserSortProperty(controlRef, &col);
-
+
DataBrowserTableViewColumnIndex column = 0;
verify_noerr( GetDataBrowserTableViewColumnPosition( controlRef, col, &column ) );
-
+
le.m_col = column;
// FIXME: we can't use the sort property for virtual listctrls
// so we need to find a better way to determine which column was clicked...
{
int id = event.GetId();
wxObject* obj = event.GetEventObject();
-
+
// even though we use a generic list ctrl underneath, make sure
// we present ourselves as wxListCtrl.
event.SetEventObject( m_list );
event.Skip();
}
-BEGIN_EVENT_TABLE(wxListCtrl, wxControl)
- EVT_LEFT_DOWN(wxListCtrl::OnLeftDown)
- EVT_LEFT_DCLICK(wxListCtrl::OnDblClick)
- EVT_MIDDLE_DOWN(wxListCtrl::OnMiddleDown)
- EVT_RIGHT_DOWN(wxListCtrl::OnRightDown)
- EVT_CHAR(wxListCtrl::OnChar)
-END_EVENT_TABLE()
-
// ============================================================================
// implementation
// ============================================================================
m_bgColor = wxNullColour;
m_textctrlWrapper = NULL;
m_current = -1;
- m_renameTimer = new wxListCtrlRenameTimer( this );
+ m_renameTimer = NULL;
}
class wxGenericListCtrlHook : public wxGenericListCtrl
int hitResult;
long current = HitTest(event.GetPosition(), hitResult);
if ((current == m_current) &&
- (hitResult == wxLIST_HITTEST_ONITEM) &&
+ (hitResult & wxLIST_HITTEST_ONITEMLABEL) &&
HasFlag(wxLC_EDIT_LABELS) )
{
- m_renameTimer->Start( 100, true );
+ if ( m_renameTimer )
+ m_renameTimer->Start( 250, true );
}
else
{
void wxListCtrl::OnDblClick(wxMouseEvent& event)
{
- if ( m_renameTimer->IsRunning() )
+ if ( m_renameTimer && m_renameTimer->IsRunning() )
m_renameTimer->Stop();
event.Skip();
}
void wxListCtrl::OnChar(wxKeyEvent& event)
{
-
+
if (m_dbImpl)
{
wxListEvent le( wxEVT_COMMAND_LIST_KEY_DOWN, GetId() );
le.SetEventObject(this);
le.m_code = event.GetKeyCode();
le.m_itemIndex = -1;
-
+
if (m_current == -1)
{
// if m_current isn't set, check if there's been a selection
// made before continuing
m_current = GetNextItem(-1, wxLIST_NEXT_BELOW, wxLIST_STATE_SELECTED);
}
-
+
// We need to determine m_current ourselves when navigation keys
// are used. Note that PAGEUP and PAGEDOWN do not alter the current
// item on native Mac ListCtrl, so we only handle up and down keys.
m_current -= 1;
else
m_current = 0;
-
+
break;
case WXK_DOWN:
m_current += 1;
else
m_current = GetItemCount() - 1;
-
+
break;
}
&& (wxSystemOptions::GetOptionInt( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL ) == 1)) ||
(style & wxLC_ICON) || (style & wxLC_SMALL_ICON) || (style & wxLC_LIST) )
{
- m_macIsUserPane = true;
-
long paneStyle = style;
paneStyle &= ~wxSIMPLE_BORDER;
paneStyle &= ~wxDOUBLE_BORDER;
else
{
- m_macIsUserPane = false;
+ DontCreatePeer();
if ( !wxWindow::Create(parent, id, pos, size, style & ~(wxHSCROLL | wxVSCROLL), name) )
return false;
m_dbImpl = new wxMacDataBrowserListCtrlControl( this, pos, size, style );
- m_peer = m_dbImpl;
+ SetPeer(m_dbImpl);
MacPostControlCreate( pos, size );
- InstallControlEventHandler( m_peer->GetControlRef() , GetwxMacListCtrlEventHandlerUPP(),
+ InstallControlEventHandler( GetPeer()->GetControlRef() , GetwxMacListCtrlEventHandlerUPP(),
GetEventTypeCount(eventList), eventList, this,
(EventHandlerRef *)&m_macListCtrlEventHandler);
+
+ m_renameTimer = new wxListCtrlRenameTimer( this );
+
+ Connect( wxID_ANY, wxEVT_CHAR, wxCharEventHandler(wxListCtrl::OnChar), NULL, this );
+ Connect( wxID_ANY, wxEVT_LEFT_DOWN, wxMouseEventHandler(wxListCtrl::OnLeftDown), NULL, this );
+ Connect( wxID_ANY, wxEVT_LEFT_DCLICK, wxMouseEventHandler(wxListCtrl::OnDblClick), NULL, this );
+ Connect( wxID_ANY, wxEVT_MIDDLE_DOWN, wxMouseEventHandler(wxListCtrl::OnMiddleDown), NULL, this );
+ Connect( wxID_ANY, wxEVT_RIGHT_DOWN, wxMouseEventHandler(wxListCtrl::OnRightDown), NULL, this );
}
return true;
delete m_imageListState;
delete m_renameTimer;
-
+
WX_CLEAR_LIST(wxColumnList, m_colsInfo);
}
attr.colFg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
attr.colBg = wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX );
- attr.font.CreateSystemFont(wxOSX_SYSTEM_FONT_VIEWS);
+ static wxFont font = wxFont(wxOSX_SYSTEM_FONT_VIEWS);
+ attr.font = font;
return attr;
}
return wxNullColour;
}
+void wxListCtrl::Freeze ()
+{
+ if (m_genericImpl)
+ m_genericImpl->Freeze();
+ wxControl::Freeze();
+}
+
+void wxListCtrl::Thaw ()
+{
+ if (m_genericImpl)
+ m_genericImpl->Thaw();
+ wxControl::Thaw();
+}
+
+void wxListCtrl::Update ()
+{
+ if (m_genericImpl)
+ m_genericImpl->Update();
+ wxControl::Update();
+}
+
// ----------------------------------------------------------------------------
// accessors
// ----------------------------------------------------------------------------
if (m_dbImpl)
{
wxASSERT_MSG( col < (int)m_colsInfo.GetCount(), wxT("invalid column index in wxMacListCtrlItem") );
-
+
long mask = item.GetMask();
{
wxListItem listItem;
if (item.GetMask() & wxLIST_MASK_TEXT)
{
wxFontEncoding enc;
- if ( m_font.Ok() )
+ if ( m_font.IsOk() )
enc = GetFont().GetEncoding();
else
enc = wxLocale::GetSystemEncoding();
}
// Gets the item text
-wxString wxListCtrl::GetItemText(long item) const
+wxString wxListCtrl::GetItemText(long item, int column) const
{
if (m_genericImpl)
- return m_genericImpl->GetItemText(item);
+ return m_genericImpl->GetItemText(item, column);
wxListItem info;
info.m_mask = wxLIST_MASK_TEXT;
info.m_itemId = item;
+ info.m_col = column;
if (!GetItem(info))
return wxEmptyString;
if (m_genericImpl)
return m_genericImpl->GetSubItemRect(item, subItem, rect, code);
- // TODO: implement for DataBrowser implementation
+ // TODO: implement for DataBrowser implementation
return false;
}
DataBrowserTableViewColumnID col = 0;
verify_noerr( m_dbImpl->GetColumnIDFromIndex( 0, &col ) );
-
+
Rect bounds;
DataBrowserPropertyPart part = kDataBrowserPropertyEnclosingPart;
if ( code == wxLIST_RECT_LABEL )
if ( !IsVirtual() )
id = (DataBrowserItemID)m_dbImpl->GetItemFromLine(line);
- if ( (state & wxLIST_STATE_FOCUSED) && (m_current == line))
+ if ( (state & wxLIST_STATE_FOCUSED) && (m_current == line))
return line;
if ( (state == wxLIST_STATE_DONTCARE ) )
if ( !IsVirtual() )
id = (DataBrowserItemID)m_dbImpl->GetItemFromLine(line);
- if ( (state & wxLIST_STATE_FOCUSED) && (m_current == line))
+ if ( (state & wxLIST_STATE_FOCUSED) && (m_current == line))
return line;
if ( (state == wxLIST_STATE_DONTCARE ) )
return -1;
}
+static void calculateCGDrawingBounds(CGRect inItemRect, CGRect *outIconRect, CGRect *outTextRect, bool hasIcon);
+
// Determines which item (if any) is at the specified point,
// giving details in 'flags' (see wxLIST_HITTEST_... flags above)
long
wxListCtrl::HitTest(const wxPoint& point, int& flags, long *ptrSubItem) const
{
+ if (ptrSubItem)
+ *ptrSubItem = -1;
+
if (m_genericImpl)
return m_genericImpl->HitTest(point, flags, ptrSubItem);
DataBrowserItemID id;
m_dbImpl->GetItemID( (DataBrowserTableViewRowIndex) row, &id );
- // TODO: Use GetDataBrowserItemPartBounds to return if we are in icon or label
- if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL ) )
+ CGPoint click_point = CGPointMake( point.x, point.y );
+ if (row < GetItemCount() )
{
- wxMacListCtrlItem* lcItem;
- lcItem = (wxMacListCtrlItem*) id;
- if (lcItem)
+ short column;
+ for( column = 0; column < GetColumnCount(); column++ )
{
- flags = wxLIST_HITTEST_ONITEM;
- return row;
- }
- }
- else
- {
- if (row < GetItemCount() )
- {
- flags = wxLIST_HITTEST_ONITEM;
- return row;
- }
- }
-
+ Rect enclosingRect;
+ CGRect enclosingCGRect, iconCGRect, textCGRect;
+ int imgIndex = -1;
+ wxMacListCtrlItem* lcItem;
+
+ WXUNUSED_UNLESS_DEBUG( OSStatus status = ) m_dbImpl->GetItemPartBounds( id, kMinColumnId + column, kDataBrowserPropertyEnclosingPart, &enclosingRect );
+ wxASSERT( status == noErr );
+
+ enclosingCGRect = CGRectMake(enclosingRect.left,
+ enclosingRect.top,
+ enclosingRect.right - enclosingRect.left,
+ enclosingRect.bottom - enclosingRect.top);
+
+ if (column >= 0)
+ {
+ if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL ) )
+ {
+ lcItem = (wxMacListCtrlItem*) id;
+ if (lcItem->HasColumnInfo(column))
+ {
+ wxListItem* item = lcItem->GetColumnInfo(column);
+
+ if (item->GetMask() & wxLIST_MASK_IMAGE)
+ {
+ imgIndex = item->GetImage();
+ }
+ }
+ }
+ else
+ {
+ long itemNum = (long)id-1;
+ if (itemNum >= 0 && itemNum < GetItemCount())
+ {
+ imgIndex = OnGetItemColumnImage( itemNum, column );
+ }
+ }
+ }
+
+ calculateCGDrawingBounds(enclosingCGRect, &iconCGRect, &textCGRect, (imgIndex != -1) );
+
+ if ( CGRectContainsPoint( iconCGRect, click_point ) )
+ {
+ flags = wxLIST_HITTEST_ONITEMICON;
+ if (ptrSubItem)
+ *ptrSubItem = column;
+ return row;
+ }
+ else if ( CGRectContainsPoint( textCGRect, click_point ) )
+ {
+ flags = wxLIST_HITTEST_ONITEMLABEL;
+ if (ptrSubItem)
+ *ptrSubItem = column;
+ return row;
+ }
+ }
+
+ if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL ) )
+ {
+ wxMacListCtrlItem* lcItem;
+ lcItem = (wxMacListCtrlItem*) id;
+ if (lcItem)
+ {
+ flags = wxLIST_HITTEST_ONITEM;
+ if (ptrSubItem)
+ *ptrSubItem = column;
+ return row;
+ }
+ }
+ else
+ {
+ flags = wxLIST_HITTEST_ONITEM;
+ if (ptrSubItem)
+ *ptrSubItem = column;
+ return row;
+ }
+ }
+ else
+ {
+ if ( wxControl::HitTest( point ) )
+ flags = wxLIST_HITTEST_NOWHERE;
+ }
}
+
return -1;
}
if (imageList && imageList->GetImageCount() > 0)
{
wxBitmap bmp = imageList->GetBitmap(0);
- //if (bmp.Ok())
+ //if (bmp.IsOk())
// type = kDataBrowserIconAndTextType;
}
just = teFlushRight;
}
m_dbImpl->InsertColumn(col, type, item.GetText(), just, width);
-
+
wxListItem* listItem = new wxListItem(item);
m_colsInfo.Insert( col, listItem );
SetColumn(col, item);
if (m_dbImpl)
{
- m_dbImpl->SetScrollPosition(dx, dy);
+ // Notice that the parameter order is correct here: first argument is
+ // the "top" displacement, second one is the "left" one.
+ m_dbImpl->SetScrollPosition(dy, dx);
}
return true;
}
wxString text;
wxFont font = wxNullFont;
int imgIndex = -1;
-
+
DataBrowserTableViewColumnIndex listColumn = 0;
GetColumnPosition( property, &listColumn );
-
+
wxListCtrl* list = wxDynamicCast( GetWXPeer() , wxListCtrl );
wxMacListCtrlItem* lcItem;
wxColour color = *wxBLACK;
if (bgColor == wxNullColour)
bgColor = listBgColor;
- if (!font.Ok())
+ if (!font.IsOk())
font = list->GetFont();
wxCFStringRef cfString( text, wxLocale::GetSystemEncoding() );
Boolean active;
ThemeDrawingState savedState = NULL;
CGContextRef context = (CGContextRef)list->MacGetDrawingContext();
+ wxMacCGContextStateSaver top_saver_cg( context );
+
RGBColor labelColor;
labelColor.red = 0;
labelColor.green = 0;
GetThemeBrushAsColor(kThemeBrushSecondaryHighlightColor, 32, true, &backgroundColor);
GetThemeTextColor(kThemeTextColorBlack, gdDepth, colorDevice, &labelColor);
}
- CGContextSaveGState(context);
+ wxMacCGContextStateSaver cg( context );
CGContextSetRGBFillColor(context, (CGFloat)backgroundColor.red / (CGFloat)USHRT_MAX,
(CGFloat)backgroundColor.green / (CGFloat)USHRT_MAX,
(CGFloat)backgroundColor.blue / (CGFloat)USHRT_MAX, (CGFloat) 1.0);
CGContextFillRect(context, enclosingCGRect);
-
- CGContextRestoreGState(context);
}
else
{
- if (color.Ok())
+ if (color.IsOk())
color.GetRGBColor(&labelColor);
- else if (list->GetTextColour().Ok())
+ else if (list->GetTextColour().IsOk())
list->GetTextColour().GetRGBColor(&labelColor);
- if (bgColor.Ok())
+ if (bgColor.IsOk())
{
bgColor.GetRGBColor(&backgroundColor);
CGContextSaveGState(context);
if (imgIndex != -1)
{
wxImageList* imageList = list->GetImageList(wxIMAGE_LIST_SMALL);
- if (imageList && imageList->GetImageCount() > 0){
+ if (imageList && imageList->GetImageCount() > 0)
+ {
wxBitmap bmp = imageList->GetBitmap(imgIndex);
IconRef icon = bmp.GetIconRef();
- CGContextSaveGState(context);
+ wxMacCGContextStateSaver cg( context );
+
CGContextTranslateCTM(context, 0,iconCGRect.origin.y + CGRectGetMaxY(iconCGRect));
CGContextScaleCTM(context,1.0f,-1.0f);
PlotIconRefInContext(context, &iconCGRect, kAlignNone,
active ? kTransformNone : kTransformDisabled, NULL,
kPlotIconRefNormalFlags, icon);
-
- CGContextRestoreGState(context);
}
}
{
info.version = kHIThemeTextInfoVersionOne;
info.fontID = kThemeViewsFont;
- if (font.Ok())
+ if (font.IsOk())
{
info.fontID = kThemeSpecifiedFont;
info.font = (CTFontRef) font.OSXGetCTFont();
info.version = kHIThemeTextInfoVersionZero;
info.fontID = kThemeViewsFont;
- if (font.Ok())
+ if (font.IsOk())
{
info.fontID = font.MacGetThemeFontID();
info.truncationPosition = kHIThemeTextTruncationEnd;
info.truncationMaxLines = 1;
- CGContextSaveGState(context);
- CGContextSetRGBFillColor (context, (CGFloat)labelColor.red / (CGFloat)USHRT_MAX,
+ {
+ wxMacCGContextStateSaver cg( context );
+ CGContextSetRGBFillColor (context, (CGFloat)labelColor.red / (CGFloat)USHRT_MAX,
(CGFloat)labelColor.green / (CGFloat)USHRT_MAX,
(CGFloat)labelColor.blue / (CGFloat)USHRT_MAX, (CGFloat) 1.0);
- HIThemeDrawTextBox(cfString, &textCGRect, &info, context, kHIThemeOrientationNormal);
-
- CGContextRestoreGState(context);
+ HIThemeDrawTextBox(cfString, &textCGRect, &info, context, kHIThemeOrientationNormal);
+ }
#ifndef __LP64__
if (savedState != NULL)
{
item = (wxMacListCtrlItem *) itemID;
}
-
+
// we want to depend on as little as possible to make sure tear-down of controls is safe
if ( message == kDataBrowserItemRemoved )
{
}
}
}
-
+
void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n, wxListItem* item )
{
-
+
wxMacDataItemBrowserControl::MacInsert(n, new wxMacListCtrlItem() );
MacSetColumnInfo(n, 0, item);
}