00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "SysVideo.h"
00010
00011 #include "Log.h"
00012
00013 #include "SDL.h"
00014 #if !defined(HAVE_X11) && !defined(WIN32)
00015 void
00016 SysVideo::setCaption(const std::string &title)
00017 {
00018 SDL_WM_SetCaption(title.c_str(), NULL);
00019 }
00020 #else
00021 #include "SDL_syswm.h"
00022 static bool sysSetCaption(SDL_SysWMinfo *info, const std::string &title);
00023
00024
00025
00026
00027
00028
00029 void
00030 SysVideo::setCaption(const std::string &title)
00031 {
00032 bool done = false;
00033 SDL_SysWMinfo info;
00034 SDL_VERSION(&info.version);
00035 if (SDL_GetWMInfo(&info) > 0) {
00036 done = sysSetCaption(&info, title);
00037 }
00038
00039 if (!done) {
00040 SDL_WM_SetCaption(title.c_str(), NULL);
00041 }
00042 }
00043
00044
00045
00046
00047
00048
00049
00050 #if defined(HAVE_X11) && !defined(DISABLE_X11) && defined(unix)
00051 #include <X11/Xutil.h>
00052 bool
00053 sysSetCaption(SDL_SysWMinfo *info, const std::string &title)
00054 {
00055 bool result = false;
00056 #ifdef X_HAVE_UTF8_STRING
00057 if (info->subsystem == SDL_SYSWM_X11) {
00058 info->info.x11.lock_func();
00059
00060 XTextProperty titleprop;
00061 char *text_list = const_cast<char*>(title.c_str());
00062 int error = Xutf8TextListToTextProperty(info->info.x11.display,
00063 &text_list, 1, XUTF8StringStyle, &titleprop);
00064 if (!error) {
00065 XSetWMName(info->info.x11.display, info->info.x11.wmwindow,
00066 &titleprop);
00067 XFree(titleprop.value);
00068 result = true;
00069 }
00070 else {
00071 LOG_DEBUG(ExInfo("not supported conversion")
00072 .addInfo("error", error)
00073 .addInfo("title", title));
00074 }
00075
00076 info->info.x11.unlock_func();
00077 }
00078 #endif
00079 return result;
00080 }
00081 #elif defined(WIN32)
00082 #define WIN32_LEAN_AND_MEAN
00083 #include <windows.h>
00084 bool
00085 sysSetCaption(SDL_SysWMinfo *info, const std::string &title)
00086 {
00087 bool result = false;
00088 LPWSTR lpszW = new WCHAR[title.size()];
00089 if (MultiByteToWideChar(CP_UTF8, 0, title.c_str(), -1,
00090 lpszW, title.size()))
00091 {
00092 result = SetWindowTextW(info->window, lpszW);
00093 }
00094 else {
00095 LOG_DEBUG(ExInfo("not supported conversion")
00096 .addInfo("error", GetLastError())
00097 .addInfo("title", title));
00098 }
00099 delete[] lpszW;
00100 return result;
00101 }
00102 #else
00103 bool
00104 sysSetCaption(SDL_SysWMinfo * , const std::string &)
00105 {
00106 return false;
00107 }
00108 #endif
00109 #endif // HAVE_X11 || WIN32
00110