Added quite a bit.
Got basic file handling soeted out. Also got the FilePanel's working (see example project) Popup menu now only responds to a right click (at last!!)
This commit is contained in:
BIN
begui/begui/libbegui/BeGUITestApp2.proj
Normal file
BIN
begui/begui/libbegui/BeGUITestApp2.proj
Normal file
Binary file not shown.
@@ -1,9 +1,13 @@
|
|||||||
/*
|
/*
|
||||||
$Header: /home/haiku/befpc/begui/begui/libbegui/BeGuiAPI.cpp,v 1.2 2002-04-02 20:42:15 memson Exp $
|
$Header: /home/haiku/befpc/begui/begui/libbegui/BeGuiAPI.cpp,v 1.3 2002-04-12 23:32:56 memson Exp $
|
||||||
|
|
||||||
$Revision: 1.2 $
|
$Revision: 1.3 $
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.2 2002/04/02 20:42:15 memson
|
||||||
|
|
||||||
|
updated for Eric
|
||||||
|
|
||||||
Revision 1.1.1.1 2002/03/31 10:36:07 memson
|
Revision 1.1.1.1 2002/03/31 10:36:07 memson
|
||||||
|
|
||||||
initial import into sourceforge
|
initial import into sourceforge
|
||||||
@@ -183,6 +187,28 @@ MMemo* MForm_AddMMemo(MForm *form, int32 left, int32 top, int32 right, int32 bot
|
|||||||
return form->Canvas()->AddMemo(btnRect, caption);
|
return form->Canvas()->AddMemo(btnRect, caption);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32 MForm_getWidth(MForm *frm){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32 MForm_getHeight(MForm *frm){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MForm_setWidth(MForm *frm, int32 value){
|
||||||
|
if (frm->Lock()) {
|
||||||
|
frm->setWidth(value);
|
||||||
|
frm->Unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MForm_setHeight(MForm *frm, int32 value){
|
||||||
|
if (frm->Lock()) {
|
||||||
|
frm->setHeight(value);
|
||||||
|
frm->Unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
|
||||||
BButton* BButton_Create(float left, float top, float right, float bottom, char *caption, uint32 msg){
|
BButton* BButton_Create(float left, float top, float right, float bottom, char *caption, uint32 msg){
|
||||||
@@ -499,6 +525,20 @@ void GenericAlert(const char *message){
|
|||||||
alert->Go();
|
alert->Go();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include <Beep.h>
|
||||||
|
|
||||||
|
status_t be_beep(){
|
||||||
|
return beep();
|
||||||
|
}
|
||||||
|
|
||||||
|
status_t be_system_beep(const char * event_name){
|
||||||
|
return system_beep(event_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
status_t be_add_system_beep_event(const char * event_name, uint32 flags){
|
||||||
|
return add_system_beep_event(event_name, flags);
|
||||||
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
|
|
||||||
//Test the API
|
//Test the API
|
||||||
|
|||||||
@@ -60,6 +60,10 @@ void MForm_AttachDrawDispatcher(MForm *form, drawAction_Message msg);
|
|||||||
void MForm_Show(MForm *frm);
|
void MForm_Show(MForm *frm);
|
||||||
void MForm_Hide(MForm *frm);
|
void MForm_Hide(MForm *frm);
|
||||||
void MForm_AddPopUpMenu(MForm *frm, MPopUpMenu *mni);
|
void MForm_AddPopUpMenu(MForm *frm, MPopUpMenu *mni);
|
||||||
|
int32 MForm_getWidth(MForm *frm);
|
||||||
|
int32 MForm_getHeight(MForm *frm);
|
||||||
|
void MForm_setWidth(MForm *frm, int32 value);
|
||||||
|
void MForm_setHeight(MForm *frm, int32 value);
|
||||||
|
|
||||||
//button
|
//button
|
||||||
MButton* MButton_Create(float left, float top, float right, float bottom, char *caption);
|
MButton* MButton_Create(float left, float top, float right, float bottom, char *caption);
|
||||||
@@ -136,6 +140,10 @@ uint32 GetBaseMessage(void);
|
|||||||
uint32 GetNextMessage(void);
|
uint32 GetNextMessage(void);
|
||||||
void GenericAlert(const char *message);
|
void GenericAlert(const char *message);
|
||||||
|
|
||||||
|
status_t be_beep();
|
||||||
|
status_t be_system_beep(const char * event_name);
|
||||||
|
status_t be_add_system_beep_event(const char * event_name, uint32 flags);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
/*
|
/*
|
||||||
$Header: /home/haiku/befpc/begui/begui/libbegui/BeGuiClasses.cpp,v 1.1.1.1 2002-03-31 10:36:16 memson Exp $
|
$Header: /home/haiku/befpc/begui/begui/libbegui/BeGuiClasses.cpp,v 1.2 2002-04-12 23:32:56 memson Exp $
|
||||||
|
|
||||||
$Revision: 1.1.1.1 $
|
$Revision: 1.2 $
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.1.1.1 2002/03/31 10:36:16 memson
|
||||||
|
|
||||||
|
initial import into sourceforge
|
||||||
|
|
||||||
Revision 1.19 2002/03/26 13:28:51 memson
|
Revision 1.19 2002/03/26 13:28:51 memson
|
||||||
|
|
||||||
added in combobox su[pport - flawed at the moment.
|
added in combobox support - flawed at the moment.
|
||||||
|
|
||||||
Revision 1.18 2002/03/14 22:31:41 memson
|
Revision 1.18 2002/03/14 22:31:41 memson
|
||||||
|
|
||||||
@@ -99,8 +103,10 @@
|
|||||||
#define BEGUI_EXPORTS 1
|
#define BEGUI_EXPORTS 1
|
||||||
|
|
||||||
#include "MList.h"
|
#include "MList.h"
|
||||||
|
#include "MFile.h"
|
||||||
#include "BeGuiClasses.h"
|
#include "BeGuiClasses.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <storage/Path.h>
|
||||||
|
|
||||||
//clik - control click
|
//clik - control click
|
||||||
#define ClickMessage 'clik'
|
#define ClickMessage 'clik'
|
||||||
@@ -788,8 +794,8 @@ void MButton::Draw(BRect updateArea)
|
|||||||
|
|
||||||
//Application Class...
|
//Application Class...
|
||||||
|
|
||||||
MApplication::MApplication():
|
MApplication::MApplication(const char* signature):
|
||||||
BApplication("application/x-vnd.beguiapp"),
|
BApplication(signature),
|
||||||
MEventPlugin()
|
MEventPlugin()
|
||||||
{
|
{
|
||||||
BRect tmpRect;
|
BRect tmpRect;
|
||||||
@@ -797,24 +803,7 @@ MApplication::MApplication():
|
|||||||
BString formname = "main";
|
BString formname = "main";
|
||||||
|
|
||||||
fMainForm = new MForm(tmpRect);
|
fMainForm = new MForm(tmpRect);
|
||||||
fMainForm->Show();
|
//fMainForm->Show();
|
||||||
|
|
||||||
fForms = new MGUIList();
|
|
||||||
fForms->AddItem(new MGUIListItem(formname, fMainForm));
|
|
||||||
|
|
||||||
fTerminating = false; //controls the act of shutting down
|
|
||||||
|
|
||||||
DoCreate( dynamic_cast<BControl*>(this) );
|
|
||||||
}
|
|
||||||
|
|
||||||
MApplication::MApplication(MForm* mainForm):
|
|
||||||
BApplication("application/x-vnd.beguiapp"),
|
|
||||||
MEventPlugin()
|
|
||||||
{
|
|
||||||
BString formname = "main";
|
|
||||||
|
|
||||||
fMainForm = mainForm;
|
|
||||||
fMainForm->Show();
|
|
||||||
|
|
||||||
fForms = new MGUIList();
|
fForms = new MGUIList();
|
||||||
fForms->AddItem(new MGUIListItem(formname, fMainForm));
|
fForms->AddItem(new MGUIListItem(formname, fMainForm));
|
||||||
@@ -829,6 +818,63 @@ MApplication::~MApplication()
|
|||||||
DoDestroy( dynamic_cast<BControl*>(this) );
|
DoDestroy( dynamic_cast<BControl*>(this) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
thread_id MApplication::Run(void)
|
||||||
|
{
|
||||||
|
if (fMainForm != NULL) fMainForm->Show();
|
||||||
|
|
||||||
|
return BApplication::Run();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void MApplication::RefsReceived(BMessage *message)
|
||||||
|
{
|
||||||
|
if (message->what == SAVE_PANEL_MESSAGE){
|
||||||
|
printf("\nSave\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MApplication::MessageReceived(BMessage *message)
|
||||||
|
{
|
||||||
|
void *pointer;
|
||||||
|
MFilePanel *filepanel;
|
||||||
|
entry_ref ref;
|
||||||
|
const char *name;
|
||||||
|
BPath path;
|
||||||
|
BEntry entry;
|
||||||
|
status_t err = B_OK;
|
||||||
|
|
||||||
|
if (message->what == SAVE_PANEL_MESSAGE || message->what == OPEN_PANEL_MESSAGE){
|
||||||
|
printf("\nSave\n");
|
||||||
|
if ( (err = message->FindRef("directory", &ref)) != B_OK ) {
|
||||||
|
printf("failed to find dir, error %d\n", err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ( (err = message->FindString("name", &name)) != B_OK ){
|
||||||
|
printf("failed to find filename, error %d\n", err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( (err = entry.SetTo(&ref)) != B_OK ){
|
||||||
|
printf("failed to create entr from path, error %d\n", err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
entry.GetPath(&path);
|
||||||
|
path.Append(name);
|
||||||
|
|
||||||
|
printf( "%s\n", path.Path() );
|
||||||
|
|
||||||
|
if (message->FindPointer("source", &pointer) == B_OK){
|
||||||
|
printf("works1\n");
|
||||||
|
if ((filepanel = reinterpret_cast<MFilePanel*>(pointer)) != NULL){
|
||||||
|
printf("works2\n");
|
||||||
|
filepanel->DoExecute( path );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void MApplication::Terminate(void)
|
void MApplication::Terminate(void)
|
||||||
{
|
{
|
||||||
//if main form is dead, we must not call this because...
|
//if main form is dead, we must not call this because...
|
||||||
@@ -963,16 +1009,18 @@ bool MForm::QuitRequested()
|
|||||||
|
|
||||||
void MForm::UpdateBounds(void)
|
void MForm::UpdateBounds(void)
|
||||||
{
|
{
|
||||||
fClientArea = this->Bounds();
|
//fClientArea = this->Bounds();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MForm::setWidth(float w)
|
void MForm::setWidth(float w)
|
||||||
{
|
{
|
||||||
float h = fClientArea.Height();
|
float h = fClientArea.Height();
|
||||||
|
|
||||||
this->ResizeTo(h, w);
|
fClientArea.Set(fClientArea.left, fClientArea.top, fClientArea.left + w, fClientArea.top + h);
|
||||||
|
|
||||||
UpdateBounds();
|
this->ResizeTo(w, h);
|
||||||
|
|
||||||
|
//UpdateBounds();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -980,9 +1028,11 @@ void MForm::setHeight(float h)
|
|||||||
{
|
{
|
||||||
float w = fClientArea.Width();
|
float w = fClientArea.Width();
|
||||||
|
|
||||||
this->ResizeTo(h, w);
|
fClientArea.Set(fClientArea.left, fClientArea.top, fClientArea.left + w, fClientArea.top + h);
|
||||||
|
|
||||||
UpdateBounds();
|
this->ResizeTo(w, h);
|
||||||
|
|
||||||
|
//UpdateBounds();
|
||||||
}
|
}
|
||||||
|
|
||||||
float MForm::getWidth(void)
|
float MForm::getWidth(void)
|
||||||
@@ -1101,6 +1151,7 @@ void MCanvas::KeyUp(const char *bytes, int32 numBytes)
|
|||||||
void MCanvas::MouseDown(BPoint pt)
|
void MCanvas::MouseDown(BPoint pt)
|
||||||
{
|
{
|
||||||
BPoint point;
|
BPoint point;
|
||||||
|
int32 buttons = 0;
|
||||||
|
|
||||||
BView::MouseDown(pt);
|
BView::MouseDown(pt);
|
||||||
|
|
||||||
@@ -1108,6 +1159,10 @@ void MCanvas::MouseDown(BPoint pt)
|
|||||||
fOnMouseDown( this, pt.x, pt.y );
|
fOnMouseDown( this, pt.x, pt.y );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Looper()->CurrentMessage()->FindInt32("buttons", &buttons);
|
||||||
|
|
||||||
|
|
||||||
|
if (buttons == B_SECONDARY_MOUSE_BUTTON) {
|
||||||
if (fPopUpMenu != NULL){
|
if (fPopUpMenu != NULL){
|
||||||
point = pt;
|
point = pt;
|
||||||
ConvertToScreen(&point);
|
ConvertToScreen(&point);
|
||||||
@@ -1120,6 +1175,7 @@ void MCanvas::MouseDown(BPoint pt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MCanvas::MouseUp(BPoint pt)
|
void MCanvas::MouseUp(BPoint pt)
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#include <PopUpMenu.h>
|
#include <PopUpMenu.h>
|
||||||
#include <Menu.h>
|
#include <Menu.h>
|
||||||
#include <CheckBox.h>
|
#include <CheckBox.h>
|
||||||
|
#include <kernel/OS.h>
|
||||||
#include "MList.h"
|
#include "MList.h"
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@@ -322,10 +323,12 @@ protected:
|
|||||||
MGUIList *fForms;
|
MGUIList *fForms;
|
||||||
bool fTerminating;
|
bool fTerminating;
|
||||||
public:
|
public:
|
||||||
MApplication();
|
MApplication(const char* signature = "application/x-vnd.beguiapp");
|
||||||
MApplication(MForm* mainForm);
|
|
||||||
virtual ~MApplication();
|
virtual ~MApplication();
|
||||||
|
virtual thread_id Run(void);
|
||||||
virtual void Terminate(void);
|
virtual void Terminate(void);
|
||||||
|
virtual void RefsReceived(BMessage *message);
|
||||||
|
virtual void MessageReceived(BMessage *message);
|
||||||
virtual MForm* AddForm(BRect ClientArea, BString name, bool showForm = false);
|
virtual MForm* AddForm(BRect ClientArea, BString name, bool showForm = false);
|
||||||
virtual MForm* GetMainForm(void){ return fMainForm; };
|
virtual MForm* GetMainForm(void){ return fMainForm; };
|
||||||
virtual bool Terminating(void){ return fTerminating; };
|
virtual bool Terminating(void){ return fTerminating; };
|
||||||
|
|||||||
Binary file not shown.
217
begui/begui/libbegui/BeTestApp2.cpp
Normal file
217
begui/begui/libbegui/BeTestApp2.cpp
Normal file
@@ -0,0 +1,217 @@
|
|||||||
|
/*
|
||||||
|
$Header: /home/haiku/befpc/begui/begui/libbegui/BeTestApp2.cpp,v 1.1 2002-04-12 23:32:56 memson Exp $
|
||||||
|
|
||||||
|
$Revision: 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 "MFile.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
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<MApplication*>(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;
|
||||||
|
void *file;
|
||||||
|
|
||||||
|
/* 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);
|
||||||
|
|
||||||
|
MForm_setWidth((MForm*)frm, 250);
|
||||||
|
MForm_setHeight((MForm*)frm, 250);
|
||||||
|
|
||||||
|
/* 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);
|
||||||
|
|
||||||
|
printf("%d", test_func());
|
||||||
|
}
|
||||||
225
begui/begui/libbegui/MFile.cpp
Normal file
225
begui/begui/libbegui/MFile.cpp
Normal file
@@ -0,0 +1,225 @@
|
|||||||
|
#include "MFile.h"
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////
|
||||||
|
// Class MFile
|
||||||
|
|
||||||
|
MFile::MFile(const char *path, uint32 openMode):
|
||||||
|
BFile(path, openMode)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
MFile::MFile(const entry_ref *ref, uint32 openMode):
|
||||||
|
BFile(ref, openMode)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////
|
||||||
|
// Exported Functions
|
||||||
|
|
||||||
|
MFile* MFile_Create(const char *path, uint32 openMode){
|
||||||
|
return new MFile(path, openMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
MFile* MFile_Create_Ref(const entry_ref *ref, uint32 openMode){
|
||||||
|
return new MFile(ref, openMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MFile_Free(MFile* file){
|
||||||
|
delete file;
|
||||||
|
}
|
||||||
|
|
||||||
|
off_t MFile_Seek(MFile* file, off_t offset, int32 seekMode){
|
||||||
|
return file->Seek(offset, seekMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
off_t MFile_Position(MFile* file){
|
||||||
|
return file->Position();
|
||||||
|
}
|
||||||
|
|
||||||
|
ssize_t MFile_Read(MFile* file, void *buffer, size_t size){
|
||||||
|
return file->Read(buffer, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
ssize_t MFile_ReadAt(MFile* file, off_t pos, void *buffer, size_t size){
|
||||||
|
return file->ReadAt(pos, buffer, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
ssize_t MFile_Write(MFile* file, const void *buffer, size_t size){
|
||||||
|
return file->Write(buffer, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
ssize_t MFile_WriteAt(MFile* file, off_t pos, const void *buffer, size_t size){
|
||||||
|
return file->WriteAt(pos, buffer, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
status_t MFile_SetSize(MFile* file, off_t size){
|
||||||
|
return file->SetSize(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
status_t MFile_SetTo(MFile* file, const char *path, uint32 open_mode){
|
||||||
|
return file->SetTo(path, open_mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////
|
||||||
|
// Generic File Panel
|
||||||
|
|
||||||
|
MFilePanel::MFilePanel(file_panel_mode panel_type,
|
||||||
|
bool allow_multiple_selection,
|
||||||
|
BMessage *msg = 0,
|
||||||
|
bool modal) :
|
||||||
|
BFilePanel(panel_type,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
allow_multiple_selection,
|
||||||
|
msg,
|
||||||
|
0,
|
||||||
|
modal,
|
||||||
|
true),
|
||||||
|
MDialogPlugin(panel_type)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
|
||||||
|
void MFilePanel_AttachDialogEvent(MFilePanel* dlg, dialog_Message msg)
|
||||||
|
{
|
||||||
|
dlg->AttachDialogEvent(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////
|
||||||
|
// Open Panel
|
||||||
|
|
||||||
|
MOpenPanel::MOpenPanel(bool allow_multiple_selection,
|
||||||
|
bool modal) :
|
||||||
|
MFilePanel(B_OPEN_PANEL,
|
||||||
|
allow_multiple_selection,
|
||||||
|
0,
|
||||||
|
modal)
|
||||||
|
{
|
||||||
|
BMessage *msg = new BMessage(OPEN_PANEL_MESSAGE);
|
||||||
|
|
||||||
|
msg->AddPointer("source", this);
|
||||||
|
|
||||||
|
SetMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
// flattened API
|
||||||
|
|
||||||
|
MOpenPanel* MOpenPanel_Create()
|
||||||
|
{
|
||||||
|
return new MOpenPanel();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MOpenPanel_Free(MOpenPanel* dlg)
|
||||||
|
{
|
||||||
|
delete &dlg;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MOpenPanel_Show(MOpenPanel* dlg)
|
||||||
|
{
|
||||||
|
dlg->Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MOpenPanel_Hide(MOpenPanel* dlg)
|
||||||
|
{
|
||||||
|
dlg->Hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MOpenPanel_IsShowing(MOpenPanel* dlg)
|
||||||
|
{
|
||||||
|
return dlg->IsShowing();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////
|
||||||
|
// Save Panel
|
||||||
|
|
||||||
|
MSavePanel::MSavePanel(bool allow_multiple_selection,
|
||||||
|
bool modal) :
|
||||||
|
MFilePanel(B_SAVE_PANEL,
|
||||||
|
allow_multiple_selection,
|
||||||
|
0,
|
||||||
|
modal)
|
||||||
|
{
|
||||||
|
BMessage *msg = new BMessage(SAVE_PANEL_MESSAGE);
|
||||||
|
|
||||||
|
msg->AddPointer("source", this);
|
||||||
|
|
||||||
|
SetMessage(msg);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//flattened API
|
||||||
|
|
||||||
|
MSavePanel* MSavePanel_Create()
|
||||||
|
{
|
||||||
|
return new MSavePanel();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MSavePanel_Free(MSavePanel* dlg)
|
||||||
|
{
|
||||||
|
delete &dlg;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MSavePanel_Show(MSavePanel* dlg)
|
||||||
|
{
|
||||||
|
dlg->Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MSavePanel_Hide(MSavePanel* dlg)
|
||||||
|
{
|
||||||
|
dlg->Hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MSavePanel_IsShowing(MSavePanel* dlg)
|
||||||
|
{
|
||||||
|
return dlg->IsShowing();
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////
|
||||||
|
// Property
|
||||||
|
|
||||||
|
MDialogPlugin::MDialogPlugin(const uint32 dialogType)
|
||||||
|
{
|
||||||
|
fDialogType = dialogType;
|
||||||
|
fDialogMsg = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
MDialogPlugin::~MDialogPlugin()
|
||||||
|
{
|
||||||
|
fDialogMsg = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MDialogPlugin::AttachDialogEvent(dialog_Message msg)
|
||||||
|
{
|
||||||
|
fDialogMsg = msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MDialogPlugin::DoExecute(BPath path)
|
||||||
|
{
|
||||||
|
uint32 amsg;
|
||||||
|
|
||||||
|
switch (fDialogType){
|
||||||
|
case B_SAVE_PANEL:
|
||||||
|
amsg = SAVE_PANEL_MESSAGE; //Matt 11/04/2002 : this is a bug...
|
||||||
|
break;
|
||||||
|
case B_OPEN_PANEL:
|
||||||
|
amsg = OPEN_PANEL_MESSAGE; //Matt 11/04/2002 : this is a bug...
|
||||||
|
break;
|
||||||
|
default: amsg = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fDialogMsg != NULL){
|
||||||
|
fDialogMsg( this, amsg, path.Path() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////
|
||||||
|
// Utility test function
|
||||||
|
uint test_func(void){
|
||||||
|
return 1024;
|
||||||
|
}
|
||||||
105
begui/begui/libbegui/MFile.h
Normal file
105
begui/begui/libbegui/MFile.h
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
/*
|
||||||
|
$Header: /home/haiku/befpc/begui/begui/libbegui/MFile.h,v 1.1 2002-04-12 23:32:56 memson Exp $
|
||||||
|
|
||||||
|
$Revision: 1.1 $
|
||||||
|
|
||||||
|
$Log: not supported by cvs2svn $
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MFILE_H
|
||||||
|
#define MFILE_H
|
||||||
|
|
||||||
|
#include <storage/Path.h>
|
||||||
|
#include <File.h>
|
||||||
|
#include <FilePanel.h>
|
||||||
|
#include <SupportDefs.h>
|
||||||
|
#include <Control.h>
|
||||||
|
|
||||||
|
typedef void (*dialog_Message)(void* sender, uint32 msg, const char *path);//, entry_ref ref);
|
||||||
|
|
||||||
|
extern "C"{
|
||||||
|
|
||||||
|
#define SAVE_PANEL_MESSAGE 'svpm'
|
||||||
|
#define OPEN_PANEL_MESSAGE 'oppm'
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class MFile : public BFile{
|
||||||
|
public:
|
||||||
|
MFile(const char *path, uint32 openMode);
|
||||||
|
MFile(const entry_ref *ref, uint32 openMode);
|
||||||
|
//add whatever
|
||||||
|
};
|
||||||
|
|
||||||
|
class MFilePanel; //forward...
|
||||||
|
|
||||||
|
class MDialogPlugin {
|
||||||
|
private:
|
||||||
|
dialog_Message fDialogMsg;
|
||||||
|
uint32 fDialogType;
|
||||||
|
public:
|
||||||
|
MDialogPlugin(const uint32 dialogType);
|
||||||
|
virtual ~MDialogPlugin();
|
||||||
|
virtual void AttachDialogEvent(dialog_Message msg);
|
||||||
|
virtual void DoExecute(BPath path);
|
||||||
|
};
|
||||||
|
|
||||||
|
class MFilePanel : public BFilePanel,
|
||||||
|
public MDialogPlugin{
|
||||||
|
public:
|
||||||
|
MFilePanel(file_panel_mode panel_type,
|
||||||
|
bool allow_multiple_selection = true,
|
||||||
|
BMessage *msg = 0,
|
||||||
|
bool modal = true);
|
||||||
|
};
|
||||||
|
|
||||||
|
class MOpenPanel : public MFilePanel{
|
||||||
|
public:
|
||||||
|
MOpenPanel(bool allow_multiple_selection = true,
|
||||||
|
bool modal = true);
|
||||||
|
};
|
||||||
|
|
||||||
|
class MSavePanel : public MFilePanel{
|
||||||
|
public:
|
||||||
|
MSavePanel(bool allow_multiple_selection = true,
|
||||||
|
bool modal = true);
|
||||||
|
};
|
||||||
|
|
||||||
|
extern "C"{
|
||||||
|
|
||||||
|
MFile* MFile_Create(const char *path, uint32 openMode);
|
||||||
|
MFile* MFile_Create_Ref(const entry_ref *ref, uint32 openMode);
|
||||||
|
void MFile_Free(MFile* file);
|
||||||
|
|
||||||
|
off_t MFile_Seek(MFile* file, off_t offset, int32 seekMode);
|
||||||
|
off_t MFile_Position(MFile* file);
|
||||||
|
|
||||||
|
ssize_t MFile_Read(MFile* file, void *buffer, size_t size);
|
||||||
|
ssize_t MFile_ReadAt(MFile* file, off_t pos, void *buffer, size_t size);
|
||||||
|
ssize_t MFile_Write(MFile* file, const void *buffer, size_t size);
|
||||||
|
ssize_t MFile_WriteAt(MFile* file, off_t pos, const void *buffer, size_t size);
|
||||||
|
|
||||||
|
status_t MFile_SetSize(MFile* file, off_t size);
|
||||||
|
status_t MFile_SetTo(MFile* file, const char *path, uint32 open_mode);
|
||||||
|
|
||||||
|
//use this for both Save and Open Panels...
|
||||||
|
void MFilePanel_AttachDialogEvent(MFilePanel* dlg, dialog_Message msg);
|
||||||
|
|
||||||
|
MOpenPanel* MOpenPanel_Create();
|
||||||
|
void MOpenPanel_Free(MOpenPanel* dlg);
|
||||||
|
void MOpenPanel_Show(MOpenPanel* dlg);
|
||||||
|
void MOpenPanel_Hide(MOpenPanel* dlg);
|
||||||
|
bool MOpenPanel_IsShowing(MOpenPanel* dlg);
|
||||||
|
|
||||||
|
MSavePanel* MSavePanel_Create();
|
||||||
|
void MSavePanel_Free(MSavePanel* dlg);
|
||||||
|
void MSavePanel_Show(MSavePanel* dlg);
|
||||||
|
void MSavePanel_Hide(MSavePanel* dlg);
|
||||||
|
bool MSavePanel_IsShowing(MSavePanel* dlg);
|
||||||
|
|
||||||
|
uint test_func(void);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif MFILE_H
|
||||||
BIN
begui/begui/libbegui/filetest.proj
Normal file
BIN
begui/begui/libbegui/filetest.proj
Normal file
Binary file not shown.
Binary file not shown.
37
begui/begui/libbegui/testfile.cpp
Normal file
37
begui/begui/libbegui/testfile.cpp
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#include "MFile.h"
|
||||||
|
#include "BeGuiAPI.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void file_io(void* sender, uint32 msg, const char *path){
|
||||||
|
char *buffer; //for output
|
||||||
|
void *file; //for MFile reference
|
||||||
|
|
||||||
|
buffer = (char*) malloc(27); //create some space in the buffer
|
||||||
|
buffer = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; //add domething to put in file
|
||||||
|
|
||||||
|
//file output...
|
||||||
|
file = MFile_Create(path, B_READ_WRITE | B_CREATE_FILE); //file read/write and create if not already there
|
||||||
|
MFile_Write( (MFile*)file, buffer, strlen(buffer) ); //output buffer contents
|
||||||
|
MFile_Free((MFile*)file); //clear the file pointer
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
void *savepanel; // MSavePanel reference
|
||||||
|
void *app; // MApplication reference
|
||||||
|
|
||||||
|
// Matt 11/04/2002 : Must have a MApplication to use a MFilePanel of descendents
|
||||||
|
app = MApplication_Create(); //create an MApplication reference
|
||||||
|
|
||||||
|
savepanel = MSavePanel_Create(); //create a MSavePanel reference
|
||||||
|
MFilePanel_AttachDialogEvent((MFilePanel*)savepanel, file_io); //attach callback for event
|
||||||
|
|
||||||
|
MSavePanel_Show((MSavePanel*) savepanel); //show the panel (this is modal)
|
||||||
|
|
||||||
|
MApplication_Run((MApplication*)app); //run the application
|
||||||
|
|
||||||
|
MApplication_Free((MApplication*)app); //clean up the app
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user