Розробники Eclipse/SWT про Windows та GTK
Implementation of SWT
Text.java – Windows and Macintosh
… SWT/win32/org/eclipse/swt/widgets/Text.java
public void selectAll() {
checkWidget();
OS.SendMessage(handle, OS.EM_SETSEL, 0, -1);
}
… SWT/carbon/org/eclipse/swt/widgets/Text.java
public void selectAll() {
checkWidget();
OS.TXNSelectAll(txnObject);
}
Text.java – GTK
… SWT/gtk/org/eclipse/swt/widgets/Text.java
public void selectAll() {
checkWidget();
if ((style & SWT.SINGLE) != 0) {
OS.gtk_editable_select_region(handle, 0, -1);
} else {
byte[] start = new byte[ITER_SIZEOF];
byte[] end = new byte[ITER_SIZEOF];
OS.gtk_text_buffer_get_iter_at_offset(h, start, 0);
OS.gtk_text_buffer_get_end_iter(h, end);
int iMark = OS.gtk_text_buffer_get_insert(h);
int sMark = OS.gtk_text_buffer_get_selection_bound(h);
OS.gtk_text_buffer_move_mark(h, sMark, start);
OS.gtk_text_buffer_move_mark(h, iMark, end);
}
}}
The “Operating System Hall of Shame”
• Windows
– OLE (ActiveX) has megalomania
• It’s just DLL’s (and “objects”, file system, storage …)
• Horribly verbose (QueryInterface(), check, cast ‘n
call)
– Bizarre limitations, strange design decisions
• Scroll Bars and Menus are not Controls
• Modal menu and resize loops
– WM_KEYDOWN, WM_SYSKEYDOWN … barf!
– GDI fumbling, SelectObject(), compatible HDC’s?
– STGC_DANGEROUSLYCOMMITMERELYTODISKCACHE
Built by “Hungarians”?
“Hungarian” Notation in Windows
Variant[] rgvarg2 = new Variant[] {rgvarg};
int[] rgdispidNamedArgs = new int[]
{COM.DISPID_PROPERTYPUT};
int dwFlags = COM.DISPATCH_PROPERTYPUT;
if ((rgvarg.getType() & COM.VT_BYREF) ==
COM.VT_BYREF)
dwFlags = COM.DISPATCH_PROPERTYPUTREF;
Variant pVarResult = new Variant();
int result = invoke(dispIdMember, dwFlags,
rgvarg2, rgdispidNamedArgs, pVarResult);
But I’m not “Hungarian”! [/size](Oh, yes, you are!)
How does Microsoft create new
controls?
BOOL InitCommonControlsEx()
BOOL Init Common Control Sex (!)
Daddy, where do widgets come from?
The “Operating System Hall of Shame”
• GTK
– “It’s not X, it’s GDK … oh wait … it’s the same!”
– Too many handles (“Dances with Handles”)
– Widgets won’t stay where you put them
– Event loops embedded in API (NEVER DO THIS)
– Everything is deferred, no way to force work to
happen, other than … running an event loop
– Too many versions (different bugs)
“Come home Windows, all is forgiven!”