diff --git a/begui/begui/imports/pascal/begui.pas b/begui/begui/imports/pascal/begui.pas new file mode 100644 index 0000000..f82f128 --- /dev/null +++ b/begui/begui/imports/pascal/begui.pas @@ -0,0 +1,166 @@ +unit BeGUI; + +{ + +$Header $ + +$Revision $ + +$Log $ + +} + +interface + +type + MApplicationH = pointer; + MFormH = pointer; + MButtonH = pointer; + MEditH = pointer; + MPanelH = pointer; + MMemoH = pointer; + + uint32 = longword; + int32 = longint; + +var + Application: MApplicationH; + +type + + base_Message = procedure (sender:pointer; msg:uint32);cdecl; + mouseMoved_Message = procedure (sender:pointer; x:double; y:double; code:uint32; msg:uint32);cdecl; + mouseAction_Message = procedure (sender:pointer; x:double; y:double);cdecl; + keyAction_Message = procedure (sender:pointer; bytes:Pchar; numBytes:int32);cdecl; + drawAction_Message = procedure (sender:pointer; left:double; top:double; right:double; bottom:double);cdecl; + +const + //Memson 30/03/2002 : changed this for FPC1.06 compatibility + BEGUILIB = 'begui'; //must be in /boot/home/config/lib and /boot/develop/lib/x86 + +{$PACKRECORDS C} + + + function MApplication_Create: MApplicationH; cdecl; external BEGUILIB; + + procedure MApplication_Free(app:MApplicationH); cdecl; external BEGUILIB; + + procedure MApplication_Run(app:MApplicationH); cdecl; external BEGUILIB; + + function MApplication_GetMainForm(app:MApplicationH):MFormH; cdecl; external BEGUILIB; + + function MApplication_AddForm(app:MApplicationH; left:double; top:double; right:double; bottom:double; + name:Pchar; caption:Pchar):MFormH; cdecl; external BEGUILIB; + + function MApplication_AddForm_int32(app:MApplicationH; left:int32; top:int32; right:int32; bottom:int32; + name:Pchar; caption:Pchar):MFormH; cdecl; external BEGUILIB; + + {added to get round fpc's inability to pass 'float' params...} + + function MButton_Create_int32(left:int32; top:int32; right:int32; bottom:int32; caption:Pchar):MButtonH; external BEGUILIB; + + function MForm_AddMEdit_int32(form:MFormH; left:int32; top:int32; right:int32; bottom:int32; caption:Pchar):MEditH; external BEGUILIB; + + function MForm_AddMMemo_int32(form:MFormH; left:int32; top:int32; right:int32; bottom:int32; caption:Pchar):MMemoH; cdecl; external BEGUILIB; + + function MForm_AddMPanel_int32(frm:MFormH; left:int32; top:int32; right:int32; bottom:int32; name:Pchar):MPanelH;cdecl; external BEGUILIB; + + {form } + procedure MForm_AddChild(form:MFormH; ctrl:pointer); cdecl; external BEGUILIB; + + procedure MForm_AttachMouseMovedDispatcher(form:MFormH; msg:mouseMoved_Message);cdecl; external BEGUILIB; + + procedure MForm_AttachMouseDownDispatcher(form:MFormH; msg:mouseAction_Message);cdecl; external BEGUILIB; + + procedure MForm_AttachMouseUpDispatcher(form:MFormH; msg:mouseAction_Message);cdecl; external BEGUILIB; + + procedure MForm_AttachKeyDownDispatcher(form:MFormH; msg:keyAction_Message);cdecl; external BEGUILIB; + + procedure MForm_AttachKeyUpDispatcher(form:MFormH; msg:keyAction_Message);cdecl; external BEGUILIB; + + procedure MForm_AttachDrawDispatcher(form:MFormH; msg:drawAction_Message);cdecl; external BEGUILIB; + + procedure MForm_Show(frm:MFormH);cdecl; external BEGUILIB; + + procedure MForm_Hide(frm:MFormH);cdecl; external BEGUILIB; + + {button } + function MButton_Create(left:double; top:double; right:double; bottom:double; caption:Pchar):MButtonH;cdecl; external BEGUILIB; + + procedure MButton_AttachClickDispatcher(btn:MButtonH; msg:base_Message);cdecl; external BEGUILIB; + + function MButton_getCaption(btn:MButtonH):pchar;cdecl; external BEGUILIB; + + procedure MButton_setCaption(btn:MButtonH; caption:Pchar);cdecl; external BEGUILIB; + + procedure MButton_AttachMouseMovedDispatcher(btn:MButtonH; msg:mouseMoved_Message);cdecl; external BEGUILIB; + + procedure MButton_AttachMouseDownDispatcher(btn:MButtonH; msg:mouseAction_Message);cdecl; external BEGUILIB; + + procedure MButton_AttachMouseUpDispatcher(btn:MButtonH; msg:mouseAction_Message);cdecl; external BEGUILIB; + + procedure MButton_AttachKeyDownDispatcher(btn:MButtonH; msg:keyAction_Message);cdecl; external BEGUILIB; + + procedure MButton_AttachKeyUpDispatcher(btn:MButtonH; msg:keyAction_Message);cdecl; external BEGUILIB; + + procedure MButton_AttachDrawDispatcher(btn:MButtonH; msg:drawAction_Message);cdecl; external BEGUILIB; + + {edit } + function MForm_AddMEdit(form:MFormH; left:double; top:double; right:double; bottom:double; + caption:Pchar):MEditH;cdecl; external BEGUILIB; + + function MEdit_getText(edt:MEditH):Pchar;cdecl; external BEGUILIB; + + procedure MEdit_setText(edt:MEditH; text:Pchar);cdecl; external BEGUILIB; + + procedure MEdit_AttachClickDispatcher(edt:MEditH; msg:base_Message);cdecl; external BEGUILIB; + + procedure MEdit_AttachMouseMovedDispatcher(edt:MEditH; msg:mouseMoved_Message);cdecl; external BEGUILIB; + + procedure MEdit_AttachMouseDownDispatcher(edt:MEditH; msg:mouseAction_Message);cdecl; external BEGUILIB; + + procedure MEdit_AttachMouseUpDispatcher(edt:MEditH; msg:mouseAction_Message);cdecl; external BEGUILIB; + + procedure MEdit_AttachKeyDownDispatcher(edt:MEditH; msg:keyAction_Message);cdecl; external BEGUILIB; + + procedure MEdit_AttachKeyUpDispatcher(edt:MEditH; msg:keyAction_Message);cdecl; external BEGUILIB; + + procedure MEdit_AttachDrawDispatcher(edt:MEditH; msg:drawAction_Message);cdecl; external BEGUILIB; + + {memo } + function MForm_AddMMemo(form:MFormH; left:double; top:double; right:double; bottom:double; + caption:Pchar):MMemoH;cdecl; external BEGUILIB; + + procedure MMemo_AttachMouseMovedDispatcher(memo:MMemoH; msg:mouseMoved_Message);cdecl; external BEGUILIB; + + procedure MMemo_AttachMouseDownDispatcher(memo:MMemoH; msg:mouseAction_Message);cdecl; external BEGUILIB; + + procedure MMemo_AttachMouseUpDispatcher(memo:MMemoH; msg:mouseAction_Message);cdecl; external BEGUILIB; + + procedure MMemo_AttachKeyDownDispatcher(memo:MMemoH; msg:keyAction_Message);cdecl; external BEGUILIB; + + procedure MMemo_AttachKeyUpDispatcher(memo:MMemoH; msg:keyAction_Message);cdecl; external BEGUILIB; + + procedure MMemo_AttachDrawDispatcher(memo:MMemoH; msg:drawAction_Message);cdecl; external BEGUILIB; + + {panel } + function MForm_AddMPanel(frm:MFormH; left:double; top:double; right:double; bottom:double; + name:Pchar):MPanelH;cdecl; external BEGUILIB; + + {needed?? } + function GetBaseMessage:uint32;cdecl; external BEGUILIB; + + function GetNextMessage:uint32;cdecl; external BEGUILIB; + +(* Const before type ignored *) + procedure GenericAlert(message:Pchar);cdecl; external BEGUILIB; + + procedure testfloat(f: integer);cdecl; external BEGUILIB; + +implementation + +initialization + Application := MApplication_create; +finalization + MApplication_free(Application); +end. \ No newline at end of file diff --git a/begui/begui/imports/pascal/examples/build.sh b/begui/begui/imports/pascal/examples/build.sh new file mode 100644 index 0000000..dcb8553 --- /dev/null +++ b/begui/begui/imports/pascal/examples/build.sh @@ -0,0 +1,3 @@ +fpc testapp.pas -Fu.. -Fl.. +fpc testapp3.pas -Fu.. -Fl.. +rm *.o diff --git a/begui/begui/imports/pascal/examples/testapp.pas b/begui/begui/imports/pascal/examples/testapp.pas new file mode 100644 index 0000000..8bdf8da --- /dev/null +++ b/begui/begui/imports/pascal/examples/testapp.pas @@ -0,0 +1,31 @@ +program TespApp; + +uses BeGUI; + +procedure EventTest(sender: pointer; msg: uint32); +begin + if sender <> nil then + GenericAlert(MButton_getCaption(sender)); +end; + +var + TestMsg: array[0..10] of char; + + Button1: MButtonH; + Edit1: MEditH; + MainForm: MFormH; + a: integer; +begin + TestMsg := 'Test'#0; + + MainForm := MApplication_GetMainForm(Application); + + Button1 := MButton_Create_int32(10, 10, 50, 20, @TestMsg); + MButton_AttachClickDispatcher(Button1, base_Message(@EventTest)); + + MForm_AddChild(MainForm, Button1); + + Edit1 := MForm_AddMEdit_int32(MainForm, 30, 100, 150, 150, @TestMsg); + + MApplication_Run(Application); +end. \ No newline at end of file diff --git a/begui/begui/imports/pascal/examples/testapp3.pas b/begui/begui/imports/pascal/examples/testapp3.pas new file mode 100644 index 0000000..5f34e78 --- /dev/null +++ b/begui/begui/imports/pascal/examples/testapp3.pas @@ -0,0 +1,305 @@ +program TespApp3; + +uses BeGUI, strings; + +Var + Calculator : MFormH; + Button: Array[1..10] Of MButtonH; + Button_Clear : MButtonH; + Button_Point : MButtonH; + Button_Egal : MButtonH; + Button_Plus : MButtonH; + Button_Minus : MButtonH; + Button_Multi : MButtonH; + Button_Divi : MButtonH; + Edit: MEditH; + Mem_Edit : String[20]; + Mem_Op : String[20]; + Mem_Operande : integer; + + Calculator_Visible : Boolean; + +Const + Pos_X : Array[1..3] of integer=(10,50,90); + Pos_Y : Array[1..4] of integer=(35,60,85,110); + weith = 30; + heigth = 10; + +procedure EventTest(sender: pointer; msg: uint32); +begin + if sender <> nil then + GenericAlert(MButton_getCaption(sender)); +end; + + + +Procedure EventButton(sender: pointer; msg: uint32); +var + Test: array[0..20] of char; + value: char; + value_real : real; + value_real2: real; + value_result: real; + er : Integer; +Begin + If sender <> nil Then + Begin + value := strPas(MButton_getCaption(sender))[1]; + + // For digit + If ( value ='1') Or ( value ='2') Or ( value ='3') or ( value ='4') + or ( value ='5') Or ( value ='6') Or ( value ='7') or ( value ='8') or (value='9') or (value='0')Then + Begin + //=C2=A0Add Value to the sting + Mem_Edit:=Mem_Edit+strPas(MButton_getCaption(sender)); + StrPCopy(test,Mem_Edit); + MEdit_setText(Edit,Test); + End; + Val(Mem_Edit,value_real,er); + // Clear + if ( value='C') Then + Begin + Mem_Op:=''; + Mem_Operande:=0; + Mem_Edit:=''; + MEdit_setText(Edit,nil); + End; + + // dot + If (Value='.') Then + Begin + If (Frac(value_real) = 0) Then + Begin + Mem_Edit:=Mem_Edit+'.'; + StrPCopy(test,Mem_Edit); + MEdit_setText(Edit,Test); + End; + End; + + // Egal + If (Value='=') Then + Begin + If (Mem_Op = '' ) Then + Begin + Str(value_real:6:2,Mem_Edit); + End Else + Begin + Val(Mem_Op,value_real2,er); + Case Mem_Operande of + 1 : Value_result:=value_real2+value_real; + 2 : Value_result:=value_real2-value_real; + 3 : Value_result:=value_real2*value_real; + 4 : Value_result:=value_real2/value_real; + End; + Str(value_result:6:2,Mem_Edit); + End; + StrPCopy(test,Mem_Edit); + MEdit_setText(Edit,Test); + End; + + // Plus + If (Value='+') Then + Begin + Mem_Op:=Mem_Edit; + Mem_Operande:=1; + Mem_Edit:=''; + StrPCopy(test,Mem_Edit); + MEdit_setText(Edit,Test); + End; + + // Minus + If (Value='-') Then + Begin + Mem_Op:=Mem_Edit; + Mem_Operande:=2; + Mem_Edit:=''; + StrPCopy(test,Mem_Edit); + MEdit_setText(Edit,Test); + End; + + // Multi + If (Value='*') Then + Begin + Mem_Op:=Mem_Edit; + Mem_Operande:=3; + Mem_Edit:=''; + StrPCopy(test,Mem_Edit); + MEdit_setText(Edit,Test); + End; + + // Division + If (Value='/') Then + Begin + Mem_Op:=Mem_Edit; + Mem_Operande:=4; + Mem_Edit:=''; + StrPCopy(test,Mem_Edit); + MEdit_setText(Edit,Test); + End; + + End; +End; + +procedure Create_Calculator; +var + Edit1: MEditH; + No_Button : Integer; +Begin + Mem_Edit:=''; + Mem_Op:=''; + Calculator_Visible:=false; + { create the form of the calculator } + { ??? - MApplication_AddForm don't take the value of size and position } + Calculator := MApplication_AddForm_int32(Application,250, 100, 500, 300, pchar('Calculator'),pchar('Calculator')); + + { create the 9 digits of the calculator } + { it's make error if i used a array of MButtonH + for No_Button:=1 to 9 Do + Begin + Button[No_Button] := MButton_Create_int32(10+(No_Button*10), 10, 50+(No_Button*10), 20, pchar('1')); + {MButton_AttachClickDispatcher(Button1, base_Message(@EventTest));} + MForm_AddChild(Calculator, Button[No_Button]); + End; + } + ////////////////////////////////////////////////////////////////////////////////////////////////////// + // Initialisation for the digit number + ////////////////////////////////////////////////////////////////////////////////////////////////////// + Button[1] := MButton_Create_int32(Pos_X[1], Pos_Y[1], Pos_X[1]+weith, Pos_Y[1]+heigth, pchar('1')); + MForm_AddChild(Calculator, Button[1]); + MButton_AttachClickDispatcher(Button[1], base_Message(@EventButton)); + + Button[2] := MButton_Create_int32(Pos_X[2],Pos_Y[1], Pos_X[2]+weith, Pos_Y[1]+heigth, pchar('2')); + MForm_AddChild(Calculator, Button[2]); + MButton_AttachClickDispatcher(Button[2], base_Message(@EventButton)); + + Button[3] := MButton_Create_int32(Pos_X[3],Pos_Y[1], Pos_X[3]+weith, Pos_Y[1]+heigth, pchar('3')); + MForm_AddChild(Calculator, Button[3]); + MButton_AttachClickDispatcher(Button[3], base_Message(@EventButton)); + + Button[4] := MButton_Create_int32(Pos_X[1],Pos_Y[2], Pos_X[1]+weith, Pos_Y[2]+heigth, pchar('4')); + MForm_AddChild(Calculator, Button[4]); + MButton_AttachClickDispatcher(Button[4], base_Message(@EventButton)); + + Button[5] := MButton_Create_int32(Pos_X[2], Pos_Y[2], Pos_X[2]+weith, Pos_Y[2]+heigth, pchar('5')); + MForm_AddChild(Calculator, Button[5]); + MButton_AttachClickDispatcher(Button[5], base_Message(@EventButton)); + + Button[6] := MButton_Create_int32(Pos_X[3],Pos_Y[2], Pos_X[3]+weith, Pos_Y[2]+heigth, pchar('6')); + MForm_AddChild(Calculator, Button[6]); + MButton_AttachClickDispatcher(Button[6], base_Message(@EventButton)); + + Button[7] := MButton_Create_int32(Pos_X[1],Pos_Y[3], Pos_X[1]+weith, Pos_Y[3]+heigth, pchar('7')); + MForm_AddChild(Calculator, Button[7]); + MButton_AttachClickDispatcher(Button[7], base_Message(@EventButton)); + + Button[8] := MButton_Create_int32(Pos_X[2],Pos_Y[3], Pos_X[2]+weith, Pos_Y[3]+heigth, pchar('8')); + MForm_AddChild(Calculator, Button[8]); + MButton_AttachClickDispatcher(Button[8], base_Message(@EventButton)); + + Button[9] := MButton_Create_int32(Pos_X[3],Pos_Y[3], Pos_X[3]+weith, Pos_Y[3]+heigth, pchar('9')); + MForm_AddChild(Calculator, Button[9]); + MButton_AttachClickDispatcher(Button[9], base_Message(@EventButton)); + + Button[10] := MButton_Create_int32(Pos_X[1],Pos_Y[4], Pos_X[1]+weith, Pos_Y[4]+heigth, pchar('0')); + MForm_AddChild(Calculator, Button[10]); + MButton_AttachClickDispatcher(Button[10], base_Message(@EventButton)); + + ////////////////////////////////////////////////////////////////////////////////////////////////////// + // Initialisation for the edit + ////////////////////////////////////////////////////////////////////////////////////////////////////// + Edit := MForm_AddMEdit_int32(Calculator, 9, 10, 160, 20, pchar('toto')); + + + ////////////////////////////////////////////////////////////////////////////////////////////////////// + // Initialisation for operation button + ////////////////////////////////////////////////////////////////////////////////////////////////////// + Button_Clear:=MButton_Create_int32(170,10,190,20, pchar('C')); + MForm_AddChild(Calculator, Button_clear); + MButton_AttachClickDispatcher(Button_Clear, base_Message(@EventButton)); + + Button_Egal:=MButton_Create_int32(170,35,190,45, pchar('=')); + MForm_AddChild(Calculator, Button_Egal); + MButton_AttachClickDispatcher(Button_Egal, base_Message(@EventButton)); + + Button_Plus:=MButton_Create_int32(170,60,190,65, pchar('+')); + MForm_AddChild(Calculator, Button_Plus); + MButton_AttachClickDispatcher(Button_Plus, base_Message(@EventButton)); + + Button_Minus:=MButton_Create_int32(170,85,190,95, pchar('-')); + MForm_AddChild(Calculator, Button_Minus); + MButton_AttachClickDispatcher(Button_Minus, base_Message(@EventButton)); + + Button_Multi:=MButton_Create_int32(170,110,190,120, pchar('*')); + MForm_AddChild(Calculator, Button_Multi); + MButton_AttachClickDispatcher(Button_Multi, base_Message(@EventButton)); + + Button_Divi:=MButton_Create_int32(170,135,190,145, pchar('/')); + MForm_AddChild(Calculator, Button_Divi); + MButton_AttachClickDispatcher(Button_Divi, base_Message(@EventButton)); + + Button_Point := MButton_Create_int32(Pos_X[2],Pos_Y[4], Pos_X[2]+weith, Pos_Y[4]+heigth, pchar('.')); + MForm_AddChild(Calculator, Button_Point); + MButton_AttachClickDispatcher(Button_Point, base_Message(@EventButton)); + +End; + +procedure Show_Calculator; +Begin + MForm_Show(Calculator); + Calculator_Visible:=true; +End; + +procedure Hide_Calculator; +Begin + MForm_Hide(Calculator); + Calculator_Visible:=false; +End; + +Procedure End_Calculator; +Begin +End; + +procedure Launch(sender: pointer; msg: uint32); +begin + if sender <> nil then + Begin + If Not Calculator_Visible Then Show_Calculator + Else Hide_Calculator; + End; +end; + + + +var + TestMsg: array[0..10] of char; + + Button1: MButtonH; + Launch_calc: MButtonH; + Edit1: MEditH; + MainForm: MFormH; + i,a: integer; + + +begin + TestMsg := 'Test'#0; + + MainForm := MApplication_GetMainForm(Application); + + Button1 := MButton_Create_int32(10, 10, 50, 20, @TestMsg); + MButton_AttachClickDispatcher(Button1, base_Message(@EventTest)); + MForm_AddChild(MainForm, Button1); + + Launch_calc := MButton_Create_int32(10, 30, 100, 40, pchar('Calculator')); + MButton_AttachClickDispatcher(Launch_calc, base_Message(@launch)); + MForm_AddChild(MainForm, Launch_calc); + + + Edit1 := MForm_AddMEdit_int32(MainForm, 30, 100, 150, 150, @TestMsg); + + + { test for MDI} + Create_Calculator; + + MApplication_Run(Application); +end. + diff --git a/begui/begui/libbegui/BeGuiAPI.cpp b/begui/begui/libbegui/BeGuiAPI.cpp new file mode 100644 index 0000000..477590b --- /dev/null +++ b/begui/begui/libbegui/BeGuiAPI.cpp @@ -0,0 +1,530 @@ +/* + $Header: /home/haiku/befpc/begui/begui/libbegui/BeGuiAPI.cpp,v 1.1.1.1 2002-03-31 10:36:07 memson Exp $ + + $Revision: 1.1.1.1 $ + + $Log: not supported by cvs2svn $ + Revision 1.20 2002/03/28 08:41:02 memson + + Commited to main tree by the above on behalf of : + + 2002/03/26 21:47:13 Jourde + Adding MApplication_AddForm_int32 to create form with correct position (for + Pascal) + + Revision 1.19 2002/03/26 13:28:51 memson + + added in combobox support - flawed at the moment. + + Revision 1.18 2002/03/14 22:31:41 memson + + Got the Menubar/menu/menuitem and popupmenu/menuitem both working... Had a + bit of a slack night, so didn't really do much else. + + Revision 1.17 2002/03/14 00:12:38 memson + + Revised the event and property class hierarchies... hopefully makes more + sense. + + Started to add in the Menu functionality. PopUpMenu is done and 'tested', + but the BMenuBar/BMenu (mainmenu) stuff is there but untested. + + Added in an OnCreate and OnDestroy event to the events, plust a wierd + offshoot class to handle the menuitem click. + + Revision 1.16 2002/03/12 23:12:37 memson + + hashed out some details - stopped child windows from screwing up app, and + also added the close action to form and terminating functionality to the app. + + Revision 1.15 2002/03/12 18:39:16 memson + + Revision 1.14 2002/03/11 23:54:06 memson + + the form works more happily, also sorted out form canvas issues. + + lost hours of work pissing about with pascal - needs quite a bit of revision + to get it happily working with fpc. + + Revision 1.13 2002/03/11 23:22:11 memson + + Revision 1.12 2002/03/03 11:31:38 memson + + began adding a class to hold additional properties (Owner and Tag for now). + + Revision 1.11 2002/02/19 17:49:53 memson + + Added half arsed support for multiple windows - not working quite right yet, + but at least they seem to 'work' in so much as they don't wipe the app out. + The secondary forms Canvas is screwed up a little.. that is a priority I + guess. + + + Revision 1.10 2002/02/18 19:28:34 memson + No *major* changes, cleaned things up a lot. Created MEventPlugin and now + use multiple inheritence to implement most of the event pointer storage. + This makes things a lot neater and also ensures that I don't have to write + the same code loads of time (mostly). + + Revision 1.9 2002/02/14 23:39:53 memson + I've now added most of the events to the MButton, MCanvas, MMemo and MEdit.. + started a MPanel component. Again, the MCanvas is *not* tread safe!!! + This means the calling thread must create it. + + NB. Before I add much more functionality, I'm going to look at other GUI + libs to see if there are any controls worth borrowing. + + Next control will probably be a MLabel followed by a MMenuBar and MMenuItem. + MForm will own a MMenuBar. + + Revision 1.8 2002/02/14 20:33:19 memson + Got the MButton OnClick, OnMouseDown/Up, OnKeyDown/Up and OnMouseMoved + events working. Started to add the required code to the rest of the classes + (should be a cut/paste job). + + Revision 1.7 2002/02/14 14:00:16 memson + fiddled a bit.. nothing major. + + Revision 1.6 2002/02/13 23:26:25 memson + Got the MMemo working. + Got the MEdit working, including OnClick event signal + Got the MButton working with a signal + Added a few get/set accessor routined for captions/text. + + Revision 1.5 2002/02/13 00:02:02 memson + Got the MTextControl basic functionality - annoying fact is that a text + control has to be added inside the thread that will display it!!!! + + Revision 1.4 2002/02/12 19:40:59 memson + Removed the Sender param for the MButton::DoClick() + + Revision 1.3 2002/02/11 23:26:44 memson + Revision 1.2 2002/01/17 20:32:54 memson + +*/ + +#define BEGUI_EXPORTS 1 + +#define MENU_BAR_HEIGHT 36.0 + +#include "MList.h" +#include "BeGuiAPI.h" +#include + +//clik - control click +#define ClickMessage 'clik' +#define ChangeMessage 'chng' + +#define TEXT_INSET 3.0 + +//////////////////////////////////////// +// +// API routines... +// +//////////////////////////////////////// + +MApplication *M_App = 0; + +MApplication* MApplication_Create(void){ + M_App = new MApplication(); + return M_App; +} + +void MApplication_Free(MApplication *app){ + app->Terminate(); +} + +void MApplication_Run(MApplication *app){ + app->Run(); +} + +MForm* MApplication_GetMainForm(MApplication *app){ + return app->GetMainForm(); +} + +MForm* MApplication_AddForm(MApplication *app, float left, float top, float right, float bottom, char *name, char *caption){ + BRect ClientArea(left, top, right, bottom); + return app->AddForm(ClientArea, BString(name), false); +} + +MForm* MApplication_AddForm_int32(MApplication *app, int32 left, int32 top, int32 right, int32 bottom, char *name, char *caption){ + BRect ClientArea(left, top, right, bottom); + return app->AddForm(ClientArea, BString(name), false); +} + +/// + +void MForm_AddChild(MForm *form, BControl *ctrl){ + form->Canvas()->AddChild(ctrl); + ctrl->SetTarget(form); +} + +MEdit* MForm_AddMEdit(MForm *form, float left, float top, float right, float bottom, char *caption){ + BRect btnRect(left, top, right, bottom); + return form->Canvas()->AddEdit(btnRect, caption); +} + +MEdit* MForm_AddMEdit_int32(MForm *form, int32 left, int32 top, int32 right, int32 bottom, char *caption){ + BRect btnRect(left, top, right, bottom); + return form->Canvas()->AddEdit(btnRect, caption); +} + +MMemo* MForm_AddMMemo(MForm *form, float left, float top, float right, float bottom, char *caption){ + BRect btnRect(left, top, right, bottom); + return form->Canvas()->AddMemo(btnRect, caption); +} + +MMemo* MForm_AddMMemo(MForm *form, int32 left, int32 top, int32 right, int32 bottom, char *caption){ + BRect btnRect(left, top, right, bottom); + return form->Canvas()->AddMemo(btnRect, caption); +} + +/// + +BButton* BButton_Create(float left, float top, float right, float bottom, char *caption, uint32 msg){ + BRect btnRect(left, top, right, bottom); + + return new BButton(btnRect, "testbutton", caption, new BMessage(msg)); +} + +MButton* MButton_Create(float left, float top, float right, float bottom, char *caption){ + BRect btnRect(left, top, right, bottom); + + return new MButton( btnRect, caption ); +} + +MButton* MButton_Create_int32(int32 left, int32 top, int32 right, int32 bottom, char *caption){ + BRect btnRect(left, top, right, bottom); + + return new MButton( btnRect, caption ); +} + +void MButton_AttachClickDispatcher(MButton *btn, base_Message msg){ + btn->AttachClickDispatcher(msg); +} + +char* MButton_getCaption(MButton *btn){ + return const_cast(btn->Label()); +} + +void MButton_setCaption(MButton *btn, char* caption){ + btn->SetLabel(caption); +} + +void MButton_AttachMouseMovedDispatcher(MButton *btn, mouseMoved_Message msg){ + btn->AttachMouseMovedDispatcher(msg); +} + +void MButton_AttachMouseDownDispatcher(MButton *btn, mouseAction_Message msg){ + btn->AttachMouseDownDispatcher(msg); +} + +void MButton_AttachMouseUpDispatcher(MButton *btn, mouseAction_Message msg){ + btn->AttachMouseUpDispatcher(msg); +} + +void MButton_AttachDrawDispatcher(MButton *btn, drawAction_Message msg){ + btn->AttachDrawDispatcher(msg); +} + +void MButton_AttachKeyDownDispatcher(MButton *btn, keyAction_Message msg){ + btn->AttachKeyDownDispatcher(msg); +} + +void MButton_AttachKeyUpDispatcher(MButton *btn, keyAction_Message msg){ + btn->AttachKeyUpDispatcher(msg); +} + +/// + +MCheckBox* MCheckBox_Create(float left, float top, float right, float bottom, char *caption){ + BRect btnRect(left, top, right, bottom); + + return new MCheckBox( btnRect, caption ); +} + +MCheckBox* MCheckBox_Create_int32(int32 left, int32 top, int32 right, int32 bottom, char *caption){ + BRect btnRect(left, top, right, bottom); + + return new MCheckBox( btnRect, caption ); +} + +char* MCheckBox_getCaption(MCheckBox *cbx){ + return const_cast(cbx->Label()); +} + +void MCheckBox_setCaption(MCheckBox *cbx, char* caption){ + cbx->SetLabel(caption); +} + +void MCheckBox_AttachMouseMovedDispatcher(MCheckBox *cbx, mouseMoved_Message msg){ + cbx->AttachMouseMovedDispatcher(msg); +} + +void MCheckBox_AttachMouseDownDispatcher(MCheckBox *cbx, mouseAction_Message msg){ + cbx->AttachMouseDownDispatcher(msg); +} + +void MCheckBox_AttachMouseUpDispatcher(MCheckBox *cbx, mouseAction_Message msg){ + cbx->AttachMouseUpDispatcher(msg); +} + +void MCheckBox_AttachKeyDownDispatcher(MCheckBox *cbx, keyAction_Message msg){ + cbx->AttachKeyDownDispatcher(msg); +} + +void MCheckBox_AttachKeyUpDispatcher(MCheckBox *cbx, keyAction_Message msg){ + cbx->AttachKeyUpDispatcher(msg); +} + +void MCheckBox_AttachDrawDispatcher(MCheckBox *cbx, drawAction_Message msg){ + cbx->AttachDrawDispatcher(msg); +} + +bool MCheckBox_Checked(MCheckBox *cbx){ + return cbx->Checked(); +} + +/// + +void MForm_AttachMouseMovedDispatcher(MForm *form, mouseMoved_Message msg){ + form->Canvas()->AttachMouseMovedDispatcher(msg); +} + +void MForm_AttachMouseDownDispatcher(MForm *form, mouseAction_Message msg){ + form->Canvas()->AttachMouseDownDispatcher(msg); +} + +void MForm_AttachMouseUpDispatcher(MForm *form, mouseAction_Message msg){ + form->Canvas()->AttachMouseUpDispatcher(msg); +} + +void MForm_AttachDrawDispatcher(MForm *form, drawAction_Message msg){ + form->Canvas()->AttachDrawDispatcher(msg); +} + +void MForm_AttachKeyDownDispatcher(MForm *form, keyAction_Message msg){ + form->Canvas()->AttachKeyDownDispatcher(msg); +} + +void MForm_AttachKeyUpDispatcher(MForm *form, keyAction_Message msg){ + form->Canvas()->AttachKeyUpDispatcher(msg); +} + +void MForm_Show(MForm *frm){ + printf("about to lock\n"); + if (frm->Lock()) { + frm->Show(); + printf("after show\n"); + frm->Unlock(); + printf("unlocked\n"); + } + else printf("lock failed\n"); +} + +void MForm_Hide(MForm *frm){ + frm->Hide(); +} + +/// + +void MEdit_AttachClickDispatcher(MEdit *edt, base_Message msg){ + edt->AttachClickDispatcher(msg); +} + +void MEdit_AttachMouseMovedDispatcher(MEdit *edt, mouseMoved_Message msg){ + edt->AttachMouseMovedDispatcher(msg); +} + +void MEdit_AttachMouseDownDispatcher(MEdit *edt, mouseAction_Message msg){ + edt->AttachMouseDownDispatcher(msg); +} + +void MEdit_AttachMouseUpDispatcher(MEdit *edt, mouseAction_Message msg){ + edt->AttachMouseUpDispatcher(msg); +} + +void MEdit_AttachDrawDispatcher(MEdit *edt, drawAction_Message msg){ + edt->AttachDrawDispatcher(msg); +} + +void MEdit_AttachKeyDownDispatcher(MEdit *edt, keyAction_Message msg){ + edt->AttachKeyDownDispatcher(msg); +} + +void MEdit_AttachKeyUpDispatcher(MEdit *edt, keyAction_Message msg){ + edt->AttachKeyUpDispatcher(msg); +} + +char* MEdit_getText(MEdit* edt){ + return const_cast(edt->Text()); +} + +void MEdit_setText(MEdit* edt, char* text){ + edt->SetText(text); +} + +/// + +void MMemo_AttachMouseMovedDispatcher(MMemo *memo, mouseMoved_Message msg){ + memo->AttachMouseMovedDispatcher(msg); +} + +void MMemo_AttachMouseDownDispatcher(MMemo *memo, mouseAction_Message msg){ + memo->AttachMouseDownDispatcher(msg); +} + +void MMemo_AttachMouseUpDispatcher(MMemo *memo, mouseAction_Message msg){ + memo->AttachMouseUpDispatcher(msg); +} + +void MMemo_AttachDrawDispatcher(MMemo *memo, drawAction_Message msg){ + memo->AttachDrawDispatcher(msg); +} + +void MMemo_AttachKeyDownDispatcher(MMemo *memo, keyAction_Message msg){ + memo->AttachKeyDownDispatcher(msg); +} + +void MMemo_AttachKeyUpDispatcher(MMemo *memo, keyAction_Message msg){ + memo->AttachKeyDownDispatcher(msg); +} + +/// + +MCheckBox* MForm_AddMCheckBox(MForm* frm, float left, float top, float right, float bottom, char *name){ + BRect cbxRect(left, top, right, bottom); + + return frm->Canvas()->AddCheckBox( cbxRect, name ); +} + +/// + +MPanel* MForm_AddMPanel(MForm* frm, float left, float top, float right, float bottom, char *name){ + BRect pnlRect(left, top, right, bottom); + + return frm->Canvas()->AddPanel( pnlRect, name ); +} + +MPanel* MForm_AddMPanel_int32(MForm* frm, int32 left, int32 top, int32 right, int32 bottom, char *name){ + BRect pnlRect(left, top, right, bottom); + + return frm->Canvas()->AddPanel( pnlRect, name ); +} + +/// + +void MForm_AddPopUpMenu(MForm *frm, MPopUpMenu *mni){ + frm->Lock(); + frm->Canvas()->setPopUpMenu(mni); + frm->Unlock(); +} + +MPopUpMenu* MPopUpMenu_Create(const char *name){ + return new MPopUpMenu(name); +} + +void MPopUpMenu_AddItem(MPopUpMenu *mnu, MMenuItem *itm){ + mnu->AddItem(dynamic_cast(itm)); +} + +MMenuItem* MMenuItem_Create(const char *name) +{ + return new MMenuItem(name); +} + +void MMenuItem_AttachMenuClickDispatcher(MMenuItem *mni, base_Message msg) +{ + mni->AttachMenuClickDispatcher(msg); +} + +/// + +BMenuBar* BMenuBar_Create(MForm* frm, const char *name) +{ + //BRect frame; + //frame.Set(0, MENU_BAR_HEIGHT, frm->Bounds().right, frm->Bounds().bottom + MENU_BAR_HEIGHT); + BRect menuBarRect; + menuBarRect.Set(0.0, 0.0, 32000.0, MENU_BAR_HEIGHT); + BMenuBar *mb = new BMenuBar(menuBarRect, "mainmenubar"); + frm->Lock(); + frm->ResizeBy(0.0, MENU_BAR_HEIGHT); + frm->Canvas()->AddChild(mb); + frm->Unlock(); + return mb; +} + +void BMenuBar_AddItem(BMenuBar *mnu, BMenu *itm) +{ + mnu->AddItem(itm); +} + +BMenu* BMenu_Create(const char *name) +{ + return new BMenu(name); +} + +void BMenu_AddItem(BMenu *mnu, MMenuItem *itm) +{ + mnu->AddItem(itm); +} + +///////////////////////////////////////// + +//utility + +uint32 _BASE_MESSAGE = 0; + +uint32 GetNextMessage(void){ + if (_BASE_MESSAGE == 0){ + _BASE_MESSAGE = GetBaseMessage(); + } + return _BASE_MESSAGE++; +} + +uint32 GetBaseMessage(void){ + return 'bgui'; +} + +void GenericAlert(const char *message){ + BAlert *alert; + + alert = new BAlert("Info", message, "OK"); + alert->Go(); +} + +///////////////////////////////////////// + +//Test the API +int test(void) +{ + return 33; +} + +//Private Local var for test +CTest* FTest; + +//Init the test class +CTest* CTest_Create(void){ + FTest = new CTest(); + return FTest; +} + +//GetValue +int CTest_GetValue(CTest* ptr){ + int ReturnValue; + ReturnValue = ptr->GetValue(); + return ReturnValue; +} + +//SetValue +void CTest_SetValue(CTest* ptr, int val){ + ptr->SetValue(val); +} + +//Destroy the variable +void CTest_Free(CTest* ptr){ + delete &ptr; +} + + diff --git a/begui/begui/libbegui/BeGuiAPI.h b/begui/begui/libbegui/BeGuiAPI.h new file mode 100644 index 0000000..2eff722 --- /dev/null +++ b/begui/begui/libbegui/BeGuiAPI.h @@ -0,0 +1,143 @@ +#ifndef BEGUIAPI_H +#define BEGUIAPI_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "MList.h" +#include "BeGuiClasses.h" + + +//////////////////////////////////////////////////////////////////// + +typedef void (*base_Message)(void* sender, uint32 msg); //callback event +typedef void (*mouseMoved_Message)(void* sender, float x, float y, uint32 code, uint32 msg); +typedef void (*mouseAction_Message)(void* sender, float x, float y); +typedef void (*keyAction_Message)(void* sender, const char *bytes, int32 numBytes); +typedef void (*drawAction_Message)(void* sender, float left, float top, float right, float bottom); + +//Exports... + +#ifdef __cplusplus +extern "C" { +#endif + +int test(void); +CTest* CTest_Create(void); +int CTest_GetValue(CTest* ptr); +void CTest_Free(CTest* ptr); +void CTest_SetValue(CTest* ptr, int val); + +//application +MApplication* MApplication_Create(void); +void MApplication_Free(MApplication *app); +void MApplication_Run(MApplication *app); +MForm* MApplication_GetMainForm(MApplication *app); +MForm* MApplication_AddForm(MApplication *app, float left, float top, float right, float bottom, char *name, char *caption); +//eric 27/03/2002 +MForm* MApplication_AddForm_int32(MApplication *app, int32 left, int32 top, int32 right, int32 bottom, char *name, char *caption); + +//form +void MForm_AddChild(MForm *form, BControl* ctrl); +void MForm_AttachMouseMovedDispatcher(MForm *form, mouseMoved_Message msg); +void MForm_AttachMouseDownDispatcher(MForm *form, mouseAction_Message msg); +void MForm_AttachMouseUpDispatcher(MForm *form, mouseAction_Message msg); +void MForm_AttachKeyDownDispatcher(MForm *form, keyAction_Message msg); +void MForm_AttachKeyUpDispatcher(MForm *form, keyAction_Message msg); +void MForm_AttachDrawDispatcher(MForm *form, drawAction_Message msg); +void MForm_Show(MForm *frm); +void MForm_Hide(MForm *frm); +void MForm_AddPopUpMenu(MForm *frm, MPopUpMenu *mni); + +//button +MButton* MButton_Create(float left, float top, float right, float bottom, char *caption); +MButton* MButton_Create_int32(int32 left, int32 top, int32 right, int32 bottom, char *caption); +void MButton_AttachClickDispatcher(MButton *btn, base_Message msg); +char* MButton_getCaption(MButton *btn); +void MButton_setCaption(MButton *btn, char* caption); +void MButton_AttachMouseMovedDispatcher(MButton *btn, mouseMoved_Message msg); +void MButton_AttachMouseDownDispatcher(MButton *btn, mouseAction_Message msg); +void MButton_AttachMouseUpDispatcher(MButton *btn, mouseAction_Message msg); +void MButton_AttachKeyDownDispatcher(MButton *btn, keyAction_Message msg); +void MButton_AttachKeyUpDispatcher(MButton *btn, keyAction_Message msg); +void MButton_AttachDrawDispatcher(MButton *btn, drawAction_Message msg); + +//edit +MEdit* MForm_AddMEdit(MForm *form, float left, float top, float right, float bottom, char *caption); +MEdit* MForm_AddMEdit_int32(MForm *form, int32 left, int32 top, int32 right, int32 bottom, char *caption); +char* MEdit_getText(MEdit* edt); +void MEdit_setText(MEdit* edt, char* text); +void MEdit_AttachClickDispatcher(MEdit *edt, base_Message msg); +void MEdit_AttachMouseMovedDispatcher(MEdit *edt, mouseMoved_Message msg); +void MEdit_AttachMouseDownDispatcher(MEdit *edt, mouseAction_Message msg); +void MEdit_AttachMouseUpDispatcher(MEdit *edt, mouseAction_Message msg); +void MEdit_AttachKeyDownDispatcher(MEdit *edt, keyAction_Message msg); +void MEdit_AttachKeyUpDispatcher(MEdit *edt, keyAction_Message msg); +void MEdit_AttachDrawDispatcher(MEdit *edt, drawAction_Message msg); + +//memo +MMemo* MForm_AddMMemo(MForm *form, float left, float top, float right, float bottom, char *caption); +MMemo* MForm_AddMMemo_int32(MForm *form, int32 left, int32 top, int32 right, int32 bottom, char *caption); +void MMemo_AttachMouseMovedDispatcher(MMemo *memo, mouseMoved_Message msg); +void MMemo_AttachMouseDownDispatcher(MMemo *memo, mouseAction_Message msg); +void MMemo_AttachMouseUpDispatcher(MMemo *memo, mouseAction_Message msg); +void MMemo_AttachKeyDownDispatcher(MMemo *memo, keyAction_Message msg); +void MMemo_AttachKeyUpDispatcher(MMemo *memo, keyAction_Message msg); +void MMemo_AttachDrawDispatcher(MMemo *memo, drawAction_Message msg); + +//panel +MPanel* MForm_AddMPanel(MForm* frm, float left, float top, float right, float bottom, char *name); +MPanel* MForm_AddMPanel_int32(MForm* frm, int32 left, int32 top, int32 right, int32 bottom, char *name); + +//popupmenu +MPopUpMenu* MPopUpMenu_Create(const char *name); +void MPopUpMenu_AddItem(MPopUpMenu *mnu, MMenuItem *itm); + +//menuitem +MMenuItem* MMenuItem_Create(const char *name); +void MMenuItem_AttachMenuClickDispatcher(MMenuItem *mni, base_Message msg); + +//menubar +BMenuBar* BMenuBar_Create(MForm* frm, const char *name); +void BMenuBar_AddItem(BMenuBar *mnu, BMenu *itm); + +//BMenu +BMenu* BMenu_Create(const char *name); +void BMenu_AddItem(BMenu *mnu, MMenuItem *itm); + +//checkbox +MCheckBox* MCheckBox_Create(float left, float top, float right, float bottom, char *caption); +MCheckBox* MCheckBox_Create_int32(int32 left, int32 top, int32 right, int32 bottom, char *caption); +MCheckBox* MForm_AddMCheckBox(MForm* frm, float left, float top, float right, float bottom, char *name); +char* MCheckBox_getCaption(MCheckBox *cbx); +void MCheckBox_setCaption(MCheckBox *cbx, char* caption); +void MCheckBox_AttachMouseMovedDispatcher(MCheckBox *cbx, mouseMoved_Message msg); +void MCheckBox_AttachMouseDownDispatcher(MCheckBox *cbx, mouseAction_Message msg); +void MCheckBox_AttachMouseUpDispatcher(MCheckBox *cbx, mouseAction_Message msg); +void MCheckBox_AttachKeyDownDispatcher(MCheckBox *cbx, keyAction_Message msg); +void MCheckBox_AttachKeyUpDispatcher(MCheckBox *cbx, keyAction_Message msg); +void MCheckBox_AttachDrawDispatcher(MCheckBox *cbx, drawAction_Message msg); +bool MCheckBox_Checked(MCheckBox *cbx); + +//needed?? +uint32 GetBaseMessage(void); +uint32 GetNextMessage(void); +void GenericAlert(const char *message); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/begui/begui/libbegui/BeGuiClasses.cpp b/begui/begui/libbegui/BeGuiClasses.cpp new file mode 100644 index 0000000..4a3567d --- /dev/null +++ b/begui/begui/libbegui/BeGuiClasses.cpp @@ -0,0 +1,1192 @@ +/* + $Header: /home/haiku/befpc/begui/begui/libbegui/BeGuiClasses.cpp,v 1.1.1.1 2002-03-31 10:36:16 memson Exp $ + + $Revision: 1.1.1.1 $ + + $Log: not supported by cvs2svn $ + Revision 1.19 2002/03/26 13:28:51 memson + + added in combobox su[pport - flawed at the moment. + + Revision 1.18 2002/03/14 22:31:41 memson + + Got the Menubar/menu/menuitem and popupmenu/menuitem both working... Had a + bit of a slack night, so didn't really do much else. + + Revision 1.17 2002/03/14 00:12:38 memson + + Revised the event and property class hierarchies... hopefully makes more + sense. + + Started to add in the Menu functionality. PopUpMenu is done and 'tested', + but the BMenuBar/BMenu (mainmenu) stuff is there but untested. + + Added in an OnCreate and OnDestroy event to the events, plust a wierd + offshoot class to handle the menuitem click. + + Revision 1.6 2002/03/12 23:12:37 memson + + hashed out some details - stopped child windows from screwing up app, and + also added the close action to form and terminating functionality to the app. + + Revision 1.15 2002/03/12 18:39:16 memson + + + Revision 1.14 2002/03/11 23:54:06 memson + + the form works more happily, also sorted out form canvas issues. + + lost hours of work pissing about with pascal - needs quite a bit of revision + to get it happily working with fpc. + + Revision 1.13 2002/03/11 23:22:11 memson + + Revision 1.12 2002/03/03 11:31:38 memson + + began adding a class to hold additional properties (Owner and Tag for now). + + Revision 1.11 2002/02/19 17:49:53 memson + + Added half arsed support for multiple windows - not working quite right yet, + but at least they seem to 'work' in so much as they don't wipe the app out. + The secondary forms Canvas is screwed up a little.. that is a priority I + guess. + + + Revision 1.10 2002/02/18 19:28:34 memson + No *major* changes, cleaned things up a lot. Created MEventPlugin and now + use multiple inheritence to implement most of the event pointer storage. + This makes things a lot neater and also ensures that I don't have to write + the same code loads of time (mostly). + + Revision 1.9 2002/02/14 23:39:53 memson + I've now added most of the events to the MButton, MCanvas, MMemo and MEdit.. + started a MPanel component. Again, the MCanvas is *not* tread safe!!! + This means the calling thread must create it. + + NB. Before I add much more functionality, I'm going to look at other GUI + libs to see if there are any controls worth borrowing. + + Next control will probably be a MLabel followed by a MMenuBar and MMenuItem. + MForm will own a MMenuBar. + + Revision 1.8 2002/02/14 20:33:19 memson + Got the MButton OnClick, OnMouseDown/Up, OnKeyDown/Up and OnMouseMoved + events working. Started to add the required code to the rest of the classes + (should be a cut/paste job). + + Revision 1.7 2002/02/14 14:00:16 memson + fiddled a bit.. nothing major. + + Revision 1.6 2002/02/13 23:26:25 memson + Got the MMemo working. + Got the MEdit working, including OnClick event signal + Got the MButton working with a signal + Added a few get/set accessor routined for captions/text. + + Revision 1.5 2002/02/13 00:02:02 memson + Got the MTextControl basic functionality - annoying fact is that a text + control has to be added inside the thread that will display it!!!! + + Revision 1.4 2002/02/12 19:40:59 memson + Removed the Sebder param for the MButton::DoClick() + + Revision 1.3 2002/02/11 23:26:44 memson + Revision 1.2 2002/01/17 20:32:54 memson + +*/ + +#define BEGUI_EXPORTS 1 + +#include "MList.h" +#include "BeGuiClasses.h" +#include + +//clik - control click +#define ClickMessage 'clik' +#define ChangeMessage 'chng' + +#define TEXT_INSET 3.0 + +//////////////////////////////////////// +// +// Classes... +// +//////////////////////////////////////// + +//////////////////////////////////////// + +// List classes... + +//List item for storing GUI classes... + +MGUIListItem::MGUIListItem(BString name, void *item): + MListItem(item) +{ + fName = name; +} + +BString MGUIListItem::getName(void){ + return fName; +} + +void MGUIListItem::setName(BString name){ + fName = name; +} + +// GUI Item store.... + +MGUIListItem* MGUIList::GetItem(int32 index){ + return (MGUIListItem*) GetItem(index); +} + +////////////////////////////////////////// + +MPropertyPlugin::MPropertyPlugin(BArchivable *AOwner) +{ + FOwner = AOwner; +} + +MPropertyPlugin::MPropertyPlugin() +{ + FOwner = 0; +} + +MPropertyPlugin::~MPropertyPlugin() +{ + FOwner = 0; +} + +void MPropertyPlugin::setTag(uint32 ATag) +{ + FTag = ATag; +} + +uint32 MPropertyPlugin::getTag(void) +{ + return FTag; +} + +BArchivable* MPropertyPlugin::getOwner(void) +{ + return FOwner; +} + +void MPropertyPlugin::setOwner(BArchivable *AOwner) +{ + if (AOwner != FOwner){ + //change over + } + + FOwner = AOwner; +} + +////////////////////////////////////////// + +// Property Plugin Class... + +MMenuPropertyPlugin::MMenuPropertyPlugin(BArchivable *AOwner): + MPropertyPlugin(AOwner) +{ + fPopUpMenu = 0; +} + +MMenuPropertyPlugin::~MMenuPropertyPlugin() +{ + //this control will be owned by a BView..BView + fPopUpMenu = 0; +} + +void MMenuPropertyPlugin::setPopUpMenu(MPopUpMenu *menu) +{ + fPopUpMenu = menu; +} + +MPopUpMenu* MMenuPropertyPlugin::getPopUpMenu(void) +{ + return fPopUpMenu; +} + +////////////////////////////////////////// + +// EventPlugin Class... + +MEventPlugin::MEventPlugin() +{ + fOnCreate = 0; + fOnDestroy = 0; +} + +MEventPlugin::~MEventPlugin() +{ + fOnCreate = 0; + fOnDestroy = 0; +} + +void MEventPlugin::AttachCreateDispatcher(genericEvent_Message value) +{ + fOnCreate = value; +} + +void MEventPlugin::AttachDestroyDispatcher(genericEvent_Message value) +{ + fOnDestroy = value; +} + +void MEventPlugin::DoCreate(BControl *self) +{ + if (fOnCreate != NULL){ + fOnCreate( self ); + } +} + +void MEventPlugin::DoDestroy(BControl *self) +{ + if (fOnDestroy != NULL){ + fOnDestroy( self ); + } +} + +////////////////////////////////////////// + +// + +MMenuEventPlugin::MMenuEventPlugin() +{ + fOnMenuClick = 0; +} + +MMenuEventPlugin::~MMenuEventPlugin() +{ + fOnMenuClick = 0; +} + +void MMenuEventPlugin::DoMenuClick(MMenuItem *self) +{ + if (fOnMenuClick != NULL){ + fOnMenuClick( self, ClickMessage ); + } +} + +void MMenuEventPlugin::AttachMenuClickDispatcher(base_Message value) +{ + fOnMenuClick = value; +} + +////////////////////////////////////////// + +//BasicEventPlugin Class... + +MBasicEventPlugin::MBasicEventPlugin(): + MEventPlugin() +{ + fOnClick = 0; + fOnChange = 0; +} + +MBasicEventPlugin::~MBasicEventPlugin() +{ + fOnClick = 0; + fOnChange = 0; +} + +void MBasicEventPlugin::AttachClickDispatcher(base_Message value) +{ + fOnClick = value; +} + +void MBasicEventPlugin::AttachChangeDispatcher(base_Message value) +{ + fOnChange = value; +} + +void MBasicEventPlugin::DoChange(BControl *self) +{ + if (fOnChange != NULL){ + fOnChange( self, ChangeMessage ); + } +} + +void MBasicEventPlugin::DoClick(BControl *self) +{ + if (fOnClick != NULL){ + fOnClick( dynamic_cast(this), ClickMessage ); + } +} + +////////////////////////////////////////// + +//ControlEventPlugin Class... + +MControlEventPlugin::MControlEventPlugin(): + MBasicEventPlugin() +{ + fOnMouseMove = 0; + fOnMouseUp = 0; + fOnMouseDown = 0; + fOnKeyUp = 0; + fOnKeyDown = 0; + fOnDraw = 0; + fOnKeyPress = 0; +} + +MControlEventPlugin::~MControlEventPlugin() +{ + fOnMouseMove = 0; + fOnMouseUp = 0; + fOnMouseDown = 0; + fOnKeyUp = 0; + fOnKeyDown = 0; + fOnDraw = 0; + fOnKeyPress = 0; +} + +void MControlEventPlugin::AttachDrawDispatcher(drawAction_Message value) +{ + fOnDraw = value; +} + +void MControlEventPlugin::AttachMouseDownDispatcher(mouseAction_Message value) +{ + fOnMouseDown = value; +} + +void MControlEventPlugin::AttachMouseUpDispatcher(mouseAction_Message value) +{ + fOnMouseUp = value; +} + +void MControlEventPlugin::AttachMouseMovedDispatcher(mouseMoved_Message value) +{ + fOnMouseMove = value; +} + +void MControlEventPlugin::AttachKeyDownDispatcher(keyAction_Message value) +{ + fOnKeyDown = value; +} + +void MControlEventPlugin::AttachKeyUpDispatcher(keyAction_Message value) +{ + fOnKeyUp = value; +} + +void MControlEventPlugin::AttachKeyPressDispatcher(keyAction_Message value) +{ + fOnKeyPress = value; +} + +void MControlEventPlugin::DoKeyPress(BControl *self, const char *bytes, int32 numBytes) +{ + if (fOnKeyPress != NULL){ + fOnKeyPress( self, bytes, numBytes ); + } +} + +////////////////////////////////////////// + +// Form Event Property + +MFormEventPlugin::MFormEventPlugin(): + MEventPlugin() +{ + fOnClose = 0; +} + +MFormEventPlugin::~MFormEventPlugin() +{ + fOnClose = 0; +} + +void MFormEventPlugin::AttachCloseDispatcher(closeAction_Message value) +{ + fOnClose = value; +} + +void MFormEventPlugin::DoClose(BView *self, MCloseAction &closeAction) +{ + if (fOnClose != NULL){ + fOnClose( self, closeAction ); + } +} + +////////////////////////////////////////// + +//Panel Class... + +MPanel::MPanel(BRect ClientArea, char *name): + MCanvas(ClientArea, name) +{ + SetViewColor(200, 200, 200); +} + +void MPanel::Draw(BRect updateArea) +{ + MCanvas::Draw(updateArea); +} + + +////////////////////////////////////////// + +//Memo Class... + +MMemo::MMemo(char *name): + BScrollView(name, + fTextArea = new BTextView(BRect(0, 0, 50, 50), + "TextArea", + BRect(0, 0, + (50 - TEXT_INSET), + (50 - TEXT_INSET)), + B_FOLLOW_ALL, + B_WILL_DRAW), + B_FOLLOW_ALL, + true, true, + B_FANCY_BORDER), + MControlEventPlugin(), + MPropertyPlugin(NULL) +{ + fTextArea->SetStylable(true); +} + +MMemo::MMemo(BRect frame, char *name): + BScrollView(name, + fTextArea = new BTextView( + BRect(frame.left, + frame.top, + (frame.right - B_V_SCROLL_BAR_WIDTH), + (frame.bottom - B_H_SCROLL_BAR_HEIGHT)), + "TextArea", + BRect(0, 0, + (frame.right - frame.left - TEXT_INSET - B_V_SCROLL_BAR_WIDTH), + (frame.bottom - frame.top - TEXT_INSET - B_H_SCROLL_BAR_HEIGHT)), + B_FOLLOW_ALL, + B_WILL_DRAW), + B_FOLLOW_ALL, + true, true, + B_FANCY_BORDER), + MControlEventPlugin(), + MPropertyPlugin(NULL) +{ + fTextArea->SetStylable(true); +} + +BTextView* MMemo::getTextView(void) +{ + return fTextArea; +} + +void MMemo::AttachedToWindow() +{ + fTextArea->SetFont(be_bold_font); + fTextArea->SetFontSize(12); + + fTextArea->MakeFocus(); +} + +void MMemo::KeyDown(const char *bytes, int32 numBytes) +{ + BScrollView::KeyDown(bytes, numBytes); + + if (fOnKeyDown != NULL){ + fOnKeyDown( this, bytes, numBytes ); + } +} + +void MMemo::KeyUp(const char *bytes, int32 numBytes) +{ + BScrollView::KeyUp(bytes, numBytes); + + if (fOnKeyUp != NULL){ + fOnKeyUp( this, bytes, numBytes ); + } + DoChange(dynamic_cast(this)); //simulate a 'change' event... +} + +void MMemo::MouseDown(BPoint pt) +{ + BScrollView::MouseDown(pt); + + if (fOnMouseDown != NULL){ + fOnMouseDown( this, pt.x, pt.y ); + } +} + +void MMemo::MouseUp(BPoint pt) +{ + BScrollView::MouseUp(pt); + + if (fOnMouseUp != NULL){ + fOnMouseUp( this, pt.x, pt.y ); + } + DoClick(dynamic_cast(this)); //simulate a click event +} + +void MMemo::MouseMoved(BPoint pt, uint32 code, const BMessage *msg) +{ + BScrollView::MouseMoved(pt, code, msg); + + if (fOnMouseMove != NULL){ + fOnMouseMove( this, pt.x, pt.y, code, 0 ); + } +} + +void MMemo::Draw(BRect updateArea) +{ + BScrollView::Draw(updateArea); + + if (fOnDraw != NULL){ + fOnDraw( this, updateArea.left, updateArea.top, updateArea.right, updateArea.bottom ); + } + +} + +////////////////////////////////////////// + +// MComboBox + +MCheckBox::MCheckBox(BRect frame, char *name): + BCheckBox(frame, name, name, new BMessage(ClickMessage)), + MControlEventPlugin(), + MPropertyPlugin(NULL) +{ + DoCreate(dynamic_cast(this)); +} + +MCheckBox::~MCheckBox() +{ + DoDestroy(dynamic_cast(this)); +} + +void MCheckBox::KeyDown(const char *bytes, int32 numBytes) +{ + BControl::KeyDown(bytes, numBytes); + + if (fOnKeyDown != NULL){ + fOnKeyDown( this, bytes, numBytes ); + } +} + +void MCheckBox::KeyUp(const char *bytes, int32 numBytes) +{ + BControl::KeyUp(bytes, numBytes); + + if (fOnKeyUp != NULL){ + fOnKeyUp( this, bytes, numBytes ); + } + DoChange(dynamic_cast(this)); //simulate a 'change' event... +} + +void MCheckBox::MouseDown(BPoint pt) +{ + BControl::MouseDown(pt); + + if (fOnMouseDown != NULL){ + fOnMouseDown( this, pt.x, pt.y ); + } +} + +void MCheckBox::MouseUp(BPoint pt) +{ + BControl::MouseUp(pt); + + if (fOnMouseUp != NULL){ + fOnMouseUp( this, pt.x, pt.y ); + } + DoClick(dynamic_cast(this)); //simulate a click event +} + +void MCheckBox::MouseMoved(BPoint pt, uint32 code, const BMessage *msg) +{ + BControl::MouseMoved(pt, code, msg); + + if (fOnMouseMove != NULL){ + fOnMouseMove( this, pt.x, pt.y, code, 0 ); + } +} + +void MCheckBox::Draw(BRect updateArea) +{ + BControl::Draw(updateArea); + + if (fOnDraw != NULL){ + fOnDraw( this, updateArea.left, updateArea.top, updateArea.right, updateArea.bottom ); + } + +} + +bool MCheckBox::Checked(void) +{ + if (this->Value() == B_CONTROL_ON) + return true; + else + return false; +} + + + +////////////////////////////////////////// + +//Edit Class... + +MEdit::MEdit(char *name): + BTextControl(BRect(0, 0, 25, 50), name, NULL, "", new BMessage(ChangeMessage)), + MControlEventPlugin(), + MPropertyPlugin(NULL) +{ + DoCreate( dynamic_cast(this) ); +} + +MEdit::MEdit(BRect frame, char *name): + BTextControl(frame, name, NULL, "", new BMessage(ChangeMessage)), + MControlEventPlugin(), + MPropertyPlugin(NULL) +{ + DoCreate( dynamic_cast(this) ); +} + +MEdit::~MEdit() +{ + DoDestroy( dynamic_cast(this) ); +} + +void MEdit::KeyDown(const char *bytes, int32 numBytes) +{ + BTextControl::KeyDown(bytes, numBytes); + + if (fOnKeyDown != NULL){ + fOnKeyDown( this, bytes, numBytes ); + } +} + +void MEdit::KeyUp(const char *bytes, int32 numBytes) +{ + BTextControl::KeyUp(bytes, numBytes); + + if (fOnKeyUp != NULL){ + fOnKeyUp( this, bytes, numBytes ); + } +} + +void MEdit::MouseDown(BPoint pt) +{ + BTextControl::MouseDown(pt); + + if (fOnMouseDown != NULL){ + fOnMouseDown( this, pt.x, pt.y ); + } +} + +void MEdit::MouseUp(BPoint pt) +{ + BTextControl::MouseUp(pt); + + if (fOnMouseUp != NULL){ + fOnMouseUp( this, pt.x, pt.y ); + } + DoClick(this); //simulate click event +} + +void MEdit::MouseMoved(BPoint pt, uint32 code, const BMessage *msg) +{ + BTextControl::MouseMoved(pt, code, msg); + + if (fOnMouseMove != NULL){ + fOnMouseMove( this, pt.x, pt.y, code, 0 ); + } +} + +void MEdit::Draw(BRect updateArea) +{ + BTextControl::Draw(updateArea); + + if (fOnDraw != NULL){ + fOnDraw( this, updateArea.left, updateArea.top, updateArea.right, updateArea.bottom ); + } + +} + +////////////////////////////////////////// + +//Button Class... + +MButton::MButton(char *name): + BButton(BRect(0, 0, 25, 50), name, name, new BMessage(ClickMessage)), + MControlEventPlugin(), + MPropertyPlugin(NULL) +{ + DoCreate(dynamic_cast(this)); +} + +MButton::MButton(BRect frame, char *name): + BButton(frame, name, name, new BMessage(ClickMessage)), + MControlEventPlugin(), + MPropertyPlugin(NULL) +{ + DoCreate(dynamic_cast(this)); +} + +MButton::~MButton() +{ + DoDestroy(dynamic_cast(this)); +} + +void MButton::KeyDown(const char *bytes, int32 numBytes) +{ + BButton::KeyDown(bytes, numBytes); + + if (fOnKeyDown != NULL){ + fOnKeyDown( this, bytes, numBytes ); + } +} + +void MButton::KeyUp(const char *bytes, int32 numBytes) +{ + BButton::KeyUp(bytes, numBytes); + + if (fOnKeyUp != NULL){ + fOnKeyUp( this, bytes, numBytes ); + } +} + +void MButton::MouseDown(BPoint pt) +{ + BButton::MouseDown(pt); + + if (fOnMouseDown != NULL){ + fOnMouseDown( this, pt.x, pt.y ); + } +} + +void MButton::MouseUp(BPoint pt) +{ + BButton::MouseUp(pt); + + if (fOnMouseUp != NULL){ + fOnMouseUp( this, pt.x, pt.y ); + } +} + +void MButton::MouseMoved(BPoint pt, uint32 code, const BMessage *msg) +{ + BButton::MouseMoved(pt, code, msg); + + if (fOnMouseMove != NULL){ + fOnMouseMove( this, pt.x, pt.y, code, 0 ); + } +} + +void MButton::Draw(BRect updateArea) +{ + BButton::Draw(updateArea); + + if (fOnDraw != NULL){ + fOnDraw( this, updateArea.left, updateArea.top, updateArea.right, updateArea.bottom ); + } +} + +////////////////////////////////////////// + +//Application Class... + +MApplication::MApplication(): + BApplication("application/x-vnd.beguiapp"), + MEventPlugin() +{ + BRect tmpRect; + tmpRect.Set(50, 50, 1000, 500); + BString formname = "main"; + + fMainForm = new MForm(tmpRect); + fMainForm->Show(); + + fForms = new MGUIList(); + fForms->AddItem(new MGUIListItem(formname, fMainForm)); + + fTerminating = false; //controls the act of shutting down + + DoCreate( dynamic_cast(this) ); +} + +MApplication::MApplication(MForm* mainForm): + BApplication("application/x-vnd.beguiapp"), + MEventPlugin() +{ + BString formname = "main"; + + fMainForm = mainForm; + fMainForm->Show(); + + fForms = new MGUIList(); + fForms->AddItem(new MGUIListItem(formname, fMainForm)); + + fTerminating = false; //controls the act of shutting down + + DoCreate( dynamic_cast(this) ); +} + +MApplication::~MApplication() +{ + DoDestroy( dynamic_cast(this) ); +} + +void MApplication::Terminate(void) +{ + //if main form is dead, we must not call this because... + if (!fTerminating) + { + //...fTerminating is set by fMainForm as it exits. + fMainForm->QuitRequested(); + } +} + +MForm* MApplication::AddForm(BRect ClientArea, BString name, bool showForm = false) +{ + MForm *form = new MForm(ClientArea); + fForms->AddItem(new MGUIListItem(name, form)); + form->Lock(); + form->Run(); + if (showForm) form->Show(); + form->Unlock(); + return form; +} + + +//////////////////////////////////////// + +//Form Class... + +MForm::MForm(BRect ClientArea): + BWindow(ClientArea, "Form", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS), + MFormEventPlugin() +{ + fClientArea = Bounds(); + + fClientArea.OffsetTo(B_ORIGIN); //reset position + fCanvas = new MCanvas(fClientArea, "Canvas"); + AddChild(fCanvas); + + fCloseAction = caHide; + + DoCreate(dynamic_cast(this)); +} + +MForm::~MForm() +{ + DoDestroy(dynamic_cast(this)); +} + +void MForm::MessageReceived(BMessage *message){ + void *pointer; + BControl *control; + MButton *btn; + MMenuItem *mni; + MEdit *edt; + + if (message->FindPointer("source", &pointer) == B_OK) + { + if ((control = reinterpret_cast(pointer)) != NULL) + { + if ((btn = dynamic_cast(control)) != NULL){ + btn->DoClick(btn); + } + else if ((edt = dynamic_cast(control)) != NULL){ + edt->DoChange(edt); //this is a funny event!! + } + else if ((mni = dynamic_cast(control)) != NULL){ + mni->DoMenuClick(mni); + } + } + else + { + BWindow::MessageReceived(message); + } + } + else + { + BWindow::MessageReceived(message); + } +} + +bool MForm::QuitRequested() +{ + MForm *frm; + + //handle the close event + DoClose(dynamic_cast(this), fCloseAction); + + if (dynamic_cast(be_app) != NULL) + { + //when terminating, just exit + if ( dynamic_cast(be_app)->Terminating() ) + { + return(true); + } + + //main form + frm = dynamic_cast(be_app)->GetMainForm(); + if (frm == this) + { + printf("killing app"); + frm->Lock(); + be_app->PostMessage(B_QUIT_REQUESTED); + frm->Unlock(); + dynamic_cast(be_app)->setTerminating( true ); + } + //sub forms + else + { + //add 'canclose' here + switch (fCloseAction) { + case caNone: + //ignore the action + return(false); + case caHide: + //hide self + this->Lock(); //must lock window before calling hide + this->Hide(); + this->Unlock(); //must remember to unlock + return(false); + case caFree: + //do default.. just remove window + return(true); + default: + return(true); + } + } + } + else + { + be_app->PostMessage(B_QUIT_REQUESTED); + } + return(true); +} + +void MForm::UpdateBounds(void) +{ + fClientArea = this->Bounds(); +} + +void MForm::setWidth(float w) +{ + float h = fClientArea.Height(); + + this->ResizeTo(h, w); + + UpdateBounds(); + +} + +void MForm::setHeight(float h) +{ + float w = fClientArea.Width(); + + this->ResizeTo(h, w); + + UpdateBounds(); +} + +float MForm::getWidth(void) +{ + return fClientArea.Width(); +} + +float MForm::getHeight(void) +{ + return fClientArea.Height(); +} + +float MForm::getLeft(void) +{ + return fClientArea.left; +} + +float MForm::getTop(void) +{ + return fClientArea.top; +} + +float MForm::getBottom(void) +{ + return fClientArea.bottom; +} + +float MForm::getRight(void) +{ + return fClientArea.right; +} + +MCanvas* MForm::Canvas(void) +{ + return fCanvas; +} + +MCloseAction MForm::getCloseAction(void) +{ + return fCloseAction; +} + +void MForm::setCloseAction(MCloseAction ca) +{ + fCloseAction = ca; +} + +//////////////////////////////////////// + +//Canvas class... + +MCanvas::MCanvas(BRect ClientArea, char *name): + BView(ClientArea, name, B_FOLLOW_ALL, 0), + MControlEventPlugin(), + MMenuPropertyPlugin(NULL) +{ + SetViewColor(150, 150, 150); + DoCreate(dynamic_cast(this)); +} + +MCanvas::~MCanvas() +{ + DoDestroy(dynamic_cast(this)); +} + +void MCanvas::AttachedToWindow() +{ +} + +MEdit* MCanvas::AddEdit(BRect ClientArea, char *name) +{ + MEdit* tmp = new MEdit(ClientArea, name); + AddChild(tmp); + return tmp; +} + +MMemo* MCanvas::AddMemo(BRect ClientArea, char *name) +{ + MMemo* tmp = new MMemo(ClientArea, name); + AddChild(tmp); + return tmp; +} + +MPanel* MCanvas::AddPanel(BRect ClientArea, char *name) +{ + MPanel* tmp = new MPanel(ClientArea, name); + AddChild(tmp); + return tmp; +} + +MCheckBox* MCanvas::AddCheckBox(BRect ClientArea, char *name) +{ + MCheckBox* tmp = new MCheckBox(ClientArea, name); + AddChild(tmp); + return tmp; +} + +void MCanvas::KeyDown(const char *bytes, int32 numBytes) +{ + BView::KeyDown(bytes, numBytes); + + if (fOnKeyDown != NULL){ + fOnKeyDown( this, bytes, numBytes ); + } +} + +void MCanvas::KeyUp(const char *bytes, int32 numBytes) +{ + BView::KeyUp(bytes, numBytes); + + if (fOnKeyUp != NULL){ + fOnKeyUp( this, bytes, numBytes ); + } +} + +void MCanvas::MouseDown(BPoint pt) +{ + BPoint point; + + BView::MouseDown(pt); + + if (fOnMouseDown != NULL){ + fOnMouseDown( this, pt.x, pt.y ); + } + + if (fPopUpMenu != NULL){ + point = pt; + ConvertToScreen(&point); + BMenuItem *mni = fPopUpMenu->Go(point, true); + + if (mni){ + MMenuItem *mmni = dynamic_cast(mni); + if(mmni){ + mmni->DoMenuClick(mmni); + } + } + } +} + +void MCanvas::MouseUp(BPoint pt) +{ + BView::MouseUp(pt); + + if (fOnMouseUp != NULL){ + fOnMouseUp( this, pt.x, pt.y ); + } + + DoClick(dynamic_cast(this)); //simulate a 'click' +} + +void MCanvas::MouseMoved(BPoint pt, uint32 code, const BMessage *msg) +{ + BView::MouseMoved(pt, code, msg); + + if (fOnMouseMove != NULL){ + fOnMouseMove( this, pt.x, pt.y, code, 0 ); + } +} + +void MCanvas::Draw(BRect updateArea) +{ + BView::Draw(updateArea); + + if (fOnDraw != NULL){ + fOnDraw( this, updateArea.left, updateArea.top, updateArea.right, updateArea.bottom ); + } + +} + +///////////////////////////////////////// + +//MenuItem Class... + +MMenuItem::MMenuItem(const char *label): + BMenuItem(label, new BMessage(ClickMessage)), + MMenuEventPlugin(){} + +MMenuItem::~MMenuItem(){} + +///////////////////////////////////////// + +//PopUpMenu Class... + +MPopUpMenu::MPopUpMenu(const char *name): + BPopUpMenu(name, false, false) +{ + //MMenuItem *mnu = new MMenuItem("test"); + //AddItem(mnu); +} + +///////////////////////////////////////// + +//Test the Library +CTest::CTest(void){ + FValue = 33; +} + +//GetTest +int CTest::GetValue(void){ + return FValue; +} + +//SetTest +void CTest::SetValue(int NewVal){ + FValue = NewVal; +} + diff --git a/begui/begui/libbegui/BeGuiClasses.h b/begui/begui/libbegui/BeGuiClasses.h new file mode 100644 index 0000000..4a40cfe --- /dev/null +++ b/begui/begui/libbegui/BeGuiClasses.h @@ -0,0 +1,336 @@ +#ifndef BEGUICLASSES_H +#define BEGUICLASSES_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "MList.h" + +//////////////////////////////////////////////////////////////////// + +enum MCloseAction {caNone=0, caHide, caFree}; + +typedef void (*base_Message)(void* sender, uint32 msg); //callback event +typedef void (*genericEvent_Message)(void* sender); +typedef void (*mouseMoved_Message)(void* sender, float x, float y, uint32 code, uint32 msg); +typedef void (*mouseAction_Message)(void* sender, float x, float y); +typedef void (*keyAction_Message)(void* sender, const char *bytes, int32 numBytes); +typedef void (*drawAction_Message)(void* sender, float left, float top, float right, float bottom); +typedef void (*closeAction_Message)(void* sender, MCloseAction &closeAction); +typedef void (*closeQueryAction_Message)(void* sender, bool &canClose); + + +//Classes... + +class CTest { +private: + int FValue; +public: + CTest(void); + int GetValue(void); + void SetValue(int); +}; + +/////////////////////////////////////////////// + +class MGUIListItem : public MListItem { +public: + MGUIListItem(BString name, void *item); + virtual BString getName(void); + virtual void setName(BString name); +private: + BString fName; +}; + +// GUI Item store.... + +class MGUIList : public MList { +public: + MGUIList() : MList(){ /*nothing*/ }; + virtual MGUIListItem* GetItem(int32 index); +}; + +/////////////////////////////////////////////// + +class MPropertyPlugin{ +protected: + BArchivable *FOwner; + uint32 FTag; +public: + MPropertyPlugin(BArchivable *AOwner); + MPropertyPlugin(); + virtual ~MPropertyPlugin(); + virtual void setTag(uint32 ATag); + virtual uint32 getTag(void); + virtual BArchivable* getOwner(void); + virtual void setOwner(BArchivable *AOwner); +}; + +class MPopUpMenu; //forward + +class MMenuPropertyPlugin: public MPropertyPlugin{ +protected: + MPopUpMenu *fPopUpMenu; +public: + MMenuPropertyPlugin(BArchivable *AOwner); + virtual ~MMenuPropertyPlugin(); + virtual void setPopUpMenu(MPopUpMenu *menu); + virtual MPopUpMenu* getPopUpMenu(void); +}; + +/////////////////////////////////////////////// + +class MEventPlugin{ +protected: + genericEvent_Message fOnCreate; + genericEvent_Message fOnDestroy; +public: + MEventPlugin(); + virtual ~MEventPlugin(); + //event stuff: Dispatchers + virtual void AttachCreateDispatcher(genericEvent_Message value); + virtual void AttachDestroyDispatcher(genericEvent_Message value); + //event stuff: Events + virtual void DoCreate(BControl *self); + virtual void DoDestroy(BControl *self); +}; + +class MMenuItem; //forward + +class MMenuEventPlugin{ +protected: + base_Message fOnMenuClick; +public: + MMenuEventPlugin(); + virtual ~MMenuEventPlugin(); + // + virtual void DoMenuClick(MMenuItem *self); + // + virtual void AttachMenuClickDispatcher(base_Message value); + +}; + +class MBasicEventPlugin: public MEventPlugin{ +protected: + base_Message fOnClick; + base_Message fOnChange; +public: + MBasicEventPlugin(); + virtual ~MBasicEventPlugin(); + // + virtual void DoClick(BControl *self); + virtual void DoChange(BControl *self); + // + virtual void AttachClickDispatcher(base_Message value); + virtual void AttachChangeDispatcher(base_Message value); +}; + +class MControlEventPlugin: public MBasicEventPlugin{ +protected: + mouseMoved_Message fOnMouseMove; + mouseAction_Message fOnMouseUp; + mouseAction_Message fOnMouseDown; + keyAction_Message fOnKeyUp; + keyAction_Message fOnKeyDown; + keyAction_Message fOnKeyPress; + drawAction_Message fOnDraw; +public: + MControlEventPlugin(); + virtual ~MControlEventPlugin(); + //event stuff: Dispatchers + virtual void AttachMouseDownDispatcher(mouseAction_Message value); + virtual void AttachMouseUpDispatcher(mouseAction_Message value); + virtual void AttachMouseMovedDispatcher(mouseMoved_Message value); + virtual void AttachKeyDownDispatcher(keyAction_Message value); + virtual void AttachKeyUpDispatcher(keyAction_Message value); + virtual void AttachKeyPressDispatcher(keyAction_Message value); + virtual void AttachDrawDispatcher(drawAction_Message value); + //event stuff: Events + virtual void DoKeyPress(BControl *self, const char *bytes, int32 numBytes); +}; + +class MFormEventPlugin: public MEventPlugin{ +protected: + closeAction_Message fOnClose; +public: + MFormEventPlugin(); + virtual ~MFormEventPlugin(); + virtual void AttachCloseDispatcher(closeAction_Message value); + virtual void DoClose(BView *self, MCloseAction &closeAction); +}; + +/////////////////////////////////////////////// + +class MMemo : public BScrollView, + public MControlEventPlugin, + public MPropertyPlugin{ +private: + BTextView* fTextArea; +public: + MMemo(char *name); + MMemo(BRect frame, char *name); + BTextView* getTextView(void); + virtual void AttachedToWindow(); + //event stuff: Events + virtual void KeyDown(const char *bytes, int32 numBytes); + virtual void KeyUp(const char *bytes, int32 numBytes); + virtual void MouseDown(BPoint pt); + virtual void MouseUp(BPoint pt); + virtual void MouseMoved(BPoint pt, uint32 code, const BMessage *msg); + virtual void Draw(BRect updateArea); +}; + + +class MEdit : public BTextControl, + public MControlEventPlugin, + public MPropertyPlugin{ +public: + MEdit(char *name); + MEdit(BRect frame, char *name); + virtual ~MEdit(); + //event stuff: Events + virtual void KeyDown(const char *bytes, int32 numBytes); + virtual void KeyUp(const char *bytes, int32 numBytes); + virtual void MouseDown(BPoint pt); + virtual void MouseUp(BPoint pt); + virtual void MouseMoved(BPoint pt, uint32 code, const BMessage *msg); + virtual void Draw(BRect updateArea); +}; + +class MButton : public BButton, + public MControlEventPlugin, + public MPropertyPlugin{ +private: + uint32 fMessage; +public: + MButton(char *name); + MButton(BRect frame, char *name); + virtual ~MButton(); + //event stuff: Events + virtual void KeyDown(const char *bytes, int32 numBytes); + virtual void KeyUp(const char *bytes, int32 numBytes); + virtual void MouseDown(BPoint pt); + virtual void MouseUp(BPoint pt); + virtual void MouseMoved(BPoint pt, uint32 code, const BMessage *msg); + virtual void Draw(BRect updateArea); +}; + +class MCheckBox : public BCheckBox, + public MControlEventPlugin, + public MPropertyPlugin{ +public: + MCheckBox(BRect frame, char *name); + virtual ~MCheckBox(); + virtual void KeyDown(const char *bytes, int32 numBytes); + virtual void KeyUp(const char *bytes, int32 numBytes); + virtual void MouseDown(BPoint pt); + virtual void MouseUp(BPoint pt); + virtual void MouseMoved(BPoint pt, uint32 code, const BMessage *msg); + virtual void Draw(BRect updateArea); + virtual bool Checked(void); + +}; + +/////////////////////////////////////////////// + +class MMenuItem: public BMenuItem, + public MMenuEventPlugin{ +public: + MMenuItem(const char *label); + virtual ~MMenuItem(); +}; + +class MPopUpMenu: public BPopUpMenu{ +public: + MPopUpMenu(const char *name); + virtual ~MPopUpMenu(){}; +}; + +/////////////////////////////////////////////// + +class MPanel; //forward +class MComboBox; + +class MCanvas : public BView, + public MControlEventPlugin, + public MMenuPropertyPlugin{ +public: + MCanvas(BRect ClientArea, char *name); + virtual ~MCanvas(); + virtual void AttachedToWindow(); + virtual MEdit* AddEdit(BRect ClientArea, char *name); + virtual MMemo* AddMemo(BRect ClientArea, char *name); + virtual MPanel* AddPanel(BRect ClientArea, char *name); + virtual MCheckBox* AddCheckBox(BRect ClientArea, char *name); + //event stuff: Events + virtual void KeyDown(const char *bytes, int32 numBytes); + virtual void KeyUp(const char *bytes, int32 numBytes); + virtual void MouseDown(BPoint pt); + virtual void MouseUp(BPoint pt); + virtual void MouseMoved(BPoint pt, uint32 code, const BMessage *msg); + virtual void Draw(BRect updateArea); +}; + +class MPanel : public MCanvas{ +public: + MPanel(BRect ClientArea, char *name); + virtual void Draw(BRect updateArea); +}; + +class MForm : public BWindow, + public MFormEventPlugin{ +protected: + BRect fClientArea; + MCanvas *fCanvas; + MCloseAction fCloseAction; +private: + void UpdateBounds(void); +public: + MForm(BRect ClientArea); + virtual ~MForm(); + virtual bool QuitRequested(); + virtual float getWidth(void); + virtual float getHeight(void); + virtual void setWidth(float w); + virtual void setHeight(float h); + virtual float getLeft(void); + virtual float getTop(void); + virtual float getBottom(void); + virtual float getRight(void); + virtual MCanvas* Canvas(void); + virtual void MessageReceived(BMessage *message); + virtual MCloseAction getCloseAction(void); + virtual void setCloseAction(MCloseAction ca); +}; + +class MApplication : public BApplication, + public MEventPlugin{ +protected: + MForm *fMainForm, *fecker; + MGUIList *fForms; + bool fTerminating; +public: + MApplication(); + MApplication(MForm* mainForm); + virtual ~MApplication(); + virtual void Terminate(void); + virtual MForm* AddForm(BRect ClientArea, BString name, bool showForm = false); + virtual MForm* GetMainForm(void){ return fMainForm; }; + virtual bool Terminating(void){ return fTerminating; }; + virtual void setTerminating(bool Value){ fTerminating = Value; }; +}; + +#endif + diff --git a/begui/begui/libbegui/BeTestApp.cpp b/begui/begui/libbegui/BeTestApp.cpp new file mode 100644 index 0000000..91ba6ff --- /dev/null +++ b/begui/begui/libbegui/BeTestApp.cpp @@ -0,0 +1,210 @@ +/* + $Header: /home/haiku/befpc/begui/begui/libbegui/BeTestApp.cpp,v 1.1.1.1 2002-03-31 10:36:21 memson Exp $ + + $Revision: 1.1.1.1 $ + + $Log: not supported by cvs2svn $ + Revision 1.15 2002/03/26 13:28:51 memson + added in combobox support - flawed at the moment. + + Revision 1.14 2002/03/14 22:31:41 memson + Got the Menubar/menu/menuitem and popupmenu/menuitem both working... Had a + bit of a slack night, so didn't really do much else. + + Revision 1.13 2002/03/14 00:12:38 memson + Revised the event and property class hierarchies... hopefully makes more + sense. + + Started to add in the Menu functionality. PopUpMenu is done and 'tested', + but the BMenuBar/BMenu (mainmenu) stuff is there but untested. + + Added in an OnCreate and OnDestroy event to the events, plust a wierd + offshoot class to handle the menuitem click. + + Revision 1.12 2002/03/12 23:12:37 memson + hashed out some details - stopped child windows from screwing up app, and + also added the close action to form and terminating functionality to the app. + + Revision 1.11 2002/03/12 18:39:16 memson + + Revision 1.10 2002/03/11 23:22:11 memson + + Revision 1.9 2002/02/19 17:49:54 memson + Added half arsed support for multiple windows - not working quite right yet, + but at least they seem to 'work' in so much as they don't wipe the app out. + The secondary forms Canvas is screwed up a little.. that is a priority I + guess. + + Revision 1.8 2002/02/14 23:39:53 memson + I've now added most of the events to the MButton, MCanvas, MMemo and MEdit.. + started a MPanel component. Again, the MCanvas is *not* tread safe!!! + This means the calling thread must create it. + + NB. Before I add much more functionality, I'm going to look at other GUI + libs to see if there are any controls worth borrowing. + + Next control will probably be a MLabel followed by a MMenuBar and MMenuItem. + MForm will own a MMenuBar. + + Revision 1.7 2002/02/14 20:33:19 memson + Got the MButton OnClick, OnMouseDown/Up, OnKeyDown/Up and OnMouseMoved + events working. Started to add the required code to the rest of the classes + (should be a cut/paste job). + + Revision 1.6 2002/02/14 14:00:16 memson + fiddled a bit.. nothing major. + + Revision 1.5 2002/02/13 23:26:25 memson + Got the MMemo working. + Got the MEdit working, including OnClick event signal + Got the MButton working with a signal + Added a few get/set accessor routined for captions/text. + + + Revision 1.4 2002/02/13 00:02:02 memson + Got the MTextControl basic functionality - annoying fact is that a text + control has to be added inside the thread that will display it!!!! + + Revision 1.3 2002/02/11 23:26:44 memson + Revision 1.2 2002/01/17 20:32:54 memson + +*/ + +#include "BeGuiAPI.h" +#include + +void *frm2 = 0; //need to add a 'parent' property?? Does BeAPI have equiv? + +/* button callback */ +void callback(void* Sender, uint32 msg){ + if (msg == 'clik') + if (Sender) { + GenericAlert(MButton_getCaption((MButton*)Sender)); + MButton_setCaption((MButton*)Sender, "X"); + } +} + +/* edit callback */ +void callback2(void* Sender, uint32 msg){ + if (msg == 'clik') + if (Sender) { + GenericAlert( MEdit_getText( (MEdit*)Sender ) ); + } +} + +void menuClick(void* Sender, uint32 msg){ + if (msg == 'clik') + GenericAlert( "Menu click" ); +} + +/* test mousemove */ +void mousemoved(void* Sender, float x, float y, uint32 code, uint32 msg){ + printf("mousemoved - x: %f, y: %f, code: %u\n", x, y, code); +} + +/* test mousedown */ +void mousedown(void* Sender, float x, float y){ + printf("mousedown - x: %f, y: %f\n", x, y); +} + +/* test mouseup */ +void mouseup(void* Sender, float x, float y){ + printf("mouseup - x: %f, y: %f\n", x, y); +} + +/* test button click */ +void doclick(void* Sender, uint32 msg){ + if (msg == 'clik') + if (Sender) { + printf("%s clicked\n", MButton_getCaption((MButton*)Sender)); + } + + if (frm2 != NULL){ + MForm_Show((MForm*)frm2); + } + + //dynamic_cast(be_app)->Terminate(); +} + +/* test form click */ +void doformclick(void* Sender, float x, float y){ + printf("mousedown - x: %f, y: %f\n", x, y); +} + + +int main(void){ + /* variables */ + void *app; + void *frm; + void *btn, *btn2; + void *edt, *edt2; + void *pnl; + void *mni, *mni2, *mnu; + void *pm, *mb; + void *cbx; + void *btncbx; + + /* must create application first!! */ + app = MApplication_Create(); + + /* application automatically creates main form + so call this to get a reference to it.. */ + frm = MApplication_GetMainForm((MApplication*)app); + MForm_AttachMouseDownDispatcher((MForm*)frm, doformclick); + + /* create a second hidded form */ + frm2 = MApplication_AddForm((MApplication*)app, 100, 100, 100, 100, "testfrm", "testfrm"); + //MForm_Show((MForm*)frm2); + + /* create 2 buttons */ + btn = MButton_Create(5, 25, 30, 20, "test"); + btn2 = MButton_Create(5, 50, 30, 30, "test2"); + cbx = MForm_AddMCheckBox((MForm*)frm, 20, 20, 100, 50, "test cbx"); + + /* add buttons to main form */ + MForm_AddChild((MForm*)frm, (BControl*)btn); + MForm_AddChild((MForm*)frm, (BControl*)btn2); + //MForm_AddChild((MForm*)frm, (BControl*)cbx); + + pm = MPopUpMenu_Create("testmenu"); + mni = MMenuItem_Create("Test Item"); + MMenuItem_AttachMenuClickDispatcher((MMenuItem*)mni, menuClick); + MPopUpMenu_AddItem((MPopUpMenu*)pm, (MMenuItem*)mni); + MForm_AddPopUpMenu((MForm*)frm, (MPopUpMenu*)pm); + + + mb = BMenuBar_Create((MForm*)frm, "testmenubar"); + mni2 = MMenuItem_Create("Test mb item"); + MMenuItem_AttachMenuClickDispatcher((MMenuItem*)mni2, menuClick); + mnu = BMenu_Create("Form"); + BMenu_AddItem((BMenu*)mnu, (MMenuItem*)mni2); + BMenuBar_AddItem((BMenuBar*)mb, (BMenu*)mnu); + + /* set the button event callback routines */ + MButton_AttachClickDispatcher((MButton*)btn, callback); + MButton_AttachClickDispatcher((MButton*)btn2, doclick); + MButton_AttachMouseMovedDispatcher((MButton*)btn, mousemoved); + MButton_AttachMouseUpDispatcher((MButton*)btn2, mouseup); + MButton_AttachMouseDownDispatcher((MButton*)btn2, mousedown); + + /* add an edit - must be done in thread of main form */ + edt2 = MForm_AddMEdit((MForm*)frm, 30, 50, 100, 50, "test4"); + + /* set the edit event callback routines */ + MEdit_AttachClickDispatcher((MEdit*)edt2, callback2); + + /* create a memo - like edit, must be done in main form's thread */ + edt = MForm_AddMMemo((MForm*)frm, 30, 100, 150, 150, "test5"); + + /* create a panel */ + //pnl = MForm_AddMPanel((MForm*)frm, 250, 200, 400, 400, "panel1"); + + //MForm_Hide((MForm*)frm); + //MForm_Show((MForm*)frm); + + /* start things rolling */ + MApplication_Run((MApplication*)app); + + /* clean up after execution */ + MApplication_Free((MApplication*)app); +} diff --git a/begui/begui/libbegui/BeTestApp.proj b/begui/begui/libbegui/BeTestApp.proj new file mode 100644 index 0000000..a04ef58 Binary files /dev/null and b/begui/begui/libbegui/BeTestApp.proj differ diff --git a/begui/begui/libbegui/MList.cpp b/begui/begui/libbegui/MList.cpp new file mode 100644 index 0000000..a00ae53 --- /dev/null +++ b/begui/begui/libbegui/MList.cpp @@ -0,0 +1,65 @@ +/* + $Header: /home/haiku/befpc/begui/begui/libbegui/MList.cpp,v 1.1.1.1 2002-03-31 10:36:25 memson Exp $ + + $Revision: 1.1.1.1 $ + + $Log: not supported by cvs2svn $ + Revision 1.7 2002/03/12 18:39:17 memson + + Revision 1.8 2002/03/11 23:22:11 memson + + Revision 1.6 2002/02/14 23:39:53 memson + + I've now added most of the events to the MButton, MCanvas, MMemo and MEdit.. + started a MPanel component. Again, the MCanvas is *not* tread safe!!! + This means the calling thread must create it. + + NB. Before I add much more functionality, I'm going to look at other GUI + libs to see if there are any controls worth borrowing. + + Next control will probably be a MLabel followed by a MMenuBar and MMenuItem. + MForm will own a MMenuBar. + + Revision 1.5 2002/02/14 14:00:16 memson + fiddled a bit.. nothing major. + + Revision 1.4 2002/02/13 23:26:25 memson + Got the MMemo working. + Got the MEdit working, including OnClick event signal + Got the MButton working with a signal + Added a few get/set accessor routined for captions/text. + + Revision 1.3 2002/02/11 23:26:44 memson + Revision 1.2 2002/01/17 20:32:54 memson + +*/ + +#include "MList.h" + +bool MList::AddItem(MListItem* item){ + return BList::AddItem((void*)item); +} + +MListItem* MList::GetItem(int32 index){ + return (MListItem*)BList::ItemAt(index); +} + +MListItem::MListItem(void *item){ + fItem = item; +} + +MListItem::~MListItem(){ + fItem = NULL; +} + +void* MListItem::getItem(void){ + return fItem; +} + +void MListItem::setItem(void *item){ + if (fItem) { + fItem = NULL; + } + + fItem = item; +} diff --git a/begui/begui/libbegui/MList.h b/begui/begui/libbegui/MList.h new file mode 100644 index 0000000..4e76398 --- /dev/null +++ b/begui/begui/libbegui/MList.h @@ -0,0 +1,60 @@ +/* + $Header: /home/haiku/befpc/begui/begui/libbegui/MList.h,v 1.1.1.1 2002-03-31 10:36:25 memson Exp $ + + $Revision: 1.1.1.1 $ + + $Log: not supported by cvs2svn $ + Revision 1.8 2002/03/12 18:39:17 memson + + Revision 1.7 2002/03/11 23:22:11 memson + + Revision 1.6 2002/02/14 23:39:53 memson + I've now added most of the events to the MButton, MCanvas, MMemo and MEdit.. + started a MPanel component. Again, the MCanvas is *not* tread safe!!! + This means the calling thread must create it. + + NB. Before I add much more functionality, I'm going to look at other GUI + libs to see if there are any controls worth borrowing. + + Next control will probably be a MLabel followed by a MMenuBar and MMenuItem. + MForm will own a MMenuBar. + + + Revision 1.5 2002/02/14 14:00:17 memson + fiddled a bit.. nothing major. + + Revision 1.4 2002/02/13 23:26:25 memson + Got the MMemo working. + Got the MEdit working, including OnClick event signal + Got the MButton working with a signal + Added a few get/set accessor routined for captions/text. + + Revision 1.3 2002/02/11 23:26:44 memson + Revision 1.2 2002/01/17 20:32:54 memson + +*/ + +#ifndef MLIST_H +#define MLIST_H + +#include + +class MListItem { +public: + MListItem(void *item); + virtual ~MListItem(); + virtual void* getItem(void); + virtual void setItem(void *item); +private: + void *fItem; +}; + +class MList: public BList { +public: + MList(): BList(20){/*nothing*/}; + virtual bool AddItem(MListItem* item); + virtual MListItem* GetItem(int32 index); +}; + +#endif MLIST_H + diff --git a/begui/begui/libbegui/libbegui.proj b/begui/begui/libbegui/libbegui.proj new file mode 100644 index 0000000..e9bd125 Binary files /dev/null and b/begui/begui/libbegui/libbegui.proj differ