/* * OfferListProc: Subclassed window procedure for offer list boxes. */ long CALLBACK OfferListProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { ID id; switch (message) { case WM_KEYDOWN: /* Return ==> look at item */ if (wParam == VK_SPACE) { id = ItemListGetId(hwnd); if (id == INVALID_ID) return 0; RequestLook(id); SetDescParams(GetParent(hwnd), DESC_NONE); /* Parent = dialog box */ return 0; } if (wParam == VK_DOWN) { id = ListBox_GetCaretIndex(hwnd); debug(("Old index = %ld\n", id)); } break; case WM_CHAR: return 0; /* Disable default Windows list box behavior */ } return CallWindowProc(lpfnDefListProc, hwnd, message, wParam, lParam); }
LOCAL void Select_OnKeyDown(HWND hWindow, UINT vk, BOOL fDown, int cRepeat, UINT flags) /***********************************************************************/ { int iCaretIndex, iTopItem, nItems; // get the listbox data pointer LPLISTBOXDATA lpData = ListBox_GetData(hWindow); if (!lpData) { FORWARD_WM_KEYDOWN(hWindow, vk, cRepeat, flags, ListBox_CallWindowProc); } else if (vk == VK_UP) { iTopItem = ListBox_GetTopIndex(hWindow); iCaretIndex = ListBox_GetCaretIndex(hWindow); --iCaretIndex; if (iCaretIndex < 0) return; // make sure the new top item is selected SelectItems(hWindow, iCaretIndex); // scroll the listbox and make sure it gets repainted if (iCaretIndex < iTopItem) ListBox_SetTopIndex(hWindow, iCaretIndex); UpdateWindow(hWindow); FORWARD_WM_COMMAND(GetParent(hWindow), GetDlgCtrlID(hWindow), hWindow, LBN_SELCHANGE, SendMessage); } else if (vk == VK_DOWN) { RECT rect; int iItemHeight, iVisible; iTopItem = ListBox_GetTopIndex(hWindow); iCaretIndex = ListBox_GetCaretIndex(hWindow); ++iCaretIndex; nItems = ListBox_GetCount(hWindow); if (iCaretIndex >= nItems) return; // make sure the new top item is selected SelectItems(hWindow, iCaretIndex); // get the client area GetClientRect(hWindow, &rect); // the height of each item iItemHeight = ListBox_GetItemHeight(hWindow, 0); // the number of visible items iVisible = (rect.bottom - rect.top) / iItemHeight; // see if there is anything to scroll if (iCaretIndex >= (iTopItem+iVisible)) { ++iTopItem; ListBox_SetTopIndex(hWindow, iTopItem); } UpdateWindow(hWindow); FORWARD_WM_COMMAND(GetParent(hWindow), GetDlgCtrlID(hWindow), hWindow, LBN_SELCHANGE, SendMessage); } // ignore all other keystrokes }
/* * LookCommand: Handle WM_COMMAND messages. */ void LookCommand(HWND hDlg, int ctrl_id, HWND hwndCtl, UINT codeNotify) { int index, num_entries, i, amount, currentAmount; list_type selection; object_node *obj; char buf[MAXNAME + 1], temp[16]; switch(ctrl_id) { case IDC_ITEMFIND: if (codeNotify == EN_UPDATE) { /* Go to object in list that user has named */ Edit_GetText(info->hwndFind, buf, MAXNAME); index = ListBox_FindString(info->hwndListBox, -1, buf); if (index != LB_ERR) if (info->flags & LD_MULTIPLESEL) ListBox_SetCaretIndex(info->hwndListBox, index); else ListBox_SetCurSel(info->hwndListBox, index); } break; case IDC_ALL: /* In multiple selection box only, select all objects. If we require that * user give amounts, don't select amount objects */ num_entries = ListBox_GetCount(info->hwndListBox); ListBox_SetSel(info->hwndListBox, TRUE, -1); WindowBeginUpdate(info->hwndQuanList); // Select all for number items for (i=0; i < num_entries; i++) { info->selected[i] = True; obj = (object_node *) ListBox_GetItemData(info->hwndListBox, i); if (IsNumberObj(obj->id)) amount = obj->amount; else amount = 1; obj->temp_amount = amount; ListBox_DeleteString(info->hwndQuanList,i); sprintf(temp, "%d", amount); ListBox_InsertString(info->hwndQuanList,i,temp); ListBox_SetItemData(info->hwndQuanList,i,amount); } WindowEndUpdate(info->hwndQuanList); break; case IDC_ITEMLIST: switch (codeNotify) { case LBN_DBLCLK: /* Look at item */ index = ListBox_GetCaretIndex(info->hwndListBox); if (index != LB_ERR) { obj = (object_node *) ListBox_GetItemData(info->hwndListBox, index); RequestLook(obj->id); SetDescParams(hDlg, DESC_NONE); ListBox_SetSel(info->hwndListBox, FALSE, index); info->selected[index] = False; } break; case LBN_SELCHANGE: #if 0 LookSelChange(hwndCtl); #else index = ListBox_GetCurSel(info->hwndListBox); obj = (object_node *) ListBox_GetItemData(info->hwndListBox, index); WindowBeginUpdate(info->hwndQuanList); ListBox_DeleteString(info->hwndQuanList,index); if (ListBox_GetSel(info->hwndListBox,index)) { if (IsNumberObj(obj->id)) amount = obj->amount; else amount = 1; sprintf(temp, "%d", amount); } else { amount = 0; strcpy(temp," "); } ListBox_InsertString(info->hwndQuanList,index,temp); ListBox_SetItemData(info->hwndQuanList,index,amount); ListBox_SetSel(info->hwndListBox,amount > 0,index); info->selected[index] = (amount > 0); obj->temp_amount = amount; ListBox_SetSel(info->hwndQuanList,FALSE,index); WindowEndUpdate(info->hwndQuanList); #endif break; } break; case IDC_QUANLIST: if (codeNotify == LBN_SELCHANGE) { char temp[16]; index = (int)ListBox_GetCurSel(info->hwndQuanList); obj = (object_node *) ListBox_GetItemData(info->hwndListBox, index); currentAmount = (int)ListBox_GetItemData(info->hwndQuanList, index); amount = currentAmount; if (ListBox_GetItemData(info->hwndQuanList, index) > 0) { if (IsNumberObj(obj->id)) { MEASUREITEMSTRUCT m; int startAmount = currentAmount; if (currentAmount == 0) startAmount = obj->amount; /* Place amount dialog just beneath selected item */ ItemListMeasureItem(info->hwndQuanList, &m); // Force highlight on (we are editing it) ListBox_SetSel(info->hwndListBox,TRUE,index); if(InputNumber(hDlg,info->hwndQuanList, 0,(index - ListBox_GetTopIndex(info->hwndQuanList) + 1) * (m.itemHeight - 1), &amount,startAmount,1,obj->amount)) { ListBox_DeleteString(info->hwndQuanList,index); if (amount > 0) { sprintf(temp, "%d", amount); ListBox_InsertString(info->hwndQuanList, index, temp); } else { ListBox_InsertString(info->hwndQuanList,index," "); } ListBox_SetItemData(info->hwndQuanList, index, amount); } else amount = currentAmount; // reset highlight based on quantity - off if zero, on otherwise ListBox_SetSel(info->hwndListBox, (ListBox_GetItemData(info->hwndQuanList,index) > 0), index); } else { ListBox_DeleteString(info->hwndQuanList,index); if (currentAmount == 0) { amount = 1; strcpy(temp,"1"); } else { amount = 0; strcpy(temp," "); } ListBox_InsertString(info->hwndQuanList,index,temp); ListBox_SetItemData(info->hwndQuanList,index,amount); } } ListBox_SetSel(info->hwndListBox,amount > 0,index); info->selected[index] = (amount > 0); obj->temp_amount = amount; ListBox_SetCurSel(info->hwndQuanList,-1); } break; case IDOK: /* Get user's selection(s) */ num_entries = ListBox_GetCount(info->hwndListBox); selection = NULL; for (i = 0; i < num_entries; i++) { /* If item is selected, add to selection list, else free */ obj = (object_node *) ListBox_GetItemData(info->hwndListBox, i); if (ListBox_GetSel(info->hwndListBox, i) > 0) selection = list_add_item(selection, obj); else ObjectDestroyAndFree(obj); } LookDialogRetval = selection; EndDialog(hDlg, IDOK); break; case IDCANCEL: LookListFreeContents(info->hwndListBox); LookDialogRetval = NULL; EndDialog(hDlg, IDCANCEL); break; } }