26#if !defined(WM_SETICON)
27# define WM_SETICON 0x0080
52 ::EnableMenuItem(HMenu, Position,
53 MF_BYPOSITION | (enable ? MF_ENABLED : MF_GRAYED));
62 ::ModifyMenu(HMenu, Position, MF_BYPOSITION | MF_STRING, Id, str);
73 ::CheckMenuItem(HMenu, Position,
74 MF_BYPOSITION | (state ==
Checked ? MF_CHECKED : MF_UNCHECKED));
103 Init(clientWnd, shrinkToClient);
118 Init(client, shrinkToClient);
128 Init(client.get(), shrinkToClient);
170 Attr.Style = WS_OVERLAPPEDWINDOW | WS_VISIBLE;
171 Attr.X = Attr.W = CW_USEDEFAULT;
174 Attr.Style |= WS_CLIPCHILDREN;
189 HWndRestoreFocus =
nullptr;
190 KeyboardHandling =
false;
191 ClientWnd = clientWnd;
196 MergeModule =
nullptr;
200 IconModule =
nullptr;
201 IconSmModule =
nullptr;
203 #if !defined( MAINWIN )
207 MinimizedPos =
TPoint(-1,-1);
236GetMenuStateBits(HMENU hmenu,
int count)
241 for (
int i = 0; i < count; i++) {
242 uint state = GetMenuState(hmenu, i, MF_BYPOSITION);
243 if (state !=
static_cast<uint>(-1)) {
244 if (!(state & (MF_DISABLED | MF_GRAYED))) {
267 if (!isSysMenu && hPopupMenu) {
268 const int count = ::GetMenuItemCount(hPopupMenu);
274 preState = GetMenuStateBits(hPopupMenu, count);
281 if (GetMenuStateBits(hPopupMenu, count) != preState)
296 if (idleCount == 0) {
301 if (!(style & WS_CHILD)) {
338 if (hFocus && client && client->
IsChild(hFocus)) {
339 TRACEX(OwlCmd, 1,
"TFrameWindow::GetCommandTarget - focus, "\
340 "child of client: " <<
static_cast<void*
>(hFocus));
347 TRACEX(OwlCmd, 1,
"TFrameWindow::GetCommandTarget - client: " << *client);
353 if (hFocus &&
IsChild(hFocus)) {
354 TRACEX(OwlCmd, 1,
"TFrameWindow::GetCommandTarget - focus, "\
355 <<
static_cast<void*
>(hFocus));
361 if (HWndRestoreFocus) {
362#if defined(__TRACE) || defined(__WARN)
365 TRACEX(OwlCmd, 1,
"TFrameWindow::GetCommandTarget - HwndRestoreFocus, "\
366 <<
static_cast<void*
>(HWndRestoreFocus));
368 TRACEX(OwlCmd, 1,
"TFrameWindow::GetCommandTarget - HwndRestoreFocus, "\
372 return HWndRestoreFocus;
377 TRACEX(OwlCmd, 1,
"TFrameWindow::GetCommandTarget - self, " << *
this);
390 TRACEX(OwlCmd, 1,
"TFrameWindow::EvCommand - id(" <<
id <<
"), ctl(" <<
391 static_cast<void*
>(hCtl) <<
"), code(" << notifyCode <<
")");
397 if (hCtl ==
nullptr) {
402 while (hCmdTarget && hCmdTarget !=
GetHandle()) {
406 return cmdTarget->
EvCommand(
id, hCtl, notifyCode);
442 if (KeyboardHandling && msg.message >= WM_KEYFIRST &&
443 msg.message <= WM_KEYLAST)
450 tchar szClassName[0x10];
454 if (parent && ::IsDialogMessage(parent, &msg))
495 if (menuResId != Attr.Menu) {
496 if (Attr.Menu.IsString())
497 delete[] Attr.Menu.GetString();
509 HMENU newMenu =
LoadMenu(Attr.Menu);
515 ::DestroyMenu(curMenu);
536 if (CurIcon && IconModule) {
544 HINSTANCE hInstance = IconModule ? HINSTANCE(*IconModule) : HINSTANCE(
nullptr);
563 if (CurIconSm && IconSmModule) {
568 IconSmModule =
module;
571 HINSTANCE hInstance = IconSmModule ? HINSTANCE(*IconSmModule) : HINSTANCE(
nullptr);
572 if (IconSmResId != 0) {
573 CurIconSm =
reinterpret_cast<HICON
>(::LoadImage(hInstance, IconSmResId.GetPointerRepresentation(), IMAGE_ICON,
606 TWindow* oldClientWnd = ClientWnd;
607 HWND oldWnd = oldClientWnd ? oldClientWnd->
GetHandle() :
static_cast<HWND
>(
nullptr);
610 if (HWndRestoreFocus == oldWnd)
611 HWndRestoreFocus =
nullptr;
613 ClientWnd = clientWnd;
616 ClientWnd->SetParent(
this);
618 if (!ClientWnd->GetHandle())
620 ClientWnd->ShowWindow(SW_SHOWNOACTIVATE);
623 ResizeClientWindow(
true);
631 ClientWnd->SetFocus();
632 HWndRestoreFocus = ClientWnd->GetHandle();
643 auto old = unique_ptr<TWindow>{SetClientWindow(c.get())};
657 if (child == ClientWnd)
659 if (child->
GetHandle() == HWndRestoreFocus) {
660 HWndRestoreFocus =
nullptr;
715 static HICON hRealAppIcon = 0;
718 static tchar className[] =
_T(
"IconSnarfer");
719 memset(&wndClass, 0,
sizeof wndClass);
721 wndClass.hIcon = ::LoadIcon(
nullptr, IDI_APPLICATION);
722 wndClass.lpszClassName = className;
723 wndClass.lpfnWndProc = ::DefWindowProc;
724 ::RegisterClass(&wndClass);
726 hRealAppIcon = wndClass.hIcon;
729 return hRealAppIcon ? hRealAppIcon : ::LoadIcon(
nullptr, IDI_APPLICATION);
757 HINSTANCE hInstance = IconModule ? HINSTANCE(*IconModule) : HINSTANCE(
nullptr);
759 return hIcon ? hIcon : getAppIcon();
769auto IsEnabledVisibleChild_(
long style) ->
bool
771 return (style & (WS_CHILD | WS_VISIBLE | WS_DISABLED)) == (WS_CHILD | WS_VISIBLE);
774auto SearchForChildWithTab_(TWindow* win) -> TWindow*
776 for (
auto& child : win->GetChildren())
778 if (!child.GetHandle())
continue;
779 long style = child.GetWindowLong(GWL_STYLE);
780 if (IsEnabledVisibleChild_(style))
782 if (style & WS_TABSTOP)
784 else if (
const auto result = SearchForChildWithTab_(&child))
804TFrameWindow::FirstChildWithTab()
806 const auto win = SearchForChildWithTab_(
this);
810 const auto i = find_if(c.begin(), c.end(), [](
TWindow& w)
811 { return w.GetHandle() && IsEnabledVisibleChild_(w.GetWindowLong(GWL_STYLE)); });
812 return (i != c.end()) ? &(*i) :
nullptr;
826 if (!hWndGain || !
IsChild(hWndGain))
827 HWndRestoreFocus = hWndLose;
845 if (!HWndRestoreFocus) {
848 HWndRestoreFocus = cmdTgt;
854 if (HWndRestoreFocus) {
860 HWndRestoreFocus =
nullptr;
884 if (ClientWnd && ClientWnd->GetHandle() == i.
Child)
896 ResizeClientWindow(
true);
935TFrameWindow::ResizeClientWindow(
bool repaint)
954 bool clientResized =
false;
964 const uint32 badClientStyles = WS_DLGFRAME | WS_THICKFRAME |
965 WS_POPUP | WS_OVERLAPPED;
969 if ((ClientWnd->
GetStyle() & badClientStyles) ||
970 (ClientWnd->
GetExStyle() & badClientExStyles)) {
975 if (childSize != tstSize) {
976 int restore = SB_BOTH;
977 if (childSize.cx == tstSize.cx)
979 if (childSize.cy == tstSize.cy)
984 if (ClientWnd->GetStyle() & badClientStyles) {
985 bool reparent = (ClientWnd->GetStyle() & (WS_POPUP|WS_OVERLAPPED)) != 0;
986 uint32 style = ClientWnd->GetStyle();
987 style &= ~badClientStyles;
988 style |= WS_CHILD | WS_BORDER | WS_VISIBLE;
989 ClientWnd->SetStyle( style );
993 if (ClientWnd->GetExStyle() & badClientExStyles) {
994 uint32 exStyle = ClientWnd->GetExStyle();
995 exStyle &= ~badClientExStyles;
996 ClientWnd->SetExStyle( exStyle );
999 if (ClientWnd->GetStyle() & WS_BORDER) {
1000 childSize = ClientWnd->GetClientRect().Size();
1002 if (childSize != clientAreaSize) {
1005 TSize border = outside.Size() - clientAreaSize;
1007 childSize.cx + border.cx, childSize.cy + border.cy,
1008 SWP_NOACTIVATE|SWP_NOMOVE| (repaint ? 0 : SWP_NOREDRAW));
1009 clientAreaSize = childSize;
1012 clientResized =
true;
1030 if (ClientWnd->GetStyle() & WS_BORDER) {
1033 ClientWnd->MoveWindow(-bx, -by, clientAreaSize.cx+bx+bx,
1034 clientAreaSize.cy+by+by, repaint);
1037 ClientWnd->MoveWindow(0, 0, clientAreaSize.cx, clientAreaSize.cy, repaint);
1042 return clientResized;
1057 ResizeClientWindow(
true);
1059 if (MinimizedPos !=
TPoint(-1,-1)) {
1061 windata.flags = WPF_SETMINPOSITION;
1062 windata.showCmd = SW_SHOWNA;
1063 windata.ptMinPosition = MinimizedPos;
1074 ::DestroyMenu(curMenu);
1077 ::DestroyMenu(newMenu);
1082 if (!HWndRestoreFocus) {
1088 TWindow* win = FirstChildWithTab();
1092 if (cmdTgt &&
IsChild(cmdTgt))
1093 HWndRestoreFocus = cmdTgt;
1125 if (sizeType == SIZE_MINIMIZED
1126 || sizeType == SIZE_MAXIMIZED
1127 || sizeType == SIZE_RESTORED)
1145 TSize newSize = size;
1148 bool sizeSent =
false;
1149 if (sizeType != SIZE_MINIMIZED) {
1150 sizeSent = ResizeClientWindow(
true);
1151 newSize = ClientWnd->GetClientRect().Size();
1154 ClientWnd->ForwardMessage();
1167 if (&menuDescr != MenuDescr)
1177 ::DestroyMenu(curMenu);
1179 ::DestroyMenu(newMenu);
1191 BarDescr = barDescr;
1210 MergeModule = childMenuDescr.
GetModule();
1214 MenuDescr->Merge(childMenuDescr, newMenu);
1220 ::DestroyMenu(curMenu);
1225 ::DestroyMenu(newMenu);
1244 MergeModule =
nullptr;
1245 ::DestroyMenu(curMenu);
1248 ::DestroyMenu(newMenu);
1256#if OWL_PERSISTENT_STREAMS
1271 is >> o->KeyboardHandling;
1272 o->HWndRestoreFocus = 0;
1277 is >> *o->MenuDescr;
1286 o->BarDescr =
new TBarDescr;
1293 is >> o->IconModule;
1298 is >> o->IconSmModule;
1304 o->IconSmModule = 0;
1312 o->
SetIcon(o->IconModule, o->IconResId);
1313 o->
SetIconSm(o->IconSmModule, o->IconSmResId);
1315 is >> o->MergeModule;
1316 is >> o->MinimizedPos;
1325TFrameWindow::Streamer::Write(
opstream& os)
const
1333 os << o->KeyboardHandling;
1335 os.writeByte(
uint8(o->MenuDescr ? 1 : 0));
1337 os << *o->MenuDescr;
1340 os.writeByte(
uint8(o->BarDescr ? 1 : 0));
1344 os << o->IconModule;
1346 os << o->IconSmModule;
1347 os << o->IconSmResId;
1349 os << o->MergeModule;
1350 auto windata = o->GetWindowPlacement();
1351 os <<
TPoint(windata.ptMinPosition);
Definition of class TApplication.
Class definition for TBarDescr.
#define DIAG_DECLARE_GROUP(group)
#define TRACEX(group, level, message)
virtual void PreProcessMenu(HMENU hMenubar)
Called by the main window to provide an oportunity to preprocess the main window's menubar before it ...
void ClearMainWindow()
Called by the main window (TFrameWindow) destructor to zero the MainWindow member.
Descriptor of Bar Implementation.
Base class for an extensible interface for auto enabling/disabling of commands (menu items,...
virtual void Enable(bool enable=true)
Enables or disables the command sender.
@ Checked
Command is enabled.
Derived from TWindow, TFrameWindow controls such window-specific behavior as keyboard navigation and ...
auto IdleAction(long idleCount) -> bool override
Overrides TWindow's virtual function.
void Init(TWindow *clientWnd, bool shrinkToClient)
Normal initialization of a default constructed TFrameWindow.
~TFrameWindow() override
Destructor for a TFrameWindow.
virtual bool MergeMenu(const TMenuDescr &childMenuDescr)
Merges the given menu descriptor with this frame's own menu descriptor and displays the resulting men...
virtual TWindow * GetClientWindow()
Returns a pointer to the client window.
void EvSize(uint sizeType, const TSize &size)
Response method for an incoming WM_SIZE message.
auto SetDocTitle(LPCTSTR docname, int index) -> bool override
Overrides TWindow's virtual function.
void EvCommandEnable(TCommandEnabler &) override
Handle WM_COMMAND_ENABLE to provide command enable distribution and default support for windows witho...
virtual bool RestoreBar()
Do nothing in TFrameWindow. Overriden in TDecoratedFrame.
virtual bool SetMenu(HMENU newMenu)
Overrides TWindow's non-virtual SetMenu function, thus allowing derived classes the opportunity to im...
void SetMenuDescr(const TMenuDescr &menuDescr)
Sets the menu descriptor to the new menu descriptor.
void CleanupWindow() override
Cleans up any associated icons.
void EvPaletteChanged(HWND hWndPalChg)
Forwards the WM_PALETTECHANGED message to the client window.
virtual HWND GetCommandTarget()
Locates and returns the child window that is the target of the command and command enable messages.
auto HoldFocusHWnd(HWND hWndLose, HWND hWndGain) -> bool override
Overrides TWindow's virtual function.
auto PreProcessMsg(MSG &) -> bool override
Overrides TWindow's virtual function.
void BroadcastResizeToChildren(uint sizeType, const TSize &size)
Tell child windows frame has minimized/maximized/restored (They may want to change enabled state or r...
auto EvCommand(uint id, HWND hWndCtl, uint notifyCode) -> TResult override
Handle WM_COMMAND to provide extra processing for commands: Extra processing for commands: starts wit...
bool EvQueryNewPalette()
Forwards the WM_QUERYNEWPALETTE message to the client window.
virtual TWindow * SetClientWindow(TWindow *clientWnd)
Sets the client window to the specified window.
void EvParentNotify(const TParentNotify &)
Responds to a message to notify the parent window that a given event has occurred.
bool SetIconSm(TModule *iconModule, TResId iconResIdSm)
Set the Small Icon (16 x 16).
bool SetIcon(TModule *iconModule, TResId iconResId)
Sets the icon in the module specified in iconModule to the resource ID specified in iconResId.
HICON EvQueryDragIcon()
Responds to a WM_QUERYDRAGICON message sent to a minimized (iconic) window that is going to be dragge...
virtual bool AssignMenu(TResId menuResId)
Perform a high-level menu assignment either before or after the HWND for the window has been created.
void SetBarDescr(TBarDescr *barDescr, TAutoDelete=AutoDelete)
Sets the control bar descriptor to the new bar descriptor.
void EvSetFocus(HWND hWndLostFocus)
Restores the focus to the active window.
void EvInitMenuPopup(HMENU hPopupMenu, uint index, bool isSysMenu)
Responds to WM_INITMENUPOPUP by performing a command enable run on each of the menu items in the popu...
TFrameWindow()
< String-aware overload
void SetupWindow() override
Calls TWindow::SetUpWindow to create windows in a child list.
void RemoveChild(TWindow *) override
If someone removes our client with a RemoveChild() call, update our client and restore focus ptrs.
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
TPoint()
Constructs an uninitialized point.
TSize Size() const
Returns the size of rectangle.
bool IsString() const
Returns true if this resource identifier encodes a string pointer.
The tagSIZE struct is defined as.
static const TUIMetric CyBorder
static const TUIMetric CySmIcon
static const TUIMetric CxBorder
static const TUIMetric CxSmIcon
static BOOL DestroyIcon(HICON)
static HICON LoadIcon(HINSTANCE, LPCTSTR)
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
HWND SetFocus()
Sets the keyboard focus to current window and activates the window that receives the focus by sending...
void ShowScrollBar(int bar, bool show=true)
Displays or hides the scroll bar.
HMENU LoadMenu(TResId id) const
bool SetMenu(HMENU hMenu)
Sets the specified window's menu to the menu indicated by hMenu.
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.
void SetBkgndColor(TColor color, bool shouldUpdate=true)
Sets the background color for the window.
void DrawMenuBar()
DrawMenuBar redraws the menu bar.
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...
bool SetWindowPos(HWND hWndInsertAfter, const TRect &rect, uint flags)
Changes the size of the window pointed to by rect.
virtual bool PreProcessMsg(MSG &msg)
Called from TApplication::ProcessAppMsg() to give the window an opportunity to perform preprocessing ...
auto GetChildren()
Returns a TWindow::TChildrenRange that can be iterated by standard means.
TWindow * GetParent() const
Retrieves the OWL object of the parent window. If none exists, returns 0.
TWindow * GetWindowPtr(HWND hWnd) const
Calls TApplication:GetWindowPtr on the application associated with this window.
virtual void RemoveChild(TWindow *child)
Removes a child window.
void SetWindowPlacement(const WINDOWPLACEMENT &place)
Wrapper for Windows API.
HICON EvQueryDragIcon()
The default message handler for WM_QUERYDRAGICON.
long GetWindowLong(int index) const
Retrieves information about the window depending on the value stored in index.
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,...
WINDOWPLACEMENT GetWindowPlacement() const
Wrapper for Windows API.
auto GetClassName(TCHAR *className, int maxCount) const -> int
Returns the Windows class name for this object's window handle.
bool EvQueryNewPalette()
The default message handler for WM_QUERYNEWPALETTE.
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.
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.
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.
virtual bool IdleAction(long idleCount)
Called when no messages are waiting to be processed, IdleAction performs idle processing as long as t...
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...
TRect GetClientRect() const
Gets the coordinates of the window's client area (the area in a window you can use for drawing).
void SetWindowText(LPCTSTR str)
Sets the window's text to the given string (by copying).
virtual TResult EvCommand(uint id, HWND hWndCtl, uint notifyCode)
WindowProc calls EvCommand to handle WM_COMMAND messages.
void EvSetFocus(HWND hWndLostFocus)
The default message handler for WM_SETFOCUS.
void ClearFlag(uint mask)
Clears the specified TWindow wfXxxx constant flags (for example wfAlias, wfTransfer,...
bool PostMessage(TMsgId, TParam1=0, TParam2=0)
Posts a message (msg) to the window in the application's message queue.
TResult SendMessage(TMsgId, TParam1=0, TParam2=0) const
Sends a message (msg) to a specified window or windows.
virtual void SetupWindow()
Performs setup following creation of an associated MS-Windows window.
bool IsFlagSet(uint mask)
Returns the state of the bit flag in Attr.Flags whose mask is supplied.
static HWND GetFocus()
Gets a handle to the window that has the focus.
void EvSize(uint sizeType, const TSize &size)
Response method for an incoming WM_SIZE message.
void EnableAutoCreate()
Ensures that an associated child window interface element is created and displayed along with its par...
void EvPaletteChanged(HWND hWndPalChg)
The default message handler for WM_PALETTECHANGED.
void GetClientRect(TRect &rect) const
Gets the coordinates of the window's client area and then copies them into the object referred to by ...
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.
ipstream, a specialized input stream derivative of pstream, is the base class for reading (extracting...
uint8 readByte()
Returns the byte at the current stream position.
Base class for writing streamable objects.
#define WM_OWLFRAMESIZE
Notify children of frame resizing.
TDockable classes: TDockableGadgetWindow & TDockableControlBar TDockingSlip classes: TFloatingSlip & ...
#define DEFINE_RESPONSE_TABLE1(cls, base)
Macro to define a response table for a class with one base.
Definition of class TFrameWindow.
TAutoDelete
Flag for Handle ctors to control Handle deletion in dtor.
void ReadVirtualBase(Base *base, ipstream &in)
void WriteVirtualBase(Base *base, opstream &out)
THandle GetHandle() const
Return the instance handle of the library module represented by the TModule obect.
#define NoErase
don't erase, wait for Paint
#define NoColor
let DefWindowProc erase
@ wfMainWindow
This frame window is the main window.
@ wfFullyCreated
Window is fully created & not being destroyed.
@ wfShrinkToClient
Shrink a frame window to its client's size.
char * strnewdup(const char *s, size_t minAllocSize=0)
Object Windows Library (OWLNext Core).
LPARAM TParam2
Second parameter type.
WPARAM TParam1
First parameter type.
TDispatch< WM_PARENTNOTIFY >::TArgs TParentNotify
Alias for convenience.
LRESULT TResult
Result type.
TDispatch< WM_PARENTNOTIFY >::TChildInfoArgs TParentNotifyChildInfo
Alias for convenience.
TModule & GetGlobalModule()
IMPLEMENT_STREAMABLE1(TApplication, TModule)
auto InternStreamedResId_(TResId id) -> TResId
#define COUNTOF(s)
Array element count Important: Only use this with an argument of array type.
#define TYPESAFE_DOWNCAST(object, toClass)
Private helper for reading resource identifiers from persistent streams.
Definition of TUIMetric, a UI metrics provider class.