OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
tabbed.cpp
Go to the documentation of this file.
1//------------------------------------------------------------------------------
2// ObjectWindows
3// Copyright © 1998 by Bidus Yura. All Rights Reserved.
4//
5/// \file
6/// Source file for implementation of TTabbedBase.
7/// Added dynamic Add/DeletePage. Contributed by David Linch.
8//------------------------------------------------------------------------------
9//@doc TTabbedBase
10#include <owl/pch.h>
11
12#include <owl/defs.h>
13#include <owl/docmanag.h>
14#include <owl/layoutwi.h>
15#include <owl/tabbed.h>
16
18
19namespace owl {
20
21static void setWindowLayoutMetrics(TLayoutMetrics& lm, TNoteTab* tab,
23{
25 lm.X.LeftOf(tab, 0);
26 lm.Y.SameAs(lmParent, lmTop);
27 lm.Width.SameAs(lmParent, lmWidth);
28 lm.Height.SameAs(lmParent, lmHeight);
29 }
30 else if(pos == TTabbedBase::tpRight){
31 lm.X.SameAs(lmParent, lmLeft);
32 lm.Y.SameAs(lmParent, lmTop);
33 lm.Width.RightOf(tab);
34 lm.Height.SameAs(lmParent, lmHeight);
35 }
36 else if(pos == TTabbedBase::tpTop){
37 lm.X.Below(tab);
38 lm.Y.SameAs(lmParent, lmTop);
39 lm.Width.SameAs(lmParent, lmWidth);
40 lm.Height.SameAs(lmParent, lmHeight);
41 }
42 else if(pos == TTabbedBase::tpBottom){
43 lm.X.SameAs(lmParent, lmLeft);
44 lm.Y.SameAs(lmParent, lmTop);
45 lm.Width.SameAs(lmParent, lmRight);
46 lm.Height.Above(tab);
47 }
48}
49
50////////////////////////////////////////////////////////////////////////////////
51// TTabbedBase
52// ~~~~~~~~~~~
53DEFINE_RESPONSE_TABLE1(TTabbedBase, TEventHandler)
54 EV_TCN_SELCHANGE(IDC_TABCONTROL, EvTabControlSelChange),
55 EV_TCN_SELCHANGING(IDC_TABCONTROL, EvTabControlSelChanging),
57
58// -----------------------------------------------------------------------------
60:
61 Position(pos)
62{
63 NoteTab = tab;
64 if(!NoteTab)
65 NoteTab = new TNoteTab(self, IDC_TABCONTROL, x,y,w,h);
66}
67// -----------------------------------------------------------------------------
76// -----------------------------------------------------------------------------
77/// Add a new tab page.
78/// \note Use before the Tab window is created!
80{
81 LPCTSTR text = titles ? titles : wnd.GetCaption();
82 if (!text)
83 text = _T("");
84
85 int index = NoteTab->Add(text, INT_PTR((TWindow*)&wnd));
86#if 0 // this code now in AddPage()
87 // if already constructed
88 if(NoteTab->GetHandle() && index >=0 ){
90 if(layoutWnd){
92 setWindowLayoutMetrics(lmWindow, NoteTab, Position);
93 if(!wnd.GetHandle())
94 wnd.Create();
95
96 layoutWnd->SetChildLayoutMetrics(wnd, lmWindow);
97 layoutWnd->Layout();
98 }
99 else{
100 if(!wnd.GetHandle())
101 wnd.Create();
103 }
104 wnd.ShowWindow(SW_SHOWNORMAL);
105
106 }
107#endif
108 return index;
109}
110// -----------------------------------------------------------------------------
112{
113 // assumes that note tab positioning
114 TWindow* parent = NoteTab->GetParentO();
115
116 // Retrieve area of tab (in terms of tabbed window)
117 TRect tRect;
119 ::MapWindowPoints(HWND_DESKTOP, *parent, LPPOINT(&tRect), 2);
121 page.GetWindowRect(pgRect);
122 ::MapWindowPoints(HWND_DESKTOP, *parent, LPPOINT(&pgRect), 2);
123 pgRect.left = pgRect.top = 0;
124
125 switch(Position){
126 case tpLeft:
127 pgRect += TPoint(tRect.Width(), 0);
128 break;
129 case tpRight:
130 if(pgRect.right > tRect.left)
131 pgRect.right = tRect.left;
132 break;
133 case tpTop:
134 pgRect += TPoint(0, tRect.Height());
135 break;
136 case tpBottom:
137 if(pgRect.bottom > tRect.top)
138 pgRect.bottom = tRect.top;
139 break;
140 }
142}
143// -----------------------------------------------------------------------------
145{
146 // first set all titles
147 TWindow* wnd;
148 TNoteTabItem Item;
149 int count = NoteTab->GetCount();
150 for(int i = 0; i< count; i++){
151 NoteTab->GetItem(i, Item);
152 wnd = ((TWindow*)Item.ClientData);
153 if (!wnd->IsWindow())
154 {
155 wnd->Create();
156//Bug#1456799 Jogy (24.3.2006)
157 wnd->ShowWindow(SW_HIDE);
158 }
159
160 // it will be here only for dialog ????
161 if(Item.Label.empty()){
163 wnd->GetWindowText(title, MAX_PATH);
164 Item.Label = title;
165 NoteTab->SetItem(i, Item);
166 }
167 // Adjust child position
168 AdjustPage(*wnd);
169 }
170 if(count){
171 int Selected = NoteTab->GetSel();
172 NoteTab->GetItem(Selected, Item);
173 wnd = (TWindow*)Item.ClientData;
174 // Show the newly selected tab, if any.
175 if(wnd)
176 wnd->ShowWindow(SW_SHOWNORMAL);
177 }
178}
179// -----------------------------------------------------------------------------
181{
182 if(index == -1)
183 index = NoteTab->GetSel();
184 TNoteTabItem Item;
185 NoteTab->GetItem(index, Item);
186
187 return (TWindow*)Item.ClientData;
188}
189
190//
191/// Hides the current page and shows the page at the given index.
192/// Does nothing if the page at the given index is already selected.
193/// Note that this function does not send any notifications.
194//
196{
197 PRECONDITION(index >= 0 && index < NoteTab->GetCount());
198 if (index == NoteTab->GetSel()) return;
199
200 if (const auto currentPage = GetPage())
201 currentPage->ShowWindow(SW_HIDE);
202 NoteTab->SetSel(index);
203 const auto newPage = GetPage();
204 newPage->ShowWindow(SW_SHOWNORMAL);
205 if (shouldFocusPage)
206 newPage->SetFocus();
207}
208
210{
211 if (const auto w = GetPage())
212 w->ShowWindow(SW_SHOWNORMAL);
213}
214
216{
217 if (const auto w = GetPage())
218 w->ShowWindow(SW_HIDE);
219 return false; // Don't veto the change.
220}
221
222//////////////////////////////////////////////////////////////
223//
224//
227
229:
230 TLayoutWindow(parent, title, module),
231 TTabbedBase(this,0,0,0,0)
232{
233 Init();
234}
235
237 : TLayoutWindow(parent, title, module),
238 TTabbedBase(this,0,0,0,0)
239{
240 Init();
241}
242
243void TTabbedWindow::Init()
244{
245 SetBkgndColor(TColor::Transparent); // No erase; see TWindow::EvEraseBkgnd.
246 ModifyStyle(0, WS_CLIPCHILDREN | WS_CLIPSIBLINGS); // Clipping reduces resize flicker.
247}
248
249//
251{
252 uint count = GetTabControl()->GetCount();
253 uint i;
254 for(i = 0; i < count; i++){
255 TWindow* wnd = GetPage(i);
256 wnd->ModifyStyle(WS_VISIBLE, 0);
257 }
258
259 // Calculate tab control height and layout.
260 //
261 uint height = GetTabControl()->GetMinimalHeight() + 1;
264 setWindowLayoutMetrics(lmWindow, GetTabControl(), Position);
265 switch(Position){
266 case tpLeft:
267 lmNoteTab.X.SameAs(lmParent, lmLeft);
268 lmNoteTab.Y.SameAs(lmParent, lmTop);
269 lmNoteTab.Width.Absolute(lmRight, height);
270 lmNoteTab.Width.Units = lmPixels;
271 lmNoteTab.Height.SameAs(lmParent, lmHeight);
272 break;
273 case tpRight:
274 lmNoteTab.X.SameAs(lmParent, lmRight);
275 lmNoteTab.Y.SameAs(lmParent, lmTop);
276 lmNoteTab.Height.SameAs(lmParent, lmHeight);
277 lmNoteTab.Width.Absolute(lmLeft, height);
278 lmNoteTab.Width.Units = lmPixels;
279 break;
280 case tpTop:
281 lmNoteTab.X.SameAs(lmParent, lmLeft);
282 lmNoteTab.Y.SameAs(lmParent, lmTop);
283 lmNoteTab.Width.SameAs(lmParent, lmWidth);
284 lmNoteTab.Height.Absolute(lmBottom, height);
285 lmNoteTab.Height.Units = lmPixels;
286 break;
287 case tpBottom:
288 lmNoteTab.X.SameAs(lmParent, lmLeft);
289
290 // Needed an adjustment of -1 here, otherwise there is a 1 pixel gap
291 // below the tab control.
292 //
293 // TODO: Determine if this is a bug in TLayoutWindow, or whether this
294 // bottom pixel exclusion is indeed correct.
295 //
297 lmNoteTab.Height.Absolute(height);
298 lmNoteTab.Height.Units = lmPixels;
299 lmNoteTab.Width.SameAs(lmParent, lmRight);
300 break;
301 }
303
304 for(i = 0; i < count; i++)
306
308
309 SetupPages();
310
311 return true;
312}
313//
314/// Add a new tab page.
315///\note Need at least one page in order to add a page. The initial page must be added before creating the window.
317{
318 TWindow* wnd1 = (TWindow*)&wnd;
319 // If the layout window hasn't been created, just Add the tab
320 if(!GetHandle())
321 return Add(*wnd1, titles);
322
323 // Need at least one page in order to add a page
324 if(GetTabControl()->GetSel() < 0)
325 return -1;
326
327 // Tell the currently selected Tab we're about to change
330
331 int index = Add(*wnd1, titles);
332 wnd1->ModifyStyle(WS_VISIBLE, 0);
333
336
337 if(!wnd1->IsWindow())
338 wnd1->Create();
339
341 Layout();
342
343 // Tell the new Tab we've changed to it
345
346 return index;
347}
348//
350{
351 TWindow* wnd1 = (TWindow*)&wnd;
352 uint count = GetTabControl()->GetCount();
353 for(uint i = 0; i < count; i++){
354 if(wnd1 == GetPage(i)) {
355 // Tell the currently selected Tab we're about to change
360 return true;
361 }
362 }
363 return false;
364}
365
367{
368 TNoteTab* t = GetTabControl(); CHECK(t);
371 m.Height.Absolute(newHeight);
372 m.SetMeasurementUnits(lmPixels);
374 Layout();
375 t->Invalidate();
376}
377
378//------------------------------------------------------------------------------
379// TTabbedView Implementation
380//
381
385
386//
387//
388//
390:
391 TTabbedWindow(parent, nullptr, doc.GetDocManager().GetApplication()),
392 TView(doc)
393{
394}
395
396//
397// Does a given HWND belong to this view? Yes if it is us, or a child of us
398//
399bool
400TTabbedView::VnIsWindow(HWND hWnd)
401{
402 return hWnd == GetHandle() || IsChild(hWnd);
403}
404
405//----------------------------------------------------------------------------
406/*
407IMPLEMENT_STREAMABLE2(TTabbedWindow, TLayoutWindow, TTabbed);
408IMPLEMENT_STREAMABLE2(TTabbedView, TTabbedWindow, TView);
409
410#if OWL_PERSISTENT_STREAMS
411
412//
413//
414//
415void*
416*/
417//TTabbedView::Streamer::Read(ipstream& is, uint32 /*version*/) const
418/*
419{
420 ReadBaseObject((TTabbedWindow*)GetObject(), is);
421 ReadBaseObject((TView*)GetObject(), is);
422 return GetObject();
423}
424
425//
426//
427//
428void
429TTabbedView::Streamer::Write(opstream& os) const
430{
431 WriteBaseObject((TTabbedWindow*)GetObject(), os);
432 WriteBaseObject((TView*)GetObject(), os);
433}
434
435#endif
436
437*/
438
439} // OWL namespace
440// -----------------------------------------------------------------------------
441// -----------------------------------------------------------------------------
442
#define CHECK(condition)
Definition checks.h:239
#define PRECONDITION(condition)
Definition checks.h:227
static const TColor Transparent
a non-painting color
Definition color.h:319
An abstract base class, TDocument is the base class for all document objects and serves as an interfa...
Definition docview.h:187
When specifying the layout metrics for a window, four layout constraints are needed.
Definition layoutwi.h:54
Derived from TWindow, TLayoutWindow provides functionality for defining the layout metrics for a wind...
Definition layoutwi.h:122
virtual void Layout()
Causes the window to resize and position its children according to the specified metrics.
Definition layoutwi.cpp:351
bool GetChildLayoutMetrics(const TWindow &child, TLayoutMetrics &metrics)
Gets the layout metrics of the child window.
Definition layoutwi.cpp:500
void SetChildLayoutMetrics(TWindow &child, const TLayoutMetrics &metrics)
Sets the metrics for the window and removes any existing ones.
Definition layoutwi.cpp:465
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:75
TNoteTab encapsulates a tab control with each tab item along the bottom of the window.
Definition notetab.h:70
TNotify is a thin wrapper around the NMHDR structure.
Definition commctrl.h:91
TPoint is a support class, derived from tagPOINT.
Definition geometry.h:87
TRect is a mathematical class derived from tagRect.
Definition geometry.h:308
TTabbedBase implements a tabbed window, designed to be mixed in with TWindow derived.
Definition tabbed.h:66
virtual void AdjustPage(TWindow &page)
Definition tabbed.cpp:111
void SetupPages()
Definition tabbed.cpp:144
TTabbedBase(TWindow *self, int x, int y, int w, int h, TTabPosition=tpBottom, TNoteTab *tab=0)
Definition tabbed.cpp:59
int Add(TWindow &wnd, LPCTSTR titles=0)
Add a new tab page.
Definition tabbed.cpp:79
void EvTabControlSelChange(TNotify &tcn)
Definition tabbed.cpp:209
void SelectPage(int index, bool shouldFocusPage=true)
Hides the current page and shows the page at the given index.
Definition tabbed.cpp:195
TWindow * GetPage(int index=-1)
Definition tabbed.cpp:180
TNoteTab * GetTabControl()
Definition tabbed.h:83
TNoteTab * NoteTab
Definition tabbed.h:94
bool EvTabControlSelChanging(TNotify &tcn)
Definition tabbed.cpp:215
TTabPosition Position
Definition tabbed.h:95
TTabbedView(TDocument &doc, TWindow *parent=0)
Definition tabbed.cpp:389
Tabbed windows it is used in tabbed window.
Definition tabbed.h:107
auto Create() -> bool override
Definition tabbed.cpp:250
bool DeletePage(TWindow &wnd)
Definition tabbed.cpp:349
TTabbedWindow(TWindow *parent=0, LPCTSTR title=0, TModule *module=0)
Definition tabbed.cpp:228
int AddPage(TWindow &wnd, LPCTSTR titles=0)
Add a new tab page.
Definition tabbed.cpp:316
void ResizeTabControl(int newHeight)
Sets the height of the tab control to the given value, then updates the layout of the window and inva...
Definition tabbed.cpp:366
Abstract base class for view access from document.
Definition docview.h:397
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
void SetBkgndColor(TColor color, bool shouldUpdate=true)
Sets the background color for the window.
Definition window.h:1925
virtual bool Create()
Creates the window interface element to be associated with this ObjectWindows interface element.
Definition window.cpp:2399
TWindow * GetParentO() const
Return the OWL's parent for this window.
Definition window.h:2006
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
void GetWindowRect(TRect &rect) const
Gets the screen coordinates of the window's rectangle and copies them into rect.
Definition window.cpp:3609
bool ModifyStyle(uint32 offBits, uint32 onBits, uint swpFlags=0)
Modifies the style bits of the window.
Definition window.cpp:3591
virtual void Invalidate(bool erase=true)
Invalidates (mark for painting) the entire client area of a window.
Definition window.h:2822
HWND GetHandle() const
Returns the handle of the window.
Definition window.h:2020
#define EV_TCN_SELCHANGE(id, method)
void method(TNotify&)
Definition commctrl.h:1327
#define EV_TCN_SELCHANGING(id, method)
bool method(TNotify&)
Definition commctrl.h:1332
#define MAX_PATH
Definition cygwin.h:98
#define _T(x)
Definition cygwin.h:51
Definition of class TDocManager.
#define DEFINE_RESPONSE_TABLE2(cls, base1, base2)
Macro to define a response table for a class with two bases.
Definition eventhan.h:506
#define DEFINE_RESPONSE_TABLE1(cls, base)
Macro to define a response table for a class with one base.
Definition eventhan.h:492
#define lmParent
Use to represent the parent in layout metrics.
Definition layoutco.h:31
@ lmTop
The top edge of the window.
Definition layoutco.h:38
@ lmBottom
The bottom edge of the window.
Definition layoutco.h:40
@ lmRight
The right edge of the window.
Definition layoutco.h:39
@ lmLeft
The left edge of the window.
Definition layoutco.h:37
@ lmPixels
Definition layoutco.h:58
@ lmAbove
Definition layoutco.h:71
@ lmWidth
Definition layoutco.h:48
@ lmHeight
Definition layoutco.h:48
int Add(LPCTSTR txt, INT_PTR clientData=0, int imageIdx=-1, TAbsLocation imageLoc=alLeft, bool shouldSelect=true)
Adds a new tabitem to the notetab control.
Definition notetab.cpp:122
int GetSel() const
Returns the index of the selected tabitem.
Definition notetab.cpp:234
INT_PTR ClientData
User-defined data associated with item.
Definition notetab.h:59
bool GetItem(int index, TNoteTabItem &item) const
Retrieve information about the tab item at the specified index.
Definition notetab.cpp:436
int SetSel(int index)
Selects the tabitem at the specified index.
Definition notetab.cpp:246
bool Delete(int index)
Remove the tabitem at the specified 'index'.
Definition notetab.cpp:162
bool SetItem(int index, const TNoteTabItem &item)
Updates information about the tab item at the specified index.
Definition notetab.cpp:460
int GetCount() const
Return the number of tab items in the notetab control.
Definition notetab.cpp:222
tstring Label
Label of tab.
Definition notetab.h:57
int GetMinimalHeight()
Returns the minimal control height for which tabs are not clipped.
Definition notetab.cpp:271
Definition of classes TLayoutMetrics & TLayoutWindow.
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
EV_VN_ISWINDOW
Definition commview.cpp:26
END_RESPONSE_TABLE
Definition button.cpp:26
std::string tstring
Definition defs.h:79
General definitions used by all ObjectWindows programs.
#define TYPESAFE_DOWNCAST(object, toClass)
Definition defs.h:269
TNoteTabItem holds information about each tab in a notetab control.
Definition notetab.h:52
OWL_DIAGINFO
Definition tabbed.cpp:17
Class definition for TTabbedBase .