diff --git a/docs/latex/wx/tunicode.tex b/docs/latex/wx/tunicode.tex index e1e68943d6..d1ff40e96b 100644 --- a/docs/latex/wx/tunicode.tex +++ b/docs/latex/wx/tunicode.tex @@ -156,5 +156,16 @@ useful, is wc\_str() function which always returns the Unicode string. % TODO describe fn_str(), wx_str(), wxCharBuf classes, ... -% Please remember to put a blank line at the end of each file! (Tex2RTF 'issue') +\subsection{Unicode-related compilation settings} + +You should define {\tt wxUSE\_UNICODE} to $1$ to compile your program in +Unicode mode. Note that it currently only works in Win32 and that some parts of +wxWindows are not Unicode-compliant yet (ODBC classes, for example). If you +compile your program in ANSI mode you can still define {\tt wxUSE\_WCHAR\_T} +to get some limited support for {\tt wchar\_t} type. + +This will allow your program to perform conversions between Unicode strings and +ANSI ones (\helpref{wxEncodingConverter}{wxencodingconverter} depends on this +partially) and construct wxString objects from Unicode strings (presumably read +from some external file or elsewhere). diff --git a/include/wx/wxchar.h b/include/wx/wxchar.h index 2f53037c71..b4b8d32913 100644 --- a/include/wx/wxchar.h +++ b/include/wx/wxchar.h @@ -22,6 +22,10 @@ // # error "MBCS is not supported by wxChar" #endif +// ---------------------------------------------------------------------------- +// first deal with Unicode setting +// ---------------------------------------------------------------------------- + // set wxUSE_UNICODE to 1 if UNICODE or _UNICODE is defined #if defined(_UNICODE) || defined(UNICODE) # undef wxUSE_UNICODE @@ -30,7 +34,7 @@ # ifndef wxUSE_UNICODE # define wxUSE_UNICODE 0 # endif -#endif +#endif // Unicode // and vice versa: define UNICODE and _UNICODE if wxUSE_UNICODE is 1... #if wxUSE_UNICODE @@ -40,7 +44,13 @@ # ifndef UNICODE # define UNICODE # endif -#endif +#endif // Unicode + +// Unicode support requires wchar_t +#if wxUSE_UNICODE +# undef wxUSE_WCHAR_T +# define wxUSE_WCHAR_T 1 +#endif // Unicode // ---------------------------------------------------------------------------- // define wxHAVE_TCHAR_FUNCTIONS for the compilers which support the @@ -98,9 +108,7 @@ // time.h functions -- none defined in tchar.h #define wxAsctime asctime #define wxCtime ctime - - -#endif +#endif // compilers with (good) TCHAR support #ifdef wxHAVE_TCHAR_FUNCTIONS # define HAVE_WCSLEN 1 @@ -116,9 +124,11 @@ typedef _TUCHAR wxUChar; # define wxSChar signed char # define wxUChar unsigned char # endif - // wchar_t is available -# undef wxUSE_WCHAR_T -# define wxUSE_WCHAR_T 1 + + // wchar_t is available + #ifndef wxUSE_WCHAR_T + #define wxUSE_WCHAR_T 1 + #endif // !defined(wxUSE_WCHAR_T) // ctype.h functions #ifndef wxNO_TCHAR_CTYPE @@ -239,10 +249,7 @@ typedef _TUCHAR wxUChar; #else // !TCHAR-aware compilers // check whether we should include wchar.h or equivalent -# if wxUSE_UNICODE -# undef wxUSE_WCHAR_T -# define wxUSE_WCHAR_T 1 // wchar_t *must* be available in Unicode mode -# elif !defined(wxUSE_WCHAR_T) +# if !defined(wxUSE_WCHAR_T) # if defined(__VISUALC__) && (__VISUALC__ < 900) # define wxUSE_WCHAR_T 0 // wchar_t is not available for MSVC++ 1.5 # elif defined(__UNIX__) @@ -263,7 +270,7 @@ typedef _TUCHAR wxUChar; // add additional compiler checks if this fails # define wxUSE_WCHAR_T 1 # endif -# endif//wxUSE_UNICODE +# endif // !defined(wxUSE_WCHAR_T) # if wxUSE_WCHAR_T # ifdef HAVE_WCSTR_H @@ -628,6 +635,10 @@ WXDLLEXPORT int wxSystem(const wxChar *psz); WXDLLEXPORT size_t wxStrftime(wxChar *s, size_t max, const wxChar *fmt, const struct tm *tm); #endif +// ---------------------------------------------------------------------------- +// common macros which are always defined +// ---------------------------------------------------------------------------- + // although global macros with such names are really bad, we want to have // another name for _T() which should be used to avoid confusion between _T() // and _() in wxWindows sources diff --git a/src/common/strconv.cpp b/src/common/strconv.cpp index 03b1504dfd..5ccb485849 100644 --- a/src/common/strconv.cpp +++ b/src/common/strconv.cpp @@ -9,6 +9,14 @@ // Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + #ifdef __GNUG__ #pragma implementation "strconv.h" #endif @@ -31,24 +39,21 @@ #include "wx/debug.h" #include "wx/strconv.h" -//---------------------------------------------------------------------------- -// wxConvCurrent -//---------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- +// globals +// ---------------------------------------------------------------------------- WXDLLEXPORT_DATA(wxMBConv *) wxConvCurrent = &wxConvLibc; -#if !wxUSE_WCHAR_T -//---------------------------------------------------------------------------- -// stand-ins in absence of wchar_t -//---------------------------------------------------------------------------- +// ============================================================================ +// implementation +// ============================================================================ -WXDLLEXPORT_DATA(wxMBConv) wxConvLibc, wxConvFile; +#if wxUSE_WCHAR_T -#else - -//---------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- // wxMBConv -//---------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- WXDLLEXPORT_DATA(wxMBConv) wxConvLibc; @@ -88,9 +93,9 @@ const wxCharBuffer wxMBConv::cWC2MB(const wchar_t *psz) const return wxCharBuffer((char *) NULL); } -//---------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- // standard file conversion -//---------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- WXDLLEXPORT_DATA(wxMBConvFile) wxConvFile; @@ -105,11 +110,11 @@ size_t wxMBConvFile::WC2MB(char *buf, const wchar_t *psz, size_t n) const return wxWC2MB(buf, psz, n); } -#ifdef __WXGTK12__ - -//---------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- // standard gdk conversion -//---------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- + +#ifdef __WXGTK12__ WXDLLEXPORT_DATA(wxMBConvGdk) wxConvGdk; @@ -138,6 +143,7 @@ size_t wxMBConvGdk::WC2MB(char *buf, const wchar_t *psz, size_t n) const } return len; } + #endif // GTK > 1.0 // ---------------------------------------------------------------------------- @@ -171,9 +177,9 @@ size_t wxMBConvUTF7::WC2MB(char * WXUNUSED(buf), return 0; } -//---------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- // UTF-8 -//---------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- WXDLLEXPORT_DATA(wxMBConvUTF8) wxConvUTF8; @@ -352,7 +358,14 @@ size_t wxCSConv::WC2MB(char *buf, const wchar_t *psz, size_t n) const #endif } -#endif - //wxUSE_WCHAR_T +#else // !wxUSE_WCHAR_T + +// ---------------------------------------------------------------------------- +// stand-ins in absence of wchar_t +// ---------------------------------------------------------------------------- + +WXDLLEXPORT_DATA(wxMBConv) wxConvLibc, wxConvFile; + +#endif // wxUSE_WCHAR_T diff --git a/src/msw/combobox.cpp b/src/msw/combobox.cpp index f00c1297c9..311c1a1c92 100644 --- a/src/msw/combobox.cpp +++ b/src/msw/combobox.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: combobox.cpp +// Name: msw/combobox.cpp // Purpose: wxComboBox class // Author: Julian Smart // Modified by: @@ -9,6 +9,14 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + #ifdef __GNUG__ #pragma implementation "combobox.h" #endif @@ -30,8 +38,56 @@ #include "wx/clipbrd.h" #include "wx/msw/private.h" +// ---------------------------------------------------------------------------- +// wxWin macros +// ---------------------------------------------------------------------------- + IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl) +// ---------------------------------------------------------------------------- +// function prototypes +// ---------------------------------------------------------------------------- + +LRESULT APIENTRY _EXPORT wxComboEditWndProc(HWND hWnd, + UINT message, + WPARAM wParam, + LPARAM lParam); + +// --------------------------------------------------------------------------- +// global vars +// --------------------------------------------------------------------------- + +// the pointer to standard radio button wnd proc +static WXFARPROC gs_wndprocEdit = (WXFARPROC)NULL; + +// ============================================================================ +// implementation +// ============================================================================ + +// ---------------------------------------------------------------------------- +// wnd proc for subclassed edit control +// ---------------------------------------------------------------------------- + +LRESULT APIENTRY _EXPORT wxComboEditWndProc(HWND hWnd, + UINT message, + WPARAM wParam, + LPARAM lParam) +{ + if ( message == WM_CHAR ) + { + HWND hwndCombo = ::GetParent(hWnd); + wxCHECK_MSG( hwndCombo, 0, _T("should have combo as parent") ); + + ::SendMessage(hwndCombo, message, wParam, lParam); + } + + return ::CallWindowProc(CASTWNDPROC gs_wndprocEdit, hWnd, message, wParam, lParam); +} + +// ---------------------------------------------------------------------------- +// wxComboBox +// ---------------------------------------------------------------------------- + bool wxComboBox::MSWCommand(WXUINT param, WXWORD WXUNUSED(id)) { switch ( param ) @@ -71,90 +127,72 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, const wxValidator& validator, const wxString& name) { - SetName(name); -#if wxUSE_VALIDATORS - SetValidator(validator); -#endif // wxUSE_VALIDATORS - if (parent) parent->AddChild(this); -// SetBackgroundColour(parent->GetBackgroundColour()) ; + // first create wxWin object + if ( !CreateControl(parent, id, pos, size, style, validator, name) ) + return FALSE; - // A choice/combobox normally has a white background (or other, depending - // on global settings) rather than inheriting the parent's background colour. - SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW)); + // get the right style + long msStyle = WS_TABSTOP | WS_VSCROLL | WS_HSCROLL | + CBS_AUTOHSCROLL | CBS_NOINTEGRALHEIGHT; + if ( style & wxCB_READONLY ) + msStyle |= CBS_DROPDOWNLIST; + else if ( style & wxCB_SIMPLE ) + msStyle |= CBS_SIMPLE; // A list (shown always) and edit control + else + msStyle |= CBS_DROPDOWN; - SetForegroundColour(parent->GetForegroundColour()) ; + if ( style & wxCB_SORT ) + msStyle |= CBS_SORT; - m_windowStyle = style; + // and now create the MSW control + if ( !MSWCreateControl(_T("COMBOBOX"), msStyle) ) + return FALSE; - if ( id == -1 ) - m_windowId = (int)NewControlId(); - else - m_windowId = id; + SetSize(pos.x, pos.y, size.x, size.y); - int x = pos.x; - int y = pos.y; - int width = size.x; - int height = size.y; + // A choice/combobox normally has a white background (or other, depending + // on global settings) rather than inheriting the parent's background colour. + SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW)); - long msStyle = WS_CHILD | WS_TABSTOP | WS_VISIBLE | - WS_VSCROLL | WS_HSCROLL | CBS_AUTOHSCROLL | CBS_NOINTEGRALHEIGHT; + for ( int i = 0; i < n; i++ ) + { + Append(choices[i]); + } - if (m_windowStyle & wxCB_READONLY) - msStyle |= CBS_DROPDOWNLIST; - else if (m_windowStyle & wxCB_SIMPLE) - msStyle |= CBS_SIMPLE; // A list (shown always) and edit control - else - msStyle |= CBS_DROPDOWN; + if ( !value.IsEmpty() ) + { + SetValue(value); + } - if (m_windowStyle & wxCB_SORT) - msStyle |= CBS_SORT; + // a (not read only) combobox is, in fact, 2 controls: the combobox itself + // and an edit control inside it and if we want to catch events from this + // edit control, we must subclass it as well + if ( !(style & wxCB_READONLY) ) + { + // first find the child edit + POINT pt; + pt.x = pt.y = 4; + HWND hwndEdit = ::ChildWindowFromPoint(GetHwnd(), pt); + if ( !hwndEdit || hwndEdit == GetHwnd() ) + { + wxFAIL_MSG(_T("not read only combobox without edit control?")); + } + else + { + gs_wndprocEdit = (WXFARPROC)::SetWindowLong + ( + hwndEdit, + GWL_WNDPROC, + (LPARAM)wxComboEditWndProc + ); + } + } - bool want3D; - WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D) ; - - // Even with extended styles, need to combine with WS_BORDER - // for them to look right. - if ( want3D || wxStyleHasBorder(m_windowStyle) ) - msStyle |= WS_BORDER; - - m_hWnd = (WXHWND)::CreateWindowEx(exStyle, wxT("COMBOBOX"), NULL, - msStyle, - 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId, - wxGetInstance(), NULL); - - wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create combobox") ); - -/* -#if wxUSE_CTL3D - if (want3D) - { - Ctl3dSubclassCtl(wx_combo); - m_useCtl3D = TRUE; - } -#endif -*/ - - // Subclass again for purposes of dialog editing mode - SubclassWin(m_hWnd); - - SetFont(parent->GetFont()); - int i; - for (i = 0; i < n; i++) - { - Append(choices[i]); - } - - SetSelection(i); - - SetSize(x, y, width, height); - if ( !value.IsEmpty() ) - { - SetValue(value); - } - - return TRUE; + return TRUE; } +// TODO: update and clear all this horrible mess (VZ) + void wxComboBox::SetValue(const wxString& value) { // If newlines are denoted by just 10, must stick 13 in front. diff --git a/src/msw/control.cpp b/src/msw/control.cpp index ce7b2fca18..546078664a 100644 --- a/src/msw/control.cpp +++ b/src/msw/control.cpp @@ -109,9 +109,8 @@ bool wxControl::MSWCreateControl(const wxChar *classname, if ( !m_hWnd ) { -#ifdef __WXDEBUG__ - wxLogError(wxT("Failed to create a control of class '%s'"), classname); -#endif // DEBUG + wxLogDebug(wxT("Failed to create a control of class '%s'"), classname); + wxFAIL_MSG(_T("something is very wrong")); return FALSE; }