1 // High level document window stuff
2 // Copyright (C) 2000 Core Technologies.
3 
4 // This file is part of e93.
5 //
6 // e93 is free software; you can redistribute it and/or modify
7 // it under the terms of the e93 LICENSE AGREEMENT.
8 //
9 // e93 is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // e93 LICENSE AGREEMENT for more details.
13 //
14 // You should have received a copy of the e93 LICENSE AGREEMENT
15 // along with e93; see the file "LICENSE.TXT".
16 
17 #include	"includes.h"
18 
LocateEditorDocumentWindow(char * bufferName)19 EDITOR_WINDOW *LocateEditorDocumentWindow(char *bufferName)
20 // attempt to locate a preexisting document window that
21 // is open to absolutePath, if one is found, return it
22 // if none is located, return NULL
23 {
24 	EDITOR_BUFFER
25 		*buffer;
26 
27 	if((buffer=LocateBuffer(bufferName)))
28 	{
29 		return(buffer->window);
30 	}
31 	return(NULL);
32 }
33 
EditorReassignDocumentWindowTitle(EDITOR_BUFFER * buffer)34 void EditorReassignDocumentWindowTitle(EDITOR_BUFFER *buffer)
35 // if buffer has a window associated with it, assign the
36 // window's title based on buffer's contentName
37 // if there is no window, do nothing
38 {
39 	char
40 		*windowTitle;
41 
42 	if(buffer->window)
43 	{
44 		if(buffer->fromFile)
45 		{
46 			if((windowTitle=CreateWindowTitleFromPath(buffer->contentName)))
47 			{
48 				SetDocumentWindowTitle(buffer->window,windowTitle);			// change the window's title
49 				MDisposePtr(windowTitle);									// get rid of memory
50 			}
51 			else
52 			{
53 				SetDocumentWindowTitle(buffer->window,buffer->contentName);	// had problem getting new name, use path
54 			}
55 		}
56 		else
57 		{
58 			SetDocumentWindowTitle(buffer->window,buffer->contentName);		// change the window's title
59 		}
60 	}
61 }
62 
EditorOpenDocumentWindow(EDITOR_BUFFER * buffer,EDITOR_RECT * rect,char * fontName,UINT32 tabSize,EDITOR_COLOR foreground,EDITOR_COLOR background)63 EDITOR_WINDOW *EditorOpenDocumentWindow(EDITOR_BUFFER *buffer,EDITOR_RECT *rect,char *fontName,UINT32 tabSize,EDITOR_COLOR foreground,EDITOR_COLOR background)
64 // create a new document edit window for buffer, place it as the front-most
65 // NOTE: if there is already a document window for buffer
66 // place it front-most, and return it
67 // if there is a problem, SetError, return NULL
68 {
69 	EDITOR_WINDOW
70 		*window;
71 	EDITOR_VIEW
72 		*view;
73 	char
74 		*titleToDelete,
75 		*windowTitle;
76 
77 	if(buffer->window)
78 	{
79 		view=GetDocumentWindowCurrentView(buffer->window);
80 		SetEditorDocumentWindowRect(buffer->window,rect);			// adjust the rectangle
81 		SetEditorViewStyleFont(view,0,fontName);					// and the font
82 		SetEditorViewTabSize(view,tabSize);							// and the tabsize
83 		SetEditorViewStyleForegroundColor(view,0,foreground);		// set colors for style 0
84 		SetEditorViewStyleBackgroundColor(view,0,background);
85 		SetEditorDocumentWindowForegroundColor(buffer->window,foreground);	// set the new colors
86 		SetEditorDocumentWindowBackgroundColor(buffer->window,background);
87 		SetTopDocumentWindow(buffer->window);						// place it on top
88 	}
89 	else
90 	{
91 		titleToDelete=NULL;
92 		if(buffer->fromFile)
93 		{
94 			titleToDelete=CreateWindowTitleFromPath(buffer->contentName);
95 		}
96 		if(titleToDelete)
97 		{
98 			windowTitle=titleToDelete;
99 		}
100 		else
101 		{
102 			windowTitle=buffer->contentName;
103 		}
104 		if((window=OpenDocumentWindow(buffer,rect,windowTitle,fontName,tabSize,foreground,background)))
105 		{
106 			buffer->window=window;
107 		}
108 		if(titleToDelete)
109 		{
110 			MDisposePtr(titleToDelete);
111 		}
112 	}
113 	return(buffer->window);
114 }
115 
EditorCloseDocumentWindow(EDITOR_WINDOW * window)116 void EditorCloseDocumentWindow(EDITOR_WINDOW *window)
117 // close the given edit window (do not destroy the buffer it is tied to)
118 // this is not allowed to fail
119 {
120 	window->buffer->window=NULL;							// point the buffer that had this window to NULL
121 	CloseDocumentWindow(window);							// get rid of the window
122 }
123