Ticket #13138: input_server_menu.patch

File input_server_menu.patch, 1.8 KB (added by jalopeura, 3 years ago)
  • src/servers/input/InputServerMethod.cpp

    diff --git a/src/servers/input/InputServerMethod.cpp b/src/servers/input/InputServerMethod.cpp
    index 6333dc5..1ff1735 100644
    a b _BMethodAddOn_::AddMethod()  
    262262    msg.AddInt32("cookie", fCookie);
    263263    msg.AddString("name", fName);
    264264    msg.AddData("icon", B_RAW_TYPE, fIcon, 16*16*1);
     265    BMessage menuMsg;
     266    if (fMenu != NULL)
     267        fMenu->Archive(&menuMsg);
     268    msg.AddMessage("menu", &menuMsg);
     269    msg.AddMessenger("target", fMessenger);
    265270    if (((InputServer*)be_app)->MethodReplicant())
    266271        return ((InputServer*)be_app)->MethodReplicant()->SendMessage(&msg);
    267272    else
  • src/servers/input/MethodReplicant.cpp

    diff --git a/src/servers/input/MethodReplicant.cpp b/src/servers/input/MethodReplicant.cpp
    index 95650e3..fbeccd0 100644
    a b MethodReplicant::AddMethod(BMessage* message)  
    367367        return;
    368368    }
    369369
     370    BMessage menuMsg;
     371    if (message->FindMessage("menu", &menuMsg) != B_OK) {
     372        fprintf(stderr, "can't find menu in message\n");
     373        return;
     374    }
     375    PRINT_OBJECT(menuMsg);
     376
     377    BMessenger messenger;
     378    if (message->FindMessenger("target", &messenger) != B_OK) {
     379        fprintf(stderr, "can't find target in message\n");
     380        return;
     381    }
     382
     383    BMenu* menu = static_cast<BMenu*>(BMenu::Instantiate(&menuMsg));
     384    if (menu == NULL) {
     385        PRINT(("can't instantiate menu\n"));
     386    } else
     387        menu->SetTargetForItems(messenger);
     388
    370389    MethodMenuItem* item = FindItemByCookie(cookie);
    371390    if (item != NULL) {
    372391        fprintf(stderr, "item with cookie %" B_PRIx32 " already exists\n", cookie);
    373392        return;
    374393    }
    375394
    376     item = new MethodMenuItem(cookie, name, icon);
     395    if (menu != NULL) {
     396        item = new MethodMenuItem(cookie, name, icon, menu, messenger);
     397    } else
     398        item = new MethodMenuItem(cookie, name, icon);
    377399    fMenu.AddItem(item);
    378400    item->SetTarget(this);
    379401