From 66acd3574138ee8e271201c9eb716ee4dbb1b863 Mon Sep 17 00:00:00 2001 From: ocoursiere Date: Sun, 11 Jan 2004 17:58:47 +0000 Subject: [PATCH] Working BFilePanel, BAlert and updated BApplication (see BPDemo project) --- .../bepascal/cpp/include/be/app/application.h | 8 +++ .../bepascal/cpp/src/be/app/Application.cpp | 53 ++++++++++++++ .../bepascal/cpp/src/be/interface/Alert.cpp | 9 ++- .../bepascal/pas/src/be/app/application.pp | 69 ++++++++++++++++++- .../bepascal/pas/src/be/bepas_kernel/beobj.pp | 11 ++- .../bepascal/pas/src/be/storage/filepanel.pp | 12 ++-- 6 files changed, 149 insertions(+), 13 deletions(-) diff --git a/bepascal/source/bepascal/cpp/include/be/app/application.h b/bepascal/source/bepascal/cpp/include/be/app/application.h index 802e4a9..b15e72f 100644 --- a/bepascal/source/bepascal/cpp/include/be/app/application.h +++ b/bepascal/source/bepascal/cpp/include/be/app/application.h @@ -50,6 +50,14 @@ class BPApplication : public BApplication, public BPLooper virtual void DispatchMessage(BMessage *message, BHandler *target); virtual void AppActivated_hookCall(bool active); virtual void ReadyToRun_hookCall(void); + virtual void RefsReceived(BMessage *message); + virtual void RefsReceived_hookCall(BMessage *message); + virtual void AboutRequested(void); + virtual void AboutRequested_hookCall(void); + virtual void ArgvReceived(int32 argc, char **argv); + virtual void ArgvReceived_hookCall(int32 argc, char **argv); + virtual void Pulse(void); + virtual void Pulse_hookCall(void); private: }; diff --git a/bepascal/source/bepascal/cpp/src/be/app/Application.cpp b/bepascal/source/bepascal/cpp/src/be/app/Application.cpp index 3f90d55..5a94a19 100644 --- a/bepascal/source/bepascal/cpp/src/be/app/Application.cpp +++ b/bepascal/source/bepascal/cpp/src/be/app/Application.cpp @@ -41,6 +41,10 @@ // definition of callback function in BApplication typedef void (*BApplication_AppActivated_hook) (TPasObject PasObject, bool active); typedef void (*BApplication_ReadyToRun_hook) (TPasObject PasObject); +typedef void (*BApplication_RefsReceived_hook) (TPasObject PasObject, BMessage *message); +typedef void (*BApplication_ArgvReceived_hook) (TPasObject PasObject, int32 argc, char **argv); +typedef void (*BApplication_AboutRequested_hook) (TPasObject PasObject); +typedef void (*BApplication_Pulse_hook) (TPasObject PasObject); // typedef bool (*BApplication_QuitRequested_hook) (TPasObject PasObject); // typedef void (*BApplication_MessageReceived_hook) (TPasObject PasObject, TCPlusObject message); @@ -50,6 +54,10 @@ extern "C" { BApplication_AppActivated_hook Application_AppActivated_hook; BApplication_ReadyToRun_hook Application_ReadyToRun_hook; +BApplication_RefsReceived_hook Application_RefsReceived_hook; +BApplication_ArgvReceived_hook Application_ArgvReceived_hook; +BApplication_AboutRequested_hook Application_AboutRequested_hook; +BApplication_Pulse_hook Application_Pulse_hook; //BApplication_QuitRequested_hook Application_QuitRequested_hook; //BApplication_MessageReceived_hook Application_MessageReceived_hook; @@ -118,6 +126,51 @@ void BPApplication::DispatchMessage(BMessage *message, BHandler *target) BApplication::DispatchMessage(message, target); } +void BPApplication::RefsReceived(BMessage *message) +{ + RefsReceived_hookCall(message); +// message->PrintToStream(); + BApplication::RefsReceived(message); +} + +void BPApplication::RefsReceived_hookCall(BMessage *message) +{ + Application_RefsReceived_hook(GetPasObject(), message); +} + +void BPApplication::ArgvReceived(int32 argc, char **argv) +{ + ArgvReceived_hookCall(argc, argv); + BApplication::ArgvReceived(argc, argv); +} + +void BPApplication::ArgvReceived_hookCall(int32 argc, char **argv) +{ + Application_ArgvReceived_hook(GetPasObject(), argc, argv); +} + +void BPApplication::AboutRequested(void) +{ + AboutRequested_hookCall(); + BApplication::AboutRequested(); +} + +void BPApplication::AboutRequested_hookCall(void) +{ + Application_AboutRequested_hook(GetPasObject()); +} + +void BPApplication::Pulse(void) +{ + Pulse_hookCall(); + BApplication::Pulse(); +} + +void BPApplication::Pulse_hookCall(void) +{ + Application_Pulse_hook(GetPasObject()); +} + #if defined(__cplusplus) extern "C" { #endif diff --git a/bepascal/source/bepascal/cpp/src/be/interface/Alert.cpp b/bepascal/source/bepascal/cpp/src/be/interface/Alert.cpp index 4fe353f..0b0e894 100644 --- a/bepascal/source/bepascal/cpp/src/be/interface/Alert.cpp +++ b/bepascal/source/bepascal/cpp/src/be/interface/Alert.cpp @@ -240,7 +240,8 @@ extern "C" { */ TCPlusObject BAlert_Create(TPasObject PasObject, const char *title, const char *text, const char *button1, const char *button2, const char *button3, button_width width, alert_type type) { - return new BPAlert(PasObject, title, text, button1, button2, button3, width, type); +// return new BPAlert(PasObject, title, text, button1, button2, button3, width, type); + return new BAlert(title, text, button1, button2, button3, width, type); } @@ -251,7 +252,8 @@ TCPlusObject BAlert_Create(TPasObject PasObject, const char *title, const char * TCPlusObject BAlert_Create_1 (TPasObject PasObject, const char *title, const char *text, const char *button1, const char *button2, const char *button3, button_width width, button_spacing spacing, alert_type type) { - return new BPAlert(PasObject, title, text, button1, button2, button3, width, spacing, type); +// return new BPAlert(PasObject, title, text, button1, button2, button3, width, spacing, type); + return new BAlert(title, text, button1, button2, button3, width, spacing, type); } /* @@ -260,7 +262,8 @@ TCPlusObject BAlert_Create_1 */ TCPlusObject BAlert_Create_2(TPasObject PasObject, BMessage *data) { - return new BPAlert(PasObject, data); +// return new BPAlert(PasObject, data); + return new BAlert(data); } diff --git a/bepascal/source/bepascal/pas/src/be/app/application.pp b/bepascal/source/bepascal/pas/src/be/app/application.pp index 851eb3b..565f097 100644 --- a/bepascal/source/bepascal/pas/src/be/app/application.pp +++ b/bepascal/source/bepascal/pas/src/be/app/application.pp @@ -21,7 +21,7 @@ unit Application; interface uses - BeObj, Looper, OS, Roster, SupportDefs; + BeObj, Looper, OS, Roster, Message, SupportDefs; type BApplication = class(BLooper) @@ -39,6 +39,10 @@ type // Hook functions procedure AppActivated(Active : Boolean); virtual; procedure ReadyToRun; virtual; + procedure RefsReceived(aMessage : BMessage); virtual; + procedure ArgvReceived(argc : integer; argv : PPChar); virtual; + procedure AboutRequested; virtual; + procedure Pulse; virtual; end; function BApplication_Create(AObject : TObject) : TCPlusObject; @@ -69,11 +73,15 @@ var implementation uses - Message, Messenger; + Messenger; var Application_AppActivated_hook : Pointer; cvar; external; Application_ReadyToRun_hook : Pointer; cvar; external; + Application_RefsReceived_hook : Pointer; cvar; external; + Application_ArgvReceived_hook : Pointer; cvar; external; + Application_AboutRequested_hook : Pointer; cvar; external; + Application_Pulse_hook : Pointer; cvar; external; // start BApplication constructor BApplication.Create; @@ -153,6 +161,37 @@ begin end; end; +procedure Application_RefsReceived_hook_func(Application : BApplication; aMessage : TCPlusObject); cdecl; +var + Message : BMessage; +begin + Message := BMessage.Wrap(aMessage); + try + if Application <> nil then + Application.RefsReceived(Message); + finally + Message.UnWrap; + end; +end; + +procedure Application_AboutRequested_hook_func(Application : BApplication); cdecl; +begin + if Application <> nil then + Application.AboutRequested; +end; + +procedure Application_ArgvReceived_hook_func(Application : BApplication; argc : integer; argv : PPChar); cdecl; +begin + if Application <> nil then + Application.ArgvReceived(argc, argv); +end; + +procedure Application_Pulse_hook_func(Application : BApplication); cdecl; +begin + if Application <> nil then + Application.Pulse; +end; + procedure BApplication.ReadyToRun; begin {$IFDEF DEBUG} @@ -160,6 +199,22 @@ begin {$ENDIF} end; +procedure BApplication.RefsReceived(aMessage : BMessage); +begin +end; + +procedure BApplication.ArgvReceived(argc : integer; argv : PPChar); +begin +end; + +procedure BApplication.AboutRequested; +begin +end; + +procedure BApplication.Pulse; +begin +end; + procedure BApplication.ShowCursor; begin BApplication_ShowCursor(CPlusObject); @@ -191,9 +246,17 @@ initialization be_app := nil; Application_AppActivated_hook := @Application_AppActivated_hook_func; Application_ReadyToRun_hook := @Application_ReadyToRun_hook_func; + Application_RefsReceived_hook := @Application_RefsReceived_hook_func; + Application_AboutRequested_hook := @Application_AboutRequested_hook_func; + Application_ArgvReceived_hook := @Application_ArgvReceived_hook_func; + Application_Pulse_hook := @Application_Pulse_hook_func; finalization Application_AppActivated_hook := nil; Application_ReadyToRun_hook := nil; + Application_RefsReceived_hook := nil; + Application_AboutRequested_hook := nil; + Application_ArgvReceived_hook := nil; + Application_Pulse_hook := nil; be_app := nil; -end. \ No newline at end of file +end. diff --git a/bepascal/source/bepascal/pas/src/be/bepas_kernel/beobj.pp b/bepascal/source/bepascal/pas/src/be/bepas_kernel/beobj.pp index df0478b..3dd667c 100644 --- a/bepascal/source/bepascal/pas/src/be/bepas_kernel/beobj.pp +++ b/bepascal/source/bepascal/pas/src/be/bepas_kernel/beobj.pp @@ -45,6 +45,7 @@ type destructor UnWrap; virtual; property CPlusObject : TCPlusObject read FCPlusObject write FCPlusObject; end; + function GetCPlusObj(anObject : TBeObject) : TCPlusObject; type TSendTextProc = procedure(aText : string); @@ -95,6 +96,14 @@ begin Result := Longword(Num); end; +function GetCPlusObj(anObject : TBeObject) : TCPlusObject; +begin + if Assigned(anObject) then + Result := anObject.CPlusObject + else + Result := nil; +end; + var PasObject_GetPasClassName_hook : Pointer; cvar; external; SendTextProc : TSendTextProc; @@ -182,4 +191,4 @@ initialization finalization PasObject_GetPasClassName_hook := nil; -end. \ No newline at end of file +end. diff --git a/bepascal/source/bepascal/pas/src/be/storage/filepanel.pp b/bepascal/source/bepascal/pas/src/be/storage/filepanel.pp index d8dc25b..46ea7da 100644 --- a/bepascal/source/bepascal/pas/src/be/storage/filepanel.pp +++ b/bepascal/source/bepascal/pas/src/be/storage/filepanel.pp @@ -25,7 +25,7 @@ uses BeObj, Classes, OS, Entry, StorageDefs, Message, Messenger, Window, SupportDefs; type - BRefFilter = class + BRefFilter = class(TBeObject) private public procedure Filter; @@ -79,10 +79,10 @@ type procedure BRefFilter_Filter(AObject : TCPlusObject); cdecl; external BePascalLibName name 'BRefFilter_Filter'; -function BFilePanel_Create(AObject : TBeObject; mode : file_panel_mode; target : BMessenger; +function BFilePanel_Create(AObject : TBeObject; mode : file_panel_mode; target : TCPlusObject; const start_directory : entry_ref; node_flavors : integer; - allow_multiple_selection : Boolean; message : BMessage; - filter : BRefFilter; modal, hide_when_done : Boolean) + allow_multiple_selection : Boolean; message : TCPlusObject; + filter : TCPlusObject; modal, hide_when_done : Boolean) : TCPlusObject; cdecl; external BePascalLibName name 'BFilePanel_Create'; procedure BFilePanel_Free(AObject : TCPlusObject); cdecl; external BePascalLibName name 'BFilePanel_Free'; @@ -148,9 +148,9 @@ constructor BFilePanel.Create(mode : file_panel_mode; target : BMessenger; hide_when_done : Boolean); begin CreatePas; - CPlusObject := BFilePanel_Create(Self, mode, target, start_directory, + CPlusObject := BFilePanel_Create(Self, mode, GetCPlusObj(target), start_directory, node_flavors, allow_multiple_selection, - message, filter, modal, hide_when_done); + GetCPlusObj(message), GetCPlusObj(filter), modal, hide_when_done); end; destructor BFilePanel.Destroy;