⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xaosdialog.cpp

📁 另一个分形程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include <Button.h>#include <Locker.h>#include <NodeInfo.h>#include <Path.h>#include <Entry.h>#include <Application.h>#include <string.h>#include <malloc.h>#include <Message.h>#include <StringView.h>#include <TextControl.h>#include <Menu.h>#include <MenuItem.h>#include <MenuField.h>#include <PopUpMenu.h>#include <FilePanel.h>#include "XaoSDialog.h"#define SEPARATOR 5#define BORDER 5struct uih_context;extern void be_help(struct uih_context *c, const char *name);/* The dialog is created from XaoSElements holding the values and labels*/class XaoSElement {public:	XaoSElement(const menudialog *dialog);	XaoSElement(void);	virtual ~XaoSElement(void);	virtual void GetValue(dialogparam *param) = 0;	virtual void GetMinimalSize(int *textwidth, int *width, int *height) = 0;	virtual void SetIt(int xstart, int textwidth, int width, int top, int height, BView *view) = 0;protected:	const menudialog *dialog;};XaoSElement::XaoSElement(const menudialog *d):	dialog(d){}XaoSElement::~XaoSElement(){}/* String elements implements input using BTextControl */class XaoSAStringElement: public XaoSElement{public:   typedef XaoSElement inherited;    XaoSAStringElement(const menudialog *dialog);   ~XaoSAStringElement();   virtual void GetMinimalSize(int *textwidth, int *width, int *height);   virtual void SetIt(int xstart, int textwidth, int width, int top, int height, BView *view);   void SetDefault(const char *string);protected:   BTextControl *text;private:   char *string;};XaoSAStringElement::XaoSAStringElement(const menudialog *d):	inherited(d){   BRect r(0,0,10,10);   text = new BTextControl(r, d->question, d->question, "" , new BMessage('XaTc'));   string=NULL;}voidXaoSAStringElement::SetDefault(const char *s){   if (string) delete string;   text->SetText(s);   string=strdup(s);}XaoSAStringElement::~XaoSAStringElement(){  if(string) free(string);}voidXaoSAStringElement::GetMinimalSize(int *textwidth, int *width, int *height){     text->ResizeToPreferred();     *textwidth=(int)text->Divider()+10;     BRect r=text->Bounds();     *height=(int)r.bottom+1;     *width=(int)r.right-*textwidth+11;}voidXaoSAStringElement::SetIt(int xstart, int textwidth, int width, int top, int height, BView *view){     BRect r(xstart,top,xstart+width+textwidth,top+height);     /* We need to re-create the widget, because it for some purpose refuses to get proper sizes for textview */     delete text;     text = new BTextControl(r, dialog->question, dialog->question, "" , new BMessage('XaTc'));     if (string!=NULL) text->SetText(string);     text->SetDivider(textwidth);     view->AddChild(text);}/* Choice elements implements input using BMenuField */class XaoSChoiceElement: public XaoSElement{public:   typedef XaoSElement inherited;    XaoSChoiceElement(const menudialog *dialog);   ~XaoSChoiceElement();   virtual void GetMinimalSize(int *textwidth, int *width, int *height);   virtual void SetIt(int xstart, int textwidth, int width, int top, int height, BView *view);   virtual void GetValue(dialogparam *param);protected:   BMenuField *field;   BMenu *menu;};XaoSChoiceElement::XaoSChoiceElement(const menudialog *d):	inherited(d){   const char * const *choices=(const char * const *)d->defstr;   int i;   BRect r(0,0,10,18);   menu = new BPopUpMenu(d->question);   menu->SetRadioMode(TRUE);   for(i=0;choices[i];i++)   {     BMenuItem *item = new BMenuItem (choices[i], new BMessage('XaMn'));     menu->AddItem (item);     if (i==d->defint) item->SetMarked(TRUE);   }   field = new BMenuField(r, d->question, d->question, menu);}voidXaoSChoiceElement::GetValue(dialogparam *param){   int i;   for(i=0;!menu->ItemAt(i)->IsMarked();i++);   param->dint=i;}XaoSChoiceElement::~XaoSChoiceElement(){}voidXaoSChoiceElement::GetMinimalSize(int *textwidth, int *width, int *height){     BFont font;     field->GetFont(&font);     *textwidth=(int)font.StringWidth(dialog->question)+10;     *width=100;     *height=(int)font.Size()+8;}voidXaoSChoiceElement::SetIt(int xstart, int textwidth, int width, int top, int height, BView *view){     field->MoveTo(xstart,top);     field->ResizeTo(width+textwidth, height);     field->SetDivider(textwidth);     view->AddChild(field);}/* String elements implements input using BTextControl */class XaoSComplexElement: public XaoSAStringElement{public:   typedef XaoSAStringElement inherited;    XaoSComplexElement(const menudialog *dialog);   ~XaoSComplexElement();   virtual void GetMinimalSize(int *textwidth, int *width, int *height);   virtual void SetIt(int xstart, int textwidth, int width, int top, int height, BView *view);   virtual void GetValue(dialogparam *param);protected:   BTextControl *text2;   BStringView *i;};XaoSComplexElement::XaoSComplexElement(const menudialog *d):	inherited(d){   char s[256];   sprintf(s,"%g",(double)dialog->deffloat);   SetDefault(s);   sprintf(s,"%g",(double)dialog->deffloat2);   BRect r(0,0,10,10);   text2 = new BTextControl(r, "+", "+", s , new BMessage('XaTc'));   i = new BStringView(r, "i", "i");}XaoSComplexElement::~XaoSComplexElement(){}voidXaoSComplexElement::GetMinimalSize(int *textwidth, int *width, int *height){     inherited::GetMinimalSize(textwidth, width, height);     *width*=2;     text2->ResizeToPreferred();}voidXaoSComplexElement::SetIt(int xstart, int textwidth, int width, int top, int height, BView *view){     char s[256];     int label1=(int)text2->Divider();     BFont font;     i->GetFont(&font);     int label2=(int)font.StringWidth("i")+4;     BRect r(xstart+textwidth+(width-label1)/2,top,xstart+width+textwidth-label2,top+height);     /* We need to re-create the widget, because it for some purpose refuses to get proper sizes for textview */     delete text2;     sprintf(s,"%g",(double)dialog->deffloat2);     inherited::SetIt(xstart,textwidth,(width-label1-label2)/2, top, height, view);     text2 = new BTextControl(r, "+", "+", s , new BMessage('XaTc'));     text2->SetDivider(label1);     view->AddChild(text2);     i->MoveTo(xstart+width+textwidth-label2+2,top);     i->ResizeTo(label2, height-4);     view->AddChild(i);}voidXaoSComplexElement::GetValue(dialogparam *param){   param->dcoord[0]=ui_getfloat((const char *)text->Text());   param->dcoord[1]=ui_getfloat((const char *)text2->Text());}/* String elements implements input using BTextControl */class XaoSFileElement: public XaoSAStringElement{public:   typedef XaoSAStringElement inherited;    XaoSFileElement(const menudialog *dialog, BWindow *target);   ~XaoSFileElement();   virtual void GetMinimalSize(int *textwidth, int *width, int *height);   virtual void SetIt(int xstart, int textwidth, int width, int top, int height, BView *view);   virtual void GetValue(dialogparam *param);   void ShowFileSelector();   int FileSelectorMessage(BMessage *m);   static void cleanup();protected:   BButton *browse;   static BFilePanel *openpanel, *savepanel;   BFilePanel *panel;   BMessenger *target;   BWindow *looper;   BLocker locker;};BFilePanel *XaoSFileElement::openpanel=NULL;BFilePanel *XaoSFileElement::savepanel=NULL;voidXaoSFileElement::ShowFileSelector(){   BMessage *message = new BMessage('XaFp');   panel->Hide();   message->AddPointer("Ptr",this);   panel->SetMessage(message);   target = new BMessenger(looper);   panel->SetTarget(*target);   if (dialog->type == DIALOG_OFILE) panel->SetSaveText(text->Text());   panel->Show();}/* Convert entry structure back to string. I am not sure how much hazardeous   this conversion is (especially for save) */intXaoSFileElement::FileSelectorMessage(BMessage *m){   locker.Lock();   if (dialog->type == DIALOG_IFILE) {	BPath path;   	entry_ref refs;   	if (m->FindRef("refs", &refs) != B_OK) {locker.Unlock(); return 0;}   	BEntry e(&refs,true);   	e.GetPath(&path);   	SetDefault(path.Path());   } else {        const char *name;	BPath path;   	entry_ref refs;   	if (m->FindRef("directory", &refs)!=B_OK) return 0;        if (m->FindString("name", &name) != B_OK) return 0;	BDirectory dir(&refs);	BEntry entry(&dir, name);	entry.GetRef(&refs);   	entry.GetPath(&path);        {		BFile file(&entry, B_WRITE_ONLY | B_ERASE_FILE | B_CREATE_FILE);		if (file.InitCheck() != B_OK) {locker.Unlock(); return 0;}		BNodeInfo ni(&file);		if (!strcmp(dialog->defstr,"fract*.xpf"))			ni.SetType("image/x-xaos-position");		else if (!strcmp(dialog->defstr,"anim*.xaf"))			ni.SetType("video/x-xaos-animation");		else if (!strcmp(dialog->defstr,"fract*.png"))			ni.SetType("image/png");        }	SetDefault(path.Path());   }   locker.Unlock();   return 1;}XaoSFileElement::XaoSFileElement(const menudialog *d, BWindow *t):	inherited(d){   BRect r(0,0,10,10);   char string[256];   int i,y;   BMessage *message = new BMessage('XaFi');   looper=t;   message->AddPointer("Ptr",this);   for(i=0,y=0;dialog->defstr[i];i++) if(dialog->defstr[i]!='*') string[y++]=dialog->defstr[i];   string[y]=0;   SetDefault(string);   browse = new BButton(r, "Browse", "Browse", message);   target=NULL;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -