summaryrefslogtreecommitdiffstats
path: root/qtsharp/src/bindings/static/QtSignal.cs
blob: 0889f3b022a8e178ec71b52e4d794743b9fbd22f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
// QtSignal.cs - Signal/slot connection support for Qt#
//
// Copyright (C) 2002  Nick Zigarovich (nick@chemlab.org)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
//
// TODO
// o See about eliminating huge ConnectSignalTo* DisconnectSignalFrom* methods;
//   want to make methods for each connection case that deal with QtSignal and
//   QtSlot instances directly.
//

namespace Qt {
	using System;
	using System.Collections;
	using System.Runtime.InteropServices;
	using System.Reflection;

	internal class QtSignal: TQObject, IDisposable {
		internal static bool traceConnects;

		static QtSignal ()
		{
			traceConnects = false;
		}

		private TQObject sender;
		private string signal;
		private string name;
		private string args;
		private ArrayList slots;
		private ArrayList signals;

		public string Identifier {
			get { return MakeSigId(sender, signal); }
		}

		public TQObject Sender {
			get { return sender; }
		}

		public string Signal {
			get { return signal; }
		}

		public string Name {
			get { return name; }
		}

		public string Args {
			get { return args; }
		}

		public string MangledArgs {
			get { return MangleArgs(Args); }
		}

		public ArrayList Signals {
			get { return signals; }
		}

		public ArrayList Slots {
			get { return slots; }
		}

		public QtSignal (TQObject sender, string signal): base (NoSignalInit.Instance)
		{
			this.sender = sender;
			this.signal = signal;
			string[] sigspl = signal.Split(new char[] {'('});
			name = sigspl[0];
			args = "(" + sigspl[1];
			slots = new ArrayList();
			signals = new ArrayList();
		}

		[DllImport("libqtc", CharSet=CharSet.Ansi)]
		private static extern void qt_del_QObject (IntPtr obj);
		internal override void Delete ()
		{
			if (deleted) return;

			qt_del_QObject (rawObject);
			deleted = true;
		}

		public bool IsCSharpSignal()
		{
			return sender.CsSignalMap.Contains(signal);
		}

		internal static bool Connect(TQObject sender, string signal, TQObject receiver, string slot)
		{
			if (IsSlot(signal)) {
				return false;
				// throw new ArgumentException("Received a slot where a signal was expected");
			}

			if (IsSignal(slot))
				return ConnectSignalToSignal(sender, NormalizeParam(signal), receiver, NormalizeParam(slot));
			else
				return ConnectSignalToSlot(sender, NormalizeParam(signal), receiver, NormalizeParam(slot));
		}

		private static bool ConnectSignalToSlot(TQObject sender, string signal, TQObject receiver, string slot)
		{
			QtSignal sigobj;
			QtSlot slotobj = new QtSlot(receiver, slot);

			if (traceConnects)
				ErrMsg ("ConnectSignalToSlot: ({0}) {1}, {2}, ({3}) {4}, {5}", sender.RawObject, sender, signal,
																				receiver.RawObject, receiver, slot);

			// Connect C# signal to...
			if (sender.CsSignalMap.Contains(signal)) {
				sigobj = sender.CsSignalMap[signal];

				// ...a C# slot
				if (slotobj.IsCSharpSlot) {
					if (sigobj.Slots.Contains(slotobj))
						return false;

					sigobj.Slots.Add(slotobj);
					return true;
				}
				// ...a C++ slot
				else {
					// C++ slots are C# methods, so we should never get here.
					throw new ArgumentException(receiver+" has no slot '"+slot+"'");
				}
			}
			// Connect C++ signal to...
			else {
				// ...a C# slot
				if (slotobj.IsCSharpSlot) {
					string id = MakeSigId(sender, signal);

					if (!sender.CppSignalMap.Contains(id))
						sigobj = sender.CppSignalMap[id] = new QtSignal(sender, signal);
					else {
						sigobj = sender.CppSignalMap[id];

						if (sigobj.Slots.Contains(slotobj))
						 	return false;
					}

					Delegate del;
					string realsignal;

					switch (slotobj.Args) {
					case "()":
						del = Delegate.CreateDelegate (typeof (del_void), receiver, slotobj.Name);
						slotobj.WrapperPtr = csharp_connect_void (sender.RawObject, TQT_SIGNAL (signal), receiver.RawObject, del);
						break;
					case "(bool)":
						del = Delegate.CreateDelegate (typeof (del_bool), receiver, slotobj.Name);
						slotobj.WrapperPtr = csharp_connect_bool (sender.RawObject, TQT_SIGNAL (signal), receiver.RawObject, del);
						break;
					case "(short)":
						del = Delegate.CreateDelegate (typeof (del_short), receiver, slotobj.Name);
						slotobj.WrapperPtr = csharp_connect_short (sender.RawObject, TQT_SIGNAL (signal), receiver.RawObject, del);
						break;
					case "(int)":
						del = Delegate.CreateDelegate (typeof (del_int), receiver, slotobj.Name);
						slotobj.WrapperPtr = csharp_connect_int (sender.RawObject, TQT_SIGNAL (signal), receiver.RawObject, del);
						break;
					case "(long)":
						del = Delegate.CreateDelegate (typeof (del_long), receiver, slotobj.Name);
						slotobj.WrapperPtr = csharp_connect_long (sender.RawObject, TQT_SIGNAL (signal), receiver.RawObject, del);
						break;
					case "(float)":
						del = Delegate.CreateDelegate (typeof (del_float), receiver, slotobj.Name);
						slotobj.WrapperPtr = csharp_connect_float (sender.RawObject, TQT_SIGNAL (signal), receiver.RawObject, del);
						break;
					case "(double)":
						del = Delegate.CreateDelegate (typeof (del_double), receiver, slotobj.Name);
						slotobj.WrapperPtr = csharp_connect_double (sender.RawObject, TQT_SIGNAL (signal), receiver.RawObject, del);
						break;
					case "(TQString)":
						realsignal = sigobj.Name + "(const TQString&)";
						Console.WriteLine("Connecting signal, sigobj.Name = {0}, realsignal = {1}",
							sigobj.Name, realsignal);
						del = Delegate.CreateDelegate (typeof (del_QString), slotobj, "SlotBridge_QString");
						slotobj.WrapperPtr = csharp_connect_QString (sender.RawObject, TQT_SIGNAL (realsignal), receiver.RawObject, del);
						break;						
					case "(TQDockWindow)":
						realsignal = sigobj.Name + "(TQDockWindow*)";
						del = Delegate.CreateDelegate (typeof (del_QDockWindow), slotobj, "SlotBridge_QDockWindow");
						slotobj.WrapperPtr = csharp_connect_QDockWindow (sender.RawObject, TQT_SIGNAL (realsignal), receiver.RawObject, del);
						break;
					case "(TQDropEvent)":
						realsignal = sigobj.Name + "(TQDropEvent*)";
						del = Delegate.CreateDelegate (typeof (del_QDropEvent), slotobj, "SlotBridge_QDropEvent");
						slotobj.WrapperPtr = csharp_connect_QDropEvent (sender.RawObject, TQT_SIGNAL (realsignal), receiver.RawObject, del);
						break;
					case "(TQDropEvent,TQListViewItem)":
						realsignal = sigobj.Name + "(TQDropEvent*,TQListViewItem*)";
						del = Delegate.CreateDelegate (typeof (del_QDropEventQListViewItem), slotobj, "SlotBridge_QDropEventQListViewItem");
						slotobj.WrapperPtr = csharp_connect_QDropEventQListViewItem (sender.RawObject, TQT_SIGNAL (realsignal), receiver.RawObject, del);
						break;
					case "(TQIconViewItem)":
						realsignal = sigobj.Name + "(TQIconViewItem*)";
						del = Delegate.CreateDelegate (typeof (del_QIconViewItem), slotobj, "SlotBridge_QIconViewItem");
						slotobj.WrapperPtr = csharp_connect_QIconViewItem (sender.RawObject, TQT_SIGNAL (realsignal), receiver.RawObject, del);
						break;
					case "(TQListBoxItem)":
						realsignal = sigobj.Name + "(TQListBoxItem*)";
						del = Delegate.CreateDelegate (typeof (del_QListBoxItem), slotobj, "SlotBridge_QListBoxItem");
						slotobj.WrapperPtr = csharp_connect_QListBoxItem (sender.RawObject, TQT_SIGNAL (realsignal), receiver.RawObject, del);
						break;
					case "(TQListViewItem)":
						realsignal = sigobj.Name + "(TQListViewItem*)";
						del = Delegate.CreateDelegate (typeof (del_QListViewItem), slotobj, "SlotBridge_QListViewItem");
						slotobj.WrapperPtr = csharp_connect_QListViewItem (sender.RawObject, TQT_SIGNAL (realsignal), receiver.RawObject, del);
						break;
					case "(TQListViewItem,TQListViewItem)":
						realsignal = sigobj.Name + "(TQListViewItem*,TQListViewItem*)";
						del = Delegate.CreateDelegate (typeof (del_QListViewItemQListViewItem), slotobj, "SlotBridge_QListViewItemQListViewItem");
						slotobj.WrapperPtr = csharp_connect_QListViewItemQListViewItem (sender.RawObject, TQT_SIGNAL (realsignal), receiver.RawObject, del);
						break;
					case "(TQListViewItem,TQListViewItem,TQListViewItem)":
						realsignal = sigobj.Name + "(TQListViewItem*,TQListViewItem*,TQListViewItem*)";
						del = Delegate.CreateDelegate (typeof (del_QListViewItemQListViewItemQListViewItem), slotobj, "SlotBridge_QListViewItemQListViewItemQListViewItem");
						slotobj.WrapperPtr = csharp_connect_QListViewItemQListViewItemQListViewItem (sender.RawObject, TQT_SIGNAL (realsignal), receiver.RawObject, del);
						break;
					case "(TQNetworkOperation)":
						realsignal = sigobj.Name + "(TQNetworkOperation*)";
						del = Delegate.CreateDelegate (typeof (del_QNetworkOperation), slotobj, "SlotBridge_QNetworkOperation");
						slotobj.WrapperPtr = csharp_connect_QNetworkOperation (sender.RawObject, TQT_SIGNAL (realsignal), receiver.RawObject, del);
						break;
					case "(TQObject)":
						realsignal = sigobj.Name + "(TQObject*)";
						del = Delegate.CreateDelegate (typeof (del_QObject), slotobj, "SlotBridge_QObject");
						slotobj.WrapperPtr = csharp_connect_QObject (sender.RawObject, TQT_SIGNAL (realsignal), receiver.RawObject, del);
						break;
					case "(TQToolBar)":
						realsignal = sigobj.Name + "(TQToolBar*)";
						del = Delegate.CreateDelegate (typeof (del_QToolBar), slotobj, "SlotBridge_QToolBar");
						slotobj.WrapperPtr = csharp_connect_QToolBar (sender.RawObject, TQT_SIGNAL (realsignal), receiver.RawObject, del);
						break;
					case "(TQWidget)":
						realsignal = sigobj.Name + "(TQWidget*)";
						del = Delegate.CreateDelegate (typeof (del_QWidget), slotobj, "SlotBridge_QWidget");
						slotobj.WrapperPtr = csharp_connect_QWidget (sender.RawObject, TQT_SIGNAL (realsignal), receiver.RawObject, del);
						break;
					case "(int,TQIconViewItem)":
						realsignal = sigobj.Name + "(int,TQIconViewItem*)";
						del = Delegate.CreateDelegate (typeof (del_intQIconViewItem), slotobj, "SlotBridge_intQIconViewItem");
						slotobj.WrapperPtr = csharp_connect_intQIconViewItem (sender.RawObject, TQT_SIGNAL (realsignal), receiver.RawObject, del);
						break;
					case "(int,TQListBoxItem)":
						realsignal = sigobj.Name + "(int,TQListBoxItem*)";
						del = Delegate.CreateDelegate (typeof (del_intQListBoxItem), slotobj, "SlotBridge_intQListBoxItem");
						slotobj.WrapperPtr = csharp_connect_intQListBoxItem (sender.RawObject, TQT_SIGNAL (realsignal), receiver.RawObject, del);
						break;
					case "(int,bool)":
						del = Delegate.CreateDelegate (typeof (del_intbool), receiver, slotobj.Name);
						slotobj.WrapperPtr = csharp_connect_intbool (sender.RawObject, TQT_SIGNAL (signal), receiver.RawObject, del);
						break;
					case "(int,int)":
						del = Delegate.CreateDelegate (typeof (del_intint), receiver, slotobj.Name);
						slotobj.WrapperPtr = csharp_connect_intint (sender.RawObject, TQT_SIGNAL (signal), receiver.RawObject, del);
						break;
					case "(int,int,int)":
						del = Delegate.CreateDelegate (typeof (del_intintint), receiver, slotobj.Name);
						slotobj.WrapperPtr = csharp_connect_intintint (sender.RawObject, TQT_SIGNAL (signal), receiver.RawObject, del);
						break;
					default:
						throw new ArgumentException ("Unsupported method prototype for C++ signal -> C# slot connection: " + slotobj.Args);
					}

					if (slotobj.WrapperPtr == IntPtr.Zero)
						return false;

					slotobj.Callback = del;

					sigobj.Slots.Add(slotobj);
					return true;
				}
				// ...a C++ slot. C++ slots are C# methods, so we should never get here.
				else {
					throw new ArgumentException(receiver+" has no slot '"+slot+"'");
					// return qt_QObject_connect1(sender.RawObject, TQT_SIGNAL(signal), receiver.RawObject, TQT_SLOT(slot));
				}
			}
		}

		private static bool ConnectSignalToSignal(TQObject sender, string signal, TQObject receiver, string target)
		{
			if (traceConnects)
				ErrMsg ("ConnectSignalToSlot: ({0}) {1}, {2}, ({3}) {4}, {5}", sender.RawObject, sender, signal,
																				receiver.RawObject, receiver, target);

			// Connect C# signal to...
			if (sender.CsSignalMap.Contains(signal)) {
				QtSignal sigobj = sender.CsSignalMap[signal];

				// ...a C# signal
				if (receiver.CsSignalMap.Contains(target)) {
					QtSignal targetobj = receiver.CsSignalMap[target];

					if (sigobj.Signals.Contains(targetobj))
						return false;

					sigobj.Signals.Add(targetobj);
					return true;
				}
				// ...a C++ signal
				else
					throw new NotImplementedException("C# signal <-> C++ signal connections not supported yet");
			}
			// Connect C++ signal to...
			else {
				// ...a C# signal
				if (receiver.CsSignalMap.Contains(target)) {
					QtSignal targetobj = receiver.CsSignalMap[target];
					string args = targetobj.Args;
					string mangle = MangleArgs(args);

					// HACK Wrap target signal in a slot and connect the slot to the sender.
					return Connect(sender, TQT_SIGNAL(signal), targetobj, TQT_SLOT("Emit_"+mangle+args));
				}
				// ...a C++ signal
				else
					return qt_QObject_connect1(sender.RawObject, TQT_SIGNAL(signal), receiver.RawObject, TQT_SIGNAL(target));
			}
		}

		internal static bool Disconnect(TQObject sender, string signal, TQObject receiver, string slot)
		{
			if (signal == null && receiver == null && slot == null)
				return DisconnectAll(sender);
			else if (receiver == null && slot == null)
				return DisconnectSignal(sender, NormalizeParam(signal));
			else if (signal == null && slot == null)
				return DisconnectReceiver(sender, receiver);
			else if (slot == null)
				return DisconnectSignalFromReceiver(sender, NormalizeParam(signal), receiver);
			else if (IsSlot(signal))
				throw new ArgumentException ("Expected a signal where a slot was found.");
			else if (IsSignal(slot))
				return DisconnectSignalFromSignal(sender, NormalizeParam(signal), receiver, NormalizeParam(slot));
			else
				return DisconnectSignalFromSlot(sender, NormalizeParam(signal), receiver, NormalizeParam(slot));
		}

		private static bool DisconnectSignalFromSlot(TQObject sender, string signal, TQObject receiver, string slot)
		{
			if (traceConnects)
				ErrMsg ("DisconnectSignalFromSlot: ({0}) {1}, {2}, ({3}) {4}, {5}", sender.RawObject, sender, signal,
																					receiver.RawObject, receiver, slot);

			QtSignal sigobj;
			QtSlot slotobj = new QtSlot(receiver, slot);

			// Disconnect C# signal from...
			if (sender.CsSignalMap.Contains(signal)) {
				sigobj = sender.CsSignalMap[signal];

				// ...a C# slot
				if (slotobj.IsCSharpSlot) {
					if (!sigobj.Slots.Contains(slotobj))
						return false;

					sigobj.Slots.Remove(slotobj);
					return true;
				}
				// ...a C++ slot
				else {
					// C++ slots are C# methods, so we should never get here.
					throw new ArgumentException(receiver+" has no slot '"+slot+"'");
				}
			}
			// Disconnect C++ signal from...
			else {
				// ...a C# slot
				if (slotobj.IsCSharpSlot) {
					string id = MakeSigId(sender, signal);
					if (!sender.CppSignalMap.Contains(id))
						return false;

					sigobj = sender.CppSignalMap[id];
					bool found = false;
					foreach (QtSlot sobj in sigobj.Slots) {
						if (slotobj.Equals(sobj)) {
							found = true;
							qt_del_QObject(sobj.WrapperPtr);
							sigobj.Slots.Remove(sobj);
							break;
						}
					}

					if (sigobj.Slots.Count == 0)
						sender.CppSignalMap.Remove(id);

					return found;
				}
				// ...a C++ slot. C++ slots are C# methods, so we should never get here.
				else {
					throw new ArgumentException(receiver+" has no slot '"+slot+"'");
					// return qt_QObject_disconnect2(sender.RawObject, TQT_SIGNAL(signal), receiver.RawObject, TQT_SLOT(slot));
				}
			}
		}

		private static bool DisconnectSignalFromSignal(TQObject sender, string signal, TQObject receiver, string target)
		{
			if (traceConnects)
				ErrMsg ("DisconnectSignalFromSignal: ({0}) {1}, {2}, ({3}) {4}, {5}", sender.RawObject, sender, signal,
																						receiver.RawObject, receiver, target);

			QtSignal sigobj;

			// Disconnect C# signal from...
			if (sender.CsSignalMap.Contains(signal)) {
				sigobj = sender.CsSignalMap[signal];

				// ...a C# signal
				if (receiver.CsSignalMap.Contains(target)) {
					QtSignal targetobj = receiver.CsSignalMap[target];
					if (!sigobj.Signals.Contains(targetobj))
						return false;

					sigobj.Signals.Remove(targetobj);
					return true;
				}
				// ...a C++ signal
				else {
					throw new NotImplementedException("C# signal <-> C++ signal (dis)connections not supported yet");
				}
			}
			// Disconnect C++ signal from...
			else {
				sigobj = new QtSignal(sender, signal);

				// ...a C# signal
				if (receiver.CsSignalMap.Contains(target)) {
					QtSignal targetobj = receiver.CsSignalMap[target];
					string args = "(" + target.Split(new char[] {'('})[1];
					return Disconnect(sender, TQT_SIGNAL(signal), targetobj, TQT_SLOT("emit_"+args));
				}
				// ...a C++ signal
				else {
					return qt_QObject_disconnect2(sender.RawObject, TQT_SIGNAL(signal), receiver.RawObject, TQT_SLOT(target));
				}
			}
		}

		private static bool DisconnectAll(TQObject sender)
		{
			if (traceConnects)
				ErrMsg ("DisconnectAll: ({0}) {1}", sender.RawObject, sender);

			IDictionaryEnumerator cse = sender.CsSignalMap.GetEnumerator();
			IDictionaryEnumerator cppe = sender.CppSignalMap.GetEnumerator();

			ArrayList signals = new ArrayList ();

			foreach (IDictionaryEnumerator de in new IDictionaryEnumerator[] { cse, cppe })
				while (de.MoveNext())
					signals.Add (de.Value);

			foreach (QtSignal signal in signals)
				foreach (QtSlot slot in new ArrayList (signal.Slots))
					Disconnect (sender, TQT_SIGNAL (signal.Signal), slot.Receiver, TQT_SLOT (slot.Slot));

			return true;
		}

		private static bool DisconnectReceiver(TQObject sender, TQObject receiver)
		{
			if (traceConnects)
				ErrMsg ("DisconnectReceiver: ({0}) {1}, ({2}) {3}", sender.RawObject, sender, receiver.RawObject, receiver);

			IDictionaryEnumerator cse = sender.CsSignalMap.GetEnumerator();
			IDictionaryEnumerator cppe = sender.CppSignalMap.GetEnumerator();

			ArrayList signals = new ArrayList ();

			foreach (IDictionaryEnumerator de in new IDictionaryEnumerator[] { cse, cppe })
				while (de.MoveNext ())
					signals.Add (de.Value);

			foreach (QtSignal signal in signals)
				foreach (QtSlot slot in new ArrayList (signal.Slots))
					Disconnect (signal.Sender, TQT_SIGNAL (signal.Name), receiver, TQT_SLOT (slot.Name));

			return true;
		}

		private static bool DisconnectSignal(TQObject sender, string signal)
		{
			if (traceConnects)
				ErrMsg ("DisconnectSignal: ({0}) {1}, {2}", sender.RawObject, sender, signal);

			foreach (QtSignalMap map in new QtSignalMap[] { sender.CsSignalMap, sender.CppSignalMap }) {
				QtSignal sig = map[signal];
				if (sig != null) {
					foreach (QtSlot slot in new ArrayList (sig.Slots))
						Disconnect (sender, TQT_SIGNAL(signal), slot.Receiver, TQT_SLOT(slot.Slot));
				}
			}

			return true;
		}

		private static bool DisconnectSignalFromReceiver (TQObject sender, string signal, TQObject receiver)
		{
			if (traceConnects)
				ErrMsg ("DisconnectSignalFromReceiver: ({0}) {1}, {2}, ({3}), {4}", sender.RawObject, sender,
																			signal, receiver.RawObject, receiver);

			foreach (QtSignalMap map in new QtSignalMap[] { sender.CsSignalMap, sender.CppSignalMap }) {
				QtSignal sig = map[signal];
				if (sig != null) {
					foreach (QtSlot slot in new ArrayList (sig.Slots))
						if (slot.Receiver == receiver)
							Disconnect (sender, signal, receiver, TQT_SLOT (slot.Name));
				}
			}

			return true;
		}

		private static string MangleArgs(string args)
		{
			// FIXME Char.Equals and Char.CompareTo don't seem to work on Mono.
			string result = args.Replace ("(", "");
			result = result.Replace (")", "");
			result = result.Replace (" ", "");
			result = result.Replace ("unsigned ", "u");
			result = result.Replace ("byte", "char");
			return result.Replace (",", "");

			/*
			char[] evict = {'(', ')', ',', ' '};
			char[] result = new char[args.Length];
			int newlen = 0;

			foreach (char c in args.ToCharArray()) {
				foreach (char cx in evict) {
					if (c.Equals(cx)) continue;
				}
				result[newlen] = c;
				newlen++;
			}

			return new String(result);
			*/
		}

		private static string MakeSigId(TQObject sender, string signal)
		{
			return sender.RawObject.ToString()+signal;
		}

		internal static string NormalizeParam(string param)
		{
			string ret = param;
			if (param.StartsWith("1") || param.StartsWith("2"))
				ret = param.Substring(1);
			return ret;

		}

		private static bool IsSignal(string name)
		{
			return name.StartsWith("2");
		}

		private static bool IsSlot(string name)
		{
			return name.StartsWith("1");
		}

		public void DumpConnections()
		{
			ErrMsg ("{0}::{1} Signal Information:", sender, signal);

			ErrMsg ("-------- Slot Connections --------");
			if (Slots.Count == 0)
				ErrMsg ("--> No slot connections.");
			else {
				foreach (QtSlot slot in slots) {
					ErrMsg ("--> ({0}) {1}::{2}", slot.Receiver.RawObject, slot.Receiver, slot.Slot);
				}
			}

			ErrMsg ("------- Signal Connections -------");
			if (Signals.Count == 0)
				ErrMsg ("--> No signal connections.");
			else {
				foreach (QtSignal sig in signals) {
					ErrMsg ("--> ({0}) {1}::{2}", sig.Sender.RawObject, sig.Sender, sig.Signal);
				}
			}
		}

		public void Emit(object[] args)
		{
			foreach (QtSlot slot in slots)
				slot.Invoke(args);

			foreach (QtSignal signal in signals) {
				signal.Emit(args);
			}
		}

		public void Emit_void ()
		{
			Emit (new object[0]);
		}
		
		public void Emit_bool (bool value0)
		{
			Emit (new object[] { value0 });
		}
		
		public void Emit_short (short value0)
		{
			Emit (new object[] { value0 });
		}
		
		public void Emit_int (int value0)
		{
			Emit (new object[] { value0 });
		}
		
		public void Emit_long (long value0)
		{
			Emit (new object[] { value0 });
		}
		
		public void Emit_float (float value0)
		{
			Emit (new object[] { value0 });
		}
		
		public void Emit_double (double value0)
		{
			Emit (new object[] { value0 });
		}
		
		public void Emit_QDockWindow (IntPtr value0)
		{
			Emit (new object[] { value0 });
		}
		
		public void Emit_QDropEvent (IntPtr value0)
		{
			Emit (new object[] { value0 });
		}
		
		public void Emit_QDropEventQListViewItem (IntPtr value0, IntPtr value1)
		{
			Emit (new object[] { value0, value1 });
		}
		
		public void Emit_QIconViewItem (IntPtr value0)
		{
			Emit (new object[] { value0 });
		}
		
		public void Emit_QListBoxItem (IntPtr value0)
		{
			Emit (new object[] { value0 });
		}
		
		public void Emit_QListViewItem (IntPtr value0)
		{
			Emit (new object[] { value0 });
		}
		
		public void Emit_QListViewItemQListViewItem (IntPtr value0, IntPtr value1)
		{
			Emit (new object[] { value0, value1 });
		}
		
		public void Emit_QListViewItemQListViewItemQListViewItem (IntPtr value0, IntPtr value1, IntPtr value2)
		{
			Emit (new object[] { value0, value1, value2 });
		}
		
		public void Emit_QNetworkOperation (IntPtr value0)
		{
			Emit (new object[] { value0 });
		}
		
		public void Emit_QObject (IntPtr value0)
		{
			Emit (new object[] { value0 });
		}
		
		public void Emit_QToolBar (IntPtr value0)
		{
			Emit (new object[] { value0 });
		}
		
		public void Emit_QWidget (IntPtr value0)
		{
			Emit (new object[] { value0 });
		}
		
		public void Emit_intQIconViewItem (int value0, IntPtr value1)
		{
			Emit (new object[] { value0, value1 });
		}
		
		public void Emit_intQListBoxItem (int value0, IntPtr value1)
		{
			Emit (new object[] { value0, value1 });
		}
		
		public void Emit_intbool (int value0, bool value1)
		{
			Emit (new object[] { value0, value1 });
		}
		
		public void Emit_intint (int value0, int value1)
		{
			Emit (new object[] { value0, value1 });
		}
		
		public void Emit_intintint (int value0, int value1, int value2)
		{
			Emit (new object[] { value0, value1, value2 });
		}

		[DllImport("libqtc", CharSet=CharSet.Ansi)]
		private static extern bool qt_QObject_connect1 (IntPtr sender, string signal, IntPtr receiver, string member);

		[DllImport("libqtc", CharSet=CharSet.Ansi)]
		private static extern bool qt_QObject_disconnect2 (IntPtr sender, string signal, IntPtr receiver, string member);

		[DllImport("libqtsharp", CharSet=CharSet.Ansi)]
		private static extern IntPtr csharp_connect_void (IntPtr sender, string signal, IntPtr receiver, Delegate cb);
		
		[DllImport("libqtsharp", CharSet=CharSet.Ansi)]
		private static extern IntPtr csharp_connect_bool (IntPtr sender, string signal, IntPtr receiver, Delegate cb);
		
		[DllImport("libqtsharp", CharSet=CharSet.Ansi)]
		private static extern IntPtr csharp_connect_short (IntPtr sender, string signal, IntPtr receiver, Delegate cb);
		
		[DllImport("libqtsharp", CharSet=CharSet.Ansi)]
		private static extern IntPtr csharp_connect_int (IntPtr sender, string signal, IntPtr receiver, Delegate cb);
		
		[DllImport("libqtsharp", CharSet=CharSet.Ansi)]
		private static extern IntPtr csharp_connect_long (IntPtr sender, string signal, IntPtr receiver, Delegate cb);
		
		[DllImport("libqtsharp", CharSet=CharSet.Ansi)]
		private static extern IntPtr csharp_connect_float (IntPtr sender, string signal, IntPtr receiver, Delegate cb);
		
		[DllImport("libqtsharp", CharSet=CharSet.Ansi)]
		private static extern IntPtr csharp_connect_double (IntPtr sender, string signal, IntPtr receiver, Delegate cb);
		
		[DllImport("libqtsharp", CharSet=CharSet.Ansi)]
		private static extern IntPtr csharp_connect_QString (IntPtr sender, string signal, IntPtr receiver, Delegate cb);
	
		[DllImport("libqtsharp", CharSet=CharSet.Ansi)]
		private static extern IntPtr csharp_connect_QDockWindow (IntPtr sender, string signal, IntPtr receiver, Delegate cb);
		
		[DllImport("libqtsharp", CharSet=CharSet.Ansi)]
		private static extern IntPtr csharp_connect_QDropEvent (IntPtr sender, string signal, IntPtr receiver, Delegate cb);
		
		[DllImport("libqtsharp", CharSet=CharSet.Ansi)]
		private static extern IntPtr csharp_connect_QDropEventQListViewItem (IntPtr sender, string signal, IntPtr receiver, Delegate cb);
		
		[DllImport("libqtsharp", CharSet=CharSet.Ansi)]
		private static extern IntPtr csharp_connect_QIconViewItem (IntPtr sender, string signal, IntPtr receiver, Delegate cb);
		
		[DllImport("libqtsharp", CharSet=CharSet.Ansi)]
		private static extern IntPtr csharp_connect_QListBoxItem (IntPtr sender, string signal, IntPtr receiver, Delegate cb);
		
		[DllImport("libqtsharp", CharSet=CharSet.Ansi)]
		private static extern IntPtr csharp_connect_QListViewItem (IntPtr sender, string signal, IntPtr receiver, Delegate cb);
		
		[DllImport("libqtsharp", CharSet=CharSet.Ansi)]
		private static extern IntPtr csharp_connect_QListViewItemQListViewItem (IntPtr sender, string signal, IntPtr receiver, Delegate cb);
		
		[DllImport("libqtsharp", CharSet=CharSet.Ansi)]
		private static extern IntPtr csharp_connect_QListViewItemQListViewItemQListViewItem (IntPtr sender, string signal, IntPtr receiver, Delegate cb);
		
		[DllImport("libqtsharp", CharSet=CharSet.Ansi)]
		private static extern IntPtr csharp_connect_QNetworkOperation (IntPtr sender, string signal, IntPtr receiver, Delegate cb);

		[DllImport("libqtsharp", CharSet=CharSet.Ansi)]
		private static extern IntPtr csharp_connect_QObject (IntPtr sender, string signal, IntPtr receiver, Delegate cb);

		[DllImport("libqtsharp", CharSet=CharSet.Ansi)]
		private static extern IntPtr csharp_connect_QToolBar (IntPtr sender, string signal, IntPtr receiver, Delegate cb);

		[DllImport("libqtsharp", CharSet=CharSet.Ansi)]
		private static extern IntPtr csharp_connect_QWidget (IntPtr sender, string signal, IntPtr receiver, Delegate cb);

		[DllImport("libqtsharp", CharSet=CharSet.Ansi)]
		private static extern IntPtr csharp_connect_intQIconViewItem (IntPtr sender, string signal, IntPtr receiver, Delegate cb);

		[DllImport("libqtsharp", CharSet=CharSet.Ansi)]
		private static extern IntPtr csharp_connect_intQListBoxItem (IntPtr sender, string signal, IntPtr receiver, Delegate cb);

		[DllImport("libqtsharp", CharSet=CharSet.Ansi)]
		private static extern IntPtr csharp_connect_intbool (IntPtr sender, string signal, IntPtr receiver, Delegate cb);

		[DllImport("libqtsharp", CharSet=CharSet.Ansi)]
		private static extern IntPtr csharp_connect_intint (IntPtr sender, string signal, IntPtr receiver, Delegate cb);

		[DllImport("libqtsharp", CharSet=CharSet.Ansi)]
		private static extern IntPtr csharp_connect_intintint (IntPtr sender, string signal, IntPtr receiver, Delegate cb);

		public delegate void del_void ();
		public delegate void del_bool (bool value0);
		public delegate void del_short (short value0);
		public delegate void del_int (int value0);
		public delegate void del_long (long value0);
		public delegate void del_float (float value0);
		public delegate void del_double (double value0);
		public delegate void del_QString (IntPtr value0);
		public delegate void del_QDockWindow (IntPtr value0);
		public delegate void del_QDropEvent (IntPtr value0);
		public delegate void del_QDropEventQListViewItem (IntPtr value0, IntPtr value1);
		public delegate void del_QIconViewItem (IntPtr value0);
		public delegate void del_QListBoxItem (IntPtr value0);
		public delegate void del_QListViewItem (IntPtr value0);
		public delegate void del_QListViewItemQListViewItem (IntPtr value0, IntPtr value1);
		public delegate void del_QListViewItemQListViewItemQListViewItem (IntPtr value0, IntPtr value1, IntPtr value2);
		public delegate void del_QNetworkOperation (IntPtr value0);
		public delegate void del_QObject (IntPtr value0);
		public delegate void del_QToolBar (IntPtr value0);
		public delegate void del_QWidget (IntPtr value0);
		public delegate void del_intQIconViewItem (int value0, IntPtr value1);
		public delegate void del_intQListBoxItem (int value0, IntPtr value1);
		public delegate void del_intbool (int value0, bool value1);
		public delegate void del_intint (int value0, int value1);
		public delegate void del_intintint (int value0, int value1, int value2);
	}
}