blob: baae0eed857567c99773dfb2428f3b41d2d610be [file] [log] [blame]
PulkoMandy9e780862023-04-21 22:52:16 +02001
PulkoMandya3e9cfe2023-04-10 10:01:36 +02002// BeDC.h //
3// The header file to use with BeDC //
4// //
5// Written By: Magnus Landahl //
6// E-Mail: magnus.landahl@swipnet.se //
7// //
8// Copyright © Magnus Landahl - Stockholm 2000 //
9//////////////////////////////////////////////////////////////////////////
10
11#ifndef _BE_DC_H_
12#define _BE_DC_H_
13
14//Messages types
15#define DC_MESSAGE 0
16#define DC_SUCCESS DC_MESSAGE + 1
17#define DC_ERROR DC_MESSAGE + 2
18#define DC_SEPARATOR DC_MESSAGE + 3
19#define DC_CLEAR DC_MESSAGE + 4
20//---------------
21
22//Color defines
23#define DEF_COLOR 0
24#define DC_WHITE DEF_COLOR + 1
25#define DC_BLACK DEF_COLOR + 2
26#define DC_BLUE DEF_COLOR + 3
27#define DC_RED DEF_COLOR + 4
28#define DC_YELLOW DEF_COLOR + 5
29#define DC_GREEN DEF_COLOR + 6
30//---------------
31
32#define BEDC_MESSAGE 'bedc'
33
34#define BEDC_MAIN_TYPE 0
35#define BEDC_BMESSAGE BEDC_MAIN_TYPE + 1
36#define BEDC_PLAIN_MESSAGE BEDC_MAIN_TYPE + 2
37#define BEDC_VER "1.0"
38
39#include <TypeConstants.h>
40#include <SupportDefs.h>
41#include <Messenger.h>
42#include <Message.h>
43#include <String.h>
44#include <string.h>
45#include <stdio.h>
46#include <Point.h>
47#include <Rect.h>
48
49class BeDC
50{
51 ////////////////////////////////////////////////
52 // Public Procedures
53
54 public:
55 BeDC(const char *c_name = "Application", int8 color = DEF_COLOR){
56 name = strdup(c_name);
57 s_color = color;
58 }
59
60 ~BeDC(){
61 delete name;
62 }
63
64 //Send a message
PulkoMandyc25f5422023-04-10 15:22:01 +020065 void SendMessage(const char *text, int8 type = DC_MESSAGE){
PulkoMandya3e9cfe2023-04-10 10:01:36 +020066 BMessage message(BEDC_MESSAGE);
67 message.AddString( "bedc_name", name);
68 message.AddInt8( "bedc_type", type);
69 message.AddString( "bedc_text", text);
70 message.AddInt8( "bedc_color", s_color);
71 message.AddString( "bedc_ver", BEDC_VER);
72 message.AddInt8( "bedc_main_type", BEDC_PLAIN_MESSAGE);
73 SendMessageToApp(&message);
74 }
75 //---------------
76
77 //Send a format string - parameters
PulkoMandy9e780862023-04-21 22:52:16 +020078 void SendFormat(const char *text, ...) __attribute__((format(printf, 2, 3))) {
79 BString str;
80
81 va_list args;
82 va_start(args, text);
83 str.SetToFormatVarArgs(text, args);
84 va_end(args);
85
86 SendMessage(str.String(), DC_MESSAGE);
87 }
88
89 void SendFormatV(const char *text, va_list args) __attribute__((format(printf, 2, 0))) {
90 BString str;
91 va_list copyOfArgs;
92 va_copy(copyOfArgs, args);
93 str.SetToFormatVarArgs(text, args);
94 va_end(copyOfArgs);
95 SendMessage(str.String(), DC_MESSAGE);
96 }
97
98 void SendFormatT(const char *text, int8 type, ...) __attribute__((format(printf, 2, 4))) {
PulkoMandya3e9cfe2023-04-10 10:01:36 +020099 char buffer[1024];
100 va_list args;
101
102 va_start(args, type);
103 vsprintf(buffer, text, args);
104 va_end(args);
105 SendMessage(buffer, type);
106 }
107 //---------------
108
109 //Dump a BMessage
110 void DumpBMessage(BMessage *Message, const char *desc = "", int8 type = DC_MESSAGE){
111 Message->AddInt32( "bedc_what", Message->what);
112 Message->AddInt8( "bedc_main_type", BEDC_BMESSAGE);
113
114 Message->AddInt8( "bedc_type", type);
115 Message->AddString( "bedc_name", name);
116 Message->AddString( "bedc_desc", desc);
117 Message->AddInt8( "bedc_color",s_color);
118 Message->AddString( "bedc_ver", BEDC_VER);
119
120 Message->what = BEDC_MESSAGE;
121 SendMessageToApp(Message);
122 }
123 //---------------
124
125 //Send a separator (Add a separator)
126 void AddSeparator(){
127 SendMessage("Separator", DC_SEPARATOR);
128 }
129 //---------------
130
131 //Send a clear message (Clear the window that is online)
132 void Clear(){
133 SendMessage("Clear", DC_CLEAR);
134 }
135 //---------------
136
137 //Send an Int32
138 void SendInt( int32 integer, const char *desc = NULL, int8 type = DC_MESSAGE){
139 str.SetTo("");
140 if (desc != NULL) str << desc; else
141 str << "Integer: ";
142 str << integer;
143 SendMessage((char *)str.String(),type);
144 }
145 //---------------
146
147 //Send an Int64
148 void SendInt( int64 integer, const char *desc = NULL, int8 type = DC_MESSAGE){
149 str.SetTo("");
150 if (desc != NULL) str << desc; else
151 str << "Integer: ";
152 str << integer;
153 SendMessage((char *)str.String(),type);
154 }
155 //---------------
156
157 //Send a BPoint
158 void SendPoint( BPoint point, const char *desc = NULL, int8 type = DC_MESSAGE){
159 str.SetTo("");
160 if (desc != NULL) str << desc; else
161 str << "Point: ";
162 str << "X = " << point.x << " Y = " << point.y;
163 SendMessage((char *)str.String(),type);
164 }
165 //---------------
166
167 //Send a BRect
168 void SendRect( BRect rect, const char *desc = NULL, int8 type = DC_MESSAGE){
169 str.SetTo("");
170 if (desc != NULL) str << desc; else
171 str << "Rectangle: ";
172 str << "Left = " << rect.left << " Top = " << rect.top
173 << " Right = " << rect.right << " Bottom = " << rect.bottom;
174 SendMessage((char *)str.String(),type);
175 }
176 //---------------
177
178 ////////////////////////////////////////////
179 // Private Data
180 private:
181 char *name;
182 int8 s_color;
183 BString str;
184
185 void SendMessageToApp(BMessage *Msg){
186 BMessenger messenger("application/x-vnd.ml-BeDCApp");
187 if (messenger.IsValid()) messenger.SendMessage(Msg);
188 }
189};
190
191#endif