X11workbench Toolkit  1.0
edit_window.h
Go to the documentation of this file.
1 // _ _ _ _ _ _ //
3 // ___ __| |(_)| |_ __ __(_) _ __ __| | ___ __ __| |__ //
4 // / _ \ / _` || || __| \ \ /\ / /| || '_ \ / _` | / _ \\ \ /\ / /| '_ \ //
5 // | __/| (_| || || |_ \ V V / | || | | || (_| || (_) |\ V V /_| | | | //
6 // \___| \__,_||_| \__|_____\_/\_/ |_||_| |_| \__,_| \___/ \_/\_/(_)_| |_| //
7 // |_____| //
8 // //
9 // a window into which you can type (and edit) text //
10 // //
12 
13 /*****************************************************************************
14 
15  X11workbench - X11 programmer's 'work bench' application and toolkit
16  Copyright (c) 2010-2019 by Bob Frazier (aka 'Big Bad Bombastic Bob')
17 
18 
19  DISCLAIMER: The X11workbench application and toolkit software are supplied
20  'as-is', with no warranties, either implied or explicit.
21  Any claims to alleged functionality or features should be
22  considered 'preliminary', and might not function as advertised.
23 
24  MIT-like license:
25 
26  There is no restriction as to what you can do with this software, so long
27  as you include the above copyright notice and DISCLAIMER for any distributed
28  work that is equal to or derived from this one, along with this paragraph
29  that explains the terms of the license if the source is also being made
30  available. A "derived work" describes a work that uses a significant portion
31  of the source files or algorithms that are included with this one.
32  Specifically excluded from this are files that were generated by the software,
33  or anything that is included with the software that is part of another package
34  (such as files that were created or added during the 'configure' process).
35  Specifically included is the use of part or all of any of the X11 workbench
36  toolkit source or header files in your distributed application. If you do not
37  ship the source, the above copyright statement is still required to be placed
38  in a reasonably prominent place, such as documentation, splash screens, and/or
39  'about the application' dialog boxes.
40 
41  Use and distribution are in accordance with GPL, LGPL, and/or the above
42  MIT-like license. See COPYING and README files for more information.
43 
44 
45  Additional information at http://sourceforge.net/projects/X11workbench
46 
47 ******************************************************************************/
48 
49 
50 #ifndef _EDIT_WINDOW_H_INCLUDED_
51 #define _EDIT_WINDOW_H_INCLUDED_
52 
53 #include "text_object.h"
54 #include "frame_window.h"
55 #include "child_frame.h"
56 
57 
73 #define EDIT_WINDOW_TAG (*((const unsigned int * const)"FWEW"))
74 
75 
76 #ifdef __cplusplus
77 extern "C" {
78 #endif // __cplusplus
79 
80 // OBSOLETE 'IDEA' CODE, LEFT FOR REFERENCE
81 //
82 //typedef struct tagWBLineBuffer
83 //{
84 // int iLength; // length of buffer (not including the structure size)
85 // int iMaxPos; // maximum position into which any text has been entered (usually end of line)
86 // int iEndOfLine; // the actual end of line (not counting trailing white space)
87 // struct tagWBLineBuffer *pPrev, *pNext; // linked list of buffers
88 // char data[4]; // the actual data for the line (typically ASCII)
89 // // variable length following this
90 //} WBLineBuffer;
91 //
92 //typedef struct
93 //{
94 // Window wSelf, wOwner; // window identifiers for self, owner
95 // WB_FONT pFont; // default font for the window
96 // WBLineBuffer *pStart, *pEnd; // pointers to start and end of linked buffer list
97 // WBLineBuffer *pBufArray; // array of buffers for visible lines
98 // int nBufArray; // maximum size of buffer array
99 // int iTop, iHeight, iLeft, iWidth; // line/char position and size of client area
100 // // iTop corresponds to pBufArray[0]
101 // int iMaxWidth, iMaxHeight; // size of document in lines and chars
102 // int iFlags; // various flags associated with the window
103 // char *pszFileName; // file name associated with edit window
104 //
105 //} WBEditWindow;
106 //
107 //enum
108 //{
109 // WBEditWindowFlags_EncodingMask = 0x7,
110 // WBEditWindowFlags_EncodingASCII = 0x0,
111 // WBEditWindowFlags_EncodingUTF8 = 0x1,
112 // WBEditWindowFlags_EncodingUTF16 = 0x2,
113 // WBEditWindowFlags_EncodingOther = 0x3, // 'other' implies locales, etc. (reserved)
114 //
115 //};
116 
117 
158 typedef struct tagWBEditWindow
159 {
161 
162  unsigned int ulTag;
163 
164  char *szFileName;
165 
166 #if defined(HAVE_LONGLONG) || defined(__DOXYGEN__)
167  unsigned long long llModDateTime;
168 #else // defined(HAVE_LONGLONG) || defined(__DOXYGEN__)
169  unsigned long llModDateTime;
170 #endif // defined(HAVE_LONGLONG) || defined(__DOXYGEN__)
171 
173 
175 
176 } WBEditWindow;
177 
178 
179 // external atoms associated with edit windows, documented elsewhere
180 
181 #ifndef _EDIT_WINDOW_C_IMPLEMENTED_
182 extern Atom aEW_HOVER_NOTIFY;
183 extern Atom aEW_EDIT_CHANGE;
184 #endif // _EDIT_WINDOW_C_IMPLEMENTED_
185 
203  const char *szFocusMenu, const WBFWMenuHandler *pHandlerArray,
204  int fFlags);
205 
206 
217 void WBDestroyEditWindow(WBEditWindow *pEditWindow);
218 
219 
231 
232 
244 int WBEditWindowLoadFile(WBEditWindow *pEditWindow, const char *pszFileName);
245 
246 
258 int WBEditWindowSaveFile(WBEditWindow *pEditWindow, const char *pszFileName);
259 
260 
270 void WBEditWindowClear(WBEditWindow *pEditWindow);
271 
272 
281 static __inline__ int WBIsValidEditWindow(WBEditWindow *pEditWindow)
282 {
283  if(!pEditWindow || // invalid pointer (TODO: check range?)
284  pEditWindow->childframe.ulTag != CHILD_FRAME_TAG || // child frame tag not valid
285  pEditWindow->ulTag != EDIT_WINDOW_TAG) // edit window tag not valid
286  {
287  return 0; // NOT valid.
288  }
289 
290  return 1;
291 }
292 
293 
294 // CALLBACK REGISTRATION
295 
296 
313 void WBEditWindowRegisterCallback(WBEditWindow *pEditWindow, WBWinEvent pUserCallback);
314 
315 
316 
317 
318 #ifdef __cplusplus
319 };
320 #endif // __cplusplus
321 
322 #endif // _EDIT_WINDOW_H_INCLUDED_
323 
int WBEditWindowLoadFile(WBEditWindow *pEditWindow, const char *pszFileName)
Open an existing file and read its contents into the Edit Window, storing the file name for later ref...
Definition: edit_window.c:446
WBChildFrame childframe
elements common to a 'child frame' (derived object)
Definition: edit_window.h:160
WBEditWindow * WBCreateEditWindow(WBFrameWindow *pOwner, WB_FONT pFont, const char *szFocusMenu, const WBFWMenuHandler *pHandlerArray, int fFlags)
Create an Edit Window.
Definition: edit_window.c:276
WBWinEvent pUserCallback
user callback function to receive notifications and unhandled messages
Definition: edit_window.h:172
structure for managing menu callbacks
Definition: frame_window.h:217
char * szFileName
malloc'd name of file associated with this edit window (NULL if none)
Definition: edit_window.h:164
unsigned int ulTag
'Tag' identifying this structure as a WBEditWindow
Definition: edit_window.h:162
Atom aEW_EDIT_CHANGE
'Edit Change' notification to user-callback, sent via ClientMessage event
Definition: edit_window.c:210
'base class' structure for TEXT_OBJECT
Definition: text_object.h:893
Structure that defines an Edit Window.
Definition: edit_window.h:158
void WBEditWindowRegisterCallback(WBEditWindow *pEditWindow, WBWinEvent pUserCallback)
Clear the contents in the Edit Window, and NULL the stored file name.
Definition: edit_window.c:578
Child Frame API functions.
#define CHILD_FRAME_TAG
TAG for the WBChildFrame structure.
Definition: child_frame.h:94
#define EDIT_WINDOW_TAG
TAG for the WBEditWindow structure.
Definition: edit_window.h:73
A 'C++'-like object for managing text, that can be overridden for custom behavior.
unsigned int ulTag
tag indicating I'm a 'Child Frame' window
Definition: frame_window.h:428
int(* WBWinEvent)(Window wID, XEvent *pEvent)
event callback function type for window events
main controlling structure for frame windows
Definition: frame_window.h:274
Atom aEW_HOVER_NOTIFY
Hover notification to user-callback, sent via ClientMessage event.
Definition: edit_window.c:192
WBEditWindow * WBEditWindowFromWindowID(Window wID)
Obtain the associated WBEditWindow structure pointer for a Window ID.
Definition: edit_window.c:432
TEXT_OBJECT xTextObject
the 'TEXT_OBJECT' member, that does MOST of the work
Definition: edit_window.h:174
struct tagWBEditWindow WBEditWindow
Structure that defines an Edit Window.
unsigned long long llModDateTime
file's mod date/time - see WBGetFileModDateTime()
Definition: edit_window.h:167
An allocated structure containing XFontStruct, XFontInfo, and XftFont [as applicable] for a specified...
Definition: font_helper.h:152
int WBEditWindowSaveFile(WBEditWindow *pEditWindow, const char *pszFileName)
Save the contents from the Edit Window to a file, overwriting the file if it already exists.
Definition: edit_window.c:538
void WBDestroyEditWindow(WBEditWindow *pEditWindow)
Destroy an Edit Window.
Definition: edit_window.c:390
Structure that defines a Child Frame within a Frame Window.
Definition: frame_window.h:426
void WBEditWindowClear(WBEditWindow *pEditWindow)
Clear the contents in the Edit Window, and NULL the stored file name.
Definition: edit_window.c:564
static __inline__ int WBIsValidEditWindow(WBEditWindow *pEditWindow)
Check for valid WBEditWindow pointer.
Definition: edit_window.h:281
Frame Window API functions and definitions.