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 menu.AppendMenu(MF_STRING, SC_ROLLDIALOG, _T("&Shrink"));
68 HasSystemMenu = true;
69 }
70
71 if (!InitialFullSize)
72 Shrink();
73}
74
75//
76/// Resize the dialog to either full size or minimal size.
77//
78void
79TRollDialog::Resize(bool currentlyFullSize)
80{
82 int oldBottom = r.bottom;
83
84 if (WantAnimation) {
85 int delta = 0;
86 for (int step = 0; delta < Height; step++) {
88 r.bottom = oldBottom - delta;
89 else
90 r.bottom = oldBottom + delta;
91 MoveWindow(r, true); // !CQ Use SetWindowPos(...,SWP_NOMOVE) ?
92 delta = static_cast<int>(Fibonacci(step));
93 }
94 }
95
97 r.bottom = oldBottom - Height;
98 else
99 r.bottom = oldBottom + Height;
100
101 MoveWindow(r, true);
102}
103
104//
105/// Event handler for the system menu option "shrink". Toggles the system menu
106/// choice to "expand".
107//
108void
110{
111 if (IsFullSize) {
112 Height = GetClientRect().Height() + 1;
113
114 Resize(IsFullSize);
115 IsFullSize = false;
116
117 if (HasSystemMenu) {
118 TSystemMenu menu(*this);
119 menu.ModifyMenu(SC_ROLLDIALOG, MF_BYCOMMAND | MF_STRING, SC_ROLLDIALOG, _T("&Expand"));
120 }
121 }
122}
123
124//
125/// Event handler for the system menu option "expand". Toggles the system menu
126/// choice to "shrink".
127//
128void
130{
131 if (!IsFullSize) {
132 Resize(IsFullSize);
133 IsFullSize = true;
134
135 if (HasSystemMenu) {
136 TSystemMenu menu(*this);
137 menu.ModifyMenu(SC_ROLLDIALOG, MF_BYCOMMAND | MF_STRING, SC_ROLLDIALOG, _T("&Shrink"));
138 }
139 }
140}
141
142//
143/// Event handler for the system menu choice. Calls either TRollDialog::Shrink or
144/// TRollDialog::Expand.
145//
146void
148{
149 uint command = cmdType & 0xFFF0;
150
151 if (command == SC_ROLLDIALOG || command == SC_RESTORE) {
152 if (IsFullSize)
153 Shrink();
154 else
155 Expand();
156 }
157 else if (command == SC_MINIMIZE)
158 Shrink();
159 else if (command == SC_MAXIMIZE)
160 Expand();
161 else
163}
164
165
166} // OWL namespace
167/* ========================================================================== */
168
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:129
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:109
void EvSysCommand(uint, const TPoint &)
Event handler for the system menu choice.
Definition rolldial.cpp:147
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