cleanup - fixed warnings, reformatting

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38088 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
David Surovell
2006-03-15 06:22:36 +00:00
parent 74af7bcf4f
commit c18353e561
2 changed files with 175 additions and 161 deletions

View File

@@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Name: checklst.cpp // Name: src/mac/carbon/checklst.cpp
// Purpose: implementation of wxCheckListBox class // Purpose: implementation of wxCheckListBox class
// Author: Stefan Csomor // Author: Stefan Csomor
// Modified by: // Modified by:
@@ -8,10 +8,9 @@
// Copyright: (c) Stefan Csomor // Copyright: (c) Stefan Csomor
// Licence: wxWindows licence // Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
//
// new DataBrowser-based version
// ============================================================================
// headers & declarations
// ============================================================================
#include "wx/wxprec.h" #include "wx/wxprec.h"
@@ -21,14 +20,11 @@
#include "wx/arrstr.h" #include "wx/arrstr.h"
#include "wx/mac/uma.h" #include "wx/mac/uma.h"
#ifndef __DARWIN__ #ifndef __DARWIN__
#include <Appearance.h> #include <Appearance.h>
#endif #endif
// ============================================================================
// implementation of wxCheckListBox
// ============================================================================
IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox, wxListBox) IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox, wxListBox)
BEGIN_EVENT_TABLE(wxCheckListBox, wxListBox) BEGIN_EVENT_TABLE(wxCheckListBox, wxListBox)
@@ -37,14 +33,13 @@ END_EVENT_TABLE()
const short kTextColumnId = 1024; const short kTextColumnId = 1024;
const short kCheckboxColumnId = 1025; const short kCheckboxColumnId = 1025;
// new databrowser based version
// Listbox item
void wxCheckListBox::Init() void wxCheckListBox::Init()
{ {
} }
bool wxCheckListBox::Create(wxWindow *parent, bool wxCheckListBox::Create(
wxWindow *parent,
wxWindowID id, wxWindowID id,
const wxPoint &pos, const wxPoint &pos,
const wxSize &size, const wxSize &size,
@@ -55,41 +50,47 @@ bool wxCheckListBox::Create(wxWindow *parent,
{ {
wxCArrayString chs( choices ); wxCArrayString chs( choices );
return Create(parent, id, pos, size, chs.GetCount(), chs.GetStrings(), return Create( parent, id, pos, size, chs.GetCount(), chs.GetStrings(), style, validator, name );
style, validator, name);
} }
#if TARGET_API_MAC_OSX #if TARGET_API_MAC_OSX
static pascal void DataBrowserItemNotificationProc(ControlRef browser, DataBrowserItemID itemID, static pascal void DataBrowserItemNotificationProc(
DataBrowserItemNotification message, DataBrowserItemDataRef itemData) ControlRef browser,
DataBrowserItemID itemID,
DataBrowserItemNotification message,
DataBrowserItemDataRef itemData )
#else #else
static pascal void DataBrowserItemNotificationProc(ControlRef browser, DataBrowserItemID itemID, static pascal void DataBrowserItemNotificationProc(
ControlRef browser,
DataBrowserItemID itemID,
DataBrowserItemNotification message ) DataBrowserItemNotification message )
#endif #endif
{ {
long ref = GetControlReference( browser ); long ref = GetControlReference( browser );
if ( ref ) if (ref != 0)
{ {
wxCheckListBox* list = wxDynamicCast( (wxObject*)ref, wxCheckListBox ); wxCheckListBox* list = wxDynamicCast( (wxObject*)ref, wxCheckListBox );
int i = itemID - 1; int i = itemID - 1;
if (i >= 0 && i < list->GetCount() ) if ((i >= 0) && (i < (int)list->GetCount()))
{ {
bool trigger = false; bool trigger = false;
wxCommandEvent event( wxCommandEvent event( wxEVT_COMMAND_LISTBOX_SELECTED, list->GetId() );
wxEVT_COMMAND_LISTBOX_SELECTED, list->GetId() );
switch ( message ) switch ( message )
{ {
case kDataBrowserItemDeselected: case kDataBrowserItemDeselected:
if ( list->HasMultipleSelection() ) if ( list->HasMultipleSelection() )
trigger = true; trigger = true;
break; break;
case kDataBrowserItemSelected: case kDataBrowserItemSelected:
trigger = true; trigger = true;
break; break;
case kDataBrowserItemDoubleClicked: case kDataBrowserItemDoubleClicked:
event.SetEventType( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED ); event.SetEventType( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED );
trigger = true; trigger = true;
break; break;
default: default:
break; break;
} }
@@ -103,19 +104,22 @@ static pascal void DataBrowserItemNotificationProc(ControlRef browser, DataBrow
event.SetClientData( list->GetClientData( i ) ); event.SetClientData( list->GetClientData( i ) );
event.SetString( list->GetString( i ) ); event.SetString( list->GetString( i ) );
event.SetInt( i ); event.SetInt( i );
event.SetExtraLong( list->HasMultipleSelection() ? message == kDataBrowserItemSelected : TRUE ); event.SetExtraLong( list->HasMultipleSelection() ? message == kDataBrowserItemSelected : true );
wxPostEvent( list->GetEventHandler(), event ); wxPostEvent( list->GetEventHandler(), event );
// direct notification is not always having the listbox GetSelection() having in synch with event
// direct notification is not always having the listbox GetSelection() having in sync with event
// list->GetEventHandler()->ProcessEvent( event ); // list->GetEventHandler()->ProcessEvent( event );
} }
} }
} }
} }
static pascal OSStatus ListBoxGetSetItemData(
static pascal OSStatus ListBoxGetSetItemData(ControlRef browser, ControlRef browser,
DataBrowserItemID itemID, DataBrowserPropertyID property, DataBrowserItemID itemID,
DataBrowserItemDataRef itemData, Boolean changeValue) DataBrowserPropertyID property,
DataBrowserItemDataRef itemData,
Boolean changeValue )
{ {
OSStatus err = errDataBrowserPropertyNotSupported; OSStatus err = errDataBrowserPropertyNotSupported;
@@ -123,15 +127,14 @@ static pascal OSStatus ListBoxGetSetItemData(ControlRef browser,
{ {
switch (property) switch (property)
{ {
case kTextColumnId: case kTextColumnId:
{ {
long ref = GetControlReference( browser ); long ref = GetControlReference( browser );
if ( ref ) if (ref != 0)
{ {
wxCheckListBox* list = wxDynamicCast( (wxObject*) ref, wxCheckListBox ); wxCheckListBox* list = wxDynamicCast( (wxObject*) ref, wxCheckListBox );
int i = itemID - 1; int i = itemID - 1;
if (i >= 0 && i < list->GetCount() ) if ((i >= 0) && (i < (int)list->GetCount()))
{ {
wxMacCFStringHolder cf( list->GetString( i ), list->GetFont().GetEncoding() ); wxMacCFStringHolder cf( list->GetString( i ), list->GetFont().GetEncoding() );
verify_noerr( ::SetDataBrowserItemDataText( itemData, cf ) ); verify_noerr( ::SetDataBrowserItemDataText( itemData, cf ) );
@@ -140,14 +143,15 @@ static pascal OSStatus ListBoxGetSetItemData(ControlRef browser,
} }
} }
break; break;
case kCheckboxColumnId: case kCheckboxColumnId:
{ {
long ref = GetControlReference( browser ); long ref = GetControlReference( browser );
if ( ref ) if (ref != 0)
{ {
wxCheckListBox* list = wxDynamicCast( (wxObject*)ref, wxCheckListBox ); wxCheckListBox* list = wxDynamicCast( (wxObject*)ref, wxCheckListBox );
int i = itemID - 1; int i = itemID - 1;
if (i >= 0 && i < list->GetCount() ) if ((i >= 0) && (i < (int)list->GetCount()))
{ {
verify_noerr( ::SetDataBrowserItemDataButtonValue( itemData, list->IsChecked( i ) ? kThemeButtonOn : kThemeButtonOff ) ); verify_noerr( ::SetDataBrowserItemDataButtonValue( itemData, list->IsChecked( i ) ? kThemeButtonOn : kThemeButtonOff ) );
err = noErr; err = noErr;
@@ -155,6 +159,7 @@ static pascal OSStatus ListBoxGetSetItemData(ControlRef browser,
} }
} }
break; break;
case kDataBrowserItemIsEditableProperty: case kDataBrowserItemIsEditableProperty:
{ {
err = ::SetDataBrowserItemDataBooleanValue( itemData, true ); err = ::SetDataBrowserItemDataBooleanValue( itemData, true );
@@ -172,11 +177,11 @@ static pascal OSStatus ListBoxGetSetItemData(ControlRef browser,
case kCheckboxColumnId: case kCheckboxColumnId:
{ {
long ref = GetControlReference( browser ); long ref = GetControlReference( browser );
if ( ref ) if (ref != 0)
{ {
wxCheckListBox* list = wxDynamicCast( (wxObject*) ref, wxCheckListBox ); wxCheckListBox* list = wxDynamicCast( (wxObject*) ref, wxCheckListBox );
int i = itemID - 1; int i = itemID - 1;
if (i >= 0 && i < list->GetCount() ) if ((i >= 0) && (i < (int)list->GetCount()))
{ {
// we have to change this behind the back, since Check() would be triggering another update round // we have to change this behind the back, since Check() would be triggering another update round
bool newVal = !list->IsChecked( i ); bool newVal = !list->IsChecked( i );
@@ -190,7 +195,6 @@ static pascal OSStatus ListBoxGetSetItemData(ControlRef browser,
list->GetEventHandler()->ProcessEvent( event ); list->GetEventHandler()->ProcessEvent( event );
} }
} }
} }
break; break;
@@ -201,10 +205,14 @@ static pascal OSStatus ListBoxGetSetItemData(ControlRef browser,
return err; return err;
} }
bool wxCheckListBox::Create(wxWindow *parent, wxWindowID id,
bool wxCheckListBox::Create(
wxWindow *parent,
wxWindowID id,
const wxPoint& pos, const wxPoint& pos,
const wxSize& size, const wxSize& size,
int n, const wxString choices[], int n,
const wxString choices[],
long style, long style,
const wxValidator& validator, const wxValidator& validator,
const wxString& name ) const wxString& name )
@@ -212,24 +220,27 @@ bool wxCheckListBox::Create(wxWindow *parent, wxWindowID id,
m_macIsUserPane = false; m_macIsUserPane = false;
wxASSERT_MSG( !(style & wxLB_MULTIPLE) || !(style & wxLB_EXTENDED), wxASSERT_MSG( !(style & wxLB_MULTIPLE) || !(style & wxLB_EXTENDED),
_T("only one of listbox selection modes can be specified") ); wxT("only one of listbox selection modes can be specified") );
if ( !wxListBoxBase::Create( parent, id, pos, size, style & ~(wxHSCROLL | wxVSCROLL), validator, name ) ) if ( !wxListBoxBase::Create( parent, id, pos, size, style & ~(wxHSCROLL | wxVSCROLL), validator, name ) )
return false; return false;
m_noItems = 0 ; // this will be increased by our append command // this will be increased by our Append command
m_noItems = 0;
m_selected = 0; m_selected = 0;
Rect bounds = wxMacGetBoundsForControl( this, pos, size ); Rect bounds = wxMacGetBoundsForControl( this, pos, size );
m_peer = new wxMacControl( this ); m_peer = new wxMacControl( this );
verify_noerr( ::CreateDataBrowserControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, kDataBrowserListView , m_peer->GetControlRefAddr() ) ); OSStatus err = ::CreateDataBrowserControl(
MAC_WXHWND(parent->MacGetTopLevelWindowRef()),
&bounds, kDataBrowserListView, m_peer->GetControlRefAddr() );
verify_noerr( err );
DataBrowserSelectionFlags options = kDataBrowserDragSelect; DataBrowserSelectionFlags options = kDataBrowserDragSelect;
if ( style & wxLB_MULTIPLE ) if ( style & wxLB_MULTIPLE )
{ {
options += kDataBrowserAlwaysExtendSelection + kDataBrowserCmdTogglesSelection ; options |= kDataBrowserAlwaysExtendSelection | kDataBrowserCmdTogglesSelection;
} }
else if ( style & wxLB_EXTENDED ) else if ( style & wxLB_EXTENDED )
{ {
@@ -237,9 +248,11 @@ bool wxCheckListBox::Create(wxWindow *parent, wxWindowID id,
} }
else else
{ {
options += kDataBrowserSelectOnlyOne ; options |= kDataBrowserSelectOnlyOne;
} }
verify_noerr(m_peer->SetSelectionFlags( options ) );
err = m_peer->SetSelectionFlags( options );
verify_noerr( err );
DataBrowserListViewColumnDesc columnDesc; DataBrowserListViewColumnDesc columnDesc;
columnDesc.headerBtnDesc.titleOffset = 0; columnDesc.headerBtnDesc.titleOffset = 0;
@@ -261,9 +274,12 @@ bool wxCheckListBox::Create(wxWindow *parent, wxWindowID id,
columnDesc.propertyDesc.propertyID = kCheckboxColumnId; columnDesc.propertyDesc.propertyID = kCheckboxColumnId;
columnDesc.propertyDesc.propertyType = kDataBrowserCheckboxType; columnDesc.propertyDesc.propertyType = kDataBrowserCheckboxType;
columnDesc.propertyDesc.propertyFlags = kDataBrowserPropertyIsMutable | kDataBrowserTableViewSelectionColumn | columnDesc.propertyDesc.propertyFlags =
kDataBrowserDefaultPropertyFlags; kDataBrowserPropertyIsMutable
verify_noerr( m_peer->AddListViewColumn( &columnDesc, kDataBrowserListViewAppendColumn) ) ; | kDataBrowserTableViewSelectionColumn
| kDataBrowserDefaultPropertyFlags;
err = m_peer->AddListViewColumn( &columnDesc, kDataBrowserListViewAppendColumn );
verify_noerr( err );
// text column // text column
@@ -278,7 +294,6 @@ bool wxCheckListBox::Create(wxWindow *parent, wxWindowID id,
#endif #endif
; ;
verify_noerr( m_peer->AddListViewColumn( &columnDesc, kDataBrowserListViewAppendColumn ) ); verify_noerr( m_peer->AddListViewColumn( &columnDesc, kDataBrowserListViewAppendColumn ) );
verify_noerr( m_peer->AutoSizeListViewColumns() ); verify_noerr( m_peer->AutoSizeListViewColumns() );
@@ -289,12 +304,12 @@ bool wxCheckListBox::Create(wxWindow *parent, wxWindowID id,
DataBrowserCallbacks callbacks; DataBrowserCallbacks callbacks;
callbacks.version = kDataBrowserLatestCallbacks; callbacks.version = kDataBrowserLatestCallbacks;
InitDataBrowserCallbacks( &callbacks ); InitDataBrowserCallbacks( &callbacks );
callbacks.u.v1.itemDataCallback = NewDataBrowserItemDataUPP(ListBoxGetSetItemData); callbacks.u.v1.itemDataCallback = NewDataBrowserItemDataUPP( &ListBoxGetSetItemData );
callbacks.u.v1.itemNotificationCallback = callbacks.u.v1.itemNotificationCallback =
#if TARGET_API_MAC_OSX #if TARGET_API_MAC_OSX
(DataBrowserItemNotificationUPP) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc) ; (DataBrowserItemNotificationUPP) NewDataBrowserItemNotificationWithItemUPP( &DataBrowserItemNotificationProc );
#else #else
NewDataBrowserItemNotificationUPP(DataBrowserItemNotificationProc) ; NewDataBrowserItemNotificationUPP( &DataBrowserItemNotificationProc );
#endif #endif
m_peer->SetCallbacks( &callbacks ); m_peer->SetCallbacks( &callbacks );
@@ -311,7 +326,8 @@ bool wxCheckListBox::Create(wxWindow *parent, wxWindowID id,
Append( choices[i] ); Append( choices[i] );
} }
SetBestSize(size); // Needed because it is a wxControlWithItems // Needed because it is a wxControlWithItems
SetBestSize( size );
return true; return true;
} }
@@ -323,7 +339,7 @@ bool wxCheckListBox::Create(wxWindow *parent, wxWindowID id,
bool wxCheckListBox::IsChecked(size_t item) const bool wxCheckListBox::IsChecked(size_t item) const
{ {
wxCHECK_MSG( item < m_checks.GetCount(), false, wxCHECK_MSG( item < m_checks.GetCount(), false,
_T("invalid index in wxCheckListBox::IsChecked") ); wxT("invalid index in wxCheckListBox::IsChecked") );
return m_checks[item] != 0; return m_checks[item] != 0;
} }
@@ -331,14 +347,17 @@ bool wxCheckListBox::IsChecked(size_t item) const
void wxCheckListBox::Check(size_t item, bool check) void wxCheckListBox::Check(size_t item, bool check)
{ {
wxCHECK_RET( item < m_checks.GetCount(), wxCHECK_RET( item < m_checks.GetCount(),
_T("invalid index in wxCheckListBox::Check") ); wxT("invalid index in wxCheckListBox::Check") );
bool isChecked = m_checks[item] != 0; bool isChecked = m_checks[item] != 0;
if ( check != isChecked ) if ( check != isChecked )
{ {
m_checks[item] = check; m_checks[item] = check;
UInt32 id = item + 1; UInt32 id = item + 1;
verify_noerr( m_peer->UpdateItems(kDataBrowserNoItem , 1 , &id , kDataBrowserItemNoProperty , kDataBrowserItemNoProperty ) ) ; OSStatus err = m_peer->UpdateItems(
kDataBrowserNoItem, 1, &id,
kDataBrowserItemNoProperty, kDataBrowserItemNoProperty );
verify_noerr( err );
} }
} }
@@ -348,10 +367,9 @@ void wxCheckListBox::Check(size_t item, bool check)
void wxCheckListBox::Delete(int n) void wxCheckListBox::Delete(int n)
{ {
wxCHECK_RET( n < GetCount(), _T("invalid index in wxCheckListBox::Delete") ); wxCHECK_RET( (size_t)n < GetCount(), wxT("invalid index in wxCheckListBox::Delete") );
wxListBox::Delete( n ); wxListBox::Delete( n );
m_checks.RemoveAt( n ); m_checks.RemoveAt( n );
} }

View File

@@ -9,10 +9,6 @@
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
//-------------------------------------------------------------------------------------
// headers
//-------------------------------------------------------------------------------------
#include "wx/wxprec.h" #include "wx/wxprec.h"
#if wxUSE_RADIOBOX #if wxUSE_RADIOBOX
@@ -433,7 +429,7 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
y_offset = y_start; y_offset = y_start;
current = m_radioButtonCycle; current = m_radioButtonCycle;
for ( i = 0 ; i < m_noItems; i++) for (i = 0 ; i < (int)m_noItems; i++)
{ {
// not to do for the zero button! // not to do for the zero button!
if ((i > 0) && ((i % GetMajorDim()) == 0)) if ((i > 0) && ((i % GetMajorDim()) == 0))