diff --git a/xvaga/xvaga.cpp b/xvaga/xvaga.cpp index 5e5a06106..7cc0fbf2f 100755 --- a/xvaga/xvaga.cpp +++ b/xvaga/xvaga.cpp @@ -3,15 +3,11 @@ #include #include #include -#include -#include #include #include #include -#include #include #include -#include #include #include #include @@ -42,11 +38,6 @@ #endif #define XVT_ASSERT(test) _AssertBox((test), __FUNCTION__, __FILE__, __LINE__) -#define CAST_WIN(win,w) wxWindow& w = *wxStaticCast((wxObject*)win, wxWindow); -#define CAST_TWIN(win,w) TwxWindow& w = *wxStaticCast((wxObject*)win, TwxWindow); -#define CAST_TDC(win,dc) TDC& dc = GetTDCMapper().GetTDC(win); -#define CAST_DC(win,dc) wxDC& dc = GetTDCMapper().GetDC(win); -#define CAST_FONT(font_id, font) TFontId& font = *wxStaticCast(font_id, TFontId); wxWindow* _mouse_trapper = NULL; RCT _startup_rect = { 0,0,0,0 }; @@ -54,6 +45,7 @@ long _startup_style = 0; wxString _startup_dir; wxString _strDefaultStatbarText; wxString _appl_name; +wxString _appl_version; wxLocale* _locale = NULL; static XVT_ERRMSG_HANDLER _error_handler = NULL; @@ -61,159 +53,6 @@ static XVT_ERRMSG_HANDLER _error_handler = NULL; const wxString& _GetAppTitle() { return _appl_name; } -/////////////////////////////////////////////////////////// -// TMessageBox -/////////////////////////////////////////////////////////// - -class TMessageBox : public wxDialog -{ - wxTimer m_timer; - -protected: - void OnButton(wxCommandEvent& evt); - void OnTimeout(wxTimerEvent& evt); - void AddButton(wxSizer* sz, int id, int ico); - DECLARE_EVENT_TABLE() - -public: - TMessageBox(wxWindow* pParent, const wxString& msg, int nStyle, int nTimeout = 0); -}; - -BEGIN_EVENT_TABLE(TMessageBox, wxDialog) - EVT_BUTTON(wxID_ANY, TMessageBox::OnButton) - EVT_TIMER(wxID_ANY, TMessageBox::OnTimeout) -END_EVENT_TABLE() - -void TMessageBox::OnButton(wxCommandEvent& evt) -{ - int ec = wxCANCEL; - switch (evt.GetId()) - { - case wxID_YES: ec = wxYES; break; - case wxID_OK : ec = wxOK; break; - case wxID_NO : ec = wxNO; break; - default : ec = GetEscapeId(); break; - } - EndModal(ec); -} - -void TMessageBox::OnTimeout(wxTimerEvent& WXUNUSED(evt)) -{ - wxWindowID id = GetEscapeId(); - if (id <= 0) - id = GetAffirmativeId(); - if (id > 0) - { - wxCommandEvent cmd(wxEVT_COMMAND_BUTTON_CLICKED, id); - AddPendingEvent(cmd); - } - else - EndModal(wxCANCEL); -} - -void TMessageBox::AddButton(wxSizer* sz, int id, int WXUNUSED(ico)) -{ - sz->Add(new wxButton(this, id, wxEmptyString, wxDefaultPosition, wxSize(80, 32)), 0, wxALL, 4); -} - -TMessageBox::TMessageBox(wxWindow* pParent, const wxString& msg, int nStyle, int nTimeout) - : wxDialog(pParent, wxID_ANY, _GetAppTitle(), wxDefaultPosition, wxDefaultSize, - wxCAPTION | wxRAISED_BORDER), m_timer(this) -{ - TTaskWin* tw = wxDynamicCast(pParent ? pParent : _task_win, TTaskWin); - if (tw != NULL) - { - const COLOR col = tw->GetCtlColor(XVT_COLOR_BACKGROUND); - if (col != COLOR_INVALID) - { - CAST_COLOR(col, rgb); - SetOwnBackgroundColour(rgb); - } - } - - wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL); - - wxBoxSizer* sz1 = new wxBoxSizer(wxHORIZONTAL); - sizer->Add(sz1); - - wxArtID nIco = wxART_INFORMATION; - if (nStyle & wxICON_HAND) nIco = wxART_ERROR; else - if (nStyle & wxICON_INFORMATION) nIco = wxART_INFORMATION; else - if (nStyle & wxICON_EXCLAMATION) nIco = wxART_WARNING; else - if (nStyle & wxICON_QUESTION) nIco = wxART_QUESTION; else - if (nStyle & 0x1000) nIco = "220"; - - const wxBitmap img = wxArtProvider::GetBitmap(nIco, wxART_MESSAGE_BOX, wxSize(64,64)); - - const int nBorder = 8; - sz1->Add(new wxStaticBitmap(this, wxID_ANY, img), 0, wxALL, nBorder); - wxStaticText* ss = new wxStaticText(this, wxID_ANY, wxEmptyString); - ss->Wrap(160); - ss->SetLabel(msg); - sz1->Add(ss, 0, wxALL|wxALIGN_CENTER|wxALIGN_CENTER_VERTICAL, nBorder); - - sizer->Add(new wxStaticLine(this), 0, wxALL|wxEXPAND, nBorder); - - wxBoxSizer* sz2 = new wxBoxSizer(wxHORIZONTAL); - sizer->Add(sz2, 0, wxALIGN_CENTER); - if (nStyle & wxYES_NO) - { - if (nStyle & wxNO_DEFAULT) - { - SetAffirmativeId(wxID_NO); - SetEscapeId(wxID_YES); - AddButton(sz2, wxID_NO, 102); - AddButton(sz2, wxID_YES, 101); - } - else - { - SetAffirmativeId(wxID_YES); - SetEscapeId(wxID_NO); - AddButton(sz2, wxID_YES, 101); - AddButton(sz2, wxID_NO, 102); - } - } - if (nStyle & wxOK) - { - SetAffirmativeId(wxID_OK); - AddButton(sz2, wxID_OK, 101); - } - if (nStyle & wxCANCEL) - { - SetEscapeId(wxID_CANCEL); - AddButton(sz2, wxID_CANCEL, 102); - } - - SetSizerAndFit(sizer); - - if (nStyle & wxCENTRE) - Centre(); - - if (nTimeout > 0) - m_timer.Start(1000*nTimeout, true); -} - -/////////////////////////////////////////////////////////// -// _*Box -/////////////////////////////////////////////////////////// - -int _MessageBox(const wxString& msg, int nStyle, int nTimeout = 0) -{ - xvt_dm_post_speech(msg, 1, TRUE); - - TMessageBox dlg(NULL, msg, nStyle, nTimeout); - const int ret = dlg.ShowModal(); - - switch(ret) - { - case wxOK : xvt_dm_post_speech(_("ok"), 7, TRUE); break; - case wxYES: xvt_dm_post_speech(_("si"), 7, TRUE); break; - case wxNO : xvt_dm_post_speech(_("no"), 7, TRUE); break; - default : xvt_dm_post_speech(_("annulla"), 7, TRUE); break; - } - return ret; -} - void _AssertBox(bool test, const char* func, const char* file, int line) { if (!test) @@ -229,226 +68,6 @@ void _AssertBox(bool test, const char* func, const char* file, int line) } } -/////////////////////////////////////////////////////////// -// _PopUpBox -/////////////////////////////////////////////////////////// - -class TPopUpBox : public wxDialog -{ - DECLARE_EVENT_TABLE(); - wxTimer m_Timer; - int m_nStep, m_nTimeout; - -protected: - void OnTimer(wxTimerEvent& evt); - void OnChar(wxKeyEvent& evt); - void OnClick(wxMouseEvent& evt); - -public: - TPopUpBox(wxWindow* pParent, const wxString& msg, int nStyle, int nTimeout); -}; - -BEGIN_EVENT_TABLE(TPopUpBox, wxDialog) - EVT_TIMER(wxID_ANY, TPopUpBox::OnTimer) - EVT_CHAR(TPopUpBox::OnChar) - EVT_LEFT_DOWN(TPopUpBox::OnClick) -END_EVENT_TABLE() - -void TPopUpBox::OnChar(wxKeyEvent& WXUNUSED(evt)) -{ - if (IsShown()) - EndModal(wxID_CANCEL); -} - -void TPopUpBox::OnClick(wxMouseEvent& WXUNUSED(evt)) -{ - if (IsShown()) - EndModal(wxID_CANCEL); -} - - -void TPopUpBox::OnTimer(wxTimerEvent& WXUNUSED(evt)) -{ - if (IsShown()) - { - const wxRect rctMain = GetParent()->GetRect(); - const wxRect rctMine = GetRect(); - const int msec = (m_nStep++)*m_Timer.GetInterval(); - if (msec <= m_nTimeout/4) - { - const double perc = double(msec)/(m_nTimeout/4); - Move(rctMain.x, rctMain.GetBottom() - rctMine.height * perc); - } - if (msec >= 3*m_nTimeout/4 && msec <= m_nTimeout) - { - const double perc = double(m_nTimeout-msec)/(m_nTimeout/4); - Move(rctMain.x, rctMain.GetBottom() - rctMine.height * perc); - } - if (msec > m_nTimeout) - { - m_Timer.Stop(); - EndModal(wxID_CANCEL); - } - } -} - -TPopUpBox::TPopUpBox(wxWindow* pParent, const wxString& msg, int nStyle, int nTimeout) - : wxDialog(pParent, wxID_ANY, wxEmptyString, wxPoint(0,2024), wxDefaultSize, wxBORDER_SIMPLE), - m_nTimeout(nTimeout*1000), m_Timer(this), m_nStep(0) -{ - TTaskWin* tw = wxDynamicCast(pParent ? pParent : _task_win, TTaskWin); - if (tw != NULL) - { - const COLOR col = tw->GetCtlColor(XVT_COLOR_BACKGROUND); - if (col != COLOR_INVALID) - { - CAST_COLOR(col, rgb); - SetOwnBackgroundColour(rgb); - } - } - - wxBoxSizer* sz = new wxBoxSizer(wxHORIZONTAL); - - wxArtID nIco = wxART_ERROR; - if (nStyle & wxICON_HAND) nIco = wxART_ERROR; else - if (nStyle & wxICON_INFORMATION) nIco = wxART_INFORMATION; else - if (nStyle & wxICON_EXCLAMATION) nIco = wxART_WARNING; else - if (nStyle & 0x1000) nIco = "220"; - const wxBitmap img = wxArtProvider::GetBitmap(nIco, wxART_MESSAGE_BOX); - - wxStaticBitmap* bmp = new wxStaticBitmap(this, wxID_ANY, img); - sz->Add(bmp, 0, wxALL, 8); - - wxStaticText* ss = new wxStaticText(this, wxID_ANY, wxEmptyString); - ss->Wrap(160); - ss->SetLabel(msg); - sz->Add(ss, 0, wxALL | wxALIGN_CENTER | wxALIGN_CENTER_VERTICAL, 8); - - SetSizerAndFit(sz); - m_Timer.Start(25); -} - -static void _PopUpBox(const wxString& msg, int nStyle, int nTimeout = 4) -{ - const int oem = xvt_sys_get_oem_int("OEM", -1); - wxWindow* pFrame = wxTheApp->GetTopWindow(); - if (oem == 0 && pFrame != NULL) - { - xvt_sys_beep(nStyle & wxICON_ERROR ? 2 : 1); - TPopUpBox dlg(pFrame, msg, nStyle, nTimeout <= 0 ? 4 : nTimeout); - dlg.ShowModal(); - } - else - _MessageBox(msg, nStyle|wxOK|wxCENTRE, nTimeout); -} - -WX_DECLARE_STRING_HASH_MAP(int, TMessagesMap); - -void xvt_sys_sorry_box(const char* func, const char* file, int line) -{ -#ifndef NDEBUG - static TMessagesMap sorry; - if (sorry[func]++ == 0) - { - wxString strMessage; - strMessage.Printf("Function %s in file %s at line %d\nis not implemented yet: be patient...", - func, file, line); - _PopUpBox(strMessage, 0x1000); // Smiley Icon - } -#endif -} - -void xvt_sys_deprecated_box(const char* oldfunc, const char* file, const char* newfunc) -{ -#ifndef NDEBUG - static TMessagesMap deprecated; - if (deprecated[oldfunc]++ == 0) - { - wxString strMessage; - strMessage.Printf("Function %s in file %s is deprecated:\n%s is much more trendy now!\nYou can blame Guy for this, if you're bold enough!", - oldfunc, file, newfunc); - _PopUpBox(strMessage, 0x1000); - } -#endif -} - -/////////////////////////////////////////////////////////// -// Font cache -/////////////////////////////////////////////////////////// - -//WX_DECLARE_HASH_MAP(wxString, wxFont*, wxStringHash, wxStringEqual, wxFontHashMap); -WX_DECLARE_STRING_HASH_MAP(wxFont*, wxFontHashMap); - -class TFontCache -{ - wxFontHashMap* m_map; - -public: - wxFont& FindOrCreate(int pointSize, int family, int style, int weight, - bool underline, const wxString& face); - void Destroy(); - TFontCache() : m_map(NULL) { } - ~TFontCache() { Destroy(); } - -} XVT_FONT_CACHE; - -void TFontCache::Destroy() -{ - if (m_map) - { - m_map->clear(); -// delete m_map; // NON funziona ma non si capisce perche': PAZIENZA! - m_map = NULL; - } -} - -wxFont& TFontCache::FindOrCreate(int pointSize, int family, int style, int weight, - bool underline, const wxString& face) -{ - if (m_map == NULL) - m_map = new wxFontHashMap; - - wxString key; - key.Printf("%s_%d_%d_%d_%d", face, pointSize, style, weight, underline); - wxFont* pFont = (*m_map)[key]; - if (pFont == NULL) - { - pFont = new wxFont(pointSize, family, style, weight, underline, face); - pFont->SetPointSize(pointSize); // Colpo di classe indispensabile per i PDF :-) - (*m_map)[key] = pFont; - } - return *pFont; -} - -/////////////////////////////////////////////////////////// -// Speech support -/////////////////////////////////////////////////////////// - -// 0 Errors -// 1 Warnings -// 2 Messages -// 3 Requests -// 7 Buttons -static int m_nSpeechMode = 0; - -void xvt_dm_enable_speech(int mode) -{ -#ifdef SPEECH_API - m_nSpeechMode = mode; -#ifdef WIN32 - if (m_nSpeechMode != 0) - { - if (!OsWin32_InitializeSpeech()) - m_nSpeechMode = 0; - } - else - { - OsWin32_DeinitializeSpeech(); - } -#endif -#endif -} - /////////////////////////////////////////////////////////// // XVT /////////////////////////////////////////////////////////// @@ -483,12 +102,12 @@ XVTDLL void xvt_app_pre_create(void) #endif } -void xvt_app_create(int argc, char **argv, unsigned long WXUNUSED(flags), - EVENT_HANDLER eh, XVT_CONFIG *config) +void xvt_app_create(int argc, char** argv, unsigned long WXUNUSED(flags), + EVENT_HANDLER eh, XVT_CONFIG* config) { _task_win_handler = eh; _appl_name = config->appl_name; - + const wxString title = config->taskwin_title; wxPoint pos = wxDefaultPosition; @@ -830,352 +449,53 @@ BOOLEAN xvt_dongle_sl_write_block(unsigned short reg, unsigned short size, const } /////////////////////////////////////////////////////////// -// Common dialogs +// Font cache /////////////////////////////////////////////////////////// -void xvt_dm_post_about_box() +//WX_DECLARE_HASH_MAP(wxString, wxFont*, wxStringHash, wxStringEqual, wxFontHashMap); +WX_DECLARE_STRING_HASH_MAP(wxFont*, wxFontHashMap); + +class TFontCache { - SORRY_BOX(); -} - -COLOR xvt_dm_post_choose_color(WINDOW win, COLOR xc) -{ - DEPRECATED_BOX("xvt_dm_post_color_sel"); - xvt_dm_post_color_sel(&xc, win); - return xc; -} - -BOOLEAN xvt_dm_post_color_sel(COLOR* color, unsigned long reserved) -{ - CAST_COLOR(*color, wc); - - wxColourData cd; - cd.SetChooseFull(true); - cd.SetColour(wc); - for (int i = 0; i < 16; i++) - { - const unsigned char val = (i & 0x8) ? 255 : 127; - const unsigned char red = (i & 0x1) ? val : 0; - const unsigned char green = (i & 0x2) ? val : 0; - const unsigned char blue = (i & 0x4) ? val : 0; - wxColour col(red, green, blue); - cd.SetCustomColour(i, col); - } - - wxWindow* win = wxDynamicCast ((void*)reserved, wxWindow); - wxColourDialog dialog(win, &cd); - if (dialog.ShowModal() == wxID_OK) - { - *color = MAKE_XVT_COLOR(dialog.GetColourData().GetColour()); - if (*color == 0) *color = COLOR_BLACK; // 0x000000 confonde XI, mentre con 0x07000000 e' a suo agio - return TRUE; - } - - return FALSE; -} - -class TwxCalendarDlg : public wxDialog -{ - enum { ID_CAL = 1883 }; - wxDateTime& m_date; - wxCalendarCtrl* m_cal; - -protected: - virtual bool TransferDataFromWindow(); - void OnCalendar(wxCalendarEvent& e); + wxFontHashMap* m_map; public: - TwxCalendarDlg(wxWindow* parent, wxDateTime& date); + wxFont& FindOrCreate(int pointSize, int family, int style, int weight, + bool underline, const wxString& face); + void Destroy(); + TFontCache() : m_map(NULL) { } + ~TFontCache() { Destroy(); } - DECLARE_EVENT_TABLE() -}; +} XVT_FONT_CACHE; -BEGIN_EVENT_TABLE(TwxCalendarDlg, wxDialog) - EVT_CALENDAR(wxID_ANY, TwxCalendarDlg::OnCalendar) -END_EVENT_TABLE() - -void TwxCalendarDlg::OnCalendar(wxCalendarEvent& WXUNUSED(e)) -{ - wxCommandEvent evt(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK); - AddPendingEvent(evt); +void TFontCache::Destroy() +{ + if (m_map) + { + m_map->clear(); +// delete m_map; // NON funziona ma non si capisce perche': PAZIENZA! + m_map = NULL; + } } -bool TwxCalendarDlg::TransferDataFromWindow() +wxFont& TFontCache::FindOrCreate(int pointSize, int family, int style, int weight, + bool underline, const wxString& face) { - bool ok = wxDialog::TransferDataFromWindow(); - if (ok) - m_date = m_cal->GetDate(); - return ok; -} - -TwxCalendarDlg::TwxCalendarDlg(wxWindow* parent, wxDateTime& date) - : wxDialog(parent, wxID_ANY, "Data", wxDefaultPosition, wxDefaultSize, wxRAISED_BORDER), m_date(date) -{ - - m_cal = new wxCalendarCtrl(this, ID_CAL, m_date, wxDefaultPosition, wxDefaultSize, - wxCAL_MONDAY_FIRST | wxCAL_SHOW_HOLIDAYS | wxCAL_SHOW_SURROUNDING_WEEKS); - - wxButton* button = new wxButton(this, wxID_OK, "OK"); - - wxGridSizer* sizer = new wxFlexGridSizer(2, 1, 8, 8); - sizer->Add(m_cal, 0, wxALIGN_CENTER); - sizer->Add(button, 0, wxALIGN_CENTER); - SetSizer(sizer); - sizer->SetSizeHints(this); -} - -unsigned int xvt_dm_post_choose_date(WINDOW win, const RCT* rct, unsigned int ansidate) -{ - int d = ansidate%100; - int m = (ansidate/100)%100; - int y = ansidate / 10000; - - wxDateTime date; - if (d >= 1 && d <= 31 && m >= 1 && m <= 12 && y > 1900) - date.Set(d, wxDateTime::Month(m-1), y); - else - date = wxDateTime::Today(); + if (m_map == NULL) + m_map = new wxFontHashMap; - CAST_WIN(win, w); - wxDialog* dlg = new TwxCalendarDlg(&w, date); - - if (rct != NULL) + wxString key; + key.Printf("%s_%d_%d_%d_%d", face, pointSize, style, weight, underline); + wxFont* pFont = (*m_map)[key]; + if (pFont == NULL) { - const wxRect client = w.GetClientRect(); - const wxRect rect = dlg->GetRect(); - wxPoint pos(rct->right - rect.width, rct->bottom); - if (pos.x < 0) - pos.x = rct->left; - if (rct->bottom + rect.height > client.GetBottom()) - pos.y = rct->top - rect.height; - dlg->Move(w.ClientToScreen(pos)); + pFont = new wxFont(pointSize, family, style, weight, underline, face); + pFont->SetPointSize(pointSize); // Colpo di classe indispensabile per i PDF :-) + (*m_map)[key] = pFont; } - - if (dlg->ShowModal() == wxID_OK) - { - d = date.GetDay(); - m = date.GetMonth()+1; - y = date.GetYear(); - ansidate = y*10000 + m*100 + d; - } - dlg->Destroy(); - - return ansidate; + return *pFont; } -BOOLEAN xvt_dm_post_speech(const char* text, int priority, BOOLEAN async) -{ - BOOLEAN ok = FALSE; -#ifdef SPEECH_API - if ((m_nSpeechMode & (1 << priority)) != 0) - { -#ifdef WIN32 - ok = OsWin32_Speak(text, async != 0); -#endif - } -#endif - return ok; -} - -ASK_RESPONSE xvt_dm_post_ask(const char* Btn1, const char* Btn2, const char* Btn3, const char* fmt) -{ - int nFlags = wxCENTRE | wxICON_QUESTION | wxYES_NO; - if (Btn3 == NULL) - { - if (wxStricmp(Btn1, "no") == 0) - nFlags |= wxNO_DEFAULT; - } - else - nFlags |= wxCANCEL; - - const int answer = _MessageBox(fmt, nFlags); - return answer == wxYES ? RESP_DEFAULT : (answer == wxNO ? RESP_2 : RESP_3); -} - -void xvt_dm_post_error(const char *fmt) -{ - //_MessageBox(fmt, wxOK | wxCENTRE | wxICON_HAND); - _PopUpBox(fmt, wxICON_HAND, 0); -} - -void xvt_dm_post_fatal_exit(const char *fmt) -{ - xvt_dm_post_speech(fmt, 1, TRUE); - wxLogFatalError(fmt); - xvt_dm_post_speech("OK", 7, TRUE); -} - -static wxString MakeFileName(const wxChar* name, const wxChar* ext) -{ - wxString f = name; - if (ext && *ext) - { - if (*ext != '.') - f += '.'; - f += ext; - } - return f; -} - -static FL_STATUS xvt_dm_post_file_ask(FILE_SPEC *fsp, const char *msg, int flags) -{ - DIRECTORY savedir; xvt_fsys_get_dir(&savedir); // Salvo cartella corrente - - wxString path = fsp->dir.path; - wxString name = MakeFileName(fsp->name, fsp->type); - wxString extension = fsp->type; - wxString wild; - if (!extension.IsEmpty() && extension != "*") - wild << "File " << extension << " (*." << extension << ")|*." << extension << "|"; - if (flags & wxFD_OPEN) - wild << "Tutti i file (*.*)|*.*|"; - wild << '|'; - - wxString selectedname = wxFileSelector(msg, path, name, extension , wild, flags); - if (selectedname.IsEmpty()) - return FL_CANCEL; - xvt_fsys_convert_str_to_fspec(selectedname, fsp); - - xvt_fsys_set_dir(&savedir); // Ripristino cartella corrente - - return FL_OK; -} - -FL_STATUS xvt_dm_post_file_open(FILE_SPEC *fsp, const char *msg) -{ - const int flags = wxFD_OPEN | wxFD_FILE_MUST_EXIST; - return xvt_dm_post_file_ask(fsp, msg, flags); -} - -FL_STATUS xvt_dm_post_file_save(FILE_SPEC *fsp, const char *msg) -{ - const int flags = wxFD_SAVE | wxFD_OVERWRITE_PROMPT; - return xvt_dm_post_file_ask(fsp, msg, flags); -} - -FL_STATUS xvt_dm_post_dir_sel(DIRECTORY *dir) -{ - wxDirDialog dlg(_task_win); - dlg.SetPath(dir->path); - if (dlg.ShowModal() == wxID_OK) - { - xvt_fsys_convert_str_to_dir(dlg.GetPath(), dir); - return FL_OK; - } - return FL_CANCEL; -} - -BOOLEAN xvt_dm_post_font_sel(WINDOW win, XVT_FNTID font_id, PRINT_RCD* WXUNUSED(precp), unsigned long reserved) -{ - CAST_FONT(font_id, font); - wxFontData data; - data.SetInitialFont(font.Font(NULL, win)); - data.EnableEffects(reserved != 0); - wxFontDialog dlg(_task_win, data); - BOOLEAN ok = dlg.ShowModal() == wxID_OK; - if (ok) - { - font.Copy(dlg.GetFontData().GetChosenFont()); - if (win == (WINDOW)_task_win) - { - EVENT e; memset(&e, 0, sizeof(EVENT)); - e.type = E_FONT; - e.v.font.font_id = font_id; - _task_win_handler(win, &e); - } - } - return ok; -} - -void xvt_dm_post_message(const char *fmt) -{ - //_MessageBox(fmt, wxOK | wxCENTRE | wxICON_INFORMATION); - _PopUpBox(fmt, wxICON_INFORMATION, 0); -} - -void xvt_dm_post_note(const char *fmt) -{ - // _MessageBox(fmt, wxOK | wxCENTRE | wxICON_EXCLAMATION); - _PopUpBox(fmt, wxICON_EXCLAMATION, 0); -} - -char* xvt_dm_post_string_prompt(const char* message, char* response, int response_len) -{ - XVT_ASSERT(message && response && response_len > 0); - wxTextEntryDialog dlg(NULL, message, _GetAppTitle(), response); - if (dlg.ShowModal() == wxID_OK) - { - wxStrncpy(response, dlg.GetValue(), response_len); - response[response_len-1] = '\0'; - } - else - *response = '\0'; - return response; -} - -void xvt_dm_post_warning(const char *fmt) -{ - // _MessageBox(fmt, wxOK | wxCENTRE | wxICON_EXCLAMATION); - _PopUpBox(fmt, wxICON_EXCLAMATION, 0); -} - -void xvt_dm_popup_error(const char *fmt) -{ - _PopUpBox(fmt, wxICON_HAND); -} - -void xvt_dm_popup_message(const char *fmt) -{ - _PopUpBox(fmt, wxICON_INFORMATION); -} - -void xvt_dm_popup_warning(const char *fmt) -{ - _PopUpBox(fmt, wxICON_EXCLAMATION); -} - -/////////////////////////////////////////////////////////// -// Help system -/////////////////////////////////////////////////////////// - -struct XVAGA_HELP_INFO -{ - wxString m_strFilename; - bool m_hlp; -} help_info; - -XVT_HELP_INFO xvt_help_open_helpfile(FILE_SPEC* WXUNUSED(fs), unsigned long WXUNUSED(flags)) -{ - return (XVT_HELP_INFO)&help_info; -} - -void xvt_help_close_helpfile(XVT_HELP_INFO hi) -{ - if (hi == NULL_HELP_INFO) - hi = (XVT_HELP_INFO)&help_info; -} - -BOOLEAN xvt_help_process_event(XVT_HELP_INFO hi, WINDOW win, EVENT *ev) -{ - BOOLEAN bProcessed = FALSE; - -#ifdef WIN32 - WXHWND hwnd = (WXHWND)xvt_vobj_get_attr(win, ATTR_NATIVE_WINDOW); - switch (ev->type) - { - case E_COMMAND: - bProcessed = OsWin32_Help(hwnd, "", ev->v.cmd.tag, NULL); - break; - case E_HELP: - bProcessed = OsWin32_Help(hwnd, "", M_HELP_ONCONTEXT, (const char*)ev->v.help.tid); - break; - default: - break; - } -#endif // WIN32 - - return bProcessed; -} /////////////////////////////////////////////////////////// // Image handling @@ -4281,6 +3601,9 @@ long xvt_vobj_get_attr(WINDOW win, long data) ret = (long)xcc; } break; + case ATTR_APPL_VERSION_STRING: + ret = (long)(const char*)_appl_version; + break; case ATTR_FRAME_WIDTH: #ifdef LINUX ret = 8; //verificare not impl @@ -4355,7 +3678,7 @@ long xvt_vobj_get_attr(WINDOW win, long data) ret = 882L; // Scelta arbitraria ma accettabile break; case ATTR_SPEECH_MODE: - ret = m_nSpeechMode; + ret = xvt_dm_speech_enabled(); break; case ATTR_TASK_WINDOW: ret = long(_task_win); @@ -4564,13 +3887,14 @@ void xvt_vobj_set_attr(WINDOW win, long data, long value) tw->SetCtlColors((XVT_COLOR_COMPONENT*)value); } break; + case ATTR_APPL_VERSION_STRING: _appl_version = (const char*)value; break; case ATTR_BACK_COLOR: SetArtistColor(win, wxAUI_DOCKART_BACKGROUND_COLOUR, value); break; case ATTR_ERRMSG_HANDLER: _error_handler = (XVT_ERRMSG_HANDLER)value; break; case ATTR_EVENT_HOOK: SORRY_BOX(); break; // TBI?: Native events hook! case ATTR_WIN_PM_DRAWABLE_TWIN: break; // Ignored: Always TRUE case ATTR_WIN_PM_TWIN_STARTUP_RCT: _startup_rect = *(RCT*)value; break; case ATTR_WIN_PM_TWIN_STARTUP_STYLE: _startup_style = value; break; - case ATTR_SPEECH_MODE: xvt_dm_enable_speech(value); break; + case ATTR_SPEECH_MODE: xvt_dm_speech_enable(value); break; default: SORRY_BOX(); break; } } diff --git a/xvaga/xvt.h b/xvaga/xvt.h index c6cd35a8d..eff057ee9 100755 --- a/xvaga/xvt.h +++ b/xvaga/xvt.h @@ -88,6 +88,9 @@ XVTDLL char* xvt_dm_post_string_prompt(const char* message, char* respon XVTDLL void xvt_dm_post_warning(const char *fmt); XVTDLL BOOLEAN xvt_dm_post_speech(const char* text, int priority, BOOLEAN async); // 0 = Error, 1 = Warning, 2 Message, ... +XVTDLL void xvt_dm_speech_enable(int mode); +XVTDLL int xvt_dm_speech_enabled(void); + // Dongle support by AGA XVTDLL BOOLEAN xvt_dongle_hl_crypt(unsigned short* data); XVTDLL BOOLEAN xvt_dongle_hl_login(unsigned short address, const unsigned char* label, const unsigned char* password); @@ -246,14 +249,15 @@ XVTDLL void xvt_menu_update(WINDOW win); XVTDLL MENU_ITEM* xvt_menu_duplicate_tree(const MENU_ITEM* m); XVTDLL short xvt_notebk_add_page(WINDOW notebk, WINDOW page, const char* title, XVT_IMAGE img, short page_no); -XVTDLL WINDOW xvt_notebk_get_page(WINDOW notebk, short page_no); +XVTDLL short xvt_notebk_get_front_page(WINDOW notebk); XVTDLL short xvt_notebk_get_num_tabs(WINDOW notebk); +XVTDLL WINDOW xvt_notebk_get_page(WINDOW notebk, short page_no); +XVTDLL char* xvt_notebk_get_tab_title(WINDOW notebk, short page_no, char* title, int sz_title); 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); XVTDLL void xvt_notebk_rem_page(WINDOW notebk, short page_no); XVTDLL void xvt_notebk_rem_tab(WINDOW notebk, short tab_no); @@ -468,12 +472,15 @@ XVTDLL BOOLEAN xvt_odbc_free_connection(XVT_ODBC handle); XVTDLL ULONG xvt_odbc_execute(XVT_ODBC handle, const char* sql, ODBC_CALLBACK cb, void* jolly); XVTDLL BOOLEAN xvt_odbc_driver(XVT_ODBC handle, char* str, int max_size); +typedef BOOLEAN PROP_CALLBACK(WINDOW win, XVT_TREEVIEW_NODE node, void* app_data); XVTDLL XVT_TREEVIEW_NODE xvt_prop_add(WINDOW win, const char* type, const char* name, const char* value, const char* label); XVTDLL XVT_TREEVIEW_NODE xvt_prop_find(WINDOW win, const char* name); +XVTDLL BOOLEAN xvt_prop_for_each(WINDOW win, PROP_CALLBACK pcb, void* jolly); XVTDLL int xvt_prop_get_string(WINDOW win, XVT_TREEVIEW_NODE node, char* label, int maxlen); XVTDLL int xvt_prop_get_data(WINDOW win, XVT_TREEVIEW_NODE node, char* value, int maxlen); XVTDLL BOOLEAN xvt_prop_restart(WINDOW win); XVTDLL BOOLEAN xvt_prop_set_data(WINDOW win, XVT_TREEVIEW_NODE node, const char* value); +XVTDLL BOOLEAN xvt_prop_set_read_only(WINDOW win, XVT_TREEVIEW_NODE node, BOOLEAN ro); XVTDLL BOOLEAN xvt_prop_suspend(WINDOW win); XVTDLL BOOLEAN xvt_mail_send(const char* to, const char* cc, const char* ccn, diff --git a/xvaga/xvt_defs.h b/xvaga/xvt_defs.h index 322512da1..5f0161cd6 100755 --- a/xvaga/xvt_defs.h +++ b/xvaga/xvt_defs.h @@ -5,7 +5,7 @@ * Agreement with XVT Software. * * $RCSfile: xvt_defs.h,v $ - * $Revision: 1.10 $ + * $Revision: 1.11 $ * * Purpose: Global XVT macro definitions. * @@ -491,6 +491,7 @@ #define ATTR_R40_TXEDIT_BEHAVIOR (ATTR_BASE + 718) #define ATTR_APP_CTL_FONT_RID (ATTR_BASE + 719) #define ATTR_SPEECH_MODE (ATTR_BASE + 720) /* Added by Guy */ +#define ATTR_APPL_VERSION_STRING (ATTR_BASE + 721) /* Added by Guy */ /* Font attributes */ #define ATTR_FONT_MAPPER (ATTR_BASE + 800) diff --git a/xvaga/xvtctl.cpp b/xvaga/xvtctl.cpp index 1a45856df..f450b52fc 100755 --- a/xvaga/xvtctl.cpp +++ b/xvaga/xvtctl.cpp @@ -88,7 +88,7 @@ protected: virtual bool SetBackgroundColour(const wxColour& col); void OnPageChanging(wxAuiNotebookEvent& e); - //void OnPageChanged(wxAuiNotebookEvent& e); + void OnPageChanged(wxAuiNotebookEvent& e); long Flags2Style(long flags) const; TwxNoteBook() {} @@ -415,7 +415,7 @@ void xvt_btn_set_images(WINDOW win, XVT_IMAGE up, XVT_IMAGE down) if (pb != NULL) { int mx, my; pb->GetSize(&mx, &my); - wxBitmap bmpUp(Image2Bitmap(up, mx, my, TRUE)); + wxBitmap bmpUp = Image2Bitmap(up, mx, my, TRUE); if (bmpUp.Ok()) { pb->SetBitmapLabel(bmpUp); @@ -425,7 +425,7 @@ void xvt_btn_set_images(WINDOW win, XVT_IMAGE up, XVT_IMAGE down) } if (down != NULL) { - wxBitmap bmpDown(Image2Bitmap(down, mx, my, TRUE)); + wxBitmap bmpDown = Image2Bitmap(down, mx, my, TRUE); if (bmpDown.Ok()) pb->SetBitmapSelected(bmpDown); } @@ -621,8 +621,8 @@ inline bool VALID_NOTEBOOK(WINDOW notebk, short page_no) { return page_no >= 0 && wxDynamicCast((wxObject*)notebk, TwxNoteBook)!=NULL; } BEGIN_EVENT_TABLE(TwxNoteBook, wxAuiNotebook) - EVT_AUINOTEBOOK_PAGE_CHANGING(wxID_ANY, OnPageChanging) - //EVT_AUINOTEBOOK_PAGE_CHANGED(wxID_ANY, OnPageChanged) + EVT_AUINOTEBOOK_PAGE_CHANGING(wxID_ANY, TwxNoteBook::OnPageChanging) + EVT_AUINOTEBOOK_PAGE_CHANGED(wxID_ANY, TwxNoteBook::OnPageChanged) END_EVENT_TABLE(); bool TwxNoteBook::SetBackgroundColour(const wxColour& col) @@ -636,6 +636,7 @@ bool TwxNoteBook::SetBackgroundColour(const wxColour& col) } return ok; } + void TwxNoteBook::OnPageChanging(wxAuiNotebookEvent& evt) { if (!m_bSuspended) @@ -646,6 +647,7 @@ void TwxNoteBook::OnPageChanging(wxAuiNotebookEvent& evt) e.v.ctl.id = evt.GetId(); ci.type = WC_NOTEBK; ci.win = WINDOW(this); + // page == NULL_WIN -> changing page; page != NULL_WIN -> page changed. ci.v.notebk.page = NULL_WIN; ci.v.notebk.page_new = evt.GetSelection(); ci.v.notebk.page_old = evt.GetOldSelection(); @@ -653,15 +655,21 @@ void TwxNoteBook::OnPageChanging(wxAuiNotebookEvent& evt) TwxWindow* win = wxStaticCast(GetParent(), TwxWindow); const bool refused = win->DoXvtEvent(e) != 0; if (refused) - evt.Veto(); + evt.Veto(); // Vieta il passaggio alla pagina nuova + else + evt.Skip(); // Permette la notifica dell'evento PageChanged m_bSuspended = false; } } -/* void TwxNoteBook::OnPageChanged(wxAuiNotebookEvent& evt) { +#if !wxCHECK_VERSION(2,9,0) + // Nelle versioni vecchie mando la notifica solo al book in basso di ba0 + if (m_flags & wxAUI_NB_BOTTOM) +#endif + if (!m_bSuspended) { m_bSuspended = true; @@ -670,7 +678,8 @@ void TwxNoteBook::OnPageChanged(wxAuiNotebookEvent& evt) e.v.ctl.id = evt.GetId(); ci.type = WC_NOTEBK; ci.win = WINDOW(this); - ci.v.notebk.page = (WINDOW)GetPage(evt.GetSelection()); + // page == NULL_WIN -> changing page; page != NULL_WIN -> page changed. + ci.v.notebk.page = (WINDOW)GetPage(evt.GetSelection()); ci.v.notebk.page_new = evt.GetSelection(); ci.v.notebk.page_old = evt.GetOldSelection(); @@ -679,13 +688,10 @@ void TwxNoteBook::OnPageChanged(wxAuiNotebookEvent& evt) m_bSuspended = false; } } -*/ short TwxNoteBook::AddTab(wxWindow* pPage, const wxString text, XVT_IMAGE xvt_img, short idx) { - wxBitmap bmp; - if (xvt_img != NULL) - bmp = Image2Bitmap(xvt_img, BOOK_ICO_SIZE, BOOK_ICO_SIZE, TRUE); + wxBitmap bmp = Image2Bitmap(xvt_img, BOOK_ICO_SIZE, BOOK_ICO_SIZE, TRUE); if (idx < 0 || idx >= (int)GetPageCount()) { @@ -700,15 +706,8 @@ short TwxNoteBook::AddTab(wxWindow* pPage, const wxString text, XVT_IMAGE xvt_im void TwxNoteBook::SetTabImage(size_t idx, XVT_IMAGE img) { - if (img != NULL) - { - wxImage ico(*wxStaticCast(img, wxImage)); - ico.Rescale(BOOK_ICO_SIZE, BOOK_ICO_SIZE, wxIMAGE_QUALITY_HIGH); - const wxBitmap bmp(ico); - SetPageBitmap(idx, bmp); - } - else - SetPageBitmap(idx, wxNullBitmap); + wxBitmap bmp = Image2Bitmap(img, BOOK_ICO_SIZE, BOOK_ICO_SIZE, TRUE); + SetPageBitmap(idx, bmp); } int TwxNoteBook::ChangeSelection(size_t tab_no) @@ -834,6 +833,18 @@ void xvt_notebk_set_front_page(WINDOW notebk, short tab_no) } } +short xvt_notebk_get_front_page(WINDOW notebk) +{ + short idx = -1; + if (notebk != NULL_WIN) + { + CAST_NOTEBOOK(notebk, nb); + idx = nb.GetSelection(); + } + return idx; +} + + char* xvt_notebk_get_tab_title(WINDOW notebk, short tab_no, char* title, int sz_title) { if (VALID_NOTEBOOK(notebk, tab_no)) @@ -2363,3 +2374,38 @@ int xvt_prop_get_data(WINDOW win, XVT_TREEVIEW_NODE node, char* value, int maxle return len; } +static BOOLEAN xvt_for_each_property(WINDOW pg, const wxPGProperty* prop, PROP_CALLBACK pcb, void* jolly) +{ + BOOLEAN ok = prop != NULL && pcb != NULL; + if (ok && !prop->IsRoot()) + ok = pcb(pg, (XVT_TREEVIEW_NODE)prop, jolly); + if (ok) + { + const int nc = prop->GetChildCount(); + for (int c = 0; c < nc && ok; c++) + ok = xvt_for_each_property(pg, prop->Item(c), pcb, jolly); + } + return ok; +} + +BOOLEAN xvt_prop_for_each(WINDOW win, PROP_CALLBACK pcb, void* jolly) +{ + BOOLEAN ok = FALSE; + wxPropertyGrid* pg = wxDynamicCast((wxObject*)win, wxPropertyGrid); + if (pg != NULL) + ok = xvt_for_each_property(win, pg->GetRoot(), pcb, jolly); + return ok; +} + +BOOLEAN xvt_prop_set_read_only(WINDOW win, XVT_TREEVIEW_NODE node, BOOLEAN ro) +{ + wxPropertyGrid* pg = wxDynamicCast((wxObject*)win, wxPropertyGrid); + if (pg != NULL) + { + wxPGProperty* pgp = wxDynamicCast((wxObject*)node, wxPGProperty); + if (pgp == NULL) + pgp = pg->GetRoot(); + pgp->SetFlagRecursively(wxPG_PROP_DISABLED, ro != 0); + } + return pg != NULL; +} diff --git a/xvaga/xvtdm.cpp b/xvaga/xvtdm.cpp new file mode 100755 index 000000000..da4016dc6 --- /dev/null +++ b/xvaga/xvtdm.cpp @@ -0,0 +1,704 @@ +#include "wxinc.h" + +#include "xvt.h" +#include "xvtwin.h" + +#include +#include +#include +#include +#include + +/////////////////////////////////////////////////////////// +// TMessageBox +/////////////////////////////////////////////////////////// + +class TMessageBox : public wxDialog +{ + wxTimer m_timer; + +protected: + void OnButton(wxCommandEvent& evt); + void OnTimeout(wxTimerEvent& evt); + void AddButton(wxSizer* sz, int id, int ico); + DECLARE_EVENT_TABLE() + +public: + TMessageBox(wxWindow* pParent, const wxString& msg, int nStyle, int nTimeout = 0); +}; + +BEGIN_EVENT_TABLE(TMessageBox, wxDialog) + EVT_BUTTON(wxID_ANY, TMessageBox::OnButton) + EVT_TIMER(wxID_ANY, TMessageBox::OnTimeout) +END_EVENT_TABLE() + +void TMessageBox::OnButton(wxCommandEvent& evt) +{ + int ec = wxCANCEL; + switch (evt.GetId()) + { + case wxID_YES: ec = wxYES; break; + case wxID_OK : ec = wxOK; break; + case wxID_NO : ec = wxNO; break; + default : ec = GetEscapeId(); break; + } + EndModal(ec); +} + +void TMessageBox::OnTimeout(wxTimerEvent& WXUNUSED(evt)) +{ + wxWindowID id = GetEscapeId(); + if (id <= 0) + id = GetAffirmativeId(); + if (id > 0) + { + wxCommandEvent cmd(wxEVT_COMMAND_BUTTON_CLICKED, id); + AddPendingEvent(cmd); + } + else + EndModal(wxCANCEL); +} + +void TMessageBox::AddButton(wxSizer* sz, int id, int WXUNUSED(ico)) +{ + sz->Add(new wxButton(this, id, wxEmptyString, wxDefaultPosition, wxSize(80, 32)), 0, wxALL, 4); +} + +TMessageBox::TMessageBox(wxWindow* pParent, const wxString& msg, int nStyle, int nTimeout) + : wxDialog(pParent, wxID_ANY, _GetAppTitle(), wxDefaultPosition, wxDefaultSize, + wxCAPTION | wxRAISED_BORDER), m_timer(this) +{ + TTaskWin* tw = wxDynamicCast(pParent ? pParent : _task_win, TTaskWin); + if (tw != NULL) + { + const COLOR col = tw->GetCtlColor(XVT_COLOR_BACKGROUND); + if (col != COLOR_INVALID) + { + CAST_COLOR(col, rgb); + SetOwnBackgroundColour(rgb); + } + } + + wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL); + + wxBoxSizer* sz1 = new wxBoxSizer(wxHORIZONTAL); + sizer->Add(sz1); + + wxArtID nIco = wxART_INFORMATION; + if (nStyle & wxICON_HAND) nIco = wxART_ERROR; else + if (nStyle & wxICON_INFORMATION) nIco = wxART_INFORMATION; else + if (nStyle & wxICON_EXCLAMATION) nIco = wxART_WARNING; else + if (nStyle & wxICON_QUESTION) nIco = wxART_QUESTION; else + if (nStyle & 0x1000) nIco = "220"; + + const wxBitmap img = wxArtProvider::GetBitmap(nIco, wxART_MESSAGE_BOX, wxSize(64,64)); + + const int nBorder = 8; + sz1->Add(new wxStaticBitmap(this, wxID_ANY, img), 0, wxALL, nBorder); + wxStaticText* ss = new wxStaticText(this, wxID_ANY, wxEmptyString); + ss->Wrap(160); + ss->SetLabel(msg); + sz1->Add(ss, 0, wxALL|wxALIGN_CENTER|wxALIGN_CENTER_VERTICAL, nBorder); + + sizer->Add(new wxStaticLine(this), 0, wxALL|wxEXPAND, nBorder); + + wxBoxSizer* sz2 = new wxBoxSizer(wxHORIZONTAL); + sizer->Add(sz2, 0, wxALIGN_CENTER); + if (nStyle & wxYES_NO) + { + if (nStyle & wxNO_DEFAULT) + { + SetAffirmativeId(wxID_NO); + SetEscapeId(wxID_YES); + AddButton(sz2, wxID_NO, 102); + AddButton(sz2, wxID_YES, 101); + } + else + { + SetAffirmativeId(wxID_YES); + SetEscapeId(wxID_NO); + AddButton(sz2, wxID_YES, 101); + AddButton(sz2, wxID_NO, 102); + } + } + if (nStyle & wxOK) + { + SetAffirmativeId(wxID_OK); + AddButton(sz2, wxID_OK, 101); + } + if (nStyle & wxCANCEL) + { + SetEscapeId(wxID_CANCEL); + AddButton(sz2, wxID_CANCEL, 102); + } + + SetSizerAndFit(sizer); + + if (nStyle & wxCENTRE) + Centre(); + + if (nTimeout > 0) + m_timer.Start(1000*nTimeout, true); +} + +/////////////////////////////////////////////////////////// +// _*Box +/////////////////////////////////////////////////////////// + +int _MessageBox(const wxString& msg, int nStyle, int nTimeout = 0) +{ + xvt_dm_post_speech(msg, 1, TRUE); + + TMessageBox dlg(NULL, msg, nStyle, nTimeout); + const int ret = dlg.ShowModal(); + + switch(ret) + { + case wxOK : xvt_dm_post_speech(_("ok"), 7, TRUE); break; + case wxYES: xvt_dm_post_speech(_("si"), 7, TRUE); break; + case wxNO : xvt_dm_post_speech(_("no"), 7, TRUE); break; + default : xvt_dm_post_speech(_("annulla"), 7, TRUE); break; + } + return ret; +} + +/////////////////////////////////////////////////////////// +// _PopUpBox +/////////////////////////////////////////////////////////// + +class TPopUpBox : public wxDialog +{ + DECLARE_EVENT_TABLE(); + wxTimer m_Timer; + int m_nStep, m_nTimeout; + +protected: + void OnTimer(wxTimerEvent& evt); + void OnChar(wxKeyEvent& evt); + void OnClick(wxMouseEvent& evt); + +public: + TPopUpBox(wxWindow* pParent, const wxString& msg, int nStyle, int nTimeout); +}; + +BEGIN_EVENT_TABLE(TPopUpBox, wxDialog) + EVT_TIMER(wxID_ANY, TPopUpBox::OnTimer) + EVT_CHAR(TPopUpBox::OnChar) + EVT_LEFT_DOWN(TPopUpBox::OnClick) +END_EVENT_TABLE() + +void TPopUpBox::OnChar(wxKeyEvent& WXUNUSED(evt)) +{ + if (IsShown()) + { + m_Timer.Stop(); + EndModal(wxID_CANCEL); + } +} + +void TPopUpBox::OnClick(wxMouseEvent& WXUNUSED(evt)) +{ + if (IsShown()) + { + m_Timer.Stop(); + EndModal(wxID_CANCEL); + } +} + + +void TPopUpBox::OnTimer(wxTimerEvent& WXUNUSED(evt)) +{ + if (IsShown()) + { + const wxRect rctMain = GetParent()->GetRect(); + const wxRect rctMine = GetRect(); + const int msec = (m_nStep++)*m_Timer.GetInterval(); + if (msec <= m_nTimeout/4) + { + const double perc = double(msec)/(m_nTimeout/4); + Move(rctMain.x, rctMain.GetBottom() - rctMine.height * perc); + } + if (msec >= 3*m_nTimeout/4 && msec <= m_nTimeout) + { + const double perc = double(m_nTimeout-msec)/(m_nTimeout/4); + Move(rctMain.x, rctMain.GetBottom() - rctMine.height * perc); + } + if (msec > m_nTimeout) + { + m_Timer.Stop(); + EndModal(wxID_CANCEL); + } + } +} + +TPopUpBox::TPopUpBox(wxWindow* pParent, const wxString& msg, int nStyle, int nTimeout) + : wxDialog(pParent, wxID_ANY, wxEmptyString, wxPoint(0,2024), wxDefaultSize, wxBORDER_SIMPLE), + m_nTimeout(nTimeout*1000), m_Timer(this), m_nStep(0) +{ + TTaskWin* tw = wxDynamicCast(pParent ? pParent : _task_win, TTaskWin); + if (tw != NULL) + { + const COLOR col = tw->GetCtlColor(XVT_COLOR_BACKGROUND); + if (col != COLOR_INVALID) + { + CAST_COLOR(col, rgb); + SetOwnBackgroundColour(rgb); + } + } + + wxBoxSizer* sz = new wxBoxSizer(wxHORIZONTAL); + + wxArtID nIco = wxART_ERROR; + if (nStyle & wxICON_HAND) nIco = wxART_ERROR; else + if (nStyle & wxICON_INFORMATION) nIco = wxART_INFORMATION; else + if (nStyle & wxICON_EXCLAMATION) nIco = wxART_WARNING; else + if (nStyle & 0x1000) nIco = "220"; + const wxBitmap img = wxArtProvider::GetBitmap(nIco, wxART_MESSAGE_BOX); + + wxStaticBitmap* bmp = new wxStaticBitmap(this, wxID_ANY, img); + sz->Add(bmp, 0, wxALL, 8); + + wxStaticText* ss = new wxStaticText(this, wxID_ANY, wxEmptyString); + ss->Wrap(160); + ss->SetLabel(msg); + sz->Add(ss, 0, wxALL | wxALIGN_CENTER | wxALIGN_CENTER_VERTICAL, 8); + + SetSizerAndFit(sz); + m_Timer.Start(25); +} + +static void _PopUpBox(const wxString& msg, int nStyle, int nTimeout = 4) +{ + const int oem = xvt_sys_get_oem_int("OEM", -1); + wxWindow* pFrame = wxTheApp->GetTopWindow(); + if (oem == 0 && pFrame != NULL) + { + xvt_sys_beep(nStyle & wxICON_ERROR ? 2 : 1); + TPopUpBox dlg(pFrame, msg, nStyle, nTimeout <= 0 ? 4 : nTimeout); + dlg.ShowModal(); + } + else + _MessageBox(msg, nStyle|wxOK|wxCENTRE, nTimeout); +} + +WX_DECLARE_STRING_HASH_MAP(int, TMessagesMap); + +void xvt_sys_sorry_box(const char* func, const char* file, int line) +{ +#ifndef NDEBUG + static TMessagesMap sorry; + if (sorry[func]++ == 0) + { + wxString strMessage; + strMessage.Printf("Function %s in file %s at line %d\nis not implemented yet: be patient...", + func, file, line); + _PopUpBox(strMessage, 0x1000); // Smiley Icon + } +#endif +} + +void xvt_sys_deprecated_box(const char* oldfunc, const char* file, const char* newfunc) +{ +#ifndef NDEBUG + static TMessagesMap deprecated; + if (deprecated[oldfunc]++ == 0) + { + wxString strMessage; + strMessage.Printf("Function %s in file %s is deprecated:\n%s is much more trendy now!\nYou can blame Guy for this, if you're bold enough!", + oldfunc, file, newfunc); + _PopUpBox(strMessage, 0x1000); + } +#endif +} + +/////////////////////////////////////////////////////////// +// Speech support +/////////////////////////////////////////////////////////// + +// 0 Errors +// 1 Warnings +// 2 Messages +// 3 Requests +// 7 Buttons +static int m_nSpeechMode = 0; + +void xvt_dm_speech_enable(int mode) +{ +#ifdef SPEECH_API + m_nSpeechMode = mode; +#ifdef WIN32 + if (m_nSpeechMode != 0) + { + if (!OsWin32_InitializeSpeech()) + m_nSpeechMode = 0; + } + else + { + OsWin32_DeinitializeSpeech(); + } +#endif +#endif +} + +int xvt_dm_speech_enabled(void) +{ + return m_nSpeechMode; +} + +/////////////////////////////////////////////////////////// +// Common dialogs +/////////////////////////////////////////////////////////// + +void xvt_dm_post_about_box() +{ + const char* ver = (const char*)xvt_vobj_get_attr(NULL_WIN, ATTR_APPL_VERSION_STRING); + if (ver == NULL || !*ver) ver = "2010 10.0/900"; + wxString msg; msg << "Versione " << ver; + xvt_dm_post_message(msg); +} + +COLOR xvt_dm_post_choose_color(WINDOW win, COLOR xc) +{ + DEPRECATED_BOX("xvt_dm_post_color_sel"); + if (!xvt_dm_post_color_sel(&xc, win)) + xc = COLOR_INVALID; + return xc; +} + +BOOLEAN xvt_dm_post_color_sel(COLOR* color, unsigned long reserved) +{ + CAST_COLOR(*color, wc); + + wxColourData cd; + cd.SetChooseFull(true); + cd.SetColour(wc); + for (int i = 0; i < 16; i++) + { + const unsigned char val = (i & 0x8) ? 255 : 127; + const unsigned char red = (i & 0x1) ? val : 0; + const unsigned char green = (i & 0x2) ? val : 0; + const unsigned char blue = (i & 0x4) ? val : 0; + wxColour col(red, green, blue); + cd.SetCustomColour(i, col); + } + + wxWindow* win = wxDynamicCast ((void*)reserved, wxWindow); + wxColourDialog dialog(win, &cd); + if (dialog.ShowModal() == wxID_OK) + { + *color = MAKE_XVT_COLOR(dialog.GetColourData().GetColour()); + if (*color == 0) *color = COLOR_BLACK; // 0x000000 confonde XI, mentre con 0x07000000 e' a suo agio + return TRUE; + } + + return FALSE; +} + +class TwxCalendarDlg : public wxDialog +{ + enum { ID_CAL = 1883 }; + wxDateTime& m_date; + wxCalendarCtrl* m_cal; + +protected: + virtual bool TransferDataFromWindow(); + void OnCalendar(wxCalendarEvent& e); + +public: + TwxCalendarDlg(wxWindow* parent, wxDateTime& date); + + DECLARE_EVENT_TABLE() +}; + +BEGIN_EVENT_TABLE(TwxCalendarDlg, wxDialog) + EVT_CALENDAR(wxID_ANY, TwxCalendarDlg::OnCalendar) +END_EVENT_TABLE() + +void TwxCalendarDlg::OnCalendar(wxCalendarEvent& WXUNUSED(e)) +{ + wxCommandEvent evt(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK); + AddPendingEvent(evt); +} + +bool TwxCalendarDlg::TransferDataFromWindow() +{ + bool ok = wxDialog::TransferDataFromWindow(); + if (ok) + m_date = m_cal->GetDate(); + return ok; +} + +TwxCalendarDlg::TwxCalendarDlg(wxWindow* parent, wxDateTime& date) + : wxDialog(parent, wxID_ANY, "Data", wxDefaultPosition, wxDefaultSize, wxRAISED_BORDER), m_date(date) +{ + + m_cal = new wxCalendarCtrl(this, ID_CAL, m_date, wxDefaultPosition, wxDefaultSize, + wxCAL_MONDAY_FIRST | wxCAL_SHOW_HOLIDAYS | wxCAL_SHOW_SURROUNDING_WEEKS); + + wxButton* button = new wxButton(this, wxID_OK, "OK"); + + wxGridSizer* sizer = new wxFlexGridSizer(2, 1, 8, 8); + sizer->Add(m_cal, 0, wxALIGN_CENTER); + sizer->Add(button, 0, wxALIGN_CENTER); + SetSizer(sizer); + sizer->SetSizeHints(this); +} + +unsigned int xvt_dm_post_choose_date(WINDOW win, const RCT* rct, unsigned int ansidate) +{ + int d = ansidate%100; + int m = (ansidate/100)%100; + int y = ansidate / 10000; + + wxDateTime date; + if (d >= 1 && d <= 31 && m >= 1 && m <= 12 && y > 1900) + date.Set(d, wxDateTime::Month(m-1), y); + else + date = wxDateTime::Today(); + + CAST_WIN(win, w); + wxDialog* dlg = new TwxCalendarDlg(&w, date); + + if (rct != NULL) + { + const wxRect client = w.GetClientRect(); + const wxRect rect = dlg->GetRect(); + wxPoint pos(rct->right - rect.width, rct->bottom); + if (pos.x < 0) + pos.x = rct->left; + if (rct->bottom + rect.height > client.GetBottom()) + pos.y = rct->top - rect.height; + dlg->Move(w.ClientToScreen(pos)); + } + + if (dlg->ShowModal() == wxID_OK) + { + d = date.GetDay(); + m = date.GetMonth()+1; + y = date.GetYear(); + ansidate = y*10000 + m*100 + d; + } + dlg->Destroy(); + + return ansidate; +} + +BOOLEAN xvt_dm_post_speech(const char* text, int priority, BOOLEAN async) +{ + BOOLEAN ok = FALSE; +#ifdef SPEECH_API + if ((m_nSpeechMode & (1 << priority)) != 0) + { +#ifdef WIN32 + ok = OsWin32_Speak(text, async != 0); +#endif + } +#endif + return ok; +} + +ASK_RESPONSE xvt_dm_post_ask(const char* Btn1, const char* Btn2, const char* Btn3, const char* fmt) +{ + int nFlags = wxCENTRE | wxICON_QUESTION | wxYES_NO; + if (Btn3 == NULL) + { + if (wxStricmp(Btn1, "no") == 0) + nFlags |= wxNO_DEFAULT; + } + else + nFlags |= wxCANCEL; + + const int answer = _MessageBox(fmt, nFlags); + return answer == wxYES ? RESP_DEFAULT : (answer == wxNO ? RESP_2 : RESP_3); +} + +void xvt_dm_post_error(const char *fmt) +{ + //_MessageBox(fmt, wxOK | wxCENTRE | wxICON_HAND); + _PopUpBox(fmt, wxICON_HAND, 0); +} + +void xvt_dm_post_fatal_exit(const char *fmt) +{ + xvt_dm_post_speech(fmt, 1, TRUE); + wxLogFatalError(fmt); + xvt_dm_post_speech("OK", 7, TRUE); +} + +static wxString MakeFileName(const wxChar* name, const wxChar* ext) +{ + wxString f = name; + if (ext && *ext) + { + if (*ext != '.') + f += '.'; + f += ext; + } + return f; +} + +static FL_STATUS xvt_dm_post_file_ask(FILE_SPEC *fsp, const char *msg, int flags) +{ + DIRECTORY savedir; xvt_fsys_get_dir(&savedir); // Salvo cartella corrente + + wxString path = fsp->dir.path; + wxString name = MakeFileName(fsp->name, fsp->type); + wxString extension = fsp->type; + wxString wild; + if (!extension.IsEmpty() && extension != "*") + wild << "File " << extension << " (*." << extension << ")|*." << extension << "|"; + if (flags & wxFD_OPEN) + wild << "Tutti i file (*.*)|*.*|"; + wild << '|'; + + wxString selectedname = wxFileSelector(msg, path, name, extension , wild, flags); + if (selectedname.IsEmpty()) + return FL_CANCEL; + xvt_fsys_convert_str_to_fspec(selectedname, fsp); + + xvt_fsys_set_dir(&savedir); // Ripristino cartella corrente + + return FL_OK; +} + +FL_STATUS xvt_dm_post_file_open(FILE_SPEC *fsp, const char *msg) +{ + const int flags = wxFD_OPEN | wxFD_FILE_MUST_EXIST; + return xvt_dm_post_file_ask(fsp, msg, flags); +} + +FL_STATUS xvt_dm_post_file_save(FILE_SPEC *fsp, const char *msg) +{ + const int flags = wxFD_SAVE | wxFD_OVERWRITE_PROMPT; + return xvt_dm_post_file_ask(fsp, msg, flags); +} + +FL_STATUS xvt_dm_post_dir_sel(DIRECTORY *dir) +{ + wxDirDialog dlg(_task_win); + dlg.SetPath(dir->path); + if (dlg.ShowModal() == wxID_OK) + { + xvt_fsys_convert_str_to_dir(dlg.GetPath(), dir); + return FL_OK; + } + return FL_CANCEL; +} + +BOOLEAN xvt_dm_post_font_sel(WINDOW win, XVT_FNTID font_id, PRINT_RCD* WXUNUSED(precp), unsigned long reserved) +{ + CAST_FONT(font_id, font); + wxFontData data; + data.SetInitialFont(font.Font(NULL, win)); + data.EnableEffects(reserved != 0); + wxFontDialog dlg(_task_win, data); + BOOLEAN ok = dlg.ShowModal() == wxID_OK; + if (ok) + { + font.Copy(dlg.GetFontData().GetChosenFont()); + if (win == (WINDOW)_task_win) + { + EVENT e; memset(&e, 0, sizeof(EVENT)); + e.type = E_FONT; + e.v.font.font_id = font_id; + _task_win_handler(win, &e); + } + } + return ok; +} + +void xvt_dm_post_message(const char *fmt) +{ + //_MessageBox(fmt, wxOK | wxCENTRE | wxICON_INFORMATION); + _PopUpBox(fmt, wxICON_INFORMATION, 0); +} + +void xvt_dm_post_note(const char *fmt) +{ + // _MessageBox(fmt, wxOK | wxCENTRE | wxICON_EXCLAMATION); + _PopUpBox(fmt, wxICON_EXCLAMATION, 0); +} + +char* xvt_dm_post_string_prompt(const char* message, char* response, int response_len) +{ + if (message && response && response_len > 0) + { + wxTextEntryDialog dlg(NULL, message, _GetAppTitle(), response); + if (dlg.ShowModal() == wxID_OK) + { + wxStrncpy(response, dlg.GetValue(), response_len); + response[response_len-1] = '\0'; + } + else + *response = '\0'; + } + return response; +} + +void xvt_dm_post_warning(const char *fmt) +{ + // _MessageBox(fmt, wxOK | wxCENTRE | wxICON_EXCLAMATION); + _PopUpBox(fmt, wxICON_EXCLAMATION, 0); +} + +void xvt_dm_popup_error(const char *fmt) +{ + _PopUpBox(fmt, wxICON_HAND); +} + +void xvt_dm_popup_message(const char *fmt) +{ + _PopUpBox(fmt, wxICON_INFORMATION); +} + +void xvt_dm_popup_warning(const char *fmt) +{ + _PopUpBox(fmt, wxICON_EXCLAMATION); +} + +/////////////////////////////////////////////////////////// +// Help system +/////////////////////////////////////////////////////////// + +#ifdef __WXMSW__ +#include "OsWin32.h" +#endif + +struct XVAGA_HELP_INFO +{ + wxString m_strFilename; + bool m_hlp; +} help_info; + +XVT_HELP_INFO xvt_help_open_helpfile(FILE_SPEC* WXUNUSED(fs), unsigned long WXUNUSED(flags)) +{ + return (XVT_HELP_INFO)&help_info; +} + +void xvt_help_close_helpfile(XVT_HELP_INFO hi) +{ + if (hi == NULL_HELP_INFO) + hi = (XVT_HELP_INFO)&help_info; +} + +BOOLEAN xvt_help_process_event(XVT_HELP_INFO hi, WINDOW win, EVENT *ev) +{ + BOOLEAN bProcessed = FALSE; + +#ifdef __WXMSW__ + WXHWND hwnd = (WXHWND)xvt_vobj_get_attr(win, ATTR_NATIVE_WINDOW); + switch (ev->type) + { + case E_COMMAND: + bProcessed = OsWin32_Help(hwnd, "", ev->v.cmd.tag, NULL); + break; + case E_HELP: + bProcessed = OsWin32_Help(hwnd, "", M_HELP_ONCONTEXT, (const char*)ev->v.help.tid); + break; + default: + break; + } +#endif // WIN32 + + return bProcessed; +} diff --git a/xvaga/xvtwin.h b/xvaga/xvtwin.h index b817fd944..bec8196d4 100755 --- a/xvaga/xvtwin.h +++ b/xvaga/xvtwin.h @@ -231,6 +231,12 @@ struct XVT_EVENT : public EVENT #define TIMER_ID 1 const wxString& _GetAppTitle(); +#define CAST_WIN(win,w) wxWindow& w = *wxStaticCast((wxObject*)win, wxWindow); +#define CAST_TWIN(win,w) TwxWindow& w = *wxStaticCast((wxObject*)win, TwxWindow); +#define CAST_TDC(win,dc) TDC& dc = GetTDCMapper().GetTDC(win); +#define CAST_DC(win,dc) wxDC& dc = GetTDCMapper().GetDC(win); +#define CAST_FONT(font_id, font) TFontId& font = *wxStaticCast(font_id, TFontId); + #define CAST_COLOR(xc, wc) wxColour wc((xc>>16)&0xFF, (xc>>8)&0xFF, xc&0xFF) #define MAKE_XVT_COLOR(wc) XVT_MAKE_COLOR(wc.Red(), wc.Green(), wc.Blue()) wxRect NormalizeRCT(const RCT* prct);