| 1 | /* | 
    
      | 2 | * Copyright (c) 2021-2022 joshua stein <jcs@jcs.org> | 
    
      | 3 | * | 
    
      | 4 | * Permission to use, copy, modify, and distribute this software for any | 
    
      | 5 | * purpose with or without fee is hereby granted, provided that the above | 
    
      | 6 | * copyright notice and this permission notice appear in all copies. | 
    
      | 7 | * | 
    
      | 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | 
    
      | 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | 
    
      | 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | 
    
      | 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | 
    
      | 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | 
    
      | 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | 
    
      | 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 
    
      | 15 | */ | 
    
      | 16 |  | 
    
      | 17 | #ifndef __CHATTER_H__ | 
    
      | 18 | #define __CHATTER_H__ | 
    
      | 19 |  | 
    
      | 20 | #include <stdio.h> | 
    
      | 21 |  | 
    
      | 22 | #include "focusable.h" | 
    
      | 23 | #include "irc.h" | 
    
      | 24 | #include "util.h" | 
    
      | 25 |  | 
    
      | 26 | #define PROGRAM_NAME			"Wallops" | 
    
      | 27 | #define HOMEPAGE				"http://jcs.org/wallops" | 
    
      | 28 |  | 
    
      | 29 | #define CHATTER_FONT			geneva | 
    
      | 30 | #define CHATTER_FONT_SIZE		10 | 
    
      | 31 |  | 
    
      | 32 | #define MBAR_ID					128 | 
    
      | 33 |  | 
    
      | 34 | #define NOTIFICATION_ICON_ID	128 | 
    
      | 35 |  | 
    
      | 36 | #define ABOUT_DLOG_ID			130 | 
    
      | 37 |  | 
    
      | 38 | #define APPLE_MENU_ID			128 | 
    
      | 39 | #define APPLE_MENU_ABOUT_ID		1 | 
    
      | 40 |  | 
    
      | 41 | #define FILE_MENU_ID			129 | 
    
      | 42 | #define FILE_MENU_CONNECT_ID	1 | 
    
      | 43 | #define FILE_MENU_QUIT_ID		3 | 
    
      | 44 |  | 
    
      | 45 | #define EDIT_MENU_ID			130 | 
    
      | 46 | #define EDIT_MENU_CUT_ID		1 | 
    
      | 47 | #define EDIT_MENU_COPY_ID		2 | 
    
      | 48 | #define EDIT_MENU_PASTE_ID		3 | 
    
      | 49 |  | 
    
      | 50 | #define VIEW_MENU_ID			131 | 
    
      | 51 | #define VIEW_MENU_PREV_TAB_ID	1 | 
    
      | 52 | #define VIEW_MENU_NEXT_TAB_ID	2 | 
    
      | 53 | #define VIEW_MENU_CLOSE_ID		3 | 
    
      | 54 | #define VIEW_MENU_IGNORE_ID		4 | 
    
      | 55 |  | 
    
      | 56 | #define IGNORE_MENU_ID			132 | 
    
      | 57 | #define IGNORE_MENU_JOINS_ID	1 | 
    
      | 58 | #define IGNORE_MENU_QUITS_ID	2 | 
    
      | 59 | #define IGNORE_MENU_NICKS_ID	3 | 
    
      | 60 |  | 
    
      | 61 | #define WINDOW_MENU_ID			133 | 
    
      | 62 | #define WINDOW_MENU_HIDE_ID		1 | 
    
      | 63 | #define WINDOW_MENU_N_ID		3 | 
    
      | 64 |  | 
    
      | 65 | #define WAIT_TYPE_NONE			(1 << 0) | 
    
      | 66 | #define WAIT_TYPE_BACKGROUND	(1 << 1) | 
    
      | 67 | #define WAIT_TYPE_FOREGROUND	(1 << 2) | 
    
      | 68 | #define WAIT_TYPE_URGENT		(1 << 3) | 
    
      | 69 |  | 
    
      | 70 | #define IGNORE_NONE				(1 << 0) | 
    
      | 71 | #define IGNORE_JOINS			(1 << 1) | 
    
      | 72 | #define IGNORE_QUITS			(1 << 2) | 
    
      | 73 | #define IGNORE_NICKS			(1 << 3) | 
    
      | 74 |  | 
    
      | 75 | struct chatter_tab { | 
    
      | 76 | SLIST_ENTRY(chatter_tab) list; | 
    
      | 77 | struct irc_connection *conn; | 
    
      | 78 | struct irc_channel *channel; | 
    
      | 79 | char query_nick[member_size(struct irc_user, nick)]; | 
    
      | 80 | TEHandle messages_te; | 
    
      | 81 | ControlHandle messages_scroller; | 
    
      | 82 | ListHandle nick_list; | 
    
      | 83 | Rect label_rect; | 
    
      | 84 | bool have_activity; | 
    
      | 85 | bool ignore_activity; | 
    
      | 86 | }; | 
    
      | 87 | SLIST_HEAD(chatter_tabs_head, chatter_tab); | 
    
      | 88 |  | 
    
      | 89 | struct chatter { | 
    
      | 90 | struct focusable *focusable; | 
    
      | 91 | WindowPtr win; | 
    
      | 92 | BitMap shadow; | 
    
      | 93 | Rect shadow_bounds; | 
    
      | 94 | short shadow_refcnt; | 
    
      | 95 | TEHandle input_te; | 
    
      | 96 | char input[IRC_MAX_MSG_SIZE]; | 
    
      | 97 | char tab_comp_input[member_size(struct irc_user, nick)]; | 
    
      | 98 | char tab_comp_match[member_size(struct irc_user, nick)]; | 
    
      | 99 | bool quitting; | 
    
      | 100 | bool need_tab_bar_redraw; | 
    
      | 101 | short ntabs; | 
    
      | 102 | struct chatter_tabs_head tabs_list; | 
    
      | 103 | struct chatter_tab *current_tab; | 
    
      | 104 | }; | 
    
      | 105 |  | 
    
      | 106 | extern MenuHandle apple_menu, file_menu, edit_menu, view_menu, ignore_menu, | 
    
      | 107 | window_menu; | 
    
      | 108 |  | 
    
      | 109 | void notify(void); | 
    
      | 110 | void cancel_notification(void); | 
    
      | 111 |  | 
    
      | 112 | struct chatter * chatter_init(const char *server, | 
    
      | 113 | const unsigned short port, const char *password, const char *nick, | 
    
      | 114 | const char *ident, const char *realname, bool hide_motd, | 
    
      | 115 | const char *channel); | 
    
      | 116 | void chatter_update_titlebar(struct chatter *chatter); | 
    
      | 117 | size_t chatter_printf(struct chatter *chatter, struct irc_connection *conn, | 
    
      | 118 | char *dest_tab, const char *format, ...); | 
    
      | 119 | void chatter_insert_to_nick_list(struct chatter *chatter, | 
    
      | 120 | struct irc_channel *channel, struct irc_channel_nick *nick, short pos); | 
    
      | 121 | void chatter_remove_from_nick_list(struct chatter *chatter, | 
    
      | 122 | struct irc_channel *channel, struct irc_channel_nick *nick, short pos); | 
    
      | 123 | void chatter_sync_nick_list(struct chatter *chatter, | 
    
      | 124 | struct irc_channel *channel); | 
    
      | 125 | void chatter_clear_messages(struct chatter *chatter, | 
    
      | 126 | struct chatter_tab *tab); | 
    
      | 127 | struct chatter_tab * chatter_add_tab(struct chatter *chatter, | 
    
      | 128 | Rect *win_bounds, struct irc_connection *conn, | 
    
      | 129 | struct irc_channel *channel, char *query_nick); | 
    
      | 130 | void chatter_close_tab(struct chatter *chatter, struct chatter_tab *tab); | 
    
      | 131 | struct chatter_tab * chatter_find_tab(struct chatter *chatter, | 
    
      | 132 | struct irc_connection *conn, char *dest_tab); | 
    
      | 133 |  | 
    
      | 134 | #endif |