From e80b274a23cb6bbe83bc48058c779624b16dd556 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 7 May 2024 14:46:11 +0200 Subject: MHR-23: ErrorID error codes are now deprecated in favor of HError. - Cleanup done in SystemLib. - Refactor system API. Signed-off-by: Amlal El Mahrouss --- Public/Developer/SystemLib/Headers/2D.h | 19 --- Public/Developer/SystemLib/Headers/Alert.h | 21 ++++ Public/Developer/SystemLib/Headers/Defines.h | 32 ++--- Public/Developer/SystemLib/Headers/Dialog.h | 46 ------- Public/Developer/SystemLib/Headers/Intl.h | 24 ++++ Public/Developer/SystemLib/Headers/TrueType.h | 38 ------ Public/Developer/SystemLib/Headers/Wm.h | 171 -------------------------- Public/Developer/SystemLib/Headers/l18n.h | 24 ---- Public/Developer/SystemLib/Sources/App.c | 2 +- Public/Developer/SystemLib/Sources/TrueType.c | 42 ------- Public/Developer/SystemLib/Sources/Wm.c | 100 --------------- 11 files changed, 63 insertions(+), 456 deletions(-) delete mode 100644 Public/Developer/SystemLib/Headers/2D.h create mode 100644 Public/Developer/SystemLib/Headers/Alert.h delete mode 100644 Public/Developer/SystemLib/Headers/Dialog.h create mode 100644 Public/Developer/SystemLib/Headers/Intl.h delete mode 100644 Public/Developer/SystemLib/Headers/TrueType.h delete mode 100644 Public/Developer/SystemLib/Headers/Wm.h delete mode 100644 Public/Developer/SystemLib/Headers/l18n.h delete mode 100644 Public/Developer/SystemLib/Sources/TrueType.c delete mode 100644 Public/Developer/SystemLib/Sources/Wm.c (limited to 'Public/Developer/SystemLib') diff --git a/Public/Developer/SystemLib/Headers/2D.h b/Public/Developer/SystemLib/Headers/2D.h deleted file mode 100644 index ad7ba9fe..00000000 --- a/Public/Developer/SystemLib/Headers/2D.h +++ /dev/null @@ -1,19 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#include - -/************************************************************* - * - * File: Draw.h - * Purpose: Xtrem Composer API for NewOS. - * Date: 3/26/24 - * - * Copyright Mahrouss Logic, all rights reserved. - * - *************************************************************/ diff --git a/Public/Developer/SystemLib/Headers/Alert.h b/Public/Developer/SystemLib/Headers/Alert.h new file mode 100644 index 00000000..443b6829 --- /dev/null +++ b/Public/Developer/SystemLib/Headers/Alert.h @@ -0,0 +1,21 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +/************************************************************* + * + * File: Alert.h + * Purpose: New OS alert dialog. + * Date: 3/26/24 + * + * Copyright Mahrouss Logic, all rights reserved. + * + *************************************************************/ + +#pragma once + +#include + +CA_EXTERN_C VoidType Alert(const CharacterTypeUTF8* fmt, ...); diff --git a/Public/Developer/SystemLib/Headers/Defines.h b/Public/Developer/SystemLib/Headers/Defines.h index 8272213e..db2e1884 100644 --- a/Public/Developer/SystemLib/Headers/Defines.h +++ b/Public/Developer/SystemLib/Headers/Defines.h @@ -15,7 +15,7 @@ { \ if (!e) \ { \ - DlgMsgBox("Sorry, an assertion failed.\nFile: %s\nLine: %i", __FILE__, __LINE__) RtAssertTriggerInterrupt() \ + Alert("Sorry, an assertion failed.\nFile: %s\nLine: %i", __FILE__, __LINE__) RtAssertTriggerInterrupt() \ } \ } #else @@ -32,7 +32,7 @@ #endif -struct Application; +struct ApplicationInterface; struct GUID; CA_EXTERN_C void RtAssertTriggerInterrupt(void); @@ -45,6 +45,8 @@ CA_EXTERN_C void RtAssertTriggerInterrupt(void); #define CA_PASCAL CA_STDCALL +#include + typedef __UINT8_TYPE__ ByteType; typedef __UINT16_TYPE__ WordType; typedef __UINT32_TYPE__ DWordType; @@ -127,7 +129,8 @@ enum RtProcessCall kCallSizePtr, kCallCheckPtr, kCallAllocStack, - /// @brief Open a specific handle (can be used as sel to call methods related to it.) + /// @brief Open a specific handle + /// (can be used as sel to call methods related to it.) kCallOpenFile, kCallCloseFile, kCallOpenDir, @@ -145,9 +148,6 @@ enum RtProcessCall kCallsCount, }; -#include -#include - /** * @brief GUID type, something you can also find in CFKit. * @author Amlal El Mahrouss @@ -162,12 +162,12 @@ typedef struct GUID /// \brief Application Interface. /// \author Amlal El Mahrouss -typedef struct Application +typedef struct ApplicationInterface { - VoidType (*Release)(struct Application* Self, DWordType ExitCode); - IntPtrType (*Invoke)(struct Application* Self, DWordType Sel, ...); - VoidType (*Query)(struct Application* Self, PtrVoidType* Dst, SizeType SzDst, struct GUID* GuidOf); -} Application, *ApplicationRef; + VoidType (*Release)(struct ApplicationInterface* Self, DWordType ExitCode); + IntPtrType (*Invoke)(struct ApplicationInterface* Self, DWordType Sel, ...); + VoidType (*Query)(struct ApplicationInterface* Self, PtrVoidType* Dst, SizeType SzDst, struct GUID* GuidOf); +} ApplicationInterface, *ApplicationInterfaceRef; #ifdef __cplusplus @@ -187,21 +187,21 @@ typedef struct Application KLASS& operator=(KLASS&&) = default; \ KLASS(KLASS&&) = default; -#define app_cast reinterpret_cast +#define app_cast reinterpret_cast template using StrType = CharacterTypeUTF8[N]; #else -#define app_cast (ApplicationRef) +#define app_cast (ApplicationInterfaceRef) #endif // ifdef C++ /// @brief Get app singleton. /// @param /// @return -CA_EXTERN_C ApplicationRef RtGetAppPointer(VoidType); +CA_EXTERN_C ApplicationInterfaceRef RtGetAppPointer(VoidType); /// @brief Get argument count /// @param @@ -213,7 +213,7 @@ CA_EXTERN_C SizeType RtGetAppArgumentsCount(VoidType); /// @return CA_EXTERN_C CharacterTypeUTF8** RtGetAppArgumentsPtr(VoidType); -CA_EXTERN_C ApplicationRef kSharedApplication; +CA_EXTERN_C ApplicationInterfaceRef kSharedApplication; typedef CharacterTypeUTF8 StrType255[255]; @@ -226,3 +226,5 @@ typedef CharacterTypeUTF8 StrType255[255]; #ifndef kInvalidRef #define kInvalidRef 0 #endif + +#include diff --git a/Public/Developer/SystemLib/Headers/Dialog.h b/Public/Developer/SystemLib/Headers/Dialog.h deleted file mode 100644 index 14e3d3a7..00000000 --- a/Public/Developer/SystemLib/Headers/Dialog.h +++ /dev/null @@ -1,46 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#include - -struct _DialogPort; -struct _DialogPoint; - -/// @brief Dialog procedure type. -typedef VoidType (*WmDialogFn)(struct _DialogPort* port, UInt32Type msg, UIntPtrType pParam, UIntPtrType iParam); - -/// @brief A point, can represent the size, position of a window. -typedef struct _DialogPoint -{ - PositionType X, Y; -} DialogPoint; - -typedef struct _DialogPort -{ - WordType dlgPort; - WordType dlgKind; - BooleanType dlgVisible : 1; - BooleanType dlgMoving : 1; - DialogPoint dlgPosition; - WmDialogFn dlgProc; - struct _WmGFX* dlgGfx; - struct _WmWindowPort* parentPort; -} DialogPort; - -/// @brief Creates a new dialog from a rsrc fork id. -/// @param rsrcId the resource id. -/// @return the dialog port. -CA_EXTERN_C DialogPort* DlgCreateFromRsrc(QWordType rsrcId); - -/// @brief Shows an message box according to format. -/// @param title the message box title -/// @param format the format -/// @param va_list the va args, that goes along with it. -/// @return 0: the user clicked Ok -/// @return > 0: User clicked on specific button. -CA_EXTERN_C Int32Type DlgMsgBox(const CharacterTypeUTF8* title, const CharacterTypeUTF8* format, ...); diff --git a/Public/Developer/SystemLib/Headers/Intl.h b/Public/Developer/SystemLib/Headers/Intl.h new file mode 100644 index 00000000..1cd5ea64 --- /dev/null +++ b/Public/Developer/SystemLib/Headers/Intl.h @@ -0,0 +1,24 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + +/// @brief Intlization primitives. + +#include + +typedef UInt64Type IntlRef; + +/// @brief locale getter and setters. + +IntlRef IntlGetLocale(const char* name); +BooleanType IntlSetLocale(const IntlRef intl); + +/// @brief locale helpers. + +/// @brief translate a string from a locale. +const CharacterTypeUTF8* IntlTranslate(const CharacterTypeUTF8* input, + const IntlRef locale); diff --git a/Public/Developer/SystemLib/Headers/TrueType.h b/Public/Developer/SystemLib/Headers/TrueType.h deleted file mode 100644 index 49b111cc..00000000 --- a/Public/Developer/SystemLib/Headers/TrueType.h +++ /dev/null @@ -1,38 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#include - -/************************************************************* - * - * File: TrueType.h - * Purpose: TrueType font implementation for NewOS. - * Date: 3/26/24 - * - * Copyright Mahrouss Logic, all rights reserved. - * - *************************************************************/ - -typedef QWordType TTFFontRef; - -/// @brief Loads a new font into app's memory. -/// @param name -/// @return -CA_EXTERN_C TTFFontRef FnCreateFont(const CharacterTypeUTF8* name); - -/// @brief Dispose an allocated font. -/// @param fon -/// @return -CA_EXTERN_C VoidType FnDisposeFont(TTFFontRef fon); - -/// @brief Gets the font gylph for character. -/// @param fon -/// @return -CA_EXTERN_C PtrVoidType FnGetGlyph(TTFFontRef fon, UInt32Type utfCh); - -/// TODO: Get font metadata. \ No newline at end of file diff --git a/Public/Developer/SystemLib/Headers/Wm.h b/Public/Developer/SystemLib/Headers/Wm.h deleted file mode 100644 index e0333310..00000000 --- a/Public/Developer/SystemLib/Headers/Wm.h +++ /dev/null @@ -1,171 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#include -#include - -/************************************************************* - * - * File: Wm.h - * Purpose: Window Manager API for NewOS. - * Date: 3/26/24 - * - * Copyright Mahrouss Logic, all rights reserved. - * - *************************************************************/ - -struct _WmPoint; -struct _WmWindowPort; -struct _WmGFX; -struct _WmControlPort; -struct _WmPoint; - -/// @brief Window Graphics type. -typedef struct _WmGFX -{ - UInt32Type Depth; - UInt32Type* DataFrame; - SizeType DataFrameWidth; - SizeType DataFrameHeight; -} WmGFX, *WmGFXRef; - -/// @brief Window procedure type. -typedef VoidType (*WmWindowFn)(struct _WmWindowPort* port, UInt32Type msg, UIntPtrType pParam, UIntPtrType iParam); - -/// @brief A point, can represent the size, position of a window. -typedef struct _WmPoint -{ - PositionType X, Y; -} WmPoint; - -/// @brief Window port type, can be used to control the window. -typedef struct _WmWindowPort -{ - WordType windowPort; - WordType windowKind; - BooleanType windowVisible : 1; - BooleanType windowMaximized : 1; - BooleanType windowMinimized : 1; - BooleanType windowMoving : 1; // Set if the window is moving. - BooleanType windowDisableClose : 1; // Set if user or app request a close action. - BooleanType windowDisableMinimize : 1; // Set if user request a minimize action. - BooleanType windowInvalidate : 1; // Set if invalidation action is done. - WmPoint windowPosition; - WmPoint windowSize; - WmGFXRef windowGfx; - WmWindowFn windowProc; - struct _WmWindowPort* windowMenuPort; ///! Attached menu to it. - struct _WmWindowPort* windowParentPort; -} WindowPort; - -/// @brief Control port type. -typedef struct _WmControlPort -{ - WordType controlPort; - WordType controlKind; - BooleanType controlVisible : 1; - BooleanType controlMoving : 1; - WmPoint controlPosition; - WmWindowFn controlProc; - WmGFXRef controlGfx; - WindowPort* parentPort; -} WmControlPort; - -enum -{ - kWmErrIncompatible = 0x74, - kWmErrOutOfMemory, - kWmErrInvalidArg, - kWmErrNotImplemented, -}; - -/// @brief Color reference. -typedef UInt32Type ColorRef; - -/***********************************************************************************/ -/// Color utils. -/***********************************************************************************/ - -CA_EXTERN_C const ColorRef kRgbRed; -CA_EXTERN_C const ColorRef kRgbGreen; -CA_EXTERN_C const ColorRef kRgbBlue; -CA_EXTERN_C const ColorRef kRgbBlack; -CA_EXTERN_C const ColorRef kRgbWhite; - -/***********************************************************************************/ -/// Color macro. -/***********************************************************************************/ - -#define WmMakeColorRef(R, G, B) (ColorRef)(0x##R##G##B) - -#define kControlKindWindow 0 -#define kControlKindDialog 1 -#define kControlKindMenu 2 -#define kControlKindButton 3 -#define kControlKindLabel 4 -#define kControlKindDropdownMenu 5 -#define kControlKindIcon 6 -#define kControlKindRadioBox 7 -#define kControlKindCheckBox 8 -#define kControlKindUserDefined 9 - -/// @brief Creates a new control -/// @param id the control rsrc fork. -/// @return -CA_EXTERN_C WmControlPort* WmCreateControl(DWordType id); - -/// @brief Releases the control -/// @param ctrlPort the control ref. -/// @return -CA_EXTERN_C VoidType WmReleaseControl(WmControlPort* ctrlPort); - -/// @brief Moves a control inside a WmControlPort. -/// @param ctrlPort the control ref. -/// @param where where to move at. -/// @return -CA_EXTERN_C Int32Type WmSetControlPosition(WmControlPort* ctrlPort, WmPoint where); - -/// @brief Enable control. -/// @param ctrlPort -/// @param enabled -/// @return -CA_EXTERN_C Int32Type WmSetControlEnabled(WmControlPort* ctrlPort, BooleanType enabled); - -/// @brief Make control visible. -/// @param ctrlPort -/// @param visible -/// @return -CA_EXTERN_C Int32Type WmSetControlVisible(WmControlPort* ctrlPort, BooleanType visible); - -/// @brief Creates a new window. -/// @param name the window name -/// @param rsrcId the window fork rsrc ctrlPort. -/// @return the window graphics port. -CA_EXTERN_C WindowPort* WmCreateWindow(const CharacterTypeUTF8* name, const DWordType rsrcId); - -/// @brief Creates a new menu -/// @param name the menu's name -/// @param rsrcId the menu fork rsrc ctrlPort. -/// @return the menu graphics port. -CA_EXTERN_C WindowPort* WmCreateMenu(const CharacterTypeUTF8* name, const DWordType rsrcId); - -/// @brief Releases the window. -/// @param port the window port. -/// @return void -CA_EXTERN_C VoidType WmReleaseWindow(WindowPort* port); - -/// @brief Releases the menu -/// @param port the menu port. -/// @return void -CA_EXTERN_C VoidType WmReleaseMenu(WindowPort* port); - -/// @brief Moves a window on the desktop. (menu arent movable, will return kErrIncompatible if menu is provided.) -/// @param wndPort the gfx port. -/// @param where to move. -/// @return error code. -CA_EXTERN_C Int32Type WmMoveWindow(WindowPort* wndPort, WmPoint where); diff --git a/Public/Developer/SystemLib/Headers/l18n.h b/Public/Developer/SystemLib/Headers/l18n.h deleted file mode 100644 index 1cd5ea64..00000000 --- a/Public/Developer/SystemLib/Headers/l18n.h +++ /dev/null @@ -1,24 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -/// @brief Intlization primitives. - -#include - -typedef UInt64Type IntlRef; - -/// @brief locale getter and setters. - -IntlRef IntlGetLocale(const char* name); -BooleanType IntlSetLocale(const IntlRef intl); - -/// @brief locale helpers. - -/// @brief translate a string from a locale. -const CharacterTypeUTF8* IntlTranslate(const CharacterTypeUTF8* input, - const IntlRef locale); diff --git a/Public/Developer/SystemLib/Sources/App.c b/Public/Developer/SystemLib/Sources/App.c index c85b2dd8..7778c064 100644 --- a/Public/Developer/SystemLib/Sources/App.c +++ b/Public/Developer/SystemLib/Sources/App.c @@ -7,7 +7,7 @@ #include /// @brief Main Application object, retrieved from the RtGetAppPointer symbol. -ApplicationRef kSharedApplication = NullPtr; +ApplicationInterfaceRef kSharedApplication = NullPtr; /// @brief Gets the app arguments count. /// @param void no arguments. diff --git a/Public/Developer/SystemLib/Sources/TrueType.c b/Public/Developer/SystemLib/Sources/TrueType.c deleted file mode 100644 index 49b1c2e8..00000000 --- a/Public/Developer/SystemLib/Sources/TrueType.c +++ /dev/null @@ -1,42 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#include -#include -#include -#include - -#define kTTFFork "fon " /* TrueType */ - -/// @brief TrueType container reader -typedef struct TTFReader -{ - FSForkRef fFork; - FSRef fFile; - PtrVoidType fBlob; // cached blob - SizeType fBlobSize; // cached blob size - VoidType (*__fReadBytes)(SizeType count); - VoidType (*__fSkipBytes)(SizeType count); -} TTFReader; - -/// @brief Grab a TTF reader reference. -/// @param fs filesystem reference. -/// @return TTFReader* the new TTFReader type. -CA_STATIC TTFReader* GrabTTFReader(FSRef fs) -{ - FSForkRef forkRef = FsGetFork(fs, kTTFFork); - - if (forkRef = kInvalidRef) - return NullPtr; - - TTFReader* reader = RtTlsAllocate(sizeof(TTFReader), kStandardAllocation); - - reader->fFile = fs; - reader->fFork = forkRef; - - return reader; -} -/// EOF. diff --git a/Public/Developer/SystemLib/Sources/Wm.c b/Public/Developer/SystemLib/Sources/Wm.c deleted file mode 100644 index 607e7dcf..00000000 --- a/Public/Developer/SystemLib/Sources/Wm.c +++ /dev/null @@ -1,100 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#include -#include - -/// invalid resource handle, they always start from 1. -#define kInvalidRsrc (0U) - -/// @brief Color refs. - -const ColorRef kRgbRed = 0x000000FF; -const ColorRef kRgbGreen = 0x0000FF00; -const ColorRef kRgbBlue = 0x00FF0000; -const ColorRef kRgbBlack = 0x00000000; -const ColorRef kRgbWhite = 0xFFFFFFFF; - -///////////////////////////////////////////////////////////////////////// - -CA_EXTERN_C WindowPort* WmCreateWindow(const CharacterTypeUTF8* name, - const DWordType rsrcId) -{ - CA_MUST_PASS(name); - CA_MUST_PASS(rsrcId != kInvalidRsrc); - - if (!name) - return NullPtr; - if (rsrcId == kInvalidRsrc) - return NullPtr; - - return (WindowPort*)kSharedApplication->Invoke( - kSharedApplication, kCallCreateWindow, name, rsrcId); -} - -///////////////////////////////////////////////////////////////////////// - -CA_EXTERN_C VoidType WmReleaseWindow(WindowPort* winPort) -{ - CA_MUST_PASS(winPort); - if (!winPort) - return; - - kSharedApplication->Invoke(kSharedApplication, kCallCloseWindow, winPort); -} - -///////////////////////////////////////////////////////////////////////// - -CA_EXTERN_C WindowPort* WmCreateMenu(const CharacterTypeUTF8* name, - const DWordType rsrcId) -{ - CA_MUST_PASS(name); - CA_MUST_PASS(rsrcId != kInvalidRsrc); - - if (!name) - return NullPtr; - if (rsrcId == kInvalidRsrc) - return NullPtr; - - return (WindowPort*)kSharedApplication->Invoke(kSharedApplication, - kCallCreateMenu, name, rsrcId); -} - -///////////////////////////////////////////////////////////////////////// - -CA_EXTERN_C VoidType WmReleaseMenu(WindowPort* winPort) -{ - CA_MUST_PASS(winPort); - - if (!winPort) - return; - kSharedApplication->Invoke(kSharedApplication, kCallCloseMenu, winPort); -} - -///////////////////////////////////////////////////////////////////////// - -CA_EXTERN_C Int32Type WmMoveWindow(WindowPort* wndPort, WmPoint where) -{ - if (!wndPort) - return kWmErrInvalidArg; - - wndPort->windowPosition.X = where.X; - wndPort->windowPosition.Y = where.Y; - wndPort->windowMoving = True; - - return 0; -} - -/// @brief Causes the window to invalidate and redraw. -/// @param wndPort The Window port. -/// @return nothing. -CA_EXTERN_C VoidType WmInvalidateGfx(WindowPort* wndPort) -{ - if (wndPort) - { - wndPort->windowInvalidate = Yes; - } -} -- cgit v1.2.3