// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
-// Licence: wxWindows license
+// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#ifndef WX_PRECOMP
#include "wx/choice.h"
+#include "wx/utils.h"
#endif
#include "wx/msw/private.h"
IMPLEMENT_DYNAMIC_CLASS(wxChoice, wxControl)
#endif
-bool wxChoice::MSWCommand(const WXUINT param, const WXWORD WXUNUSED(id))
+bool wxChoice::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
{
if (param == CBN_SELCHANGE)
{
- wxCommandEvent event(wxEVENT_TYPE_CHOICE_COMMAND, m_windowId);
+ wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, m_windowId);
event.SetInt(GetSelection());
event.SetEventObject(this);
event.SetString(copystring(GetStringSelection()));
else return FALSE;
}
-bool wxChoice::Create(wxWindow *parent, const wxWindowID id,
+bool wxChoice::Create(wxWindow *parent, wxWindowID id,
const wxPoint& pos,
const wxSize& size,
- const int n, const wxString choices[],
- const long style,
+ int n, const wxString choices[],
+ long style,
const wxValidator& validator,
const wxString& name)
{
SetName(name);
SetValidator(validator);
if (parent) parent->AddChild(this);
- SetBackgroundColour(parent->GetDefaultBackgroundColour()) ;
- SetForegroundColour(parent->GetDefaultForegroundColour()) ;
- no_strings = n;
+ SetBackgroundColour(parent->GetBackgroundColour()) ;
+ SetForegroundColour(parent->GetForegroundColour()) ;
+ m_noStrings = 0;
m_windowStyle = style;
if ( id == -1 )
- m_windowId = (int)NewControlId();
+ m_windowId = (int)NewControlId();
else
- m_windowId = id;
+ m_windowId = id;
int x = pos.x;
int y = pos.y;
// Even with extended styles, need to combine with WS_BORDER
// for them to look right.
- if (want3D || (m_windowStyle & wxSIMPLE_BORDER) || (m_windowStyle & wxRAISED_BORDER) ||
- (m_windowStyle & wxSUNKEN_BORDER) || (m_windowStyle & wxDOUBLE_BORDER))
+ if ( want3D || wxStyleHasBorder(m_windowStyle) )
msStyle |= WS_BORDER;
- HWND wx_combo = CreateWindowEx(exStyle, "COMBOBOX", NULL,
+ m_hWnd = (WXHWND)::CreateWindowEx(exStyle, "COMBOBOX", NULL,
msStyle,
0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId,
wxGetInstance(), NULL);
+
+ wxCHECK_MSG( m_hWnd, FALSE, "Failed to create combobox" );
+
/*
-#if CTL3D
+#if wxUSE_CTL3D
if (want3D)
{
m_useCtl3D = TRUE;
#endif
*/
- m_hWnd = (WXHWND) wx_combo;
-
// Subclass again for purposes of dialog editing mode
- SubclassWin((WXHWND) wx_combo);
+ SubclassWin(m_hWnd);
- SetFont(* parent->GetFont());
+ SetFont(parent->GetFont());
int i;
for (i = 0; i < n; i++)
- SendMessage(wx_combo, CB_INSERTSTRING, i, (LONG)(const char *)choices[i]);
- SendMessage(wx_combo, CB_SETCURSEL, i, 0);
+ {
+ Append(choices[i]);
+ }
+ SetSelection(n);
SetSize(x, y, width, height);
{
SendMessage((HWND) GetHWND(), CB_ADDSTRING, 0, (LONG)(const char *)item);
- no_strings ++;
+ m_noStrings ++;
}
-void wxChoice::Delete(const int n)
+void wxChoice::Delete(int n)
{
- no_strings = (int)SendMessage((HWND) GetHWND(), CB_DELETESTRING, n, 0);
+ m_noStrings = (int)SendMessage((HWND) GetHWND(), CB_DELETESTRING, n, 0);
}
void wxChoice::Clear(void)
{
SendMessage((HWND) GetHWND(), CB_RESETCONTENT, 0, 0);
- no_strings = 0;
+ m_noStrings = 0;
}
return (int)SendMessage((HWND) GetHWND(), CB_GETCURSEL, 0, 0);
}
-void wxChoice::SetSelection(const int n)
+void wxChoice::SetSelection(int n)
{
SendMessage((HWND) GetHWND(), CB_SETCURSEL, n, 0);
}
#endif
}
-wxString wxChoice::GetString(const int n) const
+wxString wxChoice::GetString(int n) const
{
int len = (int)SendMessage((HWND) GetHWND(), CB_GETLBTEXT, n, (long)wxBuffer);
wxBuffer[len] = 0;
return wxString(wxBuffer);
}
-void wxChoice::SetSize(const int x, const int y, const int width, const int height, const int sizeFlags)
+void wxChoice::DoSetSize(int x, int y, int width, int height, int sizeFlags)
{
int currentX, currentY;
GetPosition(¤tX, ¤tY);
if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
y1 = currentY;
+ AdjustForParentClientOrigin(x1, y1, sizeFlags);
+
// If we're prepared to use the existing size, then...
if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO))
{
int cx; // button font dimensions
int cy;
- wxGetCharSize(GetHWND(), &cx, &cy, GetFont());
+ wxGetCharSize(GetHWND(), &cx, &cy, & this->GetFont());
- float control_width, control_height;
+ int control_width, control_height;
// Ignore height parameter because height doesn't
// mean 'initially displayed' height, it refers to the
if (width <= 0)
{
// Find the longest string
- if (no_strings == 0)
- control_width = (float)100.0;
+ if (m_noStrings == 0)
+ {
+ control_width = 100;
+ }
else
{
- float len, ht;
- float longest = (float)0.0;
+ int len, ht;
+ int longest = 0;
int i;
- for (i = 0; i < no_strings; i++)
+ for (i = 0; i < m_noStrings; i++)
{
wxString str(GetString(i));
- GetTextExtent(str, &len, &ht, NULL, NULL,GetFont());
- if ( len > longest) longest = len;
+ GetTextExtent(str, &len, &ht, NULL, NULL, & this->GetFont());
+ if ( len > longest)
+ longest = len;
}
- control_width = (float)(int)(longest + cx*5);
+ control_width = longest + cx*5;
}
}
+ else
+ {
+ // If non-default width...
+ control_width = w1;
+ }
+
// Choice drop-down list depends on number of items (limited to 10)
if (h1 <= 0)
{
- if (no_strings == 0)
- h1 = (int)(EDIT_CONTROL_FACTOR*cy*10.0);
- else h1 = (int)(EDIT_CONTROL_FACTOR*cy*(wxMin(10, no_strings) + 1));
+ if (m_noStrings == 0)
+ h1 = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy)*10;
+ else
+ h1 = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy)*(wxMin(10, m_noStrings) + 1);
}
- // If non-default width...
- if (width >= 0)
- control_width = (float)width;
-
- control_height = (float)h1;
+ control_height = h1;
// Calculations may have made text size too small
if (control_height <= 0)
- control_height = (float)(int)(cy*EDIT_CONTROL_FACTOR) ;
+ control_height = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
if (control_width <= 0)
- control_width = (float)100.0;
-
- MoveWindow((HWND) GetHWND(), x1, y1,
- (int)control_width, (int)control_height, TRUE);
+ control_width = 100;
-/*
-#if WXWIN_COMPATIBILITY
- GetEventHandler()->OldOnSize(width, height);
-#else
- wxSizeEvent event(wxSize(width, height), m_windowId);
- event.eventObject = this;
- GetEventHandler()->ProcessEvent(event);
-#endif
-*/
+ MoveWindow((HWND)GetHWND(), x1, y1,
+ control_width, control_height, TRUE);
}
-WXHBRUSH wxChoice::OnCtlColor(const WXHDC pDC, const WXHWND pWnd, const WXUINT nCtlColor,
- WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
+WXHBRUSH wxChoice::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
+ WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
{
- return 0;
+ return 0;
}
long wxChoice::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)