LOCAL LPLISTBOXDATA DragOK(HWND hWindow) /***********************************************************************/ { // get the listbox data pointer, if we don't have one, get out LPLISTBOXDATA lpData = ListBox_GetData(hWindow); if (!lpData) return(NULL); if (!lpData->fEnableMove) return(NULL); // the number of items in the list box lpData->iCount = ListBox_GetCount(hWindow); if (lpData->iCount == 0 ) // don't do anything to and empty list box return(NULL); // see if this is a multiple selection listbox DWORD dwStyle = GetWindowLong (hWindow, GWL_STYLE); if (dwStyle & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) { // see how many items are selected we only work if one is selected int iSelCount = ListBox_GetSelCount(hWindow); if (iSelCount != 1) return(NULL); ListBox_GetSelItems(hWindow, 1, &lpData->iOldPos); } else // the current item lpData->iOldPos = ListBox_GetCurSel(hWindow); return(lpData); }
void ListBox_MoveAllStrings(HWND hwndListBox, int iAmount) { int iCount = ListBox_GetSelCount(hwndListBox), i; LPINT lpiItems = (LPINT)Mem_Alloc(iCount * sizeof(INT)); SetWindowRedraw(hwndListBox, FALSE); ListBox_GetSelItems(hwndListBox, iCount, lpiItems); if (iAmount < 0) { for (i = 0; i < iCount; i++) { int nIndex = ListBox_MoveString(hwndListBox, lpiItems[i], iAmount, TRUE); ASSERT(nIndex != LB_ERR); } } else { for (i = (iCount - 1); i > -1; i--) { int nIndex = ListBox_MoveString(hwndListBox, lpiItems[i], iAmount, TRUE); ASSERT(nIndex != LB_ERR); } } // Reselect all the items moved for (i = 0; i < iCount; i++) ListBox_SetSel(hwndListBox, TRUE, lpiItems[i] + iAmount); SetWindowRedraw(hwndListBox, TRUE); RedrawWindow(hwndListBox, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW); Mem_Free(lpiItems); }
/* This function removes an item from the outbasket. */ void FASTCALL DeleteFromOutBasket( LPOB lpob ) { /* Now closes down the window if there is one * YH 03/05/96 */ HWND hwndSay; if( hwndSay = Amob_GetEditWindow( lpob ) ) SendDlgCommand( hwndSay, IDCANCEL, BN_CLICKED ); if( NULL != hwndOutBasket && !fIgnoreDeleteEvent ) { HWND hwndList; hwndList = GetDlgItem( hwndOutBasket, IDD_LIST ); if( hwndList ) { int wCount; int nSel; wCount = ListBox_GetCount( hwndList ); for( nSel = 0; nSel < wCount; ++nSel ) if( (LPOB)ListBox_GetItemData( hwndList, nSel ) == lpob ) { if( ListBox_DeleteString( hwndList, nSel ) == nSel ) --nSel; if( ListBox_GetSelCount( hwndList ) == 0 ) ListBox_SetSel( hwndList, TRUE, nSel ); break; } } UpdateOutBasketStatus(); } }
/* This function updates the out-basket status */ void FASTCALL UpdateOutBasketStatus( void ) { if( hwndOutBasket ) { BOOL fIsEditable; BOOL fHasItem; BOOL fCanDelete; HWND hwndList; int nSelCount; hwndList = GetDlgItem( hwndOutBasket, IDD_LIST ); fIsEditable = FALSE; fHasItem = ( ListBox_GetCount( hwndList ) > 0 ); fCanDelete = FALSE; if( ( nSelCount = ListBox_GetSelCount( hwndList ) ) > 0 ) { OBINFO obinfo; LPOB lpob; int nSel; ListBox_GetSelItems( hwndList, 1, &nSel ); lpob = (LPOB)ListBox_GetItemData( hwndList, nSel ); Amob_GetObInfo( lpob, &obinfo ); SetWindowText( GetDlgItem( hwndOutBasket, IDD_HOLD ), ( obinfo.obHdr.wFlags & OBF_HOLD ) ? GS(IDS_STR282) : GS(IDS_STR281) ); SetWindowText( GetDlgItem( hwndOutBasket, IDD_KEEP ), ( obinfo.obHdr.wFlags & OBF_KEEP ) ? GS(IDS_STR318) : GS(IDS_STR319) ); fIsEditable = !fInitiatingBlink && Amob_IsEditable( obinfo.obHdr.clsid ) && !TestF(obinfo.obHdr.wFlags, OBF_PENDING ) && !TestF(obinfo.obHdr.wFlags, OBF_ACTIVE ); fCanDelete = !fInitiatingBlink && !TestF(obinfo.obHdr.wFlags, OBF_PENDING ) && !TestF(obinfo.obHdr.wFlags, OBF_ACTIVE ); } EnableControl( hwndOutBasket, IDOK, fIsEditable ); EnableControl( hwndOutBasket, IDD_LIST, fHasItem ); EnableControl( hwndOutBasket, IDD_DELETE, fCanDelete ); EnableControl( hwndOutBasket, IDD_HOLD, fHasItem && fCanDelete ); EnableControl( hwndOutBasket, IDD_KEEP, fHasItem && fCanDelete ); } }
///////////////////////////////////////////////////////////////////////// //Function: RemoveItem //Description: remove a item from selected object list ///////////////////////////////////////////////////////////////////////// void RemoveItem(HWND hDlg) { long nObjects ; long Index ; EnableWindow(GetDlgItem(hDlg, removeB), FALSE) ; EnableWindow(GetDlgItem(hDlg, editB), FALSE) ; /*nObjects = SendDlgItemMessage (hDlg, IDD_FIELDSLIST, LB_GETSELCOUNT, 0, 0L) ; if (nObjects!=0 &&(0!=SendDlgItemMessage (hDlg, IDD_FIELDSLIST, LB_GETCOUNT, 0, 0))) { while(SendDlgItemMessage (hDlg, IDD_FIELDSLIST, LB_GETSELITEMS, 1, (long) &Index) !=0) { SendDlgItemMessage (hDlg, IDD_FIELDSLIST, LB_DELETESTRING, (WORD)Index, 0) ; } SendDlgItemMessage (hDlg, IDD_FIELDSLIST, LB_SETCARETINDEX, 0, 0) ; }*/ nObjects = ListBox_GetSelCount (GetDlgItem(hDlg, IDD_FIELDSLIST)) ; if(nObjects!=0&&(0!=ListBox_GetCount(GetDlgItem(hDlg, IDD_FIELDSLIST)))) { while(ListBox_GetSelItems (GetDlgItem(hDlg,IDD_FIELDSLIST),1, &Index)!=0) { ListBox_DeleteString (GetDlgItem(hDlg, IDD_FIELDSLIST), Index) ; } ListBox_SetCaretIndex (GetDlgItem(hDlg, IDD_FIELDSLIST),0) ; } SetFocus(GetDlgItem (hDlg,IDD_FIELDSLIST)) ; }
///////////////////////////////////////////////////////////////////////// //Function: AddItem //Description: Add a item to Selected object list ///////////////////////////////////////////////////////////////////////// void AddItem (HWND hDlg) { int nObjects ; char *lpszString ; int *SelectedIndexes ; DWORD objectIndex ; OBJECTID theObj ; int i ; //nObjects = (int) SendDlgItemMessage (hDlg, IDD_OBJECTSLIST, LB_GETSELCOUNT, 0, 0L) ; nObjects = ListBox_GetSelCount (GetDlgItem(hDlg, IDD_OBJECTSLIST)) ; if (nObjects == 0) return ; SelectedIndexes = new int[nObjects] ; //SendDlgItemMessage (hDlg, IDD_OBJECTSLIST, LB_GETSELITEMS, (WPARAM)nObjects, (long)SelectedIndexes) ; ListBox_GetSelItems (GetDlgItem (hDlg, IDD_OBJECTSLIST), nObjects, SelectedIndexes) ; lpszString = new char[256] ; for (i = 0; i < nObjects; i++) { //SendDlgItemMessage (hDlg, IDD_OBJECTSLIST, LB_GETTEXT, SelectedIndexes[i], (long) lpszString) ; //theObj =(OBJECTID)SendDlgItemMessage (hDlg, IDD_OBJECTSLIST, LB_GETITEMDATA, SelectedIndexes[i], 0) ; //objectIndex = (DWORD)SendDlgItemMessage(hDlg, IDD_FIELDSLIST, LB_INSERTSTRING, -1, (long)lpszString) ; //SendDlgItemMessage(hDlg, IDD_FIELDSLIST, LB_SETITEMDATA, (WPARAM)objectIndex, (long)theObj) ; ListBox_GetText (GetDlgItem (hDlg, IDD_FIELDSLIST),SelectedIndexes[i], lpszString) ; theObj = (OBJECTID)ListBox_GetItemData (GetDlgItem (hDlg, IDD_FIELDSLIST),SelectedIndexes[i]) ; objectIndex = ListBox_InsertString (GetDlgItem (hDlg, IDD_FIELDSLIST), -1, lpszString) ; ListBox_SetItemData (GetDlgItem(hDlg, IDD_FIELDSLIST), objectIndex, theObj) ; } delete(SelectedIndexes) ; delete(lpszString) ; return ; }
vector<int> ListBox::GetSelectedItemsIndex() { int count = ListBox_GetSelCount(ThisWindow); vector<int> res(count); if (count != 0) ListBox_GetSelItems(ThisWindow, count, &res[0]); return res; }
/* This function simply inserts the pointer to the out-basket object into the * list box for the out-basket then updates the total of out-basket items. It * does not check to ascertain whether the object already appears in the list, * so this function should only be called for new out-basket items. */ void FASTCALL AddStringToOutBasket( HWND hwnd, LPOB lpob ) { HWND hwndList; hwndList = GetDlgItem( hwnd, IDD_LIST ); if( hwndList ) { ListBox_InsertString( hwndList, -1, lpob ); if( ListBox_GetSelCount( hwndList ) == 0 ) ListBox_SetSel( hwndList, TRUE, 0 ); ShowOutBasketTotal( hwnd ); } }
///////////////////////////////////////////////////////////////////////// //Function: EditItem //Description: Edit a item in Selected Object list ///////////////////////////////////////////////////////////////////////// void EditItem(HWND hDlg) { long nObjects ; int Index ; OBJECTID theObject ; //nObjects = SendDlgItemMessage (hDlg, IDD_FIELDSLIST, LB_GETSELCOUNT, 0, 0L) ; nObjects = ListBox_GetSelCount (GetDlgItem(hDlg, IDD_FIELDSLIST)) ; if (nObjects != 1) return ; //SendDlgItemMessage (hDlg, IDD_FIELDSLIST, LB_GETSELITEMS, 1, (long)&Index) ; //theObject =(OBJECTID) SendDlgItemMessage(hDlg, IDD_FIELDSLIST, LB_GETITEMDATA, Index, 0L) ; ListBox_GetSelItems (GetDlgItem(hDlg, IDD_FIELDSLIST),1, &Index) ; theObject = (OBJECTID) ListBox_GetItemData (GetDlgItem(hDlg, IDD_FIELDSLIST), Index) ; AObjEdit(theObject) ; return ; }
BOOL ListBox_DeleteAllStrings(HWND hwndListBox) { BOOL bSuccess = FALSE; int iCount = ListBox_GetSelCount(hwndListBox); LPINT lpiItems = (LPINT)_alloca(iCount * sizeof(INT)); ListBox_GetSelItems(hwndListBox, iCount, lpiItems); SetWindowRedraw(hwndListBox, FALSE); for ( ; iCount > 0; iCount--) { if (ListBox_DeleteString(hwndListBox, lpiItems[iCount - 1]) != LB_ERR) bSuccess = TRUE; } SetWindowRedraw(hwndListBox, TRUE); return (bSuccess); }
// Return number of selections and an array of selected integers int wxListBox::GetSelections(wxArrayInt& aSelections) const { aSelections.Empty(); if ( HasMultipleSelection() ) { int countSel = ListBox_GetSelCount(GetHwnd()); if ( countSel == LB_ERR ) { wxLogDebug(wxT("ListBox_GetSelCount failed")); } else if ( countSel != 0 ) { int *selections = new int[countSel]; if ( ListBox_GetSelItems(GetHwnd(), countSel, selections) == LB_ERR ) { wxLogDebug(wxT("ListBox_GetSelItems failed")); countSel = -1; } else { aSelections.Alloc(countSel); for ( int n = 0; n < countSel; n++ ) aSelections.Add(selections[n]); } delete [] selections; } return countSel; } else // single-selection listbox { if (ListBox_GetCurSel(GetHwnd()) > -1) aSelections.Add(ListBox_GetCurSel(GetHwnd())); return aSelections.Count(); } }
/* This function intercepts messages for the out-basket list box window * so that we can handle the right mouse button. */ LRESULT EXPORT FAR PASCAL OutBaskListProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ) { switch( msg ) { case WM_ERASEBKGND: { RECT rc; GetClientRect( hwnd, &rc ); FillRect( (HDC)wParam, &rc, hbrOutBaskWnd ); return( TRUE ); } case WM_CONTEXTMENU: /*!!SM!!*/ case WM_RBUTTONDOWN: { POINT pt; LPOB lpob; HWND hwndOpen; HMENU hPopupMenu; int index; AEPOPUP aep; /* Make sure this window is active and select the item * at the cursor. */ if( hwndActive != GetParent( hwnd ) ) SendMessage( hwndMDIClient, WM_MDIACTIVATE, (WPARAM)hwndOutBasket, 0L ); /* Select the item under the cursor only if nothing is * currently selected. */ index = ItemFromPoint( hwnd, (short)LOWORD(lParam), (short)HIWORD(lParam) ); if( ListBox_GetSel( hwnd, index ) == 0 ) { CallWindowProc( lpProcListCtl, hwnd, WM_LBUTTONDOWN, wParam, lParam ); CallWindowProc( lpProcListCtl, hwnd, WM_LBUTTONUP, wParam, lParam ); } /* Get the out-basket menu. */ hPopupMenu = GetSubMenu( hPopupMenus, IPOP_OBASKWINDOW ); hwndOpen = GetDlgItem( GetParent( hwnd ), IDOK ); MenuEnable( hPopupMenu, IDOK, IsWindowEnabled( hwndOpen ) ); /* If we have any selected items, use the attributes * of the first item to determine the menu items. */ if( ListBox_GetSelCount( hwnd ) > 0 ) { OBINFO obinfo; ListBox_GetSelItems( hwnd, 1, &index ); lpob = (LPOB)ListBox_GetItemData( hwnd, index ); Amob_GetObInfo( lpob, &obinfo ); if( TestF(obinfo.obHdr.wFlags, OBF_HOLD) ) MenuString( hPopupMenu, IDD_HOLD, GS(IDS_STR275) ); else MenuString( hPopupMenu, IDD_HOLD, GS(IDS_STR277) ); if( TestF(obinfo.obHdr.wFlags, OBF_KEEP) ) MenuString( hPopupMenu, IDD_KEEP, GS(IDS_STR440) ); else MenuString( hPopupMenu, IDD_KEEP, GS(IDS_STR439) ); MenuEnable( hPopupMenu, IDOK, !fInitiatingBlink && Amob_IsEditable( obinfo.obHdr.clsid ) && !TestF(obinfo.obHdr.wFlags, OBF_PENDING) && !TestF(obinfo.obHdr.wFlags, OBF_ACTIVE ) ); MenuEnable( hPopupMenu, IDD_DELETE, !fInitiatingBlink && !TestF(obinfo.obHdr.wFlags, OBF_PENDING ) && !TestF(obinfo.obHdr.wFlags, OBF_ACTIVE ) ); MenuEnable( hPopupMenu, IDD_KEEP, !fInitiatingBlink && !TestF(obinfo.obHdr.wFlags, OBF_PENDING ) && !TestF(obinfo.obHdr.wFlags, OBF_ACTIVE ) ); MenuEnable( hPopupMenu, IDD_HOLD, !fInitiatingBlink && !TestF(obinfo.obHdr.wFlags, OBF_PENDING ) && !TestF(obinfo.obHdr.wFlags, OBF_ACTIVE ) ); } else { MenuEnable( hPopupMenu, IDOK, FALSE ); MenuEnable( hPopupMenu, IDD_KEEP, FALSE ); MenuEnable( hPopupMenu, IDD_HOLD, FALSE ); MenuEnable( hPopupMenu, IDD_DELETE, FALSE ); } /* Call the AE_POPUP event. */ aep.wType = WIN_OUTBASK; aep.pFolder = NULL; aep.pSelectedText = NULL; aep.cchSelectedText = 0; aep.hMenu = hPopupMenu; aep.nInsertPos = 2; Amuser_CallRegistered( AE_POPUP, (LPARAM)(LPSTR)&aep, 0L ); GetCursorPos( &pt ); TrackPopupMenu( hPopupMenu, TPM_LEFTALIGN|TPM_RIGHTBUTTON, pt.x, pt.y, 0, hwndFrame, NULL ); return( 0 ); } case WM_KEYDOWN: /* Trap the Delete and Shift+Delete key in the outbasket * list box to handle the Delete command. */ if( wParam == VK_DELETE ) { PostDlgCommand( GetParent( hwnd ), IDD_DELETE, 0 ); return( 0 ); } /* Trap the Pause and Shift+Pause key in the outbasket * list box to handle the Hold command. */ if( wParam == VK_PAUSE ) { PostDlgCommand( GetParent( hwnd ), IDD_HOLD, 1 ); return( 0 ); } break; } return( CallWindowProc( lpProcListCtl, hwnd, msg, wParam, lParam ) ); }
BOOL CALLBACK GroupObjectProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { OBJECTID hobjGroup ; int Index ; OBJECTID theObj ; switch (message) { case WM_INITDIALOG: AUtlSetTitleFont(OTYPE_GROUP, NULL, GetDlgItem(hDlg, IDD_OBJECT)); AUtlCenterDialog(hDlg, 0); SetWindowLong(hDlg, DWL_USER, lParam) ; hobjGroup = (OBJECTID)lParam ; InitDialog(hDlg, hobjGroup) ; return FALSE ; case WM_COMMAND: if (LOWORD(wParam) >= textB && LOWORD(wParam) <= otherB) { CheckRadioButton (hDlg, textB, otherB, LOWORD(wParam)) ; UpdateObjectList(hDlg, LOWORD(wParam)) ; return TRUE ; } switch (LOWORD(wParam)) { case IDD_OBJECTSLIST: //switch (HIWORD (lParam)) switch(HIWORD(wParam)) { case LBN_SELCHANGE: EnableWindow(GetDlgItem(hDlg, addB), TRUE) ; return TRUE ; case LBN_DBLCLK: AddItem(hDlg) ; return TRUE ; } break ; case IDD_FIELDSLIST: switch (HIWORD (lParam)) { case LBN_SELCHANGE: EnableWindow (GetDlgItem(hDlg, removeB), TRUE) ; //if (SendDlgItemMessage (hDlg, IDD_FIELDSLIST, LB_GETSELCOUNT, 0, 0L)==1) if (ListBox_GetSelCount (GetDlgItem(hDlg, IDD_FIELDSLIST))==1) EnableWindow (GetDlgItem(hDlg, editB), TRUE) ; else EnableWindow (GetDlgItem(hDlg, editB), FALSE) ; return TRUE ; case LBN_DBLCLK: Index = (int)ListBox_GetCurSel(GetDlgItem(hDlg, IDD_FIELDSLIST)) ; theObj = (OBJECTID)ListBox_GetItemData(GetDlgItem (hDlg,IDD_FIELDSLIST), Index) ; //theObj =(OBJECTID) SendDlgItemMessage (hDlg, IDD_FIELDSLIST, LB_GETITEMDATA, Index, 0) ; return (AObjEdit(theObj) == A_MODIFIED); } break ; case addB: AddItem(hDlg) ; //EnableWindow (GetDlgItem(hDlg, addB), FALSE) ; return TRUE ; case removeB: RemoveItem(hDlg) ; return TRUE ; case editB: EditItem(hDlg) ; return TRUE ; case IDOK: // save the File object's default extention // save the typeIDs for each object to be stored hobjGroup =(OBJECTID)GetWindowLong (hDlg, DWL_USER) ; saveObj (hDlg, hobjGroup) ; EndDialog (hDlg, TRUE) ; return TRUE ; case IDCANCEL: EndDialog (hDlg, FALSE) ; return TRUE ; case IDHELP: WinHelp (hDlg, "serhelp.hlp", HELP_CONTEXT, HELPID_OBJD_Grup) ; return TRUE ; } } return FALSE ; }