OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
framewin.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1991, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Implementation of class TFrameWindow, a TWindow with additional features
7/// for frames, such as client window, menus, icons, etc.
8//----------------------------------------------------------------------------
9#include <owl/pch.h>
10
11#include <stdio.h>
12
13#include <owl/docking.h>
14#include <owl/framewin.h>
15#include <owl/applicat.h>
16#include <owl/menu.h>
17#include <owl/uimetric.h>
18#include <owl/bardescr.h>
19#include "strmresid.h"
20#include <algorithm>
21
22using namespace std;
23
24namespace owl {
25
26#if !defined(WM_SETICON)
27# define WM_SETICON 0x0080
28#endif
29
31DIAG_DECLARE_GROUP(OwlCmd);
32
33
34DEFINE_RESPONSE_TABLE1(TFrameWindow, TWindow)
43
44//
45/// Overrides TCommandEnable::Enable. Enables or disables the menu options that
46/// control the appearance of the corresponding menu item.
47//
48void
50{
52 ::EnableMenuItem(HMenu, Position,
53 MF_BYPOSITION | (enable ? MF_ENABLED : MF_GRAYED));
54}
55
56//
57/// Overrides TCommandEnable::SetText. Changes the text of the corresponding menu
58//
59void
61{
62 ::ModifyMenu(HMenu, Position, MF_BYPOSITION | MF_STRING, Id, str);
63}
64
65//
66/// Overrides TCommandEnable::SetCheck. Checks or unchecks the corresponding menu
67/// item. The state parameter reflects the menu item's state, which can be checked,
68/// unchecked, or indeterminate.
69//
70void
72{
73 ::CheckMenuItem(HMenu, Position,
74 MF_BYPOSITION | (state == Checked ? MF_CHECKED : MF_UNCHECKED));
75}
76
77//----------------------------------------------------------------------------
78
79//
80/// Constructs a window object with the parent window supplied in parent, which is
81/// zero if this is the main window. title, which by default is zero, contains the
82/// title displayed in the window's caption bar. clientWnd is the client window for
83/// this frame window or zero if none exists. shrinkToClient controls whether the
84/// client window will size to fit the frame or the frame window will fit the
85/// client. Note that this parameter only affects the size of the main window. When
86/// a client window is used in a frame window that doesn't have shrinktoClient set,
87/// the client window resizes to fit the frame window. When a client window is used
88/// in a frame window that has the shrinktoClient set, the frame window shrinks to
89/// fit the size of the client window.
90//
92 LPCTSTR title,
93 TWindow* clientWnd,
94 bool shrinkToClient,
95 TModule* module)
96{
97 // Initialize virtual base, in case the derived-most used default ctor
98 //
99 TWindow::Init(parent, title, module);
100
101
102 IconResId = 0; // remember that we still need to init
103 Init(clientWnd, shrinkToClient);
104}
105
106//
107/// String-aware overload
108//
110 TWindow* parent,
111 const tstring& title,
112 TWindow* client,
113 bool shrinkToClient,
114 TModule* module)
115{
116 TWindow::Init(parent, title, module);
117 IconResId = 0;
118 Init(client, shrinkToClient);
119}
120
121//
122/// Smart-pointer-aware overload.
123//
124TFrameWindow::TFrameWindow(TWindow* parent, const tstring& title, unique_ptr<TWindow> client, bool shrinkToClient, TModule* module)
125{
126 TWindow::Init(parent, title, module);
127 IconResId = nullptr;
128 Init(client.get(), shrinkToClient);
129 client.release(); // We took ownership;
130}
131
132//
133/// Constructor for a TFrameWindow that is being used as an alias for a
134/// non-ObjectWindows window. hWnd is the handle to the existing window object that
135/// TFrameWindow controls; module contains the module passed to the base class's
136/// contructor.
137///
138/// This constructor is generally not used by derived
139/// classes, only as generic alias to a framewindow-like HWND
140//
142:
143 TWindow(THandle, module)
144{
145 Init(nullptr);
146}
147
148//
149/// Protected constructor for use by immediate virtually derived classes.
150/// Immediate derivitives must call Init() before constructions are done.
151//
153{
154 IconResId = 0; // Zero this member to remember that we still need to init
155}
156
157//
158/// Normal initialization of a default constructed TFrameWindow. Is ignored
159/// if called more than once.
160///
161/// This initialize function is for use with virtually derived classes, which must
162/// call Init before construction is completed. This procedure provides necessary
163/// data to virtually derived classes and takes care of providing the data in the
164/// appropriate sequence.
165//
166void
167TFrameWindow::Init(TWindow* clientWnd, bool shrinkToClient)
168{
169 if (!IconResId) {
170 Attr.Style = WS_OVERLAPPEDWINDOW | WS_VISIBLE;
171 Attr.X = Attr.W = CW_USEDEFAULT;
172
173 if (clientWnd)
174 Attr.Style |= WS_CLIPCHILDREN;
175
176 if (shrinkToClient)
178
179 Init(clientWnd);
180 }
181}
182
183//
184// Private initializer does a bulk of the common frame window initialization
185//
186void
187TFrameWindow::Init(TWindow* clientWnd)
188{
189 HWndRestoreFocus = nullptr;
190 KeyboardHandling = false;
191 ClientWnd = clientWnd;
192
193 MenuDescr = nullptr;
194 BarDescr = 0;
195 DeleteBar = false;
196 MergeModule = nullptr;
197
198 CurIcon = nullptr;
199 CurIconSm = nullptr;
200 IconModule = nullptr;
201 IconSmModule = nullptr;
202 SetIcon(&GetGlobalModule(), IDI_OWLAPP);
203 #if !defined( MAINWIN )
204 SetIconSm(&GetGlobalModule(), IDI_OWLAPPSM);
205 #endif
206
207 MinimizedPos = TPoint(-1,-1); // Windows convention for never minimized
208
209 if (ClientWnd) {
210 ClientWnd->SetParent(this);
211 ClientWnd->EnableAutoCreate(); // in case client is a dialog
212 SetBkgndColor(NoErase); // no need to erase client area
213 }
214}
215
216//
217/// Destructor for a TFrameWindow
218//
219/// Deletes any associated menu descriptor.
220//
222{
224 if (GetApplication()->GetMainWindow() == this)
226
227 delete MenuDescr;
228 if(DeleteBar)
229 delete BarDescr;
230}
231
232//
233// Return a state mask representing the enabled menu items (up to 32)
234//
235static uint32
236GetMenuStateBits(HMENU hmenu, int count)
237{
238 uint32 bit = 1;
239 uint32 result = 0;
240
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))) {
245 result |= bit;
246 }
247 }
248 bit <<= 1;
249 }
250
251 return result;
252}
253
254//
255/// Responds to WM_INITMENUPOPUP by performing a command enable run on each
256/// of the menu items in the popup menu
257///
258/// Sent before a pop-up menu is displayed, EvInitMenuPopup lets an application
259/// change the items on the menu before the menu is displayed. EvInitMenuPopup
260/// controls whether the items on the pop-up menu are enabled or disabled, checked
261/// or unchecked, or strings. HMENU indicates the menu handle. index is the index of
262/// the pop-up menu. sysMenu indicates if the pop-up menu is the system menu.
263//
264void
265TFrameWindow::EvInitMenuPopup(HMENU hPopupMenu, uint index, bool isSysMenu)
266{
267 if (!isSysMenu && hPopupMenu) {
268 const int count = ::GetMenuItemCount(hPopupMenu);
269
270 // Save current state of visible top level menus
271 //
272 uint32 preState = 0;
273 if (hPopupMenu == GetMenu())
274 preState = GetMenuStateBits(hPopupMenu, count);
275
276 TWindow::EvInitMenuPopup(hPopupMenu, index, isSysMenu);
277
278 // If the top level menu state changes, redraw the menu bar
279 //
280 if (hPopupMenu == GetMenu())
281 if (GetMenuStateBits(hPopupMenu, count) != preState)
282 DrawMenuBar();
283 }
284}
285
286//
287/// Overrides TWindow's virtual function. TApplication calls the main window's
288/// IdleAction when no messages are waiting to be processed. TFrameWindow uses this
289/// idle time to perform command enabling for the menu bar. It also forwards
290/// IdleAction to each of its children. IdleAction can be overridden to do
291/// background processing.
292//
293bool
295{
296 if (idleCount == 0) {
297 // do command enabling for the menu bar if this is the active task
298 //
299 if (GetFocus()) {
300 long style = ::GetWindowLong(*this, GWL_STYLE);
301 if (!(style & WS_CHILD)) {
302 if (IsWindow()) {
303 HMENU hMenu = ::GetMenu(*this);
304 if (IsMenu(hMenu)) {
305 HandleMessage(WM_INITMENUPOPUP, TParam1(hMenu));
306 HandleMessage(WM_UNINITMENUPOPUP, TParam1(hMenu));
307 }
308 }
309 }
310 }
311 }
312 // give child windows an opportunity to do any idle processing
313 //
314 return TWindow::IdleAction(idleCount);
315}
316
317//
318/// Locates and returns the child window that is the target of the command and
319/// command enable messages. If the current application does not have focus or if
320/// the focus is within a toolbar in the application, GetCommandTarget returns the
321/// most recently active child window.
322///
323/// If an alternative form of command processing is desired, a user's main window
324/// class can override this function. TFrameWindow's EvCommand and EvCommandEnable
325/// functions use GetCommandTarget to find the command target window. This member is
326/// not available under Presentation Manager.
327//
328HWND
330{
331 // Retrieve the focus window and our client
332 //
333 HWND hFocus = ::GetFocus();
334 TWindow* client = GetClientWindow();
335
336 // 1. The first candidate is a focus window that's a child of our client
337 //
338 if (hFocus && client && client->IsChild(hFocus)) {
339 TRACEX(OwlCmd, 1, "TFrameWindow::GetCommandTarget - focus, "\
340 "child of client: " << static_cast<void*>(hFocus));
341 return hFocus;
342 }
343
344 // 2. The next option is our client window itself
345 //
346 if (client) {
347 TRACEX(OwlCmd, 1, "TFrameWindow::GetCommandTarget - client: " << *client);
348 return *client;
349 }
350
351 // 3. The next option is a focus window that's a child of ours
352 //
353 if (hFocus && IsChild(hFocus)) {
354 TRACEX(OwlCmd, 1, "TFrameWindow::GetCommandTarget - focus, "\
355 << static_cast<void*>(hFocus));
356 return hFocus;
357 }
358
359 // 4. If all of the above fail, resort to the last focus child of ours
360 //
361 if (HWndRestoreFocus) {
362#if defined(__TRACE) || defined(__WARN)
363 TWindow* win = GetWindowPtr(HWndRestoreFocus);
364 if (!win) {
365 TRACEX(OwlCmd, 1, "TFrameWindow::GetCommandTarget - HwndRestoreFocus, "\
366 << static_cast<void*>(HWndRestoreFocus));
367 } else {
368 TRACEX(OwlCmd, 1, "TFrameWindow::GetCommandTarget - HwndRestoreFocus, "\
369 << *win);
370 }
371#endif
372 return HWndRestoreFocus;
373 }
374
375 // 5. When all else fails, send ourselves in
376 //
377 TRACEX(OwlCmd, 1, "TFrameWindow::GetCommandTarget - self, " << *this);
378 return *this;
379}
380
381//
382/// Handle WM_COMMAND to provide extra processing for commands:
383/// Extra processing for commands: starts with the command target window
384/// (usually the focus window) and gives it and its parent windows an
385/// opportunity to handle the command.
386//
388TFrameWindow::EvCommand(uint id, HWND hCtl, uint notifyCode)
389{
390 TRACEX(OwlCmd, 1, "TFrameWindow::EvCommand - id(" << id << "), ctl(" <<
391 static_cast<void*>(hCtl) << "), code(" << notifyCode << ")");
392
393 // Walk the command chain from the command target back up to us or until
394 // we hit a child that is an owl window. Delegate to owl-child or forward to
395 // our base if no child is found.
396 //
397 if (hCtl == nullptr) {
398 HWND hCmdTarget = GetCommandTarget();
399
400 // Check owl parentage too in case the HWNDs were reparented
401 //
402 while (hCmdTarget && hCmdTarget != GetHandle()) {
403 TWindow* cmdTarget = GetWindowPtr(hCmdTarget);
404
405 if (cmdTarget)
406 return cmdTarget->EvCommand(id, hCtl, notifyCode);
407
408 hCmdTarget = ::GetParent(hCmdTarget);
409 }
410 }
411
412 return TWindow::EvCommand(id, hCtl, notifyCode);
413}
414
415//
416/// Handle WM_COMMAND_ENABLE to provide command enable distribution and default
417/// support for windows without command enable handlers.
418///
419/// Handles checking and unchecking of the frame window's menu items.
420/// EvCommandEnable uses TWindow's RouteCommandEnable member function to perform the
421/// majority of this command enabling work.
422//
423void
425{
426 // Don't process for windows out of our window tree (esp. other apps)
427 //
428 RouteCommandEnable(GetCommandTarget(), commandEnabler);
429}
430
431//
432/// Overrides TWindow's virtual function. Performs preprocessing of window messages.
433/// If the child window has requested keyboard navigation, PreProcessMsg handles any
434/// accelerator key messages and then processes any other keyboard messages.
435//
436bool
438{
439 if (TWindow::PreProcessMsg(msg))
440 return true; // Processed accelerators
441
442 if (KeyboardHandling && msg.message >= WM_KEYFIRST &&
443 msg.message <= WM_KEYLAST)
444 {
445 HWND parent = ::GetParent(msg.hwnd);
446
447 // Retrieve the COMBO handle if we're in the EDIT ctrl parented to the
448 // combobox
449 //
450 tchar szClassName[0x10];
451 ::GetClassName(parent, szClassName, COUNTOF(szClassName));
452 if (!_tcsicmp(szClassName, _T("COMBOBOX")))
453 parent = ::GetParent(parent);
454 if (parent && ::IsDialogMessage(parent, &msg))
455 return true;
456 }
457
458 return false;
459}
460
461//
462/// Overrides TWindow's non-virtual SetMenu function, thus allowing derived classes
463/// the opportunity to implement this function differently from TWindow. SetMenu
464/// sets the window's menu to the menu indicated by newMenu. If newMenu is 0, the
465/// window's current menu is removed. SetMenu returns 0 if the menu remains
466/// unchanged; otherwise, it returns a nonzero value.
467///
468/// It also calls the application's PreProcessMenu() if it is the main window
469/// to let it make any changes just before setting.
470//
471bool
473{
475 GetApplication()->PreProcessMenu(newMenu);
476
477 return TWindow::SetMenu(newMenu);
478}
479
480//
481/// Perform a high-level menu assignment either before or after the HWND for the
482/// window has been created.
483///
484/// Sets Attr.Menu to the supplied menuResId and frees any previous strings pointed
485/// to by Attr.Menu. If HWindow is nonzero, loads and sets the menu of the window,
486/// destroying any previously existing menu.
487///
488/// Returns true if successful; false otherwise
489//
490
491bool
493{
494
495 if (menuResId != Attr.Menu) {
496 if (Attr.Menu.IsString())
497 delete[] Attr.Menu.GetString();
498
499 Attr.Menu = menuResId.IsString() ? TResId(strnewdup(menuResId)) : menuResId;
500 }
501
502 // If the window has been created then load and set the new menu and destroy
503 // the old menu
504 //
505 if (!GetHandle())
506 return true;
507
508 HMENU curMenu = GetMenu();
509 HMENU newMenu = LoadMenu(Attr.Menu);
510
511 if (!SetMenu(newMenu))
512 return false;
513
514 if (curMenu)
515 ::DestroyMenu(curMenu);
516
517 return true;
518}
519
520//
521/// Sets the icon in the module specified in iconModule to the resource ID specified
522/// in iconResId. See the sample file BMPVIEW.CPP for an example of painting an icon
523/// from a bitmap. You can set the iconResId to one of these predefined values as
524/// well as user-defined values:
525/// - \c \b IDI_APPLICATION Default icon used for applications
526/// - \c \b IDI_ASTERISK Asterisk used for an informative message
527/// - \c \b IDI_EXCLAMATION Exclamation mark used for a warning message
528/// - \c \b IDI_HAND Hand used for warning messages
529/// - \c \b IDI_QUESTION Question mark used for prompting a response
530//
531bool
533{
534 // Delete old icon if not system icon
535 //
536 if (CurIcon && IconModule) {
537 TUser::DestroyIcon(CurIcon);
538 CurIcon = nullptr;
539 }
540
541 IconModule = module;
542 IconResId = resId;
543
544 HINSTANCE hInstance = IconModule ? HINSTANCE(*IconModule) : HINSTANCE(nullptr);
545
546 if (IconResId != 0)
547 CurIcon = TUser::LoadIcon(hInstance, IconResId);
548
549 if (CurIcon && IsWindow())
550 SendMessage(WM_SETICON, true, reinterpret_cast<LPARAM>(static_cast<HICON>(CurIcon)));
551
552 return true;
553}
554
555//
556/// Set the Small Icon (16 x 16)
557//
558bool
560{
561 // Delete old small icon
562 //
563 if (CurIconSm && IconSmModule) {
564 TUser::DestroyIcon(CurIconSm);
565 CurIconSm = nullptr;
566 }
567
568 IconSmModule = module;
569 IconSmResId = resId;
570
571 HINSTANCE hInstance = IconSmModule ? HINSTANCE(*IconSmModule) : HINSTANCE(nullptr);
572 if (IconSmResId != 0) {
573 CurIconSm = reinterpret_cast<HICON>(::LoadImage(hInstance, IconSmResId.GetPointerRepresentation(), IMAGE_ICON,
575 LR_DEFAULTCOLOR));
576 if (!CurIconSm)
577 CurIconSm = TUser::LoadIcon(hInstance, IconSmResId);
578 }
579
580 if (CurIconSm && IsWindow())
581 SendMessage(WM_SETICON, false, reinterpret_cast<LPARAM>(static_cast<HICON>(CurIconSm)));
582
583 return true;
584}
585
586//
587/// Returns a pointer to the client window. If you are trying to access a
588/// window-based object in a TMDIChild (which is a frame window), you can use this
589/// function.
590//
591TWindow*
593{
594 return ClientWnd;
595}
596
597//
598/// Sets the client window to the specified window. Users are responsible for
599/// destroying the old client window if they want to eliminate it.
600///
601/// Assume clientWnd was parented to us.
602//
603TWindow*
605{
606 TWindow* oldClientWnd = ClientWnd;
607 HWND oldWnd = oldClientWnd ? oldClientWnd->GetHandle() : static_cast<HWND>(nullptr);
608 RemoveChild(ClientWnd);
609
610 if (HWndRestoreFocus == oldWnd)
611 HWndRestoreFocus = nullptr;
612
613 ClientWnd = clientWnd;
614
615 if (ClientWnd) {
616 ClientWnd->SetParent(this);
617 if (GetHandle()) {
618 if (!ClientWnd->GetHandle())
619 ClientWnd->Create();
620 ClientWnd->ShowWindow(SW_SHOWNOACTIVATE);
621 }
622 SetBkgndColor(NoErase); // no need to erase client area
623 ResizeClientWindow(true); // !CQ defer repaint?
624 }
625 else
626 SetBkgndColor(NoColor); // will need to erase client area
627
628 // Pass the focus to the new client, but only if we have it currently
629 //
630 if (ClientWnd && ClientWnd->GetHandle() && GetFocus() == GetHandle()) {
631 ClientWnd->SetFocus();
632 HWndRestoreFocus = ClientWnd->GetHandle();
633 }
634
635 return oldClientWnd;
636}
637
638//
639/// Smart-pointer-aware overload.
640//
641auto TFrameWindow::SetClientWindow(unique_ptr<TWindow> c) -> unique_ptr<TWindow>
642{
643 auto old = unique_ptr<TWindow>{SetClientWindow(c.get())};
644 c.release(); // We took ownership.
645 return old;
646}
647
648//
649/// If someone removes our client with a RemoveChild() call, update our client
650/// and restore focus ptrs.
651//
652void
654{
656 if (child) {
657 if (child == ClientWnd)
658 ClientWnd = nullptr;
659 if (child->GetHandle() == HWndRestoreFocus) {
660 HWndRestoreFocus = nullptr;
661 }
662 }
663}
664
665//
666/// Overrides TWindow's virtual function. Pastes the number of the view into the
667/// caption and then shows the number on the screen. This function can be overridden
668/// if you don't want to use the default implementation, which displays a number on
669/// the screen. That is, you might want to write "Two" instead of ":2" on the
670/// screen. For an example of the behavior of this function, see step 12 of the
671/// ObjectWindows tutorial, which renumbers the views if one of them is closed.
672///
673/// Generates a composite title based on the caption, docname, and index
674/// if it is > 0.
675/// \code
676/// [<Title> - ]<docname>[:<index>]
677/// \endcode
678//
679bool
680TFrameWindow::SetDocTitle(LPCTSTR docname, int index)
681{
682 if (index >= 0) {
683 tstring title;
684
685 LPCTSTR c = GetCaption();
686 if (c && *c) {
687 title = c;
688 title += _T(" - ");
689 }
690
691 if (docname)
692 title += docname;
693
694 if (index > 0) {
695 title += _T(":");
696 tchar num[10];
697 _stprintf(num, _T("%d"), index );
698 title += num;
699 }
700
701 SetWindowText(title.c_str());
702 }// else if index negative, simply acknowledge that title will display
703 return true;
704}
705
706//
707// Obtain the real windows application icon. The IDI_APPLICATION icon is an
708// ugly black & white box, but when a class is registered with this icon it
709// gets substituted with a better windows icon. Worse case we end up with the
710// ugly box icon.
711//
712static HICON
713getAppIcon()
714{
715 static HICON hRealAppIcon = 0;
716 if (!hRealAppIcon) {
717 WNDCLASS wndClass;
718 static tchar className[] = _T("IconSnarfer");
719 memset(&wndClass, 0, sizeof wndClass);
720 wndClass.hInstance = GetGlobalModule().GetHandle();
721 wndClass.hIcon = ::LoadIcon(nullptr, IDI_APPLICATION);
722 wndClass.lpszClassName = className;
723 wndClass.lpfnWndProc = ::DefWindowProc;
724 ::RegisterClass(&wndClass);
725 ::GetClassInfo(GetGlobalModule().GetHandle(), className, &wndClass);
726 hRealAppIcon = wndClass.hIcon;
727 ::UnregisterClass(className, GetGlobalModule().GetHandle());
728 }
729 return hRealAppIcon ? hRealAppIcon : ::LoadIcon(nullptr, IDI_APPLICATION);
730}
731
732//
733/// Responds to a WM_QUERYDRAGICON message sent to a minimized (iconic) window that
734/// is going to be dragged. Instead of the default icon, EvQueryDragIcon uses the
735/// icon that was set using SetIcon.
736/// This member is not available under Presentation Manager.
737//
738HICON
740{
741 // !JK Consider the following problems:
742 // !JK (1) If a derived class sets CurIcon (instantiated with something other
743 // !JK than a module & res id), this function will ignore it! Why do a
744 // !JK ::LoadIcon again? It won't actually load again anyway (see MS
745 // !JK Win16/Win32 doc). It doesn't reference count either.
746 // !JK
747 // !JK (2) If IconResId is non-zero but bad (i.e., ::LoadIcon fails), getAppIcon()
748 // !JK is returned; but if IconResId is zero, TWindow::EvQueryDragIcon() is
749 // !JK returned. What is the rationale behind returning one icon in the case
750 // !JK of a bad res id and a different icon in the case of a zero res id?
751 // !JK
752 // !JK This function body should be:
753 // !JK return (CurIcon)? CurIcon: TWindow::EvQueryDragIcon();
754 // !JK -or-
755 // !JK return (CurIcon)? CurIcon: getAppIcon();
756 if (IconResId) {
757 HINSTANCE hInstance = IconModule ? HINSTANCE(*IconModule) : HINSTANCE(nullptr);
758 HICON hIcon = TUser::LoadIcon(hInstance, IconResId);
759 return hIcon ? hIcon : getAppIcon();
760 // !CQ This LoadIcon() may be causing a resource leak. May need to keep icon
761 // !CQ We are keeping it!!! CurIcon!!!
762 }
763 else
765}
766
767namespace {
768
769auto IsEnabledVisibleChild_(long style) -> bool
770{
771 return (style & (WS_CHILD | WS_VISIBLE | WS_DISABLED)) == (WS_CHILD | WS_VISIBLE);
772}
773
774auto SearchForChildWithTab_(TWindow* win) -> TWindow*
775 {
776 for (auto& child : win->GetChildren())
777 {
778 if (!child.GetHandle()) continue;
779 long style = child.GetWindowLong(GWL_STYLE);
780 if (IsEnabledVisibleChild_(style))
781 {
782 if (style & WS_TABSTOP)
783 return &child;
784 else if (const auto result = SearchForChildWithTab_(&child))
785 return result;
786 }
787 }
788 return nullptr;
789 }
790
791} // namespace
792
793//
794// If the receiver doesn't have any children then returns 0. Otherwise
795// we search for the first child with WS_TABSTOP; If no child has WS_TABSTOP
796// then we return the first enabled visible child
797//
798// Does a depth-first search of nested child windows
799//
800// NOTE: we stop at the first child with WS_TABSTOP and do not search its
801// children...
802//
803TWindow*
804TFrameWindow::FirstChildWithTab()
805{
806 const auto win = SearchForChildWithTab_(this);
807 if (win) return win;
808
809 auto c = GetChildren();
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;
813}
814
815//
816/// Overrides TWindow's virtual function. Responds to a request by a child window to
817/// hold its HWND when it is losing focus. Stores the child's HWND in
818/// HwndRestoreFocus.
819///
820/// return true if caller can stop searching for a window to hold its handle.
821//
822bool
823TFrameWindow::HoldFocusHWnd(HWND hWndLose, HWND hWndGain)
824{
825 if (IsChild(hWndLose)) {
826 if (!hWndGain || !IsChild(hWndGain))
827 HWndRestoreFocus = hWndLose;
828 return true;
829 }
830 return hWndLose == GetHandle();
831}
832
833//
834/// Restores the focus to the active window. hWndLostFocus contains the handle for
835/// the window that lost focus.
836///
837/// Handle WM_SETFOCUS to return focus back to the child that had it most
838/// recently, or find the best one to give it to otherwise.
839//
840void
841TFrameWindow::EvSetFocus(HWND hWndLostFocus)
842{
843 TWindow::EvSetFocus(hWndLostFocus);
844
845 if (!HWndRestoreFocus) {
846 HWND cmdTgt = GetCommandTarget();
847 if (cmdTgt && IsChild(cmdTgt))
848 HWndRestoreFocus = cmdTgt;
849 }
850
851// if (HWndRestoreFocus == hWndLostFocus)
852// HWndRestoreFocus = GetHandle();
853
854 if (HWndRestoreFocus) {
855 // Set focus to the saved HWND as long as it is still a valid window handle
856 //
857 if (::IsWindow(HWndRestoreFocus))
858 ::SetFocus(HWndRestoreFocus);
859 else
860 HWndRestoreFocus = nullptr;
861 }
862}
863
864//
865/// Responds to a message to notify the parent window that a given event has
866/// occurred. If the client window is destroyed, closes the parent window. If
867/// shrinkToClient is set and the child window has changed size, the frame is
868/// adjusted.
869/// When a TFrameWindow's client window is destroyed, the TFrameWindow object sees
870/// the WM_PARENTNOTIFY message and posts a close message to itself. Without this
871/// message, an empty frame would remain and the client window would then have to
872/// determine how to destroy the frame. If you don't want this to happen, you can
873/// derive from the frame window and have your application handle the EvParentNotify
874/// or EvClose messages.
875//
876void
878{
879 switch (n.Event)
880 {
881 case WM_DESTROY:
882 {
883 const TParentNotifyChildInfo& i = static_cast<const TParentNotifyChildInfo&>(n);
884 if (ClientWnd && ClientWnd->GetHandle() == i.Child)
885 PostMessage(WM_CLOSE); // Using ShutDownWindow() has side effects.
886 TWindow* c = GetWindowPtr(i.Child);
887 if (c)
889 }
890 break;
891
892 case WM_SIZE: // TODO: This is not a documented event for the WM_PARENTNOTIFY message. Investigate.
893 {
894 const TParentNotifyChildInfo& i = static_cast<const TParentNotifyChildInfo&>(n);
895 if (IsFlagSet(wfShrinkToClient) && ClientWnd && ClientWnd->GetHandle() == i.Child && !IsIconic())
896 ResizeClientWindow(true);
897 }
898 break;
899 }
901}
902
903//
904/// Forwards the WM_QUERYNEWPALETTE message to the client window.
905//
906bool
914
915//
916/// Forwards the WM_PALETTECHANGED message to the client window.
917//
918void
920{
921 if (GetClientWindow())
923 else
924 TWindow::EvPaletteChanged(hWndPalChg);
925}
926
927//
928// Resize & reposition the client window to fit in this frames client area
929// or resize the frame to fit around the client's client area if
930// wfShrinkToClient
931// Return true if a client was actualy resized.
932// Adjust clients styles & make sure they get set.
933//
934bool
935TFrameWindow::ResizeClientWindow(bool repaint)
936{
937/// bool hasThickFrame = Attr.Style & WS_THICKFRAME;
938/// Attr.Style |= WS_THICKFRAME;
939
940 // Nothing to resize if there's not Client window
941 //
942 if (!ClientWnd)
943 return false;
944
945 // Prevent recursion during resize by ignore calls from EvParentNotify and
946 // EvSize when we have already been called.
947 // Do this by disabling notifications while resizing using the
948 // wfShrinkToClient flag as a semaphore on the client
949 //
950 if (ClientWnd->IsFlagSet(wfShrinkToClient))
951 return true;
952 ClientWnd->SetFlag(wfShrinkToClient);
953
954 bool clientResized = false;
955 TSize clientAreaSize = GetClientRect().Size();
956 TSize childSize = ClientWnd->GetWindowRect().Size();
957
958 // First time through, strip client window of thick borders.
959 // If shrink-to-client, then must measure the client size first
960 // If the client has scrolls bars, we must hide them to obtain the correct
961 // size.
962 // Border style is left on & dealt with by hand below
963 //
964 const uint32 badClientStyles = WS_DLGFRAME | WS_THICKFRAME | // bad borders
965 WS_POPUP | WS_OVERLAPPED; // bad parenting
966 const uint32 badClientExStyles = WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE |
967 WS_EX_STATICEDGE; // more bad borders
968
969 if ((ClientWnd->GetStyle() & badClientStyles) ||
970 (ClientWnd->GetExStyle() & badClientExStyles)) {
972 TSize tstSize = ClientWnd->GetClientRect().Size();
973 ClientWnd->ShowScrollBar(SB_BOTH, false);
974 childSize = ClientWnd->GetClientRect().Size();
975 if (childSize != tstSize) {
976 int restore = SB_BOTH;
977 if (childSize.cx == tstSize.cx)
978 restore = SB_HORZ;
979 if (childSize.cy == tstSize.cy)
980 restore = SB_VERT;
981 ClientWnd->ShowScrollBar(restore, true);
982 }
983 }
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 );
990 if (reparent)
991 ::SetParent(*ClientWnd, *this);
992 }
993 if (ClientWnd->GetExStyle() & badClientExStyles) {
994 uint32 exStyle = ClientWnd->GetExStyle();
995 exStyle &= ~badClientExStyles;
996 ClientWnd->SetExStyle( exStyle );
997 }
998 }
999 if (ClientWnd->GetStyle() & WS_BORDER) {
1000 childSize = ClientWnd->GetClientRect().Size();
1001 }
1002 if (childSize != clientAreaSize) {
1004 TRect outside = GetWindowRect();
1005 TSize border = outside.Size() - clientAreaSize;
1006 SetWindowPos(nullptr, 0, 0,
1007 childSize.cx + border.cx, childSize.cy + border.cy,
1008 SWP_NOACTIVATE|SWP_NOMOVE| (repaint ? 0 : SWP_NOREDRAW));
1009 clientAreaSize = childSize; // Must move client, will not cause an EvSize
1010 }
1011 else {
1012 clientResized = true; // Client will get resized
1013 }
1014 }
1015 // If frame is sizeable, turn off flag so that user can then resize
1016 // after initial setup
1017 //
1018 if (Attr.Style & WS_THICKFRAME && !TYPESAFE_DOWNCAST(this, TFloatingSlip))
1020
1021
1022/// if (!hasThickFrame) {
1023/// Attr.Style &= ~WS_THICKFRAME;
1024/// }
1025
1026 // Handle simple border style by shoving the client's borders under the frame
1027 // This code MUST not resize the client if shrinkToClient
1028 // !CQ use SetWindowPos() to get at SWP_NOSIZE?
1029 //
1030 if (ClientWnd->GetStyle() & WS_BORDER) {
1031 int bx = TUIMetric::CxBorder;
1032 int by = TUIMetric::CyBorder;
1033 ClientWnd->MoveWindow(-bx, -by, clientAreaSize.cx+bx+bx,
1034 clientAreaSize.cy+by+by, repaint);
1035 }
1036 else
1037 ClientWnd->MoveWindow(0, 0, clientAreaSize.cx, clientAreaSize.cy, repaint);
1038
1039 // Turn off semaphore bit
1040 //
1041 ClientWnd->ClearFlag(wfShrinkToClient);
1042 return clientResized;
1043}
1044
1045//
1046/// Calls TWindow::SetUpWindow to create windows in a child list. SetupWindow
1047/// performs the initial adjustment of the client window if one exists, assigns the
1048/// frame's menu based on the menu descriptor, and initializes HwndRestoreFocus.
1049//
1050void
1052{
1053 // Create windows in child list (this includes the client window)
1054 //
1056
1057 ResizeClientWindow(true); // !CQ defer repaint?
1058
1059 if (MinimizedPos != TPoint(-1,-1)) {
1060 auto windata = GetWindowPlacement();
1061 windata.flags = WPF_SETMINPOSITION;
1062 windata.showCmd = SW_SHOWNA;
1063 windata.ptMinPosition = MinimizedPos;
1064 SetWindowPlacement(windata);
1065 }
1066
1067 // If SetMenuDescr() was called before window created, update the menu now
1068 //
1069 if (IsFlagSet(wfMainWindow) && MenuDescr) {
1070 HMENU curMenu = GetMenu();
1071 TMenu newMenu(*MenuDescr, NoAutoDelete);
1072 if (SetMenu(newMenu)) {
1073 if (curMenu)
1074 ::DestroyMenu(curMenu);
1075 }
1076 else
1077 ::DestroyMenu(newMenu);
1078 }
1079
1080 // If we haven't set THandleRestoreFocus then pick the first child with tabstop
1081 //
1082 if (!HWndRestoreFocus) {
1083///TH Previous version would be to search for first child with tabstop.
1084///TH Why not use CommandTarget?
1085// !BB Because it breaks when GetCommandTarget returns a non-child window
1086// !BB Please, leave this code AS IS?
1087#if 1
1088 TWindow* win = FirstChildWithTab();
1089 HWndRestoreFocus = win ? win->GetHandle() : GetHandle();
1090#else
1091 HWND cmdTgt = GetCommandTarget();
1092 if (cmdTgt && IsChild(cmdTgt))
1093 HWndRestoreFocus = cmdTgt;
1094#endif
1095 }
1096
1097 if (CurIcon)
1098 SendMessage(WM_SETICON, true, reinterpret_cast<LPARAM>(CurIcon));
1099
1100 if (CurIconSm)
1101 SendMessage(WM_SETICON, false, reinterpret_cast<LPARAM>(CurIconSm));
1102}
1103
1104//
1105/// Cleans up any associated icons.
1106//
1107void
1109{
1110 // icon cleanup
1111 //
1112 SetIcon(nullptr, 0);
1113 SetIconSm(nullptr, 0);
1114
1116}
1117
1118//
1119/// Tell child windows frame has minimized/maximized/restored
1120/// (They may want to change enabled state or release/restore resources)
1121//
1122void
1124{
1125 if (sizeType == SIZE_MINIMIZED
1126 || sizeType == SIZE_MAXIMIZED
1127 || sizeType == SIZE_RESTORED)
1128 {
1129 ChildBroadcastMessage(WM_OWLFRAMESIZE, sizeType, reinterpret_cast<TParam2>(&size));
1130 }
1131}
1132
1133//
1134/// Response method for an incoming WM_SIZE message
1135///
1136/// Resizes the client window' so that it is equivalent to the client rectangle's
1137/// size. Calls TWindow::EvSize() in response to an incoming WM_SIZE message.
1138///
1139/// If no WM_SIZE sent, forwards WM_SIZE message to client so it can recalc.
1140//
1141void
1142TFrameWindow::EvSize(uint sizeType, const TSize& size)
1143{
1144 TWindow::EvSize(sizeType, size);
1145 TSize newSize = size;
1146
1147 if (ClientWnd) {
1148 bool sizeSent = false;
1149 if (sizeType != SIZE_MINIMIZED) {
1150 sizeSent = ResizeClientWindow(true); // !CQ defer repaint?
1151 newSize = ClientWnd->GetClientRect().Size();
1152 }
1153 if (!sizeSent)
1154 ClientWnd->ForwardMessage();
1155 }
1156
1157 BroadcastResizeToChildren(sizeType, newSize);
1158}
1159
1160
1161//
1162/// Sets the menu descriptor to the new menu descriptor.
1163//
1164void
1166{
1167 if (&menuDescr != MenuDescr) // Guard against self-assignment (the latter is useful for refreshing the menu).
1168 {
1169 delete MenuDescr;
1170 MenuDescr = new TMenuDescr(menuDescr);
1171 }
1172
1173 if (IsFlagSet(wfMainWindow) && GetHandle()) {
1174 HMENU curMenu = GetMenu();
1175 TMenu newMenu(*MenuDescr, NoAutoDelete);
1176 if (SetMenu(newMenu))
1177 ::DestroyMenu(curMenu);
1178 else
1179 ::DestroyMenu(newMenu);
1180 }
1181}
1182
1183//
1184/// Sets the control bar descriptor to the new bar descriptor.
1185//
1186void
1188{
1189 if(DeleteBar)
1190 delete BarDescr;
1191 BarDescr = barDescr;
1192 DeleteBar = delonClose == AutoDelete;
1194 RestoreBar();
1195}
1196
1197//
1198/// Merges the given menu descriptor with this frame's own menu descriptor and
1199/// displays the resulting menu in this frame. See TMenuDescr for a description of
1200/// menu bar types that can be merged.
1201///
1202/// Optionally use an existing HMENU to merge into & set
1203//
1204bool
1206{
1207 if (!MenuDescr || !GetHandle())
1208 return false;
1209
1210 MergeModule = childMenuDescr.GetModule();
1211 TMenu curMenu(*this, NoAutoDelete);
1212 TMenu newMenu(NoAutoDelete);
1213
1214 MenuDescr->Merge(childMenuDescr, newMenu);
1215
1217 GetApplication()->PreProcessMenu(newMenu);
1218
1219 if (SetMenu(newMenu)) {
1220 ::DestroyMenu(curMenu);
1221 return true;
1222
1223 }
1224 else {
1225 ::DestroyMenu(newMenu);
1226 return false;
1227 }
1228
1229}
1230
1231//
1232// Restores this frame window's menu to the one described by our menu
1233// descriptor
1234//
1235bool
1237{
1238 if (!MenuDescr)
1239 return false;
1240
1241 HMENU curMenu = GetMenu();
1242 TMenu newMenu(*MenuDescr, NoAutoDelete);
1243 if (SetMenu(newMenu)) {
1244 MergeModule = nullptr;
1245 ::DestroyMenu(curMenu);
1246 }
1247 else
1248 ::DestroyMenu(newMenu);
1249 return true;
1250}
1251
1252
1253
1255
1256#if OWL_PERSISTENT_STREAMS
1257
1258//
1259// Reads data of the uninitialized TFrameWindow from the passed ipstream
1260//
1261
1262void*
1263TFrameWindow::Streamer::Read(ipstream& is, uint32 version) const
1264{
1265 TFrameWindow* o = GetObject();
1266 ReadVirtualBase((TWindow*)o, is);
1267 if (o->IsFlagSet(wfMainWindow))
1268 return o;
1269
1270 is >> o->ClientWnd;
1271 is >> o->KeyboardHandling;
1272 o->HWndRestoreFocus = 0;
1273
1274 bool hasMenuDescr = is.readByte();
1275 if (hasMenuDescr) {
1276 o->MenuDescr = new TMenuDescr;
1277 is >> *o->MenuDescr;
1278 }
1279 else
1280 o->MenuDescr = 0;
1281
1282 o->BarDescr = 0;
1283 if(version > 2){
1284 bool hasBarDescr = is.readByte();
1285 if (hasBarDescr) {
1286 o->BarDescr = new TBarDescr;
1287 is >> *o->BarDescr;
1288 }
1289 }
1290
1291 // stream in window icon information
1292 //
1293 is >> o->IconModule;
1294 TResId iconResId;
1295 is >> iconResId;
1296 o->IconResId = InternStreamedResId_(iconResId);
1297 if (version > 1) {
1298 is >> o->IconSmModule;
1299 TResId iconSmResId;
1300 is >> iconSmResId;
1301 o->IconSmResId = InternStreamedResId_(iconSmResId);
1302 }
1303 else {
1304 o->IconSmModule = 0;
1305 o->IconSmResId = 0;
1306 }
1307
1308 // load the window's icons
1309 //
1310 o->CurIcon = 0;
1311 o->CurIconSm = 0;
1312 o->SetIcon(o->IconModule, o->IconResId);
1313 o->SetIconSm(o->IconSmModule, o->IconSmResId);
1314
1315 is >> o->MergeModule;
1316 is >> o->MinimizedPos;
1317
1318 return o;
1319}
1320
1321//
1322// Writes data of the TFrameWindow to the passed opstream
1323//
1324void
1325TFrameWindow::Streamer::Write(opstream& os) const
1326{
1327 TFrameWindow* o = GetObject();
1328 WriteVirtualBase((TWindow*)o, os);
1329 if (o->IsFlagSet(wfMainWindow))
1330 return;
1331
1332 os << o->ClientWnd;
1333 os << o->KeyboardHandling;
1334
1335 os.writeByte(uint8(o->MenuDescr ? 1 : 0));
1336 if (o->MenuDescr)
1337 os << *o->MenuDescr;
1338
1339 // added in stream ver 3
1340 os.writeByte(uint8(o->BarDescr ? 1 : 0));
1341 if (o->BarDescr)
1342 os << *o->BarDescr;
1343
1344 os << o->IconModule;
1345 os << o->IconResId;
1346 os << o->IconSmModule; // added in stream ver 2
1347 os << o->IconSmResId; // added in stream ver 2
1348
1349 os << o->MergeModule;
1350 auto windata = o->GetWindowPlacement();
1351 os << TPoint(windata.ptMinPosition);
1352}
1353
1354#endif
1355
1356
1357} // OWL namespace
1358
Definition of class TApplication.
Class definition for TBarDescr.
#define DIAG_DECLARE_GROUP(group)
Definition checks.h:404
#define TRACEX(group, level, message)
Definition checks.h:263
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.
Definition applicat.h:768
Descriptor of Bar Implementation.
Definition bardescr.h:71
Base class for an extensible interface for auto enabling/disabling of commands (menu items,...
Definition window.h:209
virtual void Enable(bool enable=true)
Enables or disables the command sender.
Definition window.cpp:301
@ Checked
Command is enabled.
Definition window.h:227
Derived from TWindow, TFrameWindow controls such window-specific behavior as keyboard navigation and ...
Definition framewin.h:96
auto IdleAction(long idleCount) -> bool override
Overrides TWindow's virtual function.
Definition framewin.cpp:294
void Init(TWindow *clientWnd, bool shrinkToClient)
Normal initialization of a default constructed TFrameWindow.
Definition framewin.cpp:167
~TFrameWindow() override
Destructor for a TFrameWindow.
Definition framewin.cpp:221
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.
Definition framewin.cpp:592
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.
Definition framewin.cpp:680
void EvCommandEnable(TCommandEnabler &) override
Handle WM_COMMAND_ENABLE to provide command enable distribution and default support for windows witho...
Definition framewin.cpp:424
virtual bool RestoreBar()
Do nothing in TFrameWindow. Overriden in TDecoratedFrame.
Definition framewin.h:341
virtual bool SetMenu(HMENU newMenu)
Overrides TWindow's non-virtual SetMenu function, thus allowing derived classes the opportunity to im...
Definition framewin.cpp:472
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.
Definition framewin.cpp:919
virtual HWND GetCommandTarget()
Locates and returns the child window that is the target of the command and command enable messages.
Definition framewin.cpp:329
auto HoldFocusHWnd(HWND hWndLose, HWND hWndGain) -> bool override
Overrides TWindow's virtual function.
Definition framewin.cpp:823
auto PreProcessMsg(MSG &) -> bool override
Overrides TWindow's virtual function.
Definition framewin.cpp:437
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...
Definition framewin.cpp:388
bool EvQueryNewPalette()
Forwards the WM_QUERYNEWPALETTE message to the client window.
Definition framewin.cpp:907
virtual TWindow * SetClientWindow(TWindow *clientWnd)
Sets the client window to the specified window.
Definition framewin.cpp:604
void EvParentNotify(const TParentNotify &)
Responds to a message to notify the parent window that a given event has occurred.
Definition framewin.cpp:877
bool SetIconSm(TModule *iconModule, TResId iconResIdSm)
Set the Small Icon (16 x 16).
Definition framewin.cpp:559
bool SetIcon(TModule *iconModule, TResId iconResId)
Sets the icon in the module specified in iconModule to the resource ID specified in iconResId.
Definition framewin.cpp:532
HICON EvQueryDragIcon()
Responds to a WM_QUERYDRAGICON message sent to a minimized (iconic) window that is going to be dragge...
Definition framewin.cpp:739
virtual bool AssignMenu(TResId menuResId)
Perform a high-level menu assignment either before or after the HWND for the window has been created.
Definition framewin.cpp:492
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.
Definition framewin.cpp:841
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...
Definition framewin.cpp:265
TFrameWindow()
< String-aware overload
Definition framewin.cpp:152
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.
Definition framewin.cpp:653
Menu with information used to allow merging.
Definition menu.h:206
TModule * GetModule() const
Returns a pointer to the module object.
Definition menu.h:279
TMenuDescr()
Default constructor for a TMenuDescr object.
Definition menudesc.cpp:165
The TMenu class encapsulates window menus.
Definition menu.h:77
TMenuItemEnabler(HMENU hMenu, uint id, HWND hWndReceiver, int position)
Constructs a TMenuItemEnabler with the specified command ID for the menu item, message responder (hWn...
Definition framewin.h:266
void SetCheck(int check)
< String-aware overload
Definition framewin.cpp:71
void SetText(LPCTSTR text)
Overrides TCommandEnable::SetText. Changes the text of the corresponding menu.
Definition framewin.cpp:60
void Enable(bool enable)
Overrides TCommandEnable::Enable.
Definition framewin.cpp:49
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:78
TPoint()
Constructs an uninitialized point.
Definition geometry.h:413
TSize Size() const
Returns the size of rectangle.
Definition geometry.h:1057
bool IsString() const
Returns true if this resource identifier encodes a string pointer.
Definition wsyscls.h:86
The tagSIZE struct is defined as.
Definition geometry.h:234
static const TUIMetric CyBorder
Definition uimetric.h:40
static const TUIMetric CySmIcon
Definition uimetric.h:84
static const TUIMetric CxBorder
Definition uimetric.h:39
static const TUIMetric CxSmIcon
Definition uimetric.h:83
static BOOL DestroyIcon(HICON)
Definition module.cpp:1078
static HICON LoadIcon(HINSTANCE, LPCTSTR)
Definition module.cpp:1067
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
HWND SetFocus()
Sets the keyboard focus to current window and activates the window that receives the focus by sending...
Definition window.h:2151
void ShowScrollBar(int bar, bool show=true)
Displays or hides the scroll bar.
Definition window.h:3043
HMENU LoadMenu(TResId id) const
Definition window.h:611
bool SetMenu(HMENU hMenu)
Sets the specified window's menu to the menu indicated by hMenu.
Definition window.h:3278
virtual void SetParent(TWindow *newParent)
Sets the parent for the specified window by setting Parent to the specified new Parent window object.
Definition window.cpp:738
TApplication * GetApplication() const
Gets a pointer to the TApplication object associated with this.
Definition window.h:1855
void ChildBroadcastMessage(TMsgId, TParam1=0, TParam2=0)
Sends the specified message to all immediate children using SendMessage.
Definition window.cpp:3340
void SetBkgndColor(TColor color, bool shouldUpdate=true)
Sets the background color for the window.
Definition window.h:1925
void DrawMenuBar()
DrawMenuBar redraws the menu bar.
Definition window.h:3313
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...
Definition window.cpp:341
bool SetWindowPos(HWND hWndInsertAfter, const TRect &rect, uint flags)
Changes the size of the window pointed to by rect.
Definition window.h:2809
virtual bool PreProcessMsg(MSG &msg)
Called from TApplication::ProcessAppMsg() to give the window an opportunity to perform preprocessing ...
Definition window.cpp:644
auto GetChildren()
Returns a TWindow::TChildrenRange that can be iterated by standard means.
Definition window.h:550
TWindow * GetParent() const
Retrieves the OWL object of the parent window. If none exists, returns 0.
Definition window.h:2013
TWindow * GetWindowPtr(HWND hWnd) const
Calls TApplication:GetWindowPtr on the application associated with this window.
Definition window.h:3567
virtual void RemoveChild(TWindow *child)
Removes a child window.
Definition window.cpp:707
void SetWindowPlacement(const WINDOWPLACEMENT &place)
Wrapper for Windows API.
Definition window.cpp:3967
HICON EvQueryDragIcon()
The default message handler for WM_QUERYDRAGICON.
Definition window.h:4021
long GetWindowLong(int index) const
Retrieves information about the window depending on the value stored in index.
Definition window.h:2388
void Init(TWindow *parent, LPCTSTR title, TModule *module)
Normal initialization of a default constructed TWindow.
Definition window.cpp:401
void SetFlag(uint mask)
Sets the specified TWindow wfXxxx constant flags (for example wfAlias, wfTransfer,...
Definition window.h:1783
WINDOWPLACEMENT GetWindowPlacement() const
Wrapper for Windows API.
Definition window.cpp:3950
auto GetClassName(TCHAR *className, int maxCount) const -> int
Returns the Windows class name for this object's window handle.
Definition window.h:2307
bool EvQueryNewPalette()
The default message handler for WM_QUERYNEWPALETTE.
Definition window.h:4028
void RouteCommandEnable(HWND hInitCmdTarget, TCommandEnabler &ce)
Walks the chain of windows from the initial target window to this window.
Definition window.cpp:1161
bool IsIconic() const
Returns true if window is iconic or minimized.
Definition window.h:2628
bool IsWindow() const
Returns true if an HWND is being used.
Definition window.h:2040
bool IsChild(HWND hWnd) const
Returns true if the window is a child window or a descendant window of this window.
Definition window.h:3176
uint32 GetExStyle() const
Gets the extra style bits of the window.
Definition window.cpp:3575
virtual void CleanupWindow()
Always called immediately before the HWindow becomes invalid, CleanupWindow gives derived classes an ...
Definition window.cpp:2640
void GetWindowRect(TRect &rect) const
Gets the screen coordinates of the window's rectangle and copies them into rect.
Definition window.cpp:3609
HMENU GetMenu() const
Returns the handle to the menu of the indicated window.
Definition window.h:3244
TResult HandleMessage(TMsgId, TParam1=0, TParam2=0)
Dispatches the given message using the response table.
Definition window.cpp:1392
virtual bool IdleAction(long idleCount)
Called when no messages are waiting to be processed, IdleAction performs idle processing as long as t...
Definition window.cpp:671
uint32 GetStyle() const
Gets the style bits of the underlying window or the 'Style' member of the attribute structure associa...
Definition window.cpp:3558
LPCTSTR GetCaption() const
Returns the Title member of TWindow.
Definition window.h:1900
TResult ForwardMessage(HWND handle, bool send=true)
Forwards the window's current message.
Definition window.cpp:3302
TResult DefaultProcessing()
Handles default processing of events, which includes continued processing of menu/accelerators comman...
Definition window.cpp:852
TRect GetClientRect() const
Gets the coordinates of the window's client area (the area in a window you can use for drawing).
Definition window.h:2217
void SetWindowText(LPCTSTR str)
Sets the window's text to the given string (by copying).
Definition window.h:2669
virtual TResult EvCommand(uint id, HWND hWndCtl, uint notifyCode)
WindowProc calls EvCommand to handle WM_COMMAND messages.
Definition window.cpp:999
void EvSetFocus(HWND hWndLostFocus)
The default message handler for WM_SETFOCUS.
Definition window.h:4084
void ClearFlag(uint mask)
Clears the specified TWindow wfXxxx constant flags (for example wfAlias, wfTransfer,...
Definition window.h:1790
bool PostMessage(TMsgId, TParam1=0, TParam2=0)
Posts a message (msg) to the window in the application's message queue.
Definition window.h:2103
TResult SendMessage(TMsgId, TParam1=0, TParam2=0) const
Sends a message (msg) to a specified window or windows.
Definition window.cpp:3288
virtual void SetupWindow()
Performs setup following creation of an associated MS-Windows window.
Definition window.cpp:2575
bool IsFlagSet(uint mask)
Returns the state of the bit flag in Attr.Flags whose mask is supplied.
Definition window.h:1797
static HWND GetFocus()
Gets a handle to the window that has the focus.
Definition window.h:2139
void EvSize(uint sizeType, const TSize &size)
Response method for an incoming WM_SIZE message.
Definition window.cpp:1632
void EnableAutoCreate()
Ensures that an associated child window interface element is created and displayed along with its par...
Definition window.h:1805
void EvPaletteChanged(HWND hWndPalChg)
The default message handler for WM_PALETTECHANGED.
Definition window.h:3960
void GetClientRect(TRect &rect) const
Gets the coordinates of the window's client area and then copies them into the object referred to by ...
Definition window.cpp:3624
HWND THandle
TWindow encapsulates an HWND.
Definition window.h:418
void EvInitMenuPopup(HMENU hPopupMenu, uint index, bool isSysMenu)
Handle WM_INITMENUPOPUP while embeded to generate command enable messages for our server menu items.
Definition window.cpp:3809
HWND GetHandle() const
Returns the handle of the window.
Definition window.h:2020
ipstream, a specialized input stream derivative of pstream, is the base class for reading (extracting...
Definition objstrm.h:391
uint8 readByte()
Returns the byte at the current stream position.
Definition objstrm.cpp:368
Base class for writing streamable objects.
Definition objstrm.h:480
#define _stprintf
Definition cygwin.h:88
#define _tcsicmp
Definition cygwin.h:76
#define _T(x)
Definition cygwin.h:51
#define WM_OWLFRAMESIZE
Notify children of frame resizing.
Definition dispatch.h:4114
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 eventhan.h:492
#define WM_SETICON
Definition framewin.cpp:27
Definition of class TFrameWindow.
TAutoDelete
Flag for Handle ctors to control Handle deletion in dtor.
Definition gdibase.h:70
void ReadVirtualBase(Base *base, ipstream &in)
Definition objstrm.h:1190
void WriteVirtualBase(Base *base, opstream &out)
Definition objstrm.h:1169
@ AutoDelete
Definition gdibase.h:70
@ NoAutoDelete
Definition gdibase.h:70
THandle GetHandle() const
Return the instance handle of the library module represented by the TModule obect.
Definition module.h:1236
#define NoErase
don't erase, wait for Paint
Definition window.h:116
#define NoColor
let DefWindowProc erase
Definition window.h:115
@ wfMainWindow
This frame window is the main window.
Definition window.h:63
@ wfFullyCreated
Window is fully created & not being destroyed.
Definition window.h:64
@ wfShrinkToClient
Shrink a frame window to its client's size.
Definition window.h:62
char * strnewdup(const char *s, size_t minAllocSize=0)
Definition memory.cpp:25
Definition of Window Menu encapsulation class.
Object Windows Library (OWLNext Core).
Definition animctrl.h:22
EV_WM_INITMENUPOPUP
Definition framewin.cpp:36
EV_WM_PALETTECHANGED
Definition framewin.cpp:41
unsigned char uint8
Definition number.h:32
unsigned long uint32
Definition number.h:34
char tchar
Definition defs.h:77
LPARAM TParam2
Second parameter type.
Definition dispatch.h:55
WPARAM TParam1
First parameter type.
Definition dispatch.h:54
TDispatch< WM_PARENTNOTIFY >::TArgs TParentNotify
Alias for convenience.
Definition dispatch.h:2894
EV_WM_SETFOCUS
Definition edit.cpp:84
EV_WM_PARENTNOTIFY
Definition docking.cpp:967
END_RESPONSE_TABLE
Definition button.cpp:26
EV_WM_QUERYNEWPALETTE
Definition framewin.cpp:40
LRESULT TResult
Result type.
Definition dispatch.h:52
std::string tstring
Definition defs.h:79
EV_WM_QUERYDRAGICON
Definition framewin.cpp:35
unsigned int uint
Definition number.h:25
TDispatch< WM_PARENTNOTIFY >::TChildInfoArgs TParentNotifyChildInfo
Alias for convenience.
Definition dispatch.h:2895
TModule & GetGlobalModule()
Definition global.cpp:48
EV_WM_SIZE
Definition decframe.cpp:34
IMPLEMENT_STREAMABLE1(TApplication, TModule)
auto InternStreamedResId_(TResId id) -> TResId
Definition strmresid.h:37
#define OWL_DIAGINFO
Definition defs.h:173
#define COUNTOF(s)
Array element count Important: Only use this with an argument of array type.
Definition defs.h:376
#define TYPESAFE_DOWNCAST(object, toClass)
Definition defs.h:269
Private helper for reading resource identifiers from persistent streams.
Definition of TUIMetric, a UI metrics provider class.
#define WS_EX_STATICEDGE
Definition wsysinc.h:60
#define WS_EX_WINDOWEDGE
Definition wsysinc.h:30