Files
mfc/tests/win16oledoc.cpp
NeoandClaude Opus 5.5 114257cce2 Classic look of the portable controls; Win16 OLE dialogs and all the common controls (#141)
* port: finish the classic look of the controls

- Scroll bars: the trough is the checker of the face and highlight
  colors, as DefWindowProc gives it for WM_CTLCOLORSCROLLBAR. A scroll
  bar control asks its parent for the brush. Disabled arrows are
  embossed, and a scroll bar control made with WS_DISABLED draws as
  disabled from the start.
- List boxes: a scroll bar that SetScrollInfo hid shows again when the
  items no longer fit. Before, a list box made empty lost WS_VSCROLL
  and never got its bar back.
- Trackbars: without TBS_BOTH, the thumb has a point toward the ticks.
  A thumb that is dragged or disabled has the checker face.
- Tabs: the two outer corners of each tab are cut.

wintest checks the trough, the list box's bar and the thumb's point.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRV6wfb9PKGryxuRrjF

* urlmon.h: define __WINPORT_EXTERN_C for the 16-bit build

The 16-bit build takes the OLE headers of the win16-sdk, which do not
include the windef.h of the portable layer. Since urlmon.h became C
compatible, afxole.h did not compile for i8086-pc-win16. The library and
the 16-bit tests build again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRV6wfb9PKGryxuRrjF

* win16: show the tooltips of the toolbar

16-bit Windows has no tooltip control, so a toolbar with CBRS_TOOLTIPS
showed no tooltip. The 16-bit toolbar window now shows them itself:
when the mouse stays on a button for half a second, it sends
TTN_NEEDTEXTA to its owner and shows the text below the mouse in a
small window. A timer finds when the mouse leaves the button. win16bar
checks the tip of a button.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRV6wfb9PKGryxuRrjF

* win16: the Insert Object, Paste Special, Links and Server Busy dialogs

16-bit OLE 2 has no OLE dialog DLL. The dialogs are now templates in
memory in src/win16oleui.cpp, with the same rules as the dialogs of the
portable layer. Change Icon, Convert, Change Source and Object
Properties still fail. tests/win16oledoc.cpp runs each dialog with a
hook that closes it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRV6wfb9PKGryxuRrjF

* win16: the progress bar, trackbar, up-down and tab control windows

16-bit Windows has no comctl32.dll. src/win16ctl.cpp registers four
window classes that do the messages of the common controls in ANSI,
with the 16-bit packing of WM_HSCROLL and WM_VSCROLL, and draws them in
the 3D style of the system colors. CProgressCtrl, CSliderCtrl,
CSpinButtonCtrl and CTabCtrl now make their windows. tests/win16cmn.cpp
checks each control and its notifications.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRV6wfb9PKGryxuRrjF

* win16: image lists, and the afxcmn.h class members

src/win16imgl.cpp gives the ImageList_ functions with 16-bit GDI: the
images side by side in one screen bitmap, the masks in one monochrome
bitmap, the draw styles, the overlays, the icons and the drag image.
cmnctls.cpp is now in the 16-bit library, so CImageList and the other
classes of afxcmn.h link. win16ctl.h has what the control windows share.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRV6wfb9PKGryxuRrjF

* Win16: add the header control and the list view

The library draws the header control (AfxHeader16, also SysHeader32) and
the list view (AfxListView16, also SysListView32) on 16-bit Windows. The
list view has the four views, virtual lists, callbacks, label editing,
check boxes, custom draw, sorting and find. The win16cmn test checks a
report view. The Win16 code is built and linked; Wine cannot run it in
this container.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRV6wfb9PKGryxuRrjF

* Win16: add the tree view

The library draws the tree view (AfxTreeView16, also SysTreeView32) on
16-bit Windows: lines, buttons, check boxes, image lists, callbacks,
label editing, custom draw, sorting, the drop highlight, the insert
mark, drag notifications and the incremental search. The win16cmn test
checks the links, the expansion, the selection and the sort of a tree.
The Win16 code is built and linked; Wine cannot run it in this
container.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRV6wfb9PKGryxuRrjF

* Win16: add the tooltip control

The library draws the tooltip (AfxToolTip16, also tooltips_class32) on
16-bit Windows: window and rectangle tools, TTM_RELAYEVENT and
TTF_SUBCLASS, the text callback, string resources, TTN_SHOW and
TTN_POP, tracking tips, titles, delay times, colors, margins and word
wrap. AFX_WNDCOMMCTL_BAR_REG registers it, as ICC_BAR_CLASSES does. The
win16cmn test checks the tools, the text, a hit test, the show and the
pop. The Win16 code is built and linked; Wine cannot run it in this
container.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRV6wfb9PKGryxuRrjF

* Win16: add the hot key, IP address, pager and link controls

The library draws the hot key control, the IP address control, the
pager and the link control (SysLink) on 16-bit Windows, with their
messages and notifications. The win16cmn test checks each of them. The
Win16 code is built and linked; Wine cannot run it in this container.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRV6wfb9PKGryxuRrjF

* Win16: add the extended combo box

The library draws the extended combo box (AfxComboBoxEx16, also
ComboBoxEx32) on 16-bit Windows with an owner-drawn combo box: indents,
images, callbacks and the CBEN_ notifications. The 16-bit CB_ messages
have the numbers of the CBEM_ messages, so afxwin16u.h moves the CBEM_
messages above them. The win16cmn test checks the items, the data and
the notifications. The Win16 code is built and linked; Wine cannot run
it in this container.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRV6wfb9PKGryxuRrjF

* Win16: draw the month calendar and the date and time picker

src/win16date.cpp registers AfxMonthCal16 and AfxDateTime16 (and the
comctl32 names). The calendar does the MCM_ messages, several months,
the selection, the range, today, week numbers and day states. The
picker reads the WIN.INI [intl] formats, does custom formats with
callback fields, the keys, the up-down button, the drop-down calendar,
DTS_SHOWNONE and DTS_APPCANPARSE, and sends the DTN_ notifications.

afxwin16u.h moves the MCHT_ flags into 16 bits. win16cmn tests both
controls. The code is built and linked, but not run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRV6wfb9PKGryxuRrjF

* Win16: draw the rebar, and build CReBar

src/win16rebar.cpp registers AfxReBar16 (and ReBarWindow32). It does
the RB_ messages: bands in rows, grippers, images, text, background
bitmaps, chevrons, drags between rows and along a row, the smallest and
largest width of a band, and CCS_VERT. It sends the RBN_ notifications
and gives the notifications of the child windows to its parent.

rebar.cpp (CReBar) is now in the Win16 library. win16cmn tests the
rebar and a CReBar. The code is built and linked, but not run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRV6wfb9PKGryxuRrjF

* Win16: draw the animation control

src/win16anim.cpp registers AfxAnimate16 (and SysAnimate32). It plays
the first video stream of an AVI clip from an AVI resource or a file,
with uncompressed or BI_RLE8 frames. It reads each frame when it shows
it, so a clip can be larger than a segment. A timer plays the clip, and
the parent gets ACN_START and ACN_STOP. ACS_CENTER, ACS_AUTOPLAY and
ACS_TRANSPARENT work.

Now the library draws all the common controls on Win16. win16cmn writes
a small RLE8 clip and checks its frames. The code is built and linked,
but not run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRV6wfb9PKGryxuRrjF

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-26 13:57:32 -08:00

300 lines
9.8 KiB
C++

// win16oledoc.cpp - tests the OLE document classes of MFC on 16-bit
// Windows. Wine's 16-bit OLE2.DLL is mostly stubs, so most of the test
// is a link check: the test makes a container document, a server
// document and item, a drop target and an in-place frame only in a
// function that does not run (LinkCheck). The part that runs caches data
// in a COleDataSource and asks for its formats through COleDataObject,
// which uses MFC code only. The OLE dialogs (Insert Object, Paste
// Special, Links and Server Busy) run with a hook that closes them.
#include <afxwin.h>
#include <afxole.h>
#include <oledlg.h>
#include <stdio.h>
#include <string.h>
static int g_failures = 0;
#define CHECK(cond) \
do { \
if (!(cond)) { \
printf("FAIL %s:%d: %s\n", __FILE__, __LINE__, #cond); \
g_failures++; \
} \
} while (0)
// A container item and its document.
class CTestItem : public COleClientItem {
public:
/// Makes an item of the document.
CTestItem(COleDocument* pDoc = NULL) : COleClientItem(pDoc) {}
};
class CTestContainerDoc : public COleDocument {
public:
/// Makes an empty container document.
CTestContainerDoc() {}
};
// A server item that draws a rectangle.
class CTestServerItem : public COleServerItem {
public:
/// Makes the item of a server document.
CTestServerItem(COleServerDoc* pDoc) : COleServerItem(pDoc, TRUE) {}
/// Draws the item.
virtual BOOL OnDraw(CDC* pDC, CSize& rSize) {
rSize = CSize(1000, 1000);
pDC->Rectangle(0, 0, 1000, 1000);
return TRUE;
}
};
// A server document with one item.
class CTestServerDoc : public COleServerDoc {
public:
/// Gives the embedded item, made on the first call.
virtual COleServerItem* OnGetEmbeddedItem() { return new CTestServerItem(this); }
};
/// Uses the container, server, drag and drop and in-place classes, so
/// that the linker must find all of their functions. The test does not
/// call it: Wine's 16-bit OLE2.DLL cannot run them.
void LinkCheck(CWnd* pWnd) {
CTestContainerDoc container;
CTestItem* pItem = new CTestItem(&container);
pItem->CreateNewItem(CLSID_NULL);
pItem->CreateFromFile("c:\\file.txt");
pItem->DoVerb(OLEIVERB_SHOW, NULL);
pItem->Close();
pItem->Delete();
CTestServerDoc* pServer = new CTestServerDoc;
pServer->GetEmbeddedItem();
pServer->NotifyChanged();
pServer->OnCloseDocument();
COleTemplateServer templateServer;
templateServer.UpdateRegistry(OAT_INPLACE_SERVER);
COleDropTarget target;
target.Register(pWnd);
target.Revoke();
COleDataSource* pSource = new COleDataSource;
pSource->DoDragDrop();
pSource->SetClipboard();
pSource->InternalRelease();
COleIPFrameWnd* pFrame = new COleIPFrameWnd;
pFrame->DestroyWindow();
COleStreamFile file;
file.CreateMemoryStream();
file.Close();
COleMessageFilter* pFilter = AfxOleGetMessageFilter();
if (pFilter != NULL) pFilter->BeginBusyState();
AfxOleInit();
}
/// Caches text in a data source and finds its format through its
/// IDataObject with COleDataObject.
static void TestDataTransfer() {
COleDataSource* pSource = new COleDataSource;
const char szText[] = "Hello, OLE";
HGLOBAL hText = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, sizeof(szText));
CHECK(hText != NULL);
if (hText == NULL) return;
memcpy(::GlobalLock(hText), szText, sizeof(szText));
::GlobalUnlock(hText);
pSource->CacheGlobalData(CF_TEXT, hText);
LPDATAOBJECT lpData = (LPDATAOBJECT)pSource->GetInterface(&IID_IDataObject);
CHECK(lpData != NULL);
if (lpData == NULL) return;
COleDataObject data;
data.Attach(lpData, FALSE);
CHECK(data.IsDataAvailable(CF_TEXT));
CHECK(!data.IsDataAvailable(CF_BITMAP));
// GetData copies the cached data with OleDuplicateData, which Wine's
// OLE2.DLL does not have, so the test does not get the data.
data.BeginEnumFormats();
FORMATETC fe;
int nFormats = 0;
while (data.GetNextFormat(&fe)) {
CHECK(fe.cfFormat == CF_TEXT && fe.tymed == TYMED_HGLOBAL);
nFormats++;
}
CHECK(nFormats == 1);
data.Release();
pSource->InternalRelease();
}
// What the hook of the dialog tests sends when a dialog starts, and what
// it saw.
static UINT g_nHookCommand = IDOK;
static int g_nHookListItems = -1;
static HWND g_hHookDialog = NULL;
/// Gives the count of items in the first list box of a dialog, or -1
/// when the dialog has no list box.
static int CountListItems(HWND hDlg) {
for (HWND h = ::GetWindow(hDlg, GW_CHILD); h != NULL; h = ::GetWindow(h, GW_HWNDNEXT)) {
char szClass[16];
::GetClassName(h, szClass, sizeof(szClass));
if (lstrcmpi(szClass, "ListBox") == 0) return (int)::SendMessage(h, LB_GETCOUNT, 0, 0);
}
return -1;
}
/// The hook of the dialog tests: when the dialog starts, it keeps the
/// window and the count of list items, and posts the command that closes
/// the dialog.
static UINT CALLBACK CloseHook(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
(void)wParam;
(void)lParam;
if (msg == WM_INITDIALOG) {
g_hHookDialog = hDlg;
g_nHookListItems = CountListItems(hDlg);
::PostMessage(hDlg, WM_COMMAND, g_nHookCommand, 0);
}
return 0;
}
// A link container with one link, for the Links dialog.
struct CTestLinks : IOleUILinkContainerA {
/// Gives the interface for IUnknown and the container.
STDMETHOD(QueryInterface)(REFIID, LPVOID* ppv) {
*ppv = this;
return S_OK;
}
/// Does not count: the object is on the stack.
STDMETHOD_(ULONG, AddRef)() { return 1; }
/// Does not count: the object is on the stack.
STDMETHOD_(ULONG, Release)() { return 1; }
/// Gives the one link, 1, after 0.
STDMETHOD_(DWORD, GetNextLink)(DWORD dwLink) { return dwLink == 0 ? 1 : 0; }
/// Accepts the options.
STDMETHOD(SetLinkUpdateOptions)(DWORD, DWORD) { return S_OK; }
/// Gives automatic updates.
STDMETHOD(GetLinkUpdateOptions)(DWORD, DWORD* lpdw) {
*lpdw = OLEUPDATE_ALWAYS;
return S_OK;
}
/// Accepts the source.
STDMETHOD(SetLinkSource)(DWORD, LPSTR, ULONG, ULONG*, BOOL) { return S_OK; }
/// Gives no names: the dialog shows an empty line for the link.
STDMETHOD(GetLinkSource)(DWORD, LPSTR* lplpszName, ULONG* lpLen, LPSTR* lplpszFull,
LPSTR* lplpszShort, BOOL* lpfAvailable, BOOL* lpfSelected) {
*lplpszName = *lplpszFull = *lplpszShort = NULL;
*lpLen = 0;
*lpfAvailable = TRUE;
*lpfSelected = FALSE;
return S_OK;
}
/// Does nothing.
STDMETHOD(OpenLinkSource)(DWORD) { return S_OK; }
/// Does nothing.
STDMETHOD(UpdateLink)(DWORD, BOOL, BOOL) { return S_OK; }
/// Does nothing.
STDMETHOD(CancelLink)(DWORD) { return S_OK; }
};
/// Runs the Insert Object, Paste Special, Links and Server Busy dialogs
/// with a hook that closes each one, and checks what they give.
static void TestDialogs() {
OLEUIINSERTOBJECTA io;
memset(&io, 0, sizeof(io));
io.cbStruct = sizeof(io);
io.dwFlags = IOF_SELECTCREATENEW;
io.lpfnHook = CloseHook;
char szFile[64] = "c:\\file.txt";
io.lpszFile = szFile;
io.cchFile = sizeof(szFile);
g_nHookCommand = IDOK;
CHECK(OleUIInsertObjectA(&io) == OLEUI_OK);
CHECK(io.dwFlags & IOF_SELECTCREATENEW);
CHECK(lstrcmp(szFile, "c:\\file.txt") == 0);
g_nHookCommand = IDCANCEL;
CHECK(OleUIInsertObjectA(&io) == OLEUI_CANCEL);
io.cbStruct = 0;
CHECK(OleUIInsertObjectA(&io) == OLEUI_ERR_CBSTRUCTINCORRECT);
COleDataSource* pSource = new COleDataSource;
HGLOBAL hText = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, 4);
lstrcpy((LPSTR)::GlobalLock(hText), "abc");
::GlobalUnlock(hText);
pSource->CacheGlobalData(CF_TEXT, hText);
OLEUIPASTEENTRYA entries[2];
memset(entries, 0, sizeof(entries));
entries[0].fmtetc.cfFormat = CF_BITMAP;
entries[0].fmtetc.dwAspect = DVASPECT_CONTENT;
entries[0].fmtetc.lindex = -1;
entries[0].fmtetc.tymed = TYMED_GDI;
entries[0].lpstrFormatName = "Bitmap";
entries[0].lpstrResultText = "a bitmap";
entries[0].dwFlags = OLEUIPASTE_PASTEONLY;
entries[1].fmtetc.cfFormat = CF_TEXT;
entries[1].fmtetc.dwAspect = DVASPECT_CONTENT;
entries[1].fmtetc.lindex = -1;
entries[1].fmtetc.tymed = TYMED_HGLOBAL;
entries[1].lpstrFormatName = "Text";
entries[1].lpstrResultText = "%s as text";
entries[1].dwFlags = OLEUIPASTE_PASTEONLY;
OLEUIPASTESPECIALA ps;
memset(&ps, 0, sizeof(ps));
ps.cbStruct = sizeof(ps);
ps.dwFlags = PSF_SELECTPASTE;
ps.lpfnHook = CloseHook;
ps.lpSrcDataObj = (LPDATAOBJECT)pSource->GetInterface(&IID_IDataObject);
ps.arrPasteEntries = entries;
ps.cPasteEntries = 2;
ps.nSelectedIndex = -1;
g_nHookCommand = IDOK;
g_nHookListItems = -1;
CHECK(OleUIPasteSpecialA(&ps) == OLEUI_OK);
CHECK(g_nHookListItems == 1); // the data source has text and no bitmap
CHECK(ps.nSelectedIndex == 1);
CHECK(!ps.fLink);
CHECK(ps.dwFlags & PSF_SELECTPASTE);
pSource->InternalRelease();
CTestLinks links;
OLEUIEDITLINKSA el;
memset(&el, 0, sizeof(el));
el.cbStruct = sizeof(el);
el.lpfnHook = CloseHook;
el.lpOleUILinkContainer = &links;
g_nHookListItems = -1;
CHECK(OleUIEditLinksA(&el) == OLEUI_OK);
CHECK(g_nHookListItems == 1);
OLEUIBUSYA bz;
memset(&bz, 0, sizeof(bz));
bz.cbStruct = sizeof(bz);
bz.lpfnHook = CloseHook;
bz.hTask = ::GetCurrentTask();
HWND hBusy = NULL;
bz.lphWndDialog = &hBusy;
g_nHookCommand = IDCANCEL;
g_hHookDialog = NULL;
CHECK(OleUIBusyA(&bz) == OLEUI_CANCEL);
CHECK(g_hHookDialog != NULL);
CHECK(hBusy == NULL);
bz.hTask = NULL;
CHECK(OleUIBusyA(&bz) == OLEUI_BZERR_HTASKINVALID);
}
/// Runs the test and prints ALL PASSED when every check holds.
int main(int argc, char** argv) {
(void)argv;
// The link check runs only when the program has 100 arguments.
if (argc == 100) LinkCheck(NULL);
TestDataTransfer();
TestDialogs();
if (g_failures == 0) printf("ALL PASSED\n");
return g_failures;
}