コード例 #1
0
            KeyBindingHitTestResult HitTest(double mouseX, double mouseY)
            {
                KeyBindingHitTestResult result = new KeyBindingHitTestResult();
                TreeIter iter;
                TreePath path;
                int      cellx, celly, mx, my;

                mx = (int)mouseX;
                my = (int)mouseY;

                if (!GetCellPosition(mx, my, out cellx, out celly, out iter, out path))
                {
                    return(result);
                }

                Text    = keyBindingsTree.Model.GetValue(iter, bindingCol) as string ?? string.Empty;
                Command = keyBindingsTree.Model.GetValue(iter, commandCol) as Command;

                var filter = keyBindingsTree.Model as TreeModelFilter;

                if (filter != null)
                {
                    iter = filter.ConvertIterToChildIter(iter);
                }

                result.Command = Command;
                result.AllKeys = Text.Split(new char [] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                result.Iter    = iter;

                using (var layout = new Pango.Layout(keyBindingsTree.PangoContext)) {
                    // GetCellArea reports the outer cell bounds, therefore we need to add 2px
                    var xpad       = (int)Xpad + 2;
                    var cellBounds = keyBindingsTree.GetCellArea(path, keyBindingsPanel.bindingTVCol);
                    keyBindingsTree.ConvertBinWindowToWidgetCoords(cellBounds.X, cellBounds.Y, out cellBounds.X, out cellBounds.Y);
                    int i = 0;
                    foreach (var key in result.AllKeys)
                    {
                        layout.SetText(KeyBindingManager.BindingToDisplayLabel(key, false));
                        layout.FontDescription = KeySymbolFont;
                        int w, h;
                        layout.GetPixelSize(out w, out h);

                        int buttonWidth  = w + (2 * KeyHPadding);
                        int buttonHeight = h + (2 * KeyVPadding);
                        var ypad         = 2 + ((cellBounds.Height / 2) - (buttonHeight / 2));

                        if (cellx > xpad && cellx <= xpad + buttonWidth &&
                            celly > ypad && celly <= ypad + buttonHeight)
                        {
                            keyBindingsPanel.bindingTVCol.CellGetPosition(this, out cellx, out w);
                            cellBounds.X += cellx;

                            result.SelectedKey  = i;
                            result.ButtonBounds = new Gdk.Rectangle(cellBounds.X + xpad, cellBounds.Y + ypad, buttonWidth, buttonHeight);
                            result.ButtonBounds.Inflate(0, 2);
                            return(result);
                        }

                        xpad += buttonWidth + Spacing;
                        i++;
                    }
                }
                return(result);
            }
コード例 #2
0
			KeyBindingHitTestResult HitTest (double mouseX, double mouseY)
			{
				KeyBindingHitTestResult result = new KeyBindingHitTestResult ();
				TreeIter iter;
				TreePath path;
				int cellx, celly, mx, my;
				mx = (int)mouseX;
				my = (int)mouseY;

				if (!GetCellPosition (mx, my, out cellx, out celly, out iter, out path))
					return result;

				Text = keyBindingsTree.Model.GetValue (iter, bindingCol) as string ?? string.Empty;
				Command = keyBindingsTree.Model.GetValue (iter, commandCol) as Command;

				var filter = keyBindingsTree.Model as TreeModelFilter;
				if (filter != null)
					iter = filter.ConvertIterToChildIter (iter);

				result.Command = Command;
				result.AllKeys = Text.Split (new char [] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList ();
				result.Iter = iter;

				using (var layout = new Pango.Layout (keyBindingsTree.PangoContext)) {

					// GetCellArea reports the outer cell bounds, therefore we need to add 2px
					var xpad = (int)Xpad + 2;
					var cellBounds = keyBindingsTree.GetCellArea (path, keyBindingsPanel.bindingTVCol);
					keyBindingsTree.ConvertBinWindowToWidgetCoords (cellBounds.X, cellBounds.Y, out cellBounds.X, out cellBounds.Y);
					int i = 0;
					foreach (var key in result.AllKeys) {
						layout.SetText (KeyBindingManager.BindingToDisplayLabel (key, false));
						layout.FontDescription = KeySymbolFont;
						int w, h;
						layout.GetPixelSize (out w, out h);

						int buttonWidth = w + (2 * KeyHPadding);
						int buttonHeight = h + (2 * KeyVPadding);
						var ypad = 2 + ((cellBounds.Height / 2) - (buttonHeight / 2));

						if (cellx > xpad && cellx <= xpad + buttonWidth &&
						    celly > ypad && celly <= ypad + buttonHeight) {
							keyBindingsPanel.bindingTVCol.CellGetPosition (this, out cellx, out w);
							cellBounds.X += cellx;

							result.SelectedKey = i;
							result.ButtonBounds = new Gdk.Rectangle (cellBounds.X + xpad, cellBounds.Y + ypad, buttonWidth, buttonHeight);
							result.ButtonBounds.Inflate (0, 2);
							return result;
						}

						xpad += buttonWidth + Spacing;
						i++;
					}
				}
				return result;
			}