📄 chatwindow.tcl
字号:
proc ContainerConfigured { window } { #only run this if the window is the outer window if { ![string equal $window [winfo toplevel $window]]} { return } set chatid [::ChatWindow::Name $window] if { $chatid != 0 } { after cancel "::ChatWindow::TopUpdate $chatid" after 200 "::ChatWindow::TopUpdate $chatid" } set geometry [wm geometry $window] set pos_start [string first "+" $geometry] #Look if the window changed size with the configure if {[::config::getKey wincontainersize] != "[string range $geometry 0 [expr {$pos_start-1}]]"} { set sizechanged 1 } else { set sizechanged 0 } #Save size of current container if { [::config::getKey savechatwinsize] } { ::config::setKey wincontainersize [string range $geometry 0 [expr {$pos_start-1}]] } #If the window changed size use checkfortoomanytabs if { [winfo exists ${window}.bar] && $sizechanged} { CheckForTooManyTabs $window 0 } } #/////////////////////////////////////////////////////////////////////////////// # ::ChatWindow::Flicker (chatid, [count]) # Called when a window must flicker, and called by itself to produce the flickering # effect. It will flicker the window until it gets the focus. # Arguments: # - chatid => Is the name of the chat to flicker (a passport login) # - count => [NOT REQUIRED] Can be any number, it's just used in self calls proc Flicker {chatid {count 0}} { if { [::ChatWindow::For $chatid] != 0 } { set window [::ChatWindow::For $chatid] } else { if { [winfo exists $chatid] } { set window $chatid } else { return 0 } } set ::ChatWindow::titles($window) [EscapeTitle [set ::ChatWindow::titles($window)]] set container [GetContainerFromWindow $window] if { $container != "" } { FlickerTab $window Flicker $container return } if { [::config::getKey flicker] == 0 } { if { [string first $window [focus]] != 0 } { catch {wm title ${window} "*$::ChatWindow::titles($window)"} res set ::ChatWindow::new_message_on(${window}) "asterisk" bind ${window} <FocusIn> "::ChatWindow::GotFocus ${window}" } return 0 } after cancel ::ChatWindow::Flicker $chatid 0 after cancel ::ChatWindow::Flicker $chatid 1 if { [string first $window [focus]] != 0 } { # If user uses Windows, call winflash to flash the window, this is done by # calling the winflash proc that should be created by the flash.dll extension # so we do it in a catch statement, if it fails. Then load the extension before # calling winflash. If this one or the first one were successful, we add a bind # on FocusIn to call the winflash with the -state 0 option to disable it and we return. if { [set ::tcl_platform(platform)] == "windows" } { if { [catch {linflash $window -count -1} ] } { if { ![catch { package require winflash winflash $window -count -1 } ] } { bind $window <FocusIn> "catch \" winflash $window -state 0\"; bind $window <FocusIn> \"\"" return } } else { bind $window <FocusIn> "catch \" winflash $window -state 0\"; bind $window <FocusIn> \"\"" return } #if on the X window system } elseif { [OnUnix] } { if { [catch {linflash $window}] } { if { ![catch { package require linflash linflash $window } ] } { bind $window <FocusIn> "catch \" linunflash $window \"; bind $window <FocusIn> \"\"" return } } else { bind $window <FocusIn> "catch \" linunflash $window \"; bind $window <FocusIn> \"\"" return } } set count [expr {( $count +1 ) % 2}] if {![catch { if { $count == 1 } { wm title ${window} "[trans newmsg]" } else { wm title ${window} "$::ChatWindow::titles($window)" } } res]} { after 300 ::ChatWindow::Flicker $chatid $count } set ::ChatWindow::new_message_on(${window}) "flicker" } else { catch {wm title ${window} "$::ChatWindow::titles($window)"} res catch {unset ::ChatWindow::new_message_on(${window})} } } #/////////////////////////////////////////////////////////////////////////////// #/////////////////////////////////////////////////////////////////////////////// # ::ChatWindow::For (chatid) # Returns the name of the window (.msg_n) that should show the messages and # information related to the chat 'chatid'. # Arguments: # - chatid => Is the chat id of the window, the passport account of the buddy proc For { chatid } { if { [info exists ::ChatWindow::msg_windows($chatid)]} { return $::ChatWindow::msg_windows($chatid) } return 0 } #/////////////////////////////////////////////////////////////////////////////// #/////////////////////////////////////////////////////////////////////////////// # ::ChatWindow::GotFocus (window) # Called when a window with a new msg gets the focus and goes back to its title # Arguments: # - window => Is the window widget focused (.msg_n - Where n is an integer) proc GotFocus { window } { if { [info exists ::ChatWindow::new_message_on(${window})] && \ $::ChatWindow::new_message_on(${window}) == "asterisk" } { unset ::ChatWindow::new_message_on(${window}) catch {wm title ${window} "[EscapeTitle $::ChatWindow::titles(${window})]"} res bind ${window} <FocusIn> "" } } #/////////////////////////////////////////////////////////////////////////////// #/////////////////////////////////////////////////////////////////////////////// # ::ChatWindow::MacPosition # To place the ::ChatWindow::Open at the right place on Mac OS X, because the # window manager will put all the windows in bottom left after some time. # Arguments: proc MacPosition { window } { #To know where the window manager want to put the window in X and Y set window [winfo toplevel $window] set info1 [winfo x $window] set info2 [winfo y $window] #Determine the maximum place in Y to place a window #Size of the screen (in y) - size of the window set max [expr {[winfo vrootheight $window] - [winfo height $window]}] #If the position of the window in y is superior to the maximum #Then up the window by the size of the window if { $info2 > $max } { set info2 [expr {$info2 - [winfo height $window]}] } #If the result is smaller than 25 (on small screen) then use 25 if { $info2 < 25 } { set info2 25 } #Replace the window to the new position on the screen wm geometry $window +${info1}+${info2} } #/////////////////////////////////////////////////////////////////////////////// #/////////////////////////////////////////////////////////////////////////////// # ::ChatWindow::MakeFor (chatid, [msg ""], [usr_name ""]) # Opens a window if it did not existed, and if it is the first message it adds # the message to a notify window (::amsn::notifyAdd), and plays sound if enabled # Arguments: # - chatid => Is the chat id of the window, the passport account of the buddy # - [msg ""] => [NOT REQUIRED] The message sent to us (first message) # - [usr_name ""] => [NOT REQUIRED] Is the user who sends the message proc MakeFor { chatid {msg ""} {usr_name ""} } { set lastfocus [focus] set win_name [::ChatWindow::For $chatid] # If there wasn't a window created and assigned to $chatid, let's create one # through ::ChatWindow::Open and assign it to $chatid with ::ChatWindow::SetFor if { $win_name == 0 } { if { [UseContainer] == 0 } { set win_name [::ChatWindow::Open] ::ChatWindow::SetFor $chatid $win_name } else { set container [::ChatWindow::GetContainerFor $chatid] set win_name [::ChatWindow::Open $container] ::ChatWindow::SetFor $chatid $win_name ::ChatWindow::NameTabButton $win_name $chatid set_balloon $::ChatWindow::win2tab($win_name) "--command--::ChatWindow::SetNickText $chatid" ::ChatWindow::SwitchToTab $container [::ChatWindow::GetCurrentWindow $container] } #update idletasks ::ChatWindow::TopUpdate $chatid if { [::config::getKey showdisplaypic] && $usr_name != ""} { ::amsn::ChangePicture $win_name [::skin::getDisplayPicture $usr_name] [trans showuserpic $usr_name] } else { ::amsn::ChangePicture $win_name [::skin::getDisplayPicture $usr_name] [trans showuserpic $usr_name] nopack } } set top_win [winfo toplevel $win_name] # PostEvent 'new_conversation' to notify plugins that the window was created if { $::ChatWindow::first_message($win_name) == 1 } { set evPar(chatid) chatid set evPar(usr_name) usr_name ::plugins::PostEvent new_conversation evPar } # If this is the first message, and no focus on window, then show notify if { $::ChatWindow::first_message($win_name) == 1 && $msg!="" } { set ::ChatWindow::first_message($win_name) 0 if { [::config::getKey newmsgwinstate] == 0 } { if { [winfo exists .bossmode] } { set ::BossMode(${win_name}) "normal" wm state ${top_win} withdraw } else { wm state ${top_win} normal } wm deiconify ${top_win} if { ![catch {tk windowingsystem} wsystem] && $wsystem == "aqua" } { # lower ${top_win} ::ChatWindow::MacPosition ${top_win} } else { raise ${top_win} } } else { # Iconify the window unless it was raised by the user already. if { [wm state $top_win] != "normal" && [wm state $top_win] != "zoomed" } { if { [winfo exists .bossmode] } { set ::BossMode(${top_win}) "iconic" wm state ${top_win} withdraw } else { wm state ${top_win} iconic } } } if { [string first ${win_name} [focus]] != 0} { if { ([::config::getKey notifymsg] == 1 && [::abook::getContactData $chatid notifymsg -1] != 0) || [::abook::getContactData $chatid notifymsg -1] == 1 } { ::amsn::notifyAdd "$msg" "::amsn::chatUser $chatid" #Regive focus on Mac OS X if { ![catch {tk windowingsystem} wsystem] && $wsystem == "aqua" } { after 1000 "catch {focus -force $lastfocus}" } } } } elseif { $msg == "" } { #If it's not a message event, then it's a window creation (user joins to chat) if { [::config::getKey newchatwinstate] == 0 } { if { [winfo exists .bossmode] } { set ::BossMode(${top_win}) "normal" wm state ${top_win} withdraw } else { wm state ${top_win} normal } wm deiconify ${top_win} #To have the new window "behind" on Mac OS X if { ![catch {tk windowingsystem} wsystem] && $wsystem == "aqua" } { #lower ${top_win} ::ChatWindow::MacPosition ${top_win} } else { raise ${top_win} } } else { #Container for tabs might be non-iconified if { [wm state $top_win] != "normal" } { if { [winfo exists .bossmode] } { set ::BossMode(${top_win}) "iconic" wm state ${top_win} withdraw } else { wm state ${top_win} iconic } } } } #If no focus, and it's a message event, do something to the window if { (([::config::getKey soundactive] == "1" && $usr_name != [::config::getKey login]) || \ [string first ${win_name} [focus]] != 0) && $msg != "" } { play_sound type.wav } #Dock Bouncing on Mac OS X if { ![catch {tk windowingsystem} wsystem] && $wsystem == "aqua" } { # tclCarbonNotification is in plugins, we have to require it package require tclCarbonNotification # Bounce unlimited of time when we are not in aMSN and receive a # message, until we re-click on aMSN icon (or get back to aMSN) if { (([::config::getKey dockbounce] == "unlimited" && $usr_name != [::config::getKey login]) \ && [focus] == "") && $msg != "" } { if {[catch {tclCarbonNotification 1 ""} res]} { status_log $res } } # Bounce then stop bouncing after 1 second, when we are not # in aMSN and receive a message (default) if { (([::config::getKey dockbounce] == "once" && $usr_name != [::config::getKey login]) \ && [focus] == "") && $msg != "" } { if {[catch {tclCarbonNotification 1 ""} res]} { status_log $res } after 1000 [list catch [list tclEndCarbonNotification]] } } return $win_name } #/////////////////////////////////////////////////////////////////////////////// #/////////////////////////////////////////////////////////////////////////////// # ::ChatWindow::Name (window) # This proc returns the user login (chatid) of the buddy in that chat. # Arguments: # - window => Is the chat window widget (.msg_n - Where n is an integer) proc Name { window } { if { [info exists ::ChatWindow::chat_ids($window)]} { return $::ChatWindow::chat_ids($window) } return 0 } #/////////////////////////////////////////////////////////////////////////////// # ::ChatWindow::getAllChatIds # Returns a list of all chatids of all open windows proc getAllChatIds { } { set chatids ""
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -