Skip to content
Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
21781 lines (19511 sloc) 631 KB
/////////////////////////////////////////////////////////////////
// TapirMail
//
// C program shell for rapid application development
// The Flying Pig!
// Started 17/7/2003
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
// Includes
#include "oslib/osmodule.h"
#include "oslib/messagetrans.h"
#include "oslib/wimp.h"
#include "oslib/dragasprite.h"
#include "oslib/macros.h"
#include "oslib/osfile.h"
#include "oslib/osfind.h"
#include "oslib/osgbpb.h"
#include "oslib/resolver.h"
#include "oslib/osbyte.h"
#include "oslib/colourtrans.h"
#include "oslib/wimpspriteop.h"
#include "oslib/territory.h"
#include "oslib/osword.h"
#include "oslib/mimemap.h"
#include "flexlib/flex.h"
#include "TapirMail.h"
#include "Mime.h"
#include "md5.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
#include <stddef.h>
#include "sys/byteorder.h"
#include "sys/select.h"
#include "Blowfish.h"
//#if defined _DEBUG
#include <clib/kernel.h>
//#endif
//////////////////////////////////////////////////////////////////
// Defines
#define WORDALIGN(b) (((b) + 3) & ~3)
#define RANGE(var,min,max) if ((var) < (min)) var = min; \
if ((var) > (max)) var = max;
#define DETAILS_MAX (512)
#define EDIT_MAX (30)
#define COLUMNS_MAX (7)
#define ROW_HEIGHT (40)
#define SENDER_MAX (64)
#define SUBJECT_MAX (128)
#define TO_MAX (1024)
#define CC_MAX (1024)
#define BCC_MAX (1024)
#define COLUMN_XOFFSET (0)
#define BUTTON_YOFFSET (80)
#define HEADER_HEIGHT (48)
#define ROW_YOFFSET (BUTTON_YOFFSET + HEADER_HEIGHT)
#define MAIN_PANE_HEIGHT (BUTTON_YOFFSET + HEADER_HEIGHT)
#define TEXT_X_OFFSET (16)
#define MILLIPOINT (400)
#define EMAIL_INVALID (-1)
#define EDIT_INVALID (-1)
#define EMAIL_TEXT_X_OFFSET (4)
#define EMAIL_TEXT_Y_OFFSET (128)
#define EDIT_TEXT_Y_OFFSET_MAX (172)
#define EDIT_TEXT_Y_OFFSET_MIN (116)
#define EDIT_HEAD_EXTENT_MAX (172)
#define EDIT_HEAD_EXTENT_MIN (116)
#define EMAIL_TEXT_WIDTH (600)
#define EMAIL_CHAR_WIDTH (77)
#define EMAIL_CHAR_XSIZE (18)
#define INDENT_CYCLE (4)
#define STYLE_BOLD (1 << 0)
#define STYLE_ITALIC (1 << 1)
#define STYLE_UNDERLINE (1 << 2)
#define STYLE_STRIKE (1 << 3)
#define STYLE_LINK (1 << 4)
#define STYLE_HIDDEN (1 << 5)
#define EDIT_CHARS_MAX (1024)
#define EDIT_LINE_MAX (1024)
#define DEFAULT_X_SCROLL (32)
#define DEFAULT_Y_SCROLL (32)
#define EDIT_CHARS_BLOCK (1024)
#define EDIT_LINE_BLOCK (1024)
#define EDIT_WIN_LINE_MIN (30)
#define EMAIL_TEXT_X_SCROLL (16)
#define RAMTRANSMIT_SIZE (10 * 1024)
#define NULL_POLL_FAST (1)
#define NULL_POLL_SLOW (10)
#define NULL_POLL_SLOWEST (20)
#define NULL_POLL_NETWORK (5)
#define MAIN_WIN_MIN_HEIGHT (ROW_YOFFSET + 1280)
#define SELECT_MEM_MIN (1024)
#define UID_MAX (80)
#define COMMAND_LEN (1024)
#define COMMAND_LEN_QUEUE (1032)
#define ACCOUNTS_SAVE "<TapirMail$ChoicesWrite>.Accounts"
#define ACCOUNTS_SAVE_DIR "<TapirMail$ChoicesWrite>"
#define ACCOUNTS_LOAD "<TapirMail$ChoicesDir>.Accounts"
#define LICENSE_SAVE "<TapirMail$LicenseWrite>.License"
#define LICENSE_SAVE_DIR "<TapirMail$LicenseWrite>"
#define LICENSE_LOAD "<TapirMail$LicenseDir>.License"
#define ADDRESS_SAVE "<TapirMail$LicenseWrite>.Addresses"
#define ADDRESS_SAVE_DIR "<TapirMail$LicenseWrite>"
#define ADDRESS_LOAD "<TapirMail$LicenseDir>.Addresses"
#define COLUMN_GAP (8)
#define BUFFERSIZE (1024*5)
#define COMMANDSIZE (1024*5)
#define Resolver_GetHost (0x46001)
#define SENDER_MAX (64)
#define SUBJECT_MAX (128)
#define MESSAGE_INVALID (-1)
#define ADDRESS_LEN_MAX (256)
#define ADDRESS_NUM_MAX (64)
#define CONNECTED_OFF_DELAY (15)
#define POP3_TIMEOUT (1 * 60 * 100)
#define SMTP_GENERIC_TIMEOUT (5 * 60 * 100)
#define SMTP_START_TIMEOUT (5 * 60 * 100)
#define SMTP_MAIL_TIMEOUT (5 * 60 * 100)
#define SMTP_RCPT_TIMEOUT (5 * 60 * 100)
#define SMTP_DATA_TIMEOUT (2 * 60 * 100)
#define SMTP_BLOCK_TIMEOUT (3 * 60 * 100)
#define SMTP_TERMINATION_TIMEOUT (10 * 60 * 100)
#define TERMINATION_TIMEOUT (1 * 60 * 100)
#define SMTP_DATAEND_DELAY (50)
#define STRING_LEN (1024)
#define TITLE_LEN (32)
#define PASS_LEN (STRING_LEN / 2)
#define ACCOUNT_MAX (20)
#define ACCOUNT_INVALID (-1)
#define COLUMN_WIDTH_MAX (1024)
#define COLUMN_REDRAW_ADD (-0)
#define COLUMN_PTR "ptr_autoscrh"
#define COLUMN_PTR_X (15)
#define COLUMN_PTR_Y (4)
#define DATE_FORMAT "%ZDY %M3 %24:%MI"
#define OPENWIN_OFFSET (-60)
#define OPENWIN_OFFSET_MAX (300)
#define FORWARD_DATE_FORMAT "%W3, %DY %M3 %CE%YR %24:%MI:%SE"
#define REPLY_DATE_FORMAT "%W3, %DY %M3 %CE%YR"
#define CHAR_BASE ('A')
#define MEMFILE_BLOCK (4096)
#define MENU_XPOS_OFFSET (-64)
#define ICONBAR_MENU_YPOS (96 + 44 * 7 + 24 * 2)
#define ICONBAR_MENU_YPOS_R (96 + 44 * 8 + 24 * 2)
#define REGISTERED (334446)
#define UNREGISTERED (874856)
#define CHECKSUM_INIT (11786)
#define SERIAL_INVALID (0)
#define MENU_ENTRY_NONE_LEN (32)
#define FONT_LIST_MAX (wimp_SIZEOF_MENU(1024))
#define FONT_LIST_IND_MAX (1024 * 8)
#define FONT_NAME_LENGTH (256)
#define ADDRESS_INVALID (-1)
#define ADDRESS_NAME_MAX (64)
#define ADDRESS_ADDRESS_MAX (128)
#define ADDRESSES_NUM_MAX (256)
#define ATTACHMENTS_NUM_MAX (256)
#define ATTACH_MENU_BUF_SIZE (4096)
#define ATTACH_NUM_TEXT_MAX (4)
#define ACCOUNT_OPEN_WIDTH (724)
#define ACCOUNT_OPEN_HEIGHT (948)
#define ACCOUNT_PANE_HEIGHT (92)
#define CHOICES_OPEN_WIDTH (724)
#define CHOICES_OPEN_HEIGHT (936)
#define CHOICES_PANE_HEIGHT (92)
#define SETTINGS_OPEN_WIDTH (724)
#define SETTINGS_OPEN_HEIGHT (684)
#define SETTINGS_PANE_HEIGHT (92)
#define PAGE_SCROLL_Y_ADD (-2)
#define SIG_LINE_NUM (4)
#define SIG_LINE_LENGTH (80)
#define REPLY_INSERT_LEN (75)
#define EDIT_TITLE_LEN (16)
#define SMILEY_MAX (32)
#define SMILEY_NAME_LEN (12)
#define ATTACHMENT_EDIT_MAX (12)
#define FILETYPE_NAME_LEN (8)
#define MIME_BOUNDARY_LEN (34)
#define MIME_SUPPORT_LINES (4)
#define ATTACHMENT_INFO_DATE_FORMAT "\%24:\%mi:\%se \%dy-\%m3-\%ce\%yr"
//#define MAX_SEND_LEN (64)
//////////////////////////////////////////////////////////////////
// Structures
typedef enum
{
STATE_INVALID = -1,
STATE_DISCONNECTED,
STATE_CREATESOCKET,
STATE_RESOLVING,
STATE_CONNECT,
STATE_CONNECTING,
STATE_CONNECTED,
STATE_POP3_AUTHORIZATION,
STATE_POP3_TRANSACTION,
STATE_POP3_QUIT,
STATE_SMTP_AUTHORIZATION,
STATE_SMTP_TRANSACTION,
STATE_SMTP_QUIT,
STATE_CANCEL,
STATE_FINISHED,
STATE_NUM
} STATE;
typedef enum
{
DETAILS_INVALID = -1,
DETAILS_NONE,
DETAILS_SIZE,
DETAILS_UID,
DETAILS_FULL,
DETAILS_DELETED,
DETAILS_NUM
} DETAILS;
typedef enum
{
AUTHSTATE_INVALID = -1,
AUTHSTATE_NOSENT,
AUTHSTATE_USERSENT,
AUTHSTATE_PASSSENT,
AUTHSTATE_HELOSENT,
AUTHSTATE_AUTHLOGIN,
AUTHSTATE_AUTHPLAIN,
AUTHSTATE_AUTHCRAMMD5,
AUTHSTATE_AUTHLOGINSENT,
AUTHSTATE_AUTHPLAINSENT,
AUTHSTATE_AUTHCRAMMD5SENT,
AUTHSTATE_AUTHLOGINUSERSENT,
AUTHSTATE_AUTHDONE,
AUTHSTATE_NUM
} AUTHSTATE;
typedef enum
{
POP3_TRANSTATE_INVALID = -1,
POP3_TRANSTATE_NOSENT,
POP3_TRANSTATE_STATSENT,
POP3_TRANSTATE_LISTSENT,
POP3_TRANSTATE_LIST,
POP3_TRANSTATE_UIDLLISTSENT,
POP3_TRANSTATE_UIDLLIST,
POP3_TRANSTATE_UIDLLISTDESYNC,
POP3_TRANSTATE_NEXTDETAILS,
POP3_TRANSTATE_TOPSENT,
POP3_TRANSTATE_TOPINTERPRET,
POP3_TRANSTATE_NEXTDOWNLOAD,
POP3_TRANSTATE_RETRUIDL,
POP3_TRANSTATE_SENDRETR,
POP3_TRANSTATE_RETRSENT,
POP3_TRANSTATE_RETRINTERPRET,
POP3_TRANSTATE_NEXTDELETE,
POP3_TRANSTATE_DELEUIDL,
POP3_TRANSTATE_SENDDELE,
POP3_TRANSTATE_DELESENT,
POP3_TRANSTATE_UIDDESYNC,
POP3_TRANSTATE_RETRFAIL,
POP3_TRANSTATE_DELEFAIL,
POP3_TRANSTATE_DONE,
POP3_TRANSTATE_NUM
} POP3_TRANSTATE;
typedef enum
{
SMTP_TRANSTATE_INVALID = -1,
SMTP_TRANSTATE_NOSENT,
SMTP_TRANSTATE_MAILSENT,
SMTP_TRANSTATE_RCPT,
SMTP_TRANSTATE_RCPTSENT,
SMTP_TRANSTATE_DATA,
SMTP_TRANSTATE_DATASENT,
SMTP_TRANSTATE_TEXT,
SMTP_TRANSSTATE_TEXTSENT,
SMTP_TRANSTATE_NEXTMAIL,
SMTP_TRANSTATE_DONE,
SMTP_TRANSTATE_NUM
} SMTP_TRANSTATE;
typedef enum
{
SOCK_INVALID = -1,
SOCK_OK,
SOCK_ERR,
SOCK_FAIL,
SOCK_WAIT,
SOCK_RECEIVE,
SOCK_MULTIDONE,
SOCK_NUM
} SOCK;
typedef enum
{
NET_INVALID = -1,
NET_POP3_LIST,
NET_POP3_DELETE,
NET_POP3_DOWNLOAD,
NET_SMTP_SEND,
NET_NUM
} NET;
typedef enum
{
SMTP_SENDTEXT_INVALID = -1,
SMTP_SENDTEXT_HEADERFROM,
SMTP_SENDTEXT_HEADERTO,
SMTP_SENDTEXT_HEADERCC,
SMTP_SENDTEXT_HEADERSUBJECT,
SMTP_SENDTEXT_HEADERDATE,
SMTP_SENDTEXT_HEADERUSERAGENT,
SMTP_SENDTEXT_HEADERMIME,
SMTP_SENDTEXT_HEADERCONTENTTYPE,
SMTP_SENDTEXT_HEADEREND,
SMTP_SENDTEXT_MIMESUPPORT,
SMTP_SENDTEXT_MIMESUPPORTEND,
SMTP_SENDTEXT_EMAILBOUNDARY,
SMTP_SENDTEXT_EMAILCONTENTTYPE,
SMTP_SENDTEXT_EMAILHEADEREND,
SMTP_SENDTEXT_EMAILTEXT,
SMTP_SENDTEXT_ATTACHMENTS,
SMTP_SENDTEXT_FAILED,
SMTP_SENDTEXT_FINISH,
SMTP_SENDTEXT_FINISHPAUSE,
SMTP_SENDTEXT_DATAEND,
SMTP_SENDTEXT_FINISHED,
SMTP_SENDTEXT_NUM
} SMTP_SENDTEXT;
typedef enum
{
SMTP_ATTACHMENTS_INVALID = -1,
SMTP_ATTACHMENTS_START,
SMTP_ATTACHMENTS_STARTATTACHMENT,
SMTP_ATTACHMENTS_BOUNDARY,
SMTP_ATTACHMENTS_HEADERCONTENTTYPE,
SMTP_ATTACHMENTS_HEADERCONTENTTYPEATTRIBUTES,
SMTP_ATTACHMENTS_HEADERCONTENTDISPOSITION,
SMTP_ATTACHMENTS_HEADERCONTENTENCODING,
SMTP_ATTACHMENTS_HEADEREND,
SMTP_ATTACHMENTS_DATA,
SMTP_ATTACHMENTS_DATAEND,
SMTP_ATTACHMENTS_FINALGAP,
SMTP_ATTACHMENTS_FINALBOUNDARY,
SMTP_ATTACHMENTS_FAILED,
SMTP_ATTACHMENTS_FINISH,
SMTP_ATTACHMENTS_NUM
} SMTP_ATTACHMENTS;
typedef enum
{
QUITSTATE_INVALID = -1,
QUITSTATE_QUIT,
QUITSTATE_QUITSENT,
QUITSTATE_NUM
} QUITSTATE;
typedef enum
{
CONNECTED_INVALID = -1,
CONNECTED_OFF,
CONNECTED_WAITING,
CONNECTED_SENDING,
CONNECTED_RECEIVING,
CONNECTED_NUM
} CONNECTED;
typedef enum
{
MAILSTATE_INVALID = -1,
MAILSTATE_LOCAL,
MAILSTATE_GETTING,
MAILSTATE_REMOTE,
MAILSTATE_DELETING,
MAILSTATE_NUM
} MAILSTATE;
typedef enum
{
PANE_INVALID = -1,
PANE_NONE,
PANE_TOP,
PANE_BASE,
PANE_NUM
} PANE;
typedef enum
{
SMTPAUTH_INVALID = -1,
SMTPAUTH_NONE,
SMTPAUTH_PLAIN,
SMTPAUTH_LOGIN,
SMTPAUTH_CRAMMD5,
SMTPAUTH_NUM
} SMTPAUTH;
typedef struct _Details
{
bool boSelected;
int nMsgNum;
int nSize;
int nServerSize;
char szSender[SENDER_MAX];
char szSenderDisplay[SENDER_MAX];
char szSubject[SUBJECT_MAX];
char pcDate[5];
DETAILS eState;
wimp_w whWindow;
wimp_w whHead;
char *szRawEmail;
char *szFormEmail;
int nHeaderEndLine;
int nLineHide;
int *anLine;
int *anRawLine;
int nLineMax;
bool boOpenOnLoad;
char szUID[UID_MAX];
int nSortPos;
wimp_i ihSenderIcon;
wimp_i ihSubjectIcon;
MAILSTATE eMailState;
MIMEDetails *asMIMEList;
int nMIMEListNum;
char *szPreMIMEEmail;
int nPreMIMESize;
char szAttachNum[ATTACH_NUM_TEXT_MAX];
wimp_i ihAttNumIcon;
} Details;
typedef struct _Edit
{
int nSize;
char szTo[TO_MAX];
char szSubject[SUBJECT_MAX];
char szCC[CC_MAX];
char szBCC[BCC_MAX];
wimp_w whWindow;
wimp_w whHead;
char *szRawEmail;
char *szFormEmail;
int *anLine;
int nLineMax;
int nFormattedTo;
bool boInsert;
bool boLineChange;
bool boAdvanced;
int nTextOffset;
bool boChanged;
char szWinTitle[EDIT_TITLE_LEN];
int nEmailMem;
int nLineMem;
char szAttachNum[ATTACH_NUM_TEXT_MAX];
int nMIMEListNum;
MIMEEditDetails asAttachments[ATTACHMENT_EDIT_MAX];
} Edit;
typedef struct _Selection
{
bool boEdit;
wimp_w whWindow;
int nEmailNum;
int nLineStart;
int nCharStart;
int nLineEnd;
int nCharEnd;
} Selection;
typedef struct _Caret
{
wimp_w whWindow;
int nEditNum;
int nLine;
int nChar;
int nPos;
int nXPos;
int nYPos;
int nCharPref;
} Caret;
typedef struct _Account
{
char szTitle[TITLE_LEN];
char szName[STRING_LEN];
char szEmailAddress[STRING_LEN];
char szPOP3Server[STRING_LEN];
int nPOP3Port;
char szPOP3Username[STRING_LEN];
bool boPOP3RememberPassword;
bool boPOP3GotPassword;
char szPOP3Password[PASS_LEN];
char szSMTPServer[STRING_LEN];
int nSMTPPort;
bool boBCCToSelf;
bool boCCBCC;
char szBCCAddress[STRING_LEN];
SMTPAUTH eSMTPAuth;
bool boSMTPUsePOP3Details;
char szSMTPUsername[STRING_LEN];
bool boSMTPRememberPassword;
bool boSMTPGotPassword;
char szSMTPPassword[PASS_LEN];
char szSigLine[SIG_LINE_NUM][SIG_LINE_LENGTH];
} Account;
typedef struct _MemFile
{
char *pcMemory;
int nSize;
int nPos;
char cMode;
char szFilename[1024];
} MemFile;
typedef struct _Address
{
char szName[ADDRESS_NAME_MAX];
char szAddress[ADDRESS_ADDRESS_MAX];
} Address;
typedef struct _Smiley
{
char szName[SMILEY_NAME_LEN];
int nNameLength;
int nOffset;
} Smiley;
typedef enum _SAVETYPE
{
SAVETYPE_INVALID = -1,
SAVETYPE_FILE,
SAVETYPE_EMAILS,
SAVETYPE_ICONTEXT,
SAVETYPE_SELECTCHOOSE,
SAVETYPE_COLUMN,
SAVETYPE_SELECTSAVE,
SAVETYPE_CLIPBOARD,
SAVETYPE_ATTACHMENT,
SAVETYPE_NUM
} SAVETYPE;
typedef enum _LOADTYPE
{
LOADTYPE_INVALID = -1,
LOADTYPE_EDITTEXT,
LOADTYPE_EDITMIME,
LOADTYPE_NUM
} LOADTYPE;
typedef enum
{
RELPOS_INVALID = -1,
RELPOS_BEFORE,
RELPOS_WITHINSTART,
RELPOS_WITHINEND,
RELPOS_AFTER,
RELPOS_OTHEREMAIL,
RELPOS_NUM
} RELPOS;
typedef enum _NULLPOLL
{
NULLPOLL_INVALID = -1,
NULLPOLL_ACTIVE_FAST,
NULLPOLL_ACTIVE_SLOW,
NULLPOLL_DEACTIVE_FAST,
NULLPOLL_DEACTIVE_SLOW,
NULLPOLL_ACTIVE_NETWORK,
NULLPOLL_DEACTIVE_NETWORK,
NULLPOLL_RESET,
NULLPOLL_NUM
} NULLPOLL;
typedef enum _QUERYACTION
{
QUERYACTION_INVALID = -1,
QUERYACTION_NONE,
QUERYACTION_STOP,
QUERYACTION_DELETEACCOUNT,
QUERYACTION_DELETEEMAILS,
QUERYACTION_DELETEADDRESS,
QUERYACTION_QUIT,
QUERYACTION_CLOSEEDIT,
QUERYACTION_NUM
} QUERYACTION;
typedef enum _ADDRESSMENU
{
ADDRESSMENU_INVALID = -1,
ADDRESSMENU_ADDRESSES,
ADDRESSMENU_TO,
ADDRESSMENU_CC,
ADDRESSMENU_BCC,
ADDRESSMENU_NUM
} ADDRESSMENU;
typedef enum _DELETETYPE
{
DELETETYPE_INVALID = -1,
DELETETYPE_GUESS,
DELETETYPE_OS4,
DELETETYPE_OS5,
DELETETYPE_NUM
} DELETETYPE;
//////////////////////////////////////////////////////////////////
// Global variables
static int gnWimpVersion;
static wimp_poll_flags guPollFlags;
static char gpcTemp[256];
static char *gpcMessages;
static wimp_w gwhMain;
static wimp_w gwhSave;
static wimp_w gwhWarn;
static wimp_w gwhText;
static wimp_w gwhEdit;
static wimp_w gwhEdHe;
static wimp_w gwhEmHe;
static wimp_w gwhMaHe;
static wimp_w gwhQery;
static wimp_w gwhAcct;
static wimp_w gwhLogn;
static wimp_w gwhUnLk;
static wimp_w gwhChce;
static wimp_w gwhRegi;
static wimp_w gwhSett;
static wimp_w gwhAddr;
static wimp_w gwhAttc;
static wimp_w gwhAcBa;
static wimp_w gwhEdAt;
static wimp_w gwhChBa;
static wimp_w gwhSeBa;
static wimp_i gihIconBarIcon;
static int gnMenuWins = 0;
static wimp_w gawhMenuWinHandle[10];
static int gnMenuXpos = 0;
static int gnMenuYpos = 0;
static wimp_menu *gpcMenuCurrent = NULL;
static wimp_menu *gpcIconBarMenu;
static wimp_menu *gpcMainMenu;
static wimp_menu *gpcEmailMenu;
static wimp_menu *gpcLognMenu;
static wimp_menu *gpcAcctMenu;
static wimp_menu *gpcNewMenu;
static wimp_menu *gpcMainSelMenu;
static wimp_menu *gpcMainSendMenu;
static wimp_menu *gpcMainHiMenu;
static wimp_menu *gpcMainAcMenu;
static wimp_menu *gpcEmailEditMenu;
static wimp_menu *gpcEmailSendMenu;
static wimp_menu *gpcNewEditMenu;
static wimp_menu *gpcChoiceAcctMenu;
static wimp_menu *gpcLocalFontMenu;
static wimp_menu *gpcRemoteFontMenu;
static wimp_menu *gpcAddrMenu;
static wimp_menu *gpcAttcMenu;
static wimp_menu *gpcEditAttcMenu;
char *gpcAcctMenuBuffer;
char *gpcAddrMenuBuffer;
char *gpcFontMenuBuffer;
char *gpcAttcMenuBuffer;
char *gpcEdAtMenuBuffer;
static wimp_t gnTaskHandle;
static bool gboDrag = FALSE;
static char gacFontRef[256];
static int gnMessageMyRef = 0;
static SAVETYPE geSaveType = SAVETYPE_INVALID;
static LOADTYPE geLoadType = LOADTYPE_INVALID;
static int gnSaveFileType;
static char gszSaveString[255];
static font_f ghFont;
static font_f ghFontB;
static font_f ghEmailFont;
static font_f ghEmailBFont;
static font_f ghEmailIFont;
static font_f ghEmailBIFont;
static int gnDetailsNum;
static int gnEditNum;
static Details gasDetails[DETAILS_MAX];
static Edit gasEdit[EDIT_MAX];
static int ganSort[DETAILS_MAX + 1];
static int ganColWidth[COLUMNS_MAX];
static int gnRowHeight;
static int gnTextYOffset;
static int gnEmailRowHeight;
static int gnEmailTextYOffset;
static int gnEmailTextWidth;
static int gnEllipsisWidth;
static int gnEllipsisWidthB;
static wimp_w gawhEmailsOpen[DETAILS_MAX + 1];
static int ganEmailsOpen[DETAILS_MAX + 1];
static wimp_w gawhEditOpen[EDIT_MAX + 1];
static int ganEditOpen[EDIT_MAX + 1];
static int ganEmailSave[DETAILS_MAX];
static bool gboEditSave;
static int gnEmailSaveNum;
static int gnEmailSavePos;
static os_colour gauIndCol[] = {os_COLOUR_LIGHT_BLUE,
os_COLOUR_DARK_BLUE,
os_COLOUR_LIGHT_RED,
os_COLOUR_DARK_GREEN};
static Selection gsSelect;
static int gnSelectLineStart;
static int gnSelectCharStart;
static int gnEmailSelected;
static bool gboEditSelected;
static int gnEditSaveSelected;
static Caret gsCaret;
static char *gpcCopySelect;
static int gnCopySelectSize;
static bool gboCaretLost;
static int gnMyRef;
static bool gboDelete;
static bool gboClipClaimed;
static char *gpcClipboard;
static int gnClipboardSize;
static wimp_message_data_xfer gsMessageStore;
static wimp_t gthSender;
static char gpcRamTransBuffer[RAMTRANSMIT_SIZE];
static int gnRamTransRef;
static char * gpcRamTransPos;
static int gnRamTransEmailPos;
static int gnRamTransAttcPos;
static int gnRamTransLeft;
static int gnFastPollAcc;
static int gnSlowPollAcc;
static bool gboNetworkPoll;
static bool gboPointerEdit;
static int gnPointerEmail;
static bool gboLinkPointer;
static bool gboColumnPointer;
static os_t gnMonotonicTime;
static os_t gnTimeInc;
static osspriteop_area *gpcSprites;
static osspriteop_area *gpcEmoticons;
static os_t gnSMTPPause;
static char gszServer[COMMAND_LEN - 5];
static char gpcBuffer[BUFFERSIZE];
static int gnBufferStart = 0;
static char gpcCommand[COMMANDSIZE];
//static char gszCommand[COMMAND_LEN];
static AUTHSTATE geAuthState = AUTHSTATE_INVALID;
static POP3_TRANSTATE gePOP3TranState = POP3_TRANSTATE_INVALID;
static SMTP_TRANSTATE geSMTPTranState = SMTP_TRANSTATE_INVALID;
static QUITSTATE geQuitState = QUITSTATE_INVALID;
static int gnCurrentMsg;
#if defined _DEBUG
static STATE gePrevState = STATE_INVALID;
#endif
static STATE geState = STATE_INVALID;
static int gnAddress;
static socket_s gsSocket;
static int ganRETRAct[DETAILS_MAX + 1];
static int gnRETRActNum;
static int gnRETRActPos;
static int ganMAILAct[DETAILS_MAX + 1];
static int gnMAILActNum;
static int gnMAILActPos;
static int gnMAILActLine;
static int ganDELEAct[DETAILS_MAX + 1];
static int gnDELEActNum;
static int gnDELEActPos;
static Account gasAccount[ACCOUNT_MAX];
static int gnAccount;
static int gnAccountNum;
static int gnAccountDialogue;
static int gnAccountSettingsDialogue;
static int gnAccountLogin;
static NET geNetCom;
static int gnDownloadPos;
static int gnPort;
static char gaszToAddress[ADDRESS_LEN_MAX][ADDRESS_NUM_MAX];
static int gnToAddressNum;
static int gnCCAddressNum;
static int gnBCCAddressNum;
static int gnAllAddressNum;
static int gnToAddressPos;
static SMTP_SENDTEXT geSMTPSendTextState;
static char *gpcCurrentEmail;
static char gszProgTitle[128];
static int gnTotalMailSize;
static int gnTotalMailSizeTemp;
static CONNECTED geConnectStatus;
static os_t gnLastSendRecTime;
static os_t gnTimeoutTime;
static int gnDragColumn;
static int gnColumnXPosStart;
static int gnOpenOffset;
static int gnSelected;
static bool gboTentativeSelection;
static bool gboAccountsLoaded;
static char gszUnlockPassword[1024];
static char gszDateFormat[1024];
static bool gboLog;
static QUERYACTION geQueryAction;
static int gnRegistered = UNREGISTERED;
static char gszName[256];
static unsigned int guSerial = SERIAL_INVALID;
static int gnDefaultAccount = ACCOUNT_INVALID;
static int gnDefaultAccountDisplay = ACCOUNT_INVALID;
static char gszFont[FONT_NAME_LENGTH] = "Trinity.Medium";
static char gszFontB[FONT_NAME_LENGTH] = "Trinity.Bold";
static char gszLocalChoiceFont[FONT_NAME_LENGTH] = "";
static char gszRemoteChoiceFont[FONT_NAME_LENGTH] = "";
static int gnAddress = ADDRESS_INVALID;
static Address gasAddresses[ADDRESSES_NUM_MAX];
static int gnAddressNum;
static ADDRESSMENU geAddressMenuType;
static int gnAttachmentNum;
static bool gboSMTPAuthLOGIN;
static bool gboSMTPAuthPLAIN;
static bool gboSMTPAuthCRAMMD5;
static char gacBase16[16] = "0123456789abcdef";
static int gnEmailCharWidth = EMAIL_CHAR_XSIZE;
static wimp_w gwhWindowClose;
static DELETETYPE geDeleteTypeConfig;
static bool gboIyonixDelete;
static osspriteop_trans_tab *gpsTransTable = NULL;
static int gnSmileyNum;
static Smiley gasSmileys[SMILEY_MAX];
static bool gboEmoticons;
static char gszLoadFileName[MIME_FILENAME_MAX];
static int gnLoadFileType = 0;
static char gszMIMEBoundary[MIME_BOUNDARY_LEN];
static SMTP_ATTACHMENTS geSMTPAttachmentsState;
static int gnSMTPAttachmentsNum;
static int gnSMTPAttachmentsPos;
static char gszSendCommand[COMMAND_LEN_QUEUE];
static int gnSendCommandSent;
static int gnSendCommandLen;
static socket_s gsSendSocket;
static bool gboUIDDesync;
static char gacBoundaryCharList[64]
= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
#if defined _DEBUG
static int gnDebugQueued = 0;
static int gnDebugSent = 0;
#endif
#if defined MAX_SEND_LEN
static int gnMaxSendLen = MAX_SEND_LEN;
static int gnNullPollNetwork = NULL_POLL_NETWORK;
static bool gboFastSending = FALSE;
#endif
//////////////////////////////////////////////////////////////////
// Main application
void RedrawWindow (wimp_block *pcBlock);
void RedrawMain (wimp_draw *psRedraw);
void SetMainExtent (int nEmailMax);
void ClearAllSelected (void);
int EmailRow (int nYPos);
void ToggleSelectRow (int nRow);
void CreateEmailWindow (int nEmailNum);
void RedrawEmail (wimp_draw *psRedraw, int nEmailNum);
int CreateFormattedEmail (int nEmailNum);
void InsertEmailColour (char *szFormatted, int * pnMemory, os_colour uCol, os_colour uBack);
int CopyFormatted (char * szFrom, char * szTo, int nLen, os_colour uCol, os_colour uBack);
void CheckStyles (char * szWordStart, char * szWordEnd, unsigned int * puStyles);
void SelectReOrder (Selection *psSelection);
void InvertSelection (Selection * psSelect, wimp_draw *psRedraw);
void ChangeSelection (Selection * psNew);
void FindEmailCoords (int nEmailNum, int nXPos, int nYPos, int * pnLine, int * pnChar);
void DragSelectionBox (bool boEdit, int nEmailNum, int nXPos, int nYPos);
void NullPoll (wimp_block *pcBlock);
RELPOS PointRelativeSelection (bool boEdit, int nEmailNum, int nXPos, int nYPos, Selection * psSelect, int * pnLine, int * pnChar);
int CreateEditWindow (void);
int CreateEditWindowAddress (char * szAddress);
void RedrawEdit (wimp_draw *psRedraw, int nEditNum);
int FormatLines (int nEditNum, int nLineStart, int nLineEnd);
void ReFormat (int nEditNum, int nChangedLine, int nLineEnd, int * psStartLine, int * psEndLine);
void FindEditCoords (int nEditNum, int nXPos, int nYPos, int * pnLine, int * pnChar);
void SetCaretPos (int nEditNum, int nLine, int nChar);
void InsertChar (int nEditNum, int nPos, int nLine, char cChar);
void UpdateEditWindow (int nEditNum, int nStartLine, int nEndLine);
void MoveCaretRight (int nRight);
void MoveCaretLeft (int nLeft);
void MoveCaretDown (int nDown);
void MoveCaretUp (int nUp);
void DeleteChar (int nEditNum, int nPos, int nLine);
void DragCentred (int nXPos, int nYPos, char * szIconName);
bool DeleteSection (int nEditNum, Selection * psSelect);
void ShiftSelection (Caret * psCaretPre, Caret * psCaret);
void SearchCaretRight (char * szSearch);
void SearchCaretLeft (char * szSearch);
void InsertString (int nEditNum, int nPos, int nLine, char * szString);
void ShiftLines (int nEditNum, int nLineStart, int nLine, int nChar);
void LoseCaret (wimp_block *pcBlock);
void ScrollRequest (wimp_block *pcBlock);
void CreateEditSelect (int nEditNum, bool boEdit, char ** ppcMem, int * pnSize);
int CountNonControl (char * szString, int nLength);
void ClearCaret (void);
void InsertText (int nEditNum, int nPos, int nLine, char * szString, int nLength);
void InsertTextFlex (int nEditNum, int nPos, int nLine, char * * pszString, int nLength);
void ClearSelection (void);
void SetEditHeight (int nEditNum, int nLine);
void CopySelectToClip (void);
void ClearClipboard (void);
void DataRequest (wimp_block * pcBlock);
void ClaimEntity (wimp_block * pcBlock);
void LaunchURL (wimp_block * pcBlock);
void PasteClipboard (void);
void ScrollWindowToCaret (void);
void RamFetchReturned (wimp_block *pcBlock);
void SetNullPollActive (bool boActive);
void PointerEntering (wimp_block * pcBlock);
void PointerLeaving (wimp_block * pcBlock);
void FindWordAtCoords (bool boEdit, int nEmailNum, int nXPos, int nYPos, char ** pszWordStart, char ** pszWordEnd);
bool WordIsLink (char * szWordStart, char * szWordEnd);
int WordIsSmiley (char * szWordStart, char * szWordEnd);
void ClickOnURL (bool boEdit, int nEmailNum, int nXPos, int nYPos);
void PlotSmileys(font_f hFont, char *szPlotLine, int nXPos, int nYPos, int nPlotLen);
void OpenWindowInitPane (wimp_w whWindow, wimp_w whPane, PANE ePaneType);
void OpenWindowInitPaneCentreSize (wimp_w whWindow, wimp_w whPane, PANE ePaneType, int nWidth, int nHeight);
void OpenWindowInitPaneNew (wimp_w whWindow, wimp_w whPane, PANE ePaneType);
void ShowHeader (int nEmailNum, bool boShow);
void RedrawMainHead (wimp_draw *psRedraw);
void UpdateMain (int nRowStart, int nRowEnd);
void CompileSelectedList (void);
void DestroyEditWindow (int nEditNum);
char * TagArg (char * szTag, char * szArg0);
void ShowWarningTagArg (char * szTag, char * szArg0);
void SendEmail (int nEditNum);
void DestroyEmailWindow (int nEmailNum);
void DestroySelectedEmails (void);
void DeleteMultipleEmails (int nStartEmail, int nEndEmail);
void DeleteEmailDetails (int nEmailNum);
void RenumberQueues (int nDeletedEmail);
void SetIconSprite (char * szSprite, wimp_w whWindow, wimp_i ihIcon);
wimp_w LoadTemplateMaHe (char * szWindowTitle, osspriteop_area * pcSpriteArea);
STATE ImmediateUpdate (socket_s * psSocket);
void ShowQueryTag (char * szTag, char * szContinueTag, char * szCancelTag, QUERYACTION eAction);
void ShowQueryTagVolatile (char * szTag, char * szContinueTag, char * szCancelTag, QUERYACTION eAction);
void CloseQuery (void);
void ClearAccountDetails (int nAccount);
void SetAccountDetails (int nAccount);
void SetAccountSettingsDetails (int nAccount);
void SetAccountDialogue (int nAccount);
void SetAccountSettingsDialogue (int nAccount);
void GenerateAccountMenu (wimp_menu * pcMenu);
void OpenLoginMenu (void);
void OpenLoginWindow (int nShowAccount);
void SetLoginWindow (int nShowAccount);
void SetupIconbarMenu (void);
void MenuSelectIconbarAccount (int nAccount);
void LoginAccount (int nAccount);
void OpenMainLoginMenu (void);
void SaveAccountDetails (void);
void SaveSection (FILE * pfhFile, char * szSection);
void SaveDetail (FILE * pfhFile, char * szName, char * szDetails);
bool LoadAccountDetails (void);
int FindSection (FILE * pfhFile, char * szSection);
bool FindValue (FILE * pfhFile, int nSection, char * szName, char * szValue, int nValueLen);
void MouseClickMaHeWorkArea (int nXPos, int nYPos, int nButton);
void SortEmails (bool (*Compare)(int, int));
bool CompareSizeIncreasing (int nEmail1, int nEmail2);
bool CompareSizeDecreasing (int nEmail1, int nEmail2);
bool CompareMsgNumIncreasing (int nEmail1, int nEmail2);
bool CompareMsgNumDecreasing (int nEmail1, int nEmail2);
bool CompareSenderIncreasing (int nEmail1, int nEmail2);
bool CompareSenderDecreasing (int nEmail1, int nEmail2);
bool CompareSubjectIncreasing (int nEmail1, int nEmail2);
bool CompareSubjectDecreasing (int nEmail1, int nEmail2);
bool CompareDateIncreasing (int nEmail1, int nEmail2);
bool CompareDateDecreasing (int nEmail1, int nEmail2);
bool CompareMailStateIncreasing (int nEmail1, int nEmail2);
bool CompareMailStateDecreasing (int nEmail1, int nEmail2);
void InterpretDate (char * szTime, char * pcUTCTime);
void DateToText (char * pcUTCTime, char * szDate, int nStringLen);
int cmpstr (char * szString1, char * szString2);
void CopySenderDisplay (char * szCopyTo, char * szSender);
void CopySize (int nSize, char * szCopyTo);
void DragColumnWidth (int nXPos, int nYPos, int nColumn);
void SetColumnWidth (int nColumn, int nWidth);
void SetColumnFromScreen (int nColumn, int nXPos);
void CheckColumnEdgePointer (int nXPos, int nYPos);
void OpenAccountWindow (int nDialogueAccount);
void OpenAccountSettingsWindow (int nDialogueAccount);
void SetEmailSave (int nEmailNum, bool boEdit);
int EmailSaveSize (void);
void RamFetchEmails (wimp_block *pcBlock);
bool SetEmailSaveSelection ();
void CreateForwardMessage (int nEmailNum);
void CreateReplyMessage (int nEmailNum);
void AppendExtractedAddresses (char * szInput, char * szOutput, int nOutLen, bool boIncludeSelf);
void CreateReplyToAllMessage (int nEmailNum);
void SetSubMenu (wimp_menu * pcMain, int nItem, wimp_menu * pcSub);
void SetMenuItemGreyness (bool boState, wimp_menu * pcMenu, int nItem);
void SetMenuItemTicked (bool boTicked, wimp_menu * pcMenu, int nItem);;
void SelectAllEmails (void);
void InvertAllEmails (void);
void SetUpMainMenu (void);
void SetUpEmailMenu (void);
void SetUpNewMenu (void);
void OpenSelectedEmails (void);
void ScrambleData (int * anPlain, int * anBuffer, int nBufferLen, char * szPassword);
void UnscrambleData (int * anScrambled, int * anBuffer, int nBufferLen, char * szPassword);
void HexToString (char * szPlainText, int * anBuffer, int nBufferLen);
void StringToHex (char * szPlainText, int * anBuffer, int nBufferLen);
int LoadFileFlex (char * szFilename, char * * ppcMemory, int * pnSize);
char * memgets (char * str, int n, MemFile * psMemory);
int memseek (MemFile * psMemory, int pos, int from);
int memtell (MemFile * psMemory);
int FindSectionMem (MemFile * pfhFile, char * szSection);
bool FindValueMem (MemFile * pfhFile, int nSection, char * szName, char * szValue, int nValueLen);
int memputc (int c, MemFile * psMemory);
int memputs (char * str, MemFile * psMemory);
void SaveSectionMem (MemFile * pfhFile, char * szSection);
void SaveDetailMem (MemFile * pfhFile, char * szName, char * szDetails);
MemFile * memopen (char * filename, char * mode);
int memclose (MemFile * psMemFile);
void OpenUnlockWindow (void);
void OpenChoicesWindow (void);
void UnlockOkay (void);
void ChoicesOkay (void);
void SetChoicesDetails (void);
void SetChoicesDialogue (void);
void DeleteAccount (int nAccount);
void QueryContinue (void);
void QueryCancel (void);
bool TransferInProgress (void);
void PreQuit (void);
void Lock (void);
int ExtendLineMem (int nEditNum);
int ExtendEmailMem (int nEditNum);
int ExtendLineMemTo (int nEditNum, int nSize);
int ExtendEmailMemTo (int nEditNum, int nSize);
void FindAdditionalFonts (void);
void ReleaseAdditionalFonts (void);
void ModeChange (void);
void Register (void);
unsigned int CheckRegister (char * szName, unsigned int uKey);
void LoadLicense (void);
void SetRegistrationInfo (void);
void OpenRegisterWindow (void);
void RegisterCancel (void);
void GetOSVersion (char * szVersion, int nLength);
void OpenChoicesLoginMenu (void);
void SetChoicesAccount (int nShowAccount);
void GenerateAccountMenuOffset (wimp_menu * pcMenu, int nOffset);
void GenerateAccountMenuNone (wimp_menu * pcMenu);
void ShowChoicesAccount (int nShowAccount);
void OpenDefaultAccount (void);
void OpenChoicesLocalFontMenu (void);
void ChoicesLocalFontSelect (wimp_selection * psSelection);
void OpenChoicesRemoteFontMenu (void);
void ChoicesRemoteFontSelect (wimp_selection * psSelection);
void SetUpFontMenu (wimp_menu * pcMenu, char * szFont);
bool ChangeListFonts (char * szFont, char * szFontB);
void ShowAdvanced (int nEditNum, bool boShow);
void OpenAddressesWindow (int nAddress);
void SetAddressesDialogue (int nAddress);
void AddressesDialogueDelete (void);
void AddressesDialogueUpdate (void);
void AddressesDialogueNew (void);
void SaveAddressesDetails (void);
bool LoadAddressesDetails (void);
void GenerateAddressesMenu (ADDRESSMENU eMenuType);
void OpenAddressMenu (wimp_w whWindow, wimp_i ihIcon, ADDRESSMENU eMenuType);
void AddAddressToIcon (wimp_w whWindow, wimp_i ihIcon, int nAddress, int nMaxLen);
void AddFromToAddress (int nEmailNum);
void CloseWindowHandlePane (wimp_w whWindow, wimp_w whPane);
inline void EditChanged (int nEditNum);
void EditChangedInitial (int nEditNum);
void SetIconTextIncrement (char * szText, wimp_w whWindow, wimp_i ihIcon);
void IconTextIncrement (wimp_w whWindow, wimp_i ihIcon);
void SetDeleteType (DELETETYPE eDeleteType);
char * strnchr (char * szString, char cChar, int nLength);
char * strnzchr (char * szString, char cChar, int nLength);
void GenerateTransTable (void);
void PopulateSmileys (void);
void RedrawAllEmailEditWindows (void);
int ConvertString (char * szOutput, char * szInput, int nBufferLen);
//void POPloop (/*int argc, char * * argv*/);
void NetworkLoop (NET eNetCom);
void ShowWarning (os_error * sError);
STATE Resolve (char * szHostName, int * pnAddress);
#if defined _DEBUG
void PrintState (STATE eState);
#endif
SOCK CreateSocket (socket_s * psSocket);
STATE Connect (int nAddress, socket_s * psSocket, int nPort);
SOCK POP3SocketRead (socket_s * psSocket);
SOCK SendCommand (char * szCommand, socket_s * psSocket);
SOCK POP3RemoveLine (char * pcBuffer, int nLength, int * pnBufferStart);
STATE POP3Authorization (socket_s * psSocket);
STATE POP3Transaction (socket_s * psSocket);
STATE POP3Quit (socket_s * psSocket);
void ResetDetails (void);
SOCK SMTPSocketRead (socket_s * psSocket);
SOCK SMTPRemoveLine (char * pcBuffer, int nLength, int * pnBufferStart);
STATE SMTPAuthorization (socket_s * psSocket);
STATE SMTPTransaction (socket_s * psSocket);
STATE SMTPQuit (socket_s * psSocket);
void ParseAddresses (int nEditNum);
int AddressesToArray (char * szText, int nCount, int nMax);
void CheckNetCom (NET eNetCom);
void AddToRETRQueue (int nEmailNum);
void ShiftRETRQueue (void);
void AddToMAILQueue (int nEmailNum);
void ShiftMAILQueue (void);
void AddToDELEQueue (int nEmailNum);
void ShiftDELEQueue (void);
void ShiftDELEQueueRedraw (void);
SMTP_TRANSTATE SMTPSendText (socket_s * psSocket, SOCK eReturnSend);
void SMTPMailSendSuccess (int nEditNum);
void SMTPMailSendFail (int nEditNum);
void PrintPOP3Transaction (POP3_TRANSTATE eState);
void CompileDeleteList (void);
void ClearPOP3Queues (void);
void SetConnectStatus (CONNECTED eStatus);
void ResetTimeout (os_t nTime);
void CheckTimeout (void);
void Cancel (void);
STATE CheckConnected (socket_s sSocket);
void CheckMIME (int nEmailNum);
void GenerateAttachmentMenu (wimp_menu * pcMenu, int nEmailNum);
void OpenAttachmentMenu (wimp_w whWindow, wimp_i ihIcon, int nEmailNum);
void GenerateEditAttachmentMenu (wimp_menu * pcMenu, int nEmailNum);
void OpenEditAttachmentMenu (wimp_w whWindow, wimp_i ihIcon, int nEmailNum);
void MenuWarning (wimp_block *pcBlock);
void AttachmentSave (void);
void SaveAttachment (char * szFilename);
void RamFetchAttachment (wimp_block *pcBlock);
void EditAttachmentsIconUpdate (int nEditNum);
bool AddFileToAttachmentsListFlex (int nEditNum, char * szFileName, int nFileType, char * * ppcStartFile, int nFileSize, bool boUseAttributes, unsigned int uLoad, unsigned int uExec, unsigned int uAccess);
void RemoveFileFromAttachmentsList (int nEditNum, int nAttachmentNum);
void SetEditAttachmentDetails (int nEditNum, int nAttachmentNum);
SMTP_SENDTEXT SMTPSendAttachments (socket_s * psSocket, SOCK eReturnSend);
SOCK SendCommandStart (char * szCommand, socket_s * psSocket);
SOCK SendCommandUpdate (void);
void SendCommandReset (void);
void SetSMTPAuthGreyness (void);
void EncodeMD5 (char * pcIn, int nInSize, char * pcOut);
void EncodeHMACMD5 (char * pcIn, int nInSize, char * pcKey, int nKeySize, char * pcOut);
// Respond to swi errors
inline void err (os_error * psError)
{
if (psError)
{
ShowWarning (psError);
}
}
//////////////////////////////////////////////////////////////////
// Log a string to reporter
inline void Log (char * szPrefix, char * szText)
{
char szLog[1024];
_kernel_swi_regs sRegs;
if (gboLog)
{
strncpy (szLog, szPrefix, 512);
strncat (szLog, szText, 512);
sRegs.r[0] = (int)szLog;
_kernel_swi (Report_Text0, & sRegs, & sRegs);
}
}
//////////////////////////////////////////////////////////////////
// Log a string to reporter
inline void LogVar (char * szFormat, int nVariable)
{
char szLog[1024];
_kernel_swi_regs sRegs;
if (gboLog)
{
sprintf (szLog, szFormat, nVariable);
sRegs.r[0] = (int)szLog;
_kernel_swi (Report_Text0, & sRegs, & sRegs);
}
}
// Main program
int main (int argc, char * * argv)
{
wimp_block cBlock;
int nCount;
int nSubCount;
wimp_event_no nEvent;
wimp_MESSAGE_LIST(12) sMessages = {{message_DATA_SAVE,
message_DATA_SAVE_ACK,
message_DATA_LOAD,
// message_DATA_OPEN,
message_RAM_FETCH,
message_RAM_TRANSMIT,
message_CLAIM_ENTITY,
message_DATA_REQUEST,
message_MODE_CHANGE,
message_HELP,
message_MENU_WARNING,
message_URL_LAUNCH,
0u}};
wimp_message_list *psUserMessages = (wimp_message_list*)&sMessages;
os_t nMonotonicTime;
int nAllocSuccess;
bool boEmailLaunch;
char szEmailLaunchTo[TO_MAX];
int nArgPos;
// Check for parameters
boEmailLaunch = FALSE;
szEmailLaunchTo[0] = 0;
nArgPos = 1;
while (nArgPos < argc)
{
REPORT (argv[nArgPos]);
if (strcmp (argv[nArgPos], "-url") == 0)
{
nArgPos++;
if (nArgPos < argc)
{
if (strncmp (argv[nArgPos], "mailto:", 7) == 0)
{
strncpy (szEmailLaunchTo, argv[nArgPos] + 7, TO_MAX);
}
else
{
strncpy (szEmailLaunchTo, argv[nArgPos], TO_MAX);
}
boEmailLaunch = TRUE;
}
}
nArgPos++;
}
// Variables
guPollFlags = FLAGS;
gnFastPollAcc = 0;
gnSlowPollAcc = 0;
gboNetworkPoll = FALSE;
gnTimeoutTime = -1;
gpcCurrentEmail = NULL;
gnOpenOffset = 0;
gnSelected = 0;
gboTentativeSelection = TRUE;
strcpy (gszUnlockPassword, "");
geQueryAction = QUERYACTION_NONE;
gnAddressNum = 0;
gnAttachmentNum = 0;
SetDeleteType (DELETETYPE_GUESS);
gboUIDDesync = FALSE;
#if defined MAX_SEND_LEN
gnMaxSendLen = MAX_SEND_LEN;
gnNullPollNetwork = NULL_POLL_NETWORK;
gboFastSending = FALSE;
#endif
// SetNullPollActive (NULLPOLL_ACTIVE_SLOW);
gboPointerEdit = FALSE;
gnPointerEmail = EMAIL_INVALID;
gboLinkPointer = FALSE;
gboColumnPointer = FALSE;
strncpy (gszDateFormat, DATE_FORMAT, sizeof (gszDateFormat));
gboLog = FALSE;
// Reset the account details
for (nCount = 0; nCount <= ACCOUNT_MAX; nCount++)
{
ClearAccountDetails (nCount);
}
gnAccountNum = 0;
gnAccount = ACCOUNT_INVALID;
gnAccountDialogue = ACCOUNT_INVALID;
gnAccountLogin = 0;
gnDefaultAccount = ACCOUNT_INVALID;
gnAccountSettingsDialogue = ACCOUNT_INVALID;
gnAddress = ADDRESS_INVALID;
geAddressMenuType = ADDRESSMENU_INVALID;
FindAdditionalFonts ();
// Set up blank edit structures
for (nCount = 0; nCount < EDIT_MAX; nCount++)
{
gasEdit[nCount].nSize = -1;
strcpy (gasEdit[nCount].szTo, "");
strcpy (gasEdit[nCount].szSubject, "");
strcpy (gasEdit[nCount].szCC, "");
strcpy (gasEdit[nCount].szBCC, "");
gasEdit[nCount].whWindow = wimp_BACKGROUND;
gasEdit[nCount].whHead = wimp_BACKGROUND;
gasEdit[nCount].szRawEmail = NULL;
gasEdit[nCount].szFormEmail = NULL;
gasEdit[nCount].boInsert = FALSE;
gasEdit[nCount].boLineChange = FALSE;
gasEdit[nCount].boAdvanced = FALSE;
gasEdit[nCount].nTextOffset = EDIT_TEXT_Y_OFFSET_MIN;
gasEdit[nCount].boChanged = FALSE;
strcpy (gasEdit[nCount].szWinTitle, "");
strncpy (gasEdit[nCount].szAttachNum, "0", ATTACH_NUM_TEXT_MAX);
gasEdit[nCount].nMIMEListNum = 0;
for (nSubCount = 0; nSubCount < ATTACHMENT_EDIT_MAX; nSubCount++)
{
ClearMIMEEditDetails (& gasEdit[nCount].asAttachments[nSubCount]);
}
gawhEditOpen[nCount] = wimp_BACKGROUND;
ganEditOpen[nCount] = EDIT_INVALID;
}
gawhEditOpen[EDIT_MAX] = wimp_BACKGROUND;
ganEditOpen[EDIT_MAX] = EDIT_INVALID;
gnEditNum = 0;
gwhWindowClose = 0;
// Set up some arbitrary details
ResetDetails ();
gnBufferStart = 0;
geState = STATE_DISCONNECTED;
gnRETRActNum = 0;
gnRETRActPos = 0;
gnMAILActNum = 0;
gnMAILActPos = 0;
gnDELEActNum = 0;
gnDELEActPos = 0;
geNetCom = NET_INVALID;
for (nCount = 0; nCount < (DETAILS_MAX + 1); nCount++)
{
ganRETRAct[nCount] = EMAIL_INVALID;
ganMAILAct[nCount] = EMAIL_INVALID;
ganDELEAct[nCount] = EMAIL_INVALID;
}
for (nCount = 0; nCount < DETAILS_MAX; nCount++)
{
ganEmailSave[nCount] = EMAIL_INVALID;
}
gnEmailSaveNum = 0;
gboEditSave = FALSE;
gnEmailSavePos = 0;
// for (nCount = 0; nCount < DETAILS_MAX; nCount++)
// {
// gasDetails[nCount].nMsgNum = nCount + 1;
// gasDetails[nCount].nSize = nCount * 15;
// gasDetails[nCount].boSelected = FALSE;
// sprintf (gasDetails[nCount].szSender, "sender%d@anon.com", nCount);
// sprintf (gasDetails[nCount].szSubject, "Here's email number %d", nCount);
// gasDetails[nCount].szRawEmail = NULL;
// gasDetails[nCount].whWindow = wimp_BACKGROUND;
// gasDetails[nCount].whHead = wimp_BACKGROUND;
// gawhEmailsOpen[nCount] = wimp_BACKGROUND;
// ganEmailsOpen[nCount] = EMAIL_INVALID;
// }
// gasDetails[0].szRawEmail = LoadFile ("<TapirMail$Dir>.Email1",
// & gasDetails[0].nSize);
// gasDetails[5].szRawEmail = LoadFile ("<TapirMail$Dir>.Email1",
// & gasDetails[5].nSize);
gnEmailSelected = EMAIL_INVALID;
gboEditSelected = FALSE;
gnEditSaveSelected = EDIT_INVALID;
gnTotalMailSize = 0;
gnTotalMailSizeTemp = 0;
ganColWidth[0] = 0;
ganColWidth[1] = ganColWidth[0] + 56;
ganColWidth[2] = ganColWidth[1] + 80;
ganColWidth[3] = ganColWidth[2] + 120;
ganColWidth[4] = ganColWidth[3] + 380;
ganColWidth[5] = ganColWidth[4] + 420;
ganColWidth[6] = ganColWidth[5] + 224;
gsSelect.boEdit = FALSE;
gsSelect.nLineStart = 20;
gsSelect.nCharStart = 15;
gsSelect.nLineEnd = 29;
gsSelect.nCharEnd = 11;
gsSelect.whWindow = wimp_BACKGROUND;
gsSelect.nEmailNum = EMAIL_INVALID;
gpcCopySelect = NULL;
gnCopySelectSize = 0;
gboClipClaimed = FALSE;
gpcClipboard = NULL;
gnClipboardSize = 0;
gboEmoticons = TRUE;
gnRamTransRef = -1;
gpcRamTransPos = NULL;
gnRamTransLeft = 0;
gnRamTransEmailPos = 0;
gnRamTransAttcPos = 0;
ClearCaret ();
gboCaretLost = TRUE;
gnMyRef = -1;
// Load Messages file
gpcMessages = osmodule_alloc (17 + sizeof(MESSAGES));
strcpy(gpcMessages + 16, MESSAGES);
messagetrans_open_file ((messagetrans_control_block*)gpcMessages,
gpcMessages + 16, 0);
// Initialise task
gnTaskHandle = wimp_initialise (wimp_VERSION_RO3, Tag ("Tsk"),
psUserMessages, & gnWimpVersion);
// Initialise the flex memory
strncpy (gszProgTitle, Tag("Tsk"), sizeof (gszProgTitle));
flex_init (gszProgTitle, 0, 0);
// Load license
LoadLicense ();
// Create a clipboard area
nAllocSuccess = flex_alloc ((flex_ptr)(& gpcCopySelect), SELECT_MEM_MIN);
if (nAllocSuccess == 0)
{
gpcCopySelect = NULL;
}
gnCopySelectSize = 0;
// Load templates
for (nCount = 0; nCount < 256; nCount++)
{
gacFontRef[nCount] = 0;
}
wimp_open_template (TEMPLATES);
gwhMain = LoadTemplate ("Main");
gwhSave = LoadTemplate ("Save");
gwhWarn = LoadTemplate ("Warning");
gwhText = LoadTemplate ("Text");
gwhEdit = LoadTemplate ("Edit");
gwhQery = LoadTemplate ("Query");
gwhAcct = LoadTemplate ("Account");
gwhLogn = LoadTemplate ("Login");
gwhUnLk = LoadTemplate ("Unlock");
gwhChce = LoadTemplate ("Choices");
gwhSett = LoadTemplate ("Settings");
gwhAddr = LoadTemplate ("Addresses");
gwhAttc = LoadTemplate ("SaveAttc");
gwhAcBa = LoadTemplate ("AccBase");
gwhChBa = LoadTemplate ("ChoBase");
gwhSeBa = LoadTemplate ("SetBase");
gwhEdAt = LoadTemplate ("EditAttc");
if (gnRegistered != REGISTERED)
{
gwhRegi = LoadTemplate ("Register");
}
else
{
gwhRegi = NULL;
}
SetIconText (Tag ("SaveEmail"), gwhSave, 2);
// Load sprites
gpcSprites = LoadSprites (SPRITES);
gwhEdHe = LoadTemplateSprites ("EditHead", gpcSprites);
gwhEmHe = LoadTemplateSprites ("EmailHead", gpcSprites);
// gwhMaHe = LoadTemplateSprites ("MainHead", gpcSprites);
gwhMaHe = LoadTemplateMaHe ("MainHead", gpcSprites);
// Load emoticon sprites
gpcEmoticons = LoadSprites (EMOTICONS);
PopulateSmileys ();
GenerateTransTable ();
// Create menus
if (gnRegistered != REGISTERED)
{
gpcIconBarMenu = CreateMenu (Tag ("Menu1R"));
}
else
{
gpcIconBarMenu = CreateMenu (Tag ("Menu1"));
}
gpcMainMenu = CreateMenu (Tag ("Menu2"));
gpcEmailMenu = CreateMenu (Tag ("Menu3"));
gpcNewMenu = CreateMenu (Tag ("Menu4"));
gpcMainSelMenu = CreateMenu (Tag ("Menu2-0"));
gpcMainSendMenu = CreateMenu (Tag ("Menu2-1"));
gpcMainHiMenu = CreateMenu (Tag ("Menu2-2"));
gpcMainAcMenu = CreateMenu (Tag ("Menu2-3"));
gpcEmailEditMenu = CreateMenu (Tag ("Menu3-0"));
gpcEmailSendMenu = CreateMenu (Tag ("Menu3-1"));
gpcNewEditMenu = CreateMenu (Tag ("Menu4-0"));
SetSubMenu (gpcMainMenu, 1, gpcMainSelMenu);
SetSubMenu (gpcMainMenu, 2, gpcMainSendMenu);
SetSubMenu (gpcMainMenu, 3, gpcMainHiMenu);
SetSubMenu (gpcMainMenu, 4, gpcMainAcMenu);
SetSubMenu (gpcEmailMenu, 2, gpcEmailEditMenu);
SetSubMenu (gpcEmailMenu, 3, gpcEmailSendMenu);
SetSubMenu (gpcNewMenu, 2, gpcNewEditMenu);
SetSubMenu (gpcMainSelMenu, 2, (wimp_menu*)gwhSave);
SetSubMenu (gpcEmailMenu, 0, (wimp_menu*)gwhSave);
SetSubMenu (gpcNewMenu, 0, (wimp_menu*)gwhSave);
SetMenuItemGreyness (TRUE, gpcEmailEditMenu, 0);
SetMenuItemGreyness (TRUE, gpcEmailEditMenu, 2);
SetMenuItemGreyness (TRUE, gpcEmailEditMenu, 4);
gpcLognMenu = (wimp_menu*)malloc (wimp_SIZEOF_MENU(ACCOUNT_MAX));
gpcAcctMenu = (wimp_menu*)malloc (wimp_SIZEOF_MENU(ACCOUNT_MAX));
gpcChoiceAcctMenu = (wimp_menu*)malloc
(wimp_SIZEOF_MENU((ACCOUNT_MAX + 1)));
gpcAcctMenuBuffer = (char *)malloc (256 + ACCOUNT_MAX * TITLE_LEN);
gpcIconBarMenu->entries[1].sub_menu = gpcAcctMenu;
gpcAddrMenu = (wimp_menu*)malloc (wimp_SIZEOF_MENU((ADDRESSES_NUM_MAX)));
gpcAddrMenuBuffer = (char *)malloc (32);
gpcAttcMenuBuffer = (char *)malloc (ATTACH_MENU_BUF_SIZE);
gpcEdAtMenuBuffer = (char *)malloc (ATTACH_MENU_BUF_SIZE);
gpcAttcMenu = (wimp_menu*)malloc (wimp_SIZEOF_MENU((ATTACHMENTS_NUM_MAX)));
gpcEditAttcMenu = (wimp_menu*)malloc
(wimp_SIZEOF_MENU((ATTACHMENTS_NUM_MAX)));
SetSubMenu (gpcEmailMenu, 1, gpcAttcMenu);
SetSubMenu (gpcNewMenu, 1, gpcEditAttcMenu);
// Create space for the font menus
gpcLocalFontMenu = (wimp_menu*)malloc (FONT_LIST_MAX);
gpcRemoteFontMenu = (wimp_menu*)malloc (FONT_LIST_MAX);
gpcFontMenuBuffer = malloc (FONT_LIST_IND_MAX);
// Close templates
wimp_close_template ();
// Set up the registration and version info
SetRegistrationInfo ();
SetIconText (VERSION_STRING_LONG, gawhMenuWinHandle[0], 3);
// Create icon
gihIconBarIcon = CreateIconbarIcon (Tag ("Icn"), 92, 68);
geConnectStatus = CONNECTED_INVALID;
SetConnectStatus (CONNECTED_OFF);
// Load account details
gboAccountsLoaded = LoadAccountDetails ();
LoadAddressesDetails ();
// Resize the main window
SetMainExtent (-1);
// Open an email window if -url argument set
if (boEmailLaunch)
{
if (gnAccountNum != 0)
{
CreateEditWindowAddress (szEmailLaunchTo);
boEmailLaunch = FALSE;
}
else
{
ShowWarningTag ("Er31");
}
}
xos_read_monotonic_time (& gnMonotonicTime);
srand (gnMonotonicTime);
gnTimeInc = NULL_POLL_SLOWEST;
// Main polling loop
//////////////////////////////////////////////////////////////////
do
{
nEvent = wimp_poll_idle (guPollFlags, & cBlock, gnMonotonicTime, NULL);
xos_read_monotonic_time (& nMonotonicTime);
if (nMonotonicTime > gnMonotonicTime)
{
gnMonotonicTime = nMonotonicTime + gnTimeInc;
}
switch (nEvent)
{
case 0: // Null
NullPoll (& cBlock);
break;
case 1: // Redraw window
RedrawWindow (& cBlock);
break;
case 2: // Open window
OpenWindow (& cBlock);
break;
case 3: // Closewindow
CloseWindow (& cBlock);
break;
case 4: // Pointer leaving window
PointerLeaving (& cBlock);
break;
case 5: // Pointer entering window
PointerEntering (& cBlock);
break;
case 6:
MouseClick (& cBlock);
break;
case 7: // User drag box
UserDragBox (& cBlock);
break;
case 8: // Keys
Keys (& cBlock);
break;
case 9:
MenuSelect (& cBlock);
break;
case 10: // Scroll request
ScrollRequest (& cBlock);
break;
case 11: // Lose caret
LoseCaret (& cBlock);
break;
case 12: // Gain caret
break;
case 17: // Receive message
case 18:
Receive (& cBlock);
break;
case 19: // UserMessage Acknowledge
Acknowledged (& cBlock);
break;
default: // Default
break;
}
} while TRUE;
//////////////////////////////////////////////////////////////////
return 0;
}
//////////////////////////////////////////////////////////////////
// Poll 16,17: Message received
void Receive (wimp_block *pcBlock)
{
switch (pcBlock->message.action)
{
case message_QUIT:
PreQuit ();
break;
case message_DATA_SAVE:
DataSave (pcBlock);
break;
case message_DATA_SAVE_ACK:
DataSaveAck (pcBlock);
break;
case message_DATA_LOAD:
DataLoad (pcBlock);
break;
// case message_DATA_OPEN:
// DataOpen (pcBlock);
// break;
case message_RAM_FETCH:
RamFetch (pcBlock);
break;
case message_RAM_TRANSMIT:
RamTransmit (pcBlock);
break;
case message_CLAIM_ENTITY:
ClaimEntity (pcBlock);
break;
case message_DATA_REQUEST:
DataRequest (pcBlock);
break;
case message_MODE_CHANGE:
ModeChange ();
case message_HELP:
Help (pcBlock);
break;
case message_MENU_WARNING:
MenuWarning (pcBlock);
break;
case message_URL_LAUNCH:
LaunchURL (pcBlock);
break;
}
}
//////////////////////////////////////////////////////////////////
// Poll 19: Message acknowledge received
void Acknowledged (wimp_block *pcBlock)
{
switch (pcBlock->message.action)
{
case message_RAM_FETCH:
RamFetchReturned (pcBlock);
break;
case message_URL_LAUNCH:
OpenURLReturned (pcBlock);
break;
}
gnMessageMyRef = 0;
}
//////////////////////////////////////////////////////////////////
// Pre quit
void PreQuit (void)
{
int nEditNum;
bool boChanged;
if (TransferInProgress ())
{
ShowQueryTag ("Ms4", "MsYes", "MsNo", QUERYACTION_QUIT);
}
else
{
nEditNum = 0;
boChanged = FALSE;
while ((!boChanged) && (nEditNum < EDIT_MAX))
{
if ((gasEdit[nEditNum].whWindow != wimp_BACKGROUND)
&& (gasEdit[nEditNum].boChanged))
{
boChanged = TRUE;
}
nEditNum++;
}
if (boChanged)
{
ShowQueryTag ("Ms7", "MsYes", "MsNo", QUERYACTION_QUIT);
}
else
{
Quit ();
}
}
}
//////////////////////////////////////////////////////////////////
// Quit task
void Quit (void)
{
int nCount;
int nRemove;
ReleaseAdditionalFonts ();
// Free the fonts
for (nCount = 0; nCount < 256; nCount++)
{
if (gacFontRef[nCount])
{
for (nRemove = 0; nRemove < gacFontRef[nCount]; nRemove++)
{
xfont_lose_font ((font_f)nCount);
}
}
}
// Close the program
wimp_close_down (gnTaskHandle);
}
//////////////////////////////////////////////////////////////////
// The edit window has been changed
inline void EditChanged (int nEditNum)
{
if (!gasEdit[nEditNum].boChanged)
{
EditChangedInitial (nEditNum);
}
}
//////////////////////////////////////////////////////////////////
// The edit window has been changed for the first time
void EditChangedInitial (int nEditNum)
{
wimp_window_info sWindow;
wimp_outline sOutline;
gasEdit[nEditNum].boChanged = TRUE;
sWindow.w = gasEdit[nEditNum].whWindow;
xwimp_get_window_info_header_only (& sWindow);
strncpy (sWindow.title_data.indirected_text.text,
Tag("EditTitle"), sWindow.title_data.indirected_text.size - 2);
strcat (sWindow.title_data.indirected_text.text, " *");
if (gnWimpVersion < 502)
{
// Non nested wimp
sOutline.w = gasEdit[nEditNum].whWindow;
xwimp_get_window_outline (& sOutline);
xwimp_force_redraw (wimp_BACKGROUND, sOutline.outline.x0,
sWindow.visible.y1, sOutline.outline.x1, sOutline.outline.y1);
}
else
{
// Nested wimp
xwimp_force_redraw_title (gasEdit[nEditNum].whWindow);
}
}
//////////////////////////////////////////////////////////////////
// Poll 6: Process mouse clicks
void MouseClick (wimp_block *pcBlock)
{
int nXPos = pcBlock->pointer.pos.x;
int nYPos = pcBlock->pointer.pos.y;
wimp_mouse_state nButton = pcBlock->pointer.buttons;
wimp_w whWindow = pcBlock->pointer.w;
wimp_i ihIcon = pcBlock->pointer.i;
char *szFileIcon;
int nEmailNum;
wimp_window_state sState;
int nWinXPos;
int nWinYPos;
Selection sSelect;
bool boWinFound;
int nEmailSearch;
int nEditSearch;
RELPOS eRelPos;
int nLine;
int nChar;
int nStartLine;
int nEndLine;
bool boClearSelect;
bool boRemember;
char szSnip[1024];
int nLength;
bool boUpdate;
boWinFound = FALSE;
sState.w = whWindow;
xwimp_get_window_state (& sState);
nWinXPos = nXPos - sState.visible.x0 + sState.xscroll;
nWinYPos = nYPos - sState.visible.y1 + sState.yscroll;
if (whWindow == wimp_ICON_BAR)
{
switch (nButton)
{
case wimp_CLICK_SELECT:
if (gboAccountsLoaded)
{
if (gnAccount != ACCOUNT_INVALID)
{
OpenWindowInitPane (gwhMain, gwhMaHe, PANE_TOP);
}
else
{
if (gnAccountNum > 0)
{
OpenLoginWindow (gnAccount);
}
else
{
OpenAccountWindow (ACCOUNT_INVALID);
}
}
}
else
{
OpenUnlockWindow ();
}
break;
case wimp_CLICK_MENU:
SetupIconbarMenu ();
if (gnRegistered == REGISTERED)
{
OpenMenu (gpcIconBarMenu, nXPos + MENU_XPOS_OFFSET,
ICONBAR_MENU_YPOS);
}
else
{
OpenMenu (gpcIconBarMenu, nXPos + MENU_XPOS_OFFSET,
ICONBAR_MENU_YPOS_R);
}
break;
case wimp_CLICK_ADJUST:
if (gboAccountsLoaded)
{
if (gnAccountNum > 0)
{
OpenLoginWindow (gnAccount);
}
else
{
OpenAccountWindow (ACCOUNT_INVALID);
}
}
else
{
OpenUnlockWindow ();
}
break;
}
boWinFound = TRUE;
}
if (whWindow == gwhMain)
{
if (nButton == wimp_CLICK_MENU)
{
SetUpMainMenu ();
if (gboTentativeSelection)
{
nEmailNum = EmailRow (nWinYPos);
// Clear current selection
ClearAllSelected ();
// Select an email
ToggleSelectRow (nEmailNum);
SetUpMainMenu ();
gboTentativeSelection = TRUE;
}
OpenMenu (gpcMainMenu, nXPos + MENU_XPOS_OFFSET, nYPos);
}
else
{
switch (ihIcon)
{
case -1: // Work area
nEmailNum = EmailRow (nWinYPos);
if (nButton & wimp_SINGLE_ADJUST)
{
// Select an email
ToggleSelectRow (nEmailNum);
}
if (nButton & wimp_SINGLE_SELECT)
{
if (!gasDetails[ganSort[nEmailNum]].boSelected)
{
// Clear current selection
ClearAllSelected ();
// Select an email
ToggleSelectRow (nEmailNum);
}
}
if ((nButton & wimp_DOUBLE_SELECT)
|| (nButton & wimp_DOUBLE_ADJUST))
{
if (nEmailNum != EMAIL_INVALID)
{
if (gasDetails[ganSort[nEmailNum]].szRawEmail)
{
CreateEmailWindow (ganSort[nEmailNum]);
}
else
{
gasDetails[ganSort[nEmailNum]].boOpenOnLoad = TRUE;
AddToRETRQueue (ganSort[nEmailNum]);
CheckNetCom (NET_POP3_DOWNLOAD);
}
}
}
if ((nButton & wimp_DRAG_SELECT)
|| (nButton & wimp_DRAG_ADJUST))
{
if (SetEmailSaveSelection ())
{
gnSaveFileType = 0xfff;
DragCentred (nXPos, nYPos, "file_fff");
geSaveType = SAVETYPE_EMAILS;
}
}
break;
default: // Save drag
if (nButton & (wimp_DRAG_SELECT | wimp_DRAG_ADJUST))
{
strncpy (gszSaveString, GetIconText (whWindow, ihIcon),
sizeof(gszSaveString));
DragBox (whWindow, ihIcon);
geSaveType = SAVETYPE_ICONTEXT;
}
break;
}
}
boWinFound = TRUE;
}
if (whWindow == gwhSave)
{
switch (ihIcon)
{
case (wimp_i)3: // Save drag
if (nButton & (wimp_DRAG_SELECT | wimp_DRAG_ADJUST))
{
szFileIcon = GetIconText (gwhSave, 3);
gnSaveFileType = 0xfff;
DragSprite (whWindow, ihIcon, "file_fff");
geSaveType = SAVETYPE_FILE;
}
break;
case (wimp_i)1: // Cancel
CloseMenu ();
break;
case (wimp_i)0: // Save
gnSaveFileType = 0xfff;
SaveSave ();
if (nButton != wimp_CLICK_ADJUST)
{
CloseMenu ();
}
break;
}
boWinFound = TRUE;
}
if (whWindow == gwhAttc)
{
switch (ihIcon)
{
case (wimp_i)3: // Save drag
if (nButton & (wimp_DRAG_SELECT | wimp_DRAG_ADJUST))
{
szFileIcon = GetIconText (gwhAttc, 3);
gnSaveFileType = gasDetails[gnEmailSelected]
.asMIMEList[gnAttachmentNum].nFileType;
DragSprite (whWindow, ihIcon, szFileIcon);
geSaveType = SAVETYPE_ATTACHMENT;
}
break;
case (wimp_i)1: // Cancel
CloseMenu ();
break;
case (wimp_i)0: // Save
gnSaveFileType = gasDetails[gnEmailSelected]
.asMIMEList[gnAttachmentNum].nFileType;
AttachmentSave ();
if (nButton != wimp_CLICK_ADJUST)
{
CloseMenu ();
}
break;
}
boWinFound = TRUE;
}
if (whWindow == gwhWarn)
{
switch (ihIcon)
{
case (wimp_i)0: // OK
CloseWarning ();
break;
}
boWinFound = TRUE;
}
if (whWindow == gwhQery)
{
switch (ihIcon)
{
case (wimp_i)0: // Continue
QueryContinue ();
break;
case (wimp_i)5: // Cancel
QueryCancel ();
break;
}
boWinFound = TRUE;
}
if (whWindow == gawhMenuWinHandle[0])
{
switch (ihIcon)
{
case (wimp_i)8: // Email
OpenURL (Tag("Email"));
if (nButton != wimp_CLICK_ADJUST)
{
CloseMenu ();
}
break;
case (wimp_i)9: // Website
OpenURL (Tag("Website"));
if (nButton != wimp_CLICK_ADJUST)
{
CloseMenu ();
}
break;
}
boWinFound = TRUE;
}
if (whWindow == gwhMaHe)
{
switch (ihIcon)
{
case (wimp_i)-1: // Work area
MouseClickMaHeWorkArea (nWinXPos, nWinYPos, nButton);
break;
case (wimp_i)1: // Download list
CheckNetCom (NET_POP3_LIST);
break;
case (wimp_i)2: // Download emails
CompileSelectedList ();
CheckNetCom (NET_POP3_DOWNLOAD);
break;
case (wimp_i)3: // Forget emails
DestroySelectedEmails ();
break;
case (wimp_i)4: // Delete emails
ShowQueryTag ("Ms3", "MsYes", "MsNo", QUERYACTION_DELETEEMAILS);
break;
case (wimp_i)5: // New email
CreateEditWindow ();
break;
case (wimp_i)6: // Stop operation
if (geConnectStatus != CONNECTED_OFF)
{
ShowQueryTag ("Ms1", "MsYes", "MsNo", QUERYACTION_STOP);
}
break;
case (wimp_i)7: // Invert selection
InvertAllEmails ();
break;
case (wimp_i)8: // Open Accounts menu
OpenMainLoginMenu ();
break;
default:
break;
}
boWinFound = TRUE;
}
if (whWindow == gwhAcct)
{
switch (ihIcon)
{
case (wimp_i)18: // POP3 remember password
boRemember = !GetIconSelectionState (gwhAcct, 18);
SetIconGreyness (boRemember, gwhAcct, 19);
SetIconGreyness (boRemember, gwhAcct, 20);
break;
case (wimp_i)31: // SMTP use POP3 details
case (wimp_i)34: // SMTP remember password
case (wimp_i)27: // None
case (wimp_i)28: // Plain
case (wimp_i)29: // Login
case (wimp_i)30: // Cram-MD5
SetSMTPAuthGreyness ();
break;
default:
break;
}
boWinFound = TRUE;
}
if (whWindow == gwhAcBa)
{
switch (ihIcon)
{
case (wimp_i)2: // OK
if (gnAccountDialogue == ACCOUNT_INVALID)
{
SetAccountDetails (gnAccountNum);
gnAccountDialogue = gnAccountNum;
gnAccountNum++;
}
else
{
SetAccountDetails (gnAccountDialogue);
SetLoginWindow (gnAccountLogin);
}
if (nButton == wimp_CLICK_SELECT)
{
CloseWindowHandlePane (gwhAcct, gwhAcBa);
}
break;
case (wimp_i)1: // Save
if (gnAccountDialogue == ACCOUNT_INVALID)
{
SetAccountDetails (gnAccountNum);
gnAccountDialogue = gnAccountNum;
gnAccountNum++;
}
else
{
SetAccountDetails (gnAccountDialogue);
SetLoginWindow (gnAccountLogin);
}
SaveAccountDetails ();
SaveAddressesDetails ();
if (nButton == wimp_CLICK_SELECT)
{
CloseWindowHandlePane (gwhAcct, gwhAcBa);
}
break;
case (wimp_i)0: // Cancel
if (nButton == wimp_CLICK_SELECT)
{
CloseWindowHandlePane (gwhAcct, gwhAcBa);
}
SetAccountDialogue (gnAccountDialogue);
break;
case (wimp_i)3: // Delete
ShowQueryTag ("Ms2", "MsYes", "MsNo", QUERYACTION_DELETEACCOUNT);
CloseWindowHandlePane (gwhAcct, gwhAcBa);
break;
default:
break;
}
boWinFound = TRUE;
}
if (whWindow == gwhSett)
{
switch (ihIcon)
{
default: // Save drag
if (nButton & (wimp_DRAG_SELECT | wimp_DRAG_ADJUST))
{
strncpy (gszSaveString, GetIconText (whWindow, ihIcon),
sizeof(gszSaveString));
DragBox (whWindow, ihIcon);
geSaveType = SAVETYPE_ICONTEXT;
}
break;
}
boWinFound = TRUE;
}
if (whWindow == gwhSeBa)
{
switch (ihIcon)
{
case (wimp_i)2: // OK
if (gnAccountSettingsDialogue != ACCOUNT_INVALID)
{
SetAccountSettingsDetails (gnAccountSettingsDialogue);
}
if (nButton == wimp_CLICK_SELECT)
{
CloseWindowHandlePane (gwhSett, gwhSeBa);
}
break;
case (wimp_i)1: // Save
if (gnAccountSettingsDialogue != ACCOUNT_INVALID)
{
SetAccountSettingsDetails (gnAccountSettingsDialogue);
}
SaveAccountDetails ();
SaveAddressesDetails ();
if (nButton == wimp_CLICK_SELECT)
{
CloseWindowHandlePane (gwhSett, gwhSeBa);
}
break;
case (wimp_i)0: // Cancel
if (nButton == wimp_CLICK_SELECT)
{
CloseWindowHandlePane (gwhSett, gwhSeBa);
}
SetAccountSettingsDialogue (gnAccountSettingsDialogue);
break;
}
boWinFound = TRUE;
}
if (whWindow == gwhLogn)
{
switch (ihIcon)
{
case (wimp_i)4: // OK
gasAccount[gnAccountLogin].boPOP3GotPassword = FALSE;
gasAccount[gnAccountLogin].boSMTPGotPassword = FALSE;
LoginAccount (gnAccountLogin);
if (nButton == wimp_CLICK_SELECT)
{
CloseWindowHandle (gwhLogn);
}
break;
case (wimp_i)3: // Cancel
if (nButton == wimp_CLICK_SELECT)
{
CloseWindowHandle (gwhLogn);
}
break;
case (wimp_i)0: // Account Menu
OpenLoginMenu ();
break;
default:
break;
}
boWinFound = TRUE;
}
if (whWindow == gwhUnLk)
{
switch (ihIcon)
{
case (wimp_i)1: // OK
UnlockOkay ();
if ((nButton == wimp_CLICK_SELECT) || gboAccountsLoaded)
{
CloseWindowHandle (gwhUnLk);
}
break;
case (wimp_i)0: // Cancel
if (nButton == wimp_CLICK_SELECT)
{
CloseWindowHandle (gwhUnLk);
}
break;
default:
break;
}
boWinFound = TRUE;
}
if (whWindow == gwhChce)
{
switch (ihIcon)
{
case (wimp_i)20: // Open local mail font menu
OpenChoicesLocalFontMenu ();
break;
case (wimp_i)23: // Open remote mail font menu
OpenChoicesRemoteFontMenu ();
break;
case (wimp_i)28: // Open account choices menu
OpenChoicesLoginMenu ();
break;
default:
break;
}
boWinFound = TRUE;
}
if (whWindow == gwhChBa)
{
switch (ihIcon)
{
case (wimp_i)2: // OK
ChoicesOkay ();
if (nButton == wimp_CLICK_SELECT)
{
CloseWindowHandlePane (gwhChce, gwhChBa);
}
break;
case (wimp_i)0: // Cancel
SetChoicesDialogue ();
if (nButton == wimp_CLICK_SELECT)
{
CloseWindowHandlePane (gwhChce, gwhChBa);
}
break;
case (wimp_i)1: // Save all
ChoicesOkay ();
SaveAccountDetails ();
SaveAddressesDetails ();
if (nButton == wimp_CLICK_SELECT)
{
CloseWindowHandlePane (gwhChce, gwhChBa);
}
break;
}
boWinFound = TRUE;
}
if (whWindow == gwhRegi)
{
switch (ihIcon)
{
case (wimp_i)7: // OK
if (nButton == wimp_CLICK_SELECT)
{
CloseWindowHandle (gwhRegi);
}
Register ();
break;
case (wimp_i)6: // Cancel
RegisterCancel ();
if (nButton == wimp_CLICK_SELECT)
{
CloseWindowHandle (gwhRegi);
}
break;
case (wimp_i)5: // Open website
OpenURL (Tag("WebReg"));
break;
default:
break;
}
boWinFound = TRUE;
}
if (whWindow == gwhAddr)
{
switch (ihIcon)
{
case (wimp_i)2: // Addresses menu
OpenAddressMenu (whWindow, ihIcon, ADDRESSMENU_ADDRESSES);
break;
case (wimp_i)3: // Close
if (nButton == wimp_CLICK_SELECT)
{
CloseWindowHandle (gwhAddr);
}
break;
case (wimp_i)4: // Save addresses
SaveAddressesDetails ();
if (nButton == wimp_CLICK_SELECT)
{
CloseWindowHandle (gwhAddr);
}
break;
case (wimp_i)11: // Delete
ShowQueryTag ("Ms5", "MsYes", "MsNo", QUERYACTION_DELETEADDRESS);
break;
case (wimp_i)12: // New
AddressesDialogueNew ();
break;
case (wimp_i)13: // Set
AddressesDialogueUpdate ();
break;
default: // Save drag
if (nButton & (wimp_DRAG_SELECT | wimp_DRAG_ADJUST))
{
strncpy (gszSaveString, GetIconText (whWindow, ihIcon),
sizeof(gszSaveString));
DragBox (whWindow, ihIcon);
geSaveType = SAVETYPE_ICONTEXT;
}
break;
}
boWinFound = TRUE;
}
if (whWindow == gwhEdAt)
{
switch (ihIcon)
{
case (wimp_i)10: // Remove
RemoveFileFromAttachmentsList (gnEmailSelected, gnAttachmentNum);
if (nButton == wimp_CLICK_ADJUST)
{
if (gnAttachmentNum < gasEdit[gnEmailSelected].nMIMEListNum)
{
SetEditAttachmentDetails (gnEmailSelected, gnAttachmentNum);
}
GenerateEditAttachmentMenu (gpcEditAttcMenu, gnEmailSelected);
OpenMenu (gpcMenuCurrent, gnMenuXpos, gnMenuYpos);
}
else
{
CloseMenu ();
}
break;
default: // Save drag
if (nButton & (wimp_DRAG_SELECT | wimp_DRAG_ADJUST))
{
strncpy (gszSaveString, GetIconText (whWindow, ihIcon),
sizeof(gszSaveString));
DragBox (whWindow, ihIcon);
geSaveType = SAVETYPE_ICONTEXT;
}
break;
}
}
// Check for all of the email windows
nEmailSearch = 0;
while ((!boWinFound) && (gawhEmailsOpen[nEmailSearch] != wimp_BACKGROUND))
{
if (whWindow == gawhEmailsOpen[nEmailSearch])
{
if (nButton == wimp_CLICK_MENU)
{
gnEmailSelected = ganEmailsOpen[nEmailSearch];
gboEditSelected = FALSE;
SetUpEmailMenu ();
SetEmailSave (gnEmailSelected, FALSE);
OpenMenu (gpcEmailMenu, nXPos + MENU_XPOS_OFFSET, nYPos);
}
eRelPos = PointRelativeSelection (FALSE, ganEmailsOpen[nEmailSearch],
nXPos, nYPos, & gsSelect, & nLine, & nChar);
if (nButton & wimp_SINGLE_SELECT)
{
if ((eRelPos != RELPOS_WITHINSTART)
&& (eRelPos != RELPOS_WITHINEND))
{
ClearSelection ();
}
}
if (nButton & wimp_DOUBLE_SELECT)
{
// Launch a URL
ClickOnURL (FALSE, ganEmailsOpen[nEmailSearch], nXPos, nYPos);
}
if (nButton & wimp_SINGLE_ADJUST)
{
if ((eRelPos == RELPOS_BEFORE)
|| (eRelPos == RELPOS_WITHINSTART))
{
sSelect = gsSelect;
sSelect.nLineStart = nLine;
sSelect.nCharStart = nChar;
ChangeSelection (& sSelect);
}
if ((eRelPos == RELPOS_AFTER)
|| (eRelPos == RELPOS_WITHINEND))
{
sSelect = gsSelect;
sSelect.nLineEnd = nLine;
sSelect.nCharEnd = nChar;
ChangeSelection (& sSelect);
}
}
if (nButton & wimp_DRAG_SELECT)
{
if ((eRelPos == RELPOS_WITHINSTART)
|| (eRelPos == RELPOS_WITHINEND))
{
CreateEditSelect (ganEmailsOpen[nEmailSearch], FALSE,
& gpcCopySelect, & gnCopySelectSize);
geSaveType = SAVETYPE_SELECTSAVE;
DragCentred (nXPos, nYPos, "file_fff");
}
else
{
gnSelectLineStart = nLine;
gnSelectCharStart = nChar;
DragSelectionBox (FALSE, ganEmailsOpen[nEmailSearch], nXPos,
nYPos);
geSaveType = SAVETYPE_SELECTCHOOSE;
SetNullPollActive (NULLPOLL_ACTIVE_FAST);
}
}
if (nButton & wimp_DRAG_ADJUST)
{
gnSelectLineStart = nLine;
gnSelectCharStart = nChar;
if ((eRelPos == RELPOS_BEFORE)
|| (eRelPos == RELPOS_WITHINSTART))
{
gnSelectLineStart = gsSelect.nLineEnd;
gnSelectCharStart = gsSelect.nCharEnd;
}
if ((eRelPos == RELPOS_AFTER)
|| (eRelPos == RELPOS_WITHINEND))
{
gnSelectLineStart = gsSelect.nLineStart;
gnSelectCharStart = gsSelect.nCharStart;
}
DragSelectionBox (FALSE, ganEmailsOpen[nEmailSearch], nXPos, nYPos);
geSaveType = SAVETYPE_SELECTCHOOSE;
SetNullPollActive (NULLPOLL_ACTIVE_FAST);
}
boWinFound = TRUE;
}
if ((!boWinFound)
&& (gasDetails[ganEmailsOpen[nEmailSearch]].whHead == whWindow))
{
switch (ihIcon)
{
case 4: // Copy
CopySelectToClip ();
ClearSelection ();
break;
case 5: // Reply
CreateReplyMessage (ganEmailsOpen[nEmailSearch]);
break;
case 6: // Reply to all
CreateReplyToAllMessage (ganEmailsOpen[nEmailSearch]);
break;
case 7: // Forward
CreateForwardMessage (ganEmailsOpen[nEmailSearch]);
break;
case 8: // Save
gnEmailSelected = ganEmailsOpen[nEmailSearch];
gboEditSelected = FALSE;
SetEmailSave (gnEmailSelected, FALSE);
OpenMenu ((wimp_menu *)gwhSave, nXPos + MENU_XPOS_OFFSET, nYPos);
break;
case 9: // Toggle Header
if (gasDetails[ganEmailsOpen[nEmailSearch]].nLineHide == 0)
{
ShowHeader (ganEmailsOpen[nEmailSearch], FALSE);
}
else
{
ShowHeader (ganEmailsOpen[nEmailSearch], TRUE);
}
break;
case 10: // Add 'From:' address to address book
AddFromToAddress (ganEmailsOpen[nEmailSearch]);
break;
case 11: // Open Attachments menu
if (gasDetails[ganEmailsOpen[nEmailSearch]].nMIMEListNum > 0)
{
gnEmailSelected = ganEmailsOpen[nEmailSearch];
gboEditSelected = FALSE;
OpenAttachmentMenu (whWindow, ihIcon,
ganEmailsOpen[nEmailSearch]);
}
break;
default: // Save drag
if (nButton & (wimp_DRAG_SELECT | wimp_DRAG_ADJUST))
{
strncpy (gszSaveString, GetIconText (whWindow, ihIcon),
sizeof(gszSaveString));
DragBox (whWindow, ihIcon);
geSaveType = SAVETYPE_ICONTEXT;
}
break;
}
boWinFound = TRUE;
}
nEmailSearch++;
}
// Check for all of the edit windows
nEditSearch = 0;
while ((!boWinFound) && (gawhEditOpen[nEditSearch] != wimp_BACKGROUND))
{
if (whWindow == gawhEditOpen[nEditSearch])
{
eRelPos = PointRelativeSelection (TRUE, ganEditOpen[nEditSearch],
nXPos, nYPos, & gsSelect, & nLine, & nChar);
if (nButton == wimp_CLICK_MENU)
{
gnEmailSelected = ganEditOpen[nEditSearch];
gboEditSelected = TRUE;
SetUpNewMenu ();
SetEmailSave (gnEmailSelected, TRUE);
OpenMenu (gpcNewMenu, nXPos + MENU_XPOS_OFFSET, nYPos);
}
if (nButton & wimp_SINGLE_SELECT)
{
SetCaretPos (ganEditOpen[nEditSearch], nLine, nChar);
gsCaret.nCharPref = gsCaret.nChar;
if ((eRelPos != RELPOS_WITHINSTART)
&& (eRelPos != RELPOS_WITHINEND))
{
ClearSelection ();
}
}
if (nButton & wimp_DOUBLE_SELECT)
{
// Launch a URL
ClickOnURL (TRUE, ganEditOpen[nEditSearch], nXPos, nYPos);
}
if (nButton & wimp_SINGLE_ADJUST)
{
if (eRelPos == RELPOS_OTHEREMAIL)
{
sSelect.boEdit = TRUE;
sSelect.whWindow = whWindow;
sSelect.nEmailNum = ganEditOpen[nEditSearch];
sSelect.nLineStart = gsCaret.nLine;
sSelect.nCharStart = gsCaret.nChar;
sSelect.nLineEnd = nLine;
sSelect.nCharEnd = nChar;
ChangeSelection (& sSelect);
}
SetCaretPos (ganEditOpen[nEditSearch], nLine, nChar);
gsCaret.nCharPref = gsCaret.nChar;
if ((eRelPos == RELPOS_BEFORE)
|| (eRelPos == RELPOS_WITHINSTART))
{
sSelect = gsSelect;
sSelect.nLineStart = nLine;
sSelect.nCharStart = nChar;
ChangeSelection (& sSelect);
}
if ((eRelPos == RELPOS_AFTER)
|| (eRelPos == RELPOS_WITHINEND))
{
sSelect = gsSelect;
sSelect.nLineEnd = nLine;
sSelect.nCharEnd = nChar;
ChangeSelection (& sSelect);
}
}
if (nButton & wimp_DRAG_SELECT)
{
if ((eRelPos == RELPOS_WITHINSTART)
|| (eRelPos == RELPOS_WITHINEND))
{
CreateEditSelect (ganEditOpen[nEditSearch], TRUE,
& gpcCopySelect, & gnCopySelectSize);
geSaveType = SAVETYPE_SELECTSAVE;
DragCentred (nXPos, nYPos, "file_fff");
}
else
{
SetCaretPos (ganEditOpen[nEditSearch], nLine, nChar);
gsCaret.nCharPref = gsCaret.nChar;
gnSelectLineStart = nLine;
gnSelectCharStart = nChar;
DragSelectionBox (TRUE, ganEditOpen[nEditSearch], nXPos, nYPos);
geSaveType = SAVETYPE_SELECTCHOOSE;
SetNullPollActive (NULLPOLL_ACTIVE_FAST);
}
}
if (nButton & wimp_DRAG_ADJUST)
{
SetCaretPos (ganEditOpen[nEditSearch], nLine, nChar);
gsCaret.nCharPref = gsCaret.nChar;
gnSelectLineStart = nLine;
gnSelectCharStart = nChar;
if ((eRelPos == RELPOS_BEFORE)
|| (eRelPos == RELPOS_WITHINSTART))
{
gnSelectLineStart = gsSelect.nLineEnd;
gnSelectCharStart = gsSelect.nCharEnd;
}
if ((eRelPos == RELPOS_AFTER)
|| (eRelPos == RELPOS_WITHINEND))
{
gnSelectLineStart = gsSelect.nLineStart;
gnSelectCharStart = gsSelect.nCharStart;
}
DragSelectionBox (TRUE, ganEditOpen[nEditSearch], nXPos, nYPos);
geSaveType = SAVETYPE_SELECTCHOOSE;
SetNullPollActive (NULLPOLL_ACTIVE_FAST);
}
boWinFound = TRUE;
}
if ((!boWinFound)
&& (gasEdit[ganEditOpen[nEditSearch]].whHead == whWindow))
{
boClearSelect = FALSE;
switch (ihIcon)
{
case 4: // Cut
CopySelectToClip ();
if (nButton & wimp_CLICK_ADJUST)
{
boUpdate = DeleteSection (ganEditOpen[nEditSearch], & gsSelect);
if (ganEditOpen[nEditSearch] == gsCaret.nEditNum)
{
if (gsCaret.nChar == 0)
{
nLength = ConvertString(szSnip, Tag("Snip"), sizeof(szSnip));
}
else
{
nLength = ConvertString(szSnip, Tag("SnipMid"),
sizeof(szSnip));
}
InsertText (gsCaret.nEditNum, gsCaret.nPos, gsCaret.nLine,
szSnip, nLength);
boUpdate = TRUE;
}
if (boUpdate)
{
EditChanged (ganEditOpen[nEditSearch]);
ReFormat (ganEditOpen[nEditSearch], gsCaret.nLine, -1,
& nStartLine, & nEndLine);
UpdateEditWindow (ganEditOpen[nEditSearch], nStartLine,
nEndLine);
}
}
else
{
if (DeleteSection (ganEditOpen[nEditSearch], & gsSelect))
{
ReFormat (ganEditOpen[nEditSearch], gsCaret.nLine, -1,
& nStartLine, & nEndLine);
UpdateEditWindow (ganEditOpen[nEditSearch], nStartLine,
nEndLine);
EditChanged (ganEditOpen[nEditSearch]);
}
}
break;
case 5: // Copy
CopySelectToClip ();
boClearSelect = TRUE;
break;
case 6: // Paste
PasteClipboard ();
EditChanged (ganEditOpen[nEditSearch]);
break;
case 7: // Send
SendEmail (ganEditOpen[nEditSearch]);
break;
case 8: // Save
gnEmailSelected = ganEditOpen[nEditSearch];
gboEditSelected = TRUE;
SetEmailSave (gnEmailSelected, TRUE);
OpenMenu ((wimp_menu *)gwhSave, nXPos + MENU_XPOS_OFFSET, nYPos);
break;
case 14: // Toggle Advanced
if (gasEdit[ganEditOpen[nEditSearch]].boAdvanced == TRUE)
{
ShowAdvanced (ganEditOpen[nEditSearch], FALSE);
}
else
{
ShowAdvanced (ganEditOpen[nEditSearch], TRUE);
}
break;
case 15: // 'To:' address menu
gnEmailSelected = ganEditOpen[nEditSearch];
gboEditSelected = TRUE;
OpenAddressMenu (whWindow, ihIcon, ADDRESSMENU_TO);
break;
case 16: // 'CC:' address menu
gnEmailSelected = ganEditOpen[nEditSearch];
gboEditSelected = TRUE;
OpenAddressMenu (whWindow, ihIcon, ADDRESSMENU_CC);
break;
case 17: // 'BCC:' address menu
gnEmailSelected = ganEditOpen[nEditSearch];
gboEditSelected = TRUE;
OpenAddressMenu (whWindow, ihIcon, ADDRESSMENU_BCC);
break;
case 18: // Open Attachments menu
if (gasEdit[ganEditOpen[nEditSearch]].nMIMEListNum > 0)
{
gnEmailSelected = ganEditOpen[nEditSearch];
gboEditSelected = TRUE;
OpenEditAttachmentMenu (whWindow, ihIcon,
ganEditOpen[nEditSearch]);
}
break;
default: // Save drag
if (nButton & (wimp_DRAG_SELECT | wimp_DRAG_ADJUST))
{
strncpy (gszSaveString, GetIconText (whWindow, ihIcon),
sizeof(gszSaveString));
DragBox (whWindow, ihIcon);
geSaveType = SAVETYPE_ICONTEXT;
}
break;
}
if (boClearSelect
&& (gsSelect.nLineStart != -1)
&& (gsSelect.whWindow == gasEdit[ganEditOpen[nEditSearch]].whWindow)
&& (gsSelect.nEmailNum == ganEditOpen[nEditSearch]))
{
ClearSelection ();
}
boWinFound = TRUE;
}
nEditSearch++;
}
}
//////////////////////////////////////////////////////////////////
// Poll 8: Act on user key presses
void Keys (wimp_block *pcBlock)
{
wimp_w whWindow;
wimp_i ihIcon;
wimp_key_no nKey;
int nEditSearch;
bool boWinFound;
int nStartLine;
int nEndLine;
bool boClearSelect;
Caret sCaretPre;
bool boShift;
char szSnip[1024];
int nLength;
bool boUpdate;
whWindow = pcBlock->key.w;
ihIcon = pcBlock->key.i;
nKey = pcBlock->key.c;
boWinFound = FALSE;
boShift = (osbyte1 (osbyte_SCAN_KEYBOARD, 0x80, 0) == 0xff);
// Check for all of the edit windows
nEditSearch = 0;
while ((!boWinFound) && (gawhEditOpen[nEditSearch] != wimp_BACKGROUND))
{
if (whWindow == gawhEditOpen[nEditSearch])
{
boClearSelect = FALSE;
switch (nKey)
{
case ('C' - 64):
CopySelectToClip ();
boClearSelect = TRUE;
break;
case ('X' - 64):
CopySelectToClip ();
if (boShift)
{
boUpdate = DeleteSection (ganEditOpen[nEditSearch], & gsSelect);
if (ganEditOpen[nEditSearch] == gsCaret.nEditNum)
{
if (gsCaret.nChar == 0)
{
nLength = ConvertString(szSnip, Tag("Snip"), sizeof(szSnip));
}
else
{
nLength = ConvertString(szSnip, Tag("SnipMid"),
sizeof(szSnip));
}
InsertText (gsCaret.nEditNum, gsCaret.nPos, gsCaret.nLine,
szSnip, nLength);
boUpdate = TRUE;
}
if (boUpdate)
{
EditChanged (ganEditOpen[nEditSearch]);
ReFormat (ganEditOpen[nEditSearch], gsCaret.nLine, -1,
& nStartLine, & nEndLine);
UpdateEditWindow (ganEditOpen[nEditSearch], nStartLine,
nEndLine);
}
}
else
{
if (DeleteSection (ganEditOpen[nEditSearch], & gsSelect))
{
EditChanged (ganEditOpen[nEditSearch]);
ReFormat (ganEditOpen[nEditSearch], gsCaret.nLine, -1,
& nStartLine, & nEndLine);
UpdateEditWindow (ganEditOpen[nEditSearch], nStartLine,
nEndLine);
}
}
break;
case ('V' - 64):
PasteClipboard ();
EditChanged (ganEditOpen[nEditSearch]);
break;
case ('Z' - 64):
boClearSelect = TRUE;
break;
case wimp_KEY_TAB:
DeleteSection (ganEditOpen[nEditSearch], & gsSelect);
InsertString (ganEditOpen[nEditSearch], gsCaret.nPos,
gsCaret.nLine, " ");
ReFormat (ganEditOpen[nEditSearch], gsCaret.nLine, -1,
& nStartLine, & nEndLine);
MoveCaretRight (5);
UpdateEditWindow (ganEditOpen[nEditSearch], nStartLine,
nEndLine);
EditChanged (ganEditOpen[nEditSearch]);
boClearSelect = TRUE;
break;
case wimp_KEY_INSERT:
gasEdit[ganEditOpen[nEditSearch]].boInsert
= !gasEdit[ganEditOpen[nEditSearch]].boInsert;
break;
case (wimp_KEY_RIGHT + wimp_KEY_CONTROL):
SearchCaretRight (" \n");
boClearSelect = TRUE;
break;
case (wimp_KEY_LEFT + wimp_KEY_CONTROL):
SearchCaretLeft (" \n");
boClearSelect = TRUE;
break;
case (wimp_KEY_DOWN + wimp_KEY_CONTROL):
SearchCaretRight ("\n");
boClearSelect = TRUE;
break;
case (wimp_KEY_UP + wimp_KEY_CONTROL):
SearchCaretLeft ("\n");
boClearSelect = TRUE;
break;
case (wimp_KEY_RIGHT + wimp_KEY_CONTROL + wimp_KEY_SHIFT):
sCaretPre = gsCaret;
SearchCaretRight (" \n");
ShiftSelection (& sCaretPre, & gsCaret);
break;
case (wimp_KEY_LEFT + wimp_KEY_CONTROL + wimp_KEY_SHIFT):
sCaretPre = gsCaret;
SearchCaretLeft (" \n");
ShiftSelection (& sCaretPre, & gsCaret);
break;
case (wimp_KEY_DOWN + wimp_KEY_CONTROL + wimp_KEY_SHIFT):
sCaretPre = gsCaret;
SearchCaretRight ("\n");
ShiftSelection (& sCaretPre, & gsCaret);
break;
case (wimp_KEY_UP + wimp_KEY_CONTROL + wimp_KEY_SHIFT):
sCaretPre = gsCaret;
SearchCaretLeft ("\n");
ShiftSelection (& sCaretPre, & gsCaret);
break;
case (wimp_KEY_LEFT + wimp_KEY_SHIFT):
sCaretPre = gsCaret;
MoveCaretLeft(1);
ShiftSelection (& sCaretPre, & gsCaret);
break;
case (wimp_KEY_RIGHT + wimp_KEY_SHIFT):
sCaretPre = gsCaret;
MoveCaretRight(1);
ShiftSelection (& sCaretPre, & gsCaret);
break;
case (wimp_KEY_UP + wimp_KEY_SHIFT):
sCaretPre = gsCaret;
MoveCaretUp(1);
ShiftSelection (& sCaretPre, & gsCaret);
break;
case (wimp_KEY_DOWN + wimp_KEY_SHIFT):
sCaretPre = gsCaret;
MoveCaretDown(1);
ShiftSelection (& sCaretPre, & gsCaret);
break;
case wimp_KEY_LEFT:
MoveCaretLeft(1);
boClearSelect = TRUE;
break;
case wimp_KEY_RIGHT:
MoveCaretRight(1);
boClearSelect = TRUE;
break;
case wimp_KEY_UP:
MoveCaretUp(1);
boClearSelect = TRUE;
break;
case wimp_KEY_DOWN:
MoveCaretDown(1);
boClearSelect = TRUE;
break;
case wimp_KEY_HOME:
SetCaretPos (gsCaret.nEditNum, gsCaret.nLine, 0);
// SearchCaretLeft ("\n");
gsCaret.nCharPref = gsCaret.nChar;
boClearSelect = TRUE;
break;
case wimp_KEY_COPY:
if (gboIyonixDelete)
{
SetCaretPos (gsCaret.nEditNum, gsCaret.nLine,
gasEdit[gsCaret.nEditNum].anLine[gsCaret.nLine + 1]
- gasEdit[gsCaret.nEditNum].anLine[gsCaret.nLine] - 1);
gsCaret.nCharPref = gsCaret.nChar;
// SearchCaretRight ("\n");
}
else
{
if (!DeleteSection (ganEditOpen[nEditSearch], & gsSelect))
{
DeleteChar (ganEditOpen[nEditSearch], gsCaret.nPos,
gsCaret.nLine);
}
EditChanged (ganEditOpen[nEditSearch]);
ReFormat (ganEditOpen[nEditSearch], gsCaret.nLine, -1,
& nStartLine, & nEndLine);
UpdateEditWindow (ganEditOpen[nEditSearch], nStartLine,
nEndLine);
}
boClearSelect = TRUE;
break;
case wimp_KEY_BACKSPACE:
// case wimp_KEY_DELETE:
if (!DeleteSection (ganEditOpen[nEditSearch], & gsSelect))
{
if (gsCaret.nPos > 0)
{
MoveCaretLeft(1);
DeleteChar (ganEditOpen[nEditSearch], gsCaret.nPos,
gsCaret.nLine);
}
}
EditChanged (ganEditOpen[nEditSearch]);
ReFormat (ganEditOpen[nEditSearch], gsCaret.nLine, -1,
& nStartLine, & nEndLine);
UpdateEditWindow (ganEditOpen[nEditSearch], nStartLine, nEndLine);
boClearSelect = TRUE;
break;
case wimp_KEY_DELETE:
// case wimp_KEY_COPY:
if (!DeleteSection (ganEditOpen[nEditSearch], & gsSelect))
{
if (gboIyonixDelete)
{
DeleteChar (ganEditOpen[nEditSearch], gsCaret.nPos,
gsCaret.nLine);
}
else
{
if (gsCaret.nPos > 0)
{
MoveCaretLeft(1);
DeleteChar (ganEditOpen[nEditSearch], gsCaret.nPos,
gsCaret.nLine);
}
}
}
EditChanged (ganEditOpen[nEditSearch]);
ReFormat (ganEditOpen[nEditSearch], gsCaret.nLine, -1,
& nStartLine, & nEndLine);
UpdateEditWindow (ganEditOpen[nEditSearch], nStartLine, nEndLine);
boClearSelect = TRUE;
break;
case wimp_KEY_RETURN:
DeleteSection (ganEditOpen[nEditSearch], & gsSelect);
InsertChar (ganEditOpen[nEditSearch], gsCaret.nPos,
gsCaret.nLine, '\n');
ReFormat (ganEditOpen[nEditSearch], gsCaret.nLine, -1,
& nStartLine, & nEndLine);
MoveCaretRight (1);
UpdateEditWindow (ganEditOpen[nEditSearch], nStartLine,
nEndLine);
EditChanged (ganEditOpen[nEditSearch]);
boClearSelect = TRUE;
break;
default:
if ((nKey >= 32) && (nKey < 127))
{
DeleteSection (ganEditOpen[nEditSearch], & gsSelect);
InsertChar (ganEditOpen[nEditSearch], gsCaret.nPos,
gsCaret.nLine, (char)nKey);
ReFormat (ganEditOpen[nEditSearch], gsCaret.nLine, -1,
& nStartLine, & nEndLine);
MoveCaretRight (1);
UpdateEditWindow (ganEditOpen[nEditSearch], nStartLine,
nEndLine);
EditChanged (ganEditOpen[nEditSearch]);
boClearSelect = TRUE;
}
else
{
xwimp_process_key (nKey);
}
break;
}
if (boClearSelect
&& (gsSelect.nLineStart != -1)
&& (gsSelect.whWindow == whWindow)
&& (gsSelect.nEmailNum == ganEditOpen[nEditSearch]))
{
ClearSelection ();
}
boWinFound = TRUE;
}
nEditSearch++;
}
nEditSearch = 0;
while ((!boWinFound) && (gawhEditOpen[nEditSearch] != wimp_BACKGROUND))
{
if (whWindow == gasEdit[ganEditOpen[nEditSearch]].whHead)
{
switch (nKey)
{
case wimp_KEY_RETURN:
SetCaretPos (ganEditOpen[nEditSearch], 0, 0);
gsCaret.nCharPref = gsCaret.nChar;
break;
default:
xwimp_process_key (nKey);
break;
}
boWinFound = TRUE;
}
nEditSearch++;
}
if (!boWinFound)
{
if (whWindow == gwhLogn)
{
switch (nKey)
{
case wimp_KEY_RETURN:
gasAccount[gnAccountLogin].boPOP3GotPassword = FALSE;
gasAccount[gnAccountLogin].boSMTPGotPassword = FALSE;
LoginAccount (gnAccountLogin);
CloseWindowHandle (gwhLogn);
break;
case wimp_KEY_ESCAPE:
CloseWindowHandle (gwhLogn);
break;
case wimp_KEY_UP:
gnAccountLogin = (gnAccountNum + gnAccountLogin - 1)
% gnAccountNum;
SetLoginWindow (gnAccountLogin);
break;
case wimp_KEY_DOWN:
gnAccountLogin = (gnAccountLogin + 1) % gnAccountNum;
SetLoginWindow (gnAccountLogin);
break;
default:
xwimp_process_key (nKey);
break;
}
boWinFound = TRUE;
}
}
if (!boWinFound)
{
switch (nKey)
{
case wimp_KEY_RETURN:
if (whWindow == gwhSave)
{
gnSaveFileType = 0xfff;
SaveSave ();
CloseMenu ();
}
if (whWindow == gwhAttc)
{
gnSaveFileType = gasDetails[gnEmailSelected]
.asMIMEList[gnAttachmentNum].nFileType;
AttachmentSave ();
CloseMenu ();
}
if (whWindow == gwhWarn)
{
CloseWarning ();
}
if (whWindow == gwhQery)
{
QueryContinue ();
}
if (whWindow == gwhAcct)
{
if (gnAccountDialogue == ACCOUNT_INVALID)
{
SetAccountDetails (gnAccountNum);
gnAccountDialogue = gnAccountNum;
gnAccountNum++;
}
else
{
SetAccountDetails (gnAccountDialogue);
SetLoginWindow (gnAccountLogin);
}
CloseWindowHandlePane (gwhAcct, gwhAcBa);
}
if (whWindow == gwhSett)
{
if (gnAccountSettingsDialogue != ACCOUNT_INVALID)
{
SetAccountSettingsDetails (gnAccountSettingsDialogue);
}
CloseWindowHandlePane (gwhSett, gwhSeBa);
}
if (whWindow == gwhUnLk)
{
UnlockOkay ();
CloseWindowHandle (gwhUnLk);
}
if (whWindow == gwhChce)
{
ChoicesOkay ();
CloseWindowHandlePane (gwhChce, gwhChBa);
}
if (whWindow == gwhRegi)
{
CloseWindowHandle (gwhRegi);
Register ();
}
if (whWindow == gwhAddr)
{
AddressesDialogueUpdate ();
}
break;
case wimp_KEY_ESCAPE:
if ((whWindow == gwhSave) || (whWindow == gwhAttc))
{
CloseMenu ();
}
if (whWindow == gwhWarn)
{
CloseWarning ();
}
if (whWindow == gwhQery)
{
QueryCancel ();
}
if (whWindow == gwhAcct)
{
CloseWindowHandlePane (gwhAcct, gwhAcBa);
SetAccountDialogue (gnAccountDialogue);
}
if (whWindow == gwhSett)
{
CloseWindowHandlePane (gwhSett, gwhSeBa);
SetAccountSettingsDialogue (gnAccountSettingsDialogue);
}
if (whWindow == gwhUnLk)
{
CloseWindowHandle (gwhUnLk);
}
if (whWindow == gwhChce)
{
CloseWindowHandlePane (gwhChce, gwhChBa);
}
if (whWindow == gwhRegi)
{
RegisterCancel ();
CloseWindowHandle (gwhRegi);
}
if (whWindow == gwhAddr)
{
CloseWindowHandle (gwhAddr);
}
break;
default:
xwimp_process_key (nKey);
break;
}
}
}
//////////////////////////////////////////////////////////////////
// Poll 9: Act on menu selections
void MenuSelect (wimp_block *pcBlock)
{
wimp_pointer sPointer;
int nStartLine;
int nEndLine;
char szSnip[1024];
int nLength;
xwimp_get_pointer_info (& sPointer);
if (gpcMenuCurrent == gpcIconBarMenu)
{
switch (pcBlock->selection.items[0])
{
case 1: // Account
if (pcBlock->selection.items[1] == -1)
{
OpenLoginWindow (gnAccount);
}
else
{
MenuSelectIconbarAccount (pcBlock->selection.items[1]);
}
break;
case 2: // New account
OpenAccountWindow (ACCOUNT_INVALID);
break;
case 3: // Choices
OpenChoicesWindow ();
break;
case 4: // Addresses
OpenAddressesWindow (ADDRESS_INVALID);
break;
case 5: // Lock
Lock ();
break;
case 6: // Quit
if (gnRegistered == REGISTERED)
{
PreQuit ();
}
else
{
OpenRegisterWindow ();
}
break;
case 7: // Quit (Unregistered)
PreQuit ();
break;
default:
break;
}
}
if (gpcMenuCurrent == gpcMainMenu)
{
switch (pcBlock->selection.items[0])
{
case 0: // Check mail
CheckNetCom (NET_POP3_LIST);
break;
case 1: // Selection
switch (pcBlock->selection.items[1])
{
case 0: // Open emails
OpenSelectedEmails ();
break;
case 1: // Download emails
CompileSelectedList ();
CheckNetCom (NET_POP3_DOWNLOAD);
break;
case 3: // Forget emails
DestroySelectedEmails ();
break;
case 4: // Delete emails
ShowQueryTag ("Ms3", "MsYes", "MsNo", QUERYACTION_DELETEEMAILS);
break;
default:
break;
}
break;
case 2: // Send
switch (pcBlock->selection.items[1])
{
case 0: // New
CreateEditWindow ();
break;
case 1: // Reply
CreateReplyMessage (ganEmailSave[0]);
break;
case 2: // Reply to all
CreateReplyToAllMessage (ganEmailSave[0]);
break;
case 3: // Forward
CreateForwardMessage (ganEmailSave[0]);
break;
default:
break;
}
break;
case 3: // Highlight
switch (pcBlock->selection.items[1])
{
case 0: // All
SelectAllEmails ();
break;
case 1: // None
ClearAllSelected ();
break;
case 2: // Invert
InvertAllEmails ();
break;
default:
break;
}
break;
case 4: // Account
switch (pcBlock->selection.items[1])
{
case 0: // Profile
OpenAccountWindow (gnAccount);
break;
case 1: // Options
OpenAccountSettingsWindow (gnAccount);
break;
default:
break;
}
break;
case 5: // Stop operation
if (geConnectStatus != CONNECTED_OFF)
{
ShowQueryTag ("Ms1", "MsYes", "MsNo", QUERYACTION_STOP);
}
break;
default:
break;
}
}
if (gpcMenuCurrent == gpcEmailMenu)
{
switch (pcBlock->selection.items[0])
{
case 2: // Edit
switch (pcBlock->selection.items[1])
{
case 1: // Copy
CopySelectToClip ();
ClearSelection ();
break;
case 3: // Clear
ClearSelection ();
break;
default:
break;
}
break;
case 3: // Send
switch (pcBlock->selection.items[1])
{
case 0: // Reply
CreateReplyMessage (gnEmailSelected);
break;
case 1: // Reply to all
CreateReplyToAllMessage (gnEmailSelected);
break;
case 2: // Forward
CreateForwardMessage (gnEmailSelected);
break;
default:
break;
}
break;
case 4: // Header
if (gasDetails[gnEmailSelected].nLineHide == 0)
{
ShowHeader (gnEmailSelected, FALSE);
}
else
{
ShowHeader (gnEmailSelected, TRUE);
}
break;
default:
break;
}
}
if (gpcMenuCurrent == gpcLognMenu)
{
SetLoginWindow (pcBlock->selection.items[0]);
}
if (gpcMenuCurrent == gpcNewMenu)
{
switch (pcBlock->selection.items[0])
{
case 2: // Edit
switch (pcBlock->selection.items[1])
{
case 0: // Cut
CopySelectToClip ();
if (DeleteSection (gnEmailSelected, & gsSelect))
{
EditChanged (gnEmailSelected);
ReFormat (gnEmailSelected, gsCaret.nLine, -1,
& nStartLine, & nEndLine);
UpdateEditWindow (gnEmailSelected, nStartLine,
nEndLine);
}
break;
case 1: // Copy
CopySelectToClip ();
ClearSelection ();
break;
case 2: // Paste
PasteClipboard ();
EditChanged (gnEmailSelected);
break;
case 3: // Clear
ClearSelection ();
break;
case 4: // Snip
CopySelectToClip ();
DeleteSection (gnEmailSelected, & gsSelect);
EditChanged (gnEmailSelected);
if (gsCaret.nChar == 0)
{
nLength = ConvertString(szSnip, Tag("Snip"), sizeof(szSnip));
}
else
{
nLength = ConvertString(szSnip, Tag("SnipMid"),
sizeof(szSnip));
}
InsertText (gsCaret.nEditNum, gsCaret.nPos, gsCaret.nLine,
szSnip, nLength);
ReFormat (gnEmailSelected, gsCaret.nLine, -1,
& nStartLine, & nEndLine);
UpdateEditWindow (gnEmailSelected, nStartLine,
nEndLine);
break;
default:
break;
}
break;
case 3: // Send
SendEmail (gnEmailSelected);
break;
case 4: // Advanced
if (gasEdit[gnEmailSelected].boAdvanced)
{
ShowAdvanced (gnEmailSelected, FALSE);
}
else
{
ShowAdvanced (gnEmailSelected, TRUE);
}
break;
default:
break;
}
}
if (gpcMenuCurrent == gpcChoiceAcctMenu)
{
SetChoicesAccount (pcBlock->selection.items[0] - 1);
}
if (gpcMenuCurrent == gpcLocalFontMenu)
{
ChoicesLocalFontSelect (& pcBlock->selection);
if (sPointer.buttons & wimp_CLICK_ADJUST)
{
SetUpFontMenu (gpcLocalFontMenu, gszLocalChoiceFont);
}
}
if (gpcMenuCurrent == gpcRemoteFontMenu)
{
ChoicesRemoteFontSelect (& pcBlock->selection);
if (sPointer.buttons & wimp_CLICK_ADJUST)
{
SetUpFontMenu (gpcRemoteFontMenu, gszRemoteChoiceFont);
}
}
if (gpcMenuCurrent == gpcAddrMenu)
{
switch (geAddressMenuType)
{
case ADDRESSMENU_ADDRESSES:
SetAddressesDialogue (pcBlock->selection.items[0]);
break;
case ADDRESSMENU_TO:
AddAddressToIcon (gasEdit[gnEmailSelected].whHead, (wimp_i)0,
pcBlock->selection.items[0], TO_MAX);
break;
case ADDRESSMENU_CC:
AddAddressToIcon (gasEdit[gnEmailSelected].whHead, (wimp_i)9,
pcBlock->selection.items[0], CC_MAX);
break;
case ADDRESSMENU_BCC:
AddAddressToIcon (gasEdit[gnEmailSelected].whHead, (wimp_i)12,
pcBlock->selection.items[0], BCC_MAX);
break;
default:
break;
}
GenerateAddressesMenu (geAddressMenuType);
}
if (gpcMenuCurrent == gpcAcctMenu)
{
MenuSelectIconbarAccount (pcBlock->selection.items[0]);
}
if (sPointer.buttons & wimp_CLICK_ADJUST)
{
if (gpcMenuCurrent == gpcIconBarMenu)
{
SetupIconbarMenu ();
}
if (gpcMenuCurrent == gpcMainMenu)
{
SetUpMainMenu ();
}
if (gpcMenuCurrent == gpcEmailMenu)
{
SetUpEmailMenu ();
}
if (gpcMenuCurrent == gpcNewMenu)
{
SetUpNewMenu ();
}
if ((gpcMenuCurrent == gpcLognMenu)
|| (gpcMenuCurrent == gpcAcctMenu))
{
GenerateAccountMenu (gpcMenuCurrent);
}
if (gpcMenuCurrent == gpcChoiceAcctMenu)
{
GenerateAccountMenuNone (gpcMenuCurrent);
}
OpenMenu (gpcMenuCurrent, gnMenuXpos, gnMenuYpos);
}
}
//////////////////////////////////////////////////////////////////
// Poll 7: User has finished dragging an object
void UserDragBox (wimp_block *pcBlock)
{
char *szFilename;
wimp_w whWindow;
wimp_pointer sPointer;
wimp_message sMessage;
Selection sSelect;
wimp_auto_scroll_info sScrollInfo;
pcBlock = pcBlock;
xdragasprite_stop ();
gboDrag = FALSE;
xwimp_get_pointer_info (& sPointer);
whWindow = sPointer.w;
if ((whWindow != gwhMain)
&& (whWindow != gwhSave)
&& (whWindow != gwhWarn))
{
switch (geSaveType)
{
case SAVETYPE_EMAILS:
sMessage.data.data_xfer.w = whWindow;
sMessage.data.data_xfer.i = sPointer.i;
sMessage.data.data_xfer.pos = sPointer.pos;
sMessage.data.data_xfer.est_size = EmailSaveSize ();
sMessage.data.data_xfer.file_type = gnSaveFileType;
strncpy (sMessage.data.data_xfer.file_name, Tag ("SaveEmailSel"),
211);
sMessage.data.data_xfer.file_name[211] = 0;
sMessage.size = WORDALIGN((44 + 1 + strlen (Tag("SaveEmailSel"))));
sMessage.your_ref = 0;
sMessage.action = message_DATA_SAVE;
xwimp_send_message_to_window (wimp_USER_MESSAGE, & sMessage,
whWindow, sPointer.i, NULL);
break;
case SAVETYPE_FILE:
sMessage.data.data_xfer.w = whWindow;
sMessage.data.data_xfer.i = sPointer.i;
sMessage.data.data_xfer.pos = sPointer.pos;
sMessage.data.data_xfer.est_size = EmailSaveSize ();
sMessage.data.data_xfer.file_type = gnSaveFileType;
szFilename = GetIconText (gwhSave, 2);
while (strchr (szFilename, '.'))
{
szFilename = strchr(szFilename, '.') + 1;
}
strncpy (sMessage.data.data_xfer.file_name, szFilename, 211);
sMessage.data.data_xfer.file_name[211] = 0;
sMessage.size = WORDALIGN((44 + 1 + strlen (szFilename)));
sMessage.your_ref = 0;
sMessage.action = message_DATA_SAVE;
xwimp_send_message_to_window (wimp_USER_MESSAGE, & sMessage,
whWindow, sPointer.i, NULL);
break;
case SAVETYPE_ICONTEXT:
sMessage.data.data_xfer.w = whWindow;
sMessage.data.data_xfer.i = sPointer.i;
sMessage.data.data_xfer.pos = sPointer.pos;
sMessage.data.data_xfer.est_size = strlen(gszSaveString) + 1;
sMessage.data.data_xfer.file_type = 0xfff;
strncpy (sMessage.data.data_xfer.file_name, "IconText", 12);
sMessage.data.data_xfer.file_name[11] = 0;
sMessage.size = WORDALIGN((44 + 12));
sMessage.your_ref = 0;
sMessage.action = message_DATA_SAVE;
xwimp_send_message_to_window (wimp_USER_MESSAGE, & sMessage,
whWindow, sPointer.i, NULL);
break;
case SAVETYPE_SELECTCHOOSE:
SetNullPollActive (NULLPOLL_DEACTIVE_FAST);
if (gsSelect.boEdit)
{
FindEditCoords (gsSelect.nEmailNum, sPointer.pos.x,
sPointer.pos.y, & sSelect.nLineEnd, & sSelect.nCharEnd);
}
else
{
FindEmailCoords (gsSelect.nEmailNum, sPointer.pos.x,
sPointer.pos.y, & sSelect.nLineEnd, & sSelect.nCharEnd);
}
sSelect.boEdit = gsSelect.boEdit;
sSelect.nLineStart = gnSelectLineStart;
sSelect.nCharStart = gnSelectCharStart;
sSelect.whWindow = gsSelect.whWindow;
sSelect.nEmailNum = gsSelect.nEmailNum;
ChangeSelection (& sSelect);
sScrollInfo.w = gsSelect.whWindow;
sScrollInfo.pause_zone_sizes.x0 = 80;
sScrollInfo.pause_zone_sizes.y0 = 80;
sScrollInfo.pause_zone_sizes.x1 = 80;
sScrollInfo.pause_zone_sizes.y1 = 80;
sScrollInfo.pause_duration = 0;
sScrollInfo.state_change = NULL;
sScrollInfo.handle = NULL;
xwimp_auto_scroll (0, & sScrollInfo, NULL);
break;
case SAVETYPE_SELECTSAVE:
if (gpcCopySelect)
{
sMessage.data.data_xfer.w = whWindow;
sMessage.data.data_xfer.i = sPointer.i;
sMessage.data.data_xfer.pos = sPointer.pos;
sMessage.data.data_xfer.est_size = gnCopySelectSize;
sMessage.data.data_xfer.file_type = 0xfff;
strncpy (sMessage.data.data_xfer.file_name,
Tag ("SaveSel"), 12);
sMessage.data.data_xfer.file_name[11] = 0;
sMessage.size = WORDALIGN((44 + 12));
sMessage.your_ref = 0;
sMessage.action = message_DATA_SAVE;
xwimp_send_message_to_window (wimp_USER_MESSAGE, & sMessage,
whWindow, sPointer.i, NULL);
}
break;
case SAVETYPE_COLUMN:
SetNullPollActive (NULLPOLL_DEACTIVE_FAST);
SetColumnFromScreen (gnDragColumn, sPointer.pos.x);
break;
case SAVETYPE_ATTACHMENT:
sMessage.data.data_xfer.w = whWindow;
sMessage.data.data_xfer.i = sPointer.i;
sMessage.data.data_xfer.pos = sPointer.pos;
switch (gasDetails[gnEmailSelected].asMIMEList[gnAttachmentNum].
eEncoding)
{
case CTENCODING_QUOTEDPRINTABLE:
case CTENCODING_PLAIN:
default:
sMessage.data.data_xfer.est_size = gasDetails[gnEmailSelected]
.asMIMEList[gnAttachmentNum].nSizePre;
break;
case CTENCODING_BASE64:
sMessage.data.data_xfer.est_size = ((gasDetails[gnEmailSelected]
.asMIMEList[gnAttachmentNum].nSizePre * 3) / 4) + 3;
break;
}
sMessage.data.data_xfer.file_type = gnSaveFileType;
szFilename = GetIconText (gwhAttc, 2);
while (strchr (szFilename, '.'))
{
szFilename = strchr(szFilename, '.') + 1;
}
strncpy (sMessage.data.data_xfer.file_name, szFilename, 211);
sMessage.data.data_xfer.file_name[211] = 0;
sMessage.size = WORDALIGN((44 + 1 + strlen (szFilename)));
sMessage.your_ref = 0;
sMessage.action = message_DATA_SAVE;
xwimp_send_message_to_window (wimp_USER_MESSAGE, & sMessage,
whWindow, sPointer.i, NULL);
break;
default:
break;
}
}
}
//////////////////////////////////////////////////////////////////
// Opens the pane for a window
void OpenWindowPane (PANE ePaneType, wimp_w whPane, wimp_open * psMainOpen, wimp_open * psPaneOpen, int nHeight)
{
switch (ePaneType)
{
default:
case PANE_TOP:
*psPaneOpen = *psMainOpen;
psPaneOpen->w = whPane;
xwimp_open_window (psPaneOpen);
psMainOpen->next = psPaneOpen->w;
break;
case PANE_BASE:
*psPaneOpen = *psMainOpen;
psPaneOpen->visible.y1 = psMainOpen->visible.y0 + nHeight;
psPaneOpen->w = whPane;
xwimp_open_window (psPaneOpen);
psMainOpen->next = psPaneOpen->w;
break;
}
}
//////////////////////////////////////////////////////////////////
// Poll 2: Open window given window block
void OpenWindow (wimp_block *pcBlock)
{
wimp_w whWindow;
bool boWinFound;
int nEmailSearch;
wimp_open sPaneOpen;
PANE ePaneType;
int nHeight = 0;
whWindow = pcBlock->open.w;
ePaneType = PANE_NONE;
boWinFound = FALSE;
if (whWindow == gwhMain)
{
ePaneType = PANE_TOP;
boWinFound = TRUE;
nHeight = MAIN_PANE_HEIGHT;
OpenWindowPane (ePaneType, gwhMaHe, & pcBlock->open, & sPaneOpen,
nHeight);
}
if (whWindow == gwhAcct)
{
ePaneType = PANE_BASE;
boWinFound = TRUE;
nHeight = ACCOUNT_PANE_HEIGHT;
OpenWindowPane (ePaneType, gwhAcBa, & pcBlock->open, & sPaneOpen,
nHeight);
}
if (whWindow == gwhChce)
{
ePaneType = PANE_BASE;
boWinFound = TRUE;
nHeight = CHOICES_PANE_HEIGHT;
OpenWindowPane (ePaneType, gwhChBa, & pcBlock->open, & sPaneOpen,
nHeight);
}
if (whWindow == gwhSett)
{
ePaneType = PANE_BASE;
boWinFound = TRUE;
nHeight = SETTINGS_PANE_HEIGHT;
OpenWindowPane (ePaneType, gwhSeBa, & pcBlock->open, & sPaneOpen,
nHeight);
}
nEmailSearch = 0;
while ((!boWinFound) && (gawhEmailsOpen[nEmailSearch] != wimp_BACKGROUND))
{
if (whWindow == gawhEmailsOpen[nEmailSearch])
{
sPaneOpen = pcBlock->open;
sPaneOpen.w = gasDetails[ganEmailsOpen[nEmailSearch]].whHead;
xwimp_open_window (& sPaneOpen);
pcBlock->open.next = sPaneOpen.w;
ePaneType = PANE_TOP;
boWinFound = TRUE;
}
nEmailSearch++;
}
nEmailSearch = 0;
while ((!boWinFound) && (gawhEditOpen[nEmailSearch] != wimp_BACKGROUND))
{
if (whWindow == gawhEditOpen[nEmailSearch])
{
sPaneOpen = pcBlock->open;
sPaneOpen.w = gasEdit[ganEditOpen[nEmailSearch]].whHead;
xwimp_open_window (& sPaneOpen);
pcBlock->open.next = sPaneOpen.w;
ePaneType = PANE_TOP;
boWinFound = TRUE;
}
nEmailSearch++;
}
xwimp_open_window (& pcBlock->open);
if (ePaneType != PANE_NONE)
{
switch (ePaneType)
{
case PANE_TOP:
// Check to see whether the pane is in the correct position
if ((sPaneOpen.visible.x0 != pcBlock->open.visible.x0)
|| (sPaneOpen.visible.y1 != pcBlock->open.visible.y1)
|| (sPaneOpen.visible.x1 != pcBlock->open.visible.x1))
{
sPaneOpen.visible = pcBlock->open.visible;
xwimp_open_window (& sPaneOpen);
}
break;
case PANE_BASE:
// Check to see whether the pane is in the correct position
if ((sPaneOpen.visible.x0 != pcBlock->open.visible.x0)
|| (sPaneOpen.visible.y0 != pcBlock->open.visible.y0)
|| (sPaneOpen.visible.x1 != pcBlock->open.visible.x1))
{
sPaneOpen.visible = pcBlock->open.visible;
sPaneOpen.visible.y1 = pcBlock->open.visible.y0 + nHeight;
xwimp_open_window (& sPaneOpen);
}
break;
default:
// Do nothing
break;
}
}
}
//////////////////////////////////////////////////////////////////
// Open a window on screen that is currently closed
void OpenWindowInit (wimp_w whWindow)
{
wimp_window_state sState;
sState.w = whWindow;
xwimp_get_window_state (& sState);
sState.next = wimp_TOP;
xwimp_open_window ((wimp_open *)& sState);
}
//////////////////////////////////////////////////////////////////
// Open a window on screen that is currently closed with its pane
void OpenWindowInitPane (wimp_w whWindow, wimp_w whPane, PANE ePaneType)
{
wimp_window_state sState;
wimp_window_state sPane;
sState.w = whWindow;
xwimp_get_window_state (& sState);
sState.next = wimp_TOP;
xwimp_open_window ((wimp_open *)& sState);
switch (ePaneType)
{
default:
case PANE_TOP:
sState.w = whPane;
xwimp_open_window ((wimp_open *)& sState);
break;
case PANE_BASE:
sPane.w = whPane;
xwimp_get_window_state (& sPane);
sState.w = whPane;
sState.visible.y1
= sState.visible.y0 + (sPane.visible.y1 - sPane.visible.y0);
xwimp_open_window ((wimp_open *)& sState);
break;
}
}
//////////////////////////////////////////////////////////////////
// Open a window on screen that is currently closed with its pane
void OpenWindowInitPaneNew (wimp_w whWindow, wimp_w whPane, PANE ePaneType)
{
wimp_window_state sState;
wimp_window_state sPane;
sState.w = whWindow;
xwimp_get_window_state (& sState);
sState.yscroll = 0;
sState.next = wimp_TOP;
xwimp_open_window ((wimp_open *)& sState);
switch (ePaneType)
{
default:
case PANE_TOP:
sState.w = whPane;
xwimp_open_window ((wimp_open *)& sState);
break;
case PANE_BASE:
sPane.w = whPane;
xwimp_get_window_state (& sPane);
sState.w = whPane;
sState.visible.y1
= sState.visible.y0 + (sPane.visible.y1 - sPane.visible.y0);
xwimp_open_window ((wimp_open *)& sState);
break;
}
}
//////////////////////////////////////////////////////////////////
// Open a window in the centre of the screen
void OpenWindowInitCentre (wimp_w whWindow)
{
int nHeight;
int nWidth;
int nEigFactor;
int nSize;
int nPosition;
wimp_window_state sState;
sState.w = whWindow;
xwimp_get_window_state (& sState);
sState.next = wimp_TOP;
nWidth = sState.visible.x1 - sState.visible.x0;
nHeight = sState.visible.y1 - sState.visible.y0;
xos_read_mode_variable (os_CURRENT_MODE, os_MODEVAR_XEIG_FACTOR,
& nEigFactor, NULL);
xos_read_mode_variable (os_CURRENT_MODE, os_MODEVAR_XWIND_LIMIT,
& nSize, NULL);
nPosition = ((nSize << nEigFactor) - nWidth) / 2;
sState.visible.x0 = nPosition;
sState.visible.x1 = nPosition + nWidth;
xos_read_mode_variable (os_CURRENT_MODE, os_MODEVAR_YEIG_FACTOR,
& nEigFactor, NULL);
xos_read_mode_variable (os_CURRENT_MODE, os_MODEVAR_YWIND_LIMIT,
& nSize, NULL);
nPosition = ((nSize << nEigFactor) - nHeight) / 2;
sState.visible.y0 = nPosition;
sState.visible.y1 = nPosition + nHeight;
xwimp_open_window ((wimp_open *)& sState);
}
//////////////////////////////////////////////////////////////////
// Open a window in the centre of the screen with a pane
void OpenWindowInitPaneCentreSize (wimp_w whWindow, wimp_w whPane, PANE ePaneType, int nWidth, int nHeight)
{
// int nHeight;
// int nWidth;
int nEigFactor;
int nSize;
int nPosition;
wimp_window_state sState;
wimp_window_state sPane;
sState.w = whWindow;
xwimp_get_window_state (& sState);
sState.next = wimp_TOP;
sState.xscroll = 0;
sState.yscroll = 0;
// nWidth = sState.visible.x1 - sState.visible.x0;
// nHeight = sState.visible.y1 - sState.visible.y0;
xos_read_mode_variable (os_CURRENT_MODE, os_MODEVAR_XEIG_FACTOR,
& nEigFactor, NULL);
xos_read_mode_variable (os_CURRENT_MODE, os_MODEVAR_XWIND_LIMIT,
& nSize, NULL);
nPosition = ((nSize << nEigFactor) - nWidth) / 2;
sState.visible.x0 = nPosition;
sState.visible.x1 = nPosition + nWidth;
xos_read_mode_variable (os_CURRENT_MODE, os_MODEVAR_YEIG_FACTOR,
& nEigFactor, NULL);
xos_read_mode_variable (os_CURRENT_MODE, os_MODEVAR_YWIND_LIMIT,
& nSize, NULL);
nPosition = ((nSize << nEigFactor) - nHeight) / 2;
sState.visible.y0 = nPosition;
sState.visible.y1 = nPosition + nHeight;
xwimp_open_window ((wimp_open *)& sState);
switch (ePaneType)
{
default:
case PANE_TOP:
sState.w = whPane;
xwimp_open_window ((wimp_open *)& sState);
break;
case PANE_BASE:
sPane.w = whPane;
xwimp_get_window_state (& sPane);
sState.w = whPane;
sState.visible.y1
= sState.visible.y0 + (sPane.visible.y1 - sPane.visible.y0);
xwimp_open_window ((wimp_open *)& sState);
break;
}
}
//////////////////////////////////////////////////////////////////
// Open a given menu at the given position on screen
void OpenMenu (wimp_menu * pcMenu, int nXPos, int nYPos)
{
xwimp_create_menu (pcMenu, nXPos, nYPos);
gnMenuXpos = nXPos;
gnMenuYpos = nYPos;
gpcMenuCurrent = pcMenu;
}
//////////////////////////////////////////////////////////////////
// Poll 3: Close a window
void CloseWindow (wimp_block *pcBlock)
{
wimp_w whWindow;
bool boWinFound;
int nEmailSearch;
whWindow = pcBlock->open.w;
boWinFound = FALSE;
if (whWindow == gwhMain)
{
err (xwimp_close_window (whWindow));
err (xwimp_close_window (gwhMaHe));
boWinFound = TRUE;
}
if (whWindow == gwhAcct)
{
err (xwimp_close_window (whWindow));
err (xwimp_close_window (gwhAcBa));
boWinFound = TRUE;
}
if (whWindow == gwhChce)
{
err (xwimp_close_window (whWindow));
err (xwimp_close_window (gwhChBa));
boWinFound = TRUE;
}
if (whWindow == gwhSett)
{
err (xwimp_close_window (whWindow));
err (xwimp_close_window (gwhSeBa));
boWinFound = TRUE;
}
nEmailSearch = 0;
while ((!boWinFound) && (gawhEmailsOpen[nEmailSearch] != wimp_BACKGROUND))
{
if (whWindow == gawhEmailsOpen[nEmailSearch])
{
err( xwimp_close_window (whWindow));
err( xwimp_close_window
(gasDetails[ganEmailsOpen[nEmailSearch]].whHead));
boWinFound = TRUE;
}
nEmailSearch++;
}
nEmailSearch = 0;
while ((!boWinFound) && (gawhEditOpen[nEmailSearch] != wimp_BACKGROUND))
{
if (whWindow == gawhEditOpen[nEmailSearch])
{
if (gasEdit[ganEditOpen[nEmailSearch]].boChanged)
{
gwhWindowClose = whWindow;
ShowQueryTagVolatile ("Ms6", "MsDiscard", "MsCancel",
QUERYACTION_CLOSEEDIT);
}
else
{
err (xwimp_close_window (whWindow));
err (xwimp_close_window (gasEdit[ganEditOpen[nEmailSearch]].whHead));
DestroyEditWindow (ganEditOpen[nEmailSearch]);
}
boWinFound = TRUE;
}
nEmailSearch++;
}
if (!boWinFound)
{
wimp_close_window (whWindow);
}
}
//////////////////////////////////////////////////////////////////
// Close window given handle
void CloseWindowHandle (wimp_w whWindow)
{
wimp_close_window (whWindow);
}
//////////////////////////////////////////////////////////////////
// Close window given handle and its pane
void CloseWindowHandlePane (wimp_w whWindow, wimp_w whPane)
{
wimp_close_window (whWindow);
wimp_close_window (whPane);
}
//////////////////////////////////////////////////////////////////
// Close the currently open menu
void CloseMenu (void)
{
xwimp_create_menu ((wimp_menu*)-1, 0, 0);
gnMenuXpos = 0;
gnMenuYpos = 0;
gpcMenuCurrent = NULL;
}
//////////////////////////////////////////////////////////////////
// Create an iconbar icon
wimp_i CreateIconbarIcon (char * szSprite, int nWidth, int nHeight)
{
wimp_i ihIcon;
wimp_icon_create sIconBlock;
sIconBlock.w = wimp_ICON_BAR_RIGHT;
sIconBlock.icon.extent.x0 = 0;
sIconBlock.icon.extent.y0 = 0;
sIconBlock.icon.extent.x1 = nWidth;
sIconBlock.icon.extent.y1 = nHeight;
sIconBlock.icon.flags = wimp_ICON_SPRITE |
(wimp_BUTTON_CLICK << wimp_ICON_BUTTON_TYPE_SHIFT);
strncpy(sIconBlock.icon.data.sprite, szSprite, 12);
ihIcon = wimp_create_icon (& sIconBlock);
return ihIcon;
}
//////////////////////////////////////////////////////////////////
// Create window from Templates file
wimp_w LoadTemplate (char * szWindowTitle)
{
wimp_window *pcWindow;
char * pcIndirected;
int nWindowSize;
int nIndirectedSize;
char szTitle[12];
wimp_w whWindow;
wimp_load_template (0, NULL, NULL, NULL, szWindowTitle, 0,
& nWindowSize, & nIndirectedSize);
pcWindow = (wimp_window*)malloc (nWindowSize);
pcIndirected = malloc (nIndirectedSize);
strncpy (szTitle, szWindowTitle, 12);
wimp_load_template (pcWindow, pcIndirected, pcIndirected + nIndirectedSize,
gacFontRef, szWindowTitle, 0, NULL, NULL);
whWindow = wimp_create_window (pcWindow);
free((void *)pcWindow);
return whWindow;
}
//////////////////////////////////////////////////////////////////
// Create window from Templates file with sprites
wimp_w LoadTemplateSprites (char * szWindowTitle, osspriteop_area * pcSpriteArea)
{
wimp_window *pcWindow;
char * pcIndirected;
int nWindowSize;
int nIndirectedSize;
char szTitle[12];
wimp_w whWindow;
wimp_load_template (0, NULL, NULL, NULL, szWindowTitle, 0,
& nWindowSize, & nIndirectedSize);
pcWindow = (wimp_window*)malloc (nWindowSize);
pcIndirected = malloc (nIndirectedSize);
strncpy (szTitle, szWindowTitle, 12);
wimp_load_template (pcWindow, pcIndirected, pcIndirected + nIndirectedSize,
gacFontRef, szWindowTitle, 0, NULL, NULL);
if (pcSpriteArea)
{
pcWindow->sprite_area = pcSpriteArea;
}
whWindow = wimp_create_window (pcWindow);
free((void *)pcWindow);
return whWindow;
}
//////////////////////////////////////////////////////////////////
// Create Main Head window from Templates file with sprites
wimp_w LoadTemplateMaHe (char * szWindowTitle, osspriteop_area * pcSpriteArea)
{
wimp_window *pcWindow;
char * pcIndirected;
int nWindowSize;
int nIndirectedSize;
char szTitle[12];
wimp_w whWindow;
wimp_load_template (0, NULL, NULL, NULL, szWindowTitle, 0,
& nWindowSize, & nIndirectedSize);
pcWindow = (wimp_window*)malloc (nWindowSize);
pcIndirected = malloc (nIndirectedSize);
strncpy (szTitle, szWindowTitle, 12);
wimp_load_template (pcWindow, pcIndirected, pcIndirected + nIndirectedSize,
gacFontRef, szWindowTitle, 0, NULL, NULL);
if (pcSpriteArea)
{
pcWindow->sprite_area = pcSpriteArea;
}
pcWindow->icons[0].data.indirected_sprite.area = pcSpriteArea;
whWindow = wimp_create_window (pcWindow);
free((void *)pcWindow);
return whWindow;
}
//////////////////////////////////////////////////////////////////
// Create a menu from a text string - usually kept in the messages file
wimp_menu * CreateMenu (char * szMenu)
{
wimp_menu *pcMenu;
char * pcBuffer;
char * nAt = 0;
char * nAt2 = 0;
int nWidth = 0;
wimp_menu_flags uFlags;
char szMenuString[512];
char * pcMenuString;
int nMenuItems;
char *szItem;
int nMenuEntry;
int nStringLen;
nMenuItems = -1;
szItem = szMenu;
while (szItem)
{
nMenuItems++;
szItem = strchr(szItem + 1, ',');
}
pcMenu = (wimp_menu*)malloc (wimp_SIZEOF_MENU(nMenuItems));
pcBuffer = (char *)malloc (strlen(szMenu));
nAt = strchr (szMenu, ',');
if (!nAt)
{
nAt = (char *)strlen (szMenu);
}
else
{
nAt -= (int)szMenu;
}
strncpy (szMenuString, szMenu, (int)nAt);
szMenuString[(int)nAt] = 0;
if (strlen (szMenuString) >= 12)
{
strcpy (pcBuffer, szMenuString);
pcMenu->title_data.indirected_text.text = pcBuffer;
pcBuffer += strlen (szMenuString) + 1;
uFlags = wimp_MENU_TITLE_INDIRECTED;
}
else
{
strncpy (pcMenu->title_data.text, szMenuString, 12);
uFlags = 0u;
}
pcMenu->title_fg = wimp_COLOUR_BLACK;
pcMenu->title_bg = wimp_COLOUR_LIGHT_GREY;
pcMenu->work_fg = wimp_COLOUR_BLACK;
pcMenu->work_bg = wimp_COLOUR_WHITE;
pcMenu->height = 44;
pcMenu->gap = 0;
nMenuEntry = 0;
do
{
pcMenu->entries[nMenuEntry].sub_menu = (wimp_menu*)-1;
pcMenu->entries[nMenuEntry].icon_flags = wimp_ICON_TEXT
| wimp_ICON_FILLED
| (wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT);
nAt2 = nAt + 1;
nAt = strchr (szMenu + (int)nAt2, ',');
if (!nAt)
{
nAt = (char *)strlen (szMenu) + 1;
}
else
{
nAt -= (int)szMenu;
}
strncpy (szMenuString, szMenu + (int)nAt2, (int)nAt - (int)nAt2);
szMenuString[(int)nAt - (int)nAt2] = 0;
pcMenuString = szMenuString;
if (pcMenuString[0] == '+')
{
uFlags = wimp_MENU_TICKED;
pcMenuString++;
}
if (pcMenuString[0] == '-')
{
uFlags |= wimp_MENU_SEPARATE;
pcMenuString++;
}
if (pcMenuString[0] == '|')
{
uFlags |= wimp_MENU_WRITABLE;
pcMenuString++;
}
if (pcMenuString[0] == '>')
{
pcMenuString++;
if (gnMenuWins < (int)sizeof(gawhMenuWinHandle))
{
gawhMenuWinHandle[gnMenuWins] = LoadTemplate (pcMenuString);
pcMenu->entries[nMenuEntry].sub_menu
= (wimp_menu*)gawhMenuWinHandle[gnMenuWins];
gnMenuWins++;
}
}
nStringLen = (int)strlen (pcMenuString);
if (strlen (pcMenuString) >= 12)
{
pcMenu->entries[nMenuEntry].icon_flags |= wimp_ICON_INDIRECTED;
pcMenu->entries[nMenuEntry].data.indirected_text.text = pcBuffer;
pcMenu->entries[nMenuEntry].data.indirected_text.validation = NULL;
pcMenu->entries[nMenuEntry].data.indirected_text.size = nStringLen + 1;
strcpy (pcBuffer, pcMenuString);
pcBuffer += nStringLen + 1;
}
else
{
strncpy (pcMenu->entries[nMenuEntry].data.text, pcMenuString, 12);
}
pcMenu->entries[nMenuEntry].menu_flags = uFlags;
if (nStringLen > nWidth)
{
nWidth = nStringLen;
}
nMenuEntry++;
uFlags = 0u;
} while ((int)nAt < (int)strlen (szMenu));
pcMenu->width = (nWidth + 1) * 16;
pcMenu->entries[nMenuEntry - 1].menu_flags |= wimp_MENU_LAST;
return pcMenu;
}