CW5.2 Pro Adaptions, wxMac starting to move in
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4366 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -18,10 +18,22 @@
|
||||
#include "wx/dynarray.h"
|
||||
#include "wx/log.h"
|
||||
|
||||
#include "wx/utils.h"
|
||||
#include "extldef.h"
|
||||
|
||||
#if !USE_SHARED_LIBRARY
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxListBox, wxControl)
|
||||
|
||||
BEGIN_EVENT_TABLE(wxListBox, wxControl)
|
||||
EVT_SIZE( wxListBox::OnSize )
|
||||
END_EVENT_TABLE()
|
||||
#endif
|
||||
|
||||
#include <wx/mac/uma.h>
|
||||
|
||||
extern "C" void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refCon) ;
|
||||
const short kwxMacListWithVerticalScrollbar = 128 ;
|
||||
|
||||
// ============================================================================
|
||||
// list box control implementation
|
||||
// ============================================================================
|
||||
@@ -41,111 +53,197 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id,
|
||||
const wxValidator& validator,
|
||||
const wxString& name)
|
||||
{
|
||||
m_noItems = n;
|
||||
m_noItems = 0 ; // this will be increased by our append command
|
||||
m_selected = 0;
|
||||
|
||||
SetName(name);
|
||||
SetValidator(validator);
|
||||
Rect bounds ;
|
||||
Str255 title ;
|
||||
m_macHorizontalBorder = 5 ; // additional pixels around the real control
|
||||
m_macVerticalBorder = 5 ;
|
||||
|
||||
MacPreControlCreate( parent , id , "" , pos , size ,style, validator , name , &bounds , title ) ;
|
||||
|
||||
if (parent) parent->AddChild(this);
|
||||
m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , kwxMacListWithVerticalScrollbar , 0 , 0,
|
||||
kControlListBoxProc , (long) this ) ;
|
||||
|
||||
long result ;
|
||||
UMAGetControlData( m_macControl , kControlNoPart , kControlListBoxListHandleTag , sizeof( ListHandle ) , (char*) &m_macList , &result ) ;
|
||||
|
||||
wxSystemSettings settings;
|
||||
SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW));
|
||||
NewExtLDEFInfo( m_macList , MacDrawStringCell , (long) this ) ;
|
||||
(**m_macList).selFlags = lOnlyOne ;
|
||||
if ( style & wxLB_MULTIPLE )
|
||||
{
|
||||
(**m_macList).selFlags += lNoExtend ;
|
||||
}
|
||||
else if ( style & wxLB_EXTENDED )
|
||||
{
|
||||
(**m_macList).selFlags += lExtendDrag ;
|
||||
}
|
||||
Point pt = (**m_macList).cellSize ;
|
||||
pt.v = 14 ;
|
||||
LCellSize( pt , m_macList ) ;
|
||||
|
||||
m_windowId = ( id == -1 ) ? (int)NewControlId() : id;
|
||||
LAddColumn( 1 , 0 , m_macList ) ;
|
||||
|
||||
// TODO create listbox
|
||||
MacPostControlCreate() ;
|
||||
|
||||
return FALSE;
|
||||
ControlFontStyleRec controlstyle ;
|
||||
controlstyle.flags = kControlUseFontMask + kControlUseSizeMask ;
|
||||
//controlstyle.font = kControlFontSmallSystemFont ;
|
||||
controlstyle.font = kFontIDMonaco ;
|
||||
controlstyle.size = 9 ;
|
||||
::UMASetControlFontStyle( m_macControl , &controlstyle ) ;
|
||||
|
||||
for ( int i = 0 ; i < n ; i++ )
|
||||
{
|
||||
Append( choices[i] ) ;
|
||||
}
|
||||
|
||||
LSetDrawingMode( true , m_macList ) ;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
wxListBox::~wxListBox()
|
||||
{
|
||||
// DisposeExtLDEFInfo( m_macList ) ;
|
||||
}
|
||||
|
||||
void wxListBox::SetFirstItem(int N)
|
||||
{
|
||||
// TODO
|
||||
MacScrollTo( N ) ;
|
||||
}
|
||||
|
||||
void wxListBox::SetFirstItem(const wxString& s)
|
||||
{
|
||||
// TODO
|
||||
MacScrollTo( FindString( s ) ) ;
|
||||
}
|
||||
|
||||
void wxListBox::Delete(int N)
|
||||
{
|
||||
m_noItems --;
|
||||
// TODO
|
||||
m_dataArray.Remove( N ) ;
|
||||
m_stringArray.Remove( N ) ;
|
||||
m_noItems --;
|
||||
|
||||
MacDelete( N ) ;
|
||||
}
|
||||
|
||||
void wxListBox::Append(const wxString& item)
|
||||
{
|
||||
m_noItems ++;
|
||||
|
||||
// TODO
|
||||
Append( item , NULL ) ;
|
||||
}
|
||||
|
||||
void wxListBox::Append(const wxString& item, char *Client_data)
|
||||
{
|
||||
m_noItems ++;
|
||||
|
||||
// TODO
|
||||
if( wxApp::s_macDefaultEncodingIsPC )
|
||||
{
|
||||
m_stringArray.Add( wxMacMakeMacStringFromPC( item ) ) ;
|
||||
}
|
||||
else
|
||||
m_stringArray.Add( item ) ;
|
||||
m_dataArray.Add( Client_data ) ;
|
||||
m_noItems ++;
|
||||
|
||||
MacAppend( item ) ;
|
||||
}
|
||||
|
||||
void wxListBox::Set(int n, const wxString *choices, char** clientData)
|
||||
{
|
||||
m_noItems = n;
|
||||
|
||||
// TODO
|
||||
Clear() ;
|
||||
for( int i = 0 ; i < n ; ++i )
|
||||
{
|
||||
if ( clientData )
|
||||
Append( choices[i] , clientData[0] ) ;
|
||||
else
|
||||
Append( choices[i] ) ;
|
||||
}
|
||||
}
|
||||
|
||||
int wxListBox::FindString(const wxString& s) const
|
||||
int wxListBox::FindString(const wxString& st) const
|
||||
{
|
||||
// TODO
|
||||
return -1;
|
||||
wxString s ;
|
||||
if( wxApp::s_macDefaultEncodingIsPC )
|
||||
{
|
||||
s = wxMacMakeMacStringFromPC( st ) ;
|
||||
}
|
||||
else
|
||||
s = st ;
|
||||
|
||||
if ( s.Right(1) == "*" )
|
||||
{
|
||||
wxString search = s.Left( s.Length() - 1 ) ;
|
||||
int len = search.Length() ;
|
||||
for ( int i = 0 ; i < m_noItems ; ++ i )
|
||||
{
|
||||
if ( equalstring( m_stringArray[i].Left( len ) , search , false , false ) )
|
||||
return i ;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for ( int i = 0 ; i < m_noItems ; ++ i )
|
||||
{
|
||||
if ( equalstring( m_stringArray[i] , s , false , false ) )
|
||||
return i ;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void wxListBox::Clear()
|
||||
{
|
||||
m_noItems = 0;
|
||||
// TODO
|
||||
m_stringArray.Empty() ;
|
||||
m_dataArray.Empty() ;
|
||||
MacClear() ;
|
||||
}
|
||||
|
||||
void wxListBox::SetSelection(int N, bool select)
|
||||
{
|
||||
// TODO
|
||||
wxCHECK_RET( N >= 0 && N < m_noItems,
|
||||
"invalid index in wxListBox::SetSelection" );
|
||||
MacSetSelection( N , select ) ;
|
||||
}
|
||||
|
||||
bool wxListBox::Selected(int N) const
|
||||
{
|
||||
// TODO
|
||||
return FALSE;
|
||||
wxCHECK_MSG( N >= 0 && N < m_noItems, FALSE,
|
||||
"invalid index in wxListBox::Selected" );
|
||||
|
||||
return MacIsSelected( N ) ;
|
||||
}
|
||||
|
||||
void wxListBox::Deselect(int N)
|
||||
{
|
||||
// TODO
|
||||
wxCHECK_RET( N >= 0 && N < m_noItems,
|
||||
"invalid index in wxListBox::Deselect" );
|
||||
|
||||
SetSelection( N , false ) ;
|
||||
}
|
||||
|
||||
char *wxListBox::GetClientData(int N) const
|
||||
{
|
||||
// TODO
|
||||
return (char *)NULL;
|
||||
wxCHECK_MSG( N >= 0 && N < m_noItems, NULL,
|
||||
"invalid index in wxListBox::GetClientData" );
|
||||
|
||||
return m_dataArray[N];
|
||||
}
|
||||
|
||||
void wxListBox::SetClientData(int N, char *Client_data)
|
||||
{
|
||||
// TODO
|
||||
wxCHECK_RET( N >= 0 && N < m_noItems,
|
||||
"invalid index in wxListBox::SetClientData" );
|
||||
|
||||
m_dataArray[N] = Client_data ;
|
||||
}
|
||||
|
||||
// Return number of selections and an array of selected integers
|
||||
int wxListBox::GetSelections(wxArrayInt& aSelections) const
|
||||
{
|
||||
aSelections.Empty();
|
||||
return MacGetSelections( aSelections ) ;
|
||||
|
||||
/* TODO
|
||||
if ((m_windowStyle & wxLB_MULTIPLE) || (m_windowStyle & wxLB_EXTENDED))
|
||||
if ((m_windowStyle & wxLB_MULTIMacE) || (m_windowStyle & wxLB_EXTENDED))
|
||||
{
|
||||
int no_sel = ??
|
||||
for ( int n = 0; n < no_sel; n++ )
|
||||
@@ -160,38 +258,41 @@ int wxListBox::GetSelections(wxArrayInt& aSelections) const
|
||||
return 1;
|
||||
}
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Get single selection, for single choice list items
|
||||
int wxListBox::GetSelection() const
|
||||
{
|
||||
// TODO
|
||||
return -1;
|
||||
return MacGetSelection() ;
|
||||
}
|
||||
|
||||
// Find string for position
|
||||
wxString wxListBox::GetString(int N) const
|
||||
{
|
||||
// TODO
|
||||
return wxString("");
|
||||
}
|
||||
|
||||
void wxListBox::SetSize(int x, int y, int width, int height, int sizeFlags)
|
||||
{
|
||||
// TODO
|
||||
if( wxApp::s_macDefaultEncodingIsPC )
|
||||
{
|
||||
return wxMacMakePCStringFromMac( m_stringArray[N] ) ;
|
||||
}
|
||||
else
|
||||
return m_stringArray[N] ;
|
||||
}
|
||||
|
||||
void wxListBox::InsertItems(int nItems, const wxString items[], int pos)
|
||||
{
|
||||
m_noItems += nItems;
|
||||
for ( int i = 0 ; i < nItems ; i++ )
|
||||
{
|
||||
m_stringArray.Insert( items[i] , pos + i ) ;
|
||||
m_dataArray.Insert( NULL , pos + i ) ;
|
||||
MacInsert( pos + i , items[i] ) ;
|
||||
}
|
||||
|
||||
// TODO
|
||||
m_noItems += nItems;
|
||||
}
|
||||
|
||||
void wxListBox::SetString(int N, const wxString& s)
|
||||
{
|
||||
// TODO
|
||||
m_stringArray[N] = s ;
|
||||
MacSet( N , s ) ;
|
||||
}
|
||||
|
||||
int wxListBox::Number () const
|
||||
@@ -204,7 +305,9 @@ wxString wxListBox::GetStringSelection () const
|
||||
{
|
||||
int sel = GetSelection ();
|
||||
if (sel > -1)
|
||||
return this->GetString (sel);
|
||||
{
|
||||
return GetString (sel);
|
||||
}
|
||||
else
|
||||
return wxString("");
|
||||
}
|
||||
@@ -233,3 +336,182 @@ void wxListBox::Command (wxCommandEvent & event)
|
||||
ProcessCommand (event);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// list box control implementation
|
||||
// ============================================================================
|
||||
|
||||
void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refCon)
|
||||
{
|
||||
wxListBox* list;
|
||||
// typecast our refCon
|
||||
list = (wxListBox*)refCon;
|
||||
|
||||
MoveTo(cellRect->left + 4 , cellRect->top + 10 );
|
||||
const wxString text = list->m_stringArray[lCell.v] ;
|
||||
::TextFont( kFontIDMonaco ) ;
|
||||
::TextSize( 9 );
|
||||
::TextFace( 0 ) ;
|
||||
DrawText(text, 0 , text.Length());
|
||||
|
||||
}
|
||||
|
||||
void wxListBox::MacDelete( int N )
|
||||
{
|
||||
ListHandle list ;
|
||||
long result ;
|
||||
Cell cell = { 0 , 0 } ;
|
||||
UMAGetControlData( m_macControl , kControlNoPart , kControlListBoxListHandleTag , sizeof( ListHandle ) , (char*) &list , &result ) ;
|
||||
LDelRow( 1 , N , list ) ;
|
||||
}
|
||||
|
||||
void wxListBox::MacInsert( int n , const char * text)
|
||||
{
|
||||
Cell cell ;
|
||||
|
||||
cell.h = 0 ;
|
||||
cell.v = n ;
|
||||
|
||||
LAddRow( 1 , cell.v , m_macList ) ;
|
||||
}
|
||||
|
||||
void wxListBox::MacAppend( const char * text)
|
||||
{
|
||||
Cell cell = { 0 , 0 } ;
|
||||
cell.v = (**m_macList).dataBounds.bottom ;
|
||||
LAddRow( 1 , cell.v , m_macList ) ;
|
||||
}
|
||||
|
||||
void wxListBox::MacClear()
|
||||
{
|
||||
LDelRow( (**m_macList).dataBounds.bottom , 0 , m_macList ) ;
|
||||
}
|
||||
|
||||
void wxListBox::MacSetSelection( int n , bool select )
|
||||
{
|
||||
Cell cell = { 0 , 0 } ;
|
||||
if ( LGetSelect( TRUE , &cell , m_macList ) )
|
||||
{
|
||||
LSetSelect( false , cell , m_macList ) ;
|
||||
}
|
||||
|
||||
cell.v = n ;
|
||||
LSetSelect( select , cell , m_macList ) ;
|
||||
LAutoScroll( m_macList ) ;
|
||||
}
|
||||
|
||||
bool wxListBox::MacIsSelected( int n ) const
|
||||
{
|
||||
Cell cell = { 0 , 0 } ;
|
||||
cell.v = n ;
|
||||
return LGetSelect( false , &cell , m_macList ) ;
|
||||
}
|
||||
|
||||
void wxListBox::MacDestroy()
|
||||
{
|
||||
// DisposeExtLDEFInfo( m_macList ) ;
|
||||
}
|
||||
|
||||
int wxListBox::MacGetSelection() const
|
||||
{
|
||||
Cell cell = { 0 , 0 } ;
|
||||
if ( LGetSelect( true , &cell , m_macList ) )
|
||||
return cell.v ;
|
||||
else
|
||||
return -1 ;
|
||||
}
|
||||
|
||||
int wxListBox::MacGetSelections( wxArrayInt& aSelections ) const
|
||||
{
|
||||
int no_sel = 0 ;
|
||||
|
||||
aSelections.Empty();
|
||||
|
||||
Cell cell = { 0 , 0 } ;
|
||||
cell.v = 0 ;
|
||||
|
||||
while ( LGetSelect( true , &cell , m_macList ) )
|
||||
{
|
||||
aSelections.Add( cell.v ) ;
|
||||
no_sel++ ;
|
||||
cell.v++ ;
|
||||
}
|
||||
return no_sel ;
|
||||
}
|
||||
|
||||
void wxListBox::MacSet( int n , const char * text )
|
||||
{
|
||||
// our implementation does not store anything in the list
|
||||
// so we just have to redraw
|
||||
Cell cell = { 0 , 0 } ;
|
||||
cell.v = n ;
|
||||
LDraw( cell , m_macList ) ;
|
||||
}
|
||||
|
||||
void wxListBox::MacScrollTo( int n )
|
||||
{
|
||||
// TODO implement scrolling
|
||||
}
|
||||
|
||||
void wxListBox::OnSize( const wxSizeEvent &event)
|
||||
{
|
||||
Point pt = (**m_macList).cellSize ;
|
||||
pt.h = m_width - 15 /* scrollbar */ - m_macHorizontalBorder * 2 ;
|
||||
LCellSize( pt , m_macList ) ;
|
||||
}
|
||||
|
||||
void wxListBox::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
|
||||
{
|
||||
Boolean wasDoubleClick = false ;
|
||||
long result ;
|
||||
|
||||
UMAGetControlData( m_macControl , kControlNoPart , kControlListBoxDoubleClickTag , sizeof( wasDoubleClick ) , (char*) &wasDoubleClick , &result ) ;
|
||||
if ( !wasDoubleClick )
|
||||
{
|
||||
MacDoClick() ;
|
||||
}
|
||||
else
|
||||
{
|
||||
MacDoDoubleClick() ;
|
||||
}
|
||||
}
|
||||
|
||||
void wxListBox::MacSetRedraw( bool doDraw )
|
||||
{
|
||||
LSetDrawingMode( doDraw , m_macList ) ;
|
||||
|
||||
}
|
||||
|
||||
void wxListBox::MacDoClick()
|
||||
{
|
||||
wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, m_windowId);
|
||||
wxArrayInt aSelections;
|
||||
int count = GetSelections(aSelections);
|
||||
if ( count > 0 )
|
||||
{
|
||||
event.m_commandInt = aSelections[0] ;
|
||||
event.m_clientData = GetClientData(event.m_commandInt);
|
||||
wxString str(GetString(event.m_commandInt));
|
||||
if (str != "")
|
||||
event.m_commandString = copystring((char *)(const char *)str);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ;
|
||||
/*
|
||||
event.m_commandInt = -1 ;
|
||||
event.m_commandString = copystring("") ;
|
||||
*/
|
||||
}
|
||||
|
||||
event.SetEventObject( this );
|
||||
ProcessCommand(event);
|
||||
if (event.m_commandString)
|
||||
delete[] event.m_commandString ;
|
||||
}
|
||||
|
||||
void wxListBox::MacDoDoubleClick()
|
||||
{
|
||||
wxCommandEvent event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, m_windowId);
|
||||
event.SetEventObject( this );
|
||||
GetEventHandler()->ProcessEvent(event) ;
|
||||
}
|
||||
|
Reference in New Issue
Block a user