Find out the selected child index in a viewitem ?

I subscribed to the SelectedViewItemChangedIndication as mentioned in other threads:

_messageRegistrationObjects.Add(EnvironmentManager.Instance.RegisterReceiver(SelectedViewItemChangedReceiver, new MessageIdFilter(MessageId.SmartClient.SelectedViewItemChangedIndication)));

So far it works fine, I get the message each time a child in the view is selected or is switched with another image. If the image is changed, also the GuiD of the child view is changed. (So I can see which child was changed) But when I select it by mouse (blue frame) nothing changes in the child GuiD and if I try to get the index as described in this thread:

https://developer.milestonesys.com/s/question/0D50O00005h9FZxSAM/how-where-can-i-see-in-a-background-pluginwhich-window-is-active-in-a-view

I always get “-1” as a result.

This is the code:

children.FindIndex(f => f.FQID.ObjectId == _view_item.FQID.ObjectId);

Is there a possibility to find out, which child is selected ?

For better understanding..

Can you please describe what is working, what is not working and some more detail on what you want to achieve?

What does “child Guid” mean? (Perhaps a snippet of you code would help in understanding the object you have.)

Yes, no problem.

I want do Drag&Drop texts to multiviewlayouts, consisting of more than one view. They are addressed by the index with this command:

ClientControl.Instance.CallOnUiThread(() => EnvironmentManager.Instance.SendMessage(

               new VideoOS.Platform.Messaging.Message(MessageId.SmartClient.SetSelectedViewItemCommand,

               new SetSelectedViewItemData()

               {

                   LayoutIndex = output - 1,

                   MoveCommand = "Index"

               })));

For the drag&drop I created an imageview with a d&d sensitive button in a background plugin. (A modified “Activeelementsoverlay”)

This background plugin informs my mainplugin about the dropped text, the view(FQID) and (doesn’t at the moment, but should do) about the index, on which the text was dropped to the button. This works nice with the one view layout (in this case the viewid is sufficent) but not with a multiview, here I would need the index additionally.

So I tried different ways to get this index. One is to subscribe to the SelectedViewItemChangedIndication message, as shown in the first posting.

Then I tried to get the index, but always got “-1” as result. (as described above)

Now I tried to get the objectIDs of the child views, (e.g. 4 in a quadrant) and to compare it with a reference , to see which one has changed. So I could get a kind of index.

In this routine I get these indexes and send them to my debugger by UDP.

List children = button_ViewList_item[zeiger * 2 - 1].GetChildren();

                   foreach (Item citem in children)

                       SendUdp(9999, m\_sRemoteIp, IRemotePort, Encoding.ASCII.GetBytes("BD: Children: " + citem.FQID.ObjectId.ToString()));

Principally it works fine, the problem is, that these child IDs only change, when the image is changed or released a all. I would need a change, if the view is selected by the user.(blue frame) So he would have to select a view and afterwards he can drag the text to the button on this selected view. Much better would be to get the index, when the text is dropped on the button, but I don’t think, that this is possible.

So far, I hope, it is a little bit clearer, what I need.

Have a nice weekend and best regards

Tom

I am in doubt what you want to have happen when the item is dropped apart from the viewitem being selected, and wondering if there might be something simpler. Can you tell me what happens?

I did figure a way to find the index. As I understand it you use something similar to the ActiveElementsOverlay sample to have something to dragdrop onto. I then modified sample, ActiveElementsOverlayBackgroundPlugin, the method:

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var button = sender as Button;
            var imageViewerAddOn = _imageViewerAddOnButtons.First(keyValuePair => keyValuePair.Value == button).Key;
            // below code added to sample
            int indexfound = 0;
            for (int i = 0; i < imageViewerAddOn.WindowInformation.ViewAndLayoutItem.Layout.Count(); i++)
            {
                // layout size values are in the range from 0 to 1000
                int xmin = imageViewerAddOn.WindowInformation.ViewAndLayoutItem.Layout[i].X;
                int xmax = imageViewerAddOn.WindowInformation.ViewAndLayoutItem.Layout[i].X + imageViewerAddOn.WindowInformation.ViewAndLayoutItem.Layout[i].Width;
                int ymin = imageViewerAddOn.WindowInformation.ViewAndLayoutItem.Layout[i].Y;
                int ymax = imageViewerAddOn.WindowInformation.ViewAndLayoutItem.Layout[i].Y + imageViewerAddOn.WindowInformation.ViewAndLayoutItem.Layout[i].Height;
                // by division with the size and multiplication with the layout size values the coordinates are normed to be the same range 0 to 1000
                var x = imageViewerAddOn.Location.X * imageViewerAddOn.WindowInformation.ViewAndLayoutItem.Layout[i].Width / imageViewerAddOn.Size.Width; 
                var y = imageViewerAddOn.Location.Y *imageViewerAddOn.WindowInformation.ViewAndLayoutItem.Layout[i].Height / imageViewerAddOn.Size.Height;
                if (x >= xmin && x <= xmax && y >= ymin && y <= ymax)
                {
                    indexfound = i;
                    break;
                }
            }
            MessageBox.Show("index " + indexfound.ToString());
            // above code added to sample

I hope this code can work for you directly or be a help for you to implement a solution that works for you.

Thank you very much, you made my day ! This works fine. I have implemented this in my Button_Drop routine, now I can do d&d on every view.

Now, after longer time of testing I have another question.

The method works very fine on windows without tree and original layout view.

But if you doubleclick to get the actual camera in a single view, the coordinates are no longer valid, and the method switches to the wrong index. The same is the fact, if the sidebar tree is visible and you make the window smaller, then it switches to the wrong index. (The coordinates are taken from the complete window with tree, I would need only the video view without tree)

I checked the imageViewerAddOn.WindowInformation.ViewAndLayoutItem.Properties, but didn’t find a difference between multilayout and single layout. Also didn’t find a method to see, if the sidebar with the tree is active or removed by the user.

Is there a possibilty, to find out these two facts or to get the coordinates only from the actual video view ?

Please make a new post for the new question.