test: convarea.c Source File

Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

# convarea.c

Go to the documentation of this file.

    00001 /*++
    00002
    00003 Copyright (c) 1985 - 1999, Microsoft Corporation
    00004
    00005 Module Name:
    00006
    00007     convarea.c
    00008
    00009 Abstract:
    00010
    00011 Author:
    00012
    00013     KazuM Mar.8,1993
    00014
    00015 Revision History:
    00016
    00017 --*/
    00018
    00019 #include "precomp.h"
    00020 #pragma hdrstop
    00021
    00022 #if defined(FE_IME)
    00023
    00024
    00025
    00026
    00027 VOID
    00028 LinkConversionArea(
    00029     IN PCONSOLE_INFORMATION Console,
    00030     IN PCONVERSIONAREA_INFORMATION ConvAreaInfo
    00031     )
    00032 {
    00033     PCONVERSIONAREA_INFORMATION PrevConvAreaInfo;
    00034
    00035     if (Console->ConsoleIme.ConvAreaRoot == NULL) {
    00036         Console->ConsoleIme.ConvAreaRoot = ConvAreaInfo;
    00037     }
    00038     else {
    00039         PrevConvAreaInfo = Console->ConsoleIme.ConvAreaRoot;
    00040         while (PrevConvAreaInfo->ConvAreaNext)
    00041             PrevConvAreaInfo = PrevConvAreaInfo->ConvAreaNext;
    00042         PrevConvAreaInfo->ConvAreaNext = ConvAreaInfo;
    00043     }
    00044 }
    00045
    00046
    00047 NTSTATUS
    00048 FreeConvAreaScreenBuffer(
    00049     IN PSCREEN_INFORMATION ScreenInfo
    00050     )
    00051
    00052 /*++
    00053
    00054 Routine Description:
    00055
    00056     This routine frees the memory associated with a screen buffer.
    00057
    00058 Arguments:
    00059
    00060     ScreenInfo - screen buffer data to free.
    00061
    00062 Return Value:
    00063
    00064 Note: console handle table lock must be held when calling this routine
    00065
    00066 --*/
    00067
    00068 {
    00069     return FreeScreenBuffer(ScreenInfo);
    00070 }
    00071
    00072
    00073
    00074 NTSTATUS
    00075 AllocateConversionArea(
    00076     IN PCONSOLE_INFORMATION Console,
    00077     IN COORD dwScreenBufferSize,
    00078     OUT PCONVERSIONAREA_INFORMATION *ConvAreaInfo
    00079     )
    00080 {
    00081     COORD dwWindowSize;
    00082     CHAR_INFO Fill, PopupFill;
    00083     PCONVERSIONAREA_INFORMATION ca;
    00084     int FontIndex;
    00085     NTSTATUS Status;
    00086
    00087     //
    00088     // allocate console data
    00089     //
    00090
    00091     ca = (PCONVERSIONAREA_INFORMATION)ConsoleHeapAlloc(
    00092                                                 MAKE_TAG( CONVAREA_TAG ),
    00093                                                 sizeof(CONVERSIONAREA_INFORMATION));
    00094     if (ca == NULL) {
    00095         return STATUS_NO_MEMORY;
    00096     }
    00097
    00098     dwWindowSize.X = CONSOLE_WINDOW_SIZE_X(Console->CurrentScreenBuffer);
    00099     dwWindowSize.Y = CONSOLE_WINDOW_SIZE_Y(Console->CurrentScreenBuffer);
    00100     Fill.Attributes = Console->CurrentScreenBuffer->Attributes;
    00101     PopupFill.Attributes = Console->CurrentScreenBuffer->PopupAttributes;
    00102     FontIndex = FindCreateFont(CON_FAMILY(Console),
    00103                                CON_FACENAME(Console),
    00104                                CON_FONTSIZE(Console),
    00105                                CON_FONTWEIGHT(Console),
    00106                                CON_FONTCODEPAGE(Console)
    00107                               );
    00108     Status = CreateScreenBuffer(&ca->ScreenBuffer,
    00109                                 dwWindowSize,
    00110                                 FontIndex,
    00111                                 dwScreenBufferSize,
    00112                                 Fill,
    00113                                 PopupFill,
    00114                                 Console,
    00115                                 CONSOLE_TEXTMODE_BUFFER,
    00116                                 NULL,
    00117                                 NULL,
    00118                                 NULL,
    00119                                 CURSOR_SMALL_SIZE,
    00120                                 NULL
    00121                                );
    00122     if (!NT_SUCCESS(Status)) {
    00123         ConsoleHeapFree(ca);
    00124         return Status;
    00125     }
    00126
    00127     *ConvAreaInfo = ca;
    00128
    00129     return STATUS_SUCCESS;
    00130 }
    00131
    00132
    00133
    00134 NTSTATUS
    00135 SetUpConversionArea(
    00136     IN PCONSOLE_INFORMATION Console,
    00137     IN COORD coordCaBuffer,
    00138     IN SMALL_RECT rcViewCaWindow,
    00139     IN COORD coordConView,
    00140     IN DWORD dwOption,
    00141     OUT PCONVERSIONAREA_INFORMATION *ConvAreaInfo
    00142     )
    00143 {
    00144     NTSTATUS Status;
    00145     PCONVERSIONAREA_INFORMATION ca;
    00146
    00147     Status = AllocateConversionArea(Console, coordCaBuffer, &ca);
    00148     if (!NT_SUCCESS(Status)) {
    00149         return Status;
    00150     }
    00151
    00152     ca->ConversionAreaMode    = dwOption;
    00153     ca->CaInfo.coordCaBuffer  = coordCaBuffer;
    00154     ca->CaInfo.rcViewCaWindow = rcViewCaWindow;
    00155     ca->CaInfo.coordConView   = coordConView;
    00156
    00157     ca->ConvAreaNext = NULL;
    00158
    00159     ca->ScreenBuffer->ConvScreenInfo = ca;
    00160
    00161     LinkConversionArea(Console, ca);
    00162
    00163     SetUndetermineAttribute( Console ) ;
    00164
    00165     *ConvAreaInfo = ca;
    00166
    00167     return STATUS_SUCCESS;
    00168 }
    00169
    00170
    00171
    00172
    00173
    00174
    00175
    00176
    00177
    00178
    00179 VOID
    00180 WriteConvRegionToScreen(
    00181     IN PSCREEN_INFORMATION ScreenInfo,
    00182     IN PCONVERSIONAREA_INFORMATION ConvAreaInfo,
    00183     IN PSMALL_RECT ConvRegion
    00184     )
    00185
    00186 /*++
    00187
    00188 Routine Description:
    00189
    00190 Arguments:
    00191
    00192     ClippedRegion - Rectangle of region by screen coordinate.
    00193
    00194 Return Value:
    00195
    00196 --*/
    00197
    00198 {
    00199     SMALL_RECT Region;
    00200     SMALL_RECT ClippedRegion;
    00201
    00202     if (ScreenInfo->Console->CurrentScreenBuffer->Flags & CONSOLE_GRAPHICS_BUFFER)
    00203         return;
    00204
    00205     while (ConvAreaInfo) {
    00206
    00207         if ((ConvAreaInfo->ConversionAreaMode & (CA_HIDDEN+CA_HIDE_FOR_SCROLL))==0) {
    00208             //
    00209             // Do clipping region
    00210             //
    00211             Region.Left   = ScreenInfo->Window.Left +
    00212                             ConvAreaInfo->CaInfo.rcViewCaWindow.Left +
    00213                             ConvAreaInfo->CaInfo.coordConView.X;
    00214             Region.Right  = Region.Left +
    00215                             (ConvAreaInfo->CaInfo.rcViewCaWindow.Right -
    00216                              ConvAreaInfo->CaInfo.rcViewCaWindow.Left);
    00217             Region.Top    = ScreenInfo->Window.Top +
    00218                             ConvAreaInfo->CaInfo.rcViewCaWindow.Top +
    00219                             ConvAreaInfo->CaInfo.coordConView.Y;
    00220             Region.Bottom = Region.Top +
    00221                             (ConvAreaInfo->CaInfo.rcViewCaWindow.Bottom -
    00222                              ConvAreaInfo->CaInfo.rcViewCaWindow.Top);
    00223             ClippedRegion.Left   = max(Region.Left,   ScreenInfo->Window.Left);
    00224             ClippedRegion.Top    = max(Region.Top,    ScreenInfo->Window.Top);
    00225             ClippedRegion.Right  = min(Region.Right,  ScreenInfo->Window.Right);
    00226             ClippedRegion.Bottom = min(Region.Bottom, ScreenInfo->Window.Bottom);
    00227             if (ClippedRegion.Right < ClippedRegion.Left ||
    00228                 ClippedRegion.Bottom < ClippedRegion.Top) {
    00229                 ;
    00230             }
    00231             else {
    00232                 Region = ClippedRegion;
    00233                 ClippedRegion.Left   = max(Region.Left,   ConvRegion->Left);
    00234                 ClippedRegion.Top    = max(Region.Top,    ConvRegion->Top);
    00235                 ClippedRegion.Right  = min(Region.Right,  ConvRegion->Right);
    00236                 ClippedRegion.Bottom = min(Region.Bottom, ConvRegion->Bottom);
    00237                 if (ClippedRegion.Right < ClippedRegion.Left ||
    00238                     ClippedRegion.Bottom < ClippedRegion.Top) {
    00239                     ;
    00240                 }
    00241                 else {
    00242                     ConvAreaInfo->ScreenBuffer->BufferInfo.TextInfo.Flags &= ~TEXT_VALID_HINT;
    00243                     ConvAreaInfo->ScreenBuffer->BufferInfo.TextInfo.Flags |= CONSOLE_CONVERSION_AREA_REDRAW;
    00244                     WriteRegionToScreen(ConvAreaInfo->ScreenBuffer,
    00245                                         &ClippedRegion
    00246                                        );
    00247                     ConvAreaInfo->ScreenBuffer->BufferInfo.TextInfo.Flags &= ~CONSOLE_CONVERSION_AREA_REDRAW;
    00248                 }
    00249             }
    00250         }
    00251         ConvAreaInfo = ConvAreaInfo->ConvAreaNext;
    00252     }
    00253 }
    00254
    00255
    00256 BOOL
    00257 ConsoleImeBottomLineUse(
    00258     IN PSCREEN_INFORMATION ScreenInfo,
    00259     IN SHORT ScrollOffset
    00260     )
    00261
    00262 /*++
    00263
    00264 Routine Description:
    00265
    00266 Arguments:
    00267
    00268     ScreenInfo -
    00269
    00270     ScrollOffset -
    00271
    00272 Return Value:
    00273
    00274 --*/
    00275
    00276 {
    00277     SMALL_RECT ScrollRectangle;
    00278     COORD DestinationOrigin;
    00279     CHAR_INFO Fill;
    00280     PCONVERSIONAREA_INFORMATION ConvAreaInfo;
    00281     SMALL_RECT WriteRegion;
    00282     BOOL fRedraw = FALSE;
    00283
    00284     if (!(ScreenInfo->Console->ConsoleIme.ScrollFlag & HIDE_FOR_SCROLL)) {
    00285         ScreenInfo->Console->ConsoleIme.ScrollFlag |= HIDE_FOR_SCROLL;
    00286         if (ConvAreaInfo = ScreenInfo->Console->ConsoleIme.ConvAreaRoot) {
    00287             do {
    00288                 if ((ConvAreaInfo->ConversionAreaMode & (CA_STATUS_LINE))==0) {
    00289                     ConvAreaInfo->ConversionAreaMode |= CA_HIDE_FOR_SCROLL;
    00290                     fRedraw = TRUE;
    00291                 }
    00292             } while (ConvAreaInfo = ConvAreaInfo->ConvAreaNext);
    00293
    00294             if (fRedraw) {
    00295                 // Check code for must CONSOLE_TEXTMODE_BUFFER !!
    00296                 if (ScreenInfo->Flags & CONSOLE_GRAPHICS_BUFFER)
    00297                 {
    00298                     ASSERT(FALSE);
    00299                 }
    00300                 else {
    00301                     WriteRegion = ScreenInfo->Window;
    00302                     WriteRegion.Bottom--;
    00303                     ScreenInfo->BufferInfo.TextInfo.Flags &= ~TEXT_VALID_HINT;
    00304                     ScreenInfo->BufferInfo.TextInfo.Flags |= CONSOLE_CONVERSION_AREA_REDRAW;
    00305                     WriteToScreen(ScreenInfo,&WriteRegion);
    00306                     ScreenInfo->BufferInfo.TextInfo.Flags &= ~CONSOLE_CONVERSION_AREA_REDRAW;
    00307                 }
    00308             }
    00309         }
    00310     }
    00311
    00312     if (ScrollOffset) {
    00313         ScrollRectangle.Top = 1 ;
    00314         ScrollRectangle.Left = 0 ;
    00315         ScrollRectangle.Right = ScreenInfo->ScreenBufferSize.X-1;
    00316         ScrollRectangle.Bottom = ScreenInfo->ScreenBufferSize.Y-1;
    00317         ScrollRectangle.Bottom -= (ScrollOffset-1);
    00318         DestinationOrigin.X = ScrollRectangle.Left;
    00319         DestinationOrigin.Y = ScrollRectangle.Top-1;
    00320         Fill.Char.UnicodeChar = '\0';
    00321         Fill.Attributes = 0;
    00322         ScrollRegion(ScreenInfo,
    00323                      &ScrollRectangle,
    00324                      NULL,
    00325                      DestinationOrigin,
    00326                      Fill
    00327                     );
    00328 #if defined(FE_SB)
    00329 #if defined(FE_IME)
    00330         if ( ! (ScreenInfo->Console->InputBuffer.ImeMode.Disable) &&
    00331              ! (ScreenInfo->Console->InputBuffer.ImeMode.Unavailable) &&
    00332              (ScreenInfo->Console->InputBuffer.ImeMode.Open) &&
    00333              (ScrollRectangle.Left == ScreenInfo->Window.Left) &&
    00334              (ScrollRectangle.Right == ScreenInfo->Window.Right) ) {
    00335             ScrollRectangle.Top = ScreenInfo->Window.Bottom ;
    00336             ScrollRectangle.Bottom = ScreenInfo->Window.Bottom ;
    00337             WriteToScreen(ScreenInfo,&ScrollRectangle);
    00338             WriteConvRegionToScreen(ScreenInfo,
    00339                                     ScreenInfo->Console->ConsoleIme.ConvAreaRoot,
    00340                                     &ScrollRectangle);
    00341         }
    00342 #endif
    00343 #endif
    00344     }
    00345     else {
    00346         ScreenInfo->Console->ConsoleIme.ScrollWaitCountDown = ScreenInfo->Console->ConsoleIme.ScrollWaitTimeout;
    00347     }
    00348     return TRUE;
    00349 }
    00350
    00351
    00352
    00353 VOID
    00354 ConsoleImeBottomLineInUse(
    00355     IN PSCREEN_INFORMATION ScreenInfo
    00356     )
    00357
    00358 /*++
    00359
    00360 Routine Description:
    00361
    00362 Arguments:
    00363
    00364     ScreenInfo -
    00365
    00366 Return Value:
    00367
    00368 --*/
    00369
    00370 {
    00371     PCONVERSIONAREA_INFORMATION ConvAreaInfo;
    00372     SMALL_RECT WriteRegion;
    00373     BOOL fRedraw = FALSE;
    00374     COORD CursorPosition;
    00375
    00376     ScreenInfo->Console->ConsoleIme.ScrollFlag &= ~HIDE_FOR_SCROLL;
    00377     if (ConvAreaInfo = ScreenInfo->Console->ConsoleIme.ConvAreaRoot) {
    00378         do {
    00379             if (ConvAreaInfo->ConversionAreaMode & CA_HIDE_FOR_SCROLL) {
    00380                 ConvAreaInfo->ConversionAreaMode &= ~CA_HIDE_FOR_SCROLL;
    00381                 fRedraw = TRUE;
    00382             }
    00383         } while (ConvAreaInfo = ConvAreaInfo->ConvAreaNext);
    00384
    00385         if (fRedraw) {
    00386             // Check code for must CONSOLE_TEXTMODE_BUFFER !!
    00387             if (ScreenInfo->Flags & CONSOLE_GRAPHICS_BUFFER)
    00388             {
    00389                 ASSERT(FALSE);
    00390             }
    00391             else {
    00392                 if (ScreenInfo->BufferInfo.TextInfo.CursorPosition.Y == (ScreenInfo->ScreenBufferSize.Y-1)) {
    00393                     ConsoleHideCursor(ScreenInfo);
    00394                     ConsoleImeBottomLineUse(ScreenInfo,1);
    00395                     CursorPosition = ScreenInfo->BufferInfo.TextInfo.CursorPosition;
    00396                     CursorPosition.Y--;
    00397                     SetCursorPosition(ScreenInfo,CursorPosition,TRUE);
    00398                     if (ScreenInfo->Console->lpCookedReadData) {
    00399                         ((PCOOKED_READ_DATA)(ScreenInfo->Console->lpCookedReadData))->OriginalCursorPosition.Y--;
    00400                     }
    00401                     ConsoleShowCursor(ScreenInfo);
    00402                 }
    00403                 else if (ScreenInfo->BufferInfo.TextInfo.CursorPosition.Y == ScreenInfo->Window.Bottom) {
    00404                     ;
    00405                 }
    00406
    00407                 WriteRegion.Top = 0;
    00408                 WriteRegion.Bottom = (SHORT)(ScreenInfo->ScreenBufferSize.Y-1);
    00409                 WriteRegion.Left = 0;
    00410                 WriteRegion.Right = (SHORT)(ScreenInfo->ScreenBufferSize.X-1);
    00411                 ScreenInfo->BufferInfo.TextInfo.Flags &= ~TEXT_VALID_HINT;
    00412                 ScreenInfo->BufferInfo.TextInfo.Flags |= CONSOLE_CONVERSION_AREA_REDRAW;
    00413                 WriteToScreen(ScreenInfo,&WriteRegion);
    00414                 ScreenInfo->BufferInfo.TextInfo.Flags &= ~CONSOLE_CONVERSION_AREA_REDRAW;
    00415             }
    00416         }
    00417     }
    00418 }
    00419
    00420
    00421
    00422 NTSTATUS
    00423 CreateConvAreaUndetermine(
    00424     PCONSOLE_INFORMATION Console
    00425     )
    00426 {
    00427     PCONSOLE_IME_INFORMATION ConsoleIme = &Console->ConsoleIme;
    00428     NTSTATUS Status;
    00429     COORD coordCaBuffer;
    00430     SMALL_RECT rcViewCaWindow;
    00431     COORD coordConView;
    00432     PCONVERSIONAREA_INFORMATION ConvAreaInfo;
    00433
    00434     if (ConsoleIme->ConvAreaCompStr) {
    00435         ConsoleIme->ConvAreaCompStr =
    00436             ConsoleHeapReAlloc(
    00437                         0,
    00438                         ConsoleIme->ConvAreaCompStr,
    00439                         ConsoleHeapSize(
    00440                                  ConsoleIme->ConvAreaCompStr)+sizeof(PCONVERSIONAREA_INFORMATION));
    00441         if (ConsoleIme->ConvAreaCompStr == NULL)
    00442             return STATUS_NO_MEMORY;
    00443     }
    00444     else {
    00445         ConsoleIme->ConvAreaCompStr =
    00446             ConsoleHeapAlloc(
    00447                       MAKE_TAG( CONVAREA_TAG ),
    00448                       sizeof(PCONVERSIONAREA_INFORMATION));
    00449         if (ConsoleIme->ConvAreaCompStr == NULL)
    00450             return STATUS_NO_MEMORY;
    00451     }
    00452
    00453     coordCaBuffer = Console->CurrentScreenBuffer->ScreenBufferSize;
    00454     coordCaBuffer.Y = 1;
    00455     rcViewCaWindow.Top    = 0;
    00456     rcViewCaWindow.Left   = 0;
    00457     rcViewCaWindow.Bottom = 0;
    00458     rcViewCaWindow.Right  = 0;
    00459     coordConView.X = 0;
    00460     coordConView.Y = 0;
    00461     Status = SetUpConversionArea(Console,
    00462                                  coordCaBuffer,
    00463                                  rcViewCaWindow,
    00464                                  coordConView,
    00465                                  (Console->ConsoleIme.ScrollFlag & HIDE_FOR_SCROLL) ?
    00466                                      CA_HIDE_FOR_SCROLL :
    00467                                      CA_HIDDEN,
    00468                                  &ConvAreaInfo
    00469                                 );
    00470     if (!NT_SUCCESS(Status)) {
    00471         return Status;
    00472     }
    00473
    00474     ConsoleIme->ConvAreaCompStr[ConsoleIme->NumberOfConvAreaCompStr] = ConvAreaInfo;
    00475     ConsoleIme->NumberOfConvAreaCompStr++;
    00476
    00477     return Status;
    00478 }
    00479
    00480
    00481 NTSTATUS
    00482 CreateConvAreaModeSystem(
    00483     PCONSOLE_INFORMATION Console
    00484     )
    00485 {
    00486     PCONSOLE_IME_INFORMATION ConsoleIme = &Console->ConsoleIme;
    00487     NTSTATUS Status;
    00488     COORD coordCaBuffer;
    00489     SMALL_RECT rcViewCaWindow;
    00490     COORD coordConView;
    00491     PCONVERSIONAREA_INFORMATION ConvAreaInfo;
    00492
    00493     /*
    00494      * Create mode text buffer
    00495      */
    00496     coordCaBuffer = Console->CurrentScreenBuffer->ScreenBufferSize;
    00497     coordCaBuffer.Y = 1;
    00498     rcViewCaWindow.Top    = 0;
    00499     rcViewCaWindow.Left   = 0;
    00500     rcViewCaWindow.Bottom = 0;
    00501     rcViewCaWindow.Right  = 0;
    00502     coordConView.X = 0;
    00503     coordConView.Y = 0;
    00504     Status = SetUpConversionArea(Console,
    00505                                  coordCaBuffer,
    00506                                  rcViewCaWindow,
    00507                                  coordConView,
    00508                                  CA_HIDDEN+CA_STATUS_LINE,
    00509                                  &ConvAreaInfo
    00510                                 );
    00511     if (!NT_SUCCESS(Status)) {
    00512         return Status;
    00513     }
    00514
    00515     ConsoleIme->ConvAreaMode = ConvAreaInfo;
    00516
    00517     /*
    00518      * Create system text buffer
    00519      */
    00520     Status = SetUpConversionArea(Console,
    00521                                  coordCaBuffer,
    00522                                  rcViewCaWindow,
    00523                                  coordConView,
    00524                                  CA_HIDDEN+CA_STATUS_LINE,
    00525                                  &ConvAreaInfo
    00526                                 );
    00527     if (!NT_SUCCESS(Status)) {
    00528         return Status;
    00529     }
    00530
    00531     ConsoleIme->ConvAreaSystem = ConvAreaInfo;
    00532
    00533     return Status;
    00534 }
    00535
    00536
    00537 #define LOCAL_BUFFER_SIZE 100
    00538 NTSTATUS
    00539 WriteUndetermineChars(
    00540     PCONSOLE_INFORMATION Console,
    00541     LPWSTR lpString,
    00542     PBYTE  lpAtr,
    00543     PWORD  lpAtrIdx,
    00544     DWORD  NumChars  // character count
    00545     )
    00546 {
    00547     PSCREEN_INFORMATION ScreenInfo;
    00548     PSCREEN_INFORMATION ConvScreenInfo;
    00549     WCHAR LocalBuffer[LOCAL_BUFFER_SIZE];
    00550     BYTE LocalBufferA[LOCAL_BUFFER_SIZE];
    00551     PWCHAR LocalBufPtr;
    00552     PBYTE LocalBufPtrA;
    00553     DWORD BufferSize;
    00554     COORD Position;
    00555     ULONG i;
    00556     SMALL_RECT Region;
    00557     COORD CursorPosition;
    00558     WCHAR Char;
    00559     WORD Attr;
    00560     PCONSOLE_IME_INFORMATION ConsoleIme;
    00561     PCONVERSIONAREA_INFORMATION ConvAreaInfo;
    00562     DWORD ConvAreaIndex;
    00563     NTSTATUS Status;
    00564     ULONG NumStr ;
    00565     int WholeLen ;
    00566     int WholeRow ;
    00567     SHORT PosY ;
    00568     BOOL UndetAreaUp = FALSE ;
    00569
    00570     ConsoleIme = &Console->ConsoleIme;
    00571     ScreenInfo = Console->CurrentScreenBuffer;
    00572
    00573     // Check code for must CONSOLE_TEXTMODE_BUFFER !!
    00574     ASSERT(!(ScreenInfo->Flags & CONSOLE_GRAPHICS_BUFFER));
    00575
    00576     Position = ScreenInfo->BufferInfo.TextInfo.CursorPosition;
    00577
    00578         if ((ScreenInfo->Window.Left <= Position.X && Position.X <= ScreenInfo->Window.Right) &&
    00579             (ScreenInfo->Window.Top  <= Position.Y && Position.Y <= ScreenInfo->Window.Bottom)  ) {
    00580             Position.X = ScreenInfo->BufferInfo.TextInfo.CursorPosition.X - ScreenInfo->Window.Left;
    00581             Position.Y = ScreenInfo->BufferInfo.TextInfo.CursorPosition.Y - ScreenInfo->Window.Top;
    00582         }
    00583         else {
    00584             Position.X = 0;
    00585             Position.Y = CONSOLE_WINDOW_SIZE_Y(ScreenInfo) - 2;
    00586         }
    00587
    00588     PosY = Position.Y ;
    00589     RtlUnicodeToMultiByteSize(&NumStr, lpString, NumChars*sizeof(WCHAR));
    00590
    00591     WholeLen = (int)Position.X + (int)NumStr ;
    00592     WholeRow = WholeLen / CONSOLE_WINDOW_SIZE_X(ScreenInfo);
    00593     if ( ( PosY + WholeRow ) > ( CONSOLE_WINDOW_SIZE_Y(ScreenInfo) - 2) ) {
    00594         PosY = CONSOLE_WINDOW_SIZE_Y(ScreenInfo) - 2 - WholeRow ;
    00595         if (PosY < 0) {
    00596             PosY = ScreenInfo->Window.Top ;
    00597         }
    00598     }
    00599     if (PosY != Position.Y) {
    00600         Position.Y = PosY ;
    00601         UndetAreaUp = TRUE ;
    00602     }
    00603
    00604     ConvAreaIndex = 0;
    00605
    00606     BufferSize = NumChars;
    00607     NumChars = 0;
    00608
    00609     for (ConvAreaIndex = 0; NumChars < BufferSize; ConvAreaIndex++) {
    00610
    00611         if (ConvAreaIndex+1 > ConsoleIme->NumberOfConvAreaCompStr) {
    00612             Status = CreateConvAreaUndetermine(Console);
    00613             if (!NT_SUCCESS(Status)) {
    00614                 return Status;
    00615             }
    00616         }
    00617         ConvAreaInfo = ConsoleIme->ConvAreaCompStr[ConvAreaIndex];
    00618         ConvScreenInfo = ConvAreaInfo->ScreenBuffer;
    00619         ConvScreenInfo->BufferInfo.TextInfo.CursorPosition.X = Position.X;
    00620
    00621         if ((ConvAreaInfo->ConversionAreaMode & CA_HIDDEN) ||
    00622             (UndetAreaUp)) {
    00623             /*
    00624              * This conversion area need positioning onto cursor position.
    00625              */
    00626             CursorPosition.X = 0;
    00627             CursorPosition.Y = (SHORT)(Position.Y + ConvAreaIndex);
    00628             ConsoleImeViewInfo(Console,ConvAreaInfo,CursorPosition);
    00629         }
    00630
    00631         Region.Left = ConvScreenInfo->BufferInfo.TextInfo.CursorPosition.X;
    00632         Region.Top = 0;
    00633         Region.Bottom = 0;
    00634
    00635         while (NumChars < BufferSize) {
    00636             i=0;
    00637             LocalBufPtr = LocalBuffer;
    00638             LocalBufPtrA = LocalBufferA;
    00639
    00640             while (NumChars < BufferSize &&
    00641                    i < LOCAL_BUFFER_SIZE &&
    00642                    Position.X < CONSOLE_WINDOW_SIZE_X(ScreenInfo)) {
    00643                 Char = *lpString;
    00644                 Attr = *lpAtr;
    00645                 if (Char >= (WCHAR)' ') {
    00646                     if (IsConsoleFullWidth(Console->hDC,Console->OutputCP,Char)) {
    00647                         if (i < (LOCAL_BUFFER_SIZE-1) &&
    00648                             Position.X < CONSOLE_WINDOW_SIZE_X(ScreenInfo)-1) {
    00649                             *LocalBufPtr++ = Char;
    00650                             *LocalBufPtrA++ = ATTR_LEADING_BYTE;
    00651                             *LocalBufPtr++ = Char;
    00652                             *LocalBufPtrA++ = ATTR_TRAILING_BYTE;
    00653                             Position.X+=2;
    00654                             i+=2;
    00655                         }
    00656                         else {
    00657                             Position.X++;
    00658                             break;
    00659                         }
    00660                     }
    00661                     else {
    00662                         *LocalBufPtr++ = Char;
    00663                         *LocalBufPtrA++ = 0;
    00664                         Position.X++;
    00665                         i++;
    00666                     }
    00667                 }
    00668                 lpString++;
    00669                 lpAtr++;
    00670                 NumChars++;
    00671
    00672                 if (NumChars < BufferSize &&
    00673                     Attr != *lpAtr)
    00674                     break;
    00675             }
    00676             if (i != 0) {
    00677                 ConvScreenInfo->Attributes = lpAtrIdx[Attr & 0x07];
    00678                 if (Attr & 0x10)
    00679                     ConvScreenInfo->Attributes |= (COMMON_LVB_GRID_SINGLEFLAG + COMMON_LVB_GRID_RVERTICAL) ;
    00680                 else if (Attr & 0x20)
    00681                     ConvScreenInfo->Attributes |= (COMMON_LVB_GRID_SINGLEFLAG + COMMON_LVB_GRID_LVERTICAL) ;
    00682                 StreamWriteToScreenBufferIME(LocalBuffer,
    00683                                           (SHORT)i,
    00684                                           ConvScreenInfo,
    00685                                           LocalBufferA
    00686                                          );
    00687
    00688                 ConvScreenInfo->BufferInfo.TextInfo.CursorPosition.X += (SHORT)i;
    00689
    00690                 if (NumChars == BufferSize ||
    00691                     Position.X >= CONSOLE_WINDOW_SIZE_X(ScreenInfo) ||
    00692                     ( (Char >= (WCHAR)' ' &&
    00693                       IsConsoleFullWidth(Console->hDC,Console->OutputCP,Char) &&
    00694                       Position.X >= CONSOLE_WINDOW_SIZE_X(ScreenInfo)-1) )
    00695                    ) {
    00696
    00697                     Region.Right = (SHORT)(ConvScreenInfo->BufferInfo.TextInfo.CursorPosition.X - 1);
    00698                     ConsoleImeWindowInfo(Console,ConvAreaInfo,Region);
    00699
    00700                     ConvAreaInfo->ConversionAreaMode &= ~CA_HIDDEN;
    00701
    00702                     ConsoleImePaint(Console,ConvAreaInfo);
    00703
    00704                     Position.X = 0;
    00705                     break;
    00706                 }
    00707
    00708                 if (NumChars == BufferSize) {
    00709                     return STATUS_SUCCESS;
    00710                 }
    00711                 continue;
    00712
    00713             } else if (NumChars == BufferSize) {
    00714                 return STATUS_SUCCESS;
    00715             }
    00716             if (!NT_SUCCESS(Status)) {
    00717                 return Status;
    00718             }
    00719             if (Position.X >= CONSOLE_WINDOW_SIZE_X(ScreenInfo)) {
    00720                 Position.X = 0;
    00721                 break;
    00722             }
    00723         }
    00724
    00725     }
    00726
    00727     for ( ; ConvAreaIndex < ConsoleIme->NumberOfConvAreaCompStr; ConvAreaIndex++) {
    00728         ConvAreaInfo = ConsoleIme->ConvAreaCompStr[ConvAreaIndex];
    00729         if (!(ConvAreaInfo->ConversionAreaMode & CA_HIDDEN)) {
    00730             ConvAreaInfo->ConversionAreaMode |= CA_HIDDEN;
    00731             ConsoleImePaint(Console,ConvAreaInfo);
    00732         }
    00733     }
    00734
    00735     return STATUS_SUCCESS;
    00736 }
    00737
    00738
    00739 VOID
    00740 WriteModeSystemChars(
    00741     PCONSOLE_INFORMATION Console,
    00742     PCONVERSIONAREA_INFORMATION ConvAreaInfo,
    00743     PCHAR_INFO Buffer,
    00744     DWORD NumberOfChars,
    00745     DWORD ViewPosition
    00746     )
    00747 {
    00748     SMALL_RECT CharRegion;
    00749     COORD CursorPosition;
    00750
    00751     if (Buffer) {
    00752         CharRegion.Left   = 0;
    00753         CharRegion.Top    = 0;
    00754         CharRegion.Right  = CalcWideCharToColumn(Console,Buffer,NumberOfChars);
    00755         CharRegion.Right  = (CharRegion.Right ? CharRegion.Right-1 : 0);
    00756         CharRegion.Bottom = 0;
    00757     }
    00758     else {
    00759         CharRegion = ConvAreaInfo->CaInfo.rcViewCaWindow;
    00760     }
    00761     if (ConvAreaInfo) {
    00762         if (!(ConvAreaInfo->ConversionAreaMode & CA_HIDDEN)) {
    00763             if (CharRegion.Left   != ConvAreaInfo->CaInfo.rcViewCaWindow.Left ||
    00764                 CharRegion.Top    != ConvAreaInfo->CaInfo.rcViewCaWindow.Top ||
    00765                 CharRegion.Right  != ConvAreaInfo->CaInfo.rcViewCaWindow.Right ||
    00766                 CharRegion.Bottom != ConvAreaInfo->CaInfo.rcViewCaWindow.Bottom) {
    00767                 switch (ViewPosition) {
    00768                     case VIEW_LEFT:
    00769                         CursorPosition.X = 0;
    00770                         break;
    00771                     case VIEW_RIGHT:
    00772                         CursorPosition.X = CONSOLE_WINDOW_SIZE_X(Console->CurrentScreenBuffer) - (CharRegion.Right + 1);
    00773                         break;
    00774                 }
    00775                 CursorPosition.Y = CONSOLE_WINDOW_SIZE_Y(Console->CurrentScreenBuffer) - 1;
    00776                 ConsoleImeViewInfo(Console,ConvAreaInfo,CursorPosition);
    00777
    00778                 ConsoleImeWindowInfo(Console,ConvAreaInfo,CharRegion);
    00779             }
    00780         }
    00781         else {
    00782             /*
    00783              * This conversion area need positioning onto cursor position.
    00784              */
    00785             switch (ViewPosition) {
    00786                 case VIEW_LEFT:
    00787                     CursorPosition.X = 0;
    00788                     break;
    00789                 case VIEW_RIGHT:
    00790                     CursorPosition.X = CONSOLE_WINDOW_SIZE_X(Console->CurrentScreenBuffer) - (CharRegion.Right + 1);
    00791                     break;
    00792             }
    00793             CursorPosition.Y = CONSOLE_WINDOW_SIZE_Y(Console->CurrentScreenBuffer) - 1;
    00794             ConsoleImeViewInfo(Console,ConvAreaInfo,CursorPosition);
    00795
    00796             ConsoleImeWindowInfo(Console,ConvAreaInfo,CharRegion);
    00797         }
    00798
    00799         if (Buffer) {
    00800             ConvAreaInfo->ConversionAreaMode &= ~CA_HIDDEN;
    00801             ConsoleImeWriteOutput(Console,ConvAreaInfo,Buffer,CharRegion,TRUE);
    00802         }
    00803         else {
    00804             ConsoleImePaint(Console,ConvAreaInfo);
    00805         }
    00806     }
    00807 }
    00808
    00809
    00810 NTSTATUS
    00811 FillUndetermineChars(
    00812     PCONSOLE_INFORMATION Console,
    00813     PCONVERSIONAREA_INFORMATION ConvAreaInfo
    00814     )
    00815 {
    00816     COORD Coord;
    00817     DWORD CharsToWrite;
    00818
    00819     ConvAreaInfo->ConversionAreaMode |= CA_HIDDEN;
    00820     Coord.X = 0;
    00821     Coord.Y = 0;
    00822     CharsToWrite = ConvAreaInfo->ScreenBuffer->ScreenBufferSize.X;
    00823     FillOutput(ConvAreaInfo->ScreenBuffer,
    00824                (WCHAR)' ',
    00825                Coord,
    00826                CONSOLE_FALSE_UNICODE, // faster than real unicode
    00827                &CharsToWrite
    00828               );
    00829     CharsToWrite = ConvAreaInfo->ScreenBuffer->ScreenBufferSize.X;
    00830     FillOutput(ConvAreaInfo->ScreenBuffer,
    00831                Console->CurrentScreenBuffer->Attributes,
    00832                Coord,
    00833                CONSOLE_ATTRIBUTE,
    00834                &CharsToWrite
    00835               );
    00836     ConsoleImePaint(Console,ConvAreaInfo);
    00837     return STATUS_SUCCESS;
    00838 }
    00839
    00840
    00841 NTSTATUS
    00842 ConsoleImeCompStr(
    00843     IN PCONSOLE_INFORMATION Console,
    00844     IN LPCONIME_UICOMPMESSAGE CompStr
    00845     )
    00846 {
    00847     UINT i;
    00848     PCONVERSIONAREA_INFORMATION ConvAreaInfo;
    00849
    00850     if (CompStr->dwCompStrLen == 0 ||
    00851         CompStr->dwResultStrLen != 0
    00852        ) {
    00853
    00854         // Cursor turn ON.
    00855         if ((Console->CurrentScreenBuffer->Flags & CONSOLE_TEXTMODE_BUFFER) &&
    00856              Console->ConsoleIme.SavedCursorVisible                             )
    00857         {
    00858             Console->ConsoleIme.SavedCursorVisible = FALSE;
    00859             SetCursorInformation(Console->CurrentScreenBuffer,
    00860                                  Console->CurrentScreenBuffer->BufferInfo.TextInfo.CursorSize,
    00861                                  TRUE);
    00862         }
    00863
    00864         /*
    00865          * Determine string.
    00866          */
    00867         for (i=0; i<Console->ConsoleIme.NumberOfConvAreaCompStr; i++) {
    00868             ConvAreaInfo = Console->ConsoleIme.ConvAreaCompStr[i];
    00869             if (ConvAreaInfo &&
    00870                 (!(ConvAreaInfo->ConversionAreaMode & CA_HIDDEN))) {
    00871                 FillUndetermineChars(Console,ConvAreaInfo);
    00872             }
    00873         }
    00874
    00875         if (CompStr->dwResultStrLen != 0)
    00876         {
    00877             if (!InsertConverTedString(Console, (LPWSTR)((PBYTE)CompStr + CompStr->dwResultStrOffset))) {
    00878                 return STATUS_INVALID_HANDLE;
    00879             }
    00880         }
    00881         if (Console->ConsoleIme.CompStrData) {
    00882             ConsoleHeapFree(Console->ConsoleIme.CompStrData);
    00883             Console->ConsoleIme.CompStrData = NULL;
    00884         }
    00885     }
    00886     else {
    00887         LPWSTR lpStr;
    00888         PBYTE  lpAtr;
    00889         PWORD  lpAtrIdx;
    00890
    00891         // Cursor turn OFF.
    00892         if ((Console->CurrentScreenBuffer->Flags & CONSOLE_TEXTMODE_BUFFER) &&
    00893              Console->CurrentScreenBuffer->BufferInfo.TextInfo.CursorVisible  )
    00894         {
    00895             Console->ConsoleIme.SavedCursorVisible = TRUE;
    00896             SetCursorInformation(Console->CurrentScreenBuffer,
    00897                                  Console->CurrentScreenBuffer->BufferInfo.TextInfo.CursorSize,
    00898                                  FALSE);
    00899         }
    00900
    00901         /*
    00902          * Composition string.
    00903          */
    00904         for (i=0; i<Console->ConsoleIme.NumberOfConvAreaCompStr; i++) {
    00905             ConvAreaInfo = Console->ConsoleIme.ConvAreaCompStr[i];
    00906             if (ConvAreaInfo &&
    00907                 (!(ConvAreaInfo->ConversionAreaMode & CA_HIDDEN))) {
    00908                 FillUndetermineChars(Console,ConvAreaInfo);
    00909             }
    00910         }
    00911
    00912         lpStr = (LPWSTR)((PBYTE)CompStr + CompStr->dwCompStrOffset);
    00913         lpAtr = (PBYTE)CompStr + CompStr->dwCompAttrOffset;
    00914         lpAtrIdx = (PWORD)CompStr->CompAttrColor ;
    00915         WriteUndetermineChars(Console, lpStr, lpAtr, lpAtrIdx, CompStr->dwCompStrLen / sizeof(WCHAR));
    00916     }
    00917
    00918     return STATUS_SUCCESS;
    00919 }
    00920
    00921
    00922
    00923
    00924 NTSTATUS
    00925 ConsoleImeResizeModeSystemView(
    00926     PCONSOLE_INFORMATION Console,
    00927     SMALL_RECT WindowRect
    00928     )
    00929 {
    00930     PCONVERSIONAREA_INFORMATION ConvAreaInfo;
    00931     SMALL_RECT CharRegion;
    00932     COORD CursorPosition;
    00933
    00934     /*
    00935      * Mode string
    00936      */
    00937
    00938     ConvAreaInfo = Console->ConsoleIme.ConvAreaMode;
    00939
    00940     if (ConvAreaInfo &&
    00941         (!(ConvAreaInfo->ConversionAreaMode & CA_HIDDEN))) {
    00942         ConvAreaInfo->ConversionAreaMode |= CA_HIDDEN;
    00943         ConsoleImePaint(Console,ConvAreaInfo);
    00944         CharRegion = ConvAreaInfo->CaInfo.rcViewCaWindow;
    00945
    00946         if (Console->ConsoleIme.ConvAreaModePosition == VIEW_LEFT){
    00947             CursorPosition.X = 0;
    00948         }
    00949         else{
    00950             CursorPosition.X = CONSOLE_WINDOW_SIZE_X(Console->CurrentScreenBuffer) - (CharRegion.Right + 1);
    00951         }
    00952
    00953         CursorPosition.Y = CONSOLE_WINDOW_SIZE_Y(Console->CurrentScreenBuffer) - 1;
    00954         ConsoleImeViewInfo(Console,ConvAreaInfo,CursorPosition);
    00955         ConsoleImeWindowInfo(Console,ConvAreaInfo,CharRegion);
    00956         ConvAreaInfo->ConversionAreaMode &= ~CA_HIDDEN;
    00957
    00958         WriteModeSystemChars(Console,
    00959                              Console->ConsoleIme.ConvAreaMode,
    00960                              NULL,
    00961                              0,
    00962                              Console->ConsoleIme.ConvAreaModePosition);
    00963     }
    00964
    00965     /*
    00966      * System string
    00967      */
    00968     ConvAreaInfo = Console->ConsoleIme.ConvAreaSystem;
    00969     if (ConvAreaInfo &&
    00970         (!(ConvAreaInfo->ConversionAreaMode & CA_HIDDEN))) {
    00971
    00972         ConvAreaInfo->ConversionAreaMode |= CA_HIDDEN;
    00973         ConsoleImePaint(Console,ConvAreaInfo);
    00974
    00975         CharRegion = ConvAreaInfo->CaInfo.rcViewCaWindow;
    00976         CursorPosition.X = 0;
    00977         CursorPosition.Y = CONSOLE_WINDOW_SIZE_Y(Console->CurrentScreenBuffer) - 1;
    00978         ConsoleImeViewInfo(Console,ConvAreaInfo,CursorPosition);
    00979         ConsoleImeWindowInfo(Console,ConvAreaInfo,CharRegion);
    00980         ConvAreaInfo->ConversionAreaMode &= ~CA_HIDDEN;
    00981
    00982         WriteModeSystemChars(Console,
    00983                              Console->ConsoleIme.ConvAreaSystem,
    00984                              NULL,
    00985                              0,
    00986                              VIEW_LEFT);
    00987     }
    00988
    00989     return STATUS_SUCCESS;
    00990     UNREFERENCED_PARAMETER(WindowRect);
    00991 }
    00992
    00993
    00994 NTSTATUS
    00995 ConsoleImeResizeCompStrView(
    00996     PCONSOLE_INFORMATION Console,
    00997     SMALL_RECT WindowRect
    00998     )
    00999 {
    01000     UINT i;
    01001     PCONVERSIONAREA_INFORMATION ConvAreaInfo;
    01002     LPCONIME_UICOMPMESSAGE CompStr;
    01003     LPWSTR lpStr;
    01004     PBYTE  lpAtr;
    01005     PWORD  lpAtrIdx;
    01006
    01007     /*
    01008      * Compositon string
    01009      */
    01010     CompStr = Console->ConsoleIme.CompStrData;
    01011     if (CompStr) {
    01012         for (i=0; i<Console->ConsoleIme.NumberOfConvAreaCompStr; i++) {
    01013             ConvAreaInfo = Console->ConsoleIme.ConvAreaCompStr[i];
    01014             if (ConvAreaInfo &&
    01015                 (!(ConvAreaInfo->ConversionAreaMode & CA_HIDDEN))) {
    01016                 FillUndetermineChars(Console,ConvAreaInfo);
    01017             }
    01018         }
    01019
    01020         lpStr = (LPWSTR)((PBYTE)CompStr + CompStr->dwCompStrOffset);
    01021         lpAtr = (PBYTE)CompStr + CompStr->dwCompAttrOffset;
    01022         lpAtrIdx = (PWORD)CompStr->CompAttrColor ;
    01023
    01024         WriteUndetermineChars(Console, lpStr, lpAtr, lpAtrIdx, CompStr->dwCompStrLen / sizeof(WCHAR));
    01025     }
    01026     return STATUS_SUCCESS;
    01027     UNREFERENCED_PARAMETER(WindowRect);
    01028 }
    01029
    01030
    01031 NTSTATUS
    01032 ConsoleImeResizeModeSystemScreenBuffer(
    01033     PCONSOLE_INFORMATION Console,
    01034     COORD NewScreenSize
    01035     )
    01036 {
    01037     NTSTATUS Status;
    01038     PCONVERSIONAREA_INFORMATION ConvAreaInfo;
    01039
    01040     /*
    01041      * Mode string
    01042      */
    01043     ConvAreaInfo = Console->ConsoleIme.ConvAreaMode;
    01044     if (ConvAreaInfo) {
    01045         if (!(ConvAreaInfo->ConversionAreaMode & CA_HIDDEN)) {
    01046             ConvAreaInfo->ConversionAreaMode |= CA_HIDDEN;
    01047             ConsoleImePaint(Console,ConvAreaInfo);
    01048             ConvAreaInfo->ConversionAreaMode &= ~CA_HIDDEN;
    01049         }
    01050
    01051         Status = ConsoleImeResizeScreenBuffer(ConvAreaInfo->ScreenBuffer,NewScreenSize,ConvAreaInfo);
    01052         if (! NT_SUCCESS(Status))
    01053             return Status;
    01054     }
    01055
    01056     /*
    01057      * System string
    01058      */
    01059     ConvAreaInfo = Console->ConsoleIme.ConvAreaSystem;
    01060     if (ConvAreaInfo) {
    01061         if (!(ConvAreaInfo->ConversionAreaMode & CA_HIDDEN)) {
    01062             ConvAreaInfo->ConversionAreaMode |= CA_HIDDEN;
    01063             ConsoleImePaint(Console,ConvAreaInfo);
    01064             ConvAreaInfo->ConversionAreaMode &= ~CA_HIDDEN;
    01065         }
    01066
    01067         Status = ConsoleImeResizeScreenBuffer(ConvAreaInfo->ScreenBuffer,NewScreenSize,ConvAreaInfo);
    01068         if (! NT_SUCCESS(Status))
    01069             return Status;
    01070     }
    01071
    01072     return STATUS_SUCCESS;
    01073 }
    01074
    01075
    01076 NTSTATUS
    01077 ConsoleImeResizeCompStrScreenBuffer(
    01078     PCONSOLE_INFORMATION Console,
    01079     COORD NewScreenSize
    01080     )
    01081 {
    01082     NTSTATUS Status;
    01083     UINT i;
    01084     PCONVERSIONAREA_INFORMATION ConvAreaInfo;
    01085
    01086     /*
    01087      * Compositon string
    01088      */
    01089     for (i=0; i<Console->ConsoleIme.NumberOfConvAreaCompStr; i++) {
    01090         ConvAreaInfo = Console->ConsoleIme.ConvAreaCompStr[i];
    01091
    01092         if (ConvAreaInfo) {
    01093             if (!(ConvAreaInfo->ConversionAreaMode & CA_HIDDEN)) {
    01094                 ConvAreaInfo->ConversionAreaMode |= CA_HIDDEN;
    01095                 ConsoleImePaint(Console,ConvAreaInfo);
    01096             }
    01097
    01098             Status = ConsoleImeResizeScreenBuffer(ConvAreaInfo->ScreenBuffer,NewScreenSize,ConvAreaInfo);
    01099             if (! NT_SUCCESS(Status))
    01100                 return Status;
    01101         }
    01102
    01103     }
    01104     return STATUS_SUCCESS;
    01105 }
    01106
    01107
    01108 SHORT
    01109 CalcWideCharToColumn(
    01110     IN PCONSOLE_INFORMATION Console,
    01111     IN PCHAR_INFO Buffer,
    01112     IN DWORD NumberOfChars
    01113     )
    01114 {
    01115     SHORT Column = 0;
    01116
    01117     while (NumberOfChars--) {
    01118         if (IsConsoleFullWidth(Console->hDC,Console->OutputCP,Buffer->Char.UnicodeChar))
    01119             Column += 2;
    01120         else
    01121             Column++;
    01122         Buffer++;
    01123     }
    01124     return Column;
    01125 }
    01126
    01127
    01128
    01129
    01130
    01131
    01132
    01133
    01134
    01135
    01136
    01137
    01138
    01139 LONG
    01140 ConsoleImePaint(
    01141     IN PCONSOLE_INFORMATION Console,
    01142     IN PCONVERSIONAREA_INFORMATION ConvAreaInfo
    01143     )
    01144
    01145 /*++
    01146
    01147     This routine
    01148
    01149 --*/
    01150
    01151 {
    01152     PSCREEN_INFORMATION ScreenInfo;
    01153     SMALL_RECT WriteRegion;
    01154     COORD CursorPosition;
    01155
    01156     if (!ConvAreaInfo)
    01157         return FALSE;
    01158
    01159     ScreenInfo = Console->CurrentScreenBuffer;
    01160     if (!ScreenInfo)
    01161         return FALSE;
    01162
    01163     // Check code for must CONSOLE_TEXTMODE_BUFFER !!
    01164     ASSERT(!(ScreenInfo->Flags & CONSOLE_GRAPHICS_BUFFER));
    01165
    01166     WriteRegion.Left   = ScreenInfo->Window.Left
    01167                          + ConvAreaInfo->CaInfo.coordConView.X
    01168                          + ConvAreaInfo->CaInfo.rcViewCaWindow.Left;
    01169     WriteRegion.Right  = WriteRegion.Left
    01170                          + (ConvAreaInfo->CaInfo.rcViewCaWindow.Right - ConvAreaInfo->CaInfo.rcViewCaWindow.Left);
    01171     WriteRegion.Top    = ScreenInfo->Window.Top
    01172                          + ConvAreaInfo->CaInfo.coordConView.Y
    01173                          + ConvAreaInfo->CaInfo.rcViewCaWindow.Top;
    01174     WriteRegion.Bottom = WriteRegion.Top
    01175                          + (ConvAreaInfo->CaInfo.rcViewCaWindow.Bottom - ConvAreaInfo->CaInfo.rcViewCaWindow.Top);
    01176
    01177     if ((ConvAreaInfo->ConversionAreaMode & (CA_HIDDEN+CA_STATUS_LINE))==(CA_STATUS_LINE)) {
    01178         if (ScreenInfo->BufferInfo.TextInfo.CursorPosition.Y == (ScreenInfo->ScreenBufferSize.Y-1)) {
    01179             ConsoleHideCursor(ScreenInfo);
    01180             ConsoleImeBottomLineUse(ScreenInfo,1);
    01181             CursorPosition = ScreenInfo->BufferInfo.TextInfo.CursorPosition;
    01182             CursorPosition.Y--;
    01183             SetCursorPosition(ScreenInfo,CursorPosition,TRUE);
    01184             if (ScreenInfo->Console->lpCookedReadData) {
    01185                 ((PCOOKED_READ_DATA)(ScreenInfo->Console->lpCookedReadData))->OriginalCursorPosition.Y--;
    01186             }
    01187             ConsoleShowCursor(ScreenInfo);
    01188         }
    01189         else if (ScreenInfo->BufferInfo.TextInfo.CursorPosition.Y == ScreenInfo->Window.Bottom) {
    01190             WriteRegion.Top    = ScreenInfo->Window.Top
    01191                                  + ConvAreaInfo->CaInfo.coordConView.Y
    01192                                  + ConvAreaInfo->CaInfo.rcViewCaWindow.Top;
    01193             WriteRegion.Bottom = WriteRegion.Top
    01194                                  + (ConvAreaInfo->CaInfo.rcViewCaWindow.Bottom - ConvAreaInfo->CaInfo.rcViewCaWindow.Top);
    01195         }
    01196     }
    01197
    01198     ScreenInfo->BufferInfo.TextInfo.Flags &= ~TEXT_VALID_HINT;
    01199     ScreenInfo->BufferInfo.TextInfo.Flags |= CONSOLE_CONVERSION_AREA_REDRAW;
    01200     if (!(ConvAreaInfo->ConversionAreaMode & (CA_HIDDEN | CA_HIDE_FOR_SCROLL))) {
    01201         WriteConvRegionToScreen(ScreenInfo,
    01202                                 ConvAreaInfo,
    01203                                 &WriteRegion
    01204                                );
    01205     }
    01206     else {
    01207         WriteToScreen(ScreenInfo,&WriteRegion);
    01208     }
    01209     ScreenInfo->BufferInfo.TextInfo.Flags &= ~CONSOLE_CONVERSION_AREA_REDRAW;
    01210
    01211     return TRUE;
    01212 }
    01213
    01214 VOID
    01215 ConsoleImeViewInfo(
    01216     IN PCONSOLE_INFORMATION Console,
    01217     IN PCONVERSIONAREA_INFORMATION ConvAreaInfo,
    01218     IN COORD coordConView
    01219     )
    01220 {
    01221     SMALL_RECT OldRegion;
    01222     SMALL_RECT NewRegion;
    01223
    01224     if (ConvAreaInfo->ConversionAreaMode & CA_HIDDEN) {
    01225         ConvAreaInfo->CaInfo.coordConView = coordConView;
    01226         NewRegion = ConvAreaInfo->CaInfo.rcViewCaWindow;
    01227         NewRegion.Left   += ConvAreaInfo->CaInfo.coordConView.X;
    01228         NewRegion.Right  += ConvAreaInfo->CaInfo.coordConView.X;
    01229         NewRegion.Top    += ConvAreaInfo->CaInfo.coordConView.Y;
    01230         NewRegion.Bottom += ConvAreaInfo->CaInfo.coordConView.Y;
    01231     }
    01232     else {
    01233         OldRegion = ConvAreaInfo->CaInfo.rcViewCaWindow;
    01234         OldRegion.Left   += ConvAreaInfo->CaInfo.coordConView.X;
    01235         OldRegion.Right  += ConvAreaInfo->CaInfo.coordConView.X;
    01236         OldRegion.Top    += ConvAreaInfo->CaInfo.coordConView.Y;
    01237         OldRegion.Bottom += ConvAreaInfo->CaInfo.coordConView.Y;
    01238         ConvAreaInfo->CaInfo.coordConView = coordConView;
    01239
    01240         // Check code for must CONSOLE_TEXTMODE_BUFFER !!
    01241         ASSERT(!(Console->CurrentScreenBuffer->Flags & CONSOLE_GRAPHICS_BUFFER));
    01242
    01243         Console->CurrentScreenBuffer->BufferInfo.TextInfo.Flags &= ~TEXT_VALID_HINT;
    01244         Console->CurrentScreenBuffer->BufferInfo.TextInfo.Flags |= CONSOLE_CONVERSION_AREA_REDRAW;
    01245         WriteToScreen(Console->CurrentScreenBuffer,&OldRegion);
    01246
    01247         NewRegion = ConvAreaInfo->CaInfo.rcViewCaWindow;
    01248         NewRegion.Left   += ConvAreaInfo->CaInfo.coordConView.X;
    01249         NewRegion.Right  += ConvAreaInfo->CaInfo.coordConView.X;
    01250         NewRegion.Top    += ConvAreaInfo->CaInfo.coordConView.Y;
    01251         NewRegion.Bottom += ConvAreaInfo->CaInfo.coordConView.Y;
    01252         Console->CurrentScreenBuffer->BufferInfo.TextInfo.Flags &= ~TEXT_VALID_HINT;
    01253         WriteToScreen(Console->CurrentScreenBuffer,&NewRegion);
    01254         Console->CurrentScreenBuffer->BufferInfo.TextInfo.Flags &= ~CONSOLE_CONVERSION_AREA_REDRAW;
    01255     }
    01256 }
    01257
    01258 VOID
    01259 ConsoleImeWindowInfo(
    01260     IN PCONSOLE_INFORMATION Console,
    01261     IN PCONVERSIONAREA_INFORMATION ConvAreaInfo,
    01262     IN SMALL_RECT rcViewCaWindow
    01263     )
    01264 {
    01265     if (rcViewCaWindow.Left   != ConvAreaInfo->CaInfo.rcViewCaWindow.Left ||
    01266         rcViewCaWindow.Top    != ConvAreaInfo->CaInfo.rcViewCaWindow.Top ||
    01267         rcViewCaWindow.Right  != ConvAreaInfo->CaInfo.rcViewCaWindow.Right ||
    01268         rcViewCaWindow.Bottom != ConvAreaInfo->CaInfo.rcViewCaWindow.Bottom) {
    01269         if (!(ConvAreaInfo->ConversionAreaMode & CA_HIDDEN)) {
    01270             ConvAreaInfo->ConversionAreaMode |= CA_HIDDEN;
    01271             ConsoleImePaint(Console,ConvAreaInfo);
    01272
    01273             ConvAreaInfo->CaInfo.rcViewCaWindow = rcViewCaWindow;
    01274             ConvAreaInfo->ConversionAreaMode &= ~CA_HIDDEN;
    01275             ConvAreaInfo->ScreenBuffer->BisectFlag &= ~(BISECT_LEFT | BISECT_RIGHT | BISECT_TOP | BISECT_BOTTOM);
    01276             ConsoleImePaint(Console,ConvAreaInfo);
    01277         }
    01278         else
    01279             ConvAreaInfo->CaInfo.rcViewCaWindow = rcViewCaWindow;
    01280     }
    01281 }
    01282
    01283 NTSTATUS
    01284 ConsoleImeResizeScreenBuffer(
    01285     IN PSCREEN_INFORMATION ScreenInfo,
    01286     IN COORD NewScreenSize,
    01287     PCONVERSIONAREA_INFORMATION ConvAreaInfo
    01288     )
    01289 {
    01290     NTSTATUS Status;
    01291
    01292     Status = ResizeScreenBuffer(ScreenInfo,
    01293                                 NewScreenSize,
    01294                                 FALSE);
    01295     if (NT_SUCCESS(Status)) {
    01296         ConvAreaInfo->CaInfo.coordCaBuffer = NewScreenSize;
    01297         if (ConvAreaInfo->CaInfo.rcViewCaWindow.Left   > NewScreenSize.X-1)
    01298             ConvAreaInfo->CaInfo.rcViewCaWindow.Left   = NewScreenSize.X-1;
    01299         if (ConvAreaInfo->CaInfo.rcViewCaWindow.Right  > NewScreenSize.X-1)
    01300             ConvAreaInfo->CaInfo.rcViewCaWindow.Right  = NewScreenSize.X-1;
    01301         if (ConvAreaInfo->CaInfo.rcViewCaWindow.Top    > NewScreenSize.Y-1)
    01302             ConvAreaInfo->CaInfo.rcViewCaWindow.Top    = NewScreenSize.Y-1;
    01303         if (ConvAreaInfo->CaInfo.rcViewCaWindow.Bottom > NewScreenSize.Y-1)
    01304             ConvAreaInfo->CaInfo.rcViewCaWindow.Bottom = NewScreenSize.Y-1;
    01305
    01306     }
    01307
    01308     return Status;
    01309 }
    01310
    01311 NTSTATUS
    01312 ConsoleImeWriteOutput(
    01313     IN PCONSOLE_INFORMATION Console,
    01314     IN PCONVERSIONAREA_INFORMATION ConvAreaInfo,
    01315     IN PCHAR_INFO Buffer,
    01316     IN SMALL_RECT CharRegion,
    01317     IN BOOL fUnicode
    01318     )
    01319 {
    01320     NTSTATUS Status;
    01321     PSCREEN_INFORMATION ScreenInfo;
    01322     COORD BufferSize;
    01323     SMALL_RECT ConvRegion;
    01324     COORD CursorPosition;
    01325
    01326     BufferSize.X = (SHORT)(CharRegion.Right - CharRegion.Left + 1);
    01327     BufferSize.Y = (SHORT)(CharRegion.Bottom - CharRegion.Top + 1);
    01328
    01329     ConvRegion = CharRegion;
    01330
    01331     ScreenInfo = ConvAreaInfo->ScreenBuffer;
    01332
    01333     if (!fUnicode) {
    01334         TranslateOutputToUnicode(Console,
    01335                                  Buffer,
    01336                                  BufferSize
    01337                                 );
    01338         Status = WriteScreenBuffer(ScreenInfo,
    01339                                    Buffer,
    01340                                    &ConvRegion
    01341                                   );
    01342     } else {
    01343         CHAR_INFO StackBuffer[STACK_BUFFER_SIZE * 2];
    01344         PCHAR_INFO TransBuffer;
    01345         BOOL StackBufferF = FALSE;
    01346
    01347         if (BufferSize.Y * BufferSize.X <= STACK_BUFFER_SIZE) {
    01348             TransBuffer = StackBuffer;
    01349             StackBufferF = TRUE;
    01350         } else {
    01351             TransBuffer = (PCHAR_INFO)ConsoleHeapAlloc(MAKE_TAG( TMP_DBCS_TAG ),(BufferSize.Y * BufferSize.X) * 2 * sizeof(CHAR_INFO));
    01352             if (TransBuffer == NULL) {
    01353                 return STATUS_NO_MEMORY;
    01354             }
    01355         }
    01356         if ((Console->CurrentScreenBuffer->Flags & CONSOLE_OEMFONT_DISPLAY) &&
    01357                 ((Console->FullScreenFlags & CONSOLE_FULLSCREEN) == 0)) {
    01358             TranslateOutputToAnsiUnicode(Console,
    01359                                          Buffer,
    01360                                          BufferSize,
    01361                                          &TransBuffer[0]
    01362                                         );
    01363         }
    01364         else {
    01365             TranslateOutputToPaddingUnicode(Console,
    01366                                             Buffer,
    01367                                             BufferSize,
    01368                                             &TransBuffer[0]
    01369                                            );
    01370         }
    01371
    01372         Status = WriteScreenBuffer(ScreenInfo,
    01373                                    &TransBuffer[0],
    01374                                    &ConvRegion
    01375                                   );
    01376         if (!StackBufferF)
    01377             ConsoleHeapFree(TransBuffer);
    01378     }
    01379
    01380     if (NT_SUCCESS(Status)) {
    01381
    01382         ScreenInfo = Console->CurrentScreenBuffer;
    01383
    01384
    01385         // Check code for must CONSOLE_TEXTMODE_BUFFER !!
    01386         if (ScreenInfo->Flags & CONSOLE_GRAPHICS_BUFFER) {
    01387             ASSERT(FALSE);
    01388         }
    01389         else if ((ConvAreaInfo->ConversionAreaMode & (CA_HIDDEN+CA_STATUS_LINE))==(CA_STATUS_LINE)) {
    01390             if (ScreenInfo->BufferInfo.TextInfo.CursorPosition.Y == (ScreenInfo->ScreenBufferSize.Y-1)
    01391                )
    01392             {
    01393                 ConsoleHideCursor(ScreenInfo);
    01394                 ConsoleImeBottomLineUse(ScreenInfo,1);
    01395                 CursorPosition = ScreenInfo->BufferInfo.TextInfo.CursorPosition;
    01396                 CursorPosition.Y--;
    01397                 SetCursorPosition(ScreenInfo,CursorPosition,TRUE);
    01398                 if (ScreenInfo->Console->lpCookedReadData) {
    01399                     ((PCOOKED_READ_DATA)(ScreenInfo->Console->lpCookedReadData))->OriginalCursorPosition.Y--;
    01400                 }
    01401                 ConsoleShowCursor(ScreenInfo);
    01402             }
    01403             else if (ScreenInfo->BufferInfo.TextInfo.CursorPosition.Y == ScreenInfo->Window.Bottom) {
    01404                 COORD WindowOrigin ;
    01405                 WindowOrigin.X = ScreenInfo->Window.Left ;
    01406                 WindowOrigin.Y = ScreenInfo->Window.Top+1 ;
    01407                 SetWindowOrigin(ScreenInfo, TRUE, WindowOrigin) ;
    01408                 if ( ! (ScreenInfo->Console->InputBuffer.ImeMode.Disable) &&
    01409                      ! (ScreenInfo->Console->InputBuffer.ImeMode.Unavailable) &&
    01410                      (ScreenInfo->Console->InputBuffer.ImeMode.Open) ) {
    01411                     SMALL_RECT Rectangle;
    01412                     Rectangle.Left = ScreenInfo->Window.Left ;
    01413                     Rectangle.Right = ScreenInfo->Window.Right ;
    01414                     Rectangle.Top = ScreenInfo->Window.Bottom ;
    01415                     Rectangle.Bottom = ScreenInfo->Window.Bottom ;
    01416                     ScreenInfo->BufferInfo.TextInfo.Flags &= ~TEXT_VALID_HINT;
    01417                     WriteToScreen(ScreenInfo,&Rectangle);
    01418                     ScreenInfo->BufferInfo.TextInfo.Flags |= TEXT_VALID_HINT;
    01419                     WriteConvRegionToScreen(ScreenInfo,
    01420                                             ScreenInfo->Console->ConsoleIme.ConvAreaRoot,
    01421                                             &Rectangle);
    01422                 }
    01423             }
    01424         }
    01425
    01426         //
    01427         // cause screen to be updated
    01428         //
    01429         ConvRegion.Left   += (ScreenInfo->Window.Left + ConvAreaInfo->CaInfo.coordConView.X);
    01430         ConvRegion.Right  += (ScreenInfo->Window.Left + ConvAreaInfo->CaInfo.coordConView.X);
    01431         ConvRegion.Top    += (ScreenInfo->Window.Top + ConvAreaInfo->CaInfo.coordConView.Y);
    01432         ConvRegion.Bottom += (ScreenInfo->Window.Top + ConvAreaInfo->CaInfo.coordConView.Y);
    01433
    01434
    01435         // Check code for must CONSOLE_TEXTMODE_BUFFER !!
    01436         if (ScreenInfo->Flags & CONSOLE_GRAPHICS_BUFFER) {
    01437             ASSERT(FALSE);
    01438         }
    01439         else
    01440             ScreenInfo->BufferInfo.TextInfo.Flags &= ~TEXT_VALID_HINT;
    01441         WriteConvRegionToScreen(ScreenInfo,
    01442                                 ConvAreaInfo,
    01443                                 &ConvRegion
    01444                                );
    01445         ConvAreaInfo->ScreenBuffer->BisectFlag &= ~(BISECT_LEFT | BISECT_RIGHT | BISECT_TOP | BISECT_BOTTOM);
    01446     }
    01447     return Status;
    01448 }
    01449
    01450
    01451
    01452
    01453
    01454
    01455
    01456
    01457 NTSTATUS
    01458 ImeControl(
    01459     IN PCONSOLE_INFORMATION Console,
    01460     IN HWND hWndConsoleIME,
    01461     IN PCOPYDATASTRUCT lParam
    01462     )
    01463
    01464 /*++
    01465
    01466 Routine Description:
    01467
    01468     This routine handle WM_COPYDATA message.
    01469
    01470 Arguments:
    01471
    01472     Console - Pointer to console information structure.
    01473
    01474     wParam -
    01475
    01476     lParam -
    01477
    01478 Return Value:
    01479
    01480 --*/
    01481
    01482 {
    01483     PSCREEN_INFORMATION ScreenInfo;
    01484     PCONVERSIONAREA_INFORMATION ConvAreaInfo;
    01485     PCHAR_INFO SystemString ;
    01486     DWORD i ;
    01487     DWORD j ;
    01488
    01489     if (lParam == NULL) {
    01490         // fail safe.
    01491         return STATUS_SUCCESS;
    01492     }
    01493
    01494     ScreenInfo = Console->CurrentScreenBuffer;
    01495     switch ((LONG)lParam->dwData) {
    01496         case CI_CONIMECOMPOSITION:
    01497             if (lParam->cbData >= sizeof(CONIME_UICOMPMESSAGE)) {
    01498                 LPCONIME_UICOMPMESSAGE CompStr;
    01499
    01500                 DBGPRINT(("CONSRV: Get IR_CONIMECOMPOSITION Message\n"));
    01501                 CompStr = (LPCONIME_UICOMPMESSAGE)lParam->lpData;
    01502                 if (CompStr && CompStr->dwSize == lParam->cbData) {
    01503                     if (Console->ConsoleIme.CompStrData)
    01504                         ConsoleHeapFree(Console->ConsoleIme.CompStrData);
    01505                     Console->ConsoleIme.CompStrData = ConsoleHeapAlloc(
    01506                                                                 MAKE_TAG( IME_TAG ),
    01507                                                                 CompStr->dwSize);
    01508                     if (Console->ConsoleIme.CompStrData == NULL)
    01509                         break;
    01510                     memmove(Console->ConsoleIme.CompStrData,CompStr,CompStr->dwSize);
    01511                     ConsoleImeCompStr(Console, Console->ConsoleIme.CompStrData);
    01512                 }
    01513             }
    01514             break;
    01515         case CI_CONIMEMODEINFO:
    01516             if (lParam->cbData == sizeof(CONIME_UIMODEINFO)) {
    01517                 LPCONIME_UIMODEINFO lpModeInfo ;
    01518
    01519                 DBGPRINT(("CONSRV: Get IR_CONIMEMODEINFO Message\n"));
    01520
    01521                 lpModeInfo = (LPCONIME_UIMODEINFO)lParam->lpData ;
    01522                 if (lpModeInfo != NULL) {
    01523                     if (! Console->InputBuffer.ImeMode.Disable) {
    01524                         if (lpModeInfo->ModeStringLen != 0){
    01525                             for (j = 0 ; j < lpModeInfo->ModeStringLen ; j++ )
    01526                                 lpModeInfo->ModeString[j].Attributes = Console->CurrentScreenBuffer->Attributes ;
    01527                             Console->ConsoleIme.ConvAreaModePosition = lpModeInfo->Position;
    01528                             WriteModeSystemChars(Console,
    01529                                                  Console->ConsoleIme.ConvAreaMode,
    01530                                                  (PCHAR_INFO)&lpModeInfo->ModeString,
    01531                                                  lpModeInfo->ModeStringLen,
    01532                                                  Console->ConsoleIme.ConvAreaModePosition);
    01533                         }
    01534                         else{
    01535                             ConvAreaInfo = Console->ConsoleIme.ConvAreaMode;
    01536                             if (ConvAreaInfo &&
    01537                                 (!(ConvAreaInfo->ConversionAreaMode & CA_HIDDEN))) {
    01538                                 FillUndetermineChars(Console,ConvAreaInfo);
    01539                             }
    01540                             ConvAreaInfo = Console->ConsoleIme.ConvAreaSystem ;
    01541                             if (ConvAreaInfo &&
    01542                                 (!(ConvAreaInfo->ConversionAreaMode & CA_HIDDEN))) {
    01543                                 FillUndetermineChars(Console,ConvAreaInfo);
    01544                             }
    01545                         }
    01546                     }
    01547                 }
    01548             }
    01549             break;
    01550         case CI_CONIMESYSINFO: {
    01551             PWCHAR SourceString ;
    01552
    01553             DBGPRINT(("CONSRV: Get IR_CONIMESYSINFO Message\n"));
    01554
    01555             if ((lParam->cbData != 0) &&
    01556                 (lParam->lpData != NULL) &&
    01557                 (! Console->InputBuffer.ImeMode.Disable)) {
    01558                 i = (lParam->cbData / sizeof(WCHAR))-1 ;
    01559                 SourceString = ((LPCONIME_UIMESSAGE)(lParam->lpData))->String ;
    01560                 SystemString = (PCHAR_INFO)ConsoleHeapAlloc(
    01561                                                  MAKE_TAG( IME_TAG ),
    01562                                                  sizeof(CHAR_INFO)*i) ;
    01563                 if (SystemString == NULL) {
    01564                     break ;
    01565                 }
    01566                 for (j = 0 ; j < i ; j++ ) {
    01567                     SystemString[j].Char.UnicodeChar = *SourceString ;
    01568                     SystemString[j].Attributes = Console->CurrentScreenBuffer->Attributes ;
    01569                     SourceString++ ;
    01570                 }
    01571                 WriteModeSystemChars(Console,
    01572                                      Console->ConsoleIme.ConvAreaSystem,
    01573                                      (PCHAR_INFO)SystemString,
    01574                                      i,
    01575                                      VIEW_LEFT);
    01576                 ConsoleHeapFree(SystemString);
    01577             }
    01578             else {
    01579                 ConvAreaInfo = Console->ConsoleIme.ConvAreaSystem ;
    01580                 if (ConvAreaInfo &&
    01581                     (!(ConvAreaInfo->ConversionAreaMode & CA_HIDDEN))) {
    01582                     FillUndetermineChars(Console,ConvAreaInfo);
    01583                 }
    01584             }
    01585             break;
    01586         }
    01587         case CI_CONIMECANDINFO:{
    01588             PWCHAR SourceString;
    01589             PUCHAR SourceAttr;
    01590             DWORD LengthToWrite;
    01591             LPCONIME_CANDMESSAGE CandInfo = (LPCONIME_CANDMESSAGE)(lParam->lpData);
    01592
    01593             DBGPRINT(("CONSRV: Get IR_CONIMESYSINFO Message\n"));
    01594
    01595             if ((lParam->cbData != 0) &&
    01596                 (CandInfo != NULL) ){
    01597                 SourceString = CandInfo->String;
    01598                 SourceAttr = (PUCHAR)((PBYTE)CandInfo + CandInfo->AttrOff);
    01599                 LengthToWrite = lstrlenW(SourceString);
    01600                 SystemString = (PCHAR_INFO)ConsoleHeapAlloc(
    01601                                                  MAKE_TAG( IME_TAG ),
    01602                                                  sizeof(CHAR_INFO) * LengthToWrite);
    01603                 if (SystemString == NULL) {
    01604                     break ;
    01605                 }
    01606                 for (j = 0 ; j < LengthToWrite ; j++ ) {
    01607                     SystemString[j].Char.UnicodeChar = *SourceString ;
    01608                     if (*SourceAttr == 1 &&
    01609                         Console->ConsoleIme.CompStrData != NULL) {
    01610                         SystemString[j].Attributes = Console->ConsoleIme.CompStrData->CompAttrColor[1];
    01611                     }
    01612                     else {
    01613                         SystemString[j].Attributes = Console->CurrentScreenBuffer->Attributes ;
    01614                     }
    01615                     SourceString++ ;
    01616                     SourceAttr++ ;
    01617                 }
    01618                 WriteModeSystemChars(Console,
    01619                                      Console->ConsoleIme.ConvAreaSystem,
    01620                                      (PCHAR_INFO)SystemString,
    01621                                      LengthToWrite,
    01622                                      VIEW_LEFT);
    01623                 ConsoleHeapFree(SystemString);
    01624             }
    01625             else {
    01626                 ConvAreaInfo = Console->ConsoleIme.ConvAreaSystem;
    01627                 if (ConvAreaInfo) {
    01628                     SMALL_RECT rcViewCaWindow = {0, 0, 0, 0};
    01629                     FillUndetermineChars(Console,ConvAreaInfo);
    01630                     ConvAreaInfo->ConversionAreaMode |= CA_HIDDEN;
    01631                     ConsoleImeWindowInfo(Console,ConvAreaInfo,rcViewCaWindow);
    01632                 }
    01633             }
    01634             break;
    01635         }
    01636         case CI_CONIMEPROPERTYINFO:{
    01637             WPARAM* wParam = (WPARAM*)(lParam->lpData);
    01638
    01639             if ((lParam->cbData != 0) &&
    01640                 (wParam != NULL) ){
    01641                 switch (*wParam) {
    01642                     case IMS_OPENPROPERTYWINDOW:
    01643                         Console->InputBuffer.hWndConsoleIME = hWndConsoleIME;
    01644                         break;
    01645                     case IMS_CLOSEPROPERTYWINDOW:
    01646                         Console->InputBuffer.hWndConsoleIME = NULL;
    01647                         SetFocus(Console->hWnd);
    01648                         break;
    01649                 }
    01650             }
    01651             break;
    01652         }
    01653     }
    01654
    01655     return STATUS_SUCCESS;
    01656 }
    01657
    01658 BOOL
    01659 InsertConverTedString(
    01660     IN PCONSOLE_INFORMATION Console,
    01661     LPWSTR lpStr
    01662     )
    01663 {
    01664     ULONG EventsWritten;
    01665     PINPUT_RECORD InputEvent,TmpInputEvent;
    01666     DWORD dwControlKeyState;
    01667     DWORD dwLen;
    01668     DWORD dwConversion;
    01669     BOOL fResult = FALSE;
    01670
    01671     // Check code for must CONSOLE_TEXTMODE_BUFFER !!
    01672     if (Console->CurrentScreenBuffer->Flags & CONSOLE_GRAPHICS_BUFFER) {
    01673         ASSERT(FALSE);
    01674     }
    01675     else if(Console->CurrentScreenBuffer->BufferInfo.TextInfo.CursorOn){
    01676         CursorTimerRoutine(Console->CurrentScreenBuffer) ;
    01677     }
    01678
    01679     dwLen = wcslen(lpStr)+1;
    01680     InputEvent = ConsoleHeapAlloc(MAKE_TAG( IME_TAG ),sizeof(INPUT_RECORD)*dwLen);
    01681     if (InputEvent == NULL) {
    01682         return FALSE;
    01683     }
    01684
    01685     TmpInputEvent = InputEvent;
    01686     dwControlKeyState = GetControlKeyState(0);
    01687
    01688     if (!NT_SUCCESS(GetImeKeyState(Console, &dwConversion))) {
    01689         goto skip_and_return;
    01690     }
    01691
    01692     dwControlKeyState |= ImmConversionToConsole(dwConversion);
    01693
    01694     while (*lpStr) {
    01695         TmpInputEvent->EventType = KEY_EVENT;
    01696         TmpInputEvent->Event.KeyEvent.bKeyDown = TRUE;
    01697         TmpInputEvent->Event.KeyEvent.wVirtualKeyCode = 0;
    01698         TmpInputEvent->Event.KeyEvent.wVirtualScanCode = 0;
    01699         TmpInputEvent->Event.KeyEvent.dwControlKeyState = dwControlKeyState;
    01700         TmpInputEvent->Event.KeyEvent.uChar.UnicodeChar = *lpStr++;
    01701         TmpInputEvent->Event.KeyEvent.wRepeatCount = 1;
    01702         TmpInputEvent++;
    01703     }
    01704
    01705     EventsWritten = WriteInputBuffer( Console,
    01706                                       &Console->InputBuffer,
    01707                                       InputEvent,
    01708                                       dwLen-1
    01709                                      );
    01710
    01711     fResult = TRUE;
    01712
    01713 skip_and_return:
    01714     ConsoleHeapFree(InputEvent);
    01715     return fResult;
    01716 }
    01717
    01718
    01719 VOID
    01720 SetUndetermineAttribute(
    01721     IN PCONSOLE_INFORMATION Console
    01722     )
    01723 {
    01724
    01725     PSCREEN_INFORMATION ScreenInfo;
    01726     PCONVERSIONAREA_INFORMATION ConvAreaInfo ;
    01727
    01728     ScreenInfo = Console->CurrentScreenBuffer;
    01729
    01730     ConvAreaInfo = Console->ConsoleIme.ConvAreaRoot ;
    01731     if (ConvAreaInfo != NULL) {
    01732         do {
    01733             ConvAreaInfo->ScreenBuffer->Attributes = ScreenInfo->Attributes;
    01734             ConvAreaInfo = ConvAreaInfo->ConvAreaNext ;
    01735         } while (ConvAreaInfo != NULL);
    01736     }
    01737
    01738     if (Console->ConsoleIme.ConvAreaMode != NULL)
    01739         Console->ConsoleIme.ConvAreaMode->ScreenBuffer->Attributes = ScreenInfo->Attributes;
    01740
    01741     if (Console->ConsoleIme.ConvAreaSystem != NULL)
    01742         Console->ConsoleIme.ConvAreaSystem->ScreenBuffer->Attributes = ScreenInfo->Attributes;
    01743 }
    01744
    01745
    01746 VOID
    01747 StreamWriteToScreenBufferIME(
    01748     IN PWCHAR String,
    01749     IN SHORT StringLength,
    01750     IN PSCREEN_INFORMATION ScreenInfo,
    01751     IN PCHAR StringA
    01752     )
    01753 {
    01754     SHORT RowIndex;
    01755     PROW Row;
    01756     PWCHAR Char;
    01757     COORD TargetPoint;
    01758
    01759     DBGOUTPUT(("StreamWriteToScreenBuffer\n"));
    01760
    01761     // Check code for must CONSOLE_TEXTMODE_BUFFER !!
    01762     ASSERT(!(ScreenInfo->Flags & CONSOLE_GRAPHICS_BUFFER));
    01763
    01764     ScreenInfo->BufferInfo.TextInfo.Flags |= TEXT_VALID_HINT;
    01765     TargetPoint = ScreenInfo->BufferInfo.TextInfo.CursorPosition;
    01766     RowIndex = (ScreenInfo->BufferInfo.TextInfo.FirstRow+TargetPoint.Y) % ScreenInfo->ScreenBufferSize.Y;
    01767     Row = &ScreenInfo->BufferInfo.TextInfo.Rows[RowIndex];
    01768     DBGOUTPUT(("RowIndex = %lx, Row = %lx, TargetPoint = (%d,%d)\n",
    01769             RowIndex, Row, TargetPoint.X, TargetPoint.Y));
    01770
    01771     //
    01772     // copy chars
    01773     //
    01774
    01775 //#if defined(FE_SB)
    01776     BisectWrite(StringLength,TargetPoint,ScreenInfo);
    01777     if (TargetPoint.Y == ScreenInfo->ScreenBufferSize.Y-1 &&
    01778         TargetPoint.X+StringLength >= ScreenInfo->ScreenBufferSize.X &&
    01779         *(StringA+ScreenInfo->ScreenBufferSize.X-TargetPoint.X-1) & ATTR_LEADING_BYTE
    01780        ) {
    01781         *(String+ScreenInfo->ScreenBufferSize.X-TargetPoint.X-1) = UNICODE_SPACE;
    01782         *(StringA+ScreenInfo->ScreenBufferSize.X-TargetPoint.X-1) = 0;
    01783         if (StringLength > ScreenInfo->ScreenBufferSize.X-TargetPoint.X-1) {
    01784             *(String+ScreenInfo->ScreenBufferSize.X-TargetPoint.X) = UNICODE_SPACE;
    01785             *(StringA+ScreenInfo->ScreenBufferSize.X-TargetPoint.X) = 0;
    01786         }
    01787     }
    01788 //#endif
    01789     RtlCopyMemory(&Row->CharRow.Chars[TargetPoint.X],String,StringLength*sizeof(WCHAR));
    01790 //#if defined(FE_SB)
    01791     RtlCopyMemory(&Row->CharRow.KAttrs[TargetPoint.X],StringA,StringLength*sizeof(CHAR));
    01792 //#endif
    01793
    01794     // recalculate first and last non-space char
    01795
    01796     Row->CharRow.OldLeft = Row->CharRow.Left;
    01797     if (TargetPoint.X < Row->CharRow.Left) {
    01798 //#if defined(FE_SB)
    01799         /*
    01800          * CharRow.Left is leftmost bound of chars in Chars array (array will be full width)
    01801          * i.e. type is COORD
    01802          */
    01803         PWCHAR LastChar = &Row->CharRow.Chars[ScreenInfo->ScreenBufferSize.X-1];
    01804 //#else
    01805 //        PWCHAR LastChar = &Row->CharRow.Chars[ScreenInfo->ScreenBufferSize.X];
    01806 //#endif
    01807
    01808         for (Char=&Row->CharRow.Chars[TargetPoint.X];Char < LastChar && *Char==(WCHAR)' ';Char++)
    01809             ;
    01810         Row->CharRow.Left = (SHORT)(Char-Row->CharRow.Chars);
    01811     }
    01812
    01813     Row->CharRow.OldRight = Row->CharRow.Right;
    01814     if ((TargetPoint.X+StringLength) >= Row->CharRow.Right) {
    01815         PWCHAR FirstChar = Row->CharRow.Chars;
    01816
    01817         for (Char=&Row->CharRow.Chars[TargetPoint.X+StringLength-1];*Char==(WCHAR)' ' && Char >= FirstChar;Char--)
    01818             ;
    01819         Row->CharRow.Right = (SHORT)(Char+1-FirstChar);
    01820     }
    01821
    01822     //
    01823     // see if attr string is different.  if so, allocate a new
    01824     // attr buffer and merge the two strings.
    01825     //
    01826
    01827     if (Row->AttrRow.Length != 1 ||
    01828         Row->AttrRow.Attrs->Attr != ScreenInfo->Attributes) {
    01829         PATTR_PAIR NewAttrs;
    01830         WORD NewAttrsLength;
    01831         ATTR_PAIR Attrs;
    01832
    01833 //#if defined(FE_SB) && defined(FE_IME)
    01834         if ((ScreenInfo->Attributes & (COMMON_LVB_GRID_SINGLEFLAG + COMMON_LVB_GRID_RVERTICAL)) ==
    01835             (COMMON_LVB_GRID_SINGLEFLAG + COMMON_LVB_GRID_RVERTICAL)){
    01836             SHORT i ;
    01837             for (i = 0 ; i < StringLength ; i++ ) {
    01838                 Attrs.Length = 1 ;
    01839                 if (*(StringA + i) & ATTR_LEADING_BYTE)
    01840                     Attrs.Attr = ScreenInfo->Attributes & ~(COMMON_LVB_GRID_SINGLEFLAG + COMMON_LVB_GRID_RVERTICAL) ;
    01841                 else
    01842                     Attrs.Attr = ScreenInfo->Attributes & ~COMMON_LVB_GRID_SINGLEFLAG ;
    01843
    01844                 if (!NT_SUCCESS(MergeAttrStrings(Row->AttrRow.Attrs,
    01845                                  Row->AttrRow.Length,
    01846                                  &Attrs,
    01847                                  1,
    01848                                  &NewAttrs,
    01849                                  &NewAttrsLength,
    01850                                  (SHORT)(TargetPoint.X+i),
    01851                                  (SHORT)(TargetPoint.X+i),
    01852                                  Row,
    01853                                  ScreenInfo
    01854                                 ))) {
    01855                     return;
    01856                 }
    01857                 if (Row->AttrRow.Length > 1) {
    01858                     ConsoleHeapFree(Row->AttrRow.Attrs);
    01859                 }
    01860                 else {
    01861                     ASSERT(Row->AttrRow.Attrs == &Row->AttrRow.AttrPair);
    01862                 }
    01863                 Row->AttrRow.Attrs = NewAttrs;
    01864                 Row->AttrRow.Length = NewAttrsLength;
    01865             }
    01866             Row->CharRow.OldLeft = INVALID_OLD_LENGTH;
    01867             Row->CharRow.OldRight = INVALID_OLD_LENGTH;
    01868         }
    01869         else if ((ScreenInfo->Attributes & (COMMON_LVB_GRID_SINGLEFLAG + COMMON_LVB_GRID_LVERTICAL)) ==
    01870             (COMMON_LVB_GRID_SINGLEFLAG + COMMON_LVB_GRID_LVERTICAL)){
    01871             SHORT i ;
    01872             for (i = 0 ; i < StringLength ; i++ ) {
    01873                 Attrs.Length = 1 ;
    01874                 if (*(StringA + i) & ATTR_TRAILING_BYTE)
    01875                     Attrs.Attr = ScreenInfo->Attributes & ~(COMMON_LVB_GRID_SINGLEFLAG + COMMON_LVB_GRID_LVERTICAL);
    01876                 else
    01877                     Attrs.Attr = ScreenInfo->Attributes & ~COMMON_LVB_GRID_SINGLEFLAG ;
    01878
    01879                 if (!NT_SUCCESS(MergeAttrStrings(Row->AttrRow.Attrs,
    01880                                  Row->AttrRow.Length,
    01881                                  &Attrs,
    01882                                  1,
    01883                                  &NewAttrs,
    01884                                  &NewAttrsLength,
    01885                                  (SHORT)(TargetPoint.X+i),
    01886                                  (SHORT)(TargetPoint.X+i),
    01887                                  Row,
    01888                                  ScreenInfo
    01889                                 ))) {
    01890                     return;
    01891                 }
    01892                 if (Row->AttrRow.Length > 1) {
    01893                     ConsoleHeapFree(Row->AttrRow.Attrs);
    01894                 }
    01895                 else {
    01896                     ASSERT(Row->AttrRow.Attrs == &Row->AttrRow.AttrPair);
    01897                 }
    01898                 Row->AttrRow.Attrs = NewAttrs;
    01899                 Row->AttrRow.Length = NewAttrsLength;
    01900             }
    01901             Row->CharRow.OldLeft = INVALID_OLD_LENGTH;
    01902             Row->CharRow.OldRight = INVALID_OLD_LENGTH;
    01903         }
    01904         else{
    01905 //#endif
    01906         Attrs.Length = StringLength;
    01907         Attrs.Attr = ScreenInfo->Attributes;
    01908         if (!NT_SUCCESS(MergeAttrStrings(Row->AttrRow.Attrs,
    01909                          Row->AttrRow.Length,
    01910                          &Attrs,
    01911                          1,
    01912                          &NewAttrs,
    01913                          &NewAttrsLength,
    01914                          TargetPoint.X,
    01915                          (SHORT)(TargetPoint.X+StringLength-1),
    01916                          Row,
    01917                          ScreenInfo
    01918                         ))) {
    01919             return;
    01920         }
    01921         if (Row->AttrRow.Length > 1) {
    01922             ConsoleHeapFree(Row->AttrRow.Attrs);
    01923         }
    01924         else {
    01925             ASSERT(Row->AttrRow.Attrs == &Row->AttrRow.AttrPair);
    01926         }
    01927         Row->AttrRow.Attrs = NewAttrs;
    01928         Row->AttrRow.Length = NewAttrsLength;
    01929         Row->CharRow.OldLeft = INVALID_OLD_LENGTH;
    01930         Row->CharRow.OldRight = INVALID_OLD_LENGTH;
    01931 //#if defined(FE_SB) && defined(FE_IME)
    01932     }
    01933 //#endif
    01934     }
    01935     ResetTextFlags(ScreenInfo,TargetPoint.Y,TargetPoint.Y);
    01936 }
    01937
    01938 #endif // FE_IME