void PositionContextMenu (Gtk.Menu menu,
out int x, out int y, out bool push_in)
{
int pos_x;
int pos_y;
Gtk.TreePath path;
Gtk.TreePath [] selected_rows;
Gdk.Rectangle cell_rect;
// Set default "return" values
push_in = true;
x = 0;
y = 0;
// Are we currently in the note list?
// else, assume we're in the notebook list
Gtk.TreeView currentTree = (tree.HasFocus) ? tree : notebooksTree;
selected_rows = currentTree.Selection.GetSelectedRows ();
// Get TreeView's coordinates
currentTree.GdkWindow.GetOrigin (out pos_x, out pos_y);
if (selected_rows.Length > 0) {
// Popup near the selection
path = selected_rows [0];
cell_rect = currentTree.GetCellArea (path, currentTree.Columns [0]);
// Add 100 to x, so it isn't too close to the left border
x = pos_x + cell_rect.X + 100;
// Add 47 to y, so it's right at the bottom of the selected row
y = pos_y + cell_rect.Y + 47;
}
}