/* * 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); }
/* * StatsListRButton: User clicked right button on stats list. */ void StatsListRButton(HWND hwnd, BOOL fDoubleClick, int x, int y, UINT keyFlags) { int index; Statistic *s; SetFocus(hwnd); index = y / ListBox_GetItemHeight(hwnd, 0) + ListBox_GetTopIndex(hwnd); if (index >= ListBox_GetCount(hwnd)) return; ListBox_SetCurSel(hwnd, index); s = (Statistic *) ListBox_GetItemData(hwnd, index); if (s == NULL) return; SetDescParams(cinfo->hMain, DESC_NONE); RequestLook(s->list.id); }
/* * InventoryKey: User pressed a key on the inventory list. * Return True iff key should NOT be passed on to Windows for default processing. */ Bool InventoryKey(HWND hwnd, UINT key, Bool fDown, int cRepeat, UINT flags) { ID id; Bool held_down = (flags & 0x4000) ? True : False; /* Is key being held down? */ int action, params; InvItem *item; void *action_data; Bool inform; UserDidSomething(); /* See if inventory handles this key specially */ action = TranslateKey(key, inventory_key_table, &action_data); if (action == A_NOACTION) return False; // Skip held-down keys, except for moving cursor around if (held_down && !IsCursorAction(action)) return True; item = InventoryGetCurrentItem(); if (item == NULL) id = INVALID_ID; else id = item->obj->id; // See if we should inform modules about event inform = True; switch (action) { case A_TABFWD: case A_TABBACK: case A_TOGGLEUSE: case A_USE: case A_UNUSE: case A_DROP: case A_APPLY: case A_LOOKINVENTORY: case A_SELECT: action_data = (void *) id; break; default: inform = False; // Modules will be informed in PerformAction call below } // See if a module wants to handle this action if (inform) if (ModuleEvent(EVENT_USERACTION, action, action_data) == False) return True; if (IsCursorAction(action)) { InventoryCursorMove(action); return True; } switch (action) { case A_TABFWD: TextInputSetFocus(True); // ajw //StatsSetFocus(True); break; case A_TABBACK: SetFocus(cinfo->hMain); break; case A_TOGGLEUSE: if (id != INVALID_ID) { if (item->obj->flags & OF_APPLYABLE) StartApply(id); else ToggleUse(id); } break; case A_USE: if (id != INVALID_ID) RequestUse(id); break; case A_UNUSE: if (id != INVALID_ID) RequestUnuse(id); break; case A_DROP: if (id != INVALID_ID) InventoryDropCurrentItem(NULL); break; case A_APPLY: if (id != INVALID_ID) StartApply(id); break; case A_LOOKINVENTORY: if (id == INVALID_ID) break; params = DESC_DROP; if (item->is_using) params |= DESC_UNUSE; else if (item->obj->flags & OF_APPLYABLE) params |= DESC_APPLY; else params |= DESC_USE; SetDescParams(cinfo->hMain, params); RequestLook(id); break; case A_SELECT: if (id != INVALID_ID) SelectedObject(id); break; default: PerformAction(action, action_data); break; } return True; }
BOOL CALLBACK SendOfferDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { static HWND hwndSend, hwndReceive; /* Subwindows */ switch (message) { case WM_INITDIALOG: hSendOfferDlg = hDlg; CenterWindow(hDlg, hMain); hwndSend = GetDlgItem(hDlg, IDC_OFFERSEND); hwndReceive = GetDlgItem(hDlg, IDC_OFFERRECEIVE); SendMessage(hDlg, BK_SETDLGFONTS, 0, 0); // Set up owner drawn boxes SetWindowLong(hwndSend, GWL_USERDATA, OD_DRAWOBJ); SetWindowLong(hwndReceive, GWL_USERDATA, OD_DRAWOBJ); SendInfo = (SendOfferDialogStruct *) lParam; /* Display offered items in list */ ItemListSetContents(hwndSend, SendInfo->items, TRUE); // boolean is to list quantities /* Subclass list boxes */ lpfnDefListProc = SubclassWindow(hwndSend, OfferListProc); SubclassWindow(hwndReceive, OfferListProc); /* Display receiver's name */ Edit_SetText(GetDlgItem(hDlg, IDC_OFFEREDIT), LookupNameRsc(SendInfo->receiver_name)); /* Gray out "Accept" button until counteroffer arrives */ ShowWindow(hwndReceive, SW_HIDE); EnableWindow(GetDlgItem(hDlg, IDOK), FALSE); return TRUE; case WM_ACTIVATE: if (wParam == 0) hCurrentDlg = NULL; else hCurrentDlg = hDlg; return TRUE; case BK_SETDLGFONTS: SetWindowFont(GetDlgItem(hDlg, IDC_OFFEREDIT), GetFont(FONT_LIST), TRUE); return TRUE; case BK_SETDLGCOLORS: InvalidateRect(hDlg, NULL, TRUE); return TRUE; case WM_COMPAREITEM: return ItemListCompareItem(hDlg, (const COMPAREITEMSTRUCT *) lParam); case WM_MEASUREITEM: ItemListMeasureItem(hDlg, (MEASUREITEMSTRUCT *) lParam); return TRUE; case WM_DRAWITEM: return ItemListDrawItemNoSelect(hDlg, (const DRAWITEMSTRUCT *)(lParam)); HANDLE_MSG(hDlg, WM_CTLCOLOREDIT, DialogCtlColor); HANDLE_MSG(hDlg, WM_CTLCOLORLISTBOX, DialogCtlColor); HANDLE_MSG(hDlg, WM_CTLCOLORSTATIC, DialogCtlColor); HANDLE_MSG(hDlg, WM_CTLCOLORDLG, DialogCtlColor); HANDLE_MSG(hDlg, WM_INITMENUPOPUP, InitMenuPopupHandler); case BK_COUNTEROFFER: /* Update receive list */ receive_items = (list_type) lParam; ItemListSetContents(hwndReceive, receive_items, True); /* Enable Accept button */ ShowWindow(hwndReceive, SW_NORMAL); EnableWindow(GetDlgItem(hDlg, IDOK), TRUE); SetWindowText(GetDlgItem(hDlg, IDC_MESSAGE), GetString(hInst, IDS_GOTOFFER)); return TRUE; case WM_CLOSE: SendCancelOffer(); /* fall through */ case BK_OFFERDONE: SendOfferEndDialog(hDlg); break; case WM_COMMAND: switch(GET_WM_COMMAND_ID(wParam, lParam)) { case IDC_OFFERSEND: case IDC_OFFERRECEIVE: /* Double click ==> look at item */ if (GET_WM_COMMAND_CMD(wParam, lParam) == LBN_DBLCLK) { RequestLook(ItemListGetId(GET_WM_COMMAND_HWND(wParam, lParam))); SetDescParams(hDlg, DESC_NONE); } return TRUE; case IDCANCEL: SendCancelOffer(); SendOfferEndDialog(hDlg); return TRUE; case IDOK: SendAcceptOffer(); SendOfferEndDialog(hDlg); return TRUE; } break; } return FALSE; }
BOOL CALLBACK RcvOfferDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { static HWND hwndSend, hwndReceive; switch (message) { case WM_INITDIALOG: CenterWindow(hDlg, hMain); hwndSend = GetDlgItem(hDlg, IDC_OFFERSEND); hwndReceive = GetDlgItem(hDlg, IDC_OFFERRECEIVE); SendMessage(hDlg, BK_SETDLGFONTS, 0, 0); // Set up owner drawn boxes SetWindowLong(hwndSend, GWL_USERDATA, OD_DRAWOBJ); SetWindowLong(hwndReceive, GWL_USERDATA, OD_DRAWOBJ); RcvInfo = (RcvOfferDialogStruct *) lParam; /* Display offered items in list */ ItemListSetContents(hwndReceive, RcvInfo->items, True); /* Subclass list boxes */ lpfnDefListProc = (WNDPROC) GetWindowLong(hwndSend, GWL_WNDPROC); SubclassWindow(hwndSend, OfferListProc); SubclassWindow(hwndReceive, OfferListProc); /* Display receiver's name */ Edit_SetText(GetDlgItem(hDlg, IDC_OFFEREDIT), LookupNameRsc(RcvInfo->sender_name)); ShowWindow(hDlg, SW_HIDE); hRcvOfferDlg = hDlg; return TRUE; case WM_ACTIVATE: if (wParam == 0) hCurrentDlg = NULL; else hCurrentDlg = hDlg; return TRUE; case BK_SETDLGFONTS: SetWindowFont(GetDlgItem(hDlg, IDC_OFFEREDIT), GetFont(FONT_LIST), TRUE); return TRUE; case BK_SETDLGCOLORS: InvalidateRect(hDlg, NULL, TRUE); return TRUE; case WM_COMPAREITEM: return ItemListCompareItem(hDlg, (const COMPAREITEMSTRUCT *) lParam); case WM_MEASUREITEM: ItemListMeasureItem(hDlg, (MEASUREITEMSTRUCT *) lParam); return TRUE; case WM_DRAWITEM: return ItemListDrawItemNoSelect(hDlg, (const DRAWITEMSTRUCT *)(lParam)); HANDLE_MSG(hDlg, WM_CTLCOLOREDIT, DialogCtlColor); HANDLE_MSG(hDlg, WM_CTLCOLORLISTBOX, DialogCtlColor); HANDLE_MSG(hDlg, WM_CTLCOLORSTATIC, DialogCtlColor); HANDLE_MSG(hDlg, WM_CTLCOLORDLG, DialogCtlColor); HANDLE_MSG(hDlg, WM_INITMENUPOPUP, InitMenuPopupHandler); case WM_CLOSE: SendCancelOffer(); /* fall through */ case BK_OFFERDONE: RcvOfferEndDialog(hDlg); return TRUE; case BK_COUNTEROFFERED: /* Display items we counteroffered */ send_items = (list_type) lParam; ItemListSetContents(hwndSend, send_items, True); return TRUE; case WM_COMMAND: switch(GET_WM_COMMAND_ID(wParam, lParam)) { case IDC_OFFERSEND: case IDC_OFFERRECEIVE: /* Double click ==> look at item */ if (GET_WM_COMMAND_CMD(wParam, lParam) == LBN_DBLCLK) { RequestLook(ItemListGetId(GET_WM_COMMAND_HWND(wParam, lParam))); SetDescParams(hDlg, DESC_NONE); } return TRUE; case IDC_SETITEMS: /* Close any other look dialogs that are up */ AbortLookList(); /* Get list of items from inventory & tell server */ send_items = UserInventoryList(hDlg, GetString(hInst, IDS_OFFERITEMS)); /* fall through */ case IDOK: /* Send counteroffer */ RequestCounteroffer(send_items); send_items = ObjectListDestroy(send_items); EnableWindow(GetDlgItem(hDlg, IDOK), FALSE); EnableWindow(GetDlgItem(hDlg, IDC_SETITEMS), FALSE); SetWindowText(GetDlgItem(hDlg, IDC_MESSAGE), GetString(hInst, IDS_WAITRESPONSE)); return TRUE; case IDCANCEL: SendCancelOffer(); RcvOfferEndDialog(hDlg); return TRUE; } break; } return FALSE; }
/* * 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; } }