kivio

kivio_spawner_drag.cpp
1/*
2 * Kivio - Visual Modelling and Flowcharting
3 * Copyright (C) 2000-2001 theKompany.com & Dave Marotti
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19#include "kivio_spawner_drag.h"
20
21#include "kivio_stencil_spawner.h"
22#include "kivio_stencil_spawner_info.h"
23#include "kivio_stencil_spawner_set.h"
24#include "kivio_icon_view.h"
25
26#include <kdebug.h>
27
28KivioSpawnerDrag::KivioSpawnerDrag( KivioIconView *view, TQWidget *parent, const char *name )
29 : TQIconDrag( parent, name )
30{
31 m_pView = view;
32}
33
34KivioSpawnerDrag::~KivioSpawnerDrag()
35{
36 m_pView->clearCurrentDrag();
37 kdDebug(43000) << "KivioSpawnerDrag - this destroyed" << endl;
38}
39
40const char *KivioSpawnerDrag::format( int i ) const
41{
42 if( i==0 )
43 return "application/x-qiconlist";
44 else if( i==1 )
45 return "kivio/stencilSpawner";
46 else
47 return 0L;
48}
49
50TQByteArray KivioSpawnerDrag::encodedData( const char *mime ) const
51{
52 TQByteArray a;
53
54 if( TQString(mime) == "application/x-qiconlist" )
55 {
56 a = TQIconDrag::encodedData(mime);
57 }
58 else if( TQString(mime) == "kivio/stencilSpawner" )
59 {
60 TQString s = m_spawners.join("\r\n");
61 a.resize(s.length());
62 memcpy( a.data(), s.latin1(), s.length() );
63 }
64
65 return a;
66}
67
68bool KivioSpawnerDrag::canDecode( TQMimeSource *e )
69{
70 return e->provides( "application/x-qiconlist" ) ||
71 e->provides( "kivio/stencilSpawner" );
72}
73
74void KivioSpawnerDrag::append( const TQIconDragItem &item, const TQRect &pr,
75 const TQRect &tr, KivioStencilSpawner &spawner )
76{
77 TQIconDrag::append( item, pr, tr );
78
79 TQString full = spawner.set()->dir() + "/" + spawner.info()->title();
80
81 kdDebug(43000) << "KivioSpawnerDrag::append() - Adding " << full << endl;
82
83 m_spawners << full;
84}