OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
rolldial.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1995, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Implementation of class TRollDialog, an automatic roll-up dialog
7//----------------------------------------------------------------------------
8#include <owl/pch.h>
9#include <owl/rolldial.h>
10#include <owl/menu.h>
11
12namespace owl {
13
15
16//
17// Fibonacci sequence used for accelerated animation.
18//
19static uint32 Fibonacci(int n)
20{
21 if (n == 0 || n == 1) {
22 return 1;
23 }
24 uint32 older = 1;
25 uint32 old = 1;
27
28 for (int i = 2; i < n; i++) {
29 older = old;
30 old = answer;
31 answer = old + older;
32 }
33 return answer;
34}
35
36
37DEFINE_RESPONSE_TABLE1(TRollDialog, TDialog)
40
41//
42/// Sets up data members for the various properties of the dialog.
43//
45 bool fullSize, TModule* module)
46:
47 TDialog(parent, resId, module),
48 IsFullSize(true),
49 InitialFullSize(fullSize),
50 WantAnimation(animated)
51{
52}
53
54//
55/// Adds the shrink system menu option, if desired. This also shrinks the dialog if
56/// that option was chosen.
57//
58void
60{
62
63 // Add to system menu if present
64 //
65 if (GetStyle() & WS_SYSMENU) {
66 TSystemMenu menu(*this);
67#if defined(BI_MSG_LANGUAGE) && BI_MSG_LANGUAGE == 0x0411
68 menu.AppendMenu(MF_STRING, SC_ROLLDIALOG, "k(&S)");
69#else
70 menu.AppendMenu(MF_STRING, SC_ROLLDIALOG, _T("&Shrink"));
71#endif
72 HasSystemMenu = true;
73 }
74
75 if (!InitialFullSize)
76 Shrink();
77}
78
79//
80/// Resize the dialog to either full size or minimal size.
81//
82void
83TRollDialog::Resize(bool currentlyFullSize)
84{
86 int oldBottom = r.bottom;
87
88 if (WantAnimation) {
89 int delta = 0;
90 for (int step = 0; delta < Height; step++) {
92 r.bottom = oldBottom - delta;
93 else
94 r.bottom = oldBottom + delta;
95 MoveWindow(r, true); // !CQ Use SetWindowPos(...,SWP_NOMOVE) ?
96 delta = static_cast<int>(Fibonacci(step));
97 }
98 }
99
101 r.bottom = oldBottom - Height;
102 else
103 r.bottom = oldBottom + Height;
104
105 MoveWindow(r, true);
106}
107
108//
109/// Event handler for the system menu option "shrink". Toggles the system menu
110/// choice to "expand".
111//
112void
114{
115 if (IsFullSize) {
116 Height = GetClientRect().Height() + 1;
117
118 Resize(IsFullSize);
119 IsFullSize = false;
120
121 if (HasSystemMenu) {
122 TSystemMenu menu(*this);
123 menu.ModifyMenu(SC_ROLLDIALOG, MF_BYCOMMAND | MF_STRING, SC_ROLLDIALOG,
125 "WJ(&E)");
126#else
127 _T("&Expand"));
128#endif
129 }
130 }
131}
132
133//
134/// Event handler for the system menu option "expand". Toggles the system menu
135/// choice to "shrink".
136//
137void
139{
140 if (!IsFullSize) {
141 Resize(IsFullSize);
142 IsFullSize = true;
143
144 if (HasSystemMenu) {
145 TSystemMenu menu(*this);
146 menu.ModifyMenu(SC_ROLLDIALOG, MF_BYCOMMAND | MF_STRING, SC_ROLLDIALOG,
147#if BI_MSG_LANGUAGE == 0x0411
148 "k(&S)");
149#else
150 _T("&Shrink"));
151#endif
152 }
153 }
154}
155
156//
157/// Event handler for the system menu choice. Calls either TRollDialog::Shrink or
158/// TRollDialog::Expand.
159//
160void
162{
163 uint command = cmdType & 0xFFF0;
164
165 if (command == SC_ROLLDIALOG || command == SC_RESTORE) {
166 if (IsFullSize)
167 Shrink();
168 else
169 Expand();
170 }
171 else if (command == SC_MINIMIZE)
172 Shrink();
173 else if (command == SC_MAXIMIZE)
174 Expand();
175 else
177}
178
179
180} // OWL namespace
181/* ========================================================================== */
182
Typically used to obtain information from a user, a dialog box is a window inside of which other cont...
Definition dialog.h:85
void SetupWindow() override
Overrides the virtual function defined in TWindow.
Definition dialog.cpp:825
bool ModifyMenu(uint item, uint flags, TMenuItem newItem=-1, LPCTSTR newStr=nullptr)
Changes an existing menu item from the item specified in item to newItem.
Definition menu.h:480
bool AppendMenu(uint flags, TMenuItem newItem=static_cast< unsigned int >(-1), LPCTSTR newStr=nullptr)
Adds a text menu item to the end of the menu.
Definition menu.h:342
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:75
TPoint is a support class, derived from tagPOINT.
Definition geometry.h:87
TRect is a mathematical class derived from tagRect.
Definition geometry.h:308
int Height() const
Returns the height of this rectangle (bottom - top).
Definition geometry.h:1048
void Expand()
Event handler for the system menu option "expand".
Definition rolldial.cpp:138
void SetupWindow() override
Adds the shrink system menu option, if desired.
Definition rolldial.cpp:59
bool IsFullSize
track if the dialog is currently full size
Definition rolldial.h:51
void Shrink()
Event handler for the system menu option "shrink".
Definition rolldial.cpp:113
void EvSysCommand(uint, const TPoint &)
Event handler for the system menu choice.
Definition rolldial.cpp:161
TRollDialog(TWindow *parent, TResId resId, bool animated=true, bool fullSize=true, TModule *module=0)
Sets up data members for the various properties of the dialog.
Definition rolldial.cpp:44
TSystemMenu creates a system menu object that then becomes the existing system menu.
Definition menu.h:175
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
TRect GetWindowRect() const
Gets the screen coordinates of the window's rectangle.
Definition window.h:2257
bool MoveWindow(int x, int y, int w, int h, bool repaint=false)
Repositions the specified window.
Definition window.h:2571
uint32 GetStyle() const
Gets the style bits of the underlying window or the 'Style' member of the attribute structure associa...
Definition window.cpp:3558
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 EvSysCommand(uint cmdType, const TPoint &point)
Responds to a user-selected command from the System menu or when the user selects the maximize or min...
Definition window.h:4014
#define _T(x)
Definition cygwin.h:51
#define DEFINE_RESPONSE_TABLE1(cls, base)
Macro to define a response table for a class with one base.
Definition eventhan.h:492
Definition of Window Menu encapsulation class.
Height
Definition occtrl.cpp:160
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
EV_WM_SYSCOMMAND
Definition floatfra.cpp:26
unsigned long uint32
Definition number.h:34
OWL_DIAGINFO
Definition animctrl.cpp:14
END_RESPONSE_TABLE
Definition button.cpp:26
unsigned int uint
Definition number.h:25