예제 #1
0
파일: ListViews.cpp 프로젝트: DonCN/haiku
// InitiateDrag
bool
DragSortableListView::InitiateDrag(BPoint point, int32 index, bool)
{
	// supress drag&drop while an item is focused
	if (fFocusedIndex >= 0)
		return false;

	bool success = false;
	BListItem* item = ItemAt(CurrentSelection(0));
	if (!item) {
		// workarround a timing problem
		Select(index);
		item = ItemAt(index);
	}
	if (item) {
		// create drag message
		BMessage msg(fDragCommand);
		MakeDragMessage(&msg);
		// figure out drag rect
		float width = Bounds().Width();
		BRect dragRect(0.0, 0.0, width, -1.0);
		// figure out, how many items fit into our bitmap
		int32 numItems;
		bool fade = false;
		for (numItems = 0; BListItem* item = ItemAt(CurrentSelection(numItems)); numItems++) {
			dragRect.bottom += ceilf(item->Height()) + 1.0;
			if (dragRect.Height() > MAX_DRAG_HEIGHT) {
				fade = true;
				dragRect.bottom = MAX_DRAG_HEIGHT;
				numItems++;
				break;
			}
		}
		BBitmap* dragBitmap = new BBitmap(dragRect, B_RGB32, true);
		if (dragBitmap && dragBitmap->IsValid()) {
			if (BView *v = new BView(dragBitmap->Bounds(), "helper",
									 B_FOLLOW_NONE, B_WILL_DRAW)) {
				dragBitmap->AddChild(v);
				dragBitmap->Lock();
				BRect itemBounds(dragRect) ;
				itemBounds.bottom = 0.0;
				// let all selected items, that fit into our drag_bitmap, draw
				for (int32 i = 0; i < numItems; i++) {
					int32 index = CurrentSelection(i);
					BListItem* item = ItemAt(index);
					itemBounds.bottom = itemBounds.top + ceilf(item->Height());
					if (itemBounds.bottom > dragRect.bottom)
						itemBounds.bottom = dragRect.bottom;
					DrawListItem(v, index, itemBounds);
					itemBounds.top = itemBounds.bottom + 1.0;
				}
				// make a black frame arround the edge
				v->SetHighColor(0, 0, 0, 255);
				v->StrokeRect(v->Bounds());
				v->Sync();
	
				uint8 *bits = (uint8 *)dragBitmap->Bits();
				int32 height = (int32)dragBitmap->Bounds().Height() + 1;
				int32 width = (int32)dragBitmap->Bounds().Width() + 1;
				int32 bpr = dragBitmap->BytesPerRow();
	
				if (fade) {
					for (int32 y = 0; y < height - ALPHA / 2; y++, bits += bpr) {
						uint8 *line = bits + 3;
						for (uint8 *end = line + 4 * width; line < end; line += 4)
							*line = ALPHA;
					}
					for (int32 y = height - ALPHA / 2; y < height; y++, bits += bpr) {
						uint8 *line = bits + 3;
						for (uint8 *end = line + 4 * width; line < end; line += 4)
							*line = (height - y) << 1;
					}
				} else {
					for (int32 y = 0; y < height; y++, bits += bpr) {
						uint8 *line = bits + 3;
						for (uint8 *end = line + 4 * width; line < end; line += 4)
							*line = ALPHA;
					}
				}
				dragBitmap->Unlock();
			}
		} else {
			delete dragBitmap;
			dragBitmap = NULL;
		}
		if (dragBitmap)
			DragMessage(&msg, dragBitmap, B_OP_ALPHA, BPoint(0.0, 0.0));
		else
			DragMessage(&msg, dragRect.OffsetToCopy(point), this);

		_SetDragMessage(&msg);
		success = true;
	}
	return success;
}
예제 #2
0
static int canvasFunc( ClientData data, Tcl_Interp *interp,
      int objc, Tcl_Obj * const objv[] )
{
   const char *cmds[] = { "delete", "configure", "cget", "isMapped",
         "getCurrentSize", "update", "raise", "lower", 
         "create", "itemDelete", "itemShow",
         "itemConfigure", "itemCget", "itemCommand", 
         "affine", "scale", "move", "rotate",
         "windowToCanvas", "canvasToWindow",
         "findItemAt", "getBounds", "findWithTag",
         NULL };
   enum cmdIdx { DeleteIdx, ConfigureIdx, CgetIdx, IsMappedIdx,
         GetCurSizeIdx, UpdateIdx, RaiseIdx, LowerIdx,
         CreateIdx, ItemDeleteIdx, ItemShowIdx,
         ItemConfigureIdx, ItemCgetIdx, ItemCommandIdx, 
         AffineIdx, ScaleIdx, MoveIdx, RotateIdx,
         WindowToCanvasIdx, CanvasToWindowIdx,
         FindItemAtIdx, GetBoundsIdx, GetIDsFromTagIdx };
   CanvasParams *para = (CanvasParams *)data;
   GtkWidget    *widget = GTK_WIDGET( para->canvas );
   int idx;

   if( objc < 2 )
   {
      Tcl_WrongNumArgs( interp, 1, objv, "command" );
      return TCL_ERROR;
   }

   if( Tcl_GetIndexFromObj( interp, objv[1], cmds, "command", 
         TCL_EXACT, &idx ) != TCL_OK )
      return TCL_ERROR;

   switch( idx )
   {
      case DeleteIdx:
            return gnoclDelete( interp, widget, objc, objv );

      case ConfigureIdx:
            {
               int ret = TCL_ERROR;
               if( gnoclParseAndSetOptions( interp, objc - 1, objv + 1, 
                     canvasOptions, G_OBJECT( widget ) ) == TCL_OK )
               {

                  if( canvasOptions[antialiasedIdx].status 
                        == GNOCL_STATUS_CHANGED )
                  {
                     Tcl_SetResult( interp, "antialiasing cannot be changed "
                           "after creation", TCL_STATIC );
                  }
                  else
                     ret = configure( interp, para, canvasOptions );
               }
               gnoclClearOptions( canvasOptions );
               return ret;
            }
            break;
      case CgetIdx:
            {
               int     idx;
               switch( gnoclCget( interp, objc, objv, G_OBJECT( widget ), 
                     canvasOptions, &idx ) )
               {
                  case GNOCL_CGET_ERROR:  
                           return TCL_ERROR;
                  case GNOCL_CGET_HANDLED:
                           return TCL_OK;
                  case GNOCL_CGET_NOTHANDLED:
                           return cget( interp, para->canvas, 
                                 canvasOptions, idx );
               }
               break;
            }
      case IsMappedIdx:
            return isMapped( interp, widget, objc, objv );
      case GetCurSizeIdx:
            return getCurSize( interp, widget, objc, objv );
      case UpdateIdx:
            if( objc != 2 )
            {
               Tcl_WrongNumArgs( interp, 2, objv, NULL );
               return TCL_ERROR;
            }
            gnome_canvas_update_now( para->canvas );
            break;
      case CreateIdx:
            return canvasCreateItem( interp, objc, objv, para );
      case RaiseIdx:
      case LowerIdx:
      case ItemDeleteIdx:
      case ItemShowIdx:
      case ItemConfigureIdx:
      case ItemCgetIdx:
      case ItemCommandIdx:
      case AffineIdx:
      case ScaleIdx:
      case MoveIdx:
      case RotateIdx:
      case GetBoundsIdx:
      case GetIDsFromTagIdx:
            {
               GPtrArray *items;
               int       ret;

               if( objc < 3 )
               {
                  Tcl_WrongNumArgs( interp, 2, objv, 
                        "tag-or-id ?option val ...?" );
                  return TCL_ERROR;
               }
               if( gnoclCanvasItemsFromTagOrId( interp, para, 
                     Tcl_GetString( objv[2] ), &items ) != TCL_OK )
                  return TCL_ERROR;

               switch( idx )
               {
                  case RaiseIdx:
                  case LowerIdx:
                     ret = itemRaise( interp, objc, objv, para, items,
                           idx == RaiseIdx );
                     break;
                  case ItemDeleteIdx:
                     ret = itemDelete( interp, objc, objv, para, items );
                     break;
                  case ItemShowIdx:
                     ret = itemShow( interp, objc, objv, para, items );
                     break;
                  case ItemConfigureIdx:
                     ret = itemConfigure( interp, objc, objv, para, items );
                     break;
                  case ItemCgetIdx:
                     ret = itemCget( interp, objc, objv, para, items );
                     break;
                  case ItemCommandIdx:
                     ret = itemCommand( interp, objc, objv, para, items );
                     break;
                  case AffineIdx:
                     ret = affine( interp, objc, objv, para, items, Affine );
                     break;
                  case ScaleIdx:
                     ret = affine( interp, objc, objv, para, items, Scale );
                     break;
                  case MoveIdx:
                     ret = affine( interp, objc, objv, para, items, Move );
                     break;
                  case RotateIdx:
                     ret = affine( interp, objc, objv, para, items, Rotate );
                     break;
                  case GetBoundsIdx:
                     ret = itemBounds( interp, objc, objv, para, items );
                     break;
                  case GetIDsFromTagIdx:
                     ret = getIDs( interp, objc, objv, para, items );
                     break;
                  default:
                     assert( 0 );
               }
               if( items )
                  g_ptr_array_free( items, 0 );
               return ret;
            }
            break; 
      case WindowToCanvasIdx:
            return windowToCanvas( interp, objc, objv, para, 0 );
      case CanvasToWindowIdx:
            return windowToCanvas( interp, objc, objv, para, 1 );
      case FindItemAtIdx:
            return findItemAt( interp, objc, objv, para );
   }

   return TCL_OK;
}
예제 #3
0
bool
AudioListView::InitiateDrag(BPoint point, int32 dragIndex, bool)
{
	BListItem* item = ItemAt(CurrentSelection(0));
	if (item == NULL) {
		// workaround for a timing problem (see Locale prefs)
		Select(dragIndex);
		item = ItemAt(dragIndex);
	}
	if (item == NULL)
		return false;

	// create drag message
	BMessage message(kDraggedItem);
	for (int32 i = 0;; i++) {
		int32 index = CurrentSelection(i);
		if (index < 0)
			break;
		message.AddPointer("trackitem", ItemAt(CurrentSelection(i)));
	}

	// figure out drag rect
	BRect dragRect(0.0, 0.0, Bounds().Width(), -1.0);

	// figure out, how many items fit into our bitmap
	bool fade = false;

	for (int32 i = 0; message.FindPointer("trackitem", i,
		reinterpret_cast<void**>(&item)) == B_OK; i++) {

		dragRect.bottom += ceilf(item->Height()) + 1.0;

		if (dragRect.Height() > MAX_DRAG_HEIGHT) {
			dragRect.bottom = MAX_DRAG_HEIGHT;
			fade = true;
			break;
		}
	}

	BBitmap* dragBitmap = new BBitmap(dragRect, B_RGB32, true);
	if (dragBitmap->IsValid()) {
		BView* view = new BView(dragBitmap->Bounds(), "helper", B_FOLLOW_NONE,
			B_WILL_DRAW);
		dragBitmap->AddChild(view);
		dragBitmap->Lock();
		BRect itemBounds(dragRect) ;
		itemBounds.bottom = 0.0;
		// let all selected items, that fit into our drag_bitmap, draw
		for (int32 i = 0; message.FindPointer("trackitem", i,
				reinterpret_cast<void**>(&item)) == B_OK; i++) {
			AudioListItem* item;
			message.FindPointer("trackitem", i,
				reinterpret_cast<void**>(&item));
			itemBounds.bottom = itemBounds.top + ceilf(item->Height());
			if (itemBounds.bottom > dragRect.bottom)
				itemBounds.bottom = dragRect.bottom;
			item->DrawItem(view, itemBounds);
			itemBounds.top = itemBounds.bottom + 1.0;
		}
		// make a black frame around the edge
		view->SetHighColor(0, 0, 0, 255);
		view->StrokeRect(view->Bounds());
		view->Sync();

		uint8* bits = (uint8*)dragBitmap->Bits();
		int32 height = (int32)dragBitmap->Bounds().Height() + 1;
		int32 width = (int32)dragBitmap->Bounds().Width() + 1;
		int32 bpr = dragBitmap->BytesPerRow();

		if (fade) {
			for (int32 y = 0; y < height - ALPHA / 2; y++, bits += bpr) {
				uint8* line = bits + 3;
				for (uint8* end = line + 4 * width; line < end; line += 4)
					*line = ALPHA;
			}
			for (int32 y = height - ALPHA / 2; y < height;
				y++, bits += bpr) {
				uint8* line = bits + 3;
				for (uint8* end = line + 4 * width; line < end; line += 4)
					*line = (height - y) << 1;
			}
		} else {
			for (int32 y = 0; y < height; y++, bits += bpr) {
				uint8* line = bits + 3;
				for (uint8* end = line + 4 * width; line < end; line += 4)
					*line = ALPHA;
			}
		}
		dragBitmap->Unlock();
	} else {
		delete dragBitmap;
		dragBitmap = NULL;
	}

	if (dragBitmap != NULL)
		DragMessage(&message, dragBitmap, B_OP_ALPHA, BPoint(0.0, 0.0));
	else
		DragMessage(&message, dragRect.OffsetToCopy(point), this);

	return true;
}
bool
LanguageListView::InitiateDrag(BPoint point, int32 dragIndex,
	bool /*wasSelected*/)
{
	if (fDragMessage == NULL)
		return false;

	BListItem* item = ItemAt(CurrentSelection(0));
	if (item == NULL) {
		// workaround for a timing problem
		// TODO: this should support extending the selection
		item = ItemAt(dragIndex);
		Select(dragIndex);
	}
	if (item == NULL)
		return false;

	// create drag message
	BMessage message = *fDragMessage;
	message.AddPointer("listview", this);

	for (int32 i = 0;; i++) {
		int32 index = CurrentSelection(i);
		if (index < 0)
			break;

		message.AddInt32("index", index);
	}

	// figure out drag rect

	BRect dragRect(0.0, 0.0, Bounds().Width(), -1.0);
	int32 numItems = 0;
	bool fade = false;

	// figure out, how many items fit into our bitmap
	for (int32 i = 0, index; message.FindInt32("index", i, &index) == B_OK;
			i++) {
		BListItem* item = ItemAt(index);
		if (item == NULL)
			break;

		dragRect.bottom += ceilf(item->Height()) + 1.0;
		numItems++;

		if (dragRect.Height() > MAX_DRAG_HEIGHT) {
			dragRect.bottom = MAX_DRAG_HEIGHT;
			fade = true;
			break;
		}
	}

	BBitmap* dragBitmap = new BBitmap(dragRect, B_RGB32, true);
	if (dragBitmap->IsValid()) {
		BView* view = new BView(dragBitmap->Bounds(), "helper", B_FOLLOW_NONE,
			B_WILL_DRAW);
		dragBitmap->AddChild(view);
		dragBitmap->Lock();
		BRect itemBounds(dragRect) ;
		itemBounds.bottom = 0.0;
		// let all selected items, that fit into our drag_bitmap, draw
		for (int32 i = 0; i < numItems; i++) {
			int32 index = message.FindInt32("index", i);
			LanguageListItem* item
				= static_cast<LanguageListItem*>(ItemAt(index));
			itemBounds.bottom = itemBounds.top + ceilf(item->Height());
			if (itemBounds.bottom > dragRect.bottom)
				itemBounds.bottom = dragRect.bottom;
			item->DrawItem(view, itemBounds);
			itemBounds.top = itemBounds.bottom + 1.0;
		}
		// make a black frame arround the edge
		view->SetHighColor(0, 0, 0, 255);
		view->StrokeRect(view->Bounds());
		view->Sync();

		uint8* bits = (uint8*)dragBitmap->Bits();
		int32 height = (int32)dragBitmap->Bounds().Height() + 1;
		int32 width = (int32)dragBitmap->Bounds().Width() + 1;
		int32 bpr = dragBitmap->BytesPerRow();

		if (fade) {
			for (int32 y = 0; y < height - ALPHA / 2; y++, bits += bpr) {
				uint8* line = bits + 3;
				for (uint8* end = line + 4 * width; line < end; line += 4)
					*line = ALPHA;
			}
			for (int32 y = height - ALPHA / 2; y < height;
				y++, bits += bpr) {
				uint8* line = bits + 3;
				for (uint8* end = line + 4 * width; line < end; line += 4)
					*line = (height - y) << 1;
			}
		} else {
			for (int32 y = 0; y < height; y++, bits += bpr) {
				uint8* line = bits + 3;
				for (uint8* end = line + 4 * width; line < end; line += 4)
					*line = ALPHA;
			}
		}
		dragBitmap->Unlock();
	} else {
		delete dragBitmap;
		dragBitmap = NULL;
	}

	if (dragBitmap != NULL)
		DragMessage(&message, dragBitmap, B_OP_ALPHA, BPoint(0.0, 0.0));
	else
		DragMessage(&message, dragRect.OffsetToCopy(point), this);

	return true;
}