signs_gui.cpp

Go to the documentation of this file.
00001 /* $Id: signs_gui.cpp 23740 2012-01-03 21:32:51Z rubidium $ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
00008  */
00009 
00012 #include "stdafx.h"
00013 #include "company_gui.h"
00014 #include "company_func.h"
00015 #include "signs_base.h"
00016 #include "signs_func.h"
00017 #include "debug.h"
00018 #include "command_func.h"
00019 #include "strings_func.h"
00020 #include "window_func.h"
00021 #include "map_func.h"
00022 #include "viewport_func.h"
00023 #include "querystring_gui.h"
00024 #include "sortlist_type.h"
00025 #include "string_func.h"
00026 #include "core/geometry_func.hpp"
00027 #include "hotkeys.h"
00028 #include "transparency.h"
00029 
00030 #include "widgets/sign_widget.h"
00031 
00032 #include "table/strings.h"
00033 #include "table/sprites.h"
00034 
00040 struct FilterInfo {
00041   const char *string;  
00042   bool case_sensitive; 
00043 };
00044 
00045 struct SignList {
00050   typedef GUIList<const Sign *, FilterInfo> GUISignList;
00051 
00052   static const Sign *last_sign;
00053   GUISignList signs;
00054 
00055   char filter_string[MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH]; 
00056   static bool match_case;                                           
00057 
00061   SignList()
00062   {
00063     filter_string[0] = '\0';
00064   }
00065 
00066   void BuildSignsList()
00067   {
00068     if (!this->signs.NeedRebuild()) return;
00069 
00070     DEBUG(misc, 3, "Building sign list");
00071 
00072     this->signs.Clear();
00073 
00074     const Sign *si;
00075     FOR_ALL_SIGNS(si) *this->signs.Append() = si;
00076 
00077     this->signs.SetFilterState(true);
00078     this->FilterSignList();
00079     this->signs.Compact();
00080     this->signs.RebuildDone();
00081   }
00082 
00084   static int CDECL SignNameSorter(const Sign * const *a, const Sign * const *b)
00085   {
00086     static char buf_cache[64];
00087     char buf[64];
00088 
00089     SetDParam(0, (*a)->index);
00090     GetString(buf, STR_SIGN_NAME, lastof(buf));
00091 
00092     if (*b != last_sign) {
00093       last_sign = *b;
00094       SetDParam(0, (*b)->index);
00095       GetString(buf_cache, STR_SIGN_NAME, lastof(buf_cache));
00096     }
00097 
00098     int r = strnatcmp(buf, buf_cache); // Sort by name (natural sorting).
00099 
00100     return r != 0 ? r : ((*a)->index - (*b)->index);
00101   }
00102 
00103   void SortSignsList()
00104   {
00105     if (!this->signs.Sort(&SignNameSorter)) return;
00106 
00107     /* Reset the name sorter sort cache */
00108     this->last_sign = NULL;
00109   }
00110 
00112   static bool CDECL SignNameFilter(const Sign * const *a, FilterInfo filter_info)
00113   {
00114     /* Get sign string */
00115     char buf1[MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH];
00116     SetDParam(0, (*a)->index);
00117     GetString(buf1, STR_SIGN_NAME, lastof(buf1));
00118 
00119     return (filter_info.case_sensitive ? strstr(buf1, filter_info.string) : strcasestr(buf1, filter_info.string)) != NULL;
00120   }
00121 
00123   static bool CDECL OwnerDeityFilter(const Sign * const *a, FilterInfo filter_info)
00124   {
00125     /* You should never be able to edit signs of owner DEITY */
00126     return (*a)->owner != OWNER_DEITY;
00127   }
00128 
00130   static bool CDECL OwnerVisibilityFilter(const Sign * const *a, FilterInfo filter_info)
00131   {
00132     assert(!HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS));
00133     /* Hide sign if non-own signs are hidden in the viewport */
00134     return (*a)->owner == _local_company;
00135   }
00136 
00138   void FilterSignList()
00139   {
00140     FilterInfo filter_info = {this->filter_string, this->match_case};
00141     this->signs.Filter(&SignNameFilter, filter_info);
00142     this->signs.Filter(&OwnerDeityFilter, filter_info);
00143     if (!HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS)) {
00144       this->signs.Filter(&OwnerVisibilityFilter, filter_info);
00145     }
00146   }
00147 };
00148 
00149 const Sign *SignList::last_sign = NULL;
00150 bool SignList::match_case = false;
00151 
00153 enum SignListHotkeys {
00154   SLHK_FOCUS_FILTER_BOX, 
00155 };
00156 
00157 struct SignListWindow : QueryStringBaseWindow, SignList {
00158   int text_offset; 
00159   Scrollbar *vscroll;
00160 
00161   SignListWindow(const WindowDesc *desc, WindowNumber window_number) : QueryStringBaseWindow(MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_SIGN_NAME_CHARS)
00162   {
00163     this->CreateNestedTree(desc);
00164     this->vscroll = this->GetScrollbar(WID_SIL_SCROLLBAR);
00165     this->FinishInitNested(desc, window_number);
00166     this->SetWidgetLoweredState(WID_SIL_FILTER_MATCH_CASE_BTN, SignList::match_case);
00167 
00168     /* Initialize the text edit widget */
00169     this->afilter = CS_ALPHANUMERAL;
00170     InitializeTextBuffer(&this->text, this->edit_str_buf, MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_SIGN_NAME_CHARS);
00171     ClearFilterTextWidget();
00172 
00173     /* Initialize the filtering variables */
00174     this->SetFilterString("");
00175 
00176     /* Create initial list. */
00177     this->signs.ForceRebuild();
00178     this->signs.ForceResort();
00179     this->BuildSortSignList();
00180   }
00181 
00186   void ClearFilterTextWidget()
00187   {
00188     this->edit_str_buf[0] = '\0';
00189     UpdateTextBufferSize(&this->text);
00190 
00191     this->SetWidgetDirty(WID_SIL_FILTER_TEXT);
00192   }
00193 
00200   void SetFilterString(const char *new_filter_string)
00201   {
00202     /* check if there is a new filter string */
00203     if (!StrEmpty(new_filter_string)) {
00204       /* Copy new filter string */
00205       strecpy(this->filter_string, new_filter_string, lastof(this->filter_string));
00206 
00207       this->EnableWidget(WID_SIL_FILTER_CLEAR_BTN);
00208     } else {
00209       /* There is no new string -> clear this->filter_string */
00210       this->filter_string[0] = '\0';
00211 
00212       this->DisableWidget(WID_SIL_FILTER_CLEAR_BTN);
00213     }
00214 
00215     /* Repaint the clear button since its disabled state may have changed */
00216     this->SetWidgetDirty(WID_SIL_FILTER_CLEAR_BTN);
00217 
00218     /* Rebuild the list of signs */
00219     this->InvalidateData();
00220   }
00221 
00222   virtual void OnPaint()
00223   {
00224     if (this->signs.NeedRebuild()) this->BuildSortSignList();
00225     this->DrawWidgets();
00226     if (!this->IsShaded()) this->DrawEditBox(WID_SIL_FILTER_TEXT);
00227   }
00228 
00229   virtual void DrawWidget(const Rect &r, int widget) const
00230   {
00231     switch (widget) {
00232       case WID_SIL_LIST: {
00233         uint y = r.top + WD_FRAMERECT_TOP; // Offset from top of widget.
00234         /* No signs? */
00235         if (this->vscroll->GetCount() == 0) {
00236           DrawString(r.left + WD_FRAMETEXT_LEFT, r.right, y, STR_STATION_LIST_NONE);
00237           return;
00238         }
00239 
00240         bool rtl = _current_text_dir == TD_RTL;
00241         int sprite_offset_y = (FONT_HEIGHT_NORMAL - 10) / 2 + 1;
00242         uint icon_left  = 4 + (rtl ? r.right - this->text_offset : r.left);
00243         uint text_left  = r.left + (rtl ? WD_FRAMERECT_LEFT : this->text_offset);
00244         uint text_right = r.right - (rtl ? this->text_offset : WD_FRAMERECT_RIGHT);
00245 
00246         /* At least one sign available. */
00247         for (uint16 i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < this->vscroll->GetCount(); i++) {
00248           const Sign *si = this->signs[i];
00249 
00250           if (si->owner != OWNER_NONE) DrawCompanyIcon(si->owner, icon_left, y + sprite_offset_y);
00251 
00252           SetDParam(0, si->index);
00253           DrawString(text_left, text_right, y, STR_SIGN_NAME, TC_YELLOW);
00254           y += this->resize.step_height;
00255         }
00256         break;
00257       }
00258     }
00259   }
00260 
00261   virtual void SetStringParameters(int widget) const
00262   {
00263     if (widget == WID_SIL_CAPTION) SetDParam(0, this->vscroll->GetCount());
00264   }
00265 
00266   virtual void OnClick(Point pt, int widget, int click_count)
00267   {
00268     switch (widget) {
00269       case WID_SIL_LIST: {
00270         uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SIL_LIST, WD_FRAMERECT_TOP);
00271         if (id_v == INT_MAX) return;
00272 
00273         const Sign *si = this->signs[id_v];
00274         ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
00275         break;
00276       }
00277       case WID_SIL_FILTER_CLEAR_BTN:
00278         this->ClearFilterTextWidget(); // Empty the text in the EditBox widget
00279         this->SetFilterString("");     // Use empty text as filter text (= view all signs)
00280         break;
00281 
00282       case WID_SIL_FILTER_MATCH_CASE_BTN:
00283         SignList::match_case = !SignList::match_case; // Toggle match case
00284         this->SetWidgetLoweredState(WID_SIL_FILTER_MATCH_CASE_BTN, SignList::match_case); // Toggle button pushed state
00285         this->InvalidateData(); // Rebuild the list of signs
00286         break;
00287     }
00288   }
00289 
00290   virtual void OnResize()
00291   {
00292     this->vscroll->SetCapacityFromWidget(this, WID_SIL_LIST, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
00293   }
00294 
00295   virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
00296   {
00297     switch (widget) {
00298       case WID_SIL_LIST: {
00299         Dimension spr_dim = GetSpriteSize(SPR_COMPANY_ICON);
00300         this->text_offset = WD_FRAMETEXT_LEFT + spr_dim.width + 2; // 2 pixels space between icon and the sign text.
00301         resize->height = max<uint>(FONT_HEIGHT_NORMAL, spr_dim.height);
00302         Dimension d = {this->text_offset + WD_FRAMETEXT_RIGHT, WD_FRAMERECT_TOP + 5 * resize->height + WD_FRAMERECT_BOTTOM};
00303         *size = maxdim(*size, d);
00304         break;
00305       }
00306 
00307       case WID_SIL_CAPTION:
00308         SetDParam(0, max<size_t>(1000, Sign::GetPoolSize()));
00309         *size = GetStringBoundingBox(STR_SIGN_LIST_CAPTION);
00310         size->height += padding.height;
00311         size->width  += padding.width;
00312         break;
00313     }
00314   }
00315 
00316   virtual EventState OnKeyPress(uint16 key, uint16 keycode)
00317   {
00318     EventState state = ES_NOT_HANDLED;
00319     switch (this->HandleEditBoxKey(WID_SIL_FILTER_TEXT, key, keycode, state)) {
00320       case HEBR_EDITING:
00321         this->SetFilterString(this->text.buf);
00322         break;
00323 
00324       case HEBR_CONFIRM: // Enter pressed -> goto first sign in list
00325         if (this->signs.Length() >= 1) {
00326           const Sign *si = this->signs[0];
00327           ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
00328         }
00329         return state;
00330 
00331       case HEBR_CANCEL: // ESC pressed, clear filter.
00332         this->OnClick(Point(), WID_SIL_FILTER_CLEAR_BTN, 1); // Simulate click on clear button.
00333         this->UnfocusFocusedWidget();                    // Unfocus the text box.
00334         return state;
00335 
00336       case HEBR_NOT_FOCUSED: // The filter text box is not globaly focused.
00337         if (CheckHotkeyMatch(signlist_hotkeys, keycode, this) == SLHK_FOCUS_FILTER_BOX) {
00338           this->SetFocusedWidget(WID_SIL_FILTER_TEXT);
00339           SetFocusedWindow(this); // The user has asked to give focus to the text box, so make sure this window is focused.
00340           state = ES_HANDLED;
00341         }
00342         break;
00343 
00344       default:
00345         NOT_REACHED();
00346     }
00347 
00348     if (state == ES_HANDLED) OnOSKInput(WID_SIL_FILTER_TEXT);
00349 
00350     return state;
00351   }
00352 
00353   virtual void OnOSKInput(int widget)
00354   {
00355     if (widget == WID_SIL_FILTER_TEXT) this->SetFilterString(this->text.buf);
00356   }
00357 
00358   virtual void OnMouseLoop()
00359   {
00360     this->HandleEditBox(WID_SIL_FILTER_TEXT);
00361   }
00362 
00363   void BuildSortSignList()
00364   {
00365     if (this->signs.NeedRebuild()) {
00366       this->BuildSignsList();
00367       this->vscroll->SetCount(this->signs.Length());
00368       this->SetWidgetDirty(WID_SIL_CAPTION);
00369     }
00370     this->SortSignsList();
00371   }
00372 
00373   virtual void OnHundredthTick()
00374   {
00375     this->BuildSortSignList();
00376     this->SetDirty();
00377   }
00378 
00384   virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
00385   {
00386     /* When there is a filter string, we always need to rebuild the list even if
00387      * the amount of signs in total is unchanged, as the subset of signs that is
00388      * accepted by the filter might has changed. */
00389     if (data == 0 || data == -1 || !StrEmpty(this->filter_string)) { // New or deleted sign, changed visibility setting or there is a filter string
00390       /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
00391       this->signs.ForceRebuild();
00392     } else { // Change of sign contents while there is no filter string
00393       this->signs.ForceResort();
00394     }
00395   }
00396 
00397   static Hotkey<SignListWindow> signlist_hotkeys[];
00398 };
00399 
00400 Hotkey<SignListWindow> SignListWindow::signlist_hotkeys[] = {
00401   Hotkey<SignListWindow>('F', "focus_filter_box", SLHK_FOCUS_FILTER_BOX),
00402   HOTKEY_LIST_END(SignListWindow)
00403 };
00404 Hotkey<SignListWindow> *_signlist_hotkeys = SignListWindow::signlist_hotkeys;
00405 
00406 static const NWidgetPart _nested_sign_list_widgets[] = {
00407   NWidget(NWID_HORIZONTAL),
00408     NWidget(WWT_CLOSEBOX, COLOUR_GREY),
00409     NWidget(WWT_CAPTION, COLOUR_GREY, WID_SIL_CAPTION), SetDataTip(STR_SIGN_LIST_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
00410     NWidget(WWT_SHADEBOX, COLOUR_GREY),
00411     NWidget(WWT_STICKYBOX, COLOUR_GREY),
00412   EndContainer(),
00413   NWidget(NWID_HORIZONTAL),
00414     NWidget(NWID_VERTICAL),
00415       NWidget(WWT_PANEL, COLOUR_GREY, WID_SIL_LIST), SetMinimalSize(WD_FRAMETEXT_LEFT + 16 + 255 + WD_FRAMETEXT_RIGHT, 50),
00416                 SetResize(1, 10), SetFill(1, 0), SetScrollbar(WID_SIL_SCROLLBAR), EndContainer(),
00417       NWidget(NWID_HORIZONTAL),
00418         NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 1),
00419           NWidget(WWT_EDITBOX, COLOUR_GREY, WID_SIL_FILTER_TEXT), SetMinimalSize(80, 12), SetResize(1, 0), SetFill(1, 0), SetPadding(2, 2, 2, 2),
00420               SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
00421         EndContainer(),
00422         NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SIL_FILTER_MATCH_CASE_BTN), SetDataTip(STR_SIGN_LIST_MATCH_CASE, STR_SIGN_LIST_MATCH_CASE_TOOLTIP),
00423         NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SIL_FILTER_CLEAR_BTN), SetDataTip(STR_SIGN_LIST_CLEAR, STR_SIGN_LIST_CLEAR_TOOLTIP),
00424       EndContainer(),
00425     EndContainer(),
00426     NWidget(NWID_VERTICAL),
00427       NWidget(NWID_VERTICAL), SetFill(0, 1),
00428         NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_SIL_SCROLLBAR),
00429       EndContainer(),
00430       NWidget(WWT_RESIZEBOX, COLOUR_GREY),
00431     EndContainer(),
00432   EndContainer(),
00433 };
00434 
00435 static const WindowDesc _sign_list_desc(
00436   WDP_AUTO, 358, 138,
00437   WC_SIGN_LIST, WC_NONE,
00438   WDF_UNCLICK_BUTTONS,
00439   _nested_sign_list_widgets, lengthof(_nested_sign_list_widgets)
00440 );
00441 
00447 Window *ShowSignList()
00448 {
00449   return AllocateWindowDescFront<SignListWindow>(&_sign_list_desc, 0);
00450 }
00451 
00452 EventState SignListGlobalHotkeys(uint16 key, uint16 keycode)
00453 {
00454   int num = CheckHotkeyMatch<SignListWindow>(_signlist_hotkeys, keycode, NULL, true);
00455   if (num == -1) return ES_NOT_HANDLED;
00456   Window *w = ShowSignList();
00457   if (w == NULL) return ES_NOT_HANDLED;
00458   return w->OnKeyPress(key, keycode);
00459 }
00460 
00467 static bool RenameSign(SignID index, const char *text)
00468 {
00469   bool remove = StrEmpty(text);
00470   DoCommandP(0, index, 0, CMD_RENAME_SIGN | (StrEmpty(text) ? CMD_MSG(STR_ERROR_CAN_T_DELETE_SIGN) : CMD_MSG(STR_ERROR_CAN_T_CHANGE_SIGN_NAME)), NULL, text);
00471   return remove;
00472 }
00473 
00474 struct SignWindow : QueryStringBaseWindow, SignList {
00475   SignID cur_sign;
00476 
00477   SignWindow(const WindowDesc *desc, const Sign *si) : QueryStringBaseWindow(MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_SIGN_NAME_CHARS)
00478   {
00479     this->caption = STR_EDIT_SIGN_CAPTION;
00480     this->afilter = CS_ALPHANUMERAL;
00481 
00482     this->InitNested(desc, WN_QUERY_STRING_SIGN);
00483 
00484     this->LowerWidget(WID_QES_TEXT);
00485     UpdateSignEditWindow(si);
00486     this->SetFocusedWidget(WID_QES_TEXT);
00487   }
00488 
00489   void UpdateSignEditWindow(const Sign *si)
00490   {
00491     char *last_of = &this->edit_str_buf[this->edit_str_size - 1]; // points to terminating '\0'
00492 
00493     /* Display an empty string when the sign hasnt been edited yet */
00494     if (si->name != NULL) {
00495       SetDParam(0, si->index);
00496       GetString(this->edit_str_buf, STR_SIGN_NAME, last_of);
00497     } else {
00498       GetString(this->edit_str_buf, STR_EMPTY, last_of);
00499     }
00500     *last_of = '\0';
00501 
00502     this->cur_sign = si->index;
00503     InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, this->max_chars);
00504 
00505     this->SetWidgetDirty(WID_QES_TEXT);
00506     this->SetFocusedWidget(WID_QES_TEXT);
00507   }
00508 
00514   const Sign *PrevNextSign(bool next)
00515   {
00516     /* Rebuild the sign list */
00517     this->signs.ForceRebuild();
00518     this->signs.NeedResort();
00519     this->BuildSignsList();
00520     this->SortSignsList();
00521 
00522     /* Search through the list for the current sign, excluding
00523      * - the first sign if we want the previous sign or
00524      * - the last sign if we want the next sign */
00525     uint end = this->signs.Length() - (next ? 1 : 0);
00526     for (uint i = next ? 0 : 1; i < end; i++) {
00527       if (this->cur_sign == this->signs[i]->index) {
00528         /* We've found the current sign, so return the sign before/after it */
00529         return this->signs[i + (next ? 1 : -1)];
00530       }
00531     }
00532     /* If we haven't found the current sign by now, return the last/first sign */
00533     return this->signs[next ? 0 : this->signs.Length() - 1];
00534   }
00535 
00536   virtual void SetStringParameters(int widget) const
00537   {
00538     switch (widget) {
00539       case WID_QES_CAPTION:
00540         SetDParam(0, this->caption);
00541         break;
00542     }
00543   }
00544 
00545   virtual void OnPaint()
00546   {
00547     this->DrawWidgets();
00548     if (!this->IsShaded()) this->DrawEditBox(WID_QES_TEXT);
00549   }
00550 
00551   virtual void OnClick(Point pt, int widget, int click_count)
00552   {
00553     switch (widget) {
00554       case WID_QES_PREVIOUS:
00555       case WID_QES_NEXT: {
00556         const Sign *si = this->PrevNextSign(widget == WID_QES_NEXT);
00557 
00558         /* Rebuild the sign list */
00559         this->signs.ForceRebuild();
00560         this->signs.NeedResort();
00561         this->BuildSignsList();
00562         this->SortSignsList();
00563 
00564         /* Scroll to sign and reopen window */
00565         ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
00566         UpdateSignEditWindow(si);
00567         break;
00568       }
00569 
00570       case WID_QES_DELETE:
00571         /* Only need to set the buffer to null, the rest is handled as the OK button */
00572         RenameSign(this->cur_sign, "");
00573         /* don't delete this, we are deleted in Sign::~Sign() -> DeleteRenameSignWindow() */
00574         break;
00575 
00576       case WID_QES_OK:
00577         if (RenameSign(this->cur_sign, this->text.buf)) break;
00578         /* FALL THROUGH */
00579 
00580       case WID_QES_CANCEL:
00581         delete this;
00582         break;
00583     }
00584   }
00585 
00586   virtual EventState OnKeyPress(uint16 key, uint16 keycode)
00587   {
00588     EventState state = ES_NOT_HANDLED;
00589     switch (this->HandleEditBoxKey(WID_QES_TEXT, key, keycode, state)) {
00590       default: break;
00591 
00592       case HEBR_CONFIRM:
00593         if (RenameSign(this->cur_sign, this->text.buf)) break;
00594         /* FALL THROUGH */
00595 
00596       case HEBR_CANCEL: // close window, abandon changes
00597         delete this;
00598         break;
00599     }
00600     return state;
00601   }
00602 
00603   virtual void OnMouseLoop()
00604   {
00605     this->HandleEditBox(WID_QES_TEXT);
00606   }
00607 
00608   virtual void OnOpenOSKWindow(int wid)
00609   {
00610     ShowOnScreenKeyboard(this, wid, WID_QES_CANCEL, WID_QES_OK);
00611   }
00612 };
00613 
00614 static const NWidgetPart _nested_query_sign_edit_widgets[] = {
00615   NWidget(NWID_HORIZONTAL),
00616     NWidget(WWT_CLOSEBOX, COLOUR_GREY),
00617     NWidget(WWT_CAPTION, COLOUR_GREY, WID_QES_CAPTION), SetDataTip(STR_WHITE_STRING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
00618   EndContainer(),
00619   NWidget(WWT_PANEL, COLOUR_GREY),
00620     NWidget(WWT_EDITBOX, COLOUR_GREY, WID_QES_TEXT), SetMinimalSize(256, 12), SetDataTip(STR_EDIT_SIGN_SIGN_OSKTITLE, STR_NULL), SetPadding(2, 2, 2, 2),
00621   EndContainer(),
00622   NWidget(NWID_HORIZONTAL),
00623     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_QES_OK), SetMinimalSize(61, 12), SetDataTip(STR_BUTTON_OK, STR_NULL),
00624     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_QES_CANCEL), SetMinimalSize(60, 12), SetDataTip(STR_BUTTON_CANCEL, STR_NULL),
00625     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_QES_DELETE), SetMinimalSize(60, 12), SetDataTip(STR_TOWN_VIEW_DELETE_BUTTON, STR_NULL),
00626     NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 1), EndContainer(),
00627     NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_QES_PREVIOUS), SetMinimalSize(11, 12), SetDataTip(AWV_DECREASE, STR_EDIT_SIGN_PREVIOUS_SIGN_TOOLTIP),
00628     NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_QES_NEXT), SetMinimalSize(11, 12), SetDataTip(AWV_INCREASE, STR_EDIT_SIGN_NEXT_SIGN_TOOLTIP),
00629   EndContainer(),
00630 };
00631 
00632 static const WindowDesc _query_sign_edit_desc(
00633   WDP_AUTO, 0, 0,
00634   WC_QUERY_STRING, WC_NONE,
00635   WDF_CONSTRUCTION | WDF_UNCLICK_BUTTONS,
00636   _nested_query_sign_edit_widgets, lengthof(_nested_query_sign_edit_widgets)
00637 );
00638 
00643 void HandleClickOnSign(const Sign *si)
00644 {
00645   if (_ctrl_pressed && si->owner == _local_company) {
00646     RenameSign(si->index, NULL);
00647     return;
00648   }
00649   ShowRenameSignWindow(si);
00650 }
00651 
00656 void ShowRenameSignWindow(const Sign *si)
00657 {
00658   /* Delete all other edit windows */
00659   DeleteWindowByClass(WC_QUERY_STRING);
00660 
00661   new SignWindow(&_query_sign_edit_desc, si);
00662 }
00663 
00668 void DeleteRenameSignWindow(SignID sign)
00669 {
00670   SignWindow *w = dynamic_cast<SignWindow *>(FindWindowById(WC_QUERY_STRING, WN_QUERY_STRING_SIGN));
00671 
00672   if (w != NULL && w->cur_sign == sign) delete w;
00673 }