This commit is contained in:
pinkerton%netscape.com 1998-09-29 17:29:34 +00:00
Родитель 4f2e315c15
Коммит 9d38f4cfe6
11 изменённых файлов: 13 добавлений и 2926 удалений

Просмотреть файл

@ -1,312 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "CFontMenuAttachment.h"
#include "CEditView.h"
#include "CBrowserContext.h" // operator MWContext*()
#include "resgui.h" // cmd_FormatViewerFont, cmd_FormatFixedFont, FONT_MENU_BASE
#include "macutil.h" // CMediatedWindow
#include "edt.h"
#include "mforms.h"
LMenu *CFontMenuAttachment::sMenu = NULL;
//===========================================================
// CFontMenuAttachment
//===========================================================
CFontMenuAttachment::CFontMenuAttachment()
{
UpdateMenu();
}
MWContext *CFontMenuAttachment::GetTopWindowContext()
{
// Ok, ok. I know this is skanky,
// but there is no common way to get the context from a window: it depends on the window type.
// So, we look around for a CEditView somewhere in the top window.
// A CEditView we understand (and get an MWContext from).
CMediatedWindow* topWin = NULL; // find the top window to use the plugin in
CWindowIterator iter(WindowType_Any);
iter.Next(topWin);
if (topWin == NULL) return NULL;
if (topWin->GetWindowType() == WindowType_Editor || topWin->GetWindowType() == WindowType_Compose)
{
CEditView *editView = (CEditView *)(topWin->FindPaneByID(CEditView::pane_ID));
if (editView == NULL || editView->GetNSContext() == NULL)
return NULL;
return editView->GetNSContext()->operator MWContext*();
}
else if (topWin->GetWindowType() == WindowType_Browser)
{
// we're in a browser window, so check for an htmlarea that has the focus
LCommander *com = LCommander::GetTarget();
CFormHTMLArea *ender = dynamic_cast<CFormHTMLArea*>(com);
if (!ender) return NULL;
return ender->GetNSContext()->operator MWContext*();
}
return NULL;
}
// Processes:
//
void CFontMenuAttachment::ExecuteSelf( MessageT inMessage, void* ioParam )
{
mExecuteHost = FALSE;
switch ( inMessage )
{
case msg_CommandStatus:
{
SCommandStatus* status = (SCommandStatus*)ioParam;
EDT_CharacterData* better;
if ( status->command == cmd_FormatViewerFont || status->command == cmd_FormatFixedFont
|| ( status->command >= FONT_MENU_BASE && status->command <= FONT_MENU_BASE_LAST ) )
{
*(status->enabled) = true;
*(status->usesMark) = false;
better = NULL;
MWContext *cntxt = GetTopWindowContext();
if ( cntxt )
better = EDT_GetCharacterData( cntxt );
if ( better == NULL )
{
*(status->enabled) = false;
return;
}
}
switch ( status->command )
{
case cmd_FormatViewerFont:
*(status->usesMark) = ( ! ( better->values & TF_FIXED ) && !( better->values & TF_FONT_FACE ) );
*(status->mark) = *(status->usesMark) ? checkMark : 0;
*(status->usesMark) = true;
EDT_FreeCharacterData(better);
mExecuteHost = false;
return;
break;
case cmd_FormatFixedFont:
*(status->usesMark) = ( better->values & TF_FIXED ) != 0;
*(status->mark) = *(status->usesMark) ? checkMark : 0;
*(status->usesMark) = true;
EDT_FreeCharacterData(better);
mExecuteHost = false;
return;
break;
default:
if ( status->command >= FONT_MENU_BASE && status->command <= FONT_MENU_BASE_LAST )
{
// get font menu item
Str255 fontItemString;
fontItemString[0] = 0;
MenuHandle menuh = GetMenu()->GetMacMenuH();
::GetMenuItemText ( menuh, status->command - FONT_MENU_BASE + PERM_FONT_ITEMS + 1, fontItemString );
p2cstr( fontItemString );
// in mixed situation the mask bit will be cleared
*(status->usesMark) = ( better->values & TF_FONT_FACE && better->pFontFace && XP_STRLEN((char *)fontItemString) > 0
&& XP_STRSTR( better->pFontFace, (char *)fontItemString ) != NULL );
*(status->mark) = *(status->usesMark) ? checkMark : 0;
*(status->usesMark) = true;
EDT_FreeCharacterData(better);
mExecuteHost = false;
return;
}
}
}
break;
case cmd_FormatViewerFont:
MWContext *cntxt2 = GetTopWindowContext();
if ( cntxt2 )
EDT_SetFontFace( cntxt2, NULL, 0, NULL );
break;
case cmd_FormatFixedFont:
MWContext *cntxt3 = GetTopWindowContext();
if ( cntxt3 )
EDT_SetFontFace( cntxt3, NULL, 1, NULL );
break;
default:
{
if ( inMessage >= FONT_MENU_BASE && inMessage <= FONT_MENU_BASE_LAST )
{
MWContext *cntxt2 = GetTopWindowContext();
if ( cntxt2 )
{
// get font menu item
Str255 newFontItemString;
newFontItemString[0] = 0;
MenuHandle menuh = GetMenu()->GetMacMenuH();
::GetMenuItemText ( menuh, inMessage - FONT_MENU_BASE + PERM_FONT_ITEMS + 1, newFontItemString );
p2cstr( newFontItemString );
EDT_SetFontFace( cntxt2, NULL, -1, (char *)newFontItemString );
mExecuteHost = false;
return;
}
}
}
break;
}
mExecuteHost = TRUE; // Let application handle it
}
LMenu *CFontMenuAttachment::GetMenu()
{
if (!sMenu)
sMenu = new LMenu(cFontMenuID);
return sMenu;
}
// build the font menu from the system
void CFontMenuAttachment::UpdateMenu()
{
if (!GetMenu() || !LMenuBar::GetCurrentMenuBar())
return;
int i;
// ¥ delete all the menu items after the separator line
MenuHandle menu = sMenu->GetMacMenuH();
if ( menu )
{
for ( i = ::CountMItems( menu ); i > PERM_FONT_ITEMS; i-- )
sMenu->RemoveItem( i );
}
Try_
{
ThrowIfNil_( menu );
// Add fonts to menu
::InsertResMenu( menu, 'FONT', PERM_FONT_ITEMS );
int commandNum = FONT_MENU_BASE;
int newHowMany = ::CountMItems( menu );
for (i = PERM_FONT_ITEMS + 1; i <= newHowMany; i++ )
sMenu->SetCommand( i, commandNum++ );
}
Catch_( inErr )
{
}
EndCatch_
}
void CFontMenuAttachment::RemoveMenus()
{
if (sMenu)
{
LMenuBar *currentMenuBar = LMenuBar::GetCurrentMenuBar();
if (currentMenuBar)
currentMenuBar->RemoveMenu(sMenu);
}
}
void CFontMenuAttachment::InstallMenus()
{
if (sMenu)
{
LMenuBar *currentMenuBar = LMenuBar::GetCurrentMenuBar();
if (currentMenuBar)
{
StValueChanger<EDebugAction> okayToFail(gDebugThrow, debugAction_Nothing);
currentMenuBar->InstallMenu(sMenu, hierMenu);
ResIDT resID;
MenuHandle menuh;
Int16 whichItem;
currentMenuBar->FindMenuItem( cmd_ID_toSearchFor, resID, menuh, whichItem );
if ( menuh )
{
// make it hierarchical
::SetItemCmd( menuh, whichItem, hMenuCmd );
::SetItemMark( menuh, whichItem, menu_ID );
}
}
}
}
#pragma mark -
CFontMenuPopup::CFontMenuPopup( LStream *inStream ) : CPatternButtonPopupText( inStream )
{
}
CFontMenuPopup::~CFontMenuPopup()
{
}
void CFontMenuPopup::FinishCreateSelf( void )
{
CPatternButtonPopupText::FinishCreateSelf();
int i;
// ¥ delete all the menu items after the separator line
LMenu *ppmenu = GetMenu();
MenuHandle menuh = ppmenu ? ppmenu->GetMacMenuH() : NULL;
if ( menuh )
{
for ( i = ::CountMItems( menuh ); i > CFontMenuAttachment::PERM_FONT_ITEMS; i-- )
ppmenu->RemoveItem( i );
}
Try_
{
ThrowIfNil_( menuh );
// Add fonts to menu
::InsertResMenu( menuh, 'FONT', CFontMenuAttachment::PERM_FONT_ITEMS );
int commandNum = FONT_MENU_BASE;
int newHowMany = ::CountMItems( menuh );
for (i = CFontMenuAttachment::PERM_FONT_ITEMS + 1; i <= newHowMany; i++ )
ppmenu->SetCommand( i, commandNum++ );
SetMaxValue( newHowMany );
}
Catch_( inErr )
{
}
EndCatch_
}

Просмотреть файл

@ -1,210 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
//===========================================================
// CRecentEditMenuAttachment.cp
//===========================================================
#include "CRecentEditMenuAttachment.h"
#include "CEditView.h"
#include "CBrowserContext.h" // operator MWContext*()
#include "resgui.h"
#include "macutil.h" // CMediatedWindow
#include "UMenuUtils.h"
#include "edt.h"
#include "CEditorWindow.h"
LMenu *CRecentEditMenuAttachment::sMenu = NULL;
CRecentEditMenuAttachment::CRecentEditMenuAttachment()
{
UpdateMenu();
}
MWContext *CRecentEditMenuAttachment::GetTopWindowContext()
{
// Ok, ok. I know this is skanky,
// but there is no common way to get the context from a window: it depends on the window type.
// So, we look around for a CEditView somewhere in the top window.
// A CEditView we understand (and get an MWContext from).
CMediatedWindow* topWin = NULL; // find the top window to use the plugin in
CWindowIterator iter(WindowType_Any);
iter.Next(topWin);
if (topWin == NULL
|| ! (topWin->GetWindowType() == WindowType_Editor || topWin->GetWindowType() == WindowType_Compose) )
return NULL;
CEditView *editView = (CEditView *)(topWin->FindPaneByID(CEditView::pane_ID));
if (editView == NULL || editView->GetNSContext() == NULL)
return NULL;
return editView->GetNSContext()->operator MWContext*();
}
// Processes
void CRecentEditMenuAttachment::ExecuteSelf( MessageT inMessage, void* ioParam )
{
switch ( inMessage )
{
case msg_CommandStatus:
{
SCommandStatus* status = (SCommandStatus*)ioParam;
if ( status->command >= RECENT_EDIT_MENU_BASE && status->command <= RECENT_EDIT_MENU_BASE_LAST )
{
*(status->enabled) = true;
mExecuteHost = false;
return;
}
}
break;
default:
{
if ( inMessage >= RECENT_EDIT_MENU_BASE && inMessage <= RECENT_EDIT_MENU_BASE_LAST )
{
MWContext *cntxt2 = GetTopWindowContext();
if ( cntxt2 )
{
char *aURLtoOpen = NULL;
if ( EDT_GetEditHistory( cntxt2, inMessage - RECENT_EDIT_MENU_BASE - 1, &aURLtoOpen, NULL) )
{
URL_Struct* theURL = NET_CreateURLStruct( aURLtoOpen, NET_NORMAL_RELOAD );
if ( theURL )
CEditorWindow::MakeEditWindow( NULL, theURL );
mExecuteHost = false;
return;
}
}
}
}
break;
}
mExecuteHost = true; // Let application handle it
}
LMenu *CRecentEditMenuAttachment::GetMenu()
{
if (!sMenu)
sMenu = new LMenu( menu_ID );
return sMenu;
}
// build the font menu from the system
void CRecentEditMenuAttachment::UpdateMenu()
{
if (!GetMenu() || !LMenuBar::GetCurrentMenuBar())
return;
int i;
// ¥ delete all the menu items after the separator line
MenuHandle menu = sMenu->GetMacMenuH();
if ( menu )
{
for ( i = ::CountMItems( menu ); i > 0; i-- )
sMenu->RemoveItem( i );
}
Try_
{
ThrowIfNil_( menu );
// Add recently edited URLs to menu
int i;
char *urlp = NULL, *titlep = NULL;
for ( i = 0; i < MAX_EDIT_HISTORY_LOCATIONS
&& EDT_GetEditHistory( GetTopWindowContext(), i, &urlp, &titlep ); i++ )
{
NET_UnEscape( urlp );
// convert string to pascal-string for menu
CStr255 menuStr(urlp);
if ( menuStr.IsEmpty() )
menuStr = titlep;
if ( !menuStr.IsEmpty() )
{
// Insert a "blank" item first...
::InsertMenuItem( GetMenu()->GetMacMenuH(), "\p ", i );
// Then change it. We do this so that no interpretation of metacharacters will occur.
::SetMenuItemText( GetMenu()->GetMacMenuH(), i + 1, menuStr );
// SetCommand for menu item
sMenu->SetCommand( i, RECENT_EDIT_MENU_BASE + i );
sMenu->SetUsed( true );
}
else
break;
}
}
Catch_( inErr )
{
}
EndCatch_
}
void CRecentEditMenuAttachment::RemoveMenus()
{
if (sMenu)
{
LMenuBar *currentMenuBar = LMenuBar::GetCurrentMenuBar();
if (currentMenuBar)
currentMenuBar->RemoveMenu(sMenu);
}
}
void CRecentEditMenuAttachment::InstallMenus()
{
if (sMenu)
{
LMenuBar *currentMenuBar = LMenuBar::GetCurrentMenuBar();
if (currentMenuBar)
{
StValueChanger<EDebugAction> okayToFail(gDebugThrow, debugAction_Nothing);
currentMenuBar->InstallMenu(sMenu, hierMenu);
ResIDT resID;
MenuHandle menuh;
Int16 whichItem;
currentMenuBar->FindMenuItem( cmd_ID_toSearchFor, resID, menuh, whichItem );
if ( menuh )
{
// make it hierarchical
::SetItemCmd( menuh, whichItem, hMenuCmd );
::SetItemMark( menuh, whichItem, menu_ID );
}
}
}
}

Просмотреть файл

@ -1,338 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "CToolsAttachment.h"
#include "CEditView.h"
#include "CBrowserContext.h" // operator MWContext*()
#include "resgui.h" // TOOLS_MENU_BASE_LAST
#include "macutil.h" // CMediatedWindow
#include "UMenuUtils.h"
#include "edt.h"
//#include "CSpellChecker.h"
#include <LArray.h>
#define PERM_TOOLS_ITEMS 2
#define PERM_TOOLS_END_ITEMS 1
const CommandT cmd_ToolsHierItem = TOOLS_MENU_BASE_LAST;
LMenu *CToolsAttachment::sMenu = NULL;
Boolean CToolsAttachment::sInvalidMenu = true;
LArray CToolsAttachment::sMenusList;
//===========================================================
// CToolsAttachment
//===========================================================
CToolsAttachment::CToolsAttachment()
{
}
MWContext *CToolsAttachment::GetTopWindowContext()
{
// Ok, ok. I know this is skanky,
// but there is no common way to get the context from a window: it depends on the window type.
// So, we look around for a CEditView somewhere in the top window.
// A CEditView we understand (and get an MWContext from).
CMediatedWindow* topWin = NULL; // find the top window to use the plugin in
CWindowIterator iter(WindowType_Any);
// do {
iter.Next(topWin);
// } while (topWin && topWin->GetWindowType() != WindowType_Editor && topWin->GetWindowType() != WindowType_Compose);
if (topWin == NULL)
return NULL;
if ( topWin->GetWindowType() != WindowType_Editor && topWin->GetWindowType() != WindowType_Compose )
return NULL;
CEditView *editView = (CEditView *)(topWin->FindPaneByID(CEditView::pane_ID));
if (editView == NULL || editView->GetNSContext() == NULL)
return NULL;
return editView->GetNSContext()->operator MWContext*();
}
// Processes:
void CToolsAttachment::ExecuteSelf( MessageT inMessage, void* ioParam )
{
mExecuteHost = FALSE;
switch ( inMessage )
{
// case cmd_CheckSpelling: // spell checker
// return;
case cmd_EditorPluginStop:
MWContext *cntxt = GetTopWindowContext();
if (cntxt)
EDT_StopPlugin(cntxt);
return;
case msg_CommandStatus:
{
SCommandStatus* status = (SCommandStatus*)ioParam;
switch ( status->command )
{
case cmd_EditorPluginStop:
MWContext *cntxt = GetTopWindowContext();
*(status->enabled) = cntxt && EDT_IsPluginActive(cntxt);
*(status->usesMark) = FALSE;
return;
default:
if ( status->command >= TOOLS_MENU_BASE && status->command <= TOOLS_MENU_BASE_LAST )
{
*(status->enabled) = TRUE;
*(status->usesMark) = FALSE;
return;
}
break;
}
}
break;
default:
{
if ( inMessage >= TOOLS_MENU_BASE && inMessage <= TOOLS_MENU_BASE_LAST )
{
int32 index = inMessage - TOOLS_MENU_BASE;
for (int32 CategoryIndex = 0; CategoryIndex < EDT_NumberOfPluginCategories(); CategoryIndex++)
for (int32 PluginIndex = 0; PluginIndex < EDT_NumberOfPlugins(CategoryIndex); PluginIndex++)
if (index-- == 0)
{ // count down until we find which one...
MWContext *cntxt = GetTopWindowContext();
if (cntxt)
EDT_PerformPlugin(cntxt, CategoryIndex, PluginIndex, 0, 0); // what is the result for?
return;
}
}
}
break;
}
mExecuteHost = TRUE; // Let application handle it
}
LMenu *CToolsAttachment::GetMenu()
{
if (!sMenu)
sMenu = new LMenu(cToolsMenuID);
return sMenu;
}
void CToolsAttachment::UpdateMenu()
{
if (!sInvalidMenu || !GetMenu() || !LMenuBar::GetCurrentMenuBar())
return;
int i;
// ¥ delete all the dynamically created menus
// ¥Êdelete all the hierarchical menus we have added from the menubar
for ( i = 1; i <= sMenusList.GetCount(); i++ )
{
LMenu* m;
sMenusList.FetchItemAt( i, &m );
if ( m )
LMenuBar::GetCurrentMenuBar()->RemoveMenu( m );
delete m;
}
// ¥ delete all the menu items after the line in Tools menu
MenuHandle menu = sMenu->GetMacMenuH();
if ( menu )
{
int howMany = ::CountMItems( menu );
for ( i = howMany - PERM_TOOLS_END_ITEMS; i > PERM_TOOLS_ITEMS; i-- )
sMenu->RemoveItem( i );
}
sMenusList.RemoveItemsAt( sMenusList.GetCount(), 1 );
int whichItem = PERM_TOOLS_ITEMS;
int commandNum = TOOLS_MENU_BASE;
int nextMenuID = cEditorPluginsFirstHierMenuID;
Try_
{
ThrowIfNil_( sMenu );
MenuHandle mHand = sMenu->GetMacMenuH();
ThrowIfNil_( mHand );
for (int32 CategoryIndex = 0; CategoryIndex < EDT_NumberOfPluginCategories(); CategoryIndex++) {
CStr255 headerName( EDT_GetPluginCategoryName( CategoryIndex ) );
CreateMenuString( headerName ); // make sure it isn't too long
whichItem = UMenuUtils::InsertMenuItem(mHand, headerName, whichItem); // returns actual insert loc
sMenu->SetCommand(whichItem, cmd_ToolsHierItem);
// ¥ Are there actually any menu items to put on this Hierarchical menu?
if (EDT_NumberOfPlugins(CategoryIndex)) {
// ¥ do we have any hierarchical menus left?
if (nextMenuID <= cEditorPluginsLastHierMenuID) {
LMenu* subMenu = (LMenuBar::GetCurrentMenuBar())->FetchMenu( nextMenuID );
if ( !subMenu )
{
StringHandle menuStringH = GetString( NEW_RESID );
Assert_(menuStringH);
if (menuStringH)
{
StHandleLocker locker((Handle)menuStringH);
subMenu = new LMenu( nextMenuID,
(unsigned char *)*menuStringH );
LMenuBar::GetCurrentMenuBar()->InstallMenu( subMenu, hierMenu );
}
}
else
SysBeep( 1 );
nextMenuID++;
if ( subMenu )
{
sMenusList.InsertItemsAt( 1, sMenusList.GetCount(), &subMenu );
// ¥Êmake item hierarchical
::SetItemCmd( mHand, whichItem, hMenuCmd );
::SetItemMark( mHand, whichItem, subMenu->GetMenuID() );
FillMenu(
CategoryIndex,
subMenu,
commandNum,
0 );
}
} else {
// ¥ There are no hierarchical menus left,
// so we will just add these onto the bottom of the main tools menu.
// We have already put the (disabled) category name in the main tools menu
FillMenu(
CategoryIndex,
sMenu,
commandNum,
whichItem );
whichItem += EDT_NumberOfPlugins(CategoryIndex);
}
}
}
// this is a hack. The menu item "Stop Active Plug-in" gets pushed around and loses its command. So, reset it.
sMenu->SetCommand(++whichItem, cmd_EditorPluginStop);
}
Catch_( inErr )
{
}
EndCatch_
sInvalidMenu = true;
}
void CToolsAttachment::FillMenu(
int32 CategoryIndex,
LMenu* newMenu,
int& commandNum, // next menu to create
int whichItem ) // id of the first item to insert
{
Try_
{
ThrowIfNil_( newMenu );
MenuHandle mHand = newMenu->GetMacMenuH();
ThrowIfNil_( mHand );
for (int32 PluginIndex = 0; PluginIndex < EDT_NumberOfPlugins(CategoryIndex); PluginIndex++) {
// ¥ should really convert this to sMenu chars
CStr255 pluginName( EDT_GetPluginName( CategoryIndex, PluginIndex) );
CreateMenuString( pluginName );
whichItem = UMenuUtils::InsertMenuItem(mHand, pluginName, whichItem); // returns actual insert loc
newMenu->SetCommand(whichItem, commandNum++);
}
}
Catch_( inErr )
{
}
EndCatch_
}
void CToolsAttachment::RemoveMenus()
{
if (sMenu)
{
LMenuBar *currentMenuBar = LMenuBar::GetCurrentMenuBar();
if (currentMenuBar)
{
currentMenuBar->RemoveMenu(sMenu);
for (ArrayIndexT index = 1; index <= sMenusList.GetCount(); ++index)
{
LMenu *menu;
sMenusList.FetchItemAt(index, &menu);
if (menu)
currentMenuBar->RemoveMenu(menu);
}
}
}
}
void CToolsAttachment::InstallMenus()
{
if (sMenu)
{
LMenuBar *currentMenuBar = LMenuBar::GetCurrentMenuBar();
if (currentMenuBar)
{
for (ArrayIndexT index = sMenusList.GetCount(); index > 0; --index)
{
LMenu *menu;
sMenusList.FetchItemAt(index, &menu);
if (menu)
{
StValueChanger<EDebugAction> okayToFail(gDebugThrow, debugAction_Nothing);
currentMenuBar->InstallMenu(menu, hierMenu);
}
}
StValueChanger<EDebugAction> okayToFail(gDebugThrow, debugAction_Nothing);
currentMenuBar->InstallMenu(sMenu, InstallMenu_AtEnd);
}
}
}

Просмотреть файл

@ -397,10 +397,10 @@ OSErr CPluginHandler::InitCodeResource(NPNetscapeFuncs* funcs, _np_handle* handl
OSErr err = noErr;
#ifdef DEBUG
EDebugAction oldThrow = gDebugThrow;
EDebugAction oldSignal = gDebugSignal;
gDebugThrow = debugAction_Nothing;
gDebugSignal = debugAction_Nothing;
EDebugAction oldThrow = UDebugging::gDebugThrow;
EDebugAction oldSignal = UDebugging::gDebugSignal;
UDebugging::gDebugThrow = debugAction_Nothing;
UDebugging::gDebugSignal = debugAction_Nothing;
#endif
Try_
{
@ -474,8 +474,8 @@ OSErr CPluginHandler::InitCodeResource(NPNetscapeFuncs* funcs, _np_handle* handl
EndCatch_
CPrefs::UseApplicationResFile(); // Revert the resource chain
#ifdef DEBUG
gDebugThrow = oldThrow;
gDebugSignal = oldSignal;
UDebugging::gDebugThrow = oldThrow;
UDebugging::gDebugSignal = oldSignal;
#endif
return err;
}

Просмотреть файл

@ -1,401 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
// Handle creating and maintaining the top-level bookmarks menu. It pulls the info
// out of the RDF container the user designates as their "quickfile menu" and listens
// to the messages from RDF to update it.
#include "CBookmarksAttachment.h"
#include "htrdf.h"
#include "CNetscapeWindow.h"
#include "URDFUtilities.h"
#include "net.h"
#include "resgui.h"
#include "uapp.h"
#include "macutil.h"
#include "UMenuUtils.h"
#include <Icons.h>
#include <Sound.h>
LMenu *CBookmarksAttachment::sMenu = NULL;
Boolean CBookmarksAttachment::sInvalidMenu = true;
LArray CBookmarksAttachment::sMenusList; // this will use the default constructor
HT_View CBookmarksAttachment::sQuickfileView = NULL;
const uint32 PERM_BOOKMARK_ITEMS = 2;
const CommandT cmd_BookmarkHierItem = BOOKMARKS_MENU_BASE_LAST;
//===========================================================
// CBookmarksAttachment
//===========================================================
CBookmarksAttachment::CBookmarksAttachment()
{
InitQuickfileView();
}
//
// InitQuickfileView
//
// Called at startup to get a new view from the HT backend that represents the
// bookmarks menu. This can be called multiple times without problems.
//
void
CBookmarksAttachment :: InitQuickfileView ( )
{
if ( ! sQuickfileView ) {
HT_Notification notifyStruct = CreateNotificationStruct();
HT_Pane quickfilePane = HT_NewQuickFilePane(notifyStruct);
sQuickfileView = HT_GetSelectedView(quickfilePane);
}
} // InitQuickfileView
void
CBookmarksAttachment :: HandleNotification( HT_Notification /* notifyStruct*/,
HT_Resource node, HT_Event event, void *token, uint32 tokenType)
{
switch (event) {
case HT_EVENT_NODE_ADDED:
case HT_EVENT_VIEW_REFRESH:
// only update menu if the quickfile view changes
//¥¥¥We need a way to not update on node_added events else we add items to the
//¥¥¥bookmarks menu on the order of N^2 where N is # of bookmarks.
if ( HT_GetView(node) == sQuickfileView ) {
sInvalidMenu = true;
UpdateMenu();
}
break;
case HT_EVENT_NODE_VPROP_CHANGED:
// optimization: only update when the name column changes
break;
case HT_EVENT_NODE_DELETED_DATA:
case HT_EVENT_NODE_DELETED_NODATA:
// free FE data, but don't update the menu yet (HT not in good state)
break;
} // case of which event
} // HandleNotification
// Processes:
//
void CBookmarksAttachment::ExecuteSelf( MessageT inMessage, void* ioParam )
{
mExecuteHost = FALSE;
switch ( inMessage )
{
CNetscapeWindow *bookmarkableWindow = nil;
case msg_CommandStatus:
{
SCommandStatus* status = (SCommandStatus*)ioParam;
switch ( status->command )
{
default:
if (CFrontApp::GetApplication()->HasBookmarksMenu())
{
if ( status->command >= BOOKMARKS_MENU_BASE && status->command <= BOOKMARKS_MENU_BASE_LAST )
{
*(status->enabled) = TRUE;
*(status->usesMark) = FALSE;
return;
}
}
break;
}
}
break;
default:
{
if (CFrontApp::GetApplication()->HasBookmarksMenu())
{
if ( inMessage >= BOOKMARKS_MENU_BASE && inMessage <= BOOKMARKS_MENU_BASE_LAST )
{
Uint32 index = inMessage - BOOKMARKS_MENU_BASE;
// load the url
HT_Resource itemNode = HT_GetNthItem(sQuickfileView, index);
char* url = HT_GetNodeURL( itemNode );
if ( !URDFUtilities::LaunchNode(itemNode) && url )
CFrontApp::DoGetURL ( url );
return;
}
}
}
break;
}
mExecuteHost = TRUE; // Let application handle it
}
void CBookmarksAttachment::AddToBookmarks( const char* url, const CStr255& title )
{
HT_Resource topNode = HT_TopNode ( sQuickfileView );
HT_AddBookmark ( const_cast<char*>(url), title );
}
LMenu *CBookmarksAttachment::GetMenu()
{
if (!sMenu)
{
sMenu = new LMenu(cBookmarksMenuID);
if (sMenu)
{
MenuHandle macMenu = sMenu->GetMacMenuH();
if (macMenu)
UMenuUtils::ConvertToIconMenu(macMenu, 15312);
}
}
return sMenu;
}
void CBookmarksAttachment::UpdateMenu()
{
if (CFrontApp::GetApplication()->HasBookmarksMenu())
{
if (!sInvalidMenu || !GetMenu() || !LMenuBar::GetCurrentMenuBar() )
return;
int i;
// ¥ delete all the dynamically created menus
// ¥Êdelete all the hierarchical menus we have added from the menubar
for ( i = 1; i <= sMenusList.GetCount(); i++ )
{
LMenu* m;
sMenusList.FetchItemAt( i, &m );
if ( m )
LMenuBar::GetCurrentMenuBar()->RemoveMenu( m );
delete m;
}
// ¥ delete all the menu items after the line in Bookmark menu
MenuHandle menu = sMenu->GetMacMenuH();
if ( menu )
{
int howMany = ::CountMItems( menu );
for ( i = howMany; i > PERM_BOOKMARK_ITEMS; i-- )
sMenu->RemoveItem( i );
}
sMenusList.RemoveItemsAt( sMenusList.GetCount(), 1 );
// ¥ walk through the list, and let the submenus be inserted recursively
int nextMenuID = cBookmarksFirstHierMenuID;
FillMenuFromList( HT_TopNode(sQuickfileView), sMenu, nextMenuID, PERM_BOOKMARK_ITEMS, 0 );
sInvalidMenu = false;
}
}
// ¥Êrecursively create submenus, given a list ptr
// returns NULL if the menu cannot be created
// it creates submenus recursively
void CBookmarksAttachment::FillMenuFromList(
HT_Resource top,
LMenu* newMenu,
int& nextMenuID, // next menu to create
int whichItem, // id of the first item to insert
int depth ) // how deep are we?
{
// keep us from infinite recursion if the data file contains an infinite loop
if ( depth > 4 )
return;
if (CFrontApp::GetApplication()->HasBookmarksMenu())
{
Try_
{
ThrowIfNil_( newMenu );
MenuHandle mHand = newMenu->GetMacMenuH();
ThrowIfNil_( mHand );
// ¥Êremove all the extra items if they exist
long removeThese = ::CountMItems( mHand ) - whichItem;
for ( long i = 1; i < removeThese; i++ )
newMenu->RemoveItem( whichItem );
MenuHandle theMacMenu = newMenu->GetMacMenuH();
// Open up the container and get an iterator on its contents (we have to open it before
// we can see anything inside it). If the cursor is null, it is probably because the container
// is locked so just put up a leaf item (disabled, of course) and bail.
HT_SetOpenState ( top, PR_TRUE );
HT_Cursor cursor = HT_NewCursor( top );
if ( !cursor ) {
whichItem = UMenuUtils::InsertMenuItem(theMacMenu, "\pLocked", whichItem);
newMenu->SetCommand(whichItem, 0);
return;
}
HT_Resource currNode = HT_GetNextItem(cursor);
while ( currNode )
{
if ( HT_IsSeparator(currNode) )
newMenu->InsertCommand( "\p-", cmd_Nothing, whichItem++ );
else if ( ! HT_IsContainer(currNode) )
{
// ¥ should really convert this to menu chars
CStr255 urlName( HT_GetNodeName(currNode) );
CreateMenuString( urlName );
whichItem = UMenuUtils::InsertMenuItem(theMacMenu, urlName, whichItem); // returns actual insert loc
newMenu->SetCommand(whichItem, BOOKMARKS_MENU_BASE + HT_GetNodeIndex(sQuickfileView, currNode) );
}
else
{
CStr255 headerName( HT_GetNodeName(currNode) );
CreateMenuString( headerName );
whichItem = UMenuUtils::InsertMenuItem(theMacMenu, headerName, whichItem); // returns actual insert loc
newMenu->SetCommand(whichItem, cmd_BookmarkHierItem);
// ¥Êdo we have space to create more?
if ( nextMenuID <= cBookmarksLastHierMenuID)
{
LMenu* subMenu = (LMenuBar::GetCurrentMenuBar())->FetchMenu( nextMenuID );
if ( !subMenu )
{
StringHandle menuStringH = GetString( NEW_RESID );
Assert_(menuStringH);
if (menuStringH)
{
StHandleLocker locker((Handle)menuStringH);
subMenu = new LMenu( nextMenuID,
(unsigned char *)*menuStringH );
LMenuBar::GetCurrentMenuBar()->InstallMenu( subMenu, hierMenu );
}
}
else
SysBeep( 1 );
nextMenuID++;
// Skip the "Apple" menu or we're in deep donuts.
if (nextMenuID == MENU_Apple)
nextMenuID++;
if ( subMenu )
{
sMenusList.InsertItemsAt( 1, LArray::index_Last, &subMenu );
// ¥Êmake item hierarchical
::SetItemCmd( mHand, whichItem, hMenuCmd );
::SetItemMark( mHand, whichItem, subMenu->GetMenuID() );
if ( currNode )
FillMenuFromList( currNode, subMenu, nextMenuID, 0, depth+1 );
}
}
}
currNode = HT_GetNextItem ( cursor );
} // while
}
Catch_( inErr )
{
}
EndCatch_
}
}
void CBookmarksAttachment::RemoveMenus()
{
if (CFrontApp::GetApplication()->HasBookmarksMenu())
{
if (sMenu)
{
LMenuBar *currentMenuBar = LMenuBar::GetCurrentMenuBar();
if (currentMenuBar)
{
currentMenuBar->RemoveMenu(sMenu);
for (ArrayIndexT index = 1; index <= sMenusList.GetCount(); ++index)
{
LMenu *menu;
sMenusList.FetchItemAt(index, &menu);
if (menu)
currentMenuBar->RemoveMenu(menu);
}
}
}
}
}
void CBookmarksAttachment::InstallMenus()
{
if (CFrontApp::GetApplication()->HasBookmarksMenu())
{
if (GetMenu())
{
LMenuBar *currentMenuBar = LMenuBar::GetCurrentMenuBar();
if (currentMenuBar)
{
for (ArrayIndexT index = sMenusList.GetCount(); index > 0; --index)
{
LMenu *menu;
sMenusList.FetchItemAt(index, &menu);
if (menu)
{
StValueChanger<EDebugAction> okayToFail(gDebugThrow, debugAction_Nothing);
currentMenuBar->InstallMenu(menu, hierMenu);
}
}
StValueChanger<EDebugAction> okayToFail(gDebugThrow, debugAction_Nothing);
currentMenuBar->InstallMenu(sMenu, InstallMenu_AtEnd);
#if 0
// no more Guide menu. Leave this here in case mktg wants to replace it with something (pinkerton).
LMenu *directoryMenu = currentMenuBar->FetchMenu(cDirectoryMenuID);
if (directoryMenu)
{
CFrontApp::BuildConfigurableMenu( directoryMenu->GetMacMenuH(), "menu.places.item" );
for (short index2 = CountMItems(directoryMenu->GetMacMenuH()); index2 > 0; --index2)
directoryMenu->SetCommand(index2, DIR_MENU_BASE + index2 - 1);
}
#endif
}
}
}
}

Просмотреть файл

@ -1,670 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
// InternetConfig.cp
//
// Created by Tim Craycroft, 2/9/96
//
#include "InternetConfig.h"
#include <ICAPI.h>
#include <ICKeys.h>
#include <LListener.h>
#include <LPeriodical.h>
#include "xp_core.h"
#include "xp_str.h"
#include "uprefd.h"
#include "prefapi.h" // ns/modules/libpref
#include "ufilemgr.h"
#include "resgui.h"
//
// InternetConfig class.
//
// Checks the IC seed on resume events
//
class CInternetConfig
{
public:
static void Connect();
static void Disconnect();
static ICError GetInternetConfigString(ConstStr255Param icKey,
Str255 s,
long *port = nil);
static ICError GetInternetConfigFileMapping( OSType fileType,
OSType creator,
ConstStr255Param fileName,
ICMapEntry *ent);
static ICError MapFileName( ConstStr255Param filename, ICMapEntry *ent );
static ICError GetFileSpec( ConstStr255Param icKey , FSSpec & ioSpec );
static ICError LaunchInternetConfigApplication(ConstStr255Param key);
#ifndef MOZ_MAIL_NEWS
static ICError SendInternetConfigURL(char *address);
#endif
static int UseICPrefCallback(const char *prefString, void *);
static void ResumeEvent();
static Boolean CurrentlyUsingIC();
static Boolean HaveICInstance();
private:
CInternetConfig();
~CInternetConfig();
void SynchIf(); // iff the seed has changed
void SynchFromIC();
ICError SynchStringFromIC( ConstStr255Param icKey,
CPrefs::PrefEnum netscapePref,
Boolean stripPort = false,
const char *xpPortPrefName = nil,
int32 defaultPort = 0);
ICError SynchSplitStringFromIC( ConstStr255Param icKey,
char divider,
CPrefs::PrefEnum firstString,
CPrefs::PrefEnum secondString,
Boolean stripPort = false);
ICError SyncFileSpec ( ConstStr255Param icKey, CPrefs::PrefEnum netscapePref );
ICError GetICString( ConstStr255Param icKey,
Str255 s,
int32 *port = nil);
ICError GetFSSpec( ConstStr255Param icKey , FSSpec & ioSpec );
ICError GetICFileMapping( OSType fileType,
OSType creator,
ConstStr255Param fileName,
ICMapEntry *ent);
ICError MapICFileName( ConstStr255Param filename, ICMapEntry *ent );
ICError LaunchICApplication(ConstStr255Param key);
#ifndef MOZ_MAIL_NEWS
ICError SendICURL(char *address);
#endif
ICInstance fInstance;
SInt32 fSeed;
static CInternetConfig* sInternetConfigConnection;
};
void
CInternetConfigInterface::ResumeEvent()
{
CInternetConfig::ResumeEvent();
}
//
// ConnectToInternetConfig
//
// Only public entrypoint to this InternetConfig module.
//
// gets the folder from CPrefs::GetFilePrototype(prefSpec(, MainFolder)
//
void
CInternetConfigInterface::ConnectToInternetConfig()
{
// I assume that this is only called once, at startup.
const char *useICPrefName = "browser.mac.use_internet_config";
PREF_RegisterCallback(useICPrefName, CInternetConfig::UseICPrefCallback, nil);
try
{
if (CInternetConfig::CurrentlyUsingIC())
{
CInternetConfig::Connect();
}
}
catch(ICError err)
{
// do something ? a dialog perhaps ?
// only if there is a real problem, not if
// IC just isn't installed.
}
}
void
CInternetConfigInterface::DisconnectFromInternetConfig()
{
CInternetConfig::Disconnect();
}
Boolean
CInternetConfigInterface::CurrentlyUsingIC(void)
{
Boolean returnValue = TRUE;
returnValue = returnValue && CInternetConfig::CurrentlyUsingIC();
returnValue = returnValue && CInternetConfig::HaveICInstance();
return returnValue;
}
void
CInternetConfigInterface::GetInternetConfigString( ConstStr255Param icKey,
Str255 s,
long *port)
{
if (CInternetConfig::GetInternetConfigString(icKey, s, port))
{
s[0] = 0;
}
}
ICError
CInternetConfigInterface::GetInternetConfigFileMapping( OSType fileType,
OSType creator,
ConstStr255Param fileName,
ICMapEntry *ent)
{
return CInternetConfig::GetInternetConfigFileMapping(fileType, creator,
fileName, ent);
}
ICError CInternetConfigInterface::MapFileName( ConstStr255Param filename, ICMapEntry *ent )
{
return CInternetConfig::MapFileName( filename , ent );
}
#ifndef MOZ_MAIL_NEWS
ICError
CInternetConfigInterface::SendInternetConfigURL(char *address)
{
return CInternetConfig::SendInternetConfigURL(address);
}
#endif
ICError
CInternetConfigInterface::LaunchInternetConfigApplication(ConstStr255Param key)
{
return CInternetConfig::LaunchInternetConfigApplication(key);
}
ICError CInternetConfigInterface::GetFileSpec( ConstStr255Param icKey , FSSpec & ioSpec )
{
return CInternetConfig::GetFileSpec( icKey, ioSpec);
}
CInternetConfig*
CInternetConfig::sInternetConfigConnection = nil;
Boolean
CInternetConfig::CurrentlyUsingIC()
{
XP_Bool result;
const char *useICPrefName = "browser.mac.use_internet_config";
if (PREF_NOERROR != PREF_GetBoolPref(useICPrefName, &result))
{
result = false;
}
return (Boolean)result;
}
//
// CInternetConfig::Connect
//
// Call once to hook up with IC.
//
void
CInternetConfig::Connect()
{
if (!sInternetConfigConnection)
{
sInternetConfigConnection = new CInternetConfig();
}
}
//
// Bail
//
void
CInternetConfig::Disconnect()
{
if (sInternetConfigConnection != nil)
{
delete sInternetConfigConnection;
sInternetConfigConnection = nil;
}
}
Boolean
CInternetConfig::HaveICInstance(void)
{
Boolean returnValue = FALSE;
Connect();
if (sInternetConfigConnection != nil)
{
returnValue = (sInternetConfigConnection->fInstance != NULL);
}
return returnValue;
}
//
// CInternetConfig::CInternetConfig
//
CInternetConfig::CInternetConfig():
fInstance(NULL)
{
ICError err;
// Detect IC, if present
StValueChanger<EDebugAction> okayToFail(gDebugThrow, debugAction_Nothing);
err = ::ICStart(&fInstance, emSignature);
//ThrowIfOSErr_(err);
if (!err)
{
try
{
ICDirSpec prefDir[1];
ICDirSpecArrayPtr prefDirArray;
UInt32 dirCount = 0;
// what a wonderful api...
//
// Give IC the directory that contains the pref file we're using
// so it can look there for an IC config file.
prefDirArray = (ICDirSpecArrayPtr) &prefDir;
FSSpec prefSpec = CPrefs::GetFilePrototype(CPrefs::MainFolder);
prefDir[0].vRefNum = prefSpec.vRefNum;
prefDir[0].dirID = prefSpec.parID;
dirCount = 1;
err = ::ICFindConfigFile(fInstance, dirCount, prefDirArray);
ThrowIfOSErr_(err);
// Remember initial seed
err = ::ICGetSeed(fInstance, &fSeed);
ThrowIfOSErr_(err);
// Read prefs from IC
if (CurrentlyUsingIC())
{
SynchFromIC();
}
}
catch(ICError err)
{
// Close IC connection and pass the error along
::ICStop(fInstance);
fInstance = NULL;
// throw(err);
// we probably out to delete "this" as well
}
}
}
int
CInternetConfig::UseICPrefCallback(const char *, void *)
{
if (CInternetConfig::CurrentlyUsingIC())
{
Connect();
sInternetConfigConnection->SynchFromIC();
}
return 0; // You don't even want to know my opinion of this!
}
//
// CInternetConfig::~CInternetConfig
//
CInternetConfig::~CInternetConfig()
{
if (fInstance != NULL)
{
::ICStop(fInstance); // close IC connection
}
}
//
// CInternetConfig::SynchFromIC
//
// Reads IC settings and converts them to Netscape prefs
//
void
CInternetConfig::SynchFromIC()
{
ICError err;
err = ::ICBegin(fInstance, icReadOnlyPerm);
ThrowIfOSErr_(err);
// Again, this is lame.
//
// We should have a table of some sort
//
SynchStringFromIC(kICRealName, CPrefs::UserName);
SynchStringFromIC(kICEmail, CPrefs::UserEmail);
SynchStringFromIC(kICEmail, CPrefs::ReplyTo); // IC has no reply-to
SynchSplitStringFromIC(kICMailAccount, '@', CPrefs::PopID, CPrefs::PopHost, true);
SynchStringFromIC(kICSMTPHost, CPrefs::SMTPHost, true);
SynchStringFromIC(kICWWWHomePage, CPrefs::HomePage);
SynchStringFromIC(kICOrganization, CPrefs::Organization);
SynchStringFromIC(kICNNTPHost, CPrefs::NewsHost, true, "news.server_port", 119);
SyncFileSpec( kICDownloadFolder, CPrefs::DownloadFolder );
::ICEnd(fInstance);
}
void
CInternetConfig::SynchIf()
{
SInt32 seed;
if (::ICGetSeed(fInstance, &seed))
{
return;
}
if (seed != fSeed)
{
try
{
SynchFromIC();
}
catch(ICError err)
{
}
fSeed = seed;
}
}
//
// CInternetConfig::ResumeEvent
//
//
void
CInternetConfig::ResumeEvent()
{
if (CurrentlyUsingIC())
{
Connect();
sInternetConfigConnection->SynchIf();
}
}
//
// CInternetConfig::SynchStringFromIC
//
// Set a netscape string from an IC string
ICError
CInternetConfig::SynchStringFromIC( ConstStr255Param icKey,
CPrefs::PrefEnum netscapePref,
Boolean stripPort,
const char *xpPortPrefName,
int32 defaultPort)
{
char s[256];
ICError err;
int32 *portPtr = stripPort ? &defaultPort : nil;
err = GetICString(icKey, (unsigned char*) s, portPtr);
if (err == 0)
{
p2cstr((StringPtr)s);
CPrefs::SetString(s, netscapePref);
if (xpPortPrefName)
{
PREF_SetIntPref(xpPortPrefName, defaultPort);
}
}
return err;
}
//
// CInternetConfig::SynchSplitStringFromIC
//
// Takes a single IC string and splits it into two Netscape strings.
// Useful for machine@host.domain.com, or proxy.address:port type stuff
//
// If the divider can't be found, the entire string is put into the
// first netscape string and the second netscape string is set to '\0'
//
ICError
CInternetConfig::SynchSplitStringFromIC( ConstStr255Param icKey,
char divider,
CPrefs::PrefEnum firstString,
CPrefs::PrefEnum secondString,
Boolean stripPort)
{
char buffer[256];
char *s;
char *split;
ICError err;
s = buffer;
err = GetICString(icKey, (unsigned char *) s);
if (err != 0) return err;
p2cstr((StringPtr)s);
split = strchr(s, divider);
if (split != NULL)
{
*split = '\0';
if (stripPort)
{
char *colon = strchr(split+1, ':');
if (colon)
{
*colon = '\0';
}
}
CPrefs::SetString(split+1, secondString);
}
else
{
CPrefs::SetString('\0', secondString);
}
CPrefs::SetString(s, firstString);
return 0;
}
//
// CInternetConfig::GetICString
//
// Gets an IC string pref
//
ICError
CInternetConfig::GetInternetConfigString( ConstStr255Param icKey,
Str255 s,
long *port)
{
Connect();
return sInternetConfigConnection->GetICString(icKey, s, port);
}
//
// CInternetConfig::GetICString
//
// Gets an IC string pref
//
ICError
CInternetConfig::GetICString( ConstStr255Param icKey,
Str255 s,
int32 *port)
{
ICAttr attr;
long size = 256;
ICError result;
result = ::ICGetPref(fInstance, icKey, &attr, (Ptr)s, &size);
if (!result)
{
if (port)
{
char cString[256];
BlockMoveData(&s[1], cString, s[0]);
cString[s[0]] = '\0';
char *colon = strchr(cString, ':');
if (colon)
{
*colon = '\0';
s[0] = colon - cString;
++colon;
// IC supposedly supports notations like:
// news.netscape.com:nntp
// The protocol services don't seem to work in IC (or I'm to stupid
// to make them work), so we just check for this one value ("nntp")
// because that is the only protocol for which we support port numbers.
if (!XP_STRCASECMP("nntp", colon))
{
*port = 119;
}
else
{
// Add more protocols here if/when we suppor them.
long portFromICString;
int numargs = sscanf(colon, "%ld", &portFromICString);
if (1 == numargs)
{
if (portFromICString >= 0) // negative port numbers are not valid
{
*port = portFromICString;
}
}
// else we just use the default port
}
}
}
}
return result;
}
#ifndef MOZ_MAIL_NEWS
ICError
CInternetConfig::SendInternetConfigURL(char *address)
{
Connect();
return sInternetConfigConnection->SendICURL(address);
}
ICError
CInternetConfig::SendICURL(char *address)
{
if (address == NULL)
return icNoURLErr;
long selStart = 0;
long selEnd = strlen(address);
if( CInternetConfig::HaveICInstance() )
return ::ICLaunchURL(fInstance, "\p", address, selEnd, &selStart, &selEnd);
else
return icPrefNotFoundErr;
}
#endif
ICError
CInternetConfig::GetInternetConfigFileMapping( OSType fileType,
OSType creator,
ConstStr255Param filename,
ICMapEntry *ent)
{
Connect();
return sInternetConfigConnection->GetICFileMapping(fileType, creator, filename, ent);
}
ICError
CInternetConfig::GetICFileMapping( OSType fileType,
OSType creator,
ConstStr255Param filename,
ICMapEntry *ent)
{
if( CInternetConfig::HaveICInstance() )
return ::ICMapTypeCreator(fInstance, fileType, creator, filename, ent);
else
return icPrefNotFoundErr;
}
ICError
CInternetConfig::LaunchInternetConfigApplication(ConstStr255Param key)
{
Connect();
return sInternetConfigConnection->LaunchICApplication(key);
}
ICError
CInternetConfig::LaunchICApplication(ConstStr255Param key)
{
if (CInternetConfig::HaveICInstance())
return ::ICEditPreferences(fInstance, key);
else
return icPrefNotFoundErr;
}
ICError
CInternetConfig::MapFileName( ConstStr255Param filename, ICMapEntry *ent)
{
Connect();
return sInternetConfigConnection->MapICFileName(filename, ent);
}
ICError CInternetConfig::MapICFileName( ConstStr255Param filename, ICMapEntry *ent )
{
if( CInternetConfig::HaveICInstance() )
return ::ICMapFilename(fInstance, filename, ent);
else
return icPrefNotFoundErr;
}
ICError CInternetConfig::GetFileSpec( ConstStr255Param icKey , FSSpec & ioSpec )
{
Connect();
return sInternetConfigConnection->GetFSSpec(icKey, ioSpec);
}
ICError CInternetConfig::GetFSSpec( ConstStr255Param icKey , FSSpec & ioSpec )
{
ICFileSpec* spec;
ICAttr attr;
char buffer[512];
long size = 512;
ICError result;
result = ::ICGetPref(fInstance, icKey, &attr, buffer, &size);
if (!result)
{
spec = (ICFileSpec *) buffer;
CFileMgr::CopyFSSpec( spec->fss, ioSpec );
}
return result;
}
ICError CInternetConfig::SyncFileSpec ( ConstStr255Param icKey, CPrefs::PrefEnum netscapePref )
{
FSSpec icSpec;
ICError result = GetFSSpec( icKey, icSpec );
if( !result )
{
CPrefs::SetFolderSpec( icSpec , netscapePref );
}
return result;
}

Просмотреть файл

@ -2325,7 +2325,7 @@ void CBrowserWindow::HandleGetURLEvent(const AppleEvent &inAppleEvent,
char * winName = NULL;
#ifdef DEBUG
StValueChanger<EDebugAction> changeDebugThrow(gDebugThrow, debugAction_Nothing);
StValueChanger<EDebugAction> changeDebugThrow(UDebugging::gDebugThrow, debugAction_Nothing);
#endif
MoreExtractFromAEDesc::GetCString(inAppleEvent, keyDirectObject, url);
@ -2447,20 +2447,15 @@ void CBrowserWindow::HandleOpenURLEvent(const AppleEvent &inAppleEvent,
AEDesc &/*outResult*/,
CBrowserWindow *inBrowserWindow)
{
// The use of "volatile" in the following lines
// (a) generated compiler warnings, because they are passed to routines that
// are not declared with correspondingly volatile parameters.
// (b) do not appear to need to be volatile in the sense given (If they were
// declared as volatile char*, that would be another thing...
char * /*volatile*/ formData = NULL; // Do not free this
char * /*volatile*/ formHeader = NULL; // form headers (MIME type)
char * formData = NULL; // Do not free this
char * formHeader = NULL; // form headers (MIME type)
ProcessSerialNumber psn;
FSSpec fileSpec;
Boolean hasFileSpec = FALSE;
Boolean hasFormData = FALSE;
Boolean hasPSN = FALSE;
Boolean forceReload = FALSE;
OSErr volatile err;
OSErr err;
Size actualSize;
DescType realType;

Просмотреть файл

@ -1,977 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*====================================================================================*/
#pragma mark INCLUDE FILES
/*====================================================================================*/
#include "CDateView.h"
/*====================================================================================*/
#pragma mark TYPEDEFS
/*====================================================================================*/
/*====================================================================================*/
#pragma mark CONSTANTS
/*====================================================================================*/
// Pane IDs
static const PaneIDT eDayEditFieldID = 1;
static const PaneIDT eMonthEditFieldID = 2;
static const PaneIDT eYearEditFieldID = 3;
// Resource IDs
static const short cArrowWidth = 11;
static const short cArrowHeight = 9;
static const UInt32 cBroadcastMessageDelay = 12;
/*====================================================================================*/
#pragma mark INTERNAL CLASS DECLARATIONS
/*====================================================================================*/
class CDateArrowButton : public LButton {
public:
enum { class_ID = 'DaBt' };
CDateArrowButton(LStream *inStream);
// When clicking in button, send these messages
enum { msg_ClickUpArrow = CDateView::paneID_UpButton,
msg_ClickDownArrow = CDateView::paneID_DownButton };
virtual void SimulateHotSpotClick(Int16 inHotSpot);
protected:
// Overriden methods
virtual void DisableSelf(void);
virtual void EnableSelf(void);
virtual Boolean TrackHotSpot(Int16 inHotSpot, Point inPoint, Int16 inModifiers);
virtual void HotSpotAction(Int16 inHotSpot, Boolean inCurrInside, Boolean inPrevInside);
virtual void HotSpotResult(short inHotSpot);
// Instance variables ==========================================================
UInt32 mNextBroadcastTime; // Last time a message was broadcast
UInt16 mBroadcastCount; // Number of continuous braodcast messages
};
/*====================================================================================*/
#pragma mark INTERNAL FUNCTION PROTOTYPES
/*====================================================================================*/
#ifdef Debug_Signal
#define AssertFail_(test) ThrowIfNot_(test)
#else // Debug_Signal
#define AssertFail_(test) ((void) 0)
#endif // Debug_Signal
static inline Boolean IsBetween(long inVal, long inMin, long inMax) {
return ((inVal >= inMin) && (inVal <= inMax));
}
/*====================================================================================*/
#pragma mark CLASS IMPLEMENTATIONS
/*====================================================================================*/
#pragma mark -
/*======================================================================================
Register classes related to this class.
======================================================================================*/
void CDateView::RegisterDateClasses(void) {
RegisterClass_(CDateView);
RegisterClass_(CDateField);
RegisterClass_(CDateArrowButton);
}
/*======================================================================================
Constructor.
======================================================================================*/
CDateView::CDateView(LStream *inStream) :
LView(inStream) {
mDayField = mMonthField = mYearField = nil;
}
/*======================================================================================
Constructor.
======================================================================================*/
void CDateView::FinishCreateSelf(void) {
// Load in date/time resources
Intl0Hndl int0H = (Intl0Hndl) ::GetIntlResource(0);
UInt8 leadingDayChar, leadingMonthChar, separatingChar;
if ( int0H ) {
switch ( (**int0H).dateOrder ) {
case mdy: mDayPosition = 2; mMonthPosition = 1; mYearPosition = 3; break;
case dmy: mDayPosition = 1; mMonthPosition = 2; mYearPosition = 3; break;
case ymd: mDayPosition = 3; mMonthPosition = 2; mYearPosition = 1; break;
case myd: mDayPosition = 3; mMonthPosition = 1; mYearPosition = 2; break;
case dym: mDayPosition = 1; mMonthPosition = 3; mYearPosition = 2; break;
default: /* ydm */ mDayPosition = 2; mMonthPosition = 3; mYearPosition = 1; break;
}
leadingDayChar = ((**int0H).shrtDateFmt & dayLdingZ) ? '0' : ' ';
leadingMonthChar = ((**int0H).shrtDateFmt & mntLdingZ) ? '0' : ' ';
separatingChar = (**int0H).dateSep;
} else {
// Set to defaults
separatingChar = '/';
leadingDayChar = '0';
leadingMonthChar = '0';
mDayPosition = 2;
mMonthPosition = 1;
mYearPosition = 3;
}
SetRefreshAllWhenResized(false);
// Must create the subpanes here for correct function of tabbed edit fields
CreateDateFields(leadingDayChar, leadingMonthChar, separatingChar);
}
/*======================================================================================
Destructor.
======================================================================================*/
CDateView::~CDateView(void) {
}
/*======================================================================================
Determine if the specified date is valid.
inYear (cMinViewYear..cMaxViewYear)
inMonth (1..12)
inDay (1..31)
======================================================================================*/
Boolean CDateView::IsValidDate(Int16 inYear, UInt8 inMonth, UInt8 inDay) {
if ( (inDay < 1) || (inDay > 31) || (inMonth < 1) || (inMonth > 12) ||
(inYear < cMinViewYear) || (inYear > cMaxViewYear) ) {
return false;
}
DateTimeRec dtRec = { inYear, inMonth, inDay, 1, 1, 1 };
UInt32 seconds;
::DateToSeconds(&dtRec, &seconds);
::SecondsToDate(seconds, &dtRec);
return ((inDay == dtRec.day) && (inMonth == dtRec.month) && (inYear == dtRec.year));
}
/*======================================================================================
Get the currently displayed date.
outYear (cMinViewYear..cMaxViewYear)
outMonth (1..12)
outDay (1..31)
======================================================================================*/
void CDateView::GetDate(Int16 *outYear, UInt8 *outMonth, UInt8 *outDay) {
*outYear = mYearField->GetValue();
*outMonth = mMonthField->GetValue();
*outDay = mDayField->GetValue();
}
/*======================================================================================
Set the displayed date to the date specified by the input parameters. If the
input parameters specify a date that is not valid, return false and don't do
anything; otherwise return true.
inYear (cMinViewYear..cMaxViewYear)
inMonth (1..12)
inDay (1..31)
======================================================================================*/
Boolean CDateView::SetDate(Int16 inYear, UInt8 inMonth, UInt8 inDay) {
Boolean rtnVal = IsValidDate(inYear, inMonth, inDay);
if ( rtnVal ) {
SetDateString(mYearField, inYear, '0');
SetDateString(mMonthField, inMonth, mMonthField->GetLeadingChar());
SetDateString(mDayField, inDay, mDayField->GetLeadingChar());
}
return rtnVal;
}
/*======================================================================================
Set the date displayed to today's date.
======================================================================================*/
void CDateView::SetToToday(void) {
UInt32 seconds;
::GetDateTime(&seconds);
DateTimeRec dtRec;
::SecondsToDate(seconds, &dtRec);
if ( dtRec.year < cMinViewYear ) {
dtRec.year = cMinViewYear;
} else if ( dtRec.year > cMaxViewYear ) {
dtRec.year = cMaxViewYear;
}
SetDate(dtRec.year, dtRec.month, dtRec.day);
}
/*======================================================================================
Select the specified date field in this view.
======================================================================================*/
void CDateView::SelectDateField(Int16 inField) {
PaneIDT paneID;
switch ( inField ) {
case eYearField: paneID = eYearEditFieldID; break;
case eMonthField: paneID = eMonthEditFieldID; break;
case eDayField: paneID = eDayEditFieldID; break;
default: Assert_(false); return;
}
CDateField *newTarget = (CDateField *) FindPaneByID(paneID);
Assert_(newTarget != nil);
if ( LCommander::SwitchTarget(newTarget) ) {
newTarget->SelectAll();
}
}
/*======================================================================================
Select the first date field in this view if one is not yet selected.
======================================================================================*/
void CDateView::Select(void) {
// Check if we're already there
if ( ContainsTarget() ) return;
// Find the first field
LEditField *newTarget;
if ( mDayPosition == 1 ) {
newTarget = mDayField;
} else if ( mMonthPosition == 1 ) {
newTarget = mMonthField;
} else {
Assert_(mYearPosition == 1);
newTarget = mYearField;
}
if ( LCommander::SwitchTarget(newTarget) ) {
newTarget->SelectAll();
}
}
/*======================================================================================
Return true if one of the date fields in this view is the current target.
======================================================================================*/
Boolean CDateView::ContainsTarget(void) {
return (mDayField->IsTarget() || mMonthField->IsTarget() || mYearField->IsTarget());
}
/*======================================================================================
Listen to message from broadcasters.
======================================================================================*/
void CDateView::ListenToMessage(MessageT inMessage, void *ioParam) {
#pragma unused(ioParam)
switch ( inMessage ) {
case CDateArrowButton::msg_ClickUpArrow:
case CDateArrowButton::msg_ClickDownArrow:
DoClickArrow(inMessage == CDateArrowButton::msg_ClickUpArrow);
break;
case CDateField::msg_HideDateArrows:
case CDateField::msg_ShowDateArrows:
ShowHideArrows(inMessage == CDateField::msg_ShowDateArrows);
break;
case CDateField::msg_UserChangedText:
BroadcastMessage(msg_DateViewChanged, this);
break;
}
}
/*======================================================================================
Process a click in an arrow from a key.
======================================================================================*/
void CDateView::DoKeyArrow(Boolean inClickUpArrow) {
LControl *theControl;
if ( inClickUpArrow ) {
theControl = (LControl *) FindPaneByID(paneID_UpButton);
} else {
theControl = (LControl *) FindPaneByID(paneID_DownButton);
}
if ( theControl && theControl->FocusDraw() ) {
theControl->SimulateHotSpotClick(1);
}
}
/*======================================================================================
Process a click in an arrow.
======================================================================================*/
void CDateView::DoClickArrow(Boolean inClickUpArrow) {
#pragma unused(inClickUpArrow)
CDateField *theDateField = (CDateField *) LCommander::GetTarget();
Assert_(theDateField);
if ( !theDateField ) return;
Int16 year;
UInt8 month, day;
GetDate(&year, &month, &day);
// Validate that the current character is OK for the active field
Int16 adder = inClickUpArrow ? 1 : -1;
switch ( theDateField->GetPaneID() ) {
case eDayEditFieldID:
day += adder;
if ( day > 31 ) {
day = 1;
} else if ( day < 1 ) {
day = 31;
}
break;
case eMonthEditFieldID:
month += adder;
if ( month > 12 ) {
month = 1;
} else if ( month < 1 ) {
month = 12;
}
break;
default:
year += adder;
if ( year > cMaxViewYear ) {
year = cMinViewYear;
} else if ( year < cMinViewYear ) {
year = cMaxViewYear;
}
break;
}
if ( !SetDate(year, month, day) ) {
if ( adder > 0 ) {
// Day must be wrong, too large!
SetDate(year, month, 1);
} else {
while ( !SetDate(year, month, --day) ) {
; // Nothing
}
}
}
}
/*======================================================================================
Hide or show the arrows.
======================================================================================*/
void CDateView::ShowHideArrows(Boolean inShow) {
ShowHideArrow(FindPaneByID(paneID_UpButton), inShow);
ShowHideArrow(FindPaneByID(paneID_DownButton), inShow);
}
/*======================================================================================
Filter for incoming data characters.
======================================================================================*/
EKeyStatus CDateView::DateFieldFilter(TEHandle inMacTEH, Char16 theKey, Char16& theChar, SInt16 inModifiers) {
EKeyStatus theKeyStatus = keyStatus_PassUp;
//Char16 theKey = inKeyEvent.message;
//Char16 theChar = theKey & charCodeMask;
CDateField *theDateField = (CDateField *) LCommander::GetTarget();
Assert_(theDateField);
CDateView *theDateView = (CDateView *) theDateField->GetSuperView();
Assert_(theDateView);
if ( !theDateField || !theDateView ) return theKeyStatus;
switch (theChar)
{
case char_UpArrow:
case char_DownArrow:
theKeyStatus = keyStatus_Ignore;
theDateView->DoKeyArrow(theChar == char_UpArrow);
break;
case char_Tab:
case char_Enter:
case char_Return:
case char_Escape:
theKeyStatus = keyStatus_PassUp;
break;
default:
if ( UKeyFilters::IsPrintingChar(theChar) && UKeyFilters::IsNumberChar(theChar) )
{
PaneIDT paneID = theDateField->GetPaneID();
Str15 currentText;
theDateField->GetDescriptor(currentText);
theKeyStatus = keyStatus_Input;
Int16 year;
UInt8 month, day;
theDateView->GetDate(&year, &month, &day);
// Validate that the current character is OK for the active field
Str15 numString;
long wouldBeNumber;
theDateField->GetDescriptor(numString);
Assert_(numString[0] == 2 || numString[0] == 4);
numString[numString[0] - 1] = currentText[currentText[0]];
numString[numString[0]] = theChar;
::StringToNum(numString, &wouldBeNumber);
switch ( paneID )
{
case eDayEditFieldID:
day = wouldBeNumber;
break;
case eMonthEditFieldID:
month = wouldBeNumber;
break;
default: // eYearEditFieldID
year = wouldBeNumber;
if ( year > cMaxViewYear ) year -= 100;
if ( year < cMinViewYear ) year += 100;
if (year != wouldBeNumber)
{
Str15 temp;
theDateField->GetDescriptor(temp);
temp[1] = '0' + year/1000;
temp[2] = '0' + (year/100)%10;
theDateField->SetDescriptor(temp);
}
break;
}
if ( !theDateView->IsValidDate(year, month, day) ||
((paneID != eYearEditFieldID) && (numString[1] == '0')) )
{
if ( theChar == '0' )
theKeyStatus = keyStatus_Reject;
else
{
currentText[1] = currentText[2] = theDateField->GetLeadingChar();
theDateField->SetDescriptor(currentText);
}
}
}
else
{
theKeyStatus = keyStatus_Reject;
}
break;
}
return theKeyStatus;
}
/*======================================================================================
Set the edit field date.
======================================================================================*/
void CDateView::SetDateString(LEditField *inField, UInt16 inValue, UInt8 inLeadingChar) {
Str15 valueString, tempString;
::NumToString(inValue, valueString);
if ( valueString[0] == 1 ) {
valueString[2] = valueString[1];
valueString[1] = inLeadingChar;
valueString[0] = 2;
}
inField->GetDescriptor(tempString);
if (! ::EqualString(tempString, valueString, false, false)) {
inField->SetDescriptor(valueString);
if ( inField->IsTarget() ) {
inField->SelectAll();
}
inField->Draw(nil);
}
}
/*======================================================================================
Show or hide the arrow nicely.
======================================================================================*/
void CDateView::ShowHideArrow(LPane *inArrow, Boolean inShow) {
if ( inArrow ) {
if ( inShow ) {
inArrow->DontRefresh(true);
if ( !inArrow->IsVisible() ) {
inArrow->Show();
inArrow->DontRefresh();
inArrow->Draw(nil);
}
} else {
inArrow->Hide();
}
}
}
/*======================================================================================
Finish creating the search dialog.
======================================================================================*/
void CDateView::CreateDateFields(UInt8 inLeadingDayChar, UInt8 inLeadingMonthChar,
UInt8 inSeparatingChar) {
// Init the panes in the view
UInt8 separatingString[2] = { 1, inSeparatingChar };
PaneIDT field1ID, field2ID, field3ID;
UInt8 leadingChar1, leadingChar2, leadingChar3;
switch ( mDayPosition ) {
case 1:
field1ID = eDayEditFieldID;
leadingChar1 = inLeadingDayChar;
if ( mMonthPosition == 2 ) {
field2ID = eMonthEditFieldID;
leadingChar2 = inLeadingMonthChar;
field3ID = eYearEditFieldID;
leadingChar3 = '0';
} else {
field3ID = eMonthEditFieldID;
leadingChar3 = inLeadingMonthChar;
field2ID = eYearEditFieldID;
leadingChar2 = '0';
}
break;
case 2:
field2ID = eDayEditFieldID;
leadingChar2 = inLeadingDayChar;
if ( mMonthPosition == 1 ) {
field1ID = eMonthEditFieldID;
leadingChar1 = inLeadingMonthChar;
field3ID = eYearEditFieldID;
leadingChar3 = '0';
} else {
field3ID = eMonthEditFieldID;
leadingChar3 = inLeadingMonthChar;
field1ID = eYearEditFieldID;
leadingChar1 = '0';
}
break;
default:
field3ID = eDayEditFieldID;
leadingChar3 = inLeadingDayChar;
if ( mMonthPosition == 1 ) {
field1ID = eMonthEditFieldID;
leadingChar1 = inLeadingMonthChar;
field2ID = eYearEditFieldID;
leadingChar2 = '0';
} else {
field2ID = eMonthEditFieldID;
leadingChar2 = inLeadingMonthChar;
field1ID = eYearEditFieldID;
leadingChar1 = '0';
}
break;
}
// Field 1
CDateField *theDateField = (CDateField *) FindPaneByID(paneID_DateField1);
ThrowIfResFail_(theDateField);
theDateField->SetPaneID(field1ID);
theDateField->SetLeadingChar(leadingChar1);
theDateField->SetKeyFilter(DateFieldFilter);
theDateField->AddListener(this);
// Separator 1
LCaption *theCaption = (LCaption *) FindPaneByID(paneID_Separator1);
ThrowIfResFail_(theCaption);
theCaption->SetDescriptor(separatingString);
// Field 2
theDateField = (CDateField *) FindPaneByID(paneID_DateField2);
ThrowIfResFail_(theDateField);
theDateField->SetPaneID(field2ID);
theDateField->SetLeadingChar(leadingChar2);
theDateField->SetKeyFilter(DateFieldFilter);
theDateField->AddListener(this);
// Separator 2
theCaption = (LCaption *) FindPaneByID(paneID_Separator2);
ThrowIfResFail_(theCaption);
theCaption->SetDescriptor(separatingString);
// Field 3
theDateField = (CDateField *) FindPaneByID(paneID_DateField3);
ThrowIfResFail_(theDateField);
theDateField->SetPaneID(field3ID);
theDateField->SetLeadingChar(leadingChar3);
theDateField->SetKeyFilter(DateFieldFilter);
theDateField->AddListener(this);
// Up/down arrows
LButton *theButton = (LButton *) FindPaneByID(paneID_UpButton);
ThrowIfResFail_(theButton);
theButton->AddListener(this);
theButton = (LButton *) FindPaneByID(paneID_DownButton);
ThrowIfResFail_(theButton);
theButton->AddListener(this);
mDayField = (CDateField *) FindPaneByID(eDayEditFieldID);
mMonthField = (CDateField *) FindPaneByID(eMonthEditFieldID);
mYearField = (CDateField *) FindPaneByID(eYearEditFieldID);
// Set the date to the current date
ShowHideArrows(eHideArrows);
SetToToday();
}
#pragma mark -
/*======================================================================================
Constructor.
======================================================================================*/
CDateField::CDateField(LStream *inStream) :
LGAEditField(inStream) {
mLeadingChar = '/';
Str15 initString = { 2, mLeadingChar, mLeadingChar };
SetDescriptor(initString);
}
/*======================================================================================
Set the text for the date field. This method does not refresh or redraw the
field after setting the text.
======================================================================================*/
void CDateField::SetDescriptor(ConstStr255Param inDescriptor) {
if ( FocusExposed() ) {
//StEmptyVisRgn emptyRgn(GetMacPort());
::TESetText(inDescriptor + 1, StrLength(inDescriptor), mTextEditH);
} else {
::TESetText(inDescriptor + 1, StrLength(inDescriptor), mTextEditH);
}
}
/*======================================================================================
Disallow pasting and cutting.
======================================================================================*/
void CDateField::FindCommandStatus(CommandT inCommand, Boolean &outEnabled,
Boolean &outUsesMark, Char16 &outMark,
Str255 outName) {
switch ( inCommand ) {
case cmd_Paste:
case cmd_Cut:
case cmd_Clear:
case cmd_SelectAll:
outEnabled = false;
break;
default:
LEditField::FindCommandStatus(inCommand, outEnabled, outUsesMark, outMark, outName);
break;
}
}
/*======================================================================================
Select all text when clicking.
======================================================================================*/
void CDateField::ClickSelf(const SMouseDownEvent &inMouseDown) {
#pragma unused(inMouseDown)
if ( !IsTarget() ) {
if ( LCommander::SwitchTarget(this) ) {
this->SelectAll();
}
}
}
/*======================================================================================
Handle a key press.
======================================================================================*/
Boolean CDateField::HandleKeyPress(const EventRecord &inKeyEvent) {
Boolean keyHandled;
if ( (inKeyEvent.modifiers & cmdKey) || !mKeyFilter ) {
keyHandled = LCommander::HandleKeyPress(inKeyEvent);
} else {
Char16 theChar = inKeyEvent.message & charCodeMask;
//EKeyStatus theKeyStatus = (*mKeyFilter)(inKeyEvent, (**mTextEditH).selStart);
EKeyStatus theKeyStatus = (*mKeyFilter)(mTextEditH, inKeyEvent.message & keyCodeMask, theChar, inKeyEvent.modifiers);
switch ( theKeyStatus ) {
case keyStatus_PassUp:
keyHandled = LCommander::HandleKeyPress(inKeyEvent);
break;
case keyStatus_Reject:
SysBeep(1);
break;
case keyStatus_Input: {
// Get the current string
Str15 numString;
GetDescriptor(numString);
Assert_(numString[0] == 2 || numString[0] == 4);
numString[numString[0] - 1] = numString[numString[0]];
numString[numString[0]] = theChar;
Boolean doDraw = FocusExposed();
SetDescriptor(numString);
SelectAll();
if ( doDraw ) {
DrawSelf();
}
keyHandled = true;
}
break;
}
}
return keyHandled;
}
/*======================================================================================
Select all text when clicking.
======================================================================================*/
void CDateField::AdjustCursorSelf(Point inPortPt, const EventRecord &inMacEvent) {
LPane::AdjustCursorSelf(inPortPt, inMacEvent);
}
/*======================================================================================
EditField is becoming the Target.
======================================================================================*/
void CDateField::BeTarget(void) {
StFocusAndClipIfHidden focus(this);
::TEActivate(mTextEditH); // Show active selection
BroadcastMessage(msg_ShowDateArrows);
}
/*======================================================================================
EditField is no longer the Target.
======================================================================================*/
void CDateField::DontBeTarget(void) {
StFocusAndClipIfHidden focus(this);
::TEDeactivate(mTextEditH); // Show inactive selection
BroadcastMessage(msg_HideDateArrows);
}
/*======================================================================================
The user has changed some text, broadcast a message.
======================================================================================*/
void CDateField::UserChangedText(void) {
LEditField::UserChangedText();
BroadcastMessage(msg_UserChangedText, this);
}
#pragma mark -
/*======================================================================================
Constructor.
======================================================================================*/
CDateArrowButton::CDateArrowButton(LStream *inStream) :
LButton(inStream) {
mNextBroadcastTime = 0;
mBroadcastCount = 0;
}
/*======================================================================================
======================================================================================*/
void CDateArrowButton::DisableSelf(void) {
Draw(nil);
}
/*======================================================================================
======================================================================================*/
void CDateArrowButton::EnableSelf(void) {
Draw(nil);
}
/*======================================================================================
======================================================================================*/
Boolean CDateArrowButton::TrackHotSpot(Int16 inHotSpot, Point inPoint, Int16 inModifiers) {
mBroadcastCount = 0;
mNextBroadcastTime = 0;
return LButton::TrackHotSpot(inHotSpot, inPoint, inModifiers);
}
/*======================================================================================
======================================================================================*/
void CDateArrowButton::HotSpotAction(Int16 inHotSpot, Boolean inCurrInside, Boolean inPrevInside) {
LButton::HotSpotAction(inHotSpot, inCurrInside, inPrevInside);
if ( inCurrInside ) {
if ( mNextBroadcastTime < LMGetTicks() ) {
BroadcastValueMessage();
if ( mBroadcastCount > 4 ) {
mNextBroadcastTime = LMGetTicks() + (cBroadcastMessageDelay/3);
} else {
++mBroadcastCount;
mNextBroadcastTime = LMGetTicks() + cBroadcastMessageDelay;
}
}
} else {
mBroadcastCount = 0;
}
}
/*======================================================================================
======================================================================================*/
void CDateArrowButton::HotSpotResult(short inHotSpot) {
if ( mBroadcastCount ) {
HotSpotAction(inHotSpot, false, true);
} else {
LButton::HotSpotResult(inHotSpot);
}
}
/*======================================================================================
======================================================================================*/
void CDateArrowButton::SimulateHotSpotClick(Int16 inHotSpot) {
if ( IsEnabled() ) {
mBroadcastCount = 0;
mNextBroadcastTime = 0;
unsigned long endTicks;
HotSpotAction(inHotSpot, true, false); // Do action for click inside
::Delay(4, &endTicks);
//HotSpotAction(inHotSpot, false, true); // Undo visual effect
HotSpotResult(inHotSpot);
::Delay(4, &endTicks);
}
}

Просмотреть файл

@ -135,7 +135,7 @@ void CButton::Draw(RgnHandle inSuperDrawRgnH)
StColorPenState::Normalize();
// Fail safe offscreen drawing
StValueChanger<EDebugAction> okayToFail(gDebugThrow, debugAction_Nothing);
StValueChanger<EDebugAction> okayToFail(UDebugging::gDebugThrow, debugAction_Nothing);
try
{
LGWorld theOffWorld(theFrame, 0, useTempMem);

Просмотреть файл

@ -108,7 +108,7 @@ void COffscreenCaption::Draw(RgnHandle inSuperDrawRgnH)
StColorPenState::Normalize();
// Fail safe offscreen drawing
StValueChanger<EDebugAction> okayToFail(gDebugThrow, debugAction_Nothing);
StValueChanger<EDebugAction> okayToFail(UDebugging::gDebugThrow, debugAction_Nothing);
try
{
LGWorld theOffWorld(theFrame, 0, useTempMem);

Просмотреть файл

@ -188,7 +188,7 @@ void CTabControl::Draw(RgnHandle inSuperDrawRgnH)
StColorPenState::Normalize();
// Fail safe offscreen drawing
StValueChanger<EDebugAction> okayToFail(gDebugThrow, debugAction_Nothing);
StValueChanger<EDebugAction> okayToFail(UDebugging::gDebugThrow, debugAction_Nothing);
try
{
LGWorld theOffWorld(theFrame, 0, useTempMem);