Разработка информационно-поисковой системы, страница 18

                  CallWindowProc(origLVWndProc, hWnd, mMsg, wParam, lParam);

                  return 0; /* no further processing of this message */

            }

            /* onlySelected=true if the item clicked is selected, and no others are */

            bool onlySelected = (ListView_GetItemState(hWnd, hti.iItem, LVIS_SELECTED) != 0);

            for (int item=0; item < wnd->rows; item++)

                  if (item!=hti.iItem && ListView_GetItemState(hWnd, item, LVIS_SELECTED)!=0)

                        onlySelected = false;

            bool ctrlKeyDown = ((wParam&MK_CONTROL) != 0);

            bool shiftKeyDown = ((wParam&MK_SHIFT) != 0);

            if (onlySelected && !ctrlKeyDown && !shiftKeyDown)

            {

                  /* deselect all items */

                  ListView_SetItemState(hWnd, -1, 0, LVIS_SELECTED);

                  /* get the bounding box for the field to be edited */

                  RECT bounds;

                  memset(&bounds, 0, sizeof(bounds));

                  ListView_GetSubItemRect (hWnd, hti.iItem, hti.iSubItem, LVIR_LABEL, &bounds);

                  TCHAR buf[256];

                  ListView_GetItemText (hWnd, hti.iItem, hti.iSubItem, (LPSTR)&buf, sizeof(buf));

                  if (coltype == CT_TEXT)

                  {

                        /* create the edit box */

                        hCell = CreateWindowEx (0, WC_EDIT, "",

                              WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL,

                              bounds.left, bounds.top,

                              bounds.right - bounds.left, bounds.bottom - bounds.top,

                              hWnd, 0, hInstance, NULL);

                        /* subclass */

                        origEditWndProc = (WNDPROC)SetWindowLong(hCell, GWL_WNDPROC, (DWORD)EditWndProc);

                        /* set edit box text to what that field's value is */

                        SendMessage(hCell, WM_SETTEXT, FALSE, (LPARAM)&buf);

                        /* select all text in the edit box */

                        SendMessage(hCell, EM_SETSEL, (WPARAM)(INT)0, (LPARAM)(INT)-1);

                  }

                  else

                  if (coltype == CT_COMBO || coltype == CT_COMBO_EX)

                  {

                        /* create the combo box */

                        hCell = CreateWindowEx (0, WC_COMBOBOX, "",

                              WS_VISIBLE | WS_CHILD | /*CBS_AUTOHSCROLL | CBS_NOINTEGRALHEIGHT | */

                              CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP,

                              bounds.left, bounds.top,

                              bounds.right - bounds.left, 120,//2*(bounds.bottom - bounds.top),

                        //    60, 62, 136, 60,

                              hWnd, 0, hInstance, NULL);

                        /* subclass */

                        origComboWndProc = (WNDPROC)SetWindowLong(hCell, GWL_WNDPROC, (DWORD)ComboWndProc);

                        /* set combo box text to what that field's value is */

                        load_combobox (wnd, hCell);

                        /* select all text in the edit box */

                        rc = SendMessage(hCell, CB_SETCURSEL,

                              SendMessage(hCell, CB_FINDSTRING, (WPARAM)-1, (LPARAM)buf), (LPARAM)(INT)0);

                  }

                  /* use the default GUI font, not the default system (fixed) font */

                  rc = SendMessage(hCell, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), FALSE);

                  ShowWindow (hCell, SW_SHOWNORMAL);

                  UpdateWindow(hCell);

                  SetFocus(hCell);

            }

                  else CallWindowProc(origLVWndProc, hWnd, mMsg, wParam, lParam);

            return 0; /* no further processing of this message */

      }

      case WM_LBUTTONDBLCLK:

      {

            /* treat the double-click as another single click */

            SendMessage(hWnd, WM_LBUTTONDOWN, wParam, lParam);

            return 0;