upseudosupport.cpp
来自「WinCVS 源码,流行的CVS客户端源码程序」· C++ 代码 · 共 969 行 · 第 1/2 页
CPP
969 行
::UEventGiveTime();
Inherited::DoSetupMenus();
}
bool TPseudoAppBehavior::DoToolboxEvent(TToolboxEvent* event)
{
if(event && event->GetIdentifier() == activateEvt)
{
bool activate = ((event->GetModifiers()) & activeFlag) != 0;
TWindow * aWindow = TWindow::WMgrToWindow((WindowRef)(event->GetMessage()));
if(aWindow)
{
UEventNotifyMessage(EV_UPDATEFOCUS, !activate, aWindow);
// so the pseudo widget update its current widget.
// it's important for the menu handling.
}
}
return Inherited::DoToolboxEvent(event);
}
#undef Inherited
#define Inherited TIconButton
MA_DEFINE_CLASS_M1(TPseudoIconButton, Inherited);
TPseudoIconButton::TPseudoIconButton()
{
}
TPseudoIconButton::~TPseudoIconButton()
{
}
void TPseudoIconButton::ReadFields(CStream_AC* aStream)
{
Inherited::ReadFields(aStream);
*aStream >> fContentType;
SetContentRsrcID(fContentType, fRsrcID);
}
void TPseudoIconButton::WriteFields(CStream_AC* aStream) const
{
Inherited::WriteFields(aStream);
*aStream << fContentType;
}
#undef Inherited
#define Inherited TPopup
MA_DEFINE_CLASS_M1(TBuggyPopup, Inherited);
TBuggyPopup::TBuggyPopup()
{
}
TBuggyPopup::~TBuggyPopup()
{
}
void TBuggyPopup::ReadFields(CStream_AC* aStream)
{
Inherited::ReadFields(aStream);
*aStream >> fRealWidth;
}
void TBuggyPopup::WriteFields(CStream_AC* aStream) const
{
Inherited::WriteFields(aStream);
*aStream << fRealWidth;
}
void TBuggyPopup::DoPostCreate(TDocument* itsDocument)
{
if(fRealWidth > 0)
{
CViewRect r = GetExtent();
Resize(CViewPoint(fRealWidth, r.Height()), true);
}
}
#undef Inherited
#define Inherited TIconPopup
MA_DEFINE_CLASS_M1(TPseudoIconPopup, Inherited);
TPseudoIconPopup::TPseudoIconPopup()
{
}
TPseudoIconPopup::~TPseudoIconPopup()
{
}
void TPseudoIconPopup::ReadFields(CStream_AC* aStream)
{
Inherited::ReadFields(aStream);
*aStream >> fContentType;
SetContentRsrcID(fContentType, fRsrcID);
}
void TPseudoIconPopup::WriteFields(CStream_AC* aStream) const
{
Inherited::WriteFields(aStream);
*aStream << fContentType;
}
#undef Inherited
#define Inherited TScrollBar
MA_DEFINE_CLASS_M1(TPseudoScrollBar, Inherited);
TPseudoScrollBar::TPseudoScrollBar() : fPageStep(1), fButtonStep(1)
{
}
TPseudoScrollBar::~TPseudoScrollBar()
{
}
void TPseudoScrollBar::TrackScrollBar(short partCode)
{
switch (partCode)
{
case kControlPageUpPart:
if (GetValue() > GetMinimum())
DeltaValue(-fPageStep);
break;
case kControlUpButtonPart:
if (GetValue() > GetMinimum())
DeltaValue(-fButtonStep);
break;
case kControlPageDownPart:
if (GetValue() < GetMaximum())
DeltaValue(fPageStep);
break;
case kControlDownButtonPart:
if (GetValue() < GetMaximum())
DeltaValue(fButtonStep);
break;
}
}
#undef Inherited
#define Inherited TPseudoIconButton
MA_DEFINE_CLASS_M1(TPseudoRotateIconButton, Inherited);
TPseudoRotateIconButton::TPseudoRotateIconButton() : fCurrentIcon(0)
{
}
TPseudoRotateIconButton::~TPseudoRotateIconButton()
{
}
void TPseudoRotateIconButton::ReadFields(CStream_AC* aStream)
{
Inherited::ReadFields(aStream);
CChar255_AC str(aStream->ReadString(255));
const char *ptr = str;
while(ptr != 0L)
{
int v;
const char *tmp = strchr(ptr, ',');
if(tmp != 0L)
{
CChar255_AC stmp;
size_t offset = tmp - ptr;
stmp.CopyFrom(ptr, offset);
ptr += offset + 1;
if(sscanf(stmp, "%d", &v) == 1)
fIconSuite.push_back(v);
}
else
{
if(sscanf(ptr, "%d", &v) == 1)
fIconSuite.push_back(v);
ptr = 0;
}
}
if(fIconSuite.size() != 0)
SetContentRsrcID(fContentType, fIconSuite[0]);
}
void TPseudoRotateIconButton::WriteFields(CStream_AC* aStream) const
{
Inherited::WriteFields(aStream);
// do we really need to write ?
*aStream << "";
UASSERT(0);
}
void TPseudoRotateIconButton::DoRotate(int icon)
{
if(fCurrentIcon != icon && icon >= 0 && icon < fIconSuite.size())
{
fCurrentIcon = icon;
SetContentRsrcID(fContentType, fIconSuite[fCurrentIcon]);
ForceRedraw();
}
}
#undef Inherited
#define Inherited TIconCheckBox
MA_DEFINE_CLASS_M1(TPseudoIconCheckBox, Inherited);
TPseudoIconCheckBox::TPseudoIconCheckBox()
{
}
TPseudoIconCheckBox::~TPseudoIconCheckBox()
{
}
void TPseudoIconCheckBox::ReadFields(CStream_AC* aStream)
{
Inherited::ReadFields(aStream);
*aStream >> fContentType;
SetContentRsrcID(fContentType, fRsrcID);
}
void TPseudoIconCheckBox::WriteFields(CStream_AC* aStream) const
{
Inherited::WriteFields(aStream);
*aStream << fContentType;
}
#undef Inherited
#define Inherited TAdorner
MA_DEFINE_CLASS_M1(TPseudoWinAdorner, Inherited);
TPseudoWinAdorner::TPseudoWinAdorner() : TAdorner(kPseudoWinAdorner), fWidID(-1)
{
}
TPseudoWinAdorner::~TPseudoWinAdorner()
{
if(fWidID != -1)
UEventSendMessage(fWidID, EV_DESTROY, 0, 0L);
}
void TPseudoWinAdorner::ViewChangedFrame (TView* itsView,
const CViewRect& oldFrame,
const CViewRect& newFrame,
bool invalidate)
{
TWindow *wind = itsView->GetWindow();
if(wind != 0L && fWidID != -1)
{
int cmdid = UEventSendMessage(fWidID, EV_FETCHCMD, 0, itsView);
if(cmdid != -1)
{
URECT r;
r.left = newFrame.left;
r.right = newFrame.right;
r.top = newFrame.top;
r.bottom = newFrame.bottom;
UEventSendMessage(fWidID, EV_RESIZE, cmdid, &r);
}
}
}
UIMPLEMENT_DYNAMIC(UMacAppMenu, UMenu)
UBEGIN_MESSAGE_MAP(UMacAppMenu, UMenu)
ON_UPDATEUI(UMacAppMenu)
UEND_MESSAGE_MAP()
int UMacAppMenu::sMAMenuWidID = -1;
UMacAppMenu::UMacAppMenu() : UMenu(::UEventGetWidID())
{
sMAMenuWidID = GetWidID();
}
UMacAppMenu::~UMacAppMenu()
{
}
// If hierarchical the range of IDs for applications is restricted. See IM V-236.
// If the menu isn't managed by MacApp and is in a TPopup, its ID must be outside this range.
enum
{
kHierarchicalMin = 0,
kHierarchicalMax = 235
};
void UMacAppMenu::OnUpdateUI()
{
static bool sSemaphore = false;
USemaphore policeman(sSemaphore);
if(policeman.IsEnteredTwice())
return;
// this is the interesting thing about the toolbar : it resends the
// update UI to other widgets according to the focus information and
// allows the update to be handled several times if the handler asks for it
// (by using UCmdUI::SetContinue)
const STD map<int, UCmdTarget *> & targets = UEventGetTargets();
std::map<int, void *>::iterator w;
int cmdid;
int widFocus = UWidget::GetFocus();
for(CMenuIterator iter; iter.Current(); ++iter)
{
MenuRef menu = iter;
short menuID = (**menu).menuID;
// see UMenuMgr.cpp from MacApp
if (menuID < kHierarchicalMin || menuID > kHierarchicalMax)
continue;
short numitems = ::CountMItems(menu);
for(int j = 1; j <= numitems; j++)
{
cmdid = CommandFromMenuItem(menuID, j);
if(cmdid < 0)
{
UAppConsole("The item %d of the menu %d has not a MacApp cmd\n", j, menuID);
}
else
{
if(cmdid == kUMainWidget)
continue;
// first forward the command to the focused widget : if it doesn't want it
// we give it to the next pseudo widget.
if(widFocus != -1 && widFocus != GetWidID())
{
UCmdUI pUI(cmdid);
UEventSendMessage(widFocus, EV_UPDTCMD, pUI.m_nID, &pUI);
if(!pUI.CanContinue())
continue;
}
STD map<int, UCmdTarget *>::const_iterator i;
for(i = targets.begin(); i != targets.end(); ++i)
{
int widid = (*i).first;
if(widid == widFocus || widid == GetWidID())
continue;
UCmdUI pUI(cmdid);
UEventSendMessage(widid, EV_UPDTCMD, pUI.m_nID, &pUI);
if(!pUI.CanContinue())
break;
}
if(i == targets.end())
{
//UAppConsole("The cmd %d of the menubar has no update handler, it's gonna be disabled\n", cmdid);
UCmdUI pUI(cmdid);
pUI.Enable(false);
}
}
}
}
}
class CDummyClass
{
public:
CDummyClass()
{
InitUSlider();
if (!gUGridViewInitialized)
{
InitUGridView();
}
MA_REGISTER_CLASS(TPseudoAppBehavior);
MA_REGISTER_CLASS(TPseudoIconButton);
MA_REGISTER_CLASS(TPseudoIconPopup);
MA_REGISTER_CLASS(TPseudoScrollBar);
MA_REGISTER_CLASS(TPseudoRotateIconButton);
MA_REGISTER_CLASS(TPseudoIconCheckBox);
MA_REGISTER_CLASS(TBuggyPopup);
MA_REGISTER_CLASS(TPseudoWinBehavior);
MA_REGISTER_CLASS(TPseudoCustomView);
MA_REGISTER_CLASS(TPseudoWinAdorner);
MA_REGISTER_SIGNATURE(TPseudoTextListView,
TPseudoTextListView::kTextStringListViewSignature);
MA_REGISTER_CLASS(TPseudoDoubleNumberText);
}
} sDummyStarter;
typedef struct CViewInfo
{
TView *view;
};
static void extractInfos(std::vector<CViewInfo> & infos, std::vector<TPopup *> & popups, TView *view)
{
if(view == 0L)
return;
if(MA_MEMBER(view, TPopup) && !MA_MEMBER(view, TIconPopup))
{
popups.push_back((TPopup *)view);
}
else
{
CViewInfo info;
info.view = view;
infos.push_back(info);
}
extractInfos(infos, popups, view->GetNextView());
extractInfos(infos, popups, view->GetSubView());
}
static bool InBetweenVSide(const CViewRect & popPos, const CViewRect & pos)
{
return (popPos.top >= pos.top && popPos.top <= pos.bottom) ||
(popPos.bottom >= pos.top && popPos.bottom <= pos.bottom) ||
(pos.top >= popPos.top && pos.top <= popPos.bottom) ||
(pos.bottom >= popPos.top && pos.bottom <= popPos.bottom);
}
static int findmostright(TPopup *popup, const std::vector<CViewInfo> & infos)
{
int most_right = popup->GetWindow()->GetExtent().right;
CViewRect popPos = popup->GetFrame();
popPos = popup->GetSuperView()->LocalToRootView(popPos);
std::vector<CViewInfo>::const_iterator i;
for(i = infos.begin(); i != infos.end(); ++i)
{
TView *view = (*i).view;
CViewRect pos = view->GetFrame();
pos = view->GetSuperView()->LocalToRootView(pos);
if(pos.left > popPos.right && InBetweenVSide(popPos, pos))
{
// the top/bottom popup is inside the top/bottom view
if(pos.left < most_right)
most_right = pos.left;
}
}
return most_right;
}
void macapp_workaround_adlib_bug(TView *view)
{
std::vector<TPopup *> popups;
std::vector<CViewInfo> infos;
extractInfos(infos, popups, view->GetSubView());
# define OFFSET 40
std::vector<TPopup *>::iterator p;
for(p = popups.begin(); p != popups.end(); ++p)
{
TPopup *popup = *p;
int most_right = findmostright(popup, infos);
CViewRect oldPos = popup->GetFrame();
oldPos = popup->GetSuperView()->LocalToRootView(oldPos);
if(most_right > (oldPos.right + OFFSET))
{
oldPos.right = most_right - OFFSET;
oldPos = popup->GetSuperView()->RootViewToLocal(oldPos);
popup->SetFrame(oldPos, true);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?