///////////////////////////////////////////////////////////////////////////////
-// Name: checklst.cpp
+// Name: src/mac/classic/checklst.cpp
// Purpose: implementation of wxCheckListBox class
// Author: Stefan Csomor
-// Modified by:
+// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// headers & declarations
// ============================================================================
-#ifdef __GNUG__
-#pragma implementation "checklst.h"
-#endif
-
-#include "wx/defs.h"
+#include "wx/wxprec.h"
#if wxUSE_CHECKLISTBOX
list = (wxCheckListBox*) GetControlReference( (ControlHandle) GetListRefCon(listHandle) );
if ( list == NULL )
return ;
-
+
GrafPtr savePort;
GrafPtr grafPtr;
RgnHandle savedClipRegion;
SetPort((**listHandle).port);
grafPtr = (**listHandle).port ;
// typecast our refCon
-
+
// Calculate the cell rect.
-
+
switch( message ) {
case lInitMsg:
break;
// Save the current clip region, and set the clip region to the area we are about
// to draw.
-
+
savedClipRegion = NewRgn();
GetClip( savedClipRegion );
ClipRect( drawRect );
EraseRect( drawRect );
-
+
const wxFont& font = list->GetFont();
if ( font.Ok() )
{
::TextSize( font.GetMacFontSize()) ;
::TextFace( font.GetMacFontStyle() ) ;
}
-
+
ThemeButtonDrawInfo info ;
info.state = kThemeStateActive ;
info.value = checked ? kThemeButtonOn : kThemeButtonOff ;
info.adornment = kThemeAdornmentNone ;
Rect checkRect = *drawRect ;
-
-
+
+
checkRect.left +=0 ;
checkRect.top +=0 ;
checkRect.right = checkRect.left + list->m_checkBoxWidth ;
checkRect.bottom = checkRect.top + list->m_checkBoxHeight ;
DrawThemeButton(&checkRect,kThemeCheckBox,
&info,NULL,NULL, NULL,0);
-
+
MoveTo(drawRect->left + 2 + list->m_checkBoxWidth+2, drawRect->top + list->m_TextBaseLineOffset );
-
- DrawText(text, 0 , text.Length());
+
+ DrawText(text, 0 , text.length());
// If the cell is hilited, do the hilite now. Paint the cell contents with the
// appropriate QuickDraw transform mode.
-
+
if( isSelected ) {
savedPenMode = GetPortPenMode( (CGrafPtr) grafPtr );
SetPortPenMode( (CGrafPtr) grafPtr, hilitetransfermode );
PaintRect( drawRect );
SetPortPenMode( (CGrafPtr) grafPtr, savedPenMode );
}
-
+
// Restore the saved clip region.
-
+
SetClip( savedClipRegion );
DisposeRgn( savedClipRegion );
}
break;
case lHiliteMsg:
-
+
// Hilite or unhilite the cell. Paint the cell contents with the
// appropriate QuickDraw transform mode.
-
+
GetPort( &grafPtr );
savedPenMode = GetPortPenMode( (CGrafPtr) grafPtr );
SetPortPenMode( (CGrafPtr) grafPtr, hilitetransfermode );
default :
break ;
}
- SetPort(savePort);
+ SetPort(savePort);
}
extern "C" void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refCon) ;
m_noItems = 0 ; // this will be increased by our append command
m_selected = 0;
-
+
m_checkBoxWidth = 12;
m_checkBoxHeight= 10;
-
+
long h = m_checkBoxHeight ;
#if TARGET_CARBON
- GetThemeMetric(kThemeMetricCheckBoxWidth,(long *)&m_checkBoxWidth);
+ GetThemeMetric(kThemeMetricCheckBoxWidth,(long *)&m_checkBoxWidth);
GetThemeMetric(kThemeMetricCheckBoxHeight,&h);
#endif
FontInfo finfo;
FetchFontInfo(font.GetMacFontNum(),font.GetMacFontSize(),font.GetMacFontStyle(),&finfo);
-
+
m_TextBaseLineOffset= finfo.leading+finfo.ascent;
m_checkBoxHeight= finfo.leading+finfo.ascent+finfo.descent;
-
+
if (m_checkBoxHeight<h)
{
m_TextBaseLineOffset+= (h-m_checkBoxHeight)/2;
m_checkBoxHeight= h;
}
-
+
Rect bounds ;
Str255 title ;
-
+
MacPreControlCreate( parent , id , wxEmptyString , pos , size ,style, validator , name , &bounds , title ) ;
ListDefSpec listDef;
listDef.defType = kListDefUserProcType;
if ( macCheckListDefUPP == NULL )
{
- macCheckListDefUPP = NewListDefUPP( wxMacCheckListDefinition );
+ macCheckListDefUPP = NewListDefUPP( wxMacCheckListDefinition );
}
listDef.u.userProc = macCheckListDefUPP ;
long result ;
wxStAppResource resload ;
- m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false ,
- kwxMacListWithVerticalScrollbar , 0 , 0,
+ m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false ,
+ kwxMacListWithVerticalScrollbar , 0 , 0,
kControlListBoxProc , (long) this ) ;
::GetControlData( (ControlHandle) m_macControl , kControlNoPart , kControlListBoxListHandleTag ,
sizeof( ListHandle ) , (char*) &m_macList , &result ) ;
(**ldef).function = (void(*)()) listDef.u.userProc;
(**(ListHandle)m_macList).listDefProc = (Handle) ldef ;
}
-
+
Point pt = (**(ListHandle)m_macList).cellSize ;
pt.v = 14 ;
LCellSize( pt , (ListHandle)m_macList ) ;
options = (OptionBits) lOnlyOne ;
}
SetListSelectionFlags((ListHandle)m_macList, options);
-
+
MacPostControlCreate() ;
-
+
for ( int i = 0 ; i < n ; i++ )
{
Append( choices[i] ) ;
}
-
+
LSetDrawingMode( true , (ListHandle) m_macList ) ;
- return TRUE;
+ return true;
}
// ----------------------------------------------------------------------------
// wxCheckListBox functions
// ----------------------------------------------------------------------------
-bool wxCheckListBox::IsChecked(size_t item) const
+bool wxCheckListBox::IsChecked(unsigned int item) const
{
- wxCHECK_MSG( item < m_checks.GetCount(), FALSE,
+ wxCHECK_MSG( IsValid(item), false,
_T("invalid index in wxCheckListBox::IsChecked") );
return m_checks[item] != 0;
}
-void wxCheckListBox::Check(size_t item, bool check)
+void wxCheckListBox::Check(unsigned int item, bool check)
{
- wxCHECK_RET( item < m_checks.GetCount(),
+ wxCHECK_RET( IsValid(item),
_T("invalid index in wxCheckListBox::Check") );
// intermediate var is needed to avoid compiler warning with VC++
// methods forwarded to wxListBox
// ----------------------------------------------------------------------------
-void wxCheckListBox::Delete(int n)
+void wxCheckListBox::Delete(unsigned int n)
{
- wxCHECK_RET( n < GetCount(), _T("invalid index in wxListBox::Delete") );
+ wxCHECK_RET( IsValid(n), _T("invalid index in wxListBox::Delete") );
wxListBox::Delete(n);
int pos = wxListBox::DoAppend(item);
// the item is initially unchecked
- m_checks.Insert(FALSE, pos);
+ m_checks.Insert(false, pos);
LSetDrawingMode( true , (ListHandle) m_macList ) ;
return pos;
}
-void wxCheckListBox::DoInsertItems(const wxArrayString& items, int pos)
+void wxCheckListBox::DoInsertItems(const wxArrayString& items, unsigned int pos)
{
wxListBox::DoInsertItems(items, pos);
- size_t count = items.GetCount();
- for ( size_t n = 0; n < count; n++ )
+ unsigned int count = items.GetCount();
+ for ( unsigned int n = 0; n < count; n++ )
{
- m_checks.Insert(FALSE, pos + n);
+ m_checks.Insert(false, pos + n);
}
}
// call it first as it does DoClear()
wxListBox::DoSetItems(items, clientData);
- size_t count = items.GetCount();
- for ( size_t n = 0; n < count; n++ )
+ unsigned int count = items.GetCount();
+ for ( unsigned int n = 0; n < count; n++ )
{
- m_checks.Add(FALSE);
+ m_checks.Add(false);
}
}
EVT_LEFT_DOWN(wxCheckListBox::OnLeftClick)
END_EVENT_TABLE()
-// this will only work as soon as
+// this will only work as soon as
void wxCheckListBox::OnChar(wxKeyEvent& event)
{
topcell = (**(ListHandle)m_macList).visible.top ;
#endif
size_t nItem = ((size_t)event.GetY()) / lineheight + topcell ;
-
- if ( nItem < (size_t)m_noItems )
+
+ if ( nItem < m_noItems )
{
Check(nItem, !IsChecked(nItem) ) ;
wxCommandEvent event(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, GetId());