Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Unified Diff: views/controls/listbox/native_listbox_win.cc

Issue 2815034: Win: Add listbox view. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « views/controls/listbox/native_listbox_win.h ('k') | views/controls/listbox/native_listbox_wrapper.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: views/controls/listbox/native_listbox_win.cc
===================================================================
--- views/controls/listbox/native_listbox_win.cc (revision 0)
+++ views/controls/listbox/native_listbox_win.cc (revision 0)
@@ -0,0 +1,135 @@
+// Copyright (c) 2010 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.
+
+#include "views/controls/listbox/native_listbox_win.h"
+
+#include <commctrl.h>
+#include <windowsx.h>
+
+#include "app/l10n_util.h"
+#include "app/l10n_util_win.h"
+#include "app/resource_bundle.h"
+#include "base/logging.h"
+#include "base/utf_string_conversions.h"
+#include "base/win_util.h"
+#include "gfx/font.h"
+#include "views/controls/listbox/listbox.h"
+#include "views/widget/widget.h"
+
+namespace views {
+
+////////////////////////////////////////////////////////////////////////////////
+// NativeListboxWin, public:
+
+NativeListboxWin::NativeListboxWin(Listbox* listbox,
+ const std::vector<string16>& strings,
+ Listbox::Listener* listener)
+ : listbox_(listbox),
+ strings_(strings),
+ listener_(listener) {
+ // Associates the actual HWND with the listbox so the listbox is the one
+ // considered as having the focus (not the wrapper) when the HWND is
+ // focused directly (with a click for example).
+ set_focus_view(listbox);
+}
+
+NativeListboxWin::~NativeListboxWin() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// NativeListboxWin, NativeListboxWrapper implementation:
+
+int NativeListboxWin::GetRowCount() const {
+ if (!native_view())
+ return 0;
+ return ListBox_GetCount(native_view());
+}
+
+int NativeListboxWin::SelectedRow() const {
+ if (!native_view())
+ return -1;
+ return ListBox_GetCurSel(native_view());
+}
+
+void NativeListboxWin::SelectRow(int row) {
+ if (!native_view())
+ return;
+ ListBox_SetCurSel(native_view(), row);
+}
+
+View* NativeListboxWin::GetView() {
+ return this;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// NativeListboxWin, View overrides:
+
+gfx::Size NativeListboxWin::GetPreferredSize() {
+ SIZE sz = {0};
+ SendMessage(native_view(), BCM_GETIDEALSIZE, 0,
+ reinterpret_cast<LPARAM>(&sz));
+
+ return gfx::Size(sz.cx, sz.cy);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// NativeListboxWin, NativeControlWin overrides:
+
+bool NativeListboxWin::ProcessMessage(UINT message, WPARAM w_param,
+ LPARAM l_param, LRESULT* result) {
+ if (message == WM_COMMAND) {
+ switch (HIWORD(w_param)) {
+ case LBN_SELCHANGE:
+ if (listener_)
+ listener_->ListboxSelectionChanged(listbox_);
+ return true;
+ default:
+ break;
+ }
+ }
+
+ return NativeControlWin::ProcessMessage(message, w_param, l_param, result);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// NativeListboxWin, protected:
+
+void NativeListboxWin::CreateNativeControl() {
+ int style = WS_CHILD | LBS_NOINTEGRALHEIGHT | LBS_NOTIFY;
+ // If there's only one column and the title string is empty, don't show a
+ // header.
+ HWND hwnd = ::CreateWindowEx(WS_EX_CLIENTEDGE | GetAdditionalRTLStyle(),
+ WC_LISTBOX,
+ L"",
+ style,
+ 0, 0, width(), height(),
+ listbox_->GetWidget()->GetNativeView(),
+ NULL, NULL, NULL);
+ HFONT font = ResourceBundle::GetSharedInstance().
+ GetFont(ResourceBundle::BaseFont).hfont();
+ SendMessage(hwnd, WM_SETFONT, reinterpret_cast<WPARAM>(font), FALSE);
+ l10n_util::AdjustUIFontForWindow(hwnd);
+
+ for (size_t i = 0; i < strings_.size(); ++i)
+ ListBox_AddString(hwnd, UTF16ToWide(strings_[i]).c_str());
+
+ NativeControlCreated(hwnd);
+
+ // Bug 964884: detach the IME attached to this window.
+ // We should attach IMEs only when we need to input CJK strings.
+ ::ImmAssociateContextEx(hwnd, NULL, 0);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// NativeListboxWrapper, public:
+
+// static
+NativeListboxWrapper* NativeListboxWrapper::CreateNativeWrapper(
+ Listbox* listbox,
+ const std::vector<string16>& strings,
+ Listbox::Listener* listener) {
+ return new NativeListboxWin(listbox, strings, listener);
+}
+
+} // namespace views
Property changes on: views\controls\listbox\native_listbox_win.cc
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « views/controls/listbox/native_listbox_win.h ('k') | views/controls/listbox/native_listbox_wrapper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698