summaryrefslogtreecommitdiffstats
path: root/media/player/list.h
blob: 264b9ed83f993ec6121b93a11c144d2626104bc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Copyright (c) 2009 The Chromium Authors. All rights reserved.  Use of this
// source code is governed by a BSD-style license that can be found in the
// LICENSE file.

// list.h : class for Recent Files list

#ifndef MEDIA_PLAYER_LIST_H_
#define MEDIA_PLAYER_LIST_H_

class CMruList : public CWindowImpl<CMruList, CListBox> {
 public:

  CMruList() {
    size_.cx = 400;
    size_.cy = 150;
  }

  HWND Create(HWND hwnd) {
    CWindowImpl<CMruList, CListBox>::Create(hwnd, rcDefault, NULL,
      WS_POPUP | WS_THICKFRAME | WS_CLIPCHILDREN | WS_CLIPSIBLINGS |
      WS_VSCROLL | LBS_NOINTEGRALHEIGHT,
      WS_EX_CLIENTEDGE);
    if (IsWindow())
      SetFont(AtlGetStockFont(DEFAULT_GUI_FONT));
    return m_hWnd;
  }

  BOOL BuildList(CRecentDocumentList& mru) {
    ATLASSERT(IsWindow());

    ResetContent();

    int docs_size = mru.m_arrDocs.GetSize();
    for (int i = 0; i < docs_size; i++)
      InsertString(0, mru.m_arrDocs[i].szDocName);  // Reverse order in array.

    if (docs_size > 0) {
      SetCurSel(0);
      SetTopIndex(0);
    }

    return TRUE;
  }

  BOOL ShowList(int x, int y) {
    return SetWindowPos(NULL, x, y, size_.cx, size_.cy,
                        SWP_NOZORDER | SWP_SHOWWINDOW);
  }

  void HideList() {
    RECT rect;
    GetWindowRect(&rect);
    size_.cx = rect.right - rect.left;
    size_.cy = rect.bottom - rect.top;
    ShowWindow(SW_HIDE);
  }

  void FireCommand() {
    int selection = GetCurSel();
    if (selection != LB_ERR) {
      ::SetFocus(GetParent());  // Will hide this window.
      ::SendMessage(GetParent(), WM_COMMAND,
                    MAKEWPARAM((WORD)(ID_FILE_MRU_FIRST + selection),
                               LBN_DBLCLK), (LPARAM)m_hWnd);
    }
  }

  BEGIN_MSG_MAP(CMruList)
    MESSAGE_HANDLER(WM_KEYDOWN, OnKeyDown)
    MESSAGE_HANDLER(WM_LBUTTONDBLCLK, OnLButtonDblClk)
    MESSAGE_HANDLER(WM_KILLFOCUS, OnKillFocus)
    MESSAGE_HANDLER(WM_NCHITTEST, OnNcHitTest)
  END_MSG_MAP()

  LRESULT OnKeyDown(UINT /*message*/,
                    WPARAM wparam,
                    LPARAM /*lparam*/,
                    BOOL& handled) {
    if (wparam == VK_RETURN)
      FireCommand();
    else
      handled = FALSE;
    return 0;
  }

  LRESULT OnLButtonDblClk(UINT /*message*/,
                          WPARAM /*wparam*/,
                          LPARAM /*lparam*/,
                          BOOL& /*handled*/) {
    FireCommand();
    return 0;
  }

  LRESULT OnKillFocus(UINT /*message*/,
                      WPARAM /*wparam*/,
                      LPARAM /*lparam*/,
                      BOOL& /*handled*/) {
    HideList();
    return 0;
  }

  LRESULT OnNcHitTest(UINT message,
                      WPARAM wparam,
                      LPARAM lparam,
                      BOOL& /*handled*/) {
    LRESULT result = DefWindowProc(message, wparam, lparam);
    switch (result) {
      case HTLEFT:
      case HTTOP:
      case HTTOPLEFT:
      case HTTOPRIGHT:
      case HTBOTTOMLEFT:
        result = HTCLIENT;  // Don't allow resizing here.
        break;
      default:
        break;
    }
    return result;
  }

 private:

  SIZE size_;
};

#endif  // MEDIA_PLAYER_LIST_H_