2010-05-11 19:10:29 +00:00
|
|
|
// This file is part of BOINC.
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2008 University of California
|
|
|
|
//
|
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//
|
|
|
|
#if defined(__GNUG__) && !defined(__APPLE__)
|
2010-06-23 16:59:35 +00:00
|
|
|
#pragma implementation "NoticeListCtrl.h"
|
2010-05-11 19:10:29 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "stdwx.h"
|
2010-06-23 16:59:35 +00:00
|
|
|
#include "Events.h"
|
2010-05-11 19:10:29 +00:00
|
|
|
#include "BOINCGUIApp.h"
|
2010-06-30 18:52:20 +00:00
|
|
|
#include "MainDocument.h"
|
2010-06-23 16:59:35 +00:00
|
|
|
#include "NoticeListCtrl.h"
|
2010-05-11 19:10:29 +00:00
|
|
|
|
|
|
|
////@begin XPM images
|
|
|
|
////@end XPM images
|
|
|
|
|
2010-07-09 10:18:48 +00:00
|
|
|
#if wxUSE_ACCESSIBILITY || defined(__WXMAC__)
|
|
|
|
|
2010-05-11 19:10:29 +00:00
|
|
|
#ifdef __WXMAC__
|
|
|
|
|
2010-06-23 16:59:35 +00:00
|
|
|
CNoticeListCtrlAccessible::CNoticeListCtrlAccessible(wxWindow* win) {
|
2010-05-11 19:10:29 +00:00
|
|
|
mp_win = win;
|
|
|
|
SetupMacAccessibilitySupport();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-23 16:59:35 +00:00
|
|
|
CNoticeListCtrlAccessible::~CNoticeListCtrlAccessible() {
|
2010-05-11 19:10:29 +00:00
|
|
|
RemoveMacAccessibilitySupport();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Gets the name of the specified object.
|
2010-10-29 18:58:26 +00:00
|
|
|
wxAccStatus CNoticeListCtrlAccessible::GetName(int childId, wxString* name) {
|
2010-06-30 18:52:20 +00:00
|
|
|
static wxString strBuffer;
|
|
|
|
|
2010-10-29 18:58:26 +00:00
|
|
|
if (childId == wxACC_SELF) {
|
2010-06-23 21:44:31 +00:00
|
|
|
*name = _("Notice List");
|
2010-10-29 18:58:26 +00:00
|
|
|
} else {
|
2010-06-30 18:52:20 +00:00
|
|
|
CMainDocument* pDoc = wxDynamicCast(wxGetApp().GetDocument(), CMainDocument);
|
|
|
|
strBuffer = wxEmptyString;
|
|
|
|
|
2010-10-29 18:58:26 +00:00
|
|
|
if (pDoc) {
|
2010-07-23 22:57:54 +00:00
|
|
|
strBuffer = wxString(pDoc->notice(childId-1)->title, wxConvUTF8);
|
2010-07-23 23:42:25 +00:00
|
|
|
pDoc->LocalizeNoticeText(strBuffer, true);
|
2010-07-08 11:55:43 +00:00
|
|
|
strBuffer = StripHTMLTags(strBuffer);
|
2010-06-30 18:52:20 +00:00
|
|
|
*name = strBuffer.c_str();
|
2010-05-11 19:10:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return wxACC_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Can return either a child object, or an integer
|
|
|
|
// representing the child element, starting from 1.
|
2010-10-29 18:58:26 +00:00
|
|
|
wxAccStatus CNoticeListCtrlAccessible::HitTest(const wxPoint& pt, int* childId, wxAccessible** /*childObject*/) {
|
2010-06-23 16:59:35 +00:00
|
|
|
CNoticeListCtrl* pCtrl = wxDynamicCast(GetWindow(), CNoticeListCtrl);
|
2010-10-29 18:58:26 +00:00
|
|
|
if (pCtrl) {
|
2010-05-11 19:10:29 +00:00
|
|
|
*childId = pCtrl->HitTest(pt);
|
|
|
|
return wxACC_OK;
|
|
|
|
}
|
|
|
|
// Let the framework handle the other cases.
|
|
|
|
return wxACC_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Returns the rectangle for this object (id = 0) or a child element (id > 0).
|
2010-10-29 18:58:26 +00:00
|
|
|
wxAccStatus CNoticeListCtrlAccessible::GetLocation(wxRect& rect, int elementId) {
|
2010-06-23 16:59:35 +00:00
|
|
|
CNoticeListCtrl* pCtrl = wxDynamicCast(GetWindow(), CNoticeListCtrl);
|
2010-10-29 18:58:26 +00:00
|
|
|
if (pCtrl && (0 == elementId)) {
|
2010-05-11 19:10:29 +00:00
|
|
|
// List control
|
|
|
|
rect.SetPosition(pCtrl->GetScreenPosition());
|
|
|
|
rect.SetWidth(pCtrl->GetSize().GetWidth());
|
|
|
|
rect.SetHeight(pCtrl->GetSize().GetHeight());
|
|
|
|
return wxACC_OK;
|
2010-10-29 18:58:26 +00:00
|
|
|
} else if (pCtrl && (0 != elementId)) {
|
2010-08-15 14:17:01 +00:00
|
|
|
pCtrl->GetItemRect(elementId - 1, rect);
|
|
|
|
pCtrl->ClientToScreen(&rect.x, &rect.y);
|
2010-05-11 19:10:29 +00:00
|
|
|
|
|
|
|
return wxACC_OK;
|
|
|
|
}
|
|
|
|
// Let the framework handle the other cases.
|
|
|
|
return wxACC_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Gets the number of children.
|
2010-10-29 18:58:26 +00:00
|
|
|
wxAccStatus CNoticeListCtrlAccessible::GetChildCount(int* childCount) {
|
2010-06-23 16:59:35 +00:00
|
|
|
CNoticeListCtrl* pCtrl = wxDynamicCast(GetWindow(), CNoticeListCtrl);
|
2010-10-29 18:58:26 +00:00
|
|
|
if (pCtrl) {
|
2010-05-11 19:10:29 +00:00
|
|
|
*childCount = (int)pCtrl->GetItemCount();
|
|
|
|
return wxACC_OK;
|
|
|
|
}
|
|
|
|
// Let the framework handle the other cases.
|
|
|
|
return wxACC_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Performs the default action. childId is 0 (the action for this object)
|
|
|
|
// or > 0 (the action for a child).
|
|
|
|
// Return wxACC_NOT_SUPPORTED if there is no default action for this
|
|
|
|
// window (e.g. an edit control).
|
2010-10-29 18:58:26 +00:00
|
|
|
wxAccStatus CNoticeListCtrlAccessible::DoDefaultAction(int childId) {
|
2010-08-15 14:17:01 +00:00
|
|
|
#if ALLOW_NOTICES_SELECTION
|
|
|
|
|
2010-06-23 16:59:35 +00:00
|
|
|
CNoticeListCtrl* pCtrl = wxDynamicCast(GetWindow(), CNoticeListCtrl);
|
2010-06-30 18:52:20 +00:00
|
|
|
CMainDocument* pDoc = wxDynamicCast(wxGetApp().GetDocument(), CMainDocument);
|
2010-10-29 18:58:26 +00:00
|
|
|
if (pCtrl && (childId != wxACC_SELF)) {
|
2010-05-11 19:10:29 +00:00
|
|
|
// Zero-based array index
|
|
|
|
int iRealChildId = childId - 1;
|
|
|
|
|
|
|
|
pCtrl->SetSelection(iRealChildId);
|
|
|
|
|
|
|
|
// Fire Event
|
2010-06-23 16:59:35 +00:00
|
|
|
NoticeListCtrlEvent evt(
|
|
|
|
wxEVT_NOTICELIST_ITEM_CHANGE,
|
2010-06-30 18:52:20 +00:00
|
|
|
pDoc->notice(iRealChildId)->seqno,
|
|
|
|
wxString(pDoc->notice(iRealChildId)->link, wxConvUTF8)
|
2010-05-11 19:10:29 +00:00
|
|
|
);
|
|
|
|
#ifdef __WXMAC__
|
|
|
|
evt.SetEventObject(pCtrl);
|
|
|
|
#else
|
|
|
|
evt.SetEventObject(this);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
pCtrl->GetParent()->AddPendingEvent( evt );
|
|
|
|
|
|
|
|
return wxACC_OK;
|
|
|
|
}
|
2010-08-15 14:17:01 +00:00
|
|
|
|
|
|
|
#endif // ALLOW_NOTICES_SELECTION
|
2010-06-23 16:59:35 +00:00
|
|
|
|
2010-05-11 19:10:29 +00:00
|
|
|
// Let the framework handle the other cases.
|
|
|
|
return wxACC_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the description for this object or a child.
|
2010-10-29 18:58:26 +00:00
|
|
|
wxAccStatus CNoticeListCtrlAccessible::GetDescription(int childId, wxString* description) {
|
2010-06-30 18:52:20 +00:00
|
|
|
CMainDocument* pDoc = wxGetApp().GetDocument();
|
|
|
|
static wxString strBuffer;
|
2010-07-08 11:55:43 +00:00
|
|
|
wxDateTime dtBuffer;
|
2010-07-23 22:57:54 +00:00
|
|
|
wxString strDescription = wxEmptyString;
|
2010-07-08 11:55:43 +00:00
|
|
|
wxString strProjectName = wxEmptyString;
|
|
|
|
wxString strArrivalTime = wxEmptyString;
|
2010-06-30 18:52:20 +00:00
|
|
|
|
2010-07-20 23:13:26 +00:00
|
|
|
if (pDoc && (childId != wxACC_SELF)) {
|
2010-06-30 18:52:20 +00:00
|
|
|
strBuffer = wxEmptyString;
|
2010-07-20 23:13:26 +00:00
|
|
|
|
|
|
|
strProjectName = wxString(pDoc->notice(childId-1)->project_name, wxConvUTF8);
|
2010-07-23 22:57:54 +00:00
|
|
|
|
|
|
|
strDescription = wxString(pDoc->notice(childId-1)->description.c_str(), wxConvUTF8);
|
2010-07-23 23:42:25 +00:00
|
|
|
pDoc->LocalizeNoticeText(strDescription, true);
|
2010-07-23 22:57:54 +00:00
|
|
|
|
2010-07-20 23:13:26 +00:00
|
|
|
dtBuffer.Set((time_t)pDoc->notice(childId-1)->arrival_time);
|
|
|
|
strArrivalTime = dtBuffer.Format();
|
2010-07-23 22:57:54 +00:00
|
|
|
|
2010-07-20 23:13:26 +00:00
|
|
|
if (strProjectName.IsEmpty()) {
|
|
|
|
strBuffer.Printf(_("%s; received on %s"), strDescription.c_str(), strArrivalTime.c_str());
|
|
|
|
} else {
|
|
|
|
strBuffer.Printf(_("%s; received from %s; on %s"), strDescription.c_str(), strProjectName.c_str(), strArrivalTime.c_str());
|
2010-06-30 18:52:20 +00:00
|
|
|
}
|
2010-07-20 23:13:26 +00:00
|
|
|
|
|
|
|
strBuffer = StripHTMLTags(strBuffer);
|
|
|
|
*description = strBuffer.c_str();
|
|
|
|
|
|
|
|
return wxACC_OK;
|
2010-05-11 19:10:29 +00:00
|
|
|
}
|
2010-06-30 18:52:20 +00:00
|
|
|
|
2010-05-11 19:10:29 +00:00
|
|
|
// Let the framework handle the other cases.
|
|
|
|
return wxACC_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-08 11:55:43 +00:00
|
|
|
wxString CNoticeListCtrlAccessible::StripHTMLTags(wxString inBuf) {
|
|
|
|
wxString outBuf = wxEmptyString;
|
|
|
|
wxString tempBuf = inBuf;
|
|
|
|
|
|
|
|
while (!tempBuf.IsEmpty()) {
|
|
|
|
outBuf += tempBuf.BeforeFirst(wxT('<'));
|
|
|
|
tempBuf = tempBuf.AfterFirst(wxT('<'));
|
|
|
|
if (tempBuf.IsEmpty()) break;
|
|
|
|
tempBuf = tempBuf.AfterFirst(wxT('>'));
|
|
|
|
}
|
|
|
|
|
|
|
|
return outBuf;
|
|
|
|
}
|
|
|
|
|
2010-05-11 19:10:29 +00:00
|
|
|
#ifndef __WXMAC__
|
|
|
|
|
|
|
|
// Navigates from fromId to toId/toObject.
|
2010-06-23 16:59:35 +00:00
|
|
|
wxAccStatus CNoticeListCtrlAccessible::Navigate(
|
2010-05-11 19:10:29 +00:00
|
|
|
wxNavDir navDir, int fromId, int* toId, wxAccessible** toObject
|
|
|
|
) {
|
|
|
|
|
2010-06-23 16:59:35 +00:00
|
|
|
CNoticeListCtrl* pCtrl = wxDynamicCast(GetWindow(), CNoticeListCtrl);
|
2010-05-11 19:10:29 +00:00
|
|
|
*toObject = NULL;
|
|
|
|
|
2010-10-29 18:58:26 +00:00
|
|
|
if (0 != fromId) {
|
|
|
|
switch (navDir) {
|
2010-05-11 19:10:29 +00:00
|
|
|
case wxNAVDIR_PREVIOUS:
|
|
|
|
case wxNAVDIR_UP:
|
2010-10-29 18:58:26 +00:00
|
|
|
if (1 == fromId){
|
2010-05-11 19:10:29 +00:00
|
|
|
return wxACC_FALSE;
|
2010-10-29 18:58:26 +00:00
|
|
|
} else {
|
2010-05-11 19:10:29 +00:00
|
|
|
*toId = fromId - 1;
|
|
|
|
return wxACC_OK;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case wxNAVDIR_NEXT:
|
|
|
|
case wxNAVDIR_DOWN:
|
2010-10-29 18:58:26 +00:00
|
|
|
if ((int)pCtrl->GetItemCount() == fromId) {
|
2010-05-11 19:10:29 +00:00
|
|
|
return wxACC_FALSE;
|
2010-10-29 18:58:26 +00:00
|
|
|
} else {
|
2010-05-11 19:10:29 +00:00
|
|
|
*toId = fromId + 1;
|
|
|
|
return wxACC_OK;
|
|
|
|
}
|
|
|
|
return wxACC_FALSE;
|
|
|
|
break;
|
|
|
|
case wxNAVDIR_LEFT:
|
|
|
|
return wxACC_FALSE;
|
|
|
|
break;
|
|
|
|
case wxNAVDIR_RIGHT:
|
|
|
|
return wxACC_FALSE;
|
|
|
|
break;
|
|
|
|
case wxNAVDIR_FIRSTCHILD:
|
2010-10-29 18:58:26 +00:00
|
|
|
if (1 == fromId) {
|
2010-05-11 19:10:29 +00:00
|
|
|
return wxACC_FALSE;
|
2010-10-29 18:58:26 +00:00
|
|
|
} else {
|
2010-05-11 19:10:29 +00:00
|
|
|
*toId = 1;
|
|
|
|
return wxACC_OK;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case wxNAVDIR_LASTCHILD:
|
2010-10-29 18:58:26 +00:00
|
|
|
if ((int)pCtrl->GetItemCount() == fromId) {
|
2010-05-11 19:10:29 +00:00
|
|
|
return wxACC_FALSE;
|
2010-10-29 18:58:26 +00:00
|
|
|
} else {
|
2010-05-11 19:10:29 +00:00
|
|
|
*toId = (int)pCtrl->GetItemCount();
|
|
|
|
return wxACC_OK;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Let the framework handle the other cases.
|
|
|
|
return wxACC_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Gets the default action for this object (0) or > 0 (the action for a child).
|
|
|
|
// Return wxACC_OK even if there is no action. actionName is the action, or the empty
|
|
|
|
// string if there is no action.
|
|
|
|
// The retrieved string describes the action that is performed on an object,
|
|
|
|
// not what the object does as a result. For example, a toolbar button that prints
|
|
|
|
// a document has a default action of "Press" rather than "Prints the current document."
|
2010-10-29 18:58:26 +00:00
|
|
|
wxAccStatus CNoticeListCtrlAccessible::GetDefaultAction(int childId, wxString* actionName) {
|
2010-06-23 16:59:35 +00:00
|
|
|
CNoticeListCtrl* pCtrl = wxDynamicCast(GetWindow(), CNoticeListCtrl);
|
2010-10-29 18:58:26 +00:00
|
|
|
if (pCtrl && (childId != wxACC_SELF)) {
|
2010-05-11 19:10:29 +00:00
|
|
|
*actionName = _("Click");
|
|
|
|
return wxACC_OK;
|
|
|
|
}
|
|
|
|
// Let the framework handle the other cases.
|
|
|
|
return wxACC_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Returns a role constant.
|
2010-10-29 18:58:26 +00:00
|
|
|
wxAccStatus CNoticeListCtrlAccessible::GetRole(int childId, wxAccRole* role) {
|
|
|
|
if (childId == wxACC_SELF) {
|
2010-05-11 19:10:29 +00:00
|
|
|
*role = wxROLE_SYSTEM_LIST;
|
2010-10-29 18:58:26 +00:00
|
|
|
} else {
|
2010-05-11 19:10:29 +00:00
|
|
|
*role = wxROLE_SYSTEM_LISTITEM;
|
|
|
|
}
|
|
|
|
return wxACC_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Returns a role constant.
|
2010-10-29 18:58:26 +00:00
|
|
|
wxAccStatus CNoticeListCtrlAccessible::GetState(int childId, long* state) {
|
|
|
|
if (childId == wxACC_SELF) {
|
2010-05-11 19:10:29 +00:00
|
|
|
*state = wxACC_STATE_SYSTEM_DEFAULT;
|
2010-10-29 18:58:26 +00:00
|
|
|
} else {
|
2010-06-23 16:59:35 +00:00
|
|
|
CNoticeListCtrl* pCtrl = wxDynamicCast(GetWindow(), CNoticeListCtrl);
|
2010-10-29 18:58:26 +00:00
|
|
|
if (pCtrl && (pCtrl->IsSelected(childId - 1))) {
|
2010-05-11 19:10:29 +00:00
|
|
|
*state = wxACC_STATE_SYSTEM_SELECTABLE |
|
|
|
|
wxACC_STATE_SYSTEM_FOCUSABLE |
|
|
|
|
wxACC_STATE_SYSTEM_SELECTED |
|
|
|
|
wxACC_STATE_SYSTEM_FOCUSED;
|
2010-10-29 18:58:26 +00:00
|
|
|
} else if (pCtrl && (pCtrl->IsVisible(childId - 1))) {
|
2010-05-11 19:10:29 +00:00
|
|
|
*state = wxACC_STATE_SYSTEM_SELECTABLE |
|
|
|
|
wxACC_STATE_SYSTEM_FOCUSABLE;
|
2010-10-29 18:58:26 +00:00
|
|
|
} else {
|
2010-05-11 19:10:29 +00:00
|
|
|
*state = wxACC_STATE_SYSTEM_SELECTABLE |
|
|
|
|
wxACC_STATE_SYSTEM_FOCUSABLE |
|
|
|
|
wxACC_STATE_SYSTEM_OFFSCREEN |
|
|
|
|
wxACC_STATE_SYSTEM_INVISIBLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return wxACC_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Selects the object or child.
|
2010-10-29 18:58:26 +00:00
|
|
|
wxAccStatus CNoticeListCtrlAccessible::Select(int , wxAccSelectionFlags ) {
|
2010-05-11 19:10:29 +00:00
|
|
|
// Let the framework handle the other cases.
|
|
|
|
return wxACC_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Gets a variant representing the selected children
|
|
|
|
// of this object.
|
|
|
|
// Acceptable values:
|
|
|
|
// - a null variant (IsNull() returns true)
|
|
|
|
// - a list variant (GetType() == wxT("list"))
|
|
|
|
// - an integer representing the selected child element,
|
|
|
|
// or 0 if this object is selected (GetType() == wxT("long"))
|
|
|
|
// - a "void*" pointer to a wxAccessible child object
|
2010-10-29 18:58:26 +00:00
|
|
|
wxAccStatus CNoticeListCtrlAccessible::GetSelections(wxVariant* ) {
|
2010-05-11 19:10:29 +00:00
|
|
|
// Let the framework handle the other cases.
|
|
|
|
return wxACC_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
#endif // ifndef __WXMAC__
|
2010-07-06 19:26:53 +00:00
|
|
|
|
2010-05-11 19:10:29 +00:00
|
|
|
#endif // wxUSE_ACCESSIBILITY || defined(__WXMAC__)
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
2010-06-23 16:59:35 +00:00
|
|
|
* CNoticeListCtrl event definitions
|
2010-05-11 19:10:29 +00:00
|
|
|
*/
|
2010-06-23 16:59:35 +00:00
|
|
|
DEFINE_EVENT_TYPE( wxEVT_NOTICELIST_ITEM_CHANGE )
|
|
|
|
DEFINE_EVENT_TYPE( wxEVT_NOTICELIST_ITEM_DISPLAY )
|
2010-05-11 19:10:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*!
|
2010-06-23 16:59:35 +00:00
|
|
|
* CNoticeListCtrl type definition
|
2010-05-11 19:10:29 +00:00
|
|
|
*/
|
2010-08-15 14:17:01 +00:00
|
|
|
IMPLEMENT_DYNAMIC_CLASS( CNoticeListCtrl, CBOINCHtmlListBox )
|
2010-06-23 16:59:35 +00:00
|
|
|
IMPLEMENT_DYNAMIC_CLASS( NoticeListCtrlEvent, wxNotifyEvent )
|
2010-05-11 19:10:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*!
|
2010-06-23 16:59:35 +00:00
|
|
|
* CNoticeListCtrl event table definition
|
2010-05-11 19:10:29 +00:00
|
|
|
*/
|
|
|
|
|
2010-08-15 14:17:01 +00:00
|
|
|
BEGIN_EVENT_TABLE( CNoticeListCtrl, CBOINCHtmlListBox )
|
2010-06-23 16:59:35 +00:00
|
|
|
|
|
|
|
////@begin CNoticeListCtrl event table entries
|
|
|
|
EVT_LISTBOX(ID_LIST_NOTIFICATIONSVIEW, CNoticeListCtrl::OnSelected)
|
|
|
|
EVT_LISTBOX_DCLICK(ID_LIST_NOTIFICATIONSVIEW, CNoticeListCtrl::OnDClicked)
|
|
|
|
EVT_HTML_CELL_CLICKED(ID_LIST_NOTIFICATIONSVIEW, CNoticeListCtrl::OnClicked)
|
|
|
|
EVT_HTML_LINK_CLICKED(ID_LIST_NOTIFICATIONSVIEW, CNoticeListCtrl::OnLinkClicked)
|
|
|
|
////@end CNoticeListCtrl event table entries
|
2010-05-11 19:10:29 +00:00
|
|
|
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
/*!
|
2010-06-23 16:59:35 +00:00
|
|
|
* CNoticeListCtrl constructors
|
2010-05-11 19:10:29 +00:00
|
|
|
*/
|
|
|
|
|
2010-06-23 16:59:35 +00:00
|
|
|
CNoticeListCtrl::CNoticeListCtrl( )
|
2010-05-11 19:10:29 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-06-23 16:59:35 +00:00
|
|
|
CNoticeListCtrl::CNoticeListCtrl( wxWindow* parent )
|
2010-05-11 19:10:29 +00:00
|
|
|
{
|
|
|
|
Create( parent );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-23 16:59:35 +00:00
|
|
|
CNoticeListCtrl::~CNoticeListCtrl( )
|
2010-06-30 09:38:43 +00:00
|
|
|
{
|
|
|
|
#ifdef __WXMAC__
|
|
|
|
if (m_accessible) {
|
|
|
|
delete m_accessible;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-11 19:10:29 +00:00
|
|
|
/*!
|
2010-06-23 16:59:35 +00:00
|
|
|
* CNoticeListCtrl creator
|
2010-05-11 19:10:29 +00:00
|
|
|
*/
|
|
|
|
|
2010-06-23 16:59:35 +00:00
|
|
|
bool CNoticeListCtrl::Create( wxWindow* parent )
|
2010-05-11 19:10:29 +00:00
|
|
|
{
|
2010-06-23 16:59:35 +00:00
|
|
|
////@begin CNoticeListCtrl member initialisation
|
|
|
|
////@end CNoticeListCtrl member initialisation
|
2010-05-11 19:10:29 +00:00
|
|
|
|
2010-06-23 16:59:35 +00:00
|
|
|
////@begin CNoticeListCtrl creation
|
2010-08-15 14:17:01 +00:00
|
|
|
CBOINCHtmlListBox::Create( parent, ID_LIST_NOTIFICATIONSVIEW, wxDefaultPosition, wxDefaultSize,
|
2010-05-11 19:10:29 +00:00
|
|
|
wxSUNKEN_BORDER | wxTAB_TRAVERSAL );
|
|
|
|
|
|
|
|
#if wxUSE_ACCESSIBILITY
|
2010-06-23 16:59:35 +00:00
|
|
|
SetAccessible(new CNoticeListCtrlAccessible(this));
|
2010-05-11 19:10:29 +00:00
|
|
|
#endif
|
|
|
|
#ifdef __WXMAC__
|
2010-07-10 08:02:00 +00:00
|
|
|
// Enable accessibility only after drawing the page
|
|
|
|
// to avoid a mysterious crash bug
|
2010-07-10 07:38:44 +00:00
|
|
|
m_accessible = NULL;
|
2010-05-11 19:10:29 +00:00
|
|
|
#endif
|
2010-06-23 16:59:35 +00:00
|
|
|
////@end CNoticeListCtrl creation
|
2010-05-11 19:10:29 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-23 16:59:35 +00:00
|
|
|
void CNoticeListCtrl::OnSelected( wxCommandEvent& event )
|
2010-05-11 19:10:29 +00:00
|
|
|
{
|
|
|
|
// Fire Event
|
2010-06-23 16:59:35 +00:00
|
|
|
NoticeListCtrlEvent evt(
|
|
|
|
wxEVT_NOTICELIST_ITEM_CHANGE,
|
2010-06-30 18:52:20 +00:00
|
|
|
event.GetInt(),
|
|
|
|
wxEmptyString
|
2010-05-11 19:10:29 +00:00
|
|
|
);
|
|
|
|
evt.SetEventObject(this);
|
|
|
|
|
|
|
|
GetParent()->AddPendingEvent( evt );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-23 16:59:35 +00:00
|
|
|
void CNoticeListCtrl::OnClicked( wxHtmlCellEvent& event )
|
2010-05-11 19:10:29 +00:00
|
|
|
{
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-23 16:59:35 +00:00
|
|
|
void CNoticeListCtrl::OnDClicked( wxCommandEvent& event )
|
2010-05-11 19:10:29 +00:00
|
|
|
{
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-23 16:59:35 +00:00
|
|
|
void CNoticeListCtrl::OnLinkClicked( wxHtmlLinkEvent& event )
|
2010-05-11 19:10:29 +00:00
|
|
|
{
|
|
|
|
// Fire Event
|
2010-06-23 16:59:35 +00:00
|
|
|
NoticeListCtrlEvent evt(
|
|
|
|
wxEVT_NOTICELIST_ITEM_DISPLAY,
|
2010-06-30 18:52:20 +00:00
|
|
|
event.GetInt(),
|
|
|
|
event.GetLinkInfo().GetHref()
|
2010-05-11 19:10:29 +00:00
|
|
|
);
|
|
|
|
evt.SetEventObject(this);
|
|
|
|
|
|
|
|
GetParent()->AddPendingEvent( evt );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-29 18:58:26 +00:00
|
|
|
wxString CNoticeListCtrl::OnGetItem(size_t i) const {
|
2010-07-23 22:57:54 +00:00
|
|
|
CMainDocument* pDoc = wxGetApp().GetDocument();
|
2010-06-30 18:52:20 +00:00
|
|
|
wxString strTitle = wxEmptyString;
|
|
|
|
wxString strDescription = wxEmptyString;
|
|
|
|
wxString strProjectName = wxEmptyString;
|
|
|
|
wxString strURL = wxEmptyString;
|
|
|
|
wxString strArrivalTime = wxEmptyString;
|
2010-05-11 19:10:29 +00:00
|
|
|
wxString strBuffer = wxEmptyString;
|
2010-06-23 16:59:35 +00:00
|
|
|
wxString strTemp = wxEmptyString;
|
2010-06-30 18:52:20 +00:00
|
|
|
wxDateTime dtBuffer;
|
2010-10-29 18:58:26 +00:00
|
|
|
char buf[1024];
|
2010-06-30 18:52:20 +00:00
|
|
|
|
|
|
|
wxASSERT(pDoc);
|
|
|
|
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
|
2010-06-23 16:59:35 +00:00
|
|
|
|
2010-06-30 18:52:20 +00:00
|
|
|
|
2010-10-19 19:28:29 +00:00
|
|
|
if (pDoc->GetNoticeCount() <= 0) {
|
|
|
|
strBuffer = wxT("<table border=0 cellpadding=5><tr><td>");
|
2010-10-29 18:58:26 +00:00
|
|
|
strBuffer += _("There are no notices at this time.");
|
2010-10-19 19:28:29 +00:00
|
|
|
strBuffer += wxT("</font></td></tr></table><hr>");
|
|
|
|
} else {
|
|
|
|
NOTICE* np = pDoc->notice((unsigned int)i);
|
2010-07-23 22:57:54 +00:00
|
|
|
|
2010-10-19 19:28:29 +00:00
|
|
|
strURL = wxString(np->link, wxConvUTF8);
|
2010-07-23 22:57:54 +00:00
|
|
|
|
2010-10-29 18:58:26 +00:00
|
|
|
if (!strcmp(np->category, "client")) {
|
|
|
|
if (strlen(np->project_name)) {
|
|
|
|
sprintf(buf, "%s: %s", np->project_name, "_(\"Notice from BOINC\")");
|
|
|
|
} else {
|
|
|
|
strcpy(buf, "_(\"Notice from BOINC\")");
|
|
|
|
}
|
|
|
|
} else if (!strcmp(np->category, "scheduler")) {
|
|
|
|
sprintf(buf, "%s: %s", np->project_name, "_(\"Notice from server\")");
|
|
|
|
} else {
|
|
|
|
if (strlen(np->project_name)) {
|
|
|
|
sprintf(buf, "%s: %s", np->project_name, np->title);
|
|
|
|
} else {
|
|
|
|
strcpy(buf, np->title);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
strTitle = wxString(buf, wxConvUTF8);
|
2010-10-19 19:28:29 +00:00
|
|
|
pDoc->LocalizeNoticeText(strTitle, true);
|
2010-06-30 18:52:20 +00:00
|
|
|
|
2010-10-19 19:28:29 +00:00
|
|
|
strDescription = wxString(np->description.c_str(), wxConvUTF8);
|
|
|
|
pDoc->LocalizeNoticeText(strDescription, true);
|
2010-06-30 18:52:20 +00:00
|
|
|
|
2010-10-19 19:28:29 +00:00
|
|
|
dtBuffer.Set((time_t)np->arrival_time);
|
|
|
|
strArrivalTime = dtBuffer.Format();
|
2010-07-22 22:00:15 +00:00
|
|
|
|
2010-10-19 19:28:29 +00:00
|
|
|
strBuffer = wxT("<table border=0 cellpadding=5><tr><td>");
|
2010-05-11 19:10:29 +00:00
|
|
|
|
2010-10-19 19:28:29 +00:00
|
|
|
if (!strTitle.IsEmpty()) {
|
|
|
|
strTemp.Printf(
|
|
|
|
wxT("<b>%s</b><br>"),
|
|
|
|
strTitle.c_str()
|
|
|
|
);
|
|
|
|
strBuffer += strTemp;
|
|
|
|
}
|
2010-05-11 19:10:29 +00:00
|
|
|
|
2010-10-19 19:28:29 +00:00
|
|
|
strBuffer += strDescription;
|
2010-05-11 19:10:29 +00:00
|
|
|
|
2010-10-19 19:28:29 +00:00
|
|
|
strBuffer += wxT("<br><font size=-2 color=#8f8f8f>");
|
2010-05-11 19:10:29 +00:00
|
|
|
|
2010-10-19 19:28:29 +00:00
|
|
|
strBuffer += strArrivalTime;
|
2010-05-11 19:10:29 +00:00
|
|
|
|
2010-10-19 19:28:29 +00:00
|
|
|
if (!strURL.IsEmpty()) {
|
|
|
|
strTemp.Printf(
|
|
|
|
wxT(" · <a target=_new href=%s>%s</a> "),
|
|
|
|
strURL.c_str(),
|
|
|
|
_("more...")
|
|
|
|
);
|
|
|
|
strBuffer += strTemp;
|
|
|
|
}
|
|
|
|
|
|
|
|
strBuffer += wxT("</font></td></tr></table><hr>");
|
2010-05-11 19:10:29 +00:00
|
|
|
}
|
|
|
|
|
2010-10-19 19:28:29 +00:00
|
|
|
|
2010-06-23 16:59:35 +00:00
|
|
|
|
|
|
|
return strBuffer;
|
2010-05-11 19:10:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
2010-06-30 18:52:20 +00:00
|
|
|
* Update the UI.
|
2010-06-28 02:41:34 +00:00
|
|
|
*/
|
|
|
|
|
2010-06-30 18:52:20 +00:00
|
|
|
bool CNoticeListCtrl::UpdateUI()
|
2010-06-25 15:30:20 +00:00
|
|
|
{
|
2010-06-30 18:52:20 +00:00
|
|
|
CMainDocument* pDoc = wxGetApp().GetDocument();
|
2010-06-28 18:05:31 +00:00
|
|
|
|
2010-06-30 18:52:20 +00:00
|
|
|
wxASSERT(pDoc);
|
|
|
|
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
|
2010-06-28 18:05:31 +00:00
|
|
|
|
2010-08-15 14:17:01 +00:00
|
|
|
// Call Freeze() / Thaw() only when actually needed;
|
|
|
|
// otherwise it causes unnecessary redraws
|
2010-10-19 19:28:29 +00:00
|
|
|
if (pDoc->GetNoticeCount() <= 0) {
|
2010-08-15 14:17:01 +00:00
|
|
|
Freeze();
|
2010-10-19 19:28:29 +00:00
|
|
|
SetItemCount(1);
|
2010-08-15 14:17:01 +00:00
|
|
|
Thaw();
|
2010-08-03 09:17:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-06-30 20:12:24 +00:00
|
|
|
if (
|
2010-06-30 23:42:34 +00:00
|
|
|
((int)GetItemCount() != pDoc->GetNoticeCount()) ||
|
2010-06-30 20:12:24 +00:00
|
|
|
pDoc->notices.complete
|
|
|
|
) {
|
2010-08-15 14:17:01 +00:00
|
|
|
Freeze();
|
2010-06-30 18:52:20 +00:00
|
|
|
SetItemCount(pDoc->GetNoticeCount());
|
2010-06-30 23:42:34 +00:00
|
|
|
pDoc->notices.complete = false;
|
2010-08-15 14:17:01 +00:00
|
|
|
Thaw();
|
2010-06-28 18:05:31 +00:00
|
|
|
}
|
2010-07-10 07:38:44 +00:00
|
|
|
#ifdef __WXMAC__
|
2010-07-10 08:02:00 +00:00
|
|
|
// Enable accessibility only after drawing the page
|
|
|
|
// to avoid a mysterious crash bug
|
2010-07-10 07:38:44 +00:00
|
|
|
if (m_accessible == NULL) {
|
|
|
|
m_accessible = new CNoticeListCtrlAccessible(this);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-06-25 15:30:20 +00:00
|
|
|
return true;
|
|
|
|
}
|