diff --git a/xvaga/oswin32.cpp b/xvaga/oswin32.cpp index f69206bae..9f33eaaa3 100755 --- a/xvaga/oswin32.cpp +++ b/xvaga/oswin32.cpp @@ -550,7 +550,7 @@ void OsWin32_PlaceProcessInWindow(unsigned int instance, const char* name, unsig for (int i = 0; w._hwnd == NULL && i < 20; i++) { - wxThread::Sleep(500); + ::wxMilliSleep(500); ::EnumWindows(EnumWindowsProc, LPARAM(&w)); } diff --git a/xvaga/xvaga.cpp b/xvaga/xvaga.cpp index 9608f467a..a88582574 100755 --- a/xvaga/xvaga.cpp +++ b/xvaga/xvaga.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -403,16 +404,26 @@ void xvt_app_allow_quit(void) wxTheApp->ExitMainLoop(); // Già lo fa la destroy } -void xvt_app_create(int argc, char **argv, unsigned long flags, - EVENT_HANDLER eh, XVT_CONFIG *config) +XVTDLL void xvt_app_pre_create(void) { xvt_fsys_get_default_dir(NULL); // Init Startup Directory + + wxLocale locale; + locale.Init(wxLocale::GetSystemLanguage()); // wxLANGUAGE_ITALIAN + ::wxInitAllImageHandlers(); + if (wxTheApp->GetComCtl32Version() >= 600 && ::wxDisplayDepth() >= 32) + wxSystemOptions::SetOption(wxT("msw.remap"), 2); + #ifdef SPEECH_API xvt_dm_enable_speech(0xFF); #endif +} +void xvt_app_create(int argc, char **argv, unsigned long flags, + EVENT_HANDLER eh, XVT_CONFIG *config) +{ _task_win_handler = eh; _appl_name = config->appl_name; @@ -559,8 +570,8 @@ void xvt_app_process_pending_events(void) { while (a->Pending()) a->Dispatch(); - //a->ProcessIdle(); // Necessario per wxAUI - //a->Yield(true); + a->ProcessIdle(); // Necessario per wxAUI + //a->Yield(true); // Non so se serva veramente } } @@ -2349,8 +2360,7 @@ XVT_IMAGE xvt_image_capture(WINDOW win, const RCT* src) wxBitmap bmp(r.GetWidth(), r.GetHeight()); CAST_DC(win, wdc); - wxMemoryDC mdc; - mdc.SelectObject(bmp); + wxMemoryDC mdc(bmp); mdc.Blit(wxPoint(0,0), r.GetSize(), &wdc, r.GetPosition()); TXVT_IMAGE* i = new TXVT_IMAGE; @@ -2368,7 +2378,8 @@ XVT_IMAGE xvt_image_create(XVT_IMAGE_FORMAT format, short width, short height, l void xvt_image_destroy(XVT_IMAGE image) { - delete (TXVT_IMAGE*)image; + if (image != NULL) + delete (TXVT_IMAGE*)image; } COLOR xvt_image_get_clut(XVT_IMAGE image, short index) @@ -3487,7 +3498,7 @@ public: wxThread::ExitCode TIconizeTaskThread::Entry() { - Sleep(500); + ::wxMilliSleep(500); if (__bChildRunning) // Il programma e' ancora attivo { wxFrame* frame = (wxFrame*)_task_win; @@ -3765,7 +3776,7 @@ int xvt_sys_get_os_version() void xvt_sys_sleep(unsigned long msec) { - wxThread::Sleep(msec); + ::wxMilliSleep(msec); } /////////////////////////////////////////////////////////// @@ -3886,11 +3897,12 @@ void xvt_vobj_destroy(WINDOW win) wxWindow* w = (wxWindow*)_nice_windows.Get(win); if (w != NULL) { - delete w; - _nice_windows.Delete(win); + wxASSERT((wxWindow*)win == w); + w->Destroy(); // formerly delete w; + _nice_windows.Delete(win); // Elimina dalla lista delle finestre attive } } - GetTDCMapper().DestroyTDC(win); + GetTDCMapper().DestroyTDC(win); // Elimina dalla lista dei display context } } diff --git a/xvaga/xvapp.cpp b/xvaga/xvapp.cpp index 557ba9ede..4f2b989d2 100755 --- a/xvaga/xvapp.cpp +++ b/xvaga/xvapp.cpp @@ -1,14 +1,14 @@ #include "../xvaga/wxinc.h" +#include "xvt.h" + #include #include -#include extern int xvt_main(int argc, char** argv); class TMainApp : public wxApp { - wxLocale m_Locale; wxSingleInstanceChecker* m_sic; protected: @@ -22,7 +22,6 @@ protected: IMPLEMENT_DYNAMIC_CLASS(TMainApp, wxApp) -//DECLARE_APP(TMainApp) IMPLEMENT_APP(TMainApp) #define TIMER_ID 883 @@ -33,6 +32,7 @@ END_EVENT_TABLE() void TMainApp::OnTimer(wxTimerEvent& event) { + xvt_app_pre_create(); xvt_main(argc, argv); } @@ -42,11 +42,6 @@ bool TMainApp::OnInit() const wxString strApp = strWrk.GetName().Lower(); m_sic = new wxSingleInstanceChecker(strApp); - m_Locale.Init(wxLocale::GetSystemLanguage()); // wxLANGUAGE_ITALIAN - - if (GetComCtl32Version() >= 600 && ::wxDisplayDepth() >= 32) - wxSystemOptions::SetOption(wxT("msw.remap"), 2); - wxTimerEvent evt(TIMER_ID); AddPendingEvent(evt); return true; diff --git a/xvaga/xvt.h b/xvaga/xvt.h index 9c1735ac0..30afdb6f7 100755 --- a/xvaga/xvt.h +++ b/xvaga/xvt.h @@ -43,6 +43,7 @@ extern "C" { #endif XVTDLL void xvt_app_allow_quit(void); +XVTDLL void xvt_app_pre_create(void); XVTDLL void xvt_app_create(int argc, char **argv, unsigned long flags, EVENT_HANDLER eh, XVT_CONFIG *config); XVTDLL void xvt_app_destroy(void); XVTDLL BOOLEAN xvt_app_escape(int esc_code, PRINT_RCD*, long* ph, long* pw, long* pvr, long* phr); @@ -234,6 +235,8 @@ XVTDLL short xvt_notebk_add_page(WINDOW notebk, WINDOW page, const char* title, XVTDLL WINDOW xvt_notebk_get_page(WINDOW notebk, short page_no); XVTDLL short xvt_notebk_get_num_tabs(WINDOW notebk); XVTDLL void xvt_notebk_set_front_page(WINDOW notebk, short page_no); +XVTDLL void xvt_notebk_set_tab_icon(WINDOW notebk, short page_no, int rid); +XVTDLL void xvt_notebk_set_tab_image(WINDOW notebk, short page_no, XVT_IMAGE img); XVTDLL void xvt_notebk_set_tab_title(WINDOW notebk, short page_no, const char* title); XVTDLL void xvt_notebk_set_page_title(WINDOW notebk, short page_no, const char* title); XVTDLL char* xvt_notebk_get_tab_title(WINDOW notebk, short page_no, char* title, int sz_title); diff --git a/xvaga/xvtctl.cpp b/xvaga/xvtctl.cpp index 52a67e37b..3cf45f931 100755 --- a/xvaga/xvtctl.cpp +++ b/xvaga/xvtctl.cpp @@ -3,11 +3,11 @@ #include "xvtwin.h" #include "statbar.h" -#include #include #include #include #include +#include /////////////////////////////////////////////////////////// // Utility functions @@ -88,27 +88,30 @@ public: { Create(parent, id, pos, size, style); } }; -class TwxNoteBook : public wxNotebook +class TwxNoteBook : public wxAuiNotebook { + enum { BOOK_ICO_SIZE = 16 }; + bool m_bSuspended; + protected: DECLARE_EVENT_TABLE() void OnPageChanged(wxNotebookEvent& e); - + long Flags2Style(long flags) const; public: - short AddTab(wxWindow* pPage, const wxString text, wxBitmap* bmp = NULL, short idx = -1); + int ChangeSelection(size_t tab_no); // wxNotebook had it! + void SetTabImage(size_t tab_no, XVT_IMAGE img); + + short AddTab(wxWindow* pPage, const wxString text, XVT_IMAGE img = NULL, short idx = -1); TwxNoteBook(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style); ~TwxNoteBook(); }; class TwxTreeCtrl : public wxTreeCtrl { -#if wxCHECK_VERSION(2,8,7) WX_DECLARE_VOIDPTR_HASH_MAP(int, XVT_IMAGE_Map); XVT_IMAGE_Map m_img; -#else - wxHashTable m_img; -#endif + wxFont m_font; int m_nFrozen; @@ -126,11 +129,7 @@ protected: public: void SetNodeImages(const wxTreeItemId& id, XVT_IMAGE item_image, XVT_IMAGE collapsed_image, XVT_IMAGE expanded_image); -#if wxCHECK_VERSION(2,8,7) virtual bool SetFont(const wxFont& font) { m_font = font; return font.IsOk(); } -#else - virtual bool SetFont(const wxFont& font) { m_font = font; return true; } -#endif virtual wxFont GetFont() const; void Suspend(); @@ -151,6 +150,7 @@ class TwxOutlookBar : public wxVListBox TwxOutlookItem m_item[MAX_ITEMS]; bool m_bCaptured; int m_nHovering; + DECLARE_EVENT_TABLE() protected: @@ -234,12 +234,7 @@ WINDOW xvt_ctl_create_def(WIN_DEF *win_def_p, WINDOW parent_win, long app_data) break; case WC_NOTEBK: { - const long flags = win_def_p->v.ctl.flags; - long style = 0; - if (flags & CTL_FLAG_LEFT_JUST) style |= wxNB_LEFT; - if (flags & CTL_FLAG_RIGHT_JUST) style |= wxNB_RIGHT; - if (flags & CTL_FLAG_CENTER_JUST) style |= wxNB_BOTTOM; - TwxNoteBook* nb = new TwxNoteBook(pParent, id, rct.GetPosition(), rct.GetSize(), style); + TwxNoteBook* nb = new TwxNoteBook(pParent, id, rct.GetPosition(), rct.GetSize(), win_def_p->v.ctl.flags); win = (WINDOW)nb; } break; @@ -413,55 +408,103 @@ XVTDLL BOOLEAN xvt_pane_detach(WINDOW win) inline bool VALID_NOTEBOOK(WINDOW notebk, short page_no) { return notebk != NULL_WIN && page_no >= 0; } -BEGIN_EVENT_TABLE(TwxNoteBook, wxNotebook) +BEGIN_EVENT_TABLE(TwxNoteBook, wxAuiNotebook) EVT_NOTEBOOK_PAGE_CHANGED(wxID_ANY, TwxNoteBook::OnPageChanged) END_EVENT_TABLE(); void TwxNoteBook::OnPageChanged(wxNotebookEvent& evt) { - EVENT e; memset(&e, 0, sizeof(EVENT)); - e.type = E_CONTROL; - e.v.ctl.id = evt.GetId(); - e.v.ctl.ci.type = WC_NOTEBK; - e.v.ctl.ci.win = WINDOW(this); - e.v.ctl.ci.v.notebk.face = (WINDOW)GetPage(evt.GetSelection()); - e.v.ctl.ci.v.notebk.tab_no = evt.GetSelection(); - e.v.ctl.ci.v.notebk.page_no = evt.GetOldSelection(); + if (!m_bSuspended) + { + m_bSuspended = true; + EVENT e; memset(&e, 0, sizeof(EVENT)); + e.type = E_CONTROL; + e.v.ctl.id = evt.GetId(); + e.v.ctl.ci.type = WC_NOTEBK; + e.v.ctl.ci.win = WINDOW(this); + e.v.ctl.ci.v.notebk.face = (WINDOW)GetPage(evt.GetSelection()); + e.v.ctl.ci.v.notebk.tab_no = evt.GetSelection(); + e.v.ctl.ci.v.notebk.page_no = evt.GetOldSelection(); - TwxWindow* win = (TwxWindow*)GetParent(); - win->DoXvtEvent(e); + TwxWindow* win = (TwxWindow*)GetParent(); + win->DoXvtEvent(e); + m_bSuspended = false; + } } -short TwxNoteBook::AddTab(wxWindow* pPage, const wxString text, wxBitmap* bmp, short idx) +short TwxNoteBook::AddTab(wxWindow* pPage, const wxString text, XVT_IMAGE xvt_img, short idx) { - int imageId = -1; - if (bmp != NULL) + wxBitmap bmp; + if (xvt_img != NULL) { - wxImageList* il = GetImageList(); - if (il == NULL) - AssignImageList(il = new wxImageList(bmp->GetWidth(), bmp->GetHeight())); - imageId = il->Add(*bmp); + wxImage& img = *(wxImage*)xvt_img; + img.Rescale(BOOK_ICO_SIZE, BOOK_ICO_SIZE, wxIMAGE_QUALITY_HIGH); + bmp = Image2Bitmap(xvt_img, true); } + if (pPage->GetParent() != this) pPage->Reparent(this); if (idx < 0 || idx >= (int)GetPageCount()) { - AddPage(pPage, text, false, imageId); + AddPage(pPage, text, false, bmp); idx = GetPageCount()-1; } else - InsertPage(idx, pPage, text, false, imageId); + InsertPage(idx, pPage, text, false, bmp); return idx; } +void TwxNoteBook::SetTabImage(size_t idx, XVT_IMAGE img) +{ + if (img != NULL) + { + wxImage ico(*(wxImage*)img); + ico.Rescale(BOOK_ICO_SIZE, BOOK_ICO_SIZE, wxIMAGE_QUALITY_HIGH); + const wxBitmap bmp(ico); + SetPageBitmap(idx, bmp); + } + else + SetPageBitmap(idx, wxNullBitmap); +} + +int TwxNoteBook::ChangeSelection(size_t tab_no) +{ + const size_t nSel = GetSelection(); + if (!m_bSuspended && tab_no != nSel) + { + m_bSuspended = true; + SetSelection(tab_no); + m_bSuspended = false; + } + return nSel; +} + +long TwxNoteBook::Flags2Style(long flags) const +{ + long style = wxAUI_NB_TAB_MOVE | wxAUI_NB_SCROLL_BUTTONS; + if (flags & CTL_FLAG_CENTER_JUST) + style |= wxAUI_NB_BOTTOM; + else + style |= wxAUI_NB_TOP; + return style; +} + TwxNoteBook::TwxNoteBook(wxWindow *parent, wxWindowID id, - const wxPoint& pos, const wxSize& size, long style) - : wxNotebook(parent, id, pos, size, style) + const wxPoint& pos, const wxSize& size, long flags) + : wxAuiNotebook(parent, id, pos, size, Flags2Style(flags)), m_bSuspended(false) { _nice_windows.Put((WINDOW)this, this); } TwxNoteBook::~TwxNoteBook() { + // Il wxAuiNotebook non gradisce le pagine doppie, per cui ... le ammazzo io. + for (int i = GetPageCount()-1; i > 0; i--) + { + wxWindow* page = GetPage(i); // Pagina corrente a partire dall'ultima + if (GetPageIndex(page) < i) // C'e' anche prima ... + RemovePage(i); // ... allora la rimuovo (senza delete!) + } + _nice_windows.Delete((WINDOW)this); } @@ -471,11 +514,10 @@ short xvt_notebk_add_page(WINDOW notebk, WINDOW page, const char* title, XVT_IMA if (notebk != NULL_WIN) { CAST_NOTEBOOK(notebk, nb); - wxBitmap* bmp = NULL; wxString strTitle = title; if (strTitle.IsEmpty() && page != NULL_WIN) strTitle = ((wxWindow*)page)->GetLabel(); - idx = nb.AddTab((wxWindow*)page, strTitle, bmp, tab_no); + idx = nb.AddTab((wxWindow*)page, strTitle, image, tab_no); } return idx; } @@ -529,7 +571,7 @@ void xvt_notebk_set_front_page(WINDOW notebk, short tab_no) wxWindow* w = nb.GetPage(tab_no); if (w != NULL) { - nb.ChangeSelection(tab_no); // Non generare eventi di cambio pagina! + nb.ChangeSelection(tab_no); // Non genera evento di cambio pagina! if (!w->IsShown()) // A volte succede che la prima pagina sia nascosta! w->Show(true); } @@ -556,6 +598,23 @@ void xvt_notebk_set_page_title(WINDOW notebk, short tab_no, const char* title) xvt_vobj_set_title(win, title); } +void xvt_notebk_set_tab_image(WINDOW notebk, short tab_no, XVT_IMAGE img) +{ + if (notebk != NULL_WIN && tab_no >= 0) + { + CAST_NOTEBOOK(notebk, nb); + nb.SetTabImage(tab_no, img); // Se img=NULL toglie l'immagine + } +} + +void xvt_notebk_set_tab_icon(WINDOW notebk, short tab_no, int rid) +{ + const wxString strName = _GetResourceName("Icon", rid); + XVT_IMAGE img = xvt_image_read(strName); + xvt_notebk_set_tab_image(notebk, tab_no, img); + xvt_image_destroy(img); +} + void xvt_notebk_set_tab_title(WINDOW notebk, short tab_no, const char* title) { if (notebk != NULL_WIN && tab_no >= 0) @@ -1263,26 +1322,28 @@ BOOLEAN xvt_toolbar_add_control(WINDOW win, int cid, TOOL_TYPE type, const char return ok; } -WINDOW xvt_toolbar_create(int cid, int left, int top, int right, int bottom, long nStyle, WINDOW parent) +WINDOW xvt_toolbar_create(int cid, int left, int top, int right, int bottom, long nFlags, WINDOW parent) { + long nStyle = wxNO_BORDER | wxTB_NODIVIDER; + if (nFlags & CTL_FLAG_PASSWORD) + nStyle |= wxTB_TEXT | wxTB_FLAT; + const wxPoint ptPos(left, top); wxSize szSize(right-left, bottom-top); - nStyle |= wxNO_BORDER | wxTB_NODIVIDER; // wxTB_FLAT non disegna il bordo! + int nIcoSize = 24; if (bottom > 0) { nStyle |= wxTB_HORIZONTAL; nIcoSize = RoundToIcon(szSize.y); - szSize.y = nIcoSize; } else { nStyle |= wxTB_VERTICAL; nIcoSize = RoundToIcon(szSize.x); - szSize.x = nIcoSize; } - TwxToolBar* tb = new TwxToolBar((wxWindow*)parent, cid, ptPos, szSize, nStyle); + TwxToolBar* tb = new TwxToolBar((wxWindow*)parent, cid, ptPos, wxDefaultSize, nStyle); tb->SetToolBitmapSize(wxSize(nIcoSize, nIcoSize)); return (WINDOW)tb; } diff --git a/xvaga/xvtwin.cpp b/xvaga/xvtwin.cpp index ec8c92b17..b47f27c83 100755 --- a/xvaga/xvtwin.cpp +++ b/xvaga/xvtwin.cpp @@ -245,8 +245,8 @@ wxDC& TDC::GetDC(bool bPaint) if (bPaint) { KillDC(); - //_dc = new wxPaintDC(_owner); - _dc = new wxAutoBufferedPaintDC(_owner); + //_dc = new wxAutoBufferedPaintDC(_owner); // Funziona ma si vedono cose strane temporanee + _dc = new wxPaintDC(_owner); _dirty = -1; } else @@ -933,10 +933,10 @@ TwxWindow::~TwxWindow() e.type = E_DESTROY; DoXvtEvent(e); - if (_timer) + if (_timer != NULL) delete _timer; - if (m_pManager) + if (m_pManager != NULL) { m_pManager->UnInit(); // Obbligatorio ma, chissa' perche', non gestito dal distruttore! delete m_pManager; @@ -947,6 +947,7 @@ TwxWindow::~TwxWindow() xvt_res_free_menu_tree(m_menu); ((TTaskWin*)_task_win)->PopMenuTree(); } + _nice_windows.Delete((WINDOW)this); }