📄 baseimcontainer.mm
字号:
// get message data m_data = [[TextTool getTextData:message faceList:nil] retain]; // calculate fragment count m_fragmentCount = ([m_data length] - 1) / kQQMaxMessageFragmentLength + 1; if(m_fragmentCount > 1) { // set next index m_nextFragmentIndex = 0; // send first fragment NSData* messageData = [NSData dataWithBytes:[m_data bytes] length:kQQMaxMessageFragmentLength]; m_waitingSequence = [self doSend:messageData style:style fragmentCount:m_fragmentCount fragmentIndex:m_nextFragmentIndex]; m_nextFragmentIndex++; } else { // send message m_waitingSequence = [self doSend:m_data style:style fragmentCount:1 fragmentIndex:0]; [m_data release]; m_data = nil; } } else { // build sending list [m_faceSendingList removeAllObjects]; for(int i = 0; i < [m_faceList count]; i++) { CustomFace* face = [m_faceList face:i includeReference:NO]; if(face == nil) break; else [m_faceSendingList setObject:face forKey:[face filename]]; } // begin sending custom face [self sendCustomFaces:m_faceList]; }}- (void)sendCustomFaces:(CustomFaceList*)faceList { NSLog(@"Send Custom Face, Subclass must implement this");}- (UInt16)doSend:(NSData*)data style:(FontStyle*)style fragmentCount:(int)fragmentCount fragmentIndex:(int)fragmentIndex { return 0;}- (void)handleHistoryDidSelected:(NSNotification*)notification {}- (void)handleCustomFaceFailedToReceive:(NSNotification*)notification { NSString* filename = [notification object]; NSNumber* loc = [m_faceWaitingList objectForKey:filename]; if(loc) { NSString* path = [[NSBundle mainBundle] pathForImageResource:kImageNoSuchImage]; [m_txtOutput replaceCustomFaceAtIndex:[loc intValue] path:path]; [m_faceWaitingList removeObjectForKey:filename]; }}- (void)handleCustomFaceDidReceived:(NSNotification*)notification { NSString* filename = [notification object]; NSNumber* loc = [m_faceWaitingList objectForKey:filename]; if(loc) { NSString* path = [FileTool getReceivedCustomFacePath:[[m_mainWindowController me] QQ] file:filename]; [m_txtOutput replaceCustomFaceAtIndex:[loc intValue] path:path]; [m_faceWaitingList removeObjectForKey:filename]; }}- (void)handleCustomFaceListFailedToSend:(NSNotification*)notification { if([m_faceSendingList count] > 0) { CustomFaceList* faceList = [notification object]; if(faceList == m_faceList) { // clear sending list [m_faceSendingList removeAllObjects]; // append error hint if count is 0 NSAttributedString* hint = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:L(@"LQHintCustomFaceFailedToSend", @"BaseIMContainer"), [[notification userInfo] objectForKey:kUserInfoErrorMessage]] attributes:m_errorHintAttributes]; [[m_txtOutput textStorage] appendAttributedString:hint]; // cancel sending current message [m_sendQueue removeObjectAtIndex:0]; // send next message m_sending = NO; [self sendNextMessage]; } }}- (void)handleCustomFaceDidSent:(NSNotification*)notification { if([m_faceSendingList count] > 0) { CustomFace* face = [notification object]; if([face owner] == [[self owner] intValue]) { [m_faceSendingList removeObjectForKey:[face filename]]; if([m_faceSendingList count] == 0) { // get next message NSAttributedString* message = [m_sendQueue objectAtIndex:0]; // generate font style FontStyle* style = [FontTool chatFontStyleWithPreference:[[m_mainWindowController me] QQ]]; // get message data m_data = [[TextTool getTextData:message faceList:m_faceList] retain]; // calculate fragment count m_fragmentCount = ([m_data length] - 1) / kQQMaxMessageFragmentLength + 1; if(m_fragmentCount > 1) { // set next index m_nextFragmentIndex = 0; // send first fragment NSData* messageData = [NSData dataWithBytes:[m_data bytes] length:kQQMaxMessageFragmentLength]; m_waitingSequence = [self doSend:messageData style:style fragmentCount:m_fragmentCount fragmentIndex:m_nextFragmentIndex]; m_nextFragmentIndex++; } else { // send message m_waitingSequence = [self doSend:m_data style:style fragmentCount:1 fragmentIndex:0]; [m_data release]; m_data = nil; } } } }}- (void)handleIMContainerAttachedToWindow:(NSNotification*)notification { }- (void)handleModelMessageCountChanged:(NSNotification*)notification { if(m_obj == [notification object]) [self setObjectCount:3];}#pragma mark -#pragma mark actions- (IBAction)onFont:(id)sender { NSFontManager* fm = [NSFontManager sharedFontManager]; [fm orderFrontFontPanel:self];}- (IBAction)onColor:(id)sender { NSColorPanel* colorPanel = [NSColorPanel sharedColorPanel]; [colorPanel setTarget:self]; [colorPanel setAction:@selector(onColorChanged:)]; [colorPanel orderFront:self];}- (IBAction)onSmiley:(id)sender { if(m_faceSelector) return; // get button bound NSRect bound = [m_txtInput bounds]; // calculate bound = [m_txtInput convertRect:bound toView:nil]; bound.origin.y += bound.size.height; // create image selector window controller with frame m_faceSelector = [[ImageSelectorWindowController alloc] initWithDataSource:[[[FaceSelectorDataSource alloc] initWithFaceManager:[m_mainWindowController faceManager] showCustomFace:[self allowCustomFace]] autorelease] delegate:self]; [m_faceSelector showWindow:self]; [[m_faceSelector window] setFrameOrigin:[[m_imView window] convertBaseToScreen:bound.origin]];}- (IBAction)onColorChanged:(id)sender { NSColor* color = [sender color]; [m_txtInput setTextColor:color];}- (IBAction)onFaceManager:(id)sender { [[m_mainWindowController windowRegistry] showFaceManagerWindow:[[m_mainWindowController me] QQ] mainWindow:m_mainWindowController];}- (IBAction)onSendPicture:(id)sender { // open open panel NSOpenPanel* panel = [NSOpenPanel openPanel]; [panel setAllowsMultipleSelection:NO]; [panel setCanChooseDirectories:NO]; [panel setCanChooseFiles:YES]; [panel beginSheetForDirectory:NSHomeDirectory() file:nil types:[NSArray arrayWithObjects:@"jpg", @"gif", @"bmp", @"png", @"tiff", nil] modalForWindow:[m_imView window] modalDelegate:self didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:) contextInfo:nil];}- (IBAction)onScreenscrap:(id)sender { ScreenscrapHelper* helper = [ScreenscrapHelper sharedHelper]; [helper beginScreenscrap];}- (IBAction)onSend:(id)sender { [self send:self];}#pragma mark -#pragma mark open panel delegate- (void)openPanelDidEnd:(NSOpenPanel*)panel returnCode:(int)returnCode contextInfo:(void*)contextInfo { if(returnCode = NSOKButton) { // load image file NSString* file = [panel filename]; NSBitmapImageRep* rep = [NSBitmapImageRep imageRepWithData:[NSData dataWithContentsOfFile:file]]; if(rep == nil) return; // convert to jpg file NSData* data = [rep representationUsingType:NSJPEGFileType properties:nil]; // save to a temp file named by UUID CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault); NSString* uuidStr = (NSString*)CFUUIDCreateString(kCFAllocatorDefault, uuid); CFRelease(uuid); // write to file NSString* path = [NSString stringWithFormat:@"/tmp/{%@}.JPG", uuidStr]; [data writeToFile:path atomically:YES]; [uuidStr release]; // post notification NSNotification* n = [NSNotification notificationWithName:kTempJPGFileDidCreatedNotificationName object:data userInfo:[NSDictionary dictionaryWithObject:path forKey:kUserInfoImagePath]]; [[NSNotificationQueue defaultQueue] enqueueNotification:n postingStyle:NSPostASAP]; }}#pragma mark -#pragma mark getter and setter- (NSView*)view { return m_imView;}- (QQTextView*)inputBox { return m_txtInput;}- (QQTextView*)outputBox { return m_txtOutput;}- (History*)history { return m_history;}#pragma mark -#pragma mark image selector delegate- (void)imageChanged:(id)sender image:(NSImage*)image imageId:(id)imageId panel:(int)panelId { // check image id if(imageId) { if([imageId isKindOfClass:[NSNumber class]]) { int index = [DefaultFace code2index:[imageId intValue]]; if(index != -1) [m_txtInput insertDefaultFace:index]; } else if([imageId isKindOfClass:[NSString class]]) { Face* face = [[m_mainWindowController faceManager] face:imageId]; NSString* path = [FileTool getCustomFacePath:[[m_mainWindowController me] QQ] group:[[[m_mainWindowController faceManager] group:(panelId - 1)] name] file:[face original]]; [m_txtInput insertCustomFace:kFaceTypeCustomFace md5:imageId path:path received:NO]; } }}- (void)enterImage:(id)sender image:(NSImage*)image imageId:(id)imageId panel:(int)panelId {}- (void)exitImage:(id)sender image:(NSImage*)image imageId:(id)imageId panel:(int)panelId {}- (void)auxiliaryAction:(id)sender { [self onFaceManager:sender];}- (void)showTooltipAtPoint:(NSPoint)screenPoint image:(NSImage*)image imageId:(id)imageId panel:(int)panelId { [self showPreviewWindow]; if(imageId) { if([imageId isKindOfClass:[NSNumber class]]) { [self showPreviewWindow]; [m_ivPreview setImage:image]; [m_ivPreview setAnimates:YES]; [m_txtShortcut setStringValue:[DefaultFace code2name:[imageId intValue]]]; } else { [self showPreviewWindow]; Face* face = [[m_mainWindowController faceManager] face:imageId]; NSString* path = [FileTool getCustomFacePath:[[m_mainWindowController me] QQ] group:[[[m_mainWindowController faceManager] group:(panelId - 1)] name] file:[face original]]; NSImage* image = [[[NSImage alloc] initWithContentsOfFile:path] autorelease]; [m_ivPreview setImage:image]; [m_ivPreview setAnimates:[face multiframe]]; [m_txtShortcut setStringValue:[face shortcut]]; } }}- (void)hideTooltip { if(m_winFacePreview) { [m_winFacePreview orderOut:self]; [m_winFacePreview autorelease]; m_winFacePreview = nil; }}@end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -