--------------------------------------------------------------------------
-- Notepad.lua
--------------------------------------------------------------------------
--[[

	-- Author
	Copyright (C) 2004  Vladimir Vukicevic <vladimir@pobox.com>
	- Bugfixes and Send Note functionality is added by <zespr@mail.ru>
	- Updated for World of Warcraft 2.0 by Darius Makaitis (Feithar - Stonespire)

	-- Description
	This file is part of the Notepad AddOn for Blizzard Entertainment
	Inc. World of Warcraft

	-- Changes
	2.0	- Initial version

  -- SVN info
	$Id: Notepad.lua 4911 2007-05-24 17:46:36Z Gryphon $
	$Rev: 4911 $
	$LastChangedBy: Gryphon $
	$Date: 2007-05-24 12:46:36 -0500 (Thu, 24 May 2007) $

]]--

-------------------------------------------------------------------------------
--
-- Constants
--
-------------------------------------------------------------------------------

-- this is the max number of buttons that we have available, numbered 1 through this value
NOTEPAD_MAX_BUTTONS = 25;

-- Debug
NOTEPAD_DEBUG = false

-------------------------------------------------------------------------------
--
-- Global Variables
--
-------------------------------------------------------------------------------

-- All the entries; this is an array of tables,
-- with each table having a "title" and "body" attribute.
Notepad_Entries = nil;
Notepad_EntriesGlobal = {};

-- Currently selected entry. 0 = no/new entry.
Notepad_SelectedEntryGlobal = 0;

-- Default Notepad configuration.
Notepad_Config = {};
Notepad_Config.acceptNotes = true;
Notepad_Config.acceptDuplicates = false;

Notepad_SaveByKhaosProfile = nil

--
-- UI state variables
--

-- Are we resizing?
local Notepad_IsResizing = 0;

-- The number of visible entry buttons
local Notepad_NumVisibleEntryButtons = 0;
local Notepad_CurrentOffset = 0;

StaticPopupDialogs["NOTEPAD_SEND_NOTE"] = {
	text = TEXT(NOTEPAD_SEND_NOTE_LABEL),
	button1 = TEXT(ACCEPT),
	button2 = TEXT(CANCEL),
	editText = "",
	hasEditBox = 1,
	maxLetters = 12,

	OnAccept = function()
		local editBox = getglobal(this:GetParent():GetName().."EditBox");
			Notepad_SendNote(editBox:GetText());
		end,
		OnShow = function()
		getglobal(this:GetName().."EditBox"):SetText(StaticPopupDialogs["NOTEPAD_SEND_NOTE"].editText);
		getglobal(this:GetName().."EditBox"):SetFocus();
	end,

	OnHide = function()
		if ( ChatFrameEditBox:IsVisible() ) then
			ChatFrameEditBox:SetFocus();
		end
		getglobal(this:GetName().."EditBox"):SetText("");
	end,

	EditBoxOnEnterPressed = function()
		local editBox = getglobal(this:GetParent():GetName().."EditBox");
		Notepad_SendNote(editBox:GetText());
		this:GetParent():Hide();
	end,

	EditBoxOnEscapePressed = function()
		this:GetParent():Hide();
	end,

	timeout = 0,
	exclusive = 1,
	whileDead = 1
};

UIPanelWindows["NotepadFrame"] = { area = "left", pushable = 5, whileDead = 1 };

-------------------------------------------------------------------------------
--
-- Library Functions
--
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------
--
-- Normal Functions
--
-------------------------------------------------------------------------------

--[[
-- Logs a message to the default chat frame if Notepad is running in debug mode.
--]]
local function Notepad_LogDebug(text)
	if ( NOTEPAD_DEBUG ) then
		DEFAULT_CHAT_FRAME:AddMessage("DEBUG: " .. text);
	end
	if (Sea and Sea.io and Sea.io.dprint) then
		Sea.io.dprint(NOTEPAD_DEBUG, text);
	end
end

--[[
-- Toggles the visibility of the Notepad frame.
--]]
function Notepad_Toggle()
	Notepad_LogDebug("Notepad_Toggle()");

	if (NotepadFrame:IsVisible()) then
		HideUIPanel(NotepadFrame);
	else
		ShowUIPanel(NotepadFrame);
	end
end

--[[
-- Registers Notepad with Khaos.
--]]
function Notepad_RegisterForKhaos()
	Notepad_LogDebug("Notepad_RegisterForKhaos()");

	-- Register our option set...
	local optionSet = {
		id="Notepad";
		text=NOTEPAD_KHAOS_TEXT;
		helptext=NOTEPAD_KHAOS_HELP;
		difficulty=1;
		default=true;
		options={
			{
				id="Notepad_SaveByKhaosProfile";
				text = NOTEPAD_KHAOS_SAVEBYKHAOSPROFILE_TEXT;
				helptext = NOTEPAD_KHAOS_SAVEBYKHAOSPROFILE_HELP;
				type = K_TEXT;
				check = true;
				callback = function(state) Notepad_Khaos_SaveByProfileToggle(state.checked); end;
				feedback = function(state) end;
				default = {checked = true};
				disabled = {checked = false};
			};
		};
	};

	Khaos.registerOptionSet("other", optionSet);
end

--[[
-- Enable Using Khaos profile Notepad data.
--]]
function Notepad_EnableKhaosSaving()
	Notepad_LogDebug("Notepad_EnableKhaosSaving()");

	Notepad_Entires = Sea.table.copy ( Notepad_EntriesGlobal )
	Khaos.registerGlobal("Notepad_Entries");
	Khaos.registerGlobal("Notepad_SelectedEntry");
	Notepad_Global = false;

	Khaos.registerConfigurationLoadNotice( {
		id="NotepadRedraw";
		onConfigurationChange=function()
		Notepad_UpdateEntryList();
		if ( Notepad_SelectedEntry ~= 0 ) then
			Notepad_LoadEntry(Notepad_SelectedEntry);
		end
		end;
		description="Redraws the notepad when the configuration is changed.";
	} )
end

--[[
-- Disable saving with Khaos and load Global
--]]
function Notepad_DisableKhaosSaving()
	Notepad_LogDebug("Notepad_DisableKhaosSaving()");

	Khaos.unregisterGlobal("Notepad_Entries")
	Notepad_Entries = Notepad_EntriesGlobal;

	Khaos.unregisterGlobal("Notepad_SelectedEntry")
	Notepad_SelectedEntry = Notepad_SelectedEntryGlobal

	Notepad_Global = true

	Khaos.unregisterConfigurationLoadNotice("NotepadRedraw" )

	-- Refresh
	Notepad_UpdateEntryList();
	if ( Notepad_SelectedEntry ~= 0 ) then
		Notepad_LoadEntry(Notepad_SelectedEntry);
	end
end

function Notepad_DecodeMessage(note, who)
	Notepad_LogDebug("Notepad_DecodeMessage(..., ...)");

	local index = string.find(note,">",11,true);
	local title = string.sub(note, 11, index - 1);
	local body = string.sub(note, index + 1);
	local yl = LIGHTYELLOW_FONT_COLOR_CODE;
	local ct = FONT_COLOR_CODE_CLOSE;

	if (not Notepad_Config.acceptDuplicates) then
		for index, entry in pairs(Notepad_Entries) do
			if (entry.title == title) then
				DEFAULT_CHAT_FRAME:AddMessage(yl .. "You received a notepad note from player " .. who .. ct);
				DEFAULT_CHAT_FRAME:AddMessage(yl .. "Title: " .. title .. ct);
				DEFAULT_CHAT_FRAME:AddMessage(yl .. "You already have entry(s) with this title in your notepad" .. ct);
				DEFAULT_CHAT_FRAME:AddMessage(yl .. "Note is discarded" .. ct);
				return;
			end
		end
	end

	--	local entryIndex = table.getn(Notepad_Entries) + 1;
	--	table.setn(Notepad_Entries, entryIndex);
	local entryIndex = Notepad_GetNextUnusedIndex();

	local newEntry = {};
	newEntry.title = title;
	newEntry.body = body;
	Notepad_Entries[entryIndex] = newEntry;

	Notepad_UpdateEntryList();

	DEFAULT_CHAT_FRAME:AddMessage(yl .. "You received a notepad note from player " .. who .. ct);
	DEFAULT_CHAT_FRAME:AddMessage(yl .. "Title: " .. title .. ct);
end

--[[
-- Sends the currently active note to the given player using Telepathy.
--]]
function Notepad_SendNote(player)
	Notepad_LogDebug("Notepad_SendNote(...)");

	local title = NotepadEntryTitleEditBox:GetText();
	local body = NotepadEntryEditBox:GetText();
	local message = string.format("%s%s%s%s","<Notepad><",title,">",body);
	local yl = LIGHTYELLOW_FONT_COLOR_CODE;
	local ct = FONT_COLOR_CODE_CLOSE;

	DEFAULT_CHAT_FRAME:AddMessage(yl .. "Sending message to player " .. player .. ct);
	Telepathy.sendMessage("Notepad", message, "WHISPER",  player, "BULK");
end

--[[
-- Take the window's current height and show the appropriate number of buttons
--]]
function Notepad_UpdateEntryButtonVisibility()
	Notepad_LogDebug("Notepad_UpdateEntryButtonVisibility()");

	local buttonHeight, frameHeight, numButtons, numEntries;

	local uiScale = GetCVar("uiscale");

	buttonHeight = 24;
	frameHeight = NotepadEntriesScrollFrame:GetHeight() + 5; -- 5 seems to be a magic fudge factor!
	if ( GetCVar("useUiScale") == "1" ) then
		if (uiScale) then
			frameHeight = frameHeight / uiScale;
		end
	end

	numButtons = frameHeight / buttonHeight;
	numEntries = getn(Notepad_Entries);

	for i=1, NOTEPAD_MAX_BUTTONS do
		local theButton = getglobal ("NotepadEntry" .. i);
		if ( i <= numButtons and i <= numEntries ) then
			theButton:Show();
		else
			theButton:Hide();
		end
	end

	Notepad_NumVisibleEntryButtons = floor(numButtons);
end

--[[
-- Figure out where to set the various faux scroll frame bits
--]]
function Notepad_UpdateScrollFrame()
	Notepad_LogDebug("Notepad_UpdateScrollFrame()");
	FauxScrollFrame_Update(NotepadEntriesScrollFrame,
			  table.getn(Notepad_Entries),
			  Notepad_NumVisibleEntryButtons,
			  32);
end

--[[
-- On loading, make sure that our current button state is set up, and do UI
-- hook setup
--]]
function Notepad_Initialize()
	Notepad_LogDebug("Notepad_Initialize()");
	-- Checking for old saved Notepad_Entries
	if Notepad_Entries == nil then
		Notepad_Entries = Notepad_EntriesGlobal
	else
		Notepad_EntriesGlobal = Notepad_Entries
	end

	Notepad_SelectedEntry = Notepad_SelectedEntryGlobal
	Notepad_Global = true

	if ( Khaos ) then
		Notepad_RegisterForKhaos()
	end

	-- If FeatureFrame is loaded, add a button so the user can get to Notepad
	-- through the FeatureFrame menu
	if ( FeatureFrame_AddButton ) then
		FeatureFrame_AddButton( {
			id="Notepad";
			name=TEXT(NOTEPAD_BUTTON_NAME);
			subtext=TEXT(NOTEPAD_BUTTON_DESC);
			tooltip=TEXT(NOTEPAD_BUTTON_LONGDESC);
			icon="Interface\\AddOns\\Notepad\\Skin\\Notepad_Icon";
			callback=Notepad_Toggle;
		} );
        elseif ( Cosmos_RegisterButton ) then
                   Cosmos_RegisterButton (TEXT(NOTEPAD_BUTTON_NAME),
                                          TEXT(NOTEPAD_BUTTON_DESC),
                                          TEXT(NOTEPAD_BUTTON_LONGDESC),
                                          "Interface\\AddOns\\Notepad\\Skin\\Notepad_Icon",
                                          Notepad_Toggle);
	end

	if ( Telepathy )then
		Telepathy.registerListener ( "Notepad", { "WHISPER" }, Notepad_Telepathy_OnMessageReceived );
	else
		NotepadSendNoteButton:Disable();
	end
end

--[[
-- Saves the currently active note entry.
--]]
function Notepad_SaveCurrentEntry()
	Notepad_LogDebug("Notepad_SaveCurrentEntry()");

	local title = NotepadEntryTitleEditBox:GetText();
	local body = NotepadEntryEditBox:GetText();

	-- If the body and title are empty, we don't save
	if (title == "" and body == "") then
		return;
	end

	-- Otherwise
	local entryIndex = Notepad_SelectedEntry;
	if ( entryIndex == 0 ) then
		--	entryIndex = table.getn(Notepad_Entries) + 1;
		--	table.setn(Notepad_Entries, entryIndex);
		entryIndex = Notepad_GetNextUnusedIndex();
	end

	local entry = {};
	entry.title = title;
	entry.body = body;
	Notepad_Entries[entryIndex] = entry;
	Notepad_SelectedEntrySetValue( entryIndex );

	Notepad_UpdateEntryList();
end

--[[
-- Simple function to also update global settings when we are using those.
--]]
function Notepad_SelectedEntrySetValue( value )
	Notepad_LogDebug("Notepad_SelectedEntrySetValue(...)");

	if Notepad_Global then
		Notepad_SelectedEntry = value
		Notepad_SelectedEntryGlobal = value
	else
		Notepad_SelectedEntry = value
	end
end

--[[
-- Updates the note entry buttons to display the correct number/titles.
--]]
function Notepad_UpdateEntryList()
	Notepad_LogDebug("Notepad_UpdateEntryList()");

	Notepad_UpdateEntryButtonVisibility();
	Notepad_UpdateScrollFrame();
	Notepad_FauxScrollFrame_UpdateEntries();
end

--[[
-- Load the entry with the given index.
--]]
function Notepad_LoadEntry(aEntryId)
	Notepad_LogDebug("Notepad_LoadEntry("..aEntryId..")");

	Notepad_SelectedEntrySetValue( aEntryId );
	NotepadEntryTitleEditBox:SetText(Notepad_Entries[aEntryId].title);
	NotepadEntryEditBox:SetText(Notepad_Entries[aEntryId].body);

	if (false) then
		-- is the tab visible?
		if (aEntryId < Notepad_CurrentOffset or (Notepad_CurrentOffset + Notepad_NumVisibleEntryButtons) >= aEntryId) then
			local newOffset;
			-- no; place it at the start or the end
			if ( aEntryId < Notepad_CurrentOffset ) then
				newOffset = aEntryId;
			else
				newOffset = aEntryId - Notepad_NumVisibleEntryButtons;
			end

			Notepad_CurrentOffset = newOffset;
			FauxScrollFrame_SetOffset(NotepadEntriesScrollFrame, newOffset);
		end
	end
end

--[[
-- Clears the note entry interface, essentially creating a new, empty note.
--]]
function Notepad_ClearEntry()
	Notepad_LogDebug("Notepad_ClearEntry()");

	Notepad_SelectedEntrySetValue(0);
	NotepadEntryTitleEditBox:SetText("");
	NotepadEntryEditBox:SetText("");
	NotepadEntryTitleEditBox:SetFocus();
end

--[[
-- Hides the Notepad frame when the user presses the Escape key.
--
-- TODO: Is this even necessary, or is it taken care of automagically?
--]]
--function Notepad_EscapeHide()
--	Notepad_LogDebug("Notepad_EscapeHide()");
--
--	if ( NotepadFrame:IsVisible() ) then
--		NotepadFrame:Hide();
--		return false;
--	else
--		return true;
--	end
--end

function Notepad_OnEntryBodyTextChanged()
	Notepad_LogDebug("Notepad_OnEntryBodyTextChanged()");

	-- borrowed from MailFrame.xml; update the scrollbar
	local scrollBar = getglobal(this:GetParent():GetParent():GetName().."ScrollBar");
	this:GetParent():GetParent():UpdateScrollChildRect();
	local min, max
	min, max = scrollBar:GetMinMaxValues();
	if ( max > 0 and (this.max ~= max) ) then
		this.max = max
		scrollBar:SetValue(max);
	end
end

--[[
-- Obtains the index of the first empty note in the database, for creating a
-- new entry.
--]]
function Notepad_GetNextUnusedIndex()
	Notepad_LogDebug("Notepad_GetNextUnusedIndex()");

	local index = 1
	while ( Notepad_Entries[index] ~= nil ) do
		index = index + 1;
	end
	return index;
end

-------------------------------------------------------------------------------
--
-- Callback Functions
--
-------------------------------------------------------------------------------

--[[
-- Called by Khaos when the user clicks the "Save the notepad based on profile"
-- button.
--]]
function Notepad_Khaos_SaveByProfileToggle( checked )
	Notepad_LogDebug("Notepad_Khaos_SaveByProfileToggle(...)");

	if Notepad_SaveByKhaosProfile == checked then
		return
	end

	Notepad_SaveByKhaosProfile = checked;

	if checked then
		Notepad_EnableKhaosSaving()
	else
		Notepad_DisableKhaosSaving()
	end
end

--[[
-- Called by Telepathy when a message is received from another user.
--]]
function Notepad_Telepathy_OnMessageReceived(message, sender, method)
	Notepad_LogDebug("Notepad_Telepathy_OnMessageReceived(..., ..., ...)");
	if (Notepad_Config.acceptNotes)	then
		Notepad_DecodeMessage(message, sender)
	end
end

--[[
-- Called from FauxScrollFrame when the user scrolls through the note entry buttons
--]]
function Notepad_FauxScrollFrame_UpdateEntries()
	Notepad_LogDebug("Notepad_FauxScrollFrame_UpdateEntries()");

	Notepad_CurrentOffset = FauxScrollFrame_GetOffset(NotepadEntriesScrollFrame);
	for i=1, min(Notepad_NumVisibleEntryButtons, table.getn(Notepad_Entries)) do
		local button = getglobal("NotepadEntry" .. i);
		button:SetText(Notepad_Entries[Notepad_CurrentOffset + i].title);
	end
end

-------------------------------------------------------------------------------
--
-- Event Handlers
--
-------------------------------------------------------------------------------

function Notepad_NotepadEntryButtonTemplate_OnClick(aButtonID)
	Notepad_LogDebug("Notepad_NotepadEntryButtonTemplate_OnClick("..aButtonID..")");

	Notepad_SaveCurrentEntry();

	local entryId = Notepad_CurrentOffset + aButtonID;
	Notepad_LoadEntry(entryId);
end

-------------------------------------------------------------------------------

function Notepad_Frame_OnLoad()
	Notepad_LogDebug("Notepad_OnLoad()");
	this:RegisterForDrag("LeftButton");
	this:RegisterEvent("VARIABLES_LOADED");
end

--
-- Notepad event handler
--
-- We only care about VARIABLES_LOADED, so that we can load the previously
-- selected entry and initialize the scroll frame
function Notepad_Frame_OnEvent(event)
--	Notepad_LogDebug("Notepad_OnEvent("..event..")");
	if event == "VARIABLES_LOADED" then
		Notepad_Initialize()

		-- we finally (!) have our variables loaded, grrr
		Notepad_UpdateEntryList()

		if ( Notepad_SelectedEntry ~= 0 ) then
			Notepad_LoadEntry(Notepad_SelectedEntry);
		end
		NotepadFrame:UnregisterEvent("VARIABLES_LOADED")
	end
end

function Notepad_Frame_OnDragStart()
	Notepad_LogDebug("Notepad_OnDragStart()");
	this:StartMoving();
end

function Notepad_Frame_OnDragStop()
	Notepad_LogDebug("Notepad_OnDragStop()");
	this:StopMovingOrSizing();
end

function Notepad_Frame_OnEscapePressed()
	Notepad_LogDebug("Notepad_Frame_OnEscapePressed()");
	HideUIPanel(NotepadFrame);
end

function Notepad_Frame_OnClick()
	Notepad_LogDebug("Notepad_Frame_OnClick()");
	NotepadEntryEditBox:SetFocus();
end

-------------------------------------------------------------------------------

function Notepad_NotepadCloseButton_OnClick(aArg)
	Notepad_LogDebug("Notepad_NotepadCloseButton_OnClick(...)");
	HideUIPanel(NotepadFrame);
end

-------------------------------------------------------------------------------

function Notepad_NotepadResizeButton_OnMouseDown(aWhichCorner)
	Notepad_LogDebug("Notepad_NotepadResizeButton_OnMouseDown(...)");
	Notepad_IsResizing = 1;
	this:GetParent():StartSizing(aWhichCorner);
end

function Notepad_NotepadResizeButton_OnMouseUp()
	Notepad_LogDebug("Notepad_NotepadResizeButton_OnMouseUp()");
	Notepad_IsResizing = 0;

	this:GetParent():StopMovingOrSizing();
end

-------------------------------------------------------------------------------

function Notepad_NotepadNewNoteButton_OnClick()
	Notepad_LogDebug("Notepad_NotepadNewNoteButton_OnClick()");
	Notepad_SaveCurrentEntry();
	Notepad_ClearEntry();
end

-------------------------------------------------------------------------------

function Notepad_NotepadDeleteNoteButton_OnClick()
	Notepad_LogDebug("Notepad_NotepadDeleteNoteButton_OnClick()");
	if ( Notepad_SelectedEntry ~= 0 ) then
		table.remove(Notepad_Entries, Notepad_SelectedEntry);
	end

	Notepad_ClearEntry();
	Notepad_UpdateEntryList();
end

-------------------------------------------------------------------------------

function Notepad_NotepadSendNoteButton_OnClick()
	Notepad_LogDebug("Notepad_NotepadSendNoteButton_OnClick()");
	local name = "";
	--	if ( UnitCanCooperate("player", "target") ) then
	if ( UnitIsPlayer("target") and UnitIsFriend("player","target")) then
		name = UnitName("target");
	end
	StaticPopupDialogs["NOTEPAD_SEND_NOTE"].editText = name;
	StaticPopup_Show("NOTEPAD_SEND_NOTE");
end

-------------------------------------------------------------------------------

function Notepad_NotepadEntriesScrollFrame_OnScrollRangeChanged()
	Notepad_LogDebug("Notepad_NotepadEntriesScrollFrame_OnScrollRangeChanged()");
	Notepad_UpdateEntryList();
end

function Notepad_NotepadEntriesScrollFrame_OnSizeChanged()
	Notepad_LogDebug("Notepad_NotepadEntriesScrollFrame_OnSizeChanged()");
	Notepad_UpdateEntryList();
end

function Notepad_NotepadEntriesScrollFrame_OnVerticalScroll()
	Notepad_LogDebug("Notepad_NotepadEntriesScrollFrame_OnVerticalScroll()");
	FauxScrollFrame_OnVerticalScroll(32, Notepad_FauxScrollFrame_UpdateEntries);
end

-------------------------------------------------------------------------------

function Notepad_NotepadEntryTitleEditBox_OnTabPressed()
	Notepad_LogDebug("Notepad_NotepadEntryTitleEditBox_OnTabPressed()");
	NotepadEntryEditBox:SetFocus();
end

function Notepad_NotepadEntryTitleEditBox_OnEscapePressed()
	Notepad_LogDebug("Notepad_NotepadEntryTitleEditBox_OnEscapePressed()");
	this:ClearFocus();
end

function Notepad_NotepadEntryTitleEditBox_OnClick()
	Notepad_LogDebug("Notepad_NotepadEntryTitleEditBox_OnClick()");
	this:SetFocus();
end

function Notepad_NotepadEntryTitleEditBox_OnEditFocusLost()
	Notepad_LogDebug("Notepad_NotepadEntryTitleEditBox_OnEditFocusLost()");
	Notepad_SaveCurrentEntry();
end

-------------------------------------------------------------------------------

function Notepad_NotepadEntryEditBox_OnTabPressed()
	Notepad_LogDebug("Notepad_NotepadEntryEditBox_OnTabPressed()");
	NotepadEntryTitleEditBox:SetFocus();
end

function Notepad_NotepadEntryEditBox_OnEscapePressed()
	Notepad_LogDebug("Notepad_NotepadEntryEditBox_OnEscapePressed()");
	this:ClearFocus();
end

function Notepad_NotepadEntryEditBox_OnTextChanged()
	Notepad_LogDebug("Notepad_NotepadEntryEditBox_OnTextChanged()");
	ScrollingEdit_OnTextChanged();
end

function Notepad_NotepadEntryEditBox_OnEditFocusLost()
	Notepad_LogDebug("Notepad_NotepadEntryEditBox_OnEditFocusLost()");
	Notepad_SaveCurrentEntry();
end

function Notepad_NotepadEntryEditBox_OnCursorChanged(arg1, arg2, arg3, arg4)
	Notepad_LogDebug("Notepad_NotepadEntryEditBox_OnCursorChanged(..., ..., ..., ...)");
	ScrollingEdit_OnCursorChanged(arg1, arg2, arg3, arg4);
end

function Notepad_NotepadEntryEditBox_OnUpdate()
--	Notepad_LogDebug("Notepad_OnEntryBodyTextUpdate()");
	ScrollingEdit_OnUpdate();
	NotepadEntryEditBox:SetWidth(NotepadFrame:GetWidth() - 220);
end

-------------------------------------------------------------------------------

function Notepad_NotepadEntryScrollFrame_OnMouseUp()
	Notepad_LogDebug("Notepad_NotepadEntryScrollFrame_OnMouseUp()");
	NotepadEntryEditBox:SetFocus();
end