bool wxGetResource(const wxString& section, const wxString& entry, char **value, const wxString& file) { if (!wxResourceDatabase) { Display *display = wxGlobalDisplay(); wxXMergeDatabases (wxTheApp, display); } XrmDatabase database; if (file != "") { char buffer[500]; // Is this right? Trying to get it to look in the user's // home directory instead of current directory -- JACS (void) GetIniFile (buffer, file); wxNode *node = wxResourceCache.Find (buffer); if (node) database = (XrmDatabase) node->Data (); else { database = XrmGetFileDatabase (buffer); wxResourceCache.Append (buffer, (wxObject *) database); } } else database = wxResourceDatabase; XrmValue xvalue; char *str_type[20]; char buf[150]; strcpy (buf, section); strcat (buf, "."); strcat (buf, entry); Bool success = XrmGetResource (database, buf, "*", str_type, &xvalue); // Try different combinations of upper/lower case, just in case... if (!success) { buf[0] = (isupper (buf[0]) ? tolower (buf[0]) : toupper (buf[0])); success = XrmGetResource (database, buf, "*", str_type, &xvalue); } if (success) { if (*value) delete[] *value; *value = new char[xvalue.size + 1]; strncpy (*value, xvalue.addr, (int) xvalue.size); return true; } return false; }
void wxTopLevelWindowX11::Restore() { // This is the way to deiconify the window, according to the X FAQ if (m_iconized && X11GetMainWindow()) { XMapWindow(wxGlobalDisplay(), (Window) X11GetMainWindow()); m_iconized = false; } }
void wxGetMousePosition( int* x, int* y ) { #if wxUSE_NANOX // TODO *x = 0; *y = 0; #else XMotionEvent xev; Window root, child; XQueryPointer(wxGlobalDisplay(), DefaultRootWindow(wxGlobalDisplay()), &root, &child, &(xev.x_root), &(xev.y_root), &(xev.x), &(xev.y), &(xev.state)); *x = xev.x_root; *y = xev.y_root; #endif };
void wxWindowX11::DoClientToScreen(int *x, int *y) const { Display *display = wxGlobalDisplay(); Window rootWindow = RootWindowOfScreen(DefaultScreenOfDisplay(display)); Window thisWindow = (Window) m_clientWindow; Window childWindow; int xx = *x; int yy = *y; XTranslateCoordinates(display, thisWindow, rootWindow, xx, yy, x, y, &childWindow); }
void wxTopLevelWindowX11::SetTitle(const wxString& title) { m_title = title; if (X11GetMainWindow()) { #if wxUSE_UNICODE // I wonder of e.g. Metacity takes UTF-8 here XStoreName(wxGlobalDisplay(), (Window) X11GetMainWindow(), (const char*) title.ToAscii() ); XSetIconName(wxGlobalDisplay(), (Window) X11GetMainWindow(), (const char*) title.ToAscii() ); #else XStoreName(wxGlobalDisplay(), (Window) X11GetMainWindow(), (const char*) title); XSetIconName(wxGlobalDisplay(), (Window) X11GetMainWindow(), (const char*) title); #endif } }
wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const { // get X protocol version Display *display = wxGlobalDisplay(); if (display) { if ( verMaj ) *verMaj = ProtocolVersion (display); if ( verMin ) *verMin = ProtocolRevision (display); } return wxPORT_X11; }
void wxColourRefData::AllocColour( WXColormap cmap ) { if (m_hasPixel && (m_colormap == cmap)) return; FreeColour(); #if !wxUSE_NANOX if ((wxTheApp->m_visualInfo->m_visualType == GrayScale) || (wxTheApp->m_visualInfo->m_visualType == PseudoColor)) { m_hasPixel = XAllocColor( wxGlobalDisplay(), (Colormap) cmap, &m_color ); int idx = m_color.pixel; colMapAllocCounter[ idx ] = colMapAllocCounter[ idx ] + 1; } else #endif { m_hasPixel = XAllocColor( wxGlobalDisplay(), (Colormap) cmap, &m_color ); } m_colormap = cmap; }
bool wxWindowX11::SetBackgroundColour(const wxColour& col) { wxWindowBase::SetBackgroundColour(col); Display *xdisplay = (Display*) wxGlobalDisplay(); int xscreen = DefaultScreen( xdisplay ); Colormap cm = DefaultColormap( xdisplay, xscreen ); m_backgroundColour.CalcPixel( (WXColormap) cm ); // We don't set the background colour as we paint // the background ourselves. // XSetWindowBackground( xdisplay, (Window) m_clientWindow, m_backgroundColour.GetPixel() ); return TRUE; }
// Wait for an appropriate window to be created. // If exactMatch is FALSE, a substring match is OK. // If windowName is empty, then wait for the next overrideRedirect window. bool wxReparenter::WaitAndReparent(wxWindow* newParent, wxAdoptedWindow* toReparent, const wxString& windowName, bool exactMatch) { sm_newParent = newParent; sm_toReparent = toReparent; sm_exactMatch = exactMatch; sm_name = windowName; Display* display = wxGlobalDisplay(); XSelectInput(display, RootWindowOfScreen(DefaultScreenOfDisplay(display)), SubstructureNotifyMask); if (!WM_STATE) WM_STATE = XInternAtom(display, "WM_STATE", False); #ifdef __WXDEBUG__ if (!windowName.IsEmpty()) wxLogDebug(_T("Waiting for window %s"), windowName.c_str()); #endif sm_done = FALSE; wxEventLoop eventLoop; while (!sm_done) { if (eventLoop.Pending()) { XEvent xevent; XNextEvent(display, & xevent); if (!wxTheApp->ProcessXEvent((WXEvent*) & xevent)) { // Do the local event processing ProcessXEvent((WXEvent*) & xevent); } } else { #if wxUSE_TIMER wxTimer::NotifyTimers(); wxTheApp->ProcessIdle(); #endif } } return TRUE; }
void wxWindowX11::DoCaptureMouse() { if ((g_captureWindow != NULL) && (g_captureWindow != this)) { wxASSERT_MSG(FALSE, wxT("Trying to capture before mouse released.")); // Core dump now int *tmp = NULL; (*tmp) = 1; return; } if (m_winCaptured) return; Window xwindow = (Window) m_clientWindow; wxCHECK_RET( xwindow, wxT("invalid window") ); g_captureWindow = (wxWindow*) this; if (xwindow) { int res = XGrabPointer(wxGlobalDisplay(), xwindow, FALSE, ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, GrabModeAsync, GrabModeAsync, None, None, /* cursor */ // TODO: This may need to be set to the cursor of this window CurrentTime ); if (res != GrabSuccess) { wxString msg; msg.Printf(wxT("Failed to grab pointer for window %s"), this->GetClassInfo()->GetClassName()); wxLogDebug(msg); if (res == GrabNotViewable) wxLogDebug( wxT("This is not a viewable window - perhaps not shown yet?") ); g_captureWindow = NULL; return; } m_winCaptured = TRUE; } }
bool wxClipboard::AddData( wxDataObject *data ) { wxCHECK_MSG( data, false, "data is invalid" ); wxCHECK_MSG( m_open, false, "clipboard not open" ); m_data.Append( data ); Display* xdisplay = wxGlobalDisplay(); Widget xwidget = (Widget)wxTheApp->GetTopLevelRealizedWidget(); Window xwindow = XtWindow( xwidget ); wxXmString label( wxTheApp->GetAppDisplayName() ); Time timestamp = XtLastTimestampProcessed( xdisplay ); long itemId; int retval; while( ( retval = XmClipboardStartCopy( xdisplay, xwindow, label(), timestamp, xwidget, wxClipboardCallback, &itemId ) ) == XmClipboardLocked ); if( retval != XmClipboardSuccess ) return false; size_t count = data->GetFormatCount( wxDataObject::Get ); wxDataFormatScopedArray dfarr(count); data->GetAllFormats( dfarr.get(), wxDataObject::Get ); for( size_t i = 0; i < count; ++i ) { size_t size = data->GetDataSize( dfarr[i] ); long data_id; wxString id = dfarr[i].GetId(); while( ( retval = XmClipboardCopy( xdisplay, xwindow, itemId, id.char_str(), NULL, size, i, &data_id ) ) == XmClipboardLocked ); m_idToObject.Append( new wxDataIdToDataObject( data, data_id, size ) ); } while( XmClipboardEndCopy( xdisplay, xwindow, itemId ) == XmClipboardLocked ); return true; }
// Get size *available for subwindows* i.e. excluding menu bar etc. void wxWindowX11::DoGetClientSize(int *x, int *y) const { Window window = (Window) m_mainWindow; if (window) { XWindowAttributes attr; Status status = XGetWindowAttributes( wxGlobalDisplay(), window, &attr ); wxASSERT(status); if (status) { *x = attr.width ; *y = attr.height ; } } }
bool wxColour::FromString(const wxString& name) { Display *dpy = wxGlobalDisplay(); WXColormap colormap = wxTheApp->GetMainColormap( dpy ); XColor xcol; if ( XParseColor( dpy, (Colormap)colormap, name.mbc_str(), &xcol ) ) { UnRef(); m_refData = new wxColourRefData; M_COLDATA->m_colormap = colormap; M_COLDATA->m_color = xcol; return true; } return wxColourBase::FromString(name); }
// Get total size void wxWindowX11::DoGetSize(int *x, int *y) const { Window xwindow = (Window) m_mainWindow; wxCHECK_RET( xwindow, wxT("invalid window") ); //XSync(wxGlobalDisplay(), False); XWindowAttributes attr; Status status = XGetWindowAttributes( wxGlobalDisplay(), xwindow, &attr ); wxASSERT(status); if (status) { *x = attr.width /* + 2*m_borderSize */ ; *y = attr.height /* + 2*m_borderSize */ ; } }
void wxWindowX11::DoReleaseMouse() { g_captureWindow = NULL; if ( !m_winCaptured ) return; Window xwindow = (Window) m_clientWindow; if (xwindow) { XUngrabPointer( wxGlobalDisplay(), CurrentTime ); } // wxLogDebug( "Ungrabbed pointer in %s", GetName().c_str() ); m_winCaptured = FALSE; }
PangoContext* wxApp::GetPangoContext() { static PangoContext *s_pangoContext = NULL; if ( !s_pangoContext ) { Display *dpy = wxGlobalDisplay(); int xscreen = DefaultScreen(dpy); s_pangoContext = pango_xft_get_context(dpy, xscreen); if (!PANGO_IS_CONTEXT(s_pangoContext)) { wxLogError( wxT("No pango context.") ); } } return s_pangoContext; }
/* static */ wxColour wxColour::CreateByName(const wxString& name) { wxColour col; Display *dpy = wxGlobalDisplay(); WXColormap colormap = wxTheApp->GetMainColormap( dpy ); XColor xcol; if ( XParseColor( dpy, (Colormap)colormap, name.mb_str(), &xcol ) ) { col.m_red = xcol.red & 0xff; col.m_green = xcol.green & 0xff; col.m_blue = xcol.blue & 0xff; col.m_isInit = true; col.m_pixel = -1; } return col; }
void wxWindowX11::DoSetSize(int x, int y, int width, int height, int sizeFlags) { // wxLogDebug("DoSetSize: %s (%ld) %d, %d %dx%d", GetClassInfo()->GetClassName(), GetId(), x, y, width, height); Window xwindow = (Window) m_mainWindow; wxCHECK_RET( xwindow, wxT("invalid window") ); XWindowAttributes attr; Status status = XGetWindowAttributes( wxGlobalDisplay(), xwindow, &attr ); wxCHECK_RET( status, wxT("invalid window attributes") ); int new_x = attr.x; int new_y = attr.y; int new_w = attr.width; int new_h = attr.height; if (x != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) { int yy = 0; AdjustForParentClientOrigin( x, yy, sizeFlags); new_x = x; } if (y != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) { int xx = 0; AdjustForParentClientOrigin( xx, y, sizeFlags); new_y = y; } if (width != -1) { new_w = width; if (new_w <= 0) new_w = 20; } if (height != -1) { new_h = height; if (new_h <= 0) new_h = 20; } DoMoveWindow( new_x, new_y, new_w, new_h ); }
bool wxWindowX11::Show(bool show) { wxWindowBase::Show(show); Window xwindow = (Window) m_mainWindow; Display *xdisp = wxGlobalDisplay(); if (show) { // wxLogDebug( "Mapping window of type %s", GetName().c_str() ); XMapWindow(xdisp, xwindow); } else { // wxLogDebug( "Unmapping window of type %s", GetName().c_str() ); XUnmapWindow(xdisp, xwindow); } return TRUE; }
// Get the window with the focus wxWindow *wxWindowBase::DoFindFocus() { Window xfocus = (Window) 0; int revert = 0; XGetInputFocus( wxGlobalDisplay(), &xfocus, &revert); if (xfocus) { wxWindow *win = wxGetWindowFromTable( xfocus ); if (!win) { win = wxGetClientWindowFromTable( xfocus ); } return win; } return NULL; }
// Wait for an appropriate window to be created. // If exactMatch is false, a substring match is OK. // If windowName is empty, then wait for the next overrideRedirect window. bool wxReparenter::WaitAndReparent(wxWindow* newParent, wxAdoptedWindow* toReparent, const wxString& windowName, bool exactMatch) { sm_newParent = newParent; sm_toReparent = toReparent; sm_exactMatch = exactMatch; sm_name = windowName; Display* display = wxGlobalDisplay(); XSelectInput(display, RootWindowOfScreen(DefaultScreenOfDisplay(display)), SubstructureNotifyMask); if (!WM_STATE) WM_STATE = XInternAtom(display, "WM_STATE", False); sm_done = false; wxEventLoop eventLoop; while (!sm_done) { if (eventLoop.Pending()) { XEvent xevent; XNextEvent(display, & xevent); if (!wxTheApp->ProcessXEvent((WXEvent*) & xevent)) { // Do the local event processing ProcessXEvent((WXEvent*) & xevent); } } else { #if wxUSE_TIMER wxGenericTimerImpl::NotifyTimers(); wxTheApp->ProcessIdle(); #endif } } return true; }
bool wxClipboard::IsSupported(const wxDataFormat& format) { Display* xdisplay = wxGlobalDisplay(); Window xwindow = XtWindow( (Widget)wxTheApp->GetTopLevelRealizedWidget() ); bool isSupported = false; int retval, count; unsigned long max_name_length; wxString id = format.GetId(); while( ( retval = XmClipboardLock( xdisplay, xwindow ) ) == XmClipboardLocked ); if( retval != XmClipboardSuccess ) return false; if( XmClipboardInquireCount( xdisplay, xwindow, &count, &max_name_length ) == XmClipboardSuccess ) { wxCharBuffer buf( max_name_length + 1 ); unsigned long copied; for( int i = 0; i < count; ++i ) { if( XmClipboardInquireFormat( xdisplay, xwindow, i + 1, (XtPointer)buf.data(), max_name_length, &copied ) != XmClipboardSuccess ) continue; buf.data()[copied] = '\0'; if( buf == id ) { isSupported = true; break; } } } XmClipboardUnlock( xdisplay, xwindow, False ); return isSupported; }
// Get the current mouse position. wxPoint wxGetMousePosition() { #if wxUSE_NANOX /* TODO */ return wxPoint(0, 0); #else Display *display = wxGlobalDisplay(); Window rootWindow = RootWindowOfScreen (DefaultScreenOfDisplay(display)); Window rootReturn, childReturn; int rootX, rootY, winX, winY; unsigned int maskReturn; XQueryPointer (display, rootWindow, &rootReturn, &childReturn, &rootX, &rootY, &winX, &winY, &maskReturn); return wxPoint(rootX, rootY); #endif }
void wxColourRefData::FreeColour() { if (!m_colormap) return; #if !wxUSE_NANOX if ( wxTheApp && (wxTheApp->m_visualInfo->m_visualType == GrayScale || wxTheApp->m_visualInfo->m_visualType == PseudoColor) ) { int idx = m_color.pixel; colMapAllocCounter[ idx ] = colMapAllocCounter[ idx ] - 1; if (colMapAllocCounter[ idx ] == 0) { unsigned long pixel = m_color.pixel; XFreeColors( wxGlobalDisplay(), (Colormap) m_colormap, &pixel, 1, 0 ); } } #endif }
wxToolkitInfo& wxGUIAppTraits::GetToolkitInfo() { static wxToolkitInfo info; info.shortName = _T("motif"); info.name = _T("wxMotif"); #ifdef __WXUNIVERSAL__ info.shortName << _T("univ"); info.name << _T("/wxUniversal"); #endif // FIXME TODO // This code is WRONG!! Does NOT return the // Motif version of the libs but the X protocol // version! Display *display = wxGlobalDisplay(); info.versionMajor = ProtocolVersion (display); info.versionMinor = ProtocolRevision (display); info.os = wxMOTIF_X; return info; }
void wxTopLevelWindowX11::DoSetIcon(const wxIcon& icon) { if (icon.IsOk() && X11GetMainWindow()) { #if !wxUSE_NANOX XWMHints *wmHints = XAllocWMHints(); wmHints->icon_pixmap = (Pixmap) icon.GetPixmap(); wmHints->flags = IconPixmapHint; if (icon.GetMask()) { wmHints->flags |= IconMaskHint; wmHints->icon_mask = (Pixmap) icon.GetMask()->GetBitmap(); } XSetWMHints(wxGlobalDisplay(), (Window) X11GetMainWindow(), wmHints); XFree(wmHints); #endif } }
bool wxClipboard::GetData( wxDataObject& data ) { // get formats count in the wxDataObject // for each data format, search it in x11 selection // and store it to wxDataObject size_t count = data.GetFormatCount(); wxDataFormatScopedArray dfarr(count); data.GetAllFormats(dfarr.get()); // prepare and find the root window, // the copied data stored in the root window as window property Display* xdisplay = wxGlobalDisplay(); int xscreen = DefaultScreen(xdisplay); Window window = RootWindow(xdisplay, xscreen); // retrieve the data in each format. for( size_t i = 0; i < count; ++i ) { GetClipboardData(xdisplay, window, data, dfarr[i]); } return true; }
void wxWindowX11::SendNcPaintEvents() { wxWindow *window = (wxWindow*) this; // All this for drawing the small square between the scrollbars. int width = 0; int height = 0; int x = 0; int y = 0; wxScrollBar *sb = window->GetScrollbar( wxHORIZONTAL ); if (sb && sb->IsShown()) { height = sb->GetSize().y; y = sb->GetPosition().y; sb = window->GetScrollbar( wxVERTICAL ); if (sb && sb->IsShown()) { width = sb->GetSize().x; x = sb->GetPosition().x; Display *xdisplay = wxGlobalDisplay(); Window xwindow = (Window) GetMainWindow(); Colormap cm = (Colormap) wxTheApp->GetMainColormap( wxGetDisplay() ); wxColour colour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE); colour.CalcPixel( (WXColormap) cm ); XSetForeground( xdisplay, g_eraseGC, colour.GetPixel() ); XFillRectangle( xdisplay, xwindow, g_eraseGC, x, y, width, height ); } } wxNcPaintEvent nc_paint_event( GetId() ); nc_paint_event.SetEventObject( this ); GetEventHandler()->ProcessEvent( nc_paint_event ); m_updateNcArea = FALSE; }
bool wxClipboard::AddData( wxDataObject *data ) { #if wxUSE_NANOX return false; #else wxCHECK_MSG( m_open, false, wxT("clipboard not open") ); wxCHECK_MSG( data, false, wxT("data is invalid") ); // in x11, the "copied data" hold by the program itself. // so here just use m_data to hold the "copied data" // use wxApp->ProcessXEvent to check whether there has // SelectionRequest event arrived. If the event arrived, // check the request format, if wx program has the request // format, reply the data. // Reply the data means fill up the data in requestor's // window property. // See HandleSelectionRequest for more details m_data = data; // prepare and find the root window, // the copied data stored in the root window as window property Display* xdisplay = wxGlobalDisplay(); int xscreen = DefaultScreen(xdisplay); Window window = RootWindow(xdisplay, xscreen); size_t size = m_data->GetDataSize(wxDF_UNICODETEXT); wxCharTypeBuffer<unsigned char> buf(size); m_data->GetDataHere(wxDF_UNICODETEXT, buf.data()); XChangeProperty(xdisplay, window, XA_CLIPBOARD, XA_STRING, 8, PropModeReplace, buf.data(), size); XSetSelectionOwner(xdisplay, XA_CLIPBOARD, window, CurrentTime); XFlush(xdisplay); return true; #endif }
void wxTopLevelWindowX11::DoSetClientSize(int width, int height) { int old_width = m_width; int old_height = m_height; m_width = width; m_height = height; if (m_width == old_width && m_height == old_height) return; // wxLogDebug("DoSetClientSize: %s (%ld) %dx%d", GetClassInfo()->GetClassName(), GetId(), width, height); #if !wxUSE_NANOX XSizeHints size_hints; size_hints.flags = PSize; size_hints.width = width; size_hints.height = height; XSetWMNormalHints( wxGlobalDisplay(), (Window) X11GetMainWindow(), &size_hints ); #endif wxWindowX11::DoSetClientSize(width, height); }