#include "diawxgtk.h" class mywxFrame: public wxFrame{ public: bool in_onsize; bool was_resized; int last_width,last_height; MFORM *tbonpaint[100]; int nbonpaint; public: MAINFORM *mf; mywxFrame (wxFrame *_parent, MAINFORM *_mf, int x, int y, long style) : wxFrame(_parent,-1,"", wxPoint(x, y), wxDefaultSize,style) { mf = _mf; in_onsize = false; was_resized = false; last_width = last_height = 0; nbonpaint = 0; } void record_onpaint( MFORM *f){ if (in_onsize){ tbonpaint[nbonpaint++] = f; }else{ f->OnPaint(); } } bool OnClose(wxCloseEvent &){ mf->dump(); mf->escape(); return FALSE; } void menufunc(wxEvent &event){ int id = event.m_id; char path[300]; formbase_getabspath(mf,path); remadmin_setcursor (cursor_wait); mf->dump(); fprintf (mform_fout,"menubar %s %d\n",path,id); fflush (mform_fout); } void SetClientSize (int w, int h) { if (w != -1) last_width = w; if (h != -1) last_height = h; wxFrame::SetClientSize (w,h); } void sizefunc (wxSizeEvent &ev) { wxSize fsz = ev.GetSize(); wxSize msz = mf->GetSize(); // fprintf (stderr,"sizefunc frame [%d,%d] form [%d,%d]\n",fsz.x,fsz.y,msz.x,msz.y); // Not sure how much pixels to reserve mf->SetSize (0,0,fsz.x-6,fsz.y-2); } void SetSize(int x, int y, int width, int height, int sizeFlags) { // fprintf (stderr,"mywxframe setsize %d %d %d %d %d\n",x,y,width,height,sizeFlags); wxFrame::SetSize (x,y,width,height,sizeFlags); } void SetSize (int w, int h) { // fprintf (stderr,"mywxframe setsize %d %d\n",w,h); wxFrame::SetSize (w,h); } DECLARE_EVENT_TABLE() }; #ifndef PROTO_SKIP BEGIN_EVENT_TABLE(mywxFrame,wxFrame) EVT_MENU (-1,mywxFrame::menufunc) EVT_CLOSE (mywxFrame::OnClose) EVT_SIZE (mywxFrame::sizefunc) END_EVENT_TABLE() #endif PUBLIC void MAINFORM::mainlayout() { BUG ("start mainlayout\n"); doalllayout(); int w,h; GetSize (&w,&h); wxMenuBar *bar = fram->GetMenuBar(); int toph = 0; if (bar != NULL){ int w; bar->GetSize(&w,&toph); } h += toph; fram->SetClientSize (w,h); //fprintf (stderr,"End mainlayout %d %d %d\n",w,h,toph); } PRIVATE void MAINFORM::init( wxFrame *_parent, int x, int y, long style) { nopopup = false; enteraction = NULL; fram = new mywxFrame(_parent,this,x,y,style); Create (fram,-1); //wxSizer *s = new wxBoxSizer(wxVERTICAL); //s->Add (this); //fram->SetSizer (s); } PRIVATE void MAINFORM::init(const char *type) { int opt = wxDEFAULT_FRAME_STYLE; int x = -1,y=-1; if (strcmp(type,"error")==0){ x = 300; y=300; opt = wxSTAY_ON_TOP; }else if (strcmp(type,"notice")==0){ x = 300; y=300; opt = wxSTAY_ON_TOP; }else if (strcmp(type,"popup")==0){ rem_getlastmouse(x,y); opt = wxSTAY_ON_TOP; } init (NULL,x,y,opt); } PUBLIC MAINFORM::MAINFORM( const char *_id, const char *_titre, const char *type) : MFORM (_id) { init(type); setTitle (_titre); max_width = 800; const char *trigger = rem_getvar("htrigger"); if (trigger != NULL) max_width = atoi(trigger); } PUBLIC MAINFORM::MAINFORM(const char *_id) : MFORM(_id) { init(""); } PUBLIC MAINFORM::MAINFORM( wxFrame *_parent, const char *_id, int x, int y, long style) : MFORM(_id) { init(_parent,x,y,style); } PUBLIC MAINFORM::~MAINFORM() { free (enteraction); } PUBLIC void MAINFORM::reset() { MFORM::reset(); } PUBLIC void MAINFORM::Popup() { if (!nopopup){ fram->in_onsize = true; // fprintf (stderr,"mainform popup %d\n",pref_width); //if (pref_width == -1) mainlayout(); //fprintf (stderr,"Start fit1\n"); //Fit(); fram->Show(TRUE); fram->in_onsize = false; } } PUBLIC void MAINFORM::Fit() { // layout_debug (id,"Avant Fit\n"); wxFORMBASE::Fit(); // layout_debug (id,"Apres fit\n"); fram->Fit(); int wx,wy; fram->GetSize(&wx,&wy); fram->SetSizeHints (wx,wy); } /* Turn off the Popup function until a show function is executed Normally, every time a sub-form is included in a MAINFORM, it requests a popup to redo the layout. */ PUBLIC void MAINFORM::waitpopup() { nopopup = true; } PUBLIC void MAINFORM::setTitle(const char *title) { fram->SetTitle(title); } PUBLIC VIRTUAL void MAINFORM::dispose() { fram->Destroy(); } PUBLIC void MAINFORM::show() { nopopup = false; Popup(); } PUBLIC void MAINFORM::hide() { fram->Show(FALSE); } PUBLIC void MAINFORM::escape() { remadmin_setcursor (cursor_wait); char path[300]; formbase_getabspath(this,path); fprintf (mform_fout,"action %s X\n",path); fflush (mform_fout); } PUBLIC void MAINFORM::setenteraction(const char *str) { free (enteraction); enteraction = strdup(str); } PUBLIC const char *MAINFORM::getenteraction() { return enteraction; } /* Select the mouse cursor */ PUBLIC void MAINFORM::setcursor(const wxCursor *cur) { fram->SetCursor(*cur); } PUBLIC wxFrame *MAINFORM::getframe() { return fram; } PUBLIC void MAINFORM::record_onpaint( MFORM *f) { fram->record_onpaint(f); } PUBLIC bool MAINFORM::was_resized() { return fram->was_resized; } static wxEventType myevent = wxEVT_USER_FIRST+1; PUBLIC void MAINFORM::popupmenu (wxMenu *mn, int x, int y) { wxCommandEvent ev(myevent); ev.SetClientData(mn); ev.SetInt(x); ev.SetExtraLong(y); AddPendingEvent (ev); } PUBLIC void MAINFORM::dopopup (wxCommandEvent &ev) { POPUPMENU *mn = (POPUPMENU*)ev.GetClientData(); int x,y; fram->GetPosition (&x,&y); x = ev.GetInt() - x; y = ev.GetExtraLong() - y; fram->PopupMenu (mn,x,y); mn->done(); } #ifndef PROTO_SKIP BEGIN_EVENT_TABLE(MAINFORM,MFORM) EVT_COMMAND (-1,myevent,MAINFORM::dopopup) END_EVENT_TABLE() #endif