OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
wsyscls.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1993, 1996 by Borland International, All Rights Reserved
4//
5/// \file wsyscls.cpp
6/// Implementation of window system structure and type encapsulation
7//----------------------------------------------------------------------------
8
9#include <owl/pch.h>
10#include <owl/defs.h>
11#include <owl/wsyscls.h>
12#include <owl/private/memory.h>
13#include <owl/shellitm.h>
14#include <owl/time.h>
15#include <Oleauto.h> // for VarDateFromStr
16
17#include <owl/except.rh>
18
19namespace owl {
20
21//
22/// Supports drag and drop.
23//
25:
26 FileName(strnewdup(fileName.c_str())),
27 Point(p),
28 InClientArea(inClient)
29{
30}
31
32//
33/// Constructs a TFileDroplet given a DropInfo and a file index.
34///
35/// The location is relative to the client coordinates, and will have negative
36/// values if dropped in the non-client parts of the window.
37///
38/// DragQueryPoint copies that point where the file was dropped and returns whether
39/// or not the point is in the client area. Regardless of whether or not the file
40/// is dropped in the client or non-client area of the window, you will still
41/// receive the file name.
42//
44{
45 // Tell DragQueryFile the file wanted (i) and the length of the buffer.
46 //
47 int namelen = drop.DragQueryFileNameLen(i) + 1;
48 FileName = new tchar[namelen];
49
50 drop.DragQueryFile(i, FileName, namelen);
51
52 InClientArea = drop.DragQueryPoint(Point);
53}
54
55//
56/// The destructor for this class.
57///
58/// Clean up the new'd filename
59//
61{
62 delete[] FileName;
63}
64
65//
66/// Releases any memory allocated for the transferring of this TDropInfo object's
67/// files during drag operations.
68//
69void
71{
72 TShell::DragFinish(Handle);
73}
74
75//
76// Functor for CopyText; see DragQueryFile below.
77//
78struct TDragQueryFile
79{
80 HDROP Handle;
81 uint Index;
82
83 int operator()(LPTSTR buf, int bufSize)
84 {return TShell::DragQueryFile(Handle, Index, buf, bufSize);}
85};
86
87//
88/// String-aware overload
89//
92{
93 PRECONDITION(index <= 0x7FFFFFFFu);
94 TDragQueryFile f = {Handle, index};
95 return CopyText(DragQueryFileNameLen(index), f);
96}
97
98//
99/// Retrieves the name of the file and related information for this i object. If
100/// index is set to -1 (0xFFFF), DragQueryFile returns the number of dropped files.
101/// This is equivalent to calling DragQueryFileCount.
102/// If index lies between 0 and the total number of dropped files for this object,
103/// DragQueryFile copies to the name buffer (of length nameLen bytes) the name of
104/// the dropped file that corresponds to index, and returns the number of bytes
105/// actually copied.
106/// If name is 0, DragQueryFile returns the required buffer size (in bytes) for the
107/// given index. This is equivalent to calling DragQueryFileNameLen.
108//
109uint
111{
113 return TShell::DragQueryFile(Handle, index, name, nameLen);
114}
115//
116/// Returns the number of dropped files in this TDropInfo object. This call is
117/// equivalent to calling DragQueryFile(-1, 0, 0).
118//
119uint
121{
122 return TShell::DragQueryFile(Handle, uint(-1), nullptr, 0);
123}
124//
125/// Returns the length of the name of the file in this TDropInfo object
126/// corresponding to the given index. This call is equivalent to calling
127/// DragQueryFile(index, 0, 0).
128//
129uint
131{
132 return TShell::DragQueryFile(Handle, index, nullptr, 0);
133}
134
135//
136/// Functional-style overload
137//
138std::pair<TPoint, bool>
140{
141 TPoint p;
142 bool r = DragQueryPoint(p);
143 return std::make_pair(p, r);
144}
145
146//
147/// Retrieves the mouse pointer position when this object's files are dropped and
148/// copies the coordinates to the given point object. point refers to the window
149/// that received the WM_DROPFILES message. DragQueryPoint returns true if the drop
150/// occurs inside the window's client area, otherwise false.
151//
152bool
154{
155 return TShell::DragQueryPoint(Handle, &point);
156}
157
159{
160 *this = tm.GetFileTime();
161 //uint16 fdate, ftime;
162 //__MakeDosTime(tm, fdate, ftime);
163 //DosDateTimeToFileTime(fdate,ftime,this)
164}
165
168{
169 *this = tm.GetFileTime();
170 //uint16 fdate, ftime;
171 //__MakeDosTime(tm, fdate, ftime);
172 //DosDateTimeToFileTime(fdate,ftime,this)
173 return *this;
174}
175
177{
179 bool retval = ::FileTimeToLocalFileTime(this, &tm);
180 *this = tm;
181 return retval;
182}
183
185{
187 bool retval = ::LocalFileTimeToFileTime(this, &tm);
188 *this = tm;
189 return retval;
190}
191
192
194{
196 LPCOLESTR olestr = _A2W_A(s.c_str());
198 const ULONG flags = 0;
199 DATE date;
200 HRESULT hr = VarDateFromStr(olestr, lcid, flags, &date);
202 int r = VariantTimeToSystemTime(date, this);
204}
205
206} // OWL namespace
#define PRECONDITION(condition)
Definition checks.h:227
TDropInfo is a simple class that supports file-name drag-and-drop operations using the WM_DROPFILES m...
Definition wsyscls.h:257
tstring DragQueryFile(uint index) const
String-aware overload.
Definition wsyscls.cpp:91
std::pair< TPoint, bool > DragQueryPoint() const
Functional-style overload.
Definition wsyscls.cpp:139
uint DragQueryFileCount() const
Returns the number of dropped files in this TDropInfo object.
Definition wsyscls.cpp:120
uint DragQueryFileNameLen(uint index) const
Returns the length of the name of the file in this TDropInfo object corresponding to the given index.
Definition wsyscls.cpp:130
void DragFinish() const
Releases any memory allocated for the transferring of this TDropInfo object's files during drag opera...
Definition wsyscls.cpp:70
~TFileDroplet()
The destructor for this class.
Definition wsyscls.cpp:60
TFileDroplet(const tstring &fileName, const TPoint &p, bool inClient)
Supports drag and drop.
Definition wsyscls.cpp:24
TFileTime is a class derived from the structure FILETIME.
Definition wsyscls.h:362
bool ToUniversalTime()
Definition wsyscls.cpp:184
bool ToLocalTime()
Definition wsyscls.cpp:176
TFileTime & operator=(const TTime &tm)
Definition wsyscls.cpp:167
TFileTime()
Constructs a empty TFileTime object.
Definition wsyscls.h:365
TPoint is a support class, derived from tagPOINT.
Definition geometry.h:87
static void DragFinish(HDROP)
Invokes 'DragFinish' indirectly.
Definition shellitm.cpp:84
static BOOL DragQueryPoint(HDROP, LPPOINT)
Invokes 'DragQueryPoint' indirectly.
Definition shellitm.cpp:104
static UINT DragQueryFile(HDROP, UINT, TCHAR *, UINT)
Invokes 'DragQueryFile' indirectly.
Definition shellitm.cpp:94
The TTime class encapsulates time functions and characteristics.
Definition time.h:38
static void Raise(const tstring &msg, uint resId=0)
Definition except.cpp:186
Reliable platform independent header for common memory and string functions.
#define _USES_CONVERSION_A
Definition memory.h:218
char * strnewdup(const char *s, size_t minAllocSize=0)
Definition memory.cpp:25
#define _A2W_A(lpw)
Definition memory.h:224
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
tstring CopyText(int size, TGetText get_text)
Copies text from a C-string (null-terminated character array) into a string object,...
Definition defs.h:317
std::string tstring
Definition defs.h:79
unsigned int uint
Definition number.h:25
General definitions used by all ObjectWindows programs.
Definitions of Win95 Shell Clases: TShellItem, TShellItemIterator, TPidl, TShellMalloc.
Classes for window system structure and type encapsulation.