IResultData::DeleteItem and IResultData::DeleteAllRsltItems return E_UNEXPECTED - windows

We have a problem with an ATL-based Visual C++ MMC snapin. We have a scope item that is only showed in the scope pane. When this item is selected it populates the result pane with a set of result items.
When the user selects "delete all items" popup menu command our snapin code is invoked - first it does some work, then proceeds to clearing the result view. We want the following behavior: the user clicks that menu item, our custom code is called to do useful work, then all items disappear from the result pane, the scope item remains selected.
I tried two variations of what to do to remove all result items.
Variation 1 - it calls IResultData::DeleteAllRsltItems() which returns E_UNEXPECTED and items are not removed - they just stay there.
VAriation 2 - it calls IResultData::DeleteItem() for each item previosuly inserted into result pane. Again each call returns E_UNEXPECTED and items are not removed.
How do I properly remove all result items from the MMC view?

We do this in the OnShow handler. All child items are removed like this:
CComPtr<IResultData> pResultData;
result = pConsole->QueryInterface(IID_IResultData, (void **)&pResultData);
assert( SUCCEEDED(result) );
pResultData->DeleteAllRsltItems();
Then re-added:
RESULTDATAITEM rdi;
ZeroMemory(&rdi, sizeof(RESULTDATAITEM) );
rdi.mask = RDI_STR | RDI_IMAGE | RDI_PARAM;
rdi.nImage = m_resultChildren[i]->GetBitmapIndex();
rdi.str = reinterpret_cast< wchar_t* >(MMC_CALLBACK);
rdi.nCol = 0;
rdi.lParam = (LPARAM)m_resultChildren[i].get();
HRESULT result = pResultData->InsertItem( &rdi );
This works to remove the result items. I assume that you have another problem in the code that is causing the E_UNEXPECTED.

Related

E4 RCP How to set selection of ToolBarItem that contains Radio Buttons

In Eclipse E4 (Luna), using the application model to create parts, handlers, commands, handled menu items etc, (these are not created programatically). I have a toolbar. This contains a sub-Menu item called "Filter" that contains another sub-menu of two filters. The two filters are two Handled Menu Items which are set up as "Radio" Buttons.
When I select the appropriate in the UI of my running app from the selection, the Radio button switches just fine to the selected Item. However I would like this selection to update (deselecting one Radio button and selecting the appropriate radio button of the handled menu item) when my ViewPart changes through other UI selection. Currently my ViewPart updates, but the Radio buttons are on the same previous selection through the UI.
Is there a way in which I get access both Handled Menu Item's IDs and set the selection (one to false, the other to true) when the viewer is updated.
Image of design is attached below:
Hierarchy of the application model is as follows:
Thanks in advance,
Marv
You can use the model service to find menu items. Use something like:
#Inject
EModelService modelService;
#Inject
MApplication app;
List<MMenuItem> items = modelService.findElements(app, "menu item id", MMenuItem.class, Collections.emptyList(), EModelService.IN_MAIN_MENU);
Once you have the MMenuItem you can call the setSelected(boolean) method to change the selection.
To find a menu item which is in a Part menu use:
modelService.findElements(app, "menu item id", MMenuItem.class, Collections.emptyList(), EModelService.IN_PART);
(IN_PART argument instead of IN_MAIN_MENU).
You could also specify the MPart rather than the Application as the first argument to findElements which may speed up the search.
For menus as a child of a Tool Bar Item it appears that the model services cannot find these directly. However you can find the Tool Bar Item and look at the menu yourself:
List<MToolItem> items = modelService.findElements(app, "tool bar item id", MToolItem.class, Collections.emptyList(), EModelService.IN_PART);
MToolItem item = items.get(0);
MMenu menu = item.getMenu();
List<MMenuElement> children = menu.getChildren();
... search menu elements
I solved this by starting with MPart PartID and drilling down to the HandledMenuItems on which I wanted to set the Radio Button selections, then setting the selection property for each individual HandledMenuItem.
This can probably be refactored to be more concise, but I've left the code with each step to have the solution easier to read.
BTW, in every instance / combination of the EModelService methods, the list returned a size of 0. So I'm not certain if that will work for what I'm trying to achieve. The following does work, although I'm not certain it is the most efficient means.
I hope this helps others.
// Get view part
MPart viewPart = _partService.findPart("part_id");
// get list of all menu items from the Part
List<MMenu> viewPartMenu = viewPart.getMenus();
// Get list of ViewMenus from viewPartMenu there is only one View Menu so it will be index 0
MMenu viewMenu = viewPartMenu .get(0);
// Get list of MMenuElements from the viewMenu - the children in the view menu
List<MMenuElement> viewMenuElements = viewMenu.getChildren();
// This gets me to the 2 HandledMenuItems
// Upper Most HandledMenuItem Radio Button is at viewMenuElements index 0. This is cast to MHandledMenuItem
MHandledMenuItem upperHandledMenuItem = (MHandledMenuItem) viewMenuElements.get(0);
// Set Selection
upperHandledMenuItem.setSelected(false);
// Lower Most HandledMenuItem Radio Button is at viewMenuElements index 1. This is cast to MHandledMenuItem
MHandledMenuItem lowerHandledMenuItem = (MHandledMenuItem) viewMenuElements.get(1);
// Set selection
lowerHandledMenuItem.setSelected(true);

LiveCycle drop-down list change event only works on second change

I want a Text Field to appear when a certain item is chosen from a drop-down list. I'm using a change event.
if(this.rawValue == 1){
Tolerance.presence = "visible";
}
else{
Tolerance.presence = "hidden";
}
The problem is that the Text Field presence does not change immediately when a selection is made, but only after I go back to the list box and select again (any value, not just the same one).
The new value of the dropdown only registers after the change event. This means this.rawValue points to the old value of the dropdown in a change event.
Either move your script dropdown exit event or make use of the event.newText in the if conditional in the change event.

How to draw the static part of the combobox

I have a custom drawn combobox with style CBS_DROPDOWNLIST and CBS_OWNERDRAWVARIABLE I can draw the items of the dropdownlist ok but whe user select an item it is drawn in the combobox static part [the part of combo that stay visible after selecting item and show the selection], I want to give it a custom text like in the following image
But I can't determine it I found a code like this
if(DrawItemStruct.CtlType == ODT_COMBOBOX)//the static part of the combo
DrawComboText(pDC, DrawItemStruct.itemID, &DrawItemStruct.rcItem);
else//the rest items
{
// Copy the text of the item to a string
char sItem[256];
GetString(sItem, DrawItemStruct.itemID);
biDrawText(pDC, sItem, -1, &DrawItemStruct.rcItem, f | DT_VCENTER | DT_SINGLELINE);
}
but when I used it I get all the items has CtlType == ODT_COMBOBOX, when I debugged the above code It return ODT_COMBOBOX for the static part, and for items of the drop down list it return ODT_LISTBOX.
I want to know how to fix this problem, how to detect that I'm drawing the static part or a regular item in the dropdown list?
I just check the state for ODS_COMBOBOXEDIT. If ifthe dcumentation says that this flag is set for the edit Control, it works for the drop down list to.
I have checked combo box implementation like you that works in the sane way.
bool bDrawStaticControl = (pDIS->itemState & ODS_COMBOBOXEDIT)!=0;

How to switch to another local view from CCoeControl object in Symbian

My GUI application has two views, First view has a ListBox control - Derived from CCoeControl - and from this object I want to switch to the second view, How can I do this ?
In other words, When user click ListBox Item ...the second view appears.
Assuming that your 'views' are derived from CAknView.
Code From this link
const TUid KDemo1ViewId = { 1 }; // UID of the first view
AppUI()->ActivateLocalViewL(KDemo1ViewId); // activate view 1
Also find these links very useful.Getting a pointer to AppUI
Getting a Pointer to a View
Edit :
CYourApplicationAppUi* appui = (static_cast<CYourApplicationAppUi*>(iEikonEnv>AppUi()));
// Get the view you want CSomeView* view = (CSomeView*)appui->View(TUid::Uid(ESomeViewId))

how to add message map to dynamic menu item in MFC

I writing a MFC which has a listview control. When the user right clicks any item , I am generating a dynamic menu item with that text that is selected in listview. Everything is displaying properly, but I do not know how to add a message map to that dynamic menu item.
Any help?
void CMyListDlg::OnRclickList(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
int nIndex = m_List.GetSelectionMark();
CString pString = m_List.GetItemText(nIndex,1);
CMenu menu, * pSubMenu;
int pos=0;
menu.LoadMenu(IDR_MENU1);
pSubMenu = menu.GetSubMenu (0);
pSubMenu->DeleteMenu(0,MF_BYPOSITION);
pSubMenu->InsertMenu(pos,MF_BYPOSITION,NULL,pString);
CPoint oPoint;
GetCursorPos (& oPoint);
pSubMenu-> TrackPopupMenu (TPM_LEFTALIGN, oPoint.x, oPoint.y, this);
*pResult = 0;
}
At the moment you are inserting the menu item with ID = 0 (NULL). That way you can't figure out which command was pressed. You have to assign an ID to the item, the simplest one is to
#define WM_MYMESSAGE WM_USER + 1
then you insert it like this:
pSubMenu->InsertMenu(pos,MF_BYPOSITION,WM_MYMESSAGE,pString);
If you override OnCommand for your window, you get your ID as wParam.
To actually figure out what happened, store some additional information in another class member, like m_nLastItemClicked or ... you get the idea?!
Check the MFCIE sample, it generates a favorite menu from the user's favorite folder and navigates to the favorite url when a favorite menu item is clicked.
Just add ON_COMMAND (and ON_UPDATE_COMMAND_UI if necessary) handlers for the menu items' IDs on your class.

Resources