mirror of
https://github.com/clang-retro/mfc.git
synced 2026-11-28 13:19:26 -08:00
* 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>
278 lines
11 KiB
C++
278 lines
11 KiB
C++
// win16bar.cpp - the toolbar and the status bar on 16-bit Windows: a
|
|
// CToolBar with buttons and a separator, a click that sends a command,
|
|
// the idle update that disables a button and checks another, docking at
|
|
// the left edge, floating, and a CStatusBar with indicator panes and the
|
|
// message pane. It prints ALL PASSED when each step worked.
|
|
#include <afxwin.h>
|
|
#include <afxext.h>
|
|
#include <afxpriv.h>
|
|
#include <stdio.h>
|
|
#include "win16bar.h"
|
|
|
|
static int g_failures = 0;
|
|
static BOOL g_bDone = FALSE; // the last step ran
|
|
#define CHECK(cond) \
|
|
do { \
|
|
if (!(cond)) { \
|
|
printf("FAIL %s:%d: %s\n", __FILE__, __LINE__, #cond); \
|
|
g_failures++; \
|
|
} \
|
|
} while (0)
|
|
|
|
static const UINT s_buttons[] = {ID_BAR_ONE, ID_SEPARATOR, ID_BAR_TWO, ID_BAR_THREE, ID_BAR_CHECK};
|
|
static const UINT s_indicators[] = {ID_SEPARATOR, ID_INDICATOR_TEST};
|
|
|
|
/// Makes an image well of nCount images of 16 by 15 pixels, each in its
|
|
/// own color.
|
|
static HBITMAP MakeImages(int nCount) {
|
|
CClientDC dcScreen(NULL);
|
|
CDC dc;
|
|
dc.CreateCompatibleDC(&dcScreen);
|
|
CBitmap bm;
|
|
bm.CreateCompatibleBitmap(&dcScreen, 16 * nCount, 15);
|
|
CBitmap* pOld = dc.SelectObject(&bm);
|
|
dc.FillSolidRect(0, 0, 16 * nCount, 15, ::GetSysColor(COLOR_BTNFACE));
|
|
static const COLORREF colors[] = {RGB(255, 0, 0), RGB(0, 128, 0), RGB(0, 0, 255), RGB(0, 0, 0)};
|
|
for (int i = 0; i < nCount; i++) dc.FillSolidRect(i * 16 + 3, 3, 10, 9, colors[i % 4]);
|
|
dc.SelectObject(pOld);
|
|
return (HBITMAP)bm.Detach();
|
|
}
|
|
|
|
class CMainFrame : public CFrameWnd {
|
|
public:
|
|
CToolBar m_wndToolBar;
|
|
CStatusBar m_wndStatusBar;
|
|
int m_nOne;
|
|
int m_nTwo;
|
|
int m_nStep;
|
|
|
|
CMainFrame() : m_nOne(0), m_nTwo(0), m_nStep(0) {}
|
|
|
|
/// Gives the center of the button nID in the toolbar's client area.
|
|
CPoint ButtonCenter(UINT nID) {
|
|
CRect rect;
|
|
m_wndToolBar.GetItemRect(m_wndToolBar.CommandToIndex(nID), &rect);
|
|
return rect.CenterPoint();
|
|
}
|
|
|
|
/// Clicks the button nID as the mouse does.
|
|
void Click(UINT nID) {
|
|
CPoint pt = ButtonCenter(nID);
|
|
m_wndToolBar.SendMessage(WM_LBUTTONDOWN, MK_LBUTTON, MAKELONG(pt.x, pt.y));
|
|
m_wndToolBar.SendMessage(WM_LBUTTONUP, 0, MAKELONG(pt.x, pt.y));
|
|
}
|
|
|
|
/// Runs the idle update of the bars.
|
|
void IdleUpdate() { SendMessageToDescendants(WM_IDLEUPDATECMDUI, TRUE, 0, TRUE, TRUE); }
|
|
|
|
protected:
|
|
/// Makes the toolbar and the status bar, and starts the timer.
|
|
afx_msg int OnCreate(LPCREATESTRUCT lpcs) {
|
|
if (CFrameWnd::OnCreate(lpcs) == -1) return -1;
|
|
CHECK(m_wndToolBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_FLYBY | CBRS_TOOLTIPS));
|
|
CHECK(m_wndToolBar.SetButtons(s_buttons, 5));
|
|
CHECK(m_wndToolBar.SetBitmap(MakeImages(4)));
|
|
CHECK(m_wndStatusBar.Create(this));
|
|
CHECK(m_wndStatusBar.SetIndicators(s_indicators, 2));
|
|
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
|
|
EnableDocking(CBRS_ALIGN_ANY);
|
|
DockControlBar(&m_wndToolBar);
|
|
SetTimer(1, 50, NULL);
|
|
return 0;
|
|
}
|
|
|
|
/// The commands of the buttons.
|
|
afx_msg void OnOne() { m_nOne++; }
|
|
afx_msg void OnTwo() { m_nTwo++; }
|
|
|
|
/// Disables the third button and checks the check button.
|
|
afx_msg void OnUpdateThree(CCmdUI* pCmdUI) { pCmdUI->Enable(FALSE); }
|
|
afx_msg void OnUpdateCheck(CCmdUI* pCmdUI) { pCmdUI->SetCheck(1); }
|
|
afx_msg void OnCheck() {}
|
|
afx_msg void OnUpdateIndicator(CCmdUI* pCmdUI) { pCmdUI->SetText("ON"); }
|
|
|
|
/// Does one step of the test each time.
|
|
afx_msg void OnTimer(UINT_PTR nIDEvent) {
|
|
(void)nIDEvent;
|
|
switch (m_nStep++) {
|
|
case 0: {
|
|
// The toolbar has its buttons, docked at the top.
|
|
CHECK(::IsWindow(m_wndToolBar.m_hWnd));
|
|
CHECK(m_wndToolBar.IsWindowVisible());
|
|
CHECK(m_wndToolBar.CommandToIndex(ID_BAR_TWO) == 2);
|
|
CHECK(m_wndToolBar.GetItemID(1) == ID_SEPARATOR);
|
|
CRect rectOne, rectSep, rectTwo;
|
|
m_wndToolBar.GetItemRect(0, &rectOne);
|
|
m_wndToolBar.GetItemRect(1, &rectSep);
|
|
m_wndToolBar.GetItemRect(2, &rectTwo);
|
|
CHECK(rectOne.Width() == 23 && rectOne.Height() == 22);
|
|
CHECK(rectSep.Width() == 8);
|
|
CHECK(rectTwo.left == rectSep.right && rectTwo.top == rectOne.top);
|
|
CRect rectBar, rectClient;
|
|
m_wndToolBar.GetWindowRect(&rectBar);
|
|
ScreenToClient(&rectBar);
|
|
GetClientRect(&rectClient);
|
|
CHECK(rectBar.top == rectClient.top || rectBar.top <= 4);
|
|
CHECK(rectBar.Height() >= 22);
|
|
CHECK(!m_wndToolBar.IsFloating());
|
|
// The status bar is at the bottom with two panes.
|
|
CRect rectStatus;
|
|
m_wndStatusBar.GetWindowRect(&rectStatus);
|
|
ScreenToClient(&rectStatus);
|
|
CHECK(rectStatus.bottom == rectClient.bottom);
|
|
CHECK(rectStatus.Height() > 10);
|
|
CRect rectPane0, rectPane1;
|
|
m_wndStatusBar.GetItemRect(0, &rectPane0);
|
|
m_wndStatusBar.GetItemRect(1, &rectPane1);
|
|
CHECK(rectPane1.Width() > 8);
|
|
CHECK(rectPane0.right < rectPane1.left);
|
|
// The message pane stretches to the indicator.
|
|
CHECK(rectPane0.Width() > rectStatus.Width() / 2);
|
|
// The indicator has its string, or the text of an idle update.
|
|
CString strPane = m_wndStatusBar.GetPaneText(1);
|
|
CHECK(strPane == "TEST" || strPane == "ON");
|
|
break;
|
|
}
|
|
case 1: {
|
|
// A click sends the command of the button to the frame.
|
|
Click(ID_BAR_ONE);
|
|
Click(ID_BAR_TWO);
|
|
CHECK(m_nOne == 1);
|
|
CHECK(m_nTwo == 1);
|
|
// A press that leaves the button sends nothing.
|
|
CPoint pt = ButtonCenter(ID_BAR_ONE);
|
|
m_wndToolBar.SendMessage(WM_LBUTTONDOWN, MK_LBUTTON, MAKELONG(pt.x, pt.y));
|
|
m_wndToolBar.SendMessage(WM_MOUSEMOVE, MK_LBUTTON, MAKELONG(pt.x, 200));
|
|
m_wndToolBar.SendMessage(WM_LBUTTONUP, 0, MAKELONG(pt.x, 200));
|
|
CHECK(m_nOne == 1);
|
|
break;
|
|
}
|
|
case 2: {
|
|
// The idle update disables, checks and sets the pane text.
|
|
IdleUpdate();
|
|
int i3 = m_wndToolBar.CommandToIndex(ID_BAR_THREE);
|
|
int iCheck = m_wndToolBar.CommandToIndex(ID_BAR_CHECK);
|
|
CHECK((m_wndToolBar.GetButtonStyle(i3) & TBBS_DISABLED) != 0);
|
|
CHECK((m_wndToolBar.GetButtonStyle(iCheck) & TBBS_CHECKED) != 0);
|
|
CHECK((m_wndToolBar.GetButtonStyle(0) & TBBS_DISABLED) == 0);
|
|
CHECK(m_wndStatusBar.GetPaneText(1) == "ON");
|
|
// A disabled button sends nothing.
|
|
int nTwo = m_nTwo;
|
|
Click(ID_BAR_THREE);
|
|
CHECK(m_nTwo == nTwo);
|
|
// The control has the state that the class set.
|
|
CHECK((m_wndToolBar.DefWindowProc(TB_GETSTATE, ID_BAR_THREE, 0) & TBSTATE_ENABLED) == 0);
|
|
// The message pane.
|
|
SetMessageText("Hello from Win16");
|
|
char sz[64];
|
|
m_wndStatusBar.DefWindowProc(SB_GETTEXT, 0, (LPARAM)(LPSTR)sz);
|
|
CHECK(lstrcmp(sz, "Hello from Win16") == 0);
|
|
CHECK(m_wndStatusBar.GetPaneText(0) == "Hello from Win16");
|
|
m_wndToolBar.UpdateWindow();
|
|
m_wndStatusBar.UpdateWindow();
|
|
break;
|
|
}
|
|
case 3: {
|
|
// Docked at the left edge, the buttons are in one column.
|
|
DockControlBar(&m_wndToolBar, AFX_IDW_DOCKBAR_LEFT);
|
|
RecalcLayout();
|
|
CRect rectOne, rectTwo;
|
|
m_wndToolBar.GetItemRect(0, &rectOne);
|
|
m_wndToolBar.GetItemRect(2, &rectTwo);
|
|
CHECK(rectTwo.top > rectOne.bottom - 1);
|
|
CHECK(rectTwo.left == rectOne.left);
|
|
CRect rectBar;
|
|
m_wndToolBar.GetWindowRect(&rectBar);
|
|
CHECK(rectBar.Height() > rectBar.Width());
|
|
break;
|
|
}
|
|
case 4: {
|
|
// Floating, the bar is in a mini frame, in one row.
|
|
FloatControlBar(&m_wndToolBar, CPoint(300, 200));
|
|
CHECK(m_wndToolBar.IsFloating());
|
|
CFrameWnd* pMini = m_wndToolBar.GetParentFrame();
|
|
CHECK(pMini != NULL && pMini != this);
|
|
CRect rectOne, rectTwo;
|
|
m_wndToolBar.GetItemRect(0, &rectOne);
|
|
m_wndToolBar.GetItemRect(2, &rectTwo);
|
|
CHECK(rectTwo.top == rectOne.top);
|
|
// Docked again at the top.
|
|
DockControlBar(&m_wndToolBar, AFX_IDW_DOCKBAR_TOP);
|
|
CHECK(!m_wndToolBar.IsFloating());
|
|
Click(ID_BAR_ONE);
|
|
CHECK(m_nOne == 2);
|
|
break;
|
|
}
|
|
case 5: {
|
|
// The tooltip: with the mouse on a button, five ticks of the
|
|
// bar's timer show the part of the string after the newline.
|
|
CPoint pt = ButtonCenter(ID_BAR_TWO);
|
|
m_wndToolBar.ClientToScreen(&pt);
|
|
::SetCursorPos(pt.x, pt.y);
|
|
m_wndToolBar.ScreenToClient(&pt);
|
|
m_wndToolBar.SendMessage(WM_MOUSEMOVE, 0, MAKELONG(pt.x, pt.y));
|
|
for (int i = 0; i < 5; i++) m_wndToolBar.SendMessage(WM_TIMER, 1, 0);
|
|
HWND hwndTip = ::FindWindow("AfxW16ToolTip", NULL);
|
|
CHECK(hwndTip != NULL && ::IsWindowVisible(hwndTip));
|
|
char sz[32] = "";
|
|
if (hwndTip != NULL) ::GetWindowText(hwndTip, sz, sizeof(sz));
|
|
CHECK(lstrcmp(sz, "Second") == 0);
|
|
// A click hides it.
|
|
m_wndToolBar.SendMessage(WM_LBUTTONDOWN, MK_LBUTTON, MAKELONG(pt.x, pt.y));
|
|
m_wndToolBar.SendMessage(WM_LBUTTONUP, 0, MAKELONG(pt.x, pt.y));
|
|
CHECK(hwndTip == NULL || !::IsWindowVisible(hwndTip));
|
|
break;
|
|
}
|
|
case 6: {
|
|
// ShowControlBar hides the status bar.
|
|
ShowControlBar(&m_wndStatusBar, FALSE, FALSE);
|
|
CHECK(!m_wndStatusBar.IsWindowVisible());
|
|
ShowControlBar(&m_wndStatusBar, TRUE, FALSE);
|
|
CHECK(m_wndStatusBar.IsWindowVisible());
|
|
KillTimer(1);
|
|
g_bDone = TRUE;
|
|
if (getenv("WIN16BAR_KEEP") == NULL) DestroyWindow();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
DECLARE_MESSAGE_MAP()
|
|
};
|
|
|
|
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
|
|
ON_WM_CREATE()
|
|
ON_WM_TIMER()
|
|
ON_COMMAND(ID_BAR_ONE, OnOne)
|
|
ON_COMMAND(ID_BAR_TWO, OnTwo)
|
|
ON_COMMAND(ID_BAR_CHECK, OnCheck)
|
|
ON_UPDATE_COMMAND_UI(ID_BAR_THREE, OnUpdateThree)
|
|
ON_UPDATE_COMMAND_UI(ID_BAR_CHECK, OnUpdateCheck)
|
|
ON_UPDATE_COMMAND_UI(ID_INDICATOR_TEST, OnUpdateIndicator)
|
|
END_MESSAGE_MAP()
|
|
|
|
class CTestApp : public CWinApp {
|
|
public:
|
|
/// Makes and shows the main frame.
|
|
virtual BOOL InitInstance() {
|
|
CMainFrame* pFrame = new CMainFrame;
|
|
if (!pFrame->Create(NULL, "MFC Win16 bars", WS_OVERLAPPEDWINDOW, CRect(20, 20, 420, 320))) {
|
|
printf("FAIL Create\n");
|
|
return FALSE;
|
|
}
|
|
m_pMainWnd = pFrame;
|
|
pFrame->ShowWindow(m_nCmdShow);
|
|
pFrame->UpdateWindow();
|
|
return TRUE;
|
|
}
|
|
|
|
/// Prints the result.
|
|
virtual int ExitInstance() {
|
|
CHECK(g_bDone);
|
|
printf(g_failures == 0 ? "ALL PASSED\n" : "FAILED %d\n", g_failures);
|
|
return CWinApp::ExitInstance();
|
|
}
|
|
};
|
|
|
|
CTestApp theApp;
|