4#ifndef _Stroika_Frameworks_Led_Support_h_
5#define _Stroika_Frameworks_Led_Support_h_ 1
7#include "Stroika/Frameworks/StroikaPreComp.h"
18#if qStroika_Foundation_Common_Platform_Windows
23#elif qStroika_FeatureSupported_XWindows
28#include "Stroika/Foundation/Characters/SDKString.h"
29#include "Stroika/Foundation/Common/Common.h"
33#include "Stroika/Foundation/Execution/Throw.h"
34#include "Stroika/Foundation/Memory/Common.h"
36#include "Stroika/Frameworks/Led/Config.h"
38#if qStroika_Foundation_Common_Platform_Windows
39#include "Stroika/Foundation/Execution/Platform/Windows/HRESULTErrorException.h"
57namespace Stroika::Frameworks::Led {
61 constexpr size_t kBadIndex = size_t (-1);
63#if qStroika_Foundation_Common_Platform_Windows
116#if defined(__cplusplus)
117 using Led_tChar = wchar_t;
125#define LED_TCHAR_OF__(X) L##X
126#define LED_TCHAR_OF(X) LED_TCHAR_OF__ (X)
128 constexpr wchar_t kNonBreakingSpace = 0x00a0;
129 constexpr wchar_t kZeroWidthSpace = 0x200b;
130 constexpr wchar_t kPoundSign = 0x00a3;
131 constexpr wchar_t kCentSign = 0x00a2;
132 constexpr wchar_t kYenSign = 0x00a5;
140 using Led_tString = basic_string<Led_tChar>;
147 size_t Led_tStrlen (
const Led_tChar* s);
154 int Led_tStrCmp (
const Led_tChar* l,
const Led_tChar* r);
161 int Led_tStrnCmp (
const Led_tChar* l,
const Led_tChar* r,
size_t n);
168 int Led_tStrniCmp (
const Led_tChar* l,
const Led_tChar* r,
size_t n);
175 int Led_tStriCmp (
const Led_tChar* l,
const Led_tChar* r);
182 const Led_tChar* Led_tStrChr (
const Led_tChar* s, Led_tChar c);
188#if qTargetPlatformSDKUseswchar_t
189#define Led_SDK_TCHAROF(X) LED_TCHAR_OF__ (X)
191#define Led_SDK_TCHAROF(X) X
198 SDKString Led_tString2SDKString (
const Led_tString& s);
204 Led_tString Led_WideString2tString (
const wstring& s);
210 Led_tString Led_SDKString2tString (
const SDKString& s);
216 Led_tString Led_ANSIString2tString (
const string& s);
222 string Led_tString2ANSIString (
const Led_tString& s);
228 wstring Led_tString2WideString (
const Led_tString& s);
230 short Led_ByteSwapFromMac (
short src);
231 unsigned short Led_ByteSwapFromMac (
unsigned short src);
233 short Led_ByteSwapFromWindows (
short src);
234 unsigned short Led_ByteSwapFromWindows (
unsigned short src);
235 long Led_ByteSwapFromWindows (
long src);
236 unsigned long Led_ByteSwapFromWindows (
unsigned long src);
238 void UInt16ToBuf (uint16_t u, uint16_t* realBuf);
239 uint16_t BufToUInt16 (
const uint16_t* realBuf);
240 void UInt32ToBuf (uint32_t ul, uint32_t* realBuf);
241 uint32_t BufToUInt32 (
const uint32_t* buf);
246 void SizeTToBuf (
size_t ul, uint32_t* realBuf);
247 size_t BufToSizeT (
const uint32_t* buf);
249 size_t Led_SkrunchOutSpecialChars (Led_tChar* text,
size_t textLen, Led_tChar charToRemove);
255 template <
class VECTOR>
256 inline void PUSH_BACK (VECTOR& v,
const typename VECTOR::value_type& e)
258 size_t vSize = v.size ();
259 size_t vCap = v.capacity ();
260 Assert (vSize <= vCap);
262 size_t newCap = vSize * 2;
263 newCap = max (newCap,
size_t (4));
275 template <
typename DATA>
276 struct DiscontiguousRunElement {
277 DiscontiguousRunElement (
size_t offset,
size_t length)
278 : fOffsetFromPrev{offset}
279 , fElementLength{length}
282 DiscontiguousRunElement (
size_t offset,
size_t length,
const DATA& data)
283 : fOffsetFromPrev{offset}
284 , fElementLength{length}
289 size_t fOffsetFromPrev;
290 size_t fElementLength;
294 struct DiscontiguousRunElement<void> {
295 DiscontiguousRunElement (
size_t offset,
size_t length)
296 : fOffsetFromPrev{offset}
297 , fElementLength{length}
300 size_t fOffsetFromPrev;
301 size_t fElementLength;
312 template <
typename DATA>
313 struct DiscontiguousRun : vector<DiscontiguousRunElement<DATA>> {};
326 Led_tChar* Led_NextChar (Led_tChar* fromHere);
327 const Led_tChar* Led_NextChar (
const Led_tChar* fromHere);
335 Led_tChar* Led_PreviousChar (Led_tChar* startOfString, Led_tChar* fromHere);
336 const Led_tChar* Led_PreviousChar (
const Led_tChar* startOfString,
const Led_tChar* fromHere);
344 bool ValidateTextForCharsetConformance (
const Led_tChar* text,
size_t length);
346 unsigned Led_DigitCharToNumber (
char digitChar);
347 char Led_NumberToDigitChar (
unsigned digitValue);
349 bool Led_CasedCharsEqual (
char lhs,
char rhs,
bool ignoreCase =
true);
350 bool Led_CasedStringsEqual (
const string& lhs,
const string& rhs,
bool ignoreCase =
true);
351 bool Led_CasedStringsEqual (
const string_view& lhs,
const string_view& rhs,
bool ignoreCase =
true);
352 bool Led_CasedStringsEqual (
const string_view& lhs,
const string& rhs,
bool ignoreCase =
true);
353 bool Led_CasedStringsEqual (
const string& lhs,
const string_view& rhs,
bool ignoreCase =
true);
354 bool Led_CasedStringsEqual (
const char* lhs,
const string& rhs,
bool ignoreCase =
true);
355 bool Led_CasedStringsEqual (
const string& lhs,
const char* rhs,
bool ignoreCase =
true);
356 bool Led_CasedStringsEqual (
const char* lhs,
const string_view& rhs,
bool ignoreCase =
true);
357 bool Led_CasedStringsEqual (
const string_view& lhs,
const char* rhs,
bool ignoreCase =
true);
358 bool Led_CasedStringsEqual (
const char* lhs,
const char* rhs,
bool ignoreCase =
true);
367#ifndef qStroika_Frameworks_Led_SupportClipboard
368#define qStroika_Frameworks_Led_SupportClipboard (qStroika_Foundation_Common_Platform_Windows or qStroika_FeatureSupported_XWindows)
371#if qStroika_Foundation_Common_Platform_Windows
372 using Led_ClipFormat = CLIPFORMAT;
373#elif qStroika_FeatureSupported_XWindows
374 using Led_ClipFormat = long;
377 enum Led_ClipFormat :
unsigned short {
380#if qStroika_Foundation_Common_Platform_Windows
381 const Led_ClipFormat kTEXTClipFormat = CF_UNICODETEXT;
383 const Led_ClipFormat kPICTClipFormat = CF_DIB;
384 const Led_ClipFormat kFILEClipFormat = CF_HDROP;
385#elif qStroika_FeatureSupported_XWindows
386 const Led_ClipFormat kTEXTClipFormat = XA_STRING;
387 const Led_ClipFormat kFILEClipFormat = 1;
389 const Led_ClipFormat kTEXTClipFormat = (Led_ClipFormat)1;
390 const Led_ClipFormat kFILEClipFormat = (Led_ClipFormat)2;
392 const Led_ClipFormat kBadClipFormat = (Led_ClipFormat)(0);
394#if qStroika_Frameworks_Led_SupportClipboard
395 class Led_ClipboardObjectAcquire {
397 Led_ClipboardObjectAcquire (Led_ClipFormat clipType);
398 ~Led_ClipboardObjectAcquire ();
400 static bool FormatAvailable_TEXT ();
401 static bool FormatAvailable (Led_ClipFormat clipType);
403 nonvirtual
bool GoodClip ()
const;
404 nonvirtual
void* GetData ()
const;
405 nonvirtual
size_t GetDataLength ()
const;
408#if qStroika_Foundation_Common_Platform_Windows
409 HANDLE fOSClipHandle;
415 void Led_BeepNotify ();
418#if qStroika_FeatureSupported_XWindows
419 extern void (*gBeepNotifyCallBackProc) ();
420 unsigned long LedTickCount2XTime (
float ledTickCount);
421 void SyncronizeLedXTickCount (
unsigned long xTickCount);
424#if qStroika_Foundation_Common_Platform_Windows
425 class VariantArrayPacker {
427 VariantArrayPacker (VARIANT* v, VARTYPE vt,
size_t nElts);
428 ~VariantArrayPacker ();
431 nonvirtual
void* PokeAtData ()
const;
434 VARIANT* fSafeArrayVariant{
nullptr};
438 class VariantArrayUnpacker {
440 VariantArrayUnpacker (
const VARIANT& v);
441 ~VariantArrayUnpacker ();
444 nonvirtual
const void* PeekAtData ()
const;
445 nonvirtual VARTYPE GetArrayElementType ()
const;
446 nonvirtual
size_t GetLength ()
const;
449 SAFEARRAY* fSafeArray;
454#if qStroika_Foundation_Common_Platform_Windows
455 VARIANT CreateSafeArrayOfBSTR (
const wchar_t*
const* strsStart,
const wchar_t*
const* strsEnd);
456 VARIANT CreateSafeArrayOfBSTR (
const vector<const wchar_t*>& v);
457 VARIANT CreateSafeArrayOfBSTR (
const vector<wstring>& v);
459 vector<wstring> UnpackVectorOfStringsFromVariantArray (
const VARIANT& v);
462#if qStroika_Foundation_Common_Platform_Windows
463 void DumpSupportedInterfaces (IUnknown* obj,
const char* objectName =
nullptr,
const char* levelPrefix =
nullptr);
464 void DumpObjectsInIterator (IEnumUnknown* iter,
const char* iteratorName =
nullptr,
const char* levelPrefix =
nullptr);
478 Led_URLD (
const char* url,
const char* title);
479 Led_URLD (
const void* urlData,
size_t nBytes);
481 nonvirtual
size_t GetURLDLength ()
const;
482 nonvirtual
size_t GetURLLength ()
const;
483 nonvirtual
size_t GetTitleLength ()
const;
485 nonvirtual
char* PeekAtURLD ()
const;
486 nonvirtual
char* PeekAtURL ()
const;
487 nonvirtual
char* PeekAtTitle ()
const;
489 nonvirtual
string GetTitle ()
const;
490 nonvirtual
string GetURL ()
const;
508 class Led_URLManager {
510 Led_URLManager () =
default;
511 virtual ~Led_URLManager () =
default;
514 static Led_URLManager& Get ();
518 static void Set (Led_URLManager* newURLMgr);
521 virtual void Open (
const string& url);
522 virtual string FileSpecToURL (
const filesystem::path& p);
525#if qUseActiveXToOpenURLs
526 nonvirtual
void Open_ActiveX (
const string& url);
528#if qUseSpyglassDDESDIToOpenURLs
529 nonvirtual
void Open_SpyglassDDE (
const string& url);
532#if qUseSpyglassDDESDIToOpenURLs
534 static void InitDDEHandler ();
539 static DWORD sDDEMLInstance;
540 static HDDEDATA CALLBACK SimpleDdeCallBack (UINT , UINT , HCONV , HSZ , HSZ ,
541 HDDEDATA , DWORD , DWORD );
542 static const char* SkipToNextArgument (
const char* pFormat);
543 static HSZ ClientArguments (
const char* pFormat, ...);
544 static char* ExtractArgument (HSZ hszArgs,
int iArg);
545 static void ServerReturned (HDDEDATA hArgs,
const char* pFormat, ...);
549 string MakeSophistsAppNameVersionURL (
const string& relURL,
const string& appName,
const string& extraArgs =
string{});
558#include "Support.inl"
chrono::duration< double > DurationSeconds
chrono::duration<double> - a time span (length of time) measured in seconds, but high precision.
basic_string< SDKChar > SDKString