// InitInstance // Saves the windows instance handle, creates, and displays the main program // window //----------------------------------------------------------------------------- BOOL CPUTWindowWin::InitInstance(int nCmdShow, int windowWidth, int windowHeight, int windowX, int windowY) { // assure we have a valid hInstance ASSERT(NULL!=mhInst, _L("")); // zero sized windows means - you choose the size. :) if( (0==windowWidth) || (0==windowHeight) ) { GetDesktopDimensions(&windowWidth, &windowHeight); // default window size 1280x720 // but if screen is smaller than 1280x720, then pick 1/3 the screen size // so that it doesn't appear off the edges if(1280>windowWidth) { windowWidth = (2*windowWidth)/3; windowHeight = (2*windowHeight)/3; } else { windowWidth=1280; windowHeight=720; } } // set up size structure RECT rc = { 0, 0, windowWidth, windowHeight }; AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, FALSE ); // if x = -1, then let windows decide where to put it if(-1==windowX) { windowX = CW_USEDEFAULT; } // create the window mhWnd = CreateWindow(mAppTitle.c_str(), mAppTitle.c_str(), WS_OVERLAPPEDWINDOW, windowX, //CW_USEDEFAULT, windowY, //CW_USEDEFAULT, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, mhInst, NULL); if (!mhWnd) { return FALSE; } ShowWindow(mhWnd, nCmdShow); UpdateWindow(mhWnd); return TRUE; }
void WXAppBar::OnTimer(wxTimerEvent& event) { #if defined(__WXGTK__) long x, y; m_pMouseControl->GetPointerLocation (x, y); wxRect barRect = GetRect(); if (m_autohide && m_currentDockingMode != NON_DOCKED && m_isAutohideWindowShown && !barRect.Contains(x,y)) { // Get X11 display Display* dd= (Display *) wxGetDisplay(); assert (dd); // Get desktop working area dimensions int xDesktop, yDesktop, widthDesktop, heightDesktop, screenWidth, screenHeight; GetDesktopDimensions (dd, xDesktop, yDesktop, widthDesktop, heightDesktop, screenWidth, screenHeight); // Get original dimensions of the bar wxSize proposedSize= GetBestSize(); // Compute bar position and size depending on docking mode m_Width= proposedSize.GetWidth(); m_Height= proposedSize.GetHeight(); switch (m_currentDockingMode) { case TOP_DOCKED: m_X= (screenWidth - proposedSize.GetWidth())/2; m_Y= 0 - proposedSize.GetHeight() + AUTOHIDE_FLANGE; break; case BOTTOM_DOCKED: m_X= (screenWidth - proposedSize.GetWidth())/2; m_Y= screenHeight - AUTOHIDE_FLANGE; break; case LEFT_DOCKED: m_X= 0 - proposedSize.GetWidth() + AUTOHIDE_FLANGE; m_Y= (screenHeight - proposedSize.GetHeight())/2; break; case RIGHT_DOCKED: m_X= screenWidth - AUTOHIDE_FLANGE; m_Y= (screenHeight - proposedSize.GetHeight())/2; break; case NON_DOCKED: default: assert (false); } // Set desired location and dimensions SetSize(m_X, m_Y, m_Width, m_Height); m_isAutohideWindowShown= false; } #endif event.Skip(false); }
void WXAppBar::OnEnterWindow( wxMouseEvent& event ) { #if defined(__WXGTK__) if (m_autohide && m_currentDockingMode != NON_DOCKED && !m_isAutohideWindowShown) { // Get X11 display Display* dd= (Display *) wxGetDisplay(); assert (dd); // Get desktop working area dimensions int xDesktop, yDesktop, widthDesktop, heightDesktop, screenWidth, screenHeight; GetDesktopDimensions (dd, xDesktop, yDesktop, widthDesktop, heightDesktop, screenWidth, screenHeight); // Get original dimensions of the bar wxSize proposedSize= GetBestSize(); // Compute bar position and size depending on docking mode m_Width= proposedSize.GetWidth(); m_Height= proposedSize.GetHeight(); switch (m_currentDockingMode) { case TOP_DOCKED: m_X= (screenWidth - proposedSize.GetWidth())/2; m_Y= 0; break; case BOTTOM_DOCKED: m_X= (screenWidth - proposedSize.GetWidth())/2; m_Y= screenHeight - proposedSize.GetHeight(); break; case LEFT_DOCKED: m_X= 0; m_Y= (screenHeight - proposedSize.GetHeight())/2; break; case RIGHT_DOCKED: m_X= screenWidth - proposedSize.GetWidth(); m_Y= (screenHeight - proposedSize.GetHeight())/2; break; case NON_DOCKED: default: assert (false); } // Set desired location and dimensions SetSize(m_X, m_Y, m_Width, m_Height); m_isAutohideWindowShown= true; } #endif event.Skip(true); }
void CPUTWindowWin::SetFullscreenState(bool fullscreen) { if (mFullscreen == fullscreen) { return; } if (fullscreen) { int x, y, windowWidth, windowHeight; GetWindowDimensions(&x, &y, &windowWidth, &windowHeight); RECT windowRect = { x, y, windowWidth + x, windowHeight + y }; mWindowedRect = windowRect; int desktopX, desktopY; int desktopWidth, desktopHeight; GetDesktopDimensions(&desktopX, &desktopY, &desktopWidth, &desktopHeight); mWindowedStyle = GetWindowLong(mhWnd, GWL_STYLE); SetWindowLong(mhWnd, GWL_STYLE, (mWindowedStyle & ~WS_OVERLAPPEDWINDOW) | WS_POPUP); SetWindowPos(mhWnd, HWND_TOP, desktopX, desktopY, desktopWidth, desktopHeight, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING | SWP_NOZORDER); mFullscreen = true; } else { int width = mWindowedRect.right - mWindowedRect.left; int height = mWindowedRect.bottom - mWindowedRect.top; SetWindowLong(mhWnd, GWL_STYLE, mWindowedStyle); SetWindowPos(mhWnd, HWND_TOP, mWindowedRect.left, mWindowedRect.top, width, height, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING | SWP_NOZORDER | SWP_FRAMECHANGED); mFullscreen = false; } }
bool WXAppBar::CheckForBar() { #if defined(__WXGTK__) // Get X11 display Display* dd= (Display *) wxGetDisplay(); assert (dd); // Get desktop working area dimensions int xDesktop, yDesktop, widthDesktop, heightDesktop, screenWidth, screenHeight; GetDesktopDimensions (dd, xDesktop, yDesktop, widthDesktop, heightDesktop, screenWidth, screenHeight); switch (m_currentDockingMode) { case TOP_DOCKED: return (yDesktop > 0); break; case BOTTOM_DOCKED: return ((screenHeight - yDesktop - heightDesktop) > 0); break; case LEFT_DOCKED: return (xDesktop > 0); break; case RIGHT_DOCKED: return ((screenWidth - xDesktop - widthDesktop) > 0); break; case NON_DOCKED: default: return false; break; } #endif return false; }
// Create window //----------------------------------------------------------------------------- CPUTResult CPUTWindowWin::Create(const std::string WindowTitle, CPUTWindowCreationParams windowParams) { // // Validate that the window starting position is within the virtual desktop // ASSERT((windowParams.windowPositionX == -1) || (windowParams.windowPositionX >= GetSystemMetrics(SM_XVIRTUALSCREEN)), "You are attempting to create a window outside the desktop coordinates. Check your CPUTWindowCreationParams"); ASSERT((windowParams.windowPositionX <= GetSystemMetrics(SM_XVIRTUALSCREEN) + GetSystemMetrics(SM_CXVIRTUALSCREEN)), "You are attempting to create a window outside the desktop coordinates. Check your CPUTWindowCreationParams"); ASSERT((windowParams.windowPositionY == -1) || (windowParams.windowPositionY >= GetSystemMetrics(SM_YVIRTUALSCREEN)), "You are attempting to create a window outside the desktop coordinates. Check your CPUTWindowCreationParams"); ASSERT((windowParams.windowPositionY <= GetSystemMetrics(SM_YVIRTUALSCREEN) + GetSystemMetrics(SM_CYVIRTUALSCREEN)), "You are attempting to create a window outside the desktop coordinates. Check your CPUTWindowCreationParams"); // // Width or height of zero means to use a default size // if( (0 == windowParams.windowWidth) || (0 == windowParams.windowHeight) ) { windowParams.windowWidth = 1280; windowParams.windowHeight = 720; } // // If the requested with or height is greater than the size of the desktop, then CW_USEDDEFAULT // is used. This will size the window to the desktop extents based on the window starting position. // int desktopX, desktopY; int desktopWidth, desktopHeight; GetDesktopDimensions(&desktopX, &desktopY, &desktopWidth, &desktopHeight); if (desktopWidth < windowParams.windowWidth || desktopHeight < windowParams.windowHeight) { windowParams.windowWidth = CW_USEDEFAULT; windowParams.windowHeight = CW_USEDEFAULT; } // // A position of -1 means to use the system default value for window placement // if(-1 == windowParams.windowPositionX) { windowParams.windowPositionX = CW_USEDEFAULT; } if (-1 == windowParams.windowPositionY) { windowParams.windowPositionY = CW_USEDEFAULT; } mhInstance = GetModuleHandle(NULL); if( mhInstance == NULL ) { HandleWin32Error(); return CPUT_ERROR_CANNOT_GET_WINDOW_INSTANCE; } mAppTitle = WindowTitle; if (0 == mAppTitle.compare("")) { mAppTitle = "CPUT Sample"; } LPCTSTR iconPathName= TEXT("CPUT.ico"); UINT icon_flags = LR_LOADFROMFILE | LR_DEFAULTSIZE; HANDLE hIcon = LoadImage(mhInstance, iconPathName, IMAGE_ICON, 0, 0, icon_flags); // Clear message queue MSG msg = { 0 }; while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } // // Register the Win32 class for this app // WNDCLASSEX wc; uint32_t numWChars = MultiByteToWideChar(CP_UTF8, 0, mAppTitle.c_str(), -1, NULL, 0); wchar_t* wstr = new wchar_t[numWChars]; MultiByteToWideChar(CP_UTF8, 0, mAppTitle.c_str(), -1, wstr, numWChars); wc.cbSize = sizeof(WNDCLASSEX); wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = mhInstance; wc.hIcon = (HICON)hIcon; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); wc.lpszMenuName = NULL; wc.lpszClassName = wstr; wc.hIconSm = NULL; ATOM registeredClass = RegisterClassEx(&wc); if(0 == registeredClass) { HandleWin32Error(); delete[] wstr; return CPUT_ERROR_WINDOW_CANNOT_REGISTER_APP; } mhWnd = CreateWindowEx( 0, wstr, wstr, WS_OVERLAPPEDWINDOW, windowParams.windowPositionX, windowParams.windowPositionY, windowParams.windowWidth, windowParams.windowHeight, NULL, NULL, mhInstance, NULL ); delete[] wstr; if (!mhWnd) { HandleWin32Error(); return CPUT_ERROR_CANNOT_GET_WINDOW_INSTANCE; } ShowWindow(mhWnd, SW_SHOWNORMAL); UpdateWindow(mhWnd); return CPUT_SUCCESS; }
void WXAppBar::SetAutohideModeStep () { //CheckCreateWindow(); // // Get X11 display // Display* dd= (Display *) wxGetDisplay(); assert (dd); // // Get desktop working area dimensions // int xDesktop, yDesktop, widthDesktop, heightDesktop, screenWidth, screenHeight; GetDesktopDimensions (dd, xDesktop, yDesktop, widthDesktop, heightDesktop, screenWidth, screenHeight); // // As we need to dock the window disable decorations // m_dialogHadBorderDecorations= GetBorderDecorations(); SetBorderDecorations(false); // // Get X11 handle for our window // GtkWidget *gtkWidget= (GtkWidget *) this->GetHandle(); Window w= GDK_WINDOW_XWINDOW (gtkWidget->window); // Get original dimensions of the bar wxSize proposedSize= GetBestSize(); // Compute bar position and size depending on docking mode m_Width= proposedSize.GetWidth(); m_Height= proposedSize.GetHeight(); switch (m_currentDockingMode) { case TOP_DOCKED: m_X= (screenWidth - proposedSize.GetWidth())/2; m_Y= 0 - proposedSize.GetHeight() + AUTOHIDE_FLANGE; break; case BOTTOM_DOCKED: m_X= (screenWidth - proposedSize.GetWidth())/2; m_Y= screenHeight - AUTOHIDE_FLANGE; break; case LEFT_DOCKED: m_X= 0 - proposedSize.GetWidth() + AUTOHIDE_FLANGE; m_Y= (screenHeight - proposedSize.GetHeight())/2; break; case RIGHT_DOCKED: m_X= screenWidth - AUTOHIDE_FLANGE; m_Y= (screenHeight - proposedSize.GetHeight())/2; break; case NON_DOCKED: default: assert (false); } // // Functional type of the window (_NET_WM_WINDOW_TYPE) // Atom atomTmp= XInternAtom (dd, "_NET_WM_WINDOW_TYPE", False); Atom atom_NET_WM_WINDOW_TYPE_DOCK= XInternAtom (dd, "_NET_WM_WINDOW_TYPE_DOCK", False); Atom atom_NET_WM_WINDOW_TYPE_NORMAL= XInternAtom (dd, "_NET_WM_WINDOW_TYPE_NORMAL", False); unsigned long propInfo[2]; propInfo[0]= atom_NET_WM_WINDOW_TYPE_DOCK; propInfo[1]= atom_NET_WM_WINDOW_TYPE_NORMAL; XChangeProperty (dd, w, atomTmp, XA_ATOM, 32, PropModeReplace, (unsigned char *) &propInfo[0], 2); SetSticky(true); XSync(dd, False); // Set desired location and dimensions SetSize(m_X, m_Y, m_Width, m_Height); }
// Reserves an area for the X11 window 'w' in one of the sides of the desktop depending // on the value of 'where'. If 'where== NON_DOCKED' or area== 0 then the area is freed. static void SetStrutArea (Window w, WXAppBar::EDocking where, int area) { Display* dd= (Display *) wxGetDisplay(); // // Get desktop working area dimensions // int xDesktop, yDesktop, widthDesktop, heightDesktop, screenWidth, screenHeight; GetDesktopDimensions (dd, xDesktop, yDesktop, widthDesktop, heightDesktop, screenWidth, screenHeight); // // Reserves an area in the desktop. // // It seems that for older GNOME version (ex: 2.22.3 on Debian, using a partial strut // doesn't work properly, more TESTING NEEDED) // unsigned long strut[4] = {0, 0, 0, 0}; //unsigned long strut_p[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; /* left, right, top, bottom, left_start_y, left_end_y, right_start_y, right_end_y, top_start_x, top_end_x, bottom_start_x, bottom_end_x*/ if (area) { switch (where) { case WXAppBar::TOP_DOCKED: strut[2]= area + yDesktop; //strut_p[2]= strut[2]; break; case WXAppBar::BOTTOM_DOCKED: strut[3]= screenHeight - heightDesktop - yDesktop + area; //strut_p[3]= strut[3]; break; case WXAppBar::LEFT_DOCKED: strut[0]= area + xDesktop; //strut_p[0]= strut[0]; break; case WXAppBar::RIGHT_DOCKED: strut[1]= screenWidth - widthDesktop - xDesktop + area; //strut_p[1]= strut[1]; break; case WXAppBar::NON_DOCKED: break; default: assert (false); } } //atomTmp = XInternAtom (dd, "_NET_WM_STRUT_PARTIAL", False); //XChangeProperty (dd, w, atomTmp, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &strut_p, 12); Atom atomTmp = XInternAtom (dd, "_NET_WM_STRUT", False); XChangeProperty (dd, w, atomTmp, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &strut, 4); XSync(dd, False); // If window mapped, then wait until strut applied // TODO: is there a better way to do this? if (IsMappedWindow(dd, w)) { int new_xDesktop, new_yDesktop, new_widthDesktop, new_heightDesktop, count= 0; for (;;) { GetDesktopDimensions (dd, new_xDesktop, new_yDesktop, new_widthDesktop, new_heightDesktop, screenWidth, screenHeight); ++count; if (!(count< 20 && new_xDesktop== xDesktop && new_yDesktop== yDesktop && new_widthDesktop== widthDesktop && new_heightDesktop == heightDesktop)) break; usleep (100000); } } }