Bunch of compile fixes for wxX11 in Unicode.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@17679 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2002-11-03 13:48:04 +00:00
parent 0f7730c502
commit c60cc91708
8 changed files with 102 additions and 97 deletions

View File

@@ -48,7 +48,10 @@ public:
// Implicit conversion from the colour name // Implicit conversion from the colour name
wxColour( const wxString &colourName ) { InitFromName(colourName); } wxColour( const wxString &colourName ) { InitFromName(colourName); }
wxColour( const char *colourName ) { InitFromName(colourName); } wxColour( const char *colourName ) { InitFromName( wxString::FromAscii(colourName) ); }
#if wxUSE_UNICODE
wxColour( const wxChar *colourName ) { InitFromName( wxString(colourName) ); }
#endif
wxColour( const wxColour& col ) { Ref(col); } wxColour( const wxColour& col ) { Ref(col); }
wxColour& operator = ( const wxColour& col ) { Ref(col); return *this; } wxColour& operator = ( const wxColour& col ) { Ref(col); return *this; }

View File

@@ -26,6 +26,7 @@
#include "wx/intl.h" #include "wx/intl.h"
#include "wx/evtloop.h" #include "wx/evtloop.h"
#include "wx/timer.h" #include "wx/timer.h"
#include "wx/filename.h"
#include "wx/univ/theme.h" #include "wx/univ/theme.h"
#include "wx/univ/renderer.h" #include "wx/univ/renderer.h"
@@ -57,8 +58,6 @@ wxApp *wxTheApp = NULL;
// This is set within wxEntryStart -- too early on // This is set within wxEntryStart -- too early on
// to put these in wxTheApp // to put these in wxTheApp
static int g_newArgc = 0;
static wxChar** g_newArgv = NULL;
static bool g_showIconic = FALSE; static bool g_showIconic = FALSE;
static wxSize g_initialSize = wxDefaultSize; static wxSize g_initialSize = wxDefaultSize;
@@ -136,10 +135,6 @@ bool wxApp::Initialize()
void wxApp::CleanUp() void wxApp::CleanUp()
{ {
if (g_newArgv)
delete[] g_newArgv;
g_newArgv = NULL;
delete wxWidgetHashTable; delete wxWidgetHashTable;
wxWidgetHashTable = NULL; wxWidgetHashTable = NULL;
delete wxClientWidgetHashTable; delete wxClientWidgetHashTable;
@@ -197,20 +192,13 @@ int wxEntryStart( int& argc, char *argv[] )
#endif #endif
#endif // __WXDEBUG__ #endif // __WXDEBUG__
wxString displayName; char *displayName = NULL;
bool syncDisplay = FALSE; bool syncDisplay = FALSE;
// Parse the arguments.
// We can't use wxCmdLineParser or OnInitCmdLine and friends because
// we have to create the Display earlier. If we can find a way to
// use the wxAppBase API then I'll be quite happy to change it.
g_newArgv = new wxChar*[argc + 1];
g_newArgc = 0;
int i; int i;
for (i = 0; i < argc; i++) for (i = 0; i < argc; i++)
{ {
wxString arg(argv[i]); if (strcmp( argv[i], "-display") == 0)
if (arg == wxT("-display"))
{ {
if (i < (argc - 1)) if (i < (argc - 1))
{ {
@@ -219,16 +207,15 @@ int wxEntryStart( int& argc, char *argv[] )
continue; continue;
} }
} }
else if (arg == wxT("-geometry")) else if (strcmp( argv[i], "-geometry") == 0)
{ {
if (i < (argc - 1)) if (i < (argc - 1))
{ {
i ++; i ++;
wxString windowGeometry = argv[i];
int w, h; int w, h;
if (wxSscanf(windowGeometry.c_str(), _T("%dx%d"), &w, &h) != 2) if (sscanf(argv[i], "%dx%d", &w, &h) != 2)
{ {
wxLogError(_("Invalid geometry specification '%s'"), windowGeometry.c_str()); wxLogError( _("Invalid geometry specification '%s'"), wxString::FromAscii(argv[i]).c_str() );
} }
else else
{ {
@@ -237,30 +224,23 @@ int wxEntryStart( int& argc, char *argv[] )
continue; continue;
} }
} }
else if (arg == wxT("-sync")) else if (strcmp( argv[i], "-sync") == 0)
{ {
syncDisplay = TRUE; syncDisplay = TRUE;
continue; continue;
} }
else if (arg == wxT("-iconic")) else if (strcmp( argv[i], "-iconic") == 0)
{ {
g_showIconic = TRUE; g_showIconic = TRUE;
continue; continue;
} }
// Not eaten by wxWindows, so pass through
g_newArgv[g_newArgc] = argv[i];
g_newArgc ++;
} }
g_newArgv[g_newArgc] = NULL;
Display* xdisplay = NULL;
if (displayName.IsEmpty())
xdisplay = XOpenDisplay(NULL);
else
xdisplay = XOpenDisplay((char*) displayName.c_str());
// X11 display stuff
Display* xdisplay = XOpenDisplay( displayName );
if (!xdisplay) if (!xdisplay)
{ {
wxLogError( _("wxWindows could not open display. Exiting.") ); wxLogError( _("wxWindows could not open display. Exiting.") );
@@ -268,14 +248,36 @@ int wxEntryStart( int& argc, char *argv[] )
} }
if (syncDisplay) if (syncDisplay)
{
XSynchronize(xdisplay, True); XSynchronize(xdisplay, True);
}
wxApp::ms_display = (WXDisplay*) xdisplay; wxApp::ms_display = (WXDisplay*) xdisplay;
XSelectInput( xdisplay, XDefaultRootWindow(xdisplay), PropertyChangeMask); XSelectInput( xdisplay, XDefaultRootWindow(xdisplay), PropertyChangeMask);
// Command line argument stuff
wxTheApp->argc = argc;
#if wxUSE_UNICODE
wxTheApp->argv = new wxChar*[argc+1];
int mb_argc = 0;
while (mb_argc < argc)
{
wxString tmp = wxString::FromAscii( argv[mb_argc] );
wxTheApp->argv[mb_argc] = wxStrdup( tmp.c_str() );
mb_argc++;
}
wxTheApp->argv[mb_argc] = (wxChar *)NULL;
#else
wxTheApp->argv = argv;
#endif
if (wxTheApp->argc > 0)
{
wxFileName fname( wxTheApp->argv[0] );
wxTheApp->SetAppName( fname.GetName() );
}
// Misc.
wxSetDetectableAutoRepeat( TRUE ); wxSetDetectableAutoRepeat( TRUE );
if (!wxApp::Initialize()) if (!wxApp::Initialize())
@@ -316,32 +318,17 @@ int wxEntry( int argc, char *argv[] )
{ {
printf( "wxWindows error: No initializer - use IMPLEMENT_APP macro.\n" ); printf( "wxWindows error: No initializer - use IMPLEMENT_APP macro.\n" );
return 0; return 0;
}; }
wxTheApp = (wxApp*) (* wxApp::GetInitializerFunction()) (); wxTheApp = (wxApp*) (* wxApp::GetInitializerFunction()) ();
}; }
if (!wxTheApp) if (!wxTheApp)
{ {
printf( "wxWindows error: wxTheApp == NULL\n" ); printf( "wxWindows error: wxTheApp == NULL\n" );
return 0; return 0;
};
wxTheApp->SetClassName(wxFileNameFromPath(argv[0]));
wxTheApp->SetAppName(wxFileNameFromPath(argv[0]));
// The command line may have been changed
// by stripping out -display etc.
if (g_newArgc > 0)
{
wxTheApp->argc = g_newArgc;
wxTheApp->argv = g_newArgv;
}
else
{
wxTheApp->argc = argc;
wxTheApp->argv = argv;
} }
wxTheApp->m_showIconic = g_showIconic; wxTheApp->m_showIconic = g_showIconic;
wxTheApp->m_initialSize = g_initialSize; wxTheApp->m_initialSize = g_initialSize;

View File

@@ -85,46 +85,46 @@ wxPalette wxNullPalette;
wxFont wxNullFont; wxFont wxNullFont;
wxColour wxNullColour; wxColour wxNullColour;
// Default window names /* Default window names */
const char *wxControlNameStr = "control"; const wxChar *wxControlNameStr = wxT("control");
const char *wxButtonNameStr = "button"; const wxChar *wxButtonNameStr = wxT("button");
const char *wxCanvasNameStr = "canvas"; const wxChar *wxCanvasNameStr = wxT("canvas");
const char *wxCheckBoxNameStr = "check"; const wxChar *wxCheckBoxNameStr = wxT("check");
const char *wxChoiceNameStr = "choice"; const wxChar *wxChoiceNameStr = wxT("choice");
const char *wxComboBoxNameStr = "comboBox"; const wxChar *wxComboBoxNameStr = wxT("comboBox");
const char *wxDialogNameStr = "dialog"; const wxChar *wxDialogNameStr = wxT("dialog");
const char *wxFrameNameStr = "frame"; const wxChar *wxFrameNameStr = wxT("frame");
const char *wxGaugeNameStr = "gauge"; const wxChar *wxGaugeNameStr = wxT("gauge");
const char *wxStaticBoxNameStr = "groupBox"; const wxChar *wxStaticBoxNameStr = wxT("groupBox");
const char *wxListBoxNameStr = "listBox"; const wxChar *wxListBoxNameStr = wxT("listBox");
const char *wxStaticTextNameStr = "message"; const wxChar *wxStaticTextNameStr = wxT("message");
const char *wxStaticBitmapNameStr = "message"; const wxChar *wxStaticBitmapNameStr = wxT("message");
const char *wxMultiTextNameStr = "multitext"; const wxChar *wxMultiTextNameStr = wxT("multitext");
const char *wxPanelNameStr = "panel"; const wxChar *wxPanelNameStr = wxT("panel");
const char *wxRadioBoxNameStr = "radioBox"; const wxChar *wxRadioBoxNameStr = wxT("radioBox");
const char *wxRadioButtonNameStr = "radioButton"; const wxChar *wxRadioButtonNameStr = wxT("radioButton");
const char *wxBitmapRadioButtonNameStr = "radioButton"; const wxChar *wxBitmapRadioButtonNameStr = wxT("radioButton");
const char *wxScrollBarNameStr = "scrollBar"; const wxChar *wxScrollBarNameStr = wxT("scrollBar");
const char *wxSliderNameStr = "slider"; const wxChar *wxSliderNameStr = wxT("slider");
const char *wxStaticNameStr = "static"; const wxChar *wxStaticNameStr = wxT("static");
const char *wxTextCtrlWindowNameStr = "textWindow"; const wxChar *wxTextCtrlWindowNameStr = wxT("textWindow");
const char *wxTextCtrlNameStr = "text"; const wxChar *wxTextCtrlNameStr = wxT("text");
const char *wxVirtListBoxNameStr = "virtListBox"; const wxChar *wxVirtListBoxNameStr = wxT("virtListBox");
const char *wxButtonBarNameStr = "buttonbar"; const wxChar *wxButtonBarNameStr = wxT("buttonbar");
const char *wxEnhDialogNameStr = "Shell"; const wxChar *wxEnhDialogNameStr = wxT("Shell");
const char *wxToolBarNameStr = "toolbar"; const wxChar *wxToolBarNameStr = wxT("toolbar");
const char *wxStatusLineNameStr = "status_line"; const wxChar *wxStatusLineNameStr = wxT("status_line");
const char *wxGetTextFromUserPromptStr = "Input Text"; const wxChar *wxGetTextFromUserPromptStr = wxT("Input Text");
const char *wxMessageBoxCaptionStr = "Message"; const wxChar *wxMessageBoxCaptionStr = wxT("Message");
const char *wxFileSelectorPromptStr = "Select a file"; const wxChar *wxFileSelectorPromptStr = wxT("Select a file");
const char *wxFileSelectorDefaultWildcardStr = "*.*"; const wxChar *wxFileSelectorDefaultWildcardStr = wxT("*");
const char *wxDirDialogNameStr = "wxDirCtrl"; const wxChar *wxDirDialogNameStr = wxT("wxDirCtrl");
const char *wxDirDialogDefaultFolderStr = "/"; const wxChar *wxDirDialogDefaultFolderStr = wxT("/");
const wxChar *wxTreeCtrlNameStr = wxT("wxTreeCtrl"); const wxChar *wxTreeCtrlNameStr = wxT("wxTreeCtrl");
// See wx/utils.h /* See wx/utils.h */
const char *wxFloatToStringStr = "%.2f"; const wxChar *wxFloatToStringStr = wxT("%.2f");
const char *wxDoubleToStringStr = "%.2f"; const wxChar *wxDoubleToStringStr = wxT("%.2f");
const wxSize wxDefaultSize(-1, -1); const wxSize wxDefaultSize(-1, -1);

View File

@@ -102,7 +102,7 @@ wxString wxDataFormat::GetId() const
return wxEmptyString; return wxEmptyString;
#else #else
char *t = XGetAtomName ((Display*) wxGetDisplay(), m_format); char *t = XGetAtomName ((Display*) wxGetDisplay(), m_format);
wxString ret( t ); // this will convert from ascii to Unicode wxString ret = wxString::FromAscii( t );
if (t) if (t)
XFree( t ); XFree( t );
return ret; return ret;
@@ -132,7 +132,7 @@ void wxDataFormat::SetId( const wxChar *id )
PrepareFormats(); PrepareFormats();
m_type = wxDF_PRIVATE; m_type = wxDF_PRIVATE;
wxString tmp( id ); wxString tmp( id );
m_format = XInternAtom( (Display*) wxGetDisplay(), wxMBSTRINGCAST tmp.mbc_str(), FALSE ); // what is the string cast for? m_format = XInternAtom( (Display*) wxGetDisplay(), tmp.ToAscii(), FALSE );
#endif #endif
} }

View File

@@ -1368,7 +1368,12 @@ void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y )
wxCHECK_RET( Ok(), wxT("invalid window dc") ); wxCHECK_RET( Ok(), wxT("invalid window dc") );
if (!m_window) return; if (!m_window) return;
#if wxUSE_UNICODE
// later
#else
XFontStruct *xfont = (XFontStruct*) m_font.GetFontStruct( m_scaleY, m_display ); XFontStruct *xfont = (XFontStruct*) m_font.GetFontStruct( m_scaleY, m_display );
wxCHECK_RET( xfont, wxT("invalid font") ); wxCHECK_RET( xfont, wxT("invalid font") );
@@ -1426,6 +1431,7 @@ void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y )
CalcBoundingBox (x + width, y + height); CalcBoundingBox (x + width, y + height);
CalcBoundingBox (x, y); CalcBoundingBox (x, y);
#endif #endif
#endif
} }
void wxWindowDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y, double angle ) void wxWindowDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y, double angle )

View File

@@ -34,7 +34,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxPopupWindow, wxWindow)
bool wxPopupWindow::Create( wxWindow *parent, int style ) bool wxPopupWindow::Create( wxWindow *parent, int style )
{ {
if (!CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, style, wxDefaultValidator, "popup" )) if (!CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, style, wxDefaultValidator, wxT("popup") ))
{ {
wxFAIL_MSG( wxT("wxPopupWindow creation failed") ); wxFAIL_MSG( wxT("wxPopupWindow creation failed") );
return FALSE; return FALSE;

View File

@@ -296,13 +296,13 @@ WXWindow wxReparenter::FindAClientWindow(WXWindow window, const wxString& name)
XFetchName((Display*) wxGetDisplay(), (Window) window, &clientName); XFetchName((Display*) wxGetDisplay(), (Window) window, &clientName);
wxString str1(name); wxString str1(name);
wxString str2(clientName); wxString str2 = wxString::FromAscii(clientName);
str1.Lower(); str1.Lower();
str2.Lower(); str2.Lower();
bool matches; bool matches;
if (sm_exactMatch) if (sm_exactMatch)
matches = (name == clientName); matches = (name == wxString::FromAscii(clientName));
else else
matches = (str1.Contains(str2) || str2.Contains(str1)); matches = (str1.Contains(str2) || str2.Contains(str1));
@@ -316,7 +316,8 @@ WXWindow wxReparenter::FindAClientWindow(WXWindow window, const wxString& name)
old = XSetErrorHandler(ErrorHandler); old = XSetErrorHandler(ErrorHandler);
if (!XQueryTree((Display*) wxGetDisplay(), (Window) window, &returnroot, &returnparent, if (!XQueryTree((Display*) wxGetDisplay(), (Window) window, &returnroot, &returnparent,
&children, &numchildren) || Xerror) { &children, &numchildren) || Xerror)
{
XSetErrorHandler(old); XSetErrorHandler(old);
return NULL; return NULL;
} }

View File

@@ -410,10 +410,18 @@ void wxTopLevelWindowX11::SetTitle(const wxString& title)
if (GetMainWindow()) if (GetMainWindow())
{ {
#if wxUSE_UNICODE
// I wonder of e.g. Metacity takes UTF-8 here
XStoreName(wxGlobalDisplay(), (Window) GetMainWindow(),
(const char*) title.ToAscii() );
XSetIconName(wxGlobalDisplay(), (Window) GetMainWindow(),
(const char*) title.ToAscii() );
#else
XStoreName(wxGlobalDisplay(), (Window) GetMainWindow(), XStoreName(wxGlobalDisplay(), (Window) GetMainWindow(),
(const char*) title); (const char*) title);
XSetIconName(wxGlobalDisplay(), (Window) GetMainWindow(), XSetIconName(wxGlobalDisplay(), (Window) GetMainWindow(),
(const char*) title); (const char*) title);
#endif
} }
} }