[ Home | CW Bug Reports | Mail ]
LTableMultiSelector::DragSelect()改良版
Subject: SUG -- LTableMultiSelector::DragSelect()
---------------------------------------------------------------------------
METROWERKS PRODUCT AND USAGE SECTION
Product name : [ CodeWarrior Gold ]
Product version : [ CW12 ]
Component name : [ PowerPlant ]
Generating: [ Mac OS 68K / Mac OS PowerPC ]
Purpose: [ application ]
---------------------------------------------------------------------------
SUGGESTION
Here is an LTableMultiSelector::DragSelect() code with better hilite
redrawing.
static void RedrawHilite(LTableView *tableView,RgnHandle rh,bool hilite)
{
if ( !::EmptyRgn(rh) ) {
const Rect r = (**rh).rgnBBox;
for ( TableIndexT row = r.top; row < r.bottom; row++ ) {
for ( TableIndexT col = r.left; col < r.right; col++ ) {
Point pt;
pt.v = row;
pt.h = col;
if ( ::PtInRgn(pt,rh) ) {
STableCell redrawCell(row,col);
tableView->HiliteCell(redrawCell,hilite);
}
}
}
}
}
Boolean
LTableMultiSelector::DragSelect(
const STableCell &inCell,
const SMouseDownEvent &inMouseDown)
{
Boolean inSameCell = true;
ClickSelect(inCell, inMouseDown); // First handle as a normal click
if (inMouseDown.macEvent.modifiers & cmdKey) {
// I really have no good idea what to do when the
// command key is down. Should it toggle the selection
// of the cells dragged over? Should it set a mode
// based on the state of the cell originally clicked,
// and then continue selecting or deselecting the cells
// dragged over?
// For the moment, do the simple thing and not support
// drag select when the command key is down.
return true;
}
STableCell currCell = inCell;
StRegion oldSel;
StRegion addSel;
StRegion delSel;
while (::StillDown()) {
STableCell hitCell;
SPoint32 imageLoc;
Point mouseLoc;
mTableView->FocusDraw();
::GetMouse(&mouseLoc);
if (mTableView->AutoScrollImage(mouseLoc)) {
mTableView->FocusDraw();
Rect frame;
mTableView->CalcLocalFrameRect(frame);
Int32 pt = ::PinRect(&frame, mouseLoc);
mouseLoc = *(Point*)&pt;
}
mTableView->LocalToImagePoint(mouseLoc, imageLoc);
mTableView->GetCellHitBy(imageLoc, hitCell);
if (currCell != hitCell) {
inSameCell = false;
if (mTableView->IsValidCell(hitCell)) {
// Right now, all cells between the Anchor cell and
// Curr cell are selected. New selection will be
// all cells between the Anchor and the Hit cell.
::CopyRgn(mSelectionRgn,oldSel);
TableIndexT left, top, right, bottom;
if (mAnchorCell.col < hitCell.col) {
left = mAnchorCell.col;
right = hitCell.col + 1;
}else{
left = hitCell.col;
right = mAnchorCell.col + 1;
}
if (mAnchorCell.row < hitCell.row) {
top = mAnchorCell.row;
bottom = hitCell.row + 1;
}else{
top = hitCell.row;
bottom = mAnchorCell.row + 1;
}
::SetRectRgn(mSelectionRgn,left,top,right,bottom);
::DiffRgn(oldSel,mSelectionRgn,delSel); // delSel = oldSel - mSelectionRgn
::DiffRgn(mSelectionRgn,oldSel,addSel); // addSel = mSelectionRgn - oldSel
RedrawHilite(mTableView,delSel,false);
RedrawHilite(mTableView,addSel,true);
currCell = hitCell;
}
}
}
return inSameCell;
}
この Pageは MacOS X + Radio UserLand で作っています。