Skip to content

Commit 8145bb1

Browse files
committed
Fix scrollbars not being visible on Win32
Fix fullscreen mode on Win32 Code cleanup of Win32
1 parent 56b426c commit 8145bb1

File tree

4 files changed

+42
-29
lines changed

4 files changed

+42
-29
lines changed

webview/cocoa.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
(C) 2014 Roman Sirokov
2+
(C) 2014-2015 Roman Sirokov
33
Licensed under BSD license
44
55
http://github.com/r0x0r/pywebview/

webview/gtk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
(C) 2014 Roman Sirokov
2+
(C) 2014-2015 Roman Sirokov
33
Licensed under BSD license
44
55
http://github.com/r0x0r/pywebview/

webview/qt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
(C) 2014 Roman Sirokov
2+
(C) 2014-2015 Roman Sirokov
33
Licensed under BSD license
44
55
http://github.com/r0x0r/pywebview/

webview/win32.py

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# -*- coding: utf-8 -*-
22

33
"""
4-
(C) 2014 Roman Sirokov
4+
(C) 2014-2015 Roman Sirokov
55
Licensed under BSD license
66
77
http://github.com/r0x0r/pywebview/
88
"""
99

10-
import win32con, win32api, win32gui, win32ui
10+
import win32con, win32api, win32gui
1111
from win32com.shell import shell, shellcon
1212
import os
1313
import sys
@@ -27,14 +27,13 @@
2727

2828
GetModule('shdocvw.dll')
2929

30-
_kernel32 = windll.kernel32
31-
_user32 = windll.user32
3230
_atl = windll.atl
33-
34-
35-
#NULL = c_int(win32con.NULL)
3631
_WNDPROC = WINFUNCTYPE(c_long, c_int, c_uint, c_int, c_int)
3732

33+
# for some reason we have to set an offset for the height of ATL window in order for the vertical scrollbar to be fully
34+
# visible
35+
VERTICAL_SCROLLBAR_OFFSET = 20
36+
3837
class WNDCLASS(Structure):
3938
_fields_ = [('style', c_uint),
4039
('lpfnWndProc', _WNDPROC),
@@ -59,6 +58,9 @@ def __init__(self, title, url, width, height, resizable, fullscreen):
5958
self.resizable = resizable
6059
self.fullscreen = fullscreen
6160

61+
self.scrollbar_width = win32api.GetSystemMetrics(win32con.SM_CXVSCROLL)
62+
self.scrollbar_height = win32api.GetSystemMetrics(win32con.SM_CYHSCROLL)
63+
6264
self.atlhwnd = -1 # AtlAx host window hwnd
6365
self.browser = None # IWebBrowser2 COM object
6466

@@ -73,15 +75,15 @@ def _register_window(self):
7375
message_map = {
7476
win32con.WM_DESTROY: self._on_destroy,
7577
win32con.WM_SIZE: self._on_resize,
76-
win32con.WM_ERASEBKGND: self._on_erase_bkgnd
78+
win32con.WM_ERASEBKGND: self._on_erase_bkgnd,
7779
}
7880

7981
self.wndclass = win32gui.WNDCLASS()
8082
self.wndclass.style = win32con.CS_HREDRAW | win32con.CS_VREDRAW
8183
self.wndclass.lpfnWndProc = message_map
8284
self.wndclass.hInstance = win32api.GetModuleHandle()
83-
self.wndclass.hCursor = _user32.LoadCursorW(c_int(win32con.NULL), c_int(win32con.IDC_ARROW))
84-
self.wndclass.hbrBackground = windll.gdi32.GetStockObject(c_int(win32con.WHITE_BRUSH))
85+
self.wndclass.hCursor = win32gui.LoadCursor(win32con.NULL, win32con.IDC_ARROW)
86+
self.wndclass.hbrBackground = win32gui.GetStockObject(win32con.WHITE_BRUSH)
8587
self.wndclass.lpszMenuName = ""
8688
self.wndclass.lpszClassName = "MainWin"
8789

@@ -91,38 +93,47 @@ def _register_window(self):
9193

9294
def _create_main_window(self):
9395
# Set window style
94-
style = win32con.WS_VISIBLE
95-
if self.resizable:
96-
style = style | win32con.WS_OVERLAPPEDWINDOW
97-
else:
98-
style = style | (win32con.WS_OVERLAPPEDWINDOW ^ win32con.WS_THICKFRAME)
96+
style = win32con.WS_VISIBLE | win32con.WS_OVERLAPPEDWINDOW
97+
if not self.resizable:
98+
style = style ^ win32con.WS_THICKFRAME
9999

100100
# Center window on the screen
101-
screen_x = _user32.GetSystemMetrics(win32con.SM_CXSCREEN)
102-
screen_y = _user32.GetSystemMetrics(win32con.SM_CYSCREEN)
101+
screen_x = win32api.GetSystemMetrics(win32con.SM_CXSCREEN)
102+
screen_y = win32api.GetSystemMetrics(win32con.SM_CYSCREEN)
103103
x = int((screen_x - self.width) / 2)
104104
y = int((screen_y - self.height) / 2)
105105

106+
106107
# Create Window
107108
self.hwnd = win32gui.CreateWindow(self.wndclass.lpszClassName,
108109
self.title, style, x, y, self.width, self.height,
109110
None, None, self.wndclass.hInstance, None)
110111

111112
# Set fullscreen
112113
if self.fullscreen:
113-
style = _user32.GetWindowLongW(self.hwnd, win32con.GWL_STYLE)
114-
_user32.SetWindowLongW(self.hwnd, win32con.GWL_STYLE, style & ~win32con.WS_OVERLAPPEDWINDOW)
115-
_user32.SetWindowPos(self.hwnd, win32con.HWND_TOP, 0, 0, screen_x, screen_y,
114+
self.width = screen_x
115+
self.height = screen_y
116+
117+
style = win32gui.GetWindowLong(self.hwnd, win32con.GWL_STYLE)
118+
win32gui.SetWindowLong(self.hwnd, win32con.GWL_STYLE, style & ~win32con.WS_OVERLAPPEDWINDOW)
119+
win32gui.SetWindowPos(self.hwnd, win32con.HWND_TOP, 0, 0, screen_x, screen_y,
116120
win32con.SWP_NOOWNERZORDER | win32con.SWP_FRAMECHANGED)
117121

118122

119123
def _create_atlax_window(self):
120124
_atl.AtlAxWinInit()
121125
hInstance = win32api.GetModuleHandle(None)
126+
127+
if self.fullscreen:
128+
atl_width = self.width
129+
atl_height = self.height
130+
else:
131+
atl_width = self.width - self.scrollbar_width
132+
atl_height = self.height - self.scrollbar_height - VERTICAL_SCROLLBAR_OFFSET
133+
122134
self.atlhwnd = win32gui.CreateWindow("AtlAxWin", self.url,
123135
win32con.WS_CHILD | win32con.WS_HSCROLL | win32con.WS_VSCROLL,
124-
0, 0, self.width, self.height,
125-
self.hwnd, None, hInstance, None)
136+
0, 0, atl_width, atl_height, self.hwnd, None, hInstance, None)
126137

127138
# COM voodoo
128139
pBrowserUnk = POINTER(IUnknown)()
@@ -133,6 +144,7 @@ def _create_atlax_window(self):
133144

134145
def show(self):
135146
# Show main window
147+
win32gui.SetWindowPos(self.hwnd, win32con.HWND_TOP, 0, 0, self.width, self.height, win32con.SWP_SHOWWINDOW)
136148
win32gui.ShowWindow(self.hwnd, win32con.SW_SHOWNORMAL)
137149
win32gui.UpdateWindow(self.hwnd)
138150

@@ -185,13 +197,14 @@ def _on_destroy(self, hwnd, message, wparam, lparam):
185197

186198
def _on_resize(self, hwnd, message, wparam, lparam):
187199
# Resize the ATL window as the size of the main window is changed
188-
if BrowserView.instance != None:
200+
if BrowserView.instance != None and not self.fullscreen:
189201
atl_hwnd = BrowserView.instance.atlhwnd
190202
width = win32api.LOWORD(lparam)
191203
height = win32api.HIWORD(lparam)
192-
_user32.SetWindowPos(atl_hwnd, win32con.HWND_TOP, 0, 0, width, height, win32con.SWP_SHOWWINDOW)
193-
_user32.ShowWindow(c_int(atl_hwnd), c_int(win32con.SW_SHOW))
194-
_user32.UpdateWindow(c_int(atl_hwnd))
204+
win32gui.SetWindowPos(atl_hwnd, win32con.HWND_TOP, 0, 0, width, height, win32con.SWP_SHOWWINDOW)
205+
win32gui.ShowWindow(atl_hwnd, win32con.SW_SHOW)
206+
win32gui.UpdateWindow(atl_hwnd)
207+
195208
return 0
196209

197210
def _on_erase_bkgnd(self, hwnd, message, wparam, lparam):

0 commit comments

Comments
 (0)