21#if defined(BI_MULTI_THREAD_RTL)
35#if defined(__BORLANDC__)
54 auto GetWheelScrollLines_() ->
uint
57 const auto r = ::SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &n, 0);
58 WARN(!r,
_T(
"SystemParametersInfo(SPI_GETWHEELSCROLLLINES) failed. LastError: ") << GetLastError());
InUse(r);
69#define OWL_RTTI_MSGCACHE
70#define TYPE_UNIQUE_ID(t) reinterpret_cast<UINT_PTR>(typeid(t).name())
102#if defined(OWL5_COMPAT)
104 EV_WM_CTLCOLORMSGBOX(EvCtlColor),
291 HWndReceiver(hReceiver)
310 "PLACEMENT=" <<
TRect{wp.rcNormalPosition} <<
312 " min=" <<
TPoint{wp.ptMinPosition} <<
313 " max=" <<
TPoint{wp.ptMaxPosition} <<
314 " showCmd=" << wp.showCmd <<
315 " flags=" << wp.flags);
342 : Handle{nullptr}, Title{nullptr}, DefaultProc{nullptr}, InstanceProc{nullptr}, Module{nullptr}
344 Init(parent, title, module);
351 : Handle{nullptr}, Title{nullptr}, DefaultProc{nullptr}, InstanceProc{nullptr}, Module{nullptr}
353 Init(parent, title, module);
382 : Handle{nullptr}, Title{nullptr}, DefaultProc{nullptr}, InstanceProc{nullptr}, Module{nullptr}
385 Init(handle, module);
393 : Handle{nullptr}, Title{nullptr}, DefaultProc{nullptr}, InstanceProc{nullptr}, Module{nullptr}
405 PerformInit(parent, module);
410 Attr.Style = WS_CHILD | WS_VISIBLE;
411 Attr.X = Attr.Y = Attr.W = Attr.H = 0;
443 PerformInit(parent, module);
477 TransferBuffer =
nullptr;
478 TransferBufferSize = 0;
480 Attr.
Param =
nullptr;
485 ContextPopupMenu =
nullptr;
487 CursorModule =
nullptr;
496 InstanceProc = CreateInstanceProc();
501 Parent->AddChild(
this);
503 SiblingList =
nullptr;
509 Module =
module ? module : Parent->GetModule();
512 Module =
module ? module : nullptr;
525 TRACEX(OwlWin, 1,
_T(
"TWindow constructed @") << (
void*)
this << *
this);
534void CacheFlush(UINT_PTR
id);
552 _T(
"Restoring old WndProc after foreign subclass of:") << *
this);
556 InstanceProc =
nullptr;
560 owl::CacheFlush(UniqueId);
573 auto c = vector<TWindow*>{};
584 TRACEX(OwlWin, 0,
_T(
"~TWindow: Swallowed exception while destroying child: ") << *w);
591 WARNX(OwlWin,
GetHandle(), 0,
_T(
"Destroying from TWindow::~TWindow: ") << *
this);
595 TRACEX(OwlWin, 0,
_T(
"~TWindow: Swallowed exception while destroying this: ") << *
this);
602 Parent->RemoveChild(
this);
604 Application->Uncondemn(
this);
611 delete ContextPopupMenu;
612 if (Attr.Menu.IsString())
613 delete[] Attr.Menu.GetString();
615 TRACEX(OwlWin, 1,
_T(
"TWindow destructed @") << (
void*)
this << *
this);
618#if defined(BI_MULTI_THREAD_RTL)
651 if (tooltip && tooltip->
IsWindow()) {
652 if (msg.hwnd == *
this ||
IsChild(msg.hwnd)) {
653 if (msg.message >= WM_MOUSEFIRST && msg.message <= WM_MOUSELAST) {
659 return HAccel ? ::TranslateAccelerator(
GetHandle(), HAccel, &msg) :
false;
673 bool wantMore =
false;
709 if (child && ChildList) {
710 TWindow* lastChild = ChildList;
711 TWindow* nextChild = lastChild;
713 while (nextChild->SiblingList != lastChild &&
714 nextChild->SiblingList != child) {
715 nextChild = nextChild->SiblingList;
718 if (nextChild->SiblingList == child) {
719 if (nextChild->SiblingList == nextChild)
723 if (nextChild->SiblingList == ChildList)
724 ChildList = nextChild;
726 nextChild->SiblingList = nextChild->SiblingList->SiblingList;
740 if (Parent != newParent) {
742 Parent->RemoveChild(
this);
744 SiblingList =
nullptr;
749 Parent->AddChild(
this);
780 return Parent ? Parent->SetDocTitle(docname, index) :
false;
801 return entry.
Id == info.
Id && (entry.Msg == UINT_MAX || entry.Msg == info.
Msg);
857 if (currentEvent.
Win !=
this) {
858 TWindow* receiver = Parent ? Parent : currentEvent.
Win;
862 if (receiver->
Find(eventInfo))
872 if (currentEvent.
Message != WM_COMMAND && currentEvent.
Message != WM_NOTIFY)
886 if (currentEvent.
Message == WM_COMMAND) {
889 hWndCtl =
reinterpret_cast<HWND
>(currentEvent.
Param2);
893 notifyCode = _not.code;
894 id =
static_cast<uint>(_not.idFrom);
895 if (_not.code ==
static_cast<uint>(TTN_NEEDTEXT) &&
896 (
reinterpret_cast<TTooltipText*
>(&_not))->uFlags&TTF_IDISHWND){
899 hWndCtl = _not.hwndFrom;
905 if (currentEvent.
Win ==
this) {
908 if (hWndCtl ==
nullptr) {
912 if (app->
Find(eventInfo)) {
916 WARNX(OwlMsg, notifyCode<=1, 0,
_T(
"Unprocessed WM_COMMAND(id=") <<
id <<
_T(
")"));
931 if (hWndCtl ==
nullptr) {
936 receiver = Parent ? Parent : currentEvent.
Win;
949 equal = wildcardCheck;
950 receiver = currentEvent.
Win;
981 if (receiver->
Find(eventInfo, equal)) {
982 TParam1 param1 = eventInfo.
Entry->NotifyCode ? notifyCode : id;
983 return receiver->
Dispatch(eventInfo, param1, currentEvent.
Param2);
1001 TRACEX(OwlCmd, 1,
_T(
"TWindow::EvCommand - id(") <<
id <<
_T(
"), ctl(") <<\
1002 hex <<
reinterpret_cast<void*
>(hWndCtl) <<
_T(
"), code(") << notifyCode <<
_T(
")"));
1009 if (hWndCtl ==
nullptr) {
1033 equal = wildcardCheck;
1062 if (receiver->
Find(eventInfo, equal))
1063 return receiver->
Dispatch(eventInfo,
1064 eventInfo.
Entry->NotifyCode ? notifyCode :
id);
1083 if (notifyInfo.code == TTN_NEEDTEXT)
1085 auto& ttText =
reinterpret_cast<TTooltipText&
>(notifyInfo);
1089 const auto handled = enabler.GetHandled();
1090 WARNX(OwlWin, !handled, 1,
_T(
"No command enabler found for TTN_NEEDTEXT (Id: ") << enabler.GetId() <<
_T(
")."));
1110 equal = wildcardCheck;
1119 TEventInfo eventInfo(notifyInfo.code, ctlId);
1123 if (receiver->
Find(eventInfo, equal))
1124 return receiver->
Dispatch(eventInfo, notifyInfo.code,
TParam2(¬ifyInfo));
1141 if (
Find(eventInfo))
1167 HWND hCmdTarget = hInitCmdTarget;
1168 while (hCmdTarget && hCmdTarget != *
this) {
1193 bool enable =
false;
1196 HWND hCmdTarget = hInitCmdTarget;
1200 if (cmdTarget && cmdTarget->
Find(eventInfo)) {
1204 if (!hCmdTarget || hCmdTarget == *
this)
1215 if (app->
Find(enableInfo)) {
1220 enable = app->
Find(eventInfo);
1223 commandEnabler.
Enable(enable);
1241 bool priorException = Application && Application->HasSuspendedException();
1242 TResult result = ::CallWindowProc(DefaultProc,
GetHandle(), message, param1, param2);
1243 if (!priorException)
1257static const int msgCacheSize = 31;
1259 typedef UINT_PTR TId;
1266 TCacheEntry() : UniqueId(0), Entry(nullptr), Msg(0), Delta(0) {}
1269 UniqueId = uniqueId;
1274 bool Hit(
TMsgId msg, TId uniqueId) {
return msg == Msg && uniqueId == UniqueId;}
1276 static int Key(TId
id,
TMsgId msg) {
return (
id ^
static_cast<TId
>(msg)) % msgCacheSize;}
1280struct TCacheEntryStr
1281#if defined(BI_MULTI_THREAD_RTL)
1282:
public TLocalObject
1285 TCacheEntryStr():Enabled(true)
1292 TCacheEntry Cache[msgCacheSize];
1297 bool Check(
int index,
TMsgId, TCacheEntry::TId
id);
1299#if defined(BI_MULTI_THREAD_RTL)
1304TCacheEntry::TId TWindow::LastUniqueId = 0;
1306static TCacheEntryStr& GetCache()
1308#if defined(BI_MULTI_THREAD_RTL)
1309 static TTlsContainer<TCacheEntryStr> cacheEntry;
1310 return cacheEntry.Get();
1312 static TCacheEntryStr cacheEntry;
1322 TCacheEntryStr& InitCacheEntryStr = GetCache();
1325#if defined(BI_MULTI_THREAD_RTL)
1334 for (
int i = 0; i < msgCacheSize; i++)
1335 if (Cache[i].UniqueId ==
id)
1342 Cache[index].Set(uniqueId, msg, entry, delta);
1348 return Enabled && Cache[index].Hit(msg,
id);
1355void CacheFlush(UINT_PTR
id)
1357 GetCache().CacheFlush(
id);
1371TWindow::SetUniqueId()
1373#if defined(OWL_RTTI_MSGCACHE)
1376 if (++LastUniqueId == 0) {
1381 GetCache().Enabled =
false;
1383 UniqueId = LastUniqueId;
1396 TResult r = ReceiveMessage(Handle, msg, p1, p2);
1417 TRACEX(OwlMsg, 1,
_T(
"WM_COMMAND_ENABLE") <<
_T(
"! => ") << *
this);
1424 else if (msg == WM_COMMAND) {
1431 else if (msg == WM_NOTIFY) {
1438 dumbNMHDR.idFrom =
static_cast<UINT
>(-1);
1439 TNotify* notify = param2 ?
reinterpret_cast<TNotify*
>(param2) : &dumbNMHDR;
1441 TRACEX(OwlMsg, 1,
_T(
"WM_NOTIFY, ") << notify->idFrom <<
_T(
", ")\
1442 << notify->code <<
_T(
", ")\
1443 << hex <<
reinterpret_cast<void*
>(notify->hwndFrom) <<
_T(
", ")\
1444 <<
_T(
" ! => ") << *
this);
1452#if defined(OWL_RTTI_MSGCACHE)
1456 int key = TCacheEntry::Key(UniqueId, msg);
1461 TCacheEntryStr& cache = GetCache();
1462 if(cache.Check(key, msg, UniqueId)) {
1463 eventInfo.
Entry = cache.Cache[key].Entry;
1464 if (eventInfo.
Entry) {
1465 TRACEX(OwlMsg, 1, TMsgName(msg) <<
_T(
"* => ") << *
this);
1466 eventInfo.
Object =
reinterpret_cast<TGeneric*
>(((
reinterpret_cast<char*
>(
this)) + cache.Cache[key].Delta));
1467 return Dispatch(eventInfo, param1, param2);
1473 else if (this->
Find(eventInfo)) {
1474 TRACEX(OwlMsg, 1, TMsgName(msg) <<
_T(
" => ") << *
this);
1475 const int delta =
static_cast<int>(
reinterpret_cast<INT_PTR
>(eventInfo.
Object) -
reinterpret_cast<INT_PTR
>(
this));
1476 cache.Set(key,UniqueId, msg, eventInfo.
Entry, delta);
1477 return Dispatch(eventInfo, param1, param2);
1480 cache.Set(key,UniqueId, msg,
nullptr);
1498#if !defined(BI_COMP_GNUC)
1513 WARNX(OwlWin, hwnd != Handle, 0,
"ReceiveMessage: The passed handle does not match this window.");
1518 if (msg == GetWindowPtrMsgId && (!param2 || param2 ==
TParam2(Application)))
1525 currentEvent.
Win =
this;
1527 currentEvent.
Param1 = param1;
1528 currentEvent.
Param2 = param2;
1535 result = WindowProc(msg, param1, param2);
1539 TRACEX(OwlWin, 0,
_T(
"TWindow::ReceiveMessage: Suspending unhandled exception for message: ") << msg);
1541 GetApplication()->SuspendThrow(std::current_exception());
1543 currentEvent = saveEvent;
1547#if !defined(BI_COMP_GNUC)
1570 ::GetWindowThreadProcessId(hWnd, &processId);
1571 if (processId != ::GetCurrentProcessId())
1574 WNDPROC wndProc =
reinterpret_cast<WNDPROC
>(::GetWindowLongPtr(hWnd, GWLP_WNDPROC));
1577 return reinterpret_cast<TWindow*
>(::CallWindowProc(wndProc, hWnd, GetWindowPtrMsgId, 0, param2));
1618 holdWin = holdWin->Parent;
1635 static bool inScroller =
false;
1636 if (!inScroller && Scroller && sizeType != SIZE_MINIMIZED) {
1638 Scroller->SetPageSize();
1639 Scroller->SetSBarRange();
1643 if (sizeType == SIZE_RESTORED) {
1647 Attr.W = wndRect.
Width();
1648 Attr.H = wndRect.
Height();
1654 if (Parent && !(
GetExStyle() & WS_EX_NOPARENTNOTIFY))
1673 if ((
GetWindowLong(GWL_STYLE) & WS_CHILD) == WS_CHILD && Parent &&
1674 Parent->GetHandle())
1675 Parent->ScreenToClient(wndRect.
TopLeft());
1677 Attr.X = wndRect.left;
1678 Attr.
Y = wndRect.top;
1693 return static_cast<int>(r);
1704 if (deleteInfo.hwndItem !=
GetHandle() && win)
1717 if (drawInfo.CtlType == ODT_MENU) {
1720 DRAWITEMSTRUCT i(drawInfo);
1727 if (drawInfo.hwndItem !=
GetHandle() && win) {
1742 if (measureInfo.CtlType == ODT_MENU) {
1760 if (creationWindow) {
1761 if (creationWindow !=
this)
1762 win = creationWindow;
1781 if (win->
Find(eventInfo)){
1806 currentEvent.
Message = WM_COMMAND;
1823 if (Scroller && !(modKeys & (MK_SHIFT | MK_CONTROL)))
1825 const auto n = GetWheelScrollLines_();
1826 const auto dx = (n == WHEEL_PAGESCROLL) ?
1827 ((zDelta > 0) ? -Scroller->XPage : Scroller->XPage) :
1828 ::MulDiv(-zDelta, n, WHEEL_DELTA) * Scroller->XLine;
1829 Scroller->ScrollBy(dx, 0);
1842 if (Scroller && !(modKeys & (MK_SHIFT | MK_CONTROL)))
1844 const auto n = GetWheelScrollLines_();
1845 const auto dy = (n == WHEEL_PAGESCROLL) ?
1846 ((zDelta > 0) ? -Scroller->YPage : Scroller->YPage) :
1847 ::MulDiv(-zDelta, n, WHEEL_DELTA) * Scroller->YLine;
1848 Scroller->ScrollBy(0, dy);
1873 Scroller->HScroll(scrollCode, thumbPos);
1898 Scroller->VScroll(scrollCode, thumbPos);
1998 const auto owlChild = (ctlType != CTLCOLOR_DLG) ?
GetWindowPtr(ctl) :
nullptr;
1999 const auto shouldIgnoreControl = ctlType == CTLCOLOR_EDIT || ctlType == CTLCOLOR_LISTBOX;
2003 const auto bkgndColor = (owlChild && owlChild->GetBkgndColor() !=
TColor::None) ? owlChild->GetBkgndColor() :
2019 return defaultErasureBrush;
2023 ::SetBkMode(hDC, TRANSPARENT);
2024 return reinterpret_cast<HBRUSH
>(::GetStockObject(NULL_BRUSH));
2028 ::SetBkColor(hDC, bkgndColor);
2029 return TBrush{bkgndColor};
2051 Scroller->BeginView(dc, rect);
2053 Paint(dc, dc.
Ps.fErase, rect);
2056 Scroller->EndView();
2083 if (hWndCursor ==
GetHandle() && codeHitTest == HTCLIENT && HCursor) {
2103 if (Scroller && Scroller->IsAutoMode()) {
2106 loopMsg.message = 0;
2109 while (loopMsg.message != WM_LBUTTONUP && Scroller->IsAutoMode() &&
2110 (loopMsg.message != WM_MOUSEMOVE || (loopMsg.wParam&MK_LBUTTON))) {
2111 if (::PeekMessage(&loopMsg,
nullptr, 0, 0, PM_REMOVE)) {
2112 ::TranslateMessage(&loopMsg);
2113 ::DispatchMessage(&loopMsg);
2128 Scroller->AutoScroll();
2167 w.EnableAutoCreate();
2173 if (Parent && Parent->GetHandle())
2249 wndClass.cbClsExtra = 0;
2250 wndClass.cbWndExtra = 0;
2252 wndClass.hIcon =
nullptr;
2255 if (BkgndColor.IsSysColor() &&
2257 wndClass.hbrBackground =
reinterpret_cast<HBRUSH
>(
static_cast<INT_PTR
>(BkgndColor.Index() + 1));
2259 wndClass.hbrBackground =
reinterpret_cast<HBRUSH
>(COLOR_WINDOW + 1);
2261 wndClass.lpszMenuName =
nullptr;
2263 wndClass.style = CS_DBLCLKS;
2274 static const tchar baseClassName[] =
_T(
"OWL_Window");
2276 if (BkgndColor.IsSysColor() &&
2278 static tchar namebuff[
COUNTOF(baseClassName) + 1 + 10 + 1 + 4];
2279 _stprintf(namebuff,
_T(
"%s:%X"), baseClassName, BkgndColor.Index());
2293 Attr.AccelTable = resId;
2309 if (Attr.AccelTable) {
2311 WARNX(OwlWin, !HAccel, 0,
2312 _T(
"Unable to load accelerators ") << Attr.AccelTable
2322TWindow::MakeMenuOrId()
2326 HMENU m = Attr.
Menu ?
LoadMenu(Attr.
Menu) : reinterpret_cast<HMENU>(static_cast<INT_PTR>(Attr.Id));
2356 TMenuGuard(HMENU m_,
bool is_mine_) : m(m_), is_mine(is_mine_) {}
2357 ~TMenuGuard() {
if (is_mine) DestroyMenu(m);}
2358 operator HMENU() {
return m;}
2359 HMENU RelinquishOwnership() {is_mine =
false;
return m;}
2361 menuOrId(MakeMenuOrId(), Attr.Menu != 0);
2367 Attr.X, Attr.Y, Attr.W, Attr.H,
2368 Parent ? Parent->GetHandle() :
nullptr,
2373 if (h) menuOrId.RelinquishOwnership();
2412 SetHandle(Parent ? Parent->GetDlgItem(Attr.Id) :
nullptr);
2536#if !defined(OWL5_COMPAT)
2577 TRACEX(OwlWin, 1,
_T(
"TWindow::SetupWindow() @") << (
void*)
this << *
this);
2582 Scroller->SetWindow(
this);
2583 Scroller->SetSBarRange();
2613#if defined(OWL5_COMPAT)
2642 TRACEX(OwlWin, 1,
_T(
"TWindow::CleanupWindow() @") << (
void*)
this << *
this);
2657 if (!buffer && direction !=
tdSizeData)
return 0;
2674 p =
static_cast<char*
>(p) + w.Transfer(p, direction);
2676 return static_cast<uint>(
reinterpret_cast<char*
>(p) -
reinterpret_cast<char*
>(buffer));
2693 if (!TransferBuffer)
return;
2696 if (TransferBufferSize > 0 && size != TransferBufferSize)
2698 WARN(TransferBufferSize == 0,
2699 _T(
"TWindow::TransferData: Unsafe transfer is performed! ")
2700 _T(
"Use one of the safe overloads of SetTransferBuffer to enable buffer checks."));
2701 Transfer(TransferBuffer, direction);
2708inline static bool BelongsToCurrentProcess (HWND h)
2710 DWORD processId = 0;
2711 ::GetWindowThreadProcessId(h, &processId);
2712 return processId == ::GetCurrentProcessId();
2725 if (!BelongsToCurrentProcess(
GetHandle()))
return;
2753 if (m.IsRegisteredClass(c))
return true;
2754 auto w = WNDCLASS{};
2756 CHECK(c.GetPointerRepresentation() == w.lpszClassName);
2757 return m.IsRegisteredClass(c) ? true : ::RegisterClass(&w);
2798 return all_of(c.begin(), c.end(), [](
TWindow& w) { return !w.GetHandle() || w.CanClose(); });
2857 ::PostQuitMessage(0);
2933 InstanceProc =
nullptr;
2956 return IndexOf(ChildList) + 1;
2963TWindow::AssignZOrder()
2974 for (curWindow =
::GetWindow(curWindow, GW_HWNDLAST);
2981 wnd->ZOrder =
static_cast<uint16>(i++);
3002 if (child.GetHandle())
3006 WARNX(OwlWin, !autoCreate, 0,
_T(
"Child window(Id=") << child.GetId() <<
_T(
") not autocreated"));
3013 if (!child.Create())
3014 throw TXWindow{&child, IDS_WINDOWCREATEFAIL};
3019 if (child.IsIconic())
3020 child.SetWindowText(child.GetWindowText());
3025 HWND above = HWND_TOP;
3029 const auto i = find_if(c.begin(), c.end(), [&top](
TWindow& w) { return w.ZOrder == top; });
3045TWindow::AddChild(
TWindow* child)
3050 child->SiblingList = ChildList->SiblingList;
3051 ChildList->SiblingList = child;
3057 child->SiblingList = child;
3077 while (CurrentIndex->
Next() !=
this)
3078 CurrentIndex = CurrentIndex->
Next();
3080 return CurrentIndex;
3084#if defined(OWL5_COMPAT)
3113TWindow::FirstThat(TCondFunc test,
void* paramList)
const
3120 curChild = nextChild;
3121 nextChild = nextChild->
Next();
3126 if (test(curChild, paramList))
3128 }
while (curChild != ChildList && ChildList);
3153TWindow::ForEach(TActionFunc
action,
void* paramList)
3160 curChild = nextChild;
3161 nextChild = nextChild->Next();
3162 action(curChild, paramList);
3163 }
while (curChild != ChildList && ChildList);
3183TWindow::FirstThat(TCondMemFunc test,
void* paramList)
3186 TWindow* nextChild = ChildList->Next();
3190 CHECKX(nextChild,
_T(
"The child list was corrupted/modified while traversing it"));
3191 curChild = nextChild;
3192 nextChild = nextChild->Next();
3194 if ((this->*test)(curChild, paramList))
3196 }
while (curChild != ChildList && ChildList);
3211TWindow::ForEach(TActionMemFunc
action,
void* paramList)
3214 TWindow* nextChild = ChildList->Next();
3218 CHECKX(nextChild,
_T(
"The child list was corrupted/modified while traversing it"));
3219 curChild = nextChild;
3220 nextChild = nextChild->Next();
3221 (this->*
action)(curChild, paramList);
3222 }
while (curChild != ChildList && ChildList);
3234int TWindow::IndexOf(
const TWindow* child)
const
3258TWindow* TWindow::At(
int position)
3260 if (position < 0)
return nullptr;
3278 const auto i = find_if(c.begin(), c.end(), [
id](
TWindow& w) { return w.GetId() == id; });
3279 return (i != c.end()) ? &(*i) :
nullptr;
3316 return ::PostMessage(handle, currentEvent.
Message,
3342 for (HWND hWndChild =
GetWindow(GW_CHILD); hWndChild; ) {
3343 HWND hWndNext =
::GetWindow(hWndChild, GW_HWNDNEXT);
3346 hWndChild = hWndNext;
3359 TRACKMOUSEEVENT a = {
sizeof(TRACKMOUSEEVENT), flags,
GetHandle(),
static_cast<DWORD
>(hoverTime)};
3360 return ::TrackMouseEvent(&a) != FALSE;
3382 TRACKMOUSEEVENT a = {
sizeof(TRACKMOUSEEVENT), TME_QUERY,
GetHandle()};
3412 if (Title != title) {
3415 Title = title ?
strnewdup(title) :
nullptr;
3446 if (titleLength < 0) {
3450 Title =
new tchar[titleLength + 1];
3452 Title[titleLength] = 0;
3484 Attr.H = wndRect.
Height();
3485 Attr.W = wndRect.
Width();
3488 if ((Attr.Style & WS_CHILD) && hParent)
3491 Attr.X = wndRect.left;
3492 Attr.
Y = wndRect.top;
3507 BOOL tempTranslated;
3510 *translated = tempTranslated;
3519template <
int GwlStyle, u
int32 TWindowAttr::*StyleMem>
3522 return w->GetHandle() ? w->GetWindowLong(GwlStyle) : (w->Attr.*StyleMem);
3525template <
int GwlStyle, u
int32 TWindowAttr::*StyleMem>
3528 const auto setStyleMem = [](TWindow* w,
uint32 style)
3530 const auto oldstyle = w->Attr.*StyleMem;
3531 w->Attr.*StyleMem = style;
3534 return w->GetHandle() ? w->SetWindowLong(GwlStyle, style) : setStyleMem(w, style);
3537template <u
int32 (TWindow::*GetStyleMemFun)() const, u
int32 (TWindow::*SetStyleMemFun)(u
int32)>
3540 const auto style = (w->*GetStyleMemFun)();
3541 const auto newStyle = (style & ~offBits) | onBits;
3542 const auto isDifferent = style != newStyle;
3545 (w->*SetStyleMemFun)(newStyle);
3547 w->SetWindowPos(
nullptr, {}, swpFlags | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER);
3560 return GetStyle_<GWL_STYLE, &TWindowAttr::Style>(
this);
3569 return SetStyle_<GWL_STYLE, &TWindowAttr::Style>(
this, style);
3577 return GetStyle_<GWL_EXSTYLE, &TWindowAttr::ExStyle>(
this);
3585 return SetStyle_<GWL_EXSTYLE, &TWindowAttr::ExStyle>(
this, style);
3593 return ModifyStyle_<&TWindow::GetStyle, &TWindow::SetStyle>(
this, offBits, onBits, swpFlags);
3601 return ModifyStyle_<&TWindow::GetExStyle, &TWindow::SetExStyle>(
this, offBits, onBits, swpFlags);
3614 rect.
SetWH(Attr.X, Attr.Y, Attr.W, Attr.H);
3629 rect.
Set(0, 0, Attr.W, Attr.H);
3666 int x,
int y,
int w,
int h,
3670 return ::SetWindowPos(
GetHandle(), hWndInsertAfter, x, y, w, h, flags);
3672 if (!(flags & SWP_NOMOVE)) {
3676 if (!(flags & SWP_NOSIZE)) {
3683 if (flags & SWP_SHOWWINDOW)
3684 Attr.Style |= WS_VISIBLE;
3685 else if (flags & SWP_HIDEWINDOW)
3686 Attr.Style &= ~WS_VISIBLE;
3722 if (cmdShow == SW_MINIMIZE)
3726 return ::ShowWindow(
GetHandle(), cmdShow);
3731 Attr.Style &= ~WS_VISIBLE;
3735 Attr.Style |= WS_VISIBLE;
3736 Attr.Style &= ~(WS_MINIMIZE | WS_MAXIMIZE);
3738 case SW_SHOWMINIMIZED:
3740 case SW_SHOWMINNOACTIVE:
3741 Attr.Style |= WS_VISIBLE;
3742 Attr.Style |= WS_MINIMIZE;
3744 case SW_SHOWMAXIMIZED:
3745 Attr.Style |= WS_VISIBLE;
3746 Attr.Style |= WS_MAXIMIZE;
3748 case SW_SHOWNOACTIVATE:
3751 Attr.Style |= WS_VISIBLE;
3768 if (module == CursorModule && resId == CursorResId)
3771 HCURSOR hOldCursor = (HCursor && CursorModule) ? HCursor :
nullptr;
3773 CursorModule =
module;
3774 CursorResId = resId;
3777 HCursor = CursorModule->LoadCursor(CursorResId);
3779 HCursor =
::LoadCursor(
nullptr, CursorResId.GetPointerRepresentation());
3791 auto getClassCursor = [&] {
return reinterpret_cast<HCURSOR
>(::GetClassLongPtr(
GetHandle(), GCLP_HCURSOR)); };
3792 ::SetCursor(HCursor ? HCursor : getClassCursor());
3799 ::DestroyCursor(hOldCursor);
3814 else if (!isSysMenu && hPopupMenu) {
3815 const int count = ::GetMenuItemCount(hPopupMenu);
3817 for (
int pos = 0; pos < count; pos++) {
3821 id = ::GetMenuItemID(hPopupMenu, pos);
3829 TMenu popupMenu(hPopupMenu);
3861 WARN(!font.
IsHandleOwner(),
_T(
"The given font has (a font handle with) unmanaged lifetime."));
3867 Font = make_unique<TFont>(font);
3881 delete ContextPopupMenu;
3882 ContextPopupMenu = popupMenu;
3901 bool invalidPos = (x < 0 && y < 0);
3930 if (source == MSGF_DIALOGBOX) {
3953 auto wp = WINDOWPLACEMENT{
sizeof(WINDOWPLACEMENT)};
3955 if (!r)
throw TXOwl{
_T(
"TWindow::GetWindowPlacement failed")};
3971 wp.length =
sizeof(WINDOWPLACEMENT);
3973 if (!r)
throw TXOwl{
_T(
"TWindow::SetWindowPlacement failed")};
3976#if defined(OWL5_COMPAT)
3991 catch (
const TXOwl&)
4010 catch (
const TXOwl&)
4027 return ::SetWindowRgn(
GetHandle(), r.Release(), repaint) != 0;
4041 return ::GetScrollInfo(
GetHandle(), bar, scrollInfo);
4055 SCROLLINFO i = {
sizeof(SCROLLINFO), mask};
4057 WARNX(OwlWin, !r, 0,
_T(
"GetScrollInfo failed."));
InUse(r);
4070 return ::SetScrollInfo(
GetHandle(), bar, scrollInfo, redraw);
4094 SCROLLINFO i = {
sizeof(SCROLLINFO), SIF_POS, 0, 0, 0, pos};
4144 SCROLLINFO i = {
sizeof(SCROLLINFO), SIF_RANGE, minPos, maxPos};
4172 SCROLLINFO i = {
sizeof(SCROLLINFO), SIF_PAGE, 0, 0,
static_cast<UINT
>(page)};
4203 if (Tooltip->GetHandle())
4204 Tooltip->Activate(enable);
4217 if (Tooltip->GetHandle())
4218 Tooltip->SendMessage(WM_CLOSE);
4227 if (!Tooltip->GetHandle()) {
4230 Tooltip->Attr.Style |= WS_DISABLED;
4254 return ::GetUpdateRgn(
GetHandle(), region, erase);
4298 return MessageBox(text.c_str(), caption, flags);
4309 return MessageBox(text.c_str(), caption.c_str(), flags);
4319 auto p = MSGBOXPARAMS
4321 sizeof(MSGBOXPARAMS),
4332 return ::MessageBoxIndirect(&p);
4352 flags | MB_USERICON,
4363 va_start(argp, flags);
4368 auto buffer = array<tchar, 1024>{};
4369 const auto r = _vsntprintf(buffer.data(), buffer.size(), fmt.c_str(), argp);
4372 buffer.back() =
_T(
'\0');
4373 WARNX(OwlWin, r == -1, 0,
_T(
"TWindow::FormatMessageBox: Message was truncated."));
4375 return buffer.data();
4377 const auto s = format(formatString, argp);
4378 const auto r =
MessageBox(s, caption, flags);
4384 WARNX(OwlWin,
true, 0,
_T(
"TWindow::FormatMessageBox failed."));
4401struct TWindowGetWindowText
4404 TWindowGetWindowText(
const TWindow& w) : win(w) {}
4406 int operator()(LPTSTR buf,
int buf_size)
4422struct TWindowGetDlgItemText
4426 TWindowGetDlgItemText(
const TWindow& w,
int id_) : win(w), id(id_) {}
4428 int operator()(LPTSTR buf,
int buf_size)
4444#if defined(__TRACE) || defined(__WARN)
4450 os << static_cast<void*>(w.
GetHandle()) <<
',';
4454 os <<
"id=" << w.
GetId();
4469 if(IsBadReadPtr((
void*)data,
sizeof(
TDrawItem)))
4482 if(IsBadReadPtr(*(
void**)data,
sizeof(
void*)))
4488 item = localTryCatchBlock(data);
4518GetSuspectDescription(
TWindow* w)
4521 if (!w)
return _T(
"");
4523 tstring caption = w->GetCaption() ? w->GetCaption() :
_T(
"");
4524 tstring id = ToString(w->GetWindowAttr().Id);
4528 s +=
_T(
"\"") + caption +
_T(
"\"");
4529 s +=
_T(
", ID: ") + id;
4530 s +=
_T(
", window ") + type;
4548 if (m.SysError() != ERROR_SUCCESS)
4549 s +=
_T(
"\n\nSystem error: ") + m.SysMessage();
4558 TXOwl(MakeTXWindowMessage(win, resId), resId),
Definition of class TAppDictionary.
Definition of class TApplication.
#define WARNX(group, condition, level, message)
#define WARN(condition, message)
#define PRECONDITION(condition)
#define CHECKX(condition, message)
#define TRACEX(group, level, message)
Derived from TModule and TMsgThread and virtually derived from TEventHandler, TApplication acts as an...
void ResumeThrow()
Rethrows the suspended exception stored by a previous call to SuspendThrow.
int BeginModal(TWindow *window, int flags=MB_APPLMODAL)
Called to begin a modal window's modal message loop.
auto Find(TEventInfo &, TEqualOperator=nullptr) -> bool override
Overrides TEventHandler::Find.
void Condemn(TWindow *win)
Condemns the given window to be deleted the at the next available safe time.
virtual bool CanClose()
Determine whether the application can be closed.
TFrameWindow * GetMainWindow()
Return the current main window.
virtual TTooltip * GetTooltip() const
Get Tooltip.
void EndModal(int result)
Cause the current modal message loop to break and have it return a result Re-enable the disabled wind...
The GDI Brush class is derived from TGdiObject.
static const TColor Transparent
a non-painting color
static const TColor None
not-a-color
Base class for an extensible interface for auto enabling/disabling of commands (menu items,...
uint GetId() const
Retrieves the id of the command.
virtual void Enable(bool enable=true)
Enables or disables the command sender.
uint Flags
TCommandStatus flags Is TCommandStatus::WasHandled if the command enabler has been handled.
bool GetHandled()
Return true if the command enabler has been handled.
bool IsReceiver(HWND hReceiver)
Returns true if receiver is the same as the message responder originally set up in the constructor.
TCommandEnabler(uint id, HWND hWndReceiver=0)
Constructs the TCommandEnabler object with the specified command ID.
bool SendsCommand() const
Returns true if this command enabler sends a command message.
@ WasHandled
Command was enabled or disabled.
TDC is the root class for GDI DC wrappers.
TDC()
for derived classes only
virtual void Measure(MEASUREITEMSTRUCT &)
virtual void Draw(DRAWITEMSTRUCT &)
A nested class, TEventInfo provides specific information about the type of message sent,...
const TMsgId Msg
Contains the type of message sent.
TGeneric * Object
Points to the object that contains the function to be handled.
const uint Id
Contains the menu or accelerator resource ID (CM_xxxx) for the message response member function.
const TGenericTableEntry * Entry
Points to the response table entry (for example, EvActivate).
virtual bool Find(TEventInfo &info, TEqualOperator op=0)
Searches the list of response table entries looking for a match.
bool(*) TEqualOperator(const TGenericTableEntry &, const TEventInfo &)
TResult Dispatch(TEventInfo &info, TParam1, TParam2=0)
Takes the message data from TEventInfo's Msg data member and dispatches it to the correct event-handl...
TFont derived from TGdiObject provides constructors for creating font objects from explicit informati...
HFONT GetHandle() const
Returns the handle of the font with type HFONT.
auto IsHandleOwner() const -> bool
Returns true if handle lifetime is managed.
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
TNotify is a thin wrapper around the NMHDR structure.
A DC class that wraps begin and end paint calls for use in an WM_PAINT response function.
PAINTSTRUCT Ps
The paint structure associated with this TPaintDC object.
TPoint is a support class, derived from tagPOINT.
TPoint()
Constructs an uninitialized point.
TRect is a mathematical class derived from tagRect.
int Height() const
Returns the height of this rectangle (bottom - top).
void Set(int _left, int _top, int _right, int _bottom)
Repositions and resizes this rectangle to the given values.
void SetWH(int _left, int _top, int w, int h)
Determines the rectangle, given its upperleft point, width, and height.
const TPoint & TopLeft() const
Returns the upperleft point.
int Width() const
Returns the width of this rectangle (right - left).
int Y() const
Returns the top value.
TRegion, derived from TGdiObject, represents GDI abstract shapes or regions.
uint Id
Contains the menu or accelerator resource ID (CM_xxxx) for the message response member function.
static void DragAcceptFiles(HWND, BOOL)
Invokes 'DragAcceptFiles' indirectly.
The tagSIZE struct is defined as.
TTooltipText identifies a tool for which text is to be displayed.
Type-safe encapsulation of a Windows class name, a union between ATOM and LPCTSTR.
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
HWND GetParentH() const
Return the handle of the parent.
static void GetCursorPos(TPoint &pos)
Retrieves the cursor's current position (in window screen coordinates) and copies the values into the...
bool EvEraseBkgnd(HDC)
Handler for WM_ERASEBKGND.
static LRESULT CALLBACK InitWndProc(HWND, UINT msg, WPARAM, LPARAM)
Callback process for hooking TWindow to native window.
bool SetCursor(TModule *module, TResId resId)
Sets the mouse cursor for the window, loading the given resId from the given module.
HMENU LoadMenu(TResId id) const
HWND SetCapture()
Sets the mouse capture to the current window.
int GetScrollTrackPos(int bar) const
Returns the thumb track position in the scroll bar.
virtual THandle PerformCreate()
Called from Create to perform the final step in creating an Windows interface element to be associate...
tstring LoadString(uint id) const
void EvMove(const TPoint &clientOrigin)
Save the normal position of the window.
TCurrentEvent & GetCurrentEvent()
Returns the current event to be processed in the message queue.
void EvEnterIdle(uint source, HWND hWndDlg)
The default message handler for WM_ENTERIDLE.
virtual void SetParent(TWindow *newParent)
Sets the parent for the specified window by setting Parent to the specified new Parent window object.
TApplication * GetApplication() const
Gets a pointer to the TApplication object associated with this.
void ChildBroadcastMessage(TMsgId, TParam1=0, TParam2=0)
Sends the specified message to all immediate children using SendMessage.
HACCEL LoadAccelerators(TResId id) const
void AttachHandle(HWND handle)
int EvCompareItem(uint ctrlId, const COMPAREITEMSTRUCT &compareInfo)
Handles WM_COMPAREITEM message (for owner draw controls) by forwarding message to control itself.
virtual ~TWindow() override
Destroys this window (unless this is an alias) and the children.
TWindow()
Protected constructor for use by immediate virtually derived classes.
virtual void EnableTooltip(bool enable=true)
tstring GetWindowText() const
String-aware overload.
void EvPaint()
Response method for an incoming WM_PAINT message.
int MessageBox(LPCTSTR text, LPCTSTR caption=0, uint flags=MB_OK) const
Displays a message in a modal pop-up dialog box.
void TraceWindowPlacement()
void DispatchScroll(uint scrollCode, uint thumbPos, HWND hWndCtrl)
Called by EvHScroll and EvVScroll to dispatch messages from scroll bars.
void GetHWndState(bool forceStyleSync=false)
Copies the style, coordinate, and the resource id (but not the title) from the existing HWnd into the...
void EvClose()
The default response to a WM_CLOSE message is to call CloseWindow() and then have the window deleted ...
TWindow(TWindow *parent, LPCTSTR title=nullptr, TModule *module=nullptr)
Adds this to the child list of parent if nonzero, and calls EnableAutoCreate so that this will be cre...
void EvContextMenu(HWND childHwnd, int x, int y)
The default message handler for WM_CONTEXTMENU.
virtual void GetWindowClass(WNDCLASS &wndClass)
Redefined by derived classes, GetWindowClass fills the supplied MS-Windows registration class structu...
bool SetWindowPos(HWND hWndInsertAfter, const TRect &rect, uint flags)
Changes the size of the window pointed to by rect.
virtual void EvCommandEnable(TCommandEnabler &ce)
Called by WindowProc to handle WM_COMMAND_ENABLE messages, EvCommandEnable calls the CmXxxx command-h...
virtual int Execute()
Creates the underlying HWND and makes it modal with the help of TApplication's BeginModal support.
virtual bool PreProcessMsg(MSG &msg)
Called from TApplication::ProcessAppMsg() to give the window an opportunity to perform preprocessing ...
HWND GetWindow(uint cmd) const
Returns the handle of the window that has the indicated relationship to this window.
auto GetChildren()
Returns a TWindow::TChildrenRange that can be iterated by standard means.
void AssignContextMenu(TPopupMenu *menu)
Associates a pop-up menu with the window so that it can automatically handle a WM_CONTEXTMENU message...
TWindow * Previous()
Returns a pointer to the TWindow's previous sibling (the window previous to the TWindow in its parent...
HWND GetDlgItem(int childId) const
Retrieves the handle of a control specified by childId.
void EvMouseWheel(uint modKeys, int zDelta, const TPoint &point)
Event handler for WM_MOUSEWHEEL.
virtual void Destroy(int retVal=0)
Destroys an MS-Windows element associated with the TWindow.
void EvDestroy()
Responds to an incoming WM_DESTROY message.
virtual bool Create()
Creates the window interface element to be associated with this ObjectWindows interface element.
void SetAcceleratorTable(TResId resId)
void EvDeleteItem(uint ctrlId, const DELETEITEMSTRUCT &deleteInfo)
Handles WM_DELETEITEM message (for owner draw controls) by forwarding message to control itself.
int GetId() const
Returns Attr.Id, the ID used to find the window in a specified parent's child list.
TWindow * GetParent() const
Retrieves the OWL object of the parent window. If none exists, returns 0.
auto MessageBoxIndirect(HINSTANCE resourceModule, TResId text, TResId caption, uint flags, TResId icon, DWORD_PTR contextHelpId, MSGBOXCALLBACK, DWORD languageId) const -> int
Displays a standard message box.
TWindow * GetWindowPtr(HWND hWnd) const
Calls TApplication:GetWindowPtr on the application associated with this window.
virtual int DoExecute()
Do actual modal execution using the Begin/End Modal support of TApplication.
virtual void RemoveChild(TWindow *child)
Removes a child window.
void SetWindowFont(HFONT font, bool redraw=true)
Sets the font that a control uses to draw text.
void SetTooltip(TTooltip *tooltip)
TRACKMOUSEEVENT QueryMouseEventTracking() const
Returns the current state of mouse event tracking initiated by TrackMouseEvent.
void GetWindowTextTitle()
Updates the TWindow internal caption (Title) from the current window's caption.
void GetScrollRange(int bar, int &minPos, int &maxPos) const
Returns the minimum and maximum positions in the scroll bar.
auto FormatMessageBox(const tstring &formatStr, const tstring &caption, uint flags,...) const -> int
TRect GetWindowRect() const
Gets the screen coordinates of the window's rectangle.
virtual TTooltip * GetTooltip() const
void EvHScroll(uint scrollCode, uint thumbPos, HWND hWndCtl)
Response method for an incoming WM_HSCROLL message.
void DisableAutoCreate()
Disables the feature that allows an associated child window interface element to be created and displ...
void PerformSetupAndTransfer()
Ensures that the window is fully set up; then transfers data into the window.
void SetHandle(THandle)
Sets the window handle in a derived class.
void SetWindowPlacement(const WINDOWPLACEMENT &place)
Wrapper for Windows API.
virtual TResult WindowProc(TMsgId, TParam1, TParam2)
First virtual function called to handling incoming messages to a TWindow.
static void ShutDownWindow(TWindow *win, int retVal=0)
This version of ShutDownWindow unconditionally shuts down a given window, calls Destroy on the interf...
void EvVScroll(uint scrollCode, uint thumbPos, HWND hWndCtl)
Response method for an incoming WM_VSCROLL message.
virtual auto GetWindowClassName() -> TWindowClassName
virtual TResult DefWindowProc(TMsgId, TParam1, TParam2)
Virtual function provides final default processing for an incoming message Calls original window proc...
long GetWindowLong(int index) const
Retrieves information about the window depending on the value stored in index.
virtual uint Transfer(void *buffer, TTransferDirection direction)
Transfers data to or from any window with or without children and returns the total size of the data ...
void Init(TWindow *parent, LPCTSTR title, TModule *module)
Normal initialization of a default constructed TWindow.
void SetFlag(uint mask)
Sets the specified TWindow wfXxxx constant flags (for example wfAlias, wfTransfer,...
bool EvCreate(CREATESTRUCT &)
Response method for an incoming WM_CREATE message.
auto SetWindowRgn(HRGN, bool repaint=false) -> bool
Sets the area within the window where the system permits drawing.
void SetTextColor(TColor color, bool shouldUpdate=true)
Sets the text color for the window.
TWindow * GetParentO() const
Return the OWL's parent for this window.
WINDOWPLACEMENT GetWindowPlacement() const
Wrapper for Windows API.
static void ReleaseCapture()
Releases the mouse capture from this window.
TModule * GetModule() const
Returns a pointer to the module object.
uint32 SetExStyle(uint32 style)
Sets the extra style bits of the window.
void LoadAcceleratorTable()
Loads a handle to the window's accelerator table specified in the TWindowAttr structure (Attr....
WNDPROC GetWindowProc() const
void RouteCommandEnable(HWND hInitCmdTarget, TCommandEnabler &ce)
Walks the chain of windows from the initial target window to this window.
bool IsIconic() const
Returns true if window is iconic or minimized.
bool IsWindow() const
Returns true if an HWND is being used.
TPopupMenu * GetContextMenu() const
Returns the associated popup menu used by the window.
void ClientToScreen(TPoint &point) const
Converts the client coordinates specified in point to screen coordinates for the new window.
virtual bool SetDocTitle(LPCTSTR docname, int index)
Default behavior for updating document title is to pass it to parent frame.
void EvKillFocus(HWND hWndGetFocus)
Handle WM_KILLFOCUS so that we can have a parent window hold onto our Handle and possibly restore foc...
void SetCaption(LPCTSTR title)
Copies title to an allocated string pointed to by title.
int SetScrollInfo(int bar, SCROLLINFO *scrollInfo, bool redraw=true)
Sets the properties of the given scroll bar.
int GetWindowText(TCHAR *str, int maxCount) const
Copies the window's title into a buffer pointed to by string.
bool IsChild(HWND hWnd) const
Returns true if the window is a child window or a descendant window of this window.
uint32 GetExStyle() const
Gets the extra style bits of the window.
virtual void CleanupWindow()
Always called immediately before the HWindow becomes invalid, CleanupWindow gives derived classes an ...
void GetWindowRect(TRect &rect) const
Gets the screen coordinates of the window's rectangle and copies them into rect.
void EvDrawItem(uint ctrlId, const DRAWITEMSTRUCT &drawInfo)
HMENU GetMenu() const
Returns the handle to the menu of the indicated window.
TResult HandleMessage(TMsgId, TParam1=0, TParam2=0)
Dispatches the given message using the response table.
bool TrackMouseEvent(uint flags=TME_HOVER|TME_LEAVE, int hoverTime=HOVER_DEFAULT)
Posts messages when the mouse pointer leaves a window or hovers over a window for a specified amount ...
void SetScrollRange(int bar, int minPos, int maxPos, bool redraw=true)
Sets the thumb position in the scroll bar.
void EvLButtonDown(uint modKeys, const TPoint &point)
Response method for an incoming WM_LBUTTONDOWN message.
bool ModifyStyle(uint32 offBits, uint32 onBits, uint swpFlags=0)
Modifies the style bits of the window.
virtual bool IdleAction(long idleCount)
Called when no messages are waiting to be processed, IdleAction performs idle processing as long as t...
int GetUpdateRgn(TRegion &rgn, bool erase=true) const
Copies a window's update region into a region specified by region.
void SetScrollPage(int bar, int page, bool redraw=true)
Sets the page property (SCROLLINFO::nPage) of the given scroll bar.
void SetScroller(TScroller *scroller)
Sets the scroller object for this window.
void SubclassWindowFunction()
Installs the instance thunk as the WindowProc and saves the old window function in DefaultProc.
HCURSOR LoadCursor(TResId id) const
uint32 GetStyle() const
Gets the style bits of the underlying window or the 'Style' member of the attribute structure associa...
LPCTSTR GetCaption() const
Returns the Title member of TWindow.
TResult ForwardMessage(HWND handle, bool send=true)
Forwards the window's current message.
TResult DefaultProcessing()
Handles default processing of events, which includes continued processing of menu/accelerators comman...
uint GetDlgItemInt(int childId, bool *translated=0, bool isSigned=true) const
Translates the text of a specified control into an integer value and returns it.
TRect GetClientRect() const
Gets the coordinates of the window's client area (the area in a window you can use for drawing).
int GetDlgCtrlID() const
Returns the ID of the control.
void EvMouseHWheel(uint modKeys, int zDelta, const TPoint &point)
Event handler for WM_MOUSEHWHEEL.
void SetWindowText(LPCTSTR str)
Sets the window's text to the given string (by copying).
bool CreateChildren()
Creates the child windows in the child list whose auto-create flags (with wfAutoCreate mask) are set.
void EvNCDestroy()
Responds to an incoming WM_NCDESTROY message, the last message sent to an MS-Windows interface elemen...
bool GetScrollInfo(int bar, SCROLLINFO *scrollInfo) const
Retrieves the properties of the given scroll bar.
virtual TResult EvCommand(uint id, HWND hWndCtl, uint notifyCode)
WindowProc calls EvCommand to handle WM_COMMAND messages.
virtual bool CanClose()
Use this function to determine if it is okay to close a window.
auto GetTextColor() const -> TColor
Returns the overriding text color set for the window.
uint32 SetStyle(uint32 style)
Sets the style bits of the underlying window or the 'Style' member of the attribute structure associa...
void ClearFlag(uint mask)
Clears the specified TWindow wfXxxx constant flags (for example wfAlias, wfTransfer,...
virtual void TransferData(TTransferDirection direction)
Transfers data between the TWindow's data buffer and the child windows in its ChildList (data is not ...
bool IsZoomed() const
Returns true if window is zoomed or maximized.
virtual bool Register()
Registers the Windows registration class of this window, if this window is not already registered.
virtual TResult EvNotify(uint id, TNotify ¬ifyInfo)
Handles WM_NOTIFY and subdispatch messages from child controls.
virtual bool HoldFocusHWnd(HWND hLose, HWND hGain)
Responds to a request by a child window to hold its HWND when it is losing focus.
void EvChildInvalid(HWND hWnd)
Handle message posted to us by a control needing assistance in dealing with invalid inputs.
void ScreenToClient(TPoint &point) const
Uses the screen coordinates specified in point to calculate the client window's coordinates and then ...
TWindow * Next()
Returns a pointer to the next sibling window in the window's sibling list.
int GetDlgItemText(int childId, TCHAR *text, int maxValue) const
Retrieves the text of a control specified by childId.
bool CancelMouseEvent(uint flags=TME_HOVER|TME_LEAVE)
Encapsulates a call to TrackMouseEvent, passing the TME_CANCEL flag.
void EvSysColorChange()
Respond to WM_SYSCOLORCHANGE by broadcasting it to all children.
virtual bool ShowWindow(int cmdShow)
Displays this TWindow in a given state.
int GetScrollPos(int bar) const
Returns the thumb position in the scroll bar.
TResult SendMessage(TMsgId, TParam1=0, TParam2=0) const
Sends a message (msg) to a specified window or windows.
int SetScrollPos(int bar, int pos, bool redraw=true)
Sets the thumb position in the scroll bar.
virtual void SetupWindow()
Performs setup following creation of an associated MS-Windows window.
virtual void Paint(TDC &dc, bool erase, TRect &rect)
Repaints the client area (the area you can use for drawing) of a window.
WNDPROC SetWindowProc(WNDPROC wndProc)
void EvEndSession(bool endSession, uint flags)
Provides default handling for WM_ENDSESSION.
HBRUSH EvCtlColor(HDC hDC, HWND hWndChild, uint ctlType)
Handler for control color messages (WM_CTLCOLOR family).
bool ModifyExStyle(uint32 offBits, uint32 onBits, uint swpFlags=0)
Modifies the style bits of the window.
bool IsFlagSet(uint mask)
Returns the state of the bit flag in Attr.Flags whose mask is supplied.
bool EvQueryEndSession(uint flags)
Respond to Windows attempt to close down.
void DragAcceptFiles(bool accept)
If a window can process dropped files, DragAcceptFiles sets accept to true.
void EvSize(uint sizeType, const TSize &size)
Response method for an incoming WM_SIZE message.
uint NumChildren() const
Returns the number of child windows of the window.
void EvMeasureItem(uint ctrlId, MEASUREITEMSTRUCT &measureInfo)
Handles WM_MEASUREITEM message (for owner draw controls & menus) by forwarding message to control its...
void EnableAutoCreate()
Ensures that an associated child window interface element is created and displayed along with its par...
bool EvSetCursor(HWND hWndCursor, uint codeHitTest, TMsgId mouseMsg)
Response method for an incoming WM_SETCURSOR message.
void GetClientRect(TRect &rect) const
Gets the coordinates of the window's client area and then copies them into the object referred to by ...
TWindow * GetFirstChild()
Returns a pointer to the first child window, which is the first window created in the interface objec...
std::pair< int, int > TScrollRange
HWND THandle
TWindow encapsulates an HWND.
void EvInitMenuPopup(HMENU hPopupMenu, uint index, bool isSysMenu)
Handle WM_INITMENUPOPUP while embeded to generate command enable messages for our server menu items.
HWND GetHandle() const
Returns the handle of the window.
virtual void CloseWindow(int retVal=0)
Determines if it is okay to close a window before actually closing the window.
auto ChildWithId(int id) const -> const TWindow *
int GetWindowTextLength() const
Returns the length, in characters, of the specified window's title.
int GetScrollPage(int bar) const
Returns the page property (SCROLLINFO::nPage) of the given scroll bar.
TXOwl is root class of the ObjectWindows exception hierarchy.
A nested class, TXWindow describes an exception that results from trying to create an invalid window.
static void Raise(TWindow *win=nullptr, uint resourceId=IDS_INVALIDWINDOW)
Creates the TXWindow exception and throws it.
int Unhandled(TModule *app, uint promptResId)
Unhandled exception.
TXWindow(TWindow *win=nullptr, uint resourceId=IDS_INVALIDWINDOW)
Constructs a TXWindow object with a default resource ID of IDS_INVALIDWINDOW.
TWindow * GetWindow() const
TXWindow * Clone()
Clone the exception object for safe-throwing.
void Throw()
Throws the exception object.
Definition of classes for CommonControl encapsulation.
#define WM_COMMAND_ENABLE
#define WM_OWLHELPHIT
Notify Help manager with hit point.
#define DEFINE_RESPONSE_TABLE(cls)
Macro to define a response table for a class with no base response tables.
Definition of class TFrameWindow.
Definition of abstract GDI object class and derived classes.
#define _OBJ_FULLTYPENAME(obj)
TResponseTableEntry< TGeneric > TGenericTableEntry
static tstring MakeMessage(uint resId, const tstring &infoStr, TModule *module=&GetGlobalModule())
TXOwl(const tstring &msg, uint resId=0)
An OWL exception with a given message for displaying and an unsigned Id that can be used for identifi...
virtual int Unhandled(TModule *appModule, uint promptResId)
Per-exception class unhandled-handler, will default to the per-module unhandled-handler.
void CacheFlush(TCacheEntry::TId id)
void Set(int index, TCacheEntry::TId uniqueId, TMsgId, const TGenericTableEntry *entry, int delta=0)
bool Check(int index, TMsgId, TCacheEntry::TId id)
TTransferDirection
The TTransferDirection enum describes the constants that the transfer function uses to determine how ...
@ wfDeleteOnClose
Window is condemned on EvClose.
@ wfAlias
TWindow is an alias to a preexisting HWND.
@ wfModalWindow
Was created via TWindow::Execute.
@ wfPredefinedClass
Window class used belongs to a predefined Windows class and was not defined by OWL.
@ wfFromResource
Handle comes from HWND created from resource.
@ wfMainWindow
This frame window is the main window.
@ wfFullyCreated
Window is fully created & not being destroyed.
@ wfDetached
Window handle has been detached.
@ wfPropagateIdle
Pass down IdleAction.
@ wfTransfer
Participates in the Transfer mechanism.
@ wfAutoCreate
Create the HWND when our parent is created.
@ tdSizeData
Return the size of data transferred by the class.
@ tdSetData
Set data from the buffer into the window.
Declares THelpContext and THelpFileManager.
char * strnewdup(const char *s, size_t minAllocSize=0)
Object Windows Library (OWLNext Core).
EV_WM_CTLCOLORSTATIC(EvCtlColor)
EV_WM_CTLCOLORLISTBOX(EvCtlColor)
UINT TMsgId
Message ID type.
EV_WM_CTLCOLOREDIT(EvCtlColor)
owl::opstream & operator<<(owl::opstream &os, const TColor &c)
Insert the color value into a persistent output stream.
TApplication * GetApplicationObject(uint pid=0)
Global function that calls GetApplication() on owl's app-dictionary.
uint16 HiUint16(LRESULT r)
void SetCreationWindow(TWindow *w)
TWindow * GetWindowPtr(HWND, const TApplication *)
Raw function to retrieve a TWindow pointer given an HWND from the a given app, or any app (app==0).
EV_WM_CTLCOLORDLG(EvCtlColor)
void InUse(const T &arg)
Handy utility to avoid compiler warnings about unused parameters.
EV_WM_CTLCOLORBTN(EvCtlColor)
LPARAM TParam2
Second parameter type.
tstring CopyText(int size, TGetText get_text)
Copies text from a C-string (null-terminated character array) into a string object,...
WPARAM TParam1
First parameter type.
uint16 LoUint16(LRESULT r)
EV_WM_CTLCOLORSCROLLBAR(EvCtlColor)
TParam1 MkParam1(uint lo, uint hi)
LRESULT TResult
Result type.
const unsigned int IDW_FIRSTMDICHILD
child window IDs, 32 max to 32032
DIAG_DEFINE_GROUP_INIT(OWL_INI, OwlApp, 1, 0)
TDrawItem * ItemData2DrawItem(ULONG_PTR data)
Handles WM_DRAWITEM message (for owner draw controls & menus) by forwarding message to control itself...
TWindow * GetCreationWindow()
void DoEnableAutoCreate(TWindow *win, void *)
A TActionFunc defined in window.cpp.
DIAG_DECLARE_GROUP(OwlThread)
General definitions used by all ObjectWindows programs.
#define COUNTOF(s)
Array element count Important: Only use this with an argument of array type.
#define TYPESAFE_DOWNCAST(object, toClass)
General Registry access & registration implementation TRegKey, TRegValue, TRegKeyIterator,...
Definitions of Win95 Shell Clases: TShellItem, TShellItemIterator, TPidl, TShellMalloc.
Current event structure for windows events.
TMsgId Message
Message ID.
TWindow * Win
Window that message was sent/dispatched to.
TParam1 Param1
First parameter (WPARAM).
TParam2 Param2
Second parameter (LPARAM).
TResId Menu
Contains the resource ID for the menu associated with this window.
LPVOID Param
Contains a value that is passed to Windows when the window is created.
TResId AccelTable
Holds the resource ID for the window's accelerator table.
#define TYPE_UNIQUE_ID(t)
Base window class TWindow definition, including HWND encapsulation.