void SetDummyLabel(Container c, string section, string text) { Label lbl = new Label(); lbl.Markup = small ? "<span color=\"#FF6600\"><b><big><big>" + text + "</big></big></b></span>" : "<i>" + text + "</i>"; lbl.SetPadding(5, 5); MiscHelpers.AddToContainer(c, lbl, small); // Setup appropiate DragDest DragDropHelpers.DestSet(lbl, DestDefaults.All, DragDropHelpers.TgtFromString(section), Gdk.DragAction.Move); // correctly count the number of "real" widgets in // container, since their might be some more // widgets for layouting in it (in small mode for example) int index = 0; foreach (Widget w in c) { if (w is IDragDropWidget) { index++; } } lbl.DragDataReceived += delegate(object o, DragDataReceivedArgs args) { object data = DragDropHelpers.Deserialize(args.SelectionData); // save data here SetItem(section, index, data); // delete data there MyButton b = (MyButton)Drag.GetSourceWidget(args.Context); b.Owner.SetData(null); }; }
/// <summary> /// Handles the drag data received. /// See the EnableDrag and HandleDragDataGet in the ComponentLibraryPad where the drag /// has started and drag source is set /// </summary> /// <param name='o'> /// O. /// </param> /// <param name='args'> /// Arguments. /// </param> private void HandleDragDataReceived(object o, DragDataReceivedArgs args) { Widget source = Drag.GetSourceWidget(args.Context); TreeView treeView = source as TreeView; TreeIter selectedItem; if (treeView != null && treeView.Selection.GetSelected(out selectedItem)) { ComponentsLibraryNode selectedNode = treeView.Model.GetValue(selectedItem, 0) as ComponentsLibraryNode; Cairo.PointD translation = m_experimentCanvasWidget.ExperimentCanvas.View.ViewToDrawing(args.X, args.Y); ExperimentNode node = m_applicationViewModel.Experiment.AddComponentFromDefinition(selectedNode.Data, translation.X, translation.Y); m_experimentDrawer.DrawComponent(node, true); } Drag.Finish(args.Context, true, false, args.Time); }
void SetDragDestToAllWidgets() { DragDropHelpers.ApplyToWidget(notebookDragDrop, delegate(Widget w) { Drag.DestSet(w, DestDefaults.Motion | DestDefaults.Drop, DragDropHelpers.TgtAll, Gdk.DragAction.Move); w.DragDataReceived += delegate(object o, DragDataReceivedArgs args) { // first delete MyButton b = (MyButton)Drag.GetSourceWidget(args.Context); b.Owner.SetData(null); // then set... object data = DragDropHelpers.Deserialize(args.SelectionData); SetItem(data); }; }); }
private void GroupsTree_DragMotion(object o, DragMotionArgs args) { if (Drag.GetSourceWidget(args.Context) == groupsPanel.GroupsTree) { return; } TreePath path; TreeViewDropPosition pos; if (!groupsPanel.GroupsTree.GetDestRowAtPos(args.X, args.Y, out path, out pos)) { args.RetVal = false; return; } foreach (int index in grid.Selection) { User entity = (User)grid.Model [index]; if (entity.CanEdit()) { continue; } args.RetVal = false; return; } switch (pos) { case TreeViewDropPosition.Before: groupsPanel.GroupsTree.SetDragDestRow(path, TreeViewDropPosition.IntoOrBefore); break; case TreeViewDropPosition.After: groupsPanel.GroupsTree.SetDragDestRow(path, TreeViewDropPosition.IntoOrAfter); break; } Gdk.Drag.Status(args.Context, args.Context.SuggestedAction, args.Time); args.RetVal = true; }
void UpdateGuiSection(string section, int i, object data) { Container c = (Container)GetField("c" + section); if (data == null) { SetDummyLabel(c, section); } else if (data is List <RoundDebater> ) { // Judges or FreeSpeakers (variable number...) MiscHelpers.ClearContainer(c); List <RoundDebater> list = (List <RoundDebater>)data; if (list.Count == 0) { SetDummyLabel(c, section); } else { for (int j = 0; j < list.Count; j++) { UpdateGuiSection(section, j, list[j]); } // append label for adding by D&D if (small) { if (section == "Judges") { SetDummyLabel(c, section, roomData.Judges.Count.ToString()); } else if (section == "FreeSpeakers" && list.Count < 3) { SetDummyLabel(c, section, "F"); } } else if (section == "Judges" || list.Count < 3) { SetDummyLabel(c, section, "Drag here to add"); } } } else { IDragDropWidget w = null; if (data is TeamData) { if (small) { w = Team.Small((TeamData)data); } else { w = new Team((TeamData)data, null); } } else if (data is RoundDebater) { if (small) { w = DebaterWidget.Small((RoundDebater)data, false); } else { w = new DebaterWidget((RoundDebater)data); } } else { throw new NotImplementedException("Don't know how to create widget for data"); } // tell Debater the room for visitedRooms list.. w.SetRoom(roomData.RoundName, roomData); w.SetupDragDropSource(section, data); w.SetDataTrigger += delegate(Widget sender, object data_) { SetItem(section, i, data_); }; // Add to container after source, but before Dest Widget wi = (Widget)w; MiscHelpers.AddToContainer(c, wi, small); // Drag drop DestSet, needs Container for scrolling support... DragDropHelpers.DestSet(wi, DestDefaults.All, DragDropHelpers.TgtFromString(section), Gdk.DragAction.Move); wi.DragDataReceived += delegate(object o, DragDataReceivedArgs args) { object data_ = DragDropHelpers.Deserialize(args.SelectionData); // save data here SetItem(section, i, data_); // delete data there MyButton b = (MyButton)Drag.GetSourceWidget(args.Context); b.Owner.SetData(data); }; } // show judge quality by icons if (section == "Judges" && !small) { int nStars = 0; double sumAvgSpkr = 0.0; double sumAvgTeam = 0.0; int nAvgSpkr = 0; int nAvgTeam = 0; foreach (RoundDebater rd in roomData.Judges) { Debater d = Tournament.I.FindDebater(rd); if (d == null) { continue; } nStars += d.Role.JudgeQuality; if (!double.IsNaN(d.StatsAvg[0])) { sumAvgSpkr += d.StatsAvg[0]; nAvgSpkr++; } if (!double.IsNaN(d.StatsAvg[2])) { sumAvgTeam += d.StatsAvg[2]; nAvgTeam++; } } lblJudgeStats.Markup = "JudgeStats: " + JudgeStatsToMarkup(sumAvgSpkr, nAvgSpkr, 2) + " " + JudgeStatsToMarkup(sumAvgTeam, nAvgTeam, 5); MiscHelpers.ClearTable(tableJudgeStars); tableJudgeStars.NRows = (uint)nStars / 5 + 1; for (int j = 0; j < nStars; j++) { uint col = (uint)j % 5; uint row = (uint)j / 5; tableJudgeStars.Attach(new Image(MiscHelpers.LoadIcon("face-smile")), col, col + 1, row, row + 1, AttachOptions.Shrink, AttachOptions.Shrink, 0, 0); } if (nStars == 0) { tableJudgeStars.HideAll(); } else { tableJudgeStars.ShowAll(); } } }